@@ -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+
152176export 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 ) ;
0 commit comments