Repository navigation
feat: allow global options in the config of a sub-command - #3927
Open
itsnjstyle27 wants to merge 1 commit into
Open
itsnjstyle27 wants to merge 1 commit into
itsnjstyle27 wants to merge 1 commit into
Conversation
Global options such as sourceDir or ignoreFiles can be passed to any sub-command on the command line, but a config file only accepted them at the top level. In a sub-command section they failed with "unknown option". Accept them there too, and use them only when that sub-command runs. Sub-command sections are now applied after the top-level options, so a value for the running sub-command takes precedence over the top-level one, while a CLI value still takes precedence over both. A global option configured for another sub-command is type-checked but not used. Fixes mozilla#3571
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3571
Global options such as
sourceDirorignoreFilescan be passed to any sub-command on the command line (web-ext run --source-dir dist), but a config file only accepted them at the top level. In a sub-command section they failed:{ "webExt": { "run": { "sourceDir": "dist" }, "lint": { "ignoreFiles": ["dist/**"] } } }With this change, a sub-command section can also set global options, and they are used only when that sub-command runs. In the example above,
web-ext runusesdistas the source directory, andweb-ext lintuses the default source directory and ignoresdist/**.How it works, in
applyConfigToArgv:run.sourceDirtakes precedence over a top-levelsourceDir, whatever their order in the file. A value on the command line still takes precedence over both.Options that belong to a sub-command are handled as before.
Tests: I added unit tests to
test.config.jsfor a global option configured for the running sub-command, for the precedence over the same option at the top level (in both orders), for another sub-command not using it, for the CLI value taking precedence, and for the type check. All five fail without this change. ESLint, Prettier and the full unit suite pass (one run test, "throws error when used without firefox-profile or chromium-profile", failed once in the full run on Windows and passes on its own, on master too).The configuration file docs on Extension Workshop would need a sentence about this. I can open a PR there once this is accepted.