Skip to content

Commit

Permalink
Fix --save-exact feature for github endpoints, fixes #1925
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Sep 24, 2015
1 parent 9c52ec2 commit 87a041a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
14 changes: 8 additions & 6 deletions lib/core/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,25 @@ Project.prototype.install = function (decEndpoints, options, config) {
})
.then(function (installed) {
// Handle save and saveDev options
if (that._options.save || that._options.saveDev) {
if (that._options.save || that._options.saveDev || that._options.saveExact) {
// Cycle through the specified endpoints
decEndpoints.forEach(function (decEndpoint) {
var jsonEndpoint;

jsonEndpoint = endpointParser.decomposed2json(decEndpoint);

if (that._options.saveExact) {
jsonEndpoint[decEndpoint.name] = decEndpoint.pkgMeta.version;
}

if (that._options.save) {
that._json.dependencies = mout.object.mixIn(that._json.dependencies || {}, jsonEndpoint);
if (decEndpoint.name !== decEndpoint.source) {
jsonEndpoint[decEndpoint.name] = decEndpoint.source + '#' + decEndpoint.pkgMeta.version;
} else {
jsonEndpoint[decEndpoint.name] = decEndpoint.pkgMeta.version;
}
}

if (that._options.saveDev) {
that._json.devDependencies = mout.object.mixIn(that._json.devDependencies || {}, jsonEndpoint);
} else {
that._json.dependencies = mout.object.mixIn(that._json.dependencies || {}, jsonEndpoint);
}
});
}
Expand Down
26 changes: 4 additions & 22 deletions test/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('bower install', function () {
it('writes an exact version number to dependencies in bower.json if --save --save-exact flags are used', function () {
package.prepare({
'bower.json': {
name: 'package',
version: '1.2.3'
}
});
Expand All @@ -70,13 +71,14 @@ describe('bower install', function () {
[package.path],
{ saveExact: true, save: true }
]).then(function() {
expect(tempDir.readJson('bower.json').dependencies.package).to.equal('1.2.3');
expect(tempDir.readJson('bower.json').dependencies.package).to.equal(package.path + '#1.2.3');
});
});

it('writes an exact version number to devDependencies in bower.json if --save-dev --save-exact flags are used', function () {
package.prepare({
'bower.json': {
name: 'package',
version: '0.1.0'
}
});
Expand All @@ -91,27 +93,7 @@ describe('bower install', function () {
[package.path],
{ saveExact: true, saveDev: true }
]).then(function() {
expect(tempDir.readJson('bower.json').devDependencies.package).to.equal('0.1.0');
});
});


it('does not write to bower.json if only --save-exact flag is used', function() {
package.prepare({
'bower.json': {
version: '1.2.3'
}
});

tempDir.prepare({
'bower.json': {
name: 'test'
}
});

return helpers.run(install, [[package.path], { saveExact: true }]).then(function() {
expect(tempDir.read('bower.json')).to.not.contain('dependencies');
expect(tempDir.read('bower.json')).to.not.contain('devDependencies');
expect(tempDir.readJson('bower.json').devDependencies.package).to.equal(package.path + '#0.1.0');
});
});

Expand Down

0 comments on commit 87a041a

Please sign in to comment.