From d6ba30bfe22a851aee2ad0a146edef2cb3cd5a90 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 5 Feb 2021 13:15:34 +0100 Subject: [PATCH] fix(@angular/cli): only show incompatible NPM error when NPM is used as package manager (cherry picked from commit cae2209ca816c297793ff1b921ab54739aac724e) --- packages/angular/cli/commands/add-impl.ts | 2 +- packages/angular/cli/commands/new-impl.ts | 2 +- packages/angular/cli/commands/update-impl.ts | 2 +- packages/angular/cli/utilities/package-manager.ts | 6 +++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/angular/cli/commands/add-impl.ts b/packages/angular/cli/commands/add-impl.ts index 6812c0f92c13..f1915b512f81 100644 --- a/packages/angular/cli/commands/add-impl.ts +++ b/packages/angular/cli/commands/add-impl.ts @@ -38,7 +38,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 1d78a5a8e19b..9e85d68de03a 100644 --- a/packages/angular/cli/commands/update-impl.ts +++ b/packages/angular/cli/commands/update-impl.ts @@ -256,7 +256,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 @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 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]);