Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for save and save-exact in .bowerrc #2161

Merged
merged 1 commit into from Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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