@marver-design/marver 0.29.0 → 0.30.1
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 +60 -0
- package/README.md +2 -1
- package/dist/{anchor-check-DhlpKl2K.mjs → anchor-check-Bv4o-R2T.mjs} +1 -1
- package/dist/{build-CWbrb2bl.mjs → build-zWGXSzly.mjs} +5 -4
- package/dist/cli.mjs +5 -5
- package/dist/{daemon-Sc_z8gT6.mjs → daemon-CChgWJNq.mjs} +2 -2
- package/dist/{dev-DWBKQhxf.mjs → dev-DOgIITpT.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-CFWBcAba.mjs} +928 -539
- package/dist/{poster-CrsjqhY4.mjs → poster-DPPpQiva.mjs} +1 -1
- package/dist/{publish-bakes-DW-NDgU2.mjs → publish-bakes-_Zx8crP3.mjs} +2 -2
- package/dist/{recover-GtJ9UDAB.mjs → recover-mDUVsnPd.mjs} +1 -1
- package/dist/{shot-T04Ixrvq.mjs → shot-d4h_hJi9.mjs} +3 -3
- package/docs/app.md +194 -0
- package/docs/performance.md +100 -19
- 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 +118 -43
- package/src/client/shell/store.ts +112 -32
- 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-d4h_hJi9.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";
|
|
@@ -21,6 +21,7 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
21
21
|
import { arch, cpus, totalmem } from "node:os";
|
|
22
22
|
import { execFile } from "node:child_process";
|
|
23
23
|
import { stat } from "node:fs/promises";
|
|
24
|
+
import { isCSSRequest } from "vite";
|
|
24
25
|
//#region src/shared/frames.ts
|
|
25
26
|
/** A canvas made of content frames alone (Doc, Md, Diagram ship their own styling) needs no theme -
|
|
26
27
|
* only an app frame does (#4). Empty counts as not content-only: the warning still helps there. */
|
|
@@ -43,8 +44,12 @@ const contentOnly = (frames) => frames.length > 0 && frames.every((f) => !!f.int
|
|
|
43
44
|
* has been applied in place: the frames past it are touched (marked) but not reloaded.
|
|
44
45
|
*
|
|
45
46
|
* Every other `full-reload` Vite or Tailwind sends is dropped and becomes reloads of the frames it
|
|
46
|
-
* names
|
|
47
|
-
*
|
|
47
|
+
* names - the shell never reloads for a design edit. One that names nothing, sent while a file no
|
|
48
|
+
* document imports is being handled, is Tailwind's for a file it only scans (a note, app code): the
|
|
49
|
+
* stylesheet is pushed in place and only the frames the marks find changed reload - with the frames of
|
|
50
|
+
* a stylesheet that cannot take its update in place, and every HTML frame. Named nothing
|
|
51
|
+
* otherwise, every frame reloads: the sender is unknown. The one that passes is the dependency
|
|
52
|
+
* optimiser's: module URLs changed, every document must reload.
|
|
48
53
|
*/
|
|
49
54
|
const safeReal = (p) => {
|
|
50
55
|
try {
|
|
@@ -90,47 +95,99 @@ function framesFor(root, manifest, file, modules, skipFirst = false) {
|
|
|
90
95
|
touched: [...touched]
|
|
91
96
|
};
|
|
92
97
|
}
|
|
98
|
+
/** The hook that runs first on every hot update (spec 30 #8): this run takes its file's oldest open token, and its
|
|
99
|
+
* bracket opens. Ordered `pre`, so a plugin's own hook (Tailwind's full-reload) runs inside it. */
|
|
100
|
+
function updatesBeginPlugin(changes) {
|
|
101
|
+
return {
|
|
102
|
+
name: "marver:updates-begin",
|
|
103
|
+
hotUpdate: {
|
|
104
|
+
order: "pre",
|
|
105
|
+
handler(opts) {
|
|
106
|
+
if (this.environment.name === "client") changes.begin(opts.file, opts.timestamp);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
93
111
|
/** The hook that runs last on every hot update of the client environment. */
|
|
94
|
-
function updatesPlugin(root, manifest, hooks, landed) {
|
|
112
|
+
function updatesPlugin(root, manifest, hooks, landed, changes) {
|
|
95
113
|
return {
|
|
96
114
|
name: "marver:updates",
|
|
97
115
|
hotUpdate: {
|
|
98
116
|
order: "post",
|
|
99
117
|
handler(opts) {
|
|
100
118
|
landed(opts.file);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
try {
|
|
120
|
+
if (this.environment.name !== "client") return;
|
|
121
|
+
const h = hooks();
|
|
122
|
+
if (!h) return;
|
|
123
|
+
const t = framesFor(root, manifest(), opts.file, opts.modules);
|
|
124
|
+
if (t.doc.length || t.touched.length) {
|
|
125
|
+
const token = changes.run(opts.file, opts.timestamp);
|
|
126
|
+
h.onFrames(t, "update", token ? { token } : changes.ofFile(opts.file));
|
|
127
|
+
}
|
|
128
|
+
} finally {
|
|
129
|
+
changes.landed(opts.file, opts.timestamp);
|
|
130
|
+
}
|
|
106
131
|
}
|
|
107
132
|
}
|
|
108
133
|
};
|
|
109
134
|
}
|
|
110
|
-
/** Wraps the client's hot channel: the reload guard and refused refreshes.
|
|
111
|
-
|
|
135
|
+
/** Wraps the client's hot channel: the reload guard and refused refreshes. `onStyles`: this server's, for a scanned file no
|
|
136
|
+
* document imports - it names the stylesheets that scan it, any of which may have new classes; no frame needs a reload. */
|
|
137
|
+
function guardUpdates(server, root, manifest, hooks, changes, onStyles) {
|
|
112
138
|
const env = server.environments.client;
|
|
139
|
+
const notImported = (file) => [...env.moduleGraph.getModulesByFile(file) ?? []].every((m) => m.id == null || m.type === "asset");
|
|
140
|
+
const sheetsOf = (files) => {
|
|
141
|
+
const push = /* @__PURE__ */ new Set(), refused = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new Set();
|
|
142
|
+
const up = files.flatMap((f) => [...env.moduleGraph.getModulesByFile(f) ?? []]);
|
|
143
|
+
while (up.length) {
|
|
144
|
+
const m = up.shift();
|
|
145
|
+
if (seen.has(m)) continue;
|
|
146
|
+
seen.add(m);
|
|
147
|
+
for (const by of m.importers) {
|
|
148
|
+
if (!isCSSRequest(by.id ?? by.url)) continue;
|
|
149
|
+
if (by.isSelfAccepting === true && by.file) push.add(by.file);
|
|
150
|
+
else refused.add(by);
|
|
151
|
+
up.push(by);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const reload = /* @__PURE__ */ new Set();
|
|
155
|
+
for (const m of refused) {
|
|
156
|
+
const t = framesFor(root, manifest(), m.file ?? "", [m]);
|
|
157
|
+
for (const id of [...t.doc, ...t.touched]) reload.add(id);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
push: [...push],
|
|
161
|
+
reload
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const htmlFrames = () => manifest().frames.filter((f) => f.kind === "html").map((f) => f.id);
|
|
113
165
|
const wrap = (ch) => {
|
|
114
166
|
const send = ch.send.bind(ch);
|
|
115
167
|
ch.send = (...a) => {
|
|
116
168
|
const p = a[0];
|
|
117
169
|
if (typeof p === "object" && p?.type === "full-reload") {
|
|
118
170
|
const passed = p.path === "*" && !p.triggeredBy;
|
|
171
|
+
const by = passed ? void 0 : p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
172
|
+
const at = passed ? void 0 : by ? changes.ofFile(by) : changes.pathless();
|
|
119
173
|
hooks.onReload({
|
|
120
174
|
triggeredBy: p.triggeredBy,
|
|
121
175
|
path: p.path
|
|
122
|
-
}, passed);
|
|
176
|
+
}, passed, at);
|
|
123
177
|
if (!passed) {
|
|
124
|
-
const by = p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
125
178
|
const mods = by ? env.moduleGraph.getModulesByFile(by) : void 0;
|
|
126
|
-
const
|
|
179
|
+
const scanned = by ? [] : changes.handling().filter(notImported);
|
|
180
|
+
const all = () => manifest().frames.map((f) => f.id);
|
|
181
|
+
const sheets = scanned.length ? sheetsOf(scanned) : null;
|
|
182
|
+
const doc = sheets ? [.../* @__PURE__ */ new Set([...sheets.reload, ...htmlFrames()])] : all();
|
|
127
183
|
const t = by ? framesFor(root, manifest(), by, mods ?? []) : {
|
|
128
184
|
file: "",
|
|
129
|
-
doc
|
|
185
|
+
doc,
|
|
130
186
|
touched: [],
|
|
131
187
|
unattributed: true
|
|
132
188
|
};
|
|
133
|
-
if (
|
|
189
|
+
if (sheets) onStyles(sheets.push);
|
|
190
|
+
if (t.doc.length || t.touched.length || scanned.length) hooks.onFrames(t, "reload", at);
|
|
134
191
|
return;
|
|
135
192
|
}
|
|
136
193
|
}
|
|
@@ -146,10 +203,294 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
146
203
|
if (refused.get(mod.url) === mod.lastHMRTimestamp) return;
|
|
147
204
|
refused.set(mod.url, mod.lastHMRTimestamp);
|
|
148
205
|
const t = framesFor(root, manifest(), mod.file, [mod], true);
|
|
149
|
-
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate");
|
|
206
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate", changes.refused(mod.lastHMRTimestamp));
|
|
150
207
|
});
|
|
151
208
|
}
|
|
152
209
|
//#endregion
|
|
210
|
+
//#region src/server/changes.ts
|
|
211
|
+
/**
|
|
212
|
+
* An edit's identity, from the watcher to the send (spec 30 R1 #8-#12). Every watcher event mints an immutable token;
|
|
213
|
+
* the hot-update run that comes for it takes the file's oldest open token and opens its bracket; whatever that run
|
|
214
|
+
* causes keeps the token in its own closure, so a line deferred past `setTimeout` and `whenSettled` writes the token it
|
|
215
|
+
* was given - never a lookup, and never a guess. What cannot be known says so (R0): a page-wide reload with no path
|
|
216
|
+
* inside one bracket is that change, inside two is `ambiguous`, outside any is `unknown` (#11); a refused refresh has
|
|
217
|
+
* no identity of its own (#8). Lines the dev server writes name no page: a change belongs to every page.
|
|
218
|
+
*
|
|
219
|
+
* Kept apart from plugin.ts so the attribution rules run under test with a fake clock (test/r30-edits-changes.test.ts).
|
|
220
|
+
*/
|
|
221
|
+
/** A list in lines of at most `idsPerLine` (#10, #12): none for an empty one. */
|
|
222
|
+
function chunks(list) {
|
|
223
|
+
const out = [];
|
|
224
|
+
for (let i = 0; i < list.length; i += RELOAD_BOUNDS.idsPerLine) out.push(list.slice(i, i + RELOAD_BOUNDS.idsPerLine));
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
const bounded = (ids) => ({
|
|
228
|
+
ids: ids.slice(0, RELOAD_BOUNDS.candidates),
|
|
229
|
+
n: ids.length
|
|
230
|
+
});
|
|
231
|
+
function createChanges(o) {
|
|
232
|
+
const boot = o.boot ?? randomBytes(4).toString("hex");
|
|
233
|
+
const now = o.now ?? Date.now;
|
|
234
|
+
let n = 0;
|
|
235
|
+
/** each file's open tokens, oldest first: a run takes the oldest whose hooks have not begun */
|
|
236
|
+
const open = /* @__PURE__ */ new Map();
|
|
237
|
+
/** minted, not ended */
|
|
238
|
+
const flying = /* @__PURE__ */ new Set();
|
|
239
|
+
/** its hooks are running now (several files' runs can overlap; Vite awaits one run's hooks in sequence) */
|
|
240
|
+
const brackets = /* @__PURE__ */ new Set();
|
|
241
|
+
/** a run's identity, shared by its environments' hooks: file and timestamp */
|
|
242
|
+
const runs = /* @__PURE__ */ new Map();
|
|
243
|
+
const runKey = (file, ts) => `${ts}|${file}`;
|
|
244
|
+
/** `hmrTs -> change`, the last 512: a refused refresh's candidates (#8) */
|
|
245
|
+
const history = [];
|
|
246
|
+
const rel = (file) => relative(o.root, file).split(sep).join("/");
|
|
247
|
+
const ids = (ts) => [...ts].map((t) => t.change);
|
|
248
|
+
function writeChange(t) {
|
|
249
|
+
o.write([{
|
|
250
|
+
kind: "change",
|
|
251
|
+
change: t.change,
|
|
252
|
+
file: rel(t.file),
|
|
253
|
+
event: t.event,
|
|
254
|
+
at: t.at,
|
|
255
|
+
...t.hmrTs !== void 0 ? { hmrTs: t.hmrTs } : { outcome: "no-hook" },
|
|
256
|
+
flightMs: t.flightMs,
|
|
257
|
+
reloadN: t.reload.size,
|
|
258
|
+
inPlaceN: t.inPlace.size,
|
|
259
|
+
...t.fullReload ? { fullReload: t.fullReload } : {}
|
|
260
|
+
}]);
|
|
261
|
+
}
|
|
262
|
+
/** A token's end: its hooks landed in every environment, or the 10 s safety path. Its line follows at once, or when
|
|
263
|
+
* the last deferred line that holds it has written. */
|
|
264
|
+
function end(t) {
|
|
265
|
+
if (t.ended) return;
|
|
266
|
+
t.ended = true;
|
|
267
|
+
t.flightMs = now() - t.at;
|
|
268
|
+
flying.delete(t);
|
|
269
|
+
brackets.delete(t);
|
|
270
|
+
if (t.hmrTs !== void 0) runs.delete(runKey(t.file, t.hmrTs));
|
|
271
|
+
const q = open.get(t.file);
|
|
272
|
+
if (q?.includes(t)) {
|
|
273
|
+
q.splice(q.indexOf(t), 1);
|
|
274
|
+
if (!q.length) open.delete(t.file);
|
|
275
|
+
}
|
|
276
|
+
if (t.pending === 0) writeChange(t);
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
/** `watchChange`: a watcher event. */
|
|
280
|
+
watch(file, event) {
|
|
281
|
+
const t = {
|
|
282
|
+
change: `${boot}:${++n}`,
|
|
283
|
+
file,
|
|
284
|
+
event,
|
|
285
|
+
at: now(),
|
|
286
|
+
hits: 0,
|
|
287
|
+
ended: false,
|
|
288
|
+
pending: 0,
|
|
289
|
+
reload: /* @__PURE__ */ new Set(),
|
|
290
|
+
inPlace: /* @__PURE__ */ new Set()
|
|
291
|
+
};
|
|
292
|
+
flying.add(t);
|
|
293
|
+
const q = open.get(file);
|
|
294
|
+
if (q) q.push(t);
|
|
295
|
+
else open.set(file, [t]);
|
|
296
|
+
return t;
|
|
297
|
+
},
|
|
298
|
+
/** The `pre` hook, in the client environment (it runs first): this run takes the file's oldest open token. */
|
|
299
|
+
begin(file, hmrTs) {
|
|
300
|
+
const t = open.get(file)?.find((x) => x.hmrTs === void 0);
|
|
301
|
+
if (!t) return void 0;
|
|
302
|
+
t.hmrTs = hmrTs;
|
|
303
|
+
brackets.add(t);
|
|
304
|
+
runs.set(runKey(file, hmrTs), t);
|
|
305
|
+
history.push({
|
|
306
|
+
hmrTs,
|
|
307
|
+
change: t.change
|
|
308
|
+
});
|
|
309
|
+
if (history.length > RELOAD_BOUNDS.hmrHistory) history.shift();
|
|
310
|
+
return t;
|
|
311
|
+
},
|
|
312
|
+
/** The token of the run these hook options belong to, if it has one. */
|
|
313
|
+
run: (file, hmrTs) => runs.get(runKey(file, hmrTs)),
|
|
314
|
+
/** The `post` hook, per environment: the last one closes the bracket, and the token ends a tick later (Vite finishes
|
|
315
|
+
* the update after the hooks). */
|
|
316
|
+
landed(file, hmrTs) {
|
|
317
|
+
const t = runs.get(runKey(file, hmrTs));
|
|
318
|
+
if (!t || ++t.hits < o.envs()) return;
|
|
319
|
+
brackets.delete(t);
|
|
320
|
+
setTimeout(() => end(t), 0);
|
|
321
|
+
},
|
|
322
|
+
/** The 10 s safety path (plugin.ts `flying`): every token of the file still in flight ends. One whose hooks never
|
|
323
|
+
* began says so: the watcher coalesced it, or Vite never brought it to the hooks. */
|
|
324
|
+
expire(file) {
|
|
325
|
+
for (const t of [...open.get(file) ?? []]) end(t);
|
|
326
|
+
},
|
|
327
|
+
/** #11, at the guard: a page-wide reload that named nothing. */
|
|
328
|
+
pathless() {
|
|
329
|
+
if (brackets.size === 1) return {
|
|
330
|
+
token: [...brackets][0],
|
|
331
|
+
by: "hook"
|
|
332
|
+
};
|
|
333
|
+
if (brackets.size > 1) return {
|
|
334
|
+
by: "ambiguous",
|
|
335
|
+
candidates: bounded(ids(brackets))
|
|
336
|
+
};
|
|
337
|
+
return {
|
|
338
|
+
by: "unknown",
|
|
339
|
+
candidates: bounded(ids(flying))
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
/** The files whose hot update is running right now: a pathless reload was sent for one of these. */
|
|
343
|
+
handling() {
|
|
344
|
+
return [...brackets].map((t) => t.file);
|
|
345
|
+
},
|
|
346
|
+
/** A page-wide reload that names its file (Vite's dead end, an HTML page), sent after the file's hooks: that file's
|
|
347
|
+
* token still in flight - no time-window guess. */
|
|
348
|
+
ofFile(file) {
|
|
349
|
+
const ts = open.get(file) ?? [];
|
|
350
|
+
if (ts.length === 1) return { token: ts[0] };
|
|
351
|
+
return { candidates: bounded(ids(ts.length ? ts : flying)) };
|
|
352
|
+
},
|
|
353
|
+
/** #8: a refused refresh. `graphTs` is the module's timestamp as read, which a later save has already replaced: the
|
|
354
|
+
* change it names and those of the 10 s before it are candidates - never attributed to one. */
|
|
355
|
+
refused(graphTs) {
|
|
356
|
+
const named = history.filter((h) => h.hmrTs === graphTs);
|
|
357
|
+
const before = history.filter((h) => h.hmrTs < graphTs && h.hmrTs >= graphTs - RELOAD_BOUNDS.lookBackMs).reverse();
|
|
358
|
+
return {
|
|
359
|
+
graphTs,
|
|
360
|
+
candidates: bounded([...named, ...before].map((h) => h.change))
|
|
361
|
+
};
|
|
362
|
+
},
|
|
363
|
+
/** A line deferred past the hooks keeps the token: it holds the `change` line back until `release`. */
|
|
364
|
+
hold(at) {
|
|
365
|
+
const t = at.token;
|
|
366
|
+
if (!t) return () => {};
|
|
367
|
+
t.pending++;
|
|
368
|
+
return () => {
|
|
369
|
+
if (--t.pending === 0 && t.ended) writeChange(t);
|
|
370
|
+
};
|
|
371
|
+
},
|
|
372
|
+
/** #10: the `update` line, full membership in `update-ids` parts. */
|
|
373
|
+
update(cause, file, reload, inPlace, at) {
|
|
374
|
+
const r = chunks(reload), p = chunks(inPlace);
|
|
375
|
+
const parts = Math.max(1, r.length, p.length);
|
|
376
|
+
const change = at.token?.change ?? "unknown";
|
|
377
|
+
const lines = [{
|
|
378
|
+
kind: "update",
|
|
379
|
+
cause,
|
|
380
|
+
file: file ? rel(file) : null,
|
|
381
|
+
reload: r[0] ?? [],
|
|
382
|
+
inPlace: p[0] ?? [],
|
|
383
|
+
change,
|
|
384
|
+
reloadN: reload.length,
|
|
385
|
+
inPlaceN: inPlace.length,
|
|
386
|
+
...at.graphTs !== void 0 ? { graphTs: at.graphTs } : {},
|
|
387
|
+
...at.candidates ? { candidates: at.candidates } : {},
|
|
388
|
+
...parts > 1 ? { parts } : {}
|
|
389
|
+
}];
|
|
390
|
+
for (let i = 1; i < parts; i++) lines.push({
|
|
391
|
+
kind: "update-ids",
|
|
392
|
+
change,
|
|
393
|
+
part: i + 1,
|
|
394
|
+
parts,
|
|
395
|
+
...r[i] ? { reload: r[i] } : {},
|
|
396
|
+
...p[i] ? { inPlace: p[i] } : {}
|
|
397
|
+
});
|
|
398
|
+
o.write(lines);
|
|
399
|
+
if (at.token) {
|
|
400
|
+
for (const id of reload) at.token.reload.add(id);
|
|
401
|
+
for (const id of inPlace) at.token.inPlace.add(id);
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
/** #11: every page-wide reload Vite or a plugin tried to send, and what it knows of its change. */
|
|
405
|
+
fullReload(p, passed, at) {
|
|
406
|
+
if (at?.token) at.token.fullReload ??= passed ? "passed" : "dropped";
|
|
407
|
+
o.write([{
|
|
408
|
+
kind: "full-reload",
|
|
409
|
+
passed,
|
|
410
|
+
triggeredBy: p.triggeredBy ?? null,
|
|
411
|
+
path: p.path ?? null,
|
|
412
|
+
...at?.by ? { by: at.by } : {},
|
|
413
|
+
...at?.token ? {
|
|
414
|
+
change: at.token.change,
|
|
415
|
+
file: rel(at.token.file)
|
|
416
|
+
} : {},
|
|
417
|
+
...at?.candidates ? { candidates: at.candidates } : {}
|
|
418
|
+
}]);
|
|
419
|
+
},
|
|
420
|
+
/** #12: the send, with every change it carries - many to many, every edge kept in `invalidate-ids` parts. */
|
|
421
|
+
invalidate(revision, frames, changes) {
|
|
422
|
+
const c = chunks(changes);
|
|
423
|
+
const parts = Math.max(1, c.length);
|
|
424
|
+
const lines = [{
|
|
425
|
+
kind: "invalidate",
|
|
426
|
+
revision,
|
|
427
|
+
frames,
|
|
428
|
+
changes: c[0] ?? [],
|
|
429
|
+
...parts > 1 ? { parts } : {}
|
|
430
|
+
}];
|
|
431
|
+
for (let i = 1; i < parts; i++) lines.push({
|
|
432
|
+
kind: "invalidate-ids",
|
|
433
|
+
revision,
|
|
434
|
+
part: i + 1,
|
|
435
|
+
parts,
|
|
436
|
+
changes: c[i]
|
|
437
|
+
});
|
|
438
|
+
o.write(lines);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/server/board-writes.ts
|
|
444
|
+
/**
|
|
445
|
+
* Who may have written a board file (spec 30 #18). Every shell request that can write a board names its page and the
|
|
446
|
+
* commands folded into it (`x-mv-page`, `x-mv-cmds`); the server keeps, per board, the hashes it wrote in the last 10 s
|
|
447
|
+
* with them. The watcher reads the file after a debounce, so a matching hash proves matching bytes, not the writer - an
|
|
448
|
+
* editor can write the same bytes back. `sh:board` therefore carries a match as a candidate, never as proof: one match
|
|
449
|
+
* is `candidate`, two or more `ambiguous`, none `unknown` (an agent, the CLI, an editor, a write the server did not see).
|
|
450
|
+
*/
|
|
451
|
+
/** by project root: the middleware and the watcher share a process, not an object */
|
|
452
|
+
const written = /* @__PURE__ */ new Map();
|
|
453
|
+
/** The page and commands a request names; null when it names no page (the CLI, an agent): nothing to remember. */
|
|
454
|
+
function writerFrom(headers) {
|
|
455
|
+
const page = headers[WRITER_HEADERS.page];
|
|
456
|
+
if (typeof page !== "string" || !ID12.test(page)) return null;
|
|
457
|
+
return {
|
|
458
|
+
page,
|
|
459
|
+
cmds: decodeCmds(headers[WRITER_HEADERS.cmds] ?? "") ?? {
|
|
460
|
+
ids: [],
|
|
461
|
+
n: 0
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
const fresh = (root, now) => {
|
|
466
|
+
const kept = (written.get(root) ?? []).filter((w) => now - w.at < WRITE_MATCH_MS);
|
|
467
|
+
if (kept.length) written.set(root, kept);
|
|
468
|
+
else written.delete(root);
|
|
469
|
+
return kept;
|
|
470
|
+
};
|
|
471
|
+
/** A board write this server made, once it landed. */
|
|
472
|
+
function noteWrite(root, board, sha, who, now = Date.now()) {
|
|
473
|
+
written.set(root, [...fresh(root, now), {
|
|
474
|
+
...who,
|
|
475
|
+
board,
|
|
476
|
+
sha,
|
|
477
|
+
at: now
|
|
478
|
+
}]);
|
|
479
|
+
}
|
|
480
|
+
/** What the writes of the last 10 s say about these bytes of this board. */
|
|
481
|
+
function writerOf(root, board, sha, now = Date.now()) {
|
|
482
|
+
const match = fresh(root, now).filter((w) => w.board === board && w.sha === sha);
|
|
483
|
+
if (!match.length) return { writer: "unknown" };
|
|
484
|
+
return {
|
|
485
|
+
writer: match.length === 1 ? "candidate" : "ambiguous",
|
|
486
|
+
candidates: match.slice(-RELOAD_BOUNDS.candidates).map((w) => ({
|
|
487
|
+
page: w.page,
|
|
488
|
+
cmds: w.cmds.ids,
|
|
489
|
+
n: w.cmds.n
|
|
490
|
+
}))
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
//#endregion
|
|
153
494
|
//#region src/shared/perf-run.ts
|
|
154
495
|
/** A run's own generated id: the same in the URL, the request headers and the output line (A3.4). */
|
|
155
496
|
const RUN_ID = /^[0-9a-f]{16}$/;
|
|
@@ -1274,7 +1615,7 @@ async function inputPaths(root, w, urls) {
|
|
|
1274
1615
|
}
|
|
1275
1616
|
/** These paths' fingerprint: each file's path from the root (`../` for one outside it), size and mtime. A path that
|
|
1276
1617
|
* is gone or no file counts for nothing - so one deleted since changes it. */
|
|
1277
|
-
async function hashInputs(root, paths) {
|
|
1618
|
+
async function hashInputs(root, paths, level = "full") {
|
|
1278
1619
|
const lines = [];
|
|
1279
1620
|
for (let i = 0; i < paths.length; i += 64) {
|
|
1280
1621
|
const got = await Promise.all(paths.slice(i, i + 64).map(async (p) => {
|
|
@@ -1284,9 +1625,10 @@ async function hashInputs(root, paths) {
|
|
|
1284
1625
|
for (const l of got) if (l) lines.push(l);
|
|
1285
1626
|
}
|
|
1286
1627
|
lines.sort();
|
|
1628
|
+
if (level === "core") lines.push("\0recorder\0core");
|
|
1287
1629
|
return {
|
|
1288
1630
|
hash: createHash("sha256").update(lines.join("\n")).digest("hex").slice(0, 16),
|
|
1289
|
-
files: lines.length
|
|
1631
|
+
files: lines.length - (level === "core" ? 1 : 0)
|
|
1290
1632
|
};
|
|
1291
1633
|
}
|
|
1292
1634
|
/** The fingerprint of every watched file, plus the board files and `_sizes.json`; null before the watcher is ready. */
|
|
@@ -1615,6 +1957,22 @@ const RUN_T = {
|
|
|
1615
1957
|
runMs: 42e4
|
|
1616
1958
|
};
|
|
1617
1959
|
/** The page's own bound on `flush()` (recorder.ts): the driver waits that long, and `callMs` more. */
|
|
1960
|
+
/** 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
|
|
1961
|
+
* a frame, a move or an error the run counts. */
|
|
1962
|
+
const SOFT_SOURCES = /* @__PURE__ */ new Set([
|
|
1963
|
+
"console",
|
|
1964
|
+
"api",
|
|
1965
|
+
"resource"
|
|
1966
|
+
]);
|
|
1967
|
+
const OWN_LIMITS = /* @__PURE__ */ new Set([
|
|
1968
|
+
"errors",
|
|
1969
|
+
"console",
|
|
1970
|
+
"api",
|
|
1971
|
+
"resource",
|
|
1972
|
+
"cmd",
|
|
1973
|
+
"theme",
|
|
1974
|
+
"mode"
|
|
1975
|
+
]);
|
|
1618
1976
|
const FLUSH_MS = 15e3;
|
|
1619
1977
|
const RECORDS_MAX = 2e4;
|
|
1620
1978
|
const live = /* @__PURE__ */ new Map();
|
|
@@ -1715,8 +2073,9 @@ const runSeams = {};
|
|
|
1715
2073
|
function runT() {
|
|
1716
2074
|
return { ...RUN_T };
|
|
1717
2075
|
}
|
|
1718
|
-
/** The shell's address for a run's load: its run id, the warm-up's mark, the
|
|
1719
|
-
|
|
2076
|
+
/** 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
|
|
2077
|
+
* #58: the shell reads it, `withWs()` carries it to the frames), the board. */
|
|
2078
|
+
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
2079
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1721
2080
|
/** The last runs' own input paths, for `GET /api/perf/inputs?run=<id>` (the review of a3-runs' fixes): a run's set
|
|
1722
2081
|
* outside the root is its page's, which no request without the run can rebuild. Module state, the newest 32. */
|
|
@@ -2010,9 +2369,9 @@ function runLine(reg, s) {
|
|
|
2010
2369
|
const own = load ? recs.filter((r) => r.load === load.request) : [];
|
|
2011
2370
|
const commit = own.find((r) => r.kind === "commit"), settled = own.find((r) => r.kind === "settled");
|
|
2012
2371
|
const moves = own.filter((r) => r.kind === "move");
|
|
2013
|
-
const errors = recs.filter((r) => r.kind === "error").length;
|
|
2372
|
+
const errors = recs.filter((r) => r.kind === "error" && !SOFT_SOURCES.has(r.source)).length;
|
|
2014
2373
|
const badFrames = settled ? (settled.missing ?? 0) + (settled.neverReady ?? 0) : 0;
|
|
2015
|
-
const lost = recs.filter((r) => r.kind === "dropped" && r.reason
|
|
2374
|
+
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
2375
|
const reasons = [
|
|
2017
2376
|
["cancelled", s.cancelled],
|
|
2018
2377
|
["crash", s.crashed],
|
|
@@ -2044,6 +2403,7 @@ function runLine(reg, s) {
|
|
|
2044
2403
|
host: s.host,
|
|
2045
2404
|
power: s.power,
|
|
2046
2405
|
slow: s.slow,
|
|
2406
|
+
recorder: s.recorder ?? "full",
|
|
2047
2407
|
bakes: s.bakes,
|
|
2048
2408
|
postersMissing: s.postersSkipped,
|
|
2049
2409
|
saved: commit ? {
|
|
@@ -2081,6 +2441,7 @@ async function runOnce(o) {
|
|
|
2081
2441
|
id,
|
|
2082
2442
|
board: o.board,
|
|
2083
2443
|
slow: o.slow,
|
|
2444
|
+
recorder: o.recorder ?? "full",
|
|
2084
2445
|
startedAt: reg.startedAt,
|
|
2085
2446
|
inputs: null,
|
|
2086
2447
|
inputsEnd: null,
|
|
@@ -2106,7 +2467,7 @@ async function runOnce(o) {
|
|
|
2106
2467
|
const paths = o.watch ? await inputPaths(o.root, o.watch, urls) : null;
|
|
2107
2468
|
if (!paths) return;
|
|
2108
2469
|
set.paths = paths;
|
|
2109
|
-
seen.inputs = await hashInputs(o.root, paths);
|
|
2470
|
+
seen.inputs = await hashInputs(o.root, paths, o.recorder);
|
|
2110
2471
|
};
|
|
2111
2472
|
const requested = /* @__PURE__ */ new Set();
|
|
2112
2473
|
let offRequests = () => {};
|
|
@@ -2160,7 +2521,7 @@ async function runOnce(o) {
|
|
|
2160
2521
|
const url = m.sessionId === warmSession && m.method === "Network.requestWillBeSent" ? m.params?.request?.url : void 0;
|
|
2161
2522
|
if (typeof url === "string" && url.startsWith(`${o.origin}/`)) requested.add(url);
|
|
2162
2523
|
});
|
|
2163
|
-
await page.send("Page.navigate", { url: runUrl(o.origin, o.board, id, true) });
|
|
2524
|
+
await page.send("Page.navigate", { url: runUrl(o.origin, o.board, id, true, o.recorder) });
|
|
2164
2525
|
const warm = await until(page, (s) => loadEnded(s) && bakeIdle(id)(s), T.warmMs, halt(page));
|
|
2165
2526
|
seen.bakes = warm.ok ? "warm" : "cold";
|
|
2166
2527
|
seen.refusedInPage += warm.status?.refused ?? 0;
|
|
@@ -2199,7 +2560,7 @@ async function runOnce(o) {
|
|
|
2199
2560
|
};
|
|
2200
2561
|
const heapTimer = setInterval(sampleHeap, T.heapMs);
|
|
2201
2562
|
try {
|
|
2202
|
-
await p.send("Page.navigate", { url: runUrl(o.origin, o.board, id, false) });
|
|
2563
|
+
await p.send("Page.navigate", { url: runUrl(o.origin, o.board, id, false, o.recorder) });
|
|
2203
2564
|
sampleHeap();
|
|
2204
2565
|
const loaded = await until(p, loadEnded, T.settleMs, hp);
|
|
2205
2566
|
if (!loaded.ok || loaded.status?.load?.state === "cut") seen.cut = loaded.status?.load?.reason ?? (p.crashed ? "crash" : "timeout");
|
|
@@ -2258,7 +2619,7 @@ async function runOnce(o) {
|
|
|
2258
2619
|
lingering.add(id);
|
|
2259
2620
|
}
|
|
2260
2621
|
await sleep(T.watcherLagMs);
|
|
2261
|
-
seen.inputsEnd = set.paths ? (await hashInputs(o.root, set.paths)).hash : null;
|
|
2622
|
+
seen.inputsEnd = set.paths ? (await hashInputs(o.root, set.paths, o.recorder)).hash : null;
|
|
2262
2623
|
const done = runs.end(id) ?? reg;
|
|
2263
2624
|
seen.cancelled ||= o.signal.aborted;
|
|
2264
2625
|
const line = runLine(done, seen);
|
|
@@ -2304,7 +2665,7 @@ function readRunRequest(raw, boards) {
|
|
|
2304
2665
|
}
|
|
2305
2666
|
if (!b || typeof b !== "object" || Array.isArray(b)) return {
|
|
2306
2667
|
ok: false,
|
|
2307
|
-
error: "expected { board, slow?, repeat? }"
|
|
2668
|
+
error: "expected { board, slow?, repeat?, recorder? }"
|
|
2308
2669
|
};
|
|
2309
2670
|
if (typeof b.board !== "string" || !boards.includes(b.board)) return {
|
|
2310
2671
|
ok: false,
|
|
@@ -2319,12 +2680,17 @@ function readRunRequest(raw, boards) {
|
|
|
2319
2680
|
ok: false,
|
|
2320
2681
|
error: "repeat must be 1-5"
|
|
2321
2682
|
};
|
|
2683
|
+
if (b.recorder !== void 0 && !RECORDER_LEVELS.includes(b.recorder)) return {
|
|
2684
|
+
ok: false,
|
|
2685
|
+
error: "recorder must be core or full"
|
|
2686
|
+
};
|
|
2322
2687
|
return {
|
|
2323
2688
|
ok: true,
|
|
2324
2689
|
req: {
|
|
2325
2690
|
board: b.board,
|
|
2326
2691
|
slow: b.slow === true,
|
|
2327
|
-
repeat
|
|
2692
|
+
repeat,
|
|
2693
|
+
recorder: b.recorder === "core" ? "core" : "full"
|
|
2328
2694
|
}
|
|
2329
2695
|
};
|
|
2330
2696
|
}
|
|
@@ -2366,6 +2732,7 @@ async function serveRun(req, res, o) {
|
|
|
2366
2732
|
origin: o.origin,
|
|
2367
2733
|
board: asked.req.board,
|
|
2368
2734
|
slow: asked.req.slow,
|
|
2735
|
+
recorder: asked.req.recorder,
|
|
2369
2736
|
signal: ac.signal,
|
|
2370
2737
|
progress: write,
|
|
2371
2738
|
watch: o.watch
|
|
@@ -2535,6 +2902,12 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2535
2902
|
const notSymlink = (p) => !nodeExists(p) || isRegularFile(p);
|
|
2536
2903
|
const nodeExists$1 = nodeExists;
|
|
2537
2904
|
let sizesWarned = false;
|
|
2905
|
+
/** A board file this request wrote (spec 30 #18), with the page and commands it names - the watcher's `sh:board`
|
|
2906
|
+
* matches these bytes against it, as a candidate, never as proof. */
|
|
2907
|
+
const wroteBoard = (req, board, content) => {
|
|
2908
|
+
const who = writerFrom(req.headers);
|
|
2909
|
+
if (who) noteWrite(root, board, hash(content), who);
|
|
2910
|
+
};
|
|
2538
2911
|
try {
|
|
2539
2912
|
for (const f of readdirSync(boardsDir)) if (f.endsWith(".tmp")) rmSync(join(boardsDir, f), { force: true });
|
|
2540
2913
|
} catch {}
|
|
@@ -2754,6 +3127,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2754
3127
|
}
|
|
2755
3128
|
renameSync(tmp, w.file);
|
|
2756
3129
|
done.push(w);
|
|
3130
|
+
if (!w.plan) wroteBoard(req, name, w.next);
|
|
2757
3131
|
} catch (err) {
|
|
2758
3132
|
if (tmp) discard(tmp);
|
|
2759
3133
|
const stuck = undo();
|
|
@@ -2780,7 +3154,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2780
3154
|
};
|
|
2781
3155
|
if (path === "perf/reload" && req.method === "POST") {
|
|
2782
3156
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
2783
|
-
const raw = await readBody(req);
|
|
3157
|
+
const raw = await readBody(req, PAGE_BODY_MAX);
|
|
2784
3158
|
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
2785
3159
|
let b;
|
|
2786
3160
|
try {
|
|
@@ -2788,19 +3162,9 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2788
3162
|
} catch {
|
|
2789
3163
|
return json(res, 400, { error: "malformed JSON" });
|
|
2790
3164
|
}
|
|
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 });
|
|
3165
|
+
if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
|
|
3166
|
+
const answer = takeReloadBatch(root, b.records);
|
|
3167
|
+
return json(res, "error" in answer ? 503 : 200, answer);
|
|
2804
3168
|
}
|
|
2805
3169
|
if (path === "perf/jam" && req.method === "POST") {
|
|
2806
3170
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
@@ -2813,7 +3177,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2813
3177
|
return json(res, 400, { error: "malformed JSON" });
|
|
2814
3178
|
}
|
|
2815
3179
|
if (!b || b.kind !== "capture" && b.kind !== "upload") return json(res, 400, { error: "kind must be capture or upload" });
|
|
2816
|
-
(await import("./perf-
|
|
3180
|
+
(await import("./perf-BCxAo0IS.mjs").then((n) => n.f)).logJam(root, b);
|
|
2817
3181
|
return json(res, 200, { ok: true });
|
|
2818
3182
|
}
|
|
2819
3183
|
if (path === "perf/page" && req.method === "POST") {
|
|
@@ -2829,13 +3193,11 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2829
3193
|
return json(res, 400, { error: "malformed JSON" });
|
|
2830
3194
|
}
|
|
2831
3195
|
if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
} : {})
|
|
2838
|
-
});
|
|
3196
|
+
const answer = takePageBatch(root, b.records, run ? {
|
|
3197
|
+
run,
|
|
3198
|
+
kept: (recs) => runs.records(run, recs)
|
|
3199
|
+
} : {});
|
|
3200
|
+
return json(res, "error" in answer ? 503 : 200, answer);
|
|
2839
3201
|
}
|
|
2840
3202
|
if (path === "perf/run" && req.method === "POST" || path === "perf/inputs" && req.method === "GET") {
|
|
2841
3203
|
const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
|
|
@@ -2948,7 +3310,9 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2948
3310
|
const frames = Array.isArray(parsed?.frames) ? parsed.frames.filter((f) => typeof f === "string" && live.includes(f)) : [];
|
|
2949
3311
|
if (!validName(parsed?.board) || !frames.length) return json(res, 400, { error: "a board and frames on this canvas" });
|
|
2950
3312
|
try {
|
|
2951
|
-
|
|
3313
|
+
const pinned = pinFrames(root, parsed.board, frames, live);
|
|
3314
|
+
if (pinned.added.length) wroteBoard(req, parsed.board, readFileSync(join(boardsDir, `${parsed.board}.json`), "utf8"));
|
|
3315
|
+
return json(res, 200, pinned);
|
|
2952
3316
|
} catch (err) {
|
|
2953
3317
|
return json(res, 409, { error: err.message });
|
|
2954
3318
|
}
|
|
@@ -3022,12 +3386,14 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3022
3386
|
return json(res, 200, { name: to });
|
|
3023
3387
|
}
|
|
3024
3388
|
rmSync(fromPath);
|
|
3389
|
+
if (next !== void 0) wroteBoard(req, to, next);
|
|
3025
3390
|
return json(res, 200, {
|
|
3026
3391
|
name: to,
|
|
3027
3392
|
...next !== void 0 ? { sha256: hash(next) } : {}
|
|
3028
3393
|
});
|
|
3029
3394
|
}
|
|
3030
3395
|
atomicWrite(toPath, next);
|
|
3396
|
+
wroteBoard(req, to, next);
|
|
3031
3397
|
return json(res, 200, {
|
|
3032
3398
|
name: to,
|
|
3033
3399
|
sha256: hash(next)
|
|
@@ -3193,6 +3559,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3193
3559
|
else delete w.obj.folder;
|
|
3194
3560
|
const next = JSON.stringify(w.obj, null, 2) + "\n";
|
|
3195
3561
|
atomicWrite(w.path, next);
|
|
3562
|
+
wroteBoard(req, w.name, next);
|
|
3196
3563
|
sha256[w.name] = hash(next);
|
|
3197
3564
|
}
|
|
3198
3565
|
mkdirSync(boardsDir, { recursive: true });
|
|
@@ -3280,6 +3647,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3280
3647
|
} catch {}
|
|
3281
3648
|
const next2 = JSON.stringify(body.board, null, 2) + "\n";
|
|
3282
3649
|
atomicWrite(p, next2);
|
|
3650
|
+
wroteBoard(req, boardMatch[1], next2);
|
|
3283
3651
|
return json(res, 200, { sha256: hash(next2) });
|
|
3284
3652
|
} finally {
|
|
3285
3653
|
unlock();
|
|
@@ -3303,7 +3671,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3303
3671
|
};
|
|
3304
3672
|
const asPng = url.searchParams.get("format") === "png";
|
|
3305
3673
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3306
|
-
const { shootFrame } = await import("./shot-
|
|
3674
|
+
const { shootFrame } = await import("./shot-d4h_hJi9.mjs").then((n) => n.u);
|
|
3307
3675
|
const r = await shootFrame({
|
|
3308
3676
|
root,
|
|
3309
3677
|
viewports: opts.viewports ?? {},
|
|
@@ -3354,7 +3722,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3354
3722
|
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
|
|
3355
3723
|
const scale = body.scale === void 0 ? void 0 : body.scale;
|
|
3356
3724
|
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-
|
|
3725
|
+
const { resolveFrames, shootBatch } = await import("./shot-d4h_hJi9.mjs").then((n) => n.u);
|
|
3358
3726
|
const sel = resolveFrames(root, body);
|
|
3359
3727
|
if (!sel.ok) return json(res, sel.status, { error: sel.error });
|
|
3360
3728
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
@@ -3388,7 +3756,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3388
3756
|
if (typeof target === "string") return json(res, 400, { error: target });
|
|
3389
3757
|
const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
|
|
3390
3758
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3391
|
-
const { checkAnchor, CheckInputError } = await import("./anchor-check-
|
|
3759
|
+
const { checkAnchor, CheckInputError } = await import("./anchor-check-Bv4o-R2T.mjs");
|
|
3392
3760
|
try {
|
|
3393
3761
|
return json(res, 200, await checkAnchor({
|
|
3394
3762
|
root,
|
|
@@ -3496,8 +3864,8 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3496
3864
|
return json(res, 400, { error: "malformed JSON" });
|
|
3497
3865
|
}
|
|
3498
3866
|
const src = typeof b?.src === "string" ? b.src : "";
|
|
3499
|
-
const { ensurePoster, isLocalClip } = await import("./poster-
|
|
3500
|
-
const { isLocalAssetRef } = await import("./build-
|
|
3867
|
+
const { ensurePoster, isLocalClip } = await import("./poster-DPPpQiva.mjs");
|
|
3868
|
+
const { isLocalAssetRef } = await import("./build-zWGXSzly.mjs");
|
|
3501
3869
|
if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
|
|
3502
3870
|
const r = await ensurePoster(join(root, "design", "assets"), src);
|
|
3503
3871
|
if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
|
|
@@ -3914,7 +4282,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3914
4282
|
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
4283
|
if (readCapture(root, b.capture)) return json(res, 409, { error: "that capture is sealed" });
|
|
3916
4284
|
const theme = typeof b.theme === "string" && /^[a-z0-9-]+$/i.test(b.theme) ? b.theme : "light";
|
|
3917
|
-
const { shootFrame } = await import("./shot-
|
|
4285
|
+
const { shootFrame } = await import("./shot-d4h_hJi9.mjs").then((n) => n.u);
|
|
3918
4286
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3919
4287
|
const vp = typeof b.viewport === "string" ? opts.viewports?.[b.viewport] : void 0;
|
|
3920
4288
|
const dim = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
|
|
@@ -4584,21 +4952,31 @@ function marverPlugin(ctx) {
|
|
|
4584
4952
|
const bootId = String(process.hrtime.bigint());
|
|
4585
4953
|
let invRev = 0;
|
|
4586
4954
|
const pendingInv = /* @__PURE__ */ new Set();
|
|
4955
|
+
const pendingChanges = /* @__PURE__ */ new Set();
|
|
4587
4956
|
const flushInv = debounce(() => {
|
|
4588
4957
|
if (!devServer || !pendingInv.size) return;
|
|
4589
4958
|
const frameIds = [...pendingInv];
|
|
4590
4959
|
pendingInv.clear();
|
|
4960
|
+
const carried = [...pendingChanges];
|
|
4961
|
+
pendingChanges.clear();
|
|
4962
|
+
const revision = `${bootId}:${++invRev}`;
|
|
4591
4963
|
const docs = docRevs(root, manifest.frames);
|
|
4592
4964
|
devServer.ws.send("sh:frame-invalidated", {
|
|
4593
4965
|
frameIds,
|
|
4594
|
-
revision
|
|
4966
|
+
revision,
|
|
4595
4967
|
epoch: docs?.epoch,
|
|
4596
4968
|
docs: docs ? Object.fromEntries(frameIds.map((id) => [id, docs.doc[id] ?? 0])) : void 0
|
|
4597
4969
|
});
|
|
4970
|
+
changes.invalidate(revision, frameIds.length, carried);
|
|
4598
4971
|
}, 120);
|
|
4599
4972
|
const inFlight = /* @__PURE__ */ new Map();
|
|
4600
4973
|
const late = /* @__PURE__ */ new Map();
|
|
4601
4974
|
const envs = () => Object.keys(devServer?.environments ?? { client: 1 }).length;
|
|
4975
|
+
const changes = createChanges({
|
|
4976
|
+
root,
|
|
4977
|
+
envs,
|
|
4978
|
+
write: (lines) => logReloadLines(root, lines)
|
|
4979
|
+
});
|
|
4602
4980
|
const waiting = [];
|
|
4603
4981
|
const settled = () => inFlight.size === 0;
|
|
4604
4982
|
const whenSettled = (fn) => {
|
|
@@ -4632,6 +5010,7 @@ function marverPlugin(ctx) {
|
|
|
4632
5010
|
for (const env of Object.values(devServer?.environments ?? {})) env.moduleGraph.invalidateAll();
|
|
4633
5011
|
late.set(file, (late.get(file) ?? 0) + f.events * envs() - f.hits);
|
|
4634
5012
|
inFlight.delete(file);
|
|
5013
|
+
changes.expire(file);
|
|
4635
5014
|
drain();
|
|
4636
5015
|
}, 1e4);
|
|
4637
5016
|
inFlight.set(file, f);
|
|
@@ -4661,19 +5040,21 @@ function marverPlugin(ctx) {
|
|
|
4661
5040
|
}
|
|
4662
5041
|
});
|
|
4663
5042
|
const hooks = {
|
|
4664
|
-
onFrames: (t, cause) => {
|
|
4665
|
-
|
|
5043
|
+
onFrames: (t, cause, at) => {
|
|
5044
|
+
const release = changes.hold(at);
|
|
5045
|
+
setTimeout(() => whenSettled(() => {
|
|
5046
|
+
try {
|
|
5047
|
+
record(t, cause, at);
|
|
5048
|
+
} finally {
|
|
5049
|
+
release();
|
|
5050
|
+
}
|
|
5051
|
+
}), 0);
|
|
4666
5052
|
},
|
|
4667
|
-
onReload(p, passed) {
|
|
4668
|
-
|
|
4669
|
-
kind: "full-reload",
|
|
4670
|
-
passed,
|
|
4671
|
-
triggeredBy: p.triggeredBy ?? null,
|
|
4672
|
-
path: p.path ?? null
|
|
4673
|
-
});
|
|
5053
|
+
onReload(p, passed, at) {
|
|
5054
|
+
changes.fullReload(p, passed, at);
|
|
4674
5055
|
}
|
|
4675
5056
|
};
|
|
4676
|
-
function record(t, cause) {
|
|
5057
|
+
function record(t, cause, at) {
|
|
4677
5058
|
const seen = observe(root, manifest.frames, t.file ? { file: t.file } : {});
|
|
4678
5059
|
const doc = t.unattributed ? [] : t.doc.filter((id) => !seen.doc.includes(id));
|
|
4679
5060
|
const touched = t.touched.filter((id) => !seen.doc.includes(id) && !seen.note.includes(id) && !doc.includes(id));
|
|
@@ -4681,18 +5062,13 @@ function marverPlugin(ctx) {
|
|
|
4681
5062
|
if (touched.length) recordChanged(root, manifest.frames, touched, { doc: false });
|
|
4682
5063
|
const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
|
|
4683
5064
|
for (const id of reload) pendingInv.add(id);
|
|
5065
|
+
if (reload.length && at.token) pendingChanges.add(at.token.change);
|
|
4684
5066
|
flushInv();
|
|
4685
5067
|
if (reload.length || touched.length || seen.note.length) {
|
|
4686
5068
|
devServer?.ws.send("sh:marks", {});
|
|
4687
5069
|
liveChanged();
|
|
4688
5070
|
}
|
|
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
|
-
});
|
|
5071
|
+
changes.update(cause, t.file, reload, t.touched, at);
|
|
4696
5072
|
}
|
|
4697
5073
|
/** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
|
|
4698
5074
|
* Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
|
|
@@ -4706,500 +5082,513 @@ function marverPlugin(ctx) {
|
|
|
4706
5082
|
if (ctx.detectedThemeCss && existsSync(join(root, ctx.detectedThemeCss))) return join(root, ctx.detectedThemeCss);
|
|
4707
5083
|
return null;
|
|
4708
5084
|
};
|
|
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
|
|
5085
|
+
return [
|
|
5086
|
+
{
|
|
5087
|
+
name: "marver",
|
|
5088
|
+
watchChange(id, change) {
|
|
5089
|
+
if (devServer) {
|
|
5090
|
+
flying(id);
|
|
5091
|
+
changes.watch(id, change.event);
|
|
5092
|
+
}
|
|
5093
|
+
},
|
|
5094
|
+
enforce: "pre",
|
|
5095
|
+
resolveId(id) {
|
|
5096
|
+
if (id === VIRTUAL_THEME) return themeFile() ?? "\0virtual:sh-theme.css";
|
|
5097
|
+
if (id === VIRTUAL_CONFIG) return "\0virtual:sh-config";
|
|
5098
|
+
if (id === VIRTUAL_DATA) return "\0virtual:sh-data";
|
|
5099
|
+
},
|
|
5100
|
+
load(id) {
|
|
5101
|
+
if (id === "\0virtual:sh-theme.css") {
|
|
5102
|
+
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).");
|
|
5103
|
+
return "/* marver: no theme configured */";
|
|
5104
|
+
}
|
|
5105
|
+
if (id === "\0virtual:sh-config") {
|
|
5106
|
+
const setupPending = (() => {
|
|
5107
|
+
try {
|
|
5108
|
+
const s = readFileSync(join(root, "design", "instructions", "setup.md"), "utf8");
|
|
5109
|
+
return s.startsWith("# Setup required") && s.includes("marver init");
|
|
5110
|
+
} catch {
|
|
5111
|
+
return false;
|
|
5112
|
+
}
|
|
5113
|
+
})();
|
|
5114
|
+
return `export default ${JSON.stringify({
|
|
5115
|
+
viewports: config.viewports,
|
|
5116
|
+
themes: config.themes,
|
|
5117
|
+
zoomSpeed: config.zoomSpeed,
|
|
5118
|
+
noTheme: themeFile() == null,
|
|
5119
|
+
setup: setupPending,
|
|
5120
|
+
projectName: config.share.name || basename(root),
|
|
5121
|
+
branding: config.share.branding,
|
|
5122
|
+
jam: config.jam ? {
|
|
5123
|
+
chime: config.jam.chime,
|
|
5124
|
+
capture: config.jam.capture,
|
|
5125
|
+
names: config.jam.names && config.jam.agent === "claude"
|
|
5126
|
+
} : null,
|
|
5127
|
+
workspace: ws,
|
|
5128
|
+
version: installedVersion() ?? "0.0.0"
|
|
5129
|
+
})}`;
|
|
5130
|
+
}
|
|
5131
|
+
if (id === "\0virtual:sh-data") return "export default null";
|
|
5132
|
+
},
|
|
5133
|
+
/** HTML frames: inject theme + bridge into any design/**.html Vite serves.
|
|
5134
|
+
* Inline scripts go through vite's html-proxy import-analysis: bare specifiers resolve
|
|
5135
|
+
* through plugins (so `virtual:sh-theme` works); `/@id/` URLs are rejected there. */
|
|
5136
|
+
transformIndexHtml: {
|
|
5137
|
+
order: "pre",
|
|
5138
|
+
handler(html, hctx) {
|
|
5139
|
+
const path = (hctx.originalUrl ?? hctx.path ?? "").split("?")[0];
|
|
5140
|
+
if (!path.startsWith("/design/")) return;
|
|
5141
|
+
const bridge = "/@fs/" + join(clientDir, "frame-host", "bridge.js").split("\\").join("/") + "?html=1";
|
|
5142
|
+
const frame = manifest.frames.find((f) => "/" + f.file === path);
|
|
5143
|
+
const stamp = frame ? docRev(root, manifest.frames, frame.id) : "";
|
|
5144
|
+
return {
|
|
5145
|
+
html,
|
|
5146
|
+
tags: [
|
|
5147
|
+
{
|
|
5148
|
+
tag: "script",
|
|
5149
|
+
attrs: { type: "module" },
|
|
5150
|
+
children: `import '${VIRTUAL_THEME}'`,
|
|
5151
|
+
injectTo: "head-prepend"
|
|
4778
5152
|
},
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
5153
|
+
{
|
|
5154
|
+
tag: "script",
|
|
5155
|
+
attrs: {
|
|
5156
|
+
type: "module",
|
|
5157
|
+
src: bridge
|
|
5158
|
+
},
|
|
5159
|
+
injectTo: "head-prepend"
|
|
4786
5160
|
},
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
5161
|
+
...stamp ? [{
|
|
5162
|
+
tag: "meta",
|
|
5163
|
+
attrs: {
|
|
5164
|
+
name: "mv-doc",
|
|
5165
|
+
content: stamp
|
|
5166
|
+
},
|
|
5167
|
+
injectTo: "head-prepend"
|
|
5168
|
+
}] : []
|
|
5169
|
+
]
|
|
5170
|
+
};
|
|
5171
|
+
}
|
|
5172
|
+
},
|
|
5173
|
+
configureServer(server) {
|
|
5174
|
+
const closers = [];
|
|
5175
|
+
const onClose = (fn) => {
|
|
5176
|
+
closers.push(fn);
|
|
4790
5177
|
};
|
|
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));
|
|
5178
|
+
const closeAll = () => {
|
|
5179
|
+
for (const fn of closers.splice(0).reverse()) try {
|
|
5180
|
+
fn();
|
|
5181
|
+
} catch {}
|
|
5182
|
+
};
|
|
5183
|
+
const withdraw = ctx.startup?.defer(closeAll, server);
|
|
5184
|
+
server.httpServer?.once("close", () => {
|
|
5185
|
+
withdraw?.();
|
|
5186
|
+
closeAll();
|
|
5187
|
+
});
|
|
5188
|
+
if (served++) {
|
|
5189
|
+
manifest = scanFrames(root, projectInfo());
|
|
5190
|
+
observeLater();
|
|
5191
|
+
runs.restarted();
|
|
4838
5192
|
}
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
if (
|
|
5193
|
+
server.middlewares.use(guardMiddleware(ws));
|
|
5194
|
+
server.middlewares.use(perfRunBarrier());
|
|
5195
|
+
const hub = ctx.proof ? createLiveHub({
|
|
5196
|
+
instance: ctx.proof.instance,
|
|
5197
|
+
read: () => liveSnapshot(live.read(manifest.frames)),
|
|
5198
|
+
on: (fn) => workActivity.onChange(fn)
|
|
5199
|
+
}) : null;
|
|
5200
|
+
if (hub) onClose(() => hub.close());
|
|
5201
|
+
server.middlewares.use(liveRoute(hub, ctx.proof));
|
|
5202
|
+
const viteWatcher = server.watcher;
|
|
5203
|
+
watching.server = server;
|
|
5204
|
+
watching.watcher = viteWatcher;
|
|
5205
|
+
watching.ready = viteWatcher._readyEmitted === true;
|
|
5206
|
+
viteWatcher.once("ready", () => {
|
|
5207
|
+
if (watching.watcher !== viteWatcher) return;
|
|
5208
|
+
watching.ready = true;
|
|
5209
|
+
for (const w of watching.waiters) w();
|
|
5210
|
+
watching.waiters.clear();
|
|
5211
|
+
});
|
|
5212
|
+
viteWatcher.on("all", (_event, file) => runs.changed(file));
|
|
5213
|
+
let bakeGen = Date.now();
|
|
5214
|
+
server.middlewares.use((req, res, next) => {
|
|
5215
|
+
if (req.url && req.url.includes("/frame-host/registry.ts")) {
|
|
5216
|
+
const orig = res.setHeader.bind(res);
|
|
5217
|
+
res.setHeader = ((name, value) => orig(name, String(name).toLowerCase() === "cache-control" ? "no-cache" : value));
|
|
5218
|
+
}
|
|
5219
|
+
next();
|
|
5220
|
+
});
|
|
5221
|
+
const update = checkUpdate(root).catch(() => null);
|
|
4847
5222
|
update.then((latest) => {
|
|
4848
|
-
|
|
4849
|
-
res.setHeader("cache-control", "no-store");
|
|
4850
|
-
res.end(JSON.stringify({
|
|
4851
|
-
latest,
|
|
4852
|
-
current: installedVersion()
|
|
4853
|
-
}));
|
|
5223
|
+
if (latest) console.log(`\n update: ${PKG} ${latest} is out (installed ${installedVersion() ?? "?"}) → npm i -D ${PKG}@latest && npx ${NAME} init\n`);
|
|
4854
5224
|
});
|
|
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);
|
|
5225
|
+
server.middlewares.use((req, res, next) => {
|
|
5226
|
+
if (new URL(req.url ?? "/", "http://x").pathname !== `/__mv/api/update`) return next();
|
|
5227
|
+
update.then((latest) => {
|
|
5228
|
+
res.setHeader("content-type", "application/json");
|
|
5229
|
+
res.setHeader("cache-control", "no-store");
|
|
5230
|
+
res.end(JSON.stringify({
|
|
5231
|
+
latest,
|
|
5232
|
+
current: installedVersion()
|
|
5233
|
+
}));
|
|
5234
|
+
});
|
|
5235
|
+
});
|
|
5236
|
+
const listeningOrigin = () => originOf(server.httpServer?.address());
|
|
5237
|
+
initMarks(root, manifest.frames);
|
|
5238
|
+
tidyPerfDir(root);
|
|
5239
|
+
server.middlewares.use(apiMiddleware(root, {
|
|
5240
|
+
viewports: config.viewports,
|
|
5241
|
+
origin: listeningOrigin,
|
|
5242
|
+
bakeGen: () => bakeGen,
|
|
5243
|
+
notify: (event) => {
|
|
5244
|
+
server.ws.send(event, {});
|
|
5245
|
+
liveChanged();
|
|
5246
|
+
},
|
|
5247
|
+
manifest: () => manifest,
|
|
5248
|
+
settled,
|
|
5249
|
+
workspace: ws,
|
|
5250
|
+
inputs
|
|
5251
|
+
}));
|
|
5252
|
+
server.middlewares.use(logoRoute(root, () => config.share.logo, ctx.proof));
|
|
5253
|
+
server.middlewares.use(routesMiddleware(server, clientDir, {
|
|
5254
|
+
doc: (id) => docRev(root, manifest.frames, id),
|
|
5255
|
+
docs: () => docRevs(root, manifest.frames)
|
|
5256
|
+
}, ctx.proof));
|
|
5257
|
+
const before = devServer;
|
|
5258
|
+
devServer = server;
|
|
5259
|
+
onClose(() => {
|
|
5260
|
+
if (devServer === server) devServer = before;
|
|
5261
|
+
});
|
|
5262
|
+
guardUpdates(server, root, () => manifest, hooks, changes, (sheets) => rescanTheme(sheets));
|
|
5263
|
+
let framesKey = JSON.stringify(manifest.frames);
|
|
5264
|
+
let scenesKey = JSON.stringify(manifest.scenes);
|
|
5265
|
+
let unplacedKey = "";
|
|
5266
|
+
const sayUnplaced = () => {
|
|
5267
|
+
const { unplaced } = readMembership(root, manifest.frames.map((f) => f.id));
|
|
5268
|
+
const key = unplaced.join(",");
|
|
5269
|
+
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 ...>`);
|
|
5270
|
+
unplacedKey = key;
|
|
4919
5271
|
};
|
|
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();
|
|
5272
|
+
sayUnplaced();
|
|
5273
|
+
const regen = debounce(() => {
|
|
5274
|
+
manifest = scanFrames(root, projectInfo());
|
|
5275
|
+
sayUnplaced();
|
|
5276
|
+
const changed = writeManifest(root, manifest);
|
|
5277
|
+
observeLater();
|
|
5278
|
+
const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
|
|
5279
|
+
if (changed && key !== framesKey) {
|
|
5280
|
+
server.ws.send("sh:manifest", manifest);
|
|
5281
|
+
liveChanged();
|
|
5282
|
+
} else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
|
|
5283
|
+
framesKey = key;
|
|
5284
|
+
scenesKey = sKey;
|
|
4975
5285
|
}, 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
|
|
5286
|
+
onClose(regen.cancel);
|
|
5287
|
+
const watched = [join(root, "design", "scenes"), join(root, "design", "components")];
|
|
5288
|
+
const inScope = (file) => watched.some((w) => file.startsWith(w));
|
|
5289
|
+
const themeModules = () => {
|
|
5290
|
+
const f = themeFile();
|
|
5291
|
+
if (!f) return [];
|
|
5292
|
+
const out = [];
|
|
5293
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5294
|
+
const walk = (mod) => {
|
|
5295
|
+
if (!mod || seen.has(mod)) return;
|
|
5296
|
+
seen.add(mod);
|
|
5297
|
+
out.push(mod);
|
|
5298
|
+
for (const im of mod.clientImportedModules ?? mod.importedModules ?? []) if (String(im.id ?? "").split("?")[0].endsWith(".css")) walk(im);
|
|
4997
5299
|
};
|
|
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}`);
|
|
5300
|
+
for (const mod of server.moduleGraph.getModulesByFile(f) ?? []) walk(mod);
|
|
5301
|
+
return out;
|
|
5011
5302
|
};
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5303
|
+
const owed = /* @__PURE__ */ new Set();
|
|
5304
|
+
const pushTheme = debounce(() => {
|
|
5305
|
+
const sheets = [...owed].flatMap((f) => [...server.moduleGraph.getModulesByFile(f) ?? []]);
|
|
5306
|
+
owed.clear();
|
|
5307
|
+
for (const mod of /* @__PURE__ */ new Set([...themeModules(), ...sheets])) server.reloadModule(mod).catch(() => {});
|
|
5308
|
+
}, 150);
|
|
5309
|
+
onClose(pushTheme.cancel);
|
|
5310
|
+
const rescanTheme = (sheets = []) => {
|
|
5311
|
+
for (const mod of themeModules()) server.moduleGraph.invalidateModule(mod);
|
|
5312
|
+
for (const f of sheets) owed.add(f);
|
|
5313
|
+
pushTheme();
|
|
5314
|
+
};
|
|
5315
|
+
const localDir = join(root, "design", ".local"), boardsDirGen = join(root, "design", "boards"), manifestPath = join(root, "design", "manifest.json");
|
|
5316
|
+
const bumpGen = (f) => {
|
|
5317
|
+
if (f.startsWith(localDir) || f.startsWith(boardsDirGen) || f === manifestPath || f.includes("/node_modules/")) return;
|
|
5318
|
+
bakeGen++;
|
|
5319
|
+
prune();
|
|
5320
|
+
};
|
|
5321
|
+
const pruning = /* @__PURE__ */ new Set();
|
|
5322
|
+
const prune = () => {
|
|
5323
|
+
const t = setTimeout(async () => {
|
|
5324
|
+
pruning.delete(t);
|
|
5325
|
+
try {
|
|
5326
|
+
(await Promise.resolve().then(() => bake_exports)).pruneBakes(root, bakeGen);
|
|
5327
|
+
} catch {}
|
|
5328
|
+
}, 500);
|
|
5329
|
+
pruning.add(t);
|
|
5330
|
+
};
|
|
5331
|
+
onClose(() => {
|
|
5332
|
+
for (const t of pruning) clearTimeout(t);
|
|
5333
|
+
});
|
|
5334
|
+
prune();
|
|
5335
|
+
server.watcher.on("add", bumpGen);
|
|
5336
|
+
server.watcher.on("unlink", bumpGen);
|
|
5337
|
+
server.watcher.on("change", bumpGen);
|
|
5338
|
+
server.watcher.on("add", (f) => {
|
|
5339
|
+
if (inScope(f)) {
|
|
5340
|
+
regen();
|
|
5341
|
+
rescanTheme();
|
|
5342
|
+
}
|
|
5343
|
+
});
|
|
5344
|
+
server.watcher.on("unlink", (f) => {
|
|
5345
|
+
if (inScope(f)) {
|
|
5346
|
+
regen();
|
|
5347
|
+
rescanTheme();
|
|
5348
|
+
}
|
|
5349
|
+
});
|
|
5350
|
+
const contextDir = join(root, "context") + sep;
|
|
5351
|
+
let statusTimer;
|
|
5352
|
+
onClose(() => clearTimeout(statusTimer));
|
|
5353
|
+
const restatus = (f) => {
|
|
5354
|
+
if (!f.startsWith(contextDir) && !(inScope(f) && f.endsWith("_brief.md"))) return;
|
|
5355
|
+
clearTimeout(statusTimer);
|
|
5356
|
+
statusTimer = setTimeout(() => {
|
|
5022
5357
|
server.ws.send("sh:boards", {});
|
|
5023
5358
|
regen();
|
|
5024
|
-
boardsChanged(root);
|
|
5025
5359
|
}, 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);
|
|
5360
|
+
};
|
|
5361
|
+
server.watcher.on("add", restatus);
|
|
5362
|
+
server.watcher.on("unlink", restatus);
|
|
5363
|
+
server.watcher.on("change", restatus);
|
|
5364
|
+
server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
|
|
5365
|
+
const marksChanged = debounce(observeLater, 300);
|
|
5366
|
+
onClose(marksChanged.cancel);
|
|
5367
|
+
for (const ev of [
|
|
5368
|
+
"add",
|
|
5369
|
+
"change",
|
|
5370
|
+
"unlink"
|
|
5371
|
+
]) server.watcher.on(ev, (f) => {
|
|
5372
|
+
if (!f.startsWith(localDir) && !f.startsWith(boardsDirGen)) marksChanged();
|
|
5052
5373
|
});
|
|
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
|
-
|
|
5374
|
+
const configFile = join(root, "design", "config.ts");
|
|
5375
|
+
server.watcher.on("change", (f) => {
|
|
5376
|
+
if (f !== configFile) return;
|
|
5377
|
+
loadConfig(root).then((c) => {
|
|
5378
|
+
project = {
|
|
5379
|
+
name: c.share.name || basename(root),
|
|
5380
|
+
description: c.description
|
|
5381
|
+
};
|
|
5382
|
+
regen();
|
|
5383
|
+
}).catch(() => {});
|
|
5384
|
+
});
|
|
5385
|
+
writeManifest(root, manifest);
|
|
5386
|
+
const boardsDir = join(root, "design", "boards");
|
|
5387
|
+
try {
|
|
5388
|
+
mkdirSync(boardsDir, { recursive: true });
|
|
5389
|
+
const timers = /* @__PURE__ */ new Map();
|
|
5390
|
+
const badBoards = /* @__PURE__ */ new Map();
|
|
5391
|
+
const reportBad = (file, content, error) => {
|
|
5392
|
+
if (badBoards.get(file) === hash(content)) return;
|
|
5393
|
+
badBoards.set(file, hash(content));
|
|
5394
|
+
console.warn(`[marver] design/boards/${file} is not valid JSON - ${error}`);
|
|
5395
|
+
};
|
|
5396
|
+
if (!checkBoardsDir(root, boardsDir)) {
|
|
5397
|
+
for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
|
|
5398
|
+
}
|
|
5399
|
+
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/)`);
|
|
5400
|
+
let listTimer;
|
|
5401
|
+
const watcher = guarded(watch(boardsDir, (_event, file) => {
|
|
5402
|
+
if (file?.endsWith(".json")) runs.changed(join(boardsDir, file));
|
|
5403
|
+
if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
|
|
5404
|
+
clearTimeout(listTimer);
|
|
5405
|
+
listTimer = setTimeout(() => {
|
|
5406
|
+
server.ws.send("sh:boards", {});
|
|
5407
|
+
regen();
|
|
5408
|
+
boardsChanged(root);
|
|
5409
|
+
}, 150);
|
|
5410
|
+
clearTimeout(timers.get(file));
|
|
5411
|
+
timers.set(file, setTimeout(() => {
|
|
5412
|
+
timers.delete(file);
|
|
5413
|
+
let content;
|
|
5414
|
+
if (!isRegularFile(join(boardsDir, file))) return;
|
|
5087
5415
|
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
|
-
});
|
|
5416
|
+
content = readFileSync(join(boardsDir, file), "utf8");
|
|
5417
|
+
} catch {
|
|
5111
5418
|
return;
|
|
5112
5419
|
}
|
|
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
|
-
});
|
|
5420
|
+
const { error } = parseBoard(content);
|
|
5421
|
+
if (error) {
|
|
5422
|
+
if (!checkBoardsDir(root, boardsDir)) reportBad(file, content, error);
|
|
5124
5423
|
return;
|
|
5125
5424
|
}
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5425
|
+
badBoards.delete(file);
|
|
5426
|
+
const name = file.replace(/\.json$/, ""), sha256 = hash(content);
|
|
5427
|
+
server.ws.send("sh:board", {
|
|
5428
|
+
name,
|
|
5429
|
+
sha256,
|
|
5430
|
+
...writerOf(root, name, sha256)
|
|
5431
|
+
});
|
|
5432
|
+
}, 120));
|
|
5433
|
+
}));
|
|
5434
|
+
onClose(() => {
|
|
5435
|
+
watcher.close();
|
|
5436
|
+
clearTimeout(listTimer);
|
|
5437
|
+
for (const t of timers.values()) clearTimeout(t);
|
|
5438
|
+
});
|
|
5439
|
+
} catch {}
|
|
5440
|
+
try {
|
|
5441
|
+
const inbox = join(root, "design", ".local", "shots");
|
|
5442
|
+
mkdirSync(inbox, { recursive: true });
|
|
5443
|
+
const origin = listeningOrigin;
|
|
5444
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
5445
|
+
const processRequest = (file) => {
|
|
5446
|
+
if (!file.endsWith(".request.json") || inFlight.has(file)) return;
|
|
5447
|
+
const reqPath = join(inbox, file);
|
|
5448
|
+
if (!existsSync(reqPath)) return;
|
|
5449
|
+
inFlight.add(file);
|
|
5450
|
+
setTimeout(async () => {
|
|
5451
|
+
const base = file.replace(/\.request\.json$/, "");
|
|
5452
|
+
const resultPath = join(inbox, `${base}.result.json`);
|
|
5453
|
+
const claimed = join(inbox, `.${base}.${process.pid}.${Date.now().toString(36)}.claimed`);
|
|
5454
|
+
try {
|
|
5455
|
+
renameSync(reqPath, claimed);
|
|
5456
|
+
} catch {
|
|
5457
|
+
inFlight.delete(file);
|
|
5132
5458
|
return;
|
|
5133
5459
|
}
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5460
|
+
try {
|
|
5461
|
+
const write = (r) => {
|
|
5462
|
+
const tmp = join(inbox, `.${base}.${process.pid}.tmp`);
|
|
5463
|
+
try {
|
|
5464
|
+
writeFileSync(tmp, JSON.stringify(r, null, 2));
|
|
5465
|
+
renameSync(tmp, resultPath);
|
|
5466
|
+
} catch {
|
|
5467
|
+
try {
|
|
5468
|
+
rmSync(tmp, { force: true });
|
|
5469
|
+
} catch {}
|
|
5470
|
+
}
|
|
5471
|
+
};
|
|
5472
|
+
let spec;
|
|
5473
|
+
try {
|
|
5474
|
+
spec = JSON.parse(readFileSync(claimed, "utf8"));
|
|
5475
|
+
if (!spec || typeof spec !== "object" || Array.isArray(spec)) throw new Error("expected an object");
|
|
5476
|
+
} catch (err) {
|
|
5137
5477
|
write({
|
|
5138
5478
|
ok: false,
|
|
5139
|
-
error:
|
|
5479
|
+
error: `malformed request - ${err.message}`
|
|
5140
5480
|
});
|
|
5141
5481
|
return;
|
|
5142
5482
|
}
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
}
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
}
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5483
|
+
const theme = spec.theme === void 0 ? "light" : spec.theme;
|
|
5484
|
+
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) {
|
|
5485
|
+
write({
|
|
5486
|
+
ok: false,
|
|
5487
|
+
error: "invalid theme"
|
|
5488
|
+
});
|
|
5489
|
+
return;
|
|
5490
|
+
}
|
|
5491
|
+
const scale = spec.scale === void 0 ? void 0 : spec.scale;
|
|
5492
|
+
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) {
|
|
5493
|
+
write({
|
|
5494
|
+
ok: false,
|
|
5495
|
+
error: "invalid scale"
|
|
5496
|
+
});
|
|
5497
|
+
return;
|
|
5498
|
+
}
|
|
5499
|
+
const ways = [
|
|
5500
|
+
"frame",
|
|
5501
|
+
"frames",
|
|
5502
|
+
"scene",
|
|
5503
|
+
"all"
|
|
5504
|
+
].filter((k) => spec[k] !== void 0);
|
|
5505
|
+
if (ways.length !== 1) {
|
|
5506
|
+
write({
|
|
5507
|
+
ok: false,
|
|
5508
|
+
error: "name the frames one way: frame (an id), frames (an array of ids), scene (a name) or all (true)"
|
|
5509
|
+
});
|
|
5510
|
+
return;
|
|
5511
|
+
}
|
|
5512
|
+
const o = origin();
|
|
5513
|
+
if (!o) {
|
|
5514
|
+
write({
|
|
5515
|
+
ok: false,
|
|
5516
|
+
error: "dev server has no address yet - retry"
|
|
5517
|
+
});
|
|
5518
|
+
return;
|
|
5519
|
+
}
|
|
5520
|
+
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-d4h_hJi9.mjs").then((n) => n.u);
|
|
5521
|
+
if (ways[0] === "frame") {
|
|
5522
|
+
if (typeof spec.frame !== "string") {
|
|
5523
|
+
write({
|
|
5524
|
+
ok: false,
|
|
5525
|
+
error: "frame must be a frame id"
|
|
5526
|
+
});
|
|
5527
|
+
return;
|
|
5528
|
+
}
|
|
5529
|
+
write(await shootFrame({
|
|
5165
5530
|
root,
|
|
5166
5531
|
viewports: config.viewports,
|
|
5167
|
-
|
|
5532
|
+
frameId: spec.frame,
|
|
5168
5533
|
theme,
|
|
5169
5534
|
origin: o,
|
|
5170
5535
|
scale
|
|
5171
|
-
})
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5536
|
+
}));
|
|
5537
|
+
return;
|
|
5538
|
+
}
|
|
5539
|
+
const sel = resolveFrames(root, spec);
|
|
5540
|
+
if (!sel.ok) {
|
|
5541
|
+
write({
|
|
5542
|
+
ok: false,
|
|
5543
|
+
error: sel.error
|
|
5544
|
+
});
|
|
5545
|
+
return;
|
|
5546
|
+
}
|
|
5547
|
+
try {
|
|
5548
|
+
write({
|
|
5549
|
+
ok: true,
|
|
5550
|
+
results: await shootBatch({
|
|
5551
|
+
root,
|
|
5552
|
+
viewports: config.viewports,
|
|
5553
|
+
frames: sel.frames,
|
|
5554
|
+
theme,
|
|
5555
|
+
origin: o,
|
|
5556
|
+
scale
|
|
5557
|
+
})
|
|
5558
|
+
});
|
|
5559
|
+
} catch (err) {
|
|
5560
|
+
write({
|
|
5561
|
+
ok: false,
|
|
5562
|
+
error: err.message
|
|
5563
|
+
});
|
|
5564
|
+
}
|
|
5565
|
+
} finally {
|
|
5566
|
+
try {
|
|
5567
|
+
rmSync(claimed, { force: true });
|
|
5568
|
+
} catch {}
|
|
5569
|
+
inFlight.delete(file);
|
|
5178
5570
|
}
|
|
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)];
|
|
5571
|
+
}, 60);
|
|
5572
|
+
};
|
|
5573
|
+
const inboxWatcher = guarded(watch(inbox, { persistent: false }, (_e, file) => {
|
|
5574
|
+
if (file) processRequest(file);
|
|
5575
|
+
}));
|
|
5576
|
+
const sweep = setInterval(() => {
|
|
5577
|
+
try {
|
|
5578
|
+
for (const f of readdirSync(inbox)) processRequest(f);
|
|
5579
|
+
} catch {}
|
|
5580
|
+
}, 1e3);
|
|
5581
|
+
sweep.unref?.();
|
|
5582
|
+
onClose(() => {
|
|
5583
|
+
inboxWatcher.close();
|
|
5584
|
+
clearInterval(sweep);
|
|
5585
|
+
});
|
|
5586
|
+
} catch {}
|
|
5587
|
+
}
|
|
5588
|
+
},
|
|
5589
|
+
updatesBeginPlugin(changes),
|
|
5590
|
+
updatesPlugin(root, () => manifest, () => devServer && hooks, landed, changes)
|
|
5591
|
+
];
|
|
5203
5592
|
}
|
|
5204
5593
|
/**
|
|
5205
5594
|
* The live stream's four adapters (spec 28 A4.6 #7), the hub's `read()`: every board's comment log replayed - cached by
|