From e75ff56038e5da42f20aa1b0ed15059c8004de32 Mon Sep 17 00:00:00 2001 From: Alexandr Marchenko Date: Wed, 21 Jun 2017 09:11:08 +0300 Subject: [PATCH] fix(@angular/cli): check package manager existance before installing packages --- packages/@angular/cli/tasks/npm-install.ts | 9 +++++---- packages/@angular/cli/utilities/check-package-manager.ts | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/@angular/cli/tasks/npm-install.ts b/packages/@angular/cli/tasks/npm-install.ts index 2cd14d3ec003..a9cf2fbe6ab0 100644 --- a/packages/@angular/cli/tasks/npm-install.ts +++ b/packages/@angular/cli/tasks/npm-install.ts @@ -1,6 +1,7 @@ const Task = require('../ember-cli/lib/models/task'); import * as chalk from 'chalk'; import {exec} from 'child_process'; +import {checkYarnOrCNPM} from '../utilities/check-package-manager'; export default Task.extend({ @@ -11,7 +12,7 @@ export default Task.extend({ packageManager = 'npm'; } - return new Promise(function(resolve, reject) { + return checkYarnOrCNPM().then(function () { ui.writeLine(chalk.green(`Installing packages for tooling via ${packageManager}.`)); let installCommand = `${packageManager} install`; if (packageManager === 'npm') { @@ -21,11 +22,11 @@ export default Task.extend({ (err: NodeJS.ErrnoException, _stdout: string, stderr: string) => { if (err) { ui.writeLine(stderr); - ui.writeLine(chalk.red('Package install failed, see above.')); - reject(); + const message = 'Package install failed, see above.'; + ui.writeLine(chalk.red(message)); + throw new Error(message); } else { ui.writeLine(chalk.green(`Installed packages for tooling via ${packageManager}.`)); - resolve(); } }); }); diff --git a/packages/@angular/cli/utilities/check-package-manager.ts b/packages/@angular/cli/utilities/check-package-manager.ts index f428baeda4e9..c07c9d316304 100644 --- a/packages/@angular/cli/utilities/check-package-manager.ts +++ b/packages/@angular/cli/utilities/check-package-manager.ts @@ -8,10 +8,6 @@ const packageManager = CliConfig.fromGlobal().get('packageManager'); export function checkYarnOrCNPM() { - if (packageManager !== 'default') { - return Promise.resolve(); - } - return Promise .all([checkYarn(), checkCNPM()]) .then((data: Array) => { @@ -23,6 +19,11 @@ export function checkYarnOrCNPM() { console.log(chalk.yellow('You can `ng set --global packageManager=yarn`.')); } else if (isCNPMInstalled) { console.log(chalk.yellow('You can `ng set --global packageManager=cnpm`.')); + } else { + if (packageManager !== 'default' && packageManager !== 'npm') { + console.log(chalk.yellow(`Seems that ${packageManager} is not installed.`)); + console.log(chalk.yellow('You can `ng set --global packageManager=npm`.')); + } } }); }