@marver-design/marver 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +2 -1
- package/dist/{anchor-check-DhlpKl2K.mjs → anchor-check-c52IDkiQ.mjs} +1 -1
- package/dist/{build-CWbrb2bl.mjs → build-C3mUtjEn.mjs} +5 -4
- package/dist/cli.mjs +5 -5
- package/dist/{daemon-Sc_z8gT6.mjs → daemon-B0Wi1OQ3.mjs} +5 -3
- package/dist/{dev-DWBKQhxf.mjs → dev-5dlxoW28.mjs} +8 -8
- package/dist/{perf-Denssrko.mjs → perf-6MOTHxay.mjs} +710 -99
- package/dist/perf-BCxAo0IS.mjs +1743 -0
- package/dist/{plugin-DqoZB-D6.mjs → plugin-CXRoMA8g.mjs} +898 -539
- package/dist/{poster-CrsjqhY4.mjs → poster-CYmCa00B.mjs} +1 -1
- package/dist/{publish-bakes-DW-NDgU2.mjs → publish-bakes-C_2ZtHou.mjs} +2 -2
- package/dist/{recover-GtJ9UDAB.mjs → recover-XD8iXJOj.mjs} +1 -1
- package/dist/{shot-T04Ixrvq.mjs → shot-CRRGgxru.mjs} +3 -3
- package/docs/app.md +194 -0
- package/docs/performance.md +98 -18
- package/package.json +1 -1
- package/src/client/frame-host/bridge.js +17 -8
- package/src/client/frame-host/inplace.ts +124 -0
- package/src/client/frame-host/inspect.d.ts +1 -0
- package/src/client/frame-host/inspect.js +13 -4
- package/src/client/frame-host/main.tsx +12 -3
- package/src/client/frame-host/messages.ts +85 -0
- package/src/client/frame-host/signals.d.ts +15 -0
- package/src/client/frame-host/signals.js +219 -0
- package/src/client/recorder-level.ts +41 -0
- package/src/client/shell/App.tsx +158 -88
- package/src/client/shell/BoardList.tsx +103 -48
- package/src/client/shell/Comments.tsx +66 -42
- package/src/client/shell/ContextMenu.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +116 -71
- package/src/client/shell/LockedApp.tsx +19 -3
- package/src/client/shell/Play.tsx +94 -58
- package/src/client/shell/StatusPicker.tsx +19 -9
- package/src/client/shell/Toolbar.tsx +15 -7
- package/src/client/shell/api.ts +18 -4
- package/src/client/shell/app-bridge.ts +12 -6
- package/src/client/shell/app-perf.ts +31 -1
- package/src/client/shell/canvas/Canvas.tsx +17 -6
- package/src/client/shell/canvas/FrameNode.tsx +25 -12
- package/src/client/shell/canvas/Sticky.tsx +4 -2
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/ready-watch.ts +4 -0
- package/src/client/shell/canvas/sleep.ts +2 -0
- package/src/client/shell/canvas/updates.ts +13 -6
- package/src/client/shell/commands.ts +765 -0
- package/src/client/shell/comments-store.ts +42 -27
- package/src/client/shell/goto.ts +11 -6
- package/src/client/shell/jam-keys.ts +141 -75
- package/src/client/shell/jam-lane.tsx +19 -12
- package/src/client/shell/jam-panel.tsx +61 -48
- package/src/client/shell/jam-session.tsx +41 -37
- package/src/client/shell/jam-state.ts +9 -1
- package/src/client/shell/jam-surface-parts.tsx +8 -6
- package/src/client/shell/jam-ui.tsx +9 -6
- package/src/client/shell/jam-voice.ts +4 -2
- package/src/client/shell/main.tsx +7 -1
- package/src/client/shell/marks-ui.tsx +11 -0
- package/src/client/shell/perf.ts +51 -5
- package/src/client/shell/recorder-core.ts +4 -1
- package/src/client/shell/recorder-hmr.ts +36 -0
- package/src/client/shell/recorder-reloads.ts +264 -0
- package/src/client/shell/recorder-seams.ts +116 -0
- package/src/client/shell/recorder-self.ts +73 -0
- package/src/client/shell/recorder-signals-core.ts +139 -0
- package/src/client/shell/recorder-signals.ts +485 -0
- package/src/client/shell/recorder.ts +115 -41
- package/src/client/shell/store.ts +56 -22
- package/src/client/shell/whiteout-probes.ts +3 -1
- package/src/client/stage/main.tsx +10 -5
- package/src/shared/app-api.ts +28 -6
- package/src/shared/app-perf.ts +99 -6
- package/src/shared/app-report.ts +586 -0
- package/src/shared/perf-records.ts +445 -0
- package/src/shared/perf-run.ts +6 -2
- package/dist/perf-jam-CLkERSHo.mjs +0 -642
|
@@ -9,10 +9,10 @@ import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
|
|
|
9
9
|
import { g as LIVE_WIRE, h as LIVE_BOUNDS, i as marverHome, o as originOf, v as workspaceId } from "./slots-Dn4Onb0V.mjs";
|
|
10
10
|
import { n as localProfile, t as isConnected } from "./profile-B1FKOM1e.mjs";
|
|
11
11
|
import { c as recordChanged, i as initMarks, n as docRevs, o as observe, r as freshFrames, t as docRev } from "./marks-BnNANic9.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { C as WRITE_MATCH_MS, S as WRITER_HEADERS, _ as ID12, b as RELOAD_BOUNDS, c as takePageBatch, l as takeReloadBatch, n as appendRun, r as logReloadLines, t as PAGE_BODY_MAX, u as tidyPerfDir, v as RECORDER_LEVELS, w as decodeCmds, y as RECORDER_PARAM } from "./perf-BCxAo0IS.mjs";
|
|
13
13
|
import { n as loadConfig } from "./config-BezZTiov.mjs";
|
|
14
14
|
import { a as mergeSizes, c as serializeSizes, i as measuringFrames, l as sizesPath, n as autoWidthOf, o as readSizes, r as keptSizes, s as readSizesFile } from "./sizes-wjXDev3b.mjs";
|
|
15
|
-
import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-
|
|
15
|
+
import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-CRRGgxru.mjs";
|
|
16
16
|
import { a as appProofOk, o as proofHeaders, r as logoRoute } from "./logo-CXY-1yrn.mjs";
|
|
17
17
|
import { closeSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, watch, writeFileSync } from "node:fs";
|
|
18
18
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -90,25 +90,45 @@ function framesFor(root, manifest, file, modules, skipFirst = false) {
|
|
|
90
90
|
touched: [...touched]
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
+
/** The hook that runs first on every hot update (spec 30 #8): this run takes its file's oldest open token, and its
|
|
94
|
+
* bracket opens. Ordered `pre`, so a plugin's own hook (Tailwind's full-reload) runs inside it. */
|
|
95
|
+
function updatesBeginPlugin(changes) {
|
|
96
|
+
return {
|
|
97
|
+
name: "marver:updates-begin",
|
|
98
|
+
hotUpdate: {
|
|
99
|
+
order: "pre",
|
|
100
|
+
handler(opts) {
|
|
101
|
+
if (this.environment.name === "client") changes.begin(opts.file, opts.timestamp);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
93
106
|
/** The hook that runs last on every hot update of the client environment. */
|
|
94
|
-
function updatesPlugin(root, manifest, hooks, landed) {
|
|
107
|
+
function updatesPlugin(root, manifest, hooks, landed, changes) {
|
|
95
108
|
return {
|
|
96
109
|
name: "marver:updates",
|
|
97
110
|
hotUpdate: {
|
|
98
111
|
order: "post",
|
|
99
112
|
handler(opts) {
|
|
100
113
|
landed(opts.file);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
try {
|
|
115
|
+
if (this.environment.name !== "client") return;
|
|
116
|
+
const h = hooks();
|
|
117
|
+
if (!h) return;
|
|
118
|
+
const t = framesFor(root, manifest(), opts.file, opts.modules);
|
|
119
|
+
if (t.doc.length || t.touched.length) {
|
|
120
|
+
const token = changes.run(opts.file, opts.timestamp);
|
|
121
|
+
h.onFrames(t, "update", token ? { token } : changes.ofFile(opts.file));
|
|
122
|
+
}
|
|
123
|
+
} finally {
|
|
124
|
+
changes.landed(opts.file, opts.timestamp);
|
|
125
|
+
}
|
|
106
126
|
}
|
|
107
127
|
}
|
|
108
128
|
};
|
|
109
129
|
}
|
|
110
130
|
/** Wraps the client's hot channel: the reload guard and refused refreshes. */
|
|
111
|
-
function guardUpdates(server, root, manifest, hooks) {
|
|
131
|
+
function guardUpdates(server, root, manifest, hooks, changes) {
|
|
112
132
|
const env = server.environments.client;
|
|
113
133
|
const wrap = (ch) => {
|
|
114
134
|
const send = ch.send.bind(ch);
|
|
@@ -116,12 +136,13 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
116
136
|
const p = a[0];
|
|
117
137
|
if (typeof p === "object" && p?.type === "full-reload") {
|
|
118
138
|
const passed = p.path === "*" && !p.triggeredBy;
|
|
139
|
+
const by = passed ? void 0 : p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
140
|
+
const at = passed ? void 0 : by ? changes.ofFile(by) : changes.pathless();
|
|
119
141
|
hooks.onReload({
|
|
120
142
|
triggeredBy: p.triggeredBy,
|
|
121
143
|
path: p.path
|
|
122
|
-
}, passed);
|
|
144
|
+
}, passed, at);
|
|
123
145
|
if (!passed) {
|
|
124
|
-
const by = p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
125
146
|
const mods = by ? env.moduleGraph.getModulesByFile(by) : void 0;
|
|
126
147
|
const all = manifest().frames.map((f) => f.id);
|
|
127
148
|
const t = by ? framesFor(root, manifest(), by, mods ?? []) : {
|
|
@@ -130,7 +151,7 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
130
151
|
touched: [],
|
|
131
152
|
unattributed: true
|
|
132
153
|
};
|
|
133
|
-
if (t.doc.length || t.touched.length) hooks.onFrames(t, "reload");
|
|
154
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "reload", at);
|
|
134
155
|
return;
|
|
135
156
|
}
|
|
136
157
|
}
|
|
@@ -146,10 +167,290 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
146
167
|
if (refused.get(mod.url) === mod.lastHMRTimestamp) return;
|
|
147
168
|
refused.set(mod.url, mod.lastHMRTimestamp);
|
|
148
169
|
const t = framesFor(root, manifest(), mod.file, [mod], true);
|
|
149
|
-
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate");
|
|
170
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate", changes.refused(mod.lastHMRTimestamp));
|
|
150
171
|
});
|
|
151
172
|
}
|
|
152
173
|
//#endregion
|
|
174
|
+
//#region src/server/changes.ts
|
|
175
|
+
/**
|
|
176
|
+
* An edit's identity, from the watcher to the send (spec 30 R1 #8-#12). Every watcher event mints an immutable token;
|
|
177
|
+
* the hot-update run that comes for it takes the file's oldest open token and opens its bracket; whatever that run
|
|
178
|
+
* causes keeps the token in its own closure, so a line deferred past `setTimeout` and `whenSettled` writes the token it
|
|
179
|
+
* was given - never a lookup, and never a guess. What cannot be known says so (R0): a page-wide reload with no path
|
|
180
|
+
* inside one bracket is that change, inside two is `ambiguous`, outside any is `unknown` (#11); a refused refresh has
|
|
181
|
+
* no identity of its own (#8). Lines the dev server writes name no page: a change belongs to every page.
|
|
182
|
+
*
|
|
183
|
+
* Kept apart from plugin.ts so the attribution rules run under test with a fake clock (test/r30-edits-changes.test.ts).
|
|
184
|
+
*/
|
|
185
|
+
/** A list in lines of at most `idsPerLine` (#10, #12): none for an empty one. */
|
|
186
|
+
function chunks(list) {
|
|
187
|
+
const out = [];
|
|
188
|
+
for (let i = 0; i < list.length; i += RELOAD_BOUNDS.idsPerLine) out.push(list.slice(i, i + RELOAD_BOUNDS.idsPerLine));
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
const bounded = (ids) => ({
|
|
192
|
+
ids: ids.slice(0, RELOAD_BOUNDS.candidates),
|
|
193
|
+
n: ids.length
|
|
194
|
+
});
|
|
195
|
+
function createChanges(o) {
|
|
196
|
+
const boot = o.boot ?? randomBytes(4).toString("hex");
|
|
197
|
+
const now = o.now ?? Date.now;
|
|
198
|
+
let n = 0;
|
|
199
|
+
/** each file's open tokens, oldest first: a run takes the oldest whose hooks have not begun */
|
|
200
|
+
const open = /* @__PURE__ */ new Map();
|
|
201
|
+
/** minted, not ended */
|
|
202
|
+
const flying = /* @__PURE__ */ new Set();
|
|
203
|
+
/** its hooks are running now (several files' runs can overlap; Vite awaits one run's hooks in sequence) */
|
|
204
|
+
const brackets = /* @__PURE__ */ new Set();
|
|
205
|
+
/** a run's identity, shared by its environments' hooks: file and timestamp */
|
|
206
|
+
const runs = /* @__PURE__ */ new Map();
|
|
207
|
+
const runKey = (file, ts) => `${ts}|${file}`;
|
|
208
|
+
/** `hmrTs -> change`, the last 512: a refused refresh's candidates (#8) */
|
|
209
|
+
const history = [];
|
|
210
|
+
const rel = (file) => relative(o.root, file).split(sep).join("/");
|
|
211
|
+
const ids = (ts) => [...ts].map((t) => t.change);
|
|
212
|
+
function writeChange(t) {
|
|
213
|
+
o.write([{
|
|
214
|
+
kind: "change",
|
|
215
|
+
change: t.change,
|
|
216
|
+
file: rel(t.file),
|
|
217
|
+
event: t.event,
|
|
218
|
+
at: t.at,
|
|
219
|
+
...t.hmrTs !== void 0 ? { hmrTs: t.hmrTs } : { outcome: "no-hook" },
|
|
220
|
+
flightMs: t.flightMs,
|
|
221
|
+
reloadN: t.reload.size,
|
|
222
|
+
inPlaceN: t.inPlace.size,
|
|
223
|
+
...t.fullReload ? { fullReload: t.fullReload } : {}
|
|
224
|
+
}]);
|
|
225
|
+
}
|
|
226
|
+
/** A token's end: its hooks landed in every environment, or the 10 s safety path. Its line follows at once, or when
|
|
227
|
+
* the last deferred line that holds it has written. */
|
|
228
|
+
function end(t) {
|
|
229
|
+
if (t.ended) return;
|
|
230
|
+
t.ended = true;
|
|
231
|
+
t.flightMs = now() - t.at;
|
|
232
|
+
flying.delete(t);
|
|
233
|
+
brackets.delete(t);
|
|
234
|
+
if (t.hmrTs !== void 0) runs.delete(runKey(t.file, t.hmrTs));
|
|
235
|
+
const q = open.get(t.file);
|
|
236
|
+
if (q?.includes(t)) {
|
|
237
|
+
q.splice(q.indexOf(t), 1);
|
|
238
|
+
if (!q.length) open.delete(t.file);
|
|
239
|
+
}
|
|
240
|
+
if (t.pending === 0) writeChange(t);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
/** `watchChange`: a watcher event. */
|
|
244
|
+
watch(file, event) {
|
|
245
|
+
const t = {
|
|
246
|
+
change: `${boot}:${++n}`,
|
|
247
|
+
file,
|
|
248
|
+
event,
|
|
249
|
+
at: now(),
|
|
250
|
+
hits: 0,
|
|
251
|
+
ended: false,
|
|
252
|
+
pending: 0,
|
|
253
|
+
reload: /* @__PURE__ */ new Set(),
|
|
254
|
+
inPlace: /* @__PURE__ */ new Set()
|
|
255
|
+
};
|
|
256
|
+
flying.add(t);
|
|
257
|
+
const q = open.get(file);
|
|
258
|
+
if (q) q.push(t);
|
|
259
|
+
else open.set(file, [t]);
|
|
260
|
+
return t;
|
|
261
|
+
},
|
|
262
|
+
/** The `pre` hook, in the client environment (it runs first): this run takes the file's oldest open token. */
|
|
263
|
+
begin(file, hmrTs) {
|
|
264
|
+
const t = open.get(file)?.find((x) => x.hmrTs === void 0);
|
|
265
|
+
if (!t) return void 0;
|
|
266
|
+
t.hmrTs = hmrTs;
|
|
267
|
+
brackets.add(t);
|
|
268
|
+
runs.set(runKey(file, hmrTs), t);
|
|
269
|
+
history.push({
|
|
270
|
+
hmrTs,
|
|
271
|
+
change: t.change
|
|
272
|
+
});
|
|
273
|
+
if (history.length > RELOAD_BOUNDS.hmrHistory) history.shift();
|
|
274
|
+
return t;
|
|
275
|
+
},
|
|
276
|
+
/** The token of the run these hook options belong to, if it has one. */
|
|
277
|
+
run: (file, hmrTs) => runs.get(runKey(file, hmrTs)),
|
|
278
|
+
/** The `post` hook, per environment: the last one closes the bracket, and the token ends a tick later (Vite finishes
|
|
279
|
+
* the update after the hooks). */
|
|
280
|
+
landed(file, hmrTs) {
|
|
281
|
+
const t = runs.get(runKey(file, hmrTs));
|
|
282
|
+
if (!t || ++t.hits < o.envs()) return;
|
|
283
|
+
brackets.delete(t);
|
|
284
|
+
setTimeout(() => end(t), 0);
|
|
285
|
+
},
|
|
286
|
+
/** The 10 s safety path (plugin.ts `flying`): every token of the file still in flight ends. One whose hooks never
|
|
287
|
+
* began says so: the watcher coalesced it, or Vite never brought it to the hooks. */
|
|
288
|
+
expire(file) {
|
|
289
|
+
for (const t of [...open.get(file) ?? []]) end(t);
|
|
290
|
+
},
|
|
291
|
+
/** #11, at the guard: a page-wide reload that named nothing. */
|
|
292
|
+
pathless() {
|
|
293
|
+
if (brackets.size === 1) return {
|
|
294
|
+
token: [...brackets][0],
|
|
295
|
+
by: "hook"
|
|
296
|
+
};
|
|
297
|
+
if (brackets.size > 1) return {
|
|
298
|
+
by: "ambiguous",
|
|
299
|
+
candidates: bounded(ids(brackets))
|
|
300
|
+
};
|
|
301
|
+
return {
|
|
302
|
+
by: "unknown",
|
|
303
|
+
candidates: bounded(ids(flying))
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
/** A page-wide reload that names its file (Vite's dead end, an HTML page), sent after the file's hooks: that file's
|
|
307
|
+
* token still in flight - no time-window guess. */
|
|
308
|
+
ofFile(file) {
|
|
309
|
+
const ts = open.get(file) ?? [];
|
|
310
|
+
if (ts.length === 1) return { token: ts[0] };
|
|
311
|
+
return { candidates: bounded(ids(ts.length ? ts : flying)) };
|
|
312
|
+
},
|
|
313
|
+
/** #8: a refused refresh. `graphTs` is the module's timestamp as read, which a later save has already replaced: the
|
|
314
|
+
* change it names and those of the 10 s before it are candidates - never attributed to one. */
|
|
315
|
+
refused(graphTs) {
|
|
316
|
+
const named = history.filter((h) => h.hmrTs === graphTs);
|
|
317
|
+
const before = history.filter((h) => h.hmrTs < graphTs && h.hmrTs >= graphTs - RELOAD_BOUNDS.lookBackMs).reverse();
|
|
318
|
+
return {
|
|
319
|
+
graphTs,
|
|
320
|
+
candidates: bounded([...named, ...before].map((h) => h.change))
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
/** A line deferred past the hooks keeps the token: it holds the `change` line back until `release`. */
|
|
324
|
+
hold(at) {
|
|
325
|
+
const t = at.token;
|
|
326
|
+
if (!t) return () => {};
|
|
327
|
+
t.pending++;
|
|
328
|
+
return () => {
|
|
329
|
+
if (--t.pending === 0 && t.ended) writeChange(t);
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
/** #10: the `update` line, full membership in `update-ids` parts. */
|
|
333
|
+
update(cause, file, reload, inPlace, at) {
|
|
334
|
+
const r = chunks(reload), p = chunks(inPlace);
|
|
335
|
+
const parts = Math.max(1, r.length, p.length);
|
|
336
|
+
const change = at.token?.change ?? "unknown";
|
|
337
|
+
const lines = [{
|
|
338
|
+
kind: "update",
|
|
339
|
+
cause,
|
|
340
|
+
file: file ? rel(file) : null,
|
|
341
|
+
reload: r[0] ?? [],
|
|
342
|
+
inPlace: p[0] ?? [],
|
|
343
|
+
change,
|
|
344
|
+
reloadN: reload.length,
|
|
345
|
+
inPlaceN: inPlace.length,
|
|
346
|
+
...at.graphTs !== void 0 ? { graphTs: at.graphTs } : {},
|
|
347
|
+
...at.candidates ? { candidates: at.candidates } : {},
|
|
348
|
+
...parts > 1 ? { parts } : {}
|
|
349
|
+
}];
|
|
350
|
+
for (let i = 1; i < parts; i++) lines.push({
|
|
351
|
+
kind: "update-ids",
|
|
352
|
+
change,
|
|
353
|
+
part: i + 1,
|
|
354
|
+
parts,
|
|
355
|
+
...r[i] ? { reload: r[i] } : {},
|
|
356
|
+
...p[i] ? { inPlace: p[i] } : {}
|
|
357
|
+
});
|
|
358
|
+
o.write(lines);
|
|
359
|
+
if (at.token) {
|
|
360
|
+
for (const id of reload) at.token.reload.add(id);
|
|
361
|
+
for (const id of inPlace) at.token.inPlace.add(id);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
/** #11: every page-wide reload Vite or a plugin tried to send, and what it knows of its change. */
|
|
365
|
+
fullReload(p, passed, at) {
|
|
366
|
+
if (at?.token) at.token.fullReload ??= passed ? "passed" : "dropped";
|
|
367
|
+
o.write([{
|
|
368
|
+
kind: "full-reload",
|
|
369
|
+
passed,
|
|
370
|
+
triggeredBy: p.triggeredBy ?? null,
|
|
371
|
+
path: p.path ?? null,
|
|
372
|
+
...at?.by ? { by: at.by } : {},
|
|
373
|
+
...at?.token ? {
|
|
374
|
+
change: at.token.change,
|
|
375
|
+
file: rel(at.token.file)
|
|
376
|
+
} : {},
|
|
377
|
+
...at?.candidates ? { candidates: at.candidates } : {}
|
|
378
|
+
}]);
|
|
379
|
+
},
|
|
380
|
+
/** #12: the send, with every change it carries - many to many, every edge kept in `invalidate-ids` parts. */
|
|
381
|
+
invalidate(revision, frames, changes) {
|
|
382
|
+
const c = chunks(changes);
|
|
383
|
+
const parts = Math.max(1, c.length);
|
|
384
|
+
const lines = [{
|
|
385
|
+
kind: "invalidate",
|
|
386
|
+
revision,
|
|
387
|
+
frames,
|
|
388
|
+
changes: c[0] ?? [],
|
|
389
|
+
...parts > 1 ? { parts } : {}
|
|
390
|
+
}];
|
|
391
|
+
for (let i = 1; i < parts; i++) lines.push({
|
|
392
|
+
kind: "invalidate-ids",
|
|
393
|
+
revision,
|
|
394
|
+
part: i + 1,
|
|
395
|
+
parts,
|
|
396
|
+
changes: c[i]
|
|
397
|
+
});
|
|
398
|
+
o.write(lines);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/server/board-writes.ts
|
|
404
|
+
/**
|
|
405
|
+
* Who may have written a board file (spec 30 #18). Every shell request that can write a board names its page and the
|
|
406
|
+
* commands folded into it (`x-mv-page`, `x-mv-cmds`); the server keeps, per board, the hashes it wrote in the last 10 s
|
|
407
|
+
* with them. The watcher reads the file after a debounce, so a matching hash proves matching bytes, not the writer - an
|
|
408
|
+
* editor can write the same bytes back. `sh:board` therefore carries a match as a candidate, never as proof: one match
|
|
409
|
+
* is `candidate`, two or more `ambiguous`, none `unknown` (an agent, the CLI, an editor, a write the server did not see).
|
|
410
|
+
*/
|
|
411
|
+
/** by project root: the middleware and the watcher share a process, not an object */
|
|
412
|
+
const written = /* @__PURE__ */ new Map();
|
|
413
|
+
/** The page and commands a request names; null when it names no page (the CLI, an agent): nothing to remember. */
|
|
414
|
+
function writerFrom(headers) {
|
|
415
|
+
const page = headers[WRITER_HEADERS.page];
|
|
416
|
+
if (typeof page !== "string" || !ID12.test(page)) return null;
|
|
417
|
+
return {
|
|
418
|
+
page,
|
|
419
|
+
cmds: decodeCmds(headers[WRITER_HEADERS.cmds] ?? "") ?? {
|
|
420
|
+
ids: [],
|
|
421
|
+
n: 0
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const fresh = (root, now) => {
|
|
426
|
+
const kept = (written.get(root) ?? []).filter((w) => now - w.at < WRITE_MATCH_MS);
|
|
427
|
+
if (kept.length) written.set(root, kept);
|
|
428
|
+
else written.delete(root);
|
|
429
|
+
return kept;
|
|
430
|
+
};
|
|
431
|
+
/** A board write this server made, once it landed. */
|
|
432
|
+
function noteWrite(root, board, sha, who, now = Date.now()) {
|
|
433
|
+
written.set(root, [...fresh(root, now), {
|
|
434
|
+
...who,
|
|
435
|
+
board,
|
|
436
|
+
sha,
|
|
437
|
+
at: now
|
|
438
|
+
}]);
|
|
439
|
+
}
|
|
440
|
+
/** What the writes of the last 10 s say about these bytes of this board. */
|
|
441
|
+
function writerOf(root, board, sha, now = Date.now()) {
|
|
442
|
+
const match = fresh(root, now).filter((w) => w.board === board && w.sha === sha);
|
|
443
|
+
if (!match.length) return { writer: "unknown" };
|
|
444
|
+
return {
|
|
445
|
+
writer: match.length === 1 ? "candidate" : "ambiguous",
|
|
446
|
+
candidates: match.slice(-RELOAD_BOUNDS.candidates).map((w) => ({
|
|
447
|
+
page: w.page,
|
|
448
|
+
cmds: w.cmds.ids,
|
|
449
|
+
n: w.cmds.n
|
|
450
|
+
}))
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
153
454
|
//#region src/shared/perf-run.ts
|
|
154
455
|
/** A run's own generated id: the same in the URL, the request headers and the output line (A3.4). */
|
|
155
456
|
const RUN_ID = /^[0-9a-f]{16}$/;
|
|
@@ -465,7 +766,7 @@ async function bakeIn(b, opts) {
|
|
|
465
766
|
const deadline = setTimeout(() => {
|
|
466
767
|
timedOut = true;
|
|
467
768
|
b.abort(me, TIMED_OUT);
|
|
468
|
-
}, DEADLINE_MS);
|
|
769
|
+
}, bakeSeams.deadlineMs ?? DEADLINE_MS);
|
|
469
770
|
const closeTarget = async (id) => {
|
|
470
771
|
let t;
|
|
471
772
|
await Promise.race([b.send("Target.closeTarget", { targetId: id }).catch(() => {}), new Promise((r) => {
|
|
@@ -950,11 +1251,13 @@ function endRunBakes(owner) {
|
|
|
950
1251
|
* looks at a COMPILING outlast any held compile (A3.8 r1 #4's case, added by the review of a3-runs). */
|
|
951
1252
|
const bakeSeams = {};
|
|
952
1253
|
const holdMs = () => {
|
|
953
|
-
return
|
|
1254
|
+
if (bakeSeams.holdMs !== void 0) return bakeSeams.holdMs;
|
|
1255
|
+
const v = process.env.MARVER_SLOT_BASE ? Number(process.env.MV_BAKE_HOLD_MS) : NaN;
|
|
1256
|
+
return Number.isFinite(v) && v > 0 ? Math.min(v, 6e4) : 0;
|
|
954
1257
|
};
|
|
955
1258
|
/** The suite's answer for a compile still running, under MV_BAKE_STOP_ASKING (above). */
|
|
956
1259
|
const STOP_ASKING = "still compiling - the suite asks the page to stop asking";
|
|
957
|
-
const stillCompiling = () => COMPILING;
|
|
1260
|
+
const stillCompiling = () => bakeSeams.stopAsking ?? (!!process.env.MARVER_SLOT_BASE && process.env.MV_BAKE_STOP_ASKING === "1") ? STOP_ASKING : COMPILING;
|
|
958
1261
|
/** Compiles in flight, by generation and key: identical asks - inside one request or across
|
|
959
1262
|
* concurrent ones - share one compile. */
|
|
960
1263
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -1274,7 +1577,7 @@ async function inputPaths(root, w, urls) {
|
|
|
1274
1577
|
}
|
|
1275
1578
|
/** These paths' fingerprint: each file's path from the root (`../` for one outside it), size and mtime. A path that
|
|
1276
1579
|
* is gone or no file counts for nothing - so one deleted since changes it. */
|
|
1277
|
-
async function hashInputs(root, paths) {
|
|
1580
|
+
async function hashInputs(root, paths, level = "full") {
|
|
1278
1581
|
const lines = [];
|
|
1279
1582
|
for (let i = 0; i < paths.length; i += 64) {
|
|
1280
1583
|
const got = await Promise.all(paths.slice(i, i + 64).map(async (p) => {
|
|
@@ -1284,9 +1587,10 @@ async function hashInputs(root, paths) {
|
|
|
1284
1587
|
for (const l of got) if (l) lines.push(l);
|
|
1285
1588
|
}
|
|
1286
1589
|
lines.sort();
|
|
1590
|
+
if (level === "core") lines.push("\0recorder\0core");
|
|
1287
1591
|
return {
|
|
1288
1592
|
hash: createHash("sha256").update(lines.join("\n")).digest("hex").slice(0, 16),
|
|
1289
|
-
files: lines.length
|
|
1593
|
+
files: lines.length - (level === "core" ? 1 : 0)
|
|
1290
1594
|
};
|
|
1291
1595
|
}
|
|
1292
1596
|
/** The fingerprint of every watched file, plus the board files and `_sizes.json`; null before the watcher is ready. */
|
|
@@ -1615,6 +1919,22 @@ const RUN_T = {
|
|
|
1615
1919
|
runMs: 42e4
|
|
1616
1920
|
};
|
|
1617
1921
|
/** The page's own bound on `flush()` (recorder.ts): the driver waits that long, and `callMs` more. */
|
|
1922
|
+
/** Spec 30's error sources that do not make a run invalid (above), and the drops under a source's own limit: none of them is
|
|
1923
|
+
* a frame, a move or an error the run counts. */
|
|
1924
|
+
const SOFT_SOURCES = /* @__PURE__ */ new Set([
|
|
1925
|
+
"console",
|
|
1926
|
+
"api",
|
|
1927
|
+
"resource"
|
|
1928
|
+
]);
|
|
1929
|
+
const OWN_LIMITS = /* @__PURE__ */ new Set([
|
|
1930
|
+
"errors",
|
|
1931
|
+
"console",
|
|
1932
|
+
"api",
|
|
1933
|
+
"resource",
|
|
1934
|
+
"cmd",
|
|
1935
|
+
"theme",
|
|
1936
|
+
"mode"
|
|
1937
|
+
]);
|
|
1618
1938
|
const FLUSH_MS = 15e3;
|
|
1619
1939
|
const RECORDS_MAX = 2e4;
|
|
1620
1940
|
const live = /* @__PURE__ */ new Map();
|
|
@@ -1713,10 +2033,21 @@ const runSeams = {};
|
|
|
1713
2033
|
/** RUN_T, with the suite's overrides: `runSeams.t` in-process, `MV_PERF_RUN_T` (JSON) for a dev server a test starts -
|
|
1714
2034
|
* both read only with MARVER_SLOT_BASE set (the suite's marker). */
|
|
1715
2035
|
function runT() {
|
|
1716
|
-
|
|
2036
|
+
const t = { ...RUN_T };
|
|
2037
|
+
if (!process.env.MARVER_SLOT_BASE) return t;
|
|
2038
|
+
let env = {};
|
|
2039
|
+
try {
|
|
2040
|
+
env = JSON.parse(process.env.MV_PERF_RUN_T ?? "{}");
|
|
2041
|
+
} catch {}
|
|
2042
|
+
for (const src of [env, runSeams.t ?? {}]) for (const k of Object.keys(t)) {
|
|
2043
|
+
const v = src[k];
|
|
2044
|
+
if (typeof v === "number" && v >= 0) t[k] = v;
|
|
2045
|
+
}
|
|
2046
|
+
return t;
|
|
1717
2047
|
}
|
|
1718
|
-
/** The shell's address for a run's load: its run id, the warm-up's mark, the
|
|
1719
|
-
|
|
2048
|
+
/** The shell's address for a run's load: its run id, the warm-up's mark, the recorder's level when not `full` (spec 30
|
|
2049
|
+
* #58: the shell reads it, `withWs()` carries it to the frames), the board. */
|
|
2050
|
+
const runUrl = (origin, board, id, warm, recorder = "full") => `${origin}/?${RUN_PARAM}=${id}${warm ? `&${WARM_PARAM}=1` : ""}${recorder === "core" ? `&${RECORDER_PARAM}=core` : ""}#/b/${encodeURIComponent(board)}`;
|
|
1720
2051
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1721
2052
|
/** The last runs' own input paths, for `GET /api/perf/inputs?run=<id>` (the review of a3-runs' fixes): a run's set
|
|
1722
2053
|
* outside the root is its page's, which no request without the run can rebuild. Module state, the newest 32. */
|
|
@@ -1780,6 +2111,7 @@ async function openPage(b, o) {
|
|
|
1780
2111
|
}
|
|
1781
2112
|
};
|
|
1782
2113
|
function call(m, p = {}, sid, ms = T.callMs) {
|
|
2114
|
+
runSeams.cdp?.(m, p);
|
|
1783
2115
|
const sent = b.send(m, p, sid, own);
|
|
1784
2116
|
let t;
|
|
1785
2117
|
const late = new Promise((_, reject) => {
|
|
@@ -1843,6 +2175,7 @@ async function openPage(b, o) {
|
|
|
1843
2175
|
async function closePage(b, page) {
|
|
1844
2176
|
page.stop();
|
|
1845
2177
|
const bounded = async (m, p, sid) => {
|
|
2178
|
+
runSeams.cdp?.(m, p);
|
|
1846
2179
|
let t;
|
|
1847
2180
|
await Promise.race([b.send(m, p, sid).catch(() => {}), new Promise((r) => {
|
|
1848
2181
|
t = setTimeout(r, 2e3);
|
|
@@ -2010,9 +2343,9 @@ function runLine(reg, s) {
|
|
|
2010
2343
|
const own = load ? recs.filter((r) => r.load === load.request) : [];
|
|
2011
2344
|
const commit = own.find((r) => r.kind === "commit"), settled = own.find((r) => r.kind === "settled");
|
|
2012
2345
|
const moves = own.filter((r) => r.kind === "move");
|
|
2013
|
-
const errors = recs.filter((r) => r.kind === "error").length;
|
|
2346
|
+
const errors = recs.filter((r) => r.kind === "error" && !SOFT_SOURCES.has(r.source)).length;
|
|
2014
2347
|
const badFrames = settled ? (settled.missing ?? 0) + (settled.neverReady ?? 0) : 0;
|
|
2015
|
-
const lost = recs.filter((r) => r.kind === "dropped" && r.reason
|
|
2348
|
+
const lost = recs.filter((r) => r.kind === "dropped" && !OWN_LIMITS.has(r.reason)).reduce((n, r) => n + (typeof r.n === "number" && r.n > 0 ? r.n : 1), 0) + (reg.overflow ?? 0);
|
|
2016
2349
|
const reasons = [
|
|
2017
2350
|
["cancelled", s.cancelled],
|
|
2018
2351
|
["crash", s.crashed],
|
|
@@ -2044,6 +2377,7 @@ function runLine(reg, s) {
|
|
|
2044
2377
|
host: s.host,
|
|
2045
2378
|
power: s.power,
|
|
2046
2379
|
slow: s.slow,
|
|
2380
|
+
recorder: s.recorder ?? "full",
|
|
2047
2381
|
bakes: s.bakes,
|
|
2048
2382
|
postersMissing: s.postersSkipped,
|
|
2049
2383
|
saved: commit ? {
|
|
@@ -2081,6 +2415,7 @@ async function runOnce(o) {
|
|
|
2081
2415
|
id,
|
|
2082
2416
|
board: o.board,
|
|
2083
2417
|
slow: o.slow,
|
|
2418
|
+
recorder: o.recorder ?? "full",
|
|
2084
2419
|
startedAt: reg.startedAt,
|
|
2085
2420
|
inputs: null,
|
|
2086
2421
|
inputsEnd: null,
|
|
@@ -2106,7 +2441,7 @@ async function runOnce(o) {
|
|
|
2106
2441
|
const paths = o.watch ? await inputPaths(o.root, o.watch, urls) : null;
|
|
2107
2442
|
if (!paths) return;
|
|
2108
2443
|
set.paths = paths;
|
|
2109
|
-
seen.inputs = await hashInputs(o.root, paths);
|
|
2444
|
+
seen.inputs = await hashInputs(o.root, paths, o.recorder);
|
|
2110
2445
|
};
|
|
2111
2446
|
const requested = /* @__PURE__ */ new Set();
|
|
2112
2447
|
let offRequests = () => {};
|
|
@@ -2160,7 +2495,7 @@ async function runOnce(o) {
|
|
|
2160
2495
|
const url = m.sessionId === warmSession && m.method === "Network.requestWillBeSent" ? m.params?.request?.url : void 0;
|
|
2161
2496
|
if (typeof url === "string" && url.startsWith(`${o.origin}/`)) requested.add(url);
|
|
2162
2497
|
});
|
|
2163
|
-
await page.send("Page.navigate", { url: runUrl(o.origin, o.board, id, true) });
|
|
2498
|
+
await page.send("Page.navigate", { url: runUrl(o.origin, o.board, id, true, o.recorder) });
|
|
2164
2499
|
const warm = await until(page, (s) => loadEnded(s) && bakeIdle(id)(s), T.warmMs, halt(page));
|
|
2165
2500
|
seen.bakes = warm.ok ? "warm" : "cold";
|
|
2166
2501
|
seen.refusedInPage += warm.status?.refused ?? 0;
|
|
@@ -2199,7 +2534,7 @@ async function runOnce(o) {
|
|
|
2199
2534
|
};
|
|
2200
2535
|
const heapTimer = setInterval(sampleHeap, T.heapMs);
|
|
2201
2536
|
try {
|
|
2202
|
-
await p.send("Page.navigate", { url: runUrl(o.origin, o.board, id, false) });
|
|
2537
|
+
await p.send("Page.navigate", { url: runUrl(o.origin, o.board, id, false, o.recorder) });
|
|
2203
2538
|
sampleHeap();
|
|
2204
2539
|
const loaded = await until(p, loadEnded, T.settleMs, hp);
|
|
2205
2540
|
if (!loaded.ok || loaded.status?.load?.state === "cut") seen.cut = loaded.status?.load?.reason ?? (p.crashed ? "crash" : "timeout");
|
|
@@ -2258,7 +2593,7 @@ async function runOnce(o) {
|
|
|
2258
2593
|
lingering.add(id);
|
|
2259
2594
|
}
|
|
2260
2595
|
await sleep(T.watcherLagMs);
|
|
2261
|
-
seen.inputsEnd = set.paths ? (await hashInputs(o.root, set.paths)).hash : null;
|
|
2596
|
+
seen.inputsEnd = set.paths ? (await hashInputs(o.root, set.paths, o.recorder)).hash : null;
|
|
2262
2597
|
const done = runs.end(id) ?? reg;
|
|
2263
2598
|
seen.cancelled ||= o.signal.aborted;
|
|
2264
2599
|
const line = runLine(done, seen);
|
|
@@ -2304,7 +2639,7 @@ function readRunRequest(raw, boards) {
|
|
|
2304
2639
|
}
|
|
2305
2640
|
if (!b || typeof b !== "object" || Array.isArray(b)) return {
|
|
2306
2641
|
ok: false,
|
|
2307
|
-
error: "expected { board, slow?, repeat? }"
|
|
2642
|
+
error: "expected { board, slow?, repeat?, recorder? }"
|
|
2308
2643
|
};
|
|
2309
2644
|
if (typeof b.board !== "string" || !boards.includes(b.board)) return {
|
|
2310
2645
|
ok: false,
|
|
@@ -2319,12 +2654,17 @@ function readRunRequest(raw, boards) {
|
|
|
2319
2654
|
ok: false,
|
|
2320
2655
|
error: "repeat must be 1-5"
|
|
2321
2656
|
};
|
|
2657
|
+
if (b.recorder !== void 0 && !RECORDER_LEVELS.includes(b.recorder)) return {
|
|
2658
|
+
ok: false,
|
|
2659
|
+
error: "recorder must be core or full"
|
|
2660
|
+
};
|
|
2322
2661
|
return {
|
|
2323
2662
|
ok: true,
|
|
2324
2663
|
req: {
|
|
2325
2664
|
board: b.board,
|
|
2326
2665
|
slow: b.slow === true,
|
|
2327
|
-
repeat
|
|
2666
|
+
repeat,
|
|
2667
|
+
recorder: b.recorder === "core" ? "core" : "full"
|
|
2328
2668
|
}
|
|
2329
2669
|
};
|
|
2330
2670
|
}
|
|
@@ -2360,12 +2700,13 @@ async function serveRun(req, res, o) {
|
|
|
2360
2700
|
};
|
|
2361
2701
|
const beat = setInterval(() => write({ heartbeat: Date.now() }), T.heartbeatMs);
|
|
2362
2702
|
try {
|
|
2363
|
-
const drive = runOnce;
|
|
2703
|
+
const drive = runSeams.driver ?? runOnce;
|
|
2364
2704
|
for (let i = 0; i < asked.req.repeat && !ac.signal.aborted; i++) write({ line: await drive({
|
|
2365
2705
|
root: o.root,
|
|
2366
2706
|
origin: o.origin,
|
|
2367
2707
|
board: asked.req.board,
|
|
2368
2708
|
slow: asked.req.slow,
|
|
2709
|
+
recorder: asked.req.recorder,
|
|
2369
2710
|
signal: ac.signal,
|
|
2370
2711
|
progress: write,
|
|
2371
2712
|
watch: o.watch
|
|
@@ -2535,6 +2876,12 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2535
2876
|
const notSymlink = (p) => !nodeExists(p) || isRegularFile(p);
|
|
2536
2877
|
const nodeExists$1 = nodeExists;
|
|
2537
2878
|
let sizesWarned = false;
|
|
2879
|
+
/** A board file this request wrote (spec 30 #18), with the page and commands it names - the watcher's `sh:board`
|
|
2880
|
+
* matches these bytes against it, as a candidate, never as proof. */
|
|
2881
|
+
const wroteBoard = (req, board, content) => {
|
|
2882
|
+
const who = writerFrom(req.headers);
|
|
2883
|
+
if (who) noteWrite(root, board, hash(content), who);
|
|
2884
|
+
};
|
|
2538
2885
|
try {
|
|
2539
2886
|
for (const f of readdirSync(boardsDir)) if (f.endsWith(".tmp")) rmSync(join(boardsDir, f), { force: true });
|
|
2540
2887
|
} catch {}
|
|
@@ -2754,6 +3101,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2754
3101
|
}
|
|
2755
3102
|
renameSync(tmp, w.file);
|
|
2756
3103
|
done.push(w);
|
|
3104
|
+
if (!w.plan) wroteBoard(req, name, w.next);
|
|
2757
3105
|
} catch (err) {
|
|
2758
3106
|
if (tmp) discard(tmp);
|
|
2759
3107
|
const stuck = undo();
|
|
@@ -2780,7 +3128,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2780
3128
|
};
|
|
2781
3129
|
if (path === "perf/reload" && req.method === "POST") {
|
|
2782
3130
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
2783
|
-
const raw = await readBody(req);
|
|
3131
|
+
const raw = await readBody(req, PAGE_BODY_MAX);
|
|
2784
3132
|
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
2785
3133
|
let b;
|
|
2786
3134
|
try {
|
|
@@ -2788,19 +3136,9 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2788
3136
|
} catch {
|
|
2789
3137
|
return json(res, 400, { error: "malformed JSON" });
|
|
2790
3138
|
}
|
|
2791
|
-
|
|
2792
|
-
const
|
|
2793
|
-
|
|
2794
|
-
(await import("./perf-jam-CLkERSHo.mjs").then((n) => n.c)).logReload(root, {
|
|
2795
|
-
kind: str(b.kind),
|
|
2796
|
-
tab: str(b.tab),
|
|
2797
|
-
node: str(b.node),
|
|
2798
|
-
frame: str(b.frame),
|
|
2799
|
-
cause: str(b.cause),
|
|
2800
|
-
shown: str(b.shown),
|
|
2801
|
-
ms: num(b.ms)
|
|
2802
|
-
});
|
|
2803
|
-
return json(res, 200, { ok: true });
|
|
3139
|
+
if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
|
|
3140
|
+
const answer = takeReloadBatch(root, b.records);
|
|
3141
|
+
return json(res, "error" in answer ? 503 : 200, answer);
|
|
2804
3142
|
}
|
|
2805
3143
|
if (path === "perf/jam" && req.method === "POST") {
|
|
2806
3144
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
@@ -2813,7 +3151,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2813
3151
|
return json(res, 400, { error: "malformed JSON" });
|
|
2814
3152
|
}
|
|
2815
3153
|
if (!b || b.kind !== "capture" && b.kind !== "upload") return json(res, 400, { error: "kind must be capture or upload" });
|
|
2816
|
-
(await import("./perf-
|
|
3154
|
+
(await import("./perf-BCxAo0IS.mjs").then((n) => n.f)).logJam(root, b);
|
|
2817
3155
|
return json(res, 200, { ok: true });
|
|
2818
3156
|
}
|
|
2819
3157
|
if (path === "perf/page" && req.method === "POST") {
|
|
@@ -2829,13 +3167,11 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2829
3167
|
return json(res, 400, { error: "malformed JSON" });
|
|
2830
3168
|
}
|
|
2831
3169
|
if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
} : {})
|
|
2838
|
-
});
|
|
3170
|
+
const answer = takePageBatch(root, b.records, run ? {
|
|
3171
|
+
run,
|
|
3172
|
+
kept: (recs) => runs.records(run, recs)
|
|
3173
|
+
} : {});
|
|
3174
|
+
return json(res, "error" in answer ? 503 : 200, answer);
|
|
2839
3175
|
}
|
|
2840
3176
|
if (path === "perf/run" && req.method === "POST" || path === "perf/inputs" && req.method === "GET") {
|
|
2841
3177
|
const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
|
|
@@ -2948,7 +3284,9 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2948
3284
|
const frames = Array.isArray(parsed?.frames) ? parsed.frames.filter((f) => typeof f === "string" && live.includes(f)) : [];
|
|
2949
3285
|
if (!validName(parsed?.board) || !frames.length) return json(res, 400, { error: "a board and frames on this canvas" });
|
|
2950
3286
|
try {
|
|
2951
|
-
|
|
3287
|
+
const pinned = pinFrames(root, parsed.board, frames, live);
|
|
3288
|
+
if (pinned.added.length) wroteBoard(req, parsed.board, readFileSync(join(boardsDir, `${parsed.board}.json`), "utf8"));
|
|
3289
|
+
return json(res, 200, pinned);
|
|
2952
3290
|
} catch (err) {
|
|
2953
3291
|
return json(res, 409, { error: err.message });
|
|
2954
3292
|
}
|
|
@@ -3022,12 +3360,14 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3022
3360
|
return json(res, 200, { name: to });
|
|
3023
3361
|
}
|
|
3024
3362
|
rmSync(fromPath);
|
|
3363
|
+
if (next !== void 0) wroteBoard(req, to, next);
|
|
3025
3364
|
return json(res, 200, {
|
|
3026
3365
|
name: to,
|
|
3027
3366
|
...next !== void 0 ? { sha256: hash(next) } : {}
|
|
3028
3367
|
});
|
|
3029
3368
|
}
|
|
3030
3369
|
atomicWrite(toPath, next);
|
|
3370
|
+
wroteBoard(req, to, next);
|
|
3031
3371
|
return json(res, 200, {
|
|
3032
3372
|
name: to,
|
|
3033
3373
|
sha256: hash(next)
|
|
@@ -3193,6 +3533,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3193
3533
|
else delete w.obj.folder;
|
|
3194
3534
|
const next = JSON.stringify(w.obj, null, 2) + "\n";
|
|
3195
3535
|
atomicWrite(w.path, next);
|
|
3536
|
+
wroteBoard(req, w.name, next);
|
|
3196
3537
|
sha256[w.name] = hash(next);
|
|
3197
3538
|
}
|
|
3198
3539
|
mkdirSync(boardsDir, { recursive: true });
|
|
@@ -3280,6 +3621,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3280
3621
|
} catch {}
|
|
3281
3622
|
const next2 = JSON.stringify(body.board, null, 2) + "\n";
|
|
3282
3623
|
atomicWrite(p, next2);
|
|
3624
|
+
wroteBoard(req, boardMatch[1], next2);
|
|
3283
3625
|
return json(res, 200, { sha256: hash(next2) });
|
|
3284
3626
|
} finally {
|
|
3285
3627
|
unlock();
|
|
@@ -3303,7 +3645,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3303
3645
|
};
|
|
3304
3646
|
const asPng = url.searchParams.get("format") === "png";
|
|
3305
3647
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3306
|
-
const { shootFrame } = await import("./shot-
|
|
3648
|
+
const { shootFrame } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
3307
3649
|
const r = await shootFrame({
|
|
3308
3650
|
root,
|
|
3309
3651
|
viewports: opts.viewports ?? {},
|
|
@@ -3354,7 +3696,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3354
3696
|
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
|
|
3355
3697
|
const scale = body.scale === void 0 ? void 0 : body.scale;
|
|
3356
3698
|
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
|
|
3357
|
-
const { resolveFrames, shootBatch } = await import("./shot-
|
|
3699
|
+
const { resolveFrames, shootBatch } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
3358
3700
|
const sel = resolveFrames(root, body);
|
|
3359
3701
|
if (!sel.ok) return json(res, sel.status, { error: sel.error });
|
|
3360
3702
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
@@ -3388,7 +3730,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3388
3730
|
if (typeof target === "string") return json(res, 400, { error: target });
|
|
3389
3731
|
const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
|
|
3390
3732
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3391
|
-
const { checkAnchor, CheckInputError } = await import("./anchor-check-
|
|
3733
|
+
const { checkAnchor, CheckInputError } = await import("./anchor-check-c52IDkiQ.mjs");
|
|
3392
3734
|
try {
|
|
3393
3735
|
return json(res, 200, await checkAnchor({
|
|
3394
3736
|
root,
|
|
@@ -3496,8 +3838,8 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3496
3838
|
return json(res, 400, { error: "malformed JSON" });
|
|
3497
3839
|
}
|
|
3498
3840
|
const src = typeof b?.src === "string" ? b.src : "";
|
|
3499
|
-
const { ensurePoster, isLocalClip } = await import("./poster-
|
|
3500
|
-
const { isLocalAssetRef } = await import("./build-
|
|
3841
|
+
const { ensurePoster, isLocalClip } = await import("./poster-CYmCa00B.mjs");
|
|
3842
|
+
const { isLocalAssetRef } = await import("./build-C3mUtjEn.mjs");
|
|
3501
3843
|
if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
|
|
3502
3844
|
const r = await ensurePoster(join(root, "design", "assets"), src);
|
|
3503
3845
|
if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
|
|
@@ -3914,7 +4256,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3914
4256
|
if (!b || typeof b.capture !== "string" || !CAPTURE_ID.test(b.capture) || typeof b.frame !== "string") return json(res, 400, { error: "expected { capture, frame, theme?, viewport? }" });
|
|
3915
4257
|
if (readCapture(root, b.capture)) return json(res, 409, { error: "that capture is sealed" });
|
|
3916
4258
|
const theme = typeof b.theme === "string" && /^[a-z0-9-]+$/i.test(b.theme) ? b.theme : "light";
|
|
3917
|
-
const { shootFrame } = await import("./shot-
|
|
4259
|
+
const { shootFrame } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
3918
4260
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3919
4261
|
const vp = typeof b.viewport === "string" ? opts.viewports?.[b.viewport] : void 0;
|
|
3920
4262
|
const dim = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
|
|
@@ -4584,21 +4926,31 @@ function marverPlugin(ctx) {
|
|
|
4584
4926
|
const bootId = String(process.hrtime.bigint());
|
|
4585
4927
|
let invRev = 0;
|
|
4586
4928
|
const pendingInv = /* @__PURE__ */ new Set();
|
|
4929
|
+
const pendingChanges = /* @__PURE__ */ new Set();
|
|
4587
4930
|
const flushInv = debounce(() => {
|
|
4588
4931
|
if (!devServer || !pendingInv.size) return;
|
|
4589
4932
|
const frameIds = [...pendingInv];
|
|
4590
4933
|
pendingInv.clear();
|
|
4934
|
+
const carried = [...pendingChanges];
|
|
4935
|
+
pendingChanges.clear();
|
|
4936
|
+
const revision = `${bootId}:${++invRev}`;
|
|
4591
4937
|
const docs = docRevs(root, manifest.frames);
|
|
4592
4938
|
devServer.ws.send("sh:frame-invalidated", {
|
|
4593
4939
|
frameIds,
|
|
4594
|
-
revision
|
|
4940
|
+
revision,
|
|
4595
4941
|
epoch: docs?.epoch,
|
|
4596
4942
|
docs: docs ? Object.fromEntries(frameIds.map((id) => [id, docs.doc[id] ?? 0])) : void 0
|
|
4597
4943
|
});
|
|
4944
|
+
changes.invalidate(revision, frameIds.length, carried);
|
|
4598
4945
|
}, 120);
|
|
4599
4946
|
const inFlight = /* @__PURE__ */ new Map();
|
|
4600
4947
|
const late = /* @__PURE__ */ new Map();
|
|
4601
4948
|
const envs = () => Object.keys(devServer?.environments ?? { client: 1 }).length;
|
|
4949
|
+
const changes = createChanges({
|
|
4950
|
+
root,
|
|
4951
|
+
envs,
|
|
4952
|
+
write: (lines) => logReloadLines(root, lines)
|
|
4953
|
+
});
|
|
4602
4954
|
const waiting = [];
|
|
4603
4955
|
const settled = () => inFlight.size === 0;
|
|
4604
4956
|
const whenSettled = (fn) => {
|
|
@@ -4632,6 +4984,7 @@ function marverPlugin(ctx) {
|
|
|
4632
4984
|
for (const env of Object.values(devServer?.environments ?? {})) env.moduleGraph.invalidateAll();
|
|
4633
4985
|
late.set(file, (late.get(file) ?? 0) + f.events * envs() - f.hits);
|
|
4634
4986
|
inFlight.delete(file);
|
|
4987
|
+
changes.expire(file);
|
|
4635
4988
|
drain();
|
|
4636
4989
|
}, 1e4);
|
|
4637
4990
|
inFlight.set(file, f);
|
|
@@ -4661,19 +5014,21 @@ function marverPlugin(ctx) {
|
|
|
4661
5014
|
}
|
|
4662
5015
|
});
|
|
4663
5016
|
const hooks = {
|
|
4664
|
-
onFrames: (t, cause) => {
|
|
4665
|
-
|
|
5017
|
+
onFrames: (t, cause, at) => {
|
|
5018
|
+
const release = changes.hold(at);
|
|
5019
|
+
setTimeout(() => whenSettled(() => {
|
|
5020
|
+
try {
|
|
5021
|
+
record(t, cause, at);
|
|
5022
|
+
} finally {
|
|
5023
|
+
release();
|
|
5024
|
+
}
|
|
5025
|
+
}), 0);
|
|
4666
5026
|
},
|
|
4667
|
-
onReload(p, passed) {
|
|
4668
|
-
|
|
4669
|
-
kind: "full-reload",
|
|
4670
|
-
passed,
|
|
4671
|
-
triggeredBy: p.triggeredBy ?? null,
|
|
4672
|
-
path: p.path ?? null
|
|
4673
|
-
});
|
|
5027
|
+
onReload(p, passed, at) {
|
|
5028
|
+
changes.fullReload(p, passed, at);
|
|
4674
5029
|
}
|
|
4675
5030
|
};
|
|
4676
|
-
function record(t, cause) {
|
|
5031
|
+
function record(t, cause, at) {
|
|
4677
5032
|
const seen = observe(root, manifest.frames, t.file ? { file: t.file } : {});
|
|
4678
5033
|
const doc = t.unattributed ? [] : t.doc.filter((id) => !seen.doc.includes(id));
|
|
4679
5034
|
const touched = t.touched.filter((id) => !seen.doc.includes(id) && !seen.note.includes(id) && !doc.includes(id));
|
|
@@ -4681,18 +5036,13 @@ function marverPlugin(ctx) {
|
|
|
4681
5036
|
if (touched.length) recordChanged(root, manifest.frames, touched, { doc: false });
|
|
4682
5037
|
const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
|
|
4683
5038
|
for (const id of reload) pendingInv.add(id);
|
|
5039
|
+
if (reload.length && at.token) pendingChanges.add(at.token.change);
|
|
4684
5040
|
flushInv();
|
|
4685
5041
|
if (reload.length || touched.length || seen.note.length) {
|
|
4686
5042
|
devServer?.ws.send("sh:marks", {});
|
|
4687
5043
|
liveChanged();
|
|
4688
5044
|
}
|
|
4689
|
-
|
|
4690
|
-
kind: "update",
|
|
4691
|
-
cause,
|
|
4692
|
-
file: t.file ? relative(root, t.file).split(sep).join("/") : null,
|
|
4693
|
-
reload,
|
|
4694
|
-
inPlace: t.touched
|
|
4695
|
-
});
|
|
5045
|
+
changes.update(cause, t.file, reload, t.touched, at);
|
|
4696
5046
|
}
|
|
4697
5047
|
/** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
|
|
4698
5048
|
* Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
|
|
@@ -4706,500 +5056,509 @@ function marverPlugin(ctx) {
|
|
|
4706
5056
|
if (ctx.detectedThemeCss && existsSync(join(root, ctx.detectedThemeCss))) return join(root, ctx.detectedThemeCss);
|
|
4707
5057
|
return null;
|
|
4708
5058
|
};
|
|
4709
|
-
return [
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
if (
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
html
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
type: "module",
|
|
4777
|
-
src: bridge
|
|
5059
|
+
return [
|
|
5060
|
+
{
|
|
5061
|
+
name: "marver",
|
|
5062
|
+
watchChange(id, change) {
|
|
5063
|
+
if (devServer) {
|
|
5064
|
+
flying(id);
|
|
5065
|
+
changes.watch(id, change.event);
|
|
5066
|
+
}
|
|
5067
|
+
},
|
|
5068
|
+
enforce: "pre",
|
|
5069
|
+
resolveId(id) {
|
|
5070
|
+
if (id === VIRTUAL_THEME) return themeFile() ?? "\0virtual:sh-theme.css";
|
|
5071
|
+
if (id === VIRTUAL_CONFIG) return "\0virtual:sh-config";
|
|
5072
|
+
if (id === VIRTUAL_DATA) return "\0virtual:sh-data";
|
|
5073
|
+
},
|
|
5074
|
+
load(id) {
|
|
5075
|
+
if (id === "\0virtual:sh-theme.css") {
|
|
5076
|
+
if (themeMissing()) console.warn("[marver] no theme detected - frames render unstyled. Create design/theme.css importing your app's stylesheet (or set `theme` in design/config.ts).");
|
|
5077
|
+
return "/* marver: no theme configured */";
|
|
5078
|
+
}
|
|
5079
|
+
if (id === "\0virtual:sh-config") {
|
|
5080
|
+
const setupPending = (() => {
|
|
5081
|
+
try {
|
|
5082
|
+
const s = readFileSync(join(root, "design", "instructions", "setup.md"), "utf8");
|
|
5083
|
+
return s.startsWith("# Setup required") && s.includes("marver init");
|
|
5084
|
+
} catch {
|
|
5085
|
+
return false;
|
|
5086
|
+
}
|
|
5087
|
+
})();
|
|
5088
|
+
return `export default ${JSON.stringify({
|
|
5089
|
+
viewports: config.viewports,
|
|
5090
|
+
themes: config.themes,
|
|
5091
|
+
zoomSpeed: config.zoomSpeed,
|
|
5092
|
+
noTheme: themeFile() == null,
|
|
5093
|
+
setup: setupPending,
|
|
5094
|
+
projectName: config.share.name || basename(root),
|
|
5095
|
+
branding: config.share.branding,
|
|
5096
|
+
jam: config.jam ? {
|
|
5097
|
+
chime: config.jam.chime,
|
|
5098
|
+
capture: config.jam.capture,
|
|
5099
|
+
names: config.jam.names && config.jam.agent === "claude"
|
|
5100
|
+
} : null,
|
|
5101
|
+
workspace: ws,
|
|
5102
|
+
version: installedVersion() ?? "0.0.0"
|
|
5103
|
+
})}`;
|
|
5104
|
+
}
|
|
5105
|
+
if (id === "\0virtual:sh-data") return "export default null";
|
|
5106
|
+
},
|
|
5107
|
+
/** HTML frames: inject theme + bridge into any design/**.html Vite serves.
|
|
5108
|
+
* Inline scripts go through vite's html-proxy import-analysis: bare specifiers resolve
|
|
5109
|
+
* through plugins (so `virtual:sh-theme` works); `/@id/` URLs are rejected there. */
|
|
5110
|
+
transformIndexHtml: {
|
|
5111
|
+
order: "pre",
|
|
5112
|
+
handler(html, hctx) {
|
|
5113
|
+
const path = (hctx.originalUrl ?? hctx.path ?? "").split("?")[0];
|
|
5114
|
+
if (!path.startsWith("/design/")) return;
|
|
5115
|
+
const bridge = "/@fs/" + join(clientDir, "frame-host", "bridge.js").split("\\").join("/") + "?html=1";
|
|
5116
|
+
const frame = manifest.frames.find((f) => "/" + f.file === path);
|
|
5117
|
+
const stamp = frame ? docRev(root, manifest.frames, frame.id) : "";
|
|
5118
|
+
return {
|
|
5119
|
+
html,
|
|
5120
|
+
tags: [
|
|
5121
|
+
{
|
|
5122
|
+
tag: "script",
|
|
5123
|
+
attrs: { type: "module" },
|
|
5124
|
+
children: `import '${VIRTUAL_THEME}'`,
|
|
5125
|
+
injectTo: "head-prepend"
|
|
4778
5126
|
},
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
5127
|
+
{
|
|
5128
|
+
tag: "script",
|
|
5129
|
+
attrs: {
|
|
5130
|
+
type: "module",
|
|
5131
|
+
src: bridge
|
|
5132
|
+
},
|
|
5133
|
+
injectTo: "head-prepend"
|
|
4786
5134
|
},
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
5135
|
+
...stamp ? [{
|
|
5136
|
+
tag: "meta",
|
|
5137
|
+
attrs: {
|
|
5138
|
+
name: "mv-doc",
|
|
5139
|
+
content: stamp
|
|
5140
|
+
},
|
|
5141
|
+
injectTo: "head-prepend"
|
|
5142
|
+
}] : []
|
|
5143
|
+
]
|
|
5144
|
+
};
|
|
5145
|
+
}
|
|
5146
|
+
},
|
|
5147
|
+
configureServer(server) {
|
|
5148
|
+
const closers = [];
|
|
5149
|
+
const onClose = (fn) => {
|
|
5150
|
+
closers.push(fn);
|
|
4790
5151
|
};
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
withdraw?.();
|
|
4806
|
-
closeAll();
|
|
4807
|
-
});
|
|
4808
|
-
if (served++) {
|
|
4809
|
-
manifest = scanFrames(root, projectInfo());
|
|
4810
|
-
observeLater();
|
|
4811
|
-
runs.restarted();
|
|
4812
|
-
}
|
|
4813
|
-
server.middlewares.use(guardMiddleware(ws));
|
|
4814
|
-
server.middlewares.use(perfRunBarrier());
|
|
4815
|
-
const hub = ctx.proof ? createLiveHub({
|
|
4816
|
-
instance: ctx.proof.instance,
|
|
4817
|
-
read: () => liveSnapshot(live.read(manifest.frames)),
|
|
4818
|
-
on: (fn) => workActivity.onChange(fn)
|
|
4819
|
-
}) : null;
|
|
4820
|
-
if (hub) onClose(() => hub.close());
|
|
4821
|
-
server.middlewares.use(liveRoute(hub, ctx.proof));
|
|
4822
|
-
const viteWatcher = server.watcher;
|
|
4823
|
-
watching.server = server;
|
|
4824
|
-
watching.watcher = viteWatcher;
|
|
4825
|
-
watching.ready = viteWatcher._readyEmitted === true;
|
|
4826
|
-
viteWatcher.once("ready", () => {
|
|
4827
|
-
if (watching.watcher !== viteWatcher) return;
|
|
4828
|
-
watching.ready = true;
|
|
4829
|
-
for (const w of watching.waiters) w();
|
|
4830
|
-
watching.waiters.clear();
|
|
4831
|
-
});
|
|
4832
|
-
viteWatcher.on("all", (_event, file) => runs.changed(file));
|
|
4833
|
-
let bakeGen = Date.now();
|
|
4834
|
-
server.middlewares.use((req, res, next) => {
|
|
4835
|
-
if (req.url && req.url.includes("/frame-host/registry.ts")) {
|
|
4836
|
-
const orig = res.setHeader.bind(res);
|
|
4837
|
-
res.setHeader = ((name, value) => orig(name, String(name).toLowerCase() === "cache-control" ? "no-cache" : value));
|
|
5152
|
+
const closeAll = () => {
|
|
5153
|
+
for (const fn of closers.splice(0).reverse()) try {
|
|
5154
|
+
fn();
|
|
5155
|
+
} catch {}
|
|
5156
|
+
};
|
|
5157
|
+
const withdraw = ctx.startup?.defer(closeAll, server);
|
|
5158
|
+
server.httpServer?.once("close", () => {
|
|
5159
|
+
withdraw?.();
|
|
5160
|
+
closeAll();
|
|
5161
|
+
});
|
|
5162
|
+
if (served++) {
|
|
5163
|
+
manifest = scanFrames(root, projectInfo());
|
|
5164
|
+
observeLater();
|
|
5165
|
+
runs.restarted();
|
|
4838
5166
|
}
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
if (
|
|
5167
|
+
server.middlewares.use(guardMiddleware(ws));
|
|
5168
|
+
server.middlewares.use(perfRunBarrier());
|
|
5169
|
+
const hub = ctx.proof ? createLiveHub({
|
|
5170
|
+
instance: ctx.proof.instance,
|
|
5171
|
+
read: () => liveSnapshot(live.read(manifest.frames)),
|
|
5172
|
+
on: (fn) => workActivity.onChange(fn)
|
|
5173
|
+
}) : null;
|
|
5174
|
+
if (hub) onClose(() => hub.close());
|
|
5175
|
+
server.middlewares.use(liveRoute(hub, ctx.proof));
|
|
5176
|
+
const viteWatcher = server.watcher;
|
|
5177
|
+
watching.server = server;
|
|
5178
|
+
watching.watcher = viteWatcher;
|
|
5179
|
+
watching.ready = viteWatcher._readyEmitted === true;
|
|
5180
|
+
viteWatcher.once("ready", () => {
|
|
5181
|
+
if (watching.watcher !== viteWatcher) return;
|
|
5182
|
+
watching.ready = true;
|
|
5183
|
+
for (const w of watching.waiters) w();
|
|
5184
|
+
watching.waiters.clear();
|
|
5185
|
+
});
|
|
5186
|
+
viteWatcher.on("all", (_event, file) => runs.changed(file));
|
|
5187
|
+
let bakeGen = Date.now();
|
|
5188
|
+
server.middlewares.use((req, res, next) => {
|
|
5189
|
+
if (req.url && req.url.includes("/frame-host/registry.ts")) {
|
|
5190
|
+
const orig = res.setHeader.bind(res);
|
|
5191
|
+
res.setHeader = ((name, value) => orig(name, String(name).toLowerCase() === "cache-control" ? "no-cache" : value));
|
|
5192
|
+
}
|
|
5193
|
+
next();
|
|
5194
|
+
});
|
|
5195
|
+
const update = checkUpdate(root).catch(() => null);
|
|
4847
5196
|
update.then((latest) => {
|
|
4848
|
-
|
|
4849
|
-
res.setHeader("cache-control", "no-store");
|
|
4850
|
-
res.end(JSON.stringify({
|
|
4851
|
-
latest,
|
|
4852
|
-
current: installedVersion()
|
|
4853
|
-
}));
|
|
5197
|
+
if (latest) console.log(`\n update: ${PKG} ${latest} is out (installed ${installedVersion() ?? "?"}) → npm i -D ${PKG}@latest && npx ${NAME} init\n`);
|
|
4854
5198
|
});
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
const
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
const
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
liveChanged();
|
|
4902
|
-
} else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
|
|
4903
|
-
framesKey = key;
|
|
4904
|
-
scenesKey = sKey;
|
|
4905
|
-
}, 150);
|
|
4906
|
-
onClose(regen.cancel);
|
|
4907
|
-
const watched = [join(root, "design", "scenes"), join(root, "design", "components")];
|
|
4908
|
-
const inScope = (file) => watched.some((w) => file.startsWith(w));
|
|
4909
|
-
const themeModules = () => {
|
|
4910
|
-
const f = themeFile();
|
|
4911
|
-
if (!f) return [];
|
|
4912
|
-
const out = [];
|
|
4913
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4914
|
-
const walk = (mod) => {
|
|
4915
|
-
if (!mod || seen.has(mod)) return;
|
|
4916
|
-
seen.add(mod);
|
|
4917
|
-
out.push(mod);
|
|
4918
|
-
for (const im of mod.clientImportedModules ?? mod.importedModules ?? []) if (String(im.id ?? "").split("?")[0].endsWith(".css")) walk(im);
|
|
5199
|
+
server.middlewares.use((req, res, next) => {
|
|
5200
|
+
if (new URL(req.url ?? "/", "http://x").pathname !== `/__mv/api/update`) return next();
|
|
5201
|
+
update.then((latest) => {
|
|
5202
|
+
res.setHeader("content-type", "application/json");
|
|
5203
|
+
res.setHeader("cache-control", "no-store");
|
|
5204
|
+
res.end(JSON.stringify({
|
|
5205
|
+
latest,
|
|
5206
|
+
current: installedVersion()
|
|
5207
|
+
}));
|
|
5208
|
+
});
|
|
5209
|
+
});
|
|
5210
|
+
const listeningOrigin = () => originOf(server.httpServer?.address());
|
|
5211
|
+
initMarks(root, manifest.frames);
|
|
5212
|
+
tidyPerfDir(root);
|
|
5213
|
+
server.middlewares.use(apiMiddleware(root, {
|
|
5214
|
+
viewports: config.viewports,
|
|
5215
|
+
origin: listeningOrigin,
|
|
5216
|
+
bakeGen: () => bakeGen,
|
|
5217
|
+
notify: (event) => {
|
|
5218
|
+
server.ws.send(event, {});
|
|
5219
|
+
liveChanged();
|
|
5220
|
+
},
|
|
5221
|
+
manifest: () => manifest,
|
|
5222
|
+
settled,
|
|
5223
|
+
workspace: ws,
|
|
5224
|
+
inputs
|
|
5225
|
+
}));
|
|
5226
|
+
server.middlewares.use(logoRoute(root, () => config.share.logo, ctx.proof));
|
|
5227
|
+
server.middlewares.use(routesMiddleware(server, clientDir, {
|
|
5228
|
+
doc: (id) => docRev(root, manifest.frames, id),
|
|
5229
|
+
docs: () => docRevs(root, manifest.frames)
|
|
5230
|
+
}, ctx.proof));
|
|
5231
|
+
const before = devServer;
|
|
5232
|
+
devServer = server;
|
|
5233
|
+
onClose(() => {
|
|
5234
|
+
if (devServer === server) devServer = before;
|
|
5235
|
+
});
|
|
5236
|
+
guardUpdates(server, root, () => manifest, hooks, changes);
|
|
5237
|
+
let framesKey = JSON.stringify(manifest.frames);
|
|
5238
|
+
let scenesKey = JSON.stringify(manifest.scenes);
|
|
5239
|
+
let unplacedKey = "";
|
|
5240
|
+
const sayUnplaced = () => {
|
|
5241
|
+
const { unplaced } = readMembership(root, manifest.frames.map((f) => f.id));
|
|
5242
|
+
const key = unplaced.join(",");
|
|
5243
|
+
if (key && key !== unplacedKey) console.log(`[${NAME}] not on a board (${unplaced.length}): ${unplaced.join(", ")} - every frame goes on the board it belongs to: npx ${NAME} boards pin <board> <scene/frame ...>`);
|
|
5244
|
+
unplacedKey = key;
|
|
4919
5245
|
};
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
if (f.startsWith(localDir) || f.startsWith(boardsDirGen) || f === manifestPath || f.includes("/node_modules/")) return;
|
|
4934
|
-
bakeGen++;
|
|
4935
|
-
prune();
|
|
4936
|
-
};
|
|
4937
|
-
const pruning = /* @__PURE__ */ new Set();
|
|
4938
|
-
const prune = () => {
|
|
4939
|
-
const t = setTimeout(async () => {
|
|
4940
|
-
pruning.delete(t);
|
|
4941
|
-
try {
|
|
4942
|
-
(await Promise.resolve().then(() => bake_exports)).pruneBakes(root, bakeGen);
|
|
4943
|
-
} catch {}
|
|
4944
|
-
}, 500);
|
|
4945
|
-
pruning.add(t);
|
|
4946
|
-
};
|
|
4947
|
-
onClose(() => {
|
|
4948
|
-
for (const t of pruning) clearTimeout(t);
|
|
4949
|
-
});
|
|
4950
|
-
prune();
|
|
4951
|
-
server.watcher.on("add", bumpGen);
|
|
4952
|
-
server.watcher.on("unlink", bumpGen);
|
|
4953
|
-
server.watcher.on("change", bumpGen);
|
|
4954
|
-
server.watcher.on("add", (f) => {
|
|
4955
|
-
if (inScope(f)) {
|
|
4956
|
-
regen();
|
|
4957
|
-
rescanTheme();
|
|
4958
|
-
}
|
|
4959
|
-
});
|
|
4960
|
-
server.watcher.on("unlink", (f) => {
|
|
4961
|
-
if (inScope(f)) {
|
|
4962
|
-
regen();
|
|
4963
|
-
rescanTheme();
|
|
4964
|
-
}
|
|
4965
|
-
});
|
|
4966
|
-
const contextDir = join(root, "context") + sep;
|
|
4967
|
-
let statusTimer;
|
|
4968
|
-
onClose(() => clearTimeout(statusTimer));
|
|
4969
|
-
const restatus = (f) => {
|
|
4970
|
-
if (!f.startsWith(contextDir) && !(inScope(f) && f.endsWith("_brief.md"))) return;
|
|
4971
|
-
clearTimeout(statusTimer);
|
|
4972
|
-
statusTimer = setTimeout(() => {
|
|
4973
|
-
server.ws.send("sh:boards", {});
|
|
4974
|
-
regen();
|
|
5246
|
+
sayUnplaced();
|
|
5247
|
+
const regen = debounce(() => {
|
|
5248
|
+
manifest = scanFrames(root, projectInfo());
|
|
5249
|
+
sayUnplaced();
|
|
5250
|
+
const changed = writeManifest(root, manifest);
|
|
5251
|
+
observeLater();
|
|
5252
|
+
const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
|
|
5253
|
+
if (changed && key !== framesKey) {
|
|
5254
|
+
server.ws.send("sh:manifest", manifest);
|
|
5255
|
+
liveChanged();
|
|
5256
|
+
} else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
|
|
5257
|
+
framesKey = key;
|
|
5258
|
+
scenesKey = sKey;
|
|
4975
5259
|
}, 150);
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
});
|
|
4990
|
-
const configFile = join(root, "design", "config.ts");
|
|
4991
|
-
server.watcher.on("change", (f) => {
|
|
4992
|
-
if (f !== configFile) return;
|
|
4993
|
-
loadConfig(root).then((c) => {
|
|
4994
|
-
project = {
|
|
4995
|
-
name: c.share.name || basename(root),
|
|
4996
|
-
description: c.description
|
|
5260
|
+
onClose(regen.cancel);
|
|
5261
|
+
const watched = [join(root, "design", "scenes"), join(root, "design", "components")];
|
|
5262
|
+
const inScope = (file) => watched.some((w) => file.startsWith(w));
|
|
5263
|
+
const themeModules = () => {
|
|
5264
|
+
const f = themeFile();
|
|
5265
|
+
if (!f) return [];
|
|
5266
|
+
const out = [];
|
|
5267
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5268
|
+
const walk = (mod) => {
|
|
5269
|
+
if (!mod || seen.has(mod)) return;
|
|
5270
|
+
seen.add(mod);
|
|
5271
|
+
out.push(mod);
|
|
5272
|
+
for (const im of mod.clientImportedModules ?? mod.importedModules ?? []) if (String(im.id ?? "").split("?")[0].endsWith(".css")) walk(im);
|
|
4997
5273
|
};
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
});
|
|
5001
|
-
writeManifest(root, manifest);
|
|
5002
|
-
const boardsDir = join(root, "design", "boards");
|
|
5003
|
-
try {
|
|
5004
|
-
mkdirSync(boardsDir, { recursive: true });
|
|
5005
|
-
const timers = /* @__PURE__ */ new Map();
|
|
5006
|
-
const badBoards = /* @__PURE__ */ new Map();
|
|
5007
|
-
const reportBad = (file, content, error) => {
|
|
5008
|
-
if (badBoards.get(file) === hash(content)) return;
|
|
5009
|
-
badBoards.set(file, hash(content));
|
|
5010
|
-
console.warn(`[marver] design/boards/${file} is not valid JSON - ${error}`);
|
|
5274
|
+
for (const mod of server.moduleGraph.getModulesByFile(f) ?? []) walk(mod);
|
|
5275
|
+
return out;
|
|
5011
5276
|
};
|
|
5012
|
-
|
|
5013
|
-
for (const
|
|
5014
|
-
}
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5277
|
+
const pushTheme = debounce(() => {
|
|
5278
|
+
for (const mod of themeModules()) server.reloadModule(mod).catch(() => {});
|
|
5279
|
+
}, 150);
|
|
5280
|
+
onClose(pushTheme.cancel);
|
|
5281
|
+
const rescanTheme = () => {
|
|
5282
|
+
for (const mod of themeModules()) server.moduleGraph.invalidateModule(mod);
|
|
5283
|
+
pushTheme();
|
|
5284
|
+
};
|
|
5285
|
+
const localDir = join(root, "design", ".local"), boardsDirGen = join(root, "design", "boards"), manifestPath = join(root, "design", "manifest.json");
|
|
5286
|
+
const bumpGen = (f) => {
|
|
5287
|
+
if (f.startsWith(localDir) || f.startsWith(boardsDirGen) || f === manifestPath || f.includes("/node_modules/")) return;
|
|
5288
|
+
bakeGen++;
|
|
5289
|
+
prune();
|
|
5290
|
+
};
|
|
5291
|
+
const pruning = /* @__PURE__ */ new Set();
|
|
5292
|
+
const prune = () => {
|
|
5293
|
+
const t = setTimeout(async () => {
|
|
5294
|
+
pruning.delete(t);
|
|
5295
|
+
try {
|
|
5296
|
+
(await Promise.resolve().then(() => bake_exports)).pruneBakes(root, bakeGen);
|
|
5297
|
+
} catch {}
|
|
5298
|
+
}, 500);
|
|
5299
|
+
pruning.add(t);
|
|
5300
|
+
};
|
|
5301
|
+
onClose(() => {
|
|
5302
|
+
for (const t of pruning) clearTimeout(t);
|
|
5303
|
+
});
|
|
5304
|
+
prune();
|
|
5305
|
+
server.watcher.on("add", bumpGen);
|
|
5306
|
+
server.watcher.on("unlink", bumpGen);
|
|
5307
|
+
server.watcher.on("change", bumpGen);
|
|
5308
|
+
server.watcher.on("add", (f) => {
|
|
5309
|
+
if (inScope(f)) {
|
|
5310
|
+
regen();
|
|
5311
|
+
rescanTheme();
|
|
5312
|
+
}
|
|
5313
|
+
});
|
|
5314
|
+
server.watcher.on("unlink", (f) => {
|
|
5315
|
+
if (inScope(f)) {
|
|
5316
|
+
regen();
|
|
5317
|
+
rescanTheme();
|
|
5318
|
+
}
|
|
5319
|
+
});
|
|
5320
|
+
const contextDir = join(root, "context") + sep;
|
|
5321
|
+
let statusTimer;
|
|
5322
|
+
onClose(() => clearTimeout(statusTimer));
|
|
5323
|
+
const restatus = (f) => {
|
|
5324
|
+
if (!f.startsWith(contextDir) && !(inScope(f) && f.endsWith("_brief.md"))) return;
|
|
5325
|
+
clearTimeout(statusTimer);
|
|
5326
|
+
statusTimer = setTimeout(() => {
|
|
5022
5327
|
server.ws.send("sh:boards", {});
|
|
5023
5328
|
regen();
|
|
5024
|
-
boardsChanged(root);
|
|
5025
5329
|
}, 150);
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
return;
|
|
5040
|
-
}
|
|
5041
|
-
badBoards.delete(file);
|
|
5042
|
-
server.ws.send("sh:board", {
|
|
5043
|
-
name: file.replace(/\.json$/, ""),
|
|
5044
|
-
sha256: hash(content)
|
|
5045
|
-
});
|
|
5046
|
-
}, 120));
|
|
5047
|
-
}));
|
|
5048
|
-
onClose(() => {
|
|
5049
|
-
watcher.close();
|
|
5050
|
-
clearTimeout(listTimer);
|
|
5051
|
-
for (const t of timers.values()) clearTimeout(t);
|
|
5330
|
+
};
|
|
5331
|
+
server.watcher.on("add", restatus);
|
|
5332
|
+
server.watcher.on("unlink", restatus);
|
|
5333
|
+
server.watcher.on("change", restatus);
|
|
5334
|
+
server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
|
|
5335
|
+
const marksChanged = debounce(observeLater, 300);
|
|
5336
|
+
onClose(marksChanged.cancel);
|
|
5337
|
+
for (const ev of [
|
|
5338
|
+
"add",
|
|
5339
|
+
"change",
|
|
5340
|
+
"unlink"
|
|
5341
|
+
]) server.watcher.on(ev, (f) => {
|
|
5342
|
+
if (!f.startsWith(localDir) && !f.startsWith(boardsDirGen)) marksChanged();
|
|
5052
5343
|
});
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
}
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
};
|
|
5086
|
-
|
|
5344
|
+
const configFile = join(root, "design", "config.ts");
|
|
5345
|
+
server.watcher.on("change", (f) => {
|
|
5346
|
+
if (f !== configFile) return;
|
|
5347
|
+
loadConfig(root).then((c) => {
|
|
5348
|
+
project = {
|
|
5349
|
+
name: c.share.name || basename(root),
|
|
5350
|
+
description: c.description
|
|
5351
|
+
};
|
|
5352
|
+
regen();
|
|
5353
|
+
}).catch(() => {});
|
|
5354
|
+
});
|
|
5355
|
+
writeManifest(root, manifest);
|
|
5356
|
+
const boardsDir = join(root, "design", "boards");
|
|
5357
|
+
try {
|
|
5358
|
+
mkdirSync(boardsDir, { recursive: true });
|
|
5359
|
+
const timers = /* @__PURE__ */ new Map();
|
|
5360
|
+
const badBoards = /* @__PURE__ */ new Map();
|
|
5361
|
+
const reportBad = (file, content, error) => {
|
|
5362
|
+
if (badBoards.get(file) === hash(content)) return;
|
|
5363
|
+
badBoards.set(file, hash(content));
|
|
5364
|
+
console.warn(`[marver] design/boards/${file} is not valid JSON - ${error}`);
|
|
5365
|
+
};
|
|
5366
|
+
if (!checkBoardsDir(root, boardsDir)) {
|
|
5367
|
+
for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
|
|
5368
|
+
}
|
|
5369
|
+
if (nodeExists(join(boardsDir, `all-scenes.json`))) console.log(`[${NAME}] design/boards/${ALL_SCENES}.json is left over from the All Scenes board, gone since 0.25 - nothing reads it any more; delete it when you like (its threads stay in design/comments/)`);
|
|
5370
|
+
let listTimer;
|
|
5371
|
+
const watcher = guarded(watch(boardsDir, (_event, file) => {
|
|
5372
|
+
if (file?.endsWith(".json")) runs.changed(join(boardsDir, file));
|
|
5373
|
+
if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
|
|
5374
|
+
clearTimeout(listTimer);
|
|
5375
|
+
listTimer = setTimeout(() => {
|
|
5376
|
+
server.ws.send("sh:boards", {});
|
|
5377
|
+
regen();
|
|
5378
|
+
boardsChanged(root);
|
|
5379
|
+
}, 150);
|
|
5380
|
+
clearTimeout(timers.get(file));
|
|
5381
|
+
timers.set(file, setTimeout(() => {
|
|
5382
|
+
timers.delete(file);
|
|
5383
|
+
let content;
|
|
5384
|
+
if (!isRegularFile(join(boardsDir, file))) return;
|
|
5087
5385
|
try {
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
} catch (err) {
|
|
5091
|
-
write({
|
|
5092
|
-
ok: false,
|
|
5093
|
-
error: `malformed request - ${err.message}`
|
|
5094
|
-
});
|
|
5095
|
-
return;
|
|
5096
|
-
}
|
|
5097
|
-
const theme = spec.theme === void 0 ? "light" : spec.theme;
|
|
5098
|
-
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) {
|
|
5099
|
-
write({
|
|
5100
|
-
ok: false,
|
|
5101
|
-
error: "invalid theme"
|
|
5102
|
-
});
|
|
5103
|
-
return;
|
|
5104
|
-
}
|
|
5105
|
-
const scale = spec.scale === void 0 ? void 0 : spec.scale;
|
|
5106
|
-
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) {
|
|
5107
|
-
write({
|
|
5108
|
-
ok: false,
|
|
5109
|
-
error: "invalid scale"
|
|
5110
|
-
});
|
|
5386
|
+
content = readFileSync(join(boardsDir, file), "utf8");
|
|
5387
|
+
} catch {
|
|
5111
5388
|
return;
|
|
5112
5389
|
}
|
|
5113
|
-
const
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
"scene",
|
|
5117
|
-
"all"
|
|
5118
|
-
].filter((k) => spec[k] !== void 0);
|
|
5119
|
-
if (ways.length !== 1) {
|
|
5120
|
-
write({
|
|
5121
|
-
ok: false,
|
|
5122
|
-
error: "name the frames one way: frame (an id), frames (an array of ids), scene (a name) or all (true)"
|
|
5123
|
-
});
|
|
5390
|
+
const { error } = parseBoard(content);
|
|
5391
|
+
if (error) {
|
|
5392
|
+
if (!checkBoardsDir(root, boardsDir)) reportBad(file, content, error);
|
|
5124
5393
|
return;
|
|
5125
5394
|
}
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5395
|
+
badBoards.delete(file);
|
|
5396
|
+
const name = file.replace(/\.json$/, ""), sha256 = hash(content);
|
|
5397
|
+
server.ws.send("sh:board", {
|
|
5398
|
+
name,
|
|
5399
|
+
sha256,
|
|
5400
|
+
...writerOf(root, name, sha256)
|
|
5401
|
+
});
|
|
5402
|
+
}, 120));
|
|
5403
|
+
}));
|
|
5404
|
+
onClose(() => {
|
|
5405
|
+
watcher.close();
|
|
5406
|
+
clearTimeout(listTimer);
|
|
5407
|
+
for (const t of timers.values()) clearTimeout(t);
|
|
5408
|
+
});
|
|
5409
|
+
} catch {}
|
|
5410
|
+
try {
|
|
5411
|
+
const inbox = join(root, "design", ".local", "shots");
|
|
5412
|
+
mkdirSync(inbox, { recursive: true });
|
|
5413
|
+
const origin = listeningOrigin;
|
|
5414
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
5415
|
+
const processRequest = (file) => {
|
|
5416
|
+
if (!file.endsWith(".request.json") || inFlight.has(file)) return;
|
|
5417
|
+
const reqPath = join(inbox, file);
|
|
5418
|
+
if (!existsSync(reqPath)) return;
|
|
5419
|
+
inFlight.add(file);
|
|
5420
|
+
setTimeout(async () => {
|
|
5421
|
+
const base = file.replace(/\.request\.json$/, "");
|
|
5422
|
+
const resultPath = join(inbox, `${base}.result.json`);
|
|
5423
|
+
const claimed = join(inbox, `.${base}.${process.pid}.${Date.now().toString(36)}.claimed`);
|
|
5424
|
+
try {
|
|
5425
|
+
renameSync(reqPath, claimed);
|
|
5426
|
+
} catch {
|
|
5427
|
+
inFlight.delete(file);
|
|
5132
5428
|
return;
|
|
5133
5429
|
}
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5430
|
+
try {
|
|
5431
|
+
const write = (r) => {
|
|
5432
|
+
const tmp = join(inbox, `.${base}.${process.pid}.tmp`);
|
|
5433
|
+
try {
|
|
5434
|
+
writeFileSync(tmp, JSON.stringify(r, null, 2));
|
|
5435
|
+
renameSync(tmp, resultPath);
|
|
5436
|
+
} catch {
|
|
5437
|
+
try {
|
|
5438
|
+
rmSync(tmp, { force: true });
|
|
5439
|
+
} catch {}
|
|
5440
|
+
}
|
|
5441
|
+
};
|
|
5442
|
+
let spec;
|
|
5443
|
+
try {
|
|
5444
|
+
spec = JSON.parse(readFileSync(claimed, "utf8"));
|
|
5445
|
+
if (!spec || typeof spec !== "object" || Array.isArray(spec)) throw new Error("expected an object");
|
|
5446
|
+
} catch (err) {
|
|
5137
5447
|
write({
|
|
5138
5448
|
ok: false,
|
|
5139
|
-
error:
|
|
5449
|
+
error: `malformed request - ${err.message}`
|
|
5140
5450
|
});
|
|
5141
5451
|
return;
|
|
5142
5452
|
}
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
}
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
}
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5453
|
+
const theme = spec.theme === void 0 ? "light" : spec.theme;
|
|
5454
|
+
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) {
|
|
5455
|
+
write({
|
|
5456
|
+
ok: false,
|
|
5457
|
+
error: "invalid theme"
|
|
5458
|
+
});
|
|
5459
|
+
return;
|
|
5460
|
+
}
|
|
5461
|
+
const scale = spec.scale === void 0 ? void 0 : spec.scale;
|
|
5462
|
+
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) {
|
|
5463
|
+
write({
|
|
5464
|
+
ok: false,
|
|
5465
|
+
error: "invalid scale"
|
|
5466
|
+
});
|
|
5467
|
+
return;
|
|
5468
|
+
}
|
|
5469
|
+
const ways = [
|
|
5470
|
+
"frame",
|
|
5471
|
+
"frames",
|
|
5472
|
+
"scene",
|
|
5473
|
+
"all"
|
|
5474
|
+
].filter((k) => spec[k] !== void 0);
|
|
5475
|
+
if (ways.length !== 1) {
|
|
5476
|
+
write({
|
|
5477
|
+
ok: false,
|
|
5478
|
+
error: "name the frames one way: frame (an id), frames (an array of ids), scene (a name) or all (true)"
|
|
5479
|
+
});
|
|
5480
|
+
return;
|
|
5481
|
+
}
|
|
5482
|
+
const o = origin();
|
|
5483
|
+
if (!o) {
|
|
5484
|
+
write({
|
|
5485
|
+
ok: false,
|
|
5486
|
+
error: "dev server has no address yet - retry"
|
|
5487
|
+
});
|
|
5488
|
+
return;
|
|
5489
|
+
}
|
|
5490
|
+
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
5491
|
+
if (ways[0] === "frame") {
|
|
5492
|
+
if (typeof spec.frame !== "string") {
|
|
5493
|
+
write({
|
|
5494
|
+
ok: false,
|
|
5495
|
+
error: "frame must be a frame id"
|
|
5496
|
+
});
|
|
5497
|
+
return;
|
|
5498
|
+
}
|
|
5499
|
+
write(await shootFrame({
|
|
5165
5500
|
root,
|
|
5166
5501
|
viewports: config.viewports,
|
|
5167
|
-
|
|
5502
|
+
frameId: spec.frame,
|
|
5168
5503
|
theme,
|
|
5169
5504
|
origin: o,
|
|
5170
5505
|
scale
|
|
5171
|
-
})
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5506
|
+
}));
|
|
5507
|
+
return;
|
|
5508
|
+
}
|
|
5509
|
+
const sel = resolveFrames(root, spec);
|
|
5510
|
+
if (!sel.ok) {
|
|
5511
|
+
write({
|
|
5512
|
+
ok: false,
|
|
5513
|
+
error: sel.error
|
|
5514
|
+
});
|
|
5515
|
+
return;
|
|
5516
|
+
}
|
|
5517
|
+
try {
|
|
5518
|
+
write({
|
|
5519
|
+
ok: true,
|
|
5520
|
+
results: await shootBatch({
|
|
5521
|
+
root,
|
|
5522
|
+
viewports: config.viewports,
|
|
5523
|
+
frames: sel.frames,
|
|
5524
|
+
theme,
|
|
5525
|
+
origin: o,
|
|
5526
|
+
scale
|
|
5527
|
+
})
|
|
5528
|
+
});
|
|
5529
|
+
} catch (err) {
|
|
5530
|
+
write({
|
|
5531
|
+
ok: false,
|
|
5532
|
+
error: err.message
|
|
5533
|
+
});
|
|
5534
|
+
}
|
|
5535
|
+
} finally {
|
|
5536
|
+
try {
|
|
5537
|
+
rmSync(claimed, { force: true });
|
|
5538
|
+
} catch {}
|
|
5539
|
+
inFlight.delete(file);
|
|
5178
5540
|
}
|
|
5179
|
-
}
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
}
|
|
5194
|
-
}
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
} catch {}
|
|
5201
|
-
}
|
|
5202
|
-
}, updatesPlugin(root, () => manifest, () => devServer && hooks, landed)];
|
|
5541
|
+
}, 60);
|
|
5542
|
+
};
|
|
5543
|
+
const inboxWatcher = guarded(watch(inbox, { persistent: false }, (_e, file) => {
|
|
5544
|
+
if (file) processRequest(file);
|
|
5545
|
+
}));
|
|
5546
|
+
const sweep = setInterval(() => {
|
|
5547
|
+
try {
|
|
5548
|
+
for (const f of readdirSync(inbox)) processRequest(f);
|
|
5549
|
+
} catch {}
|
|
5550
|
+
}, 1e3);
|
|
5551
|
+
sweep.unref?.();
|
|
5552
|
+
onClose(() => {
|
|
5553
|
+
inboxWatcher.close();
|
|
5554
|
+
clearInterval(sweep);
|
|
5555
|
+
});
|
|
5556
|
+
} catch {}
|
|
5557
|
+
}
|
|
5558
|
+
},
|
|
5559
|
+
updatesBeginPlugin(changes),
|
|
5560
|
+
updatesPlugin(root, () => manifest, () => devServer && hooks, landed, changes)
|
|
5561
|
+
];
|
|
5203
5562
|
}
|
|
5204
5563
|
/**
|
|
5205
5564
|
* The live stream's four adapters (spec 28 A4.6 #7), the hub's `read()`: every board's comment log replayed - cached by
|