From b72f9bfdee0e23bb6289ed804eb1c229dabb4239 Mon Sep 17 00:00:00 2001 From: "Oskar Cieslik (rpawfuiml)" Date: Wed, 13 Apr 2016 21:54:35 +0200 Subject: [PATCH 1/2] Implement postuninstall hooks with tests --- lib/core/Project.js | 3 +++ lib/core/scripts.js | 1 + test/core/scripts.js | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/core/Project.js b/lib/core/Project.js index 50bdee4d7..2c4f34101 100644 --- a/lib/core/Project.js +++ b/lib/core/Project.js @@ -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) { diff --git a/lib/core/scripts.js b/lib/core/scripts.js index 15b9b6473..d0e7d42a0 100644 --- a/lib/core/scripts.js +++ b/lib/core/scripts.js @@ -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 diff --git a/test/core/scripts.js b/test/core/scripts.js index 2f191ccfa..705126715 100644 --- a/test/core/scripts.js +++ b/test/core/scripts.js @@ -27,7 +27,8 @@ describe('scripts', function () { scripts: { preinstall: touch('preinstall_%_%'), postinstall: touch('postinstall_%_%'), - preuninstall: touch('preuninstall_%_%') + preuninstall: touch('preuninstall_%_%'), + postuninstall: touch('postuninstall_%_%') } }; @@ -53,13 +54,14 @@ describe('scripts', function () { }); - it('should run preuninstall hook.', function (next) { + it('should run preuninstall and postuninstall hooks.', function (next) { bower.commands .uninstall([packageName], undefined, config) .on('end', function (installed) { expect(fs.existsSync(path.join(tempDir, 'preuninstall_' + packageName + '_' + packageName))).to.be(true); + expect(fs.existsSync(path.join(tempDir, 'postuninstall_' + packageName + '_' + packageName))).to.be(true); next(); }); From 92f23db331e56ff770a19d2146fe24d585c69c79 Mon Sep 17 00:00:00 2001 From: Oskar Cieslik Date: Thu, 14 Apr 2016 13:41:46 +0200 Subject: [PATCH 2/2] Separate tests for pre & post uninstall hooks --- test/core/scripts.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/core/scripts.js b/test/core/scripts.js index 705126715..1e152f233 100644 --- a/test/core/scripts.js +++ b/test/core/scripts.js @@ -54,13 +54,25 @@ describe('scripts', function () { }); - it('should run preuninstall and postuninstall hooks.', function (next) { + it('should run preuninstall hook.', function (next) { bower.commands .uninstall([packageName], undefined, config) .on('end', function (installed) { expect(fs.existsSync(path.join(tempDir, 'preuninstall_' + packageName + '_' + packageName))).to.be(true); + + next(); + }); + + }); + + 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();