Skip to content

Commit 94350fd

Browse files
committed
fix(cli): resolve TypeScript strict mode errors
Fix TypeScript compilation errors across patch, scan, and util modules: Spinner type fixes: - Update handler interfaces to accept `Spinner | null` instead of `Spinner` - Add optional chaining (`?.`) for all spinner method calls - Convert `Spinner | null` to `Spinner | undefined` where needed Process.env fixes: - Use bracket notation for environment variable access (`process.env['VITEST']` instead of `process.env.VITEST`) - Fixes index signature violations in interactive-help.mts and with-subcommands.mts Optional models fixes: - Add type cast through `unknown` for MODEL_REGISTRY indexing - Use conditional spread for optional checksum parameter These fixes enable strict TypeScript checking without compromising functionality.
1 parent f4d9a49 commit 94350fd

13 files changed

+41
-40
lines changed

packages/cli/src/commands/patch/handle-patch-apply.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ async function applyNpmPatches(
196196
logger.groupEnd()
197197

198198
if (wasSpinning) {
199-
spinner.start()
199+
spinner?.start()
200200
}
201201
return result
202202
}
@@ -388,7 +388,7 @@ export interface HandlePatchApplyConfig {
388388
dryRun: boolean
389389
outputKind: OutputKind
390390
purlObjs: PackageURL[]
391-
spinner: Spinner
391+
spinner: Spinner | null
392392
}
393393

394394
export async function handlePatchApply({
@@ -437,9 +437,9 @@ export async function handlePatchApply({
437437
purls.length > 3
438438
? `${purls.slice(0, 3).join(', ')} … and ${purls.length - 3} more`
439439
: joinAnd(purls)
440-
spinner.start(`Checking patches for: ${displayPurls}`)
440+
spinner?.start(`Checking patches for: ${displayPurls}`)
441441
} else {
442-
spinner.start('Scanning all dependencies for available patches')
442+
spinner?.start('Scanning all dependencies for available patches')
443443
}
444444

445445
const patched = []
@@ -453,7 +453,7 @@ export async function handlePatchApply({
453453
cwd,
454454
dryRun,
455455
purlObjs,
456-
spinner,
456+
spinner: spinner ?? undefined,
457457
},
458458
)
459459
patched.push(...patchingResults.passed)
@@ -491,7 +491,7 @@ export async function handlePatchApply({
491491
}
492492
}
493493

494-
spinner.stop()
494+
spinner?.stop()
495495

496496
await outputPatchResult(
497497
{
@@ -503,7 +503,7 @@ export async function handlePatchApply({
503503
outputKind,
504504
)
505505
} catch (e) {
506-
spinner.stop()
506+
spinner?.stop()
507507

508508
let message = 'Failed to apply patches'
509509
let cause = getErrorCause(e)

packages/cli/src/commands/patch/handle-patch-cleanup.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface HandlePatchCleanupConfig {
2929
all: boolean
3030
cwd: string
3131
outputKind: OutputKind
32-
spinner: Spinner
32+
spinner: Spinner | null
3333
uuid: string | undefined
3434
}
3535

packages/cli/src/commands/patch/handle-patch-download.mts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export type HandlePatchDownloadConfig = {
5252
cwd: string
5353
outputKind: OutputKind
5454
scanId?: string
55-
spinner: Spinner
55+
spinner: Spinner | null
5656
uuids: string[]
5757
}
5858

@@ -124,7 +124,7 @@ export async function handlePatchDownload({
124124
// Setup SDK.
125125
const sdkResult = await setupSdk()
126126
if (!sdkResult.ok) {
127-
spinner.failAndStop('Failed to initialize Socket SDK')
127+
spinner?.failAndStop('Failed to initialize Socket SDK')
128128
await outputPatchDownloadResult(
129129
{
130130
ok: false,
@@ -141,7 +141,7 @@ export async function handlePatchDownload({
141141
// Get organization slug.
142142
const orgSlug = await getOrgSlug(sdk)
143143
if (!orgSlug) {
144-
spinner.failAndStop('Failed to determine organization')
144+
spinner?.failAndStop('Failed to determine organization')
145145

146146
// Check if SOCKET_CLI_API_TOKEN is set to provide helpful guidance.
147147
const hasEnvToken = !!ENV.SOCKET_CLI_API_TOKEN
@@ -164,10 +164,10 @@ export async function handlePatchDownload({
164164
let patchUuids = uuids
165165

166166
if (scanId) {
167-
spinner.start('Fetching patches from scan...')
167+
spinner?.start('Fetching patches from scan...')
168168
const scanUuids = await collectPatchesFromScan(sdk, orgSlug, scanId)
169169
if (!scanUuids.length) {
170-
spinner.failAndStop('No patches found in scan')
170+
spinner?.failAndStop('No patches found in scan')
171171
await outputPatchDownloadResult(
172172
{
173173
ok: false,
@@ -179,13 +179,13 @@ export async function handlePatchDownload({
179179
return
180180
}
181181
patchUuids = scanUuids
182-
spinner.successAndStop(
182+
spinner?.successAndStop(
183183
`Found ${patchUuids.length} ${pluralize('patch', { count: patchUuids.length })} in scan`,
184184
)
185185
}
186186

187187
if (!patchUuids.length) {
188-
spinner.failAndStop('No patches to download')
188+
spinner?.failAndStop('No patches to download')
189189
await outputPatchDownloadResult(
190190
{
191191
ok: false,
@@ -205,7 +205,7 @@ export async function handlePatchDownload({
205205

206206
for (const uuid of patchUuids) {
207207
try {
208-
spinner.start(`Downloading patch ${uuid}...`)
208+
spinner?.start(`Downloading patch ${uuid}...`)
209209
// eslint-disable-next-line no-await-in-loop
210210
await downloadPatch(sdk, orgSlug, uuid, cwd)
211211
// eslint-disable-next-line no-await-in-loop
@@ -214,9 +214,9 @@ export async function handlePatchDownload({
214214
purl: patchDetails.purl,
215215
uuid,
216216
})
217-
spinner.successAndStop(`Downloaded patch ${uuid}`)
217+
spinner?.successAndStop(`Downloaded patch ${uuid}`)
218218
} catch (e: any) {
219-
spinner.failAndStop(`Failed to download patch ${uuid}`)
219+
spinner?.failAndStop(`Failed to download patch ${uuid}`)
220220
results.failed.push({
221221
error: e.message,
222222
uuid,

packages/cli/src/commands/patch/handle-patch-get.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface HandlePatchGetConfig {
2929
outputDir: string | undefined
3030
outputKind: OutputKind
3131
purl: string
32-
spinner: Spinner
32+
spinner: Spinner | null
3333
}
3434

3535
export async function handlePatchGet({

packages/cli/src/commands/patch/handle-patch-info.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface HandlePatchInfoConfig {
3333
cwd: string
3434
outputKind: OutputKind
3535
purl: string
36-
spinner: Spinner
36+
spinner: Spinner | null
3737
}
3838

3939
export async function handlePatchInfo({

packages/cli/src/commands/patch/handle-patch-list.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface HandlePatchListConfig {
3737
cwd: string
3838
interactive: boolean
3939
outputKind: OutputKind
40-
spinner: Spinner
40+
spinner: Spinner | null
4141
}
4242

4343
export async function handlePatchList({

packages/cli/src/commands/patch/handle-patch-rm.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface HandlePatchRmConfig {
3434
keepBackups: boolean
3535
outputKind: OutputKind
3636
purl: string
37-
spinner: Spinner
37+
spinner: Spinner | null
3838
}
3939

4040
export async function handlePatchRm({

packages/cli/src/commands/patch/handle-patch-status.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface HandlePatchStatusConfig {
4343
failed: boolean
4444
}
4545
outputKind: OutputKind
46-
spinner: Spinner
46+
spinner: Spinner | null
4747
}
4848

4949
/**
@@ -188,7 +188,7 @@ export async function handlePatchStatus({
188188
spinner,
189189
}: HandlePatchStatusConfig): Promise<void> {
190190
try {
191-
spinner.start('Reading patch manifest')
191+
spinner?.start('Reading patch manifest')
192192

193193
const dotSocketDirPath = normalizePath(path.join(cwd, DOT_SOCKET_DIR))
194194
const manifestPath = normalizePath(
@@ -198,7 +198,7 @@ export async function handlePatchStatus({
198198
const manifestData = JSON.parse(manifestContent)
199199
const validated = PatchManifestSchema.parse(manifestData)
200200

201-
spinner.text('Checking patch status')
201+
spinner?.start('Checking patch status')
202202

203203
const statuses: PatchStatus[] = []
204204

@@ -224,7 +224,7 @@ export async function handlePatchStatus({
224224
})
225225
}
226226

227-
spinner.stop()
227+
spinner?.stop()
228228

229229
// Apply filters.
230230
let filteredStatuses = statuses
@@ -257,7 +257,7 @@ export async function handlePatchStatus({
257257
outputKind,
258258
)
259259
} catch (e) {
260-
spinner.stop()
260+
spinner?.stop()
261261

262262
let message = 'Failed to get patch status'
263263
let cause = getErrorCause(e)

packages/cli/src/commands/scan/handle-create-new-scan.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function handleCreateNewScan({
104104
}
105105

106106
const spinner = getSpinner()
107-
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
107+
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner: spinner ?? undefined })
108108
if (!supportedFilesCResult.ok) {
109109
debug('Failed to fetch supported scan file names')
110110
debugDir({ supportedFilesCResult })
@@ -164,7 +164,7 @@ export async function handleCreateNewScan({
164164
packagePaths,
165165
reachabilityOptions: reach,
166166
repoName,
167-
spinner,
167+
spinner: spinner ?? undefined,
168168
})
169169

170170
spinner?.stop()
@@ -247,7 +247,7 @@ export async function handleCreateNewScan({
247247
)
248248
}
249249
} else {
250-
spinner.stop()
250+
spinner?.stop()
251251

252252
await outputCreateNewScan(fullScanCResult, { interactive, outputKind })
253253
}

packages/cli/src/commands/scan/handle-scan-reach.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function handleScanReach({
3333
const spinner = getSpinner()
3434

3535
// Get supported file names
36-
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
36+
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner: spinner ?? undefined })
3737
if (!supportedFilesCResult.ok) {
3838
await outputScanReach(supportedFilesCResult, {
3939
cwd,
@@ -79,11 +79,11 @@ export async function handleScanReach({
7979
outputPath,
8080
packagePaths,
8181
reachabilityOptions,
82-
spinner,
82+
spinner: spinner ?? undefined,
8383
uploadManifests: true,
8484
})
8585

86-
spinner.stop()
86+
spinner?.stop()
8787

8888
await outputScanReach(result, { cwd, outputKind, outputPath })
8989
}

0 commit comments

Comments
 (0)