@devries-cameron20 / t3code-1 / commits / a5d66e2239
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): new worktrees install Electron from the local download cache (#22712)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 00:13 UTC a5d66e22396fcf3b4d3a59a2ae7ad1e158587ad4
3 files changed +61 -10
.github/workflows/ci.yml
+24
@@ -83,6 +83,14 @@ jobs:
83 - name: Setup Vite+
84 uses: ./.github/actions/setup-ci-deps
85
86 + # electron's install.js (run by ensure:electron) reads this cache before it
87 + # downloads from GitHub. The key changes only with the Electron version.
88 + - name: Cache Electron download
89 + uses: actions/cache@v6
90 + with:
91 + path: ~/.cache/electron
92 + key: electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }}
93 +
94 - name: Ensure Electron runtime is installed
95 run: vp run --filter @t3tools/desktop ensure:electron
96
@@ -132,6 +140,14 @@ jobs:
140 - name: Setup Vite+
141 uses: ./.github/actions/setup-ci-deps
142
143 + # electron's install.js (run by ensure:electron) reads this cache before it
144 + # downloads from GitHub. The key changes only with the Electron version.
145 + - name: Cache Electron download
146 + uses: actions/cache@v6
147 + with:
148 + path: ~/.cache/electron
149 + key: electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }}
150 +
151 - name: Ensure Electron runtime is installed
152 id: electron
153 run: vp run --filter @t3tools/desktop ensure:electron
@@ -222,6 +238,14 @@ jobs:
238 - name: Setup Vite+
239 uses: ./.github/actions/setup-ci-deps
240
241 + # electron's install.js (run by ensure:electron) reads this cache before it
242 + # downloads from GitHub. The key changes only with the Electron version.
243 + - name: Cache Electron download
244 + uses: actions/cache@v6
245 + with:
246 + path: ~/.cache/electron
247 + key: electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }}
248 +
249 - name: Ensure Electron runtime is installed
250 run: vp run --filter @t3tools/desktop ensure:electron
251
apps/desktop/scripts/ensure-electron-runtime.mjs
+34 -9
@@ -116,7 +116,26 @@ function runChecked(command, args) {
116 );
117 }
118
119 -function installElectronRuntime(electronDir, version) {
119 +// electron's own installer goes through @electron/get, which reuses its
120 +// download cache (~/.cache/electron, ~/Library/Caches/electron) and verifies
121 +// the bundled checksums. pnpm 11 never runs it because electron has no
122 +// install script, so a new worktree would otherwise download 130 MB again.
123 +function installFromElectronCache(electronDir) {
124 + const result = NodeChildProcess.spawnSync(
125 + process.execPath,
126 + [NodePath.join(electronDir, "install.js")],
127 + { stdio: ["ignore", "inherit", "inherit"] },
128 + );
129 + if (result.status === 0) {
130 + return true;
131 + }
132 + process.stderr.write(
133 + `electron install.js failed with exit code ${result.status ?? "unknown"}, downloading with curl instead\n`,
134 + );
135 + return false;
136 +}
137 +
138 +function downloadElectronRuntime(electronDir, version) {
139 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-electron-"));
140 const zipPath = NodePath.join(tempDir, `electron-v${version}-${hostPlatform}-${hostArch}.zip`);
141
@@ -149,21 +168,27 @@ function installElectronRuntime(electronDir, version) {
168 }
169 }
170
171 +function resetRuntime(electronDir) {
172 + NodeFS.rmSync(NodePath.join(electronDir, "dist"), { recursive: true, force: true });
173 + NodeFS.rmSync(NodePath.join(electronDir, "path.txt"), { force: true });
174 +}
175 +
176 export function ensureElectronRuntime() {
177 const electronPackageJsonPath = require.resolve("electron/package.json");
178 const electronPackageJson = JSON.parse(NodeFS.readFileSync(electronPackageJsonPath, "utf8"));
179 const electronDir = NodePath.dirname(electronPackageJsonPath);
180 const platformPath = getPlatformPath();
181 const electronPath = NodePath.join(electronDir, "dist", platformPath);
158 - const missingBeforeInstall = missingRuntimePaths(electronDir, platformPath);
159 - const invalidBeforeInstall = invalidRuntimePaths(electronDir, platformPath);
160 -
161 - if (missingBeforeInstall.length > 0 || invalidBeforeInstall.length > 0) {
162 - if (NodeFS.existsSync(NodePath.join(electronDir, "dist"))) {
163 - NodeFS.rmSync(NodePath.join(electronDir, "dist"), { recursive: true, force: true });
182 + const needsInstall = () =>
183 + missingRuntimePaths(electronDir, platformPath).length > 0 ||
184 + invalidRuntimePaths(electronDir, platformPath).length > 0;
185 +
186 + if (needsInstall()) {
187 + resetRuntime(electronDir);
188 + if (!installFromElectronCache(electronDir) || needsInstall()) {
189 + resetRuntime(electronDir);
190 + downloadElectronRuntime(electronDir, electronPackageJson.version);
191 }
165 - NodeFS.rmSync(NodePath.join(electronDir, "path.txt"), { force: true });
166 - installElectronRuntime(electronDir, electronPackageJson.version);
192 }
193
194 const missingAfterInstall = missingRuntimePaths(electronDir, platformPath);
pnpm-workspace.yaml
+3 -1
@@ -12,7 +12,9 @@ allowBuilds:
12 browser-tabs-lock: false
13 bufferutil: false
14 core-js: false
15 - electron: true
15 + # No install script since Electron 44; ensure:electron runs install.js.
16 + # Keep the key: pnpm fails installs that still record a removed `true`.
17 + electron: false
18 electron-winstaller: false
19 esbuild: true
20 msgpackr-extract: true