Repository navigation
Follow the command wrapped by env-cmd without -- - #2374
Conversation
commit: |
webpro
left a comment
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
With --use-shell the command is now parsed as shell text, so both scripts are found. Covered with and without the -- separator.
…double-dash # Conflicts: # packages/knip/src/binaries/util.ts
…-double-dash # Conflicts: # packages/knip/test/util/get-inputs-from-scripts.test.ts
webpro
left a comment
There was a problem hiding this comment.
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.
|
🚀 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. |
env-cmd --silent -f .env.staging node scripts/build.jsonly yields theenv-cmdbinary, soscripts/build.jsis 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-cmdbecomes an args-only plugin, likeretry-cliin #2310, and leavesendOfCommandBinaries. When there is a--, the command after it still wins:-etakes several values in v11, soenv-cmd -e test production -- node x.jsrunsnode(source).