Skip to content

Commit

Permalink
Implement postuninstall hooks with tests (#2252)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpunkfu authored and sheerun committed Apr 14, 2016
1 parent e729829 commit 343e6ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/core/Project.js
Expand Up @@ -764,6 +764,9 @@ Project.prototype._removePackages = function (packages) {
.then(function () {
return that.saveJson();
})
// Run post-uninstall hook before resolving with removed packages.
.then(scripts.postuninstall.bind(
null, that._config, that._logger, packages, that._installed, that._json))
// Resolve with removed packages
.then(function () {
return mout.object.filter(packages, function (dir) {
Expand Down
1 change: 1 addition & 0 deletions lib/core/scripts.js
Expand Up @@ -89,6 +89,7 @@ var hook = function (action, ordered, config, logger, packages, installed, json)

module.exports = {
preuninstall: mout.function.partial(hook, 'preuninstall', false),
postuninstall: mout.function.partial(hook, 'postuninstall', false),
preinstall: mout.function.partial(hook, 'preinstall', true),
postinstall: mout.function.partial(hook, 'postinstall', true),
//only exposed for test
Expand Down
16 changes: 15 additions & 1 deletion test/core/scripts.js
Expand Up @@ -27,7 +27,8 @@ describe('scripts', function () {
scripts: {
preinstall: touch('preinstall_%_%'),
postinstall: touch('postinstall_%_%'),
preuninstall: touch('preuninstall_%_%')
preuninstall: touch('preuninstall_%_%'),
postuninstall: touch('postuninstall_%_%')
}
};

Expand Down Expand Up @@ -66,6 +67,19 @@ describe('scripts', function () {

});

it('should run postuninstall hook.', function (next) {

bower.commands
.uninstall([packageName], undefined, config)
.on('end', function (installed) {

expect(fs.existsSync(path.join(tempDir, 'postuninstall_' + packageName + '_' + packageName))).to.be(true);

next();
});

});

it('should not break anything when no hooks configured.', function (next) {

bower.commands
Expand Down

0 comments on commit 343e6ac

Please sign in to comment.