Skip to content

Commit bddb942

Browse files
committedNov 26, 2016
Fix yarnInstall to add new package - Fix #980
1 parent cd5e34d commit bddb942

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎lib/actions/install.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ install.runInstall = function (installer, paths, options, cb) {
3535

3636
var args = ['install'].concat(paths).concat(dargs(options));
3737

38+
// Yarn uses the `add` command to specifically add a package to a project.
39+
if (installer === 'yarn' && paths.length > 0) {
40+
args[0] = 'add';
41+
}
42+
3843
// only for npm, use a minimum cache of one day
3944
if (installer === 'npm') {
4045
args = args.concat(['--cache-min', 24 * 60 * 60]);
@@ -49,7 +54,7 @@ install.runInstall = function (installer, paths, options, cb) {
4954
this.env.runLoop.add('install', function (done) {
5055
this.emit(installer + 'Install', paths);
5156
this.spawnCommand(installer, args, options)
52-
.on('error', function (err){
57+
.on('error', function (err) {
5358
console.log(chalk.red('Could not finish installation. \n') +
5459
'Please install ' + installer + ' with ' +
5560
chalk.yellow('npm install -g ' + installer) + ' and try again.'

‎test/install.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,18 @@ describe('Base (actions/install mixin)', function () {
164164
});
165165

166166
it('run without callback', function (done) {
167-
this.dummy.yarnInstall('yo', { save: true });
167+
this.dummy.yarnInstall('yo', {dev: true});
168168
this.dummy.run(function () {
169169
sinon.assert.calledOnce(this.spawnCommandStub);
170+
sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['add', 'yo', '--dev'], {dev: true});
170171
done();
171172
}.bind(this));
172173
});
173174

174175
it('run with callback', function (done) {
175-
this.dummy.yarnInstall('yo', { save: true }, function () {
176+
this.dummy.yarnInstall('yo', function () {
176177
sinon.assert.calledOnce(this.spawnCommandStub);
178+
sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['add', 'yo'], {});
177179
done();
178180
}.bind(this));
179181
this.dummy.run();

0 commit comments

Comments
 (0)
Please sign in to comment.