From ee97f8bad45cb1adfa71158cc54eeb5577041dc9 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 24 May 2017 18:04:04 -0700 Subject: install-deps: Match symlinked transitive deps correctly --- lib/install/deps.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/install/deps.js b/lib/install/deps.js index 4137a5993..368e25030 100644 --- a/lib/install/deps.js +++ b/lib/install/deps.js @@ -183,7 +183,9 @@ function packageRelativePath (tree) { if (!tree) return '' var requested = tree.package._requested || {} var isLocal = requested.type === 'directory' || requested.type === 'file' - return isLocal ? requested.fetchSpec : tree.path + return isLocal ? requested.fetchSpec + : (tree.isLink || tree.isInLink) && !preserveSymlinks() ? tree.realpath + : tree.path } function matchingDep (tree, name) { @@ -664,6 +666,13 @@ var findRequirement = exports.findRequirement = function (tree, name, requested, return findRequirement(tree.parent, name, requested, requestor) } +function preserveSymlinks () { + if (!('NODE_PRESERVE_SYMLINKS' in process.env)) return false + const value = process.env.NODE_PRESERVE_SYMLINKS + if (value == null || value === '' || value === 'false' || value === 'no' || value === '0') return false + return true +} + // Find the highest level in the tree that we can install this module in. // If the module isn't installed above us yet, that'd be the very top. // If it is, then it's the level below where its installed. @@ -695,7 +704,7 @@ var earliestInstallable = exports.earliestInstallable = function (requiredBy, tr var devDeps = tree.package.devDependencies || {} if (tree.isTop && devDeps[pkg.name]) { - var requested = npa.resolve(pkg.name, devDeps[pkg.name], tree.path) + var requested = childDependencySpecifier(tree, pkg.name, devDeps[pkg.name]) if (!doesChildVersionMatch({package: pkg}, requested, tree)) { return null } @@ -709,7 +718,7 @@ var earliestInstallable = exports.earliestInstallable = function (requiredBy, tr if (npm.config.get('global-style') && tree.parent.isTop) return tree if (npm.config.get('legacy-bundling')) return tree - if (!process.env.NODE_PRESERVE_SYMLINKS && /^[.][.][\\/]/.test(path.relative(tree.parent.realpath, tree.realpath))) return tree + if (!preserveSymlinks() && /^[.][.][\\/]/.test(path.relative(tree.parent.realpath, tree.realpath))) return tree return (earliestInstallable(requiredBy, tree.parent, pkg) || tree) } -- cgit v1.2.3