Skip to content

Commit

Permalink
fix(npm): update to npm 3.10.2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
filipesilva committed Jun 30, 2016
1 parent 5183e1d commit afb7391
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addon/ng2/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
var GitInit = require('../tasks/git-init');
var LinkCli = require('../tasks/link-cli');
var NpmInstall = require('../tasks/npm-install');

module.exports = Command.extend({
name: 'init',
Expand Down Expand Up @@ -68,7 +69,7 @@ module.exports = Command.extend({
}

if (!commandOptions.skipNpm) {
var npmInstall = new this.tasks.NpmInstall({
var npmInstall = new NpmInstall({
ui: this.ui,
analytics: this.analytics,
project: this.project
Expand Down
11 changes: 11 additions & 0 deletions addon/ng2/tasks/npm-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

// Runs `npm install` in cwd

var NpmTask = require('./npm-task');

module.exports = NpmTask.extend({
command: 'install',
startProgressMessage: 'Installing packages for tooling via npm',
completionMessage: 'Installed packages for tooling via npm.'
});
62 changes: 62 additions & 0 deletions addon/ng2/tasks/npm-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

// Runs `npm install` in cwd

var chalk = require('chalk');
var Task = require('ember-cli/lib/models/task');
var npm = require('../utilities/npm');

module.exports = Task.extend({
// The command to run: can be 'install' or 'uninstall'
command: '',
// Message to send to ui.startProgress
startProgressMessage: '',
// Message to send to ui.writeLine on completion
completionMessage: '',

init: function() {
this.npm = this.npm || require('npm');
},
// Options: Boolean verbose
run: function(options) {
this.ui.startProgress(chalk.green(this.startProgressMessage), chalk.green('.'));

var npmOptions = {
loglevel: options.verbose ? 'verbose' : 'error',
logstream: this.ui.outputStream,
color: 'always',
// by default, do install peoples optional deps
'optional': 'optional' in options ? options.optional : true,
'save-dev': !!options['save-dev'],
'save-exact': !!options['save-exact']
};

var packages = options.packages || [];

// npm otherwise is otherwise noisy, already submitted PR for npm to fix
// misplaced console.log
this.disableLogger();

return npm(this.command, packages, npmOptions, this.npm).
finally(this.finally.bind(this)).
then(this.announceCompletion.bind(this));
},

announceCompletion: function() {
this.ui.writeLine(chalk.green(this.completionMessage));
},

finally: function() {
this.ui.stopProgress();
this.restoreLogger();
},

disableLogger: function() {
this.oldLog = console.log;
console.log = function() {};
},

restoreLogger: function() {
console.log = this.oldLog; // Hack, see above
}
});
38 changes: 38 additions & 0 deletions addon/ng2/utilities/npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

var Promise = require('ember-cli/lib/ext/promise');

//

/**
Runs the npm command `command` with the supplied args and load options.
Please note that the loaded module appears to retain some state, so do not
expect multiple invocations within the same process to work without quirks.
This problem is likely fixable.
@method npm
@param {String} command The npm command to run.
@param {Array} npmArgs The arguments passed to the npm command.
@param {Array} options The options passed when loading npm.
@param {Module} [npm] A reference to the npm module.
*/
module.exports = function npm(command, npmArgs, options/*, npm*/) {
var lib;
if (arguments.length === 4) {
lib = arguments[3];
} else {
lib = require('npm');
}

var load = Promise.denodeify(lib.load);

return load(options)
.then(function() {
// if install is denodeified outside load.then(),
// it throws "Call npm.load(config, cb) before using this command."
var operation = Promise.denodeify(lib.commands[command]);

return operation(npmArgs || []);
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"handlebars": "^4.0.5",
"leek": "0.0.21",
"lodash": "^4.11.1",
"npm": "3.10.2",
"opn": "4.0.1",
"resolve": "^1.1.7",
"shelljs": "^0.7.0",
Expand Down

0 comments on commit afb7391

Please sign in to comment.