Skip to content

Commit 034c501

Browse files
committed
feat(tracking): Check for Third party NPM replacements and make use of those if set by default
1 parent cbab6f8 commit 034c501

File tree

21 files changed

+117
-54
lines changed

21 files changed

+117
-54
lines changed

docs/documentation/new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Default applications are created in a directory of the same name, with an initia
1010
## Options
1111
`--dry-run` (`-d`) run through without making any changes
1212

13-
`--skip-npm` (`-sn`) skip installing npm packages
13+
`--skip-install` (`-si`) skip installing packages
1414

1515
`--skip-git` (`-sg`) skip initializing a git repository
1616

docs/documentation/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Initialization is done in-place, meaning that the generated application is initi
1010
## Options
1111
`--dry-run` (`-d`) run through without making any changes
1212

13-
`--skip-npm` (`-sn`) skip installing npm packages
13+
`--skip-install` (`-si`) skip installing packages
1414

1515
`--skip-git` (`-sg`) skip initializing a git repository
1616

packages/@angular/cli/commands/init.run.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as chalk from 'chalk';
2+
import {checkYarnOrCNPM} from '../utilities/check-package-manager';
3+
import {CliConfig} from '../models/config';
24
import LinkCli from '../tasks/link-cli';
35
import NpmInstall from '../tasks/npm-install';
46
import { validateProjectName } from '../utilities/validate-project-name';
57

8+
69
const Promise = require('../ember-cli/lib/ext/promise');
710
const SilentError = require('silent-error');
811
const normalizeBlueprint = require('../ember-cli/lib/utilities/normalize-blueprint-option');
@@ -11,7 +14,7 @@ const GitInit = require('../tasks/git-init');
1114

1215
export default function initRun(commandOptions: any, rawArgs: string[]) {
1316
if (commandOptions.dryRun) {
14-
commandOptions.skipNpm = true;
17+
commandOptions.skipInstall = true;
1518
}
1619

1720
const installBlueprint = new this.tasks.InstallBlueprint({
@@ -30,10 +33,12 @@ export default function initRun(commandOptions: any, rawArgs: string[]) {
3033
}
3134

3235
let npmInstall: any;
33-
if (!commandOptions.skipNpm) {
36+
if (!commandOptions.skipInstall) {
37+
const packageManager = CliConfig.fromGlobal().get('packageManager');
3438
npmInstall = new NpmInstall({
3539
ui: this.ui,
36-
project: this.project
40+
project: this.project,
41+
packageManager
3742
});
3843
}
3944

@@ -84,7 +89,7 @@ export default function initRun(commandOptions: any, rawArgs: string[]) {
8489
}
8590
})
8691
.then(function () {
87-
if (!commandOptions.skipNpm) {
92+
if (!commandOptions.skipInstall) {
8893
return npmInstall.run();
8994
}
9095
})
@@ -93,6 +98,7 @@ export default function initRun(commandOptions: any, rawArgs: string[]) {
9398
return linkCli.run();
9499
}
95100
})
101+
.then(checkYarnOrCNPM)
96102
.then(() => {
97103
this.ui.writeLine(chalk.green(`Project '${packageName}' successfully created.`));
98104
});

packages/@angular/cli/commands/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const InitCommand: any = Command.extend({
1010
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
1111
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
1212
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
13-
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
13+
{ name: 'skip-install', type: Boolean, default: false, aliases: ['si'] },
1414
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
1515
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
1616
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },

packages/@angular/cli/commands/new.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const NewCommand = Command.extend({
1515
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
1616
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
1717
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
18-
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
18+
{ name: 'skip-install', type: Boolean, default: false, aliases: ['si'] },
1919
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
2020
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
2121
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },

packages/@angular/cli/lib/config/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@
292292
},
293293
"additionalProperties": false
294294
},
295+
"packageManager": {
296+
"enum": [ "npm", "cnpm", "yarn" ],
297+
"default": "npm"
298+
},
295299
"warnings": {
296300
"description": "Allow people to disable console warnings.",
297301
"type": "object",

packages/@angular/cli/tasks/npm-install.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import {exec} from 'child_process';
66
export default Task.extend({
77
run: function() {
88
const ui = this.ui;
9+
const packageManager = this.packageManager;
910

1011
return new Promise(function(resolve, reject) {
11-
ui.writeLine(chalk.green('Installing packages for tooling via npm.'));
12-
exec('npm install',
12+
ui.writeLine(chalk.green(`Installing packages for tooling via ${packageManager}.`));
13+
exec(`${packageManager} install`,
1314
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
1415
if (err) {
1516
ui.writeLine(stderr);
1617
ui.writeLine(chalk.red('Package install failed, see above.'));
1718
reject();
1819
} else {
19-
ui.writeLine(chalk.green('Installed packages for tooling via npm.'));
20+
ui.writeLine(chalk.green(`Installed packages for tooling via ${packageManager}.`));
2021
resolve();
2122
}
2223
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as chalk from 'chalk';
2+
import {exec} from 'child_process';
3+
import {CliConfig} from '../models/config';
4+
5+
const Promise = require('../ember-cli/lib/ext/promise');
6+
const execPromise = Promise.denodeify(exec);
7+
const packageManager = CliConfig.fromGlobal().get('packageManager')
8+
9+
10+
export function checkYarnOrCNPM() {
11+
return Promise
12+
.all([checkYarn(), checkCNPM()])
13+
.then((data: Array<boolean>) => {
14+
if (packageManager === 'npm') {
15+
const [isYarnInstalled, isCNPMInstalled] = data;
16+
if (isYarnInstalled && isCNPMInstalled) {
17+
console.log(chalk.yellow('You can `ng set --global packageManager=yarn` '
18+
+ 'or `ng set --global packageManager=cnpm`.'));
19+
} else if (isYarnInstalled) {
20+
console.log(chalk.yellow('You can `ng set --global packageManager=yarn`.'));
21+
} else if (isCNPMInstalled) {
22+
console.log(chalk.yellow('You can `ng set --global packageManager=cnpm`.'));
23+
}
24+
}
25+
});
26+
}
27+
28+
function checkYarn() {
29+
return execPromise('yarn --version')
30+
.then(() => true, () => false);
31+
}
32+
33+
function checkCNPM() {
34+
return execPromise('cnpm --version')
35+
.then(() => true, () => false);
36+
}

tests/acceptance/destroy.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Acceptance: ng destroy', function () {
1111
return tmp.setup('./tmp').then(function () {
1212
process.chdir('./tmp');
1313
}).then(function () {
14-
return ng(['new', 'foo', '--skip-npm']);
14+
return ng(['new', 'foo', '--skip-install']);
1515
});
1616
});
1717

tests/acceptance/generate-class.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Acceptance: ng generate class', function () {
1616
return tmp.setup('./tmp').then(function () {
1717
process.chdir('./tmp');
1818
}).then(function () {
19-
return ng(['new', 'foo', '--skip-npm']);
19+
return ng(['new', 'foo', '--skip-install']);
2020
});
2121
});
2222

0 commit comments

Comments
 (0)