Skip to content

refactor(code): migrate build and dev to electron-vite#2811

Open
charlesvien wants to merge 12 commits into
feat/electron-builder-migrationfrom
refactor/electron-vite
Open

refactor(code): migrate build and dev to electron-vite#2811
charlesvien wants to merge 12 commits into
feat/electron-builder-migrationfrom
refactor/electron-vite

Conversation

@charlesvien

@charlesvien charlesvien commented Jun 20, 2026

Copy link
Copy Markdown
Member

Problem

The desktop app's build and dev tooling was hand-rolled: four separate Vite configs (main, preload, workspace-server, renderer) driven by a 169-line scripts/dev.mjs that spawned the renderer dev server plus three watch builds plus Electron and parsed stdout for "ready" lines, with a separate scripts/build.mjs to sequence the builds. It worked, but it was a pile of bespoke orchestration to maintain instead of the purpose-built Electron + Vite framework (electron-vite).

This replaces that with electron-vite, consolidates the native-module list into a single source of truth, and moves the packaging config to TypeScript.

Stacked on #2795 (the electron-builder migration); review the diff against feat/electron-builder-migration.

Changes

electron-vite

  • One electron.vite.config.ts with { main, preload, renderer } replaces the four vite.*.config.mts files. workspace-server is folded in as a second main rollup input (it is a Node entrypoint spawned as a child, the same shape as the bootstrap entry), not a separate build.
  • Deleted scripts/dev.mjs (the hand-rolled orchestrator) and scripts/build.mjs. dev/start is now electron-vite dev --watch (renderer HMR plus main/preload auto-restart out of the box); the build step is electron-vite build.
  • Binary and asset plugins (claude-cli, codex-acp, grammars, drizzle migrations, posthog plugin) moved verbatim into vite-main-plugins.mts.
  • window.ts reads electron-vite's ELECTRON_RENDERER_URL in dev, and the CDP :9222 port (used by the test-electron-app skill) is set in bootstrap.ts. Output paths are unchanged (.vite/build, .vite/renderer/main_window), so electron-builder, package.json main and the production load path did not move.
  • One real bug surfaced and was fixed: electron-vite nests chunks under chunks/, which broke the __dirname-relative path the main process uses to spawn workspace-server.js. Flattening the chunk output restores the original layout.
  • Updated CI, build-linux-docker.sh, knip.json and the package scripts.

Native modules: single source of truth

  • runtime-dependencies.ts is now the only place the native-module list lives, consumed by before-pack.ts (staging from the hoisted root), electron-builder.ts (files plus asarUnpack) and the Vite externals. Verified the generated globs are set-equal to the previous inline lists, so packaging behavior is unchanged.

TypeScript configs

  • electron-builder.config.cjs becomes electron-builder.ts and scripts/before-pack.cjs becomes scripts/before-pack.ts. electron-builder v26 loads .ts configs through its bundled jiti, and the beforePack hook is imported as a function so jiti transpiles the whole electron-builder.ts -> before-pack.ts -> runtime-dependencies.ts graph. No ts-node or tsx is needed.

Net result is roughly 200 fewer lines.

How did you test this?

Locally on macOS arm64:

  • electron-vite dev --watch: the app boots, the renderer loads over ELECTRON_RENDERER_URL, and the workspace-server child spawns and connects ([workspace-server] listening on http://127.0.0.1:<port>) with no module or health errors.
  • electron-vite build: produces the expected flat .vite/build layout (bootstrap.js requiring ./index-*.js, a self-contained electron-free workspace-server.js, renderer assets with ./assets/ relative paths).
  • electron-builder build --dir --mac --arm64: confirms jiti loads electron-builder.ts, the before-pack.ts hook runs and stages every native module, and out/mac-arm64/PostHog Code.app is produced.
  • pnpm typecheck, biome check and vitest run (152/152) all pass.
  • Confirmed runtime-dependencies.ts generates files/asarUnpack globs set-equal to the previous inline lists.

Not validated here (needs a tagged CI run, same caveat as the parent PR): the full signed and notarized multi-platform electron-builder publish (macOS dmg/zip, Windows, Linux) and end-to-end auto-update.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

charlesvien commented Jun 20, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 8e56223.

@charlesvien charlesvien force-pushed the refactor/electron-vite branch from e25d4d1 to 105cec7 Compare June 20, 2026 21:59
@charlesvien charlesvien force-pushed the feat/electron-builder-migration branch from ab18bbc to 3efbf3f Compare June 20, 2026 21:59
@charlesvien charlesvien changed the title migrate build and dev to electron-vite refactor(code): migrate build and dev to electron-vite Jun 20, 2026
@charlesvien charlesvien marked this pull request as ready for review June 20, 2026 22:03
@greptile-apps

greptile-apps Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. apps/code/package.json, line 368 (link)

    P2 electron-vite@4.0.1 requires Node 20.19.0 or 22.12.0+

    The lockfile records engines: {node: ^20.19.0 || >=22.12.0} for electron-vite@4.0.1. Any CI runner or developer machine on Node 20.x below 20.19.0 will have electron-vite silently installed but fail at runtime with a version-check error when pnpm exec electron-vite build is first invoked. If the project doesn't already pin a Node version ≥ 20.19.0 in .nvmrc / .node-version / the CI matrix, it's worth adding that constraint explicitly so the requirement is visible before someone hits it.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/package.json
    Line: 368
    
    Comment:
    **`electron-vite@4.0.1` requires Node 20.19.0 or 22.12.0+**
    
    The lockfile records `engines: {node: ^20.19.0 || >=22.12.0}` for `electron-vite@4.0.1`. Any CI runner or developer machine on Node 20.x below 20.19.0 will have `electron-vite` silently installed but fail at runtime with a version-check error when `pnpm exec electron-vite build` is first invoked. If the project doesn't already pin a Node version ≥ 20.19.0 in `.nvmrc` / `.node-version` / the CI matrix, it's worth adding that constraint explicitly so the requirement is visible before someone hits it.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/code/electron.vite.config.ts:132-133
**`autoServicesPlugin` silently dropped from preload build**

The old `vite.preload.config.mts` included `autoServicesPlugin(path.join(__dirname, "src/main/services"))` alongside `tsconfigPaths`. The new consolidated config omits it from the `preload` section (it still runs for `main`). If `preload.ts` (or any module it transitively imports) relies on a file auto-generated by this plugin, the preload will build stale generated code in watch/rebuild cycles after a services change, producing subtle IPC mismatches. Since `pnpm typecheck` passes and the app boots, it's likely that the preload doesn't import anything auto-generated — but it's worth a quick confirmation that the removal was intentional rather than accidental during the consolidation.

### Issue 2 of 2
apps/code/package.json:368
**`electron-vite@4.0.1` requires Node 20.19.0 or 22.12.0+**

The lockfile records `engines: {node: ^20.19.0 || >=22.12.0}` for `electron-vite@4.0.1`. Any CI runner or developer machine on Node 20.x below 20.19.0 will have `electron-vite` silently installed but fail at runtime with a version-check error when `pnpm exec electron-vite build` is first invoked. If the project doesn't already pin a Node version ≥ 20.19.0 in `.nvmrc` / `.node-version` / the CI matrix, it's worth adding that constraint explicitly so the requirement is visible before someone hits it.

Reviews (1): Last reviewed commit: "centralize native deps; ts builder confi..." | Re-trigger Greptile

Comment thread apps/code/electron.vite.config.ts
@charlesvien charlesvien added the Stamphog This will request an autostamp by stamphog on small changes label Jun 20, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied because this PR touches CI/CD workflows and build/dependency toolchain — both on the deny-list for auto-approval. Additionally, there is an unresolved substantive inline comment flagging that autoServicesPlugin was dropped from the preload build in the new consolidated config, which could silently break preload functionality.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jun 20, 2026
@charlesvien charlesvien force-pushed the refactor/electron-vite branch from 105cec7 to dd8572f Compare June 20, 2026 22:38
@charlesvien charlesvien added the Stamphog This will request an autostamp by stamphog on small changes label Jun 21, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied because this PR touches CI/CD workflows and build/dependency toolchain files, both on the deny-list for auto-approval. Additionally, there is an unresolved inline comment about autoServicesPlugin being dropped from the preload build in the new config, which could silently break preload functionality.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jun 21, 2026
@charlesvien charlesvien added the Stamphog This will request an autostamp by stamphog on small changes label Jun 21, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied: this PR touches CI/CD workflows and build/dependency toolchain files, both on the deny-list for auto-approval. There is also an unresolved inline comment about autoServicesPlugin being dropped from the preload build, which could silently break preload functionality.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jun 21, 2026
@charlesvien charlesvien force-pushed the feat/electron-builder-migration branch from 118ea82 to de167fb Compare June 21, 2026 05:09
@charlesvien charlesvien force-pushed the refactor/electron-vite branch 4 times, most recently from 507c6ab to d1b0efd Compare June 21, 2026 08:11
@charlesvien charlesvien force-pushed the feat/electron-builder-migration branch from ab2b60b to 77dc1fa Compare June 21, 2026 08:11
@charlesvien charlesvien force-pushed the feat/electron-builder-migration branch from 77dc1fa to e4c54c9 Compare June 21, 2026 08:53
@charlesvien charlesvien force-pushed the refactor/electron-vite branch from d1b0efd to 8e56223 Compare June 21, 2026 08:53
@charlesvien charlesvien added the Stamphog This will request an autostamp by stamphog on small changes label Jun 21, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied: this PR touches CI/CD workflows and build/dependency toolchain files, both on the deny-list for auto-approval. There is also an unresolved inline comment about autoServicesPlugin being dropped from the preload build, which could silently break preload functionality.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jun 21, 2026
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