Skip to content

Commit 9179c35

Browse files
committed
BREAKING CHANGE: feat(tracking): Check for Third party NPM replacements and make use of those if set by default
1 parent 1ce50fa commit 9179c35

22 files changed

+127
-55
lines changed

docs/documentation/new.md

+1-1
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

+1-1
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

+10-4
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

+1-1
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

+1-1
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

+5
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@
292292
},
293293
"additionalProperties": false
294294
},
295+
"packageManager": {
296+
"enum": [ "npm", "cnpm", "yarn", "default" ],
297+
"default": "default",
298+
"type": "string"
299+
},
295300
"warnings": {
296301
"description": "Allow people to disable console warnings.",
297302
"type": "object",

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ import {exec} from 'child_process';
66
export default Task.extend({
77
run: function() {
88
const ui = this.ui;
9+
let packageManager = this.packageManager;
10+
if (packageManager === 'default') {
11+
packageManager = 'npm';
12+
}
913

1014
return new Promise(function(resolve, reject) {
11-
ui.writeLine(chalk.green('Installing packages for tooling via npm.'));
12-
exec('npm install',
15+
ui.writeLine(chalk.green(`Installing packages for tooling via ${packageManager}.`));
16+
exec(`${packageManager} install`,
1317
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
1418
if (err) {
1519
ui.writeLine(stderr);
1620
ui.writeLine(chalk.red('Package install failed, see above.'));
1721
reject();
1822
} else {
19-
ui.writeLine(chalk.green('Installed packages for tooling via npm.'));
23+
ui.writeLine(chalk.green(`Installed packages for tooling via ${packageManager}.`));
2024
resolve();
2125
}
2226
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
if (packageManager !== 'default') {
12+
return Promise.resolve();
13+
}
14+
15+
return Promise
16+
.all([checkYarn(), checkCNPM()])
17+
.then((data: Array<boolean>) => {
18+
const [isYarnInstalled, isCNPMInstalled] = data;
19+
if (isYarnInstalled && isCNPMInstalled) {
20+
console.log(chalk.yellow('You can `ng set --global packageManager=yarn` '
21+
+ 'or `ng set --global packageManager=cnpm`.'));
22+
} else if (isYarnInstalled) {
23+
console.log(chalk.yellow('You can `ng set --global packageManager=yarn`.'));
24+
} else if (isCNPMInstalled) {
25+
console.log(chalk.yellow('You can `ng set --global packageManager=cnpm`.'));
26+
}
27+
});
28+
}
29+
30+
function checkYarn() {
31+
return execPromise('yarn --version')
32+
.then(() => true, () => false);
33+
}
34+
35+
function checkCNPM() {
36+
return execPromise('cnpm --version')
37+
.then(() => true, () => false);
38+
}

packages/@ngtools/json-schema/src/schema-tree.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ class EnumSchemaTreeNode extends LeafSchemaTreeNode<any> {
495495
return v;
496496
}
497497

498-
get type() { return 'any'; }
498+
get type() {
499+
return this._schema['type'] || 'any';
500+
}
499501
get tsType(): null { return null; }
500502
serialize(serializer: Serializer) { serializer.outputEnum(this); }
501503
}

tests/acceptance/destroy.spec.js

+1-1
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

+1-1
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

tests/acceptance/generate-component.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Acceptance: ng generate component', function () {
2020
return tmp.setup('./tmp').then(function () {
2121
process.chdir('./tmp');
2222
}).then(function () {
23-
return ng(['new', 'foo', '--skip-npm']);
23+
return ng(['new', 'foo', '--skip-install']);
2424
});
2525
});
2626

tests/acceptance/generate-directive.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Acceptance: ng generate directive', function () {
1919
return tmp.setup('./tmp').then(function () {
2020
process.chdir('./tmp');
2121
}).then(function () {
22-
return ng(['new', 'foo', '--skip-npm']);
22+
return ng(['new', 'foo', '--skip-install']);
2323
});
2424
});
2525

tests/acceptance/generate-module.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Acceptance: ng generate module', 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

tests/acceptance/generate-pipe.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Acceptance: ng generate pipe', function () {
2020
return tmp.setup('./tmp').then(function () {
2121
process.chdir('./tmp');
2222
}).then(function () {
23-
return ng(['new', 'foo', '--skip-npm']);
23+
return ng(['new', 'foo', '--skip-install']);
2424
});
2525
});
2626

tests/acceptance/generate-route.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ xdescribe('Acceptance: ng generate route', function () {
2121
return tmp.setup('./tmp').then(function () {
2222
process.chdir('./tmp');
2323
}).then(function () {
24-
return ng(['new', 'foo', '--skip-npm']);
24+
return ng(['new', 'foo', '--skip-install']);
2525
});
2626
});
2727

tests/acceptance/generate-service.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Acceptance: ng generate service', function () {
1919
return tmp.setup('./tmp').then(function () {
2020
process.chdir('./tmp');
2121
}).then(function () {
22-
return ng(['new', 'foo', '--skip-npm']);
22+
return ng(['new', 'foo', '--skip-install']);
2323
});
2424
});
2525

tests/acceptance/init.spec.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('Acceptance: ng update', function () {
9797
it('ng init does the same as ng update', function () {
9898
return ng([
9999
'init',
100-
'--skip-npm'
100+
'--skip-install'
101101
]).then(confirmBlueprinted);
102102
});
103103

@@ -109,7 +109,7 @@ describe('Acceptance: ng update', function () {
109109
.then(function () {
110110
return ng([
111111
'init',
112-
'--skip-npm',
112+
'--skip-install',
113113
'--name',
114114
'tmp'
115115
]);
@@ -121,79 +121,79 @@ describe('Acceptance: ng update', function () {
121121
});
122122

123123
it('init an already init\'d folder', function () {
124-
return ng(['init', '--skip-npm'])
124+
return ng(['init', '--skip-install'])
125125
.then(function () {
126-
return ng(['init', '--skip-npm']);
126+
return ng(['init', '--skip-install']);
127127
})
128128
.then(confirmBlueprinted);
129129
});
130130

131131
it('init a single file', function () {
132-
return ng(['init', 'package.json', '--skip-npm'])
132+
return ng(['init', 'package.json', '--skip-install'])
133133
.then(function () {
134134
return 'package.json';
135135
})
136136
.then(confirmGlobBlueprinted);
137137
});
138138

139139
it('init a single file on already init\'d folder', function () {
140-
return ng(['init', '--skip-npm'])
140+
return ng(['init', '--skip-install'])
141141
.then(function () {
142-
return ng(['init', 'package.json', '--skip-npm']);
142+
return ng(['init', 'package.json', '--skip-install']);
143143
})
144144
.then(confirmBlueprinted);
145145
});
146146

147147
it('init multiple files by glob pattern', function () {
148-
return ng(['init', 'src/**', '--skip-npm'])
148+
return ng(['init', 'src/**', '--skip-install'])
149149
.then(function () {
150150
return 'src/**';
151151
})
152152
.then(confirmGlobBlueprinted);
153153
});
154154

155155
it('init multiple files by glob pattern on already init\'d folder', function () {
156-
return ng(['init', '--skip-npm'])
156+
return ng(['init', '--skip-install'])
157157
.then(function () {
158-
return ng(['init', 'src/**', '--skip-npm']);
158+
return ng(['init', 'src/**', '--skip-install']);
159159
})
160160
.then(confirmBlueprinted);
161161
});
162162

163163
it('init multiple files by glob patterns', function () {
164-
return ng(['init', 'src/**', 'package.json', '--skip-npm'])
164+
return ng(['init', 'src/**', 'package.json', '--skip-install'])
165165
.then(function () {
166166
return '{src/**,package.json}';
167167
})
168168
.then(confirmGlobBlueprinted);
169169
});
170170

171171
it('init multiple files by glob patterns on already init\'d folder', function () {
172-
return ng(['init', '--skip-npm'])
172+
return ng(['init', '--skip-install'])
173173
.then(function () {
174-
return ng(['init', 'src/**', 'package.json', '--skip-npm']);
174+
return ng(['init', 'src/**', 'package.json', '--skip-install']);
175175
})
176176
.then(confirmBlueprinted);
177177
});
178178

179179
it('ng update --inline-template does not generate a template file', () => {
180-
return ng(['init', '--skip-npm', '--skip-git', '--inline-template'])
180+
return ng(['init', '--skip-install', '--skip-git', '--inline-template'])
181181
.then(() => {
182182
const templateFile = path.join('src', 'app', 'app.component.html');
183183
expect(existsSync(templateFile)).to.equal(false);
184184
});
185185
});
186186

187187
it('ng update --inline-style does not gener a style file', () => {
188-
return ng(['init', '--skip-npm', '--skip-git', '--inline-style'])
188+
return ng(['init', '--skip-install', '--skip-git', '--inline-style'])
189189
.then(() => {
190190
const styleFile = path.join('src', 'app', 'app.component.css');
191191
expect(existsSync(styleFile)).to.equal(false);
192192
});
193193
});
194194

195195
it('should skip spec files when passed --skip-tests', () => {
196-
return ng(['init', '--skip-npm', '--skip-git', '--skip-tests'])
196+
return ng(['init', '--skip-install', '--skip-git', '--skip-tests'])
197197
.then(() => {
198198
const specFile = path.join('src', 'app', 'app.component.spec.ts');
199199
expect(existsSync(specFile)).to.equal(false);

0 commit comments

Comments
 (0)