nukejs 0.0.11 → 0.0.13

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.
Files changed (77) hide show
  1. package/README.md +147 -0
  2. package/dist/Link.js +0 -1
  3. package/dist/app.js +0 -1
  4. package/dist/build-common.js +64 -14
  5. package/dist/build-node.js +63 -5
  6. package/dist/build-vercel.js +76 -9
  7. package/dist/builder.js +32 -4
  8. package/dist/bundle.js +47 -4
  9. package/dist/bundler.js +0 -1
  10. package/dist/component-analyzer.js +0 -1
  11. package/dist/config.js +0 -1
  12. package/dist/hmr-bundle.js +10 -1
  13. package/dist/hmr.js +7 -1
  14. package/dist/html-store.js +0 -1
  15. package/dist/http-server.js +0 -1
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +0 -1
  18. package/dist/logger.js +0 -1
  19. package/dist/metadata.js +0 -1
  20. package/dist/middleware-loader.js +0 -1
  21. package/dist/middleware.example.js +0 -1
  22. package/dist/middleware.js +0 -1
  23. package/dist/renderer.js +3 -9
  24. package/dist/request-store.js +0 -1
  25. package/dist/router.js +0 -1
  26. package/dist/ssr.js +73 -16
  27. package/dist/use-html.js +0 -1
  28. package/dist/use-request.js +0 -1
  29. package/dist/use-router.js +0 -1
  30. package/dist/utils.js +0 -1
  31. package/package.json +1 -1
  32. package/dist/Link.js.map +0 -7
  33. package/dist/app.d.ts +0 -19
  34. package/dist/app.js.map +0 -7
  35. package/dist/build-common.d.ts +0 -178
  36. package/dist/build-common.js.map +0 -7
  37. package/dist/build-node.d.ts +0 -15
  38. package/dist/build-node.js.map +0 -7
  39. package/dist/build-vercel.d.ts +0 -19
  40. package/dist/build-vercel.js.map +0 -7
  41. package/dist/builder.d.ts +0 -11
  42. package/dist/builder.js.map +0 -7
  43. package/dist/bundle.js.map +0 -7
  44. package/dist/bundler.d.ts +0 -58
  45. package/dist/bundler.js.map +0 -7
  46. package/dist/component-analyzer.d.ts +0 -75
  47. package/dist/component-analyzer.js.map +0 -7
  48. package/dist/config.d.ts +0 -35
  49. package/dist/config.js.map +0 -7
  50. package/dist/hmr-bundle.d.ts +0 -25
  51. package/dist/hmr-bundle.js.map +0 -7
  52. package/dist/hmr.d.ts +0 -55
  53. package/dist/hmr.js.map +0 -7
  54. package/dist/html-store.js.map +0 -7
  55. package/dist/http-server.d.ts +0 -92
  56. package/dist/http-server.js.map +0 -7
  57. package/dist/index.js.map +0 -7
  58. package/dist/logger.js.map +0 -7
  59. package/dist/metadata.d.ts +0 -51
  60. package/dist/metadata.js.map +0 -7
  61. package/dist/middleware-loader.d.ts +0 -50
  62. package/dist/middleware-loader.js.map +0 -7
  63. package/dist/middleware.d.ts +0 -22
  64. package/dist/middleware.example.d.ts +0 -8
  65. package/dist/middleware.example.js.map +0 -7
  66. package/dist/middleware.js.map +0 -7
  67. package/dist/renderer.d.ts +0 -44
  68. package/dist/renderer.js.map +0 -7
  69. package/dist/request-store.js.map +0 -7
  70. package/dist/router.d.ts +0 -92
  71. package/dist/router.js.map +0 -7
  72. package/dist/ssr.d.ts +0 -46
  73. package/dist/ssr.js.map +0 -7
  74. package/dist/use-html.js.map +0 -7
  75. package/dist/use-request.js.map +0 -7
  76. package/dist/use-router.js.map +0 -7
  77. package/dist/utils.js.map +0 -7
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/build-common.ts"],
4
- "sourcesContent": ["/**\r\n * build-common.ts \u2014 Shared Build Logic\r\n *\r\n * Used by both build-node.ts and build-vercel.ts.\r\n *\r\n * Exports:\r\n * \u2014 types : AnalyzedRoute, ServerPage, BuiltPage,\r\n * PageAdapterOptions, PageBundleOptions\r\n * \u2014 utility helpers : walkFiles, analyzeFile, isServerComponent,\r\n * findPageLayouts, extractDefaultExportName\r\n * \u2014 collection : collectServerPages, collectGlobalClientRegistry,\r\n * buildPerPageRegistry\r\n * \u2014 template codegen : makeApiAdapterSource, makePageAdapterSource\r\n * \u2014 bundle ops : bundleApiHandler, bundlePageHandler,\r\n * bundleClientComponents, buildPages,\r\n * buildCombinedBundle, copyPublicFiles\r\n */\r\n\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport { randomBytes } from 'node:crypto';\r\nimport { fileURLToPath, pathToFileURL } from 'url';\r\nimport { build } from 'esbuild';\r\nimport { findClientComponentsInTree } from './component-analyzer';\r\n\r\n// \u2500\u2500\u2500 Node built-in externals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * All Node.js built-in module names.\r\n * Used as the `external` list when bundling for Node so esbuild never tries\r\n * to inline them, which would produce broken `require()` shims in ESM output.\r\n */\r\nconst NODE_BUILTINS = [\r\n 'node:*',\r\n 'http', 'https', 'fs', 'path', 'url', 'crypto', 'stream', 'buffer',\r\n 'events', 'util', 'os', 'net', 'tls', 'child_process', 'worker_threads',\r\n 'cluster', 'dgram', 'dns', 'readline', 'zlib', 'assert', 'module',\r\n 'perf_hooks', 'string_decoder', 'timers', 'async_hooks', 'v8', 'vm',\r\n];\r\n\r\n// \u2500\u2500\u2500 Types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nexport interface AnalyzedRoute {\r\n /** Regex string matching the URL path, e.g. '^/users/([^/]+)$' */\r\n srcRegex: string;\r\n /** Names of captured groups in srcRegex order */\r\n paramNames: string[];\r\n /**\r\n * Subset of paramNames that are catch-all ([...slug] or [[...path]]).\r\n * Their runtime values are string[] not string.\r\n */\r\n catchAllNames: string[];\r\n /** Function namespace path, e.g. '/api/users' or '/page/about' */\r\n funcPath: string;\r\n specificity: number;\r\n}\r\n\r\nexport interface ServerPage extends AnalyzedRoute {\r\n absPath: string;\r\n}\r\n\r\nexport interface BuiltPage extends ServerPage {\r\n bundleText: string;\r\n}\r\n\r\n// \u2500\u2500\u2500 File walker \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nexport function walkFiles(dir: string, base: string = dir): string[] {\r\n if (!fs.existsSync(dir)) return [];\r\n const results: string[] = [];\r\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\r\n const full = path.join(dir, entry.name);\r\n if (entry.isDirectory()) {\r\n results.push(...walkFiles(full, base));\r\n } else if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) {\r\n results.push(path.relative(base, full));\r\n }\r\n }\r\n return results;\r\n}\r\n\r\n// \u2500\u2500\u2500 Route analysis \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Parses dynamic-route segments from a relative file path and returns a regex,\r\n * captured param names, catch-all param names, a function path, and a\r\n * specificity score.\r\n *\r\n * Supported patterns per segment:\r\n * [[...name]] optional catch-all \u2192 regex (.*) \u2192 string[]\r\n * [...name] required catch-all \u2192 regex (.+) \u2192 string[]\r\n * [[name]] optional single \u2192 regex ([^/]*)? \u2192 string\r\n * [name] required single \u2192 regex ([^/]+) \u2192 string\r\n * literal static \u2192 escaped literal\r\n *\r\n * @param relPath Relative path from the dir root (e.g. 'users/[id].tsx').\r\n * @param prefix Namespace for funcPath ('api' | 'page').\r\n */\r\nexport function analyzeFile(relPath: string, prefix = 'api'): AnalyzedRoute {\r\n const normalized = relPath.replace(/\\\\/g, '/').replace(/\\.(tsx?)$/, '');\r\n let segments = normalized.split('/');\r\n if (segments.at(-1) === 'index') segments = segments.slice(0, -1);\r\n\r\n const paramNames: string[] = [];\r\n const catchAllNames: string[] = [];\r\n const regexParts: string[] = [];\r\n let specificity = 0;\r\n\r\n for (const seg of segments) {\r\n const optCatchAll = seg.match(/^\\[\\[\\.\\.\\.(.+)\\]\\]$/);\r\n if (optCatchAll) {\r\n paramNames.push(optCatchAll[1]);\r\n catchAllNames.push(optCatchAll[1]);\r\n regexParts.push('(.*)');\r\n specificity += 1;\r\n continue;\r\n }\r\n const catchAll = seg.match(/^\\[\\.\\.\\.(.+)\\]$/);\r\n if (catchAll) {\r\n paramNames.push(catchAll[1]);\r\n catchAllNames.push(catchAll[1]);\r\n regexParts.push('(.+)');\r\n specificity += 10;\r\n continue;\r\n }\r\n const optDynamic = seg.match(/^\\[\\[([^.][^\\]]*)\\]\\]$/);\r\n if (optDynamic) {\r\n paramNames.push(optDynamic[1]);\r\n regexParts.push('__OPT__([^/]*)'); // marker \u2014 resolved below\r\n specificity += 30;\r\n continue;\r\n }\r\n const dynamic = seg.match(/^\\[(.+)\\]$/);\r\n if (dynamic) {\r\n paramNames.push(dynamic[1]);\r\n regexParts.push('([^/]+)');\r\n specificity += 100;\r\n continue;\r\n }\r\n regexParts.push(seg.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'));\r\n specificity += 1000;\r\n }\r\n\r\n // Build the regex string.\r\n // __OPT__(...) markers indicate optional single segments where the preceding\r\n // slash must also be optional (e.g. users/[[id]] should match /users).\r\n let srcRegex: string;\r\n if (segments.length === 0) {\r\n srcRegex = '^/$';\r\n } else {\r\n let body = '';\r\n for (let i = 0; i < regexParts.length; i++) {\r\n const part = regexParts[i];\r\n if (part.startsWith('__OPT__')) {\r\n const cap = part.slice(7);\r\n // At position 0, ^/ already provides the leading slash\r\n body += i === 0 ? cap : `(?:/${cap})?`;\r\n } else {\r\n body += (i === 0 ? '' : '/') + part;\r\n }\r\n }\r\n srcRegex = '^/' + body + '$';\r\n }\r\n\r\n const funcSegments = normalized.split('/');\r\n if (funcSegments.at(-1) === 'index') funcSegments.pop();\r\n const funcPath = funcSegments.length === 0\r\n ? `/${prefix}/_index`\r\n : `/${prefix}/` + funcSegments.join('/');\r\n\r\n return { srcRegex, paramNames, catchAllNames, funcPath, specificity };\r\n}\r\n\r\n// \u2500\u2500\u2500 Server-component detection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Returns true when a file does NOT begin with a \"use client\" directive,\r\n * i.e. it is a server component.\r\n */\r\nexport function isServerComponent(filePath: string): boolean {\r\n const content = fs.readFileSync(filePath, 'utf-8');\r\n for (const line of content.split('\\n').slice(0, 5)) {\r\n const trimmed = line.trim();\r\n if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('/*')) continue;\r\n if (/^[\"']use client[\"'];?$/.test(trimmed)) return false;\r\n break;\r\n }\r\n return true;\r\n}\r\n\r\n// \u2500\u2500\u2500 Layout discovery \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Walks from the pages root to the directory containing `routeFilePath` and\r\n * returns every layout.tsx found, in outermost-first order.\r\n */\r\nexport function findPageLayouts(routeFilePath: string, pagesDir: string): string[] {\r\n const layouts: string[] = [];\r\n\r\n const rootLayout = path.join(pagesDir, 'layout.tsx');\r\n if (fs.existsSync(rootLayout)) layouts.push(rootLayout);\r\n\r\n const relativePath = path.relative(pagesDir, path.dirname(routeFilePath));\r\n if (!relativePath || relativePath === '.') return layouts;\r\n\r\n const segments = relativePath.split(path.sep).filter(Boolean);\r\n for (let i = 1; i <= segments.length; i++) {\r\n const layoutPath = path.join(pagesDir, ...segments.slice(0, i), 'layout.tsx');\r\n if (fs.existsSync(layoutPath)) layouts.push(layoutPath);\r\n }\r\n\r\n return layouts;\r\n}\r\n\r\n/**\r\n * Extracts the identifier used as the default export from a component file.\r\n * Returns null when no default export is found.\r\n *\r\n * Handles three formats so that components compiled by esbuild are recognised\r\n * alongside hand-written source files:\r\n * 1. Source: `export default function Foo` / `export default Foo`\r\n * 2. esbuild: `var Foo_default = Foo` (compiled arrow-function component)\r\n * 3. Re-export: `export { Foo as default }`\r\n */\r\nexport function extractDefaultExportName(filePath: string): string | null {\r\n const content = fs.readFileSync(filePath, 'utf-8');\r\n\r\n // Format 1 \u2013 source: `export default function Foo` or `export default Foo`\r\n let m = content.match(/export\\s+default\\s+(?:function\\s+)?(\\w+)/);\r\n if (m?.[1]) return m[1];\r\n\r\n // Format 2 \u2013 esbuild compiled: `var Foo_default = Foo`\r\n m = content.match(/var\\s+\\w+_default\\s*=\\s*(\\w+)/);\r\n if (m?.[1]) return m[1];\r\n\r\n // Format 3 \u2013 explicit re-export: `export { Foo as default }`\r\n m = content.match(/export\\s*\\{[^}]*\\b(\\w+)\\s+as\\s+default\\b[^}]*\\}/);\r\n if (m?.[1] && !m[1].endsWith('_default')) return m[1];\r\n\r\n return null;\r\n}\r\n\r\n// \u2500\u2500\u2500 Server page collection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Returns all server-component pages inside `pagesDir`, sorted most-specific\r\n * first so precise routes shadow catch-alls in routers.\r\n * layout.tsx files and \"use client\" files are excluded.\r\n */\r\nexport function collectServerPages(pagesDir: string): ServerPage[] {\r\n if (!fs.existsSync(pagesDir)) return [];\r\n return walkFiles(pagesDir)\r\n .filter(relPath => {\r\n if (path.basename(relPath, path.extname(relPath)) === 'layout') return false;\r\n return isServerComponent(path.join(pagesDir, relPath));\r\n })\r\n .map(relPath => ({\r\n ...analyzeFile(relPath, 'page'),\r\n absPath: path.join(pagesDir, relPath),\r\n }))\r\n .sort((a, b) => b.specificity - a.specificity);\r\n}\r\n\r\n/**\r\n * Walks every server page and its layout chain to collect all client component\r\n * IDs reachable anywhere in the app.\r\n */\r\nexport function collectGlobalClientRegistry(\r\n serverPages: ServerPage[],\r\n pagesDir: string,\r\n): Map<string, string> {\r\n const registry = new Map<string, string>();\r\n for (const { absPath } of serverPages) {\r\n for (const [id, p] of findClientComponentsInTree(absPath, pagesDir))\r\n registry.set(id, p);\r\n for (const layoutPath of findPageLayouts(absPath, pagesDir))\r\n for (const [id, p] of findClientComponentsInTree(layoutPath, pagesDir))\r\n registry.set(id, p);\r\n }\r\n return registry;\r\n}\r\n\r\n// \u2500\u2500\u2500 Per-page registry \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Builds the per-page client component registry (page + its layout chain)\r\n * and returns both the id\u2192path map and the name\u2192id map needed by\r\n * bundlePageHandler.\r\n */\r\nexport function buildPerPageRegistry(\r\n absPath: string,\r\n layoutPaths: string[],\r\n pagesDir: string,\r\n): { registry: Map<string, string>; clientComponentNames: Record<string, string> } {\r\n const registry = new Map<string, string>();\r\n\r\n for (const [id, p] of findClientComponentsInTree(absPath, pagesDir))\r\n registry.set(id, p);\r\n for (const lp of layoutPaths)\r\n for (const [id, p] of findClientComponentsInTree(lp, pagesDir))\r\n registry.set(id, p);\r\n\r\n const clientComponentNames: Record<string, string> = {};\r\n for (const [id, filePath] of registry) {\r\n const name = extractDefaultExportName(filePath);\r\n if (name) clientComponentNames[name] = id;\r\n }\r\n\r\n return { registry, clientComponentNames };\r\n}\r\n\r\n// \u2500\u2500\u2500 High-level page builder \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Runs both passes of the page build:\r\n *\r\n * Pass 1 \u2014 bundles all client components to `staticDir/__client-component/`\r\n * and collects pre-rendered HTML for each.\r\n * Pass 2 \u2014 bundles every server-component page into a self-contained ESM\r\n * handler and returns the results as `BuiltPage[]`.\r\n */\r\nexport async function buildPages(\r\n pagesDir: string,\r\n staticDir: string,\r\n): Promise<BuiltPage[]> {\r\n const serverPages = collectServerPages(pagesDir);\r\n\r\n if (fs.existsSync(pagesDir) && walkFiles(pagesDir).length > 0 && serverPages.length === 0) {\r\n console.warn(`\u26A0 Pages found in ${pagesDir} but none are server components`);\r\n }\r\n\r\n if (serverPages.length === 0) return [];\r\n\r\n const globalRegistry = collectGlobalClientRegistry(serverPages, pagesDir);\r\n const prerenderedHtml = await bundleClientComponents(globalRegistry, pagesDir, staticDir);\r\n const prerenderedRecord = Object.fromEntries(prerenderedHtml);\r\n\r\n const builtPages: BuiltPage[] = [];\r\n\r\n for (const page of serverPages) {\r\n console.log(` building ${page.absPath} \u2192 ${page.funcPath} [page]`);\r\n\r\n const layoutPaths = findPageLayouts(page.absPath, pagesDir);\r\n const { registry, clientComponentNames } = buildPerPageRegistry(page.absPath, layoutPaths, pagesDir);\r\n\r\n const bundleText = await bundlePageHandler({\r\n absPath: page.absPath,\r\n pagesDir,\r\n clientComponentNames,\r\n allClientIds: [...registry.keys()],\r\n layoutPaths,\r\n prerenderedHtml: prerenderedRecord,\r\n routeParamNames: page.paramNames,\r\n catchAllNames: page.catchAllNames,\r\n });\r\n\r\n builtPages.push({ ...page, bundleText });\r\n }\r\n\r\n return builtPages;\r\n}\r\n\r\n// \u2500\u2500\u2500 API adapter template \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Returns the TypeScript source for a thin HTTP adapter that wraps an API\r\n * route module and exposes a single `handler(req, res)` default export.\r\n */\r\nexport function makeApiAdapterSource(handlerFilename: string): string {\r\n return `\\\r\nimport type { IncomingMessage, ServerResponse } from 'http';\r\nimport * as mod from ${JSON.stringify('./' + handlerFilename)};\r\n\r\nfunction enhance(res: ServerResponse) {\r\n (res as any).json = function (data: any, status = 200) {\r\n this.statusCode = status;\r\n this.setHeader('Content-Type', 'application/json');\r\n this.end(JSON.stringify(data));\r\n };\r\n (res as any).status = function (code: number) { this.statusCode = code; return this; };\r\n return res;\r\n}\r\n\r\nasync function parseBody(req: IncomingMessage): Promise<any> {\r\n return new Promise((resolve, reject) => {\r\n let body = '';\r\n req.on('data', chunk => { body += chunk.toString(); });\r\n req.on('end', () => {\r\n try {\r\n resolve(body && req.headers['content-type']?.includes('application/json')\r\n ? JSON.parse(body) : body);\r\n } catch (e) { reject(e); }\r\n });\r\n req.on('error', reject);\r\n });\r\n}\r\n\r\nexport default async function handler(req: IncomingMessage, res: ServerResponse) {\r\n const method = (req.method || 'GET').toUpperCase();\r\n const apiRes = enhance(res);\r\n const apiReq = req as any;\r\n\r\n apiReq.body = await parseBody(req);\r\n // In production, route dynamic segments are injected as query-string keys by\r\n // the server entry, so params and query share the same parsed URL values.\r\n const qs = Object.fromEntries(new URL(req.url || '/', 'http://localhost').searchParams);\r\n apiReq.query = qs;\r\n apiReq.params = qs;\r\n\r\n const fn = (mod as any)[method] ?? (mod as any).default;\r\n if (typeof fn !== 'function') {\r\n (apiRes as any).json({ error: \\`Method \\${method} not allowed\\` }, 405);\r\n return;\r\n }\r\n await fn(apiReq, apiRes);\r\n}\r\n`;\r\n}\r\n\r\n// \u2500\u2500\u2500 Page adapter template \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nexport interface PageAdapterOptions {\r\n /** e.g. './home.tsx' \u2014 relative import for the page default export */\r\n pageImport: string;\r\n /** Newline-joined import statements for layout components */\r\n layoutImports: string;\r\n /** function-name \u2192 cc_id map, computed at build time */\r\n clientComponentNames: Record<string, string>;\r\n /** All client component IDs reachable from this page */\r\n allClientIds: string[];\r\n /** Comma-separated list of __layout_N__ identifiers */\r\n layoutArrayItems: string;\r\n /** Pre-rendered HTML per client component ID, computed at build time */\r\n prerenderedHtml: Record<string, string>;\r\n /**\r\n * All dynamic route param names for this page (e.g. ['id', 'slug']).\r\n * Used to distinguish route segments from real query-string params at runtime.\r\n */\r\n routeParamNames: string[];\r\n /** Subset of routeParamNames whose values are string[] (catch-all segments) */\r\n catchAllNames: string[];\r\n}\r\n\r\n/**\r\n * Returns the TypeScript source for a fully self-contained page handler.\r\n *\r\n * The adapter:\r\n * \u2022 Inlines the html-store so useHtml() works without external deps.\r\n * \u2022 Contains an async recursive renderer for server + client components.\r\n * \u2022 Client components are identified via the pre-computed CLIENT_COMPONENTS\r\n * map \u2014 no fs.readFileSync at runtime.\r\n * \u2022 Emits the full HTML document including the __n_data blob and bootstrap.\r\n */\r\nexport function makePageAdapterSource(opts: PageAdapterOptions): string {\r\n const {\r\n pageImport, layoutImports, clientComponentNames, allClientIds,\r\n layoutArrayItems, prerenderedHtml, routeParamNames, catchAllNames,\r\n } = opts;\r\n\r\n return `\\\r\nimport type { IncomingMessage, ServerResponse } from 'http';\r\nimport { createElement as __createElement__ } from 'react';\r\nimport { renderToString as __renderToString__ } from 'react-dom/server';\r\nimport * as __page__ from ${pageImport};\r\n${layoutImports}\r\n\r\nconst CLIENT_COMPONENTS: Record<string, string> = ${JSON.stringify(clientComponentNames)};\r\nconst ALL_CLIENT_IDS: string[] = ${JSON.stringify(allClientIds)};\r\nconst PRERENDERED_HTML: Record<string, string> = ${JSON.stringify(prerenderedHtml)};\r\n// ROUTE_PARAM_NAMES: the dynamic segments baked into this page's URL pattern.\r\n// Used to separate them from real user-supplied query params at runtime.\r\nconst ROUTE_PARAM_NAMES = new Set<string>(${JSON.stringify(routeParamNames)});\r\nconst CATCH_ALL_NAMES = new Set<string>(${JSON.stringify(catchAllNames)});\r\n\r\n// \u2500\u2500\u2500 html-store (inlined) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\ntype TitleValue = string | ((prev: string) => string);\r\ninterface HtmlStore {\r\n titleOps: TitleValue[];\r\n htmlAttrs: Record<string, string | undefined>;\r\n bodyAttrs: Record<string, string | undefined>;\r\n meta: Record<string, string | undefined>[];\r\n link: Record<string, string | undefined>[];\r\n script: Record<string, any>[];\r\n style: { content?: string; media?: string }[];\r\n}\r\nconst __STORE_KEY__ = Symbol.for('__nukejs_html_store__');\r\nconst __getStore = (): HtmlStore | null => (globalThis as any)[__STORE_KEY__] ?? null;\r\nconst __setStore = (s: HtmlStore | null): void => { (globalThis as any)[__STORE_KEY__] = s; };\r\nconst __emptyStore = (): HtmlStore =>\r\n ({ titleOps: [], htmlAttrs: {}, bodyAttrs: {}, meta: [], link: [], script: [], style: [] });\r\nasync function runWithHtmlStore(fn: () => Promise<void>): Promise<HtmlStore> {\r\n __setStore(__emptyStore());\r\n try { await fn(); return { ...(__getStore() ?? __emptyStore()) }; }\r\n finally { __setStore(null); }\r\n}\r\nfunction resolveTitle(ops: TitleValue[], fallback = ''): string {\r\n let t = fallback;\r\n for (let i = ops.length - 1; i >= 0; i--) {\r\n const op = ops[i]; t = typeof op === 'string' ? op : op(t);\r\n }\r\n return t;\r\n}\r\n\r\n// \u2500\u2500\u2500 request-store (inlined) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nconst SENSITIVE_HEADERS = new Set([\r\n 'cookie','authorization','proxy-authorization','set-cookie','x-api-key',\r\n]);\r\n// Flattens multi-value headers to strings; keeps all headers including credentials.\r\nfunction normaliseHeaders(raw: Record<string, string | string[] | undefined>): Record<string, string> {\r\n const out: Record<string, string> = {};\r\n for (const [k, v] of Object.entries(raw)) {\r\n if (v === undefined) continue;\r\n out[k] = Array.isArray(v) ? v.join(', ') : v;\r\n }\r\n return out;\r\n}\r\n// Same as normaliseHeaders but strips credentials before embedding in HTML.\r\nfunction sanitiseHeaders(raw: Record<string, string | string[] | undefined>): Record<string, string> {\r\n const out: Record<string, string> = {};\r\n for (const [k, v] of Object.entries(raw)) {\r\n if (SENSITIVE_HEADERS.has(k.toLowerCase()) || v === undefined) continue;\r\n out[k] = Array.isArray(v) ? v.join(', ') : v;\r\n }\r\n return out;\r\n}\r\nconst __REQ_KEY__ = Symbol.for('__nukejs_request_store__');\r\nconst __getReq = () => (globalThis as any)[__REQ_KEY__] ?? null;\r\nconst __setReq = (v: any) => { (globalThis as any)[__REQ_KEY__] = v; };\r\nasync function runWithRequestStore<T>(ctx: any, fn: () => Promise<T>): Promise<T> {\r\n __setReq(ctx);\r\n try { return await fn(); } finally { __setReq(null); }\r\n}\r\n\r\n// \u2500\u2500\u2500 HTML helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nfunction escapeHtml(s: string): string {\r\n return String(s)\r\n .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\r\n .replace(/\"/g, '&quot;').replace(/'/g, '&#039;');\r\n}\r\nfunction escapeAttr(s: string): string {\r\n return String(s).replace(/&/g, '&amp;').replace(/\"/g, '&quot;');\r\n}\r\nfunction renderAttrs(attrs: Record<string, string | boolean | undefined>): string {\r\n return Object.entries(attrs)\r\n .filter(([, v]) => v !== undefined && v !== false)\r\n .map(([k, v]) => v === true ? k : \\`\\${k}=\"\\${escapeAttr(String(v))}\"\\`)\r\n .join(' ');\r\n}\r\nfunction openTag(tag: string, attrs: Record<string, string | undefined>): string {\r\n const s = renderAttrs(attrs as Record<string, string | boolean | undefined>);\r\n return s ? \\`<\\${tag} \\${s}>\\` : \\`<\\${tag}>\\`;\r\n}\r\nfunction renderMetaTag(tag: Record<string, string | undefined>): string {\r\n const key = (k: string) => k === 'httpEquiv' ? 'http-equiv' : k;\r\n const attrs: Record<string, string | undefined> = {};\r\n for (const [k, v] of Object.entries(tag)) if (v !== undefined) attrs[key(k)] = v;\r\n return \\` <meta \\${renderAttrs(attrs as any)} />\\`;\r\n}\r\nfunction renderLinkTag(tag: Record<string, string | undefined>): string {\r\n const key = (k: string) => k === 'hrefLang' ? 'hreflang' : k === 'crossOrigin' ? 'crossorigin' : k;\r\n const attrs: Record<string, string | undefined> = {};\r\n for (const [k, v] of Object.entries(tag)) if (v !== undefined) attrs[key(k)] = v;\r\n return \\` <link \\${renderAttrs(attrs as any)} />\\`;\r\n}\r\nfunction renderScriptTag(tag: any): string {\r\n const s = renderAttrs({ src: tag.src, type: tag.type, crossorigin: tag.crossOrigin,\r\n integrity: tag.integrity, defer: tag.defer, async: tag.async, nomodule: tag.noModule });\r\n return \\` \\${s ? \\`<script \\${s}>\\` : '<script>'}\\${tag.src ? '' : (tag.content ?? '')}</script>\\`;\r\n}\r\nfunction renderStyleTag(tag: any): string {\r\n const media = tag.media ? \\` media=\"\\${escapeAttr(tag.media)}\"\\` : '';\r\n return \\` <style\\${media}>\\${tag.content ?? ''}</style>\\`;\r\n}\r\n\r\n// \u2500\u2500\u2500 Renderer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nconst VOID_TAGS = new Set([\r\n 'area','base','br','col','embed','hr','img','input',\r\n 'link','meta','param','source','track','wbr',\r\n]);\r\n\r\n// \u2500\u2500\u2500 Wrapper attribute helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nfunction isWrapperAttr(key: string): boolean {\r\n return (\r\n key === 'className' ||\r\n key === 'style' ||\r\n key === 'id' ||\r\n key.startsWith('data-') ||\r\n key.startsWith('aria-')\r\n );\r\n}\r\nfunction splitWrapperAttrs(props: any): { wrapperAttrs: Record<string, any>; componentProps: Record<string, any> } {\r\n const wrapperAttrs: Record<string, any> = {};\r\n const componentProps: Record<string, any> = {};\r\n for (const [key, value] of Object.entries((props || {}) as Record<string, any>)) {\r\n if (isWrapperAttr(key)) wrapperAttrs[key] = value;\r\n else componentProps[key] = value;\r\n }\r\n return { wrapperAttrs, componentProps };\r\n}\r\nfunction buildWrapperAttrString(attrs: Record<string, any>): string {\r\n const parts = Object.entries(attrs)\r\n .map(([key, value]) => {\r\n if (key === 'className') key = 'class';\r\n if (key === 'style' && typeof value === 'object') {\r\n const css = Object.entries(value as Record<string, any>)\r\n .map(([p, val]) => \\`\\${p.replace(/[A-Z]/g, m => \\`-\\${m.toLowerCase()}\\`)}:\\${escapeHtml(String(val))}\\`)\r\n .join(';');\r\n return \\`style=\"\\${css}\"\\`;\r\n }\r\n if (typeof value === 'boolean') return value ? key : '';\r\n if (value == null) return '';\r\n return \\`\\${key}=\"\\${escapeHtml(String(value))}\"\\`;\r\n })\r\n .filter(Boolean);\r\n return parts.length ? ' ' + parts.join(' ') : '';\r\n}\r\n\r\nfunction serializeProps(value: any): any {\r\n if (typeof value === 'function') return undefined; // must come before the object check\r\n if (value == null || typeof value !== 'object') return value;\r\n if (Array.isArray(value)) return value.map(serializeProps).filter((v: any) => v !== undefined);\r\n if ((value as any).$$typeof) {\r\n const { type, props: p } = value as any;\r\n if (typeof type === 'string') return { __re: 'html', tag: type, props: serializeProps(p) };\r\n if (typeof type === 'function') {\r\n const cid = CLIENT_COMPONENTS[type.name];\r\n if (cid) return { __re: 'client', componentId: cid, props: serializeProps(p) };\r\n }\r\n return undefined;\r\n }\r\n const out: any = {};\r\n for (const [k, v] of Object.entries(value as Record<string, any>)) {\r\n const s = serializeProps(v);\r\n if (s !== undefined) out[k] = s;\r\n }\r\n return out;\r\n}\r\n\r\nasync function renderNode(node: any, hydrated: Set<string>): Promise<string> {\r\n if (node == null || typeof node === 'boolean') return '';\r\n if (typeof node === 'string') return escapeHtml(node);\r\n if (typeof node === 'number') return String(node);\r\n if (Array.isArray(node)) return (await Promise.all(node.map(n => renderNode(n, hydrated)))).join('');\r\n\r\n const { type, props } = node as { type: any; props: Record<string, any> };\r\n if (!type) return '';\r\n\r\n if (type === Symbol.for('react.fragment')) return renderNode(props?.children ?? null, hydrated);\r\n\r\n if (typeof type === 'string') {\r\n const { children, dangerouslySetInnerHTML, ...rest } = props || {};\r\n const attrParts: string[] = [];\r\n for (const [k, v] of Object.entries(rest as Record<string, any>)) {\r\n const name = k === 'className' ? 'class' : k === 'htmlFor' ? 'for' : k;\r\n if (typeof v === 'boolean') { if (v) attrParts.push(name); continue; }\r\n if (v == null) continue;\r\n if (k === 'style' && typeof v === 'object') {\r\n const css = Object.entries(v as Record<string, any>)\r\n .map(([p, val]) => \\`\\${p.replace(/[A-Z]/g, m => \\`-\\${m.toLowerCase()}\\`)}:\\${escapeHtml(String(val))}\\`)\r\n .join(';');\r\n attrParts.push(\\`style=\"\\${css}\"\\`);\r\n continue;\r\n }\r\n attrParts.push(\\`\\${name}=\"\\${escapeHtml(String(v))}\"\\`);\r\n }\r\n const attrStr = attrParts.length ? ' ' + attrParts.join(' ') : '';\r\n if (VOID_TAGS.has(type)) return \\`<\\${type}\\${attrStr} />\\`;\r\n const inner = dangerouslySetInnerHTML\r\n ? (dangerouslySetInnerHTML as any).__html\r\n : await renderNode(children ?? null, hydrated);\r\n return \\`<\\${type}\\${attrStr}>\\${inner}</\\${type}>\\`;\r\n }\r\n\r\n if (typeof type === 'function') {\r\n const clientId = CLIENT_COMPONENTS[type.name];\r\n if (clientId) {\r\n hydrated.add(clientId);\r\n const { wrapperAttrs, componentProps } = splitWrapperAttrs(props);\r\n const wrapperAttrStr = buildWrapperAttrString(wrapperAttrs);\r\n const serializedProps = serializeProps(componentProps ?? {});\r\n let ssrHtml: string;\r\n try {\r\n ssrHtml = __renderToString__(__createElement__(type as any, componentProps || {}));\r\n } catch {\r\n ssrHtml = PRERENDERED_HTML[clientId] ?? '';\r\n }\r\n return \\`<span data-hydrate-id=\"\\${clientId}\"\\${wrapperAttrStr} data-hydrate-props=\"\\${escapeHtml(JSON.stringify(serializedProps))}\">\\${ssrHtml}</span>\\`;\r\n }\r\n const instance = type.prototype?.isReactComponent ? new (type as any)(props) : null;\r\n return renderNode(instance ? instance.render() : await (type as Function)(props || {}), hydrated);\r\n }\r\n\r\n return '';\r\n}\r\n\r\n// \u2500\u2500\u2500 Layout wrapping \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nconst LAYOUT_COMPONENTS: Array<(props: any) => any> = [${layoutArrayItems}];\r\n\r\nfunction wrapWithLayouts(element: any): any {\r\n let el = element;\r\n for (let i = LAYOUT_COMPONENTS.length - 1; i >= 0; i--)\r\n el = { type: LAYOUT_COMPONENTS[i], props: { children: el }, key: null, ref: null };\r\n return el;\r\n}\r\n\r\n// \u2500\u2500\u2500 Handler \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nexport default async function handler(req: IncomingMessage, res: ServerResponse): Promise<void> {\r\n try {\r\n const parsed = new URL(req.url || '/', 'http://localhost');\r\n const url = req.url || '/';\r\n const pathname = parsed.pathname;\r\n\r\n // Route params are injected as query-string keys by the server entry.\r\n // Build 'params' only from known route segments, and 'query' from the rest.\r\n const params: Record<string, string | string[]> = {};\r\n ROUTE_PARAM_NAMES.forEach(k => {\r\n if (CATCH_ALL_NAMES.has(k)) {\r\n params[k] = parsed.searchParams.getAll(k);\r\n } else {\r\n const v = parsed.searchParams.get(k);\r\n if (v !== null) params[k] = v;\r\n }\r\n });\r\n\r\n const query: Record<string, string | string[]> = {};\r\n parsed.searchParams.forEach((_, k) => {\r\n if (!ROUTE_PARAM_NAMES.has(k)) {\r\n const all = parsed.searchParams.getAll(k);\r\n query[k] = all.length > 1 ? all : all[0];\r\n }\r\n });\r\n\r\n const rawHeaders = req.headers as Record<string, string | string[] | undefined>;\r\n // Full headers (including credentials) for server components via the request store.\r\n const normHeaders = normaliseHeaders(rawHeaders);\r\n // Stripped headers safe for embedding in the HTML document.\r\n const safeHeaders = sanitiseHeaders(rawHeaders);\r\n\r\n const hydrated = new Set<string>();\r\n // Merge query params into page props to match dev behaviour (ssr.ts mergedParams).\r\n const merged = { ...query, ...params } as any;\r\n const wrapped = wrapWithLayouts({ type: __page__.default, props: merged, key: null, ref: null });\r\n\r\n let appHtml = '';\r\n const store = await runWithRequestStore(\r\n { url, pathname, params, query, headers: normHeaders },\r\n () => runWithHtmlStore(async () => { appHtml = await renderNode(wrapped, hydrated); }),\r\n );\r\n\r\n const pageTitle = resolveTitle(store.titleOps, 'NukeJS');\r\n const headScripts = store.script.filter((s: any) => (s.position ?? 'head') === 'head');\r\n const bodyScripts = store.script.filter((s: any) => s.position === 'body');\r\n const headLines = [\r\n ' <meta charset=\"utf-8\" />',\r\n ' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />',\r\n \\` <title>\\${escapeHtml(pageTitle)}</title>\\`,\r\n ...(store.meta.length || store.link.length || store.style.length || headScripts.length ? [\r\n ' <!--n-head-->',\r\n ...store.meta.map(renderMetaTag),\r\n ...store.link.map(renderLinkTag),\r\n ...store.style.map(renderStyleTag),\r\n ...headScripts.map(renderScriptTag),\r\n ' <!--/n-head-->',\r\n ] : []),\r\n ];\r\n const bodyScriptLines = bodyScripts.length\r\n ? [' <!--n-body-scripts-->', ...bodyScripts.map(renderScriptTag), ' <!--/n-body-scripts-->']\r\n : [];\r\n const bodyScriptsHtml = bodyScriptLines.length ? '\\\\n' + bodyScriptLines.join('\\\\n') + '\\\\n' : '';\r\n\r\n const runtimeData = JSON.stringify({\r\n hydrateIds: [...hydrated], allIds: ALL_CLIENT_IDS, url, params,\r\n query, headers: safeHeaders, debug: 'silent',\r\n }).replace(/</g, '\\\\u003c').replace(/>/g, '\\\\u003e').replace(/&/g, '\\\\u0026');\r\n\r\n const html = \\`<!DOCTYPE html>\r\n\\${openTag('html', store.htmlAttrs)}\r\n<head>\r\n\\${headLines.join('\\\\n')}\r\n</head>\r\n\\${openTag('body', store.bodyAttrs)}\r\n <div id=\"app\">\\${appHtml}</div>\r\n\r\n <script id=\"__n_data\" type=\"application/json\">\\${runtimeData}</script>\r\n\r\n <script type=\"importmap\">\r\n {\r\n \"imports\": {\r\n \"react\": \"/__n.js\",\r\n \"react-dom/client\": \"/__n.js\",\r\n \"react/jsx-runtime\": \"/__n.js\",\r\n \"nukejs\": \"/__n.js\"\r\n }\r\n }\r\n </script>\r\n\r\n <script type=\"module\">\r\n const { initRuntime } = await import('nukejs');\r\n const data = JSON.parse(document.getElementById('__n_data').textContent);\r\n await initRuntime(data);\r\n </script>\r\n\\${bodyScriptsHtml}</body>\r\n</html>\\`;\r\n\r\n res.statusCode = 200;\r\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\r\n res.end(html);\r\n } catch (err: any) {\r\n console.error('[page render error]', err);\r\n res.statusCode = 500;\r\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\r\n res.end('Internal Server Error');\r\n }\r\n}\r\n`;\r\n}\r\n\r\n// \u2500\u2500\u2500 Bundle operations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Bundles an API route handler into a single self-contained ESM string.\r\n * node_modules are kept external \u2014 they exist at runtime on both Node and\r\n * Vercel (Vercel bundles them separately via the pages dispatcher).\r\n */\r\nexport async function bundleApiHandler(absPath: string): Promise<string> {\r\n const adapterName = `_api_adapter_${randomBytes(4).toString('hex')}.ts`;\r\n const adapterPath = path.join(path.dirname(absPath), adapterName);\r\n fs.writeFileSync(adapterPath, makeApiAdapterSource(path.basename(absPath)));\r\n\r\n let text: string;\r\n try {\r\n const result = await build({\r\n entryPoints: [adapterPath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'node',\r\n target: 'node20',\r\n packages: 'external',\r\n write: false,\r\n });\r\n text = result.outputFiles[0].text;\r\n } finally {\r\n fs.unlinkSync(adapterPath);\r\n }\r\n return text;\r\n}\r\n\r\nexport interface PageBundleOptions {\r\n absPath: string;\r\n pagesDir: string;\r\n clientComponentNames: Record<string, string>;\r\n allClientIds: string[];\r\n layoutPaths: string[];\r\n prerenderedHtml: Record<string, string>;\r\n routeParamNames: string[];\r\n catchAllNames: string[];\r\n}\r\n\r\n/**\r\n * Bundles a server-component page into a single self-contained ESM string.\r\n * All npm packages are kept external \u2014 the Node production server has\r\n * node_modules available at runtime.\r\n */\r\nexport async function bundlePageHandler(opts: PageBundleOptions): Promise<string> {\r\n const {\r\n absPath, clientComponentNames, allClientIds,\r\n layoutPaths, prerenderedHtml, routeParamNames, catchAllNames,\r\n } = opts;\r\n\r\n const adapterDir = path.dirname(absPath);\r\n const adapterPath = path.join(adapterDir, `_page_adapter_${randomBytes(4).toString('hex')}.ts`);\r\n\r\n const layoutImports = layoutPaths\r\n .map((lp, i) => {\r\n const rel = path.relative(adapterDir, lp).replace(/\\\\/g, '/');\r\n return `import __layout_${i}__ from ${JSON.stringify(rel.startsWith('.') ? rel : './' + rel)};`;\r\n })\r\n .join('\\n');\r\n\r\n fs.writeFileSync(adapterPath, makePageAdapterSource({\r\n pageImport: JSON.stringify('./' + path.basename(absPath)),\r\n layoutImports,\r\n clientComponentNames,\r\n allClientIds,\r\n layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(', '),\r\n prerenderedHtml,\r\n routeParamNames,\r\n catchAllNames,\r\n }));\r\n\r\n let text: string;\r\n try {\r\n const result = await build({\r\n entryPoints: [adapterPath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'node',\r\n target: 'node20',\r\n jsx: 'automatic',\r\n packages: 'external',\r\n external: NODE_BUILTINS,\r\n define: { 'process.env.NODE_ENV': '\"production\"' },\r\n write: false,\r\n });\r\n text = result.outputFiles[0].text;\r\n } finally {\r\n fs.unlinkSync(adapterPath);\r\n }\r\n return text;\r\n}\r\n\r\n/**\r\n * Bundles every client component in `globalRegistry` to\r\n * `<staticDir>/__client-component/<id>.js` and pre-renders each to HTML.\r\n */\r\nexport async function bundleClientComponents(\r\n globalRegistry: Map<string, string>,\r\n pagesDir: string,\r\n staticDir: string,\r\n): Promise<Map<string, string>> {\r\n if (globalRegistry.size === 0) return new Map();\r\n\r\n const outDir = path.join(staticDir, '__client-component');\r\n fs.mkdirSync(outDir, { recursive: true });\r\n\r\n const prerendered = new Map<string, string>();\r\n\r\n for (const [id, filePath] of globalRegistry) {\r\n console.log(` bundling client ${id} (${path.relative(pagesDir, filePath)})`);\r\n\r\n // Browser bundle \u2014 served to the client for hydration\r\n const browserResult = await build({\r\n entryPoints: [filePath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'browser',\r\n jsx: 'automatic',\r\n minify: true,\r\n external: ['react', 'react-dom/client', 'react/jsx-runtime'],\r\n define: { 'process.env.NODE_ENV': '\"production\"' },\r\n write: false,\r\n });\r\n fs.writeFileSync(path.join(outDir, `${id}.js`), browserResult.outputFiles[0].text);\r\n\r\n // SSR pre-render \u2014 bundle for Node, import, renderToString, discard\r\n const ssrTmp = path.join(\r\n path.dirname(filePath),\r\n `_ssr_${id}_${randomBytes(4).toString('hex')}.mjs`,\r\n );\r\n try {\r\n const ssrResult = await build({\r\n entryPoints: [filePath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'node',\r\n target: 'node20',\r\n jsx: 'automatic',\r\n packages: 'external',\r\n define: { 'process.env.NODE_ENV': '\"production\"' },\r\n write: false,\r\n });\r\n fs.writeFileSync(ssrTmp, ssrResult.outputFiles[0].text);\r\n\r\n const { default: Component } = await import(pathToFileURL(ssrTmp).href);\r\n const { createElement } = await import('react');\r\n const { renderToString } = await import('react-dom/server');\r\n\r\n prerendered.set(id, renderToString(createElement(Component, {})));\r\n console.log(` prerendered ${id}`);\r\n } catch {\r\n prerendered.set(id, '');\r\n } finally {\r\n if (fs.existsSync(ssrTmp)) fs.unlinkSync(ssrTmp);\r\n }\r\n }\r\n\r\n console.log(` bundled ${globalRegistry.size} client component(s) \u2192 ${path.relative(process.cwd(), outDir)}/`);\r\n return prerendered;\r\n}\r\n\r\n/**\r\n * Builds the combined browser bundle (__n.js) that contains the full React\r\n * runtime + NukeJS client runtime in a single file.\r\n */\r\nexport async function buildCombinedBundle(staticDir: string): Promise<void> {\r\n const nukeDir = path.dirname(fileURLToPath(import.meta.url));\r\n const bundleFile = nukeDir.endsWith('dist') ? 'bundle' : 'bundle.ts';\r\n\r\n const result = await build({\r\n stdin: {\r\n contents: `\r\nimport React, {\r\n useState, useEffect, useContext, useReducer, useCallback, useMemo,\r\n useRef, useImperativeHandle, useLayoutEffect, useDebugValue,\r\n useDeferredValue, useTransition, useId, useSyncExternalStore,\r\n useInsertionEffect, createContext, forwardRef, memo, lazy,\r\n Suspense, Fragment, StrictMode, Component, PureComponent\r\n} from 'react';\r\nimport { jsx, jsxs } from 'react/jsx-runtime';\r\nimport { hydrateRoot, createRoot } from 'react-dom/client';\r\nexport { initRuntime, setupLocationChangeMonitor } from './${bundleFile}';\r\nexport {\r\n useState, useEffect, useContext, useReducer, useCallback, useMemo,\r\n useRef, useImperativeHandle, useLayoutEffect, useDebugValue,\r\n useDeferredValue, useTransition, useId, useSyncExternalStore,\r\n useInsertionEffect, createContext, forwardRef, memo, lazy,\r\n Suspense, Fragment, StrictMode, Component, PureComponent,\r\n hydrateRoot, createRoot, jsx, jsxs\r\n};\r\nexport default React;\r\n`,\r\n loader: 'ts',\r\n resolveDir: nukeDir,\r\n },\r\n bundle: true,\r\n write: false,\r\n treeShaking: true,\r\n minify: true,\r\n format: 'esm',\r\n jsx: 'automatic',\r\n alias: {\r\n react: path.dirname(fileURLToPath(import.meta.resolve('react/package.json'))),\r\n 'react-dom': path.dirname(fileURLToPath(import.meta.resolve('react-dom/package.json'))),\r\n },\r\n define: { 'process.env.NODE_ENV': '\"production\"' },\r\n });\r\n\r\n fs.writeFileSync(path.join(staticDir, '__n.js'), result.outputFiles[0].text);\r\n console.log(' built __n.js (react + runtime)');\r\n}\r\n\r\n// \u2500\u2500\u2500 Public file copying \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Recursively copies every file from `publicDir` into `destDir`, preserving\r\n * the directory structure. Skips silently when `publicDir` does not exist.\r\n */\r\nexport function copyPublicFiles(publicDir: string, destDir: string): void {\r\n if (!fs.existsSync(publicDir)) return;\r\n\r\n let count = 0;\r\n (function walk(src: string, dest: string) {\r\n fs.mkdirSync(dest, { recursive: true });\r\n for (const entry of fs.readdirSync(src, { withFileTypes: true })) {\r\n const s = path.join(src, entry.name);\r\n const d = path.join(dest, entry.name);\r\n if (entry.isDirectory()) { walk(s, d); } else { fs.copyFileSync(s, d); count++; }\r\n }\r\n })(publicDir, destDir);\r\n\r\n if (count > 0)\r\n console.log(` copied ${count} public file(s) \u2192 ${path.relative(process.cwd(), destDir)}/`);\r\n}"],
5
- "mappings": "AAkBA,OAAO,QAAU;AACjB,OAAO,UAAU;AACjB,SAAS,mBAA8B;AACvC,SAAS,eAAe,qBAAqB;AAC7C,SAAS,aAA8B;AACvC,SAAS,kCAAkC;AAS3C,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EAAQ;AAAA,EAAS;AAAA,EAAM;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAU;AAAA,EAAU;AAAA,EAC1D;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAM;AAAA,EAAO;AAAA,EAAO;AAAA,EAAiB;AAAA,EACvD;AAAA,EAAW;AAAA,EAAS;AAAA,EAAO;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAU;AAAA,EACzD;AAAA,EAAc;AAAA,EAAkB;AAAA,EAAU;AAAA,EAAe;AAAA,EAAM;AACjE;AA6BO,SAAS,UAAU,KAAa,OAAe,KAAe;AACnE,MAAI,CAAC,GAAG,WAAW,GAAG,EAAG,QAAO,CAAC;AACjC,QAAM,UAAoB,CAAC;AAC3B,aAAW,SAAS,GAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAChE,UAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;AACtC,QAAI,MAAM,YAAY,GAAG;AACvB,cAAQ,KAAK,GAAG,UAAU,MAAM,IAAI,CAAC;AAAA,IACvC,WAAW,MAAM,KAAK,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS,MAAM,GAAG;AACpE,cAAQ,KAAK,KAAK,SAAS,MAAM,IAAI,CAAC;AAAA,IACxC;AAAA,EACF;AACA,SAAO;AACT;AAmBO,SAAS,YAAY,SAAiB,SAAS,OAAsB;AAC1E,QAAM,aAAa,QAAQ,QAAQ,OAAO,GAAG,EAAE,QAAQ,aAAa,EAAE;AAC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,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAChE,YAAM,IAAI,KAAK,KAAK,KAAK,MAAM,IAAI;AACnC,YAAM,IAAI,KAAK,KAAK,MAAM,MAAM,IAAI;AACpC,UAAI,MAAM,YAAY,GAAG;AAAE,aAAK,GAAG,CAAC;AAAA,MAAG,OAAO;AAAE,WAAG,aAAa,GAAG,CAAC;AAAG;AAAA,MAAS;AAAA,IAClF;AAAA,EACF,GAAG,WAAW,OAAO;AAErB,MAAI,QAAQ;AACV,YAAQ,IAAI,eAAe,KAAK,0BAAqB,KAAK,SAAS,QAAQ,IAAI,GAAG,OAAO,CAAC,GAAG;AACjG;",
6
- "names": []
7
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * build-node.ts — Node.js Production Build
3
- *
4
- * Produces a self-contained dist/ directory that runs with:
5
- * node dist/index.mjs
6
- *
7
- * Output layout:
8
- * dist/
9
- * index.mjs ← HTTP server entry point (routing: static → framework → api → pages)
10
- * manifest.json ← Route → handler mapping
11
- * api/<route>.mjs ← Bundled API handlers
12
- * pages/<route>.mjs ← Bundled page handlers
13
- * static/ ← __n.js, client components, public files
14
- */
15
- export {};
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/build-node.ts"],
4
- "sourcesContent": ["/**\r\n * build-node.ts \u2014 Node.js Production Build\r\n *\r\n * Produces a self-contained dist/ directory that runs with:\r\n * node dist/index.mjs\r\n *\r\n * Output layout:\r\n * dist/\r\n * index.mjs \u2190 HTTP server entry point (routing: static \u2192 framework \u2192 api \u2192 pages)\r\n * manifest.json \u2190 Route \u2192 handler mapping\r\n * api/<route>.mjs \u2190 Bundled API handlers\r\n * pages/<route>.mjs \u2190 Bundled page handlers\r\n * static/ \u2190 __n.js, client components, public files\r\n */\r\n\r\nimport fs from 'fs';\r\nimport path from 'path';\r\n\r\nimport { loadConfig } from './config';\r\nimport {\r\n analyzeFile,\r\n walkFiles,\r\n buildPages,\r\n bundleApiHandler,\r\n buildCombinedBundle,\r\n copyPublicFiles,\r\n type AnalyzedRoute,\r\n} from './build-common';\r\n\r\n// \u2500\u2500\u2500 Output directories \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst OUT_DIR = path.resolve('dist');\r\nconst API_DIR = path.join(OUT_DIR, 'api');\r\nconst PAGES_DIR_ = path.join(OUT_DIR, 'pages');\r\nconst STATIC_DIR = path.join(OUT_DIR, 'static');\r\n\r\n// Clean the entire dist/ folder before building so stale bundles, removed\r\n// routes, and renamed pages don't linger in the output.\r\nif (fs.existsSync(OUT_DIR)) {\r\n fs.rmSync(OUT_DIR, { recursive: true, force: true });\r\n console.log('\uD83D\uDDD1\uFE0F Cleaned dist/');\r\n}\r\n\r\nfor (const dir of [API_DIR, PAGES_DIR_, STATIC_DIR])\r\n fs.mkdirSync(dir, { recursive: true });\r\n\r\n// \u2500\u2500\u2500 Config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst config = await loadConfig();\r\nconst SERVER_DIR = path.resolve(config.serverDir);\r\nconst PAGES_DIR = path.resolve('./app/pages');\r\nconst PUBLIC_DIR = path.resolve('./app/public');\r\n\r\n// \u2500\u2500\u2500 Route manifest \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\ninterface ManifestEntry {\r\n /** Regex string matching the URL path, e.g. '^/users/([^/]+)$' */\r\n srcRegex: string;\r\n /** Names of captured groups in srcRegex order */\r\n paramNames: string[];\r\n /** Subset of paramNames whose runtime values are string[] (catch-all params) */\r\n catchAllNames: string[];\r\n /** Path to the bundled handler relative to dist/, e.g. 'api/users/[id].mjs' */\r\n handler: string;\r\n type: 'api' | 'page';\r\n}\r\n\r\nconst manifest: ManifestEntry[] = [];\r\n\r\n// \u2500\u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/** Converts a funcPath like '/api/users/[id]' to a filename 'users/[id].mjs'. */\r\nfunction funcPathToFilename(funcPath: string, prefix: 'api' | 'page'): string {\r\n return funcPath.replace(new RegExp(`^\\\\/${prefix}\\\\/`), '') + '.mjs';\r\n}\r\n\r\n// \u2500\u2500\u2500 API routes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst apiFiles = walkFiles(SERVER_DIR);\r\nif (apiFiles.length === 0) console.warn(`\u26A0 No server files found in ${SERVER_DIR}`);\r\n\r\nconst apiRoutes = apiFiles\r\n .map(relPath => ({ ...analyzeFile(relPath, 'api'), absPath: path.join(SERVER_DIR, relPath) }))\r\n .sort((a, b) => b.specificity - a.specificity);\r\n\r\nfor (const { srcRegex, paramNames, catchAllNames, funcPath, absPath } of apiRoutes) {\r\n console.log(` building ${path.relative(SERVER_DIR, absPath)} \u2192 ${funcPath}`);\r\n\r\n const filename = funcPathToFilename(funcPath, 'api');\r\n const outPath = path.join(API_DIR, filename);\r\n fs.mkdirSync(path.dirname(outPath), { recursive: true });\r\n fs.writeFileSync(outPath, await bundleApiHandler(absPath));\r\n\r\n manifest.push({ srcRegex, paramNames, catchAllNames, handler: path.join('api', filename), type: 'api' });\r\n}\r\n\r\n// \u2500\u2500\u2500 Page routes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst builtPages = await buildPages(PAGES_DIR, STATIC_DIR);\r\n\r\nfor (const { srcRegex, paramNames, catchAllNames, funcPath, bundleText } of builtPages) {\r\n const filename = funcPathToFilename(funcPath, 'page');\r\n const outPath = path.join(PAGES_DIR_, filename);\r\n fs.mkdirSync(path.dirname(outPath), { recursive: true });\r\n fs.writeFileSync(outPath, bundleText);\r\n\r\n manifest.push({ srcRegex, paramNames, catchAllNames, handler: path.join('pages', filename), type: 'page' });\r\n}\r\n\r\n// \u2500\u2500\u2500 Manifest \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n// Entries are already sorted most-specific first (both loops sort before\r\n// iterating), so the runtime can match top-to-bottom.\r\nfs.writeFileSync(\r\n path.join(OUT_DIR, 'manifest.json'),\r\n JSON.stringify({ routes: manifest }, null, 2),\r\n);\r\n\r\n// \u2500\u2500\u2500 Static assets \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nawait buildCombinedBundle(STATIC_DIR);\r\ncopyPublicFiles(PUBLIC_DIR, STATIC_DIR);\r\n\r\n// \u2500\u2500\u2500 Server entry \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n// A thin HTTP server that reads manifest.json at startup and dispatches\r\n// incoming requests to the correct pre-built handler module.\r\n\r\nconst MIME_MAP_ENTRIES = `\r\n '.html': 'text/html; charset=utf-8',\r\n '.htm': 'text/html; charset=utf-8',\r\n '.css': 'text/css; charset=utf-8',\r\n '.js': 'application/javascript; charset=utf-8',\r\n '.mjs': 'application/javascript; charset=utf-8',\r\n '.cjs': 'application/javascript; charset=utf-8',\r\n '.map': 'application/json; charset=utf-8',\r\n '.json': 'application/json; charset=utf-8',\r\n '.xml': 'application/xml; charset=utf-8',\r\n '.txt': 'text/plain; charset=utf-8',\r\n '.csv': 'text/csv; charset=utf-8',\r\n '.png': 'image/png',\r\n '.jpg': 'image/jpeg',\r\n '.jpeg': 'image/jpeg',\r\n '.gif': 'image/gif',\r\n '.webp': 'image/webp',\r\n '.avif': 'image/avif',\r\n '.svg': 'image/svg+xml',\r\n '.ico': 'image/x-icon',\r\n '.bmp': 'image/bmp',\r\n '.woff': 'font/woff',\r\n '.woff2':'font/woff2',\r\n '.ttf': 'font/ttf',\r\n '.otf': 'font/otf',\r\n '.mp4': 'video/mp4',\r\n '.webm': 'video/webm',\r\n '.mp3': 'audio/mpeg',\r\n '.wav': 'audio/wav',\r\n '.ogg': 'audio/ogg',\r\n '.pdf': 'application/pdf',\r\n '.wasm': 'application/wasm',\r\n`.trim();\r\n\r\nconst serverEntry = `\\\r\nimport http from 'http';\r\nimport path from 'path';\r\nimport fs from 'fs';\r\nimport { fileURLToPath, pathToFileURL } from 'url';\r\n\r\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\r\n\r\nconst { routes } = JSON.parse(fs.readFileSync(path.join(__dirname, 'manifest.json'), 'utf-8'));\r\nconst compiled = routes.map(r => ({ ...r, regex: new RegExp(r.srcRegex) }));\r\n\r\nconst STATIC_DIR = path.join(__dirname, 'static');\r\nconst MIME_MAP = { ${MIME_MAP_ENTRIES} };\r\n\r\nconst server = http.createServer(async (req, res) => {\r\n const url = req.url || '/';\r\n const clean = url.split('?')[0];\r\n\r\n // 1. Static files \u2014 app/public/ files are copied into STATIC_DIR last at\r\n // build time (after framework bundles), so they take priority over\r\n // framework files on name collision. path.join normalises '..' segments\r\n // before the startsWith guard, preventing directory traversal.\r\n {\r\n const candidate = path.join(STATIC_DIR, clean);\r\n const staticBase = STATIC_DIR.endsWith(path.sep) ? STATIC_DIR : STATIC_DIR + path.sep;\r\n if (\r\n candidate.startsWith(staticBase) &&\r\n candidate !== STATIC_DIR &&\r\n fs.existsSync(candidate) &&\r\n fs.statSync(candidate).isFile()\r\n ) {\r\n res.setHeader('Content-Type', MIME_MAP[path.extname(candidate)] ?? 'application/octet-stream');\r\n res.end(fs.readFileSync(candidate));\r\n return;\r\n }\r\n }\r\n\r\n // 2. Route dispatch \u2014 API routes appear before page routes in the manifest\r\n // (built in build-node.ts), so they are matched first.\r\n for (const { regex, paramNames, catchAllNames, handler } of compiled) {\r\n const m = clean.match(regex);\r\n if (!m) continue;\r\n\r\n const catchAllSet = new Set(catchAllNames);\r\n const qs = new URLSearchParams(Object.fromEntries(new URL(url, 'http://localhost').searchParams));\r\n paramNames.forEach((name, i) => {\r\n const raw = m[i + 1] ?? '';\r\n if (catchAllSet.has(name)) {\r\n raw.split('/').filter(Boolean).forEach(seg => qs.append(name, seg));\r\n } else {\r\n qs.set(name, raw);\r\n }\r\n });\r\n req.url = clean + (qs.toString() ? '?' + qs.toString() : '');\r\n\r\n const mod = await import(pathToFileURL(path.join(__dirname, handler)).href);\r\n await mod.default(req, res);\r\n return;\r\n }\r\n\r\n res.statusCode = 404;\r\n res.setHeader('Content-Type', 'text/plain');\r\n res.end('Not found');\r\n});\r\n\r\nconst PORT = Number(process.env.PORT ?? 3000);\r\nserver.listen(PORT, () => console.log('nukejs built server listening on http://localhost:' + PORT));\r\n`;\r\n\r\nfs.writeFileSync(path.join(OUT_DIR, 'index.mjs'), serverEntry);\r\n\r\nconsole.log(`\\n\u2713 Node build complete \u2014 ${manifest.length} route(s) \u2192 dist/`);\r\nconsole.log(' run with: node dist/index.mjs');"],
5
- "mappings": "AAeA,OAAO,QAAU;AACjB,OAAO,UAAU;AAEjB,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAIP,MAAM,UAAa,KAAK,QAAQ,MAAM;AACtC,MAAM,UAAa,KAAK,KAAK,SAAS,KAAK;AAC3C,MAAM,aAAa,KAAK,KAAK,SAAS,OAAO;AAC7C,MAAM,aAAa,KAAK,KAAK,SAAS,QAAQ;AAI9C,IAAI,GAAG,WAAW,OAAO,GAAG;AAC1B,KAAG,OAAO,SAAS,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AACnD,UAAQ,IAAI,gCAAoB;AAClC;AAEA,WAAW,OAAO,CAAC,SAAS,YAAY,UAAU;AAChD,KAAG,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAIvC,MAAM,SAAa,MAAM,WAAW;AACpC,MAAM,aAAa,KAAK,QAAQ,OAAO,SAAS;AAChD,MAAM,YAAa,KAAK,QAAQ,aAAa;AAC7C,MAAM,aAAa,KAAK,QAAQ,cAAc;AAgB9C,MAAM,WAA4B,CAAC;AAKnC,SAAS,mBAAmB,UAAkB,QAAgC;AAC5E,SAAO,SAAS,QAAQ,IAAI,OAAO,OAAO,MAAM,KAAK,GAAG,EAAE,IAAI;AAChE;AAIA,MAAM,WAAW,UAAU,UAAU;AACrC,IAAI,SAAS,WAAW,EAAG,SAAQ,KAAK,oCAA+B,UAAU,EAAE;AAEnF,MAAM,YAAY,SACf,IAAI,cAAY,EAAE,GAAG,YAAY,SAAS,KAAK,GAAG,SAAS,KAAK,KAAK,YAAY,OAAO,EAAE,EAAE,EAC5F,KAAK,CAAC,GAA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AAAA;AAAA;AAAA,EAgCvB,KAAK;AAEP,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAYG,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyDvC,GAAG,cAAc,KAAK,KAAK,SAAS,WAAW,GAAG,WAAW;AAE7D,QAAQ,IAAI;AAAA,oCAA6B,SAAS,MAAM,wBAAmB;AAC3E,QAAQ,IAAI,iCAAiC;",
6
- "names": []
7
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * build-vercel.ts — Vercel Production Build
3
- *
4
- * Produces a .vercel/output/ directory conforming to the Vercel Build Output
5
- * API v3. Two serverless functions are emitted:
6
- *
7
- * api.func/ ← single dispatcher bundling all API route handlers
8
- * pages.func/ ← single dispatcher bundling all SSR page handlers
9
- *
10
- * Static assets (React runtime, client components, public files) go to
11
- * .vercel/output/static/ and are served by Vercel's CDN directly.
12
- *
13
- * Notes on bundling strategy:
14
- * - npm packages are FULLY BUNDLED (no node_modules at Vercel runtime).
15
- * - Node built-ins are kept external (available in the nodejs20.x runtime).
16
- * - A createRequire banner lets CJS packages (mongoose, etc.) resolve Node
17
- * built-ins correctly inside the ESM output bundle.
18
- */
19
- export {};
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/build-vercel.ts"],
4
- "sourcesContent": ["/**\r\n * build-vercel.ts \u2014 Vercel Production Build\r\n *\r\n * Produces a .vercel/output/ directory conforming to the Vercel Build Output\r\n * API v3. Two serverless functions are emitted:\r\n *\r\n * api.func/ \u2190 single dispatcher bundling all API route handlers\r\n * pages.func/ \u2190 single dispatcher bundling all SSR page handlers\r\n *\r\n * Static assets (React runtime, client components, public files) go to\r\n * .vercel/output/static/ and are served by Vercel's CDN directly.\r\n *\r\n * Notes on bundling strategy:\r\n * - npm packages are FULLY BUNDLED (no node_modules at Vercel runtime).\r\n * - Node built-ins are kept external (available in the nodejs20.x runtime).\r\n * - A createRequire banner lets CJS packages (mongoose, etc.) resolve Node\r\n * built-ins correctly inside the ESM output bundle.\r\n */\r\n\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport { randomBytes } from 'node:crypto';\r\nimport { build } from 'esbuild';\r\n\r\nimport { loadConfig } from './config';\r\nimport {\r\n walkFiles,\r\n analyzeFile,\r\n collectServerPages,\r\n collectGlobalClientRegistry,\r\n bundleClientComponents,\r\n findPageLayouts,\r\n buildPerPageRegistry,\r\n makePageAdapterSource,\r\n buildCombinedBundle,\r\n copyPublicFiles,\r\n} from './build-common';\r\n\r\n// \u2500\u2500\u2500 Output directories \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst OUTPUT_DIR = path.resolve('.vercel/output');\r\nconst FUNCTIONS_DIR = path.join(OUTPUT_DIR, 'functions');\r\nconst STATIC_DIR = path.join(OUTPUT_DIR, 'static');\r\n\r\n// Clean the entire .vercel/output/ folder before building so stale function\r\n// bundles, removed routes, and renamed pages don't linger in the output.\r\nif (fs.existsSync(OUTPUT_DIR)) {\r\n fs.rmSync(OUTPUT_DIR, { recursive: true, force: true });\r\n console.log('\uD83D\uDDD1\uFE0F Cleaned .vercel/output/');\r\n}\r\n\r\nfor (const dir of [FUNCTIONS_DIR, STATIC_DIR])\r\n fs.mkdirSync(dir, { recursive: true });\r\n\r\n// \u2500\u2500\u2500 Config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst config = await loadConfig();\r\nconst SERVER_DIR = path.resolve(config.serverDir);\r\nconst PAGES_DIR = path.resolve('./app/pages');\r\nconst PUBLIC_DIR = path.resolve('./app/public');\r\n\r\n// \u2500\u2500\u2500 Shared esbuild config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Node built-ins that should never be bundled.\r\n * npm packages are intentionally absent \u2014 they must be bundled because\r\n * Vercel serverless functions have no node_modules at runtime.\r\n */\r\nconst NODE_BUILTINS = [\r\n 'node:*',\r\n 'http', 'https', 'fs', 'path', 'url', 'crypto', 'stream', 'buffer',\r\n 'events', 'util', 'os', 'net', 'tls', 'child_process', 'worker_threads',\r\n 'cluster', 'dgram', 'dns', 'readline', 'zlib', 'assert', 'module',\r\n 'perf_hooks', 'string_decoder', 'timers', 'async_hooks', 'v8', 'vm',\r\n];\r\n\r\n/**\r\n * Banner injected at the top of every Vercel function bundle.\r\n *\r\n * Why it's needed: esbuild bundles CJS packages (mongoose, etc.) into ESM\r\n * output and replaces their require() calls with a __require2 shim. That\r\n * shim cannot resolve Node built-ins on its own inside an ESM module scope.\r\n * Injecting a real require (backed by createRequire) fixes the shim so that\r\n * dynamic require('crypto'), require('stream'), etc. work correctly.\r\n */\r\nconst CJS_COMPAT_BANNER = {\r\n js: `import { createRequire } from 'module';\\nconst require = createRequire(import.meta.url);`,\r\n};\r\n\r\n// \u2500\u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\ntype VercelRoute = { src: string; dest: string } | { handle: 'filesystem' };\r\n\r\n/** Writes a bundled dispatcher into a Vercel .func directory. */\r\nfunction emitVercelFunction(name: string, bundleText: string): void {\r\n const funcDir = path.join(FUNCTIONS_DIR, `${name}.func`);\r\n fs.mkdirSync(funcDir, { recursive: true });\r\n fs.writeFileSync(path.join(funcDir, 'index.mjs'), bundleText);\r\n fs.writeFileSync(\r\n path.join(funcDir, '.vc-config.json'),\r\n JSON.stringify({ runtime: 'nodejs20.x', handler: 'index.mjs', launcherType: 'Nodejs' }, null, 2),\r\n );\r\n}\r\n\r\n// \u2500\u2500\u2500 API dispatcher source \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Generates a single TypeScript dispatcher that imports every API route module,\r\n * matches the incoming URL against each route's regex, injects captured params,\r\n * and calls the right HTTP-method export (GET, POST, \u2026) or default export.\r\n */\r\nfunction makeApiDispatcherSource(\r\n routes: Array<{ absPath: string; srcRegex: string; paramNames: string[] }>,\r\n): string {\r\n const imports = routes\r\n .map((r, i) => `import * as __api_${i}__ from ${JSON.stringify(r.absPath)};`)\r\n .join('\\n');\r\n\r\n const routeEntries = routes\r\n .map((r, i) =>\r\n ` { regex: ${JSON.stringify(r.srcRegex)}, params: ${JSON.stringify(r.paramNames)}, mod: __api_${i}__ },`,\r\n )\r\n .join('\\n');\r\n\r\n return `\\\r\nimport type { IncomingMessage, ServerResponse } from 'http';\r\n${imports}\r\n\r\nfunction enhance(res: ServerResponse) {\r\n (res as any).json = function(data: any, status = 200) {\r\n this.statusCode = status;\r\n this.setHeader('Content-Type', 'application/json');\r\n this.end(JSON.stringify(data));\r\n };\r\n (res as any).status = function(code: number) { this.statusCode = code; return this; };\r\n return res;\r\n}\r\n\r\nasync function parseBody(req: IncomingMessage): Promise<any> {\r\n return new Promise((resolve, reject) => {\r\n let body = '';\r\n req.on('data', (chunk: any) => { body += chunk.toString(); });\r\n req.on('end', () => {\r\n try {\r\n resolve(\r\n body && req.headers['content-type']?.includes('application/json')\r\n ? JSON.parse(body)\r\n : body,\r\n );\r\n } catch (e) { reject(e); }\r\n });\r\n req.on('error', reject);\r\n });\r\n}\r\n\r\nconst ROUTES = [\r\n${routeEntries}\r\n];\r\n\r\nexport default async function handler(req: IncomingMessage, res: ServerResponse) {\r\n const url = new URL(req.url || '/', 'http://localhost');\r\n const pathname = url.pathname;\r\n\r\n for (const route of ROUTES) {\r\n const m = pathname.match(new RegExp(route.regex));\r\n if (!m) continue;\r\n\r\n const method = (req.method || 'GET').toUpperCase();\r\n const apiRes = enhance(res);\r\n const apiReq = req as any;\r\n\r\n apiReq.body = await parseBody(req);\r\n apiReq.query = Object.fromEntries(url.searchParams);\r\n apiReq.params = {};\r\n route.params.forEach((name: string, i: number) => { apiReq.params[name] = m[i + 1]; });\r\n\r\n const fn = (route.mod as any)[method] ?? (route.mod as any)['default'];\r\n if (typeof fn !== 'function') {\r\n (apiRes as any).json({ error: \\`Method \\${method} not allowed\\` }, 405);\r\n return;\r\n }\r\n await fn(apiReq, apiRes);\r\n return;\r\n }\r\n\r\n res.statusCode = 404;\r\n res.setHeader('Content-Type', 'application/json');\r\n res.end(JSON.stringify({ error: 'Not Found' }));\r\n}\r\n`;\r\n}\r\n\r\n// \u2500\u2500\u2500 Pages dispatcher source \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Generates a TypeScript dispatcher that imports each page's pre-generated\r\n * adapter, matches the incoming URL, encodes captured dynamic params as\r\n * query-string values (catch-all params use repeated keys), then delegates\r\n * to the matching handler.\r\n */\r\nfunction makePagesDispatcherSource(\r\n routes: Array<{\r\n adapterPath: string;\r\n srcRegex: string;\r\n paramNames: string[];\r\n catchAllNames: string[];\r\n }>,\r\n): string {\r\n const imports = routes\r\n .map((r, i) => `import __page_${i}__ from ${JSON.stringify(r.adapterPath)};`)\r\n .join('\\n');\r\n\r\n const routeEntries = routes\r\n .map((r, i) =>\r\n ` { regex: ${JSON.stringify(r.srcRegex)}, params: ${JSON.stringify(r.paramNames)}, catchAll: ${JSON.stringify(r.catchAllNames)}, handler: __page_${i}__ },`,\r\n )\r\n .join('\\n');\r\n\r\n return `\\\r\nimport type { IncomingMessage, ServerResponse } from 'http';\r\n${imports}\r\n\r\nconst ROUTES: Array<{\r\n regex: string;\r\n params: string[];\r\n catchAll: string[];\r\n handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;\r\n}> = [\r\n${routeEntries}\r\n];\r\n\r\nexport default async function handler(req: IncomingMessage, res: ServerResponse) {\r\n const url = new URL(req.url || '/', 'http://localhost');\r\n const pathname = url.pathname;\r\n\r\n for (const route of ROUTES) {\r\n const m = pathname.match(new RegExp(route.regex));\r\n if (!m) continue;\r\n\r\n const catchAllSet = new Set(route.catchAll);\r\n route.params.forEach((name, i) => {\r\n const raw = m[i + 1] ?? '';\r\n if (catchAllSet.has(name)) {\r\n // Encode catch-all as repeated keys so the handler can getAll() \u2192 string[]\r\n raw.split('/').filter(Boolean).forEach(seg => url.searchParams.append(name, seg));\r\n } else {\r\n url.searchParams.set(name, raw);\r\n }\r\n });\r\n req.url = pathname + (url.search || '');\r\n\r\n return route.handler(req, res);\r\n }\r\n\r\n res.statusCode = 404;\r\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\r\n res.end('Not Found');\r\n}\r\n`;\r\n}\r\n\r\n// \u2500\u2500\u2500 Build API function \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst vercelRoutes: VercelRoute[] = [];\r\n\r\nconst apiFiles = walkFiles(SERVER_DIR);\r\nif (apiFiles.length === 0) console.warn(`\u26A0 No server files found in ${SERVER_DIR}`);\r\n\r\nconst apiRoutes = apiFiles\r\n .map(relPath => ({ ...analyzeFile(relPath, 'api'), absPath: path.join(SERVER_DIR, relPath) }))\r\n .sort((a, b) => b.specificity - a.specificity);\r\n\r\nif (apiRoutes.length > 0) {\r\n const dispatcherPath = path.join(SERVER_DIR, `_api_dispatcher_${randomBytes(4).toString('hex')}.ts`);\r\n fs.writeFileSync(dispatcherPath, makeApiDispatcherSource(apiRoutes));\r\n\r\n try {\r\n const result = await build({\r\n entryPoints: [dispatcherPath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'node',\r\n target: 'node20',\r\n banner: CJS_COMPAT_BANNER,\r\n external: NODE_BUILTINS,\r\n write: false,\r\n });\r\n emitVercelFunction('api', result.outputFiles[0].text);\r\n console.log(` built API dispatcher \u2192 api.func (${apiRoutes.length} route(s))`);\r\n } finally {\r\n fs.unlinkSync(dispatcherPath);\r\n }\r\n\r\n // API routes are listed before pages in config.json so they win on any\r\n // URL collision. Static files in .vercel/output/static/ (app/public +\r\n // framework bundles) are served by Vercel's CDN before any route is checked.\r\n for (const { srcRegex } of apiRoutes)\r\n vercelRoutes.push({ src: srcRegex, dest: '/api' });\r\n}\r\n\r\n// \u2500\u2500\u2500 Build Pages function \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nconst serverPages = collectServerPages(PAGES_DIR);\r\n\r\nif (serverPages.length > 0) {\r\n // Pass 1 \u2014 bundle all client components to static files.\r\n const globalRegistry = collectGlobalClientRegistry(serverPages, PAGES_DIR);\r\n const prerenderedHtml = await bundleClientComponents(globalRegistry, PAGES_DIR, STATIC_DIR);\r\n const prerenderedRecord = Object.fromEntries(prerenderedHtml);\r\n\r\n // Pass 2 \u2014 write one temp adapter per page next to its source file (so\r\n // relative imports resolve correctly), then bundle everything in\r\n // one esbuild pass via the dispatcher.\r\n const tempAdapterPaths: string[] = [];\r\n\r\n for (const page of serverPages) {\r\n const adapterDir = path.dirname(page.absPath);\r\n const adapterPath = path.join(adapterDir, `_page_adapter_${randomBytes(4).toString('hex')}.ts`);\r\n\r\n const layoutPaths = findPageLayouts(page.absPath, PAGES_DIR);\r\n const { registry, clientComponentNames } = buildPerPageRegistry(page.absPath, layoutPaths, PAGES_DIR);\r\n\r\n const layoutImports = layoutPaths\r\n .map((lp, i) => {\r\n const rel = path.relative(adapterDir, lp).replace(/\\\\/g, '/');\r\n return `import __layout_${i}__ from ${JSON.stringify(rel.startsWith('.') ? rel : './' + rel)};`;\r\n })\r\n .join('\\n');\r\n\r\n fs.writeFileSync(\r\n adapterPath,\r\n makePageAdapterSource({\r\n pageImport: JSON.stringify('./' + path.basename(page.absPath)),\r\n layoutImports,\r\n clientComponentNames,\r\n allClientIds: [...registry.keys()],\r\n layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(', '),\r\n prerenderedHtml: prerenderedRecord,\r\n routeParamNames: page.paramNames,\r\n catchAllNames: page.catchAllNames,\r\n }),\r\n );\r\n\r\n tempAdapterPaths.push(adapterPath);\r\n console.log(` prepared ${path.relative(PAGES_DIR, page.absPath)} \u2192 ${page.funcPath} [page]`);\r\n }\r\n\r\n const dispatcherRoutes = serverPages.map((page, i) => ({\r\n adapterPath: tempAdapterPaths[i],\r\n srcRegex: page.srcRegex,\r\n paramNames: page.paramNames,\r\n catchAllNames: page.catchAllNames,\r\n }));\r\n\r\n const dispatcherPath = path.join(PAGES_DIR, `_pages_dispatcher_${randomBytes(4).toString('hex')}.ts`);\r\n fs.writeFileSync(dispatcherPath, makePagesDispatcherSource(dispatcherRoutes));\r\n\r\n try {\r\n const result = await build({\r\n entryPoints: [dispatcherPath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'node',\r\n target: 'node20',\r\n jsx: 'automatic',\r\n banner: CJS_COMPAT_BANNER,\r\n external: NODE_BUILTINS,\r\n define: { 'process.env.NODE_ENV': '\"production\"' },\r\n write: false,\r\n });\r\n emitVercelFunction('pages', result.outputFiles[0].text);\r\n console.log(` built Pages dispatcher \u2192 pages.func (${serverPages.length} page(s))`);\r\n } finally {\r\n fs.unlinkSync(dispatcherPath);\r\n for (const p of tempAdapterPaths) if (fs.existsSync(p)) fs.unlinkSync(p);\r\n }\r\n\r\n for (const { srcRegex } of serverPages)\r\n vercelRoutes.push({ src: srcRegex, dest: '/pages' });\r\n}\r\n\r\n// \u2500\u2500\u2500 Vercel config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n// `{ handle: 'filesystem' }` instructs Vercel's routing layer to check\r\n// .vercel/output/static/ BEFORE evaluating any of our dynamic route rules.\r\n// Without this, an optional catch-all like [[page]].tsx would intercept\r\n// /__n.js, /__react.js, and app/public/* before the CDN can serve them.\r\nfs.writeFileSync(\r\n path.join(OUTPUT_DIR, 'config.json'),\r\n JSON.stringify({ version: 3, routes: [{ handle: 'filesystem' }, ...vercelRoutes] }, null, 2),\r\n);\r\nfs.writeFileSync(\r\n path.resolve('vercel.json'),\r\n JSON.stringify({ runtime: 'nodejs20.x' }, null, 2),\r\n);\r\n\r\n// \u2500\u2500\u2500 Static assets \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nawait buildCombinedBundle(STATIC_DIR);\r\ncopyPublicFiles(PUBLIC_DIR, STATIC_DIR);\r\n\r\nconst fnCount = (apiRoutes.length > 0 ? 1 : 0) + (serverPages.length > 0 ? 1 : 0);\r\nconsole.log(`\\n\u2713 Vercel build complete \u2014 ${fnCount} function(s) \u2192 .vercel/output`);"],
5
- "mappings": "AAmBA,OAAO,QAAU;AACjB,OAAO,UAAU;AACjB,SAAS,mBAAmB;AAC5B,SAAS,aAAmB;AAE5B,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,MAAM,aAAgB,KAAK,QAAQ,gBAAgB;AACnD,MAAM,gBAAgB,KAAK,KAAK,YAAY,WAAW;AACvD,MAAM,aAAgB,KAAK,KAAK,YAAY,QAAQ;AAIpD,IAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,KAAG,OAAO,YAAY,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AACtD,UAAQ,IAAI,0CAA8B;AAC5C;AAEA,WAAW,OAAO,CAAC,eAAe,UAAU;AAC1C,KAAG,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAIvC,MAAM,SAAa,MAAM,WAAW;AACpC,MAAM,aAAa,KAAK,QAAQ,OAAO,SAAS;AAChD,MAAM,YAAa,KAAK,QAAQ,aAAa;AAC7C,MAAM,aAAa,KAAK,QAAQ,cAAc;AAS9C,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EAAQ;AAAA,EAAS;AAAA,EAAM;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAU;AAAA,EAAU;AAAA,EAC1D;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAM;AAAA,EAAO;AAAA,EAAO;AAAA,EAAiB;AAAA,EACvD;AAAA,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,EAAE,KAAK,UAAU,MAAM,SAAS,CAAC;AACvD;AAQA,GAAG;AAAA,EACD,KAAK,KAAK,YAAY,aAAa;AAAA,EACnC,KAAK,UAAU,EAAE,SAAS,GAAG,QAAQ,CAAC,EAAE,QAAQ,aAAa,GAAG,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;AAC7F;AACA,GAAG;AAAA,EACD,KAAK,QAAQ,aAAa;AAAA,EAC1B,KAAK,UAAU,EAAE,SAAS,aAAa,GAAG,MAAM,CAAC;AACnD;AAIA,MAAM,oBAAoB,UAAU;AACpC,gBAAgB,YAAY,UAAU;AAEtC,MAAM,WAAW,UAAU,SAAS,IAAI,IAAI,MAAM,YAAY,SAAS,IAAI,IAAI;AAC/E,QAAQ,IAAI;AAAA,sCAA+B,OAAO,oCAA+B;",
6
- "names": []
7
- }
package/dist/builder.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * builder.ts — NukeJS Package Build Script
3
- *
4
- * Compiles the NukeJS source into dist/ via a single esbuild pass targeting
5
- * Node ESM, followed by processDist() which rewrites bare relative imports
6
- * (e.g. `from './utils'`) to include .js extensions as required by Node's
7
- * strict ESM resolver.
8
- *
9
- * Finally, `tsc --emitDeclarationOnly` generates .d.ts files for consumers.
10
- */
11
- export {};
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/builder.ts"],
4
- "sourcesContent": ["/**\r\n * builder.ts \u2014 NukeJS Package Build Script\r\n *\r\n * Compiles the NukeJS source into dist/ via a single esbuild pass targeting\r\n * Node ESM, followed by processDist() which rewrites bare relative imports\r\n * (e.g. `from './utils'`) to include .js extensions as required by Node's\r\n * strict ESM resolver.\r\n *\r\n * Finally, `tsc --emitDeclarationOnly` generates .d.ts files for consumers.\r\n */\r\n\r\nimport { build } from 'esbuild';\r\nimport fs from 'fs';\r\nimport { execSync } from 'child_process';\r\nimport path from 'path';\r\nimport { fileURLToPath } from 'url';\r\n\r\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\r\nconst srcDir = path.resolve(__dirname, '');\r\nconst outDir = path.resolve(__dirname, '../dist');\r\n\r\n// \u2500\u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nfunction cleanDist(dir: string): void {\r\n if (!fs.existsSync(dir)) return;\r\n fs.rmSync(dir, { recursive: true, force: true });\r\n console.log(`\uD83D\uDDD1\uFE0F Cleared ${dir}`);\r\n}\r\n\r\n/** Collects all .ts/.tsx/.js/.jsx files under `dir`, skipping `exclude` dirs. */\r\nfunction collectFiles(dir: string, exclude: string[] = []): string[] {\r\n const files: string[] = [];\r\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\r\n const full = path.join(dir, entry.name);\r\n if (entry.isDirectory()) {\r\n if (!exclude.includes(entry.name)) files.push(...collectFiles(full, exclude));\r\n } else if (/\\.[tj]sx?$/.test(entry.name)) {\r\n files.push(full);\r\n }\r\n }\r\n return files;\r\n}\r\n\r\n// \u2500\u2500\u2500 Post-process .js files \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/** Rewrites bare relative imports to include .js extensions for Node ESM. */\r\nfunction processDist(dir: string) {\r\n (function walk(currentDir: string) {\r\n fs.readdirSync(currentDir, { withFileTypes: true }).forEach((d) => {\r\n const fullPath = path.join(currentDir, d.name);\r\n if (d.isDirectory()) {\r\n walk(fullPath);\r\n } else if (fullPath.endsWith('.js')) {\r\n let content = fs.readFileSync(fullPath, 'utf-8');\r\n content = content.replace(/from\\s+['\"](\\.\\/.*?)['\"]/g, 'from \"$1.js\"');\r\n content = content.replace(/import\\(['\"](\\.\\/.*?)['\"]\\)/g, 'import(\"$1.js\")');\r\n fs.writeFileSync(fullPath, content, 'utf-8');\r\n }\r\n });\r\n })(dir);\r\n\r\n console.log('\uD83D\uDD27 Post-processing done: relative imports \u2192 .js extensions.');\r\n}\r\n\r\n// \u2500\u2500\u2500 Build \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nasync function runBuild(): Promise<void> {\r\n try {\r\n cleanDist(outDir);\r\n\r\n console.log('\uD83D\uDE80 Building sources\u2026');\r\n await build({\r\n entryPoints: collectFiles(srcDir),\r\n outdir: outDir,\r\n platform: 'node',\r\n format: 'esm',\r\n target: ['node20'],\r\n packages: 'external',\r\n sourcemap: true,\r\n });\r\n console.log('\u2705 Build done.');\r\n\r\n processDist(outDir);\r\n\r\n console.log('\uD83D\uDCC4 Generating TypeScript declarations\u2026');\r\n execSync('tsc --emitDeclarationOnly --declaration --outDir dist', { stdio: 'inherit' });\r\n\r\n console.log('\\n\uD83C\uDF89 Build complete \u2192 dist/');\r\n } catch (err) {\r\n console.error('\u274C Build failed:', err);\r\n process.exit(1);\r\n }\r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,QAAQ,QAAQ,gCAAgC,iBAAiB;AAC3E,WAAG,cAAc,UAAU,SAAS,OAAO;AAAA,MAC7C;AAAA,IACF,CAAC;AAAA,EACH,GAAG,GAAG;AAEN,UAAQ,IAAI,yEAA6D;AAC3E;AAIA,eAAe,WAA0B;AACvC,MAAI;AACF,cAAU,MAAM;AAEhB,YAAQ,IAAI,mCAAuB;AACnC,UAAM,MAAM;AAAA,MACV,aAAa,aAAa,MAAM;AAAA,MAChC,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,QAAQ,CAAC,QAAQ;AAAA,MACjB,UAAU;AAAA,MACV,WAAW;AAAA,IACb,CAAC;AACD,YAAQ,IAAI,qBAAgB;AAE5B,gBAAY,MAAM;AAElB,YAAQ,IAAI,qDAAyC;AACrD,aAAS,yDAAyD,EAAE,OAAO,UAAU,CAAC;AAEtF,YAAQ,IAAI,0CAA8B;AAAA,EAC5C,SAAS,KAAK;AACZ,YAAQ,MAAM,yBAAoB,GAAG;AACrC,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,SAAS;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/bundle.ts"],
4
- "sourcesContent": ["/**\r\n * bundle.ts \u2014 NukeJS Client Runtime\r\n *\r\n * This file is compiled by esbuild into /__n.js and served to every page.\r\n * It provides:\r\n *\r\n * initRuntime(data) \u2014 called once per page load to hydrate\r\n * \"use client\" components and wire up SPA nav\r\n * setupLocationChangeMonitor() \u2014 patches history.pushState/replaceState so\r\n * SPA navigation fires a 'locationchange' event\r\n *\r\n * Hydration model (partial hydration):\r\n * - The server renders the full page to HTML, wrapping each client component\r\n * in a <span data-hydrate-id=\"cc_\u2026\" data-hydrate-props=\"\u2026\"> marker.\r\n * - initRuntime loads the matching JS bundle for each marker and calls\r\n * hydrateRoot() on it, letting React take over just that subtree.\r\n * - Props serialized by the server may include nested React elements\r\n * (serialized as { __re: 'html'|'client', \u2026 }), which are reconstructed\r\n * back into React.createElement calls before mounting.\r\n *\r\n * SPA navigation:\r\n * - Link clicks / programmatic navigation dispatch a 'locationchange' event.\r\n * - The handler fetches the target URL as HTML, diffs the #app container,\r\n * unmounts the old React roots, and re-hydrates the new ones.\r\n * - HMR navigations add ?__hmr=1 so the server skips client-SSR (faster).\r\n *\r\n * Head tag management:\r\n * - The SSR renderer wraps every useHtml()-generated <meta>, <link>, <style>,\r\n * and <script> tag in <!--n-head-->\u2026<!--/n-head--> sentinel comments.\r\n * - On each navigation the client diffs the live sentinel block against the\r\n * incoming one by fingerprint, adding new tags and removing gone ones.\r\n * Tags shared between pages (e.g. a layout stylesheet) are left untouched\r\n * so there is no removal/re-insertion flash.\r\n * - New tags are always inserted before <!--/n-head--> so they stay inside\r\n * the tracked block and remain visible to the diff on subsequent navigations.\r\n */\r\n\r\n// \u2500\u2500\u2500 History patch \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Patches history.pushState and history.replaceState to fire a custom\r\n * 'locationchange' event on window. Also listens to 'popstate' for\r\n * back/forward navigation.\r\n *\r\n * Called after initRuntime sets up the navigation listener so there is no\r\n * race between the event firing and the listener being registered.\r\n */\r\nexport function setupLocationChangeMonitor(): void {\r\n const originalPushState = window.history.pushState.bind(window.history);\r\n const originalReplaceState = window.history.replaceState.bind(window.history);\r\n\r\n const dispatch = (href?: any) =>\r\n window.dispatchEvent(new CustomEvent('locationchange', { detail: { href } }));\r\n\r\n window.history.pushState = function (...args) {\r\n originalPushState(...args);\r\n dispatch(args[2]); // args[2] is the URL\r\n };\r\n\r\n window.history.replaceState = function (...args) {\r\n originalReplaceState(...args);\r\n dispatch(args[2]);\r\n };\r\n\r\n // Back/forward navigation via the browser's native UI.\r\n window.addEventListener('popstate', () => dispatch(window.location.pathname));\r\n}\r\n\r\n// \u2500\u2500\u2500 Logger \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\ntype ClientDebugLevel = 'silent' | 'error' | 'info' | 'verbose';\r\n\r\n/**\r\n * Returns a thin logger whose methods are no-ops unless `level` allows them.\r\n * The server embeds the active debug level in the __n_data JSON blob so the\r\n * client respects the same setting as the server.\r\n */\r\nfunction makeLogger(level: ClientDebugLevel) {\r\n return {\r\n verbose: (...a: any[]) => { if (level === 'verbose') console.log(...a); },\r\n info: (...a: any[]) => { if (level === 'verbose' || level === 'info') console.log(...a); },\r\n warn: (...a: any[]) => { if (level === 'verbose' || level === 'info') console.warn(...a); },\r\n error: (...a: any[]) => { if (level !== 'silent') console.error(...a); },\r\n };\r\n}\r\n\r\n// \u2500\u2500\u2500 Serialized node types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/** The wire format for React elements embedded in hydration props. */\r\ntype SerializedNode =\r\n | null\r\n | undefined\r\n | string\r\n | number\r\n | boolean\r\n | SerializedNode[]\r\n | { __re: 'html'; tag: string; props: Record<string, any> }\r\n | { __re: 'client'; componentId: string; props: Record<string, any> }\r\n | Record<string, any>;\r\n\r\ntype ModuleMap = Map<string, any>; // componentId \u2192 default export\r\n\r\n// \u2500\u2500\u2500 Prop reconstruction \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Recursively turns the server's serialized node tree back into real React\r\n * elements so they can be passed as props to hydrated components.\r\n *\r\n * The server serializes JSX passed as props (e.g. `<Button icon={<Icon />}>`)\r\n * into a JSON-safe format. This function reverses that process.\r\n */\r\nasync function reconstructElement(node: SerializedNode, mods: ModuleMap): Promise<any> {\r\n if (node === null || node === undefined) return node;\r\n if (typeof node !== 'object') return node; // primitive \u2014 pass through\r\n\r\n if (Array.isArray(node)) {\r\n const items = await Promise.all(node.map(n => reconstructElement(n, mods)));\r\n // Add index-based keys to React elements in the array to avoid the\r\n // \"Each child in a list should have a unique key prop\" warning.\r\n const React = await import('react');\r\n return items.map((el, i) =>\r\n el && typeof el === 'object' && el.$$typeof\r\n ? React.default.cloneElement(el, { key: el.key ?? i })\r\n : el,\r\n );\r\n }\r\n\r\n // Client component \u2014 look up the loaded module by ID.\r\n if ((node as any).__re === 'client') {\r\n const n = node as { __re: 'client'; componentId: string; props: Record<string, any> };\r\n const Comp = mods.get(n.componentId);\r\n if (!Comp) return null;\r\n const React = await import('react');\r\n return React.default.createElement(Comp, await reconstructProps(n.props, mods));\r\n }\r\n\r\n // Native HTML element (e.g. <div>, <span>).\r\n if ((node as any).__re === 'html') {\r\n const n = node as { __re: 'html'; tag: string; props: Record<string, any> };\r\n const React = await import('react');\r\n return React.default.createElement(n.tag, await reconstructProps(n.props, mods));\r\n }\r\n\r\n // Plain object \u2014 pass through as-is.\r\n return node;\r\n}\r\n\r\n/** Reconstructs every value in a props object, handling nested serialized nodes. */\r\nasync function reconstructProps(\r\n props: Record<string, any> | null | undefined,\r\n mods: ModuleMap,\r\n): Promise<Record<string, any>> {\r\n if (!props || typeof props !== 'object' || Array.isArray(props))\r\n return reconstructElement(props as any, mods);\r\n\r\n const out: Record<string, any> = {};\r\n for (const [k, v] of Object.entries(props))\r\n out[k] = await reconstructElement(v, mods);\r\n return out;\r\n}\r\n\r\n// \u2500\u2500\u2500 Module loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Dynamically imports each client component bundle from /__client-component/.\r\n * All fetches are issued in parallel; failures are logged but do not abort\r\n * the rest of the hydration pass.\r\n *\r\n * @param bust Optional cache-busting suffix appended as `?t=<bust>`.\r\n * Used during HMR navigation to bypass the module cache.\r\n */\r\nasync function loadModules(\r\n ids: string[],\r\n log: ReturnType<typeof makeLogger>,\r\n bust = '',\r\n): Promise<ModuleMap> {\r\n const mods: ModuleMap = new Map();\r\n await Promise.all(\r\n ids.map(async (id) => {\r\n try {\r\n const url = `/__client-component/${id}.js` + (bust ? `?t=${bust}` : '');\r\n const m = await import(url);\r\n mods.set(id, m.default);\r\n log.verbose('\u2713 Loaded:', id);\r\n } catch (err) {\r\n log.error('\u2717 Load failed:', id, err);\r\n }\r\n }),\r\n );\r\n return mods;\r\n}\r\n\r\n// \u2500\u2500\u2500 Root mounting \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/** All active React roots \u2014 tracked so they can be unmounted before navigation. */\r\ntype ReactRoot = { unmount(): void };\r\nconst activeRoots: ReactRoot[] = [];\r\n\r\n/**\r\n * Finds every `[data-hydrate-id]` span in the document and calls hydrateRoot()\r\n * on it. hydrateRoot reconciles React's virtual DOM against the existing server\r\n * HTML without discarding it, which avoids a visible flash on both initial load\r\n * and SPA navigation (where we set innerHTML to fresh SSR output before calling\r\n * mountNodes).\r\n *\r\n * Nested markers are skipped \u2014 the parent's React tree owns its children.\r\n */\r\nasync function mountNodes(\r\n mods: ModuleMap,\r\n log: ReturnType<typeof makeLogger>,\r\n): Promise<void> {\r\n const { hydrateRoot, createRoot } = await import('react-dom/client');\r\n const React = await import('react');\r\n\r\n const nodes = document.querySelectorAll<HTMLElement>('[data-hydrate-id]');\r\n log.verbose('Found', nodes.length, 'hydration point(s)');\r\n\r\n for (const node of nodes) {\r\n // Skip nested markers \u2014 the outer component owns its children.\r\n if (node.parentElement?.closest('[data-hydrate-id]')) continue;\r\n\r\n const id = node.getAttribute('data-hydrate-id')!;\r\n const Comp = mods.get(id);\r\n if (!Comp) { log.warn('No module for', id); continue; }\r\n\r\n let rawProps: Record<string, any> = {};\r\n try {\r\n rawProps = JSON.parse(node.getAttribute('data-hydrate-props') || '{}');\r\n } catch (e) {\r\n log.error('Props parse error for', id, e);\r\n }\r\n\r\n try {\r\n const element = React.default.createElement(Comp, await reconstructProps(rawProps, mods));\r\n\r\n // hydrateRoot reconciles against existing server HTML (initial page load).\r\n // createRoot renders fresh when the span is empty (HMR path \u2014 server sent\r\n // skipClientSSR=true so the span has no pre-rendered content to reconcile).\r\n let root: ReactRoot;\r\n if (node.innerHTML.trim()) {\r\n root = hydrateRoot(node, element);\r\n } else {\r\n const r = createRoot(node);\r\n r.render(element);\r\n root = r;\r\n }\r\n\r\n activeRoots.push(root);\r\n log.verbose('\u2713 Mounted:', id);\r\n } catch (err) {\r\n log.error('\u2717 Mount failed:', id, err);\r\n }\r\n }\r\n}\r\n\r\n// \u2500\u2500\u2500 Head tag sync \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Walks a <head> element and returns every Element node that lives between\r\n * the <!--n-head--> and <!--/n-head--> sentinel comments, plus the closing\r\n * comment node itself (used as the insertion anchor).\r\n *\r\n * The SSR renderer emits these sentinels around every useHtml()-generated tag\r\n * so the client can manage exactly that set without touching permanent tags\r\n * (charset, viewport, importmap, runtime <script>).\r\n */\r\nfunction headBlock(head: HTMLHeadElement): { nodes: Element[]; closeComment: Comment | null } {\r\n const nodes: Element[] = [];\r\n let closeComment: Comment | null = null;\r\n let inside = false;\r\n\r\n for (const child of Array.from(head.childNodes)) {\r\n if (child.nodeType === Node.COMMENT_NODE) {\r\n const text = (child as Comment).data.trim();\r\n if (text === 'n-head') { inside = true; continue; }\r\n if (text === '/n-head') { closeComment = child as Comment; inside = false; continue; }\r\n }\r\n if (inside && child.nodeType === Node.ELEMENT_NODE)\r\n nodes.push(child as Element);\r\n }\r\n\r\n return { nodes, closeComment };\r\n}\r\n\r\n/** Stable key for an Element: tag name + sorted attribute list (name=value pairs). */\r\nfunction fingerprint(el: Element): string {\r\n return el.tagName + '|' + Array.from(el.attributes)\r\n .sort((a, b) => a.name.localeCompare(b.name))\r\n .map(a => `${a.name}=${a.value}`)\r\n .join('&');\r\n}\r\n\r\n/**\r\n * Diffs the live <!--n-head--> block against the incoming document's block and\r\n * applies the minimal set of DOM mutations:\r\n *\r\n * - Non-script tags (meta, link, style): fingerprint-diffed so shared layout\r\n * tags are left untouched (avoids stylesheet flash on navigation).\r\n * - Script tags: always removed and re-inserted as fresh elements so the\r\n * browser re-executes them and re-fetches any changed src file.\r\n * (Fingerprint diffing silently skips re-execution when src is unchanged.)\r\n *\r\n * If the live head has no sentinel block yet (e.g. initial page had no useHtml\r\n * tags), both sentinel comments are created on the fly.\r\n */\r\nfunction syncHeadTags(doc: Document): void {\r\n const live = headBlock(document.head);\r\n const next = headBlock(doc.head);\r\n\r\n // Ensure we have an anchor to insert before.\r\n let anchor = live.closeComment;\r\n if (!anchor) {\r\n document.head.appendChild(document.createComment('n-head'));\r\n anchor = document.createComment('/n-head');\r\n document.head.appendChild(anchor);\r\n }\r\n\r\n // \u2500\u2500 Scripts: always replace \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n // Remove all live script tags and re-insert fresh ones so the browser\r\n // executes them. src gets cache-busted so the latest file is fetched.\r\n for (const el of live.nodes)\r\n if (el.tagName === 'SCRIPT') el.remove();\r\n\r\n for (const el of next.nodes) {\r\n if (el.tagName === 'SCRIPT')\r\n document.head.insertBefore(cloneScriptForExecution(el), anchor);\r\n }\r\n\r\n // \u2500\u2500 Everything else: fingerprint diff \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n const liveMap = new Map<string, Element>();\r\n for (const el of live.nodes) if (el.tagName !== 'SCRIPT') liveMap.set(fingerprint(el), el);\r\n\r\n const nextMap = new Map<string, Element>();\r\n for (const el of next.nodes) if (el.tagName !== 'SCRIPT') nextMap.set(fingerprint(el), el);\r\n\r\n for (const [fp, el] of nextMap)\r\n if (!liveMap.has(fp)) document.head.insertBefore(el, anchor);\r\n\r\n for (const [fp, el] of liveMap)\r\n if (!nextMap.has(fp)) el.remove();\r\n}\r\n\r\n/**\r\n * Walks a <body> element and returns every Element node that lives between\r\n * the <!--n-body-scripts--> and <!--/n-body-scripts--> sentinel comments,\r\n * plus the closing comment node used as the insertion anchor.\r\n *\r\n * The SSR renderer emits these sentinels around every useHtml() body script\r\n * so the client can manage exactly that set without touching permanent nodes.\r\n */\r\nfunction bodyScriptsBlock(body: HTMLBodyElement | Element): { nodes: Element[]; closeComment: Comment | null } {\r\n const nodes: Element[] = [];\r\n let closeComment: Comment | null = null;\r\n let inside = false;\r\n\r\n for (const child of Array.from(body.childNodes)) {\r\n if (child.nodeType === Node.COMMENT_NODE) {\r\n const text = (child as Comment).data.trim();\r\n if (text === 'n-body-scripts') { inside = true; continue; }\r\n if (text === '/n-body-scripts') { closeComment = child as Comment; inside = false; continue; }\r\n }\r\n if (inside && child.nodeType === Node.ELEMENT_NODE)\r\n nodes.push(child as Element);\r\n }\r\n\r\n return { nodes, closeComment };\r\n}\r\n\r\n/**\r\n * Creates a fresh <script> element from a parsed source element so the browser\r\n * actually executes it when inserted into the live document.\r\n *\r\n * Why: browsers only execute a <script> that is *created and inserted* into\r\n * the live document. Nodes moved from a DOMParser document are auto-adopted\r\n * but their script is silently skipped. Cloning via createElement is required.\r\n *\r\n * Cache-busting: src-based scripts get a ?t=<timestamp> query appended so the\r\n * browser always fetches the latest version from the server on HMR updates,\r\n * bypassing the module/response cache.\r\n */\r\nfunction cloneScriptForExecution(src: Element): HTMLScriptElement {\r\n const el = document.createElement('script');\r\n for (const { name, value } of Array.from(src.attributes)) {\r\n if (name === 'src') {\r\n // Append a timestamp to force the browser to re-fetch the script file.\r\n const url = new URL(value, location.href);\r\n url.searchParams.set('t', String(Date.now()));\r\n el.setAttribute('src', url.toString());\r\n } else {\r\n el.setAttribute(name, value);\r\n }\r\n }\r\n // Copy inline content (for content-based scripts).\r\n if (src.textContent) el.textContent = src.textContent;\r\n return el;\r\n}\r\n\r\n/**\r\n * Replaces all body scripts in the <!--n-body-scripts--> sentinel block with\r\n * fresh elements from the incoming document.\r\n *\r\n * Unlike syncHeadTags (which diffs by fingerprint to avoid removing shared\r\n * stylesheets), body scripts must ALWAYS be removed and re-inserted so that:\r\n * - File changes picked up by HMR are actually executed by the browser.\r\n * - src-based scripts are cache-busted so the browser re-fetches them.\r\n *\r\n * Fingerprint diffing would silently skip re-execution of any script whose\r\n * src/attributes haven't changed, even if the file contents changed on disk.\r\n */\r\nfunction syncBodyScripts(doc: Document): void {\r\n const live = bodyScriptsBlock(document.body);\r\n const next = bodyScriptsBlock(doc.body);\r\n\r\n // Always remove every existing body script \u2014 never leave stale ones.\r\n for (const el of live.nodes) el.remove();\r\n\r\n // Ensure we have a sentinel anchor to insert before.\r\n let anchor = live.closeComment;\r\n if (!anchor) {\r\n document.body.appendChild(document.createComment('n-body-scripts'));\r\n anchor = document.createComment('/n-body-scripts');\r\n document.body.appendChild(anchor);\r\n }\r\n\r\n // Insert every script from the incoming document as a brand-new element\r\n // so the browser executes it. src gets a timestamp to bust any cache.\r\n for (const el of next.nodes)\r\n document.body.insertBefore(cloneScriptForExecution(el), anchor);\r\n}\r\n\r\n\r\n\r\n/**\r\n * Syncs attributes from a parsed element onto the live document element.\r\n * Adds/updates attributes present in `next` and removes any that were set\r\n * on `live` but are absent in `next` (clears stale htmlAttrs/bodyAttrs).\r\n */\r\nfunction syncAttrs(live: Element, next: Element): void {\r\n for (const { name, value } of Array.from(next.attributes))\r\n live.setAttribute(name, value);\r\n for (const { name } of Array.from(live.attributes))\r\n if (!next.hasAttribute(name)) live.removeAttribute(name);\r\n}\r\n\r\n/**\r\n * Listens for 'locationchange' events and performs a soft navigation:\r\n *\r\n * 1. Fetch the target URL as HTML (?__hmr=1 skips client-SSR for HMR speed).\r\n * 2. Parse the response with DOMParser.\r\n * 3. Apply all visual DOM changes first (head tags, html/body attrs, #app\r\n * innerHTML, title, __n_data) so the new content is painted before React\r\n * cleanup effects run \u2014 prevents a useHtml restore from briefly undoing\r\n * the new document state.\r\n * 4. Unmount old React roots (runs cleanup effects against the already-updated DOM).\r\n * 5. Re-hydrate new client component markers.\r\n * 6. Scroll to top.\r\n *\r\n * Falls back to a full page reload if anything goes wrong.\r\n */\r\nfunction setupNavigation(log: ReturnType<typeof makeLogger>): void {\r\n window.addEventListener('locationchange', async ({ detail: { href, hmr } }: any) => {\r\n try {\r\n const fetchUrl = hmr\r\n ? href + (href.includes('?') ? '&' : '?') + '__hmr=1'\r\n : href;\r\n\r\n const response = await fetch(fetchUrl, { headers: { Accept: 'text/html' } });\r\n if (!response.ok) {\r\n log.error('Navigation fetch failed:', response.status);\r\n return;\r\n }\r\n\r\n const parser = new DOMParser();\r\n const doc = parser.parseFromString(await response.text(), 'text/html');\r\n const newApp = doc.getElementById('app');\r\n const currApp = document.getElementById('app');\r\n if (!newApp || !currApp) return;\r\n\r\n // \u2500\u2500 Visual update \u2014 all DOM mutations before React teardown \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n // Styles must be in place before new content appears to avoid an unstyled\r\n // flash. Unmounting runs useEffect cleanups (including useHtml restores)\r\n // which would temporarily revert document state if done first.\r\n\r\n // 1. Head tags \u2014 diff-based sync preserves shared layout tags untouched.\r\n syncHeadTags(doc);\r\n\r\n // 2. Body scripts (position='body') \u2014 diff-based sync mirrors head tag logic.\r\n syncBodyScripts(doc);\r\n\r\n // 3. <html> and <body> attributes (lang, class, style, etc.).\r\n syncAttrs(document.documentElement, doc.documentElement);\r\n syncAttrs(document.body, doc.body);\r\n\r\n // 4. Page content.\r\n currApp.innerHTML = newApp.innerHTML;\r\n\r\n // 5. <title>.\r\n const newTitle = doc.querySelector('title');\r\n if (newTitle) document.title = newTitle.textContent ?? '';\r\n\r\n // 6. Runtime data blob \u2014 must come after innerHTML swap so the new\r\n // __n_data element is part of the live document.\r\n const newDataEl = doc.getElementById('__n_data');\r\n const currDataEl = document.getElementById('__n_data');\r\n if (newDataEl && currDataEl) currDataEl.textContent = newDataEl.textContent;\r\n\r\n // \u2500\u2500 React teardown \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n // Unmount after the visual update. Cleanup effects now run against an\r\n // already-updated document, so there is nothing left to visually undo.\r\n activeRoots.splice(0).forEach(r => r.unmount());\r\n\r\n // \u2500\u2500 Re-hydration \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n const navData = JSON.parse(currDataEl?.textContent ?? '{}') as RuntimeData;\r\n log.info('\uD83D\uDD04 Route \u2192', href, '\u2014 mounting', navData.hydrateIds?.length ?? 0, 'component(s)');\r\n\r\n const mods = await loadModules(navData.allIds ?? [], log, String(Date.now()));\r\n await mountNodes(mods, log);\r\n\r\n window.scrollTo(0, 0);\r\n log.info('\uD83C\uDF89 Navigation complete:', href);\r\n } catch (err) {\r\n log.error('Navigation error, falling back to full reload:', err);\r\n window.location.href = href;\r\n }\r\n });\r\n}\r\n\r\n// \u2500\u2500\u2500 Public API \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/** Shape of the JSON blob embedded as #__n_data in every SSR page. */\r\nexport interface RuntimeData {\r\n /** IDs of client components actually rendered on this page (subset of allIds). */\r\n hydrateIds: string[];\r\n /** All client component IDs reachable from this page, including layouts.\r\n * Pre-loaded so SPA navigations to related pages feel instant. */\r\n allIds: string[];\r\n url: string;\r\n params: Record<string, any>;\r\n /** Query string parameters parsed from the URL. Multi-value keys are arrays. */\r\n query: Record<string, string | string[]>;\r\n /**\r\n * Safe subset of the incoming request headers (cookie, authorization, and\r\n * proxy-authorization are stripped before embedding in the HTML document).\r\n */\r\n headers: Record<string, string>;\r\n debug: ClientDebugLevel;\r\n}\r\n\r\n/**\r\n * Bootstraps the NukeJS client runtime.\r\n *\r\n * Called once per page load from the inline <script type=\"module\"> injected\r\n * by the SSR renderer:\r\n *\r\n * ```js\r\n * const { initRuntime } = await import('nukejs');\r\n * const data = JSON.parse(document.getElementById('__n_data').textContent);\r\n * await initRuntime(data);\r\n * ```\r\n *\r\n * Order of operations:\r\n * 1. Create the logger at the configured debug level.\r\n * 2. Wire up SPA navigation listener.\r\n * 3. Load all client component bundles in parallel.\r\n * 4. Hydrate every [data-hydrate-id] node.\r\n * 5. Patch history.pushState/replaceState so Link clicks trigger navigation.\r\n */\r\nexport async function initRuntime(data: RuntimeData): Promise<void> {\r\n const log = makeLogger(data.debug ?? 'silent');\r\n\r\n log.info('\uD83D\uDE80 Partial hydration:', data.hydrateIds.length, 'root component(s)');\r\n\r\n // Set up navigation first so any 'locationchange' fired during hydration\r\n // is captured (e.g. a redirect side-effect inside a component).\r\n setupNavigation(log);\r\n\r\n // Load all component bundles (not just hydrateIds) so SPA navigations to\r\n // related pages can mount their components without an extra network round-trip.\r\n const mods = await loadModules(data.allIds, log);\r\n await mountNodes(mods, log);\r\n\r\n log.info('\uD83C\uDF89 Done!');\r\n\r\n // Patch history last so pushState calls during hydration don't trigger a\r\n // navigation before roots are ready.\r\n setupLocationChangeMonitor();\r\n}"],
5
- "mappings": "AA+CO,SAAS,6BAAmC;AACjD,QAAM,oBAAuB,OAAO,QAAQ,UAAU,KAAK,OAAO,OAAO;AACzE,QAAM,uBAAuB,OAAO,QAAQ,aAAa,KAAK,OAAO,OAAO;AAE5E,QAAM,WAAW,CAAC,SAChB,OAAO,cAAc,IAAI,YAAY,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;AAE9E,SAAO,QAAQ,YAAY,YAAa,MAAM;AAC5C,sBAAkB,GAAG,IAAI;AACzB,aAAS,KAAK,CAAC,CAAC;AAAA,EAClB;AAEA,SAAO,QAAQ,eAAe,YAAa,MAAM;AAC/C,yBAAqB,GAAG,IAAI;AAC5B,aAAS,KAAK,CAAC,CAAC;AAAA,EAClB;AAGA,SAAO,iBAAiB,YAAY,MAAM,SAAS,OAAO,SAAS,QAAQ,CAAC;AAC9E;AAWA,SAAS,WAAW,OAAyB;AAC3C,SAAO;AAAA,IACL,SAAS,IAAI,MAAa;AAAE,UAAI,UAAU,UAAW,SAAQ,IAAI,GAAG,CAAC;AAAA,IAAG;AAAA,IACxE,MAAS,IAAI,MAAa;AAAE,UAAI,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MAAM,kDAAkD,GAAG;AAC/D,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AA0CA,eAAsB,YAAY,MAAkC;AAClE,QAAM,MAAM,WAAW,KAAK,SAAS,QAAQ;AAE7C,MAAI,KAAK,gCAAyB,KAAK,WAAW,QAAQ,mBAAmB;AAI7E,kBAAgB,GAAG;AAInB,QAAM,OAAO,MAAM,YAAY,KAAK,QAAQ,GAAG;AAC/C,QAAM,WAAW,MAAM,GAAG;AAE1B,MAAI,KAAK,iBAAU;AAInB,6BAA2B;AAC7B;",
6
- "names": []
7
- }
package/dist/bundler.d.ts DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * bundler.ts — Dev-Mode On-Demand Bundler
3
- *
4
- * Handles the three internal JS routes served only in `nuke dev`:
5
- *
6
- * /__react.js — Full React + ReactDOM browser bundle.
7
- * All hooks, jsx-runtime, hydrateRoot, createRoot.
8
- * Served once and cached by the browser.
9
- *
10
- * /__n.js — NukeJS client runtime (bundle.ts compiled to ESM).
11
- * Provides initRuntime and SPA navigation.
12
- *
13
- * /__client-component/<id> — Individual "use client" component bundles.
14
- * Built on-demand the first time they're requested.
15
- * Re-built on every request in dev (no disk cache).
16
- *
17
- * In production (`nuke build`), equivalent bundles are written to dist/static/
18
- * by build-common.ts instead of being served dynamically.
19
- */
20
- import type { ServerResponse } from 'http';
21
- /**
22
- * Bundles a single "use client" file for the browser.
23
- *
24
- * React and react-dom/client are kept external so the importmap can resolve
25
- * them to the already-loaded /__react.js bundle (avoids shipping React twice).
26
- *
27
- * @param filePath Absolute path to the source file.
28
- * @returns ESM string ready to serve as application/javascript.
29
- */
30
- export declare function bundleClientComponent(filePath: string): Promise<string>;
31
- /**
32
- * Looks up a client component by its content-hash ID (e.g. `cc_a1b2c3d4`),
33
- * bundles it on-demand, and writes the result to the HTTP response.
34
- *
35
- * The ID→path mapping comes from the component analyzer cache, which is
36
- * populated during SSR as pages and their layouts are rendered.
37
- */
38
- export declare function serveClientComponentBundle(componentId: string, res: ServerResponse): Promise<void>;
39
- /**
40
- * Builds and serves the unified React browser bundle to /__react.js.
41
- *
42
- * Exports every public React API so client components can import from 'react'
43
- * or 'react-dom/client' and have them resolve via the importmap to this single
44
- * pre-loaded bundle — no duplicate copies of React in the browser.
45
- *
46
- * esbuild aliases point at the project's installed React version so the bundle
47
- * always matches what the server is actually running.
48
- */
49
- export declare function serveReactBundle(res: ServerResponse): Promise<void>;
50
- /**
51
- * Bundles and serves the NukeJS client runtime to /__n.js.
52
- *
53
- * The entry point is bundle.ts (or bundle.js in production dist/).
54
- * React is kept external so it resolves via the importmap to /__react.js.
55
- *
56
- * Minified because this script is loaded on every page request.
57
- */
58
- export declare function serveNukeBundle(res: ServerResponse): Promise<void>;
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/bundler.ts"],
4
- "sourcesContent": ["/**\r\n * bundler.ts \u2014 Dev-Mode On-Demand Bundler\r\n *\r\n * Handles the three internal JS routes served only in `nuke dev`:\r\n *\r\n * /__react.js \u2014 Full React + ReactDOM browser bundle.\r\n * All hooks, jsx-runtime, hydrateRoot, createRoot.\r\n * Served once and cached by the browser.\r\n *\r\n * /__n.js \u2014 NukeJS client runtime (bundle.ts compiled to ESM).\r\n * Provides initRuntime and SPA navigation.\r\n *\r\n * /__client-component/<id> \u2014 Individual \"use client\" component bundles.\r\n * Built on-demand the first time they're requested.\r\n * Re-built on every request in dev (no disk cache).\r\n *\r\n * In production (`nuke build`), equivalent bundles are written to dist/static/\r\n * by build-common.ts instead of being served dynamically.\r\n */\r\n\r\nimport path from 'path';\r\nimport { fileURLToPath } from 'url';\r\nimport { build } from 'esbuild';\r\nimport type { ServerResponse } from 'http';\r\nimport { log } from './logger';\r\nimport { getComponentById } from './component-analyzer';\r\n\r\n// \u2500\u2500\u2500 Bundle caches \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n// Cache Promises (not just results) so concurrent requests share one build\r\n// instead of each spawning their own esbuild process.\r\nlet reactBundlePromise: Promise<string> | null = null;\r\nlet nukeBundlePromise: Promise<string> | null = null;\r\n\r\n// \u2500\u2500\u2500 Client component bundle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Bundles a single \"use client\" file for the browser.\r\n *\r\n * React and react-dom/client are kept external so the importmap can resolve\r\n * them to the already-loaded /__react.js bundle (avoids shipping React twice).\r\n *\r\n * @param filePath Absolute path to the source file.\r\n * @returns ESM string ready to serve as application/javascript.\r\n */\r\nexport async function bundleClientComponent(filePath: string): Promise<string> {\r\n const result = await build({\r\n entryPoints: [filePath],\r\n bundle: true,\r\n format: 'esm',\r\n platform: 'browser',\r\n write: false,\r\n jsx: 'automatic',\r\n // Keep React external \u2014 resolved by the importmap to /__react.js\r\n external: ['react', 'react-dom/client', 'react/jsx-runtime'],\r\n });\r\n return result.outputFiles[0].text;\r\n}\r\n\r\n/**\r\n * Looks up a client component by its content-hash ID (e.g. `cc_a1b2c3d4`),\r\n * bundles it on-demand, and writes the result to the HTTP response.\r\n *\r\n * The ID\u2192path mapping comes from the component analyzer cache, which is\r\n * populated during SSR as pages and their layouts are rendered.\r\n */\r\nexport async function serveClientComponentBundle(\r\n componentId: string,\r\n res: ServerResponse,\r\n): Promise<void> {\r\n const filePath = getComponentById(componentId);\r\n if (filePath) {\r\n log.verbose(`Bundling client component: ${componentId} (${path.basename(filePath)})`);\r\n res.setHeader('Content-Type', 'application/javascript');\r\n res.end(await bundleClientComponent(filePath));\r\n return;\r\n }\r\n\r\n // ID not found \u2014 either the page hasn't been visited yet (cache is empty)\r\n // or the ID is stale.\r\n log.error(`Client component not found: ${componentId}`);\r\n res.statusCode = 404;\r\n res.end('Client component not found');\r\n}\r\n\r\n// \u2500\u2500\u2500 React bundle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Builds and serves the unified React browser bundle to /__react.js.\r\n *\r\n * Exports every public React API so client components can import from 'react'\r\n * or 'react-dom/client' and have them resolve via the importmap to this single\r\n * pre-loaded bundle \u2014 no duplicate copies of React in the browser.\r\n *\r\n * esbuild aliases point at the project's installed React version so the bundle\r\n * always matches what the server is actually running.\r\n */\r\nexport async function serveReactBundle(res: ServerResponse): Promise<void> {\r\n log.verbose('Bundling React runtime');\r\n\r\n if (!reactBundlePromise) {\r\n reactBundlePromise = build({\r\n stdin: {\r\n contents: `\r\n import React, {\r\n useState, useEffect, useContext, useReducer, useCallback, useMemo,\r\n useRef, useImperativeHandle, useLayoutEffect, useDebugValue,\r\n useDeferredValue, useTransition, useId, useSyncExternalStore,\r\n useInsertionEffect, createContext, forwardRef, memo, lazy,\r\n Suspense, Fragment, StrictMode, Component, PureComponent\r\n } from 'react';\r\n import { jsx, jsxs } from 'react/jsx-runtime';\r\n import { hydrateRoot, createRoot } from 'react-dom/client';\r\n\r\n export {\r\n useState, useEffect, useContext, useReducer, useCallback, useMemo,\r\n useRef, useImperativeHandle, useLayoutEffect, useDebugValue,\r\n useDeferredValue, useTransition, useId, useSyncExternalStore,\r\n useInsertionEffect, createContext, forwardRef, memo, lazy,\r\n Suspense, Fragment, StrictMode, Component, PureComponent,\r\n hydrateRoot, createRoot, jsx, jsxs\r\n };\r\n export default React;\r\n `,\r\n loader: 'ts',\r\n },\r\n bundle: true,\r\n write: false,\r\n treeShaking: true,\r\n minify: false,\r\n format: 'esm',\r\n jsx: 'automatic',\r\n alias: {\r\n react: path.dirname(fileURLToPath(import.meta.resolve('react/package.json'))),\r\n 'react-dom': path.dirname(fileURLToPath(import.meta.resolve('react-dom/package.json'))),\r\n },\r\n define: { 'process.env.NODE_ENV': '\"development\"' },\r\n }).then(r => r.outputFiles[0].text);\r\n }\r\n\r\n res.setHeader('Content-Type', 'application/javascript');\r\n res.end(await reactBundlePromise);\r\n}\r\n\r\n// \u2500\u2500\u2500 NukeJS runtime bundle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n/**\r\n * Bundles and serves the NukeJS client runtime to /__n.js.\r\n *\r\n * The entry point is bundle.ts (or bundle.js in production dist/).\r\n * React is kept external so it resolves via the importmap to /__react.js.\r\n *\r\n * Minified because this script is loaded on every page request.\r\n */\r\nexport async function serveNukeBundle(res: ServerResponse): Promise<void> {\r\n log.verbose('Bundling nuke runtime');\r\n\r\n if (!nukeBundlePromise) {\r\n const dir = path.dirname(fileURLToPath(import.meta.url));\r\n const entry = path.join(dir, `bundle.${dir.endsWith('dist') ? 'js' : 'ts'}`);\r\n nukeBundlePromise = build({\r\n entryPoints: [entry],\r\n write: false,\r\n format: 'esm',\r\n minify: true,\r\n bundle: true,\r\n external: ['react', 'react-dom/client'],\r\n }).then(r => r.outputFiles[0].text);\r\n }\r\n\r\n res.setHeader('Content-Type', 'application/javascript');\r\n res.end(await nukeBundlePromise);\r\n}"],
5
- "mappings": "AAoBA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,aAAa;AAEtB,SAAS,WAAW;AACpB,SAAS,wBAAwB;AAMjC,IAAI,qBAA6C;AACjD,IAAI,oBAA4C;AAahD,eAAsB,sBAAsB,UAAmC;AAC7E,QAAM,SAAS,MAAM,MAAM;AAAA,IACzB,aAAa,CAAC,QAAQ;AAAA,IACtB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,OAAO;AAAA,IACP,KAAK;AAAA;AAAA,IAEL,UAAU,CAAC,SAAS,oBAAoB,mBAAmB;AAAA,EAC7D,CAAC;AACD,SAAO,OAAO,YAAY,CAAC,EAAE;AAC/B;AASA,eAAsB,2BACpB,aACA,KACe;AACf,QAAM,WAAW,iBAAiB,WAAW;AAC7C,MAAI,UAAU;AACZ,QAAI,QAAQ,8BAA8B,WAAW,KAAK,KAAK,SAAS,QAAQ,CAAC,GAAG;AACpF,QAAI,UAAU,gBAAgB,wBAAwB;AACtD,QAAI,IAAI,MAAM,sBAAsB,QAAQ,CAAC;AAC7C;AAAA,EACF;AAIA,MAAI,MAAM,+BAA+B,WAAW,EAAE;AACtD,MAAI,aAAa;AACjB,MAAI,IAAI,4BAA4B;AACtC;AAcA,eAAsB,iBAAiB,KAAoC;AACzE,MAAI,QAAQ,wBAAwB;AAEpC,MAAI,CAAC,oBAAoB;AACvB,yBAAqB,MAAM;AAAA,MACzB,OAAO;AAAA,QACL,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAqBV,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,OAAO;AAAA,QACL,OAAO,KAAK,QAAQ,cAAc,YAAY,QAAQ,oBAAoB,CAAC,CAAC;AAAA,QAC5E,aAAa,KAAK,QAAQ,cAAc,YAAY,QAAQ,wBAAwB,CAAC,CAAC;AAAA,MACxF;AAAA,MACA,QAAQ,EAAE,wBAAwB,gBAAgB;AAAA,IACpD,CAAC,EAAE,KAAK,OAAK,EAAE,YAAY,CAAC,EAAE,IAAI;AAAA,EACpC;AAEA,MAAI,UAAU,gBAAgB,wBAAwB;AACtD,MAAI,IAAI,MAAM,kBAAkB;AAClC;AAYA,eAAsB,gBAAgB,KAAoC;AACxE,MAAI,QAAQ,uBAAuB;AAEnC,MAAI,CAAC,mBAAmB;AACtB,UAAM,MAAM,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AACvD,UAAM,QAAQ,KAAK,KAAK,KAAK,UAAU,IAAI,SAAS,MAAM,IAAI,OAAO,IAAI,EAAE;AAC3E,wBAAoB,MAAM;AAAA,MACxB,aAAa,CAAC,KAAK;AAAA,MACnB,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,UAAU,CAAC,SAAS,kBAAkB;AAAA,IACxC,CAAC,EAAE,KAAK,OAAK,EAAE,YAAY,CAAC,EAAE,IAAI;AAAA,EACpC;AAEA,MAAI,UAAU,gBAAgB,wBAAwB;AACtD,MAAI,IAAI,MAAM,iBAAiB;AACjC;",
6
- "names": []
7
- }
@@ -1,75 +0,0 @@
1
- /**
2
- * component-analyzer.ts — Static Import Analyzer & Client Component Registry
3
- *
4
- * This module solves a core problem in NukeJS's partial hydration model:
5
- * the server needs to know *at render time* which components in a page's
6
- * import tree are "use client" boundaries so it can:
7
- *
8
- * 1. Emit <span data-hydrate-id="…"> markers instead of rendering them.
9
- * 2. Inject the matching bundle URLs into the page's runtime data blob.
10
- * 3. Serialize the props passed to those components so the browser can
11
- * reconstruct them after loading the bundle.
12
- *
13
- * How it works:
14
- * - analyzeComponent() checks whether a file starts with "use client"
15
- * and assigns a stable content-hash ID if it does.
16
- * - extractImports() parses `import … from '…'` statements with a
17
- * regex and resolves relative/absolute paths.
18
- * - findClientComponentsInTree() recursively walks the import graph, stopping
19
- * at client boundaries (they own their subtree).
20
- *
21
- * Results are memoised in `componentCache` (process-lifetime) so repeated SSR
22
- * renders don't re-read and re-hash files they've already seen.
23
- *
24
- * ID scheme:
25
- * The ID for a client component is `cc_` + the first 8 hex chars of the MD5
26
- * hash of its path relative to pagesDir. This is stable across restarts and
27
- * matches what the browser will request from /__client-component/<id>.js.
28
- */
29
- export interface ComponentInfo {
30
- filePath: string;
31
- /** True when the file's first non-comment line is "use client". */
32
- isClientComponent: boolean;
33
- /** Stable hash-based ID, present only for client components. */
34
- clientComponentId?: string;
35
- /**
36
- * The name of the default-exported component function.
37
- * Handles both source format (`export default Link`) and esbuild's compiled
38
- * format (`var Link_default = Link; export { Link_default as default }`).
39
- */
40
- exportedName?: string;
41
- }
42
- /**
43
- * Analyses a component file and returns cached results on subsequent calls.
44
- *
45
- * @param filePath Absolute path to the source file.
46
- * @param pagesDir Absolute path to the pages root (used for ID generation).
47
- */
48
- export declare function analyzeComponent(filePath: string, pagesDir: string): ComponentInfo;
49
- /**
50
- * Recursively walks the import graph from `filePath`, collecting every
51
- * "use client" file encountered.
52
- *
53
- * The walk stops at client boundaries: a "use client" file is recorded and
54
- * its own imports are NOT walked (the client runtime handles their subtree).
55
- *
56
- * The `visited` set prevents infinite loops from circular imports.
57
- *
58
- * @returns Map<id, absoluteFilePath> for every client component reachable
59
- * from `filePath` (including `filePath` itself if it's a client).
60
- */
61
- export declare function findClientComponentsInTree(filePath: string, pagesDir: string, visited?: Set<string>): Map<string, string>;
62
- /**
63
- * Looks up the absolute file path for a client component by its ID.
64
- * Returns undefined when the ID is not in the cache.
65
- */
66
- export declare function getComponentById(id: string): string | undefined;
67
- /** Returns the live component cache (used by bundler.ts for ID→path lookup). */
68
- export declare function getComponentCache(): Map<string, ComponentInfo>;
69
- /**
70
- * Removes a single file's analysis entry from the cache.
71
- * Call this whenever a source file changes in dev mode so the next render
72
- * re-analyses the file (picks up added/removed "use client" directives and
73
- * changed import graphs).
74
- */
75
- export declare function invalidateComponentCache(filePath: string): void;