Skip to content

Commit f00ebce

Browse files
committed
Make spawn use consistent
1 parent 9871ccc commit f00ebce

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/shadow/npm/bin.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import process from 'node:process'
22

3+
import { isDebug } from '@socketsecurity/registry/lib/debug'
34
import {
45
isLoglevelFlag,
56
isProgressFlag
@@ -21,11 +22,14 @@ export default async function shadowBin(
2122
level = 1
2223
) {
2324
process.exitCode = 1
25+
const useDebug = isDebug()
2426
const terminatorPos = args.indexOf('--')
2527
const binArgs = (
2628
terminatorPos === -1 ? args : args.slice(0, terminatorPos)
2729
).filter(a => !isProgressFlag(a))
2830
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)
31+
const isSilent = !useDebug && !binArgs.some(isLoglevelFlag)
32+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : []
2933
const spawnPromise = spawn(
3034
// Lazily access constants.execPath.
3135
constants.execPath,
@@ -49,8 +53,9 @@ export default async function shadowBin(
4953
await installLinks(constants.shadowBinPath, binName),
5054
// Add `--no-progress` to fix input being swallowed by the npm spinner.
5155
'--no-progress',
52-
// Add the '--loglevel=silent' flag if a loglevel flag is not provided.
53-
...(binArgs.some(isLoglevelFlag) ? [] : ['--loglevel', 'silent']),
56+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
57+
// SOCKET_CLI_DEBUG environment variable is not truthy.
58+
...logLevelArgs,
5459
...binArgs,
5560
...otherArgs
5661
],

src/utils/npm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export function safeNpmInstall(options?: SafeNpmInstallOptions) {
3737
const useIpc = isObject(ipc)
3838
const useDebug = isDebug()
3939
const terminatorPos = args.indexOf('--')
40-
const npmArgs = (
40+
const binArgs = (
4141
terminatorPos === -1 ? args : args.slice(0, terminatorPos)
4242
).filter(a => !isAuditFlag(a) && !isFundFlag(a) && !isProgressFlag(a))
4343
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)
44-
const isSilent = !useDebug && !npmArgs.some(isLoglevelFlag)
44+
const isSilent = !useDebug && !binArgs.some(isLoglevelFlag)
4545
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : []
4646
const spawnPromise = spawn(
4747
// Lazily access constants.execPath.
@@ -72,7 +72,7 @@ export function safeNpmInstall(options?: SafeNpmInstallOptions) {
7272
// Add '--loglevel=silent' if a loglevel flag is not provided and the
7373
// SOCKET_CLI_DEBUG environment variable is not truthy.
7474
...logLevelArgs,
75-
...npmArgs,
75+
...binArgs,
7676
...otherArgs
7777
],
7878
{

0 commit comments

Comments
 (0)