Files
otunes/apps/desktop/scripts/build-web.mjs
T
joshuafhigginsandClaude Opus 5.5 Verified 2a77c92332 feat(desktop): ship stock Electron for Windows and Linux
Drop the custom EAC-3 Chromium build and macOS packaging. Windows NSIS
installers and Flatpaks for x64 and ARM64 now build in one Linux
container image.

Packaged installers previously lost the bundled Next.js dependencies:
electron-builder drops the pnpm store and NSIS cannot carry symlinks.
The bundle now replaces pnpm links with nested real copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 00:14:47 -05:00

72 lines
2.4 KiB
JavaScript

import { execFileSync } from "node:child_process"
import { createRequire } from "node:module"
import { cp, mkdir, rm, readdir, readlink, realpath } from "node:fs/promises"
import path from "node:path"
import { materializeLinks } from "./materialize-links.mjs"
import { pruneNativeImages } from "./prune-native-images.mjs"
import { fileURLToPath } from "node:url"
const desktopRoot = fileURLToPath(new URL("../", import.meta.url))
const web = path.resolve(desktopRoot, "../web")
const webRequire = createRequire(path.join(web, "package.json"))
execFileSync(
process.execPath,
[webRequire.resolve("next/dist/bin/next"), "build"],
{
cwd: web,
stdio: "inherit",
env: {
...process.env,
OTUNES_DESKTOP_BUILD: "1",
NEXT_PUBLIC_CONVEX_URL: "",
},
}
)
// Junction fallbacks on Windows can point back into the developer's checkout.
// Reject them rather than shipping an installer that only works on that machine.
const standalone = path.join(web, ".next-desktop/standalone")
async function checkLinks(directory) {
for (const entry of await readdir(directory, { withFileTypes: true })) {
const file = path.join(directory, entry.name)
if (entry.isSymbolicLink()) {
const target = await readlink(file)
const resolved = await realpath(file)
const relative = path.relative(standalone, resolved)
if (
path.isAbsolute(target) ||
relative === ".." ||
relative.startsWith(`..${path.sep}`) ||
path.isAbsolute(relative)
) {
throw new Error(
"The standalone bundle contains a non-relocatable link. Enable symlink permissions or Windows Developer Mode and rebuild."
)
}
} else if (entry.isDirectory()) {
await checkLinks(file)
}
}
}
await checkLinks(standalone)
const destination = path.join(desktopRoot, "web")
await rm(destination, { recursive: true, force: true })
await cp(standalone, destination, {
recursive: true,
verbatimSymlinks: true,
filter: (file) => !path.basename(file).startsWith(".env"),
})
const app = path.join(destination, "apps/web")
await mkdir(path.join(app, ".next-desktop"), { recursive: true })
await cp(
path.join(web, ".next-desktop/static"),
path.join(app, ".next-desktop/static"),
{ recursive: true }
)
await cp(path.join(web, "public"), path.join(app, "public"), {
recursive: true,
})
await materializeLinks(destination)
await pruneNativeImages(destination)