@pithyjs/vite-plugin 0.2.0-beta.12 → 0.2.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aotCodegen/generateDomFactory.d.ts +1 -1
- package/dist/aotCodegen/generateDomFactory.d.ts.map +1 -1
- package/dist/aotCodegen/generateDomFactory.js +14 -1
- package/dist/aotCodegen/generateDomFactory.js.map +1 -1
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts.map +1 -1
- package/dist/babelPlugin/extractUsedIdentifiers.js +2 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js.map +1 -1
- package/dist/designSystemPlugin/channelVars.d.ts.map +1 -1
- package/dist/designSystemPlugin/channelVars.js +1 -2
- package/dist/designSystemPlugin/channelVars.js.map +1 -1
- package/dist/routerPlugin/manifest.d.ts.map +1 -1
- package/dist/routerPlugin/manifest.js +54 -107
- package/dist/routerPlugin/manifest.js.map +1 -1
- package/dist/routerPlugin/plugin.d.ts.map +1 -1
- package/dist/routerPlugin/plugin.js +4 -1
- package/dist/routerPlugin/plugin.js.map +1 -1
- package/dist/routerPlugin/scanner.d.ts +17 -2
- package/dist/routerPlugin/scanner.d.ts.map +1 -1
- package/dist/routerPlugin/scanner.js +107 -30
- package/dist/routerPlugin/scanner.js.map +1 -1
- package/dist/ssrPlugin/plugin.d.ts.map +1 -1
- package/dist/ssrPlugin/plugin.js +42 -19
- package/dist/ssrPlugin/plugin.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/routerPlugin/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAIF;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,GAAG,IAAI,KAAK,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,4JAA4J;AAC5J,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,M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C,IAAI,CAAC,SAAS,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite-plugin-router.manifest\",\n \"title\": \"Route Manifest Generator\",\n \"category\": \"compiler\",\n \"description\": \"Generates typed TypeScript route manifests and CLI-formatted route tables from a route tree.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"manifest.test.ts\" },\n \"integration\": { \"required\": false, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { RouteNode } from '@pithyjs/router';\n\n/**\n * Helper function to get correct filename for route file types\n */\nfunction filenameFor(type: string): string {\n return `${type}.ts`;\n}\n\n/**\n * Generate TypeScript code for the route manifest\n * Creates virtual:pithy/routes.gen module with typed RouteNode tree\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.manifest\",\"name\":\"generateManifest\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string\"} */\nexport function generateManifest(routes: RouteNode[]): string {\n const imports = generateImports(routes);\n\n const routeTree = generateRouteTree(routes);\n\n const manifest = `// Auto-generated route manifest - do not edit manually\n// Generated at: ${new Date().toISOString()}\n\n${imports}\n\n/** @typedef {import(\"../../router/src/types\").RouteNode} RouteNode */\n/** @type {Array<RouteNode>} */\nexport const routes = ${routeTree};\n\n// For TS consumers that import types:\nexport {};\n`;\n\n return manifest;\n}\n\n/**\n * Generate import statements for all route files\n */\nfunction generateImports(routes: RouteNode[]): string {\n const imports: string[] = [];\n const importMap = new Map<string, string>();\n let importCounter = 0;\n\n // Collect all unique file paths and generate import names\n for (const route of routes) {\n for (const [type] of Object.entries(route.imports)) {\n // Build the correct import path relative to the virtual module location\n const segments = route.segments.length > 0 ? route.segments : [];\n let importPath = '/src/routes';\n\n if (segments.length > 0) {\n // Convert segments back to file system format (keep route groups for file paths)\n const fileSegments = segments.map((segment: string) => {\n if (segment.startsWith(':')) {\n return `[${segment.slice(1)}]`; // :id -> [id]\n }\n if (segment === '*') {\n return '[...slug]'; // * -> [...slug]\n }\n return segment; // Keep route groups like (mkt) for file paths\n });\n\n if (fileSegments.length > 0) {\n importPath += '/' + fileSegments.join('/');\n }\n }\n\n const fullPath = `${importPath}/${filenameFor(type)}`;\n\n if (!importMap.has(fullPath)) {\n const importName = `route_${importCounter++}_${type}`;\n importMap.set(fullPath, importName);\n imports.push(`const ${importName} = () => import(\"${fullPath}\");`);\n }\n }\n }\n\n return imports.length > 0 ? imports.join('\\n') : '// No imports needed';\n}\n\n/**\n * Generate the route tree structure\n */\nfunction generateRouteTree(routes: RouteNode[]): string {\n // Build import map first\n const importMap = new Map<string, string>();\n let importCounter = 0;\n\n for (const route of routes) {\n for (const [type] of Object.entries(route.imports)) {\n const segments = route.segments.length > 0 ? route.segments : [];\n let importPath = '/src/routes';\n\n if (segments.length > 0) {\n const fileSegments = segments.map((segment: string) => {\n if (segment.startsWith(':')) {\n return `[${segment.slice(1)}]`;\n }\n if (segment === '*') {\n return '[...slug]';\n }\n return segment;\n });\n\n if (fileSegments.length > 0) {\n importPath += '/' + fileSegments.join('/');\n }\n }\n\n const fullPath = `${importPath}/${filenameFor(type)}`;\n\n if (!importMap.has(fullPath)) {\n const importName = `route_${importCounter++}_${type}`;\n importMap.set(fullPath, importName);\n }\n }\n }\n\n const routeObjects = routes.map(route =>\n generateRouteObject(route, importMap)\n );\n return `[\\n${routeObjects.map(obj => ` ${obj}`).join(',\\n')}\\n]`;\n}\n\n/**\n * Generate a single route object\n */\nfunction generateRouteObject(\n route: RouteNode,\n importMap: Map<string, string>\n): string {\n const imports = generateRouteImports(route, importMap);\n const metadata = route.metadata\n ? JSON.stringify(route.metadata, null, 2)\n : '{}';\n\n return `{\n id: ${JSON.stringify(route.id)},\n pattern: ${JSON.stringify(route.pattern)},\n path: ${JSON.stringify(route.path)},\n segments: ${JSON.stringify(route.segments)},\n params: ${JSON.stringify(route.params)},\n imports: ${imports},\n children: [],\n metadata: ${metadata}\n }`;\n}\n\n/**\n * Generate imports object for a route\n */\nfunction generateRouteImports(\n route: RouteNode,\n importMap: Map<string, string>\n): string {\n const importEntries: string[] = [];\n\n // Generate import entries based on what imports exist\n for (const [type] of Object.entries(route.imports)) {\n // Build the correct import path relative to the virtual module location\n const segments = route.segments.length > 0 ? route.segments : [];\n let importPath = '/src/routes';\n\n if (segments.length > 0) {\n // Convert segments back to file system format (keep route groups for file paths)\n const fileSegments = segments.map((segment: string) => {\n if (segment.startsWith(':')) {\n return `[${segment.slice(1)}]`; // :id -> [id]\n }\n if (segment === '*') {\n return '[...slug]'; // * -> [...slug]\n }\n return segment; // Keep route groups like (mkt) for file paths\n });\n\n if (fileSegments.length > 0) {\n importPath += '/' + fileSegments.join('/');\n }\n }\n\n const fullPath = `${importPath}/${filenameFor(type)}`;\n\n // Use the generated import constant if available\n const importName = importMap.get(fullPath);\n if (importName) {\n importEntries.push(`${type}: ${importName}`);\n } else {\n // Fallback to inline import\n importEntries.push(`${type}: () => import(\"${fullPath}\")`);\n }\n }\n\n return `{\\n ${importEntries.join(',\\n ')}\\n }`;\n}\n\n/**\n * Generate CLI command output for route tree inspection\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.manifest\",\"name\":\"generateCliOutput\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string\"} */\nexport function generateCliOutput(routes: RouteNode[]): string {\n const lines: string[] = [];\n lines.push('📁 Route Tree:');\n lines.push('');\n\n for (const route of routes) {\n lines.push(`🔗 ${route.pattern}`);\n lines.push(` ID: ${route.id}`);\n lines.push(` Files: ${Object.keys(route.imports).join(', ')}`);\n\n if (route.metadata?.isGroup) {\n lines.push(' 🏷️ Uses route groups');\n }\n\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Validate generated manifest for common issues\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.manifest\",\"name\":\"validateManifest\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string[]\"} */\nexport function validateManifest(routes: RouteNode[]): string[] {\n const errors: string[] = [];\n const patterns = new Set<string>();\n const ids = new Set<string>();\n\n for (const route of routes) {\n // Check for duplicate patterns\n if (patterns.has(route.pattern)) {\n errors.push(`Duplicate route pattern: ${route.pattern}`);\n }\n patterns.add(route.pattern);\n\n // Check for duplicate IDs\n if (ids.has(route.id)) {\n errors.push(`Duplicate route ID: ${route.id}`);\n }\n ids.add(route.id);\n\n // Validate required page import\n if (!route.imports.page) {\n errors.push(`Route ${route.pattern} missing required page component`);\n }\n\n // Validate file paths exist (basic check)\n if (!route.path) {\n errors.push(`Route ${route.pattern} missing file path`);\n }\n }\n\n return errors;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/routerPlugin/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,GAAG,IAAI,KAAK,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,4JAA4J;AAC5J,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC;SAC3B,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,SAAS,IAAI,oBAAoB,QAAQ,KAAK,CAAC;SACzE,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAE7D,MAAM,QAAQ,GAAG;mBACA,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;;EAEzC,OAA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;QAC1C,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite-plugin-router.manifest\",\n \"title\": \"Route Manifest Generator\",\n \"category\": \"compiler\",\n \"description\": \"Generates typed TypeScript route manifests and CLI-formatted route tables from a route tree.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"manifest.test.ts\" },\n \"integration\": { \"required\": false, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { RouteNode } from '@pithyjs/router';\nimport { allRouteNodes } from './scanner';\n\n/**\n * Helper function to get correct filename for route file types\n */\nfunction filenameFor(type: string): string {\n return `${type}.ts`;\n}\n\n/**\n * Generate TypeScript code for the route manifest\n * Creates virtual:pithy/routes.gen module with typed RouteNode tree\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.manifest\",\"name\":\"generateManifest\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string\"} */\nexport function generateManifest(routes: RouteNode[]): string {\n const importMap = buildImportMap(routes);\n const imports = [...importMap]\n .map(([fullPath, name]) => `const ${name} = () => import(\"${fullPath}\");`)\n .join('\\n');\n\n const routeTree = generateRouteList(routes, importMap, ' ');\n\n const manifest = `// Auto-generated route manifest - do not edit manually\n// Generated at: ${new Date().toISOString()}\n\n${imports || '// No imports needed'}\n\n/** @typedef {import(\"../../router/src/types\").RouteNode} RouteNode */\n/** @type {Array<RouteNode>} */\nexport const routes = ${routeTree};\n\n// For TS consumers that import types:\nexport {};\n`;\n\n return manifest;\n}\n\n/**\n * Module path of one of a route's files, relative to the virtual module\n * (route groups and bracketed segments are kept: they are directory names).\n */\nfunction importPathFor(route: RouteNode, type: string): string {\n const fileSegments = route.segments.map((segment: string) => {\n if (segment.startsWith(':')) {\n return `[${segment.slice(1)}]`; // :id -> [id]\n }\n if (segment === '*') {\n return '[...slug]'; // * -> [...slug]\n }\n return segment;\n });\n const dir = ['/src/routes', ...fileSegments].join('/');\n return `${dir}/${filenameFor(type)}`;\n}\n\n/** One import name per route file, in tree order. */\nfunction buildImportMap(routes: RouteNode[]): Map<string, string> {\n const importMap = new Map<string, string>();\n for (const route of allRouteNodes(routes)) {\n for (const type of Object.keys(route.imports)) {\n const fullPath = importPathFor(route, type);\n if (!importMap.has(fullPath)) {\n importMap.set(fullPath, `route_${importMap.size}_${type}`);\n }\n }\n }\n return importMap;\n}\n\nfunction generateRouteList(\n routes: RouteNode[],\n importMap: Map<string, string>,\n indent: string\n): string {\n if (routes.length === 0) return '[]';\n const routeObjects = routes.map(\n route => `${indent}${generateRouteObject(route, importMap, indent)}`\n );\n return `[\\n${routeObjects.join(',\\n')}\\n${indent.slice(2)}]`;\n}\n\n/**\n * Generate a single route object\n */\nfunction generateRouteObject(\n route: RouteNode,\n importMap: Map<string, string>,\n indent: string\n): string {\n const imports = generateRouteImports(route, importMap);\n const metadata = route.metadata\n ? JSON.stringify(route.metadata, null, 2)\n : '{}';\n const children = generateRouteList(\n route.children ?? [],\n importMap,\n `${indent} `\n );\n\n return `{\n id: ${JSON.stringify(route.id)},\n pattern: ${JSON.stringify(route.pattern)},\n path: ${JSON.stringify(route.path)},\n segments: ${JSON.stringify(route.segments)},\n params: ${JSON.stringify(route.params)},\n imports: ${imports},\n children: ${children},\n metadata: ${metadata}\n }`;\n}\n\n/**\n * Generate imports object for a route\n */\nfunction generateRouteImports(\n route: RouteNode,\n importMap: Map<string, string>\n): string {\n const importEntries = Object.keys(route.imports).map(type => {\n const fullPath = importPathFor(route, type);\n const importName = importMap.get(fullPath);\n return importName\n ? `${type}: ${importName}`\n : `${type}: () => import(\"${fullPath}\")`;\n });\n\n return `{\\n ${importEntries.join(',\\n ')}\\n }`;\n}\n\n/**\n * Generate CLI command output for route tree inspection\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.manifest\",\"name\":\"generateCliOutput\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string\"} */\nexport function generateCliOutput(routes: RouteNode[]): string {\n const lines: string[] = [];\n lines.push('📁 Route Tree:');\n lines.push('');\n\n for (const route of allRouteNodes(routes)) {\n lines.push(`🔗 ${route.pattern}${route.imports.page ? '' : ' (layout)'}`);\n lines.push(` ID: ${route.id}`);\n lines.push(` Files: ${Object.keys(route.imports).join(', ')}`);\n\n if (route.metadata?.isGroup) {\n lines.push(' 🏷️ Uses route groups');\n }\n\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Validate generated manifest for common issues\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.manifest\",\"name\":\"validateManifest\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string[]\"} */\nexport function validateManifest(routes: RouteNode[]): string[] {\n const errors: string[] = [];\n const patterns = new Set<string>();\n const ids = new Set<string>();\n\n for (const route of allRouteNodes(routes)) {\n // Check for duplicate IDs\n if (ids.has(route.id)) {\n errors.push(`Duplicate route ID: ${route.id}`);\n }\n ids.add(route.id);\n\n // A layout-only node shares its URL with the routes it wraps\n if (route.imports.layout && !route.imports.page && route.children.length) {\n continue;\n }\n\n // Check for duplicate patterns\n if (patterns.has(route.pattern)) {\n errors.push(`Duplicate route pattern: ${route.pattern}`);\n }\n patterns.add(route.pattern);\n\n // Validate required page import\n if (!route.imports.page) {\n errors.push(`Route ${route.pattern} missing required page component`);\n }\n\n // Validate file paths exist (basic check)\n if (!route.path) {\n errors.push(`Route ${route.pattern} missing file path`);\n }\n }\n\n return errors;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAcnC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,gCAAgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,mKAAmK;AACnK,wBAAgB,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAsK1E"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
*/
|
|
16
16
|
import { join } from 'path';
|
|
17
|
-
import { scanRoutes, buildRouteTree, validateRoutes } from './scanner.js';
|
|
17
|
+
import { scanRoutes, buildRouteTree, validateRoutes, routeWarnings, } from './scanner.js';
|
|
18
18
|
import { generateManifest, generateCliOutput, validateManifest, } from './manifest.js';
|
|
19
19
|
/**
|
|
20
20
|
* Vite plugin for PithyJS file-based routing.
|
|
@@ -67,6 +67,9 @@ export function pithyRouter(options = {}) {
|
|
|
67
67
|
throw new Error(`Route validation failed: ${allErrors.join(', ')}`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
for (const warning of routeWarnings(routes)) {
|
|
71
|
+
console.warn(`[pithy-router] ${warning}`);
|
|
72
|
+
}
|
|
70
73
|
// Generate manifest
|
|
71
74
|
cachedManifest = generateManifest(routes);
|
|
72
75
|
if (debug) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","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oBAC1D,CAAC;oBAED,cAAc,GAAG,IAAI,CAAC;oBAEtB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAC7C,0BAA0B,CAC3B,CAAC;oBACF,IAAI,MAAM,EAAE,CAAC;wBACX,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;gBACvC,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACvC,IAAI,KAAK,EAAE,CAAC;wBACV,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;oBAC5D,CAAC;oBAED,cAAc,GAAG,IAAI,CAAC;oBAEtB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAC7C,0BAA0B,CAC3B,CAAC;oBACF,IAAI,MAAM,EAAE,CAAC;wBACX,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite-plugin-router\",\n \"title\": \"Vite Plugin for PithyJS Router\",\n \"category\": \"plugin\",\n \"description\": \"File-based routing plugin that scans a routes directory and generates a typed route manifest as a virtual module.\",\n \"since\": \"0.0.1\",\n \"stability\": \"experimental\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"plugin.test.ts\" },\n \"integration\": { \"required\": true, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { Plugin } from 'vite';\nimport { join } from 'path';\nimport { scanRoutes, buildRouteTree, validateRoutes } from './scanner';\nimport {\n generateManifest,\n generateCliOutput,\n validateManifest,\n} from './manifest';\n\n/**\n * Vite plugin options\n */\nexport interface PithyRouterPluginOptions {\n /** Routes directory relative to project root */\n routesDir?: string;\n /** File extensions to scan */\n extensions?: string[];\n /** Enable TypeScript support */\n typescript?: boolean;\n /** Enable debug logging */\n debug?: boolean;\n}\n\n/**\n * Vite plugin for PithyJS file-based routing.\n *\n * Scans a routes directory for `page`, `layout`, `loading`, `error`,\n * `loader`, and `config` files, then generates a typed route manifest\n * exposed as the `virtual:pithy/routes.gen` virtual module.\n *\n * @param options - Plugin configuration for routes directory, extensions, and debug mode\n * @returns A Vite plugin that provides file-based route generation\n *\n * @example\n * ```ts\n * import { pithyRouter } from '@pithyjs/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [pithyRouter({ routesDir: 'src/routes' })],\n * });\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router\",\"name\":\"pithyRouter\",\"stability\":\"experimental\",\"signature\":\"(options?: PithyRouterPluginOptions) => Plugin\"} */\nexport function pithyRouter(options: PithyRouterPluginOptions = {}): Plugin {\n const {\n routesDir = 'src/routes',\n extensions = ['ts', 'js'],\n typescript = true,\n debug = false,\n } = options;\n\n let resolvedRoutesDir: string;\n let cachedManifest: string | null = null;\n\n // Helper function to generate route manifest\n async function generateRouteManifest() {\n try {\n // Scan routes directory\n const routeFiles = await scanRoutes({\n routesDir: resolvedRoutesDir,\n extensions,\n typescript,\n });\n\n if (debug) {\n console.log(`[pithy-router] Found ${routeFiles.length} route files`);\n }\n\n // Build route tree\n const routes = buildRouteTree(routeFiles);\n\n // Validate routes\n const routeErrors = validateRoutes(routes);\n const manifestErrors = validateManifest(routes);\n const allErrors = [...routeErrors, ...manifestErrors];\n\n if (allErrors.length > 0) {\n console.error('[pithy-router] Route validation errors:');\n allErrors.forEach(error => console.error(` - ${error}`));\n\n // In development, continue with warnings\n // In production, this might throw\n if (process.env.NODE_ENV === 'production') {\n throw new Error(`Route validation failed: ${allErrors.join(', ')}`);\n }\n }\n\n // Generate manifest\n cachedManifest = generateManifest(routes);\n\n if (debug) {\n console.log('[pithy-router] Generated route tree:');\n console.log(generateCliOutput(routes));\n }\n\n return cachedManifest;\n } catch (error) {\n console.error('[pithy-router] Failed to generate route manifest:', error);\n\n // Return empty manifest as fallback\n cachedManifest = `\n // Route generation failed - fallback manifest\n export const routes = [];\n export type RouteManifest = typeof routes;\n `;\n\n return cachedManifest;\n }\n }\n\n return {\n name: 'pithy-router',\n\n configResolved(config) {\n // Resolve routes directory relative to project root\n resolvedRoutesDir = join(config.root, routesDir);\n\n if (debug) {\n console.log(`[pithy-router] Routes directory: ${resolvedRoutesDir}`);\n }\n },\n\n async buildStart() {\n // Initial route scanning and validation\n await generateRouteManifest();\n },\n\n resolveId(id) {\n // Handle virtual module imports\n if (id === 'virtual:pithy/routes.gen') {\n return id;\n }\n return null;\n },\n\n async load(id) {\n // Serve the generated route manifest\n if (id === 'virtual:pithy/routes.gen') {\n if (!cachedManifest) {\n await generateRouteManifest();\n }\n return cachedManifest;\n }\n return null;\n },\n\n // Watch for route file changes in development\n configureServer(server) {\n // Watch routes directory for changes\n server.watcher.add(resolvedRoutesDir);\n\n server.watcher.on('change', async file => {\n if (file.startsWith(resolvedRoutesDir)) {\n if (debug) {\n console.log(`[pithy-router] Route file changed: ${file}`);\n }\n\n // Invalidate cached manifest\n cachedManifest = null;\n\n // Trigger HMR for the virtual module\n const module = server.moduleGraph.getModuleById(\n 'virtual:pithy/routes.gen'\n );\n if (module) {\n server.reloadModule(module);\n }\n }\n });\n\n server.watcher.on('add', async file => {\n if (file.startsWith(resolvedRoutesDir)) {\n if (debug) {\n console.log(`[pithy-router] Route file added: ${file}`);\n }\n\n cachedManifest = null;\n\n const module = server.moduleGraph.getModuleById(\n 'virtual:pithy/routes.gen'\n );\n if (module) {\n server.reloadModule(module);\n }\n }\n });\n\n server.watcher.on('unlink', async file => {\n if (file.startsWith(resolvedRoutesDir)) {\n if (debug) {\n console.log(`[pithy-router] Route file removed: ${file}`);\n }\n\n cachedManifest = null;\n\n const module = server.moduleGraph.getModuleById(\n 'virtual:pithy/routes.gen'\n );\n if (module) {\n server.reloadModule(module);\n }\n }\n });\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/routerPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAgBpB;;;;;;;;;;;;;;;;;;GAkBG;AACH,mKAAmK;AACnK,MAAM,UAAU,WAAW,CAAC,UAAoC,EAAE;IAChE,MAAM,EACJ,SAAS,GAAG,YAAY,EACxB,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,EACzB,UAAU,GAAG,IAAI,EACjB,KAAK,GAAG,KAAK,GACd,GAAG,OAAO,CAAC;IAEZ,IAAI,iBAAyB,CAAC;IAC9B,IAAI,cAAc,GAAkB,IAAI,CAAC;IAEzC,6CAA6C;IAC7C,KAAK,UAAU,qBAAqB;QAClC,IAAI,CAAC;YACH,wBAAwB;YACxB,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC;gBAClC,SAAS,EAAE,iBAAiB;gBAC5B,UAAU;gBACV,UAAU;aACX,CAAC,CAAC;YAEH,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,GAAG,CAAC,wBAAwB,UAAU,CAAC,MAAM,cAAc,CAAC,CAAC;YACvE,CAAC;YAED,mBAAmB;YACnB,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;YAE1C,kBAAkB;YAClB,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;YAC3C,MAAM,cAAc,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC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,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;gBACpC,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACvC,IAAI,KAAK,EAAE,CAAC;wBACV,OAAO,CAAC,GAAG,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAC;oBAC1D,CAAC;oBAED,cAAc,GAAG,IAAI,CAAC;oBAEtB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAC7C,0BAA0B,CAC3B,CAAC;oBACF,IAAI,MAAM,EAAE,CAAC;wBACX,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;gBACvC,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACvC,IAAI,KAAK,EAAE,CAAC;wBACV,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;oBAC5D,CAAC;oBAED,cAAc,GAAG,IAAI,CAAC;oBAEtB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAC7C,0BAA0B,CAC3B,CAAC;oBACF,IAAI,MAAM,EAAE,CAAC;wBACX,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite-plugin-router\",\n \"title\": \"Vite Plugin for PithyJS Router\",\n \"category\": \"plugin\",\n \"description\": \"File-based routing plugin that scans a routes directory and generates a typed route manifest as a virtual module.\",\n \"since\": \"0.0.1\",\n \"stability\": \"experimental\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"plugin.test.ts\" },\n \"integration\": { \"required\": true, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { Plugin } from 'vite';\nimport { join } from 'path';\nimport {\n scanRoutes,\n buildRouteTree,\n validateRoutes,\n routeWarnings,\n} from './scanner';\nimport {\n generateManifest,\n generateCliOutput,\n validateManifest,\n} from './manifest';\n\n/**\n * Vite plugin options\n */\nexport interface PithyRouterPluginOptions {\n /** Routes directory relative to project root */\n routesDir?: string;\n /** File extensions to scan */\n extensions?: string[];\n /** Enable TypeScript support */\n typescript?: boolean;\n /** Enable debug logging */\n debug?: boolean;\n}\n\n/**\n * Vite plugin for PithyJS file-based routing.\n *\n * Scans a routes directory for `page`, `layout`, `loading`, `error`,\n * `loader`, and `config` files, then generates a typed route manifest\n * exposed as the `virtual:pithy/routes.gen` virtual module.\n *\n * @param options - Plugin configuration for routes directory, extensions, and debug mode\n * @returns A Vite plugin that provides file-based route generation\n *\n * @example\n * ```ts\n * import { pithyRouter } from '@pithyjs/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [pithyRouter({ routesDir: 'src/routes' })],\n * });\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router\",\"name\":\"pithyRouter\",\"stability\":\"experimental\",\"signature\":\"(options?: PithyRouterPluginOptions) => Plugin\"} */\nexport function pithyRouter(options: PithyRouterPluginOptions = {}): Plugin {\n const {\n routesDir = 'src/routes',\n extensions = ['ts', 'js'],\n typescript = true,\n debug = false,\n } = options;\n\n let resolvedRoutesDir: string;\n let cachedManifest: string | null = null;\n\n // Helper function to generate route manifest\n async function generateRouteManifest() {\n try {\n // Scan routes directory\n const routeFiles = await scanRoutes({\n routesDir: resolvedRoutesDir,\n extensions,\n typescript,\n });\n\n if (debug) {\n console.log(`[pithy-router] Found ${routeFiles.length} route files`);\n }\n\n // Build route tree\n const routes = buildRouteTree(routeFiles);\n\n // Validate routes\n const routeErrors = validateRoutes(routes);\n const manifestErrors = validateManifest(routes);\n const allErrors = [...routeErrors, ...manifestErrors];\n\n if (allErrors.length > 0) {\n console.error('[pithy-router] Route validation errors:');\n allErrors.forEach(error => console.error(` - ${error}`));\n\n // In development, continue with warnings\n // In production, this might throw\n if (process.env.NODE_ENV === 'production') {\n throw new Error(`Route validation failed: ${allErrors.join(', ')}`);\n }\n }\n\n for (const warning of routeWarnings(routes)) {\n console.warn(`[pithy-router] ${warning}`);\n }\n\n // Generate manifest\n cachedManifest = generateManifest(routes);\n\n if (debug) {\n console.log('[pithy-router] Generated route tree:');\n console.log(generateCliOutput(routes));\n }\n\n return cachedManifest;\n } catch (error) {\n console.error('[pithy-router] Failed to generate route manifest:', error);\n\n // Return empty manifest as fallback\n cachedManifest = `\n // Route generation failed - fallback manifest\n export const routes = [];\n export type RouteManifest = typeof routes;\n `;\n\n return cachedManifest;\n }\n }\n\n return {\n name: 'pithy-router',\n\n configResolved(config) {\n // Resolve routes directory relative to project root\n resolvedRoutesDir = join(config.root, routesDir);\n\n if (debug) {\n console.log(`[pithy-router] Routes directory: ${resolvedRoutesDir}`);\n }\n },\n\n async buildStart() {\n // Initial route scanning and validation\n await generateRouteManifest();\n },\n\n resolveId(id) {\n // Handle virtual module imports\n if (id === 'virtual:pithy/routes.gen') {\n return id;\n }\n return null;\n },\n\n async load(id) {\n // Serve the generated route manifest\n if (id === 'virtual:pithy/routes.gen') {\n if (!cachedManifest) {\n await generateRouteManifest();\n }\n return cachedManifest;\n }\n return null;\n },\n\n // Watch for route file changes in development\n configureServer(server) {\n // Watch routes directory for changes\n server.watcher.add(resolvedRoutesDir);\n\n server.watcher.on('change', async file => {\n if (file.startsWith(resolvedRoutesDir)) {\n if (debug) {\n console.log(`[pithy-router] Route file changed: ${file}`);\n }\n\n // Invalidate cached manifest\n cachedManifest = null;\n\n // Trigger HMR for the virtual module\n const module = server.moduleGraph.getModuleById(\n 'virtual:pithy/routes.gen'\n );\n if (module) {\n server.reloadModule(module);\n }\n }\n });\n\n server.watcher.on('add', async file => {\n if (file.startsWith(resolvedRoutesDir)) {\n if (debug) {\n console.log(`[pithy-router] Route file added: ${file}`);\n }\n\n cachedManifest = null;\n\n const module = server.moduleGraph.getModuleById(\n 'virtual:pithy/routes.gen'\n );\n if (module) {\n server.reloadModule(module);\n }\n }\n });\n\n server.watcher.on('unlink', async file => {\n if (file.startsWith(resolvedRoutesDir)) {\n if (debug) {\n console.log(`[pithy-router] Route file removed: ${file}`);\n }\n\n cachedManifest = null;\n\n const module = server.moduleGraph.getModuleById(\n 'virtual:pithy/routes.gen'\n );\n if (module) {\n server.reloadModule(module);\n }\n }\n });\n },\n };\n}\n"]}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
*/
|
|
16
|
-
import { RouteNode } from '@pithyjs/router';
|
|
16
|
+
import type { RouteNode } from '@pithyjs/router';
|
|
17
17
|
/**
|
|
18
18
|
* Route file types that can be discovered
|
|
19
19
|
*/
|
|
@@ -57,10 +57,25 @@ export declare function parseRouteFile(filePath: string, routesDir: string): Rou
|
|
|
57
57
|
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"buildRoutePattern","stability":"stable","signature":"(dirPath: string) => string"} */
|
|
58
58
|
export declare function buildRoutePattern(dirPath: string): string;
|
|
59
59
|
/**
|
|
60
|
-
* Build route tree from discovered route files
|
|
60
|
+
* Build the route tree from discovered route files: one node per directory
|
|
61
|
+
* holding a page or a layout. Below a layout, each node nests under its
|
|
62
|
+
* nearest ancestor directory with a node, so a page-only ancestor stays in
|
|
63
|
+
* the lineage its `error.ts` covers. Outside every layout the tree stays
|
|
64
|
+
* flat. A layout that wraps no page is dropped.
|
|
61
65
|
*/
|
|
62
66
|
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"buildRouteTree","stability":"stable","signature":"(routeFiles: RouteFile[]) => RouteNode[]"} */
|
|
63
67
|
export declare function buildRouteTree(routeFiles: RouteFile[]): RouteNode[];
|
|
68
|
+
/**
|
|
69
|
+
* Every node of a route tree, parents before their children.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
export declare function allRouteNodes(routes: RouteNode[]): RouteNode[];
|
|
73
|
+
/**
|
|
74
|
+
* Files the router never runs: guards (`config`) and loaders run for the
|
|
75
|
+
* matched leaf route only, so beside a layout with no page they are dead.
|
|
76
|
+
*/
|
|
77
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"routeWarnings","stability":"experimental","signature":"(routes: RouteNode[]) => string[]"} */
|
|
78
|
+
export declare function routeWarnings(routes: RouteNode[]): string[];
|
|
64
79
|
/**
|
|
65
80
|
* Validate route tree for conflicts and issues
|
|
66
81
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpE,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,qKAAqK;AACrK,wBAAsB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAgC5E;AAED;;GAEG;AACH,mLAAmL;AACnL,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,SAAS,GAAG,IAAI,CA4BlB;AA2BD;;;GAGG;AACH,wJAAwJ;AACxJ,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAqCzD;AAED;;;;;;GAMG;AACH,kKAAkK;AAClK,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAgBnE;AA8KD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAE9D;AAED;;;GAGG;AACH,gKAAgK;AAChK,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CAc3D;AAED;;GAEG;AACH,2JAA2J;AAC3J,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CAgC5D"}
|
|
@@ -141,46 +141,50 @@ export function buildRoutePattern(dirPath) {
|
|
|
141
141
|
return pattern === '/' ? '/' : pattern.replace(/\/$/, ''); // Remove trailing slash except for root
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
* Build route tree from discovered route files
|
|
144
|
+
* Build the route tree from discovered route files: one node per directory
|
|
145
|
+
* holding a page or a layout. Below a layout, each node nests under its
|
|
146
|
+
* nearest ancestor directory with a node, so a page-only ancestor stays in
|
|
147
|
+
* the lineage its `error.ts` covers. Outside every layout the tree stays
|
|
148
|
+
* flat. A layout that wraps no page is dropped.
|
|
145
149
|
*/
|
|
146
150
|
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"buildRouteTree","stability":"stable","signature":"(routeFiles: RouteFile[]) => RouteNode[]"} */
|
|
147
151
|
export function buildRouteTree(routeFiles) {
|
|
148
|
-
|
|
149
|
-
const routeMap = new Map();
|
|
152
|
+
const filesByDir = new Map();
|
|
150
153
|
for (const file of routeFiles) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
const dir = file.segments.join('/');
|
|
155
|
+
const files = filesByDir.get(dir) ?? [];
|
|
156
|
+
files.push(file);
|
|
157
|
+
filesByDir.set(dir, files);
|
|
154
158
|
}
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
routes.push(routeNode);
|
|
161
|
-
}
|
|
159
|
+
const nodesByDir = new Map();
|
|
160
|
+
for (const [dir, files] of filesByDir) {
|
|
161
|
+
const routeNode = files[0] && createRouteNode(files[0].pattern, files);
|
|
162
|
+
if (routeNode)
|
|
163
|
+
nodesByDir.set(dir, routeNode);
|
|
162
164
|
}
|
|
163
|
-
|
|
164
|
-
routes.sort((a, b) => a.pattern.localeCompare(b.pattern));
|
|
165
|
-
// Build nested structure
|
|
166
|
-
return buildNestedRoutes(routes);
|
|
165
|
+
return buildNestedRoutes(nodesByDir);
|
|
167
166
|
}
|
|
168
167
|
/**
|
|
169
|
-
* Create a route node from
|
|
168
|
+
* Create a route node from the files of one directory. A directory needs a
|
|
169
|
+
* page (a navigable route) or a layout (a wrapper for the routes below it).
|
|
170
170
|
*/
|
|
171
171
|
function createRouteNode(pattern, files) {
|
|
172
|
-
// Find the page file (required for a valid route)
|
|
173
172
|
const pageFile = files.find(f => f.type === 'page');
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
const ownFile = pageFile ?? files.find(f => f.type === 'layout');
|
|
174
|
+
if (!ownFile) {
|
|
176
175
|
return null;
|
|
177
176
|
}
|
|
178
|
-
//
|
|
179
|
-
|
|
177
|
+
// A layout-only node is named after its directory: a route group shares
|
|
178
|
+
// its URL pattern (and so the pattern-derived id) with other directories.
|
|
179
|
+
const routeId = pageFile
|
|
180
|
+
? pattern === '/'
|
|
181
|
+
? 'root'
|
|
182
|
+
: pattern.replace(/^\//, '').replace(/\//g, '.')
|
|
183
|
+
: ownFile.segments.join('.') || 'root';
|
|
180
184
|
// Build imports object
|
|
181
185
|
const imports = {};
|
|
182
186
|
// Use the original file system segments (including route groups)
|
|
183
|
-
const segments =
|
|
187
|
+
const segments = ownFile.segments;
|
|
184
188
|
const params = [];
|
|
185
189
|
// Process pattern segments to extract parameter names
|
|
186
190
|
const patternSegments = pattern === '/' ? [] : pattern.split('/').filter(Boolean);
|
|
@@ -235,7 +239,7 @@ function createRouteNode(pattern, files) {
|
|
|
235
239
|
return {
|
|
236
240
|
id: routeId,
|
|
237
241
|
pattern,
|
|
238
|
-
path:
|
|
242
|
+
path: ownFile.path,
|
|
239
243
|
segments,
|
|
240
244
|
params,
|
|
241
245
|
imports,
|
|
@@ -254,11 +258,81 @@ function createRouteNode(pattern, files) {
|
|
|
254
258
|
};
|
|
255
259
|
}
|
|
256
260
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
261
|
+
* Attach every node below a layout to its nearest ancestor node, then drop
|
|
262
|
+
* layout-only nodes left with nothing to wrap.
|
|
263
|
+
*/
|
|
264
|
+
function buildNestedRoutes(nodesByDir) {
|
|
265
|
+
const pageIds = new Set([...nodesByDir.values()].filter(n => n.imports.page).map(n => n.id));
|
|
266
|
+
for (const [dir, node] of nodesByDir) {
|
|
267
|
+
if (!node.imports.page && pageIds.has(node.id)) {
|
|
268
|
+
node.id = `layout:${dir || 'root'}`;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const roots = [];
|
|
272
|
+
for (const [dir, node] of nodesByDir) {
|
|
273
|
+
const parent = nearestLayoutAncestor(dir, nodesByDir)
|
|
274
|
+
? nearestAncestor(dir, nodesByDir)
|
|
275
|
+
: null;
|
|
276
|
+
(parent ? parent.children : roots).push(node);
|
|
277
|
+
}
|
|
278
|
+
return pruneAndSort(roots);
|
|
279
|
+
}
|
|
280
|
+
function nearestLayoutAncestor(dir, nodesByDir) {
|
|
281
|
+
const parts = dir ? dir.split('/') : [];
|
|
282
|
+
while (parts.length > 0) {
|
|
283
|
+
parts.pop();
|
|
284
|
+
const ancestor = nodesByDir.get(parts.join('/'));
|
|
285
|
+
if (ancestor?.imports.layout)
|
|
286
|
+
return ancestor;
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The node of the nearest ancestor directory. A page-only ancestor renders no
|
|
292
|
+
* segment, but its error boundary covers the routes below it.
|
|
293
|
+
*/
|
|
294
|
+
function nearestAncestor(dir, nodesByDir) {
|
|
295
|
+
const parts = dir ? dir.split('/') : [];
|
|
296
|
+
while (parts.length > 0) {
|
|
297
|
+
parts.pop();
|
|
298
|
+
const ancestor = nodesByDir.get(parts.join('/'));
|
|
299
|
+
if (ancestor)
|
|
300
|
+
return ancestor;
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
function pruneAndSort(nodes) {
|
|
305
|
+
const kept = [];
|
|
306
|
+
for (const node of nodes) {
|
|
307
|
+
node.children = pruneAndSort(node.children);
|
|
308
|
+
if (node.imports.page || node.children.length > 0)
|
|
309
|
+
kept.push(node);
|
|
310
|
+
}
|
|
311
|
+
return kept.sort((a, b) => a.pattern.localeCompare(b.pattern) || a.id.localeCompare(b.id));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Every node of a route tree, parents before their children.
|
|
315
|
+
* @internal
|
|
259
316
|
*/
|
|
260
|
-
function
|
|
261
|
-
return routes;
|
|
317
|
+
export function allRouteNodes(routes) {
|
|
318
|
+
return routes.flatMap(route => [route, ...allRouteNodes(route.children)]);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Files the router never runs: guards (`config`) and loaders run for the
|
|
322
|
+
* matched leaf route only, so beside a layout with no page they are dead.
|
|
323
|
+
*/
|
|
324
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"routeWarnings","stability":"experimental","signature":"(routes: RouteNode[]) => string[]"} */
|
|
325
|
+
export function routeWarnings(routes) {
|
|
326
|
+
const warnings = [];
|
|
327
|
+
for (const route of allRouteNodes(routes)) {
|
|
328
|
+
if (route.imports.page)
|
|
329
|
+
continue;
|
|
330
|
+
const dead = ['loader', 'config'].filter(type => route.imports[type]);
|
|
331
|
+
if (dead.length > 0) {
|
|
332
|
+
warnings.push(`${route.path}: ${dead.join(', ')} beside a layout with no page never run (guards and loaders run for the matched page route only)`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return warnings;
|
|
262
336
|
}
|
|
263
337
|
/**
|
|
264
338
|
* Validate route tree for conflicts and issues
|
|
@@ -267,7 +341,10 @@ function buildNestedRoutes(routes) {
|
|
|
267
341
|
export function validateRoutes(routes) {
|
|
268
342
|
const errors = [];
|
|
269
343
|
const patterns = new Set();
|
|
270
|
-
for (const route of routes) {
|
|
344
|
+
for (const route of allRouteNodes(routes)) {
|
|
345
|
+
// A layout-only node shares its URL with the routes it wraps
|
|
346
|
+
if (!route.imports.page)
|
|
347
|
+
continue;
|
|
271
348
|
// Check for duplicate patterns
|
|
272
349
|
if (patterns.has(route.pattern)) {
|
|
273
350
|
errors.push(`Duplicate route pattern: ${route.pattern}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/routerPlugin/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA8B5B;;GAEG;AACH,qKAAqK;AACrK,MAAM,CAAC,K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YAC/D,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC1C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,IACE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;oBACrB,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC;oBAC9B,CAAC,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,EACpC,CAAC;oBACD,MAAM,CAAC,IAAI,CACT,8BAA8B,KAAK,CAAC,OAAO,KAAK,OAAO,EAAE,CAC1D,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite-plugin-router.scanner\",\n \"title\": \"Route File System Scanner\",\n \"category\": \"compiler\",\n \"description\": \"Scans the file system for route files and builds a route tree with dynamic segments, catch-all routes, and route groups.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"scanner.test.ts\" },\n \"integration\": { \"required\": false, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport glob from 'fast-glob';\nimport { RouteNode } from '@pithyjs/router';\nimport { join } from 'path';\n\n/**\n * Route file types that can be discovered\n */\nexport interface RouteFile {\n /** File path relative to routes directory */\n path: string;\n /** Absolute file path */\n absolutePath: string;\n /** Route type (page, layout, error, loading, loader, config) */\n type: 'page' | 'layout' | 'error' | 'loading' | 'loader' | 'config';\n /** Route pattern derived from file path */\n pattern: string;\n /** Route segments */\n segments: string[];\n}\n\n/**\n * Scanner configuration options\n */\nexport interface ScannerConfig {\n /** Routes directory path */\n routesDir: string;\n /** File extensions to scan */\n extensions?: string[];\n /** Whether to include TypeScript files */\n typescript?: boolean;\n}\n\n/**\n * Scan the routes directory and discover route files\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"scanRoutes\",\"stability\":\"stable\",\"signature\":\"(config: ScannerConfig) => Promise<RouteFile[]>\"} */\nexport async function scanRoutes(config: ScannerConfig): Promise<RouteFile[]> {\n const { routesDir, extensions = ['ts', 'js'], typescript = true } = config;\n\n // Build glob patterns for route files\n const fileExtensions = typescript ? [...extensions, 'ts'] : extensions;\n const patterns = [\n `**/{page,layout,error,loading,loader,config}.{${fileExtensions.join(',')}}`,\n ];\n\n try {\n // Scan for route files\n const files = await glob(patterns, {\n cwd: routesDir,\n absolute: false,\n onlyFiles: true,\n });\n\n // Process discovered files\n const routeFiles: RouteFile[] = [];\n\n for (const file of files) {\n const routeFile = parseRouteFile(file, routesDir);\n if (routeFile) {\n routeFiles.push(routeFile);\n }\n }\n\n return routeFiles;\n } catch (error) {\n console.error('Failed to scan routes directory:', error);\n return [];\n }\n}\n\n/**\n * Parse a route file path into route information\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"parseRouteFile\",\"stability\":\"stable\",\"signature\":\"(filePath: string, routesDir: string) => RouteFile | null\"} */\nexport function parseRouteFile(\n filePath: string,\n routesDir: string\n): RouteFile | null {\n // Normalize path separators\n const normalizedPath = filePath.replace(/\\\\/g, '/');\n\n // Extract file name and directory\n const pathParts = normalizedPath.split('/');\n const fileName = pathParts[pathParts.length - 1];\n const dirPath = pathParts.slice(0, -1).join('/');\n\n // Determine route type from filename\n const routeType = getRouteType(fileName);\n if (!routeType) {\n return null;\n }\n\n // Build route pattern from directory structure\n const pattern = buildRoutePattern(dirPath);\n\n // Extract route segments\n const segments = dirPath ? dirPath.split('/') : [];\n\n return {\n path: normalizedPath,\n absolutePath: join(routesDir, filePath),\n type: routeType,\n pattern,\n segments,\n };\n}\n\n/**\n * Determine route type from filename\n */\nfunction getRouteType(fileName: string): RouteFile['type'] | null {\n // Remove extension\n const baseName = fileName.replace(/\\.(ts|js)$/, '');\n\n switch (baseName) {\n case 'page':\n return 'page';\n case 'layout':\n return 'layout';\n case 'error':\n return 'error';\n case 'loading':\n return 'loading';\n case 'loader':\n return 'loader';\n case 'config':\n return 'config';\n default:\n return null;\n }\n}\n\n/**\n * Build route pattern from directory path\n * Converts file system path to URL pattern\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"buildRoutePattern\",\"stability\":\"stable\",\"signature\":\"(dirPath: string) => string\"} */\nexport function buildRoutePattern(dirPath: string): string {\n if (!dirPath) {\n return '/'; // Root route\n }\n\n // Split into segments and process each\n const segments = dirPath.split('/');\n const processedSegments: string[] = [];\n\n for (const segment of segments) {\n // Skip empty segments\n if (!segment) continue;\n\n // Route groups: (group) - excluded from URL\n if (segment.startsWith('(') && segment.endsWith(')')) {\n // Groups don't contribute to the URL pattern\n continue;\n }\n\n // Dynamic segments: [id] or [...slug]\n if (segment.startsWith('[') && segment.endsWith(']')) {\n if (segment.startsWith('[...')) {\n // Catch-all segment\n processedSegments.push('*');\n } else {\n // Dynamic segment\n processedSegments.push(`:${segment.slice(1, -1)}`);\n }\n } else {\n // Static segment\n processedSegments.push(segment);\n }\n }\n\n // Build final pattern\n const pattern = '/' + processedSegments.join('/');\n return pattern === '/' ? '/' : pattern.replace(/\\/$/, ''); // Remove trailing slash except for root\n}\n\n/**\n * Build route tree from discovered route files\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"buildRouteTree\",\"stability\":\"stable\",\"signature\":\"(routeFiles: RouteFile[]) => RouteNode[]\"} */\nexport function buildRouteTree(routeFiles: RouteFile[]): RouteNode[] {\n // Group files by route pattern\n const routeMap = new Map<string, RouteFile[]>();\n\n for (const file of routeFiles) {\n const existing = routeMap.get(file.pattern) || [];\n existing.push(file);\n routeMap.set(file.pattern, existing);\n }\n\n // Build route nodes\n const routes: RouteNode[] = [];\n\n for (const [pattern, files] of routeMap.entries()) {\n const routeNode = createRouteNode(pattern, files);\n if (routeNode) {\n routes.push(routeNode);\n }\n }\n\n // Sort routes by pattern for consistent ordering\n routes.sort((a, b) => a.pattern.localeCompare(b.pattern));\n\n // Build nested structure\n return buildNestedRoutes(routes);\n}\n\n/**\n * Create a route node from route files\n */\nfunction createRouteNode(\n pattern: string,\n files: RouteFile[]\n): RouteNode | null {\n // Find the page file (required for a valid route)\n const pageFile = files.find(f => f.type === 'page');\n if (!pageFile) {\n // No page file means this isn't a complete route\n return null;\n }\n\n // Create route ID from pattern\n const routeId =\n pattern === '/' ? 'root' : pattern.replace(/^\\//, '').replace(/\\//g, '.');\n\n // Build imports object\n const imports: RouteNode['imports'] = {};\n\n // Use the original file system segments (including route groups)\n const segments = pageFile.segments;\n const params: string[] = [];\n\n // Process pattern segments to extract parameter names\n const patternSegments =\n pattern === '/' ? [] : pattern.split('/').filter(Boolean);\n for (const segment of patternSegments) {\n if (segment.startsWith(':')) {\n params.push(segment.slice(1));\n }\n }\n\n // Build imports for each file type (store as placeholder functions)\n for (const file of files) {\n switch (file.type) {\n case 'page':\n imports.page = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'layout':\n imports.layout = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'error':\n imports.error = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'loading':\n imports.loading = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'loader':\n imports.loader = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'config':\n imports.config = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n }\n }\n\n // Check if this route uses groups\n const isGroup = files.some(f =>\n f.segments.some(s => s.startsWith('(') && s.endsWith(')'))\n );\n\n // Extract group name if present\n let groupName: string | undefined;\n if (isGroup) {\n for (const file of files) {\n for (const segment of file.segments) {\n if (segment.startsWith('(') && segment.endsWith(')')) {\n groupName = segment.slice(1, -1);\n break;\n }\n }\n if (groupName) break;\n }\n }\n\n // Determine route characteristics\n const isDynamic = params.length > 0;\n const isCatchAll = pattern.includes('*');\n const isStatic = !isDynamic && !isCatchAll;\n\n return {\n id: routeId,\n pattern,\n path: pageFile.path,\n segments,\n params,\n imports,\n children: [],\n metadata: {\n isStatic,\n isDynamic,\n isCatchAll,\n isGroup,\n groupName,\n hasLayout: !!imports.layout,\n hasError: !!imports.error,\n hasLoading: !!imports.loading,\n hasLoader: !!imports.loader,\n },\n };\n}\n\n/**\n * Build nested route structure from flat route list\n * This creates parent-child relationships based on path hierarchy\n */\nfunction buildNestedRoutes(routes: RouteNode[]): RouteNode[] {\n return routes;\n}\n\n/**\n * Validate route tree for conflicts and issues\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"validateRoutes\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string[]\"} */\nexport function validateRoutes(routes: RouteNode[]): string[] {\n const errors: string[] = [];\n const patterns = new Set<string>();\n\n for (const route of routes) {\n // Check for duplicate patterns\n if (patterns.has(route.pattern)) {\n errors.push(`Duplicate route pattern: ${route.pattern}`);\n }\n patterns.add(route.pattern);\n\n // Validate dynamic segments\n if (route.pattern.includes('[') || route.pattern.includes(']')) {\n const segments = route.pattern.split('/');\n for (const segment of segments) {\n if (\n segment.includes('[') &&\n !segment.match(/^\\[[\\w.]+\\]$/) &&\n !segment.match(/^\\[\\.\\.\\.[\\w.]+\\]$/)\n ) {\n errors.push(\n `Invalid dynamic segment in ${route.pattern}: ${segment}`\n );\n }\n }\n }\n }\n\n return errors;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/routerPlugin/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA8B5B;;GAEG;AACH,qKAAqK;AACrK,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAqB;IACpD,MAAM,EAAE,SAAS,EAAE,UAAU,G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AO,EAAE,CAC1D,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite-plugin-router.scanner\",\n \"title\": \"Route File System Scanner\",\n \"category\": \"compiler\",\n \"description\": \"Scans the file system for route files and builds a route tree with dynamic segments, catch-all routes, and route groups.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"scanner.test.ts\" },\n \"integration\": { \"required\": false, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport glob from 'fast-glob';\nimport type { RouteNode } from '@pithyjs/router';\nimport { join } from 'path';\n\n/**\n * Route file types that can be discovered\n */\nexport interface RouteFile {\n /** File path relative to routes directory */\n path: string;\n /** Absolute file path */\n absolutePath: string;\n /** Route type (page, layout, error, loading, loader, config) */\n type: 'page' | 'layout' | 'error' | 'loading' | 'loader' | 'config';\n /** Route pattern derived from file path */\n pattern: string;\n /** Route segments */\n segments: string[];\n}\n\n/**\n * Scanner configuration options\n */\nexport interface ScannerConfig {\n /** Routes directory path */\n routesDir: string;\n /** File extensions to scan */\n extensions?: string[];\n /** Whether to include TypeScript files */\n typescript?: boolean;\n}\n\n/**\n * Scan the routes directory and discover route files\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"scanRoutes\",\"stability\":\"stable\",\"signature\":\"(config: ScannerConfig) => Promise<RouteFile[]>\"} */\nexport async function scanRoutes(config: ScannerConfig): Promise<RouteFile[]> {\n const { routesDir, extensions = ['ts', 'js'], typescript = true } = config;\n\n // Build glob patterns for route files\n const fileExtensions = typescript ? [...extensions, 'ts'] : extensions;\n const patterns = [\n `**/{page,layout,error,loading,loader,config}.{${fileExtensions.join(',')}}`,\n ];\n\n try {\n // Scan for route files\n const files = await glob(patterns, {\n cwd: routesDir,\n absolute: false,\n onlyFiles: true,\n });\n\n // Process discovered files\n const routeFiles: RouteFile[] = [];\n\n for (const file of files) {\n const routeFile = parseRouteFile(file, routesDir);\n if (routeFile) {\n routeFiles.push(routeFile);\n }\n }\n\n return routeFiles;\n } catch (error) {\n console.error('Failed to scan routes directory:', error);\n return [];\n }\n}\n\n/**\n * Parse a route file path into route information\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"parseRouteFile\",\"stability\":\"stable\",\"signature\":\"(filePath: string, routesDir: string) => RouteFile | null\"} */\nexport function parseRouteFile(\n filePath: string,\n routesDir: string\n): RouteFile | null {\n // Normalize path separators\n const normalizedPath = filePath.replace(/\\\\/g, '/');\n\n // Extract file name and directory\n const pathParts = normalizedPath.split('/');\n const fileName = pathParts[pathParts.length - 1];\n const dirPath = pathParts.slice(0, -1).join('/');\n\n // Determine route type from filename\n const routeType = getRouteType(fileName);\n if (!routeType) {\n return null;\n }\n\n // Build route pattern from directory structure\n const pattern = buildRoutePattern(dirPath);\n\n // Extract route segments\n const segments = dirPath ? dirPath.split('/') : [];\n\n return {\n path: normalizedPath,\n absolutePath: join(routesDir, filePath),\n type: routeType,\n pattern,\n segments,\n };\n}\n\n/**\n * Determine route type from filename\n */\nfunction getRouteType(fileName: string): RouteFile['type'] | null {\n // Remove extension\n const baseName = fileName.replace(/\\.(ts|js)$/, '');\n\n switch (baseName) {\n case 'page':\n return 'page';\n case 'layout':\n return 'layout';\n case 'error':\n return 'error';\n case 'loading':\n return 'loading';\n case 'loader':\n return 'loader';\n case 'config':\n return 'config';\n default:\n return null;\n }\n}\n\n/**\n * Build route pattern from directory path\n * Converts file system path to URL pattern\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"buildRoutePattern\",\"stability\":\"stable\",\"signature\":\"(dirPath: string) => string\"} */\nexport function buildRoutePattern(dirPath: string): string {\n if (!dirPath) {\n return '/'; // Root route\n }\n\n // Split into segments and process each\n const segments = dirPath.split('/');\n const processedSegments: string[] = [];\n\n for (const segment of segments) {\n // Skip empty segments\n if (!segment) continue;\n\n // Route groups: (group) - excluded from URL\n if (segment.startsWith('(') && segment.endsWith(')')) {\n // Groups don't contribute to the URL pattern\n continue;\n }\n\n // Dynamic segments: [id] or [...slug]\n if (segment.startsWith('[') && segment.endsWith(']')) {\n if (segment.startsWith('[...')) {\n // Catch-all segment\n processedSegments.push('*');\n } else {\n // Dynamic segment\n processedSegments.push(`:${segment.slice(1, -1)}`);\n }\n } else {\n // Static segment\n processedSegments.push(segment);\n }\n }\n\n // Build final pattern\n const pattern = '/' + processedSegments.join('/');\n return pattern === '/' ? '/' : pattern.replace(/\\/$/, ''); // Remove trailing slash except for root\n}\n\n/**\n * Build the route tree from discovered route files: one node per directory\n * holding a page or a layout. Below a layout, each node nests under its\n * nearest ancestor directory with a node, so a page-only ancestor stays in\n * the lineage its `error.ts` covers. Outside every layout the tree stays\n * flat. A layout that wraps no page is dropped.\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"buildRouteTree\",\"stability\":\"stable\",\"signature\":\"(routeFiles: RouteFile[]) => RouteNode[]\"} */\nexport function buildRouteTree(routeFiles: RouteFile[]): RouteNode[] {\n const filesByDir = new Map<string, RouteFile[]>();\n for (const file of routeFiles) {\n const dir = file.segments.join('/');\n const files = filesByDir.get(dir) ?? [];\n files.push(file);\n filesByDir.set(dir, files);\n }\n\n const nodesByDir = new Map<string, RouteNode>();\n for (const [dir, files] of filesByDir) {\n const routeNode = files[0] && createRouteNode(files[0].pattern, files);\n if (routeNode) nodesByDir.set(dir, routeNode);\n }\n\n return buildNestedRoutes(nodesByDir);\n}\n\n/**\n * Create a route node from the files of one directory. A directory needs a\n * page (a navigable route) or a layout (a wrapper for the routes below it).\n */\nfunction createRouteNode(\n pattern: string,\n files: RouteFile[]\n): RouteNode | null {\n const pageFile = files.find(f => f.type === 'page');\n const ownFile = pageFile ?? files.find(f => f.type === 'layout');\n if (!ownFile) {\n return null;\n }\n\n // A layout-only node is named after its directory: a route group shares\n // its URL pattern (and so the pattern-derived id) with other directories.\n const routeId = pageFile\n ? pattern === '/'\n ? 'root'\n : pattern.replace(/^\\//, '').replace(/\\//g, '.')\n : ownFile.segments.join('.') || 'root';\n // Build imports object\n const imports: RouteNode['imports'] = {};\n\n // Use the original file system segments (including route groups)\n const segments = ownFile.segments;\n const params: string[] = [];\n\n // Process pattern segments to extract parameter names\n const patternSegments =\n pattern === '/' ? [] : pattern.split('/').filter(Boolean);\n for (const segment of patternSegments) {\n if (segment.startsWith(':')) {\n params.push(segment.slice(1));\n }\n }\n\n // Build imports for each file type (store as placeholder functions)\n for (const file of files) {\n switch (file.type) {\n case 'page':\n imports.page = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'layout':\n imports.layout = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'error':\n imports.error = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'loading':\n imports.loading = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'loader':\n imports.loader = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n case 'config':\n imports.config = () => Promise.resolve({}); // Placeholder - will be replaced in manifest\n break;\n }\n }\n\n // Check if this route uses groups\n const isGroup = files.some(f =>\n f.segments.some(s => s.startsWith('(') && s.endsWith(')'))\n );\n\n // Extract group name if present\n let groupName: string | undefined;\n if (isGroup) {\n for (const file of files) {\n for (const segment of file.segments) {\n if (segment.startsWith('(') && segment.endsWith(')')) {\n groupName = segment.slice(1, -1);\n break;\n }\n }\n if (groupName) break;\n }\n }\n\n // Determine route characteristics\n const isDynamic = params.length > 0;\n const isCatchAll = pattern.includes('*');\n const isStatic = !isDynamic && !isCatchAll;\n\n return {\n id: routeId,\n pattern,\n path: ownFile.path,\n segments,\n params,\n imports,\n children: [],\n metadata: {\n isStatic,\n isDynamic,\n isCatchAll,\n isGroup,\n groupName,\n hasLayout: !!imports.layout,\n hasError: !!imports.error,\n hasLoading: !!imports.loading,\n hasLoader: !!imports.loader,\n },\n };\n}\n\n/**\n * Attach every node below a layout to its nearest ancestor node, then drop\n * layout-only nodes left with nothing to wrap.\n */\nfunction buildNestedRoutes(nodesByDir: Map<string, RouteNode>): RouteNode[] {\n const pageIds = new Set(\n [...nodesByDir.values()].filter(n => n.imports.page).map(n => n.id)\n );\n for (const [dir, node] of nodesByDir) {\n if (!node.imports.page && pageIds.has(node.id)) {\n node.id = `layout:${dir || 'root'}`;\n }\n }\n\n const roots: RouteNode[] = [];\n for (const [dir, node] of nodesByDir) {\n const parent = nearestLayoutAncestor(dir, nodesByDir)\n ? nearestAncestor(dir, nodesByDir)\n : null;\n (parent ? parent.children : roots).push(node);\n }\n return pruneAndSort(roots);\n}\n\nfunction nearestLayoutAncestor(\n dir: string,\n nodesByDir: Map<string, RouteNode>\n): RouteNode | null {\n const parts = dir ? dir.split('/') : [];\n while (parts.length > 0) {\n parts.pop();\n const ancestor = nodesByDir.get(parts.join('/'));\n if (ancestor?.imports.layout) return ancestor;\n }\n return null;\n}\n\n/**\n * The node of the nearest ancestor directory. A page-only ancestor renders no\n * segment, but its error boundary covers the routes below it.\n */\nfunction nearestAncestor(\n dir: string,\n nodesByDir: Map<string, RouteNode>\n): RouteNode | null {\n const parts = dir ? dir.split('/') : [];\n while (parts.length > 0) {\n parts.pop();\n const ancestor = nodesByDir.get(parts.join('/'));\n if (ancestor) return ancestor;\n }\n return null;\n}\n\nfunction pruneAndSort(nodes: RouteNode[]): RouteNode[] {\n const kept: RouteNode[] = [];\n for (const node of nodes) {\n node.children = pruneAndSort(node.children);\n if (node.imports.page || node.children.length > 0) kept.push(node);\n }\n return kept.sort(\n (a, b) => a.pattern.localeCompare(b.pattern) || a.id.localeCompare(b.id)\n );\n}\n\n/**\n * Every node of a route tree, parents before their children.\n * @internal\n */\nexport function allRouteNodes(routes: RouteNode[]): RouteNode[] {\n return routes.flatMap(route => [route, ...allRouteNodes(route.children)]);\n}\n\n/**\n * Files the router never runs: guards (`config`) and loaders run for the\n * matched leaf route only, so beside a layout with no page they are dead.\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"routeWarnings\",\"stability\":\"experimental\",\"signature\":\"(routes: RouteNode[]) => string[]\"} */\nexport function routeWarnings(routes: RouteNode[]): string[] {\n const warnings: string[] = [];\n for (const route of allRouteNodes(routes)) {\n if (route.imports.page) continue;\n const dead = (['loader', 'config'] as const).filter(\n type => route.imports[type]\n );\n if (dead.length > 0) {\n warnings.push(\n `${route.path}: ${dead.join(', ')} beside a layout with no page never run (guards and loaders run for the matched page route only)`\n );\n }\n }\n return warnings;\n}\n\n/**\n * Validate route tree for conflicts and issues\n */\n/** @codexApi {\"parent\":\"pithy.vite-plugin-router.scanner\",\"name\":\"validateRoutes\",\"stability\":\"stable\",\"signature\":\"(routes: RouteNode[]) => string[]\"} */\nexport function validateRoutes(routes: RouteNode[]): string[] {\n const errors: string[] = [];\n const patterns = new Set<string>();\n\n for (const route of allRouteNodes(routes)) {\n // A layout-only node shares its URL with the routes it wraps\n if (!route.imports.page) continue;\n\n // Check for duplicate patterns\n if (patterns.has(route.pattern)) {\n errors.push(`Duplicate route pattern: ${route.pattern}`);\n }\n patterns.add(route.pattern);\n\n // Validate dynamic segments\n if (route.pattern.includes('[') || route.pattern.includes(']')) {\n const segments = route.pattern.split('/');\n for (const segment of segments) {\n if (\n segment.includes('[') &&\n !segment.match(/^\\[[\\w.]+\\]$/) &&\n !segment.match(/^\\[\\.\\.\\.[\\w.]+\\]$/)\n ) {\n errors.push(\n `Invalid dynamic segment in ${route.pattern}: ${segment}`\n );\n }\n }\n }\n }\n\n return errors;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/ssrPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAKlD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAE9B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAiED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/ssrPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAKlD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAE9B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAiED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAoSD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,0JAA0J;AAC1J,wBAAgB,QAAQ,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAgNpE"}
|
package/dist/ssrPlugin/plugin.js
CHANGED
|
@@ -155,8 +155,13 @@ async function autoRender(server, url, configPath, entryClient, debug) {
|
|
|
155
155
|
const htmlShellFn = ssrServerMod.htmlShell;
|
|
156
156
|
const mergeHeadFn = ssrServerMod.mergeHead;
|
|
157
157
|
const injectIntoOutletFn = ssrServerMod.injectIntoOutlet;
|
|
158
|
+
const wrapInLayoutsFn = ssrServerMod.wrapInLayouts;
|
|
158
159
|
const routerMod = await server.ssrLoadModule('@pithyjs/router');
|
|
159
|
-
const { findBestMatch,
|
|
160
|
+
const { findBestMatch, findLayoutChain } = routerMod;
|
|
161
|
+
// Only page-bearing routes are destinations: a layout-only node shares its
|
|
162
|
+
// pattern with a route it wraps
|
|
163
|
+
const findRouteByPattern = routerMod.findNavigableRoute ?? routerMod.findRouteByPattern;
|
|
164
|
+
const collectPatterns = routerMod.navigablePatterns ?? routerMod.collectPatterns;
|
|
160
165
|
// Load JIT compiler (parse5) for runtime html`` templates.
|
|
161
166
|
// No-op if already loaded; must run before any renderToString() call.
|
|
162
167
|
// Imported from compile/parseHtml directly (not the barrel) to avoid
|
|
@@ -202,28 +207,46 @@ async function autoRender(server, url, configPath, entryClient, debug) {
|
|
|
202
207
|
const routeNode = findRouteByPattern(routes, match.pattern);
|
|
203
208
|
if (routeNode?.imports?.page) {
|
|
204
209
|
try {
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
210
|
+
const renderPage = async () => {
|
|
211
|
+
const pageMod = await routeNode.imports.page();
|
|
212
|
+
const PageComponent = pageMod.default;
|
|
213
|
+
if (!PageComponent) {
|
|
214
|
+
throw new Error(`[pithy-ssr] Page module for route "${match.pattern}" has no default export.`);
|
|
215
|
+
}
|
|
216
|
+
return renderToString({
|
|
217
|
+
url,
|
|
218
|
+
App: PageComponent,
|
|
219
|
+
params: match.params ?? {},
|
|
220
|
+
query: queryParams,
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
// Layouts render outermost first and the page last, so a layout gate
|
|
224
|
+
// (auth, feature flag) redirects or sets 403/404 before the page is
|
|
225
|
+
// imported or rendered.
|
|
226
|
+
const result = wrapInLayoutsFn
|
|
227
|
+
? await wrapInLayoutsFn(findLayoutChain
|
|
228
|
+
? findLayoutChain(routes, routeNode).map((n) => n.imports.layout)
|
|
229
|
+
: [], renderPage, (Layout) => renderToString({
|
|
230
|
+
url,
|
|
231
|
+
App: Layout,
|
|
232
|
+
params: match.params ?? {},
|
|
233
|
+
query: queryParams,
|
|
234
|
+
}), config.outletId ?? 'outlet', '[pithy-ssr]')
|
|
235
|
+
: await renderPage().then((page) => ({
|
|
236
|
+
...page,
|
|
237
|
+
page,
|
|
238
|
+
}));
|
|
239
|
+
if (result.redirectTo) {
|
|
221
240
|
return {
|
|
222
241
|
html: '',
|
|
223
|
-
status:
|
|
224
|
-
headers: { Location:
|
|
242
|
+
status: result.status ?? 302,
|
|
243
|
+
headers: { Location: result.redirectTo },
|
|
225
244
|
};
|
|
226
245
|
}
|
|
246
|
+
pageHtml = result.html;
|
|
247
|
+
pageHead = result.page.head;
|
|
248
|
+
pageState = result.page.state;
|
|
249
|
+
status = result.status ?? 200;
|
|
227
250
|
}
|
|
228
251
|
catch (err) {
|
|
229
252
|
if (debug) {
|