Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom CLI option namespace and improve warnings #2063

Merged
merged 3 commits into from
Mar 17, 2018

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Mar 15, 2018

As discussed in #1926:

  • Using an unknown CLI option will now trigger a warning
  • There are now separate warnings for CLI, input and output options that will only validate against their respective sets of options
  • There will be no warnings for CLI options starting with config i.e. these options can be safely used for custom functionality

Update: To not have lots of warnings in the tests, this soon turned into a much larger refactoring and cleanup of the option handling. These are the most prominent changes and improvements:

  • legacy/output.legacy was completely broken as some parts of the code assumed this to be an output option while others assumed it to be an input option. I have now turned this into an output option only (which means I should not forget to adjust the docs accordingly).
  • CLI option handling was very confused as to what the names of options could be. I decided to allow accessing both input and output options without the need for output. which is also much more in-line with the documentation. To avoid regressions, using the output. prefix will still work but is not advertised e.g. in the CLI help. Will need to check the website for this as well.
  • Default values for options can now be specified in mergeOptions which should make some unpleasant checks when boolean flags are true by default much more pleasant.

@lukastaegert
Copy link
Member Author

Seems this causes a lot of noise in the test output. I'll fix this tomorrow morning.

@guybedford
Copy link
Contributor

Amazing, thanks for looking into this so soon. Just let me know when it's ready for review.

@lukastaegert
Copy link
Member Author

When you start going down a rabbit whole...
@guybedford this is ready for review now!

lukastaegert added a commit to rollup/rollupjs.org that referenced this pull request Mar 16, 2018
Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very important rabbit hole - great work diving into these nasty parts :)

-o, --output.file <output> Output (if absent, prints to stdout)
-f, --output.format [es] Type of output (amd, cjs, es, iife, umd)
-o, --file <output> Output (if absent, prints to stdout)
-f, --format [es] Type of output (amd, cjs, es, iife, umd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

);
if (unknownOptions.length > 0)
errors.push(
`Unknown ${optionType} option: ${unknownOptions.join(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor point with the wording here for Unknown CLI option:... perhaps make this Unknown ${optionType}: where optionType is 'CLI flag' or 'input option' or 'output option'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

warnings++;
assert.equal(warning.code, 'UNKNOWN_OPTION');
assert.equal(warning.message,
'Unknown CLI option: unknownOption. Allowed options: acorn, acornInjectPlugins, amd, banner, c, cache, config, context, d, dir, e, entry, environment, experimentalCodeSplitting, experimentalDynamicImport, experimentalPreserveModules, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, input, interop, intro, l, legacy, m, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveSymlinks, silent, sourcemap, sourcemapFile, strict, treeshake, v, w, watch');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I say this is that Allowed options here may not immediately be clear to users that these are flags without using the word flag (at least it was to me - I would have interpreted these as commands rollup c etc instead of rollup -c...).

@lukastaegert lukastaegert added this to the 0.57.1 milestone Mar 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants