From 5d6602161b3151da7330c3854c9c7cce4c291f12 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 18 Dec 2019 12:11:23 -0500 Subject: [PATCH] fix(@angular/cli): inform user and error if schematics package is in unreachable location This is a workaround for the schematics runtime to support the requirement of packages containing migrations (or other schematics) to not have a direct/runtime dependency on the schematics package. Closes: #16392 --- packages/angular/cli/commands/update-impl.ts | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/angular/cli/commands/update-impl.ts b/packages/angular/cli/commands/update-impl.ts index 7ce8c23170d6..079f3fc04845 100644 --- a/packages/angular/cli/commands/update-impl.ts +++ b/packages/angular/cli/commands/update-impl.ts @@ -241,6 +241,28 @@ export class UpdateCommand extends Command { // tslint:disable-next-line:no-big-function async run(options: UpdateCommandSchema & Arguments) { + // Check if the @angular-devkit/schematics package can be resolved from the workspace root + // This works around issues with packages containing migrations that cannot directly depend on the package + // This check can be removed once the schematic runtime handles this situation + try { + require.resolve('@angular-devkit/schematics', { paths: [this.workspace.root] }); + } catch (e) { + if (e.code === 'MODULE_NOT_FOUND') { + this.logger.fatal( + 'The "@angular-devkit/schematics" package cannot be resolved from the workspace root directory. ' + + 'This may be due to an unsupported node modules structure.\n' + + 'Please remove both the "node_modules" directory and the package lock file; and then reinstall.\n' + + 'If this does not correct the problem, ' + + 'please temporarily install the "@angular-devkit/schematics" package within the workspace. ' + + 'It can be removed once the update is complete.', + ); + + return 1; + } + + throw e; + } + // Check if the current installed CLI version is older than the latest version. if (await this.checkCLILatestVersion(options.verbose, options.next)) { this.logger.warn(