Skip to content

fix(code): make postinstall cross-platform#3404

Open
trippyogi wants to merge 2 commits into
PostHog:mainfrom
trippyogi:fix/windows-postinstall-cross-platform
Open

fix(code): make postinstall cross-platform#3404
trippyogi wants to merge 2 commits into
PostHog:mainfrom
trippyogi:fix/windows-postinstall-cross-platform

Conversation

@trippyogi

@trippyogi trippyogi commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Replaces the Code app's Bash-based postinstall script with a cross-platform Node implementation so pnpm install works on Windows without WSL or Git Bash.

The new script preserves the existing postinstall behavior:

  • repairs a missing Electron distribution
  • rebuilds better-sqlite3 against Electron's ABI
  • restores the node-pty spawn-helper execute bit on POSIX systems
  • patches the Electron development app name on macOS
  • downloads the bundled agent binaries

It also adds Windows development notes and troubleshooting guidance.

Behavior note: the old shell script always invoked patch-electron-name.sh, which then no-oped when the macOS plist was absent. The Node script only invokes it when process.platform === "darwin". Intentional correction, not a regression.

Why

On a fresh Windows 11 checkout, pnpm install currently invokes:

bash scripts/postinstall.sh

Windows may resolve bash to the System32 WSL launcher even when no WSL distribution is installed, causing installation to fail with:

execvpe(/bin/bash) failed: No such file or directory

Most of the postinstall workflow already invokes Node scripts, so moving the orchestration itself to Node removes the unnecessary shell dependency.

Scope

This addresses the installation failure from #3252.

The default pnpm dev command still depends on phrocs, for which no Windows binary is currently published. Docs now recommend:

  • Prefer: pnpm dev:agent and pnpm dev:code in separate terminals
  • Alternative: pnpm dev:mprocs

Partially addresses #3252. Leaving the issue open for the remaining pnpm dev / phrocs Windows work unless maintainers decide the documented workaround is enough.

Validation

Tested on Windows 11 (build 26200), Node 22.12.0, pnpm 10.23.0:

  • node apps/code/scripts/postinstall.mjs completes on an existing checkout (rebuilds better-sqlite3 for Electron, downloads/skips agent binaries) without Git Bash / WSL
  • apps/code postinstall script points at node scripts/postinstall.mjs
  • Biome check on changed files; pnpm lint exits 0 (pre-existing warnings elsewhere)
  • Confirmed monorepo pnpm typecheck already fails on tip of upstream/main in @posthog/agent (unrelated to this change)
  • Clean install on this branch: deleted all workspace node_modules, then pnpm install (exit 0 in ~2m). PATH still prefers C:\Windows\System32\bash.exe (WSL stub); postinstall ran node scripts/postinstall.mjs and never invoked bash
  • Electron missing-dist self-heal during that clean install (Electron binary missing at .../electron/dist — downloading...), then sqlite rebuild + binary download; postinstall completed
  • Packaged Windows app rebuilt against this branch
  • macOS postinstall locally (expects CI / maintainer smoke)
  • Linux postinstall locally (expects CI / maintainer smoke)

Test plan

  • Fresh Windows tree: pnpm install after wiping node_modules, without relying on Git Bash/WSL
  • Re-run pnpm install on an already-installed tree
  • macOS: pnpm install still applies development Electron display name
  • Linux: pnpm install still rebuilds native modules and downloads binaries
  • Confirm pnpm dev / phrocs remains unchanged (out of scope)

Replace the Bash Electron postinstall with a Node script so pnpm install works on Windows without WSL or Git Bash. Document the remaining phrocs/dev workaround separately.
@trunk-io

trunk-io Bot commented Jul 13, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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.

1 participant