Skip to content

Commit d9d8b8e

Browse files
committed
Add IPC constant
1 parent 6a59ee0 commit d9d8b8e

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/constants.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import process from 'node:process'
44

55
import registryConstants from '@socketsecurity/registry/lib/constants'
66
import { envAsBoolean } from '@socketsecurity/registry/lib/env'
7+
import { isObject } from '@socketsecurity/registry/lib/objects'
78

89
type RegistryEnv = typeof registryConstants.ENV
910

@@ -14,10 +15,12 @@ type Constants = {
1415
readonly BUN: 'bun'
1516
readonly ENV: RegistryEnv & {
1617
SOCKET_CLI_DEBUG: boolean
17-
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE: boolean
18-
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
1918
}
2019
readonly DIST_TYPE: 'module-sync' | 'require'
20+
readonly IPC: () => Promise<{
21+
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE: boolean
22+
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
23+
}>
2124
readonly LOCK_EXT: '.lock'
2225
readonly MODULE_SYNC: 'module-sync'
2326
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org'
@@ -42,6 +45,29 @@ type Constants = {
4245
readonly synpBinPath: string
4346
} & typeof registryConstants
4447

48+
const { abortSignal } = registryConstants
49+
50+
const IPC = (() => {
51+
const promise = new Promise((resolve, reject) => {
52+
process.once('message', ipcData => {
53+
console.log('hi')
54+
const {
55+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: a,
56+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: b
57+
} = <any>{ __proto__: null, ...(isObject(ipcData) ? ipcData : {}) }
58+
console.log('ok')
59+
resolve({
60+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: !!a,
61+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: !!b
62+
})
63+
})
64+
abortSignal.addEventListener('abort', reject, { once: true })
65+
})
66+
return function IPC() {
67+
return promise
68+
}
69+
})()
70+
4571
const {
4672
PACKAGE_JSON,
4773
kInternalsSymbol,
@@ -77,17 +103,7 @@ const LAZY_ENV = () =>
77103
// Lazily access registryConstants.ENV.
78104
...registryConstants.ENV,
79105
// Flag set to help debug Socket CLI.
80-
[SOCKET_CLI_DEBUG]: envAsBoolean(process.env[SOCKET_CLI_DEBUG]),
81-
// Flag set by the "fix" command to accept the package alerts prompt with
82-
// "Y(es)" in the SafeArborist reify method.
83-
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: envAsBoolean(
84-
process.env[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]
85-
),
86-
// Flag set by the "optimize" command to bypass the package alerts check
87-
// in the SafeArborist reify method.
88-
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: envAsBoolean(
89-
process.env[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]
90-
)
106+
[SOCKET_CLI_DEBUG]: envAsBoolean(process.env[SOCKET_CLI_DEBUG])
91107
})
92108

93109
const lazyCdxgenBinPath = () =>
@@ -136,6 +152,7 @@ const constants = <Constants>createConstantsObject(
136152
ENV: undefined,
137153
// Lazily defined values are initialized as `undefined` to keep their key order.
138154
DIST_TYPE: undefined,
155+
IPC,
139156
LOCK_EXT,
140157
MODULE_SYNC,
141158
NPM_REGISTRY_URL,

0 commit comments

Comments
 (0)