mirror of
https://github.com/cloudflare/cloudflare-os.git
synced 2026-11-25 02:38:04 +08:00
On Windows the `pnpm` on PATH is a `.cmd` shim. Node spawns processes directly rather than through a shell, so there is no extensionless `pnpm` to execute (ENOENT), and naming the shim explicitly fails too since the CVE-2024-27980 fix (EINVAL). `shell: true` is not a fix here: a shell re-splits the command line, and these callers pass absolute paths built from the checkout location, which break apart on a path containing a space. Add scripts/pnpm-command.ts, which runs pnpm's own JS entry point under `node` when `npm_execpath` points at it, so argv survives byte-for-byte with no shell. Guarded on the path, because under `npm run` that variable points at npm and substituting it unchecked would run npm against a pnpm workspace. Where pnpm is a native executable the plain `pnpm` fallback still resolves it, since PATH lookup appends `.exe` but not `.cmd`. That alone is not enough for the `pnpm exec` sites: Vite+ runs task commands with a filtered environment that omits `npm_execpath`, so build-app.mjs has no way back to pnpm at all. Extract the existing resolveBinEntry() out of run-dev-server.ts into scripts/bin-entry.ts and reach those binaries directly, which also skips ~0.33s of pnpm startup per call. Verified on Windows 11 / Node 24.19.0 / pnpm 11.17.0: `pnpm run-local` goes from failing at the first `pnpm install` to serving HTTP 200 on 8787. Fixes #19 Fixes #120 Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
18 lines
942 B
TypeScript
18 lines
942 B
TypeScript
// Fails the suite unless it is genuinely executing inside workerd.
|
|
//
|
|
// Every package that lists this in `setupFiles` runs its tests through @cloudflare/vitest-pool-workers
|
|
// so they exercise the production runtime. When that pool cannot start, vitest falls back to running
|
|
// the files under Node -- and only the suites that import `cloudflare:test` or `cloudflare:workers`
|
|
// notice. `router` and `typed-storage` import neither, so they would stay green while silently
|
|
// testing the wrong runtime.
|
|
//
|
|
// `navigator.userAgent` is the cheapest unambiguous probe: workerd hardcodes it, Node does not define
|
|
// `navigator.userAgent` as this value.
|
|
if (navigator.userAgent !== "Cloudflare-Workers") {
|
|
throw new Error(
|
|
`Expected to be running inside workerd, but navigator.userAgent is ${JSON.stringify(
|
|
navigator.userAgent,
|
|
)}. The vitest-pool-workers pool did not start -- fix that rather than deleting this check.`,
|
|
);
|
|
}
|