Skip to content

Commit 2c7078f

Browse files
mtorpjdalton
authored andcommitted
add --no-major-updates and --show-affected-direct-dependencies flags
1 parent d9ea29b commit 2c7078f

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

src/commands/fix/cmd-fix.mts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ const generalFlags: MeowFlags = {
6161
// Hidden to allow custom documenting of the negated `--no-apply-fixes` variant.
6262
hidden: true,
6363
},
64+
majorUpdates: {
65+
type: 'boolean',
66+
default: true,
67+
description:
68+
'Allow major version updates. Use --no-major-updates to disable.',
69+
// Hidden to allow custom documenting of the negated `--no-major-updates` variant.
70+
hidden: true,
71+
},
6472
id: {
6573
type: 'string',
6674
default: [],
@@ -106,6 +114,12 @@ Available styles:
106114
description:
107115
'Set a minimum age requirement for suggested upgrade versions (e.g., 1h, 2d, 3w). A higher age requirement reduces the risk of upgrading to malicious versions. For example, setting the value to 1 week (1w) gives ecosystem maintainers one week to remove potentially malicious versions.',
108116
},
117+
showAffectedDirectDependencies: {
118+
type: 'boolean',
119+
default: false,
120+
description:
121+
'List the direct dependencies responsible for introducing transitive vulnerabilities and list the updates required to resolve the vulnerabilities',
122+
},
109123
}
110124

111125
const hiddenFlags: MeowFlags = {
@@ -197,6 +211,13 @@ async function run(
197211
...config.flags['applyFixes'],
198212
hidden: false,
199213
} as MeowFlag,
214+
// Explicitly document the negated --no-major-updates variant.
215+
noMajorUpdates: {
216+
...config.flags['majorUpdates'],
217+
description:
218+
'Do not suggest or apply fixes that require major version updates of direct or transitive dependencies',
219+
hidden: false,
220+
} as MeowFlag,
200221
})}
201222
202223
Environment Variables (for CI/PR mode)
@@ -228,12 +249,14 @@ async function run(
228249
glob,
229250
json,
230251
limit,
252+
majorUpdates,
231253
markdown,
232254
maxSatisfying,
233255
minimumReleaseAge,
234256
outputFile,
235257
prCheck,
236258
rangeStyle,
259+
showAffectedDirectDependencies,
237260
// We patched in this feature with `npx custompatch meow` at
238261
// socket-cli/patches/meow#13.2.0.patch.
239262
unknownFlags = [],
@@ -243,11 +266,13 @@ async function run(
243266
glob: string
244267
limit: number
245268
json: boolean
269+
majorUpdates: boolean
246270
markdown: boolean
247271
maxSatisfying: boolean
248272
minSatisfying: boolean
249273
prCheck: boolean
250274
rangeStyle: RangeStyle
275+
showAffectedDirectDependencies: boolean
251276
unknownFlags?: string[]
252277
outputFile: string
253278
minimumReleaseAge: string
@@ -258,6 +283,8 @@ async function run(
258283
const minSatisfying =
259284
(cli.flags['minSatisfying'] as boolean) || !maxSatisfying
260285

286+
const disableMajorUpdates = !majorUpdates
287+
261288
const outputKind = getOutputKind(json, markdown)
262289

263290
const wasValidInput = checkCommandInput(
@@ -311,6 +338,7 @@ async function run(
311338
autopilot,
312339
applyFixes,
313340
cwd,
341+
disableMajorUpdates,
314342
ghsas,
315343
glob,
316344
limit,
@@ -320,6 +348,7 @@ async function run(
320348
orgSlug,
321349
outputKind,
322350
rangeStyle,
351+
showAffectedDirectDependencies,
323352
spinner,
324353
unknownFlags,
325354
outputFile,

src/commands/fix/cmd-fix.test.mts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ describe('socket fix', async () => {
182182
--markdown Output as Markdown
183183
--minimum-release-age Set a minimum age requirement for suggested upgrade versions (e.g., 1h, 2d, 3w). A higher age requirement reduces the risk of upgrading to malicious versions. For example, setting the value to 1 week (1w) gives ecosystem maintainers one week to remove potentially malicious versions.
184184
--no-apply-fixes 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.
185+
--no-major-updates Do not suggest or apply fixes that require major version updates of direct or transitive dependencies
185186
--output-file Path to store upgrades as a JSON file at this path.
186187
--range-style Define how dependency version ranges are updated in package.json (default 'preserve').
187188
Available styles:
188189
* pin - Use the exact version (e.g. 1.2.3)
189190
* preserve - Retain the existing version range style as-is
191+
--show-affected-direct-dependencies List the direct dependencies responsible for introducing transitive vulnerabilities and list the updates required to resolve the vulnerabilities
190192
191193
Environment Variables (for CI/PR mode)
192194
CI Set to enable CI mode
@@ -377,6 +379,57 @@ describe('socket fix', async () => {
377379
},
378380
)
379381

382+
cmdit(
383+
[
384+
'fix',
385+
FLAG_DRY_RUN,
386+
'--no-major-updates',
387+
FLAG_CONFIG,
388+
'{"apiToken":"fakeToken"}',
389+
],
390+
'should accept --no-major-updates flag',
391+
async cmd => {
392+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
393+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Not saving"`)
394+
expect(code, 'should exit with code 0').toBe(0)
395+
},
396+
)
397+
398+
cmdit(
399+
[
400+
'fix',
401+
FLAG_DRY_RUN,
402+
'--show-affected-direct-dependencies',
403+
FLAG_CONFIG,
404+
'{"apiToken":"fakeToken"}',
405+
],
406+
'should accept --show-affected-direct-dependencies flag',
407+
async cmd => {
408+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
409+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Not saving"`)
410+
expect(code, 'should exit with code 0').toBe(0)
411+
},
412+
)
413+
414+
cmdit(
415+
[
416+
'fix',
417+
FLAG_DRY_RUN,
418+
'--no-major-updates',
419+
'--show-affected-direct-dependencies',
420+
'--limit',
421+
'5',
422+
FLAG_CONFIG,
423+
'{"apiToken":"fakeToken"}',
424+
],
425+
'should accept new flags in combination',
426+
async cmd => {
427+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
428+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Not saving"`)
429+
expect(code, 'should exit with code 0').toBe(0)
430+
},
431+
)
432+
380433
cmdit(
381434
[
382435
'fix',

src/commands/fix/coana-fix.mts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ export async function coanaFix(
4646
applyFixes,
4747
autopilot,
4848
cwd,
49+
disableMajorUpdates,
4950
ghsas,
5051
glob,
5152
limit,
5253
minimumReleaseAge,
5354
orgSlug,
5455
outputFile,
56+
showAffectedDirectDependencies,
5557
spinner,
5658
} = fixConfig
5759

@@ -149,6 +151,10 @@ export async function coanaFix(
149151
...(glob ? ['--glob', glob] : []),
150152
...(!applyFixes ? [FLAG_DRY_RUN] : []),
151153
...(outputFile ? ['--output-file', outputFile] : []),
154+
...(disableMajorUpdates ? ['--disable-major-updates'] : []),
155+
...(showAffectedDirectDependencies
156+
? ['--show-affected-direct-dependencies']
157+
: []),
152158
...fixConfig.unknownFlags,
153159
],
154160
fixConfig.orgSlug,
@@ -202,6 +208,10 @@ export async function coanaFix(
202208
? ['--minimum-release-age', minimumReleaseAge]
203209
: []),
204210
...(glob ? ['--glob', glob] : []),
211+
...(disableMajorUpdates ? ['--disable-major-updates'] : []),
212+
...(showAffectedDirectDependencies
213+
? ['--show-affected-direct-dependencies']
214+
: []),
205215
...fixConfig.unknownFlags,
206216
],
207217
fixConfig.orgSlug,
@@ -262,6 +272,10 @@ export async function coanaFix(
262272
? ['--minimum-release-age', minimumReleaseAge]
263273
: []),
264274
...(glob ? ['--glob', glob] : []),
275+
...(disableMajorUpdates ? ['--disable-major-updates'] : []),
276+
...(showAffectedDirectDependencies
277+
? ['--show-affected-direct-dependencies']
278+
: []),
265279
...fixConfig.unknownFlags,
266280
],
267281
fixConfig.orgSlug,

src/commands/fix/handle-fix.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export async function handleFix({
102102
applyFixes,
103103
autopilot,
104104
cwd,
105+
disableMajorUpdates,
105106
ghsas,
106107
glob,
107108
limit,
@@ -112,13 +113,15 @@ export async function handleFix({
112113
outputKind,
113114
prCheck,
114115
rangeStyle,
116+
showAffectedDirectDependencies,
115117
spinner,
116118
unknownFlags,
117119
}: HandleFixConfig) {
118120
debugFn('notice', `Starting fix command for ${orgSlug}`)
119121
debugDir('inspect', {
120122
autopilot,
121123
cwd,
124+
disableMajorUpdates,
122125
ghsas,
123126
glob,
124127
limit,
@@ -128,6 +131,7 @@ export async function handleFix({
128131
outputKind,
129132
prCheck,
130133
rangeStyle,
134+
showAffectedDirectDependencies,
131135
unknownFlags,
132136
})
133137

@@ -136,6 +140,7 @@ export async function handleFix({
136140
autopilot,
137141
applyFixes,
138142
cwd,
143+
disableMajorUpdates,
139144
// Convert mixed CVE/GHSA/PURL inputs to GHSA IDs only
140145
ghsas: await convertIdsToGhsas(ghsas),
141146
glob,
@@ -145,6 +150,7 @@ export async function handleFix({
145150
orgSlug,
146151
prCheck,
147152
rangeStyle,
153+
showAffectedDirectDependencies,
148154
spinner,
149155
unknownFlags,
150156
outputFile,

src/commands/fix/types.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type FixConfig = {
55
autopilot: boolean
66
applyFixes: boolean
77
cwd: string
8+
disableMajorUpdates: boolean
89
ghsas: string[]
910
glob: string
1011
limit: number
@@ -13,6 +14,7 @@ export type FixConfig = {
1314
orgSlug: string
1415
prCheck: boolean
1516
rangeStyle: RangeStyle
17+
showAffectedDirectDependencies: boolean
1618
spinner: Spinner | undefined
1719
unknownFlags: string[]
1820
outputFile: string

0 commit comments

Comments
 (0)