Skip to content

Commit 78ea2b7

Browse files
committed
fix(types): resolve TypeScript errors in spawn usage and unused imports
Fix TypeScript compilation errors related to spawn function usage and remove unused imports and functions. Changes: - Fix spawn process event handlers to use .process property - Add explicit type annotations for event handler parameters - Remove unused FLAG_DRY_RUN, FLAG_HELP, FLAG_JSON imports - Remove unused getToolPaths import - Remove unused getPythonChecksum function and PYTHON_CHECKSUMS constant Affected files: - src/bootstrap/node.mts: Fix spawn .process property access and types - src/commands/npm/cmd-npm.mts: Remove unused flag imports - src/commands/npx/cmd-npx.mts: Remove unused flag imports - src/utils/dlx/spawn.mts: Remove unused getToolPaths import - src/utils/python/standalone.mts: Remove unused checksum code
1 parent fb48092 commit 78ea2b7

File tree

5 files changed

+11
-75
lines changed

5 files changed

+11
-75
lines changed

packages/cli/src/bootstrap/node.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ async function downloadCli(): Promise<void> {
6363
)
6464

6565
let tarballName = ''
66-
npmPackProcess.stdout?.on('data', data => {
66+
npmPackProcess.process.stdout?.on('data', (data: Buffer) => {
6767
tarballName += data.toString()
6868
})
6969

70-
npmPackProcess.on('error', e => {
70+
npmPackProcess.process.on('error', (e: Error) => {
7171
reject(new Error(`Failed to run npm pack: ${e}`))
7272
})
7373

74-
npmPackProcess.on('exit', async code => {
74+
npmPackProcess.process.on('exit', async (code: number | null) => {
7575
if (code !== 0) {
7676
reject(new Error(`npm pack exited with code ${code}`))
7777
return
@@ -90,11 +90,11 @@ async function downloadCli(): Promise<void> {
9090
},
9191
)
9292

93-
tarExtractProcess.on('error', e => {
93+
tarExtractProcess.process.on('error', (e: Error) => {
9494
reject(new Error(`Failed to extract tarball: ${e}`))
9595
})
9696

97-
tarExtractProcess.on('exit', async extractCode => {
97+
tarExtractProcess.process.on('exit', async (extractCode: number | null) => {
9898
if (extractCode !== 0) {
9999
reject(new Error(`tar extraction exited with code ${extractCode}`))
100100
return
@@ -143,13 +143,13 @@ async function main(): Promise<void> {
143143
},
144144
)
145145

146-
child.on('error', error => {
146+
child.process.on('error', (error: Error) => {
147147
logger.error('Failed to spawn CLI:', error)
148148
// eslint-disable-next-line n/no-process-exit
149149
process.exit(1)
150150
})
151151

152-
child.on('exit', (code, signal) => {
152+
child.process.on('exit', (code: number | null, signal: NodeJS.Signals | null) => {
153153
// eslint-disable-next-line n/no-process-exit
154154
process.exit(code ?? (signal ? 1 : 0))
155155
})

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { NPM } from '@socketsecurity/lib/constants/agents'
22
import { getDefaultLogger } from '@socketsecurity/lib/logger'
33

4-
import {
5-
DRY_RUN_BAILING_NOW,
6-
FLAG_DRY_RUN,
7-
FLAG_HELP,
8-
FLAG_JSON,
9-
} from '../../constants/cli.mts'
10-
import { commonFlags, outputFlags } from '../../flags.mts'
4+
import { DRY_RUN_BAILING_NOW } from '../../constants/cli.mts'
5+
import { commonFlags } from '../../flags.mts'
116
import { meowOrExit } from '../../utils/cli/with-subcommands.mjs'
127
import { spawnSfw } from '../../utils/dlx/spawn.mjs'
138
import { getFlagApiRequirementsOutput } from '../../utils/output/formatting.mts'

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { NPX } from '@socketsecurity/lib/constants/agents'
22
import { getDefaultLogger } from '@socketsecurity/lib/logger'
33

4-
import {
5-
DRY_RUN_BAILING_NOW,
6-
FLAG_DRY_RUN,
7-
FLAG_HELP,
8-
} from '../../constants/cli.mts'
4+
import { DRY_RUN_BAILING_NOW } from '../../constants/cli.mts'
95
import { commonFlags } from '../../flags.mts'
106
import { meowOrExit } from '../../utils/cli/with-subcommands.mjs'
117
import { spawnSfw } from '../../utils/dlx/spawn.mjs'

packages/cli/src/utils/dlx/spawn.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
import {
3030
areExternalToolsAvailable,
3131
extractExternalTools,
32-
getToolPaths,
3332
} from './vfs-extract.mjs'
3433
import { getDefaultOrgSlug } from '../../commands/ci/fetch-default-org-slug.mjs'
3534
import ENV from '../../constants/env.mts'

packages/cli/src/utils/python/standalone.mts

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,6 @@ import { spawnNode } from '../spawn/spawn-node.mjs'
6060

6161
import type { CResult } from '../../types.mjs'
6262

63-
/**
64-
* SHA-256 checksums for Python 3.10.18+20250918 install_only builds.
65-
* Retrieved from: https://github.com/astral-sh/python-build-standalone/releases/tag/20250918
66-
*/
67-
const PYTHON_CHECKSUMS: Record<string, string> = {
68-
// @ts-expect-error - __proto__: null creates object without prototype.
69-
__proto__: null,
70-
'aarch64-apple-darwin':
71-
'5f2a620c5278967c7fe666c9d41dc5d653c1829b3c26f62ece0d818e1a5ff9f8',
72-
'aarch64-unknown-linux-gnu':
73-
'16cb27d4d4d03cfb68d55d64e83a96aa3cd93c002c1de8ab7ddf3aa867c9e5f0',
74-
'x86_64-apple-darwin':
75-
'4ee44bf41d06626ad2745375d690679587c12d375e41a78f857a9660ce88e255',
76-
'x86_64-pc-windows-msvc':
77-
'7f8b19397a39188d07c68d83fd88b8da35ef1e007bdb066ed86169d60539f644',
78-
'x86_64-unknown-linux-gnu':
79-
'a6b9950cee5467d3a0a35473b3e848377912616668968627ba2254e5da4a1d1e',
80-
}
81-
8263
/**
8364
* Get the download URL for python-build-standalone based on platform and architecture.
8465
*
@@ -205,39 +186,6 @@ export async function checkSystemPython(): Promise<string | null> {
205186
}
206187
}
207188

208-
/**
209-
* Get the checksum for the current platform's Python build.
210-
* Returns the SHA-256 checksum from PYTHON_CHECKSUMS map.
211-
*/
212-
function getPythonChecksum(): string {
213-
const platform = os.platform()
214-
const arch = os.arch()
215-
216-
let platformTriple: string
217-
218-
if (platform === 'darwin') {
219-
platformTriple =
220-
arch === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin'
221-
} else if (platform === 'linux') {
222-
platformTriple =
223-
arch === 'arm64'
224-
? 'aarch64-unknown-linux-gnu'
225-
: 'x86_64-unknown-linux-gnu'
226-
} else if (platform === 'win32') {
227-
platformTriple = 'x86_64-pc-windows-msvc'
228-
} else {
229-
throw new InputError(`Unsupported platform: ${platform}`)
230-
}
231-
232-
const checksum = PYTHON_CHECKSUMS[platformTriple]
233-
if (!checksum) {
234-
throw new InputError(
235-
`No checksum available for platform: ${platformTriple}`,
236-
)
237-
}
238-
239-
return checksum
240-
}
241189

242190
/**
243191
* Download and extract Python from python-build-standalone using downloadBinary.
@@ -246,17 +194,15 @@ function getPythonChecksum(): string {
246194
async function downloadPython(pythonDir: string): Promise<void> {
247195
const url = getPythonStandaloneUrl()
248196
const tarballName = 'python-standalone.tar.gz'
249-
const checksum = getPythonChecksum()
250197

251198
// Ensure directory exists.
252199
await safeMkdir(pythonDir, { recursive: true })
253200

254201
try {
255-
// Use downloadBinary to download the tarball with caching and checksum verification.
202+
// Use downloadBinary to download the tarball with caching.
256203
const result = await downloadBinary({
257204
url,
258205
name: tarballName,
259-
checksum,
260206
})
261207

262208
// Extract the tarball to pythonDir.

0 commit comments

Comments
 (0)