Skip to content

Commit afb7391

Browse files
committed
fix(npm): update to npm 3.10.2
The npm task from our current ember-cli install uses npm 2.x.x, which was causing issues with some of the dependencies. This PR copies over all files needed for the npm-install task but uses a local 3.10.2 npm version instead. Fix angular#1186 Fix angular#1191 Fix angular#1201 Fix angular#1209 Fix angular#1207 Fix angular#1248
1 parent 5183e1d commit afb7391

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

addon/ng2/commands/init.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
77
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
88
var GitInit = require('../tasks/git-init');
99
var LinkCli = require('../tasks/link-cli');
10+
var NpmInstall = require('../tasks/npm-install');
1011

1112
module.exports = Command.extend({
1213
name: 'init',
@@ -68,7 +69,7 @@ module.exports = Command.extend({
6869
}
6970

7071
if (!commandOptions.skipNpm) {
71-
var npmInstall = new this.tasks.NpmInstall({
72+
var npmInstall = new NpmInstall({
7273
ui: this.ui,
7374
analytics: this.analytics,
7475
project: this.project

addon/ng2/tasks/npm-install.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
// Runs `npm install` in cwd
4+
5+
var NpmTask = require('./npm-task');
6+
7+
module.exports = NpmTask.extend({
8+
command: 'install',
9+
startProgressMessage: 'Installing packages for tooling via npm',
10+
completionMessage: 'Installed packages for tooling via npm.'
11+
});

addon/ng2/tasks/npm-task.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
// Runs `npm install` in cwd
4+
5+
var chalk = require('chalk');
6+
var Task = require('ember-cli/lib/models/task');
7+
var npm = require('../utilities/npm');
8+
9+
module.exports = Task.extend({
10+
// The command to run: can be 'install' or 'uninstall'
11+
command: '',
12+
// Message to send to ui.startProgress
13+
startProgressMessage: '',
14+
// Message to send to ui.writeLine on completion
15+
completionMessage: '',
16+
17+
init: function() {
18+
this.npm = this.npm || require('npm');
19+
},
20+
// Options: Boolean verbose
21+
run: function(options) {
22+
this.ui.startProgress(chalk.green(this.startProgressMessage), chalk.green('.'));
23+
24+
var npmOptions = {
25+
loglevel: options.verbose ? 'verbose' : 'error',
26+
logstream: this.ui.outputStream,
27+
color: 'always',
28+
// by default, do install peoples optional deps
29+
'optional': 'optional' in options ? options.optional : true,
30+
'save-dev': !!options['save-dev'],
31+
'save-exact': !!options['save-exact']
32+
};
33+
34+
var packages = options.packages || [];
35+
36+
// npm otherwise is otherwise noisy, already submitted PR for npm to fix
37+
// misplaced console.log
38+
this.disableLogger();
39+
40+
return npm(this.command, packages, npmOptions, this.npm).
41+
finally(this.finally.bind(this)).
42+
then(this.announceCompletion.bind(this));
43+
},
44+
45+
announceCompletion: function() {
46+
this.ui.writeLine(chalk.green(this.completionMessage));
47+
},
48+
49+
finally: function() {
50+
this.ui.stopProgress();
51+
this.restoreLogger();
52+
},
53+
54+
disableLogger: function() {
55+
this.oldLog = console.log;
56+
console.log = function() {};
57+
},
58+
59+
restoreLogger: function() {
60+
console.log = this.oldLog; // Hack, see above
61+
}
62+
});

addon/ng2/utilities/npm.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
var Promise = require('ember-cli/lib/ext/promise');
4+
5+
//
6+
7+
/**
8+
Runs the npm command `command` with the supplied args and load options.
9+
10+
Please note that the loaded module appears to retain some state, so do not
11+
expect multiple invocations within the same process to work without quirks.
12+
This problem is likely fixable.
13+
14+
@method npm
15+
@param {String} command The npm command to run.
16+
@param {Array} npmArgs The arguments passed to the npm command.
17+
@param {Array} options The options passed when loading npm.
18+
@param {Module} [npm] A reference to the npm module.
19+
*/
20+
module.exports = function npm(command, npmArgs, options/*, npm*/) {
21+
var lib;
22+
if (arguments.length === 4) {
23+
lib = arguments[3];
24+
} else {
25+
lib = require('npm');
26+
}
27+
28+
var load = Promise.denodeify(lib.load);
29+
30+
return load(options)
31+
.then(function() {
32+
// if install is denodeified outside load.then(),
33+
// it throws "Call npm.load(config, cb) before using this command."
34+
var operation = Promise.denodeify(lib.commands[command]);
35+
36+
return operation(npmArgs || []);
37+
});
38+
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"handlebars": "^4.0.5",
4848
"leek": "0.0.21",
4949
"lodash": "^4.11.1",
50+
"npm": "3.10.2",
5051
"opn": "4.0.1",
5152
"resolve": "^1.1.7",
5253
"shelljs": "^0.7.0",

0 commit comments

Comments
 (0)