tempo-sdk 0.0.52 → 0.0.60
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/assets/index.js +4 -2
- package/dist/assets/index.js.map +1 -1
- package/dist/canvas/editor.d.ts +11 -16
- package/dist/canvas/editor.js +79 -49
- package/dist/canvas/editor.js.map +1 -1
- package/dist/canvas/index.d.ts +13 -7
- package/dist/canvas/index.js +227 -64
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.js +4 -3
- package/dist/canvas/parser.d.ts +10 -5
- package/dist/canvas/parser.js +3 -1
- package/dist/canvas/svelte.d.ts +8 -5
- package/dist/canvas/svelte.js +20 -5
- package/dist/canvas/svelte.js.map +1 -1
- package/dist/chunk-2IQD2KPS.js +219 -0
- package/dist/chunk-2IQD2KPS.js.map +1 -0
- package/dist/chunk-5BHIHP25.js +410 -0
- package/dist/chunk-5BHIHP25.js.map +1 -0
- package/dist/{chunk-PULSTDX2.js → chunk-7DT5DDSH.js} +284 -46
- package/dist/chunk-7DT5DDSH.js.map +1 -0
- package/dist/{chunk-7Y7XNHUM.js → chunk-FQSZRVSL.js} +18 -3
- package/dist/chunk-FQSZRVSL.js.map +1 -0
- package/dist/{chunk-ZZYNOX24.js → chunk-MXKZZOLM.js} +1717 -2460
- package/dist/chunk-MXKZZOLM.js.map +1 -0
- package/dist/{chunk-DX6XAXCK.js → chunk-N2TYN3RB.js} +189 -420
- package/dist/chunk-N2TYN3RB.js.map +1 -0
- package/dist/chunk-OTVBSF7U.js +1585 -0
- package/dist/chunk-OTVBSF7U.js.map +1 -0
- package/dist/chunk-TL4MGN7E.js +2570 -0
- package/dist/chunk-TL4MGN7E.js.map +1 -0
- package/dist/{chunk-QP2NTODB.js → chunk-VMTQDG4U.js} +117 -27
- package/dist/chunk-VMTQDG4U.js.map +1 -0
- package/dist/expo/plugin.cjs +1256 -16
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.d.cts +0 -1
- package/dist/expo/plugin.d.ts +0 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +1258 -16
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.d.cts +8 -5
- package/dist/expo-babel-plugin.d.ts +8 -5
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +647 -166
- package/dist/index.js.map +1 -1
- package/dist/nextjs/plugin.cjs +151 -0
- package/dist/nextjs/plugin.cjs.map +1 -1
- package/dist/nextjs/plugin.d.cts +1 -1
- package/dist/nextjs/plugin.d.ts +1 -1
- package/dist/nextjs/plugin.js +1 -1
- package/dist/nextjs-loader.cjs +1432 -35
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/nextjs.cjs +17 -2
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.d.cts +14 -3
- package/dist/nextjs.d.ts +14 -3
- package/dist/nextjs.js +1 -1
- package/dist/{page-xi1aI5a7.d.ts → page-DwLnOM5d.d.ts} +12 -6
- package/dist/{storyboard-DbtzTPvI.d.ts → storyboard-DjOF61B_.d.ts} +35 -15
- package/dist/svelte.d.ts +3 -2
- package/dist/svelte.js +103 -29
- package/dist/svelte.js.map +1 -1
- package/dist/v1-client-compat-qxaXEDm_.d.ts +23 -0
- package/package.json +5 -2
- package/dist/chunk-57KAYXHF.js +0 -19
- package/dist/chunk-57KAYXHF.js.map +0 -1
- package/dist/chunk-7Y7XNHUM.js.map +0 -1
- package/dist/chunk-CB5NJJJT.js +0 -345
- package/dist/chunk-CB5NJJJT.js.map +0 -1
- package/dist/chunk-DX6XAXCK.js.map +0 -1
- package/dist/chunk-F3KJDCMU.js +0 -19
- package/dist/chunk-F3KJDCMU.js.map +0 -1
- package/dist/chunk-PULSTDX2.js.map +0 -1
- package/dist/chunk-QP2NTODB.js.map +0 -1
- package/dist/chunk-ZZYNOX24.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
appendModuleVersionRecord,
|
|
3
|
+
computeTempoAnnotatedProps,
|
|
2
4
|
sourceVersionHash
|
|
3
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-2IQD2KPS.js";
|
|
4
6
|
import {
|
|
5
7
|
VITE_ERROR_CLIENT_PATH,
|
|
6
8
|
VITE_ERROR_CLIENT_SOURCE,
|
|
@@ -10,17 +12,174 @@ import {
|
|
|
10
12
|
import {
|
|
11
13
|
TEMPO_INTERACT_FRAME_NAME
|
|
12
14
|
} from "./chunk-65B52AR7.js";
|
|
15
|
+
import {
|
|
16
|
+
parseCanvasFile
|
|
17
|
+
} from "./chunk-VMTQDG4U.js";
|
|
13
18
|
import {
|
|
14
19
|
parseControlsFile
|
|
15
20
|
} from "./chunk-XLEKCOB7.js";
|
|
16
21
|
import "./chunk-DI2ZFAWL.js";
|
|
17
22
|
|
|
23
|
+
// canvas-component-reference.ts
|
|
24
|
+
import { realpathSync } from "fs";
|
|
25
|
+
import { dirname, isAbsolute, normalize, posix, resolve } from "path";
|
|
26
|
+
var COMPONENT_REFERENCE_ATTRIBUTE = "data-tempo-component-reference";
|
|
27
|
+
function moduleIdentity(file, specifier, resolved) {
|
|
28
|
+
const bundled = resolved?.get(specifier);
|
|
29
|
+
const target = bundled === void 0 ? specifier : bundled.replace(/\bt=\d{13}&?\b/, "").replace(/[?&]$/, "");
|
|
30
|
+
if (target.startsWith("\0")) return target;
|
|
31
|
+
const suffixAt = target.search(/[?#]/);
|
|
32
|
+
let path = (suffixAt < 0 ? target : target.slice(0, suffixAt)).replace(
|
|
33
|
+
/\\/g,
|
|
34
|
+
"/"
|
|
35
|
+
);
|
|
36
|
+
const suffix = suffixAt < 0 ? "" : target.slice(suffixAt);
|
|
37
|
+
if (bundled === void 0 && path.startsWith("."))
|
|
38
|
+
path = resolve(dirname(file), path);
|
|
39
|
+
if (!isAbsolute(path) && !/^[A-Za-z]:\//.test(path)) return target;
|
|
40
|
+
if (bundled !== void 0) {
|
|
41
|
+
try {
|
|
42
|
+
path = realpathSync.native(path);
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return normalize(path).replace(/\\/g, "/") + suffix;
|
|
47
|
+
}
|
|
48
|
+
function canvasComponentAnnotations(file, source, resolved) {
|
|
49
|
+
const result = /* @__PURE__ */ new Map();
|
|
50
|
+
if (!source.includes("tempo-sdk/canvas")) return result;
|
|
51
|
+
const parsed = parseCanvasFile(file, source);
|
|
52
|
+
for (const board of parsed.storyboards) {
|
|
53
|
+
const ref = board.component;
|
|
54
|
+
if (board.kind !== "component" || !ref?.localName || board.openingElementSpan === void 0)
|
|
55
|
+
continue;
|
|
56
|
+
const member = ref.expression.match(
|
|
57
|
+
/^\s*([$\w]+)(?:\s*\.\s*([$\w]+))?\s*$/
|
|
58
|
+
);
|
|
59
|
+
if (!member) continue;
|
|
60
|
+
let name;
|
|
61
|
+
if (ref.import) {
|
|
62
|
+
if (ref.import.kind === "namespace") {
|
|
63
|
+
if (!member[2]) continue;
|
|
64
|
+
name = member[2];
|
|
65
|
+
} else {
|
|
66
|
+
if (member[2]) continue;
|
|
67
|
+
name = ref.import.importedName;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
if (member[2]) continue;
|
|
71
|
+
name = ref.localName;
|
|
72
|
+
}
|
|
73
|
+
const specifier = ref.import?.source.replace(/\\/g, "/").replace(/[?#].*/, "");
|
|
74
|
+
const canvasDir = posix.dirname(file.replace(/\\/g, "/"));
|
|
75
|
+
const external = specifier !== void 0 && (!specifier.startsWith(".") || !posix.join(canvasDir, specifier).startsWith(`${canvasDir}/`));
|
|
76
|
+
result.set(board.openingElementSpan.start, {
|
|
77
|
+
[COMPONENT_REFERENCE_ATTRIBUTE]: JSON.stringify([
|
|
78
|
+
ref.import ? "import" : "local",
|
|
79
|
+
moduleIdentity(file, ref.import?.source ?? file, resolved),
|
|
80
|
+
name
|
|
81
|
+
]),
|
|
82
|
+
...external ? { "data-tempo-external-component": "true" } : {}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// canvas-dependency-scan.ts
|
|
89
|
+
import { relative, resolve as resolve2 } from "path";
|
|
90
|
+
function applyManagedCanvasDependencyScan(config, env = process.env) {
|
|
91
|
+
const host = env.TEMPO_CANVAS_HOST_ROOT;
|
|
92
|
+
const canvases = env.TEMPO_CANVAS_SOURCE_ROOT;
|
|
93
|
+
if (!host || !canvases || resolve2(config.root ?? process.cwd()) !== resolve2(host))
|
|
94
|
+
return;
|
|
95
|
+
const legacyGlob = [
|
|
96
|
+
relative(host, canvases).replace(/\\/g, "/"),
|
|
97
|
+
"**/index.canvas.tsx"
|
|
98
|
+
].filter(Boolean).join("/");
|
|
99
|
+
const entries = config.optimizeDeps?.entries;
|
|
100
|
+
const retained = (entries === void 0 ? [] : typeof entries === "string" ? [entries] : entries).filter(
|
|
101
|
+
(entry) => entry.replace(/\\/g, "/").replace(/^\.\//, "") !== legacyGlob
|
|
102
|
+
);
|
|
103
|
+
config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
104
|
+
config.optimizeDeps.entries = [.../* @__PURE__ */ new Set(["index.html", ...retained])];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// canvas-host-registration-work.ts
|
|
108
|
+
import { readFileSync } from "fs";
|
|
109
|
+
async function traceSlowRegistration(work, report) {
|
|
110
|
+
const startedAt = performance.now();
|
|
111
|
+
let slow = false;
|
|
112
|
+
const timer = setTimeout(() => {
|
|
113
|
+
slow = true;
|
|
114
|
+
report("pending", Math.round(performance.now() - startedAt));
|
|
115
|
+
}, 5e3);
|
|
116
|
+
const settled = (status) => {
|
|
117
|
+
const elapsedMs = Math.round(performance.now() - startedAt);
|
|
118
|
+
if (slow || elapsedMs >= 5e3) report(status, elapsedMs);
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
const result = await work();
|
|
122
|
+
settled("ready");
|
|
123
|
+
return result;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
settled("error");
|
|
126
|
+
throw error;
|
|
127
|
+
} finally {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function createRegistrationTransforms() {
|
|
132
|
+
const receipts = /* @__PURE__ */ new Map();
|
|
133
|
+
return async function confirm(file, transform) {
|
|
134
|
+
const source = readFileSync(file, "utf8");
|
|
135
|
+
const previous = receipts.get(file);
|
|
136
|
+
if (previous?.source === source && (previous.pending || previous.current())) {
|
|
137
|
+
return previous.result;
|
|
138
|
+
}
|
|
139
|
+
const receipt = {
|
|
140
|
+
source,
|
|
141
|
+
pending: true,
|
|
142
|
+
current: () => false,
|
|
143
|
+
result: Promise.resolve()
|
|
144
|
+
};
|
|
145
|
+
receipts.set(file, receipt);
|
|
146
|
+
receipt.result = Promise.resolve().then(async () => {
|
|
147
|
+
receipt.current = await transform();
|
|
148
|
+
receipt.pending = false;
|
|
149
|
+
}).catch((error) => {
|
|
150
|
+
if (receipts.get(file) === receipt) receipts.delete(file);
|
|
151
|
+
throw error;
|
|
152
|
+
});
|
|
153
|
+
return receipt.result;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function registrationReply(work, progress, poll, intervalMs = 1e3) {
|
|
157
|
+
if (!poll) {
|
|
158
|
+
await work;
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
let timer;
|
|
162
|
+
try {
|
|
163
|
+
return await Promise.race([
|
|
164
|
+
work.then(() => null),
|
|
165
|
+
new Promise((resolve5) => {
|
|
166
|
+
timer = setTimeout(() => resolve5(progress()), intervalMs);
|
|
167
|
+
})
|
|
168
|
+
]);
|
|
169
|
+
} finally {
|
|
170
|
+
clearTimeout(timer);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
18
174
|
// index.ts
|
|
19
175
|
import {
|
|
20
176
|
existsSync,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
177
|
+
openSync,
|
|
178
|
+
closeSync,
|
|
179
|
+
fstatSync,
|
|
180
|
+
readFileSync as readFileSync4,
|
|
181
|
+
realpathSync as realpathSync3,
|
|
182
|
+
statSync,
|
|
24
183
|
watch as watchFileSystem
|
|
25
184
|
} from "fs";
|
|
26
185
|
import { createRequire } from "module";
|
|
@@ -44,7 +203,7 @@ ${source}`;
|
|
|
44
203
|
}
|
|
45
204
|
|
|
46
205
|
// index.ts
|
|
47
|
-
import { dirname, isAbsolute, join, relative as relative2, resolve as
|
|
206
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join2, relative as relative2, resolve as resolve4 } from "path";
|
|
48
207
|
import { fileURLToPath } from "url";
|
|
49
208
|
import { createFilter } from "@rollup/pluginutils";
|
|
50
209
|
|
|
@@ -68,22 +227,26 @@ function getJSXMemberExpressionName(node) {
|
|
|
68
227
|
}
|
|
69
228
|
|
|
70
229
|
// ../../modules/file-parser/walk.ts
|
|
71
|
-
|
|
230
|
+
import visitorKeysImport from "oxc-parser/src-js/generated/visit/keys.js";
|
|
231
|
+
var importedKeys = visitorKeysImport;
|
|
232
|
+
var visitorKeys = importedKeys.default ?? importedKeys;
|
|
233
|
+
function walk(node, callbacks, parent = null) {
|
|
72
234
|
if (node === null || node === void 0 || typeof node !== "object") return;
|
|
73
235
|
if (Array.isArray(node)) {
|
|
74
236
|
for (const child of node) {
|
|
75
|
-
walk(child, callbacks);
|
|
237
|
+
walk(child, callbacks, parent);
|
|
76
238
|
}
|
|
77
239
|
return;
|
|
78
240
|
}
|
|
79
241
|
const record = node;
|
|
80
242
|
const type = record.type;
|
|
81
243
|
if (typeof type === "string" && type in callbacks) {
|
|
82
|
-
callbacks[type](node);
|
|
244
|
+
callbacks[type](node, parent);
|
|
83
245
|
}
|
|
246
|
+
const enclosing = typeof type === "string" ? node : parent;
|
|
84
247
|
for (const value of Object.values(record)) {
|
|
85
248
|
if (value !== null && typeof value === "object") {
|
|
86
|
-
walk(value, callbacks);
|
|
249
|
+
walk(value, callbacks, enclosing);
|
|
87
250
|
}
|
|
88
251
|
}
|
|
89
252
|
}
|
|
@@ -108,7 +271,6 @@ var ScopeFlags = {
|
|
|
108
271
|
|
|
109
272
|
// ../../modules/file-parser/scope-analyzer/scopeAnalyzer.ts
|
|
110
273
|
import { parseSync } from "oxc-parser";
|
|
111
|
-
import visitorKeysDefault from "oxc-parser/src-js/generated/visit/keys.js";
|
|
112
274
|
|
|
113
275
|
// ../../modules/annotation/annotate-file.ts
|
|
114
276
|
function formatPropValue(value) {
|
|
@@ -141,12 +303,13 @@ function annotateFile(source, filename, computeAnnotatedProps) {
|
|
|
141
303
|
const parseResult = parseSync2(filename, source);
|
|
142
304
|
const insertions = [];
|
|
143
305
|
walk(parseResult.program, {
|
|
144
|
-
JSXElement(node) {
|
|
306
|
+
JSXElement(node, parent) {
|
|
145
307
|
const element = node;
|
|
146
308
|
const tagName = getTagName(element.openingElement.name);
|
|
147
309
|
if (FRAGMENT_TAG_NAMES.has(tagName)) return;
|
|
310
|
+
const parentType = parent?.type ?? null;
|
|
148
311
|
const props = removeExistingProps(
|
|
149
|
-
computeAnnotatedProps({ element, tagName }),
|
|
312
|
+
computeAnnotatedProps({ element, tagName, parentType }),
|
|
150
313
|
getExistingAttributeNames(element)
|
|
151
314
|
);
|
|
152
315
|
if (Object.keys(props).length === 0) return;
|
|
@@ -173,78 +336,6 @@ function annotateFile(source, filename, computeAnnotatedProps) {
|
|
|
173
336
|
return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
|
|
174
337
|
}
|
|
175
338
|
|
|
176
|
-
// annotation-strategy.ts
|
|
177
|
-
import { realpathSync, statSync } from "fs";
|
|
178
|
-
import { relative } from "path";
|
|
179
|
-
var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
180
|
-
"area",
|
|
181
|
-
"base",
|
|
182
|
-
"br",
|
|
183
|
-
"col",
|
|
184
|
-
"embed",
|
|
185
|
-
"hr",
|
|
186
|
-
"img",
|
|
187
|
-
"input",
|
|
188
|
-
"link",
|
|
189
|
-
"meta",
|
|
190
|
-
"param",
|
|
191
|
-
"source",
|
|
192
|
-
"track",
|
|
193
|
-
"wbr"
|
|
194
|
-
]);
|
|
195
|
-
function isIntrinsicElement(tagName) {
|
|
196
|
-
return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
|
|
197
|
-
}
|
|
198
|
-
function hasJsxAttribute(info, attrName) {
|
|
199
|
-
for (const attr of info.element.openingElement.attributes) {
|
|
200
|
-
const name = attr.name;
|
|
201
|
-
if (name?.name === attrName) return true;
|
|
202
|
-
}
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion) {
|
|
206
|
-
return {
|
|
207
|
-
"data-tempo-filepath": filepath,
|
|
208
|
-
"data-tempo-position": info.element.openingElement.start,
|
|
209
|
-
"data-tempo-modifiedts": modifiedtsMs,
|
|
210
|
-
// Content-hash identity of the file this element was annotated from. The
|
|
211
|
-
// canvas reconcile loop equality-compares it against the write pipeline's
|
|
212
|
-
// computed version to decide whether a capture reflects a given edit.
|
|
213
|
-
"data-tempo-source-version": sourceVersion
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function computeTempoAnnotatedProps(params) {
|
|
217
|
-
const {
|
|
218
|
-
info,
|
|
219
|
-
filepath,
|
|
220
|
-
modifiedtsMs,
|
|
221
|
-
sourceVersion,
|
|
222
|
-
computeAnnotatedProps,
|
|
223
|
-
elementSupportOverrides
|
|
224
|
-
} = params;
|
|
225
|
-
const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, sourceVersion);
|
|
226
|
-
if (isIntrinsicElement(info.tagName)) {
|
|
227
|
-
return {
|
|
228
|
-
...userProps,
|
|
229
|
-
"data-tempo-supports-children": hasJsxAttribute(
|
|
230
|
-
info,
|
|
231
|
-
"data-tempo-supports-children"
|
|
232
|
-
) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
const override = elementSupportOverrides?.get(info.tagName);
|
|
236
|
-
if (override) {
|
|
237
|
-
return {
|
|
238
|
-
...userProps,
|
|
239
|
-
"data-tempo-supports-children": hasJsxAttribute(
|
|
240
|
-
info,
|
|
241
|
-
"data-tempo-supports-children"
|
|
242
|
-
) ? void 0 : override.supportsChildren
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
return userProps;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
339
|
// canvas-host-registration-contract.ts
|
|
249
340
|
var CANVAS_HOST_REGISTRATION_ENDPOINT = "/__tempo/canvas-host-registration";
|
|
250
341
|
var CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER = "x-tempo-canvas-host-registration";
|
|
@@ -281,6 +372,64 @@ function isComponentShaped(identity) {
|
|
|
281
372
|
return identity.name === null || /^[A-Z]/.test(identity.name);
|
|
282
373
|
}
|
|
283
374
|
|
|
375
|
+
// pruned-module-deletion.ts
|
|
376
|
+
function createPrunedModuleDeletionGuard() {
|
|
377
|
+
let sequence = 0;
|
|
378
|
+
let activeReceipts = 0;
|
|
379
|
+
let receipts = /* @__PURE__ */ new WeakMap();
|
|
380
|
+
return {
|
|
381
|
+
observePrune(graph, paths) {
|
|
382
|
+
const receipt = ++sequence;
|
|
383
|
+
for (const path of paths) {
|
|
384
|
+
const module = graph.urlToModuleMap.get(path);
|
|
385
|
+
if (module) {
|
|
386
|
+
if (!receipts.has(module)) activeReceipts++;
|
|
387
|
+
receipts.set(module, receipt);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
observeRequest(graph, url, base, fetchDestination, ifNoneMatch) {
|
|
392
|
+
if (!activeReceipts || ["document", "iframe", "frame"].includes(String(fetchDestination)))
|
|
393
|
+
return;
|
|
394
|
+
const requestSequence = sequence;
|
|
395
|
+
return async (status, contentType, responseEtag) => {
|
|
396
|
+
if (!activeReceipts || status < 200 || status >= 400) return;
|
|
397
|
+
if (status !== 304 && !/^text\/(?:javascript|css)(?:;|$)/i.test(String(contentType)))
|
|
398
|
+
return;
|
|
399
|
+
const etag = status === 304 ? ifNoneMatch : responseEtag;
|
|
400
|
+
if (typeof etag !== "string" || !graph.getModuleByEtag(etag)) return;
|
|
401
|
+
let moduleUrl = url;
|
|
402
|
+
if (base !== "/" && moduleUrl.startsWith(base))
|
|
403
|
+
moduleUrl = `/${moduleUrl.slice(base.length)}`;
|
|
404
|
+
try {
|
|
405
|
+
moduleUrl = decodeURI(moduleUrl).replace(/__x00__/g, "\0");
|
|
406
|
+
if (moduleUrl.startsWith("/@id/")) moduleUrl = moduleUrl.slice(5);
|
|
407
|
+
const [, id] = await graph.resolveUrl(moduleUrl);
|
|
408
|
+
const module = graph.getModuleById(id);
|
|
409
|
+
if (module && module.transformResult?.etag === etag && (receipts.get(module) ?? Infinity) <= requestSequence) {
|
|
410
|
+
receipts.delete(module);
|
|
411
|
+
activeReceipts--;
|
|
412
|
+
}
|
|
413
|
+
} catch {
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
},
|
|
417
|
+
suppressDeletion(graph, modules) {
|
|
418
|
+
if (!modules.length || !modules.every(
|
|
419
|
+
(module) => receipts.has(module) && module.importers.size === 0
|
|
420
|
+
))
|
|
421
|
+
return false;
|
|
422
|
+
const invalidated = /* @__PURE__ */ new Set();
|
|
423
|
+
for (const module of modules) graph.invalidateModule(module, invalidated);
|
|
424
|
+
return true;
|
|
425
|
+
},
|
|
426
|
+
clear() {
|
|
427
|
+
receipts = /* @__PURE__ */ new WeakMap();
|
|
428
|
+
activeReceipts = 0;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
284
433
|
// hmr-generation-fence.ts
|
|
285
434
|
function generationIdentity(update) {
|
|
286
435
|
const type = typeof update.type === "string" ? update.type : null;
|
|
@@ -318,13 +467,16 @@ function createHmrGenerationFence() {
|
|
|
318
467
|
}
|
|
319
468
|
|
|
320
469
|
// host-identity.ts
|
|
321
|
-
import { readFileSync } from "fs";
|
|
322
|
-
import { resolve } from "path";
|
|
470
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
471
|
+
import { resolve as resolve3 } from "path";
|
|
323
472
|
|
|
324
473
|
// package.json
|
|
325
474
|
var package_default = {
|
|
326
475
|
name: "tempo-sdk",
|
|
327
|
-
version: "0.0.
|
|
476
|
+
version: "0.0.60",
|
|
477
|
+
publishConfig: {
|
|
478
|
+
tag: "sdk-v2-latest"
|
|
479
|
+
},
|
|
328
480
|
type: "module",
|
|
329
481
|
description: "Tempo SDK \u2014 Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types",
|
|
330
482
|
repository: {
|
|
@@ -405,7 +557,7 @@ var package_default = {
|
|
|
405
557
|
demo: "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
|
|
406
558
|
"demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
|
|
407
559
|
test: "vitest run",
|
|
408
|
-
"test:browser": "vitest run asset-live-preview-browser.test.ts asset-popover-lifecycle-browser.test.ts component-controls-browser.test.ts canvas-controls-browser.test.ts canvas-capture-determinism-browser.test.ts canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts",
|
|
560
|
+
"test:browser": "vitest run canvas-dependency-scan-browser.test.ts pruned-module-deletion-browser.test.ts asset-live-preview-browser.test.ts asset-popover-lifecycle-browser.test.ts component-controls-browser.test.ts canvas-controls-browser.test.ts canvas-capture-determinism-browser.test.ts canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts",
|
|
409
561
|
"test:watch": "vitest",
|
|
410
562
|
"test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
|
|
411
563
|
"test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
|
|
@@ -458,6 +610,17 @@ var package_default = {
|
|
|
458
610
|
}
|
|
459
611
|
};
|
|
460
612
|
|
|
613
|
+
// release-channel.ts
|
|
614
|
+
var TEMPO_SDK_CHANNEL = package_default.publishConfig.tag;
|
|
615
|
+
function sdkChannelGeneration(channel) {
|
|
616
|
+
if (typeof channel !== "string") return null;
|
|
617
|
+
const match = /^sdk-v([1-9]\d*)-latest$/.exec(channel);
|
|
618
|
+
return match ? Number(match[1]) : null;
|
|
619
|
+
}
|
|
620
|
+
if (sdkChannelGeneration(TEMPO_SDK_CHANNEL) === null) {
|
|
621
|
+
throw new Error("tempo-sdk publishConfig.tag must be sdk-v<N>-latest");
|
|
622
|
+
}
|
|
623
|
+
|
|
461
624
|
// host-identity.ts
|
|
462
625
|
var TEMPO_HOST_IDENTITY_ENDPOINT = "/__tempo/identity";
|
|
463
626
|
var TEMPO_HOST_IDENTITY_CAPABILITY_HEADER = "x-tempo-host-identity";
|
|
@@ -477,7 +640,7 @@ function readTempoWorkspaceNonce(root = process.cwd()) {
|
|
|
477
640
|
if (fromEnvironment) return fromEnvironment;
|
|
478
641
|
try {
|
|
479
642
|
return normalizeWorkspaceNonce(
|
|
480
|
-
|
|
643
|
+
readFileSync2(resolve3(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
|
|
481
644
|
);
|
|
482
645
|
} catch {
|
|
483
646
|
return "";
|
|
@@ -489,6 +652,7 @@ function createTempoHostIdentity(framework, options = {}) {
|
|
|
489
652
|
contractVersion: TEMPO_HOST_IDENTITY_CONTRACT_VERSION,
|
|
490
653
|
workspaceNonce: readTempoWorkspaceNonce(options.root),
|
|
491
654
|
sdkVersion: package_default.version,
|
|
655
|
+
sdkChannel: TEMPO_SDK_CHANNEL,
|
|
492
656
|
pluginActive: options.pluginActive ?? Boolean(process.env.TEMPO),
|
|
493
657
|
framework
|
|
494
658
|
};
|
|
@@ -574,8 +738,8 @@ function createRapidHotUpdateReplay(options) {
|
|
|
574
738
|
previous.release = void 0;
|
|
575
739
|
if (previous.expiry) cancel(previous.expiry);
|
|
576
740
|
} else {
|
|
577
|
-
burst.gate = new Promise((
|
|
578
|
-
burst.release =
|
|
741
|
+
burst.gate = new Promise((resolve5) => {
|
|
742
|
+
burst.release = resolve5;
|
|
579
743
|
});
|
|
580
744
|
}
|
|
581
745
|
burst.expiry = schedule(() => burst.release?.(), quietMs * 2);
|
|
@@ -625,6 +789,23 @@ function createRapidHotUpdateReplay(options) {
|
|
|
625
789
|
var installed = /* @__PURE__ */ new WeakSet();
|
|
626
790
|
function installSynchronousReactRefreshBoundary(plugins) {
|
|
627
791
|
for (const plugin of plugins) {
|
|
792
|
+
if (plugin.name === "vite:react-refresh" && plugin.load && !installed.has(plugin)) {
|
|
793
|
+
installed.add(plugin);
|
|
794
|
+
const hook2 = plugin.load;
|
|
795
|
+
const load = typeof hook2 === "function" ? hook2 : hook2.handler;
|
|
796
|
+
const wrapped2 = async function(...args) {
|
|
797
|
+
const result = await load.apply(this, args);
|
|
798
|
+
if (!result || args[0] !== "/@react-refresh") return result;
|
|
799
|
+
const source = typeof result === "string" ? result : result.code;
|
|
800
|
+
if (!source || !/\b(?:let|const) allFamiliesByType = new WeakMap\(\)/.test(source) || !source.includes("function performReactRefresh()"))
|
|
801
|
+
return result;
|
|
802
|
+
const code = `${source}
|
|
803
|
+
globalThis[Symbol.for("tempo.react-refresh.family")] = (type) => allFamiliesByType.get(type);
|
|
804
|
+
`;
|
|
805
|
+
return typeof result === "string" ? code : { ...result, code };
|
|
806
|
+
};
|
|
807
|
+
plugin.load = typeof hook2 === "function" ? wrapped2 : { ...hook2, handler: wrapped2 };
|
|
808
|
+
}
|
|
628
809
|
if (plugin.name !== "vite:react-babel" || !plugin.transform || installed.has(plugin))
|
|
629
810
|
continue;
|
|
630
811
|
installed.add(plugin);
|
|
@@ -651,6 +832,63 @@ ${register}
|
|
|
651
832
|
}
|
|
652
833
|
}
|
|
653
834
|
|
|
835
|
+
// sdk-package-files.ts
|
|
836
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
837
|
+
import { dirname as dirname2, join } from "path";
|
|
838
|
+
var SDK_PACKAGE_NAME = "tempo-sdk";
|
|
839
|
+
var SDK_NODE_MODULES_SEGMENT = `/node_modules/${SDK_PACKAGE_NAME}/`;
|
|
840
|
+
function createSdkFileMatcher() {
|
|
841
|
+
const ownerIsSdkByDirectory = /* @__PURE__ */ new Map();
|
|
842
|
+
const nearestPackageIsSdk = (startDirectory) => {
|
|
843
|
+
const visited = [];
|
|
844
|
+
let directory = startDirectory;
|
|
845
|
+
let isSdk = false;
|
|
846
|
+
while (true) {
|
|
847
|
+
const cached = ownerIsSdkByDirectory.get(directory);
|
|
848
|
+
if (cached !== void 0) {
|
|
849
|
+
isSdk = cached;
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
visited.push(directory);
|
|
853
|
+
const manifest = readPackageManifest(directory);
|
|
854
|
+
if (manifest !== void 0) {
|
|
855
|
+
isSdk = manifest?.name === SDK_PACKAGE_NAME;
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
const parent = dirname2(directory);
|
|
859
|
+
if (parent === directory) break;
|
|
860
|
+
directory = parent;
|
|
861
|
+
}
|
|
862
|
+
for (const entry of visited) ownerIsSdkByDirectory.set(entry, isSdk);
|
|
863
|
+
return isSdk;
|
|
864
|
+
};
|
|
865
|
+
return (file) => {
|
|
866
|
+
if (file.replace(/\\/g, "/").includes(SDK_NODE_MODULES_SEGMENT)) {
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
let realFile = file;
|
|
870
|
+
try {
|
|
871
|
+
realFile = realpathSync2.native(file);
|
|
872
|
+
} catch {
|
|
873
|
+
}
|
|
874
|
+
return nearestPackageIsSdk(dirname2(realFile));
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function readPackageManifest(directory) {
|
|
878
|
+
let text;
|
|
879
|
+
try {
|
|
880
|
+
text = readFileSync3(join(directory, "package.json"), "utf8");
|
|
881
|
+
} catch {
|
|
882
|
+
return void 0;
|
|
883
|
+
}
|
|
884
|
+
try {
|
|
885
|
+
const manifest = JSON.parse(text);
|
|
886
|
+
return manifest && typeof manifest === "object" ? manifest : null;
|
|
887
|
+
} catch {
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
654
892
|
// vite-client-pending-updates.ts
|
|
655
893
|
function preservePendingViteModuleUpdates(source) {
|
|
656
894
|
const missingBoundary = /(const mod = this\.hotModulesMap\.get\(path\);\s*)if \(!mod\)\s*(?:return;|\{\s*return;\s*\})/;
|
|
@@ -810,10 +1048,10 @@ var INTERACT_PROJECTION_CLIENT_ID = "\0tempo:interact-projection";
|
|
|
810
1048
|
var VITE_ERROR_CLIENT_ID = "\0tempo:server-errors";
|
|
811
1049
|
var INTERACT_PROJECTION_SDK_SPECIFIER = "tempo-sdk/canvas/interact-projection";
|
|
812
1050
|
function resolveOwnInteractProjectionModule() {
|
|
813
|
-
const selfDir =
|
|
1051
|
+
const selfDir = dirname3(fileURLToPath(import.meta.url));
|
|
814
1052
|
for (const candidate of [
|
|
815
|
-
|
|
816
|
-
|
|
1053
|
+
join2(selfDir, "canvas", "interact-projection.ts"),
|
|
1054
|
+
join2(selfDir, "canvas", "interact-projection.js")
|
|
817
1055
|
]) {
|
|
818
1056
|
if (existsSync(candidate)) return candidate.replace(/\\/g, "/");
|
|
819
1057
|
}
|
|
@@ -893,18 +1131,18 @@ function barePackageName(specifier) {
|
|
|
893
1131
|
function resolvedIdMatchesFile(id, file) {
|
|
894
1132
|
const resolvedFile = fsPathFromModuleId(id);
|
|
895
1133
|
try {
|
|
896
|
-
return
|
|
1134
|
+
return realpathSync3.native(resolvedFile) === realpathSync3.native(file);
|
|
897
1135
|
} catch {
|
|
898
1136
|
return resolvedFile.replace(/\\/g, "/") === file.replace(/\\/g, "/");
|
|
899
1137
|
}
|
|
900
1138
|
}
|
|
901
1139
|
function moduleIdsMatch(left, right) {
|
|
902
|
-
const
|
|
903
|
-
return
|
|
1140
|
+
const normalize2 = (value) => cleanModuleId(value).replace(/^file:\/\//, "").replace(/^\/@fs\//, "/").replace(/\\/g, "/").replace(/^\/+/, "");
|
|
1141
|
+
return normalize2(left) === normalize2(right);
|
|
904
1142
|
}
|
|
905
1143
|
function resolveCanonicalRoot(root) {
|
|
906
1144
|
try {
|
|
907
|
-
return
|
|
1145
|
+
return realpathSync3.native(root);
|
|
908
1146
|
} catch {
|
|
909
1147
|
return root;
|
|
910
1148
|
}
|
|
@@ -977,10 +1215,10 @@ function createErrorServer(onErrorFile, onState) {
|
|
|
977
1215
|
return server;
|
|
978
1216
|
}
|
|
979
1217
|
function readBody(req) {
|
|
980
|
-
return new Promise((
|
|
1218
|
+
return new Promise((resolve5, reject) => {
|
|
981
1219
|
const chunks = [];
|
|
982
1220
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
983
|
-
req.on("end", () =>
|
|
1221
|
+
req.on("end", () => resolve5(Buffer.concat(chunks).toString()));
|
|
984
1222
|
req.on("error", reject);
|
|
985
1223
|
});
|
|
986
1224
|
}
|
|
@@ -1000,10 +1238,10 @@ function readGeneratedCanvasPaths(source) {
|
|
|
1000
1238
|
return [...paths];
|
|
1001
1239
|
}
|
|
1002
1240
|
async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
1003
|
-
const wrapperPath =
|
|
1241
|
+
const wrapperPath = resolve4(server.config.root, ".tempo", "tempo-host.tsx");
|
|
1004
1242
|
let wrapperSource;
|
|
1005
1243
|
try {
|
|
1006
|
-
wrapperSource =
|
|
1244
|
+
wrapperSource = readFileSync4(wrapperPath, "utf8");
|
|
1007
1245
|
} catch (error) {
|
|
1008
1246
|
throw new Error(
|
|
1009
1247
|
`Canvas host wrapper is unavailable at ${wrapperPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -1020,8 +1258,9 @@ async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
|
1020
1258
|
{ statusCode: 409 }
|
|
1021
1259
|
);
|
|
1022
1260
|
}
|
|
1023
|
-
const canonicalWrapperPath =
|
|
1261
|
+
const canonicalWrapperPath = realpathSync3(wrapperPath);
|
|
1024
1262
|
const modulePattern = /\bcanvasPath:\s*("(?:\\.|[^"\\])*")\s*,\s*load:\s*\(\)\s*=>\s*import\(\s*("(?:\\.|[^"\\])*")\s*\)/g;
|
|
1263
|
+
let moduleUrl;
|
|
1025
1264
|
const transformer = server.environments?.client ?? server;
|
|
1026
1265
|
for (const match of wrapperSource.matchAll(modulePattern)) {
|
|
1027
1266
|
if (normalizeCanvasRegistrationPath(JSON.parse(match[1])) !== canvasPath)
|
|
@@ -1032,32 +1271,86 @@ async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
|
1032
1271
|
);
|
|
1033
1272
|
if (!resolvedModule) throw new Error(`Cannot resolve canvas ${canvasPath}`);
|
|
1034
1273
|
const modulePath = fsPathFromModuleId(resolvedModule.id);
|
|
1274
|
+
moduleUrl = `/@fs/${modulePath.replace(/^\/+/, "")}`;
|
|
1035
1275
|
await retransformCanvasHostWrapper(
|
|
1276
|
+
server,
|
|
1036
1277
|
transformer,
|
|
1037
|
-
|
|
1278
|
+
realpathSync3(modulePath),
|
|
1038
1279
|
modulePath,
|
|
1039
1280
|
`/@fs/${modulePath.replace(/^\/+/, "")}`
|
|
1040
1281
|
);
|
|
1041
1282
|
break;
|
|
1042
1283
|
}
|
|
1043
1284
|
await retransformCanvasHostWrapper(
|
|
1285
|
+
server,
|
|
1044
1286
|
transformer,
|
|
1045
1287
|
canonicalWrapperPath,
|
|
1046
1288
|
wrapperPath
|
|
1047
1289
|
);
|
|
1290
|
+
return wrapperSource.includes("tempo-incremental-canvas-registration") ? moduleUrl : void 0;
|
|
1048
1291
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1292
|
+
var registrationTransforms = /* @__PURE__ */ new WeakMap();
|
|
1293
|
+
var registrationActivity = /* @__PURE__ */ new WeakMap();
|
|
1294
|
+
function registrationProgress(server) {
|
|
1295
|
+
const optimizer = server.environments?.client?.depsOptimizer;
|
|
1296
|
+
const phase = optimizer?.scanProcessing ? "scanning" : Object.values(optimizer?.metadata.discovered ?? {}).some(
|
|
1297
|
+
(dep) => dep.processing
|
|
1298
|
+
) ? "bundling" : "transforming";
|
|
1299
|
+
return {
|
|
1300
|
+
status: "compiling",
|
|
1301
|
+
phase,
|
|
1302
|
+
progress: registrationActivity.get(server) ?? 0
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
async function retransformCanvasHostWrapper(server, transformer, canonicalWrapperPath, wrapperPath, requestUrl = CANVAS_HOST_WRAPPER_URL) {
|
|
1306
|
+
let confirm = registrationTransforms.get(transformer);
|
|
1307
|
+
if (!confirm) {
|
|
1308
|
+
confirm = createRegistrationTransforms();
|
|
1309
|
+
registrationTransforms.set(transformer, confirm);
|
|
1057
1310
|
}
|
|
1311
|
+
await confirm(
|
|
1312
|
+
canonicalWrapperPath,
|
|
1313
|
+
() => traceSlowRegistration(
|
|
1314
|
+
async () => {
|
|
1315
|
+
const modules = () => transformer.moduleGraph.getModulesByFile(canonicalWrapperPath) ?? transformer.moduleGraph.getModulesByFile(wrapperPath);
|
|
1316
|
+
for (const module of modules() ?? []) {
|
|
1317
|
+
transformer.moduleGraph.invalidateModule(module);
|
|
1318
|
+
}
|
|
1319
|
+
const result = await transformer.transformRequest(requestUrl);
|
|
1320
|
+
if (!result) {
|
|
1321
|
+
throw new Error(
|
|
1322
|
+
`Vite did not transform ${requestUrl} after registration`
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
const transformed = [...modules() ?? []].map(
|
|
1326
|
+
(module) => [
|
|
1327
|
+
module,
|
|
1328
|
+
module.transformResult
|
|
1329
|
+
]
|
|
1330
|
+
);
|
|
1331
|
+
return () => transformed.length > 0 && transformed.every(
|
|
1332
|
+
([module, value]) => value != null && modules()?.has(module) && module.transformResult === value
|
|
1333
|
+
);
|
|
1334
|
+
},
|
|
1335
|
+
(status, elapsedMs) => {
|
|
1336
|
+
server.config.logger.info(
|
|
1337
|
+
`[tempo] canvas registration ${JSON.stringify({
|
|
1338
|
+
...registrationProgress(server),
|
|
1339
|
+
status,
|
|
1340
|
+
module: relative2(server.config.root, canonicalWrapperPath),
|
|
1341
|
+
elapsedMs
|
|
1342
|
+
})}`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
)
|
|
1346
|
+
);
|
|
1058
1347
|
}
|
|
1059
1348
|
function writeCanvasRegistrationResponseHeaders(res) {
|
|
1060
1349
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1350
|
+
res.setHeader(
|
|
1351
|
+
"Access-Control-Expose-Headers",
|
|
1352
|
+
CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER
|
|
1353
|
+
);
|
|
1061
1354
|
res.setHeader(CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER, "1");
|
|
1062
1355
|
}
|
|
1063
1356
|
function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
@@ -1095,13 +1388,25 @@ function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
|
1095
1388
|
{ statusCode: 400 }
|
|
1096
1389
|
);
|
|
1097
1390
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1391
|
+
let moduleUrl;
|
|
1392
|
+
const progress = await registrationReply(
|
|
1393
|
+
synchronizeCanvasHostRegistrationTransform(
|
|
1394
|
+
viteServer,
|
|
1395
|
+
canvasPath
|
|
1396
|
+
).then((url2) => {
|
|
1397
|
+
moduleUrl = url2;
|
|
1398
|
+
}),
|
|
1399
|
+
() => registrationProgress(viteServer),
|
|
1400
|
+
parsed.poll === true
|
|
1101
1401
|
);
|
|
1102
|
-
res.statusCode = 200;
|
|
1402
|
+
res.statusCode = progress ? 202 : 200;
|
|
1103
1403
|
res.setHeader("Content-Type", "application/json");
|
|
1104
|
-
res.
|
|
1404
|
+
res.setHeader("Cache-Control", "no-store");
|
|
1405
|
+
res.end(
|
|
1406
|
+
JSON.stringify(
|
|
1407
|
+
progress ?? { canvasPath, ...moduleUrl ? { moduleUrl } : {} }
|
|
1408
|
+
)
|
|
1409
|
+
);
|
|
1105
1410
|
}).catch((error) => {
|
|
1106
1411
|
res.statusCode = typeof error === "object" && error !== null && "statusCode" in error && typeof error.statusCode === "number" ? error.statusCode : 500;
|
|
1107
1412
|
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
@@ -1156,6 +1461,7 @@ function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
|
1156
1461
|
var MISSED_CHANGE_SWEEP_INTERVAL_MS = 3e3;
|
|
1157
1462
|
var COMPILE_ERROR_POLL_MAX_INTERVAL_MS = 3e4;
|
|
1158
1463
|
function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs, pollCompileErrorRecovery) {
|
|
1464
|
+
const cacheDir = server.config.cacheDir?.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1159
1465
|
const sweep = createMissedChangeSweep({
|
|
1160
1466
|
listServedFiles: () => {
|
|
1161
1467
|
const files = new Map(
|
|
@@ -1164,14 +1470,21 @@ function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs,
|
|
|
1164
1470
|
const errorFiles = listErrorFiles();
|
|
1165
1471
|
for (const errorFile of errorFiles) {
|
|
1166
1472
|
const cleanFile = fsPathFromModuleId(errorFile);
|
|
1167
|
-
const file =
|
|
1473
|
+
const file = isAbsolute2(cleanFile) ? cleanFile : resolve4(server.config.root, cleanFile);
|
|
1168
1474
|
if (!files.has(file)) files.set(file, []);
|
|
1169
1475
|
}
|
|
1476
|
+
if (cacheDir) {
|
|
1477
|
+
for (const file of files.keys()) {
|
|
1478
|
+
if (file.replace(/\\/g, "/").startsWith(`${cacheDir}/`)) {
|
|
1479
|
+
files.delete(file);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1170
1483
|
return files.entries();
|
|
1171
1484
|
},
|
|
1172
1485
|
statMtimeMs: async (file) => {
|
|
1173
1486
|
try {
|
|
1174
|
-
return
|
|
1487
|
+
return statSync(file).mtimeMs;
|
|
1175
1488
|
} catch {
|
|
1176
1489
|
return null;
|
|
1177
1490
|
}
|
|
@@ -1236,11 +1549,14 @@ function tempoVitePlugin(options = {}) {
|
|
|
1236
1549
|
const enabled = !!process.env.TEMPO;
|
|
1237
1550
|
const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
|
|
1238
1551
|
const exclude = options.exclude === void 0 ? DEFAULT_EXCLUDE : options.exclude;
|
|
1239
|
-
const
|
|
1240
|
-
const
|
|
1552
|
+
const isSdkFile = createSdkFileMatcher();
|
|
1553
|
+
const userFilter = createFilter(include, exclude);
|
|
1554
|
+
const filter = (id) => userFilter(id) && !isSdkFile(id);
|
|
1555
|
+
const userControlsFilter = createFilter(
|
|
1241
1556
|
["**/*.tsx", "**/*.jsx", "**/*.ts", "**/*.js"],
|
|
1242
1557
|
exclude
|
|
1243
1558
|
);
|
|
1559
|
+
const controlsFilter = (id) => userControlsFilter(id) && !isSdkFile(id);
|
|
1244
1560
|
const controlsModules = /* @__PURE__ */ new Set();
|
|
1245
1561
|
function transformControls(source, id) {
|
|
1246
1562
|
const code = transformControlsForHmr(source, id, controlsModules.has(id));
|
|
@@ -1263,6 +1579,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1263
1579
|
let rerunUnresolvedImportResolution = false;
|
|
1264
1580
|
let unresolvedImportWatchRearmTimer = null;
|
|
1265
1581
|
const processedUpdatePayloads = /* @__PURE__ */ new WeakSet();
|
|
1582
|
+
const prunedModuleDeletion = createPrunedModuleDeletionGuard();
|
|
1266
1583
|
const hmrGenerationFence = createHmrGenerationFence();
|
|
1267
1584
|
const rapidHotUpdateReplay = createRapidHotUpdateReplay();
|
|
1268
1585
|
const hotUpdateMtimesMs = /* @__PURE__ */ new Map();
|
|
@@ -1272,7 +1589,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1272
1589
|
const cleanFile = fsPathFromModuleId(file);
|
|
1273
1590
|
const key = normalizedFileKey(cleanFile);
|
|
1274
1591
|
try {
|
|
1275
|
-
hotUpdateMtimesMs.set(key,
|
|
1592
|
+
hotUpdateMtimesMs.set(key, statSync(cleanFile).mtimeMs);
|
|
1276
1593
|
} catch {
|
|
1277
1594
|
hotUpdateMtimesMs.delete(key);
|
|
1278
1595
|
}
|
|
@@ -1290,7 +1607,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1290
1607
|
try {
|
|
1291
1608
|
let canonicalFile = cleanFile;
|
|
1292
1609
|
try {
|
|
1293
|
-
canonicalFile =
|
|
1610
|
+
canonicalFile = realpathSync3(cleanFile);
|
|
1294
1611
|
} catch {
|
|
1295
1612
|
}
|
|
1296
1613
|
const modules = /* @__PURE__ */ new Set([
|
|
@@ -1349,27 +1666,56 @@ function tempoVitePlugin(options = {}) {
|
|
|
1349
1666
|
const canonicalIdentityKey = (idOrFile) => {
|
|
1350
1667
|
const file = fsPathFromModuleId(idOrFile);
|
|
1351
1668
|
try {
|
|
1352
|
-
return
|
|
1669
|
+
return realpathSync3.native(file);
|
|
1353
1670
|
} catch {
|
|
1354
1671
|
return file.replace(/\\/g, "/");
|
|
1355
1672
|
}
|
|
1356
1673
|
};
|
|
1357
|
-
const repairDefaultExportIdentityRewrite = (
|
|
1674
|
+
const repairDefaultExportIdentityRewrite = async (context) => {
|
|
1675
|
+
const { file } = context;
|
|
1358
1676
|
const key = canonicalIdentityKey(file);
|
|
1359
|
-
|
|
1360
|
-
if (before === void 0) return false;
|
|
1677
|
+
if (!defaultExportIdentityByFile.has(key)) return false;
|
|
1361
1678
|
let source;
|
|
1362
1679
|
try {
|
|
1363
|
-
source =
|
|
1680
|
+
source = readFileSync4(file, "utf8");
|
|
1681
|
+
if (source.length === 0) source = await context.read();
|
|
1364
1682
|
} catch {
|
|
1365
1683
|
return false;
|
|
1366
1684
|
}
|
|
1685
|
+
const before = defaultExportIdentityByFile.get(key);
|
|
1686
|
+
if (before === void 0) return false;
|
|
1367
1687
|
const after = readDefaultExportIdentity(source);
|
|
1368
1688
|
defaultExportIdentityByFile.set(key, after);
|
|
1369
1689
|
if (!isDefaultExportIdentityRewrite(before, after)) return false;
|
|
1370
1690
|
devServer?.ws.send({ type: "full-reload", path: "*" });
|
|
1371
1691
|
return true;
|
|
1372
1692
|
};
|
|
1693
|
+
const isIncrementalRegistration = (file) => {
|
|
1694
|
+
if (file.replace(/\\/g, "/") !== resolve4(canonicalRoot, ".tempo", "tempo-host.tsx").replace(/\\/g, "/"))
|
|
1695
|
+
return false;
|
|
1696
|
+
try {
|
|
1697
|
+
return readFileSync4(file, "utf8").includes(
|
|
1698
|
+
"tempo-incremental-canvas-registration"
|
|
1699
|
+
);
|
|
1700
|
+
} catch {
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
const invalidateCanvasLoader = (file, graph, modules) => {
|
|
1705
|
+
const canvasPath = relative2(sourceIdentityRoot, file).replace(/\\/g, "/");
|
|
1706
|
+
const wrapperPath = resolve4(canonicalRoot, ".tempo", "tempo-host.tsx");
|
|
1707
|
+
let source;
|
|
1708
|
+
try {
|
|
1709
|
+
source = readFileSync4(wrapperPath, "utf8");
|
|
1710
|
+
} catch {
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
if (!readGeneratedCanvasPaths(source).includes(canvasPath)) return;
|
|
1714
|
+
const wrappers = graph.getModulesByFile(wrapperPath);
|
|
1715
|
+
if (!wrappers?.size) return;
|
|
1716
|
+
for (const wrapper of wrappers) graph.invalidateModule(wrapper);
|
|
1717
|
+
return [.../* @__PURE__ */ new Set([...modules, ...wrappers])];
|
|
1718
|
+
};
|
|
1373
1719
|
const rememberUnresolvedImport = (specifier, importer, packageName) => {
|
|
1374
1720
|
const key = `${importer}\0${specifier}`;
|
|
1375
1721
|
unresolvedImports.delete(key);
|
|
@@ -1421,28 +1767,28 @@ function tempoVitePlugin(options = {}) {
|
|
|
1421
1767
|
(unresolved) => unresolved.packageName !== void 0
|
|
1422
1768
|
);
|
|
1423
1769
|
const packageWatchTarget = (unresolved) => {
|
|
1424
|
-
let candidate =
|
|
1770
|
+
let candidate = dirname3(cleanModuleId(unresolved.importer));
|
|
1425
1771
|
let nearestPackageRoot;
|
|
1426
1772
|
while (true) {
|
|
1427
1773
|
try {
|
|
1428
|
-
if (
|
|
1429
|
-
return
|
|
1774
|
+
if (statSync(join2(candidate, "node_modules")).isDirectory()) {
|
|
1775
|
+
return join2(candidate, "node_modules", unresolved.packageName);
|
|
1430
1776
|
}
|
|
1431
1777
|
} catch {
|
|
1432
1778
|
}
|
|
1433
1779
|
if (nearestPackageRoot === void 0) {
|
|
1434
1780
|
try {
|
|
1435
|
-
if (
|
|
1781
|
+
if (statSync(join2(candidate, "package.json")).isFile()) {
|
|
1436
1782
|
nearestPackageRoot = candidate;
|
|
1437
1783
|
}
|
|
1438
1784
|
} catch {
|
|
1439
1785
|
}
|
|
1440
1786
|
}
|
|
1441
|
-
const parent =
|
|
1787
|
+
const parent = dirname3(candidate);
|
|
1442
1788
|
if (parent === candidate) break;
|
|
1443
1789
|
candidate = parent;
|
|
1444
1790
|
}
|
|
1445
|
-
return
|
|
1791
|
+
return join2(
|
|
1446
1792
|
nearestPackageRoot ?? canonicalRoot,
|
|
1447
1793
|
"node_modules",
|
|
1448
1794
|
unresolved.packageName
|
|
@@ -1451,8 +1797,8 @@ function tempoVitePlugin(options = {}) {
|
|
|
1451
1797
|
const unresolvedImportWatchTarget = (unresolved) => {
|
|
1452
1798
|
return unresolved.packageName ? packageWatchTarget(
|
|
1453
1799
|
unresolved
|
|
1454
|
-
) :
|
|
1455
|
-
|
|
1800
|
+
) : resolve4(
|
|
1801
|
+
dirname3(cleanModuleId(unresolved.importer)),
|
|
1456
1802
|
cleanModuleId(unresolved.specifier)
|
|
1457
1803
|
);
|
|
1458
1804
|
};
|
|
@@ -1460,10 +1806,10 @@ function tempoVitePlugin(options = {}) {
|
|
|
1460
1806
|
let candidate = target;
|
|
1461
1807
|
while (true) {
|
|
1462
1808
|
try {
|
|
1463
|
-
if (
|
|
1809
|
+
if (statSync(candidate).isDirectory()) return candidate;
|
|
1464
1810
|
} catch {
|
|
1465
1811
|
}
|
|
1466
|
-
const parent =
|
|
1812
|
+
const parent = dirname3(candidate);
|
|
1467
1813
|
if (parent === candidate) return void 0;
|
|
1468
1814
|
candidate = parent;
|
|
1469
1815
|
}
|
|
@@ -1540,8 +1886,8 @@ function tempoVitePlugin(options = {}) {
|
|
|
1540
1886
|
if (isRelativeImportSpecifier(unresolved.specifier)) {
|
|
1541
1887
|
const suffixIndex = unresolved.specifier.search(/[?#]/);
|
|
1542
1888
|
const relativePath = suffixIndex < 0 ? unresolved.specifier : unresolved.specifier.slice(0, suffixIndex);
|
|
1543
|
-
const candidate =
|
|
1544
|
-
|
|
1889
|
+
const candidate = resolve4(
|
|
1890
|
+
dirname3(cleanModuleId(unresolved.importer)),
|
|
1545
1891
|
relativePath
|
|
1546
1892
|
);
|
|
1547
1893
|
const probes = [
|
|
@@ -1550,12 +1896,12 @@ function tempoVitePlugin(options = {}) {
|
|
|
1550
1896
|
(extension) => `${candidate}${extension}`
|
|
1551
1897
|
),
|
|
1552
1898
|
...RELATIVE_IMPORT_RESOLVE_EXTENSIONS.map(
|
|
1553
|
-
(extension) =>
|
|
1899
|
+
(extension) => join2(candidate, `index${extension}`)
|
|
1554
1900
|
)
|
|
1555
1901
|
];
|
|
1556
1902
|
for (const probe of probes) {
|
|
1557
1903
|
try {
|
|
1558
|
-
if (
|
|
1904
|
+
if (statSync(probe).isFile()) {
|
|
1559
1905
|
file = probe;
|
|
1560
1906
|
break;
|
|
1561
1907
|
}
|
|
@@ -1590,6 +1936,17 @@ function tempoVitePlugin(options = {}) {
|
|
|
1590
1936
|
name: "tempo-annotate",
|
|
1591
1937
|
apply: "serve",
|
|
1592
1938
|
enforce: "pre",
|
|
1939
|
+
config(config, environment) {
|
|
1940
|
+
if (!enabled || environment.command !== "serve") return;
|
|
1941
|
+
applyManagedCanvasDependencyScan(config);
|
|
1942
|
+
const dedupe = ["react", "react-dom"].filter(
|
|
1943
|
+
(name) => !config.resolve?.dedupe?.includes(name)
|
|
1944
|
+
);
|
|
1945
|
+
return {
|
|
1946
|
+
resolve: { dedupe },
|
|
1947
|
+
...config.css?.devSourcemap === void 0 ? { css: { devSourcemap: true } } : {}
|
|
1948
|
+
};
|
|
1949
|
+
},
|
|
1593
1950
|
resolveId: {
|
|
1594
1951
|
order: "pre",
|
|
1595
1952
|
async handler(id, importer, resolveOptions) {
|
|
@@ -1714,17 +2071,22 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1714
2071
|
}
|
|
1715
2072
|
canonicalRoot = resolveCanonicalRoot(resolvedConfig.root);
|
|
1716
2073
|
sourceIdentityRoot = options.sourceIdentityRoot ? resolveCanonicalRoot(
|
|
1717
|
-
|
|
2074
|
+
resolve4(resolvedConfig.root, options.sourceIdentityRoot)
|
|
1718
2075
|
) : canonicalRoot;
|
|
1719
2076
|
},
|
|
1720
2077
|
configureServer(server) {
|
|
1721
2078
|
if (!enabled) return;
|
|
2079
|
+
registrationActivity.set(server, 0);
|
|
2080
|
+
registrationTransforms.delete(server.environments?.client ?? server);
|
|
2081
|
+
const events = ["change", "add", "unlink"];
|
|
2082
|
+
for (const event of events)
|
|
2083
|
+
server.watcher?.prependListener?.(event, recordHotUpdateCoverage);
|
|
1722
2084
|
const ownInteractModule = resolveOwnInteractProjectionModule();
|
|
1723
2085
|
const allow = server.config?.server?.fs?.allow;
|
|
1724
2086
|
if (Array.isArray(allow)) {
|
|
1725
2087
|
const requiredRoots = [
|
|
1726
2088
|
sourceIdentityRoot,
|
|
1727
|
-
...ownInteractModule ? [
|
|
2089
|
+
...ownInteractModule ? [dirname3(ownInteractModule)] : []
|
|
1728
2090
|
];
|
|
1729
2091
|
for (const requiredRoot of requiredRoots) {
|
|
1730
2092
|
if (!allow.includes(requiredRoot)) allow.push(requiredRoot);
|
|
@@ -1738,12 +2100,30 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1738
2100
|
server.watcher?.once?.("close", closeUnresolvedImportWatchers);
|
|
1739
2101
|
server.httpServer?.once("close", closeUnresolvedImportWatchers);
|
|
1740
2102
|
server.middlewares.use((req, res, next) => {
|
|
2103
|
+
const graph = server.environments?.client?.moduleGraph;
|
|
2104
|
+
if (graph && req.url && (req.method === "GET" || req.method === "HEAD")) {
|
|
2105
|
+
const observeResponse = prunedModuleDeletion.observeRequest(
|
|
2106
|
+
graph,
|
|
2107
|
+
req.url,
|
|
2108
|
+
server.config.base,
|
|
2109
|
+
req.headers["sec-fetch-dest"],
|
|
2110
|
+
req.headers["if-none-match"]
|
|
2111
|
+
);
|
|
2112
|
+
if (observeResponse)
|
|
2113
|
+
res.once("finish", () => {
|
|
2114
|
+
void observeResponse(
|
|
2115
|
+
res.statusCode,
|
|
2116
|
+
res.getHeader("content-type"),
|
|
2117
|
+
res.getHeader("etag")
|
|
2118
|
+
);
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
1741
2121
|
const name = req.url?.match(
|
|
1742
2122
|
/^\/tempo-assets\/([a-zA-Z0-9._-]+)(?:\?.*)?$/
|
|
1743
2123
|
)?.[1];
|
|
1744
2124
|
if (name) {
|
|
1745
2125
|
const file = ["public", "static"].map(
|
|
1746
|
-
(directory) =>
|
|
2126
|
+
(directory) => join2(sourceIdentityRoot, directory, "tempo-assets", name)
|
|
1747
2127
|
).find((file2) => existsSync(file2));
|
|
1748
2128
|
if (file) req.url = `/@fs/${file.replace(/\\/g, "/")}`;
|
|
1749
2129
|
}
|
|
@@ -1762,6 +2142,14 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1762
2142
|
const payload = args[0];
|
|
1763
2143
|
if (typeof payload === "object" && payload !== null && "type" in payload) {
|
|
1764
2144
|
const typed = payload;
|
|
2145
|
+
if (typed.type === "prune") {
|
|
2146
|
+
const graph = server.environments?.client?.moduleGraph;
|
|
2147
|
+
if (graph)
|
|
2148
|
+
prunedModuleDeletion.observePrune(
|
|
2149
|
+
graph,
|
|
2150
|
+
typed.paths ?? []
|
|
2151
|
+
);
|
|
2152
|
+
}
|
|
1765
2153
|
if (typed.type === "error") {
|
|
1766
2154
|
const err = typed.err;
|
|
1767
2155
|
errorServer.setError({
|
|
@@ -1803,6 +2191,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1803
2191
|
devServer = void 0;
|
|
1804
2192
|
rapidHotUpdateReplay.clear();
|
|
1805
2193
|
hmrGenerationFence.clear();
|
|
2194
|
+
prunedModuleDeletion.clear();
|
|
1806
2195
|
hotUpdateMtimesMs.clear();
|
|
1807
2196
|
compileErrorPollSchedule.clear();
|
|
1808
2197
|
closeUnresolvedImportWatchers();
|
|
@@ -1811,12 +2200,12 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1811
2200
|
order: "post",
|
|
1812
2201
|
async handler(context) {
|
|
1813
2202
|
if (!enabled || this.environment.config.consumer !== "client") return;
|
|
2203
|
+
if (isIncrementalRegistration(context.file)) return [];
|
|
1814
2204
|
if (context.type === "create" && /\/\.tempo\/asset-edit-previews\/\d+\/index\.canvas\.tsx$/.test(
|
|
1815
2205
|
context.file.replace(/\\/g, "/")
|
|
1816
2206
|
)) {
|
|
1817
2207
|
return [];
|
|
1818
2208
|
}
|
|
1819
|
-
recordHotUpdateCoverage(context.file);
|
|
1820
2209
|
if (context.type === "update" && context.modules.length > 0) {
|
|
1821
2210
|
rapidHotUpdateReplay.observe(burstKey(context.file), () => {
|
|
1822
2211
|
context.server.config.logger.info(
|
|
@@ -1836,11 +2225,23 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1836
2225
|
defaultExportIdentityByFile.delete(
|
|
1837
2226
|
canonicalIdentityKey(context.file)
|
|
1838
2227
|
);
|
|
2228
|
+
if (prunedModuleDeletion.suppressDeletion(
|
|
2229
|
+
this.environment.moduleGraph,
|
|
2230
|
+
context.modules
|
|
2231
|
+
))
|
|
2232
|
+
return [];
|
|
1839
2233
|
return;
|
|
1840
2234
|
}
|
|
1841
|
-
if (context.type === "update" && repairDefaultExportIdentityRewrite(context
|
|
2235
|
+
if (context.type === "update" && await repairDefaultExportIdentityRewrite(context)) {
|
|
1842
2236
|
return [];
|
|
1843
2237
|
}
|
|
2238
|
+
if (context.type === "update") {
|
|
2239
|
+
return invalidateCanvasLoader(
|
|
2240
|
+
context.file,
|
|
2241
|
+
this.environment.moduleGraph,
|
|
2242
|
+
context.modules
|
|
2243
|
+
);
|
|
2244
|
+
}
|
|
1844
2245
|
}
|
|
1845
2246
|
},
|
|
1846
2247
|
// Vite 5 compatibility. Vite 6+ prefers `hotUpdate` above.
|
|
@@ -1848,7 +2249,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1848
2249
|
order: "post",
|
|
1849
2250
|
async handler(context) {
|
|
1850
2251
|
if (!enabled) return;
|
|
1851
|
-
|
|
2252
|
+
if (isIncrementalRegistration(context.file)) return [];
|
|
1852
2253
|
if (context.modules.length > 0) {
|
|
1853
2254
|
rapidHotUpdateReplay.observe(burstKey(context.file), () => {
|
|
1854
2255
|
context.server.config.logger.info(
|
|
@@ -1862,9 +2263,14 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1862
2263
|
if (hasActiveCompileError(context.file) && await recoverActiveCompileError(context.server, context.file)) {
|
|
1863
2264
|
return [];
|
|
1864
2265
|
}
|
|
1865
|
-
if (repairDefaultExportIdentityRewrite(context
|
|
2266
|
+
if (await repairDefaultExportIdentityRewrite(context)) {
|
|
1866
2267
|
return [];
|
|
1867
2268
|
}
|
|
2269
|
+
return invalidateCanvasLoader(
|
|
2270
|
+
context.file,
|
|
2271
|
+
context.server.moduleGraph,
|
|
2272
|
+
context.modules
|
|
2273
|
+
);
|
|
1868
2274
|
}
|
|
1869
2275
|
},
|
|
1870
2276
|
transformIndexHtml(html, context) {
|
|
@@ -1929,10 +2335,16 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1929
2335
|
}
|
|
1930
2336
|
return tags.length > 0 ? tags : void 0;
|
|
1931
2337
|
},
|
|
1932
|
-
transform(source, id) {
|
|
2338
|
+
async transform(source, id) {
|
|
1933
2339
|
if (!enabled || command === "build") {
|
|
1934
2340
|
return null;
|
|
1935
2341
|
}
|
|
2342
|
+
if (devServer) {
|
|
2343
|
+
registrationActivity.set(
|
|
2344
|
+
devServer,
|
|
2345
|
+
(registrationActivity.get(devServer) ?? 0) + 1
|
|
2346
|
+
);
|
|
2347
|
+
}
|
|
1936
2348
|
if (id.startsWith("\0")) {
|
|
1937
2349
|
return null;
|
|
1938
2350
|
}
|
|
@@ -1949,9 +2361,45 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1949
2361
|
}
|
|
1950
2362
|
try {
|
|
1951
2363
|
const filepath = relative2(canonicalRoot, cleanId);
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
2364
|
+
const descriptor = openSync(cleanId, "r");
|
|
2365
|
+
let snapshot;
|
|
2366
|
+
try {
|
|
2367
|
+
const before2 = fstatSync(descriptor);
|
|
2368
|
+
const rawSource2 = readFileSync4(descriptor, "utf8");
|
|
2369
|
+
snapshot = { before: before2, rawSource: rawSource2, after: fstatSync(descriptor) };
|
|
2370
|
+
} finally {
|
|
2371
|
+
closeSync(descriptor);
|
|
2372
|
+
}
|
|
2373
|
+
const { before, after, rawSource } = snapshot;
|
|
2374
|
+
const stable = ["mtimeMs", "ctimeMs", "size", "ino", "dev"];
|
|
2375
|
+
let loadedSource = source === rawSource ? source : void 0;
|
|
2376
|
+
if (loadedSource === void 0 && typeof this.getCombinedSourcemap === "function") {
|
|
2377
|
+
try {
|
|
2378
|
+
const map = this.getCombinedSourcemap();
|
|
2379
|
+
const sourceRoot = map.sourceRoot;
|
|
2380
|
+
const matches = map.sources.flatMap((path, index) => {
|
|
2381
|
+
const sourcePath = path.startsWith("file:") ? fileURLToPath(path) : path;
|
|
2382
|
+
const file = isAbsolute2(sourcePath) ? sourcePath : resolve4(
|
|
2383
|
+
dirname3(cleanId),
|
|
2384
|
+
typeof sourceRoot === "string" ? sourceRoot : "",
|
|
2385
|
+
sourcePath
|
|
2386
|
+
);
|
|
2387
|
+
let sameFile = cleanModuleId(file).replace(/\\/g, "/") === cleanId.replace(/\\/g, "/");
|
|
2388
|
+
if (!sameFile) {
|
|
2389
|
+
try {
|
|
2390
|
+
sameFile = realpathSync3.native(file) === realpathSync3.native(cleanId);
|
|
2391
|
+
} catch {
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
return sameFile && typeof map.sourcesContent?.[index] === "string" ? [map.sourcesContent[index]] : [];
|
|
2395
|
+
});
|
|
2396
|
+
if (matches.length === 1) loadedSource = matches[0];
|
|
2397
|
+
} catch {
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
const witnessed = loadedSource === rawSource && stable.every((key) => before[key] === after[key]);
|
|
2401
|
+
const modifiedtsMs = witnessed ? Math.trunc(before.mtimeMs) : 0;
|
|
2402
|
+
const sourceVersion = witnessed ? sourceVersionHash(rawSource) : "";
|
|
1955
2403
|
const identityKey = canonicalIdentityKey(cleanId);
|
|
1956
2404
|
if (!defaultExportIdentityByFile.has(identityKey)) {
|
|
1957
2405
|
defaultExportIdentityByFile.set(
|
|
@@ -1959,22 +2407,55 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1959
2407
|
readDefaultExportIdentity(rawSource)
|
|
1960
2408
|
);
|
|
1961
2409
|
}
|
|
1962
|
-
const
|
|
1963
|
-
|
|
2410
|
+
const resolvedComponents = /* @__PURE__ */ new Map();
|
|
2411
|
+
if (source.includes("tempo-sdk/canvas") && typeof this.resolve === "function") {
|
|
2412
|
+
const imports = parseCanvasFile(cleanId, source).storyboards.flatMap(
|
|
2413
|
+
(board) => board.component?.import?.source ?? []
|
|
2414
|
+
);
|
|
2415
|
+
await Promise.all(
|
|
2416
|
+
[...new Set(imports)].map(async (specifier) => {
|
|
2417
|
+
const resolved = await this.resolve(specifier, cleanId, {
|
|
2418
|
+
skipSelf: true
|
|
2419
|
+
});
|
|
2420
|
+
if (resolved) resolvedComponents.set(specifier, resolved.id);
|
|
2421
|
+
})
|
|
2422
|
+
);
|
|
2423
|
+
}
|
|
2424
|
+
const componentReferences = canvasComponentAnnotations(
|
|
1964
2425
|
cleanId,
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
filepath,
|
|
1968
|
-
modifiedtsMs,
|
|
1969
|
-
sourceVersion,
|
|
1970
|
-
computeAnnotatedProps: options.computeAnnotatedProps
|
|
1971
|
-
})
|
|
2426
|
+
source,
|
|
2427
|
+
resolvedComponents
|
|
1972
2428
|
);
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2429
|
+
const result = annotateFile(source, cleanId, (info) => {
|
|
2430
|
+
const props = {
|
|
2431
|
+
...componentReferences.get(info.element.openingElement.start),
|
|
2432
|
+
...computeTempoAnnotatedProps({
|
|
2433
|
+
info,
|
|
2434
|
+
filepath,
|
|
2435
|
+
modifiedtsMs,
|
|
2436
|
+
sourceVersion,
|
|
2437
|
+
computeAnnotatedProps: options.computeAnnotatedProps
|
|
2438
|
+
})
|
|
2439
|
+
};
|
|
2440
|
+
if (!witnessed) {
|
|
2441
|
+
delete props["data-tempo-filepath"];
|
|
2442
|
+
delete props["data-tempo-position"];
|
|
2443
|
+
delete props["data-tempo-expr"];
|
|
2444
|
+
delete props["data-tempo-modifiedts"];
|
|
2445
|
+
delete props["data-tempo-source-version"];
|
|
2446
|
+
}
|
|
2447
|
+
return props;
|
|
2448
|
+
});
|
|
2449
|
+
if (result.parseResult.errors.length > 0) return null;
|
|
2450
|
+
const annotated = result.elementsAnnotated === 0 ? source : result.annotatedSource;
|
|
2451
|
+
const withControls = controlsFilter(cleanId) ? transformControls(annotated, cleanId) : annotated;
|
|
1976
2452
|
return {
|
|
1977
|
-
code:
|
|
2453
|
+
code: witnessed ? appendModuleVersionRecord(
|
|
2454
|
+
withControls,
|
|
2455
|
+
filepath,
|
|
2456
|
+
modifiedtsMs,
|
|
2457
|
+
sourceVersion
|
|
2458
|
+
) : withControls,
|
|
1978
2459
|
map: null
|
|
1979
2460
|
};
|
|
1980
2461
|
} catch {
|