Skip to content

Commit

Permalink
fix(@angular/cli): only show incompatible NPM error when NPM is used …
Browse files Browse the repository at this point in the history
…as package manager

(cherry picked from commit cae2209)
  • Loading branch information
alan-agius4 authored and clydin committed Feb 5, 2021
1 parent 8a846d4 commit a80c25a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/angular/cli/commands/add-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {
}

async run(options: AddCommandSchema & Arguments) {
ensureCompatibleNpm();
await ensureCompatibleNpm(this.context.root);

if (!options.collection) {
this.logger.fatal(
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/commands/new-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class NewCommand extends SchematicCommand<NewCommandSchema> {
}

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');
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/commands/update-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {

// 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)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/angular/cli/utilities/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export async function getPackageManager(root: string): Promise<PackageManager> {
/**
* 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<void> {
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]);
Expand Down

0 comments on commit a80c25a

Please sign in to comment.