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
path: root/lib
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-08-10 19:34:24 +0300
committerGitHub <noreply@github.com>2022-08-10 19:34:24 +0300
commitdaaf4619c85ecf62346770735cfa8e2ddecbef8b (patch)
treeb565e27bc860abfe49a6de404e72d226d81ca5fd /lib
parenta4808fbd5601df10f6bdf20029cdbf1f06966c98 (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.js9
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,