Skip to content

Commit a5d66e2

Browse files
t3dotggclaude
andauthored
fix(desktop): new worktrees install Electron from the local download cache (pingdotgg#22712)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 73daccf commit a5d66e2

3 files changed

Lines changed: 61 additions & 10 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ jobs:
8383
- name: Setup Vite+
8484
uses: ./.github/actions/setup-ci-deps
8585

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+
8694
- name: Ensure Electron runtime is installed
8795
run: vp run --filter @t3tools/desktop ensure:electron
8896

@@ -132,6 +140,14 @@ jobs:
132140
- name: Setup Vite+
133141
uses: ./.github/actions/setup-ci-deps
134142

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+
135151
- name: Ensure Electron runtime is installed
136152
id: electron
137153
run: vp run --filter @t3tools/desktop ensure:electron
@@ -222,6 +238,14 @@ jobs:
222238
- name: Setup Vite+
223239
uses: ./.github/actions/setup-ci-deps
224240

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+
225249
- name: Ensure Electron runtime is installed
226250
run: vp run --filter @t3tools/desktop ensure:electron
227251

‎apps/desktop/scripts/ensure-electron-runtime.mjs‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,26 @@ function runChecked(command, args) {
116116
);
117117
}
118118

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) {
120139
const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-electron-"));
121140
const zipPath = NodePath.join(tempDir, `electron-v${version}-${hostPlatform}-${hostArch}.zip`);
122141

@@ -149,21 +168,27 @@ function installElectronRuntime(electronDir, version) {
149168
}
150169
}
151170

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+
152176
export function ensureElectronRuntime() {
153177
const electronPackageJsonPath = require.resolve("electron/package.json");
154178
const electronPackageJson = JSON.parse(NodeFS.readFileSync(electronPackageJsonPath, "utf8"));
155179
const electronDir = NodePath.dirname(electronPackageJsonPath);
156180
const platformPath = getPlatformPath();
157181
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);
164191
}
165-
NodeFS.rmSync(NodePath.join(electronDir, "path.txt"), { force: true });
166-
installElectronRuntime(electronDir, electronPackageJson.version);
167192
}
168193

169194
const missingAfterInstall = missingRuntimePaths(electronDir, platformPath);

‎pnpm-workspace.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ allowBuilds:
1212
browser-tabs-lock: false
1313
bufferutil: false
1414
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
1618
electron-winstaller: false
1719
esbuild: true
1820
msgpackr-extract: true

0 commit comments

Comments
 (0)