Skip to content

fix: spawn Windows .cmd shims through tinyexec's normalizeSpawnCommand - #751

Merged
JoshuaKGoldberg merged 1 commit into
mainfrom
fix/windows-cross-spawn
Nov 19, 2026
Merged

JoshuaKGoldberg merged 1 commit into
mainfrom
fix/windows-cross-spawn

Conversation

@JoshuaKGoldberg

@JoshuaKGoldberg JoshuaKGoldberg commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

PR Checklist

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'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 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), 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

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (99a97b4) to head (81cc323).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #751   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        17    +1     
  Lines          440       445    +5     
  Branches        91        92    +1     
=========================================
+ Hits           440       445    +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JoshuaKGoldberg JoshuaKGoldberg changed the title fix: spawn formatters with cross-spawn for Windows .cmd shims fix: spawn Windows .cmd shims through tinyexec's normalizeSpawnCommand Nov 19, 2026
On Windows, npx, pnpm, and yarn are .cmd shims that Node's spawn can't
run without a shell, so formatters run through the package manager
failed with `spawn npx ENOENT`. A new spawnCommand helper passes each
command through tinyexec's normalizeSpawnCommand before node:child_process
spawn, which wraps shims in an escaped cmd.exe call on Windows.

dprint's editor-info probe now goes through spawnOutput rather than
execFile, so it also gets this handling.

Fixes #675

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JoshuaKGoldberg
JoshuaKGoldberg marked this pull request as ready for review November 19, 2026 05:24
@JoshuaKGoldberg
JoshuaKGoldberg merged commit 6fa4832 into main Nov 19, 2026
12 checks passed
@JoshuaKGoldberg
JoshuaKGoldberg deleted the fix/windows-cross-spawn branch November 19, 2026 05:24
@github-actions

Copy link
Copy Markdown

🎉 This is included in version v0.12.1 🎉

The release is available on:

Cheers! 📦🚀

JoshuaKGoldberg added a commit that referenced this pull request Nov 19, 2026
## PR Checklist

- [x] Addresses an existing open issue: fixes #752
- [ ] 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

Runs the Test job on `macos-latest`, `ubuntu-latest`, and
`windows-latest`, with `fail-fast: false` so one OS failing doesn't
cancel the others. Only Ubuntu uploads coverage to Codecov.

Test changes so the suite passes on every OS:

- Unit tests for the `node_modules/.bin` fast path fake
`process.platform` as `linux`, the same way an existing test already
fakes `win32`. Previously their leftover `fs.access` mock also leaked
into a later Deno test on Windows.
- Unit tests that assert on spawned commands pass tinyexec's
`normalizeSpawnCommand` through. On Windows it wraps `.cmd` shims and
unresolved commands in `cmd.exe`. `spawnCommand.test.ts` still covers
that wiring.
- The e2e cleanup ignores `EBUSY` on Windows. dprint's long-lived editor
service keeps its cwd busy there until the test process exits.

The two Windows product bugs this CI originally caught were fixed in
#751 (#675) and #755 (#754).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

🐛 Bug: Spawned formatters fail on Windows with spawn npx ENOENT

1 participant