Skip to content

Commit 7cfefac

Browse files
committed
fix(lint): resolve lint errors and remove dead getInternals code
- Updated ESLint config to relax rules for scripts, configs, and test files - Added eslint-disable comments for legitimate no-await-in-loop cases - Removed unused eslint-disable directives from test files - Removed getInternals() function - registry no longer exposes internals - Simplified SafeArborist.reify() to always use risky reify path - Fixed lazy-ink extraneous require warnings The getInternals() function was returning an empty object since the registry no longer exposes IPC internals. All code using it was effectively dead code that always fell back to the default behavior.
1 parent 2321786 commit 7cfefac

File tree

8 files changed

+24
-112
lines changed

8 files changed

+24
-112
lines changed

packages/cli/.config/eslint.config.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,23 @@ export default [
365365
},
366366
},
367367
{
368-
// Relax rules for script files
369-
files: ['scripts/**/*.{mjs,js}', 'bin/**/*.{mjs,js}'],
368+
// Relax rules for script and config files
369+
files: [
370+
'scripts/**/*.{mjs,js}',
371+
'bin/**/*.{mjs,js}',
372+
'.config/**/*.{mjs,js}',
373+
],
370374
rules: {
375+
'n/no-extraneous-import': 'off',
376+
'n/no-extraneous-require': 'off',
371377
'n/no-process-exit': 'off',
372378
'n/no-unsupported-features/node-builtins': 'off',
373379
'n/no-missing-import': 'off',
374380
'import-x/no-unresolved': 'off',
375381
'no-await-in-loop': 'off',
376382
'no-unused-vars': 'off',
377383
'no-undef': 'off',
384+
'unicorn/consistent-function-scoping': 'off',
378385
},
379386
},
380387
{
@@ -399,6 +406,10 @@ export default [
399406
'no-undef': 'off',
400407
// Allow console in tests
401408
'no-console': 'off',
409+
// Allow process.exit in tests
410+
'n/no-process-exit': 'off',
411+
// Allow scoped functions in tests
412+
'unicorn/consistent-function-scoping': 'off',
402413
},
403414
},
404415
]

packages/cli/src/constants.mts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ import {
248248
REPORT_LEVEL_WARN,
249249
} from './constants/reporting.mts'
250250
import {
251-
getInternals,
252251
getShadowNpmBinPath as SHADOW_getShadowNpmBinPath,
253252
getShadowNpxBinPath as SHADOW_getShadowNpxBinPath,
254253
getShadowPnpmBinPath as SHADOW_getShadowPnpmBinPath,
@@ -369,7 +368,6 @@ export {
369368
getExecPath,
370369
getGithubCachePath,
371370
getInstrumentWithSentryPath,
372-
getInternals,
373371
getMinimumVersionByAgent,
374372
getNmBunPath,
375373
getNmNodeGypPath,
@@ -621,7 +619,6 @@ export default {
621619
getExecPath,
622620
getGithubCachePath,
623621
getInstrumentWithSentryPath,
624-
getInternals,
625622
getMinimumVersionByAgent,
626623
getNmBunPath,
627624
getNmNodeGypPath,

packages/cli/src/constants/shadow.mts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ export const SOCKET_CLI_SHADOW_SILENT = 'SOCKET_CLI_SHADOW_SILENT'
3030
export const SOCKET_CLI_ACCEPT_RISKS = 'SOCKET_CLI_ACCEPT_RISKS'
3131
export const SOCKET_CLI_VIEW_ALL_RISKS = 'SOCKET_CLI_VIEW_ALL_RISKS'
3232

33-
/**
34-
* Get registry internals for accessing IPC and Sentry instances.
35-
*/
36-
export function getInternals(): RegistryInternals {
37-
const registry = require('@socketsecurity/registry')
38-
return registry.internals ?? {}
39-
}
40-
4133
/**
4234
* Get the path to the shadow npm binary.
4335
*/

packages/cli/src/shadow/npm/arborist/lib/arborist/index.mts

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import { NPX } from '../../../../../constants/agents.mts'
1010
import ENV from '../../../../../constants/env.mts'
1111
import { NODE_MODULES } from '../../../../../constants/packages.mts'
1212
import {
13-
getInternals,
1413
SOCKET_CLI_ACCEPT_RISKS,
1514
SOCKET_CLI_SHADOW_ACCEPT_RISKS,
1615
SOCKET_CLI_SHADOW_API_TOKEN,
17-
SOCKET_CLI_SHADOW_BIN,
1816
SOCKET_CLI_SHADOW_PROGRESS,
1917
SOCKET_CLI_SHADOW_SILENT,
2018
SOCKET_CLI_VIEW_ALL_RISKS,
@@ -32,9 +30,6 @@ import type {
3230
NodeClass,
3331
} from '../../types.mts'
3432

35-
const internals = getInternals()
36-
const getIpc = internals.getIpc
37-
3833
export const SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
3934
__proto__: null,
4035
audit: false,
@@ -101,97 +96,7 @@ export class SafeArborist extends Arborist {
10196
this: SafeArborist,
10297
...args: Parameters<InstanceType<ArboristClass>['reify']>
10398
): Promise<NodeClass> {
104-
const options = {
105-
__proto__: null,
106-
...(args.length ? args[0] : undefined),
107-
} as ArboristReifyOptions
108-
109-
const ipc = getIpc ? await getIpc() : undefined
110-
111-
const binName = ipc?.[SOCKET_CLI_SHADOW_BIN]
112-
if (!binName) {
113-
return await this[kRiskyReify](...args)
114-
}
115-
116-
await super.reify(
117-
{
118-
...options,
119-
...SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
120-
progress: false,
121-
},
122-
// @ts-expect-error: TypeScript gets grumpy about rest parameters.
123-
...args.slice(1),
124-
)
125-
126-
const shadowAcceptRisks = !!ipc?.[SOCKET_CLI_SHADOW_ACCEPT_RISKS]
127-
const shadowProgress = !!ipc?.[SOCKET_CLI_SHADOW_PROGRESS]
128-
const shadowSilent = !!ipc?.[SOCKET_CLI_SHADOW_SILENT]
129-
130-
const acceptRisks = shadowAcceptRisks || ENV.SOCKET_CLI_ACCEPT_RISKS
131-
const reportOnlyBlocking =
132-
acceptRisks || options['dryRun'] || options['yes']
133-
const silent = !!options['silent']
134-
const spinnerInstance =
135-
silent || !shadowProgress ? undefined : (getSpinner() ?? undefined)
136-
137-
const isShadowNpx = binName === NPX
138-
const hasExisting = await findUp(NODE_MODULES, {
139-
cwd: process.cwd(),
140-
onlyDirectories: true,
141-
})
142-
const shouldCheckExisting = reportOnlyBlocking ? true : isShadowNpx
143-
144-
const needInfoOn = getDetailsFromDiff(this.diff, {
145-
filter: {
146-
existing: shouldCheckExisting,
147-
},
148-
})
149-
150-
const alertsMap = await getAlertsMapFromArborist(this, needInfoOn, {
151-
apiToken: ipc?.[SOCKET_CLI_SHADOW_API_TOKEN],
152-
spinner: spinnerInstance,
153-
filter: reportOnlyBlocking
154-
? {
155-
actions: ['error'],
156-
blocked: true,
157-
existing: shouldCheckExisting,
158-
}
159-
: {
160-
actions: ['error', 'monitor', 'warn'],
161-
existing: shouldCheckExisting,
162-
},
163-
})
164-
165-
if (alertsMap.size) {
166-
process.exitCode = 1
167-
const viewAllRisks = ENV.SOCKET_CLI_VIEW_ALL_RISKS
168-
logAlertsMap(alertsMap, {
169-
hideAt: viewAllRisks ? 'none' : 'middle',
170-
output: process.stderr,
171-
})
172-
throw new Error(
173-
`
174-
Socket ${binName} exiting due to risks.${
175-
viewAllRisks
176-
? ''
177-
: `\nView all risks - Rerun with environment variable ${SOCKET_CLI_VIEW_ALL_RISKS}=1.`
178-
}${
179-
acceptRisks
180-
? ''
181-
: `\nAccept risks - Rerun with environment variable ${SOCKET_CLI_ACCEPT_RISKS}=1.`
182-
}
183-
`.trim(),
184-
)
185-
}
186-
if (!silent && !shadowSilent) {
187-
logger.success(
188-
`Socket ${binName} ${acceptRisks ? 'accepted' : 'found no'}${hasExisting ? ' new' : ''} risks`,
189-
)
190-
if (isShadowNpx) {
191-
logger.log(`Running ${options.add?.[0]}`)
192-
}
193-
}
194-
99+
// Note: Registry no longer provides IPC, always use risky reify.
195100
return await this[kRiskyReify](...args)
196101
}
197102
}

packages/cli/src/types.test.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ describe('types', () => {
3333

3434
it('can be used as a union type', () => {
3535
// Intentionally defined inline to test type inference in specific context.
36-
// eslint-disable-next-line unicorn/consistent-function-scoping
3736
const processResult = (value: number): CResult<string> => {
3837
if (value > 0) {
3938
return { ok: true, data: `Positive: ${value}` }

packages/cli/src/utils/promise/queue.test.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ describe('PromiseQueue', () => {
9898
const queue = new PromiseQueue(1)
9999

100100
// Intentionally defined inline for test simplicity.
101-
// eslint-disable-next-line unicorn/consistent-function-scoping
102101
const goodTask = () => Promise.resolve('success')
103102
// Intentionally defined inline for test simplicity.
104-
// eslint-disable-next-line unicorn/consistent-function-scoping
105103
const badTask = () => Promise.reject(new Error('failure'))
106104

107105
const result1 = await queue.add(goodTask)

packages/cli/src/utils/registry/npm-registry.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ export async function retryWithBackoff<T>(
169169
let lastError: Error | unknown
170170
let delay = baseDelayMs
171171

172+
// Retry logic requires sequential attempts.
172173
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
173174
try {
175+
// eslint-disable-next-line no-await-in-loop
174176
return await fn()
175177
} catch (error) {
176178
lastError = error
@@ -180,6 +182,7 @@ export async function retryWithBackoff<T>(
180182
attempt < maxRetries &&
181183
(code === 'EBUSY' || code === 'EMFILE' || code === 'ENFILE')
182184
) {
185+
// eslint-disable-next-line no-await-in-loop
183186
await new Promise(resolve => setTimeout(resolve, delay))
184187
delay *= backoffFactor
185188
continue
@@ -269,12 +272,14 @@ export async function extractTarball(
269272
}
270273

271274
// Extract files to target directory.
275+
// Files must be extracted sequentially.
272276
for (const file of files) {
273277
// Sanitize file path to prevent directory traversal attacks.
274278
const sanitizedPath = sanitizeTarballPath(file.name)
275279
const targetPath = path.join(targetDir, sanitizedPath)
276280

277281
if (file.type === 'directory') {
282+
// eslint-disable-next-line no-await-in-loop
278283
await retryWithBackoff(() =>
279284
fs.mkdir(targetPath, { recursive: true }),
280285
).catch(error => {
@@ -285,6 +290,7 @@ export async function extractTarball(
285290
} else if (file.type === 'file' && file.data) {
286291
// Ensure parent directory exists.
287292
const parentDir = path.dirname(targetPath)
293+
// eslint-disable-next-line no-await-in-loop
288294
await retryWithBackoff(() =>
289295
fs.mkdir(parentDir, { recursive: true }),
290296
).catch(error => {
@@ -300,6 +306,7 @@ export async function extractTarball(
300306
})
301307

302308
// Write file.
309+
// eslint-disable-next-line no-await-in-loop
303310
await retryWithBackoff(() =>
304311
fs.writeFile(targetPath, file.data as Uint8Array<ArrayBufferLike>),
305312
).catch(error => {
@@ -319,6 +326,7 @@ export async function extractTarball(
319326
const mode = Number.parseInt(file.attrs.mode, 8)
320327
// Validate mode is a valid number before attempting chmod.
321328
if (!Number.isNaN(mode) && mode > 0) {
329+
// eslint-disable-next-line no-await-in-loop
322330
await retryWithBackoff(() => fs.chmod(targetPath, mode)).catch(
323331
error => {
324332
// Chmod failures are non-fatal - log but continue.

packages/cli/src/utils/terminal/lazy-ink.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export async function loadInkTable() {
3636
export function isInkAvailable(): boolean {
3737
try {
3838
// Check if modules exist without loading them
39+
// eslint-disable-next-line n/no-extraneous-require
3940
require.resolve('ink')
41+
// eslint-disable-next-line n/no-extraneous-require
4042
require.resolve('react')
4143
return true
4244
} catch {

0 commit comments

Comments
 (0)