Skip to content

Commit d7ede9b

Browse files
authored
Don't use permission flag on npx (#549)
1 parent 0c12d71 commit d7ede9b

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

src/shadow/npm/bin.mts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,32 @@ export default async function shadowBin(
2828
const nodeOptionsArg = rawBinArgs.findLast(isNodeOptionsFlag)
2929
const progressArg = rawBinArgs.findLast(isProgressFlag) !== '--no-progress'
3030
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)
31-
// Lazily access constants.SUPPORTS_NODE_PERMISSION_FLAG.
32-
const permArgs = constants.SUPPORTS_NODE_PERMISSION_FLAG
33-
? await (async () => {
34-
const cwd = process.cwd()
35-
const globalPrefix = (
36-
await spawn('npm', ['prefix', '-g'], { cwd })
37-
).stdout.trim()
38-
const npmCachePath = (
39-
await spawn('npm', ['config', 'get', 'cache'], { cwd })
40-
).stdout.trim()
41-
return [
42-
'--permission',
43-
// '--allow-child-process',
44-
// '--allow-addons',
45-
// '--allow-wasi',
46-
// Allow all reads because npm walks up directories looking for config
47-
// and package.json files.
48-
'--allow-fs-read=*',
49-
`--allow-fs-write=${cwd}/*`,
50-
`--allow-fs-write=${globalPrefix}/*`,
51-
`--allow-fs-write=${npmCachePath}/*`
52-
]
53-
})()
54-
: []
31+
const permArgs =
32+
binName === 'npx' &&
33+
// Lazily access constants.SUPPORTS_NODE_PERMISSION_FLAG.
34+
constants.SUPPORTS_NODE_PERMISSION_FLAG
35+
? await (async () => {
36+
const cwd = process.cwd()
37+
const globalPrefix = (
38+
await spawn('npm', ['prefix', '-g'], { cwd })
39+
).stdout.trim()
40+
const npmCachePath = (
41+
await spawn('npm', ['config', 'get', 'cache'], { cwd })
42+
).stdout.trim()
43+
return [
44+
'--permission',
45+
'--allow-child-process',
46+
// '--allow-addons',
47+
// '--allow-wasi',
48+
// Allow all reads because npm walks up directories looking for config
49+
// and package.json files.
50+
'--allow-fs-read=*',
51+
`--allow-fs-write=${cwd}/*`,
52+
`--allow-fs-write=${globalPrefix}/*`,
53+
`--allow-fs-write=${npmCachePath}/*`
54+
]
55+
})()
56+
: []
5557
const useDebug = isDebug()
5658
const useNodeOptions = nodeOptionsArg || permArgs.length
5759
const isSilent = !useDebug && !binArgs.some(isLoglevelFlag)

0 commit comments

Comments
 (0)