Skip to content

Commit f5bf475

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 (main issue) Fix angular#1191 Fix angular#1201 Fix angular#1209 Fix angular#1207 Fix angular#1248
1 parent 5183e1d commit f5bf475

File tree

5 files changed

+116
-1
lines changed

5 files changed

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

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

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)