Rebuild stale macOS dev Electron app copies (#2479)
- Detect missing Chromium framework resources before reusing the copied app - Prevent interrupted copies from leaving `pn dev` with a blank Electron window
This commit is contained in:
@@ -155,14 +155,40 @@ function prepareMacDevElectronApp() {
|
||||
null,
|
||||
2
|
||||
)
|
||||
const executablePath = path.join(appPath, 'Contents', 'MacOS', 'Electron')
|
||||
const requiredResourcePaths = [
|
||||
path.join(
|
||||
appPath,
|
||||
'Contents',
|
||||
'Frameworks',
|
||||
'Electron Framework.framework',
|
||||
'Resources',
|
||||
'icudtl.dat'
|
||||
)
|
||||
]
|
||||
|
||||
if (existsSync(markerPath) && existsSync(appPath)) {
|
||||
function copiedAppIsUsable() {
|
||||
if (!existsSync(markerPath) || !existsSync(appPath)) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
if (readFileSync(markerPath, 'utf8') === expectedMarker) {
|
||||
process.env.ELECTRON_EXEC_PATH = path.join(appPath, 'Contents', 'MacOS', 'Electron')
|
||||
return
|
||||
if (readFileSync(markerPath, 'utf8') !== expectedMarker) {
|
||||
return false
|
||||
}
|
||||
} catch {}
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
// Why: a previous interrupted copy can leave the marker and executable
|
||||
// present but miss Chromium framework resources, causing a blank crash.
|
||||
return (
|
||||
existsSync(executablePath) &&
|
||||
requiredResourcePaths.every((resourcePath) => existsSync(resourcePath))
|
||||
)
|
||||
}
|
||||
|
||||
if (copiedAppIsUsable()) {
|
||||
process.env.ELECTRON_EXEC_PATH = executablePath
|
||||
return
|
||||
}
|
||||
|
||||
rmSync(distDir, { recursive: true, force: true })
|
||||
@@ -178,7 +204,7 @@ function prepareMacDevElectronApp() {
|
||||
// and Electron's framework bundle is ambiguous to codesign when deep-signing
|
||||
// an already-built distribution. Avoid blocking `pn dev` on local signing.
|
||||
writeFileSync(markerPath, expectedMarker, 'utf8')
|
||||
process.env.ELECTRON_EXEC_PATH = path.join(appPath, 'Contents', 'MacOS', 'Electron')
|
||||
process.env.ELECTRON_EXEC_PATH = executablePath
|
||||
}
|
||||
|
||||
function getDevUserDataPath() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { mkdtempSync, readFileSync } from 'node:fs'
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
|
||||
@@ -228,4 +228,85 @@ describe('run-electron-vite-dev', () => {
|
||||
|
||||
wrapper.kill('SIGINT')
|
||||
})
|
||||
|
||||
it.skipIf(process.platform !== 'darwin')(
|
||||
'rebuilds the copied Electron app when Chromium resources are missing',
|
||||
async () => {
|
||||
const tempDir = mkdtempSync(join(tmpdir(), 'orca-dev-wrapper-'))
|
||||
const wrapperPath = resolve('config/scripts/run-electron-vite-dev.mjs')
|
||||
const fakeCliPath = resolve('src/main/startup/__fixtures__/fake-electron-vite-dev-cli.mjs')
|
||||
const baseEnv = devWrapperTestEnv({
|
||||
ORCA_ELECTRON_VITE_CLI: fakeCliPath,
|
||||
ORCA_SKIP_DEV_CLI_PREPARE: '1',
|
||||
ORCA_SKIP_DEV_WEB_PREPARE: '1',
|
||||
ORCA_DEV_BRANCH: 'feature/rebuild-electron-app',
|
||||
ORCA_DEV_WORKTREE_NAME: 'electron-app-rebuild'
|
||||
})
|
||||
|
||||
async function runWrapper(runId: string): Promise<{ electronExecPath: string }> {
|
||||
const pidFile = join(tempDir, `${runId}.pid`)
|
||||
const envFile = join(tempDir, `${runId}.json`)
|
||||
const wrapper = spawn(process.execPath, [wrapperPath, '--remote-debugging-port=9448'], {
|
||||
cwd: resolve('.'),
|
||||
env: {
|
||||
...baseEnv,
|
||||
ORCA_DEV_WRAPPER_TEST_PID_FILE: pidFile,
|
||||
ORCA_DEV_WRAPPER_TEST_ENV_FILE: envFile
|
||||
},
|
||||
stdio: 'ignore'
|
||||
})
|
||||
|
||||
expect(wrapper.pid).toBeTypeOf('number')
|
||||
processesToCleanUp.add(wrapper.pid!)
|
||||
|
||||
await waitFor(() => {
|
||||
try {
|
||||
return readFileSync(envFile, 'utf8').trim().length > 0
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}, 20000)
|
||||
|
||||
const grandchildPid = Number.parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
|
||||
if (Number.isFinite(grandchildPid)) {
|
||||
processesToCleanUp.add(grandchildPid)
|
||||
}
|
||||
|
||||
const envSnapshot = JSON.parse(readFileSync(envFile, 'utf8')) as {
|
||||
electronExecPath: string | null
|
||||
}
|
||||
expect(envSnapshot.electronExecPath).toBeTypeOf('string')
|
||||
wrapper.kill('SIGINT')
|
||||
return { electronExecPath: envSnapshot.electronExecPath! }
|
||||
}
|
||||
|
||||
let distDir: string | null = null
|
||||
try {
|
||||
const firstRun = await runWrapper('first')
|
||||
const appPath = dirname(dirname(dirname(firstRun.electronExecPath)))
|
||||
distDir = dirname(appPath)
|
||||
const icuDataPath = join(
|
||||
appPath,
|
||||
'Contents',
|
||||
'Frameworks',
|
||||
'Electron Framework.framework',
|
||||
'Resources',
|
||||
'icudtl.dat'
|
||||
)
|
||||
expect(existsSync(icuDataPath)).toBe(true)
|
||||
|
||||
rmSync(icuDataPath, { force: true })
|
||||
expect(existsSync(icuDataPath)).toBe(false)
|
||||
|
||||
const secondRun = await runWrapper('second')
|
||||
expect(secondRun.electronExecPath).toBe(firstRun.electronExecPath)
|
||||
expect(existsSync(icuDataPath)).toBe(true)
|
||||
} finally {
|
||||
if (distDir) {
|
||||
rmSync(distDir, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
},
|
||||
30000
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user