fix(desktop): build the unpacked --dir package without GitHub release assets

The JS and TS checks job packages Desktop with `builder --dir`, and its
preparation step fetched the 7zip and icons toolsets plus the Electron zip
from GitHub releases every run. An unpacked build uses none of them: no
archive target runs 7za, and the committed .icns/.ico pass through without
conversion. When icons@1.2.1/icons-bundle.tar.gz returned 504 for over ten
minutes, main went red on every push.

A dir-only preparation now selects neither toolset and, on the host arch,
copies the lock-verified Electron runtime that electron-runtime.mjs already
unpacked, so it makes no network request. Packaged formats keep the old
acquisition, and admission still refuses a non-dir manifest that lacks
the archive or icon tool.
This commit is contained in:
Teknium
2026-11-09 00:49:17 -08:00
parent 546f3b3032
commit 9ffa8c63c1
3 changed files with 72 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ import { isMain } from './utils.mjs'
import { publishPackagingInputs } from './prepared-packaging.mjs'
import { ensureWindowsBundleTools } from './windows-bundle-tools.mjs'
import { prepareDmgbuild } from './prepare-dmgbuild.mjs'
import { prepareElectronRuntime } from '../../../scripts/build/electron-runtime.mjs'
/** @param {string} source @param {string} name @returns {string} */
export function pinnedPackageRoot(source, name) {
@@ -37,6 +38,15 @@ export function packagingTargetArch(target) {
throw new Error(`Packaging preparation requires a same-OS x64/arm64 target, got ${target}`)
}
/**
* The unpacked host Electron, refused unless it is the desktop lock's version and complete.
* @param {string} source @returns {string}
*/
function installedElectronDist(source) {
prepareElectronRuntime({ source, install: false })
return path.join(pinnedPackageRoot(source, 'electron'), 'dist')
}
/** @param {string} from @param {string} to @returns {string} */
function copyTool(from, to) {
fs.rmSync(to, { recursive: true, force: true })
@@ -87,17 +97,23 @@ async function acquirePackagingTools({ source, out, cache, target, formats, buil
load('util/electronGet.js'), load('toolsets/7zip.js'), load('toolsets/icons.js'),
])
const resourcesDir = path.join(source, 'apps/desktop', config.directories?.buildResources || 'build')
// An unpacked (dir) build neither archives nor converts icons (the committed .icns/.ico pass
// through), and on the host arch it can use the lock-verified runtime install.js already unpacked.
// Fetching those GitHub release assets anyway failed `--dir` whenever one of them 504'd.
const unpackedOnly = formats.every(format => format === 'dir')
const hostRuntime = unpackedOnly && packagingTargetArch(target) === process.arch
const [archive, archiveTool, iconTools] = await Promise.all([
electronGet.downloadElectronArtifactZip({ version: config.electronVersion, platformName: process.platform, arch: packagingTargetArch(target),
artifactName: 'electron', cacheDir: path.join(cache, 'electron') }),
sevenZip.getPath7za(), icons.getIconsToolsetPath(config.toolsets?.icons, resourcesDir),
hostRuntime ? null : electronGet.downloadElectronArtifactZip({ version: config.electronVersion, platformName: process.platform,
arch: packagingTargetArch(target), artifactName: 'electron', cacheDir: path.join(cache, 'electron') }),
unpackedOnly ? null : sevenZip.getPath7za(),
unpackedOnly ? null : icons.getIconsToolsetPath(config.toolsets?.icons, resourcesDir),
])
const electron = copyTool(archive, path.join(out, 'electron.zip'))
const electron = hostRuntime ? copyTool(installedElectronDist(source), path.join(out, 'electron'))
: copyTool(/** @type {string} */ (archive), path.join(out, 'electron.zip'))
/** @type {import('./prepared-packaging.mjs').PackagingToolsets} */
const toolsets = {
sevenZip: copyTool(path.dirname(path.dirname(archiveTool)), path.join(out, 'sevenZip')),
icons: copyTool(iconTools, path.join(out, 'icons')),
}
const toolsets = {}
if (archiveTool) toolsets.sevenZip = copyTool(path.dirname(path.dirname(archiveTool)), path.join(out, 'sevenZip'))
if (iconTools) toolsets.icons = copyTool(iconTools, path.join(out, 'icons'))
let windows = null
if (process.platform === 'win32') {
const builder = await load('toolsets/winCodeSign.js')

View File

@@ -3,7 +3,7 @@ import path from 'node:path'
import { createHash } from 'node:crypto'
/** @typedef {{ path: string, digest: string }} PreparedFile */
/** @typedef {{ sevenZip: string, icons: string, winCodeSign?: string, appimage?: string, fpm?: string }} PackagingToolsets */
/** @typedef {{ sevenZip?: string, icons?: string, winCodeSign?: string, appimage?: string, fpm?: string }} PackagingToolsets */
/** @typedef {{ schema: number, source: string, out: string, identity: string, target: string, formats: string[], electron: string, toolsets: PackagingToolsets, windows: import('./windows-bundle-tools.mjs').WindowsBundleTools | null, dmgbuild: string | null, files: PreparedFile[] }} PreparedPackaging */
/** @param {string} message @returns {Error} */
@@ -111,7 +111,10 @@ export function readPackagingInputs(manifest, source, target = `${process.platfo
result.target !== target || result.identity !== packagingIdentity(source)) {
throw preparationRequired('Stale or foreign packaging inputs')
}
const required = [result.electron, result.toolsets.sevenZip, result.toolsets.icons, ...Object.values(result.toolsets)]
if (result.formats.some(format => format !== 'dir') && (!result.toolsets.sevenZip || !result.toolsets.icons)) {
throw preparationRequired('Missing archive or icon tool selection')
}
const required = [result.electron, ...Object.values(result.toolsets)]
if (target.startsWith('win32-')) {
if (!result.windows || !result.toolsets.winCodeSign || !result.windows.dotnetRoot) throw preparationRequired('Missing Windows tool selection')
required.push(result.windows.dotnetRoot)

View File

@@ -5,7 +5,8 @@ import path from 'node:path'
import { afterEach, test } from 'vitest'
import * as prepared from './prepared-packaging.mjs'
import { validatePreparedBuilderArgs } from './run-electron-builder.mjs'
import { spawnSync } from 'node:child_process'
import { spawn, spawnSync } from 'node:child_process'
import http from 'node:http'
/** @type {string[]} */
const roots = []
@@ -59,3 +60,44 @@ test('prepared inputs are path-bound and reject changed or missing bytes without
fs.rmSync(inputs.electron)
assert.throws(() => prepared.readPackagingInputs(manifest, inputs.source, 'linux-x64'), /run preparation again/i)
})
test('an unpacked build prepares from the lock-pinned install with every release host unreachable', async () => {
const source = path.resolve(import.meta.dirname, '../../..')
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'prepared-dir-offline-'))
roots.push(root)
/** @type {string[]} */
const requests = []
const server = http.createServer((request, response) => {
requests.push(String(request.url))
response.writeHead(504).end()
})
await new Promise(resolve => server.listen(0, '127.0.0.1', () => resolve(undefined)))
const mirror = `http://127.0.0.1:${/** @type {import('node:net').AddressInfo} */ (server.address()).port}/`
try {
const out = path.join(root, 'packager')
const child = spawn(process.execPath, [path.join(import.meta.dirname, 'prepare-packaging-tools.mjs'),
'--source', source, '--out', out, '--cache', path.join(root, 'cache'), '--format', 'dir'], {
env: { ...process.env, ELECTRON_BUILDER_BINARIES_MIRROR: mirror, ELECTRON_BUILDER_DANGEROUSLY_ALLOW_HTTP: 'true',
ELECTRON_MIRROR: mirror, HTTPS_PROXY: mirror, HTTP_PROXY: mirror, NO_PROXY: '' },
stdio: ['ignore', 'pipe', 'pipe'],
})
let stderr = ''
child.stderr.on('data', chunk => { stderr += chunk })
const status = await new Promise(resolve => child.on('close', resolve))
assert.equal(status, 0, stderr)
assert.deepEqual(requests, [])
const inputs = prepared.readPackagingInputs(path.join(out, 'prepared.json'), source)
assert.deepEqual(inputs.toolsets, {})
assert.ok(fs.statSync(inputs.electron).isDirectory())
} finally {
await new Promise(resolve => server.close(resolve))
}
})
test('packaged formats still require the archive and icon tools', async () => {
const inputs = fixture()
const manifest = await prepared.publishPackagingInputs({
...inputs, target: 'linux-x64', formats: ['AppImage'], toolsets: { sevenZip: inputs.sevenZip },
})
assert.throws(() => prepared.readPackagingInputs(manifest, inputs.source, 'linux-x64'), /archive or icon tool/)
})