@farm.js/plugin 0.1.39 → 0.1.41
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rsc/client-sourcemaps.d.ts +13 -0
- package/dist/rsc/client-sourcemaps.d.ts.map +1 -0
- package/dist/rsc/client-sourcemaps.js +52 -0
- package/dist/rsc/document-layouts.d.ts +16 -0
- package/dist/rsc/document-layouts.d.ts.map +1 -0
- package/dist/rsc/document-layouts.js +82 -0
- package/dist/rsc/entries/client.d.ts.map +1 -1
- package/dist/rsc/entries/client.js +21 -8
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +215 -24
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +5 -3
- package/dist/rsc/index.d.ts +4 -0
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +53 -1
- package/dist/rsc/nitro-build.d.ts.map +1 -1
- package/dist/rsc/nitro-build.js +187 -70
- package/dist/rsc/types.d.ts +20 -0
- package/dist/rsc/types.d.ts.map +1 -1
- package/dist/rsc/vite-plugin-nitro.d.ts.map +1 -1
- package/dist/rsc/vite-plugin-nitro.js +10 -2
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
/** Where an RSC build keeps client source maps, beside (not inside) the public client output. */
|
|
3
|
+
export declare const RSC_CLIENT_SOURCEMAPS_DIR = "client-sourcemaps";
|
|
4
|
+
/**
|
|
5
|
+
* Keep the client environment's source maps out of the public output, as core
|
|
6
|
+
* client builds do. A client map carries the original source of every module
|
|
7
|
+
* in a chunk, including code stripped from the client JS, such as
|
|
8
|
+
* `createServerOnlyFn` bodies. Any enabled `build.sourcemap` becomes
|
|
9
|
+
* `"hidden"` (the JS names no map), and the maps are moved beside the client
|
|
10
|
+
* output.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rscPrivateClientSourcemaps(environmentName?: string): Plugin;
|
|
13
|
+
//# sourceMappingURL=client-sourcemaps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-sourcemaps.d.ts","sourceRoot":"","sources":["../../src/rsc/client-sourcemaps.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,iGAAiG;AACjG,eAAO,MAAM,yBAAyB,sBAAsB,CAAC;AAI7D;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,SAAW,GAAG,MAAM,CAqC7E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/** Where an RSC build keeps client source maps, beside (not inside) the public client output. */
|
|
4
|
+
export const RSC_CLIENT_SOURCEMAPS_DIR = "client-sourcemaps";
|
|
5
|
+
/**
|
|
6
|
+
* Keep the client environment's source maps out of the public output, as core
|
|
7
|
+
* client builds do. A client map carries the original source of every module
|
|
8
|
+
* in a chunk, including code stripped from the client JS, such as
|
|
9
|
+
* `createServerOnlyFn` bodies. Any enabled `build.sourcemap` becomes
|
|
10
|
+
* `"hidden"` (the JS names no map), and the maps are moved beside the client
|
|
11
|
+
* output.
|
|
12
|
+
*/
|
|
13
|
+
export function rscPrivateClientSourcemaps(environmentName = "client") {
|
|
14
|
+
let maps = [];
|
|
15
|
+
let mapsDir;
|
|
16
|
+
const isClient = (environment) => environment?.name === environmentName;
|
|
17
|
+
return {
|
|
18
|
+
name: "@farm.js/plugin/rsc:private-client-sourcemaps",
|
|
19
|
+
enforce: "post",
|
|
20
|
+
apply: "build",
|
|
21
|
+
configEnvironment(name, config) {
|
|
22
|
+
if (name !== environmentName || !config.build?.sourcemap)
|
|
23
|
+
return;
|
|
24
|
+
return { build: { sourcemap: "hidden" } };
|
|
25
|
+
},
|
|
26
|
+
generateBundle(outputOptions, bundle) {
|
|
27
|
+
if (!isClient(this.environment))
|
|
28
|
+
return;
|
|
29
|
+
maps = [];
|
|
30
|
+
mapsDir = outputOptions.dir
|
|
31
|
+
? path.join(path.dirname(outputOptions.dir), RSC_CLIENT_SOURCEMAPS_DIR)
|
|
32
|
+
: undefined;
|
|
33
|
+
for (const [fileName, output] of Object.entries(bundle)) {
|
|
34
|
+
if (output.type !== "asset" || !fileName.endsWith(".map"))
|
|
35
|
+
continue;
|
|
36
|
+
maps.push([fileName, output.source ?? ""]);
|
|
37
|
+
delete bundle[fileName];
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async writeBundle() {
|
|
41
|
+
if (!isClient(this.environment) || !mapsDir)
|
|
42
|
+
return;
|
|
43
|
+
await fs.rm(mapsDir, { recursive: true, force: true });
|
|
44
|
+
for (const [fileName, source] of maps) {
|
|
45
|
+
const target = path.join(mapsDir, fileName);
|
|
46
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
47
|
+
await fs.writeFile(target, source);
|
|
48
|
+
}
|
|
49
|
+
maps = [];
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a layout module renders the whole `<html>` document, following re-exports of its default
|
|
3
|
+
* export a few modules deep (`export { default } from "../site/app/layout"`).
|
|
4
|
+
*/
|
|
5
|
+
export declare function layoutRendersDocument(file: string, depth?: number): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Files below `routesDir` whose name passes `test`, as route-relative keys (`/layout.tsx`,
|
|
8
|
+
* `/(docs)/layout.tsx`): the keys the RSC entry gives its merged route module maps.
|
|
9
|
+
*/
|
|
10
|
+
export declare function findRouteFiles(routesDir: string, test: (name: string) => boolean): Promise<Array<{
|
|
11
|
+
key: string;
|
|
12
|
+
file: string;
|
|
13
|
+
}>>;
|
|
14
|
+
/** The layouts below `routesDir` that render the `<html>` document themselves. */
|
|
15
|
+
export declare function findDocumentLayouts(routesDir: string): Promise<string[]>;
|
|
16
|
+
//# sourceMappingURL=document-layouts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-layouts.d.ts","sourceRoot":"","sources":["../../src/rsc/document-layouts.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAYrF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAC9B,OAAO,CAAC,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAuB/C;AAED,kFAAkF;AAClF,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAI9E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const LAYOUT_FILE = /^layout\.(tsx|jsx|ts|js)$/;
|
|
4
|
+
const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
5
|
+
const RENDERS_HTML = /<html[\s>]/;
|
|
6
|
+
// `export { default } from "./x"` and `export { Layout as default } from "./x"`.
|
|
7
|
+
const DEFAULT_REEXPORT = /export\s*\{[^}]*\b(?:default|[\w$]+\s+as\s+default)\b[^}]*\}\s*from\s*["'](\.{1,2}\/[^"']+)["']/;
|
|
8
|
+
async function resolveRelativeModule(fromFile, specifier) {
|
|
9
|
+
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
10
|
+
const candidates = [
|
|
11
|
+
base,
|
|
12
|
+
...SOURCE_EXTENSIONS.map((extension) => base + extension),
|
|
13
|
+
...SOURCE_EXTENSIONS.map((extension) => path.join(base, "index" + extension)),
|
|
14
|
+
];
|
|
15
|
+
for (const candidate of candidates) {
|
|
16
|
+
try {
|
|
17
|
+
if ((await fs.stat(candidate)).isFile())
|
|
18
|
+
return candidate;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// try the next candidate
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a layout module renders the whole `<html>` document, following re-exports of its default
|
|
28
|
+
* export a few modules deep (`export { default } from "../site/app/layout"`).
|
|
29
|
+
*/
|
|
30
|
+
export async function layoutRendersDocument(file, depth = 0) {
|
|
31
|
+
let source;
|
|
32
|
+
try {
|
|
33
|
+
source = await fs.readFile(file, "utf8");
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (RENDERS_HTML.test(source))
|
|
39
|
+
return true;
|
|
40
|
+
const reexport = DEFAULT_REEXPORT.exec(source);
|
|
41
|
+
if (!reexport || depth >= 4)
|
|
42
|
+
return false;
|
|
43
|
+
const target = await resolveRelativeModule(file, reexport[1]);
|
|
44
|
+
return target ? layoutRendersDocument(target, depth + 1) : false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Files below `routesDir` whose name passes `test`, as route-relative keys (`/layout.tsx`,
|
|
48
|
+
* `/(docs)/layout.tsx`): the keys the RSC entry gives its merged route module maps.
|
|
49
|
+
*/
|
|
50
|
+
export async function findRouteFiles(routesDir, test) {
|
|
51
|
+
const found = [];
|
|
52
|
+
const walk = async (dir) => {
|
|
53
|
+
let entries;
|
|
54
|
+
try {
|
|
55
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
const full = path.join(dir, entry.name);
|
|
62
|
+
if (entry.isDirectory()) {
|
|
63
|
+
if (entry.name !== "node_modules" && !entry.name.startsWith("."))
|
|
64
|
+
await walk(full);
|
|
65
|
+
}
|
|
66
|
+
else if (test(entry.name)) {
|
|
67
|
+
found.push({
|
|
68
|
+
key: "/" + path.relative(routesDir, full).split(path.sep).join("/"),
|
|
69
|
+
file: full,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
await walk(routesDir);
|
|
75
|
+
return found.sort((left, right) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0));
|
|
76
|
+
}
|
|
77
|
+
/** The layouts below `routesDir` that render the `<html>` document themselves. */
|
|
78
|
+
export async function findDocumentLayouts(routesDir) {
|
|
79
|
+
const layouts = await findRouteFiles(routesDir, (name) => LAYOUT_FILE.test(name));
|
|
80
|
+
const owners = await Promise.all(layouts.map(({ file }) => layoutRendersDocument(file)));
|
|
81
|
+
return layouts.filter((_, index) => owners[index]).map(({ key }) => key);
|
|
82
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAsU7D"}
|
|
@@ -177,9 +177,10 @@ async function main() {
|
|
|
177
177
|
|
|
178
178
|
debug('Starting client hydration');
|
|
179
179
|
|
|
180
|
-
// Clean duplicate DOM as early as possible (server may have sent two blocks)
|
|
180
|
+
// Clean duplicate DOM as early as possible (server may have sent two blocks). Only Farm's own
|
|
181
|
+
// wrapper: an app that owns the document can have an element with id="root" in its content.
|
|
181
182
|
const rootEl = document.getElementById('root');
|
|
182
|
-
if (rootEl) {
|
|
183
|
+
if (rootEl && rootEl.firstElementChild?.hasAttribute('data-farm-root')) {
|
|
183
184
|
while (rootEl.children.length > 1) rootEl.lastElementChild.remove();
|
|
184
185
|
while (rootEl.nextElementSibling) rootEl.nextElementSibling.remove();
|
|
185
186
|
}
|
|
@@ -280,8 +281,13 @@ async function main() {
|
|
|
280
281
|
debug('Fetching RSC for:', url);
|
|
281
282
|
|
|
282
283
|
try {
|
|
283
|
-
// Request RSC
|
|
284
|
-
|
|
284
|
+
// Request the page's RSC payload, '<page>.rsc', which a prerendered page serves as a
|
|
285
|
+
// static file. The page URL itself may be static HTML.
|
|
286
|
+
const payloadUrl = new URL(url, location.href);
|
|
287
|
+
payloadUrl.pathname = payloadUrl.pathname.endsWith('/')
|
|
288
|
+
? payloadUrl.pathname + 'index.rsc'
|
|
289
|
+
: payloadUrl.pathname + '.rsc';
|
|
290
|
+
const res = await fetch(payloadUrl, {
|
|
285
291
|
headers: createFarmDeploymentRequestHeaders(farmDeploymentId, {
|
|
286
292
|
Accept: 'text/x-component',
|
|
287
293
|
}),
|
|
@@ -305,6 +311,10 @@ async function main() {
|
|
|
305
311
|
// reflect the page actually rendered (auth gates redirect this way).
|
|
306
312
|
if (res.redirected && res.url) {
|
|
307
313
|
const dest = new URL(res.url);
|
|
314
|
+
if (dest.pathname.endsWith('.rsc')) {
|
|
315
|
+
const page = dest.pathname.slice(0, -'.rsc'.length);
|
|
316
|
+
dest.pathname = page.endsWith('/index') ? page.slice(0, -'index'.length) : page;
|
|
317
|
+
}
|
|
308
318
|
if (dest.origin === location.origin) {
|
|
309
319
|
const target = dest.pathname + dest.search + dest.hash;
|
|
310
320
|
if (target !== location.pathname + location.search + location.hash) {
|
|
@@ -321,14 +331,17 @@ async function main() {
|
|
|
321
331
|
location.href = url;
|
|
322
332
|
}
|
|
323
333
|
}
|
|
324
|
-
|
|
334
|
+
// A root layout that renders <html> owns the document: hydrate it whole, as Next.js does.
|
|
335
|
+
const rootElForHydrate = initial.ownsDocument ? document : document.getElementById('root');
|
|
325
336
|
if (!rootElForHydrate) {
|
|
326
337
|
console.error('[Farm.js] #root element not found');
|
|
327
338
|
return;
|
|
328
339
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
340
|
+
if (!initial.ownsDocument) {
|
|
341
|
+
// Final cleanup pass before hydrate (in case DOM changed during async)
|
|
342
|
+
while (rootElForHydrate.children.length > 1) rootElForHydrate.lastElementChild.remove();
|
|
343
|
+
while (rootElForHydrate.nextElementSibling) rootElForHydrate.nextElementSibling.remove();
|
|
344
|
+
}
|
|
332
345
|
debug('Hydrating application');
|
|
333
346
|
globalThis.__FARM_RSC_HYDRATED = true;
|
|
334
347
|
hydrateRoot(rootElForHydrate, React.createElement(BrowserRoot), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAu+C1D"}
|
package/dist/rsc/entries/rsc.js
CHANGED
|
@@ -89,6 +89,7 @@ import {
|
|
|
89
89
|
applyProductionMiddlewareHeaders,
|
|
90
90
|
createProductionMiddlewareRunner,
|
|
91
91
|
} from '@farm.js/core/middleware';
|
|
92
|
+
import { _withFarmGuardedResponseCache } from '@farm.js/core/internal/production-runtime';
|
|
92
93
|
import {
|
|
93
94
|
getAllowedAPIRouteMethods,
|
|
94
95
|
invokeAPIRouteEndpoint,
|
|
@@ -104,6 +105,16 @@ import {
|
|
|
104
105
|
compareRouteSpecificity,
|
|
105
106
|
getRoutePatternSpecificity,
|
|
106
107
|
} from '@farm.js/core/internal/production-runtime';
|
|
108
|
+
import {
|
|
109
|
+
appMiddlewareMayHandlePath,
|
|
110
|
+
configMiddlewareMayHandlePath,
|
|
111
|
+
materializeSSGRoutePath,
|
|
112
|
+
mergeMetadata,
|
|
113
|
+
mergeModuleViewport,
|
|
114
|
+
mergeRouteRenderingDirectiveConfig,
|
|
115
|
+
renderMetadataHead,
|
|
116
|
+
resolveMetadataTitle,
|
|
117
|
+
} from '@farm.js/core/internal/production-runtime';
|
|
107
118
|
|
|
108
119
|
import {
|
|
109
120
|
FARM_MARKDOWN_CONTENT_TYPE,
|
|
@@ -113,6 +124,30 @@ import {
|
|
|
113
124
|
farmRequestWantsMarkdown,
|
|
114
125
|
} from '@farm.js/core/markdown';
|
|
115
126
|
|
|
127
|
+
${ctx.images && ctx.images.runtime !== "none"
|
|
128
|
+
? `import { createCloudflareImageTransformer, createFarmImageHandler } from '@farm.js/core/image/server';
|
|
129
|
+
${ctx.images.runtime === "node"
|
|
130
|
+
? "import { createNodeImageFetcher, createNodeImageUrlValidator, createSharpImageTransformer } from '@farm.js/core/image/sharp';"
|
|
131
|
+
: ""}
|
|
132
|
+
const farmImageConfig = ${JSON.stringify(ctx.images.config)};
|
|
133
|
+
const farmImageHandler = createFarmImageHandler(farmImageConfig, ${ctx.images.runtime === "cloudflare"
|
|
134
|
+
? `{
|
|
135
|
+
transform: createCloudflareImageTransformer(),
|
|
136
|
+
onError(error) { console.error('[Farm Image]', error); },
|
|
137
|
+
}`
|
|
138
|
+
: `{
|
|
139
|
+
transform: createSharpImageTransformer(),
|
|
140
|
+
fetchRemote: createNodeImageFetcher(farmImageConfig),
|
|
141
|
+
validateRemoteUrl: createNodeImageUrlValidator(farmImageConfig),
|
|
142
|
+
onError(error) { console.error('[Farm Image]', error); },
|
|
143
|
+
}`});`
|
|
144
|
+
: "const farmImageHandler = null;"}
|
|
145
|
+
const farmImagePath = ${JSON.stringify(ctx.images?.path ?? "/_farm/image")};
|
|
146
|
+
${ctx.images
|
|
147
|
+
? `// <Image> reads this when @farm.js/core/image is not bundled (dev, or an external dependency),
|
|
148
|
+
// where the __FARM_IMAGE_CONFIG__ define never reaches it. The SSR environment shares the process.
|
|
149
|
+
globalThis.__FARM_IMAGE_CONFIG__ = ${JSON.stringify(ctx.images.public)};`
|
|
150
|
+
: ""}
|
|
116
151
|
const farmDeploymentId = ${JSON.stringify(ctx.deploymentId)};
|
|
117
152
|
const farmApiBasePath = ${JSON.stringify(ctx.apiBasePath ?? "/api")};
|
|
118
153
|
const farmMarkdownConfig = ${JSON.stringify(ctx.markdown ?? { enabled: false, expose: [], cache: false, includeMetadata: true })};
|
|
@@ -284,6 +319,14 @@ const pages = mergeRouteModules([${routeRoots
|
|
|
284
319
|
const layouts = mergeRouteModules([${routeRoots
|
|
285
320
|
.map((root, index) => `{ base: ${JSON.stringify(root.base)}, modules: layouts${index} }`)
|
|
286
321
|
.join(", ")}]);
|
|
322
|
+
// Root layouts that render <html> themselves own the document, as in Next.js.
|
|
323
|
+
const farmDocumentLayoutKeys = new Set(${JSON.stringify(ctx.documentLayouts ?? [])});
|
|
324
|
+
const farmDocumentLayoutModules = new Set(
|
|
325
|
+
Object.entries(layouts)
|
|
326
|
+
.filter(([key]) => farmDocumentLayoutKeys.has(key))
|
|
327
|
+
.map(([, module]) => module),
|
|
328
|
+
);
|
|
329
|
+
|
|
287
330
|
const loadings = mergeRouteModules([${routeRoots
|
|
288
331
|
.map((root, index) => `{ base: ${JSON.stringify(root.base)}, modules: loadings${index} }`)
|
|
289
332
|
.join(", ")}]);
|
|
@@ -601,7 +644,7 @@ function matchRoute(pathname) {
|
|
|
601
644
|
Page: module.default,
|
|
602
645
|
pattern: filePath,
|
|
603
646
|
params: match.params,
|
|
604
|
-
|
|
647
|
+
module,
|
|
605
648
|
};
|
|
606
649
|
}
|
|
607
650
|
}
|
|
@@ -610,13 +653,77 @@ function matchRoute(pathname) {
|
|
|
610
653
|
return null;
|
|
611
654
|
}
|
|
612
655
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
656
|
+
// Each page's parsed rendering directive and whether its source reads request state, baked by
|
|
657
|
+
// the build because module exports cannot tell.
|
|
658
|
+
const farmPageRenderingDirectives = ${JSON.stringify(ctx.pageRenderingDirectives ?? {})};
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* The URL paths the build prerenders, by core's SSG rules: a page asks to be static
|
|
662
|
+
* (dynamic = "force-static", generateStaticParams, "use ssg"), does not read request
|
|
663
|
+
* state, and does not revalidate. A prerendered page is a static file the server never sees, so a
|
|
664
|
+
* path any middleware may handle stays server-rendered.
|
|
665
|
+
*/
|
|
666
|
+
async function collectFarmStaticPages() {
|
|
667
|
+
${ctx.i18n?.enabled
|
|
668
|
+
? `console.info('[Farm.js] Prerendering is off: i18n resolves the locale per request.');
|
|
669
|
+
return [];`
|
|
670
|
+
: ""}
|
|
671
|
+
const middlewareRoutes = Object.keys(middlewares)
|
|
672
|
+
.map((filePath) => ({ path: middlewarePathToRoute(filePath) }))
|
|
673
|
+
.filter((route) => route.path !== null);
|
|
674
|
+
const paths = new Set();
|
|
675
|
+
for (const { filePath, module, segments } of pageRoutes) {
|
|
676
|
+
const rendering = mergeRouteRenderingDirectiveConfig(farmPageRenderingDirectives[filePath], module);
|
|
677
|
+
if (!rendering.ssg || rendering.revalidate !== undefined) continue;
|
|
678
|
+
const pattern = '/' + segments
|
|
679
|
+
.map((part) => part.isCatchAll
|
|
680
|
+
? (part.isOptional ? '[[...' + part.segment + ']]' : '[...' + part.segment + ']')
|
|
681
|
+
: part.isDynamic ? '[' + part.segment + ']' : part.segment)
|
|
682
|
+
.join('/');
|
|
683
|
+
let pagePaths;
|
|
684
|
+
try {
|
|
685
|
+
if (!segments.some((part) => part.isDynamic)) {
|
|
686
|
+
pagePaths = [pattern];
|
|
687
|
+
} else {
|
|
688
|
+
const getStaticPaths = module.getStaticPaths || module.generateStaticParams;
|
|
689
|
+
if (typeof getStaticPaths !== 'function') {
|
|
690
|
+
throw new Error('a static route with dynamic segments needs generateStaticParams()');
|
|
691
|
+
}
|
|
692
|
+
pagePaths = (await getStaticPaths()).map((params) => materializeSSGRoutePath(pattern, params));
|
|
693
|
+
}
|
|
694
|
+
} catch (error) {
|
|
695
|
+
console.error('[Farm.js] Rendering ' + filePath + ' on each request: could not list its static paths.', error);
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
for (const pagePath of pagePaths) {
|
|
699
|
+
if (
|
|
700
|
+
appMiddlewareMayHandlePath(middlewareRoutes, pagePath) ||
|
|
701
|
+
configMiddlewareMayHandlePath(farmConfigMiddleware, pagePath)
|
|
702
|
+
) {
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
paths.add(pagePath);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return [...paths];
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// The route's metadata as core's server resolves it: layouts root to leaf, then the page, each
|
|
712
|
+
// module's \`metadata\`, \`generateMetadata()\` and viewport exports merged in order.
|
|
713
|
+
async function resolveFarmRouteMetadata(layoutModules, pageModule, pageProps) {
|
|
714
|
+
let metadata = {};
|
|
715
|
+
for (const layoutModule of layoutModules) {
|
|
716
|
+
metadata = mergeMetadata(metadata, layoutModule.metadata);
|
|
717
|
+
if (typeof layoutModule.generateMetadata === 'function') {
|
|
718
|
+
metadata = mergeMetadata(metadata, await layoutModule.generateMetadata({ params: pageProps.params }));
|
|
719
|
+
}
|
|
720
|
+
metadata = await mergeModuleViewport(metadata, layoutModule, { params: pageProps.params });
|
|
721
|
+
}
|
|
722
|
+
metadata = mergeMetadata(metadata, pageModule?.metadata);
|
|
723
|
+
if (typeof pageModule?.generateMetadata === 'function') {
|
|
724
|
+
metadata = mergeMetadata(metadata, await pageModule.generateMetadata(pageProps));
|
|
618
725
|
}
|
|
619
|
-
return metadata;
|
|
726
|
+
return mergeModuleViewport(metadata, pageModule ?? {}, pageProps);
|
|
620
727
|
}
|
|
621
728
|
|
|
622
729
|
/**
|
|
@@ -667,8 +774,19 @@ function getMatchingBoundary(pageFilePath, modules, kind) {
|
|
|
667
774
|
/**
|
|
668
775
|
* Main request handler - entry point for both dev and production (Nitro).
|
|
669
776
|
* Exported as { fetch: handler } for the RSC/Nitro contract (see vite-plugin-rsc-deploy-example).
|
|
777
|
+
*
|
|
778
|
+
* Middleware that let a request through may have been a guard: an IP allowlist, an API key
|
|
779
|
+
* header, a VPN header. A CDN keys its copy by URL and never runs the guard on a hit, so
|
|
780
|
+
* whatever such a request answers stays out of shared caches, as in core's server. Only
|
|
781
|
+
* middleware declaring cache: "public" leaves the policy alone.
|
|
670
782
|
*/
|
|
671
783
|
async function handleFarmRequest(request, context) {
|
|
784
|
+
const farmCacheGuard = { guarded: false };
|
|
785
|
+
const response = await resolveFarmRequest(farmCacheGuard, request, context);
|
|
786
|
+
return farmCacheGuard.guarded ? _withFarmGuardedResponseCache(response) : response;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
async function resolveFarmRequest(farmCacheGuard, request, context) {
|
|
672
790
|
let url = new URL(request.url);
|
|
673
791
|
let matchedPage = null;
|
|
674
792
|
let errorData = new Map();
|
|
@@ -708,6 +826,7 @@ async function handleFarmRequest(request, context) {
|
|
|
708
826
|
// Execute middleware first
|
|
709
827
|
const middlewareResult = await executeMiddleware(request, context);
|
|
710
828
|
${generateRscMiddlewareResultHandling()}
|
|
829
|
+
if (middlewareResult.guarded) farmCacheGuard.guarded = true;
|
|
711
830
|
|
|
712
831
|
request = middlewareResult.request;
|
|
713
832
|
url = new URL(request.url);
|
|
@@ -730,6 +849,11 @@ async function handleFarmRequest(request, context) {
|
|
|
730
849
|
_runWithMiddlewareContext(middlewareContext, async () => {
|
|
731
850
|
const glob = '';
|
|
732
851
|
|
|
852
|
+
if (farmImageHandler && url.pathname === farmImagePath) {
|
|
853
|
+
const imageResponse = await farmImageHandler(request);
|
|
854
|
+
if (imageResponse) return imageResponse;
|
|
855
|
+
}
|
|
856
|
+
|
|
733
857
|
const apiResponse = await handleAPIRequest(request.clone());
|
|
734
858
|
if (apiResponse) {
|
|
735
859
|
return applyProductionMiddlewareHeaders(apiResponse, middlewareHeaders);
|
|
@@ -908,16 +1032,12 @@ async function handleFarmRequest(request, context) {
|
|
|
908
1032
|
return new Response('Not Found', { status: 404 });
|
|
909
1033
|
}
|
|
910
1034
|
|
|
911
|
-
const { Page, pattern, params,
|
|
1035
|
+
const { Page, pattern, params, module: pageModule } = matched;
|
|
912
1036
|
${isolateRouteModules
|
|
913
1037
|
? `const routeLoadError = findFarmRouteLoadError(matched);
|
|
914
1038
|
if (routeLoadError) throw routeLoadError;
|
|
915
1039
|
`
|
|
916
1040
|
: ""}const LayoutModules = getLayoutModules(pattern);
|
|
917
|
-
const metadata = mergeDocumentMetadata(
|
|
918
|
-
...LayoutModules.map((layoutModule) => layoutModule.metadata),
|
|
919
|
-
pageMetadata,
|
|
920
|
-
);
|
|
921
1041
|
const configuredRoutesDir = ${ctx.routesDir === undefined ? "undefined" : JSON.stringify(ctx.routesDir)};
|
|
922
1042
|
const routesDir = configuredRoutesDir === undefined ? 'app' : configuredRoutesDir.trim();
|
|
923
1043
|
const routesPath = routesDir ? '/' + routesDir : '';
|
|
@@ -930,6 +1050,14 @@ async function handleFarmRequest(request, context) {
|
|
|
930
1050
|
|
|
931
1051
|
// Page props passed to components (includes middleware shared data)
|
|
932
1052
|
const pageProps = { params, searchParams, middlewareData };
|
|
1053
|
+
const metadata = await resolveFarmRouteMetadata(LayoutModules, pageModule, pageProps);
|
|
1054
|
+
const renderedHead = renderMetadataHead(metadata, { pathname: url.pathname });
|
|
1055
|
+
// Injected into <head> by the SSR entry; React renders only the charset.
|
|
1056
|
+
const metadataHead =
|
|
1057
|
+
(renderedHead.hasExplicitTitle ? '<title>' + renderedHead.title + '</title>' : '') +
|
|
1058
|
+
renderedHead.viewport +
|
|
1059
|
+
renderedHead.tags;
|
|
1060
|
+
const metadataTitle = resolveMetadataTitle(metadata.title);
|
|
933
1061
|
|
|
934
1062
|
debug('Rendering page:', pattern, 'with props:', pageProps);
|
|
935
1063
|
|
|
@@ -975,26 +1103,36 @@ async function handleFarmRequest(request, context) {
|
|
|
975
1103
|
}
|
|
976
1104
|
}
|
|
977
1105
|
|
|
978
|
-
//
|
|
979
|
-
|
|
980
|
-
|
|
1106
|
+
// A root layout that renders <html> owns the document, as in Next.js: the head elements below
|
|
1107
|
+
// are hoisted into its <head> by React, and the browser hydrates the whole document.
|
|
1108
|
+
const ownsDocument =
|
|
1109
|
+
LayoutModules.length > 0 && farmDocumentLayoutModules.has(LayoutModules[0]);
|
|
1110
|
+
// Otherwise a single wrapper, so #root has exactly one child (avoids a duplicate block in the DOM).
|
|
1111
|
+
const rootInner = ownsDocument
|
|
1112
|
+
? h(
|
|
1113
|
+
React.Fragment,
|
|
1114
|
+
null,
|
|
1115
|
+
h('meta', { charSet: 'utf-8' }),
|
|
1116
|
+
layoutContent,
|
|
1117
|
+
)
|
|
1118
|
+
: h('div', { 'data-farm-root': 'true' }, layoutContent);
|
|
1119
|
+
// Build the full page. root = full document (for SSR). rootContent = what the browser hydrates.
|
|
981
1120
|
const payload = {
|
|
982
|
-
|
|
1121
|
+
ownsDocument,
|
|
1122
|
+
root: ownsDocument ? rootInner : h('html', null,
|
|
983
1123
|
h('head', null,
|
|
984
1124
|
h('meta', { charSet: 'utf-8' }),
|
|
985
|
-
h('
|
|
986
|
-
h('link', { rel: 'icon', href: 'data:,' }),
|
|
987
|
-
metadata?.title ? h('title', null, metadata.title) : null,
|
|
988
|
-
metadata?.description ? h('meta', { name: 'description', content: metadata.description }) : null
|
|
1125
|
+
renderedHead.hasFavicon ? null : h('link', { rel: 'icon', href: 'data:,' }),
|
|
989
1126
|
),
|
|
990
1127
|
h('body', null,
|
|
991
1128
|
h('div', { id: 'root' }, rootInner)
|
|
992
1129
|
)
|
|
993
1130
|
),
|
|
994
1131
|
rootContent: rootInner,
|
|
1132
|
+
metadataHead,
|
|
995
1133
|
metadata: {
|
|
996
|
-
title:
|
|
997
|
-
description: typeof metadata
|
|
1134
|
+
title: metadataTitle,
|
|
1135
|
+
description: typeof metadata.description === 'string' ? metadata.description : undefined,
|
|
998
1136
|
},
|
|
999
1137
|
`;
|
|
1000
1138
|
// Include action results in payload if actions are enabled
|
|
@@ -1052,8 +1190,8 @@ async function handleFarmRequest(request, context) {
|
|
|
1052
1190
|
h('meta', { charSet: 'utf-8' }),
|
|
1053
1191
|
h('meta', { name: 'viewport', content: 'width=device-width, initial-scale=1' }),
|
|
1054
1192
|
h('link', { rel: 'icon', href: 'data:,' }),
|
|
1055
|
-
|
|
1056
|
-
metadata
|
|
1193
|
+
metadataTitle ? h('title', null, metadataTitle) : null,
|
|
1194
|
+
typeof metadata.description === 'string' ? h('meta', { name: 'description', content: metadata.description }) : null,
|
|
1057
1195
|
h('link', { rel: 'stylesheet', href: globalsCssPath, as: 'style', precedence: 'default' }),
|
|
1058
1196
|
h('script', { type: 'module', src: '/@vite/client' })
|
|
1059
1197
|
),
|
|
@@ -1282,7 +1420,60 @@ async function handleFarmPageOrMarkdown(request, context) {
|
|
|
1282
1420
|
});
|
|
1283
1421
|
}
|
|
1284
1422
|
|
|
1423
|
+
// Client navigation addresses a page's RSC payload as '<page>.rsc' ('<dir>/index.rsc' for a
|
|
1424
|
+
// trailing slash), so a prerendered page can be a static HTML file next to a static payload file.
|
|
1425
|
+
// 'Accept: text/x-component' on the page URL keeps working.
|
|
1426
|
+
function farmPayloadPath(pathname) {
|
|
1427
|
+
return pathname.endsWith('/') ? pathname + 'index.rsc' : pathname + '.rsc';
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function toFarmPayloadRequest(request) {
|
|
1431
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') return request;
|
|
1432
|
+
const url = new URL(request.url);
|
|
1433
|
+
if (!url.pathname.endsWith('.rsc')) return request;
|
|
1434
|
+
if (isFarmAPIPathname(url.pathname, farmApiBasePath) || isFarmAPIPathname(url.pathname)) return request;
|
|
1435
|
+
const page = url.pathname.slice(0, -'.rsc'.length);
|
|
1436
|
+
url.pathname = page.endsWith('/index') ? page.slice(0, -'index'.length) : page;
|
|
1437
|
+
const headers = new Headers(request.headers);
|
|
1438
|
+
headers.set('accept', 'text/x-component');
|
|
1439
|
+
return new Request(url, { method: request.method, headers, signal: request.signal });
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
// The build's prerender pass (Nitro) runs this server with FARM_RSC_PRERENDER set. It seeds one
|
|
1443
|
+
// route that lists the static pages, and each prerendered page queues its payload, both through
|
|
1444
|
+
// Nitro's x-nitro-prerender response header. Production servers never answer either.
|
|
1445
|
+
const FARM_PRERENDER_ROUTES_PATH = '/__farm/rsc-prerender-routes';
|
|
1446
|
+
function isFarmPrerenderRequest(request) {
|
|
1447
|
+
return globalThis.process?.env?.FARM_RSC_PRERENDER === '1' && request.headers.has('x-nitro-prerender');
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1285
1450
|
async function handler(request, context) {
|
|
1451
|
+
const prerendering = isFarmPrerenderRequest(request);
|
|
1452
|
+
if (prerendering && new URL(request.url).pathname === FARM_PRERENDER_ROUTES_PATH) {
|
|
1453
|
+
const pages = await collectFarmStaticPages();
|
|
1454
|
+
return new Response('<!doctype html>', {
|
|
1455
|
+
headers: {
|
|
1456
|
+
'content-type': 'text/html; charset=utf-8',
|
|
1457
|
+
'x-nitro-prerender': pages.map(encodeURIComponent).join(','),
|
|
1458
|
+
},
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
const pageRequest = toFarmPayloadRequest(request);
|
|
1462
|
+
const response = await handleFarmRequestWithRuntime(pageRequest, context);
|
|
1463
|
+
if (
|
|
1464
|
+
prerendering &&
|
|
1465
|
+
pageRequest === request &&
|
|
1466
|
+
response.status === 200 &&
|
|
1467
|
+
(response.headers.get('content-type') || '').includes('text/html')
|
|
1468
|
+
) {
|
|
1469
|
+
const headers = new Headers(response.headers);
|
|
1470
|
+
headers.set('x-nitro-prerender', encodeURIComponent(farmPayloadPath(new URL(request.url).pathname)));
|
|
1471
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
1472
|
+
}
|
|
1473
|
+
return response;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
async function handleFarmRequestWithRuntime(request, context) {
|
|
1286
1477
|
return _runWithAPIRequestRuntime({
|
|
1287
1478
|
basePath: farmApiBasePath,
|
|
1288
1479
|
dispatch: async (localRequest) =>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/ssr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/ssr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAiN1D"}
|
package/dist/rsc/entries/ssr.js
CHANGED
|
@@ -117,6 +117,8 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
117
117
|
// calls client references on the server (for example, a "use client" Counter).
|
|
118
118
|
const payload = await createFromReadableStream(s1);
|
|
119
119
|
const rootElement = payload.root;
|
|
120
|
+
// The route's resolved metadata as head tags (core's renderMetadataHead), then the stylesheet.
|
|
121
|
+
const headTags = (typeof payload.metadataHead === 'string' ? payload.metadataHead : '') + cssLinkTag;
|
|
120
122
|
|
|
121
123
|
function Root() {
|
|
122
124
|
return rootElement;
|
|
@@ -171,7 +173,7 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
171
173
|
passThrough.on('error', (e) => controller.error(e));
|
|
172
174
|
}
|
|
173
175
|
});
|
|
174
|
-
let out = webStream.pipeThrough(injectIntoHeadStream(
|
|
176
|
+
let out = webStream.pipeThrough(injectIntoHeadStream(headTags));
|
|
175
177
|
out = out.pipeThrough(injectRSCPayload(s2));
|
|
176
178
|
out = out.pipeThrough(streamingClientScriptInjector);
|
|
177
179
|
return out;
|
|
@@ -181,8 +183,8 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
181
183
|
debug('Rendering to HTML stream (then buffering)');
|
|
182
184
|
const fullHtmlRaw = await pipeableStreamToString(passThrough);
|
|
183
185
|
let fullHtml = fullHtmlRaw;
|
|
184
|
-
if (
|
|
185
|
-
fullHtml = fullHtml.replace("</head>",
|
|
186
|
+
if (headTags && fullHtml.includes("</head>")) {
|
|
187
|
+
fullHtml = fullHtml.replace("</head>", () => headTags + "</head>");
|
|
186
188
|
}
|
|
187
189
|
${ctx.actionsEnabled
|
|
188
190
|
? `// Ensure __viteRscCallServer is set before any module runs (fixes "is not a function" when form submits)
|
package/dist/rsc/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type { FarmAPIConfig } from "@farm.js/core/api";
|
|
|
28
28
|
import type { FarmMiddlewareConfig } from "@farm.js/core/middleware";
|
|
29
29
|
import type { FarmServerConfig } from "@farm.js/core/internal/production-runtime";
|
|
30
30
|
import type { FarmLayerEntry, ResolvedFarmLayer } from "@farm.js/core/server";
|
|
31
|
+
import { resolveFarmImageConfig } from "@farm.js/core/vite";
|
|
31
32
|
import { type FarmMarkdownUserConfig } from "@farm.js/core/markdown";
|
|
32
33
|
import type { FarmLlmsTxtUserConfig } from "@farm.js/core/internal/production-runtime";
|
|
33
34
|
import type { FarmMCPUserConfig } from "@farm.js/core/server";
|
|
@@ -36,6 +37,7 @@ export { buildRscNitro, waitForRscManifest, waitForRscOutputs } from "./nitro-bu
|
|
|
36
37
|
export type { BuildRscNitroOptions } from "./nitro-build.js";
|
|
37
38
|
export { default as nitro } from "./vite-plugin-nitro.js";
|
|
38
39
|
export type { NitroPluginOptions } from "./vite-plugin-nitro.js";
|
|
40
|
+
type FarmImageConfig = NonNullable<Parameters<typeof resolveFarmImageConfig>[0]>;
|
|
39
41
|
export interface FarmRscConfig {
|
|
40
42
|
srcDir?: string;
|
|
41
43
|
extends?: readonly FarmLayerEntry[];
|
|
@@ -45,6 +47,8 @@ export interface FarmRscConfig {
|
|
|
45
47
|
api?: FarmAPIConfig;
|
|
46
48
|
server?: FarmServerConfig;
|
|
47
49
|
middleware?: FarmMiddlewareConfig;
|
|
50
|
+
/** Same options as core's `images`: `<Image>` URLs and the optimizer at `images.path`. */
|
|
51
|
+
images?: FarmImageConfig;
|
|
48
52
|
port?: number;
|
|
49
53
|
experimental?: {
|
|
50
54
|
/**
|
package/dist/rsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rsc/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAA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AG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,gHAAgH;IAChH,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB;;;;OAIG;IACH,EAAE,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACtC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAA;KAAE,CAAC;IACtD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,aAAkB,GAAG,UAAU,CAmEnE;AAibD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAsoC5E"}
|
package/dist/rsc/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import { loadFarmDevModule, FarmDevEnvironmentError } from "@farm.js/core/plugin
|
|
|
25
25
|
import { parseAst, version as viteVersion, } from "vite";
|
|
26
26
|
import { init as initModuleLexer, parse as parseModuleImports } from "es-module-lexer";
|
|
27
27
|
import { farmEnvironmentFunctionsPlugin } from "@farm.js/core/environment/vite";
|
|
28
|
-
import { generateClientCachePersistenceCode, resolveFarmClientCacheAdapterEntry, } from "@farm.js/core/vite";
|
|
28
|
+
import { farmFontImportsPlugin, farmImageImportsPlugin, generateClientCachePersistenceCode, getPublicFarmImageConfig, resolveFarmClientCacheAdapterEntry, resolveFarmImageConfig, resolveFarmImageProviderForRuntime, resolveFarmImageServerRuntime, readRouteRenderingDirectiveFromFile, } from "@farm.js/core/vite";
|
|
29
29
|
import { generateRscEntry } from "./entries/rsc.js";
|
|
30
30
|
import { resolveMarkdownConfig } from "@farm.js/core/markdown";
|
|
31
31
|
import { generateSsrEntry } from "./entries/ssr.js";
|
|
@@ -35,6 +35,8 @@ import { transformFarmRouteActionClients } from "./route-action-transform.js";
|
|
|
35
35
|
import { createFarmServerFnBoundaryModule, isFarmServerFnBoundaryId, transformFarmServerFns, } from "./server-fn-transform.js";
|
|
36
36
|
import { transformAutomaticOptimizedBoundaries } from "./automatic-optimized-boundary.js";
|
|
37
37
|
import { resolveRscBuildOutputPath } from "./build-paths.js";
|
|
38
|
+
import { rscPrivateClientSourcemaps } from "./client-sourcemaps.js";
|
|
39
|
+
import { findDocumentLayouts, findRouteFiles } from "./document-layouts.js";
|
|
38
40
|
import { assertRscPackageCompatibility } from "./compatibility.js";
|
|
39
41
|
import { sendRscDevelopmentResponse } from "./dev-response.js";
|
|
40
42
|
import { loadRscConfigPropertyModule, loadRscMiddlewareConfigModule, } from "./middleware-config-module.js";
|
|
@@ -59,6 +61,7 @@ const { getResolvedEnv } = require_("@farm.js/core/env");
|
|
|
59
61
|
export { buildRscNitro, waitForRscManifest, waitForRscOutputs } from "./nitro-build.js";
|
|
60
62
|
import { registerRscNitroRuntimePackage } from "./nitro-build.js";
|
|
61
63
|
export { default as nitro } from "./vite-plugin-nitro.js";
|
|
64
|
+
const PAGE_FILE = /^page\.(tsx|jsx|ts|js)$/;
|
|
62
65
|
/**
|
|
63
66
|
* Define a Farm.js RSC configuration
|
|
64
67
|
* This is the recommended way to configure your RSC app
|
|
@@ -86,6 +89,7 @@ export function defineConfig(config = {}) {
|
|
|
86
89
|
agent: config.agent,
|
|
87
90
|
mcp: config.mcp,
|
|
88
91
|
middleware: config.middleware,
|
|
92
|
+
images: config.images,
|
|
89
93
|
// Vite server configuration
|
|
90
94
|
server: {
|
|
91
95
|
...config.server,
|
|
@@ -109,6 +113,11 @@ export function defineConfig(config = {}) {
|
|
|
109
113
|
// The dev API server mounts the MCP endpoint, as core's does.
|
|
110
114
|
...(config.mcp ? { plugins: ({ root }) => resolveRscMCPPlugins(config.mcp, root) } : {}),
|
|
111
115
|
}),
|
|
116
|
+
// localFont() from @farm.js/core/font, with its CSS carried by the bundler: this pipeline
|
|
117
|
+
// has no step that merges font CSS into a global stylesheet.
|
|
118
|
+
farmFontImportsPlugin({ basePath: config.basePath ?? "/", importCss: true }),
|
|
119
|
+
// Static image imports as { src, width, height }, which <Image> sizes from.
|
|
120
|
+
farmImageImportsPlugin(),
|
|
112
121
|
farmRsc({
|
|
113
122
|
debug,
|
|
114
123
|
encryptActions: config.encryptActions,
|
|
@@ -599,6 +608,7 @@ export default function farmRsc(options = {}) {
|
|
|
599
608
|
};
|
|
600
609
|
return [
|
|
601
610
|
farmEnvironmentFunctionsPlugin(),
|
|
611
|
+
rscPrivateClientSourcemaps(),
|
|
602
612
|
{
|
|
603
613
|
name: "@farm.js/plugin/rsc:middleware-config",
|
|
604
614
|
enforce: "pre",
|
|
@@ -772,8 +782,49 @@ export default function farmRsc(options = {}) {
|
|
|
772
782
|
: `/${projectSourceDir}${routeSuffix}`;
|
|
773
783
|
return { name: source.name, base, glob: base };
|
|
774
784
|
});
|
|
785
|
+
// Each page's rendering directive and whether its source reads request state, which the
|
|
786
|
+
// runtime cannot see from module exports: the same baked input core's server merges.
|
|
787
|
+
// Later roots override earlier ones, as the entry's merged page map does.
|
|
788
|
+
const pageRenderingDirectives = {};
|
|
789
|
+
for (const source of getFarmSourceRoots(c)) {
|
|
790
|
+
const routesRoot = path.resolve(root, source.srcDir, configuredRoutesDir);
|
|
791
|
+
for (const { key, file } of await findRouteFiles(routesRoot, (name) => PAGE_FILE.test(name))) {
|
|
792
|
+
const directive = readRouteRenderingDirectiveFromFile(file);
|
|
793
|
+
if (directive)
|
|
794
|
+
pageRenderingDirectives[key] = directive;
|
|
795
|
+
else
|
|
796
|
+
delete pageRenderingDirectives[key];
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
// Root layouts that render <html> own the document (Next.js's root layout contract).
|
|
800
|
+
const documentLayouts = [
|
|
801
|
+
...new Set((await Promise.all(getFarmSourceRoots(c).map((source) => findDocumentLayouts(path.resolve(root, source.srcDir, configuredRoutesDir))))).flat()),
|
|
802
|
+
];
|
|
803
|
+
// The same images contract as core: without Sharp, "auto" keeps original URLs
|
|
804
|
+
// (provider "none") instead of pointing <Image> at an optimizer that cannot run.
|
|
805
|
+
const nitroPreset = process.env.NITRO_PRESET || "vercel";
|
|
806
|
+
const imageConfig = resolveFarmImageConfig(resolveFarmImageProviderForRuntime(c.images, {
|
|
807
|
+
root,
|
|
808
|
+
preset: nitroPreset,
|
|
809
|
+
dev: env.command === "serve",
|
|
810
|
+
}));
|
|
811
|
+
const publicImageConfig = getPublicFarmImageConfig(imageConfig);
|
|
812
|
+
// Development always optimizes with Sharp, as core's dev server does.
|
|
813
|
+
const imageRuntime = env.command === "serve"
|
|
814
|
+
? imageConfig.provider === "none"
|
|
815
|
+
? "none"
|
|
816
|
+
: "node"
|
|
817
|
+
: resolveFarmImageServerRuntime(imageConfig, nitroPreset);
|
|
775
818
|
// Build context for entry generators
|
|
776
819
|
entryContext = {
|
|
820
|
+
documentLayouts,
|
|
821
|
+
pageRenderingDirectives,
|
|
822
|
+
images: {
|
|
823
|
+
config: imageConfig,
|
|
824
|
+
public: publicImageConfig,
|
|
825
|
+
path: imageConfig.path,
|
|
826
|
+
runtime: imageRuntime,
|
|
827
|
+
},
|
|
777
828
|
srcDir,
|
|
778
829
|
outDir,
|
|
779
830
|
basePath: c.basePath ?? "/",
|
|
@@ -842,6 +893,7 @@ export default function farmRsc(options = {}) {
|
|
|
842
893
|
builder: { sharedConfigBuild: true },
|
|
843
894
|
define: {
|
|
844
895
|
__FARM_API_BASE_URL__: JSON.stringify(api.baseURL),
|
|
896
|
+
__FARM_IMAGE_CONFIG__: JSON.stringify(entryContext.images?.public),
|
|
845
897
|
},
|
|
846
898
|
ssr: {
|
|
847
899
|
external: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nitro-build.d.ts","sourceRoot":"","sources":["../../src/rsc/nitro-build.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"nitro-build.d.ts","sourceRoot":"","sources":["../../src/rsc/nitro-build.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6BH;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,IAAI,CAKN;AAcD,gBAAgB;AAChB,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAqCrF;AA4ED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACxD,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACxD,OAAO,CAAC,IAAI,CAAC,CAgCf;AA8FD,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA+MF,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkIhF"}
|
package/dist/rsc/nitro-build.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
-
import { writeFileSync, readFileSync, mkdirSync, copyFileSync, existsSync, readdirSync, statSync, } from "fs";
|
|
8
|
+
import { writeFileSync, readFileSync, mkdirSync, copyFileSync, existsSync, readdirSync, rmSync, statSync, } from "fs";
|
|
9
9
|
import { FARM_NODE_ENV_MODULE_FILE, FARM_NODE_ENV_MODULE_SOURCE, } from "@farm.js/core/internal/production-node-env";
|
|
10
10
|
import { resolveRscBuildOutputPath } from "./build-paths.js";
|
|
11
11
|
const MANIFEST_FILENAME = "__vite_rsc_assets_manifest.js";
|
|
@@ -296,9 +296,189 @@ export default defineEventHandler(async (event) => {
|
|
|
296
296
|
writeFileSync(entryPath, code, "utf-8");
|
|
297
297
|
return entryPath;
|
|
298
298
|
}
|
|
299
|
+
function listModuleFiles(dir) {
|
|
300
|
+
if (!existsSync(dir))
|
|
301
|
+
return [];
|
|
302
|
+
const files = [];
|
|
303
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
304
|
+
const full = path.join(dir, entry.name);
|
|
305
|
+
if (entry.isDirectory())
|
|
306
|
+
files.push(...listModuleFiles(full));
|
|
307
|
+
else if (/\.(?:m|c)?js$/.test(entry.name))
|
|
308
|
+
files.push(full);
|
|
309
|
+
}
|
|
310
|
+
return files;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Copy the packages the RSC and SSR bundles load into the server output. Nitro traces only its own
|
|
314
|
+
* bundle, and these are copied in afterwards; their code-split chunks and dynamic imports (such as
|
|
315
|
+
* shiki's WebAssembly engine) reach package files the entry files alone do not. The RSC bundle
|
|
316
|
+
* resolves packages with the react-server condition, the SSR bundle without it.
|
|
317
|
+
*/
|
|
318
|
+
async function traceRscBundleDependencies(root, serverDir, rscDir, ssrDir) {
|
|
319
|
+
const { traceNodeModules } = await import("nf3");
|
|
320
|
+
const traces = [
|
|
321
|
+
[listModuleFiles(rscDir), ["react-server", "node", "import", "default"]],
|
|
322
|
+
[ssrDir ? listModuleFiles(ssrDir) : [], ["node", "import", "default"]],
|
|
323
|
+
];
|
|
324
|
+
for (const [files, conditions] of traces) {
|
|
325
|
+
if (files.length === 0)
|
|
326
|
+
continue;
|
|
327
|
+
await traceNodeModules(files, { rootDir: root, outDir: serverDir, conditions });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Give the SSR bundle the production client CSS href and bootstrap script, so its HTML has styles
|
|
332
|
+
* and hydrates. Runs on the Vite output before Nitro, so the prerender pass and the copies in the
|
|
333
|
+
* server output render the same document. Only placeholders are replaced, so it is idempotent.
|
|
334
|
+
*/
|
|
335
|
+
function patchRscServerBundles(rscDir, ssrDir, publicDir, assetsDir) {
|
|
336
|
+
// Patch SSR bundle: inject production client CSS href and bootstrap script so HTML has styles and hydration works
|
|
337
|
+
const ssrIndexPath = path.join(ssrDir, "index.js");
|
|
338
|
+
const manifestPath = path.join(rscDir, MANIFEST_FILENAME);
|
|
339
|
+
let bootstrapScriptContent = "";
|
|
340
|
+
let clientEntryHref = "";
|
|
341
|
+
const RSC_CALL_SERVER_PLACEHOLDER = "(function(){if(typeof globalThis.__viteRscCallServer!=='function'){globalThis.__viteRscCallServer=function(){return Promise.reject(new Error(\"Farm.js: server actions not ready\"));}}})();\n";
|
|
342
|
+
if (existsSync(manifestPath)) {
|
|
343
|
+
try {
|
|
344
|
+
const manifestContent = readFileSync(manifestPath, "utf-8");
|
|
345
|
+
const start = manifestContent.indexOf("{");
|
|
346
|
+
const end = manifestContent.lastIndexOf("}") + 1;
|
|
347
|
+
if (start >= 0 && end > start) {
|
|
348
|
+
const manifest = JSON.parse(manifestContent.slice(start, end));
|
|
349
|
+
bootstrapScriptContent = manifest.bootstrapScriptContent || "";
|
|
350
|
+
const importMatch = bootstrapScriptContent.match(/^import\s*\(\s*["']([^"']+)["']\s*\)\s*$/);
|
|
351
|
+
if (importMatch)
|
|
352
|
+
clientEntryHref = importMatch[1];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
// ignore
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const fullBootstrap = bootstrapScriptContent
|
|
360
|
+
? RSC_CALL_SERVER_PLACEHOLDER + bootstrapScriptContent
|
|
361
|
+
: "";
|
|
362
|
+
// Patch manifest so production SSR gets bootstrap with __viteRscCallServer placeholder (SSR reads assetsManifest.bootstrapScriptContent)
|
|
363
|
+
if (fullBootstrap && existsSync(manifestPath)) {
|
|
364
|
+
try {
|
|
365
|
+
let manifestCode = readFileSync(manifestPath, "utf-8");
|
|
366
|
+
const escaped = JSON.stringify(bootstrapScriptContent);
|
|
367
|
+
const escapedFull = JSON.stringify(fullBootstrap);
|
|
368
|
+
if (manifestCode.includes(escaped) && escaped !== escapedFull) {
|
|
369
|
+
manifestCode = manifestCode.replace(escaped, escapedFull);
|
|
370
|
+
writeFileSync(manifestPath, manifestCode, "utf-8");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
// ignore
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (existsSync(ssrIndexPath)) {
|
|
378
|
+
const assetsDirName = assetsDir ?? "assets";
|
|
379
|
+
const assetsRoot = path.join(publicDir, assetsDirName);
|
|
380
|
+
let clientCssHref = "";
|
|
381
|
+
if (existsSync(assetsRoot)) {
|
|
382
|
+
const files = readdirSync(assetsRoot);
|
|
383
|
+
const cssFile = files.find((f) => f.endsWith(".css"));
|
|
384
|
+
if (cssFile)
|
|
385
|
+
clientCssHref = `/${assetsDirName}/${cssFile}`;
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
let ssrCode = readFileSync(ssrIndexPath, "utf-8");
|
|
389
|
+
// Only the assignment: the bundle also compares against the placeholder, and a second
|
|
390
|
+
// run over an already patched bundle must leave that comparison intact.
|
|
391
|
+
ssrCode = ssrCode.replace(/(CLIENT_CSS_HREF\s*=\s*)"__FARM_CLIENT_CSS_HREF__"/, "$1" + JSON.stringify(clientCssHref));
|
|
392
|
+
if (clientEntryHref && ssrCode.includes("__FARM_CLIENT_ENTRY_HREF__")) {
|
|
393
|
+
ssrCode = ssrCode.replace(/(CLIENT_ENTRY_HREF\s*=\s*)"__FARM_CLIENT_ENTRY_HREF__"/, "$1" + JSON.stringify(clientEntryHref));
|
|
394
|
+
}
|
|
395
|
+
if (fullBootstrap && ssrCode.includes("__FARM_BOOTSTRAP_SCRIPT__")) {
|
|
396
|
+
ssrCode = ssrCode.replace(/=\s*["']__FARM_BOOTSTRAP_SCRIPT__["']/, "= " + JSON.stringify(fullBootstrap));
|
|
397
|
+
}
|
|
398
|
+
writeFileSync(ssrIndexPath, ssrCode, "utf-8");
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
// ignore
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/** The route the RSC entry answers, during the prerender pass only, with its static pages. */
|
|
406
|
+
const FARM_PRERENDER_ROUTES_PATH = "/__farm/rsc-prerender-routes";
|
|
407
|
+
/**
|
|
408
|
+
* Prerender the app's static pages and their RSC payloads into the public output with Nitro's
|
|
409
|
+
* prerenderer, which serves them before the server on every preset. The RSC entry lists the pages
|
|
410
|
+
* (it has the route modules and their generateStaticParams), through Nitro's x-nitro-prerender
|
|
411
|
+
* header on a seed route that is removed afterwards.
|
|
412
|
+
*/
|
|
413
|
+
async function prerenderRscPages(nitro, prerender, viteDistDir) {
|
|
414
|
+
nitro.options.prerender = {
|
|
415
|
+
...nitro.options.prerender,
|
|
416
|
+
routes: [FARM_PRERENDER_ROUTES_PATH],
|
|
417
|
+
crawlLinks: false,
|
|
418
|
+
// Failures are judged below: a seed that cannot run only skips prerendering.
|
|
419
|
+
failOnError: false,
|
|
420
|
+
};
|
|
421
|
+
// The prerender server is a separate Nitro build of the same renderer entry. Point its imports of
|
|
422
|
+
// the prebuilt bundles at the Vite output, as the server output's are pointed at their copies.
|
|
423
|
+
nitro.hooks.hook("prerender:init", (prerenderer) => {
|
|
424
|
+
prerenderer.hooks.hook("compiled", () => {
|
|
425
|
+
rewriteRscEntryImports(prerenderer.options.output.serverDir, viteDistDir);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
let seedError;
|
|
429
|
+
const failedPages = [];
|
|
430
|
+
nitro.hooks.hook("prerender:route", (route) => {
|
|
431
|
+
if (route.route !== FARM_PRERENDER_ROUTES_PATH) {
|
|
432
|
+
if (route.error)
|
|
433
|
+
failedPages.push(`${route.route} (${route.error.message})`);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
seedError = route.error;
|
|
437
|
+
removeSeedOutput(nitro, route.fileName);
|
|
438
|
+
});
|
|
439
|
+
const previous = process.env.FARM_RSC_PRERENDER;
|
|
440
|
+
process.env.FARM_RSC_PRERENDER = "1";
|
|
441
|
+
try {
|
|
442
|
+
await prerender(nitro);
|
|
443
|
+
}
|
|
444
|
+
finally {
|
|
445
|
+
if (previous === undefined)
|
|
446
|
+
delete process.env.FARM_RSC_PRERENDER;
|
|
447
|
+
else
|
|
448
|
+
process.env.FARM_RSC_PRERENDER = previous;
|
|
449
|
+
}
|
|
450
|
+
if (seedError) {
|
|
451
|
+
// The server could not start in place (for example, a runtime package only the server output
|
|
452
|
+
// carries). Every page still renders on request, so the build goes on without static files.
|
|
453
|
+
console.warn(`[FARM] Prerendering skipped: the server could not list its static pages (${seedError.message}). Pages render on each request.`);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (failedPages.length > 0) {
|
|
457
|
+
// A page that asks to be static and fails to render fails the build, as in Next.js.
|
|
458
|
+
throw new Error(`[FARM] Prerendering failed for:\n ${failedPages.join("\n ")}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/** Remove the seed route's file, and the directories it created, from the public output. */
|
|
462
|
+
function removeSeedOutput(nitro, fileName) {
|
|
463
|
+
const publicDir = path.resolve(nitro.options.output.publicDir);
|
|
464
|
+
const prerendered = nitro
|
|
465
|
+
._prerenderedRoutes;
|
|
466
|
+
const index = prerendered?.findIndex((entry) => entry.route === FARM_PRERENDER_ROUTES_PATH) ?? -1;
|
|
467
|
+
if (index >= 0)
|
|
468
|
+
prerendered.splice(index, 1);
|
|
469
|
+
if (!fileName)
|
|
470
|
+
return;
|
|
471
|
+
let target = path.join(publicDir, fileName);
|
|
472
|
+
rmSync(target, { force: true });
|
|
473
|
+
for (target = path.dirname(target); target.startsWith(publicDir + path.sep) &&
|
|
474
|
+
existsSync(target) &&
|
|
475
|
+
readdirSync(target).length === 0; target = path.dirname(target)) {
|
|
476
|
+
rmSync(target, { recursive: true });
|
|
477
|
+
}
|
|
478
|
+
}
|
|
299
479
|
export async function buildRscNitro(options) {
|
|
300
480
|
const { rendererPath, publicDir, ssrPath, assetsDir, root, outputDir = path.join(root, ".output"), preset = "vercel", } = options;
|
|
301
|
-
const { build, copyPublicAssets, createNitro, prepare } = await import("nitro/builder");
|
|
481
|
+
const { build, copyPublicAssets, createNitro, prepare, prerender } = await import("nitro/builder");
|
|
302
482
|
console.log(`[FARM] Building RSC server with Nitro (preset: ${preset})...`);
|
|
303
483
|
const buildDir = path.join(root, ".nitro");
|
|
304
484
|
const serverDir = path.join(outputDir, "server");
|
|
@@ -361,9 +541,13 @@ export async function buildRscNitro(options) {
|
|
|
361
541
|
compatibilityDate: "2024-12-01",
|
|
362
542
|
minify: true,
|
|
363
543
|
};
|
|
544
|
+
if (ssrPath) {
|
|
545
|
+
patchRscServerBundles(path.dirname(path.resolve(rendererPath)), path.dirname(path.resolve(ssrPath)), publicDir, assetsDir);
|
|
546
|
+
}
|
|
364
547
|
const nitro = await createNitro(config);
|
|
365
548
|
await prepare(nitro);
|
|
366
549
|
await copyPublicAssets(nitro);
|
|
550
|
+
await prerenderRscPages(nitro, prerender, path.dirname(path.dirname(path.resolve(rendererPath))));
|
|
367
551
|
await build(nitro);
|
|
368
552
|
await nitro.close();
|
|
369
553
|
copyRuntimePackages(serverDir, registeredRuntimePackages);
|
|
@@ -375,6 +559,7 @@ export async function buildRscNitro(options) {
|
|
|
375
559
|
copyDir(rscSrc, path.join(serverDistDir, "rsc"));
|
|
376
560
|
if (ssrSrc)
|
|
377
561
|
copyDir(ssrSrc, path.join(serverDistDir, "ssr"));
|
|
562
|
+
await traceRscBundleDependencies(root, serverDir, rscSrc, ssrSrc);
|
|
378
563
|
// Stub manifest if missing (RSC plugin may write it after our hook runs)
|
|
379
564
|
const rscDestDir = path.join(serverDistDir, "rsc");
|
|
380
565
|
const manifestDest = path.join(rscDestDir, "__vite_rsc_assets_manifest.js");
|
|
@@ -385,74 +570,6 @@ export async function buildRscNitro(options) {
|
|
|
385
570
|
// Nitro may group the entry differently by builder. Make copied-dist imports
|
|
386
571
|
// relative to the emitted chunk so output survives moving away from the project.
|
|
387
572
|
rewriteRscEntryImports(serverDir, serverDistDir);
|
|
388
|
-
// Patch SSR bundle: inject production client CSS href and bootstrap script so HTML has styles and hydration works
|
|
389
|
-
const ssrIndexPath = path.join(serverDistDir, "ssr", "index.js");
|
|
390
|
-
const manifestPath = path.join(serverDistDir, "rsc", MANIFEST_FILENAME);
|
|
391
|
-
let bootstrapScriptContent = "";
|
|
392
|
-
let clientEntryHref = "";
|
|
393
|
-
const RSC_CALL_SERVER_PLACEHOLDER = "(function(){if(typeof globalThis.__viteRscCallServer!=='function'){globalThis.__viteRscCallServer=function(){return Promise.reject(new Error(\"Farm.js: server actions not ready\"));}}})();\n";
|
|
394
|
-
if (existsSync(manifestPath)) {
|
|
395
|
-
try {
|
|
396
|
-
const manifestContent = readFileSync(manifestPath, "utf-8");
|
|
397
|
-
const start = manifestContent.indexOf("{");
|
|
398
|
-
const end = manifestContent.lastIndexOf("}") + 1;
|
|
399
|
-
if (start >= 0 && end > start) {
|
|
400
|
-
const manifest = JSON.parse(manifestContent.slice(start, end));
|
|
401
|
-
bootstrapScriptContent = manifest.bootstrapScriptContent || "";
|
|
402
|
-
const importMatch = bootstrapScriptContent.match(/^import\s*\(\s*["']([^"']+)["']\s*\)\s*$/);
|
|
403
|
-
if (importMatch)
|
|
404
|
-
clientEntryHref = importMatch[1];
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
catch {
|
|
408
|
-
// ignore
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
const fullBootstrap = bootstrapScriptContent
|
|
412
|
-
? RSC_CALL_SERVER_PLACEHOLDER + bootstrapScriptContent
|
|
413
|
-
: "";
|
|
414
|
-
// Patch manifest so production SSR gets bootstrap with __viteRscCallServer placeholder (SSR reads assetsManifest.bootstrapScriptContent)
|
|
415
|
-
if (fullBootstrap && existsSync(manifestPath)) {
|
|
416
|
-
try {
|
|
417
|
-
let manifestCode = readFileSync(manifestPath, "utf-8");
|
|
418
|
-
const escaped = JSON.stringify(bootstrapScriptContent);
|
|
419
|
-
const escapedFull = JSON.stringify(fullBootstrap);
|
|
420
|
-
if (manifestCode.includes(escaped) && escaped !== escapedFull) {
|
|
421
|
-
manifestCode = manifestCode.replace(escaped, escapedFull);
|
|
422
|
-
writeFileSync(manifestPath, manifestCode, "utf-8");
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
catch {
|
|
426
|
-
// ignore
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
if (existsSync(ssrIndexPath)) {
|
|
430
|
-
const assetsDirName = assetsDir ?? "assets";
|
|
431
|
-
const assetsRoot = path.join(publicDir, assetsDirName);
|
|
432
|
-
let clientCssHref = "";
|
|
433
|
-
if (existsSync(assetsRoot)) {
|
|
434
|
-
const files = readdirSync(assetsRoot);
|
|
435
|
-
const cssFile = files.find((f) => f.endsWith(".css"));
|
|
436
|
-
if (cssFile)
|
|
437
|
-
clientCssHref = `/${assetsDirName}/${cssFile}`;
|
|
438
|
-
}
|
|
439
|
-
try {
|
|
440
|
-
let ssrCode = readFileSync(ssrIndexPath, "utf-8");
|
|
441
|
-
if (ssrCode.includes("__FARM_CLIENT_CSS_HREF__")) {
|
|
442
|
-
ssrCode = ssrCode.replace("__FARM_CLIENT_CSS_HREF__", clientCssHref);
|
|
443
|
-
}
|
|
444
|
-
if (clientEntryHref && ssrCode.includes("__FARM_CLIENT_ENTRY_HREF__")) {
|
|
445
|
-
ssrCode = ssrCode.replace(/(CLIENT_ENTRY_HREF\s*=\s*)"__FARM_CLIENT_ENTRY_HREF__"/, "$1" + JSON.stringify(clientEntryHref));
|
|
446
|
-
}
|
|
447
|
-
if (fullBootstrap && ssrCode.includes("__FARM_BOOTSTRAP_SCRIPT__")) {
|
|
448
|
-
ssrCode = ssrCode.replace(/=\s*["']__FARM_BOOTSTRAP_SCRIPT__["']/, "= " + JSON.stringify(fullBootstrap));
|
|
449
|
-
}
|
|
450
|
-
writeFileSync(ssrIndexPath, ssrCode, "utf-8");
|
|
451
|
-
}
|
|
452
|
-
catch {
|
|
453
|
-
// ignore
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
573
|
console.log("[FARM] RSC Nitro build completed");
|
|
457
574
|
console.log(`[FARM] Output: ${outputDir}`);
|
|
458
575
|
}
|
package/dist/rsc/types.d.ts
CHANGED
|
@@ -69,6 +69,26 @@ export interface EntryContext {
|
|
|
69
69
|
base: string;
|
|
70
70
|
glob: string;
|
|
71
71
|
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Route-relative keys of the layouts that render the `<html>` document themselves
|
|
74
|
+
* (`/layout.tsx`). Below such a root layout the app owns the document, as in Next.js.
|
|
75
|
+
*/
|
|
76
|
+
documentLayouts?: string[];
|
|
77
|
+
/**
|
|
78
|
+
* Route-relative page keys to their parsed rendering directive (`"use ssg"`) and whether the
|
|
79
|
+
* page's source reads request state. The prerender pass merges these with module exports.
|
|
80
|
+
*/
|
|
81
|
+
pageRenderingDirectives?: Record<string, unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* The resolved `images` config, its public half for `<Image>`, and the optimizer the server
|
|
84
|
+
* mounts at `images.path` (`none` when Image keeps original URLs).
|
|
85
|
+
*/
|
|
86
|
+
images?: {
|
|
87
|
+
config: unknown;
|
|
88
|
+
public: unknown;
|
|
89
|
+
path: string;
|
|
90
|
+
runtime: "none" | "node" | "cloudflare";
|
|
91
|
+
};
|
|
72
92
|
/** Whether server actions are enabled */
|
|
73
93
|
actionsEnabled: boolean;
|
|
74
94
|
/** Normalized server action request security policy. */
|
package/dist/rsc/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rsc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EACV,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,aAAa,CAAC,EAAE,uBAAuB,CAAC;IAExC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,2CAA2C;QAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IAEf,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IAEf,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC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,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"vite-plugin-nitro.d.ts","sourceRoot":"","sources":["../../src/rsc/vite-plugin-nitro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAenC,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CA6EtE;AAED,kFAAkF;AAClF,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkC1D"}
|
|
@@ -48,10 +48,18 @@ export default function nitro(options = {}) {
|
|
|
48
48
|
delete globalThis.__FARM_NITRO_SERVER_BUNDLE;
|
|
49
49
|
delete globalThis.__FARM_NITRO_PATHS;
|
|
50
50
|
delete globalThis.__FARM_NITRO_BUILD_PROMISE;
|
|
51
|
+
// The server entries are always index.js, which the Nitro step loads: Vite names an ESM
|
|
52
|
+
// server entry index.mjs when the app's package.json is not "type": "module". The Nitro
|
|
53
|
+
// output's package.json is "type": "module", so .js loads as ESM there.
|
|
54
|
+
const serverOutput = { output: { entryFileNames: "[name].js" } };
|
|
51
55
|
return {
|
|
52
56
|
environments: {
|
|
53
|
-
rsc: {
|
|
54
|
-
|
|
57
|
+
rsc: {
|
|
58
|
+
build: { outDir: path.join(NITRO_VITE_DIST, "rsc"), rolldownOptions: serverOutput },
|
|
59
|
+
},
|
|
60
|
+
ssr: {
|
|
61
|
+
build: { outDir: path.join(NITRO_VITE_DIST, "ssr"), rolldownOptions: serverOutput },
|
|
62
|
+
},
|
|
55
63
|
client: { build: { outDir: path.join(NITRO_VITE_DIST, "client") } },
|
|
56
64
|
},
|
|
57
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -59,10 +59,11 @@
|
|
|
59
59
|
"better-call": "^1.0.19",
|
|
60
60
|
"es-module-lexer": "2.0.0",
|
|
61
61
|
"h3": "2.0.1-rc.32",
|
|
62
|
+
"nf3": "0.3.24",
|
|
62
63
|
"nitro": "3.0.260903-beta",
|
|
63
64
|
"picocolors": "^1.0.0",
|
|
64
65
|
"rsc-html-stream": "^0.0.4",
|
|
65
|
-
"@farm.js/core": "0.1.
|
|
66
|
+
"@farm.js/core": "0.1.41"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@types/node": "^22.20.5",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"react-dom": "19.2.8",
|
|
84
85
|
"react-server-dom-webpack": "19.2.8",
|
|
85
86
|
"vite": ">=6.0.0",
|
|
86
|
-
"@farm.js/core": "0.1.
|
|
87
|
+
"@farm.js/core": "0.1.41"
|
|
87
88
|
},
|
|
88
89
|
"peerDependenciesMeta": {
|
|
89
90
|
"@vitejs/plugin-rsc": {
|