Repository navigation
Follow the shell command wrapped by cross-env-shell - #2362
Conversation
commit: |
webpro
left a comment
There was a problem hiding this comment.
Thanks, Éverton! The shell-command support works, but the unquoted form needs to preserve literal argument separators.
| for (const arg of command) { | ||
| const value = typeof arg === 'string' ? arg : arg.value; | ||
| if (!isEnvAssignment.test(value)) isCommand = true; | ||
| script.push(isCommand ? value : typeof arg === 'string' ? arg : arg.text.replace(quotedEnvAssignment, '$2$1')); |
There was a problem hiding this comment.
For cross-env-shell NODE_ENV=test node ./job.js -- --import unused-dep, this returns -- as a separate script element, which toScript removes. Native execution preserves it as a script argument, but Knip now reports unused-dep as an unresolved module. getScriptCommands loses the separator too.
Could you preserve it for unquoted commands in both dependency extraction and command inspection, with a regression test? Quoting the entire command already works.
There was a problem hiding this comment.
toScript now only drops a leading --, so the separator survives for unquoted commands in both dependency extraction and getScriptCommands. Added a regression for each. The script in cross-env-shell node -- ./script.js isn't picked up yet, which #2410 covers for node -- in general.
…command # Conflicts: # packages/knip/src/binaries/plugins.ts # packages/knip/src/binaries/util.ts
…-command # Conflicts: # packages/knip/src/binaries/plugins.ts
webpro
left a comment
There was a problem hiding this comment.
Thanks, Éverton! I pushed a commit that replaces the cross-env-shell step in getWrappedCommand: a fromArgs function can now return a string to have it parsed as shell script text, and cross-env-shell's args re-emit the leading NAME=value arguments as single-quoted assignments before the command. NODE_OPTIONS modules and quoted assignments keep working without the quote rewrite, and plugins can use the same return value, like env-cmd for --use-shell in #2374. Happy to merge.
|
🚀 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. |
With
cross-env-shell TZ=UTC jest(example),jestis reported as an unused devDependency. The quoted form is common too, as incross-env-shell PLATFORM=web "tsc && vite build"(example), and nothing inside the quotes was followed.cross-env-shellhands its arguments to a shell (source), and everything after the leadingNAME=valuepairs is the command (parser).getWrappedCommandnow passes that command on as script text, sogetInputsFromScriptsandgetScriptCommandsboth see what's inside the quotes.