Skip to content

Commit 9107107

Browse files
committed
Package the desktop app, and stop electron-builder failing after it succeeds
scripts/package-desktop.mjs stages the app with `pnpm deploy` before running electron-builder: the workspace dependencies are symlinks pointing outside apps/desktop, and asar refuses any path that is not under the app directory. Two failures worth recording. A stale Next cache crashes webpack's wasm hashing with "Cannot read properties of undefined (reading 'length')", which reads as a code error rather than the cache problem it is, so the packager cleans first. And CI=true — required so pnpm does not stop for a TTY prompt — also makes electron-builder try to upload to a draft GitHub release, failing the build after every artifact has already been written correctly; hence --publish never.
1 parent 38fe397 commit 9107107

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎scripts/package-desktop.mjs‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Builds the desktop packages.
4+
*
5+
* electron-builder cannot pack a pnpm workspace app directly: the workspace
6+
* dependencies are symlinks pointing outside the app directory, and asar
7+
* refuses any path that is not under it. `pnpm deploy` materialises them into
8+
* a staging directory whose node_modules is self-contained, and the build runs
9+
* from there.
10+
*
11+
* Run scripts/package-cli.mjs first: it produces the CLI copy this embeds.
12+
*/
13+
import { execFileSync } from 'node:child_process'
14+
import { existsSync, mkdirSync, rmSync } from 'node:fs'
15+
import { homedir } from 'node:os'
16+
import { join, resolve } from 'node:path'
17+
18+
const root = resolve(import.meta.dirname, '..')
19+
const desktop = join(root, 'apps/desktop')
20+
const outDir = process.argv[2] ? resolve(process.argv[2]) : join(root, 'release')
21+
22+
// Under the home cache, not /tmp: this machine's /tmp is a tmpfs too small for
23+
// an unpacked Electron app plus the squashfs the AppImage target stages there.
24+
const cache = join(homedir(), '.cache')
25+
const stage = join(cache, 'diskpush-desktop-stage')
26+
const buildTmp = join(cache, 'diskpush-build-tmp')
27+
28+
function run(command, args, cwd, env = {}) {
29+
execFileSync(command, args, { stdio: 'inherit', cwd, env: { ...process.env, CI: 'true', ...env } })
30+
}
31+
32+
if (!existsSync(join(desktop, 'resources/cli/dist/bin.js'))) {
33+
console.error('resources/cli is missing. Run scripts/package-cli.mjs first.')
34+
process.exit(1)
35+
}
36+
37+
// A stale Next cache from a previous build crashes webpack's wasm hashing
38+
// with "Cannot read properties of undefined (reading 'length')", which reads
39+
// as a code error rather than the cache problem it is.
40+
console.log('cleaning previous build output...')
41+
for (const dir of ['out', '.next', 'dist-electron', 'tsconfig.tsbuildinfo']) {
42+
rmSync(join(desktop, dir), { recursive: true, force: true })
43+
}
44+
45+
console.log('building renderer and electron...')
46+
run('pnpm', ['--filter', '@diskpush/desktop', 'build'], root)
47+
48+
console.log('staging a self-contained app...')
49+
rmSync(stage, { recursive: true, force: true })
50+
run('pnpm', ['deploy', '--filter', '@diskpush/desktop', '--legacy', stage], root)
51+
52+
mkdirSync(buildTmp, { recursive: true })
53+
const targets = process.argv.slice(3).length > 0 ? process.argv.slice(3) : ['AppImage', 'deb', 'tar.gz']
54+
55+
console.log(`packaging: ${targets.join(', ')}`)
56+
// --publish never: CI=true (needed so pnpm does not stop for a TTY prompt)
57+
// also makes electron-builder try to upload to a draft GitHub release, which
58+
// fails the build after every artifact has already been written correctly.
59+
run(
60+
'./node_modules/.bin/electron-builder',
61+
['--linux', ...targets, '--publish', 'never', `-c.directories.output=${outDir}`],
62+
stage,
63+
{ TMPDIR: buildTmp },
64+
)
65+
66+
console.log(`\nartifacts in ${outDir}`)

0 commit comments

Comments
 (0)