Skip to content

Commit 678554b

Browse files
committed
feat(fix): add --fix-version flag to override Coana CLI version
Ported from v1.x commit eeeb240 (#957) - Add --fix-version flag to override default @coana-tech/cli version - Add CoanaDlxOptions type extending DlxOptions with coanaVersion - Update spawnCoanaDlx to accept and use coanaVersion parameter - Pass coanaVersion through cmd-fix -> handle-fix -> coana-fix -> spawnCoanaDlx - Update all spawnCoanaDlx calls in coana-fix.mts to pass coanaVersion - Update test fixtures to include coanaVersion parameter Based on PR #957
1 parent 5b24343 commit 678554b

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { arrayUnique, joinAnd, joinOr } from '@socketsecurity/lib/arrays'
66
import { getDefaultLogger } from '@socketsecurity/lib/logger'
77

88
import { handleFix } from './handle-fix.mts'
9+
import * as constants from '../../constants.mts'
910
import { DRY_RUN_NOT_SAVING, FLAG_ID } from '../../constants/cli.mts'
1011
import { ERROR_UNABLE_RESOLVE_ORG } from '../../constants/errors.mts'
1112
import { commonFlags, outputFlags } from '../../flags.mts'
@@ -90,6 +91,10 @@ const generalFlags: MeowFlags = {
9091
'Limit fix analysis to specific ecosystems. Can be provided as comma separated values or as multiple flags. Defaults to all ecosystems.',
9192
isMultiple: true,
9293
},
94+
fixVersion: {
95+
type: 'string',
96+
description: `Override the version of @coana-tech/cli used for fix analysis. Default: ${constants.ENV.INLINED_SOCKET_CLI_COANA_VERSION}.`,
97+
},
9398
id: {
9499
type: 'string',
95100
default: [],
@@ -279,6 +284,7 @@ async function run(
279284
autopilot,
280285
ecosystems,
281286
exclude,
287+
fixVersion,
282288
include,
283289
json,
284290
majorUpdates,
@@ -299,6 +305,7 @@ async function run(
299305
autopilot: boolean
300306
ecosystems: string[]
301307
exclude: string[]
308+
fixVersion: string | undefined
302309
include: string[]
303310
json: boolean
304311
majorUpdates: boolean
@@ -400,6 +407,7 @@ async function run(
400407
all,
401408
applyFixes,
402409
autopilot,
410+
coanaVersion: fixVersion,
403411
cwd,
404412
disableMajorUpdates,
405413
ecosystems: validatedEcosystems,

packages/cli/src/commands/fix/coana-fix.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export async function coanaFix(
7474
all,
7575
applyFixes,
7676
autopilot,
77+
coanaVersion,
7778
cwd,
7879
disableMajorUpdates,
7980
ecosystems,
@@ -217,7 +218,7 @@ export async function coanaFix(
217218
...fixConfig.unknownFlags,
218219
],
219220
fixConfig.orgSlug,
220-
{ cwd, spinner, stdio: coanaStdio },
221+
{ coanaVersion, cwd, spinner, stdio: coanaStdio },
221222
)
222223

223224
spinner?.stop()
@@ -300,7 +301,7 @@ export async function coanaFix(
300301
...fixConfig.unknownFlags,
301302
],
302303
fixConfig.orgSlug,
303-
{ cwd, spinner, stdio: coanaStdio },
304+
{ coanaVersion, cwd, spinner, stdio: coanaStdio },
304305
)
305306

306307
if (discoverCResult.ok) {
@@ -423,7 +424,7 @@ export async function coanaFix(
423424
...fixConfig.unknownFlags,
424425
],
425426
fixConfig.orgSlug,
426-
{ cwd, spinner, stdio: coanaStdio },
427+
{ coanaVersion, cwd, spinner, stdio: coanaStdio },
427428
)
428429

429430
if (!fixCResult.ok) {

packages/cli/src/commands/fix/handle-fix.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export async function handleFix({
106106
all,
107107
applyFixes,
108108
autopilot,
109+
coanaVersion,
109110
cwd,
110111
disableMajorUpdates,
111112
ecosystems,
@@ -129,6 +130,7 @@ export async function handleFix({
129130
all,
130131
applyFixes,
131132
autopilot,
133+
coanaVersion,
132134
cwd,
133135
disableMajorUpdates,
134136
ecosystems,
@@ -151,6 +153,7 @@ export async function handleFix({
151153
all,
152154
applyFixes,
153155
autopilot,
156+
coanaVersion,
154157
cwd,
155158
disableMajorUpdates,
156159
ecosystems,

packages/cli/src/commands/fix/types.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type FixConfig = {
77
all: boolean
88
applyFixes: boolean
99
autopilot: boolean
10+
coanaVersion: string | undefined
1011
cwd: string
1112
disableMajorUpdates: boolean
1213
ecosystems: PURL_Type[]

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export type DlxOptions = ShadowBinOptions & {
3636
silent?: boolean | undefined
3737
}
3838

39+
export type CoanaDlxOptions = DlxOptions & {
40+
coanaVersion?: string | undefined
41+
}
42+
3943
export type DlxPackageSpec = {
4044
binaryName?: string | undefined
4145
name: string
@@ -110,13 +114,13 @@ export async function spawnDlx(
110114
export async function spawnCoanaDlx(
111115
args: string[] | readonly string[],
112116
orgSlug?: string,
113-
options?: DlxOptions | undefined,
117+
options?: CoanaDlxOptions | undefined,
114118
spawnExtra?: SpawnExtra | undefined,
115119
): Promise<CResult<string>> {
116-
const { env: spawnEnv, ...dlxOptions } = {
120+
const { coanaVersion, env: spawnEnv, ...dlxOptions } = {
117121
__proto__: null,
118122
...options,
119-
} as DlxOptions
123+
} as CoanaDlxOptions
120124

121125
const mixinsEnv: Record<string, string> = {
122126
SOCKET_CLI_VERSION: ENV.INLINED_SOCKET_CLI_VERSION || '',
@@ -174,7 +178,10 @@ export async function spawnCoanaDlx(
174178

175179
// Use dlx version.
176180
const result = await spawnDlx(
177-
resolution.details,
181+
{
182+
...resolution.details,
183+
version: coanaVersion || resolution.details.version,
184+
},
178185
args,
179186
{
180187
force: true,

packages/cli/test/unit/commands/fix/handle-fix-limit.test.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ describe('socket fix --limit behavior verification', () => {
126126
all: false,
127127
applyFixes: true,
128128
autopilot: false,
129+
coanaVersion: undefined,
129130
cwd: '/test/cwd',
130131
disableMajorUpdates: false,
131132
ecosystems: [],

0 commit comments

Comments
 (0)