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 9ccc6f9 commit d6ba30b
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
Expand Up @@ -38,7 +38,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
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
Expand Up @@ -256,7 +256,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 @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
Expand Down
6 changes: 5 additions & 1 deletion packages/angular/cli/utilities/package-manager.ts
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 d6ba30b

Please sign in to comment.