From 1f89c6130ed1aa908c0fa293664882480d0e3df8 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 11 Mar 2020 12:42:56 +0100 Subject: [PATCH] fix(ngcc): show helpful error when providing an invalid option (#36010) Currently, when running the ngcc binary directly and provide an invalid option ngcc will not error out and the user might have a hard time telling why ngcc is behaving not as expected. With this change we now output an actionable error: ``` yarn ngcc --unknown-option Options: --version Show version number [boolean] -s, --source A path (relative to the working directory) of the `node_modules` folder to process. [default: "./node_modules"] -p, --properties An array of names of properties in package.json to compile (e.g. `module` or `es2015`) Each of these properties should hold the path to a bundle-format. If provided, only the specified properties are considered for processing. If not provided, all the supported format properties (e.g. fesm2015, fesm5, es2015, esm2015, esm5, main, module) in the package.json are considered. [array] -t, --target A relative path (from the `source` path) to a single entry-point to process (plus its dependencies). --first-only If specified then only the first matching package.json property will be compiled. [boolean] --create-ivy-entry-points If specified then new `*_ivy_ngcc` entry-points will be added to package.json rather than modifying the ones in-place. For this to work you need to have custom resolution set up (e.g. in webpack) to look for these new entry-points. The Angular CLI does this already, so it is safe to use this option if the project is being built via the CLI. [boolean] --legacy-message-ids Render `$localize` messages with legacy format ids. The default value is `true`. Only set this to `false` if you do not want legacy message ids to be rendered. For example, if you are not using legacy message ids in your translation files AND are not doing compile-time inlining of translations, in which case the extra message ids would add unwanted size to the final source bundle. It is safe to leave this set to true if you are doing compile-time inlining because the extra legacy message ids will all be stripped during translation. [boolean] [default: true] --async Whether to compile asynchronously. This is enabled by default as it allows compilations to be parallelized. Disabling asynchronous compilation may be useful for debugging. [boolean] [default: true] -l, --loglevel The lowest severity logging message that should be output. [choices: "debug", "info", "warn", "error"] --invalidate-entry-point-manifest If this is set then ngcc will not read an entry-point manifest file from disk. Instead it will walking the directory tree as normal looking for entry-points, and then write a new manifest file. [boolean] [default: false] --help Show help [boolean] Unknown arguments: unknown-option, unknownOption ``` PR Close #36010 --- integration/ngcc/test.sh | 4 +++- packages/compiler-cli/ngcc/main-ngcc.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/integration/ngcc/test.sh b/integration/ngcc/test.sh index 4c5fb4bb61..d4729a2dc3 100755 --- a/integration/ngcc/test.sh +++ b/integration/ngcc/test.sh @@ -42,10 +42,12 @@ function assertNotEquals { fi } - ngcc --help assertSucceeded "Expected 'ngcc --help' to succeed." +ngcc --unknown-option 2>&1 | grep 'Unknown arguments: unknown-option, unknownOption' +assertSucceeded "Expected ngcc to report bad option." + # node --inspect-brk $(npm bin)/ngcc -f esm2015 # Run ngcc and check it logged compilation output as expected ngcc | grep 'Compiling' diff --git a/packages/compiler-cli/ngcc/main-ngcc.ts b/packages/compiler-cli/ngcc/main-ngcc.ts index e3a7f7d2d7..bc385c8253 100644 --- a/packages/compiler-cli/ngcc/main-ngcc.ts +++ b/packages/compiler-cli/ngcc/main-ngcc.ts @@ -76,6 +76,7 @@ if (require.main === module) { describe: 'The lowest severity logging message that should be output.', choices: ['debug', 'info', 'warn', 'error'], }) + .strict() .help() .parse(args);