diff --git a/CHANGELOG.md b/CHANGELOG.md index 64577bfd7..035b39c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Try to canonicalize any arbitrary utility to a bare value ([#19379](https://github.com/tailwindlabs/tailwindcss/pull/19379)) - Validate candidates similarly to Oxide ([#19397](https://github.com/tailwindlabs/tailwindcss/pull/19397)) - Canonicalization: combine `text-*` and `leading-*` classes ([#19396](https://github.com/tailwindlabs/tailwindcss/pull/19396)) +- Correctly handle duplicate CLI arguments ([#19416](https://github.com/tailwindlabs/tailwindcss/pull/19416)) ### Added diff --git a/packages/@tailwindcss-cli/src/utils/args.test.ts b/packages/@tailwindcss-cli/src/utils/args.test.ts index 51d2c4747..4ac2e8778 100644 --- a/packages/@tailwindcss-cli/src/utils/args.test.ts +++ b/packages/@tailwindcss-cli/src/utils/args.test.ts @@ -17,6 +17,38 @@ it('should be possible to parse a single argument', () => { `) }) +it('should only return the last value for duplicate arguments', () => { + expect( + args( + { + '--output': { type: 'string', description: 'Output file' }, + }, + ['--output', 'output.css', '--output', 'override.css'], + ), + ).toMatchInlineSnapshot(` + { + "--output": "override.css", + "_": [], + } + `) +}) + +it('uses last value when flag with "-" is supplied multiple times', () => { + let result = args( + { + '--output': { type: 'string', description: 'Output file', alias: '-o' }, + }, + ['--output', 'output.css', '--output', '-'], + ) + + expect(result).toMatchInlineSnapshot(` + { + "--output": "-", + "_": [], + } + `) +}) + it('should fallback to the default value if no flag is passed', () => { expect( args( diff --git a/packages/@tailwindcss-cli/src/utils/args.ts b/packages/@tailwindcss-cli/src/utils/args.ts index 1306aa2f2..88b306b05 100644 --- a/packages/@tailwindcss-cli/src/utils/args.ts +++ b/packages/@tailwindcss-cli/src/utils/args.ts @@ -77,9 +77,17 @@ export function args(options: T, argv = process.argv.slice( let parsed = parse(argv) for (let key in parsed) { - if (parsed[key] === '__IO_DEFAULT_VALUE__') { - parsed[key] = '-' + let value = parsed[key] + + if (key !== '_' && Array.isArray(value)) { + value = value[value.length - 1] } + + if (value === '__IO_DEFAULT_VALUE__') { + value = '-' + } + + parsed[key] = value } let result: { _: string[]; [key: string]: unknown } = {