Skip to content

Commit 1c4d22d

Browse files
committed
Use SOCKET_IPC_HANDSHAKE
1 parent c2b041b commit 1c4d22d

File tree

6 files changed

+16
-57
lines changed

6 files changed

+16
-57
lines changed

.dep-stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@socketregistry/is-interactive": "^1.0.1",
99
"@socketregistry/is-unicode-supported": "^1.0.0",
1010
"@socketsecurity/config": "^2.1.3",
11-
"@socketsecurity/registry": "^1.0.73",
11+
"@socketsecurity/registry": "^1.0.74",
1212
"@socketsecurity/sdk": "^1.4.5",
1313
"blessed": "^0.1.81",
1414
"blessed-contrib": "^4.11.0",

package-lock.json

Lines changed: 4 additions & 4 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
@@ -63,7 +63,7 @@
6363
"@socketregistry/is-interactive": "^1.0.1",
6464
"@socketregistry/is-unicode-supported": "^1.0.0",
6565
"@socketsecurity/config": "^2.1.3",
66-
"@socketsecurity/registry": "^1.0.73",
66+
"@socketsecurity/registry": "^1.0.74",
6767
"@socketsecurity/sdk": "^1.4.5",
6868
"blessed": "^0.1.81",
6969
"blessed-contrib": "^4.11.0",

src/commands/fix.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { shadowNpmInstall } from '../utils/shadow-npm'
55

66
import type { CliSubcommand } from '../utils/meow-with-subcommands'
77

8-
const { SOCKET_CLI_FIX_PACKAGE_LOCK_FILE } = constants
8+
const { SOCKET_CLI_FIX_PACKAGE_LOCK_FILE, SOCKET_IPC_HANDSHAKE } = constants
99

1010
export const fix: CliSubcommand = {
1111
description: 'Fix "fixable" Socket alerts',
@@ -14,7 +14,9 @@ export const fix: CliSubcommand = {
1414
try {
1515
await shadowNpmInstall({
1616
ipc: {
17-
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
17+
[SOCKET_IPC_HANDSHAKE]: {
18+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
19+
}
1820
}
1921
})
2022
} catch (e: any) {

src/commands/optimize.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const {
5151
PNPM,
5252
RESOLUTIONS,
5353
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
54+
SOCKET_IPC_HANDSHAKE,
5455
VLT,
5556
YARN_BERRY,
5657
YARN_CLASSIC,
@@ -919,7 +920,9 @@ export const optimize: CliSubcommand = {
919920
try {
920921
if (isNpm) {
921922
const ipc = {
922-
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
923+
[SOCKET_IPC_HANDSHAKE]: {
924+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
925+
}
923926
}
924927
await shadowNpmInstall({ ipc })
925928
// TODO: This is a temporary workaround for a `npm ci` bug where it

src/constants.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { realpathSync, writeFileSync } from 'node:fs'
1+
import { realpathSync } from 'node:fs'
22
import path from 'node:path'
33
import process from 'node:process'
44

@@ -50,14 +50,11 @@ type Constants = {
5050
readonly synpBinPath: string
5151
} & typeof registryConstants
5252

53-
const { abortSignal } = registryConstants
54-
5553
const {
5654
PACKAGE_JSON,
5755
kInternalsSymbol,
5856
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: {
59-
createConstantsObject,
60-
defineGetter
57+
createConstantsObject
6158
}
6259
} = registryConstants
6360

@@ -91,47 +88,6 @@ const LAZY_ENV = () =>
9188
[SOCKET_CLI_DEBUG]: envAsBoolean(process.env[SOCKET_CLI_DEBUG])
9289
})
9390

94-
const LAZY_IPC = (() => {
95-
// Initialize and wire-up immediately.
96-
const keys = [
97-
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
98-
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE
99-
]
100-
const _ipc = (<unknown>{ __proto__: null }) as IPCObject
101-
const ipc = (<unknown>{ __proto__: null }) as IPCObject
102-
for (const key of keys) {
103-
_ipc[key] = false
104-
defineGetter(ipc, key, () => _ipc[key])
105-
}
106-
// A forked subprocess will have the 'send' method.
107-
// https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback
108-
if (typeof process.send === 'function') {
109-
void new Promise<void>(resolve => {
110-
const onmessage = (ipcData_: Serializable) => {
111-
finish()
112-
const ipcData: { [key: string]: any } = {
113-
__proto__: null,
114-
...(isObject(ipcData_) ? ipcData_ : {})
115-
}
116-
for (const key of keys) {
117-
_ipc[key] = ipcData[key]
118-
}
119-
}
120-
const finish = () => {
121-
abortSignal.removeEventListener('abort', finish)
122-
process.removeListener('message', onmessage)
123-
resolve()
124-
}
125-
abortSignal.addEventListener('abort', finish, { once: true })
126-
process.on('message', onmessage)
127-
// The timeout of 100ms is to prevent an unresolved promised. It should be
128-
// more than enough time for the IPC handshake.
129-
setTimeout(finish, 100)
130-
})
131-
}
132-
return () => Object.freeze(ipc)
133-
})()
134-
13591
const lazyCdxgenBinPath = () =>
13692
// Lazily access constants.nmBinPath.
13793
path.join(constants.nmBinPath, 'cdxgen')
@@ -178,7 +134,6 @@ const constants = <Constants>createConstantsObject(
178134
// Lazily defined values are initialized as `undefined` to keep their key order.
179135
DIST_TYPE: undefined,
180136
ENV: undefined,
181-
IPC: undefined,
182137
LOCK_EXT,
183138
MODULE_SYNC,
184139
NPM_REGISTRY_URL,
@@ -206,7 +161,6 @@ const constants = <Constants>createConstantsObject(
206161
getters: {
207162
DIST_TYPE: LAZY_DIST_TYPE,
208163
ENV: LAZY_ENV,
209-
IPC: LAZY_IPC,
210164
distPath: lazyDistPath,
211165
cdxgenBinPath: lazyCdxgenBinPath,
212166
nmBinPath: lazyNmBinPath,

0 commit comments

Comments
 (0)