fix(evals): resolve windows EINVAL quoting issue in spawnSync#1931
fix(evals): resolve windows EINVAL quoting issue in spawnSync#1931tearf001 wants to merge 1 commit intobrowserbase:mainfrom
Conversation
On Windows, Node enforces shell:true for .cmd files. However, cmd.exe corrupts spaced arguments like --banner. This bypasses the issue by utilizing esbuild's Node API, while restoring shell:true for standard spawn commands to prevent EINVALs during the prepare script.
|
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User as Developer / CLI
participant Runner as run.ts
participant BuildScript as build-cli.ts
participant ESBuild as esbuild (Node API)
participant OS as OS Shell (CMD/sh)
participant PkgMgr as pnpm / npm
User->>Runner: Execute eval runner
rect rgb(240, 240, 240)
Note over Runner,PkgMgr: Phase 1: Parent Build Process
alt Platform is Windows
Runner->>OS: CHANGED: spawnSync("pnpm run build") with { shell: true }
else Platform is Unix/macOS
Runner->>OS: spawnSync("pnpm run build")
end
OS->>PkgMgr: Execute build scripts
PkgMgr->>BuildScript: Invoke build-cli.ts
end
rect rgb(230, 245, 230)
Note over BuildScript,ESBuild: Phase 2: CLI Bundling (The "Quoting Bug" Fix)
BuildScript->>ESBuild: NEW: esbuild.buildSync({ banner: { js: "#!..." }, ... })
Note right of ESBuild: Direct Node API call bypasses<br/>Windows shell argument splitting
ESBuild-->>BuildScript: Compilation complete (dist/cli/cli.js)
end
rect rgb(240, 240, 240)
Note over BuildScript,PkgMgr: Phase 3: Post-Build & Linking
BuildScript->>BuildScript: fs.chmodSync(cli.js, 0o755)
alt Platform is Windows
BuildScript->>OS: CHANGED: spawnSync("npm link") with { shell: true }
OS->>PkgMgr: Execute npm.cmd link
else Platform is Unix/macOS
BuildScript->>OS: spawnSync("npm link")
OS->>PkgMgr: Execute npm link
end
PkgMgr-->>BuildScript: Global link created
end
BuildScript-->>Runner: Success
Runner-->>User: Process Exit (0)
Description
This PR resolves an issue where running
pnpm install(and consequently thepreparescript) fails on Windows environments due tospawnSyncerrors within the@browserbasehq/stagehand-evalspackage.The Problem
EINVALon.cmdfiles: On Windows, Node.js refuses to execute.cmdscripts (likepnpmornpm) viaspawnSyncwithout theshell: trueoption, resulting in a silentEINVALcrash.shell: trueis added to fix theEINVALcrash, the Windowscmd.exeparser inadvertently breaks spaced arguments. Specifically, the--banner:js="#!/usr/bin/env node"argument passed toesbuildwas being split, causingesbuildto fail with:[ERROR] Must use "outdir" when there are multiple input files.The Solution
esbuildNode API: Instead of spawning a childpnpm exec esbuildprocess, the script now usesesbuild.buildSync(). This entirely bypasses the Windows shell quoting nightmare, is more robust, and is slightly faster.shell: truedynamically for safe commands: For other.cmdfiles liketscandnpm linkthat don't pass complex spaced arguments,shell: process.platform === "win32"was safely added tospawnSyncto prevent theEINVALcrashes.These changes are constrained to Windows using
process.platform === "win32", ensuring that macOS and Linux builds remain 100% unaffected.Testing
pnpm run buildsucceeds on Windows natively.pnpm run buildsucceeds on WSL / Linux.Summary by cubic
Fixes Windows install/build failures in
@browserbasehq/stagehand-evalscaused byspawnSyncEINVAL on.cmdand broken argument quoting. Switches the CLI build to theesbuildNode API and adds safe Windows-specific spawning.esbuild.buildSync()instead ofpnpm exec esbuild, preserving the#!/usr/bin/env nodebanner and existing bundling config.shell: truefor safe commands (pnpm run build,npm link) and platform-awarepnpmresolution (pnpm.cmdon Windows).Written for commit afcd7b4. Summary will update on new commits. Review in cubic