diff options
-rw-r--r-- | lib/install.js | 12 | ||||
-rw-r--r-- | lib/install/deps.js | 13 | ||||
-rw-r--r-- | lib/install/is-extraneous.js | 10 | ||||
-rw-r--r-- | lib/uninstall.js | 4 | ||||
-rw-r--r-- | test/tap/uninstall-link-clean.js | 14 |
5 files changed, 28 insertions, 25 deletions
diff --git a/lib/install.js b/lib/install.js index 80ffb0aa8..3a1dc5b98 100644 --- a/lib/install.js +++ b/lib/install.js @@ -139,6 +139,7 @@ var doParallelActions = require('./install/actions.js').doParallel var doOneAction = require('./install/actions.js').doOne var removeObsoleteDep = require('./install/deps.js').removeObsoleteDep var removeExtraneous = require('./install/deps.js').removeExtraneous +var computeVersionSpec = require('./install/deps.js').computeVersionSpec var packageId = require('./utils/package-id.js') var moduleName = require('./utils/module-name.js') var errorMessage = require('./utils/error-message.js') @@ -249,8 +250,7 @@ Installer.prototype.run = function (_cb) { if (!this.dryrun) { installSteps.push( [this.newTracker(log, 'runTopLevelLifecycles', 2)], - [this, this.runPreinstallTopLevelLifecycles] - ) + [this, this.runPreinstallTopLevelLifecycles]) } installSteps.push( [this.newTracker(log, 'loadCurrentTree', 4)], @@ -358,6 +358,14 @@ var flatNameFromTree = require('./install/flatten-tree.js').flatNameFromTree Installer.prototype.normalizeCurrentTree = function (cb) { this.currentTree.isTop = true normalizeTree(this.currentTree) + // If the user didn't have a package.json then fill in deps with what was on disk + if (this.currentTree.error) { + for (let child of this.currentTree.children) { + if (!child.fakeChild && isExtraneous(child)) { + this.currentTree.package.dependencies[child.package.name] = computeVersionSpec(this.currentTree, child) + } + } + } return cb() function normalizeTree (tree) { diff --git a/lib/install/deps.js b/lib/install/deps.js index 368e25030..cc6420ee0 100644 --- a/lib/install/deps.js +++ b/lib/install/deps.js @@ -258,9 +258,17 @@ exports.loadRequestedDeps = function (args, tree, saveToDependencies, log, next) }, andForEachChild(loadDeps, andFinishTracker(log, next))) } +module.exports.computeVersionSpec = computeVersionSpec function computeVersionSpec (tree, child) { validate('OO', arguments) - var requested = child.package._requested + var requested + if (child.package._requested) { + requested = child.package._requested + } else if (child.package._from) { + requested = npa(child.package._from) + } else { + requested = npa.resolve(child.package.name, child.package.version) + } if (requested.registry) { var version = child.package.version var rangeDescriptor = '' @@ -310,6 +318,9 @@ exports.removeDeps = function (args, tree, saveToDependencies, next) { replaceModuleByPath(tree, 'removedChildren', pkgToRemove) } } + for (let parent of pkgToRemove.requiredBy) { + parent.requires = parent.requires.filter((child) => child !== pkgToRemove) + } pkgToRemove.requiredBy = pkgToRemove.requiredBy.filter((parent) => parent !== tree) } next() diff --git a/lib/install/is-extraneous.js b/lib/install/is-extraneous.js index f0d599965..a6477c237 100644 --- a/lib/install/is-extraneous.js +++ b/lib/install/is-extraneous.js @@ -6,14 +6,6 @@ function isExtraneous (tree) { return result } -function isNotRequired (tree) { - return tree.requiredBy && tree.requiredBy.length === 0 -} - -function parentHasNoPjson (tree) { - return tree.parent && tree.parent.isTop && tree.parent.error -} - function topHasNoPjson (tree) { var top = tree while (!top.isTop) top = top.parent @@ -24,8 +16,6 @@ function isNotExtraneous (tree, isCycle) { if (!isCycle) isCycle = {} if (tree.isTop || tree.userRequired) { return true - } else if (isNotRequired(tree) && parentHasNoPjson(tree)) { - return true } else if (isCycle[tree.path]) { return topHasNoPjson(tree) } else { diff --git a/lib/uninstall.js b/lib/uninstall.js index 29a32b393..473b47acc 100644 --- a/lib/uninstall.js +++ b/lib/uninstall.js @@ -66,9 +66,7 @@ class Uninstaller extends Installer { const saveDeps = getSaveType() super.loadAllDepsIntoIdealTree(iferr(cb, () => { - removeDeps(this.remove, this.idealTree, saveDeps, (err) => { - cb(err) - }) + removeDeps(this.remove, this.idealTree, saveDeps, cb) })) } diff --git a/test/tap/uninstall-link-clean.js b/test/tap/uninstall-link-clean.js index b4759e889..2b1d244d0 100644 --- a/test/tap/uninstall-link-clean.js +++ b/test/tap/uninstall-link-clean.js @@ -3,15 +3,15 @@ var path = require('path') var existsSync = fs.existsSync || path.existsSync var mkdirp = require('mkdirp') -var osenv = require('osenv') var rimraf = require('rimraf') var test = require('tap').test var common = require('../common-tap.js') -var pkg = path.join(__dirname, 'uninstall-link-clean') -var dep = path.join(__dirname, 'dep') -var work = path.join(__dirname, 'uninstall-link-clean-TEST') +var testdir = path.join(__dirname, path.basename(__filename, '.js')) +var pkg = path.join(testdir, 'pkg') +var dep = path.join(testdir, 'dep') +var work = path.join(testdir, 'uninstall-link-clean-TEST') var modules = path.join(work, 'node_modules') var EXEC_OPTS = { cwd: work, stdio: [0, 'ignore', 2] } @@ -54,7 +54,6 @@ test('setup', function (t) { fs.writeFileSync(path.join(dep, 'world.js'), world) mkdirp.sync(modules) - process.chdir(work) t.end() }) @@ -110,8 +109,5 @@ test('cleanup', function (t) { }) function cleanup () { - process.chdir(osenv.tmpdir()) - rimraf.sync(dep) - rimraf.sync(work) - rimraf.sync(pkg) + rimraf.sync(testdir) } |