Repository navigation
fix: escape all cmd/bat file args - #172
Merged
Merged
Conversation
43081j
force-pushed
the
jg/windows-nonsense
branch
from
September 8, 2026 07:54
032952d to
fc01bcb
Compare
Merged
2 of 3 tasks
JoshuaKGoldberg
added a commit
to JoshuaKGoldberg/formatly
that referenced
this pull request
Nov 19, 2026
#751) ## PR Checklist - [x] Addresses an existing open issue: fixes #675 - [ ] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/formatly/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/formatly/blob/main/.github/CONTRIBUTING.md) were taken ## Overview On Windows, `resolvePackageCommand` falls back to `npx` / `pnpm` / `yarn`, which are `.cmd` shims. Node's `spawn` can't run those without a shell, so oxfmt, Biome, dprint, and out-of-cwd Prettier failed with `spawn npx ENOENT`. A new `spawnCommand` helper first runs each command through [tinyexec](https://github.com/tinylibs/tinyexec)'s `normalizeSpawnCommand`, then calls `node:child_process`'s `spawn`. On Windows, `normalizeSpawnCommand` wraps shims in an escaped `cmd.exe /d /s /c` call. On other platforms it returns its inputs unchanged. Every formatter spawn goes through the helper. dprint's `editor-info` probe moved from `execFile` to the shared `spawnOutput`, and it still falls back to `dprint fmt --stdin` on any failure. tinyexec was chosen over cross-spawn because it has no dependencies, and e18e's [module-replacements](https://github.com/es-tooling/module-replacements/blob/main/docs/modules/cross-spawn.md) suggests it as cross-spawn's replacement. It's also already in most modern toolchains through vitest, tsup, and lint-staged. Using only its normalization, rather than its `x()` runner, keeps the raw `ChildProcess` that the long-lived dprint editor service needs. Known limitations on Windows: - cmd.exe still expands `%VAR%` in arguments passed through a `.cmd` shim. - In tinyexec 1.3.1, arguments get double meta-char escaping only for `.cmd` files in `node_modules/.bin`, not for `npx.cmd`. This only matters for arguments containing `"`, which file paths can't contain. tinyexec has fixed it upstream ([tinylibs/tinyexec#172](tinylibs/tinyexec#172)), but the fix isn't released yet. - A missing command surfaces as a cmd.exe exit code 1 with a "not recognized" message on stderr, not as an `ENOENT` error. - The dprint editor-service child is the cmd.exe wrapper. dprint still exits with its parent because of `--parent-pid`.⚠️ Not yet tested on Windows. #753 adds Windows to CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
No description provided.