tempo-sdk 0.0.3 → 0.0.4
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/README.md +272 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +131 -7
- package/dist/index.js.map +1 -1
- package/dist/nextjs-loader.cjs +901 -0
- package/dist/nextjs-loader.cjs.map +1 -0
- package/dist/nextjs.cjs +204 -0
- package/dist/nextjs.cjs.map +1 -0
- package/dist/nextjs.d.cts +108 -0
- package/dist/nextjs.d.ts +108 -0
- package/dist/nextjs.js +174 -0
- package/dist/nextjs.js.map +1 -0
- package/package.json +39 -21
|
@@ -0,0 +1,901 @@
|
|
|
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
|
+
// nextjs-loader.ts
|
|
31
|
+
var nextjs_loader_exports = {};
|
|
32
|
+
__export(nextjs_loader_exports, {
|
|
33
|
+
_resetLoaderState: () => _resetLoaderState,
|
|
34
|
+
default: () => nextjs_loader_default,
|
|
35
|
+
injectRootMetaIntoAnnotatedSource: () => injectRootMetaIntoAnnotatedSource,
|
|
36
|
+
injectRootMetaIntoSource: () => injectRootMetaIntoSource,
|
|
37
|
+
nextjsLoader: () => nextjsLoader
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(nextjs_loader_exports);
|
|
40
|
+
var import_node_fs3 = require("fs");
|
|
41
|
+
var import_node_module = require("module");
|
|
42
|
+
var import_node_path3 = require("path");
|
|
43
|
+
|
|
44
|
+
// ../../modules/annotation/annotate-file.ts
|
|
45
|
+
var import_oxc_parser2 = require("oxc-parser");
|
|
46
|
+
|
|
47
|
+
// ../../modules/file-parser/utils.ts
|
|
48
|
+
function getTagName(name) {
|
|
49
|
+
switch (name.type) {
|
|
50
|
+
case "JSXIdentifier":
|
|
51
|
+
return name.name;
|
|
52
|
+
case "JSXNamespacedName":
|
|
53
|
+
return `${name.namespace.name}:${name.name.name}`;
|
|
54
|
+
case "JSXMemberExpression":
|
|
55
|
+
return getJSXMemberExpressionName(name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function getJSXMemberExpressionName(node) {
|
|
59
|
+
const object = node.object.type === "JSXIdentifier" ? node.object.name : getJSXMemberExpressionName(node.object);
|
|
60
|
+
return `${object}.${node.property.name}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ../../modules/file-parser/walk.ts
|
|
64
|
+
function walk(node, callbacks) {
|
|
65
|
+
if (node === null || node === void 0 || typeof node !== "object") return;
|
|
66
|
+
if (Array.isArray(node)) {
|
|
67
|
+
for (const child of node) {
|
|
68
|
+
walk(child, callbacks);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const record = node;
|
|
73
|
+
const type = record.type;
|
|
74
|
+
if (typeof type === "string" && type in callbacks) {
|
|
75
|
+
callbacks[type](node);
|
|
76
|
+
}
|
|
77
|
+
for (const value of Object.values(record)) {
|
|
78
|
+
if (value !== null && typeof value === "object") {
|
|
79
|
+
walk(value, callbacks);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ../../modules/file-parser/scope-analyzer/types.ts
|
|
85
|
+
var ScopeFlags = {
|
|
86
|
+
Top: 1 << 0,
|
|
87
|
+
Function: 1 << 1,
|
|
88
|
+
Block: 1 << 2,
|
|
89
|
+
Catch: 1 << 3,
|
|
90
|
+
Class: 1 << 4,
|
|
91
|
+
For: 1 << 5,
|
|
92
|
+
Switch: 1 << 6,
|
|
93
|
+
Module: 1 << 7,
|
|
94
|
+
StrictMode: 1 << 8,
|
|
95
|
+
ClassStaticBlock: 1 << 9,
|
|
96
|
+
TsModuleBlock: 1 << 10,
|
|
97
|
+
TsConditional: 1 << 11,
|
|
98
|
+
Type: 1 << 12,
|
|
99
|
+
Enum: 1 << 13
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ../../modules/file-parser/scope-analyzer/scopeAnalyzer.ts
|
|
103
|
+
var import_oxc_parser = require("oxc-parser");
|
|
104
|
+
var import_keys = __toESM(require("oxc-parser/src-js/generated/visit/keys.js"), 1);
|
|
105
|
+
|
|
106
|
+
// ../../modules/annotation/annotate-file.ts
|
|
107
|
+
function formatPropValue(value) {
|
|
108
|
+
if (value === void 0) return null;
|
|
109
|
+
if (typeof value === "function") return value.toString();
|
|
110
|
+
return JSON.stringify(value);
|
|
111
|
+
}
|
|
112
|
+
function formatProps(props) {
|
|
113
|
+
return Object.entries(props).map(([key, value]) => {
|
|
114
|
+
const formatted = formatPropValue(value);
|
|
115
|
+
if (formatted === null) return null;
|
|
116
|
+
return ` ${key}={${formatted}}`;
|
|
117
|
+
}).filter((s) => s !== null).join("");
|
|
118
|
+
}
|
|
119
|
+
var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
|
|
120
|
+
function annotateFile(source, filename, computeAnnotatedProps) {
|
|
121
|
+
const parseResult = (0, import_oxc_parser2.parseSync)(filename, source);
|
|
122
|
+
const insertions = [];
|
|
123
|
+
walk(parseResult.program, {
|
|
124
|
+
JSXElement(node) {
|
|
125
|
+
const element = node;
|
|
126
|
+
const tagName = getTagName(element.openingElement.name);
|
|
127
|
+
if (FRAGMENT_TAG_NAMES.has(tagName)) return;
|
|
128
|
+
const props = computeAnnotatedProps({ element, tagName });
|
|
129
|
+
if (Object.keys(props).length === 0) return;
|
|
130
|
+
const openingElement = element.openingElement;
|
|
131
|
+
let insertPos = openingElement.end - 1;
|
|
132
|
+
if (openingElement.selfClosing) {
|
|
133
|
+
insertPos--;
|
|
134
|
+
while (insertPos > openingElement.start && /\s/.test(source[insertPos - 1])) {
|
|
135
|
+
insertPos--;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
insertions.push({ position: insertPos, text: formatProps(props) });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
insertions.sort((a, b) => a.position - b.position);
|
|
142
|
+
const chunks = [];
|
|
143
|
+
let lastPos = 0;
|
|
144
|
+
for (const { position, text } of insertions) {
|
|
145
|
+
chunks.push(source.slice(lastPos, position));
|
|
146
|
+
chunks.push(text);
|
|
147
|
+
lastPos = position;
|
|
148
|
+
}
|
|
149
|
+
chunks.push(source.slice(lastPos));
|
|
150
|
+
return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// nextjs-loader.ts
|
|
154
|
+
var import_oxc_parser3 = require("oxc-parser");
|
|
155
|
+
|
|
156
|
+
// type-analyzer.ts
|
|
157
|
+
var import_typescript2 = __toESM(require("typescript"), 1);
|
|
158
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
159
|
+
var import_node_fs2 = require("fs");
|
|
160
|
+
|
|
161
|
+
// ../../modules/typescript/workspace-service.ts
|
|
162
|
+
var import_node_fs = require("fs");
|
|
163
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
164
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
165
|
+
function canonicalPath(input) {
|
|
166
|
+
const resolved = import_node_path.default.resolve(input);
|
|
167
|
+
try {
|
|
168
|
+
return import_node_fs.realpathSync.native(resolved);
|
|
169
|
+
} catch {
|
|
170
|
+
return resolved;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function compareProjectPriority(left, right) {
|
|
174
|
+
const depthDelta = right.rootDir.length - left.rootDir.length;
|
|
175
|
+
if (depthDelta !== 0) {
|
|
176
|
+
return depthDelta;
|
|
177
|
+
}
|
|
178
|
+
const priorityDelta = right.priority - left.priority;
|
|
179
|
+
if (priorityDelta !== 0) {
|
|
180
|
+
return priorityDelta;
|
|
181
|
+
}
|
|
182
|
+
return left.id.localeCompare(right.id);
|
|
183
|
+
}
|
|
184
|
+
function isWithinRoot(filePath, rootDir) {
|
|
185
|
+
return filePath === rootDir || filePath.startsWith(`${rootDir}${import_node_path.default.sep}`);
|
|
186
|
+
}
|
|
187
|
+
function loadProject(descriptor) {
|
|
188
|
+
const id = descriptor.id.trim();
|
|
189
|
+
if (!id) {
|
|
190
|
+
throw new Error("Project id must be a non-empty string");
|
|
191
|
+
}
|
|
192
|
+
const tsconfigPath = canonicalPath(descriptor.tsconfigPath);
|
|
193
|
+
const rootDir = canonicalPath(descriptor.rootDir);
|
|
194
|
+
const readResult = import_typescript.default.readConfigFile(tsconfigPath, import_typescript.default.sys.readFile);
|
|
195
|
+
if (readResult.error) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`Failed to read tsconfig at ${tsconfigPath}: ${import_typescript.default.flattenDiagnosticMessageText(
|
|
198
|
+
readResult.error.messageText,
|
|
199
|
+
"\n"
|
|
200
|
+
)}`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
const parsed = import_typescript.default.parseJsonConfigFileContent(
|
|
204
|
+
readResult.config,
|
|
205
|
+
import_typescript.default.sys,
|
|
206
|
+
import_node_path.default.dirname(tsconfigPath)
|
|
207
|
+
);
|
|
208
|
+
if (parsed.errors.length > 0) {
|
|
209
|
+
const message = parsed.errors.map(
|
|
210
|
+
(diagnostic) => import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
|
|
211
|
+
).join("; ");
|
|
212
|
+
throw new Error(`Failed to parse tsconfig at ${tsconfigPath}: ${message}`);
|
|
213
|
+
}
|
|
214
|
+
const normalizedFiles = parsed.fileNames.map(
|
|
215
|
+
(fileName) => canonicalPath(fileName)
|
|
216
|
+
);
|
|
217
|
+
return {
|
|
218
|
+
id,
|
|
219
|
+
rootDir,
|
|
220
|
+
tsconfigPath,
|
|
221
|
+
priority: descriptor.priority ?? 0,
|
|
222
|
+
options: parsed.options,
|
|
223
|
+
fileNames: normalizedFiles,
|
|
224
|
+
moduleResolutionCache: import_typescript.default.createModuleResolutionCache(
|
|
225
|
+
rootDir,
|
|
226
|
+
(value) => value,
|
|
227
|
+
parsed.options
|
|
228
|
+
)
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function getFileMtimeVersion(filePath) {
|
|
232
|
+
try {
|
|
233
|
+
const stats = (0, import_node_fs.statSync)(filePath);
|
|
234
|
+
return String(stats.mtimeMs);
|
|
235
|
+
} catch {
|
|
236
|
+
return "0";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function createTsWorkspaceService(descriptor) {
|
|
240
|
+
if (descriptor.projects.length === 0) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
"TsWorkspaceDescriptor.projects must include at least one project"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const workspaceRoot = canonicalPath(descriptor.workspaceRoot);
|
|
246
|
+
const loadedProjects = descriptor.projects.map(
|
|
247
|
+
(project) => loadProject(project)
|
|
248
|
+
);
|
|
249
|
+
const projectsById = /* @__PURE__ */ new Map();
|
|
250
|
+
for (const project of loadedProjects) {
|
|
251
|
+
if (projectsById.has(project.id)) {
|
|
252
|
+
throw new Error(`Duplicate project id: ${project.id}`);
|
|
253
|
+
}
|
|
254
|
+
projectsById.set(project.id, project);
|
|
255
|
+
}
|
|
256
|
+
const primaryProject = (descriptor.primaryProjectId ? projectsById.get(descriptor.primaryProjectId) : null) ?? loadedProjects[0];
|
|
257
|
+
if (descriptor.primaryProjectId && !projectsById.has(descriptor.primaryProjectId)) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`Primary project id not found: ${descriptor.primaryProjectId}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
const orderedProjects = [...loadedProjects].sort(compareProjectPriority);
|
|
263
|
+
const rootFileNames = /* @__PURE__ */ new Set();
|
|
264
|
+
for (const project of loadedProjects) {
|
|
265
|
+
for (const fileName of project.fileNames) {
|
|
266
|
+
rootFileNames.add(fileName);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const inMemoryFiles = /* @__PURE__ */ new Map();
|
|
270
|
+
let projectVersion = 0;
|
|
271
|
+
function getOwningProject(filePath) {
|
|
272
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
273
|
+
for (const project of orderedProjects) {
|
|
274
|
+
if (isWithinRoot(canonicalFilePath, project.rootDir)) {
|
|
275
|
+
return project;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return primaryProject;
|
|
279
|
+
}
|
|
280
|
+
const moduleResolutionHost = {
|
|
281
|
+
fileExists: import_typescript.default.sys.fileExists,
|
|
282
|
+
readFile: import_typescript.default.sys.readFile,
|
|
283
|
+
realpath: import_typescript.default.sys.realpath,
|
|
284
|
+
directoryExists: import_typescript.default.sys.directoryExists,
|
|
285
|
+
getCurrentDirectory: () => workspaceRoot,
|
|
286
|
+
getDirectories: import_typescript.default.sys.getDirectories
|
|
287
|
+
};
|
|
288
|
+
const host = {
|
|
289
|
+
getScriptFileNames: () => Array.from(rootFileNames),
|
|
290
|
+
getScriptVersion: (filePath) => {
|
|
291
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
292
|
+
const inMemory = inMemoryFiles.get(canonicalFilePath);
|
|
293
|
+
if (inMemory) {
|
|
294
|
+
return String(inMemory.version);
|
|
295
|
+
}
|
|
296
|
+
return getFileMtimeVersion(canonicalFilePath);
|
|
297
|
+
},
|
|
298
|
+
getScriptSnapshot: (filePath) => {
|
|
299
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
300
|
+
const inMemory = inMemoryFiles.get(canonicalFilePath);
|
|
301
|
+
if (inMemory) {
|
|
302
|
+
return import_typescript.default.ScriptSnapshot.fromString(inMemory.content);
|
|
303
|
+
}
|
|
304
|
+
const diskContent = import_typescript.default.sys.readFile(canonicalFilePath);
|
|
305
|
+
if (diskContent === void 0) {
|
|
306
|
+
return void 0;
|
|
307
|
+
}
|
|
308
|
+
return import_typescript.default.ScriptSnapshot.fromString(diskContent);
|
|
309
|
+
},
|
|
310
|
+
getCurrentDirectory: () => workspaceRoot,
|
|
311
|
+
getCompilationSettings: () => primaryProject.options,
|
|
312
|
+
getDefaultLibFileName: (options) => import_typescript.default.getDefaultLibFilePath(options),
|
|
313
|
+
fileExists: import_typescript.default.sys.fileExists,
|
|
314
|
+
readFile: import_typescript.default.sys.readFile,
|
|
315
|
+
readDirectory: import_typescript.default.sys.readDirectory,
|
|
316
|
+
directoryExists: import_typescript.default.sys.directoryExists,
|
|
317
|
+
getDirectories: import_typescript.default.sys.getDirectories,
|
|
318
|
+
useCaseSensitiveFileNames: () => import_typescript.default.sys.useCaseSensitiveFileNames,
|
|
319
|
+
getProjectVersion: () => String(projectVersion),
|
|
320
|
+
resolveModuleNames: (moduleNames, containingFile) => {
|
|
321
|
+
const owningProject = getOwningProject(containingFile);
|
|
322
|
+
return moduleNames.map((moduleName) => {
|
|
323
|
+
const ownerResolution = import_typescript.default.resolveModuleName(
|
|
324
|
+
moduleName,
|
|
325
|
+
containingFile,
|
|
326
|
+
owningProject.options,
|
|
327
|
+
moduleResolutionHost,
|
|
328
|
+
owningProject.moduleResolutionCache
|
|
329
|
+
).resolvedModule;
|
|
330
|
+
if (ownerResolution) {
|
|
331
|
+
return ownerResolution;
|
|
332
|
+
}
|
|
333
|
+
if (owningProject.id === primaryProject.id) {
|
|
334
|
+
return void 0;
|
|
335
|
+
}
|
|
336
|
+
return import_typescript.default.resolveModuleName(
|
|
337
|
+
moduleName,
|
|
338
|
+
containingFile,
|
|
339
|
+
primaryProject.options,
|
|
340
|
+
moduleResolutionHost,
|
|
341
|
+
primaryProject.moduleResolutionCache
|
|
342
|
+
).resolvedModule;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const languageService = import_typescript.default.createLanguageService(
|
|
347
|
+
host,
|
|
348
|
+
import_typescript.default.createDocumentRegistry()
|
|
349
|
+
);
|
|
350
|
+
return {
|
|
351
|
+
updateFile(filePath, content) {
|
|
352
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
353
|
+
const currentVersion = inMemoryFiles.get(canonicalFilePath)?.version ?? 0;
|
|
354
|
+
inMemoryFiles.set(canonicalFilePath, {
|
|
355
|
+
version: currentVersion + 1,
|
|
356
|
+
content
|
|
357
|
+
});
|
|
358
|
+
if (!rootFileNames.has(canonicalFilePath)) {
|
|
359
|
+
rootFileNames.add(canonicalFilePath);
|
|
360
|
+
}
|
|
361
|
+
projectVersion += 1;
|
|
362
|
+
},
|
|
363
|
+
closeFile(filePath) {
|
|
364
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
365
|
+
inMemoryFiles.delete(canonicalFilePath);
|
|
366
|
+
projectVersion += 1;
|
|
367
|
+
},
|
|
368
|
+
getProgram() {
|
|
369
|
+
return languageService.getProgram() ?? null;
|
|
370
|
+
},
|
|
371
|
+
getSemanticDiagnostics(filePath) {
|
|
372
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
373
|
+
return languageService.getSemanticDiagnostics(canonicalFilePath);
|
|
374
|
+
},
|
|
375
|
+
getDefinition(filePath, position) {
|
|
376
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
377
|
+
return languageService.getDefinitionAtPosition(
|
|
378
|
+
canonicalFilePath,
|
|
379
|
+
position
|
|
380
|
+
);
|
|
381
|
+
},
|
|
382
|
+
dispose() {
|
|
383
|
+
languageService.dispose();
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// type-analyzer.ts
|
|
389
|
+
function isCustomComponent(node) {
|
|
390
|
+
const text = node.getText();
|
|
391
|
+
return text.length > 0 && text[0] !== text[0].toLowerCase();
|
|
392
|
+
}
|
|
393
|
+
function canonicalPath2(value) {
|
|
394
|
+
const resolved = import_node_path2.default.resolve(value);
|
|
395
|
+
try {
|
|
396
|
+
return import_node_fs2.realpathSync.native(resolved);
|
|
397
|
+
} catch {
|
|
398
|
+
return resolved;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function parseManagedTsconfigPaths(rawConfig) {
|
|
402
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
403
|
+
return [];
|
|
404
|
+
}
|
|
405
|
+
const metadata = rawConfig.tempobook;
|
|
406
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
const managedPaths = metadata.managedTsconfigPaths;
|
|
410
|
+
if (!Array.isArray(managedPaths)) {
|
|
411
|
+
return [];
|
|
412
|
+
}
|
|
413
|
+
return managedPaths.filter(
|
|
414
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
function parseProjectReferenceTsconfigPaths(references, configDir) {
|
|
418
|
+
if (!references || references.length === 0) {
|
|
419
|
+
return [];
|
|
420
|
+
}
|
|
421
|
+
const entries = [];
|
|
422
|
+
for (const reference of references) {
|
|
423
|
+
const referencePath = reference.path;
|
|
424
|
+
if (!referencePath) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const resolvedPath = import_node_path2.default.resolve(configDir, referencePath);
|
|
428
|
+
const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : import_node_path2.default.join(resolvedPath, "tsconfig.json");
|
|
429
|
+
entries.push(tsconfigPath);
|
|
430
|
+
}
|
|
431
|
+
return entries;
|
|
432
|
+
}
|
|
433
|
+
function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
|
|
434
|
+
const configDir = import_node_path2.default.dirname(configPath);
|
|
435
|
+
const projects = [
|
|
436
|
+
{
|
|
437
|
+
id: "root",
|
|
438
|
+
rootDir: root,
|
|
439
|
+
tsconfigPath: configPath,
|
|
440
|
+
priority: 0
|
|
441
|
+
}
|
|
442
|
+
];
|
|
443
|
+
const seenTsconfigPaths = /* @__PURE__ */ new Set([canonicalPath2(configPath)]);
|
|
444
|
+
const referencedTsconfigPaths = parseProjectReferenceTsconfigPaths(
|
|
445
|
+
parsedConfig.projectReferences,
|
|
446
|
+
configDir
|
|
447
|
+
);
|
|
448
|
+
const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
|
|
449
|
+
(entry) => import_node_path2.default.resolve(configDir, entry)
|
|
450
|
+
);
|
|
451
|
+
const candidateTsconfigPaths = [
|
|
452
|
+
...managedTsconfigPaths,
|
|
453
|
+
...referencedTsconfigPaths
|
|
454
|
+
];
|
|
455
|
+
for (const candidatePath of candidateTsconfigPaths) {
|
|
456
|
+
const normalizedPath = canonicalPath2(candidatePath);
|
|
457
|
+
if (seenTsconfigPaths.has(normalizedPath)) {
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (!import_typescript2.default.sys.fileExists(normalizedPath)) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
seenTsconfigPaths.add(normalizedPath);
|
|
464
|
+
projects.push({
|
|
465
|
+
id: `external-${projects.length}`,
|
|
466
|
+
rootDir: import_node_path2.default.dirname(normalizedPath),
|
|
467
|
+
tsconfigPath: normalizedPath,
|
|
468
|
+
priority: 0
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
return projects;
|
|
472
|
+
}
|
|
473
|
+
function createTypeAnalyzer(root) {
|
|
474
|
+
const configPath = import_typescript2.default.findConfigFile(
|
|
475
|
+
root,
|
|
476
|
+
import_typescript2.default.sys.fileExists,
|
|
477
|
+
"tsconfig.json"
|
|
478
|
+
);
|
|
479
|
+
if (!configPath) return null;
|
|
480
|
+
const configFile = import_typescript2.default.readConfigFile(configPath, import_typescript2.default.sys.readFile);
|
|
481
|
+
if (configFile.error) return null;
|
|
482
|
+
const parsedConfig = import_typescript2.default.parseJsonConfigFileContent(
|
|
483
|
+
configFile.config,
|
|
484
|
+
import_typescript2.default.sys,
|
|
485
|
+
root
|
|
486
|
+
);
|
|
487
|
+
const workspaceProjects = buildWorkspaceProjects(
|
|
488
|
+
root,
|
|
489
|
+
configPath,
|
|
490
|
+
parsedConfig,
|
|
491
|
+
configFile.config
|
|
492
|
+
);
|
|
493
|
+
const workspaceProjectRoots = workspaceProjects.map(
|
|
494
|
+
(project) => canonicalPath2(project.rootDir)
|
|
495
|
+
);
|
|
496
|
+
const workspaceService = createTsWorkspaceService({
|
|
497
|
+
workspaceRoot: root,
|
|
498
|
+
primaryProjectId: "root",
|
|
499
|
+
projects: workspaceProjects
|
|
500
|
+
});
|
|
501
|
+
let cssPropertiesType;
|
|
502
|
+
function resolveCSSPropertiesType(checker, sourceFile) {
|
|
503
|
+
if (cssPropertiesType !== void 0) return cssPropertiesType;
|
|
504
|
+
try {
|
|
505
|
+
let jsxNs = checker.resolveName(
|
|
506
|
+
"JSX",
|
|
507
|
+
sourceFile,
|
|
508
|
+
import_typescript2.default.SymbolFlags.Namespace,
|
|
509
|
+
false
|
|
510
|
+
);
|
|
511
|
+
if (!jsxNs) {
|
|
512
|
+
const program = workspaceService.getProgram();
|
|
513
|
+
const compilerOptions = program?.getCompilerOptions();
|
|
514
|
+
const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
|
|
515
|
+
const resolved = import_typescript2.default.resolveModuleName(
|
|
516
|
+
`${jsxImportSource}/jsx-runtime`,
|
|
517
|
+
sourceFile.fileName,
|
|
518
|
+
compilerOptions,
|
|
519
|
+
import_typescript2.default.sys
|
|
520
|
+
);
|
|
521
|
+
if (resolved.resolvedModule) {
|
|
522
|
+
const runtimeFile = program?.getSourceFile(
|
|
523
|
+
resolved.resolvedModule.resolvedFileName
|
|
524
|
+
);
|
|
525
|
+
if (runtimeFile) {
|
|
526
|
+
const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
|
|
527
|
+
if (runtimeSymbol) {
|
|
528
|
+
const exports2 = checker.getExportsOfModule(runtimeSymbol);
|
|
529
|
+
jsxNs = exports2.find((s) => s.name === "JSX");
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (!jsxNs) {
|
|
535
|
+
cssPropertiesType = null;
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
|
|
539
|
+
if (!intrinsicSym) {
|
|
540
|
+
cssPropertiesType = null;
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
|
|
544
|
+
if (!divSym) {
|
|
545
|
+
cssPropertiesType = null;
|
|
546
|
+
return null;
|
|
547
|
+
}
|
|
548
|
+
const styleSym = checker.getTypeOfSymbol(divSym).getProperty("style");
|
|
549
|
+
if (!styleSym) {
|
|
550
|
+
cssPropertiesType = null;
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
const styleType = checker.getTypeOfSymbol(styleSym);
|
|
554
|
+
if (styleType.isUnion()) {
|
|
555
|
+
const nonUndefined = styleType.types.find(
|
|
556
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
557
|
+
);
|
|
558
|
+
cssPropertiesType = nonUndefined ?? null;
|
|
559
|
+
} else {
|
|
560
|
+
cssPropertiesType = styleType;
|
|
561
|
+
}
|
|
562
|
+
} catch {
|
|
563
|
+
cssPropertiesType = null;
|
|
564
|
+
}
|
|
565
|
+
return cssPropertiesType;
|
|
566
|
+
}
|
|
567
|
+
let reactNodeType;
|
|
568
|
+
function resolveReactNodeType(checker, sourceFile) {
|
|
569
|
+
if (reactNodeType !== void 0) return reactNodeType;
|
|
570
|
+
try {
|
|
571
|
+
let jsxNs = checker.resolveName(
|
|
572
|
+
"JSX",
|
|
573
|
+
sourceFile,
|
|
574
|
+
import_typescript2.default.SymbolFlags.Namespace,
|
|
575
|
+
false
|
|
576
|
+
);
|
|
577
|
+
if (!jsxNs) {
|
|
578
|
+
const program = workspaceService.getProgram();
|
|
579
|
+
const compilerOptions = program?.getCompilerOptions();
|
|
580
|
+
const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
|
|
581
|
+
const resolved = import_typescript2.default.resolveModuleName(
|
|
582
|
+
`${jsxImportSource}/jsx-runtime`,
|
|
583
|
+
sourceFile.fileName,
|
|
584
|
+
compilerOptions,
|
|
585
|
+
import_typescript2.default.sys
|
|
586
|
+
);
|
|
587
|
+
if (resolved.resolvedModule) {
|
|
588
|
+
const runtimeFile = program?.getSourceFile(
|
|
589
|
+
resolved.resolvedModule.resolvedFileName
|
|
590
|
+
);
|
|
591
|
+
if (runtimeFile) {
|
|
592
|
+
const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
|
|
593
|
+
if (runtimeSymbol) {
|
|
594
|
+
const exports2 = checker.getExportsOfModule(runtimeSymbol);
|
|
595
|
+
jsxNs = exports2.find((s) => s.name === "JSX");
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (!jsxNs) {
|
|
601
|
+
reactNodeType = null;
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
|
|
605
|
+
if (!intrinsicSym) {
|
|
606
|
+
reactNodeType = null;
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
|
|
610
|
+
if (!divSym) {
|
|
611
|
+
reactNodeType = null;
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
const childrenSym = checker.getTypeOfSymbol(divSym).getProperty("children");
|
|
615
|
+
if (!childrenSym) {
|
|
616
|
+
reactNodeType = null;
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
const childrenType = checker.getTypeOfSymbol(childrenSym);
|
|
620
|
+
if (childrenType.isUnion()) {
|
|
621
|
+
const nonUndefined = childrenType.types.find(
|
|
622
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
623
|
+
);
|
|
624
|
+
reactNodeType = nonUndefined ?? null;
|
|
625
|
+
} else {
|
|
626
|
+
reactNodeType = childrenType;
|
|
627
|
+
}
|
|
628
|
+
} catch {
|
|
629
|
+
reactNodeType = null;
|
|
630
|
+
}
|
|
631
|
+
return reactNodeType;
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
analyzeFileTypes(filePath, source) {
|
|
635
|
+
const canonicalFilePath = canonicalPath2(filePath);
|
|
636
|
+
const belongsToWorkspace = workspaceProjectRoots.some(
|
|
637
|
+
(projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${import_node_path2.default.sep}`)
|
|
638
|
+
);
|
|
639
|
+
if (!belongsToWorkspace) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
workspaceService.updateFile(filePath, source);
|
|
643
|
+
const program = workspaceService.getProgram();
|
|
644
|
+
if (!program) return null;
|
|
645
|
+
const sourceFile = program.getSourceFile(filePath);
|
|
646
|
+
if (!sourceFile) return null;
|
|
647
|
+
const checker = program.getTypeChecker();
|
|
648
|
+
const cssProps = resolveCSSPropertiesType(checker, sourceFile);
|
|
649
|
+
const result = /* @__PURE__ */ new Map();
|
|
650
|
+
function visit(node) {
|
|
651
|
+
if ((import_typescript2.default.isJsxOpeningElement(node) || import_typescript2.default.isJsxSelfClosingElement(node)) && isCustomComponent(node.tagName)) {
|
|
652
|
+
const position = node.getStart(sourceFile);
|
|
653
|
+
const attrsType = checker.getContextualType(node.attributes);
|
|
654
|
+
let supportsStyle = false;
|
|
655
|
+
let supportsClassName = false;
|
|
656
|
+
let supportsChildren = false;
|
|
657
|
+
if (attrsType) {
|
|
658
|
+
const classNameProp = attrsType.getProperty("className");
|
|
659
|
+
if (classNameProp) {
|
|
660
|
+
const propType = checker.getTypeOfSymbol(classNameProp);
|
|
661
|
+
supportsClassName = checker.isTypeAssignableTo(
|
|
662
|
+
checker.getStringType(),
|
|
663
|
+
propType
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
const styleProp = attrsType.getProperty("style");
|
|
667
|
+
if (styleProp && cssProps) {
|
|
668
|
+
let propType = checker.getTypeOfSymbol(styleProp);
|
|
669
|
+
if (propType.isUnion()) {
|
|
670
|
+
const nonUndefined = propType.types.find(
|
|
671
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
672
|
+
);
|
|
673
|
+
if (nonUndefined) propType = nonUndefined;
|
|
674
|
+
}
|
|
675
|
+
supportsStyle = checker.isTypeAssignableTo(cssProps, propType);
|
|
676
|
+
}
|
|
677
|
+
const reactNode = resolveReactNodeType(checker, sourceFile);
|
|
678
|
+
const childrenProp = attrsType.getProperty("children");
|
|
679
|
+
if (childrenProp && reactNode) {
|
|
680
|
+
let propType = checker.getTypeOfSymbol(childrenProp);
|
|
681
|
+
if (propType.isUnion()) {
|
|
682
|
+
const nonUndefined = propType.types.find(
|
|
683
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
684
|
+
);
|
|
685
|
+
if (nonUndefined) propType = nonUndefined;
|
|
686
|
+
}
|
|
687
|
+
supportsChildren = checker.isTypeAssignableTo(
|
|
688
|
+
reactNode,
|
|
689
|
+
propType
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
result.set(position, { supportsStyle, supportsClassName, supportsChildren });
|
|
694
|
+
}
|
|
695
|
+
import_typescript2.default.forEachChild(node, visit);
|
|
696
|
+
}
|
|
697
|
+
visit(sourceFile);
|
|
698
|
+
return result;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// nextjs-loader.ts
|
|
704
|
+
var ROOT_META_NAME = "tempo-project-root";
|
|
705
|
+
var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
706
|
+
"area",
|
|
707
|
+
"base",
|
|
708
|
+
"br",
|
|
709
|
+
"col",
|
|
710
|
+
"embed",
|
|
711
|
+
"hr",
|
|
712
|
+
"img",
|
|
713
|
+
"input",
|
|
714
|
+
"link",
|
|
715
|
+
"meta",
|
|
716
|
+
"param",
|
|
717
|
+
"source",
|
|
718
|
+
"track",
|
|
719
|
+
"wbr"
|
|
720
|
+
]);
|
|
721
|
+
var cachedCanonicalRoot = null;
|
|
722
|
+
var cachedTypeAnalyzer = null;
|
|
723
|
+
var cachedUserComputeProps;
|
|
724
|
+
var cachedComputeModulePath = null;
|
|
725
|
+
function _resetLoaderState() {
|
|
726
|
+
cachedCanonicalRoot = null;
|
|
727
|
+
cachedTypeAnalyzer = null;
|
|
728
|
+
cachedUserComputeProps = void 0;
|
|
729
|
+
cachedComputeModulePath = null;
|
|
730
|
+
}
|
|
731
|
+
function isIntrinsicElement(tagName) {
|
|
732
|
+
return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
|
|
733
|
+
}
|
|
734
|
+
function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
|
|
735
|
+
return {
|
|
736
|
+
"data-tempo-filepath": filepath,
|
|
737
|
+
"data-tempo-position": info.element.openingElement.start,
|
|
738
|
+
"data-tempo-modifiedts": modifiedtsMs
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function stripQueryAndHash(path3) {
|
|
742
|
+
const queryIdx = path3.indexOf("?");
|
|
743
|
+
const hashIdx = path3.indexOf("#");
|
|
744
|
+
let end = path3.length;
|
|
745
|
+
if (queryIdx !== -1) end = Math.min(end, queryIdx);
|
|
746
|
+
if (hashIdx !== -1) end = Math.min(end, hashIdx);
|
|
747
|
+
return path3.slice(0, end);
|
|
748
|
+
}
|
|
749
|
+
function resolveCanonicalRoot(rootContext) {
|
|
750
|
+
try {
|
|
751
|
+
return import_node_fs3.realpathSync.native(rootContext);
|
|
752
|
+
} catch {
|
|
753
|
+
return rootContext;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function isInNodeModules(path3) {
|
|
757
|
+
return path3.includes(`${import_node_path3.sep}node_modules${import_node_path3.sep}`);
|
|
758
|
+
}
|
|
759
|
+
function findFirstJSXHead(program) {
|
|
760
|
+
let result = null;
|
|
761
|
+
walk(program, {
|
|
762
|
+
JSXElement(node) {
|
|
763
|
+
if (result) return;
|
|
764
|
+
const element = node;
|
|
765
|
+
const tagName = getTagName(element.openingElement.name);
|
|
766
|
+
if (tagName === "head") {
|
|
767
|
+
result = element;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
return result;
|
|
772
|
+
}
|
|
773
|
+
function hasRootMetaChild(headElement) {
|
|
774
|
+
for (const child of headElement.children ?? []) {
|
|
775
|
+
if (child.type !== "JSXElement") continue;
|
|
776
|
+
const childTag = getTagName(child.openingElement.name);
|
|
777
|
+
if (childTag !== "meta") continue;
|
|
778
|
+
for (const attr of child.openingElement.attributes ?? []) {
|
|
779
|
+
if (attr.type !== "JSXAttribute") continue;
|
|
780
|
+
if (getTagName(attr.name) !== "name") continue;
|
|
781
|
+
const value = attr.value;
|
|
782
|
+
if (value && value.type === "Literal" && value.value === ROOT_META_NAME) {
|
|
783
|
+
return true;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
function injectRootMetaIntoSource(source, filename, root) {
|
|
790
|
+
let parseResult;
|
|
791
|
+
try {
|
|
792
|
+
parseResult = (0, import_oxc_parser3.parseSync)(filename, source);
|
|
793
|
+
} catch {
|
|
794
|
+
return source;
|
|
795
|
+
}
|
|
796
|
+
const headElement = findFirstJSXHead(parseResult.program);
|
|
797
|
+
if (!headElement) return source;
|
|
798
|
+
if (hasRootMetaChild(headElement)) return source;
|
|
799
|
+
const insertPos = headElement.openingElement.end;
|
|
800
|
+
const metaTag = `<meta name="${ROOT_META_NAME}" content={${JSON.stringify(root)}} />`;
|
|
801
|
+
return source.slice(0, insertPos) + metaTag + source.slice(insertPos);
|
|
802
|
+
}
|
|
803
|
+
function injectRootMetaIntoAnnotatedSource(annotatedSource, filename, root) {
|
|
804
|
+
return injectRootMetaIntoSource(annotatedSource, filename, root);
|
|
805
|
+
}
|
|
806
|
+
function loadUserComputeProps(modulePath, canonicalRoot) {
|
|
807
|
+
const resolved = (0, import_node_path3.resolve)(canonicalRoot, modulePath);
|
|
808
|
+
const requireFromRoot = (0, import_node_module.createRequire)(`${canonicalRoot}/__tempo_loader__.js`);
|
|
809
|
+
const mod = requireFromRoot(resolved);
|
|
810
|
+
const fn = mod && (mod.default ?? mod);
|
|
811
|
+
if (typeof fn !== "function") {
|
|
812
|
+
return null;
|
|
813
|
+
}
|
|
814
|
+
return fn;
|
|
815
|
+
}
|
|
816
|
+
function readOptions() {
|
|
817
|
+
if (typeof this.getOptions === "function") {
|
|
818
|
+
return this.getOptions() ?? {};
|
|
819
|
+
}
|
|
820
|
+
if (typeof this.query === "string") {
|
|
821
|
+
return {};
|
|
822
|
+
}
|
|
823
|
+
return this.query ?? {};
|
|
824
|
+
}
|
|
825
|
+
function nextjsLoader(source) {
|
|
826
|
+
this.cacheable?.(true);
|
|
827
|
+
if (!process.env.TEMPO) return source;
|
|
828
|
+
const cleanPath = stripQueryAndHash(this.resourcePath ?? "");
|
|
829
|
+
if (!/\.(tsx|jsx)$/.test(cleanPath)) return source;
|
|
830
|
+
if (isInNodeModules(cleanPath)) return source;
|
|
831
|
+
const options = readOptions.call(this);
|
|
832
|
+
try {
|
|
833
|
+
if (cachedCanonicalRoot === null) {
|
|
834
|
+
cachedCanonicalRoot = resolveCanonicalRoot(this.rootContext);
|
|
835
|
+
}
|
|
836
|
+
const canonicalRoot = cachedCanonicalRoot;
|
|
837
|
+
if (cachedTypeAnalyzer === null) {
|
|
838
|
+
try {
|
|
839
|
+
cachedTypeAnalyzer = createTypeAnalyzer(canonicalRoot);
|
|
840
|
+
} catch {
|
|
841
|
+
cachedTypeAnalyzer = { analyzeFileTypes: () => null };
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const userModule = options.computeAnnotatedPropsModule;
|
|
845
|
+
if (userModule && userModule !== cachedComputeModulePath) {
|
|
846
|
+
try {
|
|
847
|
+
cachedUserComputeProps = loadUserComputeProps(userModule, canonicalRoot);
|
|
848
|
+
} catch {
|
|
849
|
+
cachedUserComputeProps = null;
|
|
850
|
+
}
|
|
851
|
+
cachedComputeModulePath = userModule;
|
|
852
|
+
} else if (cachedUserComputeProps === void 0) {
|
|
853
|
+
cachedUserComputeProps = null;
|
|
854
|
+
}
|
|
855
|
+
const userComputeProps = cachedUserComputeProps;
|
|
856
|
+
const filepath = (0, import_node_path3.relative)(canonicalRoot, cleanPath);
|
|
857
|
+
const modifiedtsMs = Math.trunc((0, import_node_fs3.statSync)(cleanPath).mtimeMs);
|
|
858
|
+
const typeInfo = cachedTypeAnalyzer?.analyzeFileTypes(
|
|
859
|
+
cleanPath,
|
|
860
|
+
source
|
|
861
|
+
) ?? null;
|
|
862
|
+
const annotated = annotateFile(source, cleanPath, (info) => {
|
|
863
|
+
const compute = userComputeProps ?? defaultComputeAnnotatedProps;
|
|
864
|
+
const userProps = compute(info, filepath, modifiedtsMs);
|
|
865
|
+
if (isIntrinsicElement(info.tagName)) {
|
|
866
|
+
return {
|
|
867
|
+
...userProps,
|
|
868
|
+
"data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
const support = typeInfo?.get(info.element.openingElement.start);
|
|
872
|
+
return {
|
|
873
|
+
...userProps,
|
|
874
|
+
"data-tempo-supports-style": support?.supportsStyle ?? false,
|
|
875
|
+
"data-tempo-supports-classname": support?.supportsClassName ?? false,
|
|
876
|
+
"data-tempo-supports-children": support?.supportsChildren ?? false
|
|
877
|
+
};
|
|
878
|
+
});
|
|
879
|
+
let finalSource = annotated.annotatedSource;
|
|
880
|
+
if (options.autoInjectRootMeta !== false) {
|
|
881
|
+
finalSource = injectRootMetaIntoAnnotatedSource(
|
|
882
|
+
finalSource,
|
|
883
|
+
cleanPath,
|
|
884
|
+
canonicalRoot
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
if (finalSource === source) return source;
|
|
888
|
+
return finalSource;
|
|
889
|
+
} catch {
|
|
890
|
+
return source;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
var nextjs_loader_default = nextjsLoader;
|
|
894
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
895
|
+
0 && (module.exports = {
|
|
896
|
+
_resetLoaderState,
|
|
897
|
+
injectRootMetaIntoAnnotatedSource,
|
|
898
|
+
injectRootMetaIntoSource,
|
|
899
|
+
nextjsLoader
|
|
900
|
+
});
|
|
901
|
+
//# sourceMappingURL=nextjs-loader.cjs.map
|