Skip to content

Commit

Permalink
Merge pull request #2161 from blcook223/feature/save-bowerrc-config
Browse files Browse the repository at this point in the history
add support for save and save-exact in .bowerrc
  • Loading branch information
sheerun committed Jan 29, 2016
2 parents 6c67d07 + 394dd7c commit 96d986f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/core/Project.js
Expand Up @@ -82,14 +82,14 @@ Project.prototype.install = function (decEndpoints, options, config) {
})
.then(function (installed) {
// Handle save and saveDev options
if (that._options.save || that._options.saveDev || that._options.saveExact) {
if (that._options.save || that._options.saveDev || that._options.saveExact || that._config.save || that._config.saveExact) {
// Cycle through the specified endpoints
decEndpoints.forEach(function (decEndpoint) {
var jsonEndpoint;

jsonEndpoint = endpointParser.decomposed2json(decEndpoint);

if (that._options.saveExact) {
if (that._options.saveExact || that._config.saveExact) {
if (decEndpoint.name !== decEndpoint.source) {
jsonEndpoint[decEndpoint.name] = decEndpoint.source + '#' + decEndpoint.pkgMeta.version;
} else {
Expand Down Expand Up @@ -741,7 +741,7 @@ Project.prototype._removePackages = function (packages) {
}

// Remove from json only if successfully deleted
if (that._options.save && that._json.dependencies) {
if ((that._options.save || that._config.save) && that._json.dependencies) {
promise = promise
.then(function () {
delete that._json.dependencies[name];
Expand Down
67 changes: 67 additions & 0 deletions test/commands/install.js
Expand Up @@ -85,6 +85,24 @@ describe('bower install', function() {
});
});

it('writes to bower.json if save config setting is set to true', function() {
mainPackage.prepare();

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

return helpers.run(install, [
[mainPackage.path], {}, {
save: true
}
]).then(function() {
expect(tempDir.read('bower.json')).to.contain('dependencies');
});
});

it('writes an exact version number to dependencies in bower.json if --save --save-exact flags are used', function() {
mainPackage.prepare({
'bower.json': {
Expand All @@ -109,6 +127,30 @@ describe('bower install', function() {
});
});

it('writes an exact version number to dependencies in bower.json if save and save-exact config settings are set to true', function() {
mainPackage.prepare({
'bower.json': {
name: 'package',
version: '1.2.3'
}
});

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

return helpers.run(install, [
[mainPackage.path], {}, {
saveExact: true,
save: true
}
]).then(function() {
expect(tempDir.readJson('bower.json').dependencies.package).to.equal(mainPackage.path + '#1.2.3');
});
});

it('writes an exact version number to devDependencies in bower.json if --save-dev --save-exact flags are used', function() {
mainPackage.prepare({
'bower.json': {
Expand All @@ -133,6 +175,31 @@ describe('bower install', function() {
});
});

it('writes an exact version number to devDependencies in bower.json if save-exact config setting is true and --save-dev flag is used', function() {
mainPackage.prepare({
'bower.json': {
name: 'package',
version: '0.1.0'
}
});

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

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

it('reads .bowerrc from cwd', function() {
mainPackage.prepare({
foo: 'bar'
Expand Down
11 changes: 11 additions & 0 deletions test/commands/uninstall.js
Expand Up @@ -54,6 +54,17 @@ describe('bower uninstall', function () {
});
});

it('removes dependency from bower.json if save config setting is true', function () {
var configWithSave = {
cwd: tempDir.path,
interactive: true,
save: true
};
return helpers.run(uninstall, [['underscore'], {}, configWithSave]).then(function () {
expect(bowerJson().dependencies).to.eql({});
});
});

it('removes dependency from relative config.directory', function () {
var targetPath = path.resolve(tempDir.path, 'other_directory/underscore');
mkdirp.sync(targetPath);
Expand Down

0 comments on commit 96d986f

Please sign in to comment.