@demiurgejs/core 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/adapter/index.d.ts +20 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/browser/file-router.d.ts +35 -0
- package/dist/browser/file-router.d.ts.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/chunks/index-BnX9Qxbm.js +44 -0
- package/dist/chunks/index-BnX9Qxbm.js.map +1 -0
- package/dist/chunks/ssr-BJejKlkZ.js +275 -0
- package/dist/chunks/ssr-BJejKlkZ.js.map +1 -0
- package/dist/chunks/static-files-DUjHw-4H.js +11 -0
- package/dist/chunks/static-files-DUjHw-4H.js.map +1 -0
- package/dist/chunks/streaming-DN1DnbRE.js +343 -0
- package/dist/chunks/streaming-DN1DnbRE.js.map +1 -0
- package/dist/chunks/testing-DR3eQAvY.js +2872 -0
- package/dist/chunks/testing-DR3eQAvY.js.map +1 -0
- package/dist/data/cache.d.ts +95 -0
- package/dist/data/cache.d.ts.map +1 -0
- package/dist/data/idempotency.d.ts +24 -0
- package/dist/data/idempotency.d.ts.map +1 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/testing.d.ts +7 -0
- package/dist/data/testing.d.ts.map +1 -0
- package/dist/data/testing.js +134 -0
- package/dist/data/testing.js.map +1 -0
- package/dist/document/hydration.d.ts +13 -0
- package/dist/document/hydration.d.ts.map +1 -0
- package/dist/document/index.d.ts +13 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/links.d.ts +17 -0
- package/dist/document/links.d.ts.map +1 -0
- package/dist/document/metadata.d.ts +62 -0
- package/dist/document/metadata.d.ts.map +1 -0
- package/dist/document/render.d.ts +29 -0
- package/dist/document/render.d.ts.map +1 -0
- package/dist/document/scripts.d.ts +24 -0
- package/dist/document/scripts.d.ts.map +1 -0
- package/dist/document/seo.d.ts +42 -0
- package/dist/document/seo.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1328 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/testing.d.ts +3 -0
- package/dist/internal/testing.d.ts.map +1 -0
- package/dist/internal/testing.js +22 -0
- package/dist/internal/testing.js.map +1 -0
- package/dist/node/http.d.ts +28 -0
- package/dist/node/http.d.ts.map +1 -0
- package/dist/node/index.d.ts +45 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +386 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/static.d.ts +9 -0
- package/dist/node/static.d.ts.map +1 -0
- package/dist/node/streaming.d.ts +5 -0
- package/dist/node/streaming.d.ts.map +1 -0
- package/dist/package-name.d.ts +2 -0
- package/dist/package-name.d.ts.map +1 -0
- package/dist/platform/analytics.d.ts +20 -0
- package/dist/platform/analytics.d.ts.map +1 -0
- package/dist/platform/fonts.d.ts +35 -0
- package/dist/platform/fonts.d.ts.map +1 -0
- package/dist/platform/images.d.ts +49 -0
- package/dist/platform/images.d.ts.map +1 -0
- package/dist/platform/index.d.ts +9 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/observability.d.ts +60 -0
- package/dist/platform/observability.d.ts.map +1 -0
- package/dist/route/action.d.ts +33 -0
- package/dist/route/action.d.ts.map +1 -0
- package/dist/route/http-error.d.ts +24 -0
- package/dist/route/http-error.d.ts.map +1 -0
- package/dist/route/index.d.ts +10 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/page.d.ts +5 -0
- package/dist/route/page.d.ts.map +1 -0
- package/dist/route/response.d.ts +100 -0
- package/dist/route/response.d.ts.map +1 -0
- package/dist/route/types.d.ts +186 -0
- package/dist/route/types.d.ts.map +1 -0
- package/dist/route/webhook.d.ts +25 -0
- package/dist/route/webhook.d.ts.map +1 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/manifest.d.ts +119 -0
- package/dist/router/manifest.d.ts.map +1 -0
- package/dist/router/navigation-data.d.ts +9 -0
- package/dist/router/navigation-data.d.ts.map +1 -0
- package/dist/routing/generate.d.ts +14 -0
- package/dist/routing/generate.d.ts.map +1 -0
- package/dist/routing/index.d.ts +3 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/types.d.ts +38 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/security/audit.d.ts +16 -0
- package/dist/security/audit.d.ts.map +1 -0
- package/dist/security/cors.d.ts +7 -0
- package/dist/security/cors.d.ts.map +1 -0
- package/dist/security/csrf.d.ts +15 -0
- package/dist/security/csrf.d.ts.map +1 -0
- package/dist/security/env.d.ts +69 -0
- package/dist/security/env.d.ts.map +1 -0
- package/dist/security/index.d.ts +17 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/policy.d.ts +18 -0
- package/dist/security/policy.d.ts.map +1 -0
- package/dist/security/rate-limit.d.ts +6 -0
- package/dist/security/rate-limit.d.ts.map +1 -0
- package/dist/security/report.d.ts +13 -0
- package/dist/security/report.d.ts.map +1 -0
- package/dist/security/request.d.ts +11 -0
- package/dist/security/request.d.ts.map +1 -0
- package/dist/security/types.d.ts +137 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security/upload.d.ts +23 -0
- package/dist/security/upload.d.ts.map +1 -0
- package/dist/security/websocket.d.ts +13 -0
- package/dist/security/websocket.d.ts.map +1 -0
- package/dist/server/errors.d.ts +13 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/failure-site.d.ts +2 -0
- package/dist/server/failure-site.d.ts.map +1 -0
- package/dist/server/fallbacks.d.ts +10 -0
- package/dist/server/fallbacks.d.ts.map +1 -0
- package/dist/server/index.d.ts +14 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/negotiate.d.ts +3 -0
- package/dist/server/negotiate.d.ts.map +1 -0
- package/dist/server/not-found.d.ts +11 -0
- package/dist/server/not-found.d.ts.map +1 -0
- package/dist/server/problem.d.ts +18 -0
- package/dist/server/problem.d.ts.map +1 -0
- package/dist/server/render-tree.d.ts +4 -0
- package/dist/server/render-tree.d.ts.map +1 -0
- package/dist/server/request-handler.d.ts +40 -0
- package/dist/server/request-handler.d.ts.map +1 -0
- package/dist/server/request-metadata.d.ts +7 -0
- package/dist/server/request-metadata.d.ts.map +1 -0
- package/dist/server/ssr.d.ts +17 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/static/index.d.ts +28 -0
- package/dist/static/index.d.ts.map +1 -0
- package/dist/static/index.js +377 -0
- package/dist/static/index.js.map +1 -0
- package/dist/static-files.d.ts +5 -0
- package/dist/static-files.d.ts.map +1 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +746 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/plugin.d.ts +37 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/package.json +93 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/package-name.ts","../../src/routing/generate.ts","../../src/vite/plugin.ts"],"sourcesContent":["// The package name is the specifier that user code imports. Generated client\n// entries, server entries, and route type declarations use it. Page route\n// detection also compares application source with it. A mismatch then breaks\n// resolution in the consumer build.\n//\n// This is deliberately not the same thing as the many internal `demiurge`\n// strings elsewhere in the source. `__demiurge_data`, `virtual:demiurge/*`,\n// `demiurge-manifest.json`, and friends name the framework, not the package,\n// and they stay put if the registry name ever changes.\nexport const PACKAGE_NAME = \"@demiurgejs/core\";\n","import { mkdir, readdir, writeFile } from \"node:fs/promises\";\nimport { dirname, relative, resolve, sep } from \"node:path\";\nimport { PACKAGE_NAME } from \"../package-name\";\n\nexport type GenerateRoutesOptions = {\n outputFile: string;\n routesDir: string;\n};\n\ntype RouteInfo = {\n pathVars: string[];\n pattern: string;\n};\n\nexport async function generateRoutes(options: GenerateRoutesOptions) {\n const routeFiles = await findRouteFiles(options.routesDir);\n const routes = routeFiles\n .map((file) => toRouteInfo(options.routesDir, file))\n .filter((route): route is RouteInfo => Boolean(route))\n .sort((a, b) => a.pattern.localeCompare(b.pattern));\n\n const source = renderRoutesModule(routes);\n\n await mkdir(dirname(options.outputFile), { recursive: true });\n await writeFile(options.outputFile, source);\n\n return {\n routes,\n source,\n };\n}\n\nasync function findRouteFiles(directory: string) {\n const entries = await readdir(directory, {\n recursive: true,\n withFileTypes: true,\n });\n\n return entries\n .filter((entry) => entry.isFile() && /\\.tsx?$/.test(entry.name))\n .map((entry) => resolve(entry.parentPath, entry.name));\n}\n\nfunction toRouteInfo(routesDir: string, file: string) {\n const relativePath = relative(routesDir, file).split(sep).join(\"/\");\n const fileSegments = relativePath.replace(/\\.tsx?$/, \"\").split(\"/\");\n const basename = fileSegments.at(-1);\n\n if (basename?.startsWith(\"@\")) {\n return null;\n }\n\n const urlSegments = fileSegments.flatMap((segment) => {\n if (isRouteGroupSegment(segment)) {\n return [];\n }\n\n if (segment === \"index\") {\n return [];\n }\n\n if (segment.startsWith(\"[...\") && segment.endsWith(\"]\")) {\n return [segment];\n }\n\n if (segment.startsWith(\"[\") && segment.endsWith(\"]\")) {\n return [segment];\n }\n\n return [segment];\n });\n\n const pathVars = fileSegments.flatMap((segment) => {\n if (isRouteGroupSegment(segment)) {\n return [];\n }\n\n if (segment.startsWith(\"[...\") && segment.endsWith(\"]\")) {\n return [segment.slice(4, -1)];\n }\n\n if (segment.startsWith(\"[\") && segment.endsWith(\"]\")) {\n return [segment.slice(1, -1)];\n }\n\n return [];\n });\n\n return {\n pathVars,\n pattern: `/${urlSegments.join(\"/\")}`.replace(/\\/$/, \"\") || \"/\",\n };\n}\n\nfunction isRouteGroupSegment(segment: string) {\n return segment.startsWith(\"(\") && segment.endsWith(\")\");\n}\n\nfunction renderRoutesModule(routes: RouteInfo[]) {\n return `// Generated by Demiurge. Do not edit by hand.\nimport \"${PACKAGE_NAME}\";\nimport type { PathValue } from \"${PACKAGE_NAME}\";\n\ndeclare module \"${PACKAGE_NAME}\" {\n interface RoutePathVars {\n${routes.map(renderPathVarsEntry).join(\"\\n\")}\n }\n\n interface RouteConcretePaths {\n${routes.map(renderConcretePathEntry).join(\"\\n\")}\n }\n}\n\nexport {};\n`;\n}\n\nfunction renderPathVarsEntry(route: RouteInfo) {\n if (route.pathVars.length === 0) {\n return ` ${JSON.stringify(route.pattern)}: {};`;\n }\n\n const pathType = route.pathVars\n .map((name) => `${name}: PathValue`)\n .join(\"; \");\n\n return ` ${JSON.stringify(route.pattern)}: { ${pathType} };`;\n}\n\nfunction renderConcretePathEntry(route: RouteInfo) {\n return ` ${JSON.stringify(route.pattern)}: ${toConcretePathType(route.pattern)};`;\n}\n\nfunction toConcretePathType(pattern: string) {\n if (!pattern.includes(\"[\")) {\n return JSON.stringify(pattern);\n }\n\n const parts = pattern.split(/(\\[\\.\\.\\.[^\\]]+\\]|\\[[^\\]]+\\])/g).filter(Boolean);\n return `\\`${parts.map((part) => (part.startsWith(\"[\") ? \"${PathValue}\" : escapeTemplate(part))).join(\"\")}\\``;\n}\n\nfunction escapeTemplate(value: string) {\n return value.replace(/[`$\\\\]/g, \"\\\\$&\");\n}\n","import { existsSync } from \"node:fs\";\nimport type { IncomingMessage } from \"node:http\";\nimport { readFile, readdir } from \"node:fs/promises\";\nimport { dirname, join, resolve, relative, sep } from \"node:path\";\nimport MagicString from \"magic-string\";\nimport {\n type ConfigEnv,\n parseAst,\n type Plugin,\n type UserConfig,\n type ViteDevServer,\n} from \"vite\";\nimport { renderDocument } from \"../document\";\nimport type {\n LinkTag,\n ResolvedMetadata,\n ScriptTag,\n} from \"../document\";\nimport { PACKAGE_NAME } from \"../package-name\";\nimport { generateRoutes } from \"../routing/generate\";\nimport {\n createRouteManifest,\n findRouteMatch,\n type RouteManifest,\n} from \"../router\";\nimport {\n handleRequestWithManifest,\n renderNotFoundResponse,\n renderPageDocument,\n type PageRenderer,\n} from \"../server\";\nimport {\n type RouteImporter,\n type RouteModule,\n} from \"../route\";\nimport {\n UnsupportedMethodError,\n toWebRequest,\n writeNotImplemented,\n writeWebResponse,\n} from \"../node/http\";\nimport { renderStreamingPageResponse } from \"../node/streaming\";\nimport { createCspNonce } from \"../security/policy\";\n\nexport type DemiurgeVitePluginOptions = {\n document?: {\n lang?: string;\n title?: string;\n };\n routesDir?: string;\n styles?: false | string;\n typedRoutes?: boolean | {\n outputFile?: string;\n };\n};\n\nconst CLIENT_ENTRY_ID = \"virtual:demiurge/client-entry\";\nconst DEV_CLIENT_ENTRY_PATH = `/@id/${CLIENT_ENTRY_ID}`;\nconst RESOLVED_CLIENT_ENTRY_ID = `\\0${CLIENT_ENTRY_ID}`;\nconst SERVER_ENTRY_ID = \"virtual:demiurge/server-entry\";\nconst RESOLVED_SERVER_ENTRY_ID = `\\0${SERVER_ENTRY_ID}`;\nconst DEFAULT_TYPED_ROUTES_OUTPUT = \".demiurge/route-manifest.d.ts\";\nexport function demiurge(options: DemiurgeVitePluginOptions = {}): Plugin {\n let root = process.cwd();\n let isBuild = false;\n const viteNoncePlaceholder = `demiurge-${createCspNonce()}`;\n\n return {\n enforce: \"post\",\n name: \"demiurge\",\n config(config, environment) {\n return createViteConfig(config, environment, viteNoncePlaceholder);\n },\n configResolved(config) {\n root = config.root;\n isBuild = config.command === \"build\";\n },\n resolveId(id) {\n if (id === CLIENT_ENTRY_ID) {\n return RESOLVED_CLIENT_ENTRY_ID;\n }\n\n if (id === SERVER_ENTRY_ID) {\n return RESOLVED_SERVER_ENTRY_ID;\n }\n\n return null;\n },\n load(id) {\n if (id === RESOLVED_CLIENT_ENTRY_ID) {\n return createClientEntrySource(root, options);\n }\n\n if (id === RESOLVED_SERVER_ENTRY_ID) {\n return createServerEntrySource(root, options);\n }\n\n return null;\n },\n transform: {\n order: \"post\",\n handler(code, id, transformOptions) {\n if (!isRouteSource(root, options, id)) {\n return null;\n }\n\n if (transformOptions?.ssr) {\n return isBuild ? null : protectSsrImportMeta(code, id);\n }\n\n const transformed = stripClientPageData(code);\n return transformed === code ? null : { code: transformed, map: null };\n },\n },\n generateBundle(_outputOptions, bundle) {\n const entry = Object.values(bundle).find(\n (item) =>\n item.type === \"chunk\" &&\n item.isEntry &&\n item.facadeModuleId === RESOLVED_CLIENT_ENTRY_ID,\n );\n\n if (!entry) {\n return;\n }\n\n const styles = Object.values(bundle)\n .filter(\n (asset): asset is Extract<(typeof bundle)[string], { type: \"asset\" }> =>\n asset.type === \"asset\" && asset.fileName.endsWith(\".css\"),\n )\n .map((asset) => `/${asset.fileName}`);\n const clientEntry = `/${entry.fileName}`;\n\n this.emitFile({\n fileName: \"index.html\",\n source: createDocumentHtml({\n entrySrc: clientEntry,\n lang: options.document?.lang,\n styles,\n title: options.document?.title,\n }),\n type: \"asset\",\n });\n this.emitFile({\n fileName: \"demiurge-manifest.json\",\n source: JSON.stringify({ clientEntry, styles }, null, 2),\n type: \"asset\",\n });\n },\n async buildStart() {\n if (isBuild) {\n await assertRootNotFoundRoute(root, options);\n }\n\n if (!options.typedRoutes) {\n return;\n }\n\n await generateTypedRoutes(root, options);\n },\n configureServer(server) {\n if (options.typedRoutes) {\n const routesDir = resolve(\n server.config.root,\n options.routesDir ?? \"src/routes\",\n );\n\n void generateTypedRoutes(server.config.root, options);\n server.watcher.add(routesDir);\n server.watcher.on(\"add\", (file) => {\n if (isRouteFile(routesDir, file)) {\n void generateTypedRoutes(server.config.root, options);\n }\n });\n server.watcher.on(\"change\", (file) => {\n if (isRouteFile(routesDir, file)) {\n void generateTypedRoutes(server.config.root, options);\n }\n });\n server.watcher.on(\"unlink\", (file) => {\n if (isRouteFile(routesDir, file)) {\n void generateTypedRoutes(server.config.root, options);\n }\n });\n }\n\n server.middlewares.use(async (request, response, next) => {\n try {\n let webRequest: Request;\n\n try {\n webRequest = toWebRequest(request, {\n // Vite performs its own configured host allowlist check before\n // Demiurge's middleware runs. Production Node listeners require\n // an explicit application allowlist instead.\n allowedHosts: [request.headers.host ?? \"localhost\"],\n });\n } catch (error) {\n if (error instanceof UnsupportedMethodError) {\n writeNotImplemented(response);\n return;\n }\n\n throw error;\n }\n\n const routesDir = resolve(\n server.config.root,\n options.routesDir ?? \"src/routes\",\n );\n const manifest = await loadDevManifest(server, request, routesDir);\n const documentSecurity = createDevDocumentSecurity(\n server,\n viteNoncePlaceholder,\n );\n const result = await handleDevRequest(\n manifest,\n webRequest,\n createDevRuntimeOptions(options, documentSecurity.transform),\n );\n\n if (result === \"next\") {\n // Vite owns its own asset URLs, so an unmatched request still\n // falls through. The post middleware below is what turns whatever\n // Vite could not serve into the same negotiated not-found\n // production returns.\n next();\n return;\n }\n\n applyDevDocumentSecurity(result, documentSecurity.nonce);\n await writeWebResponse(response, result);\n } catch (error) {\n next(error);\n }\n });\n\n // The returned hook registers this after the Vite middleware. It sees\n // only requests that Vite cannot serve. `appType` is \"custom\", so no SPA\n // fallback intercepts these requests. Development and production render\n // the same negotiated not-found response for an unmatched path.\n return () => {\n server.middlewares.use(async (request, response, next) => {\n try {\n let webRequest: Request;\n\n try {\n webRequest = toWebRequest(request, {\n allowedHosts: [request.headers.host ?? \"localhost\"],\n });\n } catch (error) {\n if (error instanceof UnsupportedMethodError) {\n writeNotImplemented(response);\n return;\n }\n\n throw error;\n }\n\n const routesDir = resolve(\n server.config.root,\n options.routesDir ?? \"src/routes\",\n );\n const manifest = await loadDevManifest(server, request, routesDir);\n\n warnMissingRootNotFound(manifest, routesDir);\n\n const documentSecurity = createDevDocumentSecurity(\n server,\n viteNoncePlaceholder,\n );\n const notFoundResponse = await renderNotFoundResponse(\n manifest,\n webRequest,\n createDevFallbackOptions(options, documentSecurity.transform),\n );\n applyDevDocumentSecurity(\n notFoundResponse,\n documentSecurity.nonce,\n );\n await writeWebResponse(response, notFoundResponse);\n } catch (error) {\n next(error);\n }\n });\n };\n },\n };\n}\n\ntype AstNode = {\n [key: string]: unknown;\n end: number;\n start: number;\n type: string;\n};\n\n// Vite 6 treats the `meta` token in `import.meta` as an imported reference.\n// Give an imported `meta` binding a private name before development SSR runs.\nfunction protectSsrImportMeta(code: string, id: string) {\n if (!code.includes(\"import.meta\")) {\n return null;\n }\n\n const ast = parseAst(code) as unknown as AstNode;\n const declaration = asNodeArray(ast.body).find((node) =>\n node.type === \"ImportDeclaration\" &&\n asNodeArray(node.specifiers).some((specifier) =>\n asNode(specifier.local)?.type === \"Identifier\" &&\n asNode(specifier.local)?.name === \"meta\"\n )\n );\n const specifier = declaration &&\n asNodeArray(declaration.specifiers).find((candidate) =>\n asNode(candidate.local)?.type === \"Identifier\" &&\n asNode(candidate.local)?.name === \"meta\"\n );\n const local = specifier && asNode(specifier.local);\n\n if (!declaration || !specifier || !local) {\n return null;\n }\n\n let alias = \"__demiurge_imported_meta__\";\n while (new RegExp(`\\\\b${alias}\\\\b`).test(code)) {\n alias += \"_\";\n }\n\n const editor = new MagicString(code);\n const imported = asNode(specifier.imported);\n editor.overwrite(\n local.start,\n local.end,\n imported?.start === local.start ? `meta as ${alias}` : alias,\n );\n editor.appendLeft(declaration.end, `\\nconst meta = ${alias};`);\n\n return {\n code: editor.toString(),\n map: editor.generateMap({\n hires: \"boundary\",\n includeContent: true,\n source: id,\n }),\n };\n}\n\n// Page data and document contributions are server capabilities. Vite and React\n// first parse TypeScript and JSX. The plugin then removes these capabilities\n// before Rollup follows the final client graph. This sequence excludes request\n// code and server-only imports from browser chunks. The exported document\n// bindings remain as `undefined` so the\n// route module keeps a stable shape without evaluating their initializers.\nexport function stripClientPageData(code: string) {\n const ast = parseAst(code) as unknown as AstNode;\n const dataRanges: Array<{ end: number; start: number }> = [];\n const documentRanges = findDocumentContributionRanges(ast);\n const serverImports: AstNode[] = [];\n\n walkAst(ast, (node) => {\n if (node.type === \"ImportDeclaration\" && isServerOnlyImport(node)) {\n serverImports.push(node);\n return;\n }\n\n if (node.type !== \"CallExpression\" || !isPageCallee(node.callee)) {\n return;\n }\n\n const argument = asNodeArray(node.arguments)[0];\n if (argument?.type !== \"ObjectExpression\") {\n return;\n }\n\n for (const property of asNodeArray(argument.properties)) {\n if (property.type === \"Property\" && propertyName(property.key) === \"data\") {\n dataRanges.push({ end: property.end, start: property.start });\n }\n }\n });\n\n const serverRanges = [...dataRanges, ...documentRanges];\n\n if (serverRanges.length === 0) {\n return code;\n }\n\n const removalRanges = [...serverRanges];\n for (const declaration of serverImports) {\n const localNames = asNodeArray(declaration.specifiers)\n .map((specifier) => asNode(specifier.local))\n .filter((local): local is AstNode => local?.type === \"Identifier\")\n .map((local) => String(local.name));\n const masked = maskRanges(code, [\n ...serverRanges,\n { end: declaration.end, start: declaration.start },\n ]);\n const leakedName = localNames.find((name) =>\n new RegExp(`\\\\b${escapeRegExp(name)}\\\\b`).test(masked)\n );\n\n if (leakedName) {\n throw new Error(\n `Server-only import ${JSON.stringify(leakedName)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`,\n );\n }\n\n removalRanges.push({ end: declaration.end, start: declaration.start });\n }\n\n return replaceRanges(code, removalRanges, (range) =>\n dataRanges.includes(range) ? \"data: undefined\" :\n documentRanges.includes(range) ? \"undefined\" : \"\"\n );\n}\n\nconst documentContributionNames = new Set([\"links\", \"metadata\", \"scripts\"]);\n\nfunction findDocumentContributionRanges(ast: AstNode) {\n const exportedLocals = new Set<string>();\n\n for (const statement of asNodeArray(ast.body)) {\n if (statement.type !== \"ExportNamedDeclaration\") continue;\n\n const declaration = asNode(statement.declaration);\n if (declaration?.type === \"VariableDeclaration\") {\n for (const declarator of asNodeArray(declaration.declarations)) {\n const id = asNode(declarator.id);\n if (\n id?.type === \"Identifier\" &&\n documentContributionNames.has(String(id.name))\n ) {\n exportedLocals.add(String(id.name));\n }\n }\n }\n\n for (const specifier of asNodeArray(statement.specifiers)) {\n const exported = propertyName(specifier.exported);\n const local = propertyName(specifier.local);\n if (exported && local && documentContributionNames.has(exported)) {\n exportedLocals.add(local);\n }\n }\n }\n\n const ranges: Array<{ end: number; start: number }> = [];\n walkAst(ast, (node) => {\n if (node.type !== \"VariableDeclarator\") return;\n const id = asNode(node.id);\n const init = asNode(node.init);\n if (\n id?.type === \"Identifier\" &&\n exportedLocals.has(String(id.name)) &&\n init\n ) {\n ranges.push({ end: init.end, start: init.start });\n }\n });\n\n return ranges;\n}\n\nfunction isRouteSource(\n root: string,\n options: DemiurgeVitePluginOptions,\n id: string,\n) {\n const file = id.split(\"?\", 1)[0] ?? id;\n const routesRoot = resolve(root, options.routesDir ?? \"src/routes\");\n const pathFromRoutes = relative(routesRoot, file);\n return pathFromRoutes !== \"\" &&\n pathFromRoutes !== \"..\" &&\n !pathFromRoutes.startsWith(`..${sep}`);\n}\n\nfunction walkAst(value: unknown, visit: (node: AstNode) => void) {\n if (!value || typeof value !== \"object\") return;\n if (Array.isArray(value)) {\n for (const item of value) walkAst(item, visit);\n return;\n }\n\n const node = value as Partial<AstNode>;\n if (typeof node.type !== \"string\") return;\n visit(node as AstNode);\n for (const [key, child] of Object.entries(node)) {\n if (!new Set([\"end\", \"loc\", \"start\", \"type\"]).has(key)) {\n walkAst(child, visit);\n }\n }\n}\n\nfunction asNode(value: unknown) {\n return value && typeof value === \"object\" && \"type\" in value\n ? value as AstNode\n : undefined;\n}\n\nfunction asNodeArray(value: unknown) {\n return Array.isArray(value)\n ? value.map(asNode).filter((node): node is AstNode => Boolean(node))\n : [];\n}\n\nfunction isPageCallee(value: unknown) {\n const callee = asNode(value);\n if (callee?.type === \"Identifier\") return callee.name === \"page\";\n return callee?.type === \"MemberExpression\" &&\n propertyName(callee.property) === \"page\";\n}\n\nfunction propertyName(value: unknown) {\n const property = asNode(value);\n return property?.type === \"Identifier\" || property?.type === \"Literal\"\n ? String(property.name ?? property.value)\n : undefined;\n}\n\nfunction isServerOnlyImport(node: AstNode) {\n const source = asNode(node.source)?.value;\n return typeof source === \"string\" &&\n /(?:^|[/.-])server(?:[/.-]|$)/.test(source);\n}\n\nfunction maskRanges(code: string, ranges: Array<{ end: number; start: number }>) {\n const characters = [...code];\n for (const { end, start } of ranges) {\n characters.fill(\" \", start, end);\n }\n return characters.join(\"\");\n}\n\nfunction replaceRanges(\n code: string,\n ranges: Array<{ end: number; start: number }>,\n replacement: (range: { end: number; start: number }) => string,\n) {\n return [...ranges]\n .sort((left, right) => right.start - left.start)\n .reduce(\n (result, range) =>\n `${result.slice(0, range.start)}${replacement(range)}${result.slice(range.end)}`,\n code,\n );\n}\n\nfunction escapeRegExp(value: string) {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction createViteConfig(\n config: UserConfig,\n environment: ConfigEnv,\n viteNoncePlaceholder: string,\n): UserConfig {\n return {\n appType: \"custom\",\n build: {\n assetsInlineLimit: config.build?.assetsInlineLimit ?? 0,\n ...(environment.isSsrBuild &&\n config.build?.target === undefined &&\n config.ssr?.target !== \"webworker\"\n ? { target: \"node22.13\" }\n : {}),\n rollupOptions: {\n input: config.build?.rollupOptions?.input ?? CLIENT_ENTRY_ID,\n },\n },\n ...(environment.command === \"serve\"\n ? { html: { cspNonce: viteNoncePlaceholder } }\n : {}),\n };\n}\n\nexport function createClientEntrySource(\n root: string,\n options: DemiurgeVitePluginOptions = {},\n) {\n const routesDir = options.routesDir ?? \"src/routes\";\n const stylesImport = createStylesImport(root, options);\n\n return `import { hydrateFileRouter } from \"${PACKAGE_NAME}\";\n${stylesImport}\n\n${createRouteMapSource(routesDir, {\n exportRoutes: false,\n includeServerOnly: false,\n })}\n\nvoid hydrateFileRouter({ routes });\n`;\n}\n\nexport function createServerEntrySource(\n root: string,\n options: DemiurgeVitePluginOptions = {},\n) {\n const routesDir = options.routesDir ?? \"src/routes\";\n\n return `import { createRequestHandler } from \"${PACKAGE_NAME}\";\n\n${createRouteMapSource(routesDir, {\n exportRoutes: true,\n includeServerOnly: true,\n })}\n\nexport function createHandler(options = {}) {\n const { clientEntry, lang, styles, title, ...handlerOptions } = options;\n\n return createRequestHandler({\n ...handlerOptions,\n routes,\n ssr: {\n clientEntry,\n lang: lang ?? ${JSON.stringify(options.document?.lang)},\n styles,\n title: title ?? ${JSON.stringify(options.document?.title)},\n },\n });\n}\n`;\n}\n\n// Both virtual entries use this function. Therefore, their prefix removal and\n// route-key formats stay equal. The server entry requires framework-attached\n// `.ts` files such as `@policy.ts` and `@middleware.ts`. Previously, a\n// `.tsx`-only glob omitted these files from production. Development still found\n// and applied them.\nfunction createRouteMapSource(\n routesDir: string,\n {\n exportRoutes,\n includeServerOnly,\n }: { exportRoutes: boolean; includeServerOnly: boolean },\n) {\n const routesGlobs = toRootAbsoluteGlobs(routesDir, includeServerOnly);\n const routesPrefix = toRootAbsolutePrefix(routesDir);\n\n return `const routeModules = import.meta.glob(${JSON.stringify(routesGlobs)});\nconst routePrefix = ${JSON.stringify(routesPrefix)};\n${exportRoutes ? \"export \" : \"\"}const routes = Object.fromEntries(\n Object.entries(routeModules).map(([file, load]) => [\n \\`./routes/\\${file.slice(routePrefix.length)}\\`,\n load,\n ]),\n);`;\n}\n\n// These two files run only on the server. They control a request before the\n// route runs and do not render. A client glob would create public chunks in\n// `dist/client`. These chunks could expose credentials, authorization logic, or\n// internal host names from a middleware or policy closure.\nconst serverOnlyRouteFiles = [\"@middleware.ts\", \"@policy.ts\"];\n\nfunction toRootAbsoluteGlobs(routesDir: string, includeServerOnly: boolean) {\n const base = `/${routesDir.replace(/^\\/|\\/$/g, \"\")}`;\n const globs = [`${base}/**/*.{ts,tsx}`];\n\n if (!includeServerOnly) {\n globs.push(\n ...serverOnlyRouteFiles.flatMap((fileName) => [\n `!${base}/${fileName}`,\n `!${base}/**/${fileName}`,\n ]),\n );\n }\n\n return globs;\n}\n\nfunction toRootAbsolutePrefix(routesDir: string) {\n return `/${routesDir.replace(/^\\/|\\/$/g, \"\")}/`;\n}\n\nfunction createStylesImport(\n root: string,\n options: DemiurgeVitePluginOptions,\n) {\n if (options.styles === false) {\n return \"\";\n }\n\n const stylesFile = options.styles ?? \"src/styles.css\";\n const resolvedStylesFile = resolve(root, stylesFile);\n\n return existsSync(resolvedStylesFile)\n ? `import ${JSON.stringify(`/${stylesFile.replace(/^\\/+/, \"\")}`)};`\n : \"\";\n}\n\n// Development renders through the production pipeline. It adds the virtual\n// client entry, the Vite HTML transform, and a development flag for stack\n// traces. The shared handler makes all security and routing decisions.\nfunction createDevRuntimeOptions(\n options: DemiurgeVitePluginOptions,\n transformDocument: (html: string) => Promise<string>,\n) {\n return {\n dev: true,\n ssr: createDevSsrOptions(options),\n transformDocument,\n renderPage: async (\n match: Parameters<PageRenderer>[0],\n renderOptions: Parameters<PageRenderer>[1],\n ) => {\n if (match.render.mode === \"streaming\") {\n return await renderStreamingPageResponse(match, {\n ...renderOptions,\n clientEntry: DEV_CLIENT_ENTRY_PATH,\n transformDocument,\n });\n }\n\n const html = await transformDocument(\n renderPageDocument(match, {\n ...renderOptions,\n clientEntry: DEV_CLIENT_ENTRY_PATH,\n }),\n );\n\n return new Response(html, {\n headers: { \"content-type\": \"text/html; charset=utf-8\" },\n });\n },\n };\n}\n\nfunction createDevDocumentSecurity(\n server: ViteDevServer,\n viteNoncePlaceholder: string,\n) {\n const nonce = createCspNonce();\n const shieldNonce = createCspNonce();\n\n return {\n nonce,\n transform: async (html: string) => {\n const shielded = shieldViteNonceTargets(html, shieldNonce);\n const transformed = await server.transformIndexHtml(\"/\", shielded);\n\n return replaceNonceAttribute(\n replaceNonceAttribute(transformed, shieldNonce),\n viteNoncePlaceholder,\n nonce,\n );\n },\n };\n}\n\nfunction shieldViteNonceTargets(html: string, nonce: string) {\n const lowerHtml = html.toLowerCase();\n let cursor = 0;\n let output = \"\";\n\n while (cursor < html.length) {\n const tagStart = html.indexOf(\"<\", cursor);\n\n if (tagStart === -1) {\n return output + html.slice(cursor);\n }\n\n output += html.slice(cursor, tagStart);\n\n if (lowerHtml.startsWith(\"<!--\", tagStart)) {\n const commentEnd = lowerHtml.indexOf(\"-->\", tagStart + 4);\n const end = commentEnd === -1 ? html.length : commentEnd + 3;\n output += html.slice(tagStart, end);\n cursor = end;\n continue;\n }\n\n const name = lowerHtml.slice(tagStart).match(/^<\\s*(script|style|link)\\b/)?.[1];\n\n if (!name) {\n output += \"<\";\n cursor = tagStart + 1;\n continue;\n }\n\n const tagEnd = findHtmlTagEnd(html, tagStart);\n\n if (tagEnd === -1) {\n return output + html.slice(tagStart);\n }\n\n const openingTag = html.slice(tagStart, tagEnd + 1);\n output += /(?:^|\\s)nonce(?:\\s|=|>)/i.test(openingTag)\n ? openingTag\n : addNonceAttribute(openingTag, nonce);\n cursor = tagEnd + 1;\n\n if (name === \"script\" || name === \"style\") {\n const closeStart = lowerHtml.indexOf(`</${name}`, cursor);\n\n if (closeStart === -1) {\n return output + html.slice(cursor);\n }\n\n output += html.slice(cursor, closeStart);\n cursor = closeStart;\n }\n }\n\n return output;\n}\n\nfunction findHtmlTagEnd(html: string, start: number) {\n let quote: \"\\\"\" | \"'\" | undefined;\n\n for (let index = start + 1; index < html.length; index++) {\n const character = html[index];\n\n if (quote) {\n if (character === quote) quote = undefined;\n continue;\n }\n\n if (character === \"\\\"\" || character === \"'\") {\n quote = character;\n } else if (character === \">\") {\n return index;\n }\n }\n\n return -1;\n}\n\nfunction addNonceAttribute(openingTag: string, nonce: string) {\n const insertion = /\\/\\s*>$/.test(openingTag)\n ? openingTag.lastIndexOf(\"/\")\n : openingTag.length - 1;\n\n return `${openingTag.slice(0, insertion)} nonce=\"${nonce}\"${openingTag.slice(insertion)}`;\n}\n\nfunction replaceNonceAttribute(\n html: string,\n current: string,\n replacement?: string,\n) {\n const pattern = new RegExp(\n `(\\\\snonce\\\\s*=\\\\s*)([\"'])${escapeRegExp(current)}\\\\2`,\n \"g\",\n );\n\n return html.replace(\n pattern,\n replacement ? `$1\"${replacement}\"` : \"\",\n );\n}\n\nfunction applyDevDocumentSecurity(response: Response, nonce: string) {\n const contentType = response.headers.get(\"content-type\");\n const csp = response.headers.get(\"content-security-policy\");\n\n if (!contentType?.toLowerCase().startsWith(\"text/html\") || !csp) {\n return;\n }\n\n const source = `'nonce-${nonce}'`;\n const withScriptNonce = addCspSource(\n csp,\n [\"script-src-elem\", \"script-src\"],\n \"script-src\",\n source,\n );\n const withStyleNonce = allowsUnsafeInline(\n withScriptNonce,\n [\"style-src-elem\", \"style-src\"],\n )\n ? withScriptNonce\n : addCspSource(\n withScriptNonce,\n [\"style-src-elem\", \"style-src\"],\n \"style-src\",\n source,\n );\n\n response.headers.set(\"content-security-policy\", withStyleNonce);\n response.headers.set(\"cache-control\", \"private, no-store\");\n}\n\nfunction addCspSource(\n csp: string,\n directiveNames: readonly string[],\n fallbackDirectiveName: \"script-src\" | \"style-src\",\n source: string,\n) {\n const directives = csp.split(\";\").map((directive) => directive.trim());\n const directiveIndex = findCspDirectiveIndex(directives, directiveNames);\n\n const defaultDirective = directives.find((directive) =>\n directive.split(/\\s+/, 1)[0]?.toLowerCase() === \"default-src\"\n );\n\n if (directiveIndex === -1 && !defaultDirective) return csp;\n\n const [currentName, ...currentSources] =\n (directiveIndex === -1 ? defaultDirective! : directives[directiveIndex]!)\n .split(/\\s+/);\n const updatedDirective = [\n directiveIndex === -1 ? fallbackDirectiveName : currentName!,\n ...new Set([\n ...currentSources.filter((current) => current !== \"'none'\"),\n source,\n ]),\n ].join(\" \");\n\n if (directiveIndex === -1) {\n directives.push(updatedDirective);\n } else {\n directives[directiveIndex] = updatedDirective;\n }\n\n return directives.join(\"; \");\n}\n\nfunction allowsUnsafeInline(\n csp: string,\n directiveNames: readonly string[],\n) {\n const directives = csp.split(\";\").map((directive) => directive.trim());\n const directiveIndex = findCspDirectiveIndex(directives, directiveNames);\n const effectiveDirective = directiveIndex === -1\n ? directives.find((directive) =>\n directive.split(/\\s+/, 1)[0]?.toLowerCase() === \"default-src\"\n )\n : directives[directiveIndex];\n const sources = effectiveDirective?.split(/\\s+/).slice(1) ?? [];\n\n return sources.includes(\"'unsafe-inline'\") &&\n !sources.some((source) => /^'(?:nonce-|sha(?:256|384|512)-)/i.test(source));\n}\n\nfunction findCspDirectiveIndex(\n directives: readonly string[],\n directiveNames: readonly string[],\n) {\n for (const name of directiveNames) {\n const index = directives.findIndex((directive) =>\n directive.split(/\\s+/, 1)[0]?.toLowerCase() === name\n );\n\n if (index !== -1) return index;\n }\n\n return -1;\n}\n\n// Both dev middlewares need the manifest for the same request, and building\n// it walks the routes directory. The pre middleware always runs, so the post\n// middleware reuses what it already produced rather than scanning twice on\n// every unmatched request.\nconst DEV_MANIFEST = Symbol.for(\"demiurge.devManifest\");\n\ntype DevManifestCarrier = { [DEV_MANIFEST]?: RouteManifest };\n\nasync function loadDevManifest(\n server: ViteDevServer,\n request: IncomingMessage,\n routesDir: string,\n) {\n const carrier = request as IncomingMessage & DevManifestCarrier;\n const cached = carrier[DEV_MANIFEST];\n\n if (cached) {\n return cached;\n }\n\n const manifest = createRouteManifest(\n await createDevRouteImporters(server, routesDir),\n );\n\n carrier[DEV_MANIFEST] = manifest;\n\n return manifest;\n}\n\nfunction createDevSsrOptions(options: DemiurgeVitePluginOptions) {\n return {\n clientEntry: DEV_CLIENT_ENTRY_PATH,\n lang: options.document?.lang,\n title: options.document?.title,\n };\n}\n\nfunction createDevFallbackOptions(\n options: DemiurgeVitePluginOptions,\n transformDocument: (html: string) => Promise<string>,\n) {\n return {\n ...createDevSsrOptions(options),\n dev: true,\n transformDocument,\n };\n}\n\nconst warnedRoots = new Set<string>();\n\n// The framework built-in is a temporary fallback, not a production 404. The\n// build gate enforces this rule. This warning gives the same message earlier.\nfunction warnMissingRootNotFound(manifest: RouteManifest, routesDir: string) {\n if (\n warnedRoots.has(routesDir) ||\n manifest.fallbacks.notFound.some(\n (fallback) => fallback.fileSegments.length === 0,\n )\n ) {\n return;\n }\n\n warnedRoots.add(routesDir);\n console.warn(missingRootNotFoundMessage(join(routesDir, \"@not-found.tsx\")));\n}\n\n// The framework ships a working 404 so nothing is ever blank, and refuses to\n// let an app reach production still rendering it. A generic framework page in\n// front of real users is a failure of the framework, not of the app that never\n// got around to it.\nexport async function assertRootNotFoundRoute(\n root: string,\n options: DemiurgeVitePluginOptions = {},\n) {\n const routesDirOption = options.routesDir ?? \"src/routes\";\n const routesDir = resolve(root, routesDirOption);\n\n if (!existsSync(routesDir)) {\n return;\n }\n\n const files = await findRouteFiles(routesDir);\n const names = files.map((file) =>\n relative(routesDir, file).split(sep).join(\"/\"),\n );\n\n if (names.some((name) => /^@not-found\\.tsx?$/.test(name))) {\n return;\n }\n\n const pageRoute = await findPageRouteFile(files);\n\n // An API-only app never wants an HTML not-found document, and nagging it\n // would be user hostile. It builds clean and gets problem+json.\n if (!pageRoute) {\n return;\n }\n\n throw new Error(\n missingRootNotFoundBuildMessage(\n routesDirOption,\n relative(routesDir, pageRoute).split(sep).join(\"/\"),\n ),\n );\n}\n\n// Page detection is a source scan rather than a module evaluation: the plugin\n// cannot execute route modules at build time. A page route is a file that\n// calls `page(...)`, which is the only way to declare one.\nasync function findPageRouteFile(files: string[]) {\n for (const file of files) {\n // Framework-attached files own no address, so they are never page routes.\n if (relative(dirname(file), file).startsWith(\"@\")) {\n continue;\n }\n\n if (declaresPageRoute(await readFile(file, \"utf8\"))) {\n return file;\n }\n }\n\n return undefined;\n}\n\n// Escaped because a package name may contain `.`, which the regex would\n// otherwise read as a wildcard.\nconst PACKAGE_NAME_PATTERN = PACKAGE_NAME.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\nconst DEMIURGE_NAMED_IMPORT = new RegExp(\n `import\\\\s*\\\\{([^}]*)\\\\}\\\\s*from\\\\s*[\"']${PACKAGE_NAME_PATTERN}[\"']`,\n \"g\",\n);\n\n// The plugin cannot evaluate route modules during the build. Therefore, page\n// detection reads the source. It checks the import, not only the word. An API\n// application can call `db.users.page(2)` without serving an HTML document.\n// Only a page route imports `page` from the framework package.\nexport function declaresPageRoute(source: string) {\n const locals = [...source.matchAll(DEMIURGE_NAMED_IMPORT)].flatMap((match) =>\n match[1].split(\",\").flatMap((binding) => {\n const [imported, local] = binding.trim().split(/\\s+as\\s+/);\n\n // `import type { page }` cannot be called, and an alias renames what the\n // call site looks like.\n return imported.replace(/^type\\s+/, \"\") === \"page\"\n ? [local ?? imported]\n : [];\n }),\n );\n\n if (locals.length === 0) {\n return false;\n }\n\n // Strip the import statements first so the binding list is not itself\n // mistaken for a call.\n const body = source.replace(DEMIURGE_NAMED_IMPORT, \"\");\n\n return locals.some((local) => new RegExp(`\\\\b${local}\\\\s*\\\\(`).test(body));\n}\n\nexport function missingRootNotFoundBuildMessage(\n routesDir: string,\n pageRoute: string,\n) {\n return `Demiurge will not build an app with page routes and no ${routesDir}/@not-found.tsx.\n\n\"${pageRoute}\" declares a page, so a browser can reach a path this app does not serve. Decide what that looks like rather than shipping the framework built-in.\n\nCreate ${routesDir}/@not-found.tsx:\n\n export default function NotFound({ pathname }: { pathname: string }) {\n return <h1>Nothing at {pathname}</h1>;\n }\n\nIt renders inside the layouts above the requested path. Opt out with \"export const layout = false\".`;\n}\n\nexport function missingRootNotFoundMessage(notFoundFile: string) {\n return `Demiurge is serving its built-in 404 because ${notFoundFile} does not exist.\n\nCreate it before building for production:\n\n export default function NotFound({ pathname }: { pathname: string }) {\n return <h1>Nothing at {pathname}</h1>;\n }\n`;\n}\n\nexport function createDocumentHtml({\n entrySrc,\n lang,\n links,\n metadata,\n nonce,\n scripts,\n styles,\n title,\n}: {\n entrySrc: string;\n lang?: string;\n links?: LinkTag[];\n metadata?: ResolvedMetadata;\n nonce?: string;\n scripts?: ScriptTag[];\n styles?: string[];\n title?: string;\n}) {\n return renderDocument({\n entrySrc,\n lang,\n links,\n metadata,\n nonce,\n scripts,\n styles,\n title,\n });\n}\n\nasync function generateTypedRoutes(\n root: string,\n options: DemiurgeVitePluginOptions,\n) {\n const routesDir = resolve(root, options.routesDir ?? \"src/routes\");\n const outputFile = resolve(\n root,\n typeof options.typedRoutes === \"object\"\n ? options.typedRoutes.outputFile ?? DEFAULT_TYPED_ROUTES_OUTPUT\n : DEFAULT_TYPED_ROUTES_OUTPUT,\n );\n\n await generateRoutes({ outputFile, routesDir });\n}\n\nfunction isRouteFile(routesDir: string, file: string) {\n return (\n file.startsWith(routesDir) &&\n /\\.tsx?$/.test(file)\n );\n}\n\nexport async function createDevRouteImporters(\n server: ViteDevServer,\n routesDir: string,\n) {\n const files = await findRouteFiles(routesDir);\n const routes: Record<string, RouteImporter> = {};\n\n for (const file of files) {\n const routeKey = toRouteKey(routesDir, file);\n routes[routeKey] = async () =>\n (await server.ssrLoadModule(file)) as RouteModule;\n }\n\n return routes;\n}\n\nexport async function handleDevRequest(\n manifest: RouteManifest,\n request: Request,\n options: Parameters<typeof handleRequestWithManifest>[2] = {},\n) {\n const url = new URL(request.url);\n const routeMatch = findRouteMatch(manifest.routes, url.pathname);\n\n if (!routeMatch) {\n return \"next\" as const;\n }\n\n return await handleRequestWithManifest(manifest, request, options);\n}\n\nasync function findRouteFiles(directory: string) {\n const entries = await readdir(directory, {\n recursive: true,\n withFileTypes: true,\n });\n\n return entries\n .filter((entry) => entry.isFile() && /\\.tsx?$/.test(entry.name))\n .map((entry) => resolve(entry.parentPath, entry.name));\n}\n\nfunction toRouteKey(routesDir: string, file: string) {\n const relativePath = relative(routesDir, file).split(sep).join(\"/\");\n return `./routes/${relativePath}`;\n}\n"],"names":["PACKAGE_NAME","generateRoutes","options","routes","findRouteFiles","file","toRouteInfo","route","a","b","source","renderRoutesModule","mkdir","dirname","writeFile","directory","readdir","entry","resolve","routesDir","fileSegments","relative","sep","urlSegments","segment","isRouteGroupSegment","renderPathVarsEntry","renderConcretePathEntry","pathType","name","toConcretePathType","pattern","part","escapeTemplate","value","CLIENT_ENTRY_ID","DEV_CLIENT_ENTRY_PATH","RESOLVED_CLIENT_ENTRY_ID","SERVER_ENTRY_ID","RESOLVED_SERVER_ENTRY_ID","DEFAULT_TYPED_ROUTES_OUTPUT","demiurge","root","isBuild","viteNoncePlaceholder","createCspNonce","config","environment","createViteConfig","id","createClientEntrySource","createServerEntrySource","code","transformOptions","isRouteSource","protectSsrImportMeta","transformed","stripClientPageData","_outputOptions","bundle","item","styles","asset","clientEntry","createDocumentHtml","assertRootNotFoundRoute","generateTypedRoutes","server","isRouteFile","request","response","next","webRequest","toWebRequest","error","UnsupportedMethodError","writeNotImplemented","manifest","loadDevManifest","documentSecurity","createDevDocumentSecurity","result","handleDevRequest","createDevRuntimeOptions","applyDevDocumentSecurity","writeWebResponse","warnMissingRootNotFound","notFoundResponse","renderNotFoundResponse","createDevFallbackOptions","ast","parseAst","declaration","asNodeArray","node","specifier","asNode","candidate","local","alias","editor","MagicString","imported","dataRanges","documentRanges","findDocumentContributionRanges","serverImports","walkAst","isServerOnlyImport","isPageCallee","argument","property","propertyName","serverRanges","removalRanges","localNames","masked","maskRanges","leakedName","escapeRegExp","replaceRanges","range","documentContributionNames","exportedLocals","statement","declarator","exported","ranges","init","routesRoot","pathFromRoutes","visit","key","child","callee","characters","end","start","replacement","left","right","stylesImport","createStylesImport","createRouteMapSource","exportRoutes","includeServerOnly","routesGlobs","toRootAbsoluteGlobs","routesPrefix","toRootAbsolutePrefix","serverOnlyRouteFiles","base","globs","fileName","stylesFile","resolvedStylesFile","existsSync","transformDocument","createDevSsrOptions","match","renderOptions","renderStreamingPageResponse","html","renderPageDocument","nonce","shieldNonce","shielded","shieldViteNonceTargets","replaceNonceAttribute","lowerHtml","cursor","output","tagStart","commentEnd","tagEnd","findHtmlTagEnd","openingTag","addNonceAttribute","closeStart","quote","index","character","insertion","current","contentType","csp","withScriptNonce","addCspSource","withStyleNonce","allowsUnsafeInline","directiveNames","fallbackDirectiveName","directives","directive","directiveIndex","findCspDirectiveIndex","defaultDirective","currentName","currentSources","updatedDirective","sources","DEV_MANIFEST","carrier","cached","createRouteManifest","createDevRouteImporters","warnedRoots","fallback","missingRootNotFoundMessage","join","routesDirOption","files","pageRoute","findPageRouteFile","missingRootNotFoundBuildMessage","declaresPageRoute","readFile","PACKAGE_NAME_PATTERN","DEMIURGE_NAMED_IMPORT","locals","binding","body","notFoundFile","entrySrc","lang","links","metadata","scripts","title","renderDocument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wM,GACpB1I,GACAhD,GACA;AACA,QAAMgM,IAAQ,MAAM/M,EAAee,CAAS,GACtChB,IAAwC,CAAA;AAE9C,aAAWE,KAAQ8M,GAAO;AACxB,UAAMoB,IAAWC,GAAWrN,GAAWd,CAAI;AAC3C,IAAAF,EAAOoO,CAAQ,IAAI,YAChB,MAAMpK,EAAO,cAAc9D,CAAI;AAAA,EACpC;AAEA,SAAOF;AACT;AAEA,eAAsB+E,GACpBL,GACAR,GACAnE,IAA2D,CAAA,GAC3D;AACA,QAAMuO,IAAM,IAAI,IAAIpK,EAAQ,GAAG;AAG/B,SAFmBqK,GAAe7J,EAAS,QAAQ4J,EAAI,QAAQ,IAMxD,MAAME,GAA0B9J,GAAUR,GAASnE,CAAO,IAHxD;AAIX;AAEA,eAAeE,EAAeW,GAAmB;AAM/C,UALgB,MAAMC,EAAQD,GAAW;AAAA,IACvC,WAAW;AAAA,IACX,eAAe;AAAA,EAAA,CAChB,GAGE,OAAO,CAACE,MAAUA,EAAM,OAAA,KAAY,UAAU,KAAKA,EAAM,IAAI,CAAC,EAC9D,IAAI,CAACA,MAAUC,EAAQD,EAAM,YAAYA,EAAM,IAAI,CAAC;AACzD;AAEA,SAASuN,GAAWrN,GAAmBd,GAAc;AAEnD,SAAO,YADcgB,EAASF,GAAWd,CAAI,EAAE,MAAMiB,CAAG,EAAE,KAAK,GAAG,CACnC;AACjC;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Plugin, type ViteDevServer } from "vite";
|
|
2
|
+
import type { LinkTag, ResolvedMetadata, ScriptTag } from "../document";
|
|
3
|
+
import { type RouteManifest } from "../router";
|
|
4
|
+
import { handleRequestWithManifest } from "../server";
|
|
5
|
+
import { type RouteImporter } from "../route";
|
|
6
|
+
export type DemiurgeVitePluginOptions = {
|
|
7
|
+
document?: {
|
|
8
|
+
lang?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
};
|
|
11
|
+
routesDir?: string;
|
|
12
|
+
styles?: false | string;
|
|
13
|
+
typedRoutes?: boolean | {
|
|
14
|
+
outputFile?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare function demiurge(options?: DemiurgeVitePluginOptions): Plugin;
|
|
18
|
+
export declare function stripClientPageData(code: string): string;
|
|
19
|
+
export declare function createClientEntrySource(root: string, options?: DemiurgeVitePluginOptions): string;
|
|
20
|
+
export declare function createServerEntrySource(root: string, options?: DemiurgeVitePluginOptions): string;
|
|
21
|
+
export declare function assertRootNotFoundRoute(root: string, options?: DemiurgeVitePluginOptions): Promise<void>;
|
|
22
|
+
export declare function declaresPageRoute(source: string): boolean;
|
|
23
|
+
export declare function missingRootNotFoundBuildMessage(routesDir: string, pageRoute: string): string;
|
|
24
|
+
export declare function missingRootNotFoundMessage(notFoundFile: string): string;
|
|
25
|
+
export declare function createDocumentHtml({ entrySrc, lang, links, metadata, nonce, scripts, styles, title, }: {
|
|
26
|
+
entrySrc: string;
|
|
27
|
+
lang?: string;
|
|
28
|
+
links?: LinkTag[];
|
|
29
|
+
metadata?: ResolvedMetadata;
|
|
30
|
+
nonce?: string;
|
|
31
|
+
scripts?: ScriptTag[];
|
|
32
|
+
styles?: string[];
|
|
33
|
+
title?: string;
|
|
34
|
+
}): string;
|
|
35
|
+
export declare function createDevRouteImporters(server: ViteDevServer, routesDir: string): Promise<Record<string, RouteImporter>>;
|
|
36
|
+
export declare function handleDevRequest(manifest: RouteManifest, request: Request, options?: Parameters<typeof handleRequestWithManifest>[2]): Promise<Response | "next">;
|
|
37
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,MAAM,EAEX,KAAK,aAAa,EACnB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,SAAS,EACV,MAAM,aAAa,CAAC;AAGr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KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,UAWA;AAwBD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,0CAYlB;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAM,8BAU9D"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,98 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@demiurgejs/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A React framework for secure routing, server rendering, and framework-managed HTML documents.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "North Shore Software Labs",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/NorthShoreSoftwareLabs/demiurge.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/NorthShoreSoftwareLabs/demiurge#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/NorthShoreSoftwareLabs/demiurge/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react",
|
|
18
|
+
"framework",
|
|
19
|
+
"router",
|
|
20
|
+
"ssr",
|
|
21
|
+
"vite",
|
|
22
|
+
"node"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./internal/testing": {
|
|
36
|
+
"types": "./dist/internal/testing.d.ts",
|
|
37
|
+
"default": "./dist/internal/testing.js"
|
|
38
|
+
},
|
|
39
|
+
"./data/testing": {
|
|
40
|
+
"types": "./dist/data/testing.d.ts",
|
|
41
|
+
"default": "./dist/data/testing.js"
|
|
42
|
+
},
|
|
43
|
+
"./vite": {
|
|
44
|
+
"types": "./dist/vite/index.d.ts",
|
|
45
|
+
"default": "./dist/vite/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./node": {
|
|
48
|
+
"types": "./dist/node/index.d.ts",
|
|
49
|
+
"default": "./dist/node/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./static": {
|
|
52
|
+
"types": "./dist/static/index.d.ts",
|
|
53
|
+
"default": "./dist/static/index.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
58
|
+
"dev": "vite build --watch",
|
|
59
|
+
"coverage": "vitest run --coverage",
|
|
60
|
+
"prepack": "pnpm build",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"typecheck": "tsc --noEmit"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=22.13.0"
|
|
66
|
+
},
|
|
6
67
|
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
68
|
+
"access": "public",
|
|
69
|
+
"provenance": true
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"react": "^19.0.0",
|
|
73
|
+
"react-dom": "^19.0.0",
|
|
74
|
+
"vite": "^6.0.7"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"vite": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@testing-library/react": "^16.3.2",
|
|
83
|
+
"@types/node": "^22.13.0",
|
|
84
|
+
"@types/react": "^19.0.2",
|
|
85
|
+
"@types/react-dom": "^19.0.2",
|
|
86
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
87
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
88
|
+
"jsdom": "^30.0.1",
|
|
89
|
+
"react": "^19.0.0",
|
|
90
|
+
"react-dom": "^19.0.0",
|
|
91
|
+
"typescript": "^5.7.2",
|
|
92
|
+
"vite": "^6.0.7",
|
|
93
|
+
"vitest": "^4.1.10"
|
|
94
|
+
},
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"magic-string": "^0.30.21"
|
|
8
97
|
}
|
|
9
98
|
}
|