@rsc-kit/core 0.29.3 → 0.29.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/export.js +6 -0
- package/dist/export.js.map +1 -1
- package/dist/files.d.ts +20 -0
- package/dist/files.js +53 -0
- package/dist/files.js.map +1 -1
- package/dist/host.js +18 -2
- package/dist/host.js.map +1 -1
- package/dist/vite.js +67 -9
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/export.js
CHANGED
|
@@ -77,6 +77,12 @@ export async function exportSite(options) {
|
|
|
77
77
|
for (const result of results) {
|
|
78
78
|
if (result.type !== 'frozen')
|
|
79
79
|
continue;
|
|
80
|
+
// Frozen, but guarded: refused above, and left out here too. Forcing an
|
|
81
|
+
// export leaves out what is refused - and a guarded page written anyway
|
|
82
|
+
// was the page published to whoever asked, with the build saying it had
|
|
83
|
+
// been left out.
|
|
84
|
+
if (guarded.has(result.component))
|
|
85
|
+
continue;
|
|
80
86
|
const key = pathKey(result.url);
|
|
81
87
|
// The root is the out dir itself; everything else is a directory with an
|
|
82
88
|
// index, so /docs stays /docs rather than becoming /docs.html.
|
package/dist/export.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,wBAAwB;AACxB,EAAE;AACF,wEAAwE;AACxE,4EAA4E;AAC5E,+BAA+B;AAC/B,EAAE;AACF,gCAAgC;AAChC,kBAAkB;AAClB,oCAAoC;AACpC,uBAAuB;AACvB,iDAAiD;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAmCxC,MAAM,OAAO,aAAc,SAAQ,KAAK;IACV,OAAO;IAAnC,YAA4B,OAA0B;QACpD,KAAK,CACH,0F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,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QACxF,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;IAED,MAAM,MAAM,EAAE,EAAE,CAAA;IAEhB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAC3B,CAAC","sourcesContent":["// Writing the whole site out as files, for a host that only serves files.\n//\n// Everything a server was doing has to have happened already, which makes the\n// refusals the important part. A site exported with a route missing, or with a\n// shell nothing will ever fill, does not fail at build time and does not fail\n// on load — it serves a page that sits there, or a 404 for a url that worked\n// yesterday. So anything that is not fully static stops the export and says\n// which routes and why.\n//\n// Layout is a directory per route with an index inside it, so urls stay\n// extensionless, and the Flight payload sits beside it under a filename the\n// client was built to ask for.\n//\n// out/index.html /\n// out/index.rsc\n// out/docs/index.html /docs\n// out/docs/index.rsc\n// out/assets/… the browser bundle\n\nimport { pathKey } from './prerender.js'\nimport type { PrerenderResult } from './prerender.js'\nimport type { RouteManifest } from './manifest.js'\n\nexport interface ExportOptions {\n /** What prerender() decided, so this can refuse what it cannot serve. */\n results: PrerenderResult[]\n /** Reads what prerender() wrote. `prerenderedFrom` in `@rsc-kit/core/files`. */\n read: (name: string) => Promise<string | null> | string | null\n /**\n * Writes the site, keyed by its url path — `docs/index.html`, not an\n * absolute one. `writeTo` in `@rsc-kit/core/files` puts those under a\n * directory; a deploy that uploads straight to a bucket writes keys.\n */\n write: (path: string, contents: string) => Promise<void> | void\n /** The route table, for what the build decided about payload urls. */\n manifest: RouteManifest\n /**\n * Brings the browser bundle along, if this export has to carry it.\n *\n * A callback rather than a directory pair: copying a tree of built files is\n * a filesystem operation by nature, and a deploy that uploads them has its\n * own tooling for it. `copyAssets` in `@rsc-kit/core/files` does the local one.\n */\n assets?: () => Promise<void> | void\n /**\n * Export anyway, leaving out whatever is not static.\n *\n * The result is a site with holes in it, which is sometimes what you want\n * while moving an app towards being exportable. It is never the default,\n * because the holes are 404s at urls that worked before.\n */\n force?: boolean\n}\n\nexport class NotExportable extends Error {\n constructor(public readonly refused: PrerenderResult[]) {\n super(\n 'This site cannot be exported as it is. A static host runs nothing, so these routes have ' +\n 'no way to finish rendering:\\n\\n' +\n refused.map((r) => ` ${r.url} — ${r.reason ?? describe(r.type)}`).join('\\n') +\n '\\n\\nMake them static, or pass force to export the rest and leave these out.',\n )\n this.name = 'NotExportable'\n }\n}\n\nfunction describe(type: PrerenderResult['type']): string {\n if (type === 'shell') {\n // Worth spelling out: a shell looks like a working page in the build\n // output, and on a static host it is a page that loads and stays empty.\n return 'only a shell was stored, and nothing on a static host will fill it'\n }\n\n return 'failed to render'\n}\n\nexport async function exportSite(options: ExportOptions): Promise<{ pages: number; refused: PrerenderResult[] }> {\n const { results, read, write, manifest, assets, force = false } = options\n\n // A guarded route is frozen on purpose — the content is the same for\n // everyone allowed to see it — but the guard runs when the page is served,\n // and a static host serves without running anything. Exporting one publishes\n // the page to whoever asks, which is the opposite of what the guard said.\n const guarded = new Set(\n (manifest.routes as { component: string; middleware?: string[]; hostMiddleware?: string[] }[])\n // The host's middleware too: `export const middleware = ['auth']` is a\n // guard a static host cannot run either.\n .filter((route) => route.middleware?.length || route.hostMiddleware?.length)\n .map((route) => route.component),\n )\n\n const refused = results\n .filter((r) => r.type !== 'frozen' || guarded.has(r.component))\n .map((r) =>\n r.type === 'frozen' && guarded.has(r.component)\n ? { ...r, reason: 'guarded, and a static host has nothing to run the guard' }\n : r,\n )\n\n if (refused.length > 0 && !force) throw new NotExportable(refused)\n\n // The client has to ask for payloads by url, because a static host cannot\n // read the header that would otherwise select one. That is decided by the\n // build, so a site exported from a server build ships a client asking the\n // wrong way — every navigation silently falls back to a full page load.\n const payloadName = manifest.build?.payloadName\n\n if (!payloadName) {\n throw new Error(\n 'This build was made for a server, so its client asks for payloads with a header rather ' +\n \"than by url. Build with output: 'export' before exporting.\",\n )\n }\n\n const copy = async (name: string, into: string) => {\n const contents = await read(name)\n\n // Missing where the results said it would be: the prerender output and the\n // results it returned disagree, which is not something to paper over with\n // a half-written site.\n if (contents === null) {\n throw new Error(`Nothing to export at ${name}. Prerender and export must read the same output.`)\n }\n\n await write(into, contents)\n }\n\n let pages = 0\n\n for (const result of results) {\n if (result.type !== 'frozen') continue\n\n const key = pathKey(result.url)\n // The root is the out dir itself; everything else is a directory with an\n // index, so /docs stays /docs rather than becoming /docs.html.\n const dir = key === 'index' ? '' : `${key}/`\n\n // A route that only redirects is frozen as its answer rather than as a\n // page, so there is no .html to copy — and reaching for one threw, which\n // is why exporting an app with a redirect in it failed outright.\n //\n // A meta refresh because it is the one redirect every static host performs\n // without being configured; `_redirects` and its equivalents are per-host\n // files this has no business writing. The canonical link is what keeps a\n // crawler pointed at the destination rather than at this page.\n const redirect = await read(`${key}.redirect.json`)\n\n if (redirect !== null) {\n const { location } = JSON.parse(redirect) as { status: number; location: string }\n const escaped = location.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<')\n\n await write(\n `${dir}index.html`,\n `<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\">` +\n `<meta http-equiv=\"refresh\" content=\"0; url=${escaped}\">` +\n `<link rel=\"canonical\" href=\"${escaped}\">` +\n `<title>Redirecting</title></head>` +\n `<body><a href=\"${escaped}\">${escaped}</a></body></html>\\n`,\n )\n\n pages++\n continue\n }\n\n await copy(`${key}.html`, `${dir}index.html`)\n await copy(`${key}.flight`, `${dir}${payloadName}`)\n\n // One file per depth a client might already hold, addressed by name\n // because a file server cannot vary on a header. Without these every\n // navigation is a whole document, which replaces the root and unmounts\n // the pages retained behind it — so going back does not restore the form\n // you were filling in.\n for (let depth = 1; ; depth++) {\n const variant = await read(`${key}.seg${depth}.flight`)\n\n if (variant === null) break\n\n await write(`${dir}${payloadName.replace(/^index\\./, `index.seg${depth}.`)}`, variant)\n }\n\n pages++\n }\n\n await assets?.()\n\n return { pages, refused }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"export.js","sourceRo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O,KAAK,OAAO,sBAAsB,CAC9D,CAAA;YAED,KAAK,EAAE,CAAA;YACP,SAAQ;QACV,CAAC;QAED,MAAM,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,GAAG,GAAG,YAAY,CAAC,CAAA;QAC7C,MAAM,IAAI,CAAC,GAAG,GAAG,SAAS,EAAE,GAAG,GAAG,GAAG,WAAW,EAAE,CAAC,CAAA;QAEnD,oEAAoE;QACpE,qEAAqE;QACrE,uEAAuE;QACvE,yEAAyE;QACzE,uBAAuB;QACvB,KAAK,IAAI,KAAK,GAAG,CAAC,GAAI,KAAK,EAAE,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,GAAG,OAAO,KAAK,SAAS,CAAC,CAAA;YAEvD,IAAI,OAAO,KAAK,IAAI;gBAAE,MAAK;YAE3B,MAAM,KAAK,CAAC,GAAG,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QACxF,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;IAED,MAAM,MAAM,EAAE,EAAE,CAAA;IAEhB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAC3B,CAAC","sourcesContent":["// Writing the whole site out as files, for a host that only serves files.\n//\n// Everything a server was doing has to have happened already, which makes the\n// refusals the important part. A site exported with a route missing, or with a\n// shell nothing will ever fill, does not fail at build time and does not fail\n// on load — it serves a page that sits there, or a 404 for a url that worked\n// yesterday. So anything that is not fully static stops the export and says\n// which routes and why.\n//\n// Layout is a directory per route with an index inside it, so urls stay\n// extensionless, and the Flight payload sits beside it under a filename the\n// client was built to ask for.\n//\n// out/index.html /\n// out/index.rsc\n// out/docs/index.html /docs\n// out/docs/index.rsc\n// out/assets/… the browser bundle\n\nimport { pathKey } from './prerender.js'\nimport type { PrerenderResult } from './prerender.js'\nimport type { RouteManifest } from './manifest.js'\n\nexport interface ExportOptions {\n /** What prerender() decided, so this can refuse what it cannot serve. */\n results: PrerenderResult[]\n /** Reads what prerender() wrote. `prerenderedFrom` in `@rsc-kit/core/files`. */\n read: (name: string) => Promise<string | null> | string | null\n /**\n * Writes the site, keyed by its url path — `docs/index.html`, not an\n * absolute one. `writeTo` in `@rsc-kit/core/files` puts those under a\n * directory; a deploy that uploads straight to a bucket writes keys.\n */\n write: (path: string, contents: string) => Promise<void> | void\n /** The route table, for what the build decided about payload urls. */\n manifest: RouteManifest\n /**\n * Brings the browser bundle along, if this export has to carry it.\n *\n * A callback rather than a directory pair: copying a tree of built files is\n * a filesystem operation by nature, and a deploy that uploads them has its\n * own tooling for it. `copyAssets` in `@rsc-kit/core/files` does the local one.\n */\n assets?: () => Promise<void> | void\n /**\n * Export anyway, leaving out whatever is not static.\n *\n * The result is a site with holes in it, which is sometimes what you want\n * while moving an app towards being exportable. It is never the default,\n * because the holes are 404s at urls that worked before.\n */\n force?: boolean\n}\n\nexport class NotExportable extends Error {\n constructor(public readonly refused: PrerenderResult[]) {\n super(\n 'This site cannot be exported as it is. A static host runs nothing, so these routes have ' +\n 'no way to finish rendering:\\n\\n' +\n refused.map((r) => ` ${r.url} — ${r.reason ?? describe(r.type)}`).join('\\n') +\n '\\n\\nMake them static, or pass force to export the rest and leave these out.',\n )\n this.name = 'NotExportable'\n }\n}\n\nfunction describe(type: PrerenderResult['type']): string {\n if (type === 'shell') {\n // Worth spelling out: a shell looks like a working page in the build\n // output, and on a static host it is a page that loads and stays empty.\n return 'only a shell was stored, and nothing on a static host will fill it'\n }\n\n return 'failed to render'\n}\n\nexport async function exportSite(options: ExportOptions): Promise<{ pages: number; refused: PrerenderResult[] }> {\n const { results, read, write, manifest, assets, force = false } = options\n\n // A guarded route is frozen on purpose — the content is the same for\n // everyone allowed to see it — but the guard runs when the page is served,\n // and a static host serves without running anything. Exporting one publishes\n // the page to whoever asks, which is the opposite of what the guard said.\n const guarded = new Set(\n (manifest.routes as { component: string; middleware?: string[]; hostMiddleware?: string[] }[])\n // The host's middleware too: `export const middleware = ['auth']` is a\n // guard a static host cannot run either.\n .filter((route) => route.middleware?.length || route.hostMiddleware?.length)\n .map((route) => route.component),\n )\n\n const refused = results\n .filter((r) => r.type !== 'frozen' || guarded.has(r.component))\n .map((r) =>\n r.type === 'frozen' && guarded.has(r.component)\n ? { ...r, reason: 'guarded, and a static host has nothing to run the guard' }\n : r,\n )\n\n if (refused.length > 0 && !force) throw new NotExportable(refused)\n\n // The client has to ask for payloads by url, because a static host cannot\n // read the header that would otherwise select one. That is decided by the\n // build, so a site exported from a server build ships a client asking the\n // wrong way — every navigation silently falls back to a full page load.\n const payloadName = manifest.build?.payloadName\n\n if (!payloadName) {\n throw new Error(\n 'This build was made for a server, so its client asks for payloads with a header rather ' +\n \"than by url. Build with output: 'export' before exporting.\",\n )\n }\n\n const copy = async (name: string, into: string) => {\n const contents = await read(name)\n\n // Missing where the results said it would be: the prerender output and the\n // results it returned disagree, which is not something to paper over with\n // a half-written site.\n if (contents === null) {\n throw new Error(`Nothing to export at ${name}. Prerender and export must read the same output.`)\n }\n\n await write(into, contents)\n }\n\n let pages = 0\n\n for (const result of results) {\n if (result.type !== 'frozen') continue\n\n // Frozen, but guarded: refused above, and left out here too. Forcing an\n // export leaves out what is refused - and a guarded page written anyway\n // was the page published to whoever asked, with the build saying it had\n // been left out.\n if (guarded.has(result.component)) continue\n\n const key = pathKey(result.url)\n // The root is the out dir itself; everything else is a directory with an\n // index, so /docs stays /docs rather than becoming /docs.html.\n const dir = key === 'index' ? '' : `${key}/`\n\n // A route that only redirects is frozen as its answer rather than as a\n // page, so there is no .html to copy — and reaching for one threw, which\n // is why exporting an app with a redirect in it failed outright.\n //\n // A meta refresh because it is the one redirect every static host performs\n // without being configured; `_redirects` and its equivalents are per-host\n // files this has no business writing. The canonical link is what keeps a\n // crawler pointed at the destination rather than at this page.\n const redirect = await read(`${key}.redirect.json`)\n\n if (redirect !== null) {\n const { location } = JSON.parse(redirect) as { status: number; location: string }\n const escaped = location.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<')\n\n await write(\n `${dir}index.html`,\n `<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\">` +\n `<meta http-equiv=\"refresh\" content=\"0; url=${escaped}\">` +\n `<link rel=\"canonical\" href=\"${escaped}\">` +\n `<title>Redirecting</title></head>` +\n `<body><a href=\"${escaped}\">${escaped}</a></body></html>\\n`,\n )\n\n pages++\n continue\n }\n\n await copy(`${key}.html`, `${dir}index.html`)\n await copy(`${key}.flight`, `${dir}${payloadName}`)\n\n // One file per depth a client might already hold, addressed by name\n // because a file server cannot vary on a header. Without these every\n // navigation is a whole document, which replaces the root and unmounts\n // the pages retained behind it — so going back does not restore the form\n // you were filling in.\n for (let depth = 1; ; depth++) {\n const variant = await read(`${key}.seg${depth}.flight`)\n\n if (variant === null) break\n\n await write(`${dir}${payloadName.replace(/^index\\./, `index.seg${depth}.`)}`, variant)\n }\n\n pages++\n }\n\n await assets?.()\n\n return { pages, refused }\n}\n\n\n"]}
|
package/dist/files.d.ts
CHANGED
|
@@ -92,6 +92,26 @@ export declare function writeTo(dir: string): ((name: string, contents: string)
|
|
|
92
92
|
* filesystem operation by nature — a deploy that uploads them to a bucket
|
|
93
93
|
* has its own way to do that, and passes its own callback instead.
|
|
94
94
|
*/
|
|
95
|
+
/**
|
|
96
|
+
* The whole client output into an exported site: every file a server would
|
|
97
|
+
* have answered as a file - the bundle, public/, icons, the web manifest,
|
|
98
|
+
* the service worker. Precompressed copies (.br, .gz, .zst) come too; a host
|
|
99
|
+
* that does not serve them ignores them.
|
|
100
|
+
*/
|
|
101
|
+
export declare function copyPublic(from: string, to: string): () => Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Stored route.ts answers written out as the files they are: the body at the
|
|
104
|
+
* url, `robots.txt` at robots.txt. Only answers a static host can give as
|
|
105
|
+
* they were - a 200 the same for everyone, at a url with an extension, since
|
|
106
|
+
* a file is typed by its extension and the stored content type would be lost.
|
|
107
|
+
*/
|
|
108
|
+
export declare function exportStoredAnswers(staticDir: string, to: string): Promise<{
|
|
109
|
+
written: string[];
|
|
110
|
+
skipped: {
|
|
111
|
+
url: string;
|
|
112
|
+
why: string;
|
|
113
|
+
}[];
|
|
114
|
+
}>;
|
|
95
115
|
export declare function copyAssets(from: string, to: string, url?: string): () => Promise<void>;
|
|
96
116
|
/**
|
|
97
117
|
* Put the stored pages among a Worker's static assets, and have the Worker
|
package/dist/files.js
CHANGED
|
@@ -346,6 +346,59 @@ export function writeTo(dir) {
|
|
|
346
346
|
* filesystem operation by nature — a deploy that uploads them to a bucket
|
|
347
347
|
* has its own way to do that, and passes its own callback instead.
|
|
348
348
|
*/
|
|
349
|
+
/**
|
|
350
|
+
* The whole client output into an exported site: every file a server would
|
|
351
|
+
* have answered as a file - the bundle, public/, icons, the web manifest,
|
|
352
|
+
* the service worker. Precompressed copies (.br, .gz, .zst) come too; a host
|
|
353
|
+
* that does not serve them ignores them.
|
|
354
|
+
*/
|
|
355
|
+
export function copyPublic(from, to) {
|
|
356
|
+
return async () => {
|
|
357
|
+
await mkdir(to, { recursive: true });
|
|
358
|
+
await cp(from, to, { recursive: true });
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Stored route.ts answers written out as the files they are: the body at the
|
|
363
|
+
* url, `robots.txt` at robots.txt. Only answers a static host can give as
|
|
364
|
+
* they were - a 200 the same for everyone, at a url with an extension, since
|
|
365
|
+
* a file is typed by its extension and the stored content type would be lost.
|
|
366
|
+
*/
|
|
367
|
+
export async function exportStoredAnswers(staticDir, to) {
|
|
368
|
+
const written = [];
|
|
369
|
+
const skipped = [];
|
|
370
|
+
let entries;
|
|
371
|
+
try {
|
|
372
|
+
entries = (await readdir(staticDir, { recursive: true }));
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return { written, skipped };
|
|
376
|
+
}
|
|
377
|
+
for (const entry of entries.sort()) {
|
|
378
|
+
if (!entry.endsWith('.api.json'))
|
|
379
|
+
continue;
|
|
380
|
+
const path = entry.slice(0, -'.api.json'.length).split(/[\\/]/).join('/');
|
|
381
|
+
const url = '/' + (path === 'index' ? '' : path);
|
|
382
|
+
const answer = JSON.parse(await readFile(join(staticDir, entry), 'utf-8'));
|
|
383
|
+
if (answer.status !== 200) {
|
|
384
|
+
skipped.push({ url, why: `answers ${answer.status}` });
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (answer.varies) {
|
|
388
|
+
skipped.push({ url, why: 'varies by request' });
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (!/\.[a-z0-9]+$/i.test(path)) {
|
|
392
|
+
skipped.push({ url, why: 'no extension to give a static host its content type' });
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
const target = join(to, path);
|
|
396
|
+
await mkdir(dirname(target), { recursive: true });
|
|
397
|
+
await writeFile(target, answer.body);
|
|
398
|
+
written.push(url);
|
|
399
|
+
}
|
|
400
|
+
return { written, skipped };
|
|
401
|
+
}
|
|
349
402
|
export function copyAssets(from, to, url = '/assets/') {
|
|
350
403
|
return async () => {
|
|
351
404
|
const at = url.replace(/^\/+|\/+$/g, '');
|
package/dist/files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4CAA4C;AAE5C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC;;;;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C,EAAE,CAAA;YACjG,MAAM,OAAO,GAAG,IAAI,MAAM,IAAI,CAAA;YAE9B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAA;YAElF,MAAM,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,uDAAuD;IACzD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["// Reading built output off a disk.\n//\n// Kept apart from the host on purpose: it is the only part of serving an RSC\n// app that assumes a filesystem, and plenty of places to run one do not have\n// one. Nothing in `@rsc-kit/core/host` imports this module, so a bundle for a\n// host without a filesystem carries no reference to `node:fs` at all.\n//\n// Assets are not here any more — Nitro publishes and serves those. What is\n// left is the prerendered output: written by the build, read by the server it\n// generates, and copied by a static export.\n\nimport { cp, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/**\n * Read what the prerenderer wrote, from a directory.\n *\n * Missing is an answer, not an error: a partial prerender is a valid state,\n * and anything not found here is rendered on demand instead.\n */\nexport function prerenderedFrom(dir: string) {\n /**\n * What is on disk, listed once.\n *\n * A miss used to be a thrown ENOENT, and misses are the common case: the\n * host asks for `{url}.html`, then `{url}.ppr.html`, then the route's\n * pattern — so every request to a page served by a pattern shell threw and\n * caught two exceptions before finding anything. Measured at 3,000 req/s\n * against 28,000 for the same page read from memory.\n *\n * Contents are cached for the life of the process. A build's output does\n * not change under a running server - a deploy restarts it, and a server\n * that outlived a rebuild would be serving a stale engine against new\n * pages anyway - so the first read is the only one. Under load the same\n * page used to be opened, read and closed thousands of times a second,\n * which a profile showed as the one cost on a stored page that was ours\n * rather than React's. Capped by bytes, so a site with more pages than\n * memory holds the hot ones and re-reads the rest.\n */\n let present: Promise<Set<string>> | null = null\n\n const CONTENT_CAP_BYTES = 64 * 1024 * 1024\n const contents = new Map<string, string>()\n let held = 0\n\n const remember = (name: string, text: string): void => {\n const size = text.length * 2\n\n if (size > CONTENT_CAP_BYTES / 4) return\n\n while (held + size > CONTENT_CAP_BYTES && contents.size > 0) {\n const oldest = contents.keys().next().value as string\n held -= contents.get(oldest)!.length * 2\n contents.delete(oldest)\n }\n\n contents.set(name, text)\n held += size\n }\n\n const listing = async (): Promise<Set<string>> => {\n present ??= readdir(dir, { recursive: true })\n .then((names) => new Set(names.map((n) => String(n).replace(/\\\\/g, '/'))))\n // An absent directory is an empty one: a partial prerender is a valid\n // state, and everything falls through to being rendered.\n .catch(() => new Set<string>())\n\n return await present\n }\n\n return async (name: string): Promise<string | null> => {\n if (name.includes('..')) return null\n\n if (!(await listing()).has(name)) return null\n\n const cached = contents.get(name)\n\n if (cached !== undefined) return cached\n\n try {\n const text = await readFile(join(dir, name), 'utf-8')\n\n remember(name, text)\n\n return text\n } catch {\n return null\n }\n }\n}\n\n/**\n * The same reader, for a directory whose absolute path is not known until the\n * server runs.\n *\n * Nitro bundles the generated entry to a different depth depending on the\n * preset — `.output/server/index.mjs` for one, `.output/server/_ssr/rsc.mjs`\n * for another — so neither a fixed relative path nor a path baked in at build\n * time survives: the first is wrong for half the presets, and the second stops\n * being true the moment `.output/` is copied to the machine that serves it.\n *\n * So the caller passes its own `import.meta.url` and the directory is found by\n * walking up from it. A few levels, bounded, and resolved once.\n *\n * prerendered: prerenderedBeside(import.meta.url, 'rsc-static')\n *\n * Not finding it is a valid state and not an error: nothing was frozen, or\n * this host has no filesystem to have frozen it on. Every page renders live,\n * which is what happens today everywhere.\n */\n/**\n * Where a compiled binary puts the frozen pages.\n *\n * `bun build --compile` embeds what is imported statically and nothing a\n * computed import names, so the walk below finds no directory and no\n * module inside a binary. The build writes `compile.mjs` beside the\n * server: it imports the inline module by name - which embeds it - and\n * hands the pages over here before importing the server. Shared as a\n * global under a registered symbol, because the wrapper and this module\n * are bundled apart.\n */\nexport const EMBEDDED_PAGES = Symbol.for('rsc-kit.embedded-pages')\n\nfunction embeddedPages(): Record<string, string> | null {\n const pages = (globalThis as Record<symbol, unknown>)[EMBEDDED_PAGES]\n\n return pages && typeof pages === 'object' ? (pages as Record<string, string>) : null\n}\n\nexport function prerenderedBeside(moduleUrl: string, dirName: string, levels = 4) {\n let reader: Promise<(name: string) => Promise<string | null>> | null = null\n\n const resolveDir = async (): Promise<(name: string) => Promise<string | null>> => {\n const embedded = embeddedPages()\n\n if (embedded) return async (name) => embedded[name] ?? null\n\n let dir: string | null = null\n\n try {\n const { fileURLToPath } = await import('node:url')\n\n dir = dirname(fileURLToPath(moduleUrl))\n } catch {\n // No filesystem, or no file: url to speak of. The inline module below\n // is the only place the pages can be.\n }\n\n if (dir !== null) {\n for (let i = 0; i <= levels; i++) {\n const candidate = join(dir, ...Array(i).fill('..'), dirName)\n\n try {\n await readdir(candidate)\n\n return prerenderedFrom(candidate)\n } catch {\n // Not at this level. Keep walking.\n }\n }\n }\n\n // A Worker: the pages were uploaded as static assets, under a prefix\n // the Worker answers first, and are read back through the binding.\n const assets = await workersAssets()\n\n if (assets) return assetsReader(assets, `/${ASSETS_PREFIX(dirName)}`)\n\n const inline = await inlinePrerendered(moduleUrl, `${dirName}-inline.mjs`, levels)\n\n return inline ? async (name) => inline[name] ?? null : async () => null\n }\n\n return async (name: string): Promise<string | null> => {\n reader ??= resolveDir()\n\n return await (await reader)(name)\n }\n}\n\n/**\n * Where the stored pages live among a Worker's static assets.\n *\n * Under a prefix, beside the app's own public files, because that is the\n * one store a Worker has that costs nothing in script size: an inline module\n * counts against the bundle's limit, and a port's 571 stored category pages\n * came to 69 MB of module against a limit of 10. The prefix is one the\n * Worker answers first - `run_worker_first` in wrangler.json, written by\n * the build - so a browser asking for `/_rsc-static/x.ppr.html` reaches the\n * app, which has no such route, rather than the asset; a stored page of a\n * guarded route is served only by the host that runs the guard.\n */\nexport const ASSETS_PREFIX = (dirName: string): string => `_${dirName}`\n\n/** The Workers assets binding, where this runs on Workers and it is bound. */\nasync function workersAssets(): Promise<AssetsBinding | null> {\n if (typeof navigator === 'undefined' || navigator.userAgent !== 'Cloudflare-Workers') return null\n\n try {\n // Computed, so neither the bundler nor tsc looks for a module only the\n // Workers runtime has.\n const specifier = 'cloudflare:workers'\n const { env } = (await import(/* @vite-ignore */ specifier)) as { env: { ASSETS?: AssetsBinding } }\n\n return env.ASSETS && typeof env.ASSETS.fetch === 'function' ? env.ASSETS : null\n } catch {\n return null\n }\n}\n\ninterface AssetsBinding {\n fetch(input: Request | string): Promise<Response>\n}\n\n/**\n * Read stored pages through the assets binding, each name once per isolate.\n *\n * The host asks for `{url}.html`, then `{url}.ppr.html`, then the pattern's,\n * on every request: three asks per page, most of them misses. The binding\n * is a fetch, not a memory read, so the answers - misses included - are kept\n * for the life of the isolate, the way the disk reader keeps its listing.\n */\nconst KNOWN_LIMIT = 4096\n\nexport function assetsReader(assets: AssetsBinding, prefix: string): (name: string) => Promise<string | null> {\n const known = new Map<string, Promise<string | null>>()\n\n return (name) => {\n let pending = known.get(name)\n\n if (!pending) {\n // Bounded. Misses are kept too, and every made-up path is three of\n // them: kept for the life of the isolate, a crawler of random urls grew\n // this without end. Dropping the oldest costs one fetch, later.\n if (known.size >= KNOWN_LIMIT) known.delete(known.keys().next().value!)\n\n const path = `${prefix}/${name.split('/').map(encodeURIComponent).join('/')}`\n\n pending = assets\n .fetch(new Request(`https://assets.invalid${path}`))\n .then((response) => (response.ok ? response.text() : null))\n .catch(() => null)\n\n known.set(name, pending)\n }\n\n return pending\n }\n}\n\n/**\n * The frozen pages as one module, for a runtime with no filesystem.\n *\n * A Worker cannot readdir. Its modules are what wrangler uploaded, and a\n * sibling .mjs beside the bundle is one of them - so the build writes every\n * stored file into `rsc-static-inline.mjs` as strings, and this walks up from\n * the caller the way the disk reader does, importing rather than reading.\n * The specifier is computed, and marked for the bundler to leave alone: at\n * bundle time the file does not exist yet, because it is written by the\n * prerender that runs the bundle.\n *\n * Two forms of the specifier, because runtimes disagree. workerd resolves a\n * relative string against the importing module's name and refuses a url;\n * Node and Bun want the url, since a relative string would resolve against\n * this file rather than the caller's.\n */\nasync function inlinePrerendered(\n moduleUrl: string,\n fileName: string,\n levels: number,\n): Promise<Record<string, string> | null> {\n for (let i = 0; i <= levels; i++) {\n const relative = './' + '../'.repeat(i) + fileName\n\n for (const specifier of [relative, safeUrl(relative, moduleUrl)]) {\n if (!specifier) continue\n\n try {\n const loaded = (await import(/* @vite-ignore */ specifier)) as { default?: Record<string, string> }\n\n if (loaded.default && typeof loaded.default === 'object') return loaded.default\n } catch {\n // Not there, or not at this level.\n }\n }\n }\n\n return null\n}\n\nfunction safeUrl(relative: string, base: string): string | null {\n try {\n return new URL(relative, base).href\n } catch {\n return null\n }\n}\n\n/**\n * The entry a binary is compiled from, written beside the server.\n *\n * Two static imports, in this order: the inline module first - evaluating\n * it hands the pages over - and the server second. A module's imports are\n * evaluated in order, before its own body, so the pages are in place before\n * the server's first line runs. Bun embeds both.\n *\n * Static rather than `await import()`: a top-level await is what made Bun\n * skip `--bytecode` for this entry, silently, byte for byte - and a port\n * whose other Nitro app compiled with it asked why this one could not.\n * `bun build --compile --bytecode .output/server/compile.mjs` works now.\n */\nexport function compileEntrySource(dirName: string): string {\n return (\n '// The entry to compile into one binary:\\n' +\n '// bun build --compile .output/server/compile.mjs --outfile dist/app\\n' +\n '//\\n' +\n '//\\n' +\n '// A binary carries what is imported by name. The server reads its frozen pages\\n' +\n '// through a computed import, which a compile cannot see - imported here, they\\n' +\n '// travel inside the binary and are handed to the server before it starts.\\n' +\n '// Two static imports in this order, and no top-level await: imports evaluate\\n' +\n '// in order, and an await here is what stopped --bytecode from applying.\\n' +\n `import \"./${inlineModuleName(dirName)}\";\\n` +\n 'import \"./index.mjs\";\\n'\n )\n}\n\n/** The name the build writes the inline module under, beside the stored pages' directory. */\nexport function inlineModuleName(dirName: string): string {\n return `${dirName}-inline.mjs`\n}\n\n/**\n * Every stored file under `dir`, as the source of the inline module.\n * Strings only: a frozen page, its flight payload, its meta, an api answer.\n */\nexport async function inlineModuleSource(dir: string): Promise<string> {\n const { readdir: list, readFile: read } = await import('node:fs/promises')\n const entries: Record<string, string> = {}\n\n const walk = async (sub: string): Promise<void> => {\n for (const entry of await list(join(dir, sub), { withFileTypes: true })) {\n const rel = sub ? `${sub}/${entry.name}` : entry.name\n\n if (entry.isDirectory()) await walk(rel)\n else entries[rel] = await read(join(dir, rel), 'utf-8')\n }\n }\n\n await walk('')\n\n // Exported for the Worker, which imports it when the directory is not\n // there, and handed over as a global for the binary, whose compile entry\n // imports it first for exactly this side effect. The same data either way.\n return (\n '// @generated by the RSC build: the stored pages, for a runtime with no filesystem.\\n' +\n 'const pages = ' +\n JSON.stringify(entries) +\n ';\\n' +\n 'globalThis[Symbol.for(\"rsc-kit.embedded-pages\")] = pages;\\n' +\n 'export default pages;\\n'\n )\n}\n\nfunction contentTypeOf(pathname: string): string {\n if (pathname.endsWith('.js')) return 'text/javascript; charset=utf-8'\n if (pathname.endsWith('.css')) return 'text/css; charset=utf-8'\n if (pathname.endsWith('.map')) return 'application/json; charset=utf-8'\n if (pathname.endsWith('.svg')) return 'image/svg+xml'\n if (pathname.endsWith('.woff2')) return 'font/woff2'\n\n return 'application/octet-stream'\n}\n\n/**\n * Write build output into a directory.\n *\n * The sink `prerender` and `exportSite` take. Names are relative and may\n * contain directories — `docs/index.html` — so each one's parent is created\n * as it goes.\n */\nexport function writeTo(dir: string): ((name: string, contents: string) => Promise<void>) & { dir: string } {\n const write = async (name: string, contents: string): Promise<void> => {\n const path = join(dir, name)\n\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, contents)\n }\n\n // Where it wrote, for a caller that has to read it back. The embeddable\n // module has to list these files, and being told the directory a second time\n // is a second place for it to be wrong.\n return Object.assign(write, { dir })\n}\n\n/**\n * Copy the built browser bundle into an exported site.\n *\n * Separate from the export itself because copying a tree of files is a\n * filesystem operation by nature — a deploy that uploads them to a bucket\n * has its own way to do that, and passes its own callback instead.\n */\nexport function copyAssets(from: string, to: string, url = '/assets/') {\n return async (): Promise<void> => {\n const at = url.replace(/^\\/+|\\/+$/g, '')\n\n if (at === '') return\n\n const target = join(to, at)\n\n await mkdir(dirname(target), { recursive: true })\n await cp(from, target, { recursive: true })\n }\n}\n\n/**\n * Put the stored pages among a Worker's static assets, and have the Worker\n * answer their prefix first.\n *\n * Run after Nitro has written its public-asset list and wrangler.json, so\n * the copies are in neither: not served as assets ahead of the Worker, and\n * not needing a wrangler key Nitro would override. `run_worker_first` is\n * added to the written config for the one prefix. The server-side directory\n * is removed once copied, so nothing in it is uploaded twice. Returns how\n * many files were moved; none when nothing was stored.\n */\nexport async function storedPagesToAssets(staticDir: string, publicDir: string, wranglerPath: string): Promise<number> {\n const { cp, readFile: read, writeFile: write, stat, readdir: list } = await import('node:fs/promises')\n const prefix = ASSETS_PREFIX(staticDir.split(/[\\\\/]/).pop() || 'rsc-static')\n\n try {\n await stat(staticDir)\n } catch {\n return 0\n }\n\n let copied = 0\n const count = async (dir: string): Promise<void> => {\n for (const entry of await list(dir, { withFileTypes: true })) {\n if (entry.isDirectory()) await count(join(dir, entry.name))\n else copied++\n }\n }\n\n await count(staticDir)\n await cp(staticDir, join(publicDir, prefix), { recursive: true })\n\n // Moved, not copied: wrangler's default rules upload every .html and\n // .txt under the server directory as a text module, and 573 stored\n // shells left beside the bundle were 55 MB of modules against a 10 MB\n // limit - a deploy that happened to fit, once.\n const { rm } = await import('node:fs/promises')\n\n await rm(staticDir, { recursive: true, force: true })\n\n try {\n const config = JSON.parse(await read(wranglerPath, 'utf-8')) as {\n assets?: { run_worker_first?: boolean | string[] } & Record<string, unknown>\n }\n\n if (config.assets && config.assets.run_worker_first !== true) {\n const first = Array.isArray(config.assets.run_worker_first) ? config.assets.run_worker_first : []\n const pattern = `/${prefix}/*`\n\n if (!first.includes(pattern)) config.assets.run_worker_first = [...first, pattern]\n\n await write(wranglerPath, JSON.stringify(config, null, 2))\n }\n } catch {\n // No wrangler.json to amend: a deploy config the app writes itself, which\n // then carries the prefix in its own run_worker_first.\n }\n\n return copied\n}\n"]}
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4CAA4C;AAE5C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,OAAO,GAAgC,IAAI,CAAA;IAE/C,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;IAC1C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC1C,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,IAAY,EAAQ,EAAE;QACpD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QAE5B,IAAI,IAAI,GAAG,iBAAiB,GAAG,CAAC;YAAE,OAAM;QAExC,OAAO,IAAI,GAAG,IAAI,GAAG,iBAAiB,IAAI,QAAQ,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC5D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAe,CAAA;YACrD,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,MAA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MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;YAC7D,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAA;YACjG,MAAM,OAAO,GAAG,IAAI,MAAM,IAAI,CAAA;YAE9B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAA;YAElF,MAAM,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,uDAAuD;IACzD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["// Reading built output off a disk.\n//\n// Kept apart from the host on purpose: it is the only part of serving an RSC\n// app that assumes a filesystem, and plenty of places to run one do not have\n// one. Nothing in `@rsc-kit/core/host` imports this module, so a bundle for a\n// host without a filesystem carries no reference to `node:fs` at all.\n//\n// Assets are not here any more — Nitro publishes and serves those. What is\n// left is the prerendered output: written by the build, read by the server it\n// generates, and copied by a static export.\n\nimport { cp, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/**\n * Read what the prerenderer wrote, from a directory.\n *\n * Missing is an answer, not an error: a partial prerender is a valid state,\n * and anything not found here is rendered on demand instead.\n */\nexport function prerenderedFrom(dir: string) {\n /**\n * What is on disk, listed once.\n *\n * A miss used to be a thrown ENOENT, and misses are the common case: the\n * host asks for `{url}.html`, then `{url}.ppr.html`, then the route's\n * pattern — so every request to a page served by a pattern shell threw and\n * caught two exceptions before finding anything. Measured at 3,000 req/s\n * against 28,000 for the same page read from memory.\n *\n * Contents are cached for the life of the process. A build's output does\n * not change under a running server - a deploy restarts it, and a server\n * that outlived a rebuild would be serving a stale engine against new\n * pages anyway - so the first read is the only one. Under load the same\n * page used to be opened, read and closed thousands of times a second,\n * which a profile showed as the one cost on a stored page that was ours\n * rather than React's. Capped by bytes, so a site with more pages than\n * memory holds the hot ones and re-reads the rest.\n */\n let present: Promise<Set<string>> | null = null\n\n const CONTENT_CAP_BYTES = 64 * 1024 * 1024\n const contents = new Map<string, string>()\n let held = 0\n\n const remember = (name: string, text: string): void => {\n const size = text.length * 2\n\n if (size > CONTENT_CAP_BYTES / 4) return\n\n while (held + size > CONTENT_CAP_BYTES && contents.size > 0) {\n const oldest = contents.keys().next().value as string\n held -= contents.get(oldest)!.length * 2\n contents.delete(oldest)\n }\n\n contents.set(name, text)\n held += size\n }\n\n const listing = async (): Promise<Set<string>> => {\n present ??= readdir(dir, { recursive: true })\n .then((names) => new Set(names.map((n) => String(n).replace(/\\\\/g, '/'))))\n // An absent directory is an empty one: a partial prerender is a valid\n // state, and everything falls through to being rendered.\n .catch(() => new Set<string>())\n\n return await present\n }\n\n return async (name: string): Promise<string | null> => {\n if (name.includes('..')) return null\n\n if (!(await listing()).has(name)) return null\n\n const cached = contents.get(name)\n\n if (cached !== undefined) return cached\n\n try {\n const text = await readFile(join(dir, name), 'utf-8')\n\n remember(name, text)\n\n return text\n } catch {\n return null\n }\n }\n}\n\n/**\n * The same reader, for a directory whose absolute path is not known until the\n * server runs.\n *\n * Nitro bundles the generated entry to a different depth depending on the\n * preset — `.output/server/index.mjs` for one, `.output/server/_ssr/rsc.mjs`\n * for another — so neither a fixed relative path nor a path baked in at build\n * time survives: the first is wrong for half the presets, and the second stops\n * being true the moment `.output/` is copied to the machine that serves it.\n *\n * So the caller passes its own `import.meta.url` and the directory is found by\n * walking up from it. A few levels, bounded, and resolved once.\n *\n * prerendered: prerenderedBeside(import.meta.url, 'rsc-static')\n *\n * Not finding it is a valid state and not an error: nothing was frozen, or\n * this host has no filesystem to have frozen it on. Every page renders live,\n * which is what happens today everywhere.\n */\n/**\n * Where a compiled binary puts the frozen pages.\n *\n * `bun build --compile` embeds what is imported statically and nothing a\n * computed import names, so the walk below finds no directory and no\n * module inside a binary. The build writes `compile.mjs` beside the\n * server: it imports the inline module by name - which embeds it - and\n * hands the pages over here before importing the server. Shared as a\n * global under a registered symbol, because the wrapper and this module\n * are bundled apart.\n */\nexport const EMBEDDED_PAGES = Symbol.for('rsc-kit.embedded-pages')\n\nfunction embeddedPages(): Record<string, string> | null {\n const pages = (globalThis as Record<symbol, unknown>)[EMBEDDED_PAGES]\n\n return pages && typeof pages === 'object' ? (pages as Record<string, string>) : null\n}\n\nexport function prerenderedBeside(moduleUrl: string, dirName: string, levels = 4) {\n let reader: Promise<(name: string) => Promise<string | null>> | null = null\n\n const resolveDir = async (): Promise<(name: string) => Promise<string | null>> => {\n const embedded = embeddedPages()\n\n if (embedded) return async (name) => embedded[name] ?? null\n\n let dir: string | null = null\n\n try {\n const { fileURLToPath } = await import('node:url')\n\n dir = dirname(fileURLToPath(moduleUrl))\n } catch {\n // No filesystem, or no file: url to speak of. The inline module below\n // is the only place the pages can be.\n }\n\n if (dir !== null) {\n for (let i = 0; i <= levels; i++) {\n const candidate = join(dir, ...Array(i).fill('..'), dirName)\n\n try {\n await readdir(candidate)\n\n return prerenderedFrom(candidate)\n } catch {\n // Not at this level. Keep walking.\n }\n }\n }\n\n // A Worker: the pages were uploaded as static assets, under a prefix\n // the Worker answers first, and are read back through the binding.\n const assets = await workersAssets()\n\n if (assets) return assetsReader(assets, `/${ASSETS_PREFIX(dirName)}`)\n\n const inline = await inlinePrerendered(moduleUrl, `${dirName}-inline.mjs`, levels)\n\n return inline ? async (name) => inline[name] ?? null : async () => null\n }\n\n return async (name: string): Promise<string | null> => {\n reader ??= resolveDir()\n\n return await (await reader)(name)\n }\n}\n\n/**\n * Where the stored pages live among a Worker's static assets.\n *\n * Under a prefix, beside the app's own public files, because that is the\n * one store a Worker has that costs nothing in script size: an inline module\n * counts against the bundle's limit, and a port's 571 stored category pages\n * came to 69 MB of module against a limit of 10. The prefix is one the\n * Worker answers first - `run_worker_first` in wrangler.json, written by\n * the build - so a browser asking for `/_rsc-static/x.ppr.html` reaches the\n * app, which has no such route, rather than the asset; a stored page of a\n * guarded route is served only by the host that runs the guard.\n */\nexport const ASSETS_PREFIX = (dirName: string): string => `_${dirName}`\n\n/** The Workers assets binding, where this runs on Workers and it is bound. */\nasync function workersAssets(): Promise<AssetsBinding | null> {\n if (typeof navigator === 'undefined' || navigator.userAgent !== 'Cloudflare-Workers') return null\n\n try {\n // Computed, so neither the bundler nor tsc looks for a module only the\n // Workers runtime has.\n const specifier = 'cloudflare:workers'\n const { env } = (await import(/* @vite-ignore */ specifier)) as { env: { ASSETS?: AssetsBinding } }\n\n return env.ASSETS && typeof env.ASSETS.fetch === 'function' ? env.ASSETS : null\n } catch {\n return null\n }\n}\n\ninterface AssetsBinding {\n fetch(input: Request | string): Promise<Response>\n}\n\n/**\n * Read stored pages through the assets binding, each name once per isolate.\n *\n * The host asks for `{url}.html`, then `{url}.ppr.html`, then the pattern's,\n * on every request: three asks per page, most of them misses. The binding\n * is a fetch, not a memory read, so the answers - misses included - are kept\n * for the life of the isolate, the way the disk reader keeps its listing.\n */\nconst KNOWN_LIMIT = 4096\n\nexport function assetsReader(assets: AssetsBinding, prefix: string): (name: string) => Promise<string | null> {\n const known = new Map<string, Promise<string | null>>()\n\n return (name) => {\n let pending = known.get(name)\n\n if (!pending) {\n // Bounded. Misses are kept too, and every made-up path is three of\n // them: kept for the life of the isolate, a crawler of random urls grew\n // this without end. Dropping the oldest costs one fetch, later.\n if (known.size >= KNOWN_LIMIT) known.delete(known.keys().next().value!)\n\n const path = `${prefix}/${name.split('/').map(encodeURIComponent).join('/')}`\n\n pending = assets\n .fetch(new Request(`https://assets.invalid${path}`))\n .then((response) => (response.ok ? response.text() : null))\n .catch(() => null)\n\n known.set(name, pending)\n }\n\n return pending\n }\n}\n\n/**\n * The frozen pages as one module, for a runtime with no filesystem.\n *\n * A Worker cannot readdir. Its modules are what wrangler uploaded, and a\n * sibling .mjs beside the bundle is one of them - so the build writes every\n * stored file into `rsc-static-inline.mjs` as strings, and this walks up from\n * the caller the way the disk reader does, importing rather than reading.\n * The specifier is computed, and marked for the bundler to leave alone: at\n * bundle time the file does not exist yet, because it is written by the\n * prerender that runs the bundle.\n *\n * Two forms of the specifier, because runtimes disagree. workerd resolves a\n * relative string against the importing module's name and refuses a url;\n * Node and Bun want the url, since a relative string would resolve against\n * this file rather than the caller's.\n */\nasync function inlinePrerendered(\n moduleUrl: string,\n fileName: string,\n levels: number,\n): Promise<Record<string, string> | null> {\n for (let i = 0; i <= levels; i++) {\n const relative = './' + '../'.repeat(i) + fileName\n\n for (const specifier of [relative, safeUrl(relative, moduleUrl)]) {\n if (!specifier) continue\n\n try {\n const loaded = (await import(/* @vite-ignore */ specifier)) as { default?: Record<string, string> }\n\n if (loaded.default && typeof loaded.default === 'object') return loaded.default\n } catch {\n // Not there, or not at this level.\n }\n }\n }\n\n return null\n}\n\nfunction safeUrl(relative: string, base: string): string | null {\n try {\n return new URL(relative, base).href\n } catch {\n return null\n }\n}\n\n/**\n * The entry a binary is compiled from, written beside the server.\n *\n * Two static imports, in this order: the inline module first - evaluating\n * it hands the pages over - and the server second. A module's imports are\n * evaluated in order, before its own body, so the pages are in place before\n * the server's first line runs. Bun embeds both.\n *\n * Static rather than `await import()`: a top-level await is what made Bun\n * skip `--bytecode` for this entry, silently, byte for byte - and a port\n * whose other Nitro app compiled with it asked why this one could not.\n * `bun build --compile --bytecode .output/server/compile.mjs` works now.\n */\nexport function compileEntrySource(dirName: string): string {\n return (\n '// The entry to compile into one binary:\\n' +\n '// bun build --compile .output/server/compile.mjs --outfile dist/app\\n' +\n '//\\n' +\n '//\\n' +\n '// A binary carries what is imported by name. The server reads its frozen pages\\n' +\n '// through a computed import, which a compile cannot see - imported here, they\\n' +\n '// travel inside the binary and are handed to the server before it starts.\\n' +\n '// Two static imports in this order, and no top-level await: imports evaluate\\n' +\n '// in order, and an await here is what stopped --bytecode from applying.\\n' +\n `import \"./${inlineModuleName(dirName)}\";\\n` +\n 'import \"./index.mjs\";\\n'\n )\n}\n\n/** The name the build writes the inline module under, beside the stored pages' directory. */\nexport function inlineModuleName(dirName: string): string {\n return `${dirName}-inline.mjs`\n}\n\n/**\n * Every stored file under `dir`, as the source of the inline module.\n * Strings only: a frozen page, its flight payload, its meta, an api answer.\n */\nexport async function inlineModuleSource(dir: string): Promise<string> {\n const { readdir: list, readFile: read } = await import('node:fs/promises')\n const entries: Record<string, string> = {}\n\n const walk = async (sub: string): Promise<void> => {\n for (const entry of await list(join(dir, sub), { withFileTypes: true })) {\n const rel = sub ? `${sub}/${entry.name}` : entry.name\n\n if (entry.isDirectory()) await walk(rel)\n else entries[rel] = await read(join(dir, rel), 'utf-8')\n }\n }\n\n await walk('')\n\n // Exported for the Worker, which imports it when the directory is not\n // there, and handed over as a global for the binary, whose compile entry\n // imports it first for exactly this side effect. The same data either way.\n return (\n '// @generated by the RSC build: the stored pages, for a runtime with no filesystem.\\n' +\n 'const pages = ' +\n JSON.stringify(entries) +\n ';\\n' +\n 'globalThis[Symbol.for(\"rsc-kit.embedded-pages\")] = pages;\\n' +\n 'export default pages;\\n'\n )\n}\n\nfunction contentTypeOf(pathname: string): string {\n if (pathname.endsWith('.js')) return 'text/javascript; charset=utf-8'\n if (pathname.endsWith('.css')) return 'text/css; charset=utf-8'\n if (pathname.endsWith('.map')) return 'application/json; charset=utf-8'\n if (pathname.endsWith('.svg')) return 'image/svg+xml'\n if (pathname.endsWith('.woff2')) return 'font/woff2'\n\n return 'application/octet-stream'\n}\n\n/**\n * Write build output into a directory.\n *\n * The sink `prerender` and `exportSite` take. Names are relative and may\n * contain directories — `docs/index.html` — so each one's parent is created\n * as it goes.\n */\nexport function writeTo(dir: string): ((name: string, contents: string) => Promise<void>) & { dir: string } {\n const write = async (name: string, contents: string): Promise<void> => {\n const path = join(dir, name)\n\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, contents)\n }\n\n // Where it wrote, for a caller that has to read it back. The embeddable\n // module has to list these files, and being told the directory a second time\n // is a second place for it to be wrong.\n return Object.assign(write, { dir })\n}\n\n/**\n * Copy the built browser bundle into an exported site.\n *\n * Separate from the export itself because copying a tree of files is a\n * filesystem operation by nature — a deploy that uploads them to a bucket\n * has its own way to do that, and passes its own callback instead.\n */\n/**\n * The whole client output into an exported site: every file a server would\n * have answered as a file - the bundle, public/, icons, the web manifest,\n * the service worker. Precompressed copies (.br, .gz, .zst) come too; a host\n * that does not serve them ignores them.\n */\nexport function copyPublic(from: string, to: string) {\n return async (): Promise<void> => {\n await mkdir(to, { recursive: true })\n await cp(from, to, { recursive: true })\n }\n}\n\n/** A stored route.ts answer, as prerender writes it. */\ninterface StoredAnswer {\n status: number\n headers: [string, string][]\n body: string\n varies: boolean\n}\n\n/**\n * Stored route.ts answers written out as the files they are: the body at the\n * url, `robots.txt` at robots.txt. Only answers a static host can give as\n * they were - a 200 the same for everyone, at a url with an extension, since\n * a file is typed by its extension and the stored content type would be lost.\n */\nexport async function exportStoredAnswers(\n staticDir: string,\n to: string,\n): Promise<{ written: string[]; skipped: { url: string; why: string }[] }> {\n const written: string[] = []\n const skipped: { url: string; why: string }[] = []\n let entries: string[]\n\n try {\n entries = (await readdir(staticDir, { recursive: true })) as string[]\n } catch {\n return { written, skipped }\n }\n\n for (const entry of entries.sort()) {\n if (!entry.endsWith('.api.json')) continue\n\n const path = entry.slice(0, -'.api.json'.length).split(/[\\\\/]/).join('/')\n const url = '/' + (path === 'index' ? '' : path)\n const answer = JSON.parse(await readFile(join(staticDir, entry), 'utf-8')) as StoredAnswer\n\n if (answer.status !== 200) {\n skipped.push({ url, why: `answers ${answer.status}` })\n continue\n }\n\n if (answer.varies) {\n skipped.push({ url, why: 'varies by request' })\n continue\n }\n\n if (!/\\.[a-z0-9]+$/i.test(path)) {\n skipped.push({ url, why: 'no extension to give a static host its content type' })\n continue\n }\n\n const target = join(to, path)\n\n await mkdir(dirname(target), { recursive: true })\n await writeFile(target, answer.body)\n written.push(url)\n }\n\n return { written, skipped }\n}\n\nexport function copyAssets(from: string, to: string, url = '/assets/') {\n return async (): Promise<void> => {\n const at = url.replace(/^\\/+|\\/+$/g, '')\n\n if (at === '') return\n\n const target = join(to, at)\n\n await mkdir(dirname(target), { recursive: true })\n await cp(from, target, { recursive: true })\n }\n}\n\n/**\n * Put the stored pages among a Worker's static assets, and have the Worker\n * answer their prefix first.\n *\n * Run after Nitro has written its public-asset list and wrangler.json, so\n * the copies are in neither: not served as assets ahead of the Worker, and\n * not needing a wrangler key Nitro would override. `run_worker_first` is\n * added to the written config for the one prefix. The server-side directory\n * is removed once copied, so nothing in it is uploaded twice. Returns how\n * many files were moved; none when nothing was stored.\n */\nexport async function storedPagesToAssets(staticDir: string, publicDir: string, wranglerPath: string): Promise<number> {\n const { cp, readFile: read, writeFile: write, stat, readdir: list } = await import('node:fs/promises')\n const prefix = ASSETS_PREFIX(staticDir.split(/[\\\\/]/).pop() || 'rsc-static')\n\n try {\n await stat(staticDir)\n } catch {\n return 0\n }\n\n let copied = 0\n const count = async (dir: string): Promise<void> => {\n for (const entry of await list(dir, { withFileTypes: true })) {\n if (entry.isDirectory()) await count(join(dir, entry.name))\n else copied++\n }\n }\n\n await count(staticDir)\n await cp(staticDir, join(publicDir, prefix), { recursive: true })\n\n // Moved, not copied: wrangler's default rules upload every .html and\n // .txt under the server directory as a text module, and 573 stored\n // shells left beside the bundle were 55 MB of modules against a 10 MB\n // limit - a deploy that happened to fit, once.\n const { rm } = await import('node:fs/promises')\n\n await rm(staticDir, { recursive: true, force: true })\n\n try {\n const config = JSON.parse(await read(wranglerPath, 'utf-8')) as {\n assets?: { run_worker_first?: boolean | string[] } & Record<string, unknown>\n }\n\n if (config.assets && config.assets.run_worker_first !== true) {\n const first = Array.isArray(config.assets.run_worker_first) ? config.assets.run_worker_first : []\n const pattern = `/${prefix}/*`\n\n if (!first.includes(pattern)) config.assets.run_worker_first = [...first, pattern]\n\n await write(wranglerPath, JSON.stringify(config, null, 2))\n }\n } catch {\n // No wrangler.json to amend: a deploy config the app writes itself, which\n // then carries the prefix in its own run_worker_first.\n }\n\n return copied\n}\n"]}
|
package/dist/host.js
CHANGED
|
@@ -694,6 +694,14 @@ export function createRscHandler(options) {
|
|
|
694
694
|
// Api routes first. A url is one or the other, and a page that shares a
|
|
695
695
|
// path with a route.ts would otherwise win by accident of ordering.
|
|
696
696
|
const api = matchApiRoute(routes, url.pathname);
|
|
697
|
+
// The sitemap the build writes itself when the app has none: stored, with
|
|
698
|
+
// no route.ts behind it, so nothing above looks for it. Every server
|
|
699
|
+
// build answered it 404 while the report said it was written.
|
|
700
|
+
if (!api && url.pathname === "/sitemap.xml") {
|
|
701
|
+
const stored = await storedAnswer(request, url);
|
|
702
|
+
if (stored)
|
|
703
|
+
return stored;
|
|
704
|
+
}
|
|
697
705
|
if (api && engine.handleApiRoute) {
|
|
698
706
|
// The guards above it run first, exactly as they would for a page in the
|
|
699
707
|
// same directory. A route.ts is colocated with the pages it belongs
|
|
@@ -997,12 +1005,20 @@ export function createRscHandler(options) {
|
|
|
997
1005
|
* for the same reason, so this is the second of two locks on the same door.
|
|
998
1006
|
*/
|
|
999
1007
|
async function frozenApi(request, url, api) {
|
|
1008
|
+
if (isGuarded(api))
|
|
1009
|
+
return null;
|
|
1010
|
+
return await storedAnswer(request, url);
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* A stored answer for this url, if the build wrote one: a route.ts's, or a
|
|
1014
|
+
* file the build wrote with no route behind it - the sitemap it writes
|
|
1015
|
+
* when the app has no sitemap.ts.
|
|
1016
|
+
*/
|
|
1017
|
+
async function storedAnswer(request, url) {
|
|
1000
1018
|
if (!options.prerendered)
|
|
1001
1019
|
return null;
|
|
1002
1020
|
if (request.method !== "GET" && request.method !== "HEAD")
|
|
1003
1021
|
return null;
|
|
1004
|
-
if (isGuarded(api))
|
|
1005
|
-
return null;
|
|
1006
1022
|
const storedName = apiKey(url.pathname);
|
|
1007
1023
|
const stored = await options.prerendered(storedName);
|
|
1008
1024
|
if (stored === null)
|