nukejs 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -5
- package/dist/{as-is/Link.js → Link.js} +3 -1
- package/dist/Link.js.map +7 -0
- package/dist/build-common.d.ts +6 -0
- package/dist/build-common.js +20 -6
- package/dist/build-common.js.map +2 -2
- package/dist/build-node.js.map +1 -1
- package/dist/build-vercel.js.map +1 -1
- package/dist/builder.d.ts +4 -10
- package/dist/builder.js +7 -38
- package/dist/builder.js.map +2 -2
- package/dist/bundle.js +60 -4
- package/dist/bundle.js.map +2 -2
- package/dist/component-analyzer.d.ts +6 -0
- package/dist/component-analyzer.js +12 -1
- package/dist/component-analyzer.js.map +2 -2
- package/dist/hmr-bundle.js +17 -4
- package/dist/hmr-bundle.js.map +2 -2
- package/dist/html-store.d.ts +7 -0
- package/dist/html-store.js.map +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/renderer.js +2 -7
- package/dist/renderer.js.map +2 -2
- package/dist/router.d.ts +20 -19
- package/dist/router.js +14 -6
- package/dist/router.js.map +2 -2
- package/dist/ssr.js +21 -4
- package/dist/ssr.js.map +2 -2
- package/dist/use-html.js +5 -1
- package/dist/use-html.js.map +2 -2
- package/dist/{as-is/useRouter.js → use-router.js} +1 -1
- package/dist/{as-is/useRouter.js.map → use-router.js.map} +2 -2
- package/package.json +1 -1
- package/dist/as-is/Link.js.map +0 -7
- package/dist/as-is/Link.tsx +0 -20
- package/dist/as-is/useRouter.ts +0 -33
- /package/dist/{as-is/Link.d.ts → Link.d.ts} +0 -0
- /package/dist/{as-is/useRouter.d.ts → use-router.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ npm create nuke@latest
|
|
|
21
21
|
- [Static Files](#static-files)
|
|
22
22
|
- [useHtml() — Head Management](#usehtml--head-management)
|
|
23
23
|
- [Configuration](#configuration)
|
|
24
|
+
- [Link Component & Navigation](#link-component--navigation)
|
|
24
25
|
- [Building & Deploying](#building--deploying)
|
|
25
26
|
|
|
26
27
|
## Overview
|
|
@@ -154,6 +155,28 @@ export default async function BlogPost({ slug }: { slug: string }) {
|
|
|
154
155
|
|
|
155
156
|
Route params are passed as props to the component.
|
|
156
157
|
|
|
158
|
+
### Query string params
|
|
159
|
+
|
|
160
|
+
Query string parameters are automatically merged into the page component's props alongside route params. If a query param shares a name with a route param, the route param takes precedence.
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
// app/pages/search.tsx
|
|
164
|
+
// URL: /search?q=nuke&page=2
|
|
165
|
+
export default function Search({ q, page }: { q: string; page: string }) {
|
|
166
|
+
return <h1>Results for "{q}" — page {page}</h1>;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
// app/pages/blog/[slug].tsx
|
|
172
|
+
// URL: /blog/hello-world?preview=true
|
|
173
|
+
export default function BlogPost({ slug, preview }: { slug: string; preview?: string }) {
|
|
174
|
+
return <article data-preview={preview}>{slug}</article>;
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
A query param that appears multiple times (e.g. `?tag=a&tag=b`) is passed as a `string[]`.
|
|
179
|
+
|
|
157
180
|
### Catch-all routes
|
|
158
181
|
|
|
159
182
|
```tsx
|
|
@@ -389,13 +412,13 @@ export default function Layout({ children }: { children: React.ReactNode }) {
|
|
|
389
412
|
| `nuke build` (Node) | Copied to `dist/static/` and served by the production HTTP server |
|
|
390
413
|
| `nuke build` (Vercel) | Copied to `.vercel/output/static/` — served by Vercel's CDN, no function invocation |
|
|
391
414
|
|
|
392
|
-
On Vercel, public files receive the same zero-latency CDN treatment as `
|
|
415
|
+
On Vercel, public files receive the same zero-latency CDN treatment as `__n.js`.
|
|
393
416
|
|
|
394
417
|
---
|
|
395
418
|
|
|
396
419
|
## useHtml() — Head Management
|
|
397
420
|
|
|
398
|
-
The `useHtml()` hook works in both server components and client components to control the document head
|
|
421
|
+
The `useHtml()` hook works in both server components and client components to control the document `<head>`, `<html>` attributes, `<body>` attributes, and scripts injected at the end of `<body>`.
|
|
399
422
|
|
|
400
423
|
```tsx
|
|
401
424
|
import { useHtml } from 'nukejs';
|
|
@@ -434,6 +457,65 @@ Result: "Home | Site"
|
|
|
434
457
|
|
|
435
458
|
The page title always serves as the base value; layout functions wrap it outward.
|
|
436
459
|
|
|
460
|
+
### Script injection & position
|
|
461
|
+
|
|
462
|
+
The `script` option accepts an array of script tags. Each entry supports the standard attributes (`src`, `type`, `async`, `defer`, `content` for inline scripts, etc.) plus a `position` field:
|
|
463
|
+
|
|
464
|
+
| `position` | Where it's injected |
|
|
465
|
+
|---|---|
|
|
466
|
+
| `'head'` (default) | Inside `<head>`, in the managed `<!--n-head-->` block |
|
|
467
|
+
| `'body'` | End of `<body>`, just before `</body>`, in the `<!--n-body-scripts-->` block |
|
|
468
|
+
|
|
469
|
+
**Use `position: 'body'`** for third-party analytics and tracking scripts (Google Analytics, Hotjar, Intercom, etc.) that should load after page content is in the DOM and must not block rendering.
|
|
470
|
+
|
|
471
|
+
```tsx
|
|
472
|
+
// app/pages/layout.tsx — Google Analytics on every page
|
|
473
|
+
import { useHtml } from 'nukejs';
|
|
474
|
+
|
|
475
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
476
|
+
useHtml({
|
|
477
|
+
script: [
|
|
478
|
+
// Load the gtag library — async so it doesn't block rendering
|
|
479
|
+
{
|
|
480
|
+
src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX',
|
|
481
|
+
async: true,
|
|
482
|
+
position: 'body',
|
|
483
|
+
},
|
|
484
|
+
// Inline initialisation — must follow the loader above
|
|
485
|
+
{
|
|
486
|
+
content: `
|
|
487
|
+
window.dataLayer = window.dataLayer || [];
|
|
488
|
+
function gtag(){dataLayer.push(arguments);}
|
|
489
|
+
gtag('js', new Date());
|
|
490
|
+
gtag('config', 'G-XXXXXXXXXX');
|
|
491
|
+
`,
|
|
492
|
+
position: 'body',
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
return <>{children}</>;
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
**Use `position: 'head'` (the default)** for scripts that must run before first paint, such as theme detection to avoid flash-of-unstyled-content:
|
|
502
|
+
|
|
503
|
+
```tsx
|
|
504
|
+
useHtml({
|
|
505
|
+
script: [
|
|
506
|
+
{
|
|
507
|
+
content: `
|
|
508
|
+
const theme = localStorage.getItem('theme') ?? 'light';
|
|
509
|
+
document.documentElement.classList.add(theme);
|
|
510
|
+
`,
|
|
511
|
+
// position defaults to 'head' — runs before the page renders
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
});
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
Both head and body scripts are re-executed on every HMR update and SPA navigation so they always reflect the current page state.
|
|
518
|
+
|
|
437
519
|
---
|
|
438
520
|
|
|
439
521
|
## Configuration
|
|
@@ -512,8 +594,7 @@ dist/
|
|
|
512
594
|
├── api/ # Bundled API route handlers (.mjs)
|
|
513
595
|
├── pages/ # Bundled page handlers (.mjs)
|
|
514
596
|
├── static/
|
|
515
|
-
│ ├──
|
|
516
|
-
│ ├── __n.js # NukeJS client runtime
|
|
597
|
+
│ ├── __n.js # NukeJS client runtime (React + NukeJS bundled together)
|
|
517
598
|
│ ├── __client-component/ # Bundled "use client" component files
|
|
518
599
|
│ └── <app/public files> # Copied from app/public/ at build time
|
|
519
600
|
├── manifest.json # Route dispatch table
|
|
@@ -521,6 +602,7 @@ dist/
|
|
|
521
602
|
```
|
|
522
603
|
|
|
523
604
|
### Vercel
|
|
605
|
+
|
|
524
606
|
Just import the code from GitHub.
|
|
525
607
|
|
|
526
608
|
### Environment variables
|
|
@@ -532,4 +614,4 @@ Just import the code from GitHub.
|
|
|
532
614
|
|
|
533
615
|
## License
|
|
534
616
|
|
|
535
|
-
MIT
|
|
617
|
+
MIT
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import useRouter from "./use-router.js";
|
|
3
4
|
const Link = ({ href, children, className }) => {
|
|
5
|
+
const r = useRouter();
|
|
4
6
|
const handleClick = (e) => {
|
|
5
7
|
e.preventDefault();
|
|
6
|
-
|
|
8
|
+
r.push(href);
|
|
7
9
|
};
|
|
8
10
|
return /* @__PURE__ */ jsx("a", { href, onClick: handleClick, className, children });
|
|
9
11
|
};
|
package/dist/Link.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Link.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\r\nimport useRouter from \"./use-router\"\r\n\r\nconst Link = ({ href, children, className }: {\r\n href: string;\r\n children: React.ReactNode;\r\n className?: string;\r\n}) => {\r\n const r = useRouter()\r\n const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {\r\n e.preventDefault();\r\n r.push(href);\r\n }\r\n return (\r\n <a href={href} onClick={handleClick} className={className} >\r\n {children}\r\n </a >\r\n );\r\n};\r\n\r\nexport default Link;\r\n"],
|
|
5
|
+
"mappings": ";AAcQ;AAbR,OAAO,eAAe;AAEtB,MAAM,OAAO,CAAC,EAAE,MAAM,UAAU,UAAU,MAIpC;AACF,QAAM,IAAI,UAAU;AACpB,QAAM,cAAc,CAAC,MAA2C;AAC5D,MAAE,eAAe;AACjB,MAAE,KAAK,IAAI;AAAA,EACf;AACA,SACI,oBAAC,OAAE,MAAY,SAAS,aAAa,WAChC,UACL;AAER;AAEA,IAAO,eAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/build-common.d.ts
CHANGED
|
@@ -65,6 +65,12 @@ export declare function findPageLayouts(routeFilePath: string, pagesDir: string)
|
|
|
65
65
|
/**
|
|
66
66
|
* Extracts the identifier used as the default export from a component file.
|
|
67
67
|
* Returns null when no default export is found.
|
|
68
|
+
*
|
|
69
|
+
* Handles three formats so that components compiled by esbuild are recognised
|
|
70
|
+
* alongside hand-written source files:
|
|
71
|
+
* 1. Source: `export default function Foo` / `export default Foo`
|
|
72
|
+
* 2. esbuild: `var Foo_default = Foo` (compiled arrow-function component)
|
|
73
|
+
* 3. Re-export: `export { Foo as default }`
|
|
68
74
|
*/
|
|
69
75
|
export declare function extractDefaultExportName(filePath: string): string | null;
|
|
70
76
|
/**
|
package/dist/build-common.js
CHANGED
|
@@ -136,7 +136,13 @@ function findPageLayouts(routeFilePath, pagesDir) {
|
|
|
136
136
|
}
|
|
137
137
|
function extractDefaultExportName(filePath) {
|
|
138
138
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
139
|
-
|
|
139
|
+
let m = content.match(/export\s+default\s+(?:function\s+)?(\w+)/);
|
|
140
|
+
if (m?.[1]) return m[1];
|
|
141
|
+
m = content.match(/var\s+\w+_default\s*=\s*(\w+)/);
|
|
142
|
+
if (m?.[1]) return m[1];
|
|
143
|
+
m = content.match(/export\s*\{[^}]*\b(\w+)\s+as\s+default\b[^}]*\}/);
|
|
144
|
+
if (m?.[1] && !m[1].endsWith("_default")) return m[1];
|
|
145
|
+
return null;
|
|
140
146
|
}
|
|
141
147
|
function collectServerPages(pagesDir) {
|
|
142
148
|
if (!fs.existsSync(pagesDir)) return [];
|
|
@@ -257,6 +263,8 @@ function makePageAdapterSource(opts) {
|
|
|
257
263
|
catchAllNames
|
|
258
264
|
} = opts;
|
|
259
265
|
return `import type { IncomingMessage, ServerResponse } from 'http';
|
|
266
|
+
import { createElement as __createElement__ } from 'react';
|
|
267
|
+
import { renderToString as __renderToString__ } from 'react-dom/server';
|
|
260
268
|
import * as __page__ from ${pageImport};
|
|
261
269
|
${layoutImports}
|
|
262
270
|
|
|
@@ -404,7 +412,7 @@ async function renderNode(node: any, hydrated: Set<string>): Promise<string> {
|
|
|
404
412
|
const serializedProps = serializeProps(props ?? {});
|
|
405
413
|
let ssrHtml: string;
|
|
406
414
|
try {
|
|
407
|
-
ssrHtml =
|
|
415
|
+
ssrHtml = __renderToString__(__createElement__(type as any, props || {}));
|
|
408
416
|
} catch {
|
|
409
417
|
ssrHtml = PRERENDERED_HTML[clientId] ?? '';
|
|
410
418
|
}
|
|
@@ -445,20 +453,26 @@ export default async function handler(req: IncomingMessage, res: ServerResponse)
|
|
|
445
453
|
let appHtml = '';
|
|
446
454
|
const store = await runWithHtmlStore(async () => { appHtml = await renderNode(wrapped, hydrated); });
|
|
447
455
|
|
|
448
|
-
const pageTitle = resolveTitle(store.titleOps, '
|
|
456
|
+
const pageTitle = resolveTitle(store.titleOps, 'NukeJS');
|
|
457
|
+
const headScripts = store.script.filter((s: any) => (s.position ?? 'head') === 'head');
|
|
458
|
+
const bodyScripts = store.script.filter((s: any) => s.position === 'body');
|
|
449
459
|
const headLines = [
|
|
450
460
|
' <meta charset="utf-8" />',
|
|
451
461
|
' <meta name="viewport" content="width=device-width, initial-scale=1" />',
|
|
452
462
|
\` <title>\${escapeHtml(pageTitle)}</title>\`,
|
|
453
|
-
...(store.meta.length || store.link.length || store.style.length ||
|
|
463
|
+
...(store.meta.length || store.link.length || store.style.length || headScripts.length ? [
|
|
454
464
|
' <!--n-head-->',
|
|
455
465
|
...store.meta.map(renderMetaTag),
|
|
456
466
|
...store.link.map(renderLinkTag),
|
|
457
467
|
...store.style.map(renderStyleTag),
|
|
458
|
-
...
|
|
468
|
+
...headScripts.map(renderScriptTag),
|
|
459
469
|
' <!--/n-head-->',
|
|
460
470
|
] : []),
|
|
461
471
|
];
|
|
472
|
+
const bodyScriptLines = bodyScripts.length
|
|
473
|
+
? [' <!--n-body-scripts-->', ...bodyScripts.map(renderScriptTag), ' <!--/n-body-scripts-->']
|
|
474
|
+
: [];
|
|
475
|
+
const bodyScriptsHtml = bodyScriptLines.length ? '\\n' + bodyScriptLines.join('\\n') + '\\n' : '';
|
|
462
476
|
|
|
463
477
|
const runtimeData = JSON.stringify({
|
|
464
478
|
hydrateIds: [...hydrated], allIds: ALL_CLIENT_IDS, url, params, debug: 'silent',
|
|
@@ -490,7 +504,7 @@ export default async function handler(req: IncomingMessage, res: ServerResponse)
|
|
|
490
504
|
const data = JSON.parse(document.getElementById('__n_data').textContent);
|
|
491
505
|
await initRuntime(data);
|
|
492
506
|
</script>
|
|
493
|
-
</body>
|
|
507
|
+
\${bodyScriptsHtml}</body>
|
|
494
508
|
</html>\`;
|
|
495
509
|
|
|
496
510
|
res.statusCode = 200;
|
package/dist/build-common.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/build-common.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * build-common.ts \u2014 Shared Build Logic\n *\n * Used by both build-node.ts and build-vercel.ts.\n *\n * Exports:\n * \u2014 types : AnalyzedRoute, ServerPage, BuiltPage,\n * PageAdapterOptions, PageBundleOptions\n * \u2014 utility helpers : walkFiles, analyzeFile, isServerComponent,\n * findPageLayouts, extractDefaultExportName\n * \u2014 collection : collectServerPages, collectGlobalClientRegistry,\n * buildPerPageRegistry\n * \u2014 template codegen : makeApiAdapterSource, makePageAdapterSource\n * \u2014 bundle ops : bundleApiHandler, bundlePageHandler,\n * bundleClientComponents, buildPages,\n * buildCombinedBundle, copyPublicFiles\n */\n\nimport fs from 'fs';\nimport path from 'path';\nimport { randomBytes } from 'node:crypto';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport { build } from 'esbuild';\nimport { findClientComponentsInTree } from './component-analyzer';\n\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\n\n/**\n * All Node.js built-in module names.\n * Used as the `external` list when bundling for Node so esbuild never tries\n * to inline them, which would produce broken `require()` shims in ESM output.\n */\nconst NODE_BUILTINS = [\n 'node:*',\n 'http', 'https', 'fs', 'path', 'url', 'crypto', 'stream', 'buffer',\n 'events', 'util', 'os', 'net', 'tls', 'child_process', 'worker_threads',\n 'cluster', 'dgram', 'dns', 'readline', 'zlib', 'assert', 'module',\n 'perf_hooks', 'string_decoder', 'timers', 'async_hooks', 'v8', 'vm',\n];\n\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\n\nexport interface AnalyzedRoute {\n /** Regex string matching the URL path, e.g. '^/users/([^/]+)$' */\n srcRegex: string;\n /** Names of captured groups in srcRegex order */\n paramNames: string[];\n /**\n * Subset of paramNames that are catch-all ([...slug] or [[...path]]).\n * Their runtime values are string[] not string.\n */\n catchAllNames: string[];\n /** Function namespace path, e.g. '/api/users' or '/page/about' */\n funcPath: string;\n specificity: number;\n}\n\nexport interface ServerPage extends AnalyzedRoute {\n absPath: string;\n}\n\nexport interface BuiltPage extends ServerPage {\n bundleText: string;\n}\n\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\n\nexport function walkFiles(dir: string, base: string = dir): string[] {\n if (!fs.existsSync(dir)) return [];\n const results: string[] = [];\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n results.push(...walkFiles(full, base));\n } else if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) {\n results.push(path.relative(base, full));\n }\n }\n return results;\n}\n\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\n\n/**\n * Parses dynamic-route segments from a relative file path and returns a regex,\n * captured param names, catch-all param names, a function path, and a\n * specificity score.\n *\n * Supported patterns per segment:\n * [[...name]] optional catch-all \u2192 regex (.*) \u2192 string[]\n * [...name] required catch-all \u2192 regex (.+) \u2192 string[]\n * [[name]] optional single \u2192 regex ([^/]*)? \u2192 string\n * [name] required single \u2192 regex ([^/]+) \u2192 string\n * literal static \u2192 escaped literal\n *\n * @param relPath Relative path from the dir root (e.g. 'users/[id].tsx').\n * @param prefix Namespace for funcPath ('api' | 'page').\n */\nexport function analyzeFile(relPath: string, prefix = 'api'): AnalyzedRoute {\n const normalized = relPath.replace(/\\\\/g, '/').replace(/\\.(tsx?)$/, '');\n let segments = normalized.split('/');\n if (segments.at(-1) === 'index') segments = segments.slice(0, -1);\n\n const paramNames: string[] = [];\n const catchAllNames: string[] = [];\n const regexParts: string[] = [];\n let specificity = 0;\n\n for (const seg of segments) {\n const optCatchAll = seg.match(/^\\[\\[\\.\\.\\.(.+)\\]\\]$/);\n if (optCatchAll) {\n paramNames.push(optCatchAll[1]);\n catchAllNames.push(optCatchAll[1]);\n regexParts.push('(.*)');\n specificity += 1;\n continue;\n }\n const catchAll = seg.match(/^\\[\\.\\.\\.(.+)\\]$/);\n if (catchAll) {\n paramNames.push(catchAll[1]);\n catchAllNames.push(catchAll[1]);\n regexParts.push('(.+)');\n specificity += 10;\n continue;\n }\n const optDynamic = seg.match(/^\\[\\[([^.][^\\]]*)\\]\\]$/);\n if (optDynamic) {\n paramNames.push(optDynamic[1]);\n regexParts.push('__OPT__([^/]*)'); // marker \u2014 resolved below\n specificity += 30;\n continue;\n }\n const dynamic = seg.match(/^\\[(.+)\\]$/);\n if (dynamic) {\n paramNames.push(dynamic[1]);\n regexParts.push('([^/]+)');\n specificity += 100;\n continue;\n }\n regexParts.push(seg.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'));\n specificity += 1000;\n }\n\n // Build the regex string.\n // __OPT__(...) markers indicate optional single segments where the preceding\n // slash must also be optional (e.g. users/[[id]] should match /users).\n let srcRegex: string;\n if (segments.length === 0) {\n srcRegex = '^/$';\n } else {\n let body = '';\n for (let i = 0; i < regexParts.length; i++) {\n const part = regexParts[i];\n if (part.startsWith('__OPT__')) {\n const cap = part.slice(7);\n // At position 0, ^/ already provides the leading slash\n body += i === 0 ? cap : `(?:/${cap})?`;\n } else {\n body += (i === 0 ? '' : '/') + part;\n }\n }\n srcRegex = '^/' + body + '$';\n }\n\n const funcSegments = normalized.split('/');\n if (funcSegments.at(-1) === 'index') funcSegments.pop();\n const funcPath = funcSegments.length === 0\n ? `/${prefix}/_index`\n : `/${prefix}/` + funcSegments.join('/');\n\n return { srcRegex, paramNames, catchAllNames, funcPath, specificity };\n}\n\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\n\n/**\n * Returns true when a file does NOT begin with a \"use client\" directive,\n * i.e. it is a server component.\n */\nexport function isServerComponent(filePath: string): boolean {\n const content = fs.readFileSync(filePath, 'utf-8');\n for (const line of content.split('\\n').slice(0, 5)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('/*')) continue;\n if (/^[\"']use client[\"'];?$/.test(trimmed)) return false;\n break;\n }\n return true;\n}\n\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\n\n/**\n * Walks from the pages root to the directory containing `routeFilePath` and\n * returns every layout.tsx found, in outermost-first order.\n */\nexport function findPageLayouts(routeFilePath: string, pagesDir: string): string[] {\n const layouts: string[] = [];\n\n const rootLayout = path.join(pagesDir, 'layout.tsx');\n if (fs.existsSync(rootLayout)) layouts.push(rootLayout);\n\n const relativePath = path.relative(pagesDir, path.dirname(routeFilePath));\n if (!relativePath || relativePath === '.') return layouts;\n\n const segments = relativePath.split(path.sep).filter(Boolean);\n for (let i = 1; i <= segments.length; i++) {\n const layoutPath = path.join(pagesDir, ...segments.slice(0, i), 'layout.tsx');\n if (fs.existsSync(layoutPath)) layouts.push(layoutPath);\n }\n\n return layouts;\n}\n\n/**\n * Extracts the identifier used as the default export from a component file.\n * Returns null when no default export is found.\n */\nexport function extractDefaultExportName(filePath: string): string | null {\n const content = fs.readFileSync(filePath, 'utf-8');\n return content.match(/export\\s+default\\s+(?:function\\s+)?(\\w+)/)?.[1] ?? null;\n}\n\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\n\n/**\n * Returns all server-component pages inside `pagesDir`, sorted most-specific\n * first so precise routes shadow catch-alls in routers.\n * layout.tsx files and \"use client\" files are excluded.\n */\nexport function collectServerPages(pagesDir: string): ServerPage[] {\n if (!fs.existsSync(pagesDir)) return [];\n return walkFiles(pagesDir)\n .filter(relPath => {\n if (path.basename(relPath, path.extname(relPath)) === 'layout') return false;\n return isServerComponent(path.join(pagesDir, relPath));\n })\n .map(relPath => ({\n ...analyzeFile(relPath, 'page'),\n absPath: path.join(pagesDir, relPath),\n }))\n .sort((a, b) => b.specificity - a.specificity);\n}\n\n/**\n * Walks every server page and its layout chain to collect all client component\n * IDs reachable anywhere in the app.\n */\nexport function collectGlobalClientRegistry(\n serverPages: ServerPage[],\n pagesDir: string,\n): Map<string, string> {\n const registry = new Map<string, string>();\n for (const { absPath } of serverPages) {\n for (const [id, p] of findClientComponentsInTree(absPath, pagesDir))\n registry.set(id, p);\n for (const layoutPath of findPageLayouts(absPath, pagesDir))\n for (const [id, p] of findClientComponentsInTree(layoutPath, pagesDir))\n registry.set(id, p);\n }\n return registry;\n}\n\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\n\n/**\n * Builds the per-page client component registry (page + its layout chain)\n * and returns both the id\u2192path map and the name\u2192id map needed by\n * bundlePageHandler.\n */\nexport function buildPerPageRegistry(\n absPath: string,\n layoutPaths: string[],\n pagesDir: string,\n): { registry: Map<string, string>; clientComponentNames: Record<string, string> } {\n const registry = new Map<string, string>();\n\n for (const [id, p] of findClientComponentsInTree(absPath, pagesDir))\n registry.set(id, p);\n for (const lp of layoutPaths)\n for (const [id, p] of findClientComponentsInTree(lp, pagesDir))\n registry.set(id, p);\n\n const clientComponentNames: Record<string, string> = {};\n for (const [id, filePath] of registry) {\n const name = extractDefaultExportName(filePath);\n if (name) clientComponentNames[name] = id;\n }\n\n return { registry, clientComponentNames };\n}\n\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\n\n/**\n * Runs both passes of the page build:\n *\n * Pass 1 \u2014 bundles all client components to `staticDir/__client-component/`\n * and collects pre-rendered HTML for each.\n * Pass 2 \u2014 bundles every server-component page into a self-contained ESM\n * handler and returns the results as `BuiltPage[]`.\n */\nexport async function buildPages(\n pagesDir: string,\n staticDir: string,\n): Promise<BuiltPage[]> {\n const serverPages = collectServerPages(pagesDir);\n\n if (fs.existsSync(pagesDir) && walkFiles(pagesDir).length > 0 && serverPages.length === 0) {\n console.warn(`\u26A0 Pages found in ${pagesDir} but none are server components`);\n }\n\n if (serverPages.length === 0) return [];\n\n const globalRegistry = collectGlobalClientRegistry(serverPages, pagesDir);\n const prerenderedHtml = await bundleClientComponents(globalRegistry, pagesDir, staticDir);\n const prerenderedRecord = Object.fromEntries(prerenderedHtml);\n\n const builtPages: BuiltPage[] = [];\n\n for (const page of serverPages) {\n console.log(` building ${page.absPath} \u2192 ${page.funcPath} [page]`);\n\n const layoutPaths = findPageLayouts(page.absPath, pagesDir);\n const { registry, clientComponentNames } = buildPerPageRegistry(page.absPath, layoutPaths, pagesDir);\n\n const bundleText = await bundlePageHandler({\n absPath: page.absPath,\n pagesDir,\n clientComponentNames,\n allClientIds: [...registry.keys()],\n layoutPaths,\n prerenderedHtml: prerenderedRecord,\n catchAllNames: page.catchAllNames,\n });\n\n builtPages.push({ ...page, bundleText });\n }\n\n return builtPages;\n}\n\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\n\n/**\n * Returns the TypeScript source for a thin HTTP adapter that wraps an API\n * route module and exposes a single `handler(req, res)` default export.\n */\nexport function makeApiAdapterSource(handlerFilename: string): string {\n return `\\\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport * as mod from ${JSON.stringify('./' + handlerFilename)};\n\nfunction enhance(res: ServerResponse) {\n (res as any).json = function (data: any, status = 200) {\n this.statusCode = status;\n this.setHeader('Content-Type', 'application/json');\n this.end(JSON.stringify(data));\n };\n (res as any).status = function (code: number) { this.statusCode = code; return this; };\n return res;\n}\n\nasync function parseBody(req: IncomingMessage): Promise<any> {\n return new Promise((resolve, reject) => {\n let body = '';\n req.on('data', chunk => { body += chunk.toString(); });\n req.on('end', () => {\n try {\n resolve(body && req.headers['content-type']?.includes('application/json')\n ? JSON.parse(body) : body);\n } catch (e) { reject(e); }\n });\n req.on('error', reject);\n });\n}\n\nexport default async function handler(req: IncomingMessage, res: ServerResponse) {\n const method = (req.method || 'GET').toUpperCase();\n const apiRes = enhance(res);\n const apiReq = req as any;\n\n apiReq.body = await parseBody(req);\n apiReq.query = Object.fromEntries(new URL(req.url || '/', 'http://localhost').searchParams);\n apiReq.params = apiReq.query;\n\n const fn = (mod as any)[method] ?? (mod as any).default;\n if (typeof fn !== 'function') {\n (apiRes as any).json({ error: \\`Method \\${method} not allowed\\` }, 405);\n return;\n }\n await fn(apiReq, apiRes);\n}\n`;\n}\n\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\n\nexport interface PageAdapterOptions {\n /** e.g. './home.tsx' \u2014 relative import for the page default export */\n pageImport: string;\n /** Newline-joined import statements for layout components */\n layoutImports: string;\n /** function-name \u2192 cc_id map, computed at build time */\n clientComponentNames: Record<string, string>;\n /** All client component IDs reachable from this page */\n allClientIds: string[];\n /** Comma-separated list of __layout_N__ identifiers */\n layoutArrayItems: string;\n /** Pre-rendered HTML per client component ID, computed at build time */\n prerenderedHtml: Record<string, string>;\n /** Catch-all param names whose runtime values are string[] not string */\n catchAllNames: string[];\n}\n\n/**\n * Returns the TypeScript source for a fully self-contained page handler.\n *\n * The adapter:\n * \u2022 Inlines the html-store so useHtml() works without external deps.\n * \u2022 Contains an async recursive renderer for server + client components.\n * \u2022 Client components are identified via the pre-computed CLIENT_COMPONENTS\n * map \u2014 no fs.readFileSync at runtime.\n * \u2022 Emits the full HTML document including the __n_data blob and bootstrap.\n */\nexport function makePageAdapterSource(opts: PageAdapterOptions): string {\n const {\n pageImport, layoutImports, clientComponentNames, allClientIds,\n layoutArrayItems, prerenderedHtml, catchAllNames,\n } = opts;\n\n return `\\\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport * as __page__ from ${pageImport};\n${layoutImports}\n\nconst CLIENT_COMPONENTS: Record<string, string> = ${JSON.stringify(clientComponentNames)};\nconst ALL_CLIENT_IDS: string[] = ${JSON.stringify(allClientIds)};\nconst PRERENDERED_HTML: Record<string, string> = ${JSON.stringify(prerenderedHtml)};\nconst CATCH_ALL_NAMES = new Set(${JSON.stringify(catchAllNames)});\n\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\ntype TitleValue = string | ((prev: string) => string);\ninterface HtmlStore {\n titleOps: TitleValue[];\n htmlAttrs: Record<string, string | undefined>;\n bodyAttrs: Record<string, string | undefined>;\n meta: Record<string, string | undefined>[];\n link: Record<string, string | undefined>[];\n script: Record<string, any>[];\n style: { content?: string; media?: string }[];\n}\nconst __STORE_KEY__ = Symbol.for('__nukejs_html_store__');\nconst __getStore = (): HtmlStore | null => (globalThis as any)[__STORE_KEY__] ?? null;\nconst __setStore = (s: HtmlStore | null): void => { (globalThis as any)[__STORE_KEY__] = s; };\nconst __emptyStore = (): HtmlStore =>\n ({ titleOps: [], htmlAttrs: {}, bodyAttrs: {}, meta: [], link: [], script: [], style: [] });\nasync function runWithHtmlStore(fn: () => Promise<void>): Promise<HtmlStore> {\n __setStore(__emptyStore());\n try { await fn(); return { ...(__getStore() ?? __emptyStore()) }; }\n finally { __setStore(null); }\n}\nfunction resolveTitle(ops: TitleValue[], fallback = ''): string {\n let t = fallback;\n for (let i = ops.length - 1; i >= 0; i--) {\n const op = ops[i]; t = typeof op === 'string' ? op : op(t);\n }\n return t;\n}\n\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\nfunction escapeHtml(s: string): string {\n return String(s)\n .replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')\n .replace(/\"/g, '"').replace(/'/g, ''');\n}\nfunction escapeAttr(s: string): string {\n return String(s).replace(/&/g, '&').replace(/\"/g, '"');\n}\nfunction renderAttrs(attrs: Record<string, string | boolean | undefined>): string {\n return Object.entries(attrs)\n .filter(([, v]) => v !== undefined && v !== false)\n .map(([k, v]) => v === true ? k : \\`\\${k}=\"\\${escapeAttr(String(v))}\"\\`)\n .join(' ');\n}\nfunction openTag(tag: string, attrs: Record<string, string | undefined>): string {\n const s = renderAttrs(attrs as Record<string, string | boolean | undefined>);\n return s ? \\`<\\${tag} \\${s}>\\` : \\`<\\${tag}>\\`;\n}\nfunction renderMetaTag(tag: Record<string, string | undefined>): string {\n const key = (k: string) => k === 'httpEquiv' ? 'http-equiv' : k;\n const attrs: Record<string, string | undefined> = {};\n for (const [k, v] of Object.entries(tag)) if (v !== undefined) attrs[key(k)] = v;\n return \\` <meta \\${renderAttrs(attrs as any)} />\\`;\n}\nfunction renderLinkTag(tag: Record<string, string | undefined>): string {\n const key = (k: string) => k === 'hrefLang' ? 'hreflang' : k === 'crossOrigin' ? 'crossorigin' : k;\n const attrs: Record<string, string | undefined> = {};\n for (const [k, v] of Object.entries(tag)) if (v !== undefined) attrs[key(k)] = v;\n return \\` <link \\${renderAttrs(attrs as any)} />\\`;\n}\nfunction renderScriptTag(tag: any): string {\n const s = renderAttrs({ src: tag.src, type: tag.type, crossorigin: tag.crossOrigin,\n integrity: tag.integrity, defer: tag.defer, async: tag.async, nomodule: tag.noModule });\n return \\` \\${s ? \\`<script \\${s}>\\` : '<script>'}\\${tag.src ? '' : (tag.content ?? '')}</script>\\`;\n}\nfunction renderStyleTag(tag: any): string {\n const media = tag.media ? \\` media=\"\\${escapeAttr(tag.media)}\"\\` : '';\n return \\` <style\\${media}>\\${tag.content ?? ''}</style>\\`;\n}\n\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\nconst VOID_TAGS = new Set([\n 'area','base','br','col','embed','hr','img','input',\n 'link','meta','param','source','track','wbr',\n]);\n\nfunction serializeProps(value: any): any {\n if (value == null || typeof value !== 'object') return value;\n if (typeof value === 'function') return undefined;\n if (Array.isArray(value)) return value.map(serializeProps).filter((v: any) => v !== undefined);\n if ((value as any).$$typeof) {\n const { type, props: p } = value as any;\n if (typeof type === 'string') return { __re: 'html', tag: type, props: serializeProps(p) };\n if (typeof type === 'function') {\n const cid = CLIENT_COMPONENTS[type.name];\n if (cid) return { __re: 'client', componentId: cid, props: serializeProps(p) };\n }\n return undefined;\n }\n const out: any = {};\n for (const [k, v] of Object.entries(value as Record<string, any>)) {\n const s = serializeProps(v);\n if (s !== undefined) out[k] = s;\n }\n return out;\n}\n\nasync function renderNode(node: any, hydrated: Set<string>): Promise<string> {\n if (node == null || typeof node === 'boolean') return '';\n if (typeof node === 'string') return escapeHtml(node);\n if (typeof node === 'number') return String(node);\n if (Array.isArray(node)) return (await Promise.all(node.map(n => renderNode(n, hydrated)))).join('');\n\n const { type, props } = node as { type: any; props: Record<string, any> };\n if (!type) return '';\n\n if (type === Symbol.for('react.fragment')) return renderNode(props?.children ?? null, hydrated);\n\n if (typeof type === 'string') {\n const { children, dangerouslySetInnerHTML, ...rest } = props || {};\n const attrParts: string[] = [];\n for (const [k, v] of Object.entries(rest as Record<string, any>)) {\n const name = k === 'className' ? 'class' : k === 'htmlFor' ? 'for' : k;\n if (typeof v === 'boolean') { if (v) attrParts.push(name); continue; }\n if (v == null) continue;\n if (k === 'style' && typeof v === 'object') {\n const css = Object.entries(v as Record<string, any>)\n .map(([p, val]) => \\`\\${p.replace(/[A-Z]/g, m => \\`-\\${m.toLowerCase()}\\`)}:\\${escapeHtml(String(val))}\\`)\n .join(';');\n attrParts.push(\\`style=\"\\${css}\"\\`);\n continue;\n }\n attrParts.push(\\`\\${name}=\"\\${escapeHtml(String(v))}\"\\`);\n }\n const attrStr = attrParts.length ? ' ' + attrParts.join(' ') : '';\n if (VOID_TAGS.has(type)) return \\`<\\${type}\\${attrStr} />\\`;\n const inner = dangerouslySetInnerHTML\n ? (dangerouslySetInnerHTML as any).__html\n : await renderNode(children ?? null, hydrated);\n return \\`<\\${type}\\${attrStr}>\\${inner}</\\${type}>\\`;\n }\n\n if (typeof type === 'function') {\n const clientId = CLIENT_COMPONENTS[type.name];\n if (clientId) {\n hydrated.add(clientId);\n const serializedProps = serializeProps(props ?? {});\n let ssrHtml: string;\n try {\n ssrHtml = await renderNode(await (type as Function)(props || {}), new Set());\n } catch {\n ssrHtml = PRERENDERED_HTML[clientId] ?? '';\n }\n return \\`<span data-hydrate-id=\"\\${clientId}\" data-hydrate-props=\"\\${escapeHtml(JSON.stringify(serializedProps))}\">\\${ssrHtml}</span>\\`;\n }\n const instance = type.prototype?.isReactComponent ? new (type as any)(props) : null;\n return renderNode(instance ? instance.render() : await (type as Function)(props || {}), hydrated);\n }\n\n return '';\n}\n\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\nconst LAYOUT_COMPONENTS: Array<(props: any) => any> = [${layoutArrayItems}];\n\nfunction wrapWithLayouts(element: any): any {\n let el = element;\n for (let i = LAYOUT_COMPONENTS.length - 1; i >= 0; i--)\n el = { type: LAYOUT_COMPONENTS[i], props: { children: el }, key: null, ref: null };\n return el;\n}\n\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\nexport default async function handler(req: IncomingMessage, res: ServerResponse): Promise<void> {\n try {\n const parsed = new URL(req.url || '/', 'http://localhost');\n const params: Record<string, string | string[]> = {};\n parsed.searchParams.forEach((_, k) => {\n params[k] = CATCH_ALL_NAMES.has(k)\n ? parsed.searchParams.getAll(k)\n : parsed.searchParams.get(k) as string;\n });\n const url = req.url || '/';\n\n const hydrated = new Set<string>();\n const wrapped = wrapWithLayouts({ type: __page__.default, props: params as any, key: null, ref: null });\n\n let appHtml = '';\n const store = await runWithHtmlStore(async () => { appHtml = await renderNode(wrapped, hydrated); });\n\n const pageTitle = resolveTitle(store.titleOps, 'Nuke');\n const headLines = [\n ' <meta charset=\"utf-8\" />',\n ' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />',\n \\` <title>\\${escapeHtml(pageTitle)}</title>\\`,\n ...(store.meta.length || store.link.length || store.style.length || store.script.length ? [\n ' <!--n-head-->',\n ...store.meta.map(renderMetaTag),\n ...store.link.map(renderLinkTag),\n ...store.style.map(renderStyleTag),\n ...store.script.map(renderScriptTag),\n ' <!--/n-head-->',\n ] : []),\n ];\n\n const runtimeData = JSON.stringify({\n hydrateIds: [...hydrated], allIds: ALL_CLIENT_IDS, url, params, debug: 'silent',\n }).replace(/</g, '\\\\u003c').replace(/>/g, '\\\\u003e').replace(/&/g, '\\\\u0026');\n\n const html = \\`<!DOCTYPE html>\n\\${openTag('html', store.htmlAttrs)}\n<head>\n\\${headLines.join('\\\\n')}\n</head>\n\\${openTag('body', store.bodyAttrs)}\n <div id=\"app\">\\${appHtml}</div>\n\n <script id=\"__n_data\" type=\"application/json\">\\${runtimeData}</script>\n\n <script type=\"importmap\">\n {\n \"imports\": {\n \"react\": \"/__n.js\",\n \"react-dom/client\": \"/__n.js\",\n \"react/jsx-runtime\": \"/__n.js\",\n \"nukejs\": \"/__n.js\"\n }\n }\n </script>\n\n <script type=\"module\">\n const { initRuntime } = await import('nukejs');\n const data = JSON.parse(document.getElementById('__n_data').textContent);\n await initRuntime(data);\n </script>\n</body>\n</html>\\`;\n\n res.statusCode = 200;\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.end(html);\n } catch (err: any) {\n console.error('[page render error]', err);\n res.statusCode = 500;\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\n res.end('Internal Server Error');\n }\n}\n`;\n}\n\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\n\n/**\n * Bundles an API route handler into a single self-contained ESM string.\n * node_modules are kept external \u2014 they exist at runtime on both Node and\n * Vercel (Vercel bundles them separately via the pages dispatcher).\n */\nexport async function bundleApiHandler(absPath: string): Promise<string> {\n const adapterName = `_api_adapter_${randomBytes(4).toString('hex')}.ts`;\n const adapterPath = path.join(path.dirname(absPath), adapterName);\n fs.writeFileSync(adapterPath, makeApiAdapterSource(path.basename(absPath)));\n\n let text: string;\n try {\n const result = await build({\n entryPoints: [adapterPath],\n bundle: true,\n format: 'esm',\n platform: 'node',\n target: 'node20',\n packages: 'external',\n write: false,\n });\n text = result.outputFiles[0].text;\n } finally {\n fs.unlinkSync(adapterPath);\n }\n return text;\n}\n\nexport interface PageBundleOptions {\n absPath: string;\n pagesDir: string;\n clientComponentNames: Record<string, string>;\n allClientIds: string[];\n layoutPaths: string[];\n prerenderedHtml: Record<string, string>;\n catchAllNames: string[];\n}\n\n/**\n * Bundles a server-component page into a single self-contained ESM string.\n * All npm packages are kept external \u2014 the Node production server has\n * node_modules available at runtime.\n */\nexport async function bundlePageHandler(opts: PageBundleOptions): Promise<string> {\n const {\n absPath, clientComponentNames, allClientIds,\n layoutPaths, prerenderedHtml, catchAllNames,\n } = opts;\n\n const adapterDir = path.dirname(absPath);\n const adapterPath = path.join(adapterDir, `_page_adapter_${randomBytes(4).toString('hex')}.ts`);\n\n const layoutImports = layoutPaths\n .map((lp, i) => {\n const rel = path.relative(adapterDir, lp).replace(/\\\\/g, '/');\n return `import __layout_${i}__ from ${JSON.stringify(rel.startsWith('.') ? rel : './' + rel)};`;\n })\n .join('\\n');\n\n fs.writeFileSync(adapterPath, makePageAdapterSource({\n pageImport: JSON.stringify('./' + path.basename(absPath)),\n layoutImports,\n clientComponentNames,\n allClientIds,\n layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(', '),\n prerenderedHtml,\n catchAllNames,\n }));\n\n let text: string;\n try {\n const result = await build({\n entryPoints: [adapterPath],\n bundle: true,\n format: 'esm',\n platform: 'node',\n target: 'node20',\n jsx: 'automatic',\n packages: 'external',\n external: NODE_BUILTINS,\n define: { 'process.env.NODE_ENV': '\"production\"' },\n write: false,\n });\n text = result.outputFiles[0].text;\n } finally {\n fs.unlinkSync(adapterPath);\n }\n return text;\n}\n\n/**\n * Bundles every client component in `globalRegistry` to\n * `<staticDir>/__client-component/<id>.js` and pre-renders each to HTML.\n */\nexport async function bundleClientComponents(\n globalRegistry: Map<string, string>,\n pagesDir: string,\n staticDir: string,\n): Promise<Map<string, string>> {\n if (globalRegistry.size === 0) return new Map();\n\n const outDir = path.join(staticDir, '__client-component');\n fs.mkdirSync(outDir, { recursive: true });\n\n const prerendered = new Map<string, string>();\n\n for (const [id, filePath] of globalRegistry) {\n console.log(` bundling client ${id} (${path.relative(pagesDir, filePath)})`);\n\n // Browser bundle \u2014 served to the client for hydration\n const browserResult = await build({\n entryPoints: [filePath],\n bundle: true,\n format: 'esm',\n platform: 'browser',\n jsx: 'automatic',\n minify: true,\n external: ['react', 'react-dom/client', 'react/jsx-runtime'],\n define: { 'process.env.NODE_ENV': '\"production\"' },\n write: false,\n });\n fs.writeFileSync(path.join(outDir, `${id}.js`), browserResult.outputFiles[0].text);\n\n // SSR pre-render \u2014 bundle for Node, import, renderToString, discard\n const ssrTmp = path.join(\n path.dirname(filePath),\n `_ssr_${id}_${randomBytes(4).toString('hex')}.mjs`,\n );\n try {\n const ssrResult = await build({\n entryPoints: [filePath],\n bundle: true,\n format: 'esm',\n platform: 'node',\n target: 'node20',\n jsx: 'automatic',\n packages: 'external',\n define: { 'process.env.NODE_ENV': '\"production\"' },\n write: false,\n });\n fs.writeFileSync(ssrTmp, ssrResult.outputFiles[0].text);\n\n const { default: Component } = await import(pathToFileURL(ssrTmp).href);\n const { createElement } = await import('react');\n const { renderToString } = await import('react-dom/server');\n\n prerendered.set(id, renderToString(createElement(Component, {})));\n console.log(` prerendered ${id}`);\n } catch {\n prerendered.set(id, '');\n } finally {\n if (fs.existsSync(ssrTmp)) fs.unlinkSync(ssrTmp);\n }\n }\n\n console.log(` bundled ${globalRegistry.size} client component(s) \u2192 ${path.relative(process.cwd(), outDir)}/`);\n return prerendered;\n}\n\n/**\n * Builds the combined browser bundle (__n.js) that contains the full React\n * runtime + NukeJS client runtime in a single file.\n */\nexport async function buildCombinedBundle(staticDir: string): Promise<void> {\n const nukeDir = path.dirname(fileURLToPath(import.meta.url));\n const bundleFile = nukeDir.endsWith('dist') ? 'bundle' : 'bundle.ts';\n\n const result = await build({\n stdin: {\n contents: `\nimport React, {\n useState, useEffect, useContext, useReducer, useCallback, useMemo,\n useRef, useImperativeHandle, useLayoutEffect, useDebugValue,\n useDeferredValue, useTransition, useId, useSyncExternalStore,\n useInsertionEffect, createContext, forwardRef, memo, lazy,\n Suspense, Fragment, StrictMode, Component, PureComponent\n} from 'react';\nimport { jsx, jsxs } from 'react/jsx-runtime';\nimport { hydrateRoot, createRoot } from 'react-dom/client';\nexport { initRuntime, setupLocationChangeMonitor } from './${bundleFile}';\nexport {\n useState, useEffect, useContext, useReducer, useCallback, useMemo,\n useRef, useImperativeHandle, useLayoutEffect, useDebugValue,\n useDeferredValue, useTransition, useId, useSyncExternalStore,\n useInsertionEffect, createContext, forwardRef, memo, lazy,\n Suspense, Fragment, StrictMode, Component, PureComponent,\n hydrateRoot, createRoot, jsx, jsxs\n};\nexport default React;\n`,\n loader: 'ts',\n resolveDir: nukeDir,\n },\n bundle: true,\n write: false,\n treeShaking: true,\n minify: true,\n format: 'esm',\n jsx: 'automatic',\n alias: {\n react: path.dirname(fileURLToPath(import.meta.resolve('react/package.json'))),\n 'react-dom': path.dirname(fileURLToPath(import.meta.resolve('react-dom/package.json'))),\n },\n define: { 'process.env.NODE_ENV': '\"production\"' },\n });\n\n fs.writeFileSync(path.join(staticDir, '__n.js'), result.outputFiles[0].text);\n console.log(' built __n.js (react + runtime)');\n}\n\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\n\n/**\n * Recursively copies every file from `publicDir` into `destDir`, preserving\n * the directory structure. Skips silently when `publicDir` does not exist.\n */\nexport function copyPublicFiles(publicDir: string, destDir: string): void {\n if (!fs.existsSync(publicDir)) return;\n\n let count = 0;\n (function walk(src: string, dest: string) {\n fs.mkdirSync(dest, { recursive: true });\n for (const entry of fs.readdirSync(src, { withFileTypes: true })) {\n const s = path.join(src, entry.name);\n const d = path.join(dest, entry.name);\n if (entry.isDirectory()) { walk(s, d); } else { fs.copyFileSync(s, d); count++; }\n }\n })(publicDir, destDir);\n\n if (count > 0)\n console.log(` copied ${count} public file(s) \u2192 ${path.relative(process.cwd(), destDir)}/`);\n}\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;A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B,MAAI,QAAQ;AACV,YAAQ,IAAI,eAAe,KAAK,0BAAqB,KAAK,SAAS,QAAQ,IAAI,GAAG,OAAO,CAAC,GAAG;AACjG;",
|
|
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 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 apiReq.query = Object.fromEntries(new URL(req.url || '/', 'http://localhost').searchParams);\r\n apiReq.params = apiReq.query;\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 /** Catch-all param names whose runtime values are string[] not string */\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, 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\nconst CATCH_ALL_NAMES = new Set(${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 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, '&').replace(/</g, '<').replace(/>/g, '>')\r\n .replace(/\"/g, '"').replace(/'/g, ''');\r\n}\r\nfunction escapeAttr(s: string): string {\r\n return String(s).replace(/&/g, '&').replace(/\"/g, '"');\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\nfunction serializeProps(value: any): any {\r\n if (value == null || typeof value !== 'object') return value;\r\n if (typeof value === 'function') return undefined;\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 serializedProps = serializeProps(props ?? {});\r\n let ssrHtml: string;\r\n try {\r\n ssrHtml = __renderToString__(__createElement__(type as any, props || {}));\r\n } catch {\r\n ssrHtml = PRERENDERED_HTML[clientId] ?? '';\r\n }\r\n return \\`<span data-hydrate-id=\"\\${clientId}\" 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 params: Record<string, string | string[]> = {};\r\n parsed.searchParams.forEach((_, k) => {\r\n params[k] = CATCH_ALL_NAMES.has(k)\r\n ? parsed.searchParams.getAll(k)\r\n : parsed.searchParams.get(k) as string;\r\n });\r\n const url = req.url || '/';\r\n\r\n const hydrated = new Set<string>();\r\n const wrapped = wrapWithLayouts({ type: __page__.default, props: params as any, key: null, ref: null });\r\n\r\n let appHtml = '';\r\n const store = await runWithHtmlStore(async () => { appHtml = await renderNode(wrapped, hydrated); });\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, 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 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, 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 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;AA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AAQ,IAAI,uCAAuC;AACrD;AAQO,SAAS,gBAAgB,WAAmB,SAAuB;AACxE,MAAI,CAAC,GAAG,WAAW,SAAS,EAAG;AAE/B,MAAI,QAAQ;AACZ,GAAC,SAAS,KAAK,KAAa,MAAc;AACxC,OAAG,UAAU,MAAM,EAAE,WAAW,KAAK,CAAC;AACtC,eAAW,SAAS,GAAG,YAAY,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
6
|
"names": []
|
|
7
7
|
}
|
package/dist/build-node.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/build-node.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * build-node.ts \u2014 Node.js Production Build\n *\n * Produces a self-contained dist/ directory that runs with:\n * node dist/index.mjs\n *\n * Output layout:\n * dist/\n * index.mjs \u2190 HTTP server entry point\n * manifest.json \u2190 Route \u2192 handler mapping\n * api/<route>.mjs \u2190 Bundled API handlers\n * pages/<route>.mjs \u2190 Bundled page handlers\n * static/ \u2190 __n.js, client components, public files\n */\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { loadConfig } from './config';\nimport {\n analyzeFile,\n walkFiles,\n buildPages,\n bundleApiHandler,\n buildCombinedBundle,\n copyPublicFiles,\n type AnalyzedRoute,\n} from './build-common';\n\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\n\nconst OUT_DIR = path.resolve('dist');\nconst API_DIR = path.join(OUT_DIR, 'api');\nconst PAGES_DIR_ = path.join(OUT_DIR, 'pages');\nconst STATIC_DIR = path.join(OUT_DIR, 'static');\n\nfor (const dir of [API_DIR, PAGES_DIR_, STATIC_DIR])\n fs.mkdirSync(dir, { recursive: true });\n\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\n\nconst config = await loadConfig();\nconst SERVER_DIR = path.resolve(config.serverDir);\nconst PAGES_DIR = path.resolve('./app/pages');\nconst PUBLIC_DIR = path.resolve('./app/public');\n\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\n\ninterface ManifestEntry {\n /** Regex string matching the URL path, e.g. '^/users/([^/]+)$' */\n srcRegex: string;\n /** Names of captured groups in srcRegex order */\n paramNames: string[];\n /** Subset of paramNames whose runtime values are string[] (catch-all params) */\n catchAllNames: string[];\n /** Path to the bundled handler relative to dist/, e.g. 'api/users/[id].mjs' */\n handler: string;\n type: 'api' | 'page';\n}\n\nconst manifest: ManifestEntry[] = [];\n\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\n\n/** Converts a funcPath like '/api/users/[id]' to a filename 'users/[id].mjs'. */\nfunction funcPathToFilename(funcPath: string, prefix: 'api' | 'page'): string {\n return funcPath.replace(new RegExp(`^\\\\/${prefix}\\\\/`), '') + '.mjs';\n}\n\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\n\nconst apiFiles = walkFiles(SERVER_DIR);\nif (apiFiles.length === 0) console.warn(`\u26A0 No server files found in ${SERVER_DIR}`);\n\nconst apiRoutes = apiFiles\n .map(relPath => ({ ...analyzeFile(relPath, 'api'), absPath: path.join(SERVER_DIR, relPath) }))\n .sort((a, b) => b.specificity - a.specificity);\n\nfor (const { srcRegex, paramNames, catchAllNames, funcPath, absPath } of apiRoutes) {\n console.log(` building ${path.relative(SERVER_DIR, absPath)} \u2192 ${funcPath}`);\n\n const filename = funcPathToFilename(funcPath, 'api');\n const outPath = path.join(API_DIR, filename);\n fs.mkdirSync(path.dirname(outPath), { recursive: true });\n fs.writeFileSync(outPath, await bundleApiHandler(absPath));\n\n manifest.push({ srcRegex, paramNames, catchAllNames, handler: path.join('api', filename), type: 'api' });\n}\n\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\n\nconst builtPages = await buildPages(PAGES_DIR, STATIC_DIR);\n\nfor (const { srcRegex, paramNames, catchAllNames, funcPath, bundleText } of builtPages) {\n const filename = funcPathToFilename(funcPath, 'page');\n const outPath = path.join(PAGES_DIR_, filename);\n fs.mkdirSync(path.dirname(outPath), { recursive: true });\n fs.writeFileSync(outPath, bundleText);\n\n manifest.push({ srcRegex, paramNames, catchAllNames, handler: path.join('pages', filename), type: 'page' });\n}\n\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\n\n// Entries are already sorted most-specific first (both loops sort before\n// iterating), so the runtime can match top-to-bottom.\nfs.writeFileSync(\n path.join(OUT_DIR, 'manifest.json'),\n JSON.stringify({ routes: manifest }, null, 2),\n);\n\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\n\nawait buildCombinedBundle(STATIC_DIR);\ncopyPublicFiles(PUBLIC_DIR, STATIC_DIR);\n\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\n// A thin HTTP server that reads manifest.json at startup and dispatches\n// incoming requests to the correct pre-built handler module.\n\nconst MIME_MAP_ENTRIES = `\n '.html': 'text/html; charset=utf-8',\n '.htm': 'text/html; charset=utf-8',\n '.css': 'text/css; charset=utf-8',\n '.js': 'application/javascript; charset=utf-8',\n '.mjs': 'application/javascript; charset=utf-8',\n '.cjs': 'application/javascript; charset=utf-8',\n '.map': 'application/json; charset=utf-8',\n '.json': 'application/json; charset=utf-8',\n '.xml': 'application/xml; charset=utf-8',\n '.txt': 'text/plain; charset=utf-8',\n '.csv': 'text/csv; charset=utf-8',\n '.png': 'image/png',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.gif': 'image/gif',\n '.webp': 'image/webp',\n '.avif': 'image/avif',\n '.svg': 'image/svg+xml',\n '.ico': 'image/x-icon',\n '.bmp': 'image/bmp',\n '.woff': 'font/woff',\n '.woff2':'font/woff2',\n '.ttf': 'font/ttf',\n '.otf': 'font/otf',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.mp3': 'audio/mpeg',\n '.wav': 'audio/wav',\n '.ogg': 'audio/ogg',\n '.pdf': 'application/pdf',\n '.wasm': 'application/wasm',\n`.trim();\n\nconst serverEntry = `\\\nimport http from 'http';\nimport path from 'path';\nimport fs from 'fs';\nimport { fileURLToPath, pathToFileURL } from 'url';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst { routes } = JSON.parse(fs.readFileSync(path.join(__dirname, 'manifest.json'), 'utf-8'));\nconst compiled = routes.map(r => ({ ...r, regex: new RegExp(r.srcRegex) }));\n\nconst STATIC_DIR = path.join(__dirname, 'static');\nconst MIME_MAP = { ${MIME_MAP_ENTRIES} };\n\nconst server = http.createServer(async (req, res) => {\n const url = req.url || '/';\n const clean = url.split('?')[0];\n\n // Internal assets: /__n.js and /__client-component/*\n if (clean === '/__n.js' || clean.startsWith('/__client-component/')) {\n const filePath = path.join(STATIC_DIR, clean);\n if (fs.existsSync(filePath)) {\n res.setHeader('Content-Type', MIME_MAP[path.extname(filePath)] ?? 'application/javascript');\n res.end(fs.readFileSync(filePath));\n return;\n }\n res.statusCode = 404;\n res.end('Not found');\n return;\n }\n\n // Public static files from app/public/.\n // path.join normalises '..' segments before the startsWith guard,\n // preventing directory traversal.\n {\n const candidate = path.join(STATIC_DIR, clean);\n const staticBase = STATIC_DIR.endsWith(path.sep) ? STATIC_DIR : STATIC_DIR + path.sep;\n if (\n candidate.startsWith(staticBase) &&\n candidate !== STATIC_DIR &&\n fs.existsSync(candidate) &&\n fs.statSync(candidate).isFile()\n ) {\n res.setHeader('Content-Type', MIME_MAP[path.extname(candidate)] ?? 'application/octet-stream');\n res.end(fs.readFileSync(candidate));\n return;\n }\n }\n\n // Route dispatch.\n for (const { regex, paramNames, catchAllNames, handler } of compiled) {\n const m = clean.match(regex);\n if (!m) continue;\n\n const catchAllSet = new Set(catchAllNames);\n const qs = new URLSearchParams(Object.fromEntries(new URL(url, 'http://localhost').searchParams));\n paramNames.forEach((name, i) => {\n const raw = m[i + 1] ?? '';\n if (catchAllSet.has(name)) {\n raw.split('/').filter(Boolean).forEach(seg => qs.append(name, seg));\n } else {\n qs.set(name, raw);\n }\n });\n req.url = clean + (qs.toString() ? '?' + qs.toString() : '');\n\n const mod = await import(pathToFileURL(path.join(__dirname, handler)).href);\n await mod.default(req, res);\n return;\n }\n\n res.statusCode = 404;\n res.setHeader('Content-Type', 'text/plain');\n res.end('Not found');\n});\n\nconst PORT = Number(process.env.PORT ?? 3000);\nserver.listen(PORT, () => console.log('nukejs built server listening on http://localhost:' + PORT));\n`;\n\nfs.writeFileSync(path.join(OUT_DIR, 'index.mjs'), serverEntry);\n\nconsole.log(`\\n\u2713 Node build complete \u2014 ${manifest.length} route(s) \u2192 dist/`);\nconsole.log(' run with: node dist/index.mjs');\n"],
|
|
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\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\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 // Internal assets: /__n.js and /__client-component/*\r\n if (clean === '/__n.js' || clean.startsWith('/__client-component/')) {\r\n const filePath = path.join(STATIC_DIR, clean);\r\n if (fs.existsSync(filePath)) {\r\n res.setHeader('Content-Type', MIME_MAP[path.extname(filePath)] ?? 'application/javascript');\r\n res.end(fs.readFileSync(filePath));\r\n return;\r\n }\r\n res.statusCode = 404;\r\n res.end('Not found');\r\n return;\r\n }\r\n\r\n // Public static files from app/public/.\r\n // path.join normalises '..' segments before the startsWith guard,\r\n // 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 // Route dispatch.\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');\r\n"],
|
|
5
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;AAE9C,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,GAAG,MAAM,EAAE,cAAc,EAAE,WAAW;AAE/C,WAAW,EAAE,UAAU,YAAY,eAAe,UAAU,QAAQ,KAAK,WAAW;AAClF,UAAQ,IAAI,eAAe,KAAK,SAAS,YAAY,OAAO,C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