tempo-sdk 0.0.52 → 0.0.57
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 +10 -6
- package/dist/canvas/index.js +130 -47
- 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-EMYYTS6D.js +1585 -0
- package/dist/chunk-EMYYTS6D.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-7Y7XNHUM.js → chunk-QXL6GL2P.js} +18 -3
- package/dist/chunk-QXL6GL2P.js.map +1 -0
- package/dist/{chunk-QP2NTODB.js → chunk-RHHVVWAC.js} +115 -25
- package/dist/chunk-RHHVVWAC.js.map +1 -0
- package/dist/chunk-TL4MGN7E.js +2570 -0
- package/dist/chunk-TL4MGN7E.js.map +1 -0
- package/dist/{chunk-PULSTDX2.js → chunk-U3SLJNRS.js} +284 -46
- package/dist/chunk-U3SLJNRS.js.map +1 -0
- package/dist/{chunk-ZZYNOX24.js → chunk-U64AHDHZ.js} +1708 -2461
- package/dist/chunk-U64AHDHZ.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 +463 -153
- 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-BtQuVGpl.d.ts} +33 -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,88 @@ import {
|
|
|
10
12
|
import {
|
|
11
13
|
TEMPO_INTERACT_FRAME_NAME
|
|
12
14
|
} from "./chunk-65B52AR7.js";
|
|
15
|
+
import {
|
|
16
|
+
parseCanvasFile
|
|
17
|
+
} from "./chunk-RHHVVWAC.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
|
+
|
|
18
88
|
// index.ts
|
|
19
89
|
import {
|
|
20
90
|
existsSync,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
91
|
+
openSync,
|
|
92
|
+
closeSync,
|
|
93
|
+
fstatSync,
|
|
94
|
+
readFileSync as readFileSync3,
|
|
95
|
+
realpathSync as realpathSync3,
|
|
96
|
+
statSync,
|
|
24
97
|
watch as watchFileSystem
|
|
25
98
|
} from "fs";
|
|
26
99
|
import { createRequire } from "module";
|
|
@@ -44,7 +117,7 @@ ${source}`;
|
|
|
44
117
|
}
|
|
45
118
|
|
|
46
119
|
// index.ts
|
|
47
|
-
import { dirname, isAbsolute, join
|
|
120
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join2, relative, resolve as resolve3 } from "path";
|
|
48
121
|
import { fileURLToPath } from "url";
|
|
49
122
|
import { createFilter } from "@rollup/pluginutils";
|
|
50
123
|
|
|
@@ -68,22 +141,26 @@ function getJSXMemberExpressionName(node) {
|
|
|
68
141
|
}
|
|
69
142
|
|
|
70
143
|
// ../../modules/file-parser/walk.ts
|
|
71
|
-
|
|
144
|
+
import visitorKeysImport from "oxc-parser/src-js/generated/visit/keys.js";
|
|
145
|
+
var importedKeys = visitorKeysImport;
|
|
146
|
+
var visitorKeys = importedKeys.default ?? importedKeys;
|
|
147
|
+
function walk(node, callbacks, parent = null) {
|
|
72
148
|
if (node === null || node === void 0 || typeof node !== "object") return;
|
|
73
149
|
if (Array.isArray(node)) {
|
|
74
150
|
for (const child of node) {
|
|
75
|
-
walk(child, callbacks);
|
|
151
|
+
walk(child, callbacks, parent);
|
|
76
152
|
}
|
|
77
153
|
return;
|
|
78
154
|
}
|
|
79
155
|
const record = node;
|
|
80
156
|
const type = record.type;
|
|
81
157
|
if (typeof type === "string" && type in callbacks) {
|
|
82
|
-
callbacks[type](node);
|
|
158
|
+
callbacks[type](node, parent);
|
|
83
159
|
}
|
|
160
|
+
const enclosing = typeof type === "string" ? node : parent;
|
|
84
161
|
for (const value of Object.values(record)) {
|
|
85
162
|
if (value !== null && typeof value === "object") {
|
|
86
|
-
walk(value, callbacks);
|
|
163
|
+
walk(value, callbacks, enclosing);
|
|
87
164
|
}
|
|
88
165
|
}
|
|
89
166
|
}
|
|
@@ -108,7 +185,6 @@ var ScopeFlags = {
|
|
|
108
185
|
|
|
109
186
|
// ../../modules/file-parser/scope-analyzer/scopeAnalyzer.ts
|
|
110
187
|
import { parseSync } from "oxc-parser";
|
|
111
|
-
import visitorKeysDefault from "oxc-parser/src-js/generated/visit/keys.js";
|
|
112
188
|
|
|
113
189
|
// ../../modules/annotation/annotate-file.ts
|
|
114
190
|
function formatPropValue(value) {
|
|
@@ -141,12 +217,13 @@ function annotateFile(source, filename, computeAnnotatedProps) {
|
|
|
141
217
|
const parseResult = parseSync2(filename, source);
|
|
142
218
|
const insertions = [];
|
|
143
219
|
walk(parseResult.program, {
|
|
144
|
-
JSXElement(node) {
|
|
220
|
+
JSXElement(node, parent) {
|
|
145
221
|
const element = node;
|
|
146
222
|
const tagName = getTagName(element.openingElement.name);
|
|
147
223
|
if (FRAGMENT_TAG_NAMES.has(tagName)) return;
|
|
224
|
+
const parentType = parent?.type ?? null;
|
|
148
225
|
const props = removeExistingProps(
|
|
149
|
-
computeAnnotatedProps({ element, tagName }),
|
|
226
|
+
computeAnnotatedProps({ element, tagName, parentType }),
|
|
150
227
|
getExistingAttributeNames(element)
|
|
151
228
|
);
|
|
152
229
|
if (Object.keys(props).length === 0) return;
|
|
@@ -173,78 +250,6 @@ function annotateFile(source, filename, computeAnnotatedProps) {
|
|
|
173
250
|
return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
|
|
174
251
|
}
|
|
175
252
|
|
|
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
253
|
// canvas-host-registration-contract.ts
|
|
249
254
|
var CANVAS_HOST_REGISTRATION_ENDPOINT = "/__tempo/canvas-host-registration";
|
|
250
255
|
var CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER = "x-tempo-canvas-host-registration";
|
|
@@ -281,6 +286,64 @@ function isComponentShaped(identity) {
|
|
|
281
286
|
return identity.name === null || /^[A-Z]/.test(identity.name);
|
|
282
287
|
}
|
|
283
288
|
|
|
289
|
+
// pruned-module-deletion.ts
|
|
290
|
+
function createPrunedModuleDeletionGuard() {
|
|
291
|
+
let sequence = 0;
|
|
292
|
+
let activeReceipts = 0;
|
|
293
|
+
let receipts = /* @__PURE__ */ new WeakMap();
|
|
294
|
+
return {
|
|
295
|
+
observePrune(graph, paths) {
|
|
296
|
+
const receipt = ++sequence;
|
|
297
|
+
for (const path of paths) {
|
|
298
|
+
const module = graph.urlToModuleMap.get(path);
|
|
299
|
+
if (module) {
|
|
300
|
+
if (!receipts.has(module)) activeReceipts++;
|
|
301
|
+
receipts.set(module, receipt);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
observeRequest(graph, url, base, fetchDestination, ifNoneMatch) {
|
|
306
|
+
if (!activeReceipts || ["document", "iframe", "frame"].includes(String(fetchDestination)))
|
|
307
|
+
return;
|
|
308
|
+
const requestSequence = sequence;
|
|
309
|
+
return async (status, contentType, responseEtag) => {
|
|
310
|
+
if (!activeReceipts || status < 200 || status >= 400) return;
|
|
311
|
+
if (status !== 304 && !/^text\/(?:javascript|css)(?:;|$)/i.test(String(contentType)))
|
|
312
|
+
return;
|
|
313
|
+
const etag = status === 304 ? ifNoneMatch : responseEtag;
|
|
314
|
+
if (typeof etag !== "string" || !graph.getModuleByEtag(etag)) return;
|
|
315
|
+
let moduleUrl = url;
|
|
316
|
+
if (base !== "/" && moduleUrl.startsWith(base))
|
|
317
|
+
moduleUrl = `/${moduleUrl.slice(base.length)}`;
|
|
318
|
+
try {
|
|
319
|
+
moduleUrl = decodeURI(moduleUrl).replace(/__x00__/g, "\0");
|
|
320
|
+
if (moduleUrl.startsWith("/@id/")) moduleUrl = moduleUrl.slice(5);
|
|
321
|
+
const [, id] = await graph.resolveUrl(moduleUrl);
|
|
322
|
+
const module = graph.getModuleById(id);
|
|
323
|
+
if (module && module.transformResult?.etag === etag && (receipts.get(module) ?? Infinity) <= requestSequence) {
|
|
324
|
+
receipts.delete(module);
|
|
325
|
+
activeReceipts--;
|
|
326
|
+
}
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
suppressDeletion(graph, modules) {
|
|
332
|
+
if (!modules.length || !modules.every(
|
|
333
|
+
(module) => receipts.has(module) && module.importers.size === 0
|
|
334
|
+
))
|
|
335
|
+
return false;
|
|
336
|
+
const invalidated = /* @__PURE__ */ new Set();
|
|
337
|
+
for (const module of modules) graph.invalidateModule(module, invalidated);
|
|
338
|
+
return true;
|
|
339
|
+
},
|
|
340
|
+
clear() {
|
|
341
|
+
receipts = /* @__PURE__ */ new WeakMap();
|
|
342
|
+
activeReceipts = 0;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
284
347
|
// hmr-generation-fence.ts
|
|
285
348
|
function generationIdentity(update) {
|
|
286
349
|
const type = typeof update.type === "string" ? update.type : null;
|
|
@@ -319,12 +382,15 @@ function createHmrGenerationFence() {
|
|
|
319
382
|
|
|
320
383
|
// host-identity.ts
|
|
321
384
|
import { readFileSync } from "fs";
|
|
322
|
-
import { resolve } from "path";
|
|
385
|
+
import { resolve as resolve2 } from "path";
|
|
323
386
|
|
|
324
387
|
// package.json
|
|
325
388
|
var package_default = {
|
|
326
389
|
name: "tempo-sdk",
|
|
327
|
-
version: "0.0.
|
|
390
|
+
version: "0.0.57",
|
|
391
|
+
publishConfig: {
|
|
392
|
+
tag: "sdk-v2-latest"
|
|
393
|
+
},
|
|
328
394
|
type: "module",
|
|
329
395
|
description: "Tempo SDK \u2014 Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types",
|
|
330
396
|
repository: {
|
|
@@ -405,7 +471,7 @@ var package_default = {
|
|
|
405
471
|
demo: "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
|
|
406
472
|
"demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
|
|
407
473
|
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",
|
|
474
|
+
"test:browser": "vitest run 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
475
|
"test:watch": "vitest",
|
|
410
476
|
"test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
|
|
411
477
|
"test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
|
|
@@ -458,6 +524,17 @@ var package_default = {
|
|
|
458
524
|
}
|
|
459
525
|
};
|
|
460
526
|
|
|
527
|
+
// release-channel.ts
|
|
528
|
+
var TEMPO_SDK_CHANNEL = package_default.publishConfig.tag;
|
|
529
|
+
function sdkChannelGeneration(channel) {
|
|
530
|
+
if (typeof channel !== "string") return null;
|
|
531
|
+
const match = /^sdk-v([1-9]\d*)-latest$/.exec(channel);
|
|
532
|
+
return match ? Number(match[1]) : null;
|
|
533
|
+
}
|
|
534
|
+
if (sdkChannelGeneration(TEMPO_SDK_CHANNEL) === null) {
|
|
535
|
+
throw new Error("tempo-sdk publishConfig.tag must be sdk-v<N>-latest");
|
|
536
|
+
}
|
|
537
|
+
|
|
461
538
|
// host-identity.ts
|
|
462
539
|
var TEMPO_HOST_IDENTITY_ENDPOINT = "/__tempo/identity";
|
|
463
540
|
var TEMPO_HOST_IDENTITY_CAPABILITY_HEADER = "x-tempo-host-identity";
|
|
@@ -477,7 +554,7 @@ function readTempoWorkspaceNonce(root = process.cwd()) {
|
|
|
477
554
|
if (fromEnvironment) return fromEnvironment;
|
|
478
555
|
try {
|
|
479
556
|
return normalizeWorkspaceNonce(
|
|
480
|
-
readFileSync(
|
|
557
|
+
readFileSync(resolve2(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
|
|
481
558
|
);
|
|
482
559
|
} catch {
|
|
483
560
|
return "";
|
|
@@ -489,6 +566,7 @@ function createTempoHostIdentity(framework, options = {}) {
|
|
|
489
566
|
contractVersion: TEMPO_HOST_IDENTITY_CONTRACT_VERSION,
|
|
490
567
|
workspaceNonce: readTempoWorkspaceNonce(options.root),
|
|
491
568
|
sdkVersion: package_default.version,
|
|
569
|
+
sdkChannel: TEMPO_SDK_CHANNEL,
|
|
492
570
|
pluginActive: options.pluginActive ?? Boolean(process.env.TEMPO),
|
|
493
571
|
framework
|
|
494
572
|
};
|
|
@@ -574,8 +652,8 @@ function createRapidHotUpdateReplay(options) {
|
|
|
574
652
|
previous.release = void 0;
|
|
575
653
|
if (previous.expiry) cancel(previous.expiry);
|
|
576
654
|
} else {
|
|
577
|
-
burst.gate = new Promise((
|
|
578
|
-
burst.release =
|
|
655
|
+
burst.gate = new Promise((resolve4) => {
|
|
656
|
+
burst.release = resolve4;
|
|
579
657
|
});
|
|
580
658
|
}
|
|
581
659
|
burst.expiry = schedule(() => burst.release?.(), quietMs * 2);
|
|
@@ -625,6 +703,23 @@ function createRapidHotUpdateReplay(options) {
|
|
|
625
703
|
var installed = /* @__PURE__ */ new WeakSet();
|
|
626
704
|
function installSynchronousReactRefreshBoundary(plugins) {
|
|
627
705
|
for (const plugin of plugins) {
|
|
706
|
+
if (plugin.name === "vite:react-refresh" && plugin.load && !installed.has(plugin)) {
|
|
707
|
+
installed.add(plugin);
|
|
708
|
+
const hook2 = plugin.load;
|
|
709
|
+
const load = typeof hook2 === "function" ? hook2 : hook2.handler;
|
|
710
|
+
const wrapped2 = async function(...args) {
|
|
711
|
+
const result = await load.apply(this, args);
|
|
712
|
+
if (!result || args[0] !== "/@react-refresh") return result;
|
|
713
|
+
const source = typeof result === "string" ? result : result.code;
|
|
714
|
+
if (!source || !/\b(?:let|const) allFamiliesByType = new WeakMap\(\)/.test(source) || !source.includes("function performReactRefresh()"))
|
|
715
|
+
return result;
|
|
716
|
+
const code = `${source}
|
|
717
|
+
globalThis[Symbol.for("tempo.react-refresh.family")] = (type) => allFamiliesByType.get(type);
|
|
718
|
+
`;
|
|
719
|
+
return typeof result === "string" ? code : { ...result, code };
|
|
720
|
+
};
|
|
721
|
+
plugin.load = typeof hook2 === "function" ? wrapped2 : { ...hook2, handler: wrapped2 };
|
|
722
|
+
}
|
|
628
723
|
if (plugin.name !== "vite:react-babel" || !plugin.transform || installed.has(plugin))
|
|
629
724
|
continue;
|
|
630
725
|
installed.add(plugin);
|
|
@@ -651,6 +746,63 @@ ${register}
|
|
|
651
746
|
}
|
|
652
747
|
}
|
|
653
748
|
|
|
749
|
+
// sdk-package-files.ts
|
|
750
|
+
import { readFileSync as readFileSync2, realpathSync as realpathSync2 } from "fs";
|
|
751
|
+
import { dirname as dirname2, join } from "path";
|
|
752
|
+
var SDK_PACKAGE_NAME = "tempo-sdk";
|
|
753
|
+
var SDK_NODE_MODULES_SEGMENT = `/node_modules/${SDK_PACKAGE_NAME}/`;
|
|
754
|
+
function createSdkFileMatcher() {
|
|
755
|
+
const ownerIsSdkByDirectory = /* @__PURE__ */ new Map();
|
|
756
|
+
const nearestPackageIsSdk = (startDirectory) => {
|
|
757
|
+
const visited = [];
|
|
758
|
+
let directory = startDirectory;
|
|
759
|
+
let isSdk = false;
|
|
760
|
+
while (true) {
|
|
761
|
+
const cached = ownerIsSdkByDirectory.get(directory);
|
|
762
|
+
if (cached !== void 0) {
|
|
763
|
+
isSdk = cached;
|
|
764
|
+
break;
|
|
765
|
+
}
|
|
766
|
+
visited.push(directory);
|
|
767
|
+
const manifest = readPackageManifest(directory);
|
|
768
|
+
if (manifest !== void 0) {
|
|
769
|
+
isSdk = manifest?.name === SDK_PACKAGE_NAME;
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
const parent = dirname2(directory);
|
|
773
|
+
if (parent === directory) break;
|
|
774
|
+
directory = parent;
|
|
775
|
+
}
|
|
776
|
+
for (const entry of visited) ownerIsSdkByDirectory.set(entry, isSdk);
|
|
777
|
+
return isSdk;
|
|
778
|
+
};
|
|
779
|
+
return (file) => {
|
|
780
|
+
if (file.replace(/\\/g, "/").includes(SDK_NODE_MODULES_SEGMENT)) {
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
let realFile = file;
|
|
784
|
+
try {
|
|
785
|
+
realFile = realpathSync2.native(file);
|
|
786
|
+
} catch {
|
|
787
|
+
}
|
|
788
|
+
return nearestPackageIsSdk(dirname2(realFile));
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
function readPackageManifest(directory) {
|
|
792
|
+
let text;
|
|
793
|
+
try {
|
|
794
|
+
text = readFileSync2(join(directory, "package.json"), "utf8");
|
|
795
|
+
} catch {
|
|
796
|
+
return void 0;
|
|
797
|
+
}
|
|
798
|
+
try {
|
|
799
|
+
const manifest = JSON.parse(text);
|
|
800
|
+
return manifest && typeof manifest === "object" ? manifest : null;
|
|
801
|
+
} catch {
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
654
806
|
// vite-client-pending-updates.ts
|
|
655
807
|
function preservePendingViteModuleUpdates(source) {
|
|
656
808
|
const missingBoundary = /(const mod = this\.hotModulesMap\.get\(path\);\s*)if \(!mod\)\s*(?:return;|\{\s*return;\s*\})/;
|
|
@@ -810,10 +962,10 @@ var INTERACT_PROJECTION_CLIENT_ID = "\0tempo:interact-projection";
|
|
|
810
962
|
var VITE_ERROR_CLIENT_ID = "\0tempo:server-errors";
|
|
811
963
|
var INTERACT_PROJECTION_SDK_SPECIFIER = "tempo-sdk/canvas/interact-projection";
|
|
812
964
|
function resolveOwnInteractProjectionModule() {
|
|
813
|
-
const selfDir =
|
|
965
|
+
const selfDir = dirname3(fileURLToPath(import.meta.url));
|
|
814
966
|
for (const candidate of [
|
|
815
|
-
|
|
816
|
-
|
|
967
|
+
join2(selfDir, "canvas", "interact-projection.ts"),
|
|
968
|
+
join2(selfDir, "canvas", "interact-projection.js")
|
|
817
969
|
]) {
|
|
818
970
|
if (existsSync(candidate)) return candidate.replace(/\\/g, "/");
|
|
819
971
|
}
|
|
@@ -893,18 +1045,18 @@ function barePackageName(specifier) {
|
|
|
893
1045
|
function resolvedIdMatchesFile(id, file) {
|
|
894
1046
|
const resolvedFile = fsPathFromModuleId(id);
|
|
895
1047
|
try {
|
|
896
|
-
return
|
|
1048
|
+
return realpathSync3.native(resolvedFile) === realpathSync3.native(file);
|
|
897
1049
|
} catch {
|
|
898
1050
|
return resolvedFile.replace(/\\/g, "/") === file.replace(/\\/g, "/");
|
|
899
1051
|
}
|
|
900
1052
|
}
|
|
901
1053
|
function moduleIdsMatch(left, right) {
|
|
902
|
-
const
|
|
903
|
-
return
|
|
1054
|
+
const normalize2 = (value) => cleanModuleId(value).replace(/^file:\/\//, "").replace(/^\/@fs\//, "/").replace(/\\/g, "/").replace(/^\/+/, "");
|
|
1055
|
+
return normalize2(left) === normalize2(right);
|
|
904
1056
|
}
|
|
905
1057
|
function resolveCanonicalRoot(root) {
|
|
906
1058
|
try {
|
|
907
|
-
return
|
|
1059
|
+
return realpathSync3.native(root);
|
|
908
1060
|
} catch {
|
|
909
1061
|
return root;
|
|
910
1062
|
}
|
|
@@ -977,10 +1129,10 @@ function createErrorServer(onErrorFile, onState) {
|
|
|
977
1129
|
return server;
|
|
978
1130
|
}
|
|
979
1131
|
function readBody(req) {
|
|
980
|
-
return new Promise((
|
|
1132
|
+
return new Promise((resolve4, reject) => {
|
|
981
1133
|
const chunks = [];
|
|
982
1134
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
983
|
-
req.on("end", () =>
|
|
1135
|
+
req.on("end", () => resolve4(Buffer.concat(chunks).toString()));
|
|
984
1136
|
req.on("error", reject);
|
|
985
1137
|
});
|
|
986
1138
|
}
|
|
@@ -1000,10 +1152,10 @@ function readGeneratedCanvasPaths(source) {
|
|
|
1000
1152
|
return [...paths];
|
|
1001
1153
|
}
|
|
1002
1154
|
async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
1003
|
-
const wrapperPath =
|
|
1155
|
+
const wrapperPath = resolve3(server.config.root, ".tempo", "tempo-host.tsx");
|
|
1004
1156
|
let wrapperSource;
|
|
1005
1157
|
try {
|
|
1006
|
-
wrapperSource =
|
|
1158
|
+
wrapperSource = readFileSync3(wrapperPath, "utf8");
|
|
1007
1159
|
} catch (error) {
|
|
1008
1160
|
throw new Error(
|
|
1009
1161
|
`Canvas host wrapper is unavailable at ${wrapperPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -1020,7 +1172,7 @@ async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
|
1020
1172
|
{ statusCode: 409 }
|
|
1021
1173
|
);
|
|
1022
1174
|
}
|
|
1023
|
-
const canonicalWrapperPath =
|
|
1175
|
+
const canonicalWrapperPath = realpathSync3(wrapperPath);
|
|
1024
1176
|
const modulePattern = /\bcanvasPath:\s*("(?:\\.|[^"\\])*")\s*,\s*load:\s*\(\)\s*=>\s*import\(\s*("(?:\\.|[^"\\])*")\s*\)/g;
|
|
1025
1177
|
const transformer = server.environments?.client ?? server;
|
|
1026
1178
|
for (const match of wrapperSource.matchAll(modulePattern)) {
|
|
@@ -1034,7 +1186,7 @@ async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
|
1034
1186
|
const modulePath = fsPathFromModuleId(resolvedModule.id);
|
|
1035
1187
|
await retransformCanvasHostWrapper(
|
|
1036
1188
|
transformer,
|
|
1037
|
-
|
|
1189
|
+
realpathSync3(modulePath),
|
|
1038
1190
|
modulePath,
|
|
1039
1191
|
`/@fs/${modulePath.replace(/^\/+/, "")}`
|
|
1040
1192
|
);
|
|
@@ -1058,6 +1210,10 @@ async function retransformCanvasHostWrapper(transformer, canonicalWrapperPath, w
|
|
|
1058
1210
|
}
|
|
1059
1211
|
function writeCanvasRegistrationResponseHeaders(res) {
|
|
1060
1212
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1213
|
+
res.setHeader(
|
|
1214
|
+
"Access-Control-Expose-Headers",
|
|
1215
|
+
CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER
|
|
1216
|
+
);
|
|
1061
1217
|
res.setHeader(CANVAS_HOST_REGISTRATION_CAPABILITY_HEADER, "1");
|
|
1062
1218
|
}
|
|
1063
1219
|
function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
@@ -1156,6 +1312,7 @@ function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
|
1156
1312
|
var MISSED_CHANGE_SWEEP_INTERVAL_MS = 3e3;
|
|
1157
1313
|
var COMPILE_ERROR_POLL_MAX_INTERVAL_MS = 3e4;
|
|
1158
1314
|
function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs, pollCompileErrorRecovery) {
|
|
1315
|
+
const cacheDir = server.config.cacheDir?.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1159
1316
|
const sweep = createMissedChangeSweep({
|
|
1160
1317
|
listServedFiles: () => {
|
|
1161
1318
|
const files = new Map(
|
|
@@ -1164,14 +1321,21 @@ function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs,
|
|
|
1164
1321
|
const errorFiles = listErrorFiles();
|
|
1165
1322
|
for (const errorFile of errorFiles) {
|
|
1166
1323
|
const cleanFile = fsPathFromModuleId(errorFile);
|
|
1167
|
-
const file =
|
|
1324
|
+
const file = isAbsolute2(cleanFile) ? cleanFile : resolve3(server.config.root, cleanFile);
|
|
1168
1325
|
if (!files.has(file)) files.set(file, []);
|
|
1169
1326
|
}
|
|
1327
|
+
if (cacheDir) {
|
|
1328
|
+
for (const file of files.keys()) {
|
|
1329
|
+
if (file.replace(/\\/g, "/").startsWith(`${cacheDir}/`)) {
|
|
1330
|
+
files.delete(file);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1170
1334
|
return files.entries();
|
|
1171
1335
|
},
|
|
1172
1336
|
statMtimeMs: async (file) => {
|
|
1173
1337
|
try {
|
|
1174
|
-
return
|
|
1338
|
+
return statSync(file).mtimeMs;
|
|
1175
1339
|
} catch {
|
|
1176
1340
|
return null;
|
|
1177
1341
|
}
|
|
@@ -1236,11 +1400,14 @@ function tempoVitePlugin(options = {}) {
|
|
|
1236
1400
|
const enabled = !!process.env.TEMPO;
|
|
1237
1401
|
const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
|
|
1238
1402
|
const exclude = options.exclude === void 0 ? DEFAULT_EXCLUDE : options.exclude;
|
|
1239
|
-
const
|
|
1240
|
-
const
|
|
1403
|
+
const isSdkFile = createSdkFileMatcher();
|
|
1404
|
+
const userFilter = createFilter(include, exclude);
|
|
1405
|
+
const filter = (id) => userFilter(id) && !isSdkFile(id);
|
|
1406
|
+
const userControlsFilter = createFilter(
|
|
1241
1407
|
["**/*.tsx", "**/*.jsx", "**/*.ts", "**/*.js"],
|
|
1242
1408
|
exclude
|
|
1243
1409
|
);
|
|
1410
|
+
const controlsFilter = (id) => userControlsFilter(id) && !isSdkFile(id);
|
|
1244
1411
|
const controlsModules = /* @__PURE__ */ new Set();
|
|
1245
1412
|
function transformControls(source, id) {
|
|
1246
1413
|
const code = transformControlsForHmr(source, id, controlsModules.has(id));
|
|
@@ -1263,6 +1430,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1263
1430
|
let rerunUnresolvedImportResolution = false;
|
|
1264
1431
|
let unresolvedImportWatchRearmTimer = null;
|
|
1265
1432
|
const processedUpdatePayloads = /* @__PURE__ */ new WeakSet();
|
|
1433
|
+
const prunedModuleDeletion = createPrunedModuleDeletionGuard();
|
|
1266
1434
|
const hmrGenerationFence = createHmrGenerationFence();
|
|
1267
1435
|
const rapidHotUpdateReplay = createRapidHotUpdateReplay();
|
|
1268
1436
|
const hotUpdateMtimesMs = /* @__PURE__ */ new Map();
|
|
@@ -1272,7 +1440,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1272
1440
|
const cleanFile = fsPathFromModuleId(file);
|
|
1273
1441
|
const key = normalizedFileKey(cleanFile);
|
|
1274
1442
|
try {
|
|
1275
|
-
hotUpdateMtimesMs.set(key,
|
|
1443
|
+
hotUpdateMtimesMs.set(key, statSync(cleanFile).mtimeMs);
|
|
1276
1444
|
} catch {
|
|
1277
1445
|
hotUpdateMtimesMs.delete(key);
|
|
1278
1446
|
}
|
|
@@ -1290,7 +1458,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1290
1458
|
try {
|
|
1291
1459
|
let canonicalFile = cleanFile;
|
|
1292
1460
|
try {
|
|
1293
|
-
canonicalFile =
|
|
1461
|
+
canonicalFile = realpathSync3(cleanFile);
|
|
1294
1462
|
} catch {
|
|
1295
1463
|
}
|
|
1296
1464
|
const modules = /* @__PURE__ */ new Set([
|
|
@@ -1349,27 +1517,45 @@ function tempoVitePlugin(options = {}) {
|
|
|
1349
1517
|
const canonicalIdentityKey = (idOrFile) => {
|
|
1350
1518
|
const file = fsPathFromModuleId(idOrFile);
|
|
1351
1519
|
try {
|
|
1352
|
-
return
|
|
1520
|
+
return realpathSync3.native(file);
|
|
1353
1521
|
} catch {
|
|
1354
1522
|
return file.replace(/\\/g, "/");
|
|
1355
1523
|
}
|
|
1356
1524
|
};
|
|
1357
|
-
const repairDefaultExportIdentityRewrite = (
|
|
1525
|
+
const repairDefaultExportIdentityRewrite = async (context) => {
|
|
1526
|
+
const { file } = context;
|
|
1358
1527
|
const key = canonicalIdentityKey(file);
|
|
1359
|
-
|
|
1360
|
-
if (before === void 0) return false;
|
|
1528
|
+
if (!defaultExportIdentityByFile.has(key)) return false;
|
|
1361
1529
|
let source;
|
|
1362
1530
|
try {
|
|
1363
|
-
source =
|
|
1531
|
+
source = readFileSync3(file, "utf8");
|
|
1532
|
+
if (source.length === 0) source = await context.read();
|
|
1364
1533
|
} catch {
|
|
1365
1534
|
return false;
|
|
1366
1535
|
}
|
|
1536
|
+
const before = defaultExportIdentityByFile.get(key);
|
|
1537
|
+
if (before === void 0) return false;
|
|
1367
1538
|
const after = readDefaultExportIdentity(source);
|
|
1368
1539
|
defaultExportIdentityByFile.set(key, after);
|
|
1369
1540
|
if (!isDefaultExportIdentityRewrite(before, after)) return false;
|
|
1370
1541
|
devServer?.ws.send({ type: "full-reload", path: "*" });
|
|
1371
1542
|
return true;
|
|
1372
1543
|
};
|
|
1544
|
+
const invalidateCanvasLoader = (file, graph, modules) => {
|
|
1545
|
+
const canvasPath = relative(sourceIdentityRoot, file).replace(/\\/g, "/");
|
|
1546
|
+
const wrapperPath = resolve3(canonicalRoot, ".tempo", "tempo-host.tsx");
|
|
1547
|
+
let source;
|
|
1548
|
+
try {
|
|
1549
|
+
source = readFileSync3(wrapperPath, "utf8");
|
|
1550
|
+
} catch {
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
if (!readGeneratedCanvasPaths(source).includes(canvasPath)) return;
|
|
1554
|
+
const wrappers = graph.getModulesByFile(wrapperPath);
|
|
1555
|
+
if (!wrappers?.size) return;
|
|
1556
|
+
for (const wrapper of wrappers) graph.invalidateModule(wrapper);
|
|
1557
|
+
return [.../* @__PURE__ */ new Set([...modules, ...wrappers])];
|
|
1558
|
+
};
|
|
1373
1559
|
const rememberUnresolvedImport = (specifier, importer, packageName) => {
|
|
1374
1560
|
const key = `${importer}\0${specifier}`;
|
|
1375
1561
|
unresolvedImports.delete(key);
|
|
@@ -1421,28 +1607,28 @@ function tempoVitePlugin(options = {}) {
|
|
|
1421
1607
|
(unresolved) => unresolved.packageName !== void 0
|
|
1422
1608
|
);
|
|
1423
1609
|
const packageWatchTarget = (unresolved) => {
|
|
1424
|
-
let candidate =
|
|
1610
|
+
let candidate = dirname3(cleanModuleId(unresolved.importer));
|
|
1425
1611
|
let nearestPackageRoot;
|
|
1426
1612
|
while (true) {
|
|
1427
1613
|
try {
|
|
1428
|
-
if (
|
|
1429
|
-
return
|
|
1614
|
+
if (statSync(join2(candidate, "node_modules")).isDirectory()) {
|
|
1615
|
+
return join2(candidate, "node_modules", unresolved.packageName);
|
|
1430
1616
|
}
|
|
1431
1617
|
} catch {
|
|
1432
1618
|
}
|
|
1433
1619
|
if (nearestPackageRoot === void 0) {
|
|
1434
1620
|
try {
|
|
1435
|
-
if (
|
|
1621
|
+
if (statSync(join2(candidate, "package.json")).isFile()) {
|
|
1436
1622
|
nearestPackageRoot = candidate;
|
|
1437
1623
|
}
|
|
1438
1624
|
} catch {
|
|
1439
1625
|
}
|
|
1440
1626
|
}
|
|
1441
|
-
const parent =
|
|
1627
|
+
const parent = dirname3(candidate);
|
|
1442
1628
|
if (parent === candidate) break;
|
|
1443
1629
|
candidate = parent;
|
|
1444
1630
|
}
|
|
1445
|
-
return
|
|
1631
|
+
return join2(
|
|
1446
1632
|
nearestPackageRoot ?? canonicalRoot,
|
|
1447
1633
|
"node_modules",
|
|
1448
1634
|
unresolved.packageName
|
|
@@ -1451,8 +1637,8 @@ function tempoVitePlugin(options = {}) {
|
|
|
1451
1637
|
const unresolvedImportWatchTarget = (unresolved) => {
|
|
1452
1638
|
return unresolved.packageName ? packageWatchTarget(
|
|
1453
1639
|
unresolved
|
|
1454
|
-
) :
|
|
1455
|
-
|
|
1640
|
+
) : resolve3(
|
|
1641
|
+
dirname3(cleanModuleId(unresolved.importer)),
|
|
1456
1642
|
cleanModuleId(unresolved.specifier)
|
|
1457
1643
|
);
|
|
1458
1644
|
};
|
|
@@ -1460,10 +1646,10 @@ function tempoVitePlugin(options = {}) {
|
|
|
1460
1646
|
let candidate = target;
|
|
1461
1647
|
while (true) {
|
|
1462
1648
|
try {
|
|
1463
|
-
if (
|
|
1649
|
+
if (statSync(candidate).isDirectory()) return candidate;
|
|
1464
1650
|
} catch {
|
|
1465
1651
|
}
|
|
1466
|
-
const parent =
|
|
1652
|
+
const parent = dirname3(candidate);
|
|
1467
1653
|
if (parent === candidate) return void 0;
|
|
1468
1654
|
candidate = parent;
|
|
1469
1655
|
}
|
|
@@ -1540,8 +1726,8 @@ function tempoVitePlugin(options = {}) {
|
|
|
1540
1726
|
if (isRelativeImportSpecifier(unresolved.specifier)) {
|
|
1541
1727
|
const suffixIndex = unresolved.specifier.search(/[?#]/);
|
|
1542
1728
|
const relativePath = suffixIndex < 0 ? unresolved.specifier : unresolved.specifier.slice(0, suffixIndex);
|
|
1543
|
-
const candidate =
|
|
1544
|
-
|
|
1729
|
+
const candidate = resolve3(
|
|
1730
|
+
dirname3(cleanModuleId(unresolved.importer)),
|
|
1545
1731
|
relativePath
|
|
1546
1732
|
);
|
|
1547
1733
|
const probes = [
|
|
@@ -1550,12 +1736,12 @@ function tempoVitePlugin(options = {}) {
|
|
|
1550
1736
|
(extension) => `${candidate}${extension}`
|
|
1551
1737
|
),
|
|
1552
1738
|
...RELATIVE_IMPORT_RESOLVE_EXTENSIONS.map(
|
|
1553
|
-
(extension) =>
|
|
1739
|
+
(extension) => join2(candidate, `index${extension}`)
|
|
1554
1740
|
)
|
|
1555
1741
|
];
|
|
1556
1742
|
for (const probe of probes) {
|
|
1557
1743
|
try {
|
|
1558
|
-
if (
|
|
1744
|
+
if (statSync(probe).isFile()) {
|
|
1559
1745
|
file = probe;
|
|
1560
1746
|
break;
|
|
1561
1747
|
}
|
|
@@ -1590,6 +1776,16 @@ function tempoVitePlugin(options = {}) {
|
|
|
1590
1776
|
name: "tempo-annotate",
|
|
1591
1777
|
apply: "serve",
|
|
1592
1778
|
enforce: "pre",
|
|
1779
|
+
config(config, environment) {
|
|
1780
|
+
if (!enabled || environment.command !== "serve") return;
|
|
1781
|
+
const dedupe = ["react", "react-dom"].filter(
|
|
1782
|
+
(name) => !config.resolve?.dedupe?.includes(name)
|
|
1783
|
+
);
|
|
1784
|
+
return {
|
|
1785
|
+
resolve: { dedupe },
|
|
1786
|
+
...config.css?.devSourcemap === void 0 ? { css: { devSourcemap: true } } : {}
|
|
1787
|
+
};
|
|
1788
|
+
},
|
|
1593
1789
|
resolveId: {
|
|
1594
1790
|
order: "pre",
|
|
1595
1791
|
async handler(id, importer, resolveOptions) {
|
|
@@ -1714,17 +1910,20 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1714
1910
|
}
|
|
1715
1911
|
canonicalRoot = resolveCanonicalRoot(resolvedConfig.root);
|
|
1716
1912
|
sourceIdentityRoot = options.sourceIdentityRoot ? resolveCanonicalRoot(
|
|
1717
|
-
|
|
1913
|
+
resolve3(resolvedConfig.root, options.sourceIdentityRoot)
|
|
1718
1914
|
) : canonicalRoot;
|
|
1719
1915
|
},
|
|
1720
1916
|
configureServer(server) {
|
|
1721
1917
|
if (!enabled) return;
|
|
1918
|
+
const events = ["change", "add", "unlink"];
|
|
1919
|
+
for (const event of events)
|
|
1920
|
+
server.watcher?.prependListener?.(event, recordHotUpdateCoverage);
|
|
1722
1921
|
const ownInteractModule = resolveOwnInteractProjectionModule();
|
|
1723
1922
|
const allow = server.config?.server?.fs?.allow;
|
|
1724
1923
|
if (Array.isArray(allow)) {
|
|
1725
1924
|
const requiredRoots = [
|
|
1726
1925
|
sourceIdentityRoot,
|
|
1727
|
-
...ownInteractModule ? [
|
|
1926
|
+
...ownInteractModule ? [dirname3(ownInteractModule)] : []
|
|
1728
1927
|
];
|
|
1729
1928
|
for (const requiredRoot of requiredRoots) {
|
|
1730
1929
|
if (!allow.includes(requiredRoot)) allow.push(requiredRoot);
|
|
@@ -1738,12 +1937,30 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1738
1937
|
server.watcher?.once?.("close", closeUnresolvedImportWatchers);
|
|
1739
1938
|
server.httpServer?.once("close", closeUnresolvedImportWatchers);
|
|
1740
1939
|
server.middlewares.use((req, res, next) => {
|
|
1940
|
+
const graph = server.environments?.client?.moduleGraph;
|
|
1941
|
+
if (graph && req.url && (req.method === "GET" || req.method === "HEAD")) {
|
|
1942
|
+
const observeResponse = prunedModuleDeletion.observeRequest(
|
|
1943
|
+
graph,
|
|
1944
|
+
req.url,
|
|
1945
|
+
server.config.base,
|
|
1946
|
+
req.headers["sec-fetch-dest"],
|
|
1947
|
+
req.headers["if-none-match"]
|
|
1948
|
+
);
|
|
1949
|
+
if (observeResponse)
|
|
1950
|
+
res.once("finish", () => {
|
|
1951
|
+
void observeResponse(
|
|
1952
|
+
res.statusCode,
|
|
1953
|
+
res.getHeader("content-type"),
|
|
1954
|
+
res.getHeader("etag")
|
|
1955
|
+
);
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1741
1958
|
const name = req.url?.match(
|
|
1742
1959
|
/^\/tempo-assets\/([a-zA-Z0-9._-]+)(?:\?.*)?$/
|
|
1743
1960
|
)?.[1];
|
|
1744
1961
|
if (name) {
|
|
1745
1962
|
const file = ["public", "static"].map(
|
|
1746
|
-
(directory) =>
|
|
1963
|
+
(directory) => join2(sourceIdentityRoot, directory, "tempo-assets", name)
|
|
1747
1964
|
).find((file2) => existsSync(file2));
|
|
1748
1965
|
if (file) req.url = `/@fs/${file.replace(/\\/g, "/")}`;
|
|
1749
1966
|
}
|
|
@@ -1762,6 +1979,14 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1762
1979
|
const payload = args[0];
|
|
1763
1980
|
if (typeof payload === "object" && payload !== null && "type" in payload) {
|
|
1764
1981
|
const typed = payload;
|
|
1982
|
+
if (typed.type === "prune") {
|
|
1983
|
+
const graph = server.environments?.client?.moduleGraph;
|
|
1984
|
+
if (graph)
|
|
1985
|
+
prunedModuleDeletion.observePrune(
|
|
1986
|
+
graph,
|
|
1987
|
+
typed.paths ?? []
|
|
1988
|
+
);
|
|
1989
|
+
}
|
|
1765
1990
|
if (typed.type === "error") {
|
|
1766
1991
|
const err = typed.err;
|
|
1767
1992
|
errorServer.setError({
|
|
@@ -1803,6 +2028,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1803
2028
|
devServer = void 0;
|
|
1804
2029
|
rapidHotUpdateReplay.clear();
|
|
1805
2030
|
hmrGenerationFence.clear();
|
|
2031
|
+
prunedModuleDeletion.clear();
|
|
1806
2032
|
hotUpdateMtimesMs.clear();
|
|
1807
2033
|
compileErrorPollSchedule.clear();
|
|
1808
2034
|
closeUnresolvedImportWatchers();
|
|
@@ -1816,7 +2042,6 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1816
2042
|
)) {
|
|
1817
2043
|
return [];
|
|
1818
2044
|
}
|
|
1819
|
-
recordHotUpdateCoverage(context.file);
|
|
1820
2045
|
if (context.type === "update" && context.modules.length > 0) {
|
|
1821
2046
|
rapidHotUpdateReplay.observe(burstKey(context.file), () => {
|
|
1822
2047
|
context.server.config.logger.info(
|
|
@@ -1836,11 +2061,23 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1836
2061
|
defaultExportIdentityByFile.delete(
|
|
1837
2062
|
canonicalIdentityKey(context.file)
|
|
1838
2063
|
);
|
|
2064
|
+
if (prunedModuleDeletion.suppressDeletion(
|
|
2065
|
+
this.environment.moduleGraph,
|
|
2066
|
+
context.modules
|
|
2067
|
+
))
|
|
2068
|
+
return [];
|
|
1839
2069
|
return;
|
|
1840
2070
|
}
|
|
1841
|
-
if (context.type === "update" && repairDefaultExportIdentityRewrite(context
|
|
2071
|
+
if (context.type === "update" && await repairDefaultExportIdentityRewrite(context)) {
|
|
1842
2072
|
return [];
|
|
1843
2073
|
}
|
|
2074
|
+
if (context.type === "update") {
|
|
2075
|
+
return invalidateCanvasLoader(
|
|
2076
|
+
context.file,
|
|
2077
|
+
this.environment.moduleGraph,
|
|
2078
|
+
context.modules
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
1844
2081
|
}
|
|
1845
2082
|
},
|
|
1846
2083
|
// Vite 5 compatibility. Vite 6+ prefers `hotUpdate` above.
|
|
@@ -1848,7 +2085,6 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1848
2085
|
order: "post",
|
|
1849
2086
|
async handler(context) {
|
|
1850
2087
|
if (!enabled) return;
|
|
1851
|
-
recordHotUpdateCoverage(context.file);
|
|
1852
2088
|
if (context.modules.length > 0) {
|
|
1853
2089
|
rapidHotUpdateReplay.observe(burstKey(context.file), () => {
|
|
1854
2090
|
context.server.config.logger.info(
|
|
@@ -1862,9 +2098,14 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1862
2098
|
if (hasActiveCompileError(context.file) && await recoverActiveCompileError(context.server, context.file)) {
|
|
1863
2099
|
return [];
|
|
1864
2100
|
}
|
|
1865
|
-
if (repairDefaultExportIdentityRewrite(context
|
|
2101
|
+
if (await repairDefaultExportIdentityRewrite(context)) {
|
|
1866
2102
|
return [];
|
|
1867
2103
|
}
|
|
2104
|
+
return invalidateCanvasLoader(
|
|
2105
|
+
context.file,
|
|
2106
|
+
context.server.moduleGraph,
|
|
2107
|
+
context.modules
|
|
2108
|
+
);
|
|
1868
2109
|
}
|
|
1869
2110
|
},
|
|
1870
2111
|
transformIndexHtml(html, context) {
|
|
@@ -1929,7 +2170,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1929
2170
|
}
|
|
1930
2171
|
return tags.length > 0 ? tags : void 0;
|
|
1931
2172
|
},
|
|
1932
|
-
transform(source, id) {
|
|
2173
|
+
async transform(source, id) {
|
|
1933
2174
|
if (!enabled || command === "build") {
|
|
1934
2175
|
return null;
|
|
1935
2176
|
}
|
|
@@ -1948,10 +2189,46 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1948
2189
|
return null;
|
|
1949
2190
|
}
|
|
1950
2191
|
try {
|
|
1951
|
-
const filepath =
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
2192
|
+
const filepath = relative(canonicalRoot, cleanId);
|
|
2193
|
+
const descriptor = openSync(cleanId, "r");
|
|
2194
|
+
let snapshot;
|
|
2195
|
+
try {
|
|
2196
|
+
const before2 = fstatSync(descriptor);
|
|
2197
|
+
const rawSource2 = readFileSync3(descriptor, "utf8");
|
|
2198
|
+
snapshot = { before: before2, rawSource: rawSource2, after: fstatSync(descriptor) };
|
|
2199
|
+
} finally {
|
|
2200
|
+
closeSync(descriptor);
|
|
2201
|
+
}
|
|
2202
|
+
const { before, after, rawSource } = snapshot;
|
|
2203
|
+
const stable = ["mtimeMs", "ctimeMs", "size", "ino", "dev"];
|
|
2204
|
+
let loadedSource = source === rawSource ? source : void 0;
|
|
2205
|
+
if (loadedSource === void 0 && typeof this.getCombinedSourcemap === "function") {
|
|
2206
|
+
try {
|
|
2207
|
+
const map = this.getCombinedSourcemap();
|
|
2208
|
+
const sourceRoot = map.sourceRoot;
|
|
2209
|
+
const matches = map.sources.flatMap((path, index) => {
|
|
2210
|
+
const sourcePath = path.startsWith("file:") ? fileURLToPath(path) : path;
|
|
2211
|
+
const file = isAbsolute2(sourcePath) ? sourcePath : resolve3(
|
|
2212
|
+
dirname3(cleanId),
|
|
2213
|
+
typeof sourceRoot === "string" ? sourceRoot : "",
|
|
2214
|
+
sourcePath
|
|
2215
|
+
);
|
|
2216
|
+
let sameFile = cleanModuleId(file).replace(/\\/g, "/") === cleanId.replace(/\\/g, "/");
|
|
2217
|
+
if (!sameFile) {
|
|
2218
|
+
try {
|
|
2219
|
+
sameFile = realpathSync3.native(file) === realpathSync3.native(cleanId);
|
|
2220
|
+
} catch {
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
return sameFile && typeof map.sourcesContent?.[index] === "string" ? [map.sourcesContent[index]] : [];
|
|
2224
|
+
});
|
|
2225
|
+
if (matches.length === 1) loadedSource = matches[0];
|
|
2226
|
+
} catch {
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
const witnessed = loadedSource === rawSource && stable.every((key) => before[key] === after[key]);
|
|
2230
|
+
const modifiedtsMs = witnessed ? Math.trunc(before.mtimeMs) : 0;
|
|
2231
|
+
const sourceVersion = witnessed ? sourceVersionHash(rawSource) : "";
|
|
1955
2232
|
const identityKey = canonicalIdentityKey(cleanId);
|
|
1956
2233
|
if (!defaultExportIdentityByFile.has(identityKey)) {
|
|
1957
2234
|
defaultExportIdentityByFile.set(
|
|
@@ -1959,22 +2236,55 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1959
2236
|
readDefaultExportIdentity(rawSource)
|
|
1960
2237
|
);
|
|
1961
2238
|
}
|
|
1962
|
-
const
|
|
1963
|
-
|
|
2239
|
+
const resolvedComponents = /* @__PURE__ */ new Map();
|
|
2240
|
+
if (source.includes("tempo-sdk/canvas") && typeof this.resolve === "function") {
|
|
2241
|
+
const imports = parseCanvasFile(cleanId, source).storyboards.flatMap(
|
|
2242
|
+
(board) => board.component?.import?.source ?? []
|
|
2243
|
+
);
|
|
2244
|
+
await Promise.all(
|
|
2245
|
+
[...new Set(imports)].map(async (specifier) => {
|
|
2246
|
+
const resolved = await this.resolve(specifier, cleanId, {
|
|
2247
|
+
skipSelf: true
|
|
2248
|
+
});
|
|
2249
|
+
if (resolved) resolvedComponents.set(specifier, resolved.id);
|
|
2250
|
+
})
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
const componentReferences = canvasComponentAnnotations(
|
|
1964
2254
|
cleanId,
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
filepath,
|
|
1968
|
-
modifiedtsMs,
|
|
1969
|
-
sourceVersion,
|
|
1970
|
-
computeAnnotatedProps: options.computeAnnotatedProps
|
|
1971
|
-
})
|
|
2255
|
+
source,
|
|
2256
|
+
resolvedComponents
|
|
1972
2257
|
);
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2258
|
+
const result = annotateFile(source, cleanId, (info) => {
|
|
2259
|
+
const props = {
|
|
2260
|
+
...componentReferences.get(info.element.openingElement.start),
|
|
2261
|
+
...computeTempoAnnotatedProps({
|
|
2262
|
+
info,
|
|
2263
|
+
filepath,
|
|
2264
|
+
modifiedtsMs,
|
|
2265
|
+
sourceVersion,
|
|
2266
|
+
computeAnnotatedProps: options.computeAnnotatedProps
|
|
2267
|
+
})
|
|
2268
|
+
};
|
|
2269
|
+
if (!witnessed) {
|
|
2270
|
+
delete props["data-tempo-filepath"];
|
|
2271
|
+
delete props["data-tempo-position"];
|
|
2272
|
+
delete props["data-tempo-expr"];
|
|
2273
|
+
delete props["data-tempo-modifiedts"];
|
|
2274
|
+
delete props["data-tempo-source-version"];
|
|
2275
|
+
}
|
|
2276
|
+
return props;
|
|
2277
|
+
});
|
|
2278
|
+
if (result.parseResult.errors.length > 0) return null;
|
|
2279
|
+
const annotated = result.elementsAnnotated === 0 ? source : result.annotatedSource;
|
|
2280
|
+
const withControls = controlsFilter(cleanId) ? transformControls(annotated, cleanId) : annotated;
|
|
1976
2281
|
return {
|
|
1977
|
-
code:
|
|
2282
|
+
code: witnessed ? appendModuleVersionRecord(
|
|
2283
|
+
withControls,
|
|
2284
|
+
filepath,
|
|
2285
|
+
modifiedtsMs,
|
|
2286
|
+
sourceVersion
|
|
2287
|
+
) : withControls,
|
|
1978
2288
|
map: null
|
|
1979
2289
|
};
|
|
1980
2290
|
} catch {
|