History

Accept prebuilt desktop bundles in dev startup

Cursor Agent committed 9 months ago

Commit 2c91b7d1 parent b8a24811 file · +1 −78Browse files

Unified · Split

apps/desktop/scripts/dev-electron.mjs+1−78
@@ -28,57 +28,6 @@ async function canConnect(host, probePort, timeoutMs = 1_000) { · 27 unmodified lines
2828
2929 const f = (p) => path.join(import.meta.dirname, "..", p);
3030
31−function collectFilesRecursively(rootDir) {
32− const files = [];
33−
34− const visit = (dir) => {
35− let entries = [];
36− try {
37− entries = fs.readdirSync(dir, { withFileTypes: true });
38− } catch {
39− return;
40− }
41−
42− for (const entry of entries) {
43− const fullPath = path.join(dir, entry.name);
44− if (entry.isDirectory()) {
45− visit(fullPath);
46− continue;
47− }
48− if (entry.isFile()) {
49− files.push(fullPath);
50− }
51− }
52− };
53−
54− visit(rootDir);
55− return files;
56−}
57−
58−function getDesktopBundleFreshnessFloor() {
59− const sourceFiles = [
60− ...collectFilesRecursively(f("src")),
61− f("tsdown.config.ts"),
62− f("tsconfig.json"),
63− f("package.json"),
64− ];
65− let newestMtimeMs = 0;
66−
67− for (const sourceFile of sourceFiles) {
68− try {
69− const stat = fs.statSync(sourceFile);
70− newestMtimeMs = Math.max(newestMtimeMs, stat.mtimeMs);
71− } catch {
72− // Best-effort: ignore transient or missing files in the readiness floor.
73− }
74− }
75−
76− return {
77− newestMtimeMs,
78− sourceFileCount: sourceFiles.length,
79− };
80−}
81−
8231 function inspectBundleFile(bundleFile) {
8332 let stat = null;
8433 try {
@@ -92,15 +41,6 @@ function inspectBundleFile(bundleFile) { · 7 unmodified lines
9241 };
9342 }
9443
95− if (bundleFile.freshnessFloorMs > 0 && stat.mtimeMs < bundleFile.freshnessFloorMs) {
96− return {
97− ...bundleFile,
98− status: "outdated",
99− mtimeMs: stat.mtimeMs,
100− reason: `mtime older than source floor by ${Math.round(bundleFile.freshnessFloorMs - stat.mtimeMs)}ms`,
101− };
102− }
103−
10444 return {
10545 ...bundleFile,
10646 status: "ready",
@@ -121,28 +61,18 @@ function describeBundleStates(states) { · 14 unmodified lines
12161
12262 function waitForDesktopBundles(timeoutMs) {
12363 const startedAt = Date.now();
124− const desktopFloor = getDesktopBundleFreshnessFloor();
125− if (desktopFloor.newestMtimeMs > 0) {
126− console.log(
127− `[dev-electron] desktop bundle freshness floor=${new Date(desktopFloor.newestMtimeMs).toISOString()} from ${desktopFloor.sourceFileCount} source files`,
128− );
129− }
130−
13164 const bundleFiles = [
13265 {
13366 path: f("dist-electron/main.mjs"),
13467 label: "desktop/main.mjs",
135− freshnessFloorMs: desktopFloor.newestMtimeMs,
13668 },
13769 {
13870 path: f("dist-electron/preload.cjs"),
13971 label: "desktop/preload.cjs",
140− freshnessFloorMs: desktopFloor.newestMtimeMs,
14172 },
14273 {
14374 path: f("../server/dist/index.mjs"),
14475 label: "server/index.mjs",
145− freshnessFloorMs: 0,
14676 },
14777 ];
14878 let lastProgressLogAt = 0;
@@ -151,9 +81,8 @@ function waitForDesktopBundles(timeoutMs) { · 2 unmodified lines
15181 const tick = () => {
15282 const states = bundleFiles.map(inspectBundleFile);
15383 const missing = states.filter((state) => state.status === "missing");
154− const outdated = states.filter((state) => state.status === "outdated");
15584
156− if (missing.length === 0 && outdated.length === 0) {
85+ if (missing.length === 0) {
15786 resolve();
15887 return;
15988 }
@@ -164,9 +93,6 @@ function waitForDesktopBundles(timeoutMs) { · 4 unmodified lines
16493 if (missing.length > 0) {
16594 parts.push(`missing: ${missing.map((state) => state.label).join(", ")}`);
16695 }
167− if (outdated.length > 0) {
168− parts.push(`outdated: ${outdated.map((state) => state.label).join(", ")}`);
169− }
17096 reject(
17197 new Error(
17298 `[dev-electron] timed out after ${timeoutMs}ms waiting for bundles (${parts.join("; ")})\n[dev-electron] bundle state: ${describeBundleStates(states)}`,
@@ -181,9 +107,6 @@ function waitForDesktopBundles(timeoutMs) { · 8 unmodified lines
181107 if (missing.length > 0) {
182108 waitParts.push(`missing=${missing.map((state) => state.label).join(",")}`);
183109 }
184− if (outdated.length > 0) {
185− waitParts.push(`outdated=${outdated.map((state) => state.label).join(",")}`);
186− }
187110 console.log(
188111 `[dev-electron] still waiting for bundles after ${elapsedMs}ms (${waitParts.join("; ")})`,
189112 );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t