Skip to content

Commit

Permalink
Allow for removing components with url instead of name (#2368)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoezGholami authored and sheerun committed Nov 7, 2016
1 parent bdabf6a commit cba4b2a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/core/Project.js
Expand Up @@ -213,6 +213,20 @@ Project.prototype.update = function (names, options) {
});
};

function resolveUrlNames(names, flattened)
{
for (var i = 0; i < names.length; i++)
if (! flattened[names[i]])
{
var url = names[i].trim().replace(/\/$/, '');
var packName;
for (packName in flattened)
if (! ( !flattened[packName].source))
if (url == flattened[packName].source.trim().replace(/\/$/, ''))
names[i] = packName;
}
}

Project.prototype.uninstall = function (names, options) {
var that = this;
var packages = {};
Expand All @@ -230,6 +244,7 @@ Project.prototype.uninstall = function (names, options) {
// Fill in the packages to be uninstalled
.spread(function (json, tree, flattened) {
var promise = Q.resolve();
resolveUrlNames(names, flattened);

names.forEach(function (name) {
var decEndpoint = flattened[name];
Expand Down
17 changes: 17 additions & 0 deletions test/commands/uninstall.js
Expand Up @@ -99,4 +99,21 @@ describe('bower uninstall', function () {
});
});

it('removes a project with url from absolute path', function () {
var targetPath = path.resolve(tempDir.path, 'other_directory/underscore');
mkdirp.sync(targetPath);
fs.writeFileSync(path.join(targetPath, '.bower.json'), '{ "name": "underscore", "_source": "git://github.com/user/repo.git" }');

return helpers.run(uninstall, [['git://github.com/user/repo.git'], undefined, {
cwd: tempDir.path,
directory: path.resolve(tempDir.path, 'other_directory'),
interactive: true
}])
.then(function () {
expect(function () {
fs.statSync(targetPath);
}).to.throwException(/no such file or directory/);
});
});

});

0 comments on commit cba4b2a

Please sign in to comment.