Skip to content

Commit c4433be

Browse files
barslevjdalton
authored andcommitted
Add --output-file and --compute-fixes-only to socket fix
1 parent a1bf8ef commit c4433be

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/commands/fix/cmd-fix.mts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ Available styles:
8383
* preserve - Retain the existing version range style as-is
8484
`.trim(),
8585
},
86+
outputFile: {
87+
type: 'string',
88+
default: '',
89+
description: 'Path to store result as json.',
90+
},
91+
computeFixesOnly: {
92+
type: 'boolean',
93+
default: false,
94+
description:
95+
'Compute fixes only, do not apply them. Logs what upgrades would be applied. If combined with --output-file, the output file will contain the upgrades that would be applied.',
96+
},
8697
}
8798

8899
const hiddenFlags: MeowFlags = {
@@ -188,6 +199,8 @@ async function run(
188199
// We patched in this feature with `npx custompatch meow` at
189200
// socket-cli/patches/meow#13.2.0.patch.
190201
unknownFlags = [],
202+
outputFile,
203+
computeFixesOnly,
191204
} = cli.flags as {
192205
autopilot: boolean
193206
limit: number
@@ -198,6 +211,8 @@ async function run(
198211
prCheck: boolean
199212
rangeStyle: RangeStyle
200213
unknownFlags?: string[]
214+
outputFile: string
215+
computeFixesOnly: boolean
201216
}
202217

203218
const dryRun = !!cli.flags['dryRun']
@@ -266,5 +281,7 @@ async function run(
266281
rangeStyle,
267282
spinner,
268283
unknownFlags,
284+
computeFixesOnly,
285+
outputFile,
269286
})
270287
}

src/commands/fix/coana-fix.mts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ import type { CResult } from '../../types.mts'
3737
export async function coanaFix(
3838
fixConfig: FixConfig,
3939
): Promise<CResult<{ fixed: boolean }>> {
40-
const { autopilot, cwd, ghsas, limit, orgSlug, spinner } = fixConfig
40+
const {
41+
autopilot,
42+
cwd,
43+
ghsas,
44+
limit,
45+
orgSlug,
46+
spinner,
47+
computeFixesOnly,
48+
outputFile,
49+
} = fixConfig
4150

4251
const fixEnv = await getFixEnv()
4352
debugDir('inspect', { fixEnv })
@@ -108,6 +117,8 @@ export async function coanaFix(
108117
? ['--range-style', fixConfig.rangeStyle]
109118
: []),
110119
...fixConfig.unknownFlags,
120+
...(computeFixesOnly ? ['--dry-run'] : []),
121+
...(outputFile ? ['--output-file', outputFile] : []),
111122
],
112123
fixConfig.orgSlug,
113124
{ cwd, spinner, stdio: 'inherit' },

src/commands/fix/handle-fix.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type HandleFixConfig = Remap<
1818
orgSlug: string
1919
outputKind: OutputKind
2020
unknownFlags: string[]
21+
computeFixesOnly: boolean
22+
outputFile: string
2123
}
2224
>
2325

@@ -97,6 +99,8 @@ export async function handleFix({
9799
rangeStyle,
98100
spinner,
99101
unknownFlags,
102+
computeFixesOnly,
103+
outputFile,
100104
}: HandleFixConfig) {
101105
await outputFixResult(
102106
await coanaFix({
@@ -111,6 +115,8 @@ export async function handleFix({
111115
rangeStyle,
112116
spinner,
113117
unknownFlags,
118+
computeFixesOnly,
119+
outputFile,
114120
}),
115121
outputKind,
116122
)

src/commands/fix/types.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ export type FixConfig = {
1212
rangeStyle: RangeStyle
1313
spinner: Spinner | undefined
1414
unknownFlags: string[]
15+
computeFixesOnly: boolean
16+
outputFile: string
1517
}

0 commit comments

Comments
 (0)