fix(ngcc): do not crash on entry-point that fails to compile (#36083)

Previously, when an entry-point contained code that caused its compilation
to fail, ngcc would exit in the middle of processing, possibly leaving other
entry-points in a corrupt state.

This change adds a new `errorOnFailedEntryPoint` option to `mainNgcc` that
specifies whether ngcc should exit immediately or log an error and continue
processing other entry-points.

The default is `false` so that ngcc will not error but continue processing
as much as possible. This is useful in post-install hooks, and async CLI
integration, where we do not have as much control over which entry-points
should be processed.

The option is forced to true if the `targetEntryPointPath` is provided,
such as the sync integration with the CLI, since in that case it is targeting
an entry-point that will actually be used in the current project so we do want
ngcc to exit with an error at that point.

PR Close #36083
This commit is contained in:
Pete Bacon Darwin
2020-03-16 15:08:47 +00:00
committed by Andrew Kushnir
parent 1790b63a5d
commit ff665b9e6a
10 changed files with 247 additions and 57 deletions

View File

@ -39,7 +39,8 @@ if (require.main === module) {
.option('t', {
alias: 'target',
describe:
'A relative path (from the `source` path) to a single entry-point to process (plus its dependencies).',
'A relative path (from the `source` path) to a single entry-point to process (plus its dependencies).\n' +
'If this property is provided then `error-on-failed-entry-point` is forced to true',
})
.option('first-only', {
describe:
@ -83,6 +84,14 @@ if (require.main === module) {
type: 'boolean',
default: false,
})
.option('error-on-failed-entry-point', {
describe:
'Set this option in order to terminate immediately with an error code if an entry-point fails to be processed.\n' +
'If `-t`/`--target` is provided then this property is always true and cannot be changed. Otherwise the default is false.\n' +
'When set to false, ngcc will continue to process entry-points after a failure. In which case it will log an error and resume processing other entry-points.',
type: 'boolean',
default: false,
})
.strict()
.help()
.parse(args);
@ -103,6 +112,7 @@ if (require.main === module) {
const logLevel = options['l'] as keyof typeof LogLevel | undefined;
const enableI18nLegacyMessageIdFormat = options['legacy-message-ids'];
const invalidateEntryPointManifest = options['invalidate-entry-point-manifest'];
const errorOnFailedEntryPoint = options['error-on-failed-entry-point'];
(async() => {
try {
@ -116,7 +126,7 @@ if (require.main === module) {
createNewEntryPointFormats,
logger,
enableI18nLegacyMessageIdFormat,
async: options['async'], invalidateEntryPointManifest,
async: options['async'], invalidateEntryPointManifest, errorOnFailedEntryPoint,
});
if (logger) {