Skip to content

Commit 33c620c

Browse files
committed
Cleanup spinner wiring in fix command
1 parent 37f4577 commit 33c620c

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

src/commands/fix/agent-fix.mts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ import type { AlertsByPurl } from '../../utils/socket-package-alert.mts'
6060
import type { EditablePackageJson } from '@socketsecurity/registry/lib/packages'
6161
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
6262

63-
export type FixOptions = {
63+
export type FixConfig = {
6464
autoMerge: boolean
6565
cwd: string
6666
limit: number
6767
purls: string[]
6868
rangeStyle: RangeStyle
69-
spinner?: Spinner | undefined
69+
spinner: Spinner | undefined
7070
test: boolean
7171
testScript: string
7272
}
@@ -83,7 +83,7 @@ export type InstallPhaseHandler = (
8383
oldVersion: string,
8484
newVersion: string,
8585
vulnerableVersionRange: string,
86-
options: FixOptions,
86+
fixConfig: FixConfig,
8787
) => Promise<void>
8888

8989
export type Installer = (
@@ -110,11 +110,11 @@ export async function agentFix(
110110
},
111111
ciEnv: CiEnv | null,
112112
openPrs: PrMatch[],
113-
options: FixOptions,
113+
fixConfig: FixConfig,
114114
): Promise<CResult<{ fixed: boolean }>> {
115-
const { autoMerge, cwd, limit, rangeStyle, test, testScript } = options
116-
const { spinner } = constants
117115
const { pkgPath: rootPath } = pkgEnvDetails
116+
const { autoMerge, cwd, limit, rangeStyle, spinner, test, testScript } =
117+
fixConfig
118118

119119
let count = 0
120120

@@ -342,7 +342,7 @@ export async function agentFix(
342342
oldVersion,
343343
newVersion,
344344
vulnerableVersionRange,
345-
options,
345+
fixConfig,
346346
)
347347
updatePackageJsonFromNode(
348348
editablePkgJson,
@@ -393,7 +393,7 @@ export async function agentFix(
393393
oldVersion,
394394
newVersion,
395395
vulnerableVersionRange,
396-
options,
396+
fixConfig,
397397
)
398398
if (test) {
399399
spinner?.info(`Testing ${newId} in ${workspace}.`)
@@ -574,7 +574,7 @@ export async function agentFix(
574574
oldVersion,
575575
newVersion,
576576
vulnerableVersionRange,
577-
options,
577+
fixConfig,
578578
)
579579
// eslint-disable-next-line no-await-in-loop
580580
await Promise.all([

src/commands/fix/cmd-fix.mts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async function run(
126126
json: boolean
127127
markdown: boolean
128128
}
129+
129130
const outputKind = getOutputKind(json, markdown)
130131

131132
let rangeStyle = cli.flags['rangeStyle'] as RangeStyle
@@ -148,6 +149,10 @@ async function run(
148149
return
149150
}
150151

152+
// Lazily access constants.spinner.
153+
const { spinner } = constants
154+
const { unknownFlags } = cli
155+
151156
let [cwd = '.'] = cli.input
152157
// Note: path.resolve vs .join:
153158
// If given path is absolute then cwd should not affect it.
@@ -167,7 +172,6 @@ async function run(
167172
: Infinity) || Infinity
168173
const purls = cmdFlagValueToArray(cli.flags['purl'])
169174
const testScript = String(cli.flags['testScript'] || 'test')
170-
const { unknownFlags } = cli
171175

172176
await handleFix({
173177
autoMerge,
@@ -177,6 +181,7 @@ async function run(
177181
outputKind,
178182
purls,
179183
rangeStyle,
184+
spinner,
180185
test,
181186
testScript,
182187
unknownFlags,

src/commands/fix/handle-fix.mts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { cmdFlagValueToArray } from '../../utils/cmd.mts'
1111
import { spawnCoana } from '../../utils/coana.mts'
1212
import { detectAndValidatePackageEnvironment } from '../../utils/package-environment.mts'
1313

14-
import type { FixOptions } from './agent-fix.mts'
14+
import type { FixConfig } from './agent-fix.mts'
1515
import type { OutputKind } from '../../types.mts'
1616
import type { Remap } from '@socketsecurity/registry/lib/objects'
1717

1818
const { NPM, PNPM } = constants
1919

20-
export type HandleFixOptions = Remap<
21-
FixOptions & {
20+
export type HandleFixConfig = Remap<
21+
FixConfig & {
2222
ghsas: string[]
2323
outputKind: OutputKind
2424
unknownFlags: string[]
@@ -33,24 +33,22 @@ export async function handleFix({
3333
outputKind,
3434
purls,
3535
rangeStyle,
36+
spinner,
3637
test,
3738
testScript,
3839
unknownFlags,
39-
}: HandleFixOptions) {
40-
// Lazily access constants.spinner.
41-
const { spinner } = constants
42-
40+
}: HandleFixConfig) {
4341
let { length: ghsasCount } = ghsas
4442
if (ghsasCount) {
45-
spinner.start('Fetching GHSA IDs...')
43+
spinner?.start('Fetching GHSA IDs...')
4644

4745
if (ghsasCount === 1 && ghsas[0] === 'auto') {
4846
const autoCResult = await spawnCoana(
4947
['compute-fixes-and-upgrade-purls', cwd],
5048
{ cwd, spinner },
5149
)
5250

53-
spinner.stop()
51+
spinner?.stop()
5452

5553
if (autoCResult.ok) {
5654
ghsas = cmdFlagValueToArray(
@@ -68,11 +66,11 @@ export async function handleFix({
6866
ghsasCount = 0
6967
}
7068

71-
spinner.start()
69+
spinner?.start()
7270
}
7371

7472
if (ghsasCount) {
75-
spinner.info(`Found ${ghsasCount} GHSA ${pluralize('ID', ghsasCount)}.`)
73+
spinner?.info(`Found ${ghsasCount} GHSA ${pluralize('ID', ghsasCount)}.`)
7674

7775
const applyFixesCResult = await spawnCoana(
7876
[
@@ -85,7 +83,7 @@ export async function handleFix({
8583
{ cwd, spinner },
8684
)
8785

88-
spinner.stop()
86+
spinner?.stop()
8987

9088
if (!applyFixesCResult.ok) {
9189
debugFn('coana fail:', {
@@ -98,7 +96,7 @@ export async function handleFix({
9896
return
9997
}
10098

101-
spinner.infoAndStop('No GHSA IDs found.')
99+
spinner?.infoAndStop('No GHSA IDs found.')
102100

103101
await outputFixResult(
104102
{

src/commands/fix/npm-fix.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getAlertsMapFromArborist } from '../../shadow/npm/arborist-helpers.mts'
2424
import { runAgentInstall } from '../../utils/agent.mts'
2525
import { getAlertsMapFromPurls } from '../../utils/alerts-map.mts'
2626

27-
import type { FixOptions, InstallOptions } from './agent-fix.mts'
27+
import type { FixConfig, InstallOptions } from './agent-fix.mts'
2828
import type {
2929
ArboristOptions,
3030
NodeClass,
@@ -54,9 +54,9 @@ async function install(
5454

5555
export async function npmFix(
5656
pkgEnvDetails: EnvDetails,
57-
options: FixOptions,
57+
fixConfig: FixConfig,
5858
): Promise<CResult<{ fixed: boolean }>> {
59-
const { limit, purls, spinner } = options
59+
const { limit, purls, spinner } = fixConfig
6060

6161
spinner?.start()
6262

@@ -150,6 +150,6 @@ export async function npmFix(
150150
},
151151
ciEnv,
152152
openPrs,
153-
options,
153+
fixConfig,
154154
)
155155
}

src/commands/fix/pnpm-fix.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { applyRange } from '../../utils/semver.mts'
2323
import { getOverridesDataPnpm } from '../optimize/get-overrides-by-agent.mts'
2424

25-
import type { FixOptions, InstallOptions } from './agent-fix.mts'
25+
import type { FixConfig, InstallOptions } from './agent-fix.mts'
2626
import type { NodeClass } from '../../shadow/npm/arborist/types.mts'
2727
import type { CResult, StringKeyValueObject } from '../../types.mts'
2828
import type { EnvDetails } from '../../utils/package-environment.mts'
@@ -59,9 +59,9 @@ async function install(
5959

6060
export async function pnpmFix(
6161
pkgEnvDetails: EnvDetails,
62-
options: FixOptions,
62+
fixConfig: FixConfig,
6363
): Promise<CResult<{ fixed: boolean }>> {
64-
const { cwd, limit, purls, spinner } = options
64+
const { cwd, limit, purls, spinner } = fixConfig
6565

6666
spinner?.start()
6767

@@ -229,6 +229,6 @@ export async function pnpmFix(
229229
},
230230
ciEnv,
231231
openPrs,
232-
options,
232+
fixConfig,
233233
)
234234
}

0 commit comments

Comments
 (0)