Skip to content

Commit f4dc31e

Browse files
committed
chore(cleanup): trim dead helpers from flags.mts, bootstrap/paths.mts, util/ipc.mts
flags.mts: drop validationFlags (defineFlags const with zero src consumers; test only verified its shape — describe block also deleted). Kept resetFlagCache (test-only utility, but it's a legitimate testability hook — the V8 space-size flag getters cache their first read; tests need a reset to exercise different env values; flagged @internal). util/ipc.mts: drop initializeIpc, getIpcExtra, getBootstrapBinaryPath (3 functions + supporting module state). Keep the IpcObject type (imported by util/dlx/spawn.mts via `import type`). Delete the test file — all its blocks tested the now-removed functions. bootstrap/shared/paths.mts: drop getBootstrapBinaryDir + getRegistryUrl (both zero src consumers). Test blocks for both deleted.
1 parent ba0ac5d commit f4dc31e

6 files changed

Lines changed: 6 additions & 303 deletions

File tree

packages/cli/src/bootstrap/shared/paths.mts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
import os from 'node:os'
1313
import path from 'node:path'
1414

15-
/**
16-
* Get the bootstrap binary installation directory. This is where SEA/yao-pkg
17-
* executables are cached.
18-
*/
19-
export function getBootstrapBinaryDir(): string {
20-
return path.join(getSocketHome(), '_cli')
21-
}
22-
2315
/**
2416
* Get the CLI entry point path.
2517
*/
@@ -50,18 +42,6 @@ export function getDlxDir(): string {
5042
return path.join(getSocketHome(), '_dlx')
5143
}
5244

53-
/**
54-
* Get npm registry URL with environment variable support. Direct process.env
55-
* access required - bootstrap runs before ENV module loads.
56-
*/
57-
export function getRegistryUrl(): string {
58-
return (
59-
process.env['SOCKET_NPM_REGISTRY'] ||
60-
process.env['NPM_REGISTRY'] ||
61-
'https://registry.npmjs.org'
62-
)
63-
}
64-
6545
/**
6646
* Get the Socket home directory path. Supports SOCKET_HOME environment variable
6747
* override. Direct process.env access required - bootstrap runs before ENV

packages/cli/src/flags.mts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ export function getRawSpaceSizeFlags(): RawSpaceSizeFlags {
181181
}
182182

183183
/**
184-
* Reset cached flag values for testing purposes.
184+
* Reset cached flag values. Test-only — the V8 space-size flag getters
185+
* memoize their first read of process.execArgv + process.env; tests need
186+
* a way to clear the cache between assertions over different env values.
185187
*
186188
* @internal
187189
*/
@@ -190,6 +192,7 @@ export function resetFlagCache(): void {
190192
maxOldSpaceSizeFlag = undefined
191193
maxSemiSpaceSizeFlag = undefined
192194
}
195+
193196
// Ensure export because dist/flags.js is required in src/constants.mts.
194197
if (typeof exports === 'object' && exports !== null) {
195198
exports.getMaxSemiSpaceSizeFlag = getMaxSemiSpaceSizeFlag
@@ -302,15 +305,3 @@ export const outputFlags = defineFlags({
302305
},
303306
})
304307

305-
export const validationFlags = defineFlags({
306-
all: {
307-
type: 'boolean',
308-
default: false,
309-
description: 'Include all issues',
310-
},
311-
strict: {
312-
type: 'boolean',
313-
default: false,
314-
description: 'Exits with an error code if any matching issues are found',
315-
},
316-
})

packages/cli/src/util/ipc.mts

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,10 @@
11
/**
2-
* IPC data handling for subprocess communication.
3-
*
4-
* Provides access to IPC data passed via bootstrap handshake. The handshake
5-
* includes configuration like fix/optimize modes and other settings needed by
6-
* spawned processes.
2+
* IPC types for subprocess communication. Used as the typed shape of the
3+
* `ipc` field in spawn options when launching child Socket CLI processes.
74
*/
85

9-
import { waitForBootstrapHandshake } from './sea/boot.mjs'
10-
116
// IpcObject type for subprocess IPC data.
127
export type IpcObject = Readonly<{
138
SOCKET_CLI_FIX?: string | undefined
149
SOCKET_CLI_OPTIMIZE?: boolean | undefined
1510
}>
16-
17-
// Store for IPC extra data received via handshake.
18-
let ipcExtra: IpcObject | undefined
19-
20-
// Store for bootstrap binary path received via handshake.
21-
let bootstrapBinaryPath: string | undefined
22-
23-
/**
24-
* Get bootstrap binary path from handshake. Returns the path to the bootstrap
25-
* wrapper that launched this CLI instance. Only available when CLI was launched
26-
* via a bootstrap wrapper (e.g., npx socket).
27-
*/
28-
export function getBootstrapBinaryPath(): string | undefined {
29-
return bootstrapBinaryPath
30-
}
31-
32-
/**
33-
* Get IPC extra data from handshake. Returns the extra field from the bootstrap
34-
* handshake.
35-
*/
36-
export function getIpcExtra(): IpcObject | undefined {
37-
return ipcExtra
38-
}
39-
40-
/**
41-
* Initialize IPC data handling. Waits for the bootstrap handshake and extracts
42-
* the extra field.
43-
*/
44-
export async function initializeIpc(): Promise<void> {
45-
try {
46-
const handshake = await waitForBootstrapHandshake(1000)
47-
if (handshake?.['extra']) {
48-
const extra = handshake['extra'] as Record<string, unknown>
49-
50-
// Extract bootstrap binary path if provided.
51-
if (typeof extra['bootstrapBinaryPath'] === 'string') {
52-
bootstrapBinaryPath = extra['bootstrapBinaryPath']
53-
}
54-
55-
// Extract IPC data (excluding bootstrap metadata).
56-
const { bootstrapBinaryPath: _, ...ipcData } = extra
57-
ipcExtra = ipcData as IpcObject
58-
}
59-
} catch {
60-
// No handshake - running without IPC.
61-
}
62-
}

packages/cli/test/unit/bootstrap/shared/paths.test.mts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ import path from 'node:path'
1313
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
1414

1515
import {
16-
getBootstrapBinaryDir,
1716
getCliEntryPoint,
1817
getCliPackageDir,
1918
getCliPackageName,
2019
getDlxDir,
21-
getRegistryUrl,
2220
getSocketHome,
2321
} from '../../../../src/bootstrap/shared/paths.mts'
2422

@@ -70,13 +68,6 @@ describe('bootstrap/shared/paths', () => {
7068
})
7169
})
7270

73-
describe('getBootstrapBinaryDir', () => {
74-
it('appends _cli to the socket home', () => {
75-
process.env['SOCKET_HOME'] = '/x'
76-
expect(getBootstrapBinaryDir()).toBe(path.join('/x', '_cli'))
77-
})
78-
})
79-
8071
describe('getDlxDir', () => {
8172
it('appends _dlx to the socket home', () => {
8273
process.env['SOCKET_HOME'] = '/x'
@@ -100,28 +91,6 @@ describe('bootstrap/shared/paths', () => {
10091
})
10192
})
10293

103-
describe('getRegistryUrl', () => {
104-
it('uses SOCKET_NPM_REGISTRY when set', () => {
105-
process.env['SOCKET_NPM_REGISTRY'] = 'https://socket-registry.example/'
106-
expect(getRegistryUrl()).toBe('https://socket-registry.example/')
107-
})
108-
109-
it('uses NPM_REGISTRY when SOCKET_NPM_REGISTRY is missing', () => {
110-
process.env['NPM_REGISTRY'] = 'https://npm-registry.example/'
111-
expect(getRegistryUrl()).toBe('https://npm-registry.example/')
112-
})
113-
114-
it('falls back to the public npm registry', () => {
115-
expect(getRegistryUrl()).toBe('https://registry.npmjs.org')
116-
})
117-
118-
it('prefers SOCKET_NPM_REGISTRY over NPM_REGISTRY', () => {
119-
process.env['SOCKET_NPM_REGISTRY'] = 'https://socket-r.example/'
120-
process.env['NPM_REGISTRY'] = 'https://npm-r.example/'
121-
expect(getRegistryUrl()).toBe('https://socket-r.example/')
122-
})
123-
})
124-
12594
describe('getCliPackageName', () => {
12695
it('uses SOCKET_CLI_PACKAGE when set', () => {
12796
process.env['SOCKET_CLI_PACKAGE'] = '@my-org/socket'

packages/cli/test/unit/flags.test.mts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import {
6767
getMaxSemiSpaceSizeFlag,
6868
outputFlags,
6969
resetFlagCache,
70-
validationFlags,
7170
} from '../../src/flags.mts'
7271

7372
import type * as OsModule from 'node:os'
@@ -302,32 +301,4 @@ describe('flags', () => {
302301
})
303302
})
304303

305-
describe('validationFlags', () => {
306-
it('exports validation-related flags', () => {
307-
expect(validationFlags).toBeDefined()
308-
expect(typeof validationFlags).toBe('object')
309-
310-
// Check for expected validation flags.
311-
expect(validationFlags).toHaveProperty('all')
312-
expect(validationFlags).toHaveProperty('strict')
313-
314-
// Check flag types.
315-
expect(validationFlags.all?.type).toBe('boolean')
316-
expect(validationFlags.strict?.type).toBe('boolean')
317-
})
318-
319-
it('has descriptions for all flags', () => {
320-
for (const [, flag] of Object.entries(validationFlags)) {
321-
expect(flag).toHaveProperty('description')
322-
expect(typeof flag.description).toBe('string')
323-
expect(flag.description.length).toBeGreaterThan(0)
324-
}
325-
})
326-
327-
it('validation flags do not have short flags', () => {
328-
// Validation flags don't have short flags by design.
329-
expect(validationFlags.all?.shortFlag).toBeUndefined()
330-
expect(validationFlags.strict?.shortFlag).toBeUndefined()
331-
})
332-
})
333304
})

packages/cli/test/unit/util/ipc.test.mts

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)