fix: add codesign hook for esbuild on Darwin platforms
fix #3378
Signing esbuild binaries seem to fix the problem with failing tests on my machine (M1 Air/macOS 15.7):
$ deno test -A
[...]
ok | 476 passed (14 steps) | 0 failed | 17 ignored (2m26s)
$ deno test -A --parallel
[...]
ok | 476 passed (14 steps) | 0 failed | 17 ignored (1m42s)
Before:
$ deno test -A packages/plugin-vite/tests/dev_server_test.ts
[...]
FAILED | 21 passed | 7 failed | 1 ignored (11s)
Below is an analysis why this is happening.
Caveat: I am not sure if this fix is correct, or if this hiding symptoms for a deeper root cause, that this manual codesign step should not be necessary. But it works for me, now, and that makes me happy.
For the curious, here are my notes while debugging this problem with the help of GPT-5 Codex -> https://gist.github.com/fry69/dca16c1164defd93a62adecaa0a2b2dd
Investigated the mac-only failures and found that macOS was killing the Vite/esbuild helper when a second dev server spun up; the crash logs showed SIGKILL (Code Signature Invalid) for the esbuild binary. These tests keep one long-lived server running while launching others, so the unsigned/adhoc esbuild binary in the npm cache got revalidated and terminated only on this platform, which is why CI (Linux) kept passing.
actions taken
- Added
ensureEsbuildSigned()in test_utils.ts to locatenpm:esbuild/bin/esbuild, runcodesign --force --sign - …once per process on Darwin, and surface clear guidance ifcodesignisn’t available. - Hooked that helper into
launchDevServer,spawnDevServer, andbuildViteso every Vite invocation now runs against a freshly re-signed binary. - Kept the rest of the test utilities unchanged, cleaned up the temporary debug artifacts, and ran formatter.
verification
deno fmt packages/plugin-vite/tests/test_utils.tsdeno test -A packages/plugin-vite/tests/dev_server_test.ts(all 28 relevant cases now pass locally on macOS)
notes & follow-ups
- The new logic depends on the macOS
codesigntool (installed with the Xcode Command Line Tools). If it’s missing, developers will get a direct error telling them to install it or sign the binary manually. - No CI impact is expected; the helper early-outs on non-Darwin systems.
- Root cause mapped: macOS code-signing enforcement → esbuild killed mid-launch → Vite servers never reported their address → tests crashed. The fix ensures the binary stays valid before any server starts.