Skip to content

Commit

Permalink
Merge pull request #1654 from bower/alexanderGugel-save-exact
Browse files Browse the repository at this point in the history
Add --save-exact flag
  • Loading branch information
sheerun committed Jan 11, 2015
2 parents 639f793 + 2f6d680 commit 9c9f3e7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ install.readOptions = function (argv) {
'force-latest': { type: Boolean, shorthand: 'F'},
'production': { type: Boolean, shorthand: 'p' },
'save': { type: Boolean, shorthand: 'S' },
'save-dev': { type: Boolean, shorthand: 'D' }
'save-dev': { type: Boolean, shorthand: 'D' },
'save-exact': { type: Boolean, shorthand: 'E' }
}, argv);

var packages = options.argv.remain.slice(1);
Expand Down
4 changes: 4 additions & 0 deletions lib/core/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Project.prototype.install = function (decEndpoints, options, config) {

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);
}
Expand Down
5 changes: 5 additions & 0 deletions templates/json/help-install.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"shorthand": "-D",
"flag": "--save-dev",
"description": "Save installed packages into the project's bower.json devDependencies"
},
{
"shorthand": "-E",
"flag": "--save-exact",
"description": "Configure installed packages with an exact version rather than semver"
}
]
}
72 changes: 68 additions & 4 deletions test/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ describe('bower install', function () {
var install = helpers.command('install', { cwd: tempDir.path });

it('correctly reads arguments', function() {
expect(install.readOptions(['jquery', 'angular', '-F', '-p', '-S', '-D']))
expect(install.readOptions(['jquery', 'angular', '-F', '-p', '-S', '-D', '-E']))
.to.eql([['jquery', 'angular'], {
forceLatest: true,
production: true,
save: true,
saveDev: true
saveDev: true,
saveExact: true
}]);
});

it('correctly reads long arguments', function() {
expect(install.readOptions([
'jquery', 'angular',
'--force-latest', '--production', '--save', '--save-dev'
'--force-latest', '--production', '--save', '--save-dev', '--save-exact'
])).to.eql([['jquery', 'angular'], {
forceLatest: true,
production: true,
save: true,
saveDev: true
saveDev: true,
saveExact: true
}]);
});

Expand All @@ -51,6 +53,68 @@ 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': {
version: '1.2.3'
}
});

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

return helpers.run(install, [
[package.path],
{ saveExact: true, save: true }
]).then(function() {
expect(tempDir.readJson('bower.json').dependencies.package).to.equal('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': {
version: '0.1.0'
}
});

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

return helpers.run(install, [
[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');
});
});

it('reads .bowerrc from cwd', function () {
package.prepare({ foo: 'bar' });

Expand Down

0 comments on commit 9c9f3e7

Please sign in to comment.