Skip to content

Commit 1f89c61

Browse files
alan-agius4matsko
authored andcommitted
fix(ngcc): show helpful error when providing an invalid option (angular#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 angular#36010
1 parent aad02e8 commit 1f89c61

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

integration/ngcc/test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ function assertNotEquals {
4242
fi
4343
}
4444

45-
4645
ngcc --help
4746
assertSucceeded "Expected 'ngcc --help' to succeed."
4847

48+
ngcc --unknown-option 2>&1 | grep 'Unknown arguments: unknown-option, unknownOption'
49+
assertSucceeded "Expected ngcc to report bad option."
50+
4951
# node --inspect-brk $(npm bin)/ngcc -f esm2015
5052
# Run ngcc and check it logged compilation output as expected
5153
ngcc | grep 'Compiling'

packages/compiler-cli/ngcc/main-ngcc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ if (require.main === module) {
7676
describe: 'The lowest severity logging message that should be output.',
7777
choices: ['debug', 'info', 'warn', 'error'],
7878
})
79+
.strict()
7980
.help()
8081
.parse(args);
8182

0 commit comments

Comments
 (0)