tempo-sdk 0.0.20 → 0.0.23
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/dist/canvas/index.d.ts +19 -2
- package/dist/canvas/index.js +224 -50
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.js +4250 -1547
- package/dist/canvas/interact-projection.js.map +1 -1
- package/dist/chunk-ZT2REPH4.js +19 -0
- package/dist/chunk-ZT2REPH4.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +610 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,13 +4,15 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// index.ts
|
|
6
6
|
import {
|
|
7
|
+
existsSync,
|
|
7
8
|
readFileSync,
|
|
8
9
|
realpathSync as realpathSync2,
|
|
9
10
|
statSync as statSync2,
|
|
10
11
|
watch as watchFileSystem
|
|
11
12
|
} from "fs";
|
|
12
13
|
import { createRequire } from "module";
|
|
13
|
-
import { dirname, join, relative as relative2, resolve } from "path";
|
|
14
|
+
import { dirname, isAbsolute, join, relative as relative2, resolve } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
14
16
|
import { createFilter } from "@rollup/pluginutils";
|
|
15
17
|
|
|
16
18
|
// ../../modules/annotation/annotate-file.ts
|
|
@@ -225,9 +227,17 @@ function computeTempoAnnotatedProps(params) {
|
|
|
225
227
|
return userProps;
|
|
226
228
|
}
|
|
227
229
|
|
|
230
|
+
// canvas-host-registration-contract.ts
|
|
231
|
+
var CANVAS_HOST_REGISTRATION_ENDPOINT = "/__tempo/canvas-host-registration";
|
|
232
|
+
var CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER = "x-tempo-canvas-host-registration";
|
|
233
|
+
function normalizeCanvasRegistrationPath(canvasPath) {
|
|
234
|
+
return canvasPath.trim().replace(/\\/g, "/").replace(/^\.\/+/, "").replace(/^\/+/, "");
|
|
235
|
+
}
|
|
236
|
+
|
|
228
237
|
// default-export-identity.ts
|
|
229
238
|
var FUNCTION_DEFAULT_RE = /^(?:async\s+)?function(?:\s*\*)?(?:\s+([A-Za-z_$][\w$]*))?\s*\(/;
|
|
230
239
|
var CLASS_DEFAULT_RE = /^(?:abstract\s+)?class(?:\s+([A-Za-z_$][\w$]*))?(?=[\s{])/;
|
|
240
|
+
var ARROW_DEFAULT_RE = /^(?:async\s+)?(?:\([^()]*\)|[A-Za-z_$][\w$]*)\s*=>/;
|
|
231
241
|
var IDENTIFIER_DEFAULT_RE = /^([A-Za-z_$][\w$]*)[ \t]*(?:;|\r?\n|$)/;
|
|
232
242
|
function readDefaultExportIdentity(source) {
|
|
233
243
|
const start = /\bexport\s+default\s+/.exec(source);
|
|
@@ -237,12 +247,15 @@ function readDefaultExportIdentity(source) {
|
|
|
237
247
|
if (fn) return { kind: "function", name: fn[1] ?? null };
|
|
238
248
|
const cls = CLASS_DEFAULT_RE.exec(tail);
|
|
239
249
|
if (cls) return { kind: "class", name: cls[1] ?? null };
|
|
250
|
+
if (ARROW_DEFAULT_RE.test(tail)) return { kind: "function", name: null };
|
|
240
251
|
const identifier = IDENTIFIER_DEFAULT_RE.exec(tail);
|
|
241
252
|
if (identifier) return { kind: "identifier", name: identifier[1] };
|
|
242
253
|
return null;
|
|
243
254
|
}
|
|
244
255
|
function isDefaultExportIdentityRewrite(before, after) {
|
|
245
|
-
if (!before
|
|
256
|
+
if (!before) return false;
|
|
257
|
+
if (before.name === null) return true;
|
|
258
|
+
if (!after) return false;
|
|
246
259
|
if (before.name === after.name) return false;
|
|
247
260
|
return isComponentShaped(before) && isComponentShaped(after);
|
|
248
261
|
}
|
|
@@ -250,33 +263,99 @@ function isComponentShaped(identity) {
|
|
|
250
263
|
return identity.name === null || /^[A-Z]/.test(identity.name);
|
|
251
264
|
}
|
|
252
265
|
|
|
266
|
+
// hmr-generation-fence.ts
|
|
267
|
+
function generationIdentity(update) {
|
|
268
|
+
const type = typeof update.type === "string" ? update.type : null;
|
|
269
|
+
const acceptedPath = typeof update.acceptedPath === "string" ? update.acceptedPath : typeof update.path === "string" ? update.path : null;
|
|
270
|
+
if (!type || !acceptedPath) return null;
|
|
271
|
+
return `${type}\0${acceptedPath}`;
|
|
272
|
+
}
|
|
273
|
+
function createHmrGenerationFence() {
|
|
274
|
+
const newestTimestampByIdentity = /* @__PURE__ */ new Map();
|
|
275
|
+
return {
|
|
276
|
+
filter(updates) {
|
|
277
|
+
const accepted = [];
|
|
278
|
+
for (const update of updates) {
|
|
279
|
+
const identity = generationIdentity(update);
|
|
280
|
+
const timestamp = update.timestamp;
|
|
281
|
+
if (identity === null || typeof timestamp !== "number" || !Number.isFinite(timestamp)) {
|
|
282
|
+
accepted.push(update);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const newestTimestamp = newestTimestampByIdentity.get(identity);
|
|
286
|
+
if (newestTimestamp !== void 0 && timestamp < newestTimestamp) {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (newestTimestamp === void 0 || timestamp > newestTimestamp) {
|
|
290
|
+
newestTimestampByIdentity.set(identity, timestamp);
|
|
291
|
+
}
|
|
292
|
+
accepted.push(update);
|
|
293
|
+
}
|
|
294
|
+
return accepted;
|
|
295
|
+
},
|
|
296
|
+
clear() {
|
|
297
|
+
newestTimestampByIdentity.clear();
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
253
302
|
// missed-change-sweep.ts
|
|
254
303
|
var MISSED_CHANGE_WATCHER_GRACE_MS = 1e3;
|
|
304
|
+
var MISSED_CHANGE_MAX_EMITS_PER_REVISION = 3;
|
|
255
305
|
function createMissedChangeSweep(args) {
|
|
256
306
|
const now = args.now ?? Date.now;
|
|
257
307
|
const graceMs = args.watcherGraceMs ?? MISSED_CHANGE_WATCHER_GRACE_MS;
|
|
308
|
+
const maxEmits = args.maxEmitsPerRevision ?? MISSED_CHANGE_MAX_EMITS_PER_REVISION;
|
|
258
309
|
const lastSeenMtimeMs = /* @__PURE__ */ new Map();
|
|
310
|
+
const pending = /* @__PURE__ */ new Map();
|
|
259
311
|
return {
|
|
260
312
|
async sweep() {
|
|
261
313
|
const emitted = [];
|
|
262
314
|
for (const [file, modules] of args.listServedFiles()) {
|
|
263
315
|
const mtimeMs = await args.statMtimeMs(file);
|
|
264
|
-
if (mtimeMs === null)
|
|
265
|
-
|
|
266
|
-
if (previous === void 0 || mtimeMs <= previous) {
|
|
267
|
-
lastSeenMtimeMs.set(file, mtimeMs);
|
|
316
|
+
if (mtimeMs === null) {
|
|
317
|
+
pending.delete(file);
|
|
268
318
|
continue;
|
|
269
319
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
break;
|
|
320
|
+
let previous = lastSeenMtimeMs.get(file);
|
|
321
|
+
if (previous === void 0) {
|
|
322
|
+
const coveredMtimeMs = args.lastHotUpdateMtimeMs?.(file);
|
|
323
|
+
if (coveredMtimeMs === void 0 || coveredMtimeMs >= mtimeMs) {
|
|
324
|
+
lastSeenMtimeMs.set(file, mtimeMs);
|
|
325
|
+
continue;
|
|
277
326
|
}
|
|
327
|
+
previous = coveredMtimeMs;
|
|
328
|
+
lastSeenMtimeMs.set(file, coveredMtimeMs);
|
|
329
|
+
}
|
|
330
|
+
if (mtimeMs > previous) {
|
|
331
|
+
if (now() - mtimeMs < graceMs) continue;
|
|
332
|
+
lastSeenMtimeMs.set(file, mtimeMs);
|
|
333
|
+
} else if (mtimeMs < previous) {
|
|
334
|
+
lastSeenMtimeMs.set(file, mtimeMs);
|
|
278
335
|
}
|
|
279
|
-
|
|
336
|
+
const entry = pending.get(file);
|
|
337
|
+
if (mtimeMs <= previous && entry === void 0) continue;
|
|
338
|
+
const hotUpdateMtimeMs = args.lastHotUpdateMtimeMs?.(file);
|
|
339
|
+
let delivered;
|
|
340
|
+
if (hotUpdateMtimeMs !== void 0) {
|
|
341
|
+
delivered = hotUpdateMtimeMs >= mtimeMs;
|
|
342
|
+
} else {
|
|
343
|
+
delivered = false;
|
|
344
|
+
for (const module of modules) {
|
|
345
|
+
if ((module.lastInvalidationTimestamp ?? 0) >= mtimeMs) {
|
|
346
|
+
delivered = true;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (delivered) {
|
|
352
|
+
pending.delete(file);
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const revision = entry !== void 0 && entry.mtimeMs === mtimeMs ? entry : { mtimeMs, emits: 0 };
|
|
356
|
+
pending.set(file, revision);
|
|
357
|
+
if (revision.emits >= maxEmits) continue;
|
|
358
|
+
revision.emits += 1;
|
|
280
359
|
args.emitChange(file);
|
|
281
360
|
emitted.push(file);
|
|
282
361
|
}
|
|
@@ -285,6 +364,181 @@ function createMissedChangeSweep(args) {
|
|
|
285
364
|
};
|
|
286
365
|
}
|
|
287
366
|
|
|
367
|
+
// rapid-hot-update-replay.ts
|
|
368
|
+
var RAPID_HOT_UPDATE_QUIET_MS = 100;
|
|
369
|
+
function createRapidHotUpdateReplay(options) {
|
|
370
|
+
const quietMs = options?.quietMs ?? RAPID_HOT_UPDATE_QUIET_MS;
|
|
371
|
+
const schedule = options?.schedule ?? setTimeout;
|
|
372
|
+
const cancel = options?.cancel ?? clearTimeout;
|
|
373
|
+
const bursts = /* @__PURE__ */ new Map();
|
|
374
|
+
const armGate = (burst, previous) => {
|
|
375
|
+
if (burst.eventCount < 2) return;
|
|
376
|
+
if (previous?.gate && previous.release) {
|
|
377
|
+
burst.gate = previous.gate;
|
|
378
|
+
burst.release = previous.release;
|
|
379
|
+
previous.release = void 0;
|
|
380
|
+
if (previous.expiry) cancel(previous.expiry);
|
|
381
|
+
} else {
|
|
382
|
+
burst.gate = new Promise((resolve2) => {
|
|
383
|
+
burst.release = resolve2;
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
burst.expiry = schedule(() => burst.release?.(), quietMs * 2);
|
|
387
|
+
};
|
|
388
|
+
return {
|
|
389
|
+
observe(file, replay) {
|
|
390
|
+
const previous = bursts.get(file);
|
|
391
|
+
if (previous?.timer) cancel(previous.timer);
|
|
392
|
+
const burst = {
|
|
393
|
+
eventCount: (previous?.eventCount ?? 0) + 1,
|
|
394
|
+
replay
|
|
395
|
+
};
|
|
396
|
+
armGate(burst, previous);
|
|
397
|
+
burst.timer = schedule(() => {
|
|
398
|
+
if (bursts.get(file) !== burst) return;
|
|
399
|
+
bursts.delete(file);
|
|
400
|
+
if (burst.expiry) cancel(burst.expiry);
|
|
401
|
+
burst.release?.();
|
|
402
|
+
if (burst.eventCount < 2) return;
|
|
403
|
+
const replayAllowance = {
|
|
404
|
+
eventCount: -1,
|
|
405
|
+
replay: burst.replay
|
|
406
|
+
};
|
|
407
|
+
replayAllowance.timer = schedule(() => {
|
|
408
|
+
if (bursts.get(file) === replayAllowance) bursts.delete(file);
|
|
409
|
+
}, quietMs);
|
|
410
|
+
bursts.set(file, replayAllowance);
|
|
411
|
+
burst.replay();
|
|
412
|
+
}, quietMs);
|
|
413
|
+
bursts.set(file, burst);
|
|
414
|
+
},
|
|
415
|
+
settled(file) {
|
|
416
|
+
return bursts.get(file)?.gate ?? Promise.resolve();
|
|
417
|
+
},
|
|
418
|
+
clear() {
|
|
419
|
+
for (const burst of bursts.values()) {
|
|
420
|
+
if (burst.timer) cancel(burst.timer);
|
|
421
|
+
if (burst.expiry) cancel(burst.expiry);
|
|
422
|
+
burst.release?.();
|
|
423
|
+
}
|
|
424
|
+
bursts.clear();
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// tailwind-scan-net.ts
|
|
430
|
+
var SCANNABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
431
|
+
"ts",
|
|
432
|
+
"tsx",
|
|
433
|
+
"js",
|
|
434
|
+
"jsx",
|
|
435
|
+
"mjs",
|
|
436
|
+
"cjs",
|
|
437
|
+
"html",
|
|
438
|
+
"mdx",
|
|
439
|
+
"md",
|
|
440
|
+
"svelte",
|
|
441
|
+
"vue",
|
|
442
|
+
"astro"
|
|
443
|
+
]);
|
|
444
|
+
var IGNORED_PATH_SEGMENTS = [
|
|
445
|
+
"/node_modules/",
|
|
446
|
+
"/.git/",
|
|
447
|
+
"/.vite/",
|
|
448
|
+
"/.tempo/"
|
|
449
|
+
];
|
|
450
|
+
var TAILWIND_SCAN_NET_DEBOUNCE_MS = 100;
|
|
451
|
+
var TAILWIND_SCAN_NET_MAX_POKES_PER_PAIR = 2;
|
|
452
|
+
var POKE_LEDGER_MAX_ENTRIES = 2e4;
|
|
453
|
+
function normalizeSlashes(path) {
|
|
454
|
+
return path.replace(/\\/g, "/");
|
|
455
|
+
}
|
|
456
|
+
function fileExtension(path) {
|
|
457
|
+
const base = path.slice(path.lastIndexOf("/") + 1);
|
|
458
|
+
const dot = base.lastIndexOf(".");
|
|
459
|
+
return dot <= 0 ? "" : base.slice(dot + 1).toLowerCase();
|
|
460
|
+
}
|
|
461
|
+
function isScannableSourceFile(file) {
|
|
462
|
+
const normalized = normalizeSlashes(file);
|
|
463
|
+
if (!SCANNABLE_EXTENSIONS.has(fileExtension(normalized))) return false;
|
|
464
|
+
return !IGNORED_PATH_SEGMENTS.some(
|
|
465
|
+
(segment) => normalized.includes(segment)
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
function isScanDep(dep) {
|
|
469
|
+
if (dep.includes("*")) return true;
|
|
470
|
+
const ext = fileExtension(normalizeSlashes(dep));
|
|
471
|
+
return ext !== "" && ext !== "css" && SCANNABLE_EXTENSIONS.has(ext);
|
|
472
|
+
}
|
|
473
|
+
function cssEntryNeedsRescanFor(entry, file) {
|
|
474
|
+
if (entry.deps === null) return false;
|
|
475
|
+
const normalizedFile = normalizeSlashes(file);
|
|
476
|
+
let scansClasses = false;
|
|
477
|
+
for (const dep of entry.deps) {
|
|
478
|
+
const normalizedDep = normalizeSlashes(dep);
|
|
479
|
+
if (normalizedDep === normalizedFile) return false;
|
|
480
|
+
if (!scansClasses && isScanDep(normalizedDep)) scansClasses = true;
|
|
481
|
+
}
|
|
482
|
+
return scansClasses;
|
|
483
|
+
}
|
|
484
|
+
function createTailwindScanNet(args) {
|
|
485
|
+
const debounceMs = args.debounceMs ?? TAILWIND_SCAN_NET_DEBOUNCE_MS;
|
|
486
|
+
const maxPokesPerPair = args.maxPokesPerPair ?? TAILWIND_SCAN_NET_MAX_POKES_PER_PAIR;
|
|
487
|
+
const pendingCssFiles = /* @__PURE__ */ new Set();
|
|
488
|
+
const pokeLedger = /* @__PURE__ */ new Map();
|
|
489
|
+
const countedThisWindow = /* @__PURE__ */ new Set();
|
|
490
|
+
let flushTimer = null;
|
|
491
|
+
let lastFlushAt = Number.NEGATIVE_INFINITY;
|
|
492
|
+
let disposed = false;
|
|
493
|
+
const flush = () => {
|
|
494
|
+
flushTimer = null;
|
|
495
|
+
lastFlushAt = Date.now();
|
|
496
|
+
countedThisWindow.clear();
|
|
497
|
+
const cssFiles = [...pendingCssFiles];
|
|
498
|
+
pendingCssFiles.clear();
|
|
499
|
+
for (const cssFile of cssFiles) {
|
|
500
|
+
args.emitChange(cssFile);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
return {
|
|
504
|
+
handleWatcherFile(file) {
|
|
505
|
+
if (disposed) return false;
|
|
506
|
+
if (!isScannableSourceFile(file)) return false;
|
|
507
|
+
let scheduled = false;
|
|
508
|
+
for (const entry of args.listCssEntries()) {
|
|
509
|
+
if (!cssEntryNeedsRescanFor(entry, file)) continue;
|
|
510
|
+
const pairKey = `${entry.cssFile}\0${normalizeSlashes(file)}`;
|
|
511
|
+
if (!countedThisWindow.has(pairKey)) {
|
|
512
|
+
const pokes = pokeLedger.get(pairKey) ?? 0;
|
|
513
|
+
if (pokes >= maxPokesPerPair) continue;
|
|
514
|
+
if (pokeLedger.size >= POKE_LEDGER_MAX_ENTRIES) pokeLedger.clear();
|
|
515
|
+
pokeLedger.set(pairKey, pokes + 1);
|
|
516
|
+
countedThisWindow.add(pairKey);
|
|
517
|
+
}
|
|
518
|
+
pendingCssFiles.add(entry.cssFile);
|
|
519
|
+
scheduled = true;
|
|
520
|
+
}
|
|
521
|
+
if (scheduled && flushTimer === null) {
|
|
522
|
+
const sinceLastFlush = Date.now() - lastFlushAt;
|
|
523
|
+
const delay = sinceLastFlush >= debounceMs ? 0 : debounceMs;
|
|
524
|
+
flushTimer = setTimeout(flush, delay);
|
|
525
|
+
flushTimer.unref?.();
|
|
526
|
+
}
|
|
527
|
+
return scheduled;
|
|
528
|
+
},
|
|
529
|
+
dispose() {
|
|
530
|
+
disposed = true;
|
|
531
|
+
pendingCssFiles.clear();
|
|
532
|
+
pokeLedger.clear();
|
|
533
|
+
countedThisWindow.clear();
|
|
534
|
+
if (flushTimer !== null) {
|
|
535
|
+
clearTimeout(flushTimer);
|
|
536
|
+
flushTimer = null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
288
542
|
// index.ts
|
|
289
543
|
var DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx"];
|
|
290
544
|
var DEFAULT_EXCLUDE = ["**/node_modules/**"];
|
|
@@ -292,6 +546,17 @@ var ROOT_META_NAME = "tempo-project-root";
|
|
|
292
546
|
var SOURCE_IDENTITY_ROOT_META_NAME = "tempo-source-identity-root";
|
|
293
547
|
var INTERACT_PROJECTION_CLIENT_PATH = "/@tempo/interact-projection";
|
|
294
548
|
var INTERACT_PROJECTION_CLIENT_ID = "\0tempo:interact-projection";
|
|
549
|
+
var INTERACT_PROJECTION_SDK_SPECIFIER = "tempo-sdk/canvas/interact-projection";
|
|
550
|
+
function resolveOwnInteractProjectionModule() {
|
|
551
|
+
const selfDir = dirname(fileURLToPath(import.meta.url));
|
|
552
|
+
for (const candidate of [
|
|
553
|
+
join(selfDir, "canvas", "interact-projection.ts"),
|
|
554
|
+
join(selfDir, "canvas", "interact-projection.js")
|
|
555
|
+
]) {
|
|
556
|
+
if (existsSync(candidate)) return candidate.replace(/\\/g, "/");
|
|
557
|
+
}
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
295
560
|
var INTERACT_PROJECTION_BOOTSTRAP = `
|
|
296
561
|
(function() {
|
|
297
562
|
if (window.parent === window || (window.name !== ${JSON.stringify(TEMPO_INTERACT_FRAME_NAME)} && !window.name.startsWith(${JSON.stringify(`${TEMPO_INTERACT_FRAME_NAME}:`)}))) return;
|
|
@@ -328,6 +593,9 @@ var INTERACT_PROJECTION_BOOTSTRAP = `
|
|
|
328
593
|
function cleanModuleId(id) {
|
|
329
594
|
return id.replace(/[?#].*$/, "");
|
|
330
595
|
}
|
|
596
|
+
function fsPathFromModuleId(id) {
|
|
597
|
+
return cleanModuleId(id).replace(/^\/@fs\//, "/");
|
|
598
|
+
}
|
|
331
599
|
function isCanvasHostRequest(requestPath) {
|
|
332
600
|
const url = new URL(requestPath, "http://tempo.local");
|
|
333
601
|
return url.pathname.replace(/\/+$/, "") === "/tempo-host";
|
|
@@ -362,7 +630,7 @@ function barePackageName(specifier) {
|
|
|
362
630
|
return packageName && /^@?[A-Za-z0-9_][A-Za-z0-9._/-]*$/.test(packageName) ? packageName : void 0;
|
|
363
631
|
}
|
|
364
632
|
function resolvedIdMatchesFile(id, file) {
|
|
365
|
-
const resolvedFile =
|
|
633
|
+
const resolvedFile = fsPathFromModuleId(id);
|
|
366
634
|
try {
|
|
367
635
|
return realpathSync2.native(resolvedFile) === realpathSync2.native(file);
|
|
368
636
|
} catch {
|
|
@@ -386,7 +654,10 @@ function hasRootMetaTag(html) {
|
|
|
386
654
|
function hasSourceIdentityRootMetaTag(html) {
|
|
387
655
|
return /<meta[^>]+name=["']tempo-source-identity-root["'][^>]*>/i.test(html);
|
|
388
656
|
}
|
|
389
|
-
function
|
|
657
|
+
function isSameError(left, right) {
|
|
658
|
+
return left.type === right.type && left.message === right.message && left.loc?.line === right.loc?.line && left.loc?.column === right.loc?.column;
|
|
659
|
+
}
|
|
660
|
+
function createErrorServer(onErrorFile) {
|
|
390
661
|
const errorsByFile = /* @__PURE__ */ new Map();
|
|
391
662
|
function getMostRecentError() {
|
|
392
663
|
if (errorsByFile.size === 0) return null;
|
|
@@ -406,9 +677,15 @@ function createErrorServer() {
|
|
|
406
677
|
get currentError() {
|
|
407
678
|
return getMostRecentError();
|
|
408
679
|
},
|
|
680
|
+
get errorFiles() {
|
|
681
|
+
return [...errorsByFile.keys()].filter((file) => file !== "unknown");
|
|
682
|
+
},
|
|
409
683
|
clients: /* @__PURE__ */ new Set(),
|
|
410
684
|
setError(error) {
|
|
411
685
|
const key = error.file ?? error.loc?.file ?? "unknown";
|
|
686
|
+
const recorded = errorsByFile.get(key);
|
|
687
|
+
if (recorded && isSameError(recorded, error)) return;
|
|
688
|
+
if (key !== "unknown" && !recorded) onErrorFile?.(key);
|
|
412
689
|
errorsByFile.delete(key);
|
|
413
690
|
errorsByFile.set(key, error);
|
|
414
691
|
broadcastCurrentState();
|
|
@@ -439,9 +716,102 @@ function readBody(req) {
|
|
|
439
716
|
req.on("error", reject);
|
|
440
717
|
});
|
|
441
718
|
}
|
|
442
|
-
|
|
719
|
+
var CANVAS_HOST_WRAPPER_URL = "/.tempo/tempo-host";
|
|
720
|
+
function readGeneratedCanvasPaths(source) {
|
|
721
|
+
const paths = /* @__PURE__ */ new Set();
|
|
722
|
+
const canvasPathPattern = /\bcanvasPath:\s*("(?:\\.|[^"\\])*")/g;
|
|
723
|
+
for (const match of source.matchAll(canvasPathPattern)) {
|
|
724
|
+
try {
|
|
725
|
+
const parsed = JSON.parse(match[1] ?? "");
|
|
726
|
+
if (typeof parsed !== "string") continue;
|
|
727
|
+
const normalized = normalizeCanvasRegistrationPath(parsed);
|
|
728
|
+
if (normalized) paths.add(normalized);
|
|
729
|
+
} catch {
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return [...paths];
|
|
733
|
+
}
|
|
734
|
+
async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
735
|
+
const wrapperPath = resolve(server.config.root, ".tempo", "tempo-host.tsx");
|
|
736
|
+
let wrapperSource;
|
|
737
|
+
try {
|
|
738
|
+
wrapperSource = readFileSync(wrapperPath, "utf8");
|
|
739
|
+
} catch (error) {
|
|
740
|
+
throw new Error(
|
|
741
|
+
`Canvas host wrapper is unavailable at ${wrapperPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
const registeredCanvasPaths = readGeneratedCanvasPaths(wrapperSource);
|
|
745
|
+
if (!registeredCanvasPaths.includes(canvasPath)) {
|
|
746
|
+
throw Object.assign(
|
|
747
|
+
new Error(
|
|
748
|
+
`Generated canvas host wrapper does not contain ${JSON.stringify(
|
|
749
|
+
canvasPath
|
|
750
|
+
)}`
|
|
751
|
+
),
|
|
752
|
+
{ statusCode: 409 }
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
const canonicalWrapperPath = realpathSync2(wrapperPath);
|
|
756
|
+
await retransformCanvasHostWrapper(
|
|
757
|
+
server.environments?.client ?? server,
|
|
758
|
+
canonicalWrapperPath,
|
|
759
|
+
wrapperPath
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
async function retransformCanvasHostWrapper(transformer, canonicalWrapperPath, wrapperPath) {
|
|
763
|
+
const modules = transformer.moduleGraph.getModulesByFile(canonicalWrapperPath) ?? transformer.moduleGraph.getModulesByFile(wrapperPath);
|
|
764
|
+
for (const module of modules ?? []) {
|
|
765
|
+
transformer.moduleGraph.invalidateModule(module);
|
|
766
|
+
}
|
|
767
|
+
const result = await transformer.transformRequest(CANVAS_HOST_WRAPPER_URL);
|
|
768
|
+
if (!result) {
|
|
769
|
+
throw new Error(
|
|
770
|
+
`Vite did not transform ${CANVAS_HOST_WRAPPER_URL} after registration`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
function writeCanvasRegistrationResponseHeaders(res) {
|
|
775
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
776
|
+
res.setHeader(CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER, "1");
|
|
777
|
+
}
|
|
778
|
+
function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
443
779
|
const url = req.url;
|
|
444
780
|
if (!url?.startsWith("/__tempo/")) return next();
|
|
781
|
+
if (url === CANVAS_HOST_REGISTRATION_ENDPOINT && req.method === "OPTIONS") {
|
|
782
|
+
writeCanvasRegistrationResponseHeaders(res);
|
|
783
|
+
res.writeHead(204, {
|
|
784
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
785
|
+
"Access-Control-Allow-Headers": "content-type"
|
|
786
|
+
});
|
|
787
|
+
res.end();
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
if (url === CANVAS_HOST_REGISTRATION_ENDPOINT && req.method === "POST") {
|
|
791
|
+
writeCanvasRegistrationResponseHeaders(res);
|
|
792
|
+
void readBody(req).then(async (body) => {
|
|
793
|
+
const parsed = JSON.parse(body);
|
|
794
|
+
const canvasPath = typeof parsed.canvasPath === "string" ? normalizeCanvasRegistrationPath(parsed.canvasPath) : "";
|
|
795
|
+
if (!canvasPath) {
|
|
796
|
+
throw Object.assign(
|
|
797
|
+
new Error("canvasPath must be a non-empty string"),
|
|
798
|
+
{ statusCode: 400 }
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
await synchronizeCanvasHostRegistrationTransform(
|
|
802
|
+
viteServer,
|
|
803
|
+
canvasPath
|
|
804
|
+
);
|
|
805
|
+
res.statusCode = 200;
|
|
806
|
+
res.setHeader("Content-Type", "application/json");
|
|
807
|
+
res.end(JSON.stringify({ canvasPath }));
|
|
808
|
+
}).catch((error) => {
|
|
809
|
+
res.statusCode = typeof error === "object" && error !== null && "statusCode" in error && typeof error.statusCode === "number" ? error.statusCode : 500;
|
|
810
|
+
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
811
|
+
res.end(error instanceof Error ? error.message : String(error));
|
|
812
|
+
});
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
445
815
|
if (url === "/__tempo/report-error" && req.method === "POST") {
|
|
446
816
|
readBody(req).then((body) => {
|
|
447
817
|
try {
|
|
@@ -487,9 +857,21 @@ function handleTempoMiddleware(errorServer, req, res, next) {
|
|
|
487
857
|
next();
|
|
488
858
|
}
|
|
489
859
|
var MISSED_CHANGE_SWEEP_INTERVAL_MS = 3e3;
|
|
490
|
-
|
|
860
|
+
var COMPILE_ERROR_POLL_MAX_INTERVAL_MS = 3e4;
|
|
861
|
+
function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs, pollCompileErrorRecovery) {
|
|
491
862
|
const sweep = createMissedChangeSweep({
|
|
492
|
-
listServedFiles: () =>
|
|
863
|
+
listServedFiles: () => {
|
|
864
|
+
const files = new Map(
|
|
865
|
+
server.moduleGraph?.fileToModulesMap ?? /* @__PURE__ */ new Map()
|
|
866
|
+
);
|
|
867
|
+
const errorFiles = listErrorFiles();
|
|
868
|
+
for (const errorFile of errorFiles) {
|
|
869
|
+
const cleanFile = fsPathFromModuleId(errorFile);
|
|
870
|
+
const file = isAbsolute(cleanFile) ? cleanFile : resolve(server.config.root, cleanFile);
|
|
871
|
+
if (!files.has(file)) files.set(file, []);
|
|
872
|
+
}
|
|
873
|
+
return files.entries();
|
|
874
|
+
},
|
|
493
875
|
statMtimeMs: async (file) => {
|
|
494
876
|
try {
|
|
495
877
|
return statSync2(file).mtimeMs;
|
|
@@ -503,20 +885,56 @@ function installMissedChangeSweep(server) {
|
|
|
503
885
|
{ timestamp: true }
|
|
504
886
|
);
|
|
505
887
|
server.watcher?.emit?.("change", file);
|
|
506
|
-
}
|
|
888
|
+
},
|
|
889
|
+
lastHotUpdateMtimeMs
|
|
507
890
|
});
|
|
508
|
-
let
|
|
891
|
+
let passRunning = false;
|
|
509
892
|
const timer = setInterval(() => {
|
|
510
|
-
if (
|
|
511
|
-
|
|
512
|
-
void sweep.sweep().catch(() => {
|
|
893
|
+
if (passRunning) return;
|
|
894
|
+
passRunning = true;
|
|
895
|
+
void sweep.sweep().then(() => pollCompileErrorRecovery()).catch(() => {
|
|
513
896
|
}).finally(() => {
|
|
514
|
-
|
|
897
|
+
passRunning = false;
|
|
515
898
|
});
|
|
516
899
|
}, MISSED_CHANGE_SWEEP_INTERVAL_MS);
|
|
517
900
|
timer.unref?.();
|
|
518
901
|
server.httpServer?.once("close", () => clearInterval(timer));
|
|
519
902
|
}
|
|
903
|
+
function installTailwindScanNet(server) {
|
|
904
|
+
const net = createTailwindScanNet({
|
|
905
|
+
listCssEntries: function* () {
|
|
906
|
+
const fileToModules = server.moduleGraph?.fileToModulesMap ?? /* @__PURE__ */ new Map();
|
|
907
|
+
for (const [file, modules] of fileToModules) {
|
|
908
|
+
if (!file.endsWith(".css")) continue;
|
|
909
|
+
for (const module of modules) {
|
|
910
|
+
const deps = [];
|
|
911
|
+
for (const imported of module.importedModules ?? []) {
|
|
912
|
+
const dep = imported.file ?? imported.url ?? imported.id;
|
|
913
|
+
if (dep) deps.push(dep);
|
|
914
|
+
}
|
|
915
|
+
yield { cssFile: file, deps };
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
emitChange: (cssFile) => {
|
|
920
|
+
server.config?.logger?.info?.(
|
|
921
|
+
`[tempo] new source file outside the Tailwind scan \u2014 re-emitting change: ${cssFile}`,
|
|
922
|
+
{ timestamp: true }
|
|
923
|
+
);
|
|
924
|
+
server.watcher?.emit?.("change", cssFile);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
const onWatcherFile = (file) => {
|
|
928
|
+
net.handleWatcherFile(file);
|
|
929
|
+
};
|
|
930
|
+
server.watcher?.on?.("add", onWatcherFile);
|
|
931
|
+
server.watcher?.on?.("change", onWatcherFile);
|
|
932
|
+
server.httpServer?.once("close", () => {
|
|
933
|
+
server.watcher?.off?.("add", onWatcherFile);
|
|
934
|
+
server.watcher?.off?.("change", onWatcherFile);
|
|
935
|
+
net.dispose();
|
|
936
|
+
});
|
|
937
|
+
}
|
|
520
938
|
function tempoVitePlugin(options = {}) {
|
|
521
939
|
const enabled = !!process.env.TEMPO;
|
|
522
940
|
const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
|
|
@@ -525,7 +943,9 @@ function tempoVitePlugin(options = {}) {
|
|
|
525
943
|
let canonicalRoot = process.cwd();
|
|
526
944
|
let sourceIdentityRoot = canonicalRoot;
|
|
527
945
|
let command = "serve";
|
|
528
|
-
const errorServer = createErrorServer(
|
|
946
|
+
const errorServer = createErrorServer(
|
|
947
|
+
(file) => pinErroneousRevisionCoverage(file)
|
|
948
|
+
);
|
|
529
949
|
const unresolvedImports = /* @__PURE__ */ new Map();
|
|
530
950
|
let devServer;
|
|
531
951
|
const unresolvedImportWatchers = /* @__PURE__ */ new Map();
|
|
@@ -534,9 +954,78 @@ function tempoVitePlugin(options = {}) {
|
|
|
534
954
|
let rerunUnresolvedImportResolution = false;
|
|
535
955
|
let unresolvedImportWatchRearmTimer = null;
|
|
536
956
|
const processedUpdatePayloads = /* @__PURE__ */ new WeakSet();
|
|
957
|
+
const hmrGenerationFence = createHmrGenerationFence();
|
|
958
|
+
const rapidHotUpdateReplay = createRapidHotUpdateReplay();
|
|
959
|
+
const hotUpdateMtimesMs = /* @__PURE__ */ new Map();
|
|
960
|
+
const normalizedFileKey = (file) => file.replace(/\\/g, "/");
|
|
961
|
+
const burstKey = (file) => normalizedFileKey(fsPathFromModuleId(file));
|
|
962
|
+
const recordHotUpdateCoverage = (file) => {
|
|
963
|
+
const cleanFile = fsPathFromModuleId(file);
|
|
964
|
+
const key = normalizedFileKey(cleanFile);
|
|
965
|
+
try {
|
|
966
|
+
hotUpdateMtimesMs.set(key, statSync2(cleanFile).mtimeMs);
|
|
967
|
+
} catch {
|
|
968
|
+
hotUpdateMtimesMs.delete(key);
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
const pinErroneousRevisionCoverage = (file) => {
|
|
972
|
+
recordHotUpdateCoverage(file);
|
|
973
|
+
};
|
|
974
|
+
const hasActiveCompileError = (file) => errorServer.errorFiles.some((errorFile) => moduleIdsMatch(errorFile, file));
|
|
975
|
+
const recoverActiveCompileError = async (server, file) => {
|
|
976
|
+
if (!hasActiveCompileError(file)) return false;
|
|
977
|
+
const cleanFile = fsPathFromModuleId(file);
|
|
978
|
+
const requestId = `/@fs/${cleanFile.replace(/^\/+/, "")}`;
|
|
979
|
+
const clientEnvironment = server.environments?.client;
|
|
980
|
+
try {
|
|
981
|
+
const result = clientEnvironment ? await clientEnvironment.transformRequest(requestId) : await server.transformRequest(requestId);
|
|
982
|
+
if (!result) return false;
|
|
983
|
+
} catch {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
errorServer.clearErrorForModules([file, cleanFile, requestId]);
|
|
987
|
+
server.config.logger.info(
|
|
988
|
+
`[tempo] recovered compile-error module after validated transform: ${cleanFile}`,
|
|
989
|
+
{ timestamp: true }
|
|
990
|
+
);
|
|
991
|
+
(clientEnvironment?.hot ?? server.ws).send({
|
|
992
|
+
type: "full-reload",
|
|
993
|
+
path: "*"
|
|
994
|
+
});
|
|
995
|
+
return true;
|
|
996
|
+
};
|
|
997
|
+
const compileErrorPollSchedule = /* @__PURE__ */ new Map();
|
|
998
|
+
const pollCompileErrorRecovery = async (server) => {
|
|
999
|
+
const activeFiles = new Map(
|
|
1000
|
+
errorServer.errorFiles.map((file) => [
|
|
1001
|
+
normalizedFileKey(fsPathFromModuleId(file)),
|
|
1002
|
+
file
|
|
1003
|
+
])
|
|
1004
|
+
);
|
|
1005
|
+
for (const key of [...compileErrorPollSchedule.keys()]) {
|
|
1006
|
+
if (!activeFiles.has(key)) compileErrorPollSchedule.delete(key);
|
|
1007
|
+
}
|
|
1008
|
+
const nowMs = Date.now();
|
|
1009
|
+
for (const [key, file] of activeFiles) {
|
|
1010
|
+
const schedule = compileErrorPollSchedule.get(key);
|
|
1011
|
+
if (schedule && nowMs < schedule.nextAttemptAtMs) continue;
|
|
1012
|
+
if (await recoverActiveCompileError(server, file)) {
|
|
1013
|
+
compileErrorPollSchedule.delete(key);
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
const intervalMs = schedule?.intervalMs ?? MISSED_CHANGE_SWEEP_INTERVAL_MS;
|
|
1017
|
+
compileErrorPollSchedule.set(key, {
|
|
1018
|
+
nextAttemptAtMs: nowMs + intervalMs,
|
|
1019
|
+
intervalMs: Math.min(
|
|
1020
|
+
intervalMs * 2,
|
|
1021
|
+
COMPILE_ERROR_POLL_MAX_INTERVAL_MS
|
|
1022
|
+
)
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
537
1026
|
const defaultExportIdentityByFile = /* @__PURE__ */ new Map();
|
|
538
1027
|
const canonicalIdentityKey = (idOrFile) => {
|
|
539
|
-
const file =
|
|
1028
|
+
const file = fsPathFromModuleId(idOrFile);
|
|
540
1029
|
try {
|
|
541
1030
|
return realpathSync2.native(file);
|
|
542
1031
|
} catch {
|
|
@@ -785,6 +1274,14 @@ function tempoVitePlugin(options = {}) {
|
|
|
785
1274
|
if (id === INTERACT_PROJECTION_CLIENT_PATH) {
|
|
786
1275
|
return INTERACT_PROJECTION_CLIENT_ID;
|
|
787
1276
|
}
|
|
1277
|
+
if (id === INTERACT_PROJECTION_SDK_SPECIFIER && importer === INTERACT_PROJECTION_CLIENT_ID) {
|
|
1278
|
+
const resolved = await this.resolve(id, importer, {
|
|
1279
|
+
...resolveOptions,
|
|
1280
|
+
skipSelf: true
|
|
1281
|
+
});
|
|
1282
|
+
if (resolved) return resolved;
|
|
1283
|
+
return resolveOwnInteractProjectionModule();
|
|
1284
|
+
}
|
|
788
1285
|
if (enabled && importer && !importer.startsWith("\0")) {
|
|
789
1286
|
const packageName = barePackageName(id);
|
|
790
1287
|
if (!isRelativeImportSpecifier(id) && !packageName) return null;
|
|
@@ -803,13 +1300,21 @@ function tempoVitePlugin(options = {}) {
|
|
|
803
1300
|
return null;
|
|
804
1301
|
}
|
|
805
1302
|
},
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
1303
|
+
// `order: "pre"` + a null return: this hook never loads anything of its
|
|
1304
|
+
// own for a project file, it only decides WHEN Vite core is allowed to
|
|
1305
|
+
// read it. Awaiting the burst gate here (rather than in `transform`) is
|
|
1306
|
+
// what makes the content terminal — by `transform` the bytes have already
|
|
1307
|
+
// been read, so delaying there would ship a stale revision late instead of
|
|
1308
|
+
// not shipping it at all.
|
|
1309
|
+
load: {
|
|
1310
|
+
order: "pre",
|
|
1311
|
+
async handler(id) {
|
|
1312
|
+
if (id === INTERACT_PROJECTION_CLIENT_ID) {
|
|
1313
|
+
return `let stop;
|
|
809
1314
|
let disposed = false;
|
|
810
1315
|
if (window.parent !== window && (window.name === ${JSON.stringify(TEMPO_INTERACT_FRAME_NAME)} || window.name.startsWith(${JSON.stringify(`${TEMPO_INTERACT_FRAME_NAME}:`)}))) {
|
|
811
1316
|
window.__tempoInteractProjectionOwner = "vite";
|
|
812
|
-
void import(
|
|
1317
|
+
void import(${JSON.stringify(INTERACT_PROJECTION_SDK_SPECIFIER)}).then(({ installTempoInteractProjectionSource }) => {
|
|
813
1318
|
if (disposed) return;
|
|
814
1319
|
stop = installTempoInteractProjectionSource();
|
|
815
1320
|
});
|
|
@@ -818,11 +1323,20 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
818
1323
|
disposed = true;
|
|
819
1324
|
stop?.();
|
|
820
1325
|
});`;
|
|
1326
|
+
}
|
|
1327
|
+
if (!enabled || command === "build" || id.startsWith("\0")) return null;
|
|
1328
|
+
await rapidHotUpdateReplay.settled(burstKey(id));
|
|
1329
|
+
return null;
|
|
821
1330
|
}
|
|
822
|
-
return null;
|
|
823
1331
|
},
|
|
824
1332
|
// Expose error server for testing
|
|
825
1333
|
_tempoErrorServer: errorServer,
|
|
1334
|
+
// Test seam pinning the exact evidence the missed-change sweep reads.
|
|
1335
|
+
_tempoHotUpdateState: {
|
|
1336
|
+
lastHotUpdateMtimeMs(file) {
|
|
1337
|
+
return hotUpdateMtimesMs.get(normalizedFileKey(file));
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
826
1340
|
_tempoUnresolvedImportState: {
|
|
827
1341
|
get size() {
|
|
828
1342
|
return unresolvedImports.size;
|
|
@@ -869,14 +1383,26 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
869
1383
|
},
|
|
870
1384
|
configureServer(server) {
|
|
871
1385
|
if (!enabled) return;
|
|
1386
|
+
const ownInteractModule = resolveOwnInteractProjectionModule();
|
|
1387
|
+
const allow = server.config?.server?.fs?.allow;
|
|
1388
|
+
if (ownInteractModule && Array.isArray(allow)) {
|
|
1389
|
+
const ownDir = dirname(ownInteractModule);
|
|
1390
|
+
if (!allow.includes(ownDir)) allow.push(ownDir);
|
|
1391
|
+
}
|
|
872
1392
|
devServer = server;
|
|
873
1393
|
syncUnresolvedImportWatcher();
|
|
874
1394
|
server.watcher?.once?.("close", closeUnresolvedImportWatchers);
|
|
875
1395
|
server.httpServer?.once("close", closeUnresolvedImportWatchers);
|
|
876
1396
|
server.middlewares.use((req, res, next) => {
|
|
877
|
-
handleTempoMiddleware(errorServer, req, res, next);
|
|
1397
|
+
handleTempoMiddleware(errorServer, server, req, res, next);
|
|
878
1398
|
});
|
|
879
|
-
installMissedChangeSweep(
|
|
1399
|
+
installMissedChangeSweep(
|
|
1400
|
+
server,
|
|
1401
|
+
() => errorServer.errorFiles,
|
|
1402
|
+
(file) => hotUpdateMtimesMs.get(normalizedFileKey(file)),
|
|
1403
|
+
() => pollCompileErrorRecovery(server)
|
|
1404
|
+
);
|
|
1405
|
+
installTailwindScanNet(server);
|
|
880
1406
|
const interceptHmrSend = (target) => {
|
|
881
1407
|
const orig = target.send.bind(target);
|
|
882
1408
|
target.send = ((...args) => {
|
|
@@ -896,31 +1422,58 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
896
1422
|
});
|
|
897
1423
|
} else if (typed.type === "update" && !processedUpdatePayloads.has(payload)) {
|
|
898
1424
|
processedUpdatePayloads.add(payload);
|
|
899
|
-
const
|
|
900
|
-
const
|
|
1425
|
+
const updatePayload = typed;
|
|
1426
|
+
const updates = updatePayload.updates;
|
|
1427
|
+
const acceptedUpdates = updates ? hmrGenerationFence.filter(updates) : void 0;
|
|
1428
|
+
if (updates && acceptedUpdates && acceptedUpdates.length !== updates.length) {
|
|
1429
|
+
updatePayload.updates = acceptedUpdates;
|
|
1430
|
+
}
|
|
1431
|
+
const paths = acceptedUpdates?.map((u) => u.path).filter((p) => typeof p === "string") ?? [];
|
|
901
1432
|
errorServer.clearErrorForModules(paths);
|
|
1433
|
+
if (updates && updates.length > 0 && acceptedUpdates?.length === 0) {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
902
1436
|
}
|
|
903
1437
|
}
|
|
904
1438
|
return orig(...args);
|
|
905
1439
|
});
|
|
906
1440
|
};
|
|
907
1441
|
interceptHmrSend(server.ws);
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1442
|
+
return () => {
|
|
1443
|
+
const clientHot = server.environments?.client?.hot;
|
|
1444
|
+
if (clientHot && clientHot !== server.ws) {
|
|
1445
|
+
interceptHmrSend(clientHot);
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
912
1448
|
},
|
|
913
1449
|
closeBundle() {
|
|
914
1450
|
devServer = void 0;
|
|
1451
|
+
rapidHotUpdateReplay.clear();
|
|
1452
|
+
hmrGenerationFence.clear();
|
|
1453
|
+
hotUpdateMtimesMs.clear();
|
|
1454
|
+
compileErrorPollSchedule.clear();
|
|
915
1455
|
closeUnresolvedImportWatchers();
|
|
916
1456
|
},
|
|
917
1457
|
hotUpdate: {
|
|
918
1458
|
order: "post",
|
|
919
|
-
handler(context) {
|
|
920
|
-
if (this.environment.
|
|
1459
|
+
async handler(context) {
|
|
1460
|
+
if (!enabled || this.environment.config.consumer !== "client") return;
|
|
1461
|
+
recordHotUpdateCoverage(context.file);
|
|
1462
|
+
if (context.type === "update" && context.modules.length > 0) {
|
|
1463
|
+
rapidHotUpdateReplay.observe(burstKey(context.file), () => {
|
|
1464
|
+
context.server.config.logger.info(
|
|
1465
|
+
`[tempo] replaying settled rapid watcher change: ${context.file}`,
|
|
1466
|
+
{ timestamp: true }
|
|
1467
|
+
);
|
|
1468
|
+
context.server.watcher.emit("change", context.file);
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
921
1471
|
if (context.type !== "create") {
|
|
922
1472
|
forgetUnresolvedImportsFrom(context.file);
|
|
923
1473
|
}
|
|
1474
|
+
if (context.type === "update" && hasActiveCompileError(context.file) && await recoverActiveCompileError(context.server, context.file)) {
|
|
1475
|
+
return [];
|
|
1476
|
+
}
|
|
924
1477
|
if (context.type === "delete") {
|
|
925
1478
|
defaultExportIdentityByFile.delete(
|
|
926
1479
|
canonicalIdentityKey(context.file)
|
|
@@ -935,8 +1488,22 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
935
1488
|
// Vite 5 compatibility. Vite 6+ prefers `hotUpdate` above.
|
|
936
1489
|
handleHotUpdate: {
|
|
937
1490
|
order: "post",
|
|
938
|
-
handler(context) {
|
|
1491
|
+
async handler(context) {
|
|
1492
|
+
if (!enabled) return;
|
|
1493
|
+
recordHotUpdateCoverage(context.file);
|
|
1494
|
+
if (context.modules.length > 0) {
|
|
1495
|
+
rapidHotUpdateReplay.observe(burstKey(context.file), () => {
|
|
1496
|
+
context.server.config.logger.info(
|
|
1497
|
+
`[tempo] replaying settled rapid watcher change: ${context.file}`,
|
|
1498
|
+
{ timestamp: true }
|
|
1499
|
+
);
|
|
1500
|
+
context.server.watcher.emit("change", context.file);
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
939
1503
|
forgetUnresolvedImportsFrom(context.file);
|
|
1504
|
+
if (hasActiveCompileError(context.file) && await recoverActiveCompileError(context.server, context.file)) {
|
|
1505
|
+
return [];
|
|
1506
|
+
}
|
|
940
1507
|
if (repairDefaultExportIdentityRewrite(context.file)) {
|
|
941
1508
|
return [];
|
|
942
1509
|
}
|