Skip to content

Commit

Permalink
fix(@angular/cli): check package manager existance before installing …
Browse files Browse the repository at this point in the history
…packages
  • Loading branch information
mac2000 authored and hansl committed Jul 5, 2017
1 parent 6ca34c6 commit b0576d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/@angular/cli/tasks/npm-install.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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') {
Expand All @@ -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();
}
});
});
Expand Down
9 changes: 5 additions & 4 deletions packages/@angular/cli/utilities/check-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>) => {
Expand All @@ -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`.'));
}
}
});
}
Expand Down

0 comments on commit b0576d6

Please sign in to comment.