Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
uninstall: Fix uninstall lifecycle order
Browse files Browse the repository at this point in the history
Fixes: #8806
PR-URL: #8859
  • Loading branch information
iarna committed Jul 10, 2015
1 parent 075a5f0 commit 32e6bbd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ var validateTree = require('./install/validate-tree.js')
var saveRequested = require('./install/save.js').saveRequested
var getSaveType = require('./install/save.js').getSaveType
var doSerialActions = require('./install/actions.js').doSerial
var doReverseSerialActions = require('./install/actions.js').doReverseSerial
var doParallelActions = require('./install/actions.js').doParallel
var doOneAction = require('./install/actions.js').doOne
var getPackageId = require('./install/get-package-id.js')
Expand Down Expand Up @@ -450,7 +451,7 @@ Installer.prototype.executeActions = function (cb) {
[mkdirp, staging],
[doParallelActions, 'extract', staging, todo, cg.newGroup('extract', 10)],
[doParallelActions, 'preinstall', staging, todo, trackLifecycle.newGroup('preinstall')],
[doSerialActions, 'remove', staging, todo, cg.newGroup('remove')],
[doReverseSerialActions, 'remove', staging, todo, cg.newGroup('remove')],
[doSerialActions, 'move', staging, todo, cg.newGroup('move')],
[doSerialActions, 'finalize', staging, todo, cg.newGroup('finalize')],
[doSerialActions, 'build', staging, todo, trackLifecycle.newGroup('build')],
Expand Down
9 changes: 9 additions & 0 deletions lib/install/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ exports.doSerial = function (type, staging, actionsToRun, log, next) {
chain(actionsToRun.map(prepareAction(staging, log)), andFinishTracker(log, next))
}

exports.doReverseSerial = function (type, staging, actionsToRun, log, next) {
validate('SSAOF', arguments)
actionsToRun = actionsToRun
.filter(function (value) { return value[0] === type })
.reverse()
log.silly('doReverseSerial', '%s %d', type, actionsToRun.length)
chain(actionsToRun.map(prepareAction(staging, log)), andFinishTracker(log, next))
}

exports.doParallel = function (type, staging, actionsToRun, log, next) {
validate('SSAOF', arguments)
actionsToRun = actionsToRun.filter(function (value) { return value[0] === type })
Expand Down
38 changes: 38 additions & 0 deletions test/tap/uninstall-in-reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'
var test = require('tap').test
var requireInject = require('require-inject')
var log = require('npmlog')

/*
The remove actions need to happen in the opposite of their normally defined
order. That is, they need to go shallow -> deep.
*/

var removed = []
var npm = requireInject.installGlobally('../../lib/npm.js', {
'../../lib/install/action/remove.js': function (top, buildpath, pkg, log, next) {
removed.push(pkg.package.name)
next()
}
})

test('setup', function (t) {
npm.load(function () {
t.pass('npm loaded')
t.end()
})
})

test('abc', function (t) {
var Installer = require('../../lib/install.js').Installer
var inst = new Installer(__dirname, false, [])
inst.progress = {executeActions: log}
inst.todo = [
['remove', {package: {name: 'first'}}],
['remove', {package: {name: 'second'}}]
]
inst.executeActions(function () {
t.isDeeply(removed, ['second', 'first'])
t.end()
})
})

0 comments on commit 32e6bbd

Please sign in to comment.