Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2022-08-01 21:20:50 +0300
committerGitHub <noreply@github.com>2022-08-01 21:20:50 +0300
commit050284d2abb6aa91a0f9ffad5b0c4f074e5dbf6d (patch)
treee2c44a8a4c15216016b080bcaa88e85da5b20256 /workspaces/arborist/lib
parent47cc95d9ffb37fc8ff62a1d5554eab16d303aa43 (diff)
fix(arborist): pass the edge to fromPath in order to determine correct path (#5233)
by passing in the edge we can determine if the edge is overridden, and if it is the path we want to return is the project root since that's what user's will have define their overrides relative to
Diffstat (limited to 'workspaces/arborist/lib')
-rw-r--r--workspaces/arborist/lib/arborist/build-ideal-tree.js3
-rw-r--r--workspaces/arborist/lib/dep-valid.js2
-rw-r--r--workspaces/arborist/lib/from-path.js19
3 files changed, 17 insertions, 7 deletions
diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js
index 0e98ed6fc..945bae56b 100644
--- a/workspaces/arborist/lib/arborist/build-ideal-tree.js
+++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js
@@ -1076,9 +1076,8 @@ This is a one-time fix-up, please be patient...
// if it fails at this point, though, dont' worry because it
// may well be an optional dep that has gone missing. it'll
// fail later anyway.
- const from = fromPath(placed)
promises.push(...this[_problemEdges](placed).map(e =>
- this[_fetchManifest](npa.resolve(e.name, e.spec, from))
+ this[_fetchManifest](npa.resolve(e.name, e.spec, fromPath(placed, e)))
.catch(er => null)))
},
})
diff --git a/workspaces/arborist/lib/dep-valid.js b/workspaces/arborist/lib/dep-valid.js
index c69ab557a..d02f397fc 100644
--- a/workspaces/arborist/lib/dep-valid.js
+++ b/workspaces/arborist/lib/dep-valid.js
@@ -20,7 +20,7 @@ const depValid = (child, requested, requestor) => {
// file: deps that depend on other files/dirs, we must resolve the
// location based on the *requestor* file/dir, not where it ends up.
// '' is equivalent to '*'
- requested = npa.resolve(child.name, requested || '*', fromPath(requestor))
+ requested = npa.resolve(child.name, requested || '*', fromPath(requestor, requestor.edgesOut.get(child.name)))
} catch (er) {
// Not invalid because the child doesn't match, but because
// the spec itself is not supported. Nothing would match,
diff --git a/workspaces/arborist/lib/from-path.js b/workspaces/arborist/lib/from-path.js
index 2a3617844..1006f73af 100644
--- a/workspaces/arborist/lib/from-path.js
+++ b/workspaces/arborist/lib/from-path.js
@@ -6,8 +6,19 @@
const { dirname } = require('path')
const npa = require('npm-package-arg')
-const fromPath = (node, spec) =>
- spec && spec.type === 'file' ? dirname(spec.fetchSpec)
- : node.realpath
+const fromPath = (node, spec, edge) => {
+ if (edge && edge.overrides && edge.overrides.name === edge.name && edge.overrides.value) {
+ // fromPath could be called with a node that has a virtual root, if that happens
+ // we want to make sure we get the real root node when overrides are in use. this
+ // is to allow things like overriding a dependency with a tarball file that's a
+ // relative path from the project root
+ return node.sourceReference
+ ? node.sourceReference.root.realpath
+ : node.root.realpath
+ }
-module.exports = node => fromPath(node, node.resolved && npa(node.resolved))
+ return spec && spec.type === 'file' ? dirname(spec.fetchSpec)
+ : node.realpath
+}
+
+module.exports = (node, edge) => fromPath(node, node.resolved && npa(node.resolved), edge)