Skip to content

Commit 7eef2a9

Browse files
committed
fix(@angular/cli): improve error logging when resolving update migrations
Failure to resolve a migration package from the workspace root will now not crash and instead error with a message. Verbose logging (`--verbose`) is also added to provide more details regarding the resolution process. (cherry picked from commit 9a44bf4)
1 parent 893afa8 commit 7eef2a9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

packages/angular/cli/commands/update-impl.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
284284
);
285285
}
286286

287+
const logVerbose = (message: string) => {
288+
if (options.verbose) {
289+
this.logger.info(message);
290+
}
291+
};
292+
287293
if (options.all) {
288294
const updateCmd = this.packageManager === PackageManager.Yarn
289295
? `'yarn upgrade-interactive' or 'yarn upgrade'`
@@ -654,7 +660,28 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
654660
for (const migration of migrations) {
655661
// Resolve the package from the workspace root, as otherwise it will be resolved from the temp
656662
// installed CLI version.
657-
const packagePath = require.resolve(migration.package, { paths: [this.context.root] });
663+
let packagePath;
664+
logVerbose(
665+
`Resolving migration package '${migration.package}' from '${this.context.root}'...`,
666+
);
667+
try {
668+
packagePath = require.resolve(migration.package, { paths: [this.context.root] });
669+
} catch (e) {
670+
if (e.code === 'MODULE_NOT_FOUND') {
671+
logVerbose(e.toString());
672+
this.logger.error(
673+
`Migrations for package (${migration.package}) were not found.` +
674+
' The package could not be found in the workspace.',
675+
);
676+
} else {
677+
this.logger.error(
678+
`Unable to resolve migrations for package (${migration.package}). [${e.message}]`,
679+
);
680+
}
681+
682+
return 1;
683+
}
684+
658685
let migrations;
659686

660687
// Check if it is a package-local location

0 commit comments

Comments
 (0)