fix(desktop): ship a prebuilt Linux node-pty for the packaged WSL backend

In packaged builds the server bundle and node-pty were sealed inside app.asar,
which the WSL backend's Linux Node cannot read, so the WSL backend never started
in release builds. It dead-ended on a misleading "node-pty not prepared / run
prepare:wsl" error. node-pty also publishes no Linux prebuilt, and the Windows
artifact is built on a Windows CI runner that cannot compile one.

- asarUnpack the server bundle and node-pty, and point the WSL backend at the
  app.asar.unpacked sibling. The Windows primary still reads app.asar via
  ELECTRON_RUN_AS_NODE, so it is unaffected and there is no payload duplication.
- Build the Linux pty.node in a dedicated Linux CI job and hand it to the
  Windows packaging job as an artifact. build-desktop-artifact stages it into
  node-pty/prebuilds/linux-<arch>/ with a marker, so the packaged app ships a
  ready binary and needs no compiler, node-gyp, or network on first launch.
- node-pty is N-API, so one Linux binary works across all WSL Node versions;
  drop the modules ABI comparison from the preflight probe accordingly.
- Runtime compile is now dev-only (allowBuild: !isPackaged). In packaged builds
  a prebuilt that cannot load surfaces a clear arch/distro diagnostic instead of
  nagging for build tools or silently compiling.
This commit is contained in:
Josh Gratton committed 2026-06-10 20:44:48 -04:00
1 parent 0bb1553690
commit da782dadd8
5 files changed
+218 -16

No files matched your search

@@ -376,10 +376,29 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
...buildObservabilityFragment(input.observabilitySettings),
};
// In packaged builds environment.appRoot is .../resources/app.asar — an
// archive FILE. The Windows primary reads its entry through
// ELECTRON_RUN_AS_NODE (asar-aware), but the WSL backend launches plain
// `wsl.exe -- node`, which can't read inside an asar. electron-builder unpacks
// the server bundle + node-pty (see asarUnpack in build-desktop-artifact.ts)
// to the app.asar.unpacked sibling, so point WSL there. In dev appRoot is
// already a real directory, so this is a no-op.
const wslAppRoot = environment.isPackaged
? environment.path.join(environment.resourcesPath, "app.asar.unpacked")
: environment.appRoot;
const wslEntryPath = environment.path.join(wslAppRoot, "apps/server/dist/bin.mjs");
const preflight = yield* runWslPreflight({
distro: input.distro,
windowsEntryPath: environment.backendEntryPath,
windowsRepoRoot: environment.appRoot,
windowsEntryPath: wslEntryPath,
windowsRepoRoot: wslAppRoot,
// Packaged builds ship a prebuilt Linux node-pty (built on Linux in CI and
// attached to the Windows artifact — see build-desktop-artifact.ts), so the
// WSL backend never needs a compiler, node-gyp, or network on first launch.
// Compiling from source is a dev-only convenience: a checkout has no shipped
// prebuilt, and developers have the toolchain. In packaged builds we instead
// surface a clear diagnostic if the prebuilt can't load (unsupported
// arch/distro), rather than silently dropping into a fragile runtime build.
allowBuild: !environment.isPackaged,
});
@@ -408,7 +427,7 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
const baseConfig = {
executablePath: "wsl.exe",
entryPath: environment.backendEntryPath,
entryPath: wslEntryPath,
cwd: environment.backendCwd,
env: {
...parentEnvWithoutT3Home,
+28 -11
View File
@@ -161,9 +161,14 @@ cd ${shellQuote(linuxServerDir)} && node <<'NODE' >/dev/null 2>&1
const fs = require("node:fs");
const path = require("node:path");
const pkgDir = path.dirname(require.resolve("node-pty/package.json"));
// node-pty 1.x is N-API based, so a single Linux pty.node is ABI-stable across
// Node versions — require() succeeding IS the real compatibility test. Compare
// only arch and node-pty version (a stale binary from a different node-pty),
// NOT process.versions.modules: that would reject a perfectly loadable prebuilt
// whenever the user's WSL Node ABI differs from the build's, defeating the
// whole point of shipping one prebuilt for all Node versions.
const expected = {
arch: process.arch,
modules: process.versions.modules,
nodePtyVersion: require("node-pty/package.json").version,
};
const marker = path.join(pkgDir, "prebuilds", "linux-" + process.arch, "t3code-wsl-node-pty.json");
@@ -325,11 +330,7 @@ const ensureNodePtyImpl = (
if (probe.exitCode === 0) return { ok: true, nodePath } as const;
// node exists but node-pty isn't ready. Run the toolchain check before the
// allowBuild branch so an out-of-range version or missing build tools
// surfaces as a specific, actionable message in both dev and packaged
// builds — otherwise users saw a generic "node-pty is not prepared" error
// pointing at a script that itself would have failed for the same reason.
// node is present but node-pty's native module didn't load.
const toolchainCheck = yield* runWslShell(
distro,
TOOLCHAIN_CHECK_SCRIPT,
@@ -337,19 +338,35 @@ const ensureNodePtyImpl = (
options,
);
const report = parseToolchainReport(toolchainCheck.stdout);
const missingReason = formatMissingToolsReason(report, options.nodeEngineRange?.trim() || null);
if (missingReason !== null) {
return { ok: false, reason: missingReason } as const;
}
if (options.allowBuild !== true) {
// Packaged builds ship a prebuilt Linux node-pty, so no compiler, node-gyp,
// or network is needed — and we must not nag the user to install build
// tools they don't need. Still surface a missing/too-old Node (both the
// prebuilt and the server require a compatible Node); otherwise reaching
// here means the bundled binary itself couldn't load, which is almost
// always an unsupported CPU architecture or incompatible system libraries.
const nodeOnlyReason = formatMissingToolsReason(
{ missingTools: report.missingTools.filter((tool) => tool === "node"), nodeVersion: report.nodeVersion },
options.nodeEngineRange?.trim() || null,
);
return {
ok: false,
reason:
"node-pty is not prepared for this WSL Node runtime. Run `bun run prepare:wsl` from this checkout, then restart the desktop app.",
nodeOnlyReason ??
"The bundled WSL backend binary (node-pty) could not be loaded in this distro. This usually means an unsupported CPU architecture or incompatible system libraries (glibc). Use a glibc-based x64/arm64 WSL distro such as Ubuntu; if you already are, please report this with your distro and the output of `uname -m`.",
} as const;
}
// Dev only: no prebuilt is bundled in a checkout, so compile node-pty from
// source. Run the toolchain check first so a missing compiler or out-of-range
// Node surfaces a specific, actionable message instead of an opaque node-gyp
// failure. Developers have the toolchain; end users never reach this path.
const missingReason = formatMissingToolsReason(report, options.nodeEngineRange?.trim() || null);
if (missingReason !== null) {
return { ok: false, reason: missingReason } as const;
}
const build = yield* runWslShell(
distro,
NODE_PTY_BUILD_SCRIPT(linuxServerDir),