Skip to content

Commit fadb0c3

Browse files
committed
Defer IPC access
1 parent 4505032 commit fadb0c3

File tree

4 files changed

+119
-62
lines changed

4 files changed

+119
-62
lines changed

package-lock.json

Lines changed: 79 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@socketregistry/is-interactive": "^1.0.1",
6969
"@socketregistry/is-unicode-supported": "^1.0.0",
7070
"@socketsecurity/config": "^2.1.3",
71-
"@socketsecurity/registry": "^1.0.79",
71+
"@socketsecurity/registry": "^1.0.81",
7272
"@socketsecurity/sdk": "^1.4.5",
7373
"blessed": "^0.1.81",
7474
"blessed-contrib": "^4.11.0",

src/constants.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,50 @@ import process from 'node:process'
55
import registryConstants from '@socketsecurity/registry/lib/constants'
66
import { envAsBoolean } from '@socketsecurity/registry/lib/env'
77

8+
const {
9+
PACKAGE_JSON,
10+
kInternalsSymbol,
11+
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: {
12+
createConstantsObject
13+
}
14+
} = registryConstants
15+
816
type RegistryEnv = typeof registryConstants.ENV
917

10-
type IPCObject = {
18+
type RegistryInternals = (typeof registryConstants)['Symbol(kInternalsSymbol)']
19+
20+
type Internals = Omit<RegistryInternals, 'getIPC'> &
21+
Readonly<{
22+
getIPC: {
23+
(): Promise<IPC>
24+
<K extends keyof IPC | undefined>(
25+
key?: K
26+
): Promise<K extends keyof IPC ? IPC[K] : IPC>
27+
}
28+
}>
29+
30+
type ENV = RegistryEnv &
31+
Readonly<{
32+
SOCKET_CLI_DEBUG: boolean
33+
}>
34+
35+
type IPC = Readonly<{
1136
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE: boolean
1237
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
13-
[key: string]: any
14-
}
38+
}>
1539

16-
type Constants = {
40+
type Constants = Omit<
41+
typeof registryConstants,
42+
'Symbol(kInternalsSymbol)' | 'ENV' | 'IPC'
43+
> & {
44+
readonly 'Symbol(kInternalsSymbol)': Internals
1745
readonly API_V0_URL: 'https://api.socket.dev/v0'
1846
readonly BABEL_RUNTIME: '@babel/runtime'
1947
readonly BINARY_LOCK_EXT: '.lockb'
2048
readonly BUN: 'bun'
21-
readonly ENV: RegistryEnv & {
22-
SOCKET_CLI_DEBUG: boolean
23-
}
49+
readonly ENV: ENV
2450
readonly DIST_TYPE: 'module-sync' | 'require'
25-
readonly IPC: IPCObject
51+
readonly IPC: IPC
2652
readonly LOCK_EXT: '.lock'
2753
readonly MODULE_SYNC: 'module-sync'
2854
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org'
@@ -46,15 +72,7 @@ type Constants = {
4672
readonly rootPkgJsonPath: string
4773
readonly shadowBinPath: string
4874
readonly synpBinPath: string
49-
} & typeof registryConstants
50-
51-
const {
52-
PACKAGE_JSON,
53-
kInternalsSymbol,
54-
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: {
55-
createConstantsObject
56-
}
57-
} = registryConstants
75+
}
5876

5977
const API_V0_URL = 'https://api.socket.dev/v0'
6078
const BABEL_RUNTIME = '@babel/runtime'

src/shadow/arborist/lib/arborist/reify.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ const {
4848
NPM_REGISTRY_URL,
4949
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
5050
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
51-
abortSignal
51+
abortSignal,
52+
kInternalsSymbol,
53+
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: { getIPC }
5254
} = constants
5355

5456
const formatter = new ColorOrMarkdown(false)
@@ -369,11 +371,10 @@ export async function reify(
369371
// Nothing to check, hmmm already installed or all private?
370372
return await this[kRiskyReify](...args)
371373
}
372-
// Lazily access constants.IPC.
373374
const {
374375
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: bypassConfirms,
375376
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: bypassAlerts
376-
} = constants.IPC
377+
} = await getIPC()
377378
const { stderr: output, stdin: input } = process
378379
let alerts: SocketPackageAlert[] = bypassAlerts
379380
? []

0 commit comments

Comments
 (0)