Skip to content

Commit 2555197

Browse files
committed
Don't alert on CLI upgrade
1 parent f423de3 commit 2555197

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/shadow/arborist/lib/arborist/index.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import type { ArboristClass, ArboristReifyOptions } from './types'
88
import type { SafeNode } from '../node'
99

1010
const {
11+
SOCKET_CLI_LEGACY_PACKAGE_NAME,
12+
SOCKET_CLI_PACKAGE_NAME,
13+
SOCKET_CLI_SENTRY_PACKAGE_NAME,
1114
SOCKET_CLI_SAFE_WRAPPER,
1215
kInternalsSymbol,
1316
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: { getIPC }
@@ -78,16 +81,30 @@ export class SafeArborist extends Arborist {
7881
__proto__: null,
7982
...(args.length ? args[0] : undefined)
8083
}
84+
const { add } = options
85+
const skipSocketCliUpgrade =
86+
options.global &&
87+
options['npmCommand'] === 'install' &&
88+
Array.isArray(add) &&
89+
add.length === 1 &&
90+
(add[0] === SOCKET_CLI_PACKAGE_NAME ||
91+
add[0] === SOCKET_CLI_LEGACY_PACKAGE_NAME ||
92+
add[0] === SOCKET_CLI_SENTRY_PACKAGE_NAME)
93+
94+
if (
95+
options.dryRun ||
96+
skipSocketCliUpgrade ||
97+
!(await getIPC(SOCKET_CLI_SAFE_WRAPPER))
98+
) {
99+
return await this[kRiskyReify](...args)
100+
}
81101
const safeArgs = [
82102
{
83103
...options,
84104
progress: false
85105
},
86106
...args.slice(1)
87107
]
88-
if (options.dryRun || !(await getIPC(SOCKET_CLI_SAFE_WRAPPER))) {
89-
return await this[kRiskyReify](...safeArgs)
90-
}
91108
Object.assign(options, SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES)
92109
const old = args[0]
93110
args[0] = options

src/shadow/shadow-bin.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import { installLinks } from './link'
1010
import constants from '../constants'
1111

1212
const {
13+
NPM,
14+
SOCKET_CLI_LEGACY_PACKAGE_NAME,
15+
SOCKET_CLI_PACKAGE_NAME,
1316
SOCKET_CLI_SAFE_WRAPPER,
1417
SOCKET_CLI_SENTRY_BUILD,
18+
SOCKET_CLI_SENTRY_PACKAGE_NAME,
1519
SOCKET_IPC_HANDSHAKE
1620
} = constants
1721

@@ -21,9 +25,18 @@ export default async function shadowBin(
2125
) {
2226
process.exitCode = 1
2327
const terminatorPos = args.indexOf('--')
24-
const binArgs = (
25-
terminatorPos === -1 ? args : args.slice(0, terminatorPos)
26-
).filter(a => !isProgressFlag(a))
28+
const skipSocketCliUpgrade = binName === NPM
29+
args.length === 3 &&
30+
args[0] === 'install' &&
31+
args[1] === '-g' &&
32+
(args[2] === SOCKET_CLI_PACKAGE_NAME ||
33+
args[2] === SOCKET_CLI_LEGACY_PACKAGE_NAME ||
34+
args[2] === SOCKET_CLI_SENTRY_PACKAGE_NAME)
35+
36+
let binArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos)
37+
if (!skipSocketCliUpgrade) {
38+
binArgs = binArgs.filter(a => !isProgressFlag(a))
39+
}
2740
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)
2841
const spawnPromise = spawn(
2942
// Lazily access constants.execPath.
@@ -46,9 +59,13 @@ export default async function shadowBin(
4659
await installLinks(constants.shadowBinPath, binName),
4760
// Add `--no-progress` and `--quiet` flags to fix input being swallowed by
4861
// the spinner when running the command with recent versions of npm.
49-
'--no-progress',
62+
...(skipSocketCliUpgrade ? [] : ['--no-progress']),
5063
// Add the '--quiet' flag if a loglevel flag is not provided.
51-
...(binArgs.some(isLoglevelFlag) ? [] : ['--quiet']),
64+
...(binArgs.some(isLoglevelFlag)
65+
? []
66+
: skipSocketCliUpgrade
67+
? ['--loglevel', 'error']
68+
: ['--quiet']),
5269
...binArgs,
5370
...otherArgs
5471
],

0 commit comments

Comments
 (0)