diff --git a/packages/angular/cli/commands/add-impl.ts b/packages/angular/cli/commands/add-impl.ts index b30ab9fbb7bb..d61d728159e7 100644 --- a/packages/angular/cli/commands/add-impl.ts +++ b/packages/angular/cli/commands/add-impl.ts @@ -39,7 +39,7 @@ export class AddCommand extends SchematicCommand { } async run(options: AddCommandSchema & Arguments) { - ensureCompatibleNpm(); + await ensureCompatibleNpm(this.context.root); if (!options.collection) { this.logger.fatal( diff --git a/packages/angular/cli/commands/new-impl.ts b/packages/angular/cli/commands/new-impl.ts index 33170dcd22db..ffa81815c9b8 100644 --- a/packages/angular/cli/commands/new-impl.ts +++ b/packages/angular/cli/commands/new-impl.ts @@ -22,7 +22,7 @@ export class NewCommand extends SchematicCommand { } public async run(options: NewCommandSchema & Arguments) { - ensureCompatibleNpm(); + await ensureCompatibleNpm(this.context.root); // Register the version of the CLI in the registry. const packageJson = require('../package.json'); diff --git a/packages/angular/cli/commands/update-impl.ts b/packages/angular/cli/commands/update-impl.ts index 35315c50929e..38b8c138bb8e 100644 --- a/packages/angular/cli/commands/update-impl.ts +++ b/packages/angular/cli/commands/update-impl.ts @@ -267,7 +267,7 @@ export class UpdateCommand extends Command { // tslint:disable-next-line:no-big-function async run(options: UpdateCommandSchema & Arguments) { - ensureCompatibleNpm(); + await ensureCompatibleNpm(this.context.root); // Check if the current installed CLI version is older than the latest version. if (!disableVersionCheck && await this.checkCLILatestVersion(options.verbose, options.next)) { diff --git a/packages/angular/cli/utilities/package-manager.ts b/packages/angular/cli/utilities/package-manager.ts index 5c21c0348310..3789c56ea23b 100644 --- a/packages/angular/cli/utilities/package-manager.ts +++ b/packages/angular/cli/utilities/package-manager.ts @@ -58,7 +58,11 @@ export async function getPackageManager(root: string): Promise { /** * Checks if the npm version is version 6.x. If not, display a message and exit. */ -export function ensureCompatibleNpm() { +export async function ensureCompatibleNpm(root: string): Promise { + if ((await getPackageManager(root)) !== PackageManager.Npm) { + return; + } + try { const version = execSync('npm --version', {encoding: 'utf8', stdio: 'pipe'}).trim(); const major = Number(version.match(/^(\d+)\./)?.[1]);