Skip to content

Commit 80120b1

Browse files
authored
fix(desktop): skip prepared server bytecode on Linux (#28700)
1 parent 82b10d5 commit 80120b1

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎docs/operations/development.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,19 @@ options.
263263

264264
### Prepared server bytecode
265265

266-
Native desktop artifact builds generate server bytecode with the packaged Electron executable,
267-
after ASAR creation and before signing. Cross-platform and cross-architecture builds skip this
268-
step explicitly. CLI, SEA and WSL runtimes keep their existing behavior; only desktop backend
269-
imports covered by generation receive prepared bytecode. Worker-only modules compile normally.
266+
Native macOS and Windows desktop artifact builds generate server bytecode with the packaged
267+
Electron executable, after ASAR creation and before signing. Linux builds skip generation until
268+
native packaging and relocated AppImage reuse have been validated. Cross-platform and
269+
cross-architecture builds also skip generation explicitly. CLI, SEA and WSL runtimes keep their
270+
existing behavior; only desktop backend imports covered by generation receive prepared bytecode.
271+
Worker-only modules compile normally.
270272

271273
Electron's Node 24 cache has no read-only option and includes the producer UID in its directory
272274
name. The backend links individual prepared files into its writable cache with keys for the
273275
installed module paths. Node replaces files atomically, so regeneration cannot write through those
274276
links into signed resources. Windows uses hard links and falls back to normal caching when volumes
275277
differ or resource permissions prevent linking. Protected installations therefore may not reuse
276-
prepared bytecode. No cache bytes are copied during startup. AppImage backends discard their links
277-
on normal exit because each mount changes module paths.
278+
prepared bytecode. No cache bytes are copied during startup.
278279

279280
The key calculation follows Node's internal portable ESM format. Generation checks that the
280281
packaged engine produced the expected CLI entry and fails the build if that format changes.

‎scripts/lib/server-compile-cache.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@
22
import * as NodeFS from "node:fs";
33
import * as NodeOS from "node:os";
44
import * as NodePath from "node:path";
5+
import * as NodeURL from "node:url";
56
import { expect, it } from "vite-plus/test";
67
import { cacheKey, seedPreparedCache } from "./server-compile-cache.ts";
78

9+
it.each(["x64", "arm64"])("skips prepared bytecode generation on Linux %s", async (arch) => {
10+
const { spawnSync } = await import("node:child_process");
11+
const hook = NodeURL.fileURLToPath(
12+
new URL("../prepare-server-compile-cache.cjs", import.meta.url),
13+
);
14+
const result = spawnSync(
15+
process.execPath,
16+
[
17+
"-e",
18+
`Object.defineProperty(process, "platform", { value: "linux" });
19+
Object.defineProperty(process, "arch", { value: ${JSON.stringify(arch)} });
20+
require(${JSON.stringify(hook)})({ electronPlatformName: "linux", arch: ${arch === "x64" ? 1 : 3} }).catch(error => { console.error(error); process.exitCode = 1; });`,
21+
],
22+
{ encoding: "utf8" },
23+
);
24+
expect(result.status, result.stderr).toBe(0);
25+
expect(result.stdout).toContain("Skipping unsupported target linux");
26+
});
27+
828
it("seeds relocated cache entries without allowing writes into shipped resources", () => {
929
const root = NodeFS.realpathSync(
1030
NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-prepared-test-")),

‎scripts/prepare-server-compile-cache.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const os = require("node:os");
66

77
// afterPack runs before signing and installer creation, against the final ASAR layout.
88
module.exports = async ({ appOutDir, electronPlatformName, arch, packager }) => {
9+
// Linux packaging and relocated AppImage cache reuse still need native validation.
10+
if (electronPlatformName !== "darwin" && electronPlatformName !== "win32") {
11+
console.log(`[server-compile-cache] Skipping unsupported target ${electronPlatformName}`);
12+
return;
13+
}
914
const targetArch = ["ia32", "x64", "armv7l", "arm64", "universal"][arch];
1015
if (electronPlatformName !== process.platform || targetArch !== process.arch) {
1116
console.log(

0 commit comments

Comments
 (0)