vorzelajs 0.0.5 → 0.0.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-stack.d.ts","sourceRoot":"","sources":["../../src/debug/error-stack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error-stack.d.ts","sourceRoot":"","sources":["../../src/debug/error-stack.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,eAAe,EAAE,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AA4ED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAa1E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,EAAE,SAAS,SAAI,YAYjF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import ErrorStackParser from 'error-stack-parser';
|
|
2
1
|
function formatFrameSource(frame) {
|
|
3
2
|
const fileName = frame.fileName ?? '<unknown>';
|
|
4
3
|
const lineNumber = frame.lineNumber ?? 0;
|
|
@@ -8,36 +7,69 @@ function formatFrameSource(frame) {
|
|
|
8
7
|
: '';
|
|
9
8
|
return `${functionName}(${fileName}:${lineNumber}:${columnNumber})`;
|
|
10
9
|
}
|
|
10
|
+
function createFrame(source, parts = {}) {
|
|
11
|
+
return {
|
|
12
|
+
...parts,
|
|
13
|
+
source,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function parseStackLine(line) {
|
|
17
|
+
const trimmed = line.trim();
|
|
18
|
+
if (trimmed === '' || trimmed.toLowerCase().startsWith('error')) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const v8Named = /^at\s+(.*?)\s+\((.+):(\d+):(\d+)\)$/u.exec(trimmed);
|
|
22
|
+
if (v8Named) {
|
|
23
|
+
const [, functionName, fileName, lineNumber, columnNumber] = v8Named;
|
|
24
|
+
return createFrame(trimmed, {
|
|
25
|
+
columnNumber: Number(columnNumber),
|
|
26
|
+
fileName,
|
|
27
|
+
functionName,
|
|
28
|
+
lineNumber: Number(lineNumber),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const v8Anonymous = /^at\s+(.+):(\d+):(\d+)$/u.exec(trimmed);
|
|
32
|
+
if (v8Anonymous) {
|
|
33
|
+
const [, fileName, lineNumber, columnNumber] = v8Anonymous;
|
|
34
|
+
return createFrame(trimmed, {
|
|
35
|
+
columnNumber: Number(columnNumber),
|
|
36
|
+
fileName,
|
|
37
|
+
lineNumber: Number(lineNumber),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const firefoxNamed = /^(.*?)@(.+):(\d+):(\d+)$/u.exec(trimmed);
|
|
41
|
+
if (firefoxNamed) {
|
|
42
|
+
const [, functionName, fileName, lineNumber, columnNumber] = firefoxNamed;
|
|
43
|
+
return createFrame(trimmed, {
|
|
44
|
+
columnNumber: Number(columnNumber),
|
|
45
|
+
fileName,
|
|
46
|
+
functionName: functionName || undefined,
|
|
47
|
+
lineNumber: Number(lineNumber),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return createFrame(trimmed);
|
|
51
|
+
}
|
|
52
|
+
function parseStackFrames(stack) {
|
|
53
|
+
return stack
|
|
54
|
+
.split('\n')
|
|
55
|
+
.map(parseStackLine)
|
|
56
|
+
.filter((frame) => frame !== undefined)
|
|
57
|
+
.map((frame) => ({
|
|
58
|
+
...frame,
|
|
59
|
+
source: frame.fileName || frame.functionName ? formatFrameSource(frame) : frame.source,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
11
62
|
export function parseErrorStack(error) {
|
|
12
63
|
if (!(error instanceof Error)) {
|
|
13
64
|
return undefined;
|
|
14
65
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const normalizedFrame = {
|
|
18
|
-
columnNumber: frame.columnNumber,
|
|
19
|
-
fileName: frame.fileName,
|
|
20
|
-
functionName: frame.functionName,
|
|
21
|
-
lineNumber: frame.lineNumber,
|
|
22
|
-
source: '',
|
|
23
|
-
};
|
|
24
|
-
normalizedFrame.source = formatFrameSource(normalizedFrame);
|
|
25
|
-
return normalizedFrame;
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
frames,
|
|
29
|
-
stack: error.stack,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
if (!error.stack) {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
frames: [],
|
|
38
|
-
stack: error.stack,
|
|
39
|
-
};
|
|
66
|
+
if (!error.stack) {
|
|
67
|
+
return undefined;
|
|
40
68
|
}
|
|
69
|
+
return {
|
|
70
|
+
frames: parseStackFrames(error.stack),
|
|
71
|
+
stack: error.stack,
|
|
72
|
+
};
|
|
41
73
|
}
|
|
42
74
|
export function formatParsedStack(stack, maxFrames = 8) {
|
|
43
75
|
if (!stack) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-plugin.d.ts","sourceRoot":"","sources":["../../src/vite/routes-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"routes-plugin.d.ts","sourceRoot":"","sources":["../../src/vite/routes-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAwWlC,wBAAsB,cAAc,CAAC,WAAW,SAAgB,iBA2B/D;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CA2C5C"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
const ROUTES_DIR = path.join('src', 'routes');
|
|
4
|
+
const SOURCE_DIR = 'src';
|
|
4
5
|
const OUTPUT_FILE = path.join('src', 'routeTree.gen.ts');
|
|
5
6
|
const OUTPUT_HYDRATION_FILE = path.join('src', 'routeHydration.gen.ts');
|
|
6
7
|
const ROUTE_FILE_PATTERN = /\.(ts|tsx)$/u;
|
|
@@ -186,8 +187,11 @@ function detectRouteHydration(source) {
|
|
|
186
187
|
? 'client'
|
|
187
188
|
: 'static';
|
|
188
189
|
}
|
|
189
|
-
function
|
|
190
|
-
return specifier.startsWith('./')
|
|
190
|
+
function isHydrationTrackedSpecifier(specifier) {
|
|
191
|
+
return specifier.startsWith('./')
|
|
192
|
+
|| specifier.startsWith('../')
|
|
193
|
+
|| specifier === '~'
|
|
194
|
+
|| specifier.startsWith('~/');
|
|
191
195
|
}
|
|
192
196
|
function extractLocalImportSpecifiers(source) {
|
|
193
197
|
const specifiers = new Set();
|
|
@@ -195,7 +199,7 @@ function extractLocalImportSpecifiers(source) {
|
|
|
195
199
|
pattern.lastIndex = 0;
|
|
196
200
|
for (const match of source.matchAll(pattern)) {
|
|
197
201
|
const specifier = match[1];
|
|
198
|
-
if (specifier &&
|
|
202
|
+
if (specifier && isHydrationTrackedSpecifier(specifier) && !isServerOnlyModuleSpecifier(specifier)) {
|
|
199
203
|
specifiers.add(specifier);
|
|
200
204
|
}
|
|
201
205
|
}
|
|
@@ -211,8 +215,12 @@ async function pathExists(filePath) {
|
|
|
211
215
|
return false;
|
|
212
216
|
}
|
|
213
217
|
}
|
|
214
|
-
async function resolveLocalModulePath(specifier, importerPath) {
|
|
215
|
-
const basePath =
|
|
218
|
+
async function resolveLocalModulePath(specifier, importerPath, projectRoot) {
|
|
219
|
+
const basePath = specifier === '~'
|
|
220
|
+
? path.resolve(projectRoot, SOURCE_DIR)
|
|
221
|
+
: specifier.startsWith('~/')
|
|
222
|
+
? path.resolve(projectRoot, SOURCE_DIR, specifier.slice(2))
|
|
223
|
+
: path.resolve(path.dirname(importerPath), specifier);
|
|
216
224
|
const candidates = path.extname(basePath)
|
|
217
225
|
? [basePath]
|
|
218
226
|
: [
|
|
@@ -226,7 +234,7 @@ async function resolveLocalModulePath(specifier, importerPath) {
|
|
|
226
234
|
}
|
|
227
235
|
return null;
|
|
228
236
|
}
|
|
229
|
-
async function detectRouteHydrationFromFile(filePath, cache) {
|
|
237
|
+
async function detectRouteHydrationFromFile(filePath, cache, projectRoot) {
|
|
230
238
|
const resolvedPath = path.resolve(filePath);
|
|
231
239
|
const cached = cache.get(resolvedPath);
|
|
232
240
|
if (cached) {
|
|
@@ -238,11 +246,11 @@ async function detectRouteHydrationFromFile(filePath, cache) {
|
|
|
238
246
|
return 'client';
|
|
239
247
|
}
|
|
240
248
|
for (const specifier of extractLocalImportSpecifiers(source)) {
|
|
241
|
-
const dependencyPath = await resolveLocalModulePath(specifier, resolvedPath);
|
|
249
|
+
const dependencyPath = await resolveLocalModulePath(specifier, resolvedPath, projectRoot);
|
|
242
250
|
if (!dependencyPath) {
|
|
243
251
|
continue;
|
|
244
252
|
}
|
|
245
|
-
if (await detectRouteHydrationFromFile(dependencyPath, cache) === 'client') {
|
|
253
|
+
if (await detectRouteHydrationFromFile(dependencyPath, cache, projectRoot) === 'client') {
|
|
246
254
|
return 'client';
|
|
247
255
|
}
|
|
248
256
|
}
|
|
@@ -251,7 +259,7 @@ async function detectRouteHydrationFromFile(filePath, cache) {
|
|
|
251
259
|
cache.set(resolvedPath, pending);
|
|
252
260
|
return pending;
|
|
253
261
|
}
|
|
254
|
-
async function createGeneratedHydrationFile(routes) {
|
|
262
|
+
async function createGeneratedHydrationFile(routes, projectRoot) {
|
|
255
263
|
const sortedRoutes = [...routes].sort((left, right) => {
|
|
256
264
|
if (left.id === '__root__')
|
|
257
265
|
return -1;
|
|
@@ -261,7 +269,7 @@ async function createGeneratedHydrationFile(routes) {
|
|
|
261
269
|
});
|
|
262
270
|
const hydrationCache = new Map();
|
|
263
271
|
const hydrationEntries = await Promise.all(sortedRoutes.map(async (route) => {
|
|
264
|
-
const detected = await detectRouteHydrationFromFile(route.filePath, hydrationCache);
|
|
272
|
+
const detected = await detectRouteHydrationFromFile(route.filePath, hydrationCache, projectRoot);
|
|
265
273
|
return ` '${route.id}': { detected: '${detected}' }`;
|
|
266
274
|
}));
|
|
267
275
|
return `/* eslint-disable */
|
|
@@ -302,7 +310,7 @@ export async function generateRoutes(projectRoot = process.cwd()) {
|
|
|
302
310
|
assertNoDuplicateMatchPaths(routesWithParents);
|
|
303
311
|
await Promise.all([
|
|
304
312
|
writeIfChanged(outputPath, createGeneratedFile(routesWithParents)),
|
|
305
|
-
writeIfChanged(hydrationOutputPath, await createGeneratedHydrationFile(routesWithParents)),
|
|
313
|
+
writeIfChanged(hydrationOutputPath, await createGeneratedHydrationFile(routesWithParents, projectRoot)),
|
|
306
314
|
]);
|
|
307
315
|
}
|
|
308
316
|
export function vorzelaRoutesPlugin() {
|