Skip to content

Commit 1f5f131

Browse files
author
Michael Smith
committed
fix: pass --global=false when preparing git dependencies
Signed-off-by: Michael Smith <owlstronaut@github.com>
1 parent 66e7ea7 commit 1f5f131

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎lib/fetcher.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class FetcherBase {
118118
// we need the actual things, not just the lockfile
119119
'--no-package-lock-only',
120120
'--no-dry-run',
121+
// override npm_config_global from the parent process: this inner
122+
// `npm install` is preparing deps inside a tmp git clone, and it
123+
// must reify into that clone's cwd, never the outer global prefix.
124+
'--global=false',
121125
]
122126
}
123127

‎tap-snapshots/test/fetcher.js.test.cjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Array [
4848
"--include=optional",
4949
"--no-package-lock-only",
5050
"--no-dry-run",
51+
"--global=false",
5152
]
5253
`
5354

@@ -66,6 +67,7 @@ Array [
6667
"--include=optional",
6768
"--no-package-lock-only",
6869
"--no-dry-run",
70+
"--global=false",
6971
]
7072
`
7173

‎test/git.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,14 @@ t.test('handle it when prepared git deps depend on each other', { skip: isWindow
770770
noPrepare: [g.resolved],
771771
cwd: cwdRegex,
772772
})
773+
// the inner `npm install` spawned by pacote to prepare a git clone
774+
// must always run with --global=false so it does not honor an
775+
// inherited npm_config_global=true and reify into the outer global
776+
// prefix.
777+
t.ok(
778+
log.argv.includes('--global=false'),
779+
'inner npm install is invoked with --global=false'
780+
)
773781
// our rudimentary package manager dumps the deps into the pkg root
774782
// but it doesn't get installed once the loop is detected.
775783
const base = basename(local)

0 commit comments

Comments
 (0)