Skip to content

Commit 563a016

Browse files
Only use the last value when parsing duplicate cli arguments (#19416)
## Summary When parsing cli args, 'mri' returns an array for duplicate args, which causes unexpected results. All current arguments assume single values only. Tailwind v3 works the same way. ## Test plan Updated tests. --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 1ee7bb9 commit 563a016

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Try to canonicalize any arbitrary utility to a bare value ([#19379](https://github.com/tailwindlabs/tailwindcss/pull/19379))
2323
- Validate candidates similarly to Oxide ([#19397](https://github.com/tailwindlabs/tailwindcss/pull/19397))
2424
- Canonicalization: combine `text-*` and `leading-*` classes ([#19396](https://github.com/tailwindlabs/tailwindcss/pull/19396))
25+
- Correctly handle duplicate CLI arguments ([#19416](https://github.com/tailwindlabs/tailwindcss/pull/19416))
2526

2627
### Added
2728

packages/@tailwindcss-cli/src/utils/args.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,38 @@ it('should be possible to parse a single argument', () => {
1717
`)
1818
})
1919

20+
it('should only return the last value for duplicate arguments', () => {
21+
expect(
22+
args(
23+
{
24+
'--output': { type: 'string', description: 'Output file' },
25+
},
26+
['--output', 'output.css', '--output', 'override.css'],
27+
),
28+
).toMatchInlineSnapshot(`
29+
{
30+
"--output": "override.css",
31+
"_": [],
32+
}
33+
`)
34+
})
35+
36+
it('uses last value when flag with "-" is supplied multiple times', () => {
37+
let result = args(
38+
{
39+
'--output': { type: 'string', description: 'Output file', alias: '-o' },
40+
},
41+
['--output', 'output.css', '--output', '-'],
42+
)
43+
44+
expect(result).toMatchInlineSnapshot(`
45+
{
46+
"--output": "-",
47+
"_": [],
48+
}
49+
`)
50+
})
51+
2052
it('should fallback to the default value if no flag is passed', () => {
2153
expect(
2254
args(

packages/@tailwindcss-cli/src/utils/args.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,17 @@ export function args<const T extends Arg>(options: T, argv = process.argv.slice(
7777
let parsed = parse(argv)
7878

7979
for (let key in parsed) {
80-
if (parsed[key] === '__IO_DEFAULT_VALUE__') {
81-
parsed[key] = '-'
80+
let value = parsed[key]
81+
82+
if (key !== '_' && Array.isArray(value)) {
83+
value = value[value.length - 1]
84+
}
85+
86+
if (value === '__IO_DEFAULT_VALUE__') {
87+
value = '-'
8288
}
89+
90+
parsed[key] = value
8391
}
8492

8593
let result: { _: string[]; [key: string]: unknown } = {

0 commit comments

Comments
 (0)