fix: run checker binaries without a shell - #795
Open
Artur- wants to merge 3 commits into
Open
Conversation
The build command was assembled into one string and handed to a shell, which splits it on whitespace. Anything the checkers built that could contain a space therefore fell apart: a project under a directory with a space in its name reached tsc as two arguments and failed with "TS5042: Option 'project' cannot be mixed with source files on a command line". Node concatenates args under `shell: true` without escaping them, and deprecates the combination for this reason (DEP0190). Spawn the binaries through cross-spawn with the arguments as a list and no shell, so nothing needs escaping. cross-spawn is what makes that work on Windows, where the binaries in node_modules/.bin are .cmd shims that Node refuses to run without a shell. The arguments now have to arrive already separated, since no shell is left to do it: the eslint and stylelint commands and biome's flags are split with the same quote aware parser the oxlint checker already uses, so a quoted argument stays whole and loses its quotes exactly as before. The empty string that used to be passed when there is no lint command is gone too; a shell dropped it, a list would not. One behaviour change comes with this: an unquoted glob in a lint command is no longer expanded by the shell before the linter sees it. Both eslint and stylelint expand globs themselves, and cmd.exe never expanded them, so this makes the platforms agree.
✅ Deploy Preview for vite-plugin-checker ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
Contributor
Author
The checker joins the project path with `path.join`, which returns backslashes on Windows, while the assertion spelled the path with forward slashes and only held on POSIX.
Contributor
Author
|
#796 fixes the test failure |
Contributor
Author
|
@danielroe you working on this project? |
Collaborator
|
@Artur- I am indeed. why do you ask? |
Contributor
Author
|
Excellent, just looking for somebody to review or discuss this change. Seems like it solves a couple of issues with deprecation warnings seen with the newest node in addition to properly escaping arguments such as paths with space. In our case, we have an issue with using |
Contributor
Author
|
The alternative solution in #792 sounds much worse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The build command was assembled into one string and handed to a shell, which splits it on whitespace. Anything the checkers built that could contain a space therefore fell apart: a project under a directory with a space in its name reached tsc as two arguments and failed with "TS5042: Option 'project' cannot be mixed with source files on a command line". Node concatenates args under
shell: truewithout escaping them, and deprecates the combination for this reason (DEP0190).Spawn the binaries through cross-spawn with the arguments as a list and no shell, so nothing needs escaping. cross-spawn is what makes that work on Windows, where the binaries in node_modules/.bin are .cmd shims that Node refuses to run without a shell.
The arguments now have to arrive already separated, since no shell is left to do it: the eslint and stylelint commands and biome's flags are split with the same quote aware parser the oxlint checker already uses, so a quoted argument stays whole and loses its quotes exactly as before. The empty string that used to be passed when there is no lint command is gone too; a shell dropped it, a list would not.
One behaviour change comes with this: an unquoted glob in a lint command is no longer expanded by the shell before the linter sees it. Both eslint and stylelint expand globs themselves, and cmd.exe never expanded them, so this makes the platforms agree.