Skip to content

Commit d88a33e

Browse files
committed
fix(desktop): remove unsupported preload imports
1 parent 918ebf6 commit d88a33e

4 files changed

Lines changed: 40 additions & 8 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ jobs:
5252
run: vp run build:desktop
5353

5454
- name: Verify preload bundle output
55-
run: |
56-
test -f apps/desktop/dist-electron/preload.cjs
57-
grep -nE "desktopBridge|getLocalEnvironmentBootstrap|PICK_FOLDER_CHANNEL|wsUrl" apps/desktop/dist-electron/preload.cjs
58-
grep -n "__clerk_internal_electron_passkeys" apps/desktop/dist-electron/preload.cjs
55+
run: node apps/desktop/scripts/verify-preload-bundle.mjs
5956

6057
# Everything except `t3` (apps/server). `--parallel` drops the package
6158
# dependency ordering that `vp run` applies by default: these `test` tasks
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as NodeFSP from "node:fs/promises";
2+
3+
const preloadUrl = new URL("../dist-electron/preload.cjs", import.meta.url);
4+
const source = await NodeFSP.readFile(preloadUrl, "utf8");
5+
6+
const expectedSymbols = [
7+
"desktopBridge",
8+
"getClientPlatform",
9+
"getLocalEnvironmentBootstrap",
10+
"PICK_FOLDER_CHANNEL",
11+
"__clerk_internal_electron_passkeys",
12+
];
13+
const missingSymbols = expectedSymbols.filter((symbol) => !source.includes(symbol));
14+
15+
if (missingSymbols.length > 0) {
16+
throw new Error(`Desktop preload bundle is missing: ${missingSymbols.join(", ")}`);
17+
}
18+
19+
const runtimeImportPattern = /\brequire\(\s*(["'])([^"']+)\1\s*\)/g;
20+
const runtimeImports = [...source.matchAll(runtimeImportPattern)].map((match) => match[2]);
21+
const runtimeRequireCount = [...source.matchAll(/\brequire\s*\(/g)].length;
22+
23+
if (runtimeImports.length !== runtimeRequireCount) {
24+
throw new Error("Desktop preload bundle contains a dynamic runtime import");
25+
}
26+
27+
const sandboxModules = new Set(["electron", "events", "timers", "url"]);
28+
const unsupportedImports = [...new Set(runtimeImports)]
29+
.filter((moduleName) => !sandboxModules.has(moduleName))
30+
.toSorted();
31+
32+
if (unsupportedImports.length > 0) {
33+
throw new Error(
34+
`Desktop preload bundle contains unsupported sandbox imports: ${unsupportedImports.join(", ")}`,
35+
);
36+
}

‎apps/desktop/src/preload.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import type {
55
DesktopPreviewTabState,
66
} from "@t3tools/contracts";
77
import { exposeClerkBridge } from "@clerk/electron/preload";
8-
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
9-
import * as Effect from "effect/Effect";
108
import { contextBridge, ipcRenderer } from "electron";
119

1210
import * as IpcChannels from "./ipc/channels.ts";
1311

1412
exposeClerkBridge({ passkeys: true });
1513

16-
const clientPlatform = Effect.runSync(HostProcessPlatform);
14+
// oxlint-disable-next-line t3code/no-global-process-runtime -- Electron exposes the client platform in its sandboxed preload process.
15+
const clientPlatform = process.platform;
1716

1817
function unwrapEnsureSshEnvironmentResult(result: unknown) {
1918
if (

‎docs/internals/ci.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and pushes to `main`:
88
- **Check**: `vp check` (format and lint; this repo sets `typeCheck: false` in its lint options),
99
then `vpr typecheck` for the workspace type check. The same job
1010
builds the desktop pipeline (`vp run build:desktop`) and verifies the preload bundle exists and
11-
still exports its expected symbols.
11+
still exports its expected symbols without runtime imports that Electron's sandbox cannot load.
1212
- **Test**: `vp run test` across the workspace.
1313
- **Mobile Native Static Analysis**: `vp run lint:mobile` on macOS, wrapping
1414
`scripts/mobile-native-static-check.ts`. A cheap Linux **Mobile Native Changes** job gates it:

0 commit comments

Comments
 (0)