Skip to content

Follow the command wrapped by env-cmd without -- - #2374

Merged
webpro merged 25 commits into
webpro-nl:mainfrom
everton-dgn:fix/env-cmd-without-double-dash
Nov 17, 2026
Merged

webpro merged 25 commits into
webpro-nl:mainfrom
everton-dgn:fix/env-cmd-without-double-dash

Conversation

@everton-dgn

@everton-dgn everton-dgn commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

env-cmd --silent -f .env.staging node scripts/build.js only yields the env-cmd binary, so scripts/build.js is reported as unused. That's how env-cmd 10 documents it (source), still the most downloaded version, and laudspeaker has it in its package.json.

env-cmd becomes an args-only plugin, like retry-cli in #2310, and leaves endOfCommandBinaries. When there is a --, the command after it still wins: -e takes several values in v11, so env-cmd -e test production -- node x.js runs node (source).

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@2374
npm i https://pkg.pr.new/@knip/language-server@2374
npm i https://pkg.pr.new/@knip/mcp@2374

commit: 4509bc0

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Éverton! The ordinary command form works. Two supported argument forms still leave executed scripts reported as unused.

const args: Args = {
boolean: ['expand-envs', 'fallback', 'recursive', 'silent', 'use-shell'],
alias: { 'expand-envs': ['x'] },
fromArgs: (parsed, args) => (parsed['--']?.length ? parsed['--'] : spawningArgs(parsed, args)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For env-cmd -f .env node ./job.js -- --import unused-dep, parsed['--'] contains the child's trailing arguments. Prioritizing it drops node ./job.js, leaving the executed file reported as unused. Both native env-cmd 10 and 11 run this form successfully. Could you distinguish the wrapper's separator from one appearing after the child command and add a regression test?

@everton-dgn everton-dgn Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command is now located by scanning env-cmd's own options, so a -- after the command stays with the child. -e reads several environments up to the next option or -- as in v11, and falls back to the single-value v10 form when that leaves no command. Reading the script after node -- is left to #2410.

const args: Args = {
boolean: ['expand-envs', 'fallback', 'recursive', 'silent', 'use-shell'],
alias: { 'expand-envs': ['x'] },
fromArgs: (parsed, args) => (parsed['--']?.length ? parsed['--'] : spawningArgs(parsed, args)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For env-cmd -f .env --use-shell "node ./job.js && node ./other.js", native env-cmd runs both scripts. This forwards the quoted shell command as a single entry path, so both files remain reported as unused. Could you handle --use-shell as shell text and cover this documented compound-command form?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With --use-shell the command is now parsed as shell text, so both scripts are found. Covered with and without the -- separator.

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Éverton! Earlier I pushed a commit that drops the environment operands in args, so the existing parsing finds the command while keeping env-cmd 11's space- and comma-separated lists. I just added one that returns the --use-shell command as shell script text, now that #2362 lets fromArgs do that. Both findings are resolved, and with #2410 in, env-cmd -f .env -- node -- ./job.js finds the script as well. Looks good.

@webpro
webpro merged commit 3ed81d7 into webpro-nl:main Nov 17, 2026
33 checks passed
@webpro

webpro commented Nov 18, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.46.0. See Release 6.46.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants