vorzelajs 0.0.5 → 0.0.7

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":"AAEA,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;AAaD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAiC1E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,EAAE,SAAS,SAAI,YAYjF"}
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
- try {
16
- const frames = ErrorStackParser.parse(error).map((frame) => {
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;AA+VlC,wBAAsB,cAAc,CAAC,WAAW,SAAgB,iBA2B/D;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CA2C5C"}
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;AAgXlC,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;
@@ -8,7 +9,7 @@ const SERVER_ONLY_ROUTE_FILE_PATTERN = /\.server\.(ts|tsx)$/u;
8
9
  const SERVER_ONLY_DIR_PATTERN = /[\\/]\.server[\\/]/u;
9
10
  const SERVER_ONLY_SPECIFIER_PATTERN = /(?:^|[\\/])\.server(?:[\\/]|$)|\.server(?:$|\.)/u;
10
11
  const CLIENT_EVENT_HANDLER_PATTERN = /\bon[A-Z][A-Za-z0-9]*\s*=/u;
11
- const CLIENT_ROUTER_HOOK_PATTERN = /\b(useNavigate|useSetSearch|Route\.useSetSearch)\b/u;
12
+ const CLIENT_ROUTER_HOOK_PATTERN = /\b(useNavigate|useSearch|useSetSearch|Route\.useSearch|Route\.useSetSearch)\b/u;
12
13
  const CLIENT_SOLID_HOOK_PATTERN = /\b(createSignal|createEffect|createRenderEffect|createResource|onMount|onCleanup)\b/u;
13
14
  const CLIENT_BROWSER_GLOBAL_PATTERN = /\b(window|document|navigator|localStorage|sessionStorage)\s*\./u;
14
15
  const CLIENT_BROWSER_FUNCTION_PATTERN = /\b(requestAnimationFrame|matchMedia)\s*\(/u;
@@ -186,8 +187,14 @@ function detectRouteHydration(source) {
186
187
  ? 'client'
187
188
  : 'static';
188
189
  }
189
- function isLocalModuleSpecifier(specifier) {
190
- return specifier.startsWith('./') || specifier.startsWith('../');
190
+ function isHydrationTrackedSpecifier(specifier) {
191
+ if (/^~\/(router|runtime)(\/|$)/u.test(specifier)) {
192
+ return false;
193
+ }
194
+ return specifier.startsWith('./')
195
+ || specifier.startsWith('../')
196
+ || specifier === '~'
197
+ || specifier.startsWith('~/');
191
198
  }
192
199
  function extractLocalImportSpecifiers(source) {
193
200
  const specifiers = new Set();
@@ -195,7 +202,7 @@ function extractLocalImportSpecifiers(source) {
195
202
  pattern.lastIndex = 0;
196
203
  for (const match of source.matchAll(pattern)) {
197
204
  const specifier = match[1];
198
- if (specifier && isLocalModuleSpecifier(specifier) && !isServerOnlyModuleSpecifier(specifier)) {
205
+ if (specifier && isHydrationTrackedSpecifier(specifier) && !isServerOnlyModuleSpecifier(specifier)) {
199
206
  specifiers.add(specifier);
200
207
  }
201
208
  }
@@ -211,10 +218,18 @@ async function pathExists(filePath) {
211
218
  return false;
212
219
  }
213
220
  }
214
- async function resolveLocalModulePath(specifier, importerPath) {
215
- const basePath = path.resolve(path.dirname(importerPath), specifier);
216
- const candidates = path.extname(basePath)
217
- ? [basePath]
221
+ async function resolveLocalModulePath(specifier, importerPath, projectRoot) {
222
+ const basePath = specifier === '~'
223
+ ? path.resolve(projectRoot, SOURCE_DIR)
224
+ : specifier.startsWith('~/')
225
+ ? path.resolve(projectRoot, SOURCE_DIR, specifier.slice(2))
226
+ : path.resolve(path.dirname(importerPath), specifier);
227
+ const ext = path.extname(basePath);
228
+ const JS_TO_TS_EXTENSIONS = { '.js': ['.ts', '.tsx', '.js'], '.jsx': ['.tsx', '.jsx'] };
229
+ const candidates = ext
230
+ ? ext in JS_TO_TS_EXTENSIONS
231
+ ? JS_TO_TS_EXTENSIONS[ext].map((replacement) => basePath.slice(0, -ext.length) + replacement)
232
+ : [basePath]
218
233
  : [
219
234
  ...SOURCE_FILE_EXTENSIONS.map((extension) => `${basePath}${extension}`),
220
235
  ...SOURCE_FILE_EXTENSIONS.map((extension) => path.join(basePath, `index${extension}`)),
@@ -226,7 +241,7 @@ async function resolveLocalModulePath(specifier, importerPath) {
226
241
  }
227
242
  return null;
228
243
  }
229
- async function detectRouteHydrationFromFile(filePath, cache) {
244
+ async function detectRouteHydrationFromFile(filePath, cache, projectRoot) {
230
245
  const resolvedPath = path.resolve(filePath);
231
246
  const cached = cache.get(resolvedPath);
232
247
  if (cached) {
@@ -238,11 +253,11 @@ async function detectRouteHydrationFromFile(filePath, cache) {
238
253
  return 'client';
239
254
  }
240
255
  for (const specifier of extractLocalImportSpecifiers(source)) {
241
- const dependencyPath = await resolveLocalModulePath(specifier, resolvedPath);
256
+ const dependencyPath = await resolveLocalModulePath(specifier, resolvedPath, projectRoot);
242
257
  if (!dependencyPath) {
243
258
  continue;
244
259
  }
245
- if (await detectRouteHydrationFromFile(dependencyPath, cache) === 'client') {
260
+ if (await detectRouteHydrationFromFile(dependencyPath, cache, projectRoot) === 'client') {
246
261
  return 'client';
247
262
  }
248
263
  }
@@ -251,7 +266,7 @@ async function detectRouteHydrationFromFile(filePath, cache) {
251
266
  cache.set(resolvedPath, pending);
252
267
  return pending;
253
268
  }
254
- async function createGeneratedHydrationFile(routes) {
269
+ async function createGeneratedHydrationFile(routes, projectRoot) {
255
270
  const sortedRoutes = [...routes].sort((left, right) => {
256
271
  if (left.id === '__root__')
257
272
  return -1;
@@ -261,7 +276,7 @@ async function createGeneratedHydrationFile(routes) {
261
276
  });
262
277
  const hydrationCache = new Map();
263
278
  const hydrationEntries = await Promise.all(sortedRoutes.map(async (route) => {
264
- const detected = await detectRouteHydrationFromFile(route.filePath, hydrationCache);
279
+ const detected = await detectRouteHydrationFromFile(route.filePath, hydrationCache, projectRoot);
265
280
  return ` '${route.id}': { detected: '${detected}' }`;
266
281
  }));
267
282
  return `/* eslint-disable */
@@ -302,7 +317,7 @@ export async function generateRoutes(projectRoot = process.cwd()) {
302
317
  assertNoDuplicateMatchPaths(routesWithParents);
303
318
  await Promise.all([
304
319
  writeIfChanged(outputPath, createGeneratedFile(routesWithParents)),
305
- writeIfChanged(hydrationOutputPath, await createGeneratedHydrationFile(routesWithParents)),
320
+ writeIfChanged(hydrationOutputPath, await createGeneratedHydrationFile(routesWithParents, projectRoot)),
306
321
  ]);
307
322
  }
308
323
  export function vorzelaRoutesPlugin() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vorzelajs",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "description": "Batteries-included SolidJS framework with file-based routing, streamed SSR, and server-only boundaries",
6
6
  "license": "MIT",