diff options
author | Gar <gar+gh@danger.computer> | 2022-08-10 19:34:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-10 19:34:24 +0300 |
commit | daaf4619c85ecf62346770735cfa8e2ddecbef8b (patch) | |
tree | b565e27bc860abfe49a6de404e72d226d81ca5fd /lib | |
parent | a4808fbd5601df10f6bdf20029cdbf1f06966c98 (diff) |
fix: ignore global prefix if --prefix is used (#5291)
When `--prefix` is used, both the local and global prefix values are set
to be identical. This is functionally broken because their directory
structures are inherently different (for instance, in posix the tree is
in `lib/node_modules` in the global prefix).
This commit makes npm exec ignore the global folders if it detects both
local and global prefix are identical.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/commands/exec.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/commands/exec.js b/lib/commands/exec.js index ddbb5f7cf..a77a6326c 100644 --- a/lib/commands/exec.js +++ b/lib/commands/exec.js @@ -34,6 +34,7 @@ class Exec extends BaseCommand { const args = [..._args] const call = this.npm.config.get('call') + let globalPath const { flatOptions, localBin, @@ -44,6 +45,12 @@ class Exec extends BaseCommand { const scriptShell = this.npm.config.get('script-shell') || undefined const packages = this.npm.config.get('package') const yes = this.npm.config.get('yes') + // --prefix sets both of these to the same thing, meaning the global prefix + // is invalid (i.e. no lib/node_modules). This is not a trivial thing to + // untangle and fix so we work around it here. + if (this.npm.localPrefix !== this.npm.globalPrefix) { + globalPath = path.resolve(globalDir, '..') + } if (call && _args.length) { throw this.usageError() @@ -59,7 +66,7 @@ class Exec extends BaseCommand { localBin, locationMsg, globalBin, - globalPath: path.resolve(globalDir, '..'), + globalPath, output, packages, path: localPrefix, |