Skip to content

Commit 8dba2d6

Browse files
Adopt Node-native TypeScript for desktop and server (#2098)
1 parent ed6b7fb commit 8dba2d6

140 files changed

Lines changed: 2071 additions & 1526 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ jobs:
7171

7272
- name: Verify preload bundle output
7373
run: |
74-
test -f apps/desktop/dist-electron/preload.js
75-
grep -nE "desktopBridge|getLocalEnvironmentBootstrap|PICK_FOLDER_CHANNEL|wsUrl" apps/desktop/dist-electron/preload.js
74+
test -f apps/desktop/dist-electron/preload.cjs
75+
grep -nE "desktopBridge|getLocalEnvironmentBootstrap|PICK_FOLDER_CHANNEL|wsUrl" apps/desktop/dist-electron/preload.cjs
7676
7777
release_smoke:
7878
name: Release Smoke

apps/desktop/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
"name": "@t3tools/desktop",
33
"version": "0.0.20",
44
"private": true,
5-
"main": "dist-electron/main.js",
5+
"type": "module",
6+
"main": "dist-electron/main.cjs",
67
"scripts": {
78
"dev": "bun run --parallel dev:bundle dev:electron",
89
"dev:bundle": "tsdown --watch",
9-
"dev:electron": "bun run scripts/dev-electron.mjs",
10+
"dev:electron": "node scripts/dev-electron.mjs",
1011
"build": "tsdown",
11-
"start": "bun run scripts/start-electron.mjs",
12+
"start": "node scripts/start-electron.mjs",
1213
"typecheck": "tsc --noEmit",
1314
"test": "vitest run --passWithNoTests",
1415
"smoke-test": "node scripts/smoke-test.mjs"

apps/desktop/scripts/dev-electron.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ if (!Number.isInteger(port) || port <= 0) {
1717
}
1818

1919
const requiredFiles = [
20-
"dist-electron/main.js",
21-
"dist-electron/preload.js",
20+
"dist-electron/main.cjs",
21+
"dist-electron/preload.cjs",
2222
"../server/dist/bin.mjs",
2323
];
2424
const watchedDirectories = [
25-
{ directory: "dist-electron", files: new Set(["main.js", "preload.js"]) },
25+
{ directory: "dist-electron", files: new Set(["main.cjs", "preload.cjs"]) },
2626
{ directory: "../server/dist", files: new Set(["bin.mjs"]) },
2727
];
2828
const forcedShutdownTimeoutMs = 1_500;
@@ -69,7 +69,7 @@ function startApp() {
6969

7070
const app = spawn(
7171
resolveElectronPath(),
72-
[`--t3code-dev-root=${desktopDir}`, "dist-electron/main.js"],
72+
[`--t3code-dev-root=${desktopDir}`, "dist-electron/main.cjs"],
7373
{
7474
cwd: desktopDir,
7575
env: childEnv,

apps/desktop/scripts/electron-launcher.mjs

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
mkdirSync,
99
mkdtempSync,
1010
readFileSync,
11-
readdirSync,
1211
rmSync,
1312
statSync,
1413
writeFileSync,
@@ -20,7 +19,7 @@ import { fileURLToPath } from "node:url";
2019
const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL);
2120
const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alpha)";
2221
const APP_BUNDLE_ID = isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code";
23-
const LAUNCHER_VERSION = 1;
22+
const LAUNCHER_VERSION = 2;
2423

2524
const __dirname = dirname(fileURLToPath(import.meta.url));
2625
export const desktopDir = resolve(__dirname, "..");
@@ -121,40 +120,6 @@ function patchMainBundleInfoPlist(appBundlePath, iconPath) {
121120
copyFileSync(iconPath, join(resourcesDir, "electron.icns"));
122121
}
123122

124-
function patchHelperBundleInfoPlists(appBundlePath) {
125-
const frameworksDir = join(appBundlePath, "Contents", "Frameworks");
126-
if (!existsSync(frameworksDir)) {
127-
return;
128-
}
129-
130-
for (const entry of readdirSync(frameworksDir, { withFileTypes: true })) {
131-
if (!entry.isDirectory() || !entry.name.endsWith(".app")) {
132-
continue;
133-
}
134-
if (!entry.name.startsWith("Electron Helper")) {
135-
continue;
136-
}
137-
138-
const helperPlistPath = join(frameworksDir, entry.name, "Contents", "Info.plist");
139-
if (!existsSync(helperPlistPath)) {
140-
continue;
141-
}
142-
143-
const suffix = entry.name.replace("Electron Helper", "").replace(".app", "").trim();
144-
const helperName = suffix
145-
? `${APP_DISPLAY_NAME} Helper ${suffix}`
146-
: `${APP_DISPLAY_NAME} Helper`;
147-
const helperIdSuffix = suffix.replace(/[()]/g, "").trim().toLowerCase().replace(/\s+/g, "-");
148-
const helperBundleId = helperIdSuffix
149-
? `${APP_BUNDLE_ID}.helper.${helperIdSuffix}`
150-
: `${APP_BUNDLE_ID}.helper`;
151-
152-
setPlistString(helperPlistPath, "CFBundleDisplayName", helperName);
153-
setPlistString(helperPlistPath, "CFBundleName", helperName);
154-
setPlistString(helperPlistPath, "CFBundleIdentifier", helperBundleId);
155-
}
156-
}
157-
158123
function readJson(path) {
159124
try {
160125
return JSON.parse(readFileSync(path, "utf8"));
@@ -192,7 +157,6 @@ function buildMacLauncher(electronBinaryPath) {
192157
rmSync(targetAppBundlePath, { recursive: true, force: true });
193158
cpSync(sourceAppBundlePath, targetAppBundlePath, { recursive: true });
194159
patchMainBundleInfoPlist(targetAppBundlePath, iconPath);
195-
patchHelperBundleInfoPlists(targetAppBundlePath);
196160
writeFileSync(metadataPath, `${JSON.stringify(expectedMetadata, null, 2)}\n`);
197161

198162
return targetBinaryPath;
@@ -206,5 +170,11 @@ export function resolveElectronPath() {
206170
return electronBinaryPath;
207171
}
208172

173+
// Dev launches do not need a renamed app bundle badly enough to risk breaking
174+
// Electron helper resource lookup on macOS.
175+
if (isDevelopment) {
176+
return electronBinaryPath;
177+
}
178+
209179
return buildMacLauncher(electronBinaryPath);
210180
}

apps/desktop/scripts/smoke-test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
55
const __dirname = dirname(fileURLToPath(import.meta.url));
66
const desktopDir = resolve(__dirname, "..");
77
const electronBin = resolve(desktopDir, "node_modules/.bin/electron");
8-
const mainJs = resolve(desktopDir, "dist-electron/main.js");
8+
const mainJs = resolve(desktopDir, "dist-electron/main.cjs");
99

1010
console.log("\nLaunching Electron smoke test...");
1111

apps/desktop/scripts/start-electron.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { desktopDir, resolveElectronPath } from "./electron-launcher.mjs";
55
const childEnv = { ...process.env };
66
delete childEnv.ELECTRON_RUN_AS_NODE;
77

8-
const child = spawn(resolveElectronPath(), ["dist-electron/main.js"], {
8+
const child = spawn(resolveElectronPath(), ["dist-electron/main.cjs"], {
99
stdio: "inherit",
1010
cwd: desktopDir,
1111
env: childEnv,

apps/desktop/src/appBranding.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
22

3-
import { resolveDesktopAppBranding, resolveDesktopAppStageLabel } from "./appBranding";
3+
import { resolveDesktopAppBranding, resolveDesktopAppStageLabel } from "./appBranding.ts";
44

55
describe("resolveDesktopAppStageLabel", () => {
66
it("uses Dev in desktop development", () => {

apps/desktop/src/appBranding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DesktopAppBranding, DesktopAppStageLabel } from "@t3tools/contracts";
22

3-
import { isNightlyDesktopVersion } from "./updateChannels";
3+
import { isNightlyDesktopVersion } from "./updateChannels.ts";
44

55
const APP_BASE_NAME = "T3 Code";
66

apps/desktop/src/backendPort.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from "vitest";
22

3-
import { resolveDesktopBackendPort } from "./backendPort";
3+
import { resolveDesktopBackendPort } from "./backendPort.ts";
44

55
describe("resolveDesktopBackendPort", () => {
66
it("returns the starting port when it is available", async () => {

apps/desktop/src/backendReadiness.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
BackendReadinessAbortedError,
55
isBackendReadinessAborted,
66
waitForHttpReady,
7-
} from "./backendReadiness";
7+
} from "./backendReadiness.ts";
88

99
describe("waitForHttpReady", () => {
1010
it("returns once the backend serves the requested readiness path", async () => {

0 commit comments

Comments
 (0)