1+ import { stripIndent } from 'common-tags'
2+
3+ import { joinOr } from '@socketsecurity/registry/lib/arrays'
14import { logger } from '@socketsecurity/registry/lib/logger'
25
36import { runFix } from './run-fix'
7+ import { RangeStyles } from './types'
48import constants from '../../constants'
59import { commonFlags } from '../../flags'
10+ import { handleBadInput } from '../../utils/handle-bad-input'
611import { meowOrExit } from '../../utils/meow-with-subcommands'
712import { getFlagListOutput } from '../../utils/output-formatting'
813
14+ import type { RangeStyle } from './types'
915import type { CliCommandConfig } from '../../utils/meow-with-subcommands'
1016
1117const { DRY_RUN_BAIL_TEXT } = constants
@@ -16,6 +22,20 @@ const config: CliCommandConfig = {
1622 hidden : true ,
1723 flags : {
1824 ...commonFlags ,
25+ rangeStyle : {
26+ type : 'string' ,
27+ default : 'preserve' ,
28+ description : stripIndent `
29+ Define how updated dependency versions should be written in package.json.
30+ Available styles:
31+ * caret - Use ^ range for compatible updates (e.g. ^1.2.3)
32+ * gt - Use >= to allow any newer version (e.g. >=1.2.3)
33+ * lt - Use < to allow only lower versions (e.g. <1.2.3)
34+ * pin - Use the exact version (e.g. 1.2.3)
35+ * preserve - Retain the existing version range as-is
36+ * tilde - Use ~ range for patch/minor updates (e.g. ~1.2.3)
37+ `
38+ } ,
1939 test : {
2040 type : 'boolean' ,
2141 default : true ,
@@ -54,6 +74,16 @@ async function run(
5474 parentName
5575 } )
5676
77+ const wasBadInput = handleBadInput ( {
78+ test : RangeStyles . includes ( cli . flags [ 'rangeStyle' ] as string ) ,
79+ message : `Expecting range style of ${ joinOr ( RangeStyles ) } ` ,
80+ pass : 'ok' ,
81+ fail : 'missing'
82+ } )
83+ if ( wasBadInput ) {
84+ return
85+ }
86+
5787 if ( cli . flags [ 'dryRun' ] ) {
5888 logger . log ( DRY_RUN_BAIL_TEXT )
5989 return
@@ -64,6 +94,9 @@ async function run(
6494
6595 await runFix ( {
6696 spinner,
97+ rangeStyle : ( cli . flags [ 'rangeStyle' ] ?? undefined ) as
98+ | RangeStyle
99+ | undefined ,
67100 test : Boolean ( cli . flags [ 'test' ] ) ,
68101 testScript : cli . flags [ 'testScript' ] as string | undefined
69102 } )
0 commit comments