tempo-sdk 0.0.14 → 0.0.16

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.
Files changed (56) hide show
  1. package/dist/annotation-strategy-DCJHc--2.d.cts +13 -0
  2. package/dist/annotation-strategy-DCJHc--2.d.ts +13 -0
  3. package/dist/canvas/editor.d.ts +129 -0
  4. package/dist/canvas/editor.js +1198 -0
  5. package/dist/canvas/editor.js.map +1 -0
  6. package/dist/canvas/index.d.ts +173 -0
  7. package/dist/canvas/index.js +2193 -0
  8. package/dist/canvas/index.js.map +1 -0
  9. package/dist/canvas/parser.d.ts +109 -0
  10. package/dist/canvas/parser.js +13 -0
  11. package/dist/canvas/parser.js.map +1 -0
  12. package/dist/chunk-2LP5G6CD.js +748 -0
  13. package/dist/chunk-2LP5G6CD.js.map +1 -0
  14. package/dist/chunk-77BNMPBS.js +319 -0
  15. package/dist/chunk-77BNMPBS.js.map +1 -0
  16. package/dist/chunk-B3PHU7XX.js +571 -0
  17. package/dist/chunk-B3PHU7XX.js.map +1 -0
  18. package/dist/chunk-EJBWZCEE.js +434 -0
  19. package/dist/chunk-EJBWZCEE.js.map +1 -0
  20. package/dist/chunk-F64WRL4H.js +884 -0
  21. package/dist/chunk-F64WRL4H.js.map +1 -0
  22. package/dist/chunk-GHPL4LGE.js +205 -0
  23. package/dist/chunk-GHPL4LGE.js.map +1 -0
  24. package/dist/chunk-ICP7LCPJ.js +615 -0
  25. package/dist/chunk-ICP7LCPJ.js.map +1 -0
  26. package/dist/chunk-IG3JZVZI.js +846 -0
  27. package/dist/chunk-IG3JZVZI.js.map +1 -0
  28. package/dist/chunk-MBTLXFNP.js +605 -0
  29. package/dist/chunk-MBTLXFNP.js.map +1 -0
  30. package/dist/chunk-MD3HJ7L3.js +457 -0
  31. package/dist/chunk-MD3HJ7L3.js.map +1 -0
  32. package/dist/chunk-O3HYJ6BU.js +433 -0
  33. package/dist/chunk-O3HYJ6BU.js.map +1 -0
  34. package/dist/chunk-X3K7Z2BH.js +900 -0
  35. package/dist/chunk-X3K7Z2BH.js.map +1 -0
  36. package/dist/chunk-ZHORRCQG.js +756 -0
  37. package/dist/chunk-ZHORRCQG.js.map +1 -0
  38. package/dist/expo/plugin.cjs +4 -22
  39. package/dist/expo/plugin.cjs.map +1 -1
  40. package/dist/expo/plugin.js +1 -1
  41. package/dist/expo-babel-plugin.cjs +4 -22
  42. package/dist/expo-babel-plugin.cjs.map +1 -1
  43. package/dist/expo-babel-plugin.d.cts +0 -6
  44. package/dist/expo-babel-plugin.d.ts +0 -6
  45. package/dist/expo-babel-plugin.js +1 -1
  46. package/dist/index.cjs +1170 -0
  47. package/dist/index.cjs.map +1 -0
  48. package/dist/index.d.cts +99 -0
  49. package/dist/index.d.ts +3 -28
  50. package/dist/index.js +0 -2
  51. package/dist/index.js.map +1 -1
  52. package/dist/nextjs-loader.cjs +0 -2
  53. package/dist/nextjs-loader.cjs.map +1 -1
  54. package/dist/page-BokkL6FZ.d.ts +35 -0
  55. package/dist/page-xi1aI5a7.d.ts +36 -0
  56. package/package.json +17 -3
package/dist/index.cjs ADDED
@@ -0,0 +1,1170 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ createTypeAnalyzer: () => createTypeAnalyzer,
34
+ tempoAnnotate: () => tempoAnnotate,
35
+ tempoVitePlugin: () => tempoVitePlugin
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // ../../modules/annotation/annotate-file.ts
40
+ var import_oxc_parser2 = require("oxc-parser");
41
+
42
+ // ../../modules/file-parser/utils.ts
43
+ function getTagName(name) {
44
+ switch (name.type) {
45
+ case "JSXIdentifier":
46
+ return name.name;
47
+ case "JSXNamespacedName":
48
+ return `${name.namespace.name}:${name.name.name}`;
49
+ case "JSXMemberExpression":
50
+ return getJSXMemberExpressionName(name);
51
+ }
52
+ }
53
+ function getJSXMemberExpressionName(node) {
54
+ const object = node.object.type === "JSXIdentifier" ? node.object.name : getJSXMemberExpressionName(node.object);
55
+ return `${object}.${node.property.name}`;
56
+ }
57
+
58
+ // ../../modules/file-parser/walk.ts
59
+ function walk(node, callbacks) {
60
+ if (node === null || node === void 0 || typeof node !== "object") return;
61
+ if (Array.isArray(node)) {
62
+ for (const child of node) {
63
+ walk(child, callbacks);
64
+ }
65
+ return;
66
+ }
67
+ const record = node;
68
+ const type = record.type;
69
+ if (typeof type === "string" && type in callbacks) {
70
+ callbacks[type](node);
71
+ }
72
+ for (const value of Object.values(record)) {
73
+ if (value !== null && typeof value === "object") {
74
+ walk(value, callbacks);
75
+ }
76
+ }
77
+ }
78
+
79
+ // ../../modules/file-parser/scope-analyzer/types.ts
80
+ var ScopeFlags = {
81
+ Top: 1 << 0,
82
+ Function: 1 << 1,
83
+ Block: 1 << 2,
84
+ Catch: 1 << 3,
85
+ Class: 1 << 4,
86
+ For: 1 << 5,
87
+ Switch: 1 << 6,
88
+ Module: 1 << 7,
89
+ StrictMode: 1 << 8,
90
+ ClassStaticBlock: 1 << 9,
91
+ TsModuleBlock: 1 << 10,
92
+ TsConditional: 1 << 11,
93
+ Type: 1 << 12,
94
+ Enum: 1 << 13
95
+ };
96
+
97
+ // ../../modules/file-parser/scope-analyzer/scopeAnalyzer.ts
98
+ var import_oxc_parser = require("oxc-parser");
99
+ var import_keys = __toESM(require("oxc-parser/src-js/generated/visit/keys.js"), 1);
100
+
101
+ // ../../modules/annotation/annotate-file.ts
102
+ function formatPropValue(value) {
103
+ if (value === void 0) return null;
104
+ if (typeof value === "function") return value.toString();
105
+ return JSON.stringify(value);
106
+ }
107
+ function formatProps(props) {
108
+ return Object.entries(props).map(([key, value]) => {
109
+ const formatted = formatPropValue(value);
110
+ if (formatted === null) return null;
111
+ return ` ${key}={${formatted}}`;
112
+ }).filter((s) => s !== null).join("");
113
+ }
114
+ var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
115
+ function annotateFile(source, filename, computeAnnotatedProps) {
116
+ const parseResult = (0, import_oxc_parser2.parseSync)(filename, source);
117
+ const insertions = [];
118
+ walk(parseResult.program, {
119
+ JSXElement(node) {
120
+ const element = node;
121
+ const tagName = getTagName(element.openingElement.name);
122
+ if (FRAGMENT_TAG_NAMES.has(tagName)) return;
123
+ const props = computeAnnotatedProps({ element, tagName });
124
+ if (Object.keys(props).length === 0) return;
125
+ const openingElement = element.openingElement;
126
+ let insertPos = openingElement.end - 1;
127
+ if (openingElement.selfClosing) {
128
+ insertPos--;
129
+ while (insertPos > openingElement.start && /\s/.test(source[insertPos - 1])) {
130
+ insertPos--;
131
+ }
132
+ }
133
+ insertions.push({ position: insertPos, text: formatProps(props) });
134
+ }
135
+ });
136
+ insertions.sort((a, b) => a.position - b.position);
137
+ const chunks = [];
138
+ let lastPos = 0;
139
+ for (const { position, text } of insertions) {
140
+ chunks.push(source.slice(lastPos, position));
141
+ chunks.push(text);
142
+ lastPos = position;
143
+ }
144
+ chunks.push(source.slice(lastPos));
145
+ return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
146
+ }
147
+
148
+ // index.ts
149
+ var import_pluginutils = require("@rollup/pluginutils");
150
+
151
+ // annotation-strategy.ts
152
+ var import_node_fs = require("fs");
153
+ var import_node_path = require("path");
154
+
155
+ // ../../modules/annotation/has-expression-children.ts
156
+ function hasJsxExpressionChild(element) {
157
+ for (const child of element.children) {
158
+ if (child.type !== "JSXExpressionContainer") continue;
159
+ const expression = child.expression;
160
+ if (!expression || expression.type === "JSXEmptyExpression") continue;
161
+ return true;
162
+ }
163
+ return false;
164
+ }
165
+
166
+ // ../../modules/tempo-dom-id/index.ts
167
+ var FNV_OFFSET_BASIS = 2166136261;
168
+ var FNV_PRIME = 16777619;
169
+ function fnv1a32(value) {
170
+ let hash = FNV_OFFSET_BASIS;
171
+ for (let index = 0; index < value.length; index += 1) {
172
+ hash ^= value.charCodeAt(index);
173
+ hash = Math.imul(hash, FNV_PRIME) >>> 0;
174
+ }
175
+ return hash.toString(36);
176
+ }
177
+ function mint_dom_id(filepath, source_position) {
178
+ return `t-${fnv1a32(
179
+ `${filepath}:${source_position.line}:${source_position.column}:${source_position.offset}`
180
+ )}`;
181
+ }
182
+
183
+ // annotation-strategy.ts
184
+ var DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx"];
185
+ var DEFAULT_EXCLUDE = ["**/node_modules/**"];
186
+ var ROOT_META_NAME = "tempo-project-root";
187
+ var IMPORT_RESOLUTION_EXTENSIONS = [
188
+ "",
189
+ ".tsx",
190
+ ".ts",
191
+ ".jsx",
192
+ ".js",
193
+ ".mjs",
194
+ ".cjs",
195
+ ".json"
196
+ ];
197
+ var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
198
+ "area",
199
+ "base",
200
+ "br",
201
+ "col",
202
+ "embed",
203
+ "hr",
204
+ "img",
205
+ "input",
206
+ "link",
207
+ "meta",
208
+ "param",
209
+ "source",
210
+ "track",
211
+ "wbr"
212
+ ]);
213
+ function cleanModuleId(id) {
214
+ return id.replace(/[?#].*$/, "");
215
+ }
216
+ function resolveCanonicalRoot(root) {
217
+ try {
218
+ return import_node_fs.realpathSync.native(root);
219
+ } catch {
220
+ return root;
221
+ }
222
+ }
223
+ function hasRootMetaTag(html) {
224
+ return /<meta[^>]+name=["']tempo-project-root["'][^>]*>/i.test(html);
225
+ }
226
+ function isIntrinsicElement(tagName) {
227
+ return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
228
+ }
229
+ function hasJsxAttribute(info, attrName) {
230
+ for (const attr of info.element.openingElement.attributes) {
231
+ const name = attr.name;
232
+ if (name?.name === attrName) return true;
233
+ }
234
+ return false;
235
+ }
236
+ function pathExistsWithCommonExtensions(basePath) {
237
+ for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
238
+ const candidate = `${basePath}${ext}`;
239
+ if ((0, import_node_fs.existsSync)(candidate)) return true;
240
+ }
241
+ for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
242
+ const candidate = (0, import_node_path.resolve)(basePath, `index${ext}`);
243
+ if ((0, import_node_fs.existsSync)(candidate)) return true;
244
+ }
245
+ return false;
246
+ }
247
+ function findMissingRelativeImport(source, importerPath) {
248
+ const importPattern = /(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?["'](\.{1,2}\/[^"']+)["']/g;
249
+ let match;
250
+ while (match = importPattern.exec(source)) {
251
+ const specifier = match[1];
252
+ if (!specifier) continue;
253
+ const resolved = (0, import_node_path.resolve)((0, import_node_path.dirname)(importerPath), specifier);
254
+ if (!pathExistsWithCommonExtensions(resolved)) {
255
+ return specifier;
256
+ }
257
+ }
258
+ return null;
259
+ }
260
+ function getSourcePositionForOffset(source, offset) {
261
+ let line = 1;
262
+ let lineStart = 0;
263
+ for (let index = 0; index < offset; index += 1) {
264
+ if (source.charCodeAt(index) === 10) {
265
+ line += 1;
266
+ lineStart = index + 1;
267
+ }
268
+ }
269
+ return { line, column: offset - lineStart, offset };
270
+ }
271
+ function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, source) {
272
+ const offset = info.element.openingElement.start;
273
+ return {
274
+ "data-tempo-filepath": filepath,
275
+ "data-tempo-position": offset,
276
+ "data-tempo-modifiedts": modifiedtsMs,
277
+ "data-dom-id": mint_dom_id(
278
+ filepath,
279
+ getSourcePositionForOffset(source, offset)
280
+ )
281
+ };
282
+ }
283
+ function computeTempoAnnotatedProps(params) {
284
+ const {
285
+ info,
286
+ filepath,
287
+ modifiedtsMs,
288
+ source,
289
+ computeAnnotatedProps,
290
+ typeInfo,
291
+ elementSupportOverrides
292
+ } = params;
293
+ const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, source);
294
+ const dynamicChildrenProp = hasJsxExpressionChild(info.element) ? { "data-tempo-dynamic-children": true } : {};
295
+ if (isIntrinsicElement(info.tagName)) {
296
+ return {
297
+ ...userProps,
298
+ ...dynamicChildrenProp,
299
+ "data-tempo-supports-children": hasJsxAttribute(
300
+ info,
301
+ "data-tempo-supports-children"
302
+ ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
303
+ };
304
+ }
305
+ const override = elementSupportOverrides?.get(info.tagName);
306
+ if (override) {
307
+ return {
308
+ ...userProps,
309
+ ...dynamicChildrenProp,
310
+ "data-tempo-supports-style": override.supportsStyle,
311
+ "data-tempo-supports-classname": override.supportsClassName,
312
+ "data-tempo-supports-children": hasJsxAttribute(
313
+ info,
314
+ "data-tempo-supports-children"
315
+ ) ? void 0 : override.supportsChildren
316
+ };
317
+ }
318
+ const support = typeInfo?.get(info.element.openingElement.start);
319
+ return {
320
+ ...userProps,
321
+ ...dynamicChildrenProp,
322
+ "data-tempo-supports-style": support?.supportsStyle ?? false,
323
+ "data-tempo-supports-classname": support?.supportsClassName ?? false,
324
+ "data-tempo-supports-children": hasJsxAttribute(
325
+ info,
326
+ "data-tempo-supports-children"
327
+ ) ? void 0 : support?.supportsChildren ?? false
328
+ };
329
+ }
330
+ function getFileAnnotationContext(params) {
331
+ const rawCleanFilename = cleanModuleId(params.filename);
332
+ let cleanFilename = rawCleanFilename;
333
+ if (params.canonicalizeFilename) {
334
+ try {
335
+ cleanFilename = import_node_fs.realpathSync.native(rawCleanFilename);
336
+ } catch {
337
+ cleanFilename = rawCleanFilename;
338
+ }
339
+ }
340
+ return {
341
+ cleanFilename,
342
+ filepath: (0, import_node_path.relative)(params.root, cleanFilename),
343
+ modifiedtsMs: Math.trunc((0, import_node_fs.statSync)(cleanFilename).mtimeMs)
344
+ };
345
+ }
346
+
347
+ // type-analyzer.ts
348
+ var import_typescript2 = __toESM(require("typescript"), 1);
349
+ var import_node_path3 = __toESM(require("path"), 1);
350
+ var import_node_fs3 = require("fs");
351
+
352
+ // ../../modules/typescript/workspace-service.ts
353
+ var import_node_fs2 = require("fs");
354
+ var import_node_path2 = __toESM(require("path"), 1);
355
+ var import_typescript = __toESM(require("typescript"), 1);
356
+ function canonicalPath(input) {
357
+ const resolved = import_node_path2.default.resolve(input);
358
+ try {
359
+ return import_node_fs2.realpathSync.native(resolved);
360
+ } catch {
361
+ return resolved;
362
+ }
363
+ }
364
+ function compareProjectPriority(left, right) {
365
+ const depthDelta = right.rootDir.length - left.rootDir.length;
366
+ if (depthDelta !== 0) {
367
+ return depthDelta;
368
+ }
369
+ const priorityDelta = right.priority - left.priority;
370
+ if (priorityDelta !== 0) {
371
+ return priorityDelta;
372
+ }
373
+ return left.id.localeCompare(right.id);
374
+ }
375
+ function isWithinRoot(filePath, rootDir) {
376
+ return filePath === rootDir || filePath.startsWith(`${rootDir}${import_node_path2.default.sep}`);
377
+ }
378
+ function loadProject(descriptor) {
379
+ const id = descriptor.id.trim();
380
+ if (!id) {
381
+ throw new Error("Project id must be a non-empty string");
382
+ }
383
+ const tsconfigPath = canonicalPath(descriptor.tsconfigPath);
384
+ const rootDir = canonicalPath(descriptor.rootDir);
385
+ const readResult = import_typescript.default.readConfigFile(tsconfigPath, import_typescript.default.sys.readFile);
386
+ if (readResult.error) {
387
+ throw new Error(
388
+ `Failed to read tsconfig at ${tsconfigPath}: ${import_typescript.default.flattenDiagnosticMessageText(
389
+ readResult.error.messageText,
390
+ "\n"
391
+ )}`
392
+ );
393
+ }
394
+ const parsed = import_typescript.default.parseJsonConfigFileContent(
395
+ readResult.config,
396
+ import_typescript.default.sys,
397
+ import_node_path2.default.dirname(tsconfigPath)
398
+ );
399
+ if (parsed.errors.length > 0) {
400
+ const message = parsed.errors.map(
401
+ (diagnostic) => import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
402
+ ).join("; ");
403
+ throw new Error(`Failed to parse tsconfig at ${tsconfigPath}: ${message}`);
404
+ }
405
+ const normalizedFiles = parsed.fileNames.map(
406
+ (fileName) => canonicalPath(fileName)
407
+ );
408
+ return {
409
+ id,
410
+ rootDir,
411
+ tsconfigPath,
412
+ priority: descriptor.priority ?? 0,
413
+ options: parsed.options,
414
+ fileNames: normalizedFiles,
415
+ moduleResolutionCache: import_typescript.default.createModuleResolutionCache(
416
+ rootDir,
417
+ (value) => value,
418
+ parsed.options
419
+ )
420
+ };
421
+ }
422
+ function getFileMtimeVersion(filePath) {
423
+ try {
424
+ const stats = (0, import_node_fs2.statSync)(filePath);
425
+ return String(stats.mtimeMs);
426
+ } catch {
427
+ return "0";
428
+ }
429
+ }
430
+ function createTsWorkspaceService(descriptor) {
431
+ if (descriptor.projects.length === 0) {
432
+ throw new Error(
433
+ "TsWorkspaceDescriptor.projects must include at least one project"
434
+ );
435
+ }
436
+ const workspaceRoot = canonicalPath(descriptor.workspaceRoot);
437
+ const loadedProjects = descriptor.projects.map(
438
+ (project) => loadProject(project)
439
+ );
440
+ const projectsById = /* @__PURE__ */ new Map();
441
+ for (const project of loadedProjects) {
442
+ if (projectsById.has(project.id)) {
443
+ throw new Error(`Duplicate project id: ${project.id}`);
444
+ }
445
+ projectsById.set(project.id, project);
446
+ }
447
+ const primaryProject = (descriptor.primaryProjectId ? projectsById.get(descriptor.primaryProjectId) : null) ?? loadedProjects[0];
448
+ if (descriptor.primaryProjectId && !projectsById.has(descriptor.primaryProjectId)) {
449
+ throw new Error(
450
+ `Primary project id not found: ${descriptor.primaryProjectId}`
451
+ );
452
+ }
453
+ const orderedProjects = [...loadedProjects].sort(compareProjectPriority);
454
+ const rootFileNames = /* @__PURE__ */ new Set();
455
+ for (const project of loadedProjects) {
456
+ for (const fileName of project.fileNames) {
457
+ rootFileNames.add(fileName);
458
+ }
459
+ }
460
+ const inMemoryFiles = /* @__PURE__ */ new Map();
461
+ let projectVersion = 0;
462
+ function getOwningProject(filePath) {
463
+ const canonicalFilePath = canonicalPath(filePath);
464
+ for (const project of orderedProjects) {
465
+ if (isWithinRoot(canonicalFilePath, project.rootDir)) {
466
+ return project;
467
+ }
468
+ }
469
+ return primaryProject;
470
+ }
471
+ const moduleResolutionHost = {
472
+ fileExists: import_typescript.default.sys.fileExists,
473
+ readFile: import_typescript.default.sys.readFile,
474
+ realpath: import_typescript.default.sys.realpath,
475
+ directoryExists: import_typescript.default.sys.directoryExists,
476
+ getCurrentDirectory: () => workspaceRoot,
477
+ getDirectories: import_typescript.default.sys.getDirectories
478
+ };
479
+ const host = {
480
+ getScriptFileNames: () => Array.from(rootFileNames),
481
+ getScriptVersion: (filePath) => {
482
+ const canonicalFilePath = canonicalPath(filePath);
483
+ const inMemory = inMemoryFiles.get(canonicalFilePath);
484
+ if (inMemory) {
485
+ return String(inMemory.version);
486
+ }
487
+ return getFileMtimeVersion(canonicalFilePath);
488
+ },
489
+ getScriptSnapshot: (filePath) => {
490
+ const canonicalFilePath = canonicalPath(filePath);
491
+ const inMemory = inMemoryFiles.get(canonicalFilePath);
492
+ if (inMemory) {
493
+ return import_typescript.default.ScriptSnapshot.fromString(inMemory.content);
494
+ }
495
+ const diskContent = import_typescript.default.sys.readFile(canonicalFilePath);
496
+ if (diskContent === void 0) {
497
+ return void 0;
498
+ }
499
+ return import_typescript.default.ScriptSnapshot.fromString(diskContent);
500
+ },
501
+ getCurrentDirectory: () => workspaceRoot,
502
+ getCompilationSettings: () => primaryProject.options,
503
+ getDefaultLibFileName: (options) => import_typescript.default.getDefaultLibFilePath(options),
504
+ fileExists: import_typescript.default.sys.fileExists,
505
+ readFile: import_typescript.default.sys.readFile,
506
+ readDirectory: import_typescript.default.sys.readDirectory,
507
+ directoryExists: import_typescript.default.sys.directoryExists,
508
+ getDirectories: import_typescript.default.sys.getDirectories,
509
+ useCaseSensitiveFileNames: () => import_typescript.default.sys.useCaseSensitiveFileNames,
510
+ getProjectVersion: () => String(projectVersion),
511
+ resolveModuleNames: (moduleNames, containingFile) => {
512
+ const owningProject = getOwningProject(containingFile);
513
+ return moduleNames.map((moduleName) => {
514
+ const ownerResolution = import_typescript.default.resolveModuleName(
515
+ moduleName,
516
+ containingFile,
517
+ owningProject.options,
518
+ moduleResolutionHost,
519
+ owningProject.moduleResolutionCache
520
+ ).resolvedModule;
521
+ if (ownerResolution) {
522
+ return ownerResolution;
523
+ }
524
+ if (owningProject.id === primaryProject.id) {
525
+ return void 0;
526
+ }
527
+ return import_typescript.default.resolveModuleName(
528
+ moduleName,
529
+ containingFile,
530
+ primaryProject.options,
531
+ moduleResolutionHost,
532
+ primaryProject.moduleResolutionCache
533
+ ).resolvedModule;
534
+ });
535
+ }
536
+ };
537
+ const languageService = import_typescript.default.createLanguageService(
538
+ host,
539
+ import_typescript.default.createDocumentRegistry()
540
+ );
541
+ return {
542
+ updateFile(filePath, content) {
543
+ const canonicalFilePath = canonicalPath(filePath);
544
+ const currentVersion = inMemoryFiles.get(canonicalFilePath)?.version ?? 0;
545
+ inMemoryFiles.set(canonicalFilePath, {
546
+ version: currentVersion + 1,
547
+ content
548
+ });
549
+ if (!rootFileNames.has(canonicalFilePath)) {
550
+ rootFileNames.add(canonicalFilePath);
551
+ }
552
+ projectVersion += 1;
553
+ },
554
+ closeFile(filePath) {
555
+ const canonicalFilePath = canonicalPath(filePath);
556
+ inMemoryFiles.delete(canonicalFilePath);
557
+ projectVersion += 1;
558
+ },
559
+ getProgram() {
560
+ return languageService.getProgram() ?? null;
561
+ },
562
+ getSemanticDiagnostics(filePath) {
563
+ const canonicalFilePath = canonicalPath(filePath);
564
+ return languageService.getSemanticDiagnostics(canonicalFilePath);
565
+ },
566
+ getDefinition(filePath, position) {
567
+ const canonicalFilePath = canonicalPath(filePath);
568
+ return languageService.getDefinitionAtPosition(
569
+ canonicalFilePath,
570
+ position
571
+ );
572
+ },
573
+ dispose() {
574
+ languageService.dispose();
575
+ }
576
+ };
577
+ }
578
+
579
+ // type-analyzer.ts
580
+ function isCustomComponent(node) {
581
+ const text = node.getText();
582
+ return text.length > 0 && text[0] !== text[0].toLowerCase();
583
+ }
584
+ function canonicalPath2(value) {
585
+ const resolved = import_node_path3.default.resolve(value);
586
+ try {
587
+ return import_node_fs3.realpathSync.native(resolved);
588
+ } catch {
589
+ return resolved;
590
+ }
591
+ }
592
+ function parseManagedTsconfigPaths(rawConfig) {
593
+ if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
594
+ return [];
595
+ }
596
+ const metadata = rawConfig.tempobook;
597
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
598
+ return [];
599
+ }
600
+ const managedPaths = metadata.managedTsconfigPaths;
601
+ if (!Array.isArray(managedPaths)) {
602
+ return [];
603
+ }
604
+ return managedPaths.filter(
605
+ (entry) => typeof entry === "string" && entry.trim().length > 0
606
+ );
607
+ }
608
+ function parseProjectReferenceTsconfigPaths(references, configDir) {
609
+ if (!references || references.length === 0) {
610
+ return [];
611
+ }
612
+ const entries = [];
613
+ for (const reference of references) {
614
+ const referencePath = reference.path;
615
+ if (!referencePath) {
616
+ continue;
617
+ }
618
+ const resolvedPath = import_node_path3.default.resolve(configDir, referencePath);
619
+ const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : import_node_path3.default.join(resolvedPath, "tsconfig.json");
620
+ entries.push(tsconfigPath);
621
+ }
622
+ return entries;
623
+ }
624
+ function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
625
+ const configDir = import_node_path3.default.dirname(configPath);
626
+ const projects = [
627
+ {
628
+ id: "root",
629
+ rootDir: root,
630
+ tsconfigPath: configPath,
631
+ priority: 0
632
+ }
633
+ ];
634
+ const seenTsconfigPaths = /* @__PURE__ */ new Set([canonicalPath2(configPath)]);
635
+ const referencedTsconfigPaths = parseProjectReferenceTsconfigPaths(
636
+ parsedConfig.projectReferences,
637
+ configDir
638
+ );
639
+ const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
640
+ (entry) => import_node_path3.default.resolve(configDir, entry)
641
+ );
642
+ const candidateTsconfigPaths = [
643
+ ...managedTsconfigPaths,
644
+ ...referencedTsconfigPaths
645
+ ];
646
+ for (const candidatePath of candidateTsconfigPaths) {
647
+ const normalizedPath = canonicalPath2(candidatePath);
648
+ if (seenTsconfigPaths.has(normalizedPath)) {
649
+ continue;
650
+ }
651
+ if (!import_typescript2.default.sys.fileExists(normalizedPath)) {
652
+ continue;
653
+ }
654
+ seenTsconfigPaths.add(normalizedPath);
655
+ projects.push({
656
+ id: `external-${projects.length}`,
657
+ rootDir: import_node_path3.default.dirname(normalizedPath),
658
+ tsconfigPath: normalizedPath,
659
+ priority: 0
660
+ });
661
+ }
662
+ return projects;
663
+ }
664
+ function createTypeAnalyzer(root) {
665
+ const configPath = import_typescript2.default.findConfigFile(
666
+ root,
667
+ import_typescript2.default.sys.fileExists,
668
+ "tsconfig.json"
669
+ );
670
+ if (!configPath) return null;
671
+ const configFile = import_typescript2.default.readConfigFile(configPath, import_typescript2.default.sys.readFile);
672
+ if (configFile.error) return null;
673
+ const parsedConfig = import_typescript2.default.parseJsonConfigFileContent(
674
+ configFile.config,
675
+ import_typescript2.default.sys,
676
+ root
677
+ );
678
+ const workspaceProjects = buildWorkspaceProjects(
679
+ root,
680
+ configPath,
681
+ parsedConfig,
682
+ configFile.config
683
+ );
684
+ const workspaceProjectRoots = workspaceProjects.map(
685
+ (project) => canonicalPath2(project.rootDir)
686
+ );
687
+ const workspaceService = createTsWorkspaceService({
688
+ workspaceRoot: root,
689
+ primaryProjectId: "root",
690
+ projects: workspaceProjects
691
+ });
692
+ let cssPropertiesType;
693
+ function resolveCSSPropertiesType(checker, sourceFile) {
694
+ if (cssPropertiesType !== void 0) return cssPropertiesType;
695
+ try {
696
+ let jsxNs = checker.resolveName(
697
+ "JSX",
698
+ sourceFile,
699
+ import_typescript2.default.SymbolFlags.Namespace,
700
+ false
701
+ );
702
+ if (!jsxNs) {
703
+ const program = workspaceService.getProgram();
704
+ const compilerOptions = program?.getCompilerOptions();
705
+ const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
706
+ const resolved = import_typescript2.default.resolveModuleName(
707
+ `${jsxImportSource}/jsx-runtime`,
708
+ sourceFile.fileName,
709
+ compilerOptions,
710
+ import_typescript2.default.sys
711
+ );
712
+ if (resolved.resolvedModule) {
713
+ const runtimeFile = program?.getSourceFile(
714
+ resolved.resolvedModule.resolvedFileName
715
+ );
716
+ if (runtimeFile) {
717
+ const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
718
+ if (runtimeSymbol) {
719
+ const exports2 = checker.getExportsOfModule(runtimeSymbol);
720
+ jsxNs = exports2.find((s) => s.name === "JSX");
721
+ }
722
+ }
723
+ }
724
+ }
725
+ if (!jsxNs) {
726
+ cssPropertiesType = null;
727
+ return null;
728
+ }
729
+ const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
730
+ if (!intrinsicSym) {
731
+ cssPropertiesType = null;
732
+ return null;
733
+ }
734
+ const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
735
+ if (!divSym) {
736
+ cssPropertiesType = null;
737
+ return null;
738
+ }
739
+ const styleSym = checker.getTypeOfSymbol(divSym).getProperty("style");
740
+ if (!styleSym) {
741
+ cssPropertiesType = null;
742
+ return null;
743
+ }
744
+ const styleType = checker.getTypeOfSymbol(styleSym);
745
+ if (styleType.isUnion()) {
746
+ const nonUndefined = styleType.types.find(
747
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
748
+ );
749
+ cssPropertiesType = nonUndefined ?? null;
750
+ } else {
751
+ cssPropertiesType = styleType;
752
+ }
753
+ } catch {
754
+ cssPropertiesType = null;
755
+ }
756
+ return cssPropertiesType;
757
+ }
758
+ let reactNodeType;
759
+ function resolveReactNodeType(checker, sourceFile) {
760
+ if (reactNodeType !== void 0) return reactNodeType;
761
+ try {
762
+ let jsxNs = checker.resolveName(
763
+ "JSX",
764
+ sourceFile,
765
+ import_typescript2.default.SymbolFlags.Namespace,
766
+ false
767
+ );
768
+ if (!jsxNs) {
769
+ const program = workspaceService.getProgram();
770
+ const compilerOptions = program?.getCompilerOptions();
771
+ const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
772
+ const resolved = import_typescript2.default.resolveModuleName(
773
+ `${jsxImportSource}/jsx-runtime`,
774
+ sourceFile.fileName,
775
+ compilerOptions,
776
+ import_typescript2.default.sys
777
+ );
778
+ if (resolved.resolvedModule) {
779
+ const runtimeFile = program?.getSourceFile(
780
+ resolved.resolvedModule.resolvedFileName
781
+ );
782
+ if (runtimeFile) {
783
+ const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
784
+ if (runtimeSymbol) {
785
+ const exports2 = checker.getExportsOfModule(runtimeSymbol);
786
+ jsxNs = exports2.find((s) => s.name === "JSX");
787
+ }
788
+ }
789
+ }
790
+ }
791
+ if (!jsxNs) {
792
+ reactNodeType = null;
793
+ return null;
794
+ }
795
+ const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
796
+ if (!intrinsicSym) {
797
+ reactNodeType = null;
798
+ return null;
799
+ }
800
+ const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
801
+ if (!divSym) {
802
+ reactNodeType = null;
803
+ return null;
804
+ }
805
+ const childrenSym = checker.getTypeOfSymbol(divSym).getProperty("children");
806
+ if (!childrenSym) {
807
+ reactNodeType = null;
808
+ return null;
809
+ }
810
+ const childrenType = checker.getTypeOfSymbol(childrenSym);
811
+ if (childrenType.isUnion()) {
812
+ const nonUndefined = childrenType.types.find(
813
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
814
+ );
815
+ reactNodeType = nonUndefined ?? null;
816
+ } else {
817
+ reactNodeType = childrenType;
818
+ }
819
+ } catch {
820
+ reactNodeType = null;
821
+ }
822
+ return reactNodeType;
823
+ }
824
+ return {
825
+ analyzeFileTypes(filePath, source) {
826
+ const canonicalFilePath = canonicalPath2(filePath);
827
+ const belongsToWorkspace = workspaceProjectRoots.some(
828
+ (projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${import_node_path3.default.sep}`)
829
+ );
830
+ if (!belongsToWorkspace) {
831
+ return null;
832
+ }
833
+ workspaceService.updateFile(filePath, source);
834
+ const program = workspaceService.getProgram();
835
+ if (!program) return null;
836
+ const sourceFile = program.getSourceFile(filePath);
837
+ if (!sourceFile) return null;
838
+ const checker = program.getTypeChecker();
839
+ const cssProps = resolveCSSPropertiesType(checker, sourceFile);
840
+ const result = /* @__PURE__ */ new Map();
841
+ function visit(node) {
842
+ if ((import_typescript2.default.isJsxOpeningElement(node) || import_typescript2.default.isJsxSelfClosingElement(node)) && isCustomComponent(node.tagName)) {
843
+ const position = node.getStart(sourceFile);
844
+ const attrsType = checker.getContextualType(node.attributes);
845
+ let supportsStyle = false;
846
+ let supportsClassName = false;
847
+ let supportsChildren = false;
848
+ if (attrsType) {
849
+ const classNameProp = attrsType.getProperty("className");
850
+ if (classNameProp) {
851
+ const propType = checker.getTypeOfSymbol(classNameProp);
852
+ supportsClassName = checker.isTypeAssignableTo(
853
+ checker.getStringType(),
854
+ propType
855
+ );
856
+ }
857
+ const styleProp = attrsType.getProperty("style");
858
+ if (styleProp && cssProps) {
859
+ let propType = checker.getTypeOfSymbol(styleProp);
860
+ if (propType.isUnion()) {
861
+ const nonUndefined = propType.types.find(
862
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
863
+ );
864
+ if (nonUndefined) propType = nonUndefined;
865
+ }
866
+ supportsStyle = checker.isTypeAssignableTo(cssProps, propType);
867
+ }
868
+ const reactNode = resolveReactNodeType(checker, sourceFile);
869
+ const childrenProp = attrsType.getProperty("children");
870
+ if (childrenProp && reactNode) {
871
+ let propType = checker.getTypeOfSymbol(childrenProp);
872
+ if (propType.isUnion()) {
873
+ const nonUndefined = propType.types.find(
874
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
875
+ );
876
+ if (nonUndefined) propType = nonUndefined;
877
+ }
878
+ supportsChildren = checker.isTypeAssignableTo(
879
+ reactNode,
880
+ propType
881
+ );
882
+ }
883
+ }
884
+ result.set(position, { supportsStyle, supportsClassName, supportsChildren });
885
+ }
886
+ import_typescript2.default.forEachChild(node, visit);
887
+ }
888
+ visit(sourceFile);
889
+ return result;
890
+ }
891
+ };
892
+ }
893
+
894
+ // index.ts
895
+ function createErrorServer() {
896
+ const errorsByFile = /* @__PURE__ */ new Map();
897
+ function getMostRecentError() {
898
+ if (errorsByFile.size === 0) return null;
899
+ let latest = null;
900
+ for (const err of errorsByFile.values()) latest = err;
901
+ return latest;
902
+ }
903
+ function broadcastCurrentState() {
904
+ const data = JSON.stringify(server.currentError);
905
+ for (const client of server.clients) {
906
+ client.write(`data: ${data}
907
+
908
+ `);
909
+ }
910
+ }
911
+ const server = {
912
+ get currentError() {
913
+ return getMostRecentError();
914
+ },
915
+ clients: /* @__PURE__ */ new Set(),
916
+ setError(error) {
917
+ const key = error.file ?? error.loc?.file ?? "unknown";
918
+ errorsByFile.delete(key);
919
+ errorsByFile.set(key, error);
920
+ broadcastCurrentState();
921
+ },
922
+ clearErrorForModules(updatedPaths) {
923
+ if (errorsByFile.size === 0) return;
924
+ let changed = false;
925
+ for (const errorKey of [...errorsByFile.keys()]) {
926
+ if (errorKey === "unknown" || updatedPaths.some(
927
+ (p) => errorKey.endsWith(p) || p.endsWith(errorKey)
928
+ )) {
929
+ errorsByFile.delete(errorKey);
930
+ changed = true;
931
+ }
932
+ }
933
+ if (changed) broadcastCurrentState();
934
+ },
935
+ clearAll() {
936
+ errorsByFile.clear();
937
+ broadcastCurrentState();
938
+ }
939
+ };
940
+ return server;
941
+ }
942
+ function readBody(req) {
943
+ return new Promise((resolve2, reject) => {
944
+ const chunks = [];
945
+ req.on("data", (chunk) => chunks.push(chunk));
946
+ req.on("end", () => resolve2(Buffer.concat(chunks).toString()));
947
+ req.on("error", reject);
948
+ });
949
+ }
950
+ function handleErrorMiddleware(errorServer, req, res, next) {
951
+ const url = req.url;
952
+ if (!url?.startsWith("/__tempo/")) return next();
953
+ if (url === "/__tempo/report-error" && req.method === "POST") {
954
+ readBody(req).then((body) => {
955
+ try {
956
+ errorServer.setError(JSON.parse(body));
957
+ } catch {
958
+ }
959
+ res.statusCode = 200;
960
+ res.end("ok");
961
+ });
962
+ return;
963
+ }
964
+ if (url === "/__tempo/report-clear" && req.method === "POST") {
965
+ errorServer.clearAll();
966
+ res.statusCode = 200;
967
+ res.end("ok");
968
+ return;
969
+ }
970
+ if (url === "/__tempo/errors" && req.method === "OPTIONS") {
971
+ res.writeHead(204, {
972
+ "Access-Control-Allow-Origin": "*",
973
+ "Access-Control-Allow-Methods": "GET, OPTIONS",
974
+ "Access-Control-Allow-Headers": "*"
975
+ });
976
+ res.end();
977
+ return;
978
+ }
979
+ if (url === "/__tempo/errors" && req.method === "GET") {
980
+ res.writeHead(200, {
981
+ "Content-Type": "text/event-stream",
982
+ "Cache-Control": "no-cache",
983
+ Connection: "keep-alive",
984
+ "Access-Control-Allow-Origin": "*"
985
+ });
986
+ res.write(`data: ${JSON.stringify(errorServer.currentError)}
987
+
988
+ `);
989
+ errorServer.clients.add(res);
990
+ req.on("close", () => {
991
+ errorServer.clients.delete(res);
992
+ });
993
+ return;
994
+ }
995
+ next();
996
+ }
997
+ function parseViteInternalServerError(message) {
998
+ if (!message.includes("Internal server error:")) return null;
999
+ const lines = message.split(/\r?\n/);
1000
+ const firstLine = lines.find(
1001
+ (line) => line.includes("Internal server error:")
1002
+ );
1003
+ if (!firstLine) return null;
1004
+ const fileLine = lines.find((line) => line.trim().startsWith("File:"));
1005
+ const pluginLine = lines.find((line) => line.trim().startsWith("Plugin:"));
1006
+ const locMatch = fileLine?.match(/File:\s*(.+?)(?::(\d+):(\d+))?\s*$/);
1007
+ return {
1008
+ type: "compile",
1009
+ message: firstLine.replace(/^.*Internal server error:\s*/, "").trim(),
1010
+ stack: message,
1011
+ file: locMatch?.[1]?.trim(),
1012
+ plugin: pluginLine?.replace(/^.*Plugin:\s*/, "").trim(),
1013
+ loc: locMatch?.[2] && locMatch?.[3] ? {
1014
+ file: locMatch[1]?.trim(),
1015
+ line: Number(locMatch[2]),
1016
+ column: Number(locMatch[3])
1017
+ } : void 0
1018
+ };
1019
+ }
1020
+ function tempoVitePlugin(options = {}) {
1021
+ const enabled = !!process.env.TEMPO;
1022
+ const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
1023
+ const exclude = options.exclude === void 0 ? DEFAULT_EXCLUDE : options.exclude;
1024
+ const filter = (0, import_pluginutils.createFilter)(include, exclude);
1025
+ const computeAnnotatedProps = options.computeAnnotatedProps;
1026
+ let canonicalRoot = process.cwd();
1027
+ let command = "serve";
1028
+ let typeAnalyzer = null;
1029
+ const errorServer = createErrorServer();
1030
+ return {
1031
+ name: "tempo-annotate",
1032
+ enforce: "pre",
1033
+ // Expose error server for testing
1034
+ _tempoErrorServer: errorServer,
1035
+ configResolved(resolvedConfig) {
1036
+ if (!enabled) return;
1037
+ command = resolvedConfig.command;
1038
+ canonicalRoot = resolveCanonicalRoot(resolvedConfig.root);
1039
+ if (command === "serve") {
1040
+ typeAnalyzer = createTypeAnalyzer(canonicalRoot);
1041
+ }
1042
+ },
1043
+ configureServer(server) {
1044
+ if (!enabled) return;
1045
+ server.middlewares.use((req, res, next) => {
1046
+ handleErrorMiddleware(errorServer, req, res, next);
1047
+ });
1048
+ const interceptHmrSend = (target) => {
1049
+ const orig = target.send.bind(target);
1050
+ target.send = ((...args) => {
1051
+ const payload = args[0];
1052
+ if (typeof payload === "object" && payload !== null && "type" in payload) {
1053
+ const typed = payload;
1054
+ if (typed.type === "error") {
1055
+ const err = typed.err;
1056
+ errorServer.setError({
1057
+ type: "compile",
1058
+ message: err?.message ?? "Unknown error",
1059
+ stack: err?.stack,
1060
+ file: err?.id ?? err?.loc?.file,
1061
+ frame: err?.frame,
1062
+ plugin: err?.plugin,
1063
+ loc: err?.loc
1064
+ });
1065
+ } else if (typed.type === "update") {
1066
+ const updates = typed.updates;
1067
+ const paths = updates?.map((u) => u.path).filter((p) => typeof p === "string") ?? [];
1068
+ errorServer.clearErrorForModules(paths);
1069
+ }
1070
+ }
1071
+ return orig(...args);
1072
+ });
1073
+ };
1074
+ interceptHmrSend(server.ws);
1075
+ const clientHot = server.environments?.client?.hot;
1076
+ if (clientHot && clientHot !== server.ws) {
1077
+ interceptHmrSend(clientHot);
1078
+ }
1079
+ if (server.config?.logger?.error) {
1080
+ const originalLoggerError = server.config.logger.error.bind(
1081
+ server.config.logger
1082
+ );
1083
+ server.config.logger.error = ((message, options2) => {
1084
+ const error = parseViteInternalServerError(String(message));
1085
+ if (error) {
1086
+ errorServer.setError(error);
1087
+ }
1088
+ return originalLoggerError(message, options2);
1089
+ });
1090
+ }
1091
+ },
1092
+ transformIndexHtml(html) {
1093
+ if (!enabled || command !== "serve") {
1094
+ return;
1095
+ }
1096
+ if (hasRootMetaTag(html)) {
1097
+ return;
1098
+ }
1099
+ return [
1100
+ {
1101
+ tag: "meta",
1102
+ attrs: {
1103
+ name: ROOT_META_NAME,
1104
+ content: canonicalRoot
1105
+ },
1106
+ injectTo: "head"
1107
+ }
1108
+ ];
1109
+ },
1110
+ transform(source, id) {
1111
+ if (!enabled || command === "build") {
1112
+ return null;
1113
+ }
1114
+ if (id.startsWith("\0")) {
1115
+ return null;
1116
+ }
1117
+ const cleanId = cleanModuleId(id);
1118
+ if (!filter(cleanId)) {
1119
+ return null;
1120
+ }
1121
+ try {
1122
+ const { filepath, modifiedtsMs } = getFileAnnotationContext({
1123
+ source,
1124
+ filename: cleanId,
1125
+ root: canonicalRoot
1126
+ });
1127
+ const missingImport = findMissingRelativeImport(source, cleanId);
1128
+ if (missingImport) {
1129
+ const message = `Failed to resolve import "${missingImport}" from "${filepath}". Does the file exist?`;
1130
+ errorServer.setError({
1131
+ type: "compile",
1132
+ message,
1133
+ file: cleanId,
1134
+ plugin: "vite:import-analysis"
1135
+ });
1136
+ } else {
1137
+ errorServer.clearErrorForModules([cleanId, filepath]);
1138
+ }
1139
+ const typeInfo = typeAnalyzer?.analyzeFileTypes(cleanId, source);
1140
+ const result = annotateFile(source, cleanId, (info) => {
1141
+ return computeTempoAnnotatedProps({
1142
+ info,
1143
+ filepath,
1144
+ modifiedtsMs,
1145
+ source,
1146
+ computeAnnotatedProps,
1147
+ typeInfo
1148
+ });
1149
+ });
1150
+ if (result.elementsAnnotated === 0) {
1151
+ return null;
1152
+ }
1153
+ return {
1154
+ code: result.annotatedSource,
1155
+ map: null
1156
+ };
1157
+ } catch {
1158
+ return null;
1159
+ }
1160
+ }
1161
+ };
1162
+ }
1163
+ var tempoAnnotate = tempoVitePlugin;
1164
+ // Annotate the CommonJS export names for ESM import in node:
1165
+ 0 && (module.exports = {
1166
+ createTypeAnalyzer,
1167
+ tempoAnnotate,
1168
+ tempoVitePlugin
1169
+ });
1170
+ //# sourceMappingURL=index.cjs.map