Skip to content

Commit a3cab64

Browse files
committedNov 26, 2016
Disambiguate cli options from spawn options - Fix #754
1 parent 687b9be commit a3cab64

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed
 

‎lib/actions/install.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ var install = module.exports;
1818
* run loop. (So don't combine the callback with `this.async()`)
1919
*
2020
* @param {String} installer Which package manager to use
21-
* @param {String|Array} [paths] Packages to install.Use an empty string for `npm install`
22-
* @param {Object} [options] Options to pass to `dargs` as arguments, then to `child_process.spawn`
21+
* @param {String|Array} [paths] Packages to install. Use an empty string for `npm install`
22+
* @param {Object} [options] Options to pass to `dargs` as arguments
2323
* @param {Function} [cb]
24+
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`. ref
25+
* https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
2426
*/
2527

26-
install.runInstall = function (installer, paths, options, cb) {
28+
install.runInstall = function (installer, paths, options, cb, spawnOptions) {
2729
if (!cb && _.isFunction(options)) {
2830
cb = options;
2931
options = {};
3032
}
3133

3234
options = options || {};
35+
spawnOptions = spawnOptions || {};
3336
cb = cb || function () {};
3437
paths = Array.isArray(paths) ? paths : paths && paths.split(' ') || [];
3538

@@ -53,7 +56,7 @@ install.runInstall = function (installer, paths, options, cb) {
5356

5457
this.env.runLoop.add('install', function (done) {
5558
this.emit(installer + 'Install', paths);
56-
this.spawnCommand(installer, args, options)
59+
this.spawnCommand(installer, args, spawnOptions)
5760
.on('error', function (err) {
5861
console.log(chalk.red('Could not finish installation. \n') +
5962
'Please install ' + installer + ' with ' +
@@ -150,12 +153,13 @@ install.installDependencies = function (options) {
150153
* The installation will automatically run during the run loop `install` phase.
151154
*
152155
* @param {String|Array} [cmpnt] Components to install
153-
* @param {Object} [options] Options to pass to `child_process.spawn` when invoking bower.
156+
* @param {Object} [options] Options to pass to `dargs` as arguments
154157
* @param {Function} [cb]
158+
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`.
155159
*/
156160

157-
install.bowerInstall = function install(cmpnt, options, cb) {
158-
return this.runInstall('bower', cmpnt, options, cb);
161+
install.bowerInstall = function install(cmpnt, options, cb, spawnOptions) {
162+
return this.runInstall('bower', cmpnt, options, cb, spawnOptions);
159163
};
160164

161165
/**
@@ -164,23 +168,25 @@ install.bowerInstall = function install(cmpnt, options, cb) {
164168
* The installation will automatically run during the run loop `install` phase.
165169
*
166170
* @param {String|Array} [pkgs] Packages to install
167-
* @param {Object} [options] Options to pass to `child_process.spawn` when invoking npm.
171+
* @param {Object} [options] Options to pass to `dargs` as arguments
168172
* @param {Function} [cb]
173+
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`.
169174
*/
170175

171-
install.npmInstall = function install(pkgs, options, cb) {
172-
return this.runInstall('npm', pkgs, options, cb);
176+
install.npmInstall = function install(pkgs, options, cb, spawnOptions) {
177+
return this.runInstall('npm', pkgs, options, cb, spawnOptions);
173178
};
174179
/**
175180
* Receives a list of `packages` and an `options` object to install through npm.
176181
*
177182
* The installation will automatically run during the run loop `install` phase.
178183
*
179184
* @param {String|Array} [pkgs] Packages to install
180-
* @param {Object} [options] Options to pass to `child_process.spawn` when invoking npm.
185+
* @param {Object} [options] Options to pass to `dargs` as arguments
181186
* @param {Function} [cb]
187+
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`.
182188
*/
183189

184-
install.yarnInstall = function install(pkgs, options, cb) {
185-
return this.runInstall('yarn', pkgs, options, cb);
190+
install.yarnInstall = function install(pkgs, options, cb, spawnOptions) {
191+
return this.runInstall('yarn', pkgs, options, cb, spawnOptions);
186192
};

‎test/install.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ describe('Base (actions/install mixin)', function () {
3232
describe('#runInstall()', function () {
3333
it('takes a config object and passes it to the spawned process', function (done) {
3434
var callbackSpy = sinon.spy();
35+
var options = {
36+
save: true
37+
};
3538
var spawnEnv = {
3639
env: {
3740
PATH: '/path/to/bin'
3841
}
3942
};
4043

4144
// args: installer, paths, options, cb
42-
this.dummy.runInstall('nestedScript', ['path1', 'path2'], spawnEnv, callbackSpy);
45+
this.dummy.runInstall('nestedScript', ['path1', 'path2'], options, callbackSpy, spawnEnv);
4346
this.dummy.run(function () {
4447
sinon.assert.calledWithExactly(
4548
this.spawnCommandStub,
4649
'nestedScript',
47-
['install', 'path1', 'path2'],
50+
['install', 'path1', 'path2', '--save'],
4851
spawnEnv
4952
);
5053

@@ -116,7 +119,7 @@ describe('Base (actions/install mixin)', function () {
116119
this.spawnCommandStub,
117120
'bower',
118121
['install', 'jquery', '--save-dev'],
119-
{ saveDev: true }
122+
{}
120123
);
121124

122125
done();
@@ -168,7 +171,7 @@ describe('Base (actions/install mixin)', function () {
168171
this.dummy.yarnInstall('yo', {dev: true});
169172
this.dummy.run(function () {
170173
sinon.assert.calledOnce(this.spawnCommandStub);
171-
sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['add', 'yo', '--dev'], {dev: true});
174+
sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['add', 'yo', '--dev'], {});
172175
done();
173176
}.bind(this));
174177
});
@@ -195,7 +198,7 @@ describe('Base (actions/install mixin)', function () {
195198
});
196199

197200
it('execute a callback after installs', function (done) {
198-
this.dummy.installDependencies({ callback: done });
201+
this.dummy.installDependencies({callback: done});
199202
this.dummy.run();
200203
});
201204

0 commit comments

Comments
 (0)
Please sign in to comment.