Skip to content

Commit 193a263

Browse files
committed
refactor: drop leading underscores from module-private identifiers
Per the fleet's socket/no-underscore-identifier rule, leading underscores on identifiers don't enforce privacy in TypeScript — module boundaries (not exporting) and `_internal/` directories do. The convention was carried over from other languages and added noise without enforcement. Renamed 48 identifiers across 31 files: memo-cache variables in packages/cli/src/util/* (yarn/pnpm/npm/git/sea path caches), config caches in src/util/config.mts, src/util/socket/sdk.mts, src/util/git/github.mts; test-fixture and mock locals across test/unit/, test/integration/, test/e2e/. All renames are `_foo` → `foo`. One conflict (`_isYarnBerry` collided with the exported `isYarnBerry` function in the same module scope) resolved as `_isYarnBerry` → `cachedIsYarnBerry`. Other fleet-rule fixes pulled in by re-cascading + verifying: - execSync → @socketsecurity/lib-stable/spawn.spawnSync in scripts/environment-variables.mts and two dlx-spawn tests (prefer-spawn-over-execsync). - McpHandleRequest type widened to `auth?: AuthInfo` (drop `| undefined`) with a per-line bypass for optional-explicit-undefined — the SDK target's exactOptionalPropertyTypes-strict shape rejects bare-undefined here while the lint rule wants it for pairing. - Misc cascade-applied content drift from upstream wheelhouse rule + script fixes. Verified: pnpm run check --all passes; pnpm test passes.
1 parent f0b16ba commit 193a263

36 files changed

Lines changed: 246 additions & 221 deletions

packages/cli/scripts/environment-variables.mts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* EnvironmentVariables.getTestVariables(vars)
1313
*/
1414

15-
import { execSync } from 'node:child_process'
15+
import { spawnSync } from '@socketsecurity/lib-stable/spawn'
1616
import { readFileSync } from 'node:fs'
1717
import path from 'node:path'
1818
import crypto from 'node:crypto'
@@ -50,10 +50,14 @@ export class EnvironmentVariables {
5050
// Get current git commit hash.
5151
let gitHash = ''
5252
try {
53-
gitHash = execSync('git rev-parse --short HEAD', {
53+
const r = spawnSync('git', ['rev-parse', '--short', 'HEAD'], {
5454
cwd: rootPath,
55-
encoding: 'utf-8',
56-
}).trim()
55+
stdio: 'pipe',
56+
stdioString: true,
57+
})
58+
if (r.status === 0 && typeof r.stdout === 'string') {
59+
gitHash = r.stdout.trim()
60+
}
5761
} catch {}
5862

5963
// Get external tool versions from bundle-tools.json.

packages/cli/src/commands/fix/cmd-fix.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export async function run(
423423
const isGhsa = upperInput.startsWith('GHSA-')
424424
const isCve = upperInput.startsWith('CVE-')
425425
const isPurl = rawInput.startsWith('pkg:')
426-
if (isGhsa || isCve || isPurl) {
426+
if (isCve || isGhsa || isPurl) {
427427
// `handle-fix.mts` validates IDs with case-sensitive format regexes:
428428
// * GHSA — prefix must be uppercase, body segments lowercase [a-z0-9]
429429
// * CVE — prefix must be uppercase, body is all digits (case-free)

packages/cli/src/commands/manifest/run-cdxgen.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function detectNodejsCdxgenSources(
9898
findUp(NODE_MODULES, { cwd, onlyDirectories: true }),
9999
])
100100
return {
101-
hasLockfile: Boolean(pnpmLockPath || npmLockPath || yarnLockPath),
101+
hasLockfile: Boolean(npmLockPath || pnpmLockPath || yarnLockPath),
102102
hasNodeModules: Boolean(nodeModulesPath),
103103
}
104104
}

packages/cli/src/commands/mcp/handle-mcp.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ export async function handleMcp(opts: HandleMcpOptions): Promise<void> {
3636
const clientId = opts.oauthClientId ?? ''
3737
const clientSecret = opts.oauthClientSecret ?? ''
3838
const partial =
39-
(issuer || clientId || clientSecret) &&
40-
!(issuer && clientId && clientSecret)
39+
(clientId || clientSecret || issuer) &&
40+
!(clientId && clientSecret && issuer)
4141
if (partial) {
4242
logger.error(
4343
'Incomplete OAuth configuration for HTTP mode. Set SOCKET_OAUTH_ISSUER, SOCKET_OAUTH_INTROSPECTION_CLIENT_ID, and SOCKET_OAUTH_INTROSPECTION_CLIENT_SECRET together.',
4444
)
4545
process.exit(1)
4646
}
47-
const oauthEnabled = Boolean(issuer && clientId && clientSecret)
47+
const oauthEnabled = Boolean(clientId && clientSecret && issuer)
4848
if (!oauthEnabled && !baseConfig.getApiToken()) {
4949
logger.error(
5050
'No SOCKET_API_TOKEN configured and OAuth is not enabled. Run `socket login` or set OAuth env vars (SOCKET_OAUTH_ISSUER, SOCKET_OAUTH_INTROSPECTION_CLIENT_ID, SOCKET_OAUTH_INTROSPECTION_CLIENT_SECRET) before starting HTTP mode.',

packages/cli/src/commands/mcp/transport-http.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type AuthenticatedRequest = IncomingMessage & { auth?: AuthInfo | undefined }
4343
// exactOptionalPropertyTypes. Cast our internal type to this at the
4444
// call boundary when handing off; that's the narrow constraint, not
4545
// our internal shape.
46+
// oxlint-disable-next-line socket/optional-explicit-undefined -- SDK target type uses `auth?: AuthInfo` (no `| undefined`); under exactOptionalPropertyTypes the bare-undefined form rejects this assignment. Pair to the SDK shape, not the local AuthenticatedRequest.
4647
type McpHandleRequest = IncomingMessage & { auth?: AuthInfo }
4748

4849
interface Session {

packages/cli/src/commands/scan/cmd-scan-create.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,12 @@ export async function run(
433433
reachabilityFlags['reachDisableAnalytics']?.default
434434

435435
const isUsingAnyReachabilityFlags =
436-
isUsingNonDefaultMemoryLimit ||
437-
isUsingNonDefaultTimeout ||
438-
isUsingNonDefaultConcurrency ||
439-
isUsingNonDefaultAnalytics ||
440436
hasReachEcosystems ||
441437
hasReachExcludePaths ||
438+
isUsingNonDefaultAnalytics ||
439+
isUsingNonDefaultConcurrency ||
440+
isUsingNonDefaultMemoryLimit ||
441+
isUsingNonDefaultTimeout ||
442442
reachEnableAnalysisSplitting ||
443443
reachLazyMode ||
444444
reachSkipCache

packages/cli/src/commands/scan/perform-reachability-analysis.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function performReachabilityAnalysis(
117117

118118
let tarHash: string | undefined
119119

120-
if (uploadManifests && orgSlug && packagePaths) {
120+
if (orgSlug && packagePaths && uploadManifests) {
121121
// Setup SDK for uploading manifests
122122
const sockSdkCResult = await setupSdk()
123123
if (!sockSdkCResult.ok) {

packages/cli/src/flags.mts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ type RawSpaceSizeFlags = {
2727
maxSemiSpaceSize: number
2828
}
2929

30-
let _rawSpaceSizeFlags: RawSpaceSizeFlags | undefined
30+
let rawSpaceSizeFlags: RawSpaceSizeFlags | undefined
3131

32-
let _maxOldSpaceSizeFlag: number | undefined
32+
let maxOldSpaceSizeFlag: number | undefined
3333

3434
// Ensure export because dist/flags.js is required in src/constants.mts.
3535
// eslint-disable-next-line n/exports-style
@@ -38,14 +38,14 @@ if (typeof exports === 'object' && exports !== null) {
3838
exports.getMaxOldSpaceSizeFlag = getMaxOldSpaceSizeFlag
3939
}
4040

41-
let _maxSemiSpaceSizeFlag: number | undefined
41+
let maxSemiSpaceSizeFlag: number | undefined
4242

4343
export function getMaxOldSpaceSizeFlag(): number {
44-
if (_maxOldSpaceSizeFlag === undefined) {
44+
if (maxOldSpaceSizeFlag === undefined) {
4545
const rawFlag = getRawSpaceSizeFlags().maxOldSpaceSize
4646
// Check if flag was explicitly set (> 0).
4747
if (rawFlag > 0) {
48-
_maxOldSpaceSizeFlag = rawFlag
48+
maxOldSpaceSizeFlag = rawFlag
4949
} else {
5050
const match = /(?<=--max-old-space-size=)\d+/.exec(
5151
NODE_OPTIONS ?? '',
@@ -54,48 +54,48 @@ export function getMaxOldSpaceSizeFlag(): number {
5454
const parsed = Number(match)
5555
/* c8 ignore start - regex (\d+) guarantees a numeric string; defensive guard */
5656
if (Number.isNaN(parsed) || parsed < 0) {
57-
_maxOldSpaceSizeFlag = 0
57+
maxOldSpaceSizeFlag = 0
5858
/* c8 ignore stop */
5959
} else {
60-
_maxOldSpaceSizeFlag = parsed
60+
maxOldSpaceSizeFlag = parsed
6161
}
6262
}
6363
}
6464
// Only apply default if no value was set (null/undefined, not 0).
65-
if (_maxOldSpaceSizeFlag == null) {
65+
if (maxOldSpaceSizeFlag == null) {
6666
// Default value determined by available system memory.
67-
_maxOldSpaceSizeFlag = Math.floor(
67+
maxOldSpaceSizeFlag = Math.floor(
6868
// Total system memory in MiB.
6969
(os.totalmem() / 1_024 / 1_024) *
7070
// Set 75% of total memory (safe buffer to avoid system pressure).
7171
0.75,
7272
)
7373
}
7474
}
75-
return _maxOldSpaceSizeFlag
75+
return maxOldSpaceSizeFlag
7676
}
7777

7878
export function getMaxSemiSpaceSizeFlag(): number {
79-
if (_maxSemiSpaceSizeFlag === undefined) {
80-
_maxSemiSpaceSizeFlag = getRawSpaceSizeFlags().maxSemiSpaceSize
81-
if (!_maxSemiSpaceSizeFlag) {
79+
if (maxSemiSpaceSizeFlag === undefined) {
80+
maxSemiSpaceSizeFlag = getRawSpaceSizeFlags().maxSemiSpaceSize
81+
if (!maxSemiSpaceSizeFlag) {
8282
const match = /(?<=--max-semi-space-size=)\d+/.exec(
8383
NODE_OPTIONS ?? '',
8484
)?.[0]
8585
if (match) {
8686
const parsed = Number(match)
8787
/* c8 ignore start - regex (\d+) guarantees a numeric string; defensive guard */
8888
if (Number.isNaN(parsed) || parsed < 0) {
89-
_maxSemiSpaceSizeFlag = 0
89+
maxSemiSpaceSizeFlag = 0
9090
/* c8 ignore stop */
9191
} else {
92-
_maxSemiSpaceSizeFlag = parsed
92+
maxSemiSpaceSizeFlag = parsed
9393
}
9494
} else {
95-
_maxSemiSpaceSizeFlag = 0
95+
maxSemiSpaceSizeFlag = 0
9696
}
9797
}
98-
if (!_maxSemiSpaceSizeFlag) {
98+
if (!maxSemiSpaceSizeFlag) {
9999
const maxOldSpaceSize = getMaxOldSpaceSizeFlag()
100100
// Dynamically scale semi-space size based on max-old-space-size.
101101
// https://nodejs.org/api/cli.html#--max-semi-space-sizesize-in-mib
@@ -104,15 +104,15 @@ export function getMaxSemiSpaceSizeFlag(): number {
104104
// generation size. This helps stay within safe memory limits on
105105
// constrained systems or CI.
106106
if (maxOldSpaceSize <= 512) {
107-
_maxSemiSpaceSizeFlag = 4
107+
maxSemiSpaceSizeFlag = 4
108108
} else if (maxOldSpaceSize <= 1_024) {
109-
_maxSemiSpaceSizeFlag = 8
109+
maxSemiSpaceSizeFlag = 8
110110
} else if (maxOldSpaceSize <= 2_048) {
111-
_maxSemiSpaceSizeFlag = 16
111+
maxSemiSpaceSizeFlag = 16
112112
} else if (maxOldSpaceSize <= 4_096) {
113-
_maxSemiSpaceSizeFlag = 32
113+
maxSemiSpaceSizeFlag = 32
114114
} else {
115-
_maxSemiSpaceSizeFlag = 64
115+
maxSemiSpaceSizeFlag = 64
116116
}
117117
} else {
118118
// For large heaps (> 8 GiB), compute semi-space size using a log-scaled
@@ -132,15 +132,15 @@ export function getMaxSemiSpaceSizeFlag(): number {
132132
// (e.g. large arrays, buffers).
133133
const log2OldSpace = Math.log2(maxOldSpaceSize)
134134
const scaledSemiSpace = Math.floor(log2OldSpace) * 8
135-
_maxSemiSpaceSizeFlag = scaledSemiSpace
135+
maxSemiSpaceSizeFlag = scaledSemiSpace
136136
}
137137
}
138138
}
139-
return _maxSemiSpaceSizeFlag
139+
return maxSemiSpaceSizeFlag
140140
}
141141

142142
export function getRawSpaceSizeFlags(): RawSpaceSizeFlags {
143-
if (_rawSpaceSizeFlags === undefined) {
143+
if (rawSpaceSizeFlags === undefined) {
144144
const cli = meow({
145145
argv: process.argv.slice(2),
146146
// Prevent meow from potentially exiting early.
@@ -174,12 +174,12 @@ export function getRawSpaceSizeFlags(): RawSpaceSizeFlags {
174174
}
175175
/* c8 ignore stop */
176176

177-
_rawSpaceSizeFlags = {
177+
rawSpaceSizeFlags = {
178178
maxOldSpaceSize,
179179
maxSemiSpaceSize,
180180
}
181181
}
182-
return _rawSpaceSizeFlags!
182+
return rawSpaceSizeFlags!
183183
}
184184

185185
/**
@@ -188,9 +188,9 @@ export function getRawSpaceSizeFlags(): RawSpaceSizeFlags {
188188
* @internal
189189
*/
190190
export function resetFlagCache(): void {
191-
_rawSpaceSizeFlags = undefined
192-
_maxOldSpaceSizeFlag = undefined
193-
_maxSemiSpaceSizeFlag = undefined
191+
rawSpaceSizeFlags = undefined
192+
maxOldSpaceSizeFlag = undefined
193+
maxSemiSpaceSizeFlag = undefined
194194
}
195195
// Ensure export because dist/flags.js is required in src/constants.mts.
196196
// eslint-disable-next-line n/exports-style

0 commit comments

Comments
 (0)