History

[codex] Enforce canonical Node namespace imports (#3238)

Julius Marminge committed 4 months ago

Commit 2fa37ec1 parent db2750271 files · +1205 −952Browse files

Showing the changes to apps/desktop/scripts (7 of 71 files). Show all

Unified · Split

7 files
  1. apps/desktop/scripts/build-preview-annotation-css.mjs +16 −16
  2. apps/desktop/scripts/dev-electron.mjs +13 −9
  3. apps/desktop/scripts/electron-launcher.mjs +89 −73
  4. apps/desktop/scripts/ensure-electron-runtime.mjs +34 −32
  5. apps/desktop/scripts/smoke-test.mjs +7 −7
  6. apps/desktop/scripts/start-electron.mjs +2 −2
  7. apps/desktop/scripts/wait-for-resources.mjs +8 −8
apps/desktop/scripts/build-preview-annotation-css.mjs+16−16
@@ -1,23 +1,23 @@
1−import { readFile, writeFile } from "node:fs/promises";
2−import { createRequire } from "node:module";
3−import { dirname, join } from "node:path";
4−import { fileURLToPath } from "node:url";
1+import * as NodeFSP from "node:fs/promises";
2+import * as NodeModule from "node:module";
3+import * as NodePath from "node:path";
4+import * as NodeURL from "node:url";
55
66 import { compile } from "tailwindcss";
77
8−const directory = dirname(fileURLToPath(import.meta.url));
9−const appRoot = join(directory, "..");
10−const sourcePath = join(appRoot, "src", "preview", "Annotation.css");
11−const preloadPath = join(appRoot, "src", "preview", "PickPreload.ts");
12−const outputPath = join(appRoot, "src", "preview", "AnnotationStyles.generated.ts");
13−const require = createRequire(import.meta.url);
14−const tailwindRoot = dirname(require.resolve("tailwindcss/package.json"));
8+const directory = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
9+const appRoot = NodePath.join(directory, "..");
10+const sourcePath = NodePath.join(appRoot, "src", "preview", "Annotation.css");
11+const preloadPath = NodePath.join(appRoot, "src", "preview", "PickPreload.ts");
12+const outputPath = NodePath.join(appRoot, "src", "preview", "AnnotationStyles.generated.ts");
13+const require = NodeModule.createRequire(import.meta.url);
14+const tailwindRoot = NodePath.dirname(require.resolve("tailwindcss/package.json"));
1515
1616 const [annotationSource, preloadSource, themeSource, preflightSource] = await Promise.all([
17− readFile(sourcePath, "utf8"),
18− readFile(preloadPath, "utf8"),
19− readFile(join(tailwindRoot, "theme.css"), "utf8"),
20− readFile(join(tailwindRoot, "preflight.css"), "utf8"),
17+ NodeFSP.readFile(sourcePath, "utf8"),
18+ NodeFSP.readFile(preloadPath, "utf8"),
19+ NodeFSP.readFile(NodePath.join(tailwindRoot, "theme.css"), "utf8"),
20+ NodeFSP.readFile(NodePath.join(tailwindRoot, "preflight.css"), "utf8"),
2121 ]);
2222
2323 const candidates = new Set(
@@ -37,4 +37,4 @@ const encodedCss = `'${css · 13 unmodified lines
3737 .replaceAll("\n", "\\n")}'`;
3838 const moduleSource = `// Generated by scripts/build-preview-annotation-css.mjs. Do not edit.\nexport const previewAnnotationStyles =\n ${encodedCss};\n`;
3939
40−await writeFile(outputPath, moduleSource);
40+await NodeFSP.writeFile(outputPath, moduleSource);
apps/desktop/scripts/dev-electron.mjs+13−9
@@ -1,7 +1,7 @@
1−import { spawn, spawnSync } from "node:child_process";
2−import { watch } from "node:fs";
1+import * as NodeChildProcess from "node:child_process";
2+import * as NodeFS from "node:fs";
33 import * as NodeOS from "node:os";
4−import { join } from "node:path";
4+import * as NodePath from "node:path";
55
66 import {
77 desktopDir,
@@ -64,7 +64,7 @@ function killChildTreeByPid(pid, signal) { · 56 unmodified lines
6464 return;
6565 }
6666
67− spawnSync("pkill", [`-${signal}`, "-P", String(pid)], { stdio: "ignore" });
67+ NodeChildProcess.spawnSync("pkill", [`-${signal}`, "-P", String(pid)], { stdio: "ignore" });
6868 }
6969
7070 function cleanupStaleDevApps() {
@@ -72,7 +72,9 @@ function cleanupStaleDevApps() { · 1 unmodified line
7272 return;
7373 }
7474
75− spawnSync("pkill", ["-f", "--", `--t3code-dev-root=${desktopDir}`], { stdio: "ignore" });
75+ NodeChildProcess.spawnSync("pkill", ["-f", "--", `--t3code-dev-root=${desktopDir}`], {
76+ stdio: "ignore",
77+ });
7678 }
7779
7880 function startApp() {
@@ -87,7 +89,7 @@ function startApp() { · 8 unmodified lines
8789 ? electronArgs
8890 : [...electronArgs, `--t3code-dev-root=${desktopDir}`, "dist-electron/main.cjs"];
8991 const electronCommand = resolveElectronLaunchCommand(launchArgs);
90− const app = spawn(electronCommand.electronPath, electronCommand.args, {
92+ const app = NodeChildProcess.spawn(electronCommand.electronPath, electronCommand.args, {
9193 cwd: desktopDir,
9294 env: childEnv,
9395 stdio: "inherit",
@@ -180,8 +182,8 @@ function scheduleRestart() { · 86 unmodified lines
180182
181183 function startWatchers() {
182184 for (const { directory, files } of watchedDirectories) {
183− const watcher = watch(
184− join(desktopDir, directory),
185+ const watcher = NodeFS.watch(
186+ NodePath.join(desktopDir, directory),
185187 { persistent: true },
186188 (_eventType, filename) => {
187189 if (typeof filename !== "string" || !files.has(filename)) {
@@ -202,7 +204,9 @@ function killChildTree(signal) { · 14 unmodified lines
202204 }
203205
204206 // Kill direct children as a final fallback in case normal shutdown leaves stragglers.
205− spawnSync("pkill", [`-${signal}`, "-P", String(process.pid)], { stdio: "ignore" });
207+ NodeChildProcess.spawnSync("pkill", [`-${signal}`, "-P", String(process.pid)], {
208+ stdio: "ignore",
209+ });
206210 }
207211
208212 async function shutdown(exitCode) {
apps/desktop/scripts/electron-launcher.mjs+89−73
@@ -1,29 +1,18 @@
11 // This file mostly exists because we want dev mode to say "T3 Code (Dev)" instead of "electron"
22
3−import { spawnSync } from "node:child_process";
4−import {
5− copyFileSync,
6− chmodSync,
7− cpSync,
8− existsSync,
9− mkdirSync,
10− mkdtempSync,
11− readFileSync,
12− rmSync,
13− statSync,
14− writeFileSync,
15−} from "node:fs";
16−import { createRequire } from "node:module";
3+import * as NodeChildProcess from "node:child_process";
4+import * as NodeFS from "node:fs";
5+import * as NodeModule from "node:module";
176 import * as NodeOS from "node:os";
18−import { basename, dirname, join, resolve } from "node:path";
19−import { fileURLToPath } from "node:url";
7+import * as NodePath from "node:path";
8+import * as NodeURL from "node:url";
209 import { ensureElectronRuntime } from "./ensure-electron-runtime.mjs";
2110
2211 const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL);
23−const __dirname = dirname(fileURLToPath(import.meta.url));
24−export const desktopDir = resolve(__dirname, "..");
25−const repoRoot = resolve(desktopDir, "..", "..");
26−const devBundleIdSuffix = basename(repoRoot)
12+const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
13+export const desktopDir = NodePath.resolve(__dirname, "..");
14+const repoRoot = NodePath.resolve(desktopDir, "..", "..");
15+const devBundleIdSuffix = NodePath.basename(repoRoot)
2716 .toLowerCase()
2817 .replaceAll(/[^a-z0-9]+/g, "");
2918 export const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alpha)";
@@ -32,22 +21,35 @@ export const APP_BUNDLE_ID = isDevelopment · 2 unmodified lines
3221 : "com.t3tools.t3code";
3322 const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : ["t3code"];
3423 const LAUNCHER_VERSION = 12;
35−const defaultIconPath = join(desktopDir, "resources", "icon.icns");
36−const developmentMacIconPngPath = join(repoRoot, "assets", "dev", "blueprint-macos-1024.png");
24+const defaultIconPath = NodePath.join(desktopDir, "resources", "icon.icns");
25+const developmentMacIconPngPath = NodePath.join(
26+ repoRoot,
27+ "assets",
28+ "dev",
29+ "blueprint-macos-1024.png",
30+);
3731 // oxlint-disable-next-line t3code/no-global-process-runtime -- Standalone launcher script has no Effect runtime.
3832 const hostPlatform = NodeOS.platform();
3933
4034 function setPlistString(plistPath, key, value) {
41− const replaceResult = spawnSync("plutil", ["-replace", key, "-string", value, plistPath], {
42− encoding: "utf8",
43− });
35+ const replaceResult = NodeChildProcess.spawnSync(
36+ "plutil",
37+ ["-replace", key, "-string", value, plistPath],
38+ {
39+ encoding: "utf8",
40+ },
41+ );
4442 if (replaceResult.status === 0) {
4543 return;
4644 }
4745
48− const insertResult = spawnSync("plutil", ["-insert", key, "-string", value, plistPath], {
49− encoding: "utf8",
50− });
46+ const insertResult = NodeChildProcess.spawnSync(
47+ "plutil",
48+ ["-insert", key, "-string", value, plistPath],
49+ {
50+ encoding: "utf8",
51+ },
52+ );
5153 if (insertResult.status === 0) {
5254 return;
5355 }
@@ -58,16 +60,24 @@ function setPlistString(plistPath, key, value) { · 4 unmodified lines
5860
5961 function setPlistJson(plistPath, key, value) {
6062 const serialized = JSON.stringify(value);
61− const replaceResult = spawnSync("plutil", ["-replace", key, "-json", serialized, plistPath], {
62− encoding: "utf8",
63− });
63+ const replaceResult = NodeChildProcess.spawnSync(
64+ "plutil",
65+ ["-replace", key, "-json", serialized, plistPath],
66+ {
67+ encoding: "utf8",
68+ },
69+ );
6470 if (replaceResult.status === 0) {
6571 return;
6672 }
6773
68− const insertResult = spawnSync("plutil", ["-insert", key, "-json", serialized, plistPath], {
69− encoding: "utf8",
70− });
74+ const insertResult = NodeChildProcess.spawnSync(
75+ "plutil",
76+ ["-insert", key, "-json", serialized, plistPath],
77+ {
78+ encoding: "utf8",
79+ },
80+ );
7181 if (insertResult.status === 0) {
7282 return;
7383 }
@@ -77,7 +87,7 @@ function setPlistJson(plistPath, key, value) { · 3 unmodified lines
7787 }
7888
7989 function runChecked(command, args) {
80− const result = spawnSync(command, args, { encoding: "utf8" });
90+ const result = NodeChildProcess.spawnSync(command, args, { encoding: "utf8" });
8191 if (result.status === 0) {
8292 return;
8393 }
@@ -91,7 +101,7 @@ function shellSingleQuote(value) { · 7 unmodified lines
91101 }
92102
93103 function writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath) {
94− const mainEntryPath = join(desktopDir, "dist-electron", "main.cjs");
104+ const mainEntryPath = NodePath.join(desktopDir, "dist-electron", "main.cjs");
95105 const envEntries = [
96106 ["VITE_DEV_SERVER_URL", process.env.VITE_DEV_SERVER_URL],
97107 ["T3CODE_PORT", process.env.T3CODE_PORT],
@@ -101,7 +111,7 @@ function writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath) { · 3 unmodified lines
101111 ["T3CODE_OTLP_EXPORT_INTERVAL_MS", process.env.T3CODE_OTLP_EXPORT_INTERVAL_MS],
102112 ["T3CODE_DESKTOP_APP_USER_MODEL_ID", APP_BUNDLE_ID],
103113 ].filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0);
104− writeFileSync(
114+ NodeFS.writeFileSync(
105115 targetBinaryPath,
106116 [
107117 "#!/bin/sh",
@@ -110,7 +120,7 @@ function writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath) { · 2 unmodified lines
110120 "",
111121 ].join("\n"),
112122 );
113− chmodSync(targetBinaryPath, 0o755);
123+ NodeFS.chmodSync(targetBinaryPath, 0o755);
114124 }
115125
116126 function registerMacLauncherBundle(appBundlePath) {
@@ -140,21 +150,24 @@ function registerMacLauncherBundle(appBundlePath) { · 23 unmodified lines
140150 }
141151
142152 function ensureDevelopmentIconIcns(runtimeDir) {
143− const generatedIconPath = join(runtimeDir, "icon-dev.icns");
144− mkdirSync(runtimeDir, { recursive: true });
153+ const generatedIconPath = NodePath.join(runtimeDir, "icon-dev.icns");
154+ NodeFS.mkdirSync(runtimeDir, { recursive: true });
145155
146− if (!existsSync(developmentMacIconPngPath)) {
156+ if (!NodeFS.existsSync(developmentMacIconPngPath)) {
147157 return defaultIconPath;
148158 }
149159
150− const sourceMtimeMs = statSync(developmentMacIconPngPath).mtimeMs;
151− if (existsSync(generatedIconPath) && statSync(generatedIconPath).mtimeMs >= sourceMtimeMs) {
160+ const sourceMtimeMs = NodeFS.statSync(developmentMacIconPngPath).mtimeMs;
161+ if (
162+ NodeFS.existsSync(generatedIconPath) &&
163+ NodeFS.statSync(generatedIconPath).mtimeMs >= sourceMtimeMs
164+ ) {
152165 return generatedIconPath;
153166 }
154167
155− const iconsetRoot = mkdtempSync(join(runtimeDir, "dev-iconset-"));
156− const iconsetDir = join(iconsetRoot, "icon.iconset");
157− mkdirSync(iconsetDir, { recursive: true });
168+ const iconsetRoot = NodeFS.mkdtempSync(NodePath.join(runtimeDir, "dev-iconset-"));
169+ const iconsetDir = NodePath.join(iconsetRoot, "icon.iconset");
170+ NodeFS.mkdirSync(iconsetDir, { recursive: true });
158171
159172 try {
160173 for (const size of [16, 32, 128, 256, 512]) {
@@ -164,7 +177,7 @@ function ensureDevelopmentIconIcns(runtimeDir) { · 3 unmodified lines
164177 String(size),
165178 developmentMacIconPngPath,
166179 "--out",
167− join(iconsetDir, `icon_${size}x${size}.png`),
180+ NodePath.join(iconsetDir, `icon_${size}x${size}.png`),
168181 ]);
169182
170183 const retinaSize = size * 2;
@@ -174,7 +187,7 @@ function ensureDevelopmentIconIcns(runtimeDir) { · 3 unmodified lines
174187 String(retinaSize),
175188 developmentMacIconPngPath,
176189 "--out",
177− join(iconsetDir, `icon_${size}x${size}@2x.png`),
190+ NodePath.join(iconsetDir, `icon_${size}x${size}@2x.png`),
178191 ]);
179192 }
180193
@@ -187,12 +200,12 @@ function ensureDevelopmentIconIcns(runtimeDir) { · 6 unmodified lines
187200 );
188201 return defaultIconPath;
189202 } finally {
190− rmSync(iconsetRoot, { recursive: true, force: true });
203+ NodeFS.rmSync(iconsetRoot, { recursive: true, force: true });
191204 }
192205 }
193206
194207 function patchMainBundleInfoPlist(appBundlePath, iconPath) {
195− const infoPlistPath = join(appBundlePath, "Contents", "Info.plist");
208+ const infoPlistPath = NodePath.join(appBundlePath, "Contents", "Info.plist");
196209 setPlistString(infoPlistPath, "CFBundleDisplayName", APP_DISPLAY_NAME);
197210 setPlistString(infoPlistPath, "CFBundleName", APP_DISPLAY_NAME);
198211 setPlistString(infoPlistPath, "CFBundleIdentifier", APP_BUNDLE_ID);
@@ -204,9 +217,9 @@ function patchMainBundleInfoPlist(appBundlePath, iconPath) { · 5 unmodified lines
204217 },
205218 ]);
206219
207− const resourcesDir = join(appBundlePath, "Contents", "Resources");
208− copyFileSync(iconPath, join(resourcesDir, "icon.icns"));
209− copyFileSync(iconPath, join(resourcesDir, "electron.icns"));
220+ const resourcesDir = NodePath.join(appBundlePath, "Contents", "Resources");
221+ NodeFS.copyFileSync(iconPath, NodePath.join(resourcesDir, "icon.icns"));
222+ NodeFS.copyFileSync(iconPath, NodePath.join(resourcesDir, "electron.icns"));
210223 }
211224
212225 function patchHelperBundleInfoPlists(appBundlePath) {
@@ -218,7 +231,7 @@ function patchHelperBundleInfoPlists(appBundlePath) { · 5 unmodified lines
218231 ];
219232
220233 for (const [bundleName, bundleIdentifierSuffix, bundleDisplayName] of helperBundleNames) {
221− const infoPlistPath = join(
234+ const infoPlistPath = NodePath.join(
222235 appBundlePath,
223236 "Contents",
224237 "Frameworks",
@@ -226,7 +239,7 @@ function patchHelperBundleInfoPlists(appBundlePath) { · 1 unmodified line
226239 "Contents",
227240 "Info.plist",
228241 );
229− if (!existsSync(infoPlistPath)) {
242+ if (!NodeFS.existsSync(infoPlistPath)) {
230243 continue;
231244 }
232245
@@ -242,34 +255,34 @@ function patchHelperBundleInfoPlists(appBundlePath) { · 9 unmodified lines
242255
243256 function readJson(path) {
244257 try {
245− return JSON.parse(readFileSync(path, "utf8"));
258+ return JSON.parse(NodeFS.readFileSync(path, "utf8"));
246259 } catch {
247260 return null;
248261 }
249262 }
250263
251264 function buildMacLauncher(electronBinaryPath) {
252− const sourceAppBundlePath = resolve(dirname(electronBinaryPath), "../..");
253− const runtimeDir = join(desktopDir, ".electron-runtime");
254− const targetAppBundlePath = join(runtimeDir, `${APP_DISPLAY_NAME}.app`);
255− const targetBinaryPath = join(targetAppBundlePath, "Contents", "MacOS", "Electron");
265+ const sourceAppBundlePath = NodePath.resolve(NodePath.dirname(electronBinaryPath), "../..");
266+ const runtimeDir = NodePath.join(desktopDir, ".electron-runtime");
267+ const targetAppBundlePath = NodePath.join(runtimeDir, `${APP_DISPLAY_NAME}.app`);
268+ const targetBinaryPath = NodePath.join(targetAppBundlePath, "Contents", "MacOS", "Electron");
256269 const iconPath = isDevelopment ? ensureDevelopmentIconIcns(runtimeDir) : defaultIconPath;
257− const metadataPath = join(runtimeDir, "metadata.json");
270+ const metadataPath = NodePath.join(runtimeDir, "metadata.json");
258271
259− mkdirSync(runtimeDir, { recursive: true });
272+ NodeFS.mkdirSync(runtimeDir, { recursive: true });
260273
261274 const expectedMetadata = {
262275 launcherVersion: LAUNCHER_VERSION,
263276 sourceAppBundlePath,
264− sourceAppMtimeMs: statSync(sourceAppBundlePath).mtimeMs,
265− iconMtimeMs: statSync(iconPath).mtimeMs,
277+ sourceAppMtimeMs: NodeFS.statSync(sourceAppBundlePath).mtimeMs,
278+ iconMtimeMs: NodeFS.statSync(iconPath).mtimeMs,
266279 appBundleId: APP_BUNDLE_ID,
267280 appProtocolSchemes: APP_PROTOCOL_SCHEMES,
268281 };
269282
270283 const currentMetadata = readJson(metadataPath);
271284 if (
272− existsSync(targetBinaryPath) &&
285+ NodeFS.existsSync(targetBinaryPath) &&
273286 currentMetadata &&
274287 JSON.stringify(currentMetadata) === JSON.stringify(expectedMetadata)
275288 ) {
@@ -277,18 +290,21 @@ function buildMacLauncher(electronBinaryPath) { · 1 unmodified line
277290 return targetBinaryPath;
278291 }
279292
280− rmSync(targetAppBundlePath, { recursive: true, force: true });
293+ NodeFS.rmSync(targetAppBundlePath, { recursive: true, force: true });
281294 // verbatimSymlinks keeps the framework's relative symlinks intact
282295 // (e.g. Resources -> Versions/Current/Resources). Without it cpSync
283296 // rewrites them to absolute paths into node_modules, which escape the
284297 // bundle and crash sandboxed helper processes (icudtl.dat not found).
285− cpSync(sourceAppBundlePath, targetAppBundlePath, { recursive: true, verbatimSymlinks: true });
298+ NodeFS.cpSync(sourceAppBundlePath, targetAppBundlePath, {
299+ recursive: true,
300+ verbatimSymlinks: true,
301+ });
286302 patchMainBundleInfoPlist(targetAppBundlePath, iconPath);
287303 patchHelperBundleInfoPlists(targetAppBundlePath);
288304 if (isDevelopment) {
289305 writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath);
290306 }
291− writeFileSync(metadataPath, `${JSON.stringify(expectedMetadata, null, 2)}\n`);
307+ NodeFS.writeFileSync(metadataPath, `${JSON.stringify(expectedMetadata, null, 2)}\n`);
292308 registerMacLauncherBundle(targetAppBundlePath);
293309
294310 return targetBinaryPath;
@@ -299,9 +315,9 @@ function isLinuxSetuidSandboxConfigured(electronBinaryPath) { · 4 unmodified lines
299315 return true;
300316 }
301317
302− const sandboxPath = join(dirname(electronBinaryPath), "chrome-sandbox");
318+ const sandboxPath = NodePath.join(NodePath.dirname(electronBinaryPath), "chrome-sandbox");
303319 try {
304− const sandboxStat = statSync(sandboxPath);
320+ const sandboxStat = NodeFS.statSync(sandboxPath);
305321 return sandboxStat.uid === 0 && (sandboxStat.mode & 0o4777) === 0o4755;
306322 } catch {
307323 return false;
@@ -322,7 +338,7 @@ function resolveLinuxSandboxArgs(electronBinaryPath) { · 14 unmodified lines
322338 export function resolveElectronPath() {
323339 ensureElectronRuntime();
324340
325− const require = createRequire(import.meta.url);
341+ const require = NodeModule.createRequire(import.meta.url);
326342 const electronBinaryPath = require("electron");
327343
328344 if (hostPlatform !== "darwin") {
@@ -345,11 +361,11 @@ export function resolveDevProtocolClient() { · 16 unmodified lines
345361 return null;
346362 }
347363
348− const require = createRequire(import.meta.url);
364+ const require = NodeModule.createRequire(import.meta.url);
349365 const electronBinaryPath = require("electron");
350366 const launcherBinaryPath = buildMacLauncher(electronBinaryPath);
351367 return {
352− appBundlePath: resolve(launcherBinaryPath, "..", "..", ".."),
368+ appBundlePath: NodePath.resolve(launcherBinaryPath, "..", "..", ".."),
353369 appBundleId: APP_BUNDLE_ID,
354370 };
355371 }
apps/desktop/scripts/ensure-electron-runtime.mjs+34−32
@@ -1,14 +1,14 @@
1−import { chmodSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2−import { createRequire } from "node:module";
3−import { arch, platform, tmpdir } from "node:os";
4−import { dirname, join } from "node:path";
5−import { spawnSync } from "node:child_process";
1+import * as NodeFS from "node:fs";
2+import * as NodeModule from "node:module";
3+import * as NodeOS from "node:os";
4+import * as NodePath from "node:path";
5+import * as NodeChildProcess from "node:child_process";
66
7−const require = createRequire(import.meta.url);
7+const require = NodeModule.createRequire(import.meta.url);
88 // oxlint-disable-next-line t3code/no-global-process-runtime -- Standalone repair script has no Effect runtime.
9−const hostPlatform = platform();
9+const hostPlatform = NodeOS.platform();
1010 // oxlint-disable-next-line t3code/no-global-process-runtime -- Standalone repair script has no Effect runtime.
11−const hostArch = arch();
11+const hostArch = NodeOS.arch();
1212
1313 function getPlatformPath() {
1414 switch (hostPlatform) {
@@ -27,26 +27,28 @@ function getPlatformPath() { · 12 unmodified lines
2727
2828 function ensureExecutable(filePath) {
2929 if (hostPlatform !== "win32") {
30− chmodSync(filePath, 0o755);
30+ NodeFS.chmodSync(filePath, 0o755);
3131 }
3232 }
3333
3434 function repairPathFile(electronDir, platformPath) {
35− const pathFile = join(electronDir, "path.txt");
36− const currentPath = existsSync(pathFile) ? readFileSync(pathFile, "utf8") : undefined;
35+ const pathFile = NodePath.join(electronDir, "path.txt");
36+ const currentPath = NodeFS.existsSync(pathFile)
37+ ? NodeFS.readFileSync(pathFile, "utf8")
38+ : undefined;
3739
3840 if (currentPath !== platformPath) {
39− writeFileSync(pathFile, platformPath);
41+ NodeFS.writeFileSync(pathFile, platformPath);
4042 }
4143 }
4244
4345 function getRequiredRuntimePaths(electronDir, platformPath) {
44− const paths = [join(electronDir, "dist", platformPath)];
46+ const paths = [NodePath.join(electronDir, "dist", platformPath)];
4547
4648 if (hostPlatform === "darwin") {
4749 paths.push(
48− join(electronDir, "dist", "Electron.app", "Contents", "Info.plist"),
49− join(
50+ NodePath.join(electronDir, "dist", "Electron.app", "Contents", "Info.plist"),
51+ NodePath.join(
5052 electronDir,
5153 "dist",
5254 "Electron.app",
@@ -66,7 +68,7 @@ function isMachO(filePath) { · 13 unmodified lines
6668 return true;
6769 }
6870
69− const result = spawnSync("file", ["-b", filePath], {
71+ const result = NodeChildProcess.spawnSync("file", ["-b", filePath], {
7072 encoding: "utf8",
7173 });
7274
@@ -75,7 +77,7 @@ function isMachO(filePath) { · 2 unmodified lines
7577
7678 function missingRuntimePaths(electronDir, platformPath) {
7779 return getRequiredRuntimePaths(electronDir, platformPath).filter((runtimePath) => {
78− return !existsSync(runtimePath);
80+ return !NodeFS.existsSync(runtimePath);
7981 });
8082 }
8183
@@ -85,8 +87,8 @@ function invalidRuntimePaths(electronDir, platformPath) { · 3 unmodified lines
8587 }
8688
8789 return [
88− join(electronDir, "dist", platformPath),
89− join(
90+ NodePath.join(electronDir, "dist", platformPath),
91+ NodePath.join(
9092 electronDir,
9193 "dist",
9294 "Electron.app",
@@ -95,11 +97,11 @@ function invalidRuntimePaths(electronDir, platformPath) { · 2 unmodified lines
9597 "Electron Framework.framework",
9698 "Electron Framework",
9799 ),
98− ].filter((runtimePath) => existsSync(runtimePath) && !isMachO(runtimePath));
100+ ].filter((runtimePath) => NodeFS.existsSync(runtimePath) && !isMachO(runtimePath));
99101 }
100102
101103 function runChecked(command, args) {
102− const result = spawnSync(command, args, {
104+ const result = NodeChildProcess.spawnSync(command, args, {
103105 encoding: "utf8",
104106 stdio: "inherit",
105107 });
@@ -114,8 +116,8 @@ function runChecked(command, args) { · 8 unmodified lines
114116 }
115117
116118 function installElectronRuntime(electronDir, version) {
117− const tempDir = mkdtempSync(join(tmpdir(), "t3-electron-"));
118− const zipPath = join(tempDir, `electron-v${version}-${hostPlatform}-${hostArch}.zip`);
119+ const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-electron-"));
120+ const zipPath = NodePath.join(tempDir, `electron-v${version}-${hostPlatform}-${hostArch}.zip`);
119121
120122 try {
121123 runChecked("curl", [
@@ -125,34 +127,34 @@ function installElectronRuntime(electronDir, version) { · 3 unmodified lines
125127 zipPath,
126128 ]);
127129 if (hostPlatform === "darwin") {
128− runChecked("ditto", ["-x", "-k", zipPath, join(electronDir, "dist")]);
130+ runChecked("ditto", ["-x", "-k", zipPath, NodePath.join(electronDir, "dist")]);
129131 } else {
130132 runChecked("python3", [
131133 "-c",
132134 "import os, sys, zipfile; os.makedirs(sys.argv[2], exist_ok=True); zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])",
133135 zipPath,
134− join(electronDir, "dist"),
136+ NodePath.join(electronDir, "dist"),
135137 ]);
136138 }
137139 } finally {
138− rmSync(tempDir, { recursive: true, force: true });
140+ NodeFS.rmSync(tempDir, { recursive: true, force: true });
139141 }
140142 }
141143
142144 export function ensureElectronRuntime() {
143145 const electronPackageJsonPath = require.resolve("electron/package.json");
144− const electronPackageJson = JSON.parse(readFileSync(electronPackageJsonPath, "utf8"));
145− const electronDir = dirname(electronPackageJsonPath);
146+ const electronPackageJson = JSON.parse(NodeFS.readFileSync(electronPackageJsonPath, "utf8"));
147+ const electronDir = NodePath.dirname(electronPackageJsonPath);
146148 const platformPath = getPlatformPath();
147− const electronPath = join(electronDir, "dist", platformPath);
149+ const electronPath = NodePath.join(electronDir, "dist", platformPath);
148150 const missingBeforeInstall = missingRuntimePaths(electronDir, platformPath);
149151 const invalidBeforeInstall = invalidRuntimePaths(electronDir, platformPath);
150152
151153 if (missingBeforeInstall.length > 0 || invalidBeforeInstall.length > 0) {
152− if (existsSync(join(electronDir, "dist"))) {
153− rmSync(join(electronDir, "dist"), { recursive: true, force: true });
154+ if (NodeFS.existsSync(NodePath.join(electronDir, "dist"))) {
155+ NodeFS.rmSync(NodePath.join(electronDir, "dist"), { recursive: true, force: true });
154156 }
155− rmSync(join(electronDir, "path.txt"), { force: true });
157+ NodeFS.rmSync(NodePath.join(electronDir, "path.txt"), { force: true });
156158 installElectronRuntime(electronDir, electronPackageJson.version);
157159 }
158160
apps/desktop/scripts/smoke-test.mjs+7−7
@@ -1,16 +1,16 @@
1−import { spawn } from "node:child_process";
2−import { dirname, resolve } from "node:path";
3−import { fileURLToPath } from "node:url";
1+import * as NodeChildProcess from "node:child_process";
2+import * as NodePath from "node:path";
3+import * as NodeURL from "node:url";
44 import { resolveElectronLaunchCommand } from "./electron-launcher.mjs";
55
6−const __dirname = dirname(fileURLToPath(import.meta.url));
7−const desktopDir = resolve(__dirname, "..");
8−const mainJs = resolve(desktopDir, "dist-electron/main.cjs");
6+const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
7+const desktopDir = NodePath.resolve(__dirname, "..");
8+const mainJs = NodePath.resolve(desktopDir, "dist-electron/main.cjs");
99
1010 console.log("\nLaunching Electron smoke test...");
1111
1212 const electronCommand = resolveElectronLaunchCommand([mainJs]);
13−const child = spawn(electronCommand.electronPath, electronCommand.args, {
13+const child = NodeChildProcess.spawn(electronCommand.electronPath, electronCommand.args, {
1414 stdio: ["pipe", "pipe", "pipe"],
1515 env: {
1616 ...process.env,
apps/desktop/scripts/start-electron.mjs+2−2
@@ -1,4 +1,4 @@
1−import { spawn } from "node:child_process";
1+import * as NodeChildProcess from "node:child_process";
22
33 import { desktopDir, resolveElectronLaunchCommand } from "./electron-launcher.mjs";
44
@@ -6,7 +6,7 @@ const childEnv = { ...process.env }; · 1 unmodified line
66 delete childEnv.ELECTRON_RUN_AS_NODE;
77
88 const electronCommand = resolveElectronLaunchCommand(["dist-electron/main.cjs"]);
9−const child = spawn(electronCommand.electronPath, electronCommand.args, {
9+const child = NodeChildProcess.spawn(electronCommand.electronPath, electronCommand.args, {
1010 stdio: "inherit",
1111 cwd: desktopDir,
1212 env: childEnv,
apps/desktop/scripts/wait-for-resources.mjs+8−8
@@ -1,13 +1,13 @@
1−import * as FileSystem from "node:fs/promises";
2−import * as Net from "node:net";
3−import * as Path from "node:path";
4−import * as Timers from "node:timers/promises";
1+import * as NodeFSP from "node:fs/promises";
2+import * as NodeNet from "node:net";
3+import * as NodePath from "node:path";
4+import * as NodeTimersPromises from "node:timers/promises";
55
66 const defaultTcpHosts = ["127.0.0.1", "localhost", "::1"];
77
88 async function fileExists(filePath) {
99 try {
10− await FileSystem.access(filePath);
10+ await NodeFSP.access(filePath);
1111 return true;
1212 } catch {
1313 return false;
@@ -16,7 +16,7 @@ async function fileExists(filePath) { · 2 unmodified lines
1616
1717 function tcpPortIsReady({ host, port, connectTimeoutMs = 500 }) {
1818 return new Promise((resolveReady) => {
19− const socket = Net.createConnection({ host, port });
19+ const socket = NodeNet.createConnection({ host, port });
2020 let settled = false;
2121
2222 const finish = (ready) => {
@@ -47,7 +47,7 @@ async function resolvePendingResources({ baseDir, files, tcpPort, tcpHosts, conn · 24 unmodified lines
4747 const pendingFiles = [];
4848
4949 for (const relativeFilePath of files) {
50− const ready = await fileExists(Path.resolve(baseDir, relativeFilePath));
50+ const ready = await fileExists(NodePath.resolve(baseDir, relativeFilePath));
5151 if (!ready) {
5252 pendingFiles.push(relativeFilePath);
5353 }
@@ -114,6 +114,6 @@ export async function waitForResources({ · 60 unmodified lines
114114 );
115115 }
116116
117− await Timers.setTimeout(intervalMs);
117+ await NodeTimersPromises.setTimeout(intervalMs);
118118 }
119119 }