diff --git a/packages/knip/src/binaries/fallback.ts b/packages/knip/src/binaries/fallback.ts index c377669e..b1356359 100644 --- a/packages/knip/src/binaries/fallback.ts +++ b/packages/knip/src/binaries/fallback.ts @@ -6,12 +6,16 @@ import { toBinary, toDeferResolve, toEntry } from '../util/input.js'; // Binaries that spawn a child process for the binary at first positional arg (and don't have custom resolver already) const spawningBinaries = ['cross-env', 'retry-cli']; +// Binaries that have a new script behind the double-dash/end-of-command (and don't have custom resolver already) +const endOfCommandBinaries = ['dotenvx']; + const positionals = new Set(['babel-node', 'esbuild', 'execa', 'vite-node', 'zx']); export const resolve: BinaryResolver = (binary, args, { fromArgs }) => { - const parsed = parseArgs(args, { boolean: ['quiet', 'verbose'] }); + const parsed = parseArgs(args, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) }); const bin = binary.startsWith('.') ? toEntry(binary) : toBinary(binary); const shiftedArgs = spawningBinaries.includes(binary) ? fromArgs(args) : []; const pos = positionals.has(binary) ? [toDeferResolve(parsed._[0])] : []; - return compact([bin, ...shiftedArgs, ...pos]); + const newCommand = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : []; + return compact([bin, ...shiftedArgs, ...pos, ...newCommand]); }; diff --git a/packages/knip/test/util/get-inputs-from-scripts.test.ts b/packages/knip/test/util/get-inputs-from-scripts.test.ts index 5c872401..0d2621e2 100644 --- a/packages/knip/test/util/get-inputs-from-scripts.test.ts +++ b/packages/knip/test/util/get-inputs-from-scripts.test.ts @@ -211,6 +211,10 @@ test('getInputsFromScripts (nodemon)', () => { t('nodemon script.js', [toBinary('nodemon'), toDeferResolveEntry('script.js')]); }); +test('getInputsFromScripts (double-dash)', () => { + t('dotenvx run --convention=nextjs -- tsx watch src/index.ts', [toBinary('dotenvx'), toBinary('tsx'), toDeferResolveEntry('src/index.ts')]); +}); + test('getInputsFromScripts (bash expressions)', () => { t('if test "$NODE_ENV" = "production" ; then make install ; fi ', [toBinary('make')]); t('node -e "if (NODE_ENV === \'production\'){process.exit(1)} " || make install', [toBinary('node'), toBinary('make')]);