Preserve Electron framework symlinks (#2958)

Preserve Electron framework symlinks
This commit is contained in:
Neil
2026-05-27 18:13:25 -07:00
committed by GitHub
parent 0a069b15d6
commit 77f5b2ad9d
2 changed files with 31 additions and 3 deletions
@@ -127,8 +127,7 @@ async function installElectronPackageBinary() {
process.exit(1)
}
rmSync(electronDistDir, { recursive: true, force: true })
cpSync(extractDir, electronDistDir, { recursive: true })
moveExtractedElectronDist(extractDir, electronDistDir)
const srcTypeDefPath = resolve(electronDistDir, 'electron.d.ts')
if (existsSync(srcTypeDefPath)) {
@@ -157,6 +156,24 @@ function extractElectronArchive(zipPath, extractDir) {
}
}
function moveExtractedElectronDist(extractDir, electronDistDir) {
rmSync(electronDistDir, { recursive: true, force: true })
try {
// Why: macOS Electron archives rely on framework symlinks. Moving the
// verified tree preserves them exactly; copying has broken them in CI.
renameSync(extractDir, electronDistDir)
} catch (/** @type {any} */ err) {
if (err?.code !== 'EXDEV') {
throw err
}
cpSync(extractDir, electronDistDir, {
recursive: true,
dereference: false,
verbatimSymlinks: true
})
}
}
function getExtractorCommand(zipPath, extractDir) {
if (process.env.ORCA_ELECTRON_PACKAGE_EXTRACTOR) {
return {
@@ -1,6 +1,7 @@
import {
copyFileSync,
existsSync,
lstatSync,
mkdirSync,
mkdtempSync,
readFileSync,
@@ -35,6 +36,13 @@ describe('install-electron-package-binary', () => {
expect(readFileSync(join(projectDir, 'node_modules', 'electron', 'path.txt'), 'utf8')).toBe(
'electron'
)
if (process.platform !== 'win32') {
expect(
lstatSync(
join(projectDir, 'node_modules', 'electron', 'dist', 'version-link')
).isSymbolicLink()
).toBe(true)
}
expect(result.stdout).toContain('Repaired Electron path.txt -> electron')
} finally {
rmSync(projectDir, { recursive: true, force: true })
@@ -153,13 +161,16 @@ function writeFakeExtractor(projectDir, { createExecutable }) {
writeFileSync(
join(projectDir, 'fake-extractor.cjs'),
`
const { mkdirSync, writeFileSync } = require('node:fs')
const { mkdirSync, symlinkSync, writeFileSync } = require('node:fs')
const { join } = require('node:path')
const extractDir = process.argv[3]
mkdirSync(join(extractDir, 'locales'), { recursive: true })
if (${JSON.stringify(createExecutable)}) {
writeFileSync(join(extractDir, 'electron'), '')
writeFileSync(join(extractDir, 'version'), 'v41.5.0')
if (process.platform !== 'win32') {
symlinkSync('version', join(extractDir, 'version-link'))
}
}
`
)