@farm.js/plugin 0.1.66 → 0.1.68
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/api/index.d.ts.map +1 -1
- package/dist/api/index.js +24 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +3 -0
- package/dist/rsc/entries/client.d.ts +1 -0
- package/dist/rsc/entries/client.d.ts.map +1 -1
- package/dist/rsc/entries/client.js +151 -18
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +21 -0
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +18 -6
- package/dist/rsc/index.d.ts +7 -1
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +79 -18
- package/dist/rsc/middleware-config-module.d.ts +15 -3
- package/dist/rsc/middleware-config-module.d.ts.map +1 -1
- package/dist/rsc/middleware-config-module.js +22 -6
- package/dist/rsc/nitro-build.d.ts.map +1 -1
- package/dist/rsc/nitro-build.js +38 -7
- package/dist/rsc/presets.d.ts +6 -0
- package/dist/rsc/presets.d.ts.map +1 -0
- package/dist/rsc/presets.js +7 -0
- package/dist/rsc/types.d.ts +39 -0
- package/dist/rsc/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAwBlD,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,MAAM,CA0iBpE;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/api/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loadFarmDevModule } from "@farm.js/core/plugin";
|
|
2
2
|
import { _withAfterNodeMiddleware } from "@farm.js/core/after";
|
|
3
3
|
import { _runWithAPIRequestRuntime, createFarmRequestBodyErrorResponse, readNodeRequestBody, resolveFarmServerConfig, } from "@farm.js/core/internal/production-runtime";
|
|
4
|
-
import { API_ROUTE_METHODS, getAllowedAPIRouteMethods, invokeAPIRouteEndpoint, matchAPIRouteAtBasePath, resolveAPIRouteEndpoint, } from "@farm.js/core/api/runtime";
|
|
4
|
+
import { API_ROUTE_METHODS, createFarmInternalServerErrorResponse, FARM_INTERNAL_SERVER_ERROR_BODY, getAllowedAPIRouteMethods, invokeAPIRouteEndpoint, matchAPIRouteAtBasePath, resolveAPIRouteEndpoint, } from "@farm.js/core/api/runtime";
|
|
5
5
|
import { sendWebResponse } from "@farm.js/core/server";
|
|
6
6
|
import { createDevRequestHeaders, resolveDevRequestURL, resolveViteHtmlFallbackUrl, } from "../dev-request.js";
|
|
7
7
|
/**
|
|
@@ -93,10 +93,9 @@ export default function farmApi(options = {}) {
|
|
|
93
93
|
return await invokeAPIRouteEndpoint(endpoint, request, match.params);
|
|
94
94
|
}
|
|
95
95
|
catch (error) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
96
|
+
// As in core's dev server and production, the failure stays in the server log.
|
|
97
|
+
console.error(`[API Error] ${pathname}:`, error);
|
|
98
|
+
return createFarmInternalServerErrorResponse();
|
|
100
99
|
}
|
|
101
100
|
};
|
|
102
101
|
log(`better-call router created with ${totalEndpoints} endpoints`);
|
|
@@ -137,10 +136,8 @@ export default function farmApi(options = {}) {
|
|
|
137
136
|
});
|
|
138
137
|
}
|
|
139
138
|
catch (error) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
headers: { "Content-Type": "application/json" },
|
|
143
|
-
});
|
|
139
|
+
console.error(`[API Error] ${url.pathname}:`, error);
|
|
140
|
+
return createFarmInternalServerErrorResponse();
|
|
144
141
|
}
|
|
145
142
|
};
|
|
146
143
|
};
|
|
@@ -305,7 +302,23 @@ export default function farmApi(options = {}) {
|
|
|
305
302
|
if (farmMiddleware) {
|
|
306
303
|
await farmMiddleware.waitForDiscovery?.();
|
|
307
304
|
const middlewareData = new Map();
|
|
308
|
-
|
|
305
|
+
let handled;
|
|
306
|
+
try {
|
|
307
|
+
handled = await farmMiddleware.execute(req, res, pathname, middlewareData);
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
if (res.headersSent)
|
|
311
|
+
throw error;
|
|
312
|
+
// As in core's dev server and production: the generic JSON 500, kept out of
|
|
313
|
+
// shared caches.
|
|
314
|
+
logResponse(method, pathname, 500, Date.now() - startTime);
|
|
315
|
+
console.error("[FARM] Middleware error:", error);
|
|
316
|
+
res.statusCode = 500;
|
|
317
|
+
res.setHeader("Content-Type", "application/json");
|
|
318
|
+
res.setHeader("Cache-Control", "private, no-store");
|
|
319
|
+
res.end(FARM_INTERNAL_SERVER_ERROR_BODY);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
309
322
|
if (handled) {
|
|
310
323
|
const duration = Date.now() - startTime;
|
|
311
324
|
logResponse(method, pathname, res.statusCode || 200, duration);
|
|
@@ -345,7 +358,7 @@ export default function farmApi(options = {}) {
|
|
|
345
358
|
console.error("[FARM] API error:", error);
|
|
346
359
|
res.statusCode = 500;
|
|
347
360
|
res.setHeader("Content-Type", "application/json");
|
|
348
|
-
res.end(
|
|
361
|
+
res.end(FARM_INTERNAL_SERVER_ERROR_BODY);
|
|
349
362
|
}
|
|
350
363
|
});
|
|
351
364
|
server.middlewares.use((req, res, next) => _runWithAPIRequestRuntime({
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAU5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AA8BjE,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,GA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AE,KAAK,EAAE,MAAM;YAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAA;SAAE,CAAC;QAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;IAC7F,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AA6KD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAsUlF;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/middleware/index.js
CHANGED
|
@@ -394,6 +394,9 @@ export default function farmMiddleware(options = {}) {
|
|
|
394
394
|
// Fail the request, as core's dev server does. Carrying on would
|
|
395
395
|
// render the page a throwing auth check was meant to protect.
|
|
396
396
|
console.error("[FARM] Middleware error:", e);
|
|
397
|
+
// Vite's error page reports it, kept out of caches like core's.
|
|
398
|
+
if (!res.headersSent)
|
|
399
|
+
res.setHeader("Cache-Control", "private, no-store");
|
|
397
400
|
return passThrough(e);
|
|
398
401
|
}
|
|
399
402
|
passThrough();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EntryContext } from "../types.js";
|
|
2
|
+
export declare const CLIENT_ENTRY_CORE_IMPORTS: readonly ["@farm.js/core/client", "@farm.js/core/deployment", "@farm.js/core/internal/client-runtime", "@farm.js/core/server-query/client"];
|
|
2
3
|
export declare const serverFnTransportErrorClientRuntime = "function createFarmServerFnTransportError(value) {\n const message = value && typeof value === 'object' && typeof value.message === 'string'\n ? value.message\n : 'Server function failed';\n const error = new Error(message);\n\n if (\n value &&\n typeof value === 'object' &&\n value.name === 'ServerFnFailure' &&\n typeof value.code === 'string' &&\n Number.isInteger(value.status) &&\n value.status >= 400 &&\n value.status <= 599 &&\n Object.prototype.hasOwnProperty.call(value, 'data')\n ) {\n error.name = 'ServerFnFailure';\n error.code = value.code;\n error.status = value.status;\n error.data = value.data;\n Object.defineProperty(error, Symbol.for('farm.server-fn.failure'), {\n value: true,\n enumerable: false,\n });\n return error;\n }\n\n error.name = 'ServerActionError';\n return error;\n}";
|
|
3
4
|
/**
|
|
4
5
|
* Generates the browser entry file.
|
|
@@ -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;
|
|
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;AAIhD,eAAO,MAAM,yBAAyB,6IAK5B,CAAC;AAEX,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CA6gB7D"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { generateMobileShellNavigation } from "../mobile-client.js";
|
|
2
|
+
// The browser entry always loads, so what it imports must be optimized before the first page.
|
|
3
|
+
export const CLIENT_ENTRY_CORE_IMPORTS = [
|
|
4
|
+
"@farm.js/core/client",
|
|
5
|
+
"@farm.js/core/deployment",
|
|
6
|
+
"@farm.js/core/internal/client-runtime",
|
|
7
|
+
"@farm.js/core/server-query/client",
|
|
8
|
+
];
|
|
2
9
|
export const serverFnTransportErrorClientRuntime = `function createFarmServerFnTransportError(value) {
|
|
3
10
|
const message = value && typeof value === 'object' && typeof value.message === 'string'
|
|
4
11
|
? value.message
|
|
@@ -61,12 +68,19 @@ import {
|
|
|
61
68
|
createFarmDeploymentRequestHeaders,
|
|
62
69
|
isFarmDeploymentMismatchResponse,
|
|
63
70
|
} from '@farm.js/core/deployment';
|
|
64
|
-
import { runFarmNavigationDelegates } from '@farm.js/core/internal/client-runtime';
|
|
71
|
+
import { createFarmRouteAnnouncer, runFarmNavigationDelegates } from '@farm.js/core/internal/client-runtime';
|
|
65
72
|
`;
|
|
66
73
|
// farm dev --mobile: every page runs in the shell's WebView, so this entry is the mobile client.
|
|
67
74
|
if (ctx.mobileClient === "inline") {
|
|
68
75
|
imports += generateMobileShellNavigation();
|
|
69
76
|
}
|
|
77
|
+
// The app's client plugins and src/client.ts. Without any, the entry has no plugin runtime.
|
|
78
|
+
const clientPlugins = ctx.clientPlugins?.empty === false ? ctx.clientPlugins : undefined;
|
|
79
|
+
if (clientPlugins) {
|
|
80
|
+
imports += `import { createClientPluginManager } from '@farm.js/core/internal/client-runtime';
|
|
81
|
+
${clientPlugins.imports}
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
70
84
|
if (ctx.actionsEnabled) {
|
|
71
85
|
imports += `import { setServerCallback, encodeReply, createTemporaryReferenceSet } from '@vitejs/plugin-rsc/browser';
|
|
72
86
|
import { applyFarmCacheInvalidations } from '@farm.js/core/internal/client-runtime';
|
|
@@ -159,6 +173,63 @@ const setPayloadRef = { current: null };
|
|
|
159
173
|
const farmNavigateRef = { current: null };
|
|
160
174
|
`;
|
|
161
175
|
}
|
|
176
|
+
// Code that only an entry with client plugins has. Each fragment is empty without them, so that
|
|
177
|
+
// entry stays as it was.
|
|
178
|
+
const withPlugins = (code) => (clientPlugins ? code : "");
|
|
179
|
+
const clientPluginRuntime = clientPlugins
|
|
180
|
+
? `
|
|
181
|
+
// Client plugins run on the manager Farm's other entries use, with this entry's router. A
|
|
182
|
+
// navigation runs their hooks from refetch() and resolves once React commits its payload. The
|
|
183
|
+
// route announcer in BrowserRoot announces navigations, so the manager doesn't.
|
|
184
|
+
let farmRouterReady;
|
|
185
|
+
const farmRouterStarted = new Promise((resolve) => {
|
|
186
|
+
farmRouterReady = resolve;
|
|
187
|
+
});
|
|
188
|
+
const farmRefreshRef = { current: null };
|
|
189
|
+
const farmClientRuntime = createClientPluginManager(
|
|
190
|
+
${clientPlugins.registrations},
|
|
191
|
+
{
|
|
192
|
+
router: {
|
|
193
|
+
// The router exists once the page hydrates; a hook that navigates earlier waits for it.
|
|
194
|
+
async navigate(href, options) {
|
|
195
|
+
await farmRouterStarted;
|
|
196
|
+
await farmNavigateRef.current(href, options?.replace === true ? 'replace' : 'push');
|
|
197
|
+
},
|
|
198
|
+
async refresh() {
|
|
199
|
+
await farmRouterStarted;
|
|
200
|
+
await farmRefreshRef.current();
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
isDev: import.meta.env?.DEV === true,
|
|
204
|
+
isProd: import.meta.env?.PROD === true,
|
|
205
|
+
deploymentId: farmDeploymentId,
|
|
206
|
+
announceRoutes: false,
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
window.__FARM_CLIENT_RUNTIME__ = farmClientRuntime;
|
|
210
|
+
void farmClientRuntime.start();
|
|
211
|
+
if (import.meta.hot) {
|
|
212
|
+
import.meta.hot.dispose(() => farmClientRuntime.close('hmr'));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Every payload the root is given, numbered in order, so a navigation knows when React has
|
|
216
|
+
// committed its payload or a later one that replaced it.
|
|
217
|
+
let farmPayloadCount = 0;
|
|
218
|
+
const farmPayloadSequence = new WeakMap();
|
|
219
|
+
const farmPendingCommits = [];
|
|
220
|
+
function farmCommitPayload(payload, signal) {
|
|
221
|
+
const setPayload = setPayloadRef.current;
|
|
222
|
+
if (!setPayload) return Promise.resolve();
|
|
223
|
+
return new Promise((resolve) => {
|
|
224
|
+
setPayload(payload);
|
|
225
|
+
// A newer navigation superseded this one, so nothing waits for it.
|
|
226
|
+
if (signal.aborted) return resolve();
|
|
227
|
+
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
228
|
+
farmPendingCommits.push({ sequence: farmPayloadSequence.get(payload), resolve });
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
`
|
|
232
|
+
: "";
|
|
162
233
|
return `${imports}
|
|
163
234
|
${ctx.clientCachePersistence?.imports ?? ""}
|
|
164
235
|
${actionSetup}
|
|
@@ -175,7 +246,7 @@ function reportDeploymentMismatch(response) {
|
|
|
175
246
|
function debug(...args) {
|
|
176
247
|
${debugLog}
|
|
177
248
|
}
|
|
178
|
-
|
|
249
|
+
${clientPluginRuntime}
|
|
179
250
|
// A server component that fails while a client navigation renders it: a redirect() becomes a
|
|
180
251
|
// client navigation to its target, and anything else loads the URL as a document, so the server
|
|
181
252
|
// answers with its status and error.tsx. Errors in the first render are left to React.
|
|
@@ -229,13 +300,22 @@ async function main() {
|
|
|
229
300
|
return;
|
|
230
301
|
}
|
|
231
302
|
|
|
303
|
+
// The page the document loaded with is the baseline: it is never announced.
|
|
304
|
+
const announceRoute = createFarmRouteAnnouncer();
|
|
305
|
+
|
|
232
306
|
// Root component that manages RSC state
|
|
233
307
|
function BrowserRoot() {
|
|
234
308
|
const [payload, set] = React.useState(initial);
|
|
235
309
|
|
|
236
310
|
// Expose setter for external updates (navigation, actions, HMR)
|
|
237
311
|
React.useEffect(() => {
|
|
238
|
-
setPayloadRef.current =
|
|
312
|
+
setPayloadRef.current = ${clientPlugins
|
|
313
|
+
? `(p) => {
|
|
314
|
+
farmPayloadSequence.set(p, ++farmPayloadCount);
|
|
315
|
+
React.startTransition(() => set(p));
|
|
316
|
+
};
|
|
317
|
+
farmRouterReady();`
|
|
318
|
+
: "(p) => React.startTransition(() => set(p));"}
|
|
239
319
|
}, []);
|
|
240
320
|
|
|
241
321
|
// Keep document metadata in sync when an RSC navigation swaps only #root.
|
|
@@ -257,11 +337,24 @@ async function main() {
|
|
|
257
337
|
description?.remove();
|
|
258
338
|
}
|
|
259
339
|
}, [payload.metadata?.title, payload.metadata?.description]);
|
|
260
|
-
|
|
340
|
+
|
|
341
|
+
// Announce a client navigation to screen readers once its page and title are in place.
|
|
342
|
+
React.useEffect(() => {
|
|
343
|
+
if (payload !== initial) announceRoute();
|
|
344
|
+
}, [payload]);
|
|
345
|
+
${withPlugins(`
|
|
346
|
+
// A navigation's hooks wait for React to commit its payload, or one set after it.
|
|
347
|
+
React.useEffect(() => {
|
|
348
|
+
const committed = farmPayloadSequence.get(payload) ?? 0;
|
|
349
|
+
while (farmPendingCommits.length > 0 && farmPendingCommits[0].sequence <= committed) {
|
|
350
|
+
farmPendingCommits.shift().resolve();
|
|
351
|
+
}
|
|
352
|
+
}, [payload]);
|
|
353
|
+
`)}
|
|
261
354
|
// Set up client-side navigation
|
|
262
355
|
React.useEffect(() => {
|
|
263
356
|
// Re-fetch RSC when URL changes
|
|
264
|
-
const nav = () => refetch(location.href);
|
|
357
|
+
const nav = () => refetch(location.href${withPlugins(", { action: 'pop', from: null }")});
|
|
265
358
|
|
|
266
359
|
// Handle browser back/forward
|
|
267
360
|
window.addEventListener('popstate', nav);
|
|
@@ -327,18 +420,26 @@ async function main() {
|
|
|
327
420
|
if (to !== from && (await runFarmNavigationDelegates({ url: url.href, from, to, action }))) {
|
|
328
421
|
return;
|
|
329
422
|
}
|
|
330
|
-
if (action === 'replace') history.replaceState(null, '', url.href);
|
|
423
|
+
${withPlugins(" const fromHref = location.href;\n")} if (action === 'replace') history.replaceState(null, '', url.href);
|
|
331
424
|
else history.pushState(null, '', url.href);
|
|
332
|
-
await refetch(location.href);
|
|
425
|
+
await refetch(location.href${withPlugins(", { action, from: fromHref }")});
|
|
333
426
|
}
|
|
334
427
|
farmNavigateRef.current = navigate;
|
|
335
|
-
|
|
428
|
+
${withPlugins(" farmRefreshRef.current = () => refetch(location.href, { action: 'replace', from: location.href });\n")}
|
|
336
429
|
// Fetch new RSC payload for a URL
|
|
337
|
-
async function refetch(url) {
|
|
430
|
+
async function refetch(url${withPlugins(", navigation")}) {
|
|
338
431
|
debug('Fetching RSC for:', url);
|
|
339
|
-
|
|
432
|
+
${withPlugins("let session;")}
|
|
340
433
|
try {
|
|
341
|
-
//
|
|
434
|
+
${withPlugins(` // A navigation (not an HMR or server action refresh) runs the client plugins' hooks.
|
|
435
|
+
if (navigation) {
|
|
436
|
+
session = await farmClientRuntime.beginNavigation({
|
|
437
|
+
from: navigation.from,
|
|
438
|
+
to: url,
|
|
439
|
+
action: navigation.action,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
`)} // Request the page's RSC payload, '<page>.rsc', which a prerendered page serves as a
|
|
342
443
|
// static file. The page URL itself may be static HTML.
|
|
343
444
|
const payloadUrl = new URL(url, location.href);
|
|
344
445
|
payloadUrl.pathname = payloadUrl.pathname.endsWith('/')
|
|
@@ -350,14 +451,20 @@ async function main() {
|
|
|
350
451
|
}),
|
|
351
452
|
});
|
|
352
453
|
if (isFarmDeploymentMismatchResponse(res, farmDeploymentId)) {
|
|
353
|
-
|
|
454
|
+
${clientPlugins
|
|
455
|
+
? `const error = reportDeploymentMismatch(res);
|
|
456
|
+
if (session) await farmClientRuntime.failNavigation(session, error);`
|
|
457
|
+
: "reportDeploymentMismatch(res);"}
|
|
354
458
|
location.assign(url);
|
|
355
459
|
return;
|
|
356
460
|
}
|
|
357
461
|
|
|
358
462
|
if (!res.ok) {
|
|
359
463
|
console.error('[Farm.js] RSC fetch failed:', res.status);
|
|
360
|
-
|
|
464
|
+
${withPlugins(` if (session) {
|
|
465
|
+
await farmClientRuntime.failNavigation(session, new Error('RSC fetch failed: ' + res.status));
|
|
466
|
+
}
|
|
467
|
+
`)} // Fall back to full page navigation
|
|
361
468
|
location.href = url;
|
|
362
469
|
return;
|
|
363
470
|
}
|
|
@@ -380,11 +487,22 @@ async function main() {
|
|
|
380
487
|
}
|
|
381
488
|
}
|
|
382
489
|
const newPayload = await createFromReadableStream(res.body);
|
|
383
|
-
|
|
490
|
+
${clientPlugins
|
|
491
|
+
? `if (session) {
|
|
492
|
+
await farmClientRuntime.markNavigationLoaded(session);
|
|
493
|
+
// Not awaited: a server action that redirects awaits this navigation, and React commits
|
|
494
|
+
// the payload only once that action is done.
|
|
495
|
+
void farmCommitPayload(newPayload, session.signal)
|
|
496
|
+
.then(() => farmClientRuntime.resolveNavigation(session))
|
|
497
|
+
.then(() => farmClientRuntime.scheduleNavigationRendered(session));
|
|
498
|
+
} else {
|
|
499
|
+
setPayloadRef.current?.(newPayload);
|
|
500
|
+
}`
|
|
501
|
+
: "setPayloadRef.current?.(newPayload);"}
|
|
384
502
|
debug('RSC navigation complete');
|
|
385
503
|
} catch (e) {
|
|
386
504
|
console.error('[Farm.js] RSC navigation failed:', e);
|
|
387
|
-
// Fall back to full page navigation
|
|
505
|
+
${withPlugins(" if (session) await farmClientRuntime.failNavigation(session, e);\n")} // Fall back to full page navigation
|
|
388
506
|
location.href = url;
|
|
389
507
|
}
|
|
390
508
|
}
|
|
@@ -394,7 +512,12 @@ async function main() {
|
|
|
394
512
|
console.error('[Farm.js] #root element not found');
|
|
395
513
|
return;
|
|
396
514
|
}
|
|
397
|
-
|
|
515
|
+
${withPlugins(` // As in Farm's other entries, client plugins have set up before the page hydrates.
|
|
516
|
+
const hydration = await farmClientRuntime.beginHydration({
|
|
517
|
+
container: initial.ownsDocument ? document.documentElement : rootElForHydrate,
|
|
518
|
+
mode: 'hydrate',
|
|
519
|
+
});
|
|
520
|
+
`)} if (!initial.ownsDocument) {
|
|
398
521
|
// Final cleanup pass before hydrate (in case DOM changed during async)
|
|
399
522
|
while (rootElForHydrate.children.length > 1) rootElForHydrate.lastElementChild.remove();
|
|
400
523
|
while (rootElForHydrate.nextElementSibling) rootElForHydrate.nextElementSibling.remove();
|
|
@@ -407,9 +530,19 @@ async function main() {
|
|
|
407
530
|
const hydrated = initial.ownsDocument
|
|
408
531
|
? React.createElement(BrowserRoot)
|
|
409
532
|
: [null, React.createElement(BrowserRoot, { key: 'root' })];
|
|
410
|
-
|
|
533
|
+
${clientPlugins
|
|
534
|
+
? `try {
|
|
535
|
+
hydrateRoot(rootElForHydrate, hydrated, {
|
|
536
|
+
formState: initial.formState,
|
|
537
|
+
});
|
|
538
|
+
await farmClientRuntime.completeHydration(hydration);
|
|
539
|
+
} catch (error) {
|
|
540
|
+
await farmClientRuntime.failHydration(hydration, error);
|
|
541
|
+
throw error;
|
|
542
|
+
}`
|
|
543
|
+
: `hydrateRoot(rootElForHydrate, hydrated, {
|
|
411
544
|
formState: initial.formState,
|
|
412
|
-
})
|
|
545
|
+
});`}
|
|
413
546
|
|
|
414
547
|
// Handle HMR for server components
|
|
415
548
|
// When server code changes, re-fetch and re-render
|
|
@@ -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;AAgBhD;;;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;AAgBhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CA0lD1D"}
|
package/dist/rsc/entries/rsc.js
CHANGED
|
@@ -57,6 +57,10 @@ export function generateRscEntry(ctx) {
|
|
|
57
57
|
const mcpConfigImports = (ctx.mcpConfigPaths ?? [])
|
|
58
58
|
.map((configPath, index) => `import * as FarmMCPConfigModule${index} from ${JSON.stringify(configPath.replace(/\\/g, "/"))};`)
|
|
59
59
|
.join("\n");
|
|
60
|
+
// Imported for their factories, which register what a plugin's server functions use.
|
|
61
|
+
const pluginsConfigImports = (ctx.pluginsConfigPaths ?? [])
|
|
62
|
+
.map((configPath) => `import ${JSON.stringify(configPath.replace(/\\/g, "/"))};`)
|
|
63
|
+
.join("\n");
|
|
60
64
|
const mcpSource = ctx.mcpConfigPaths?.length ? generateMCPPluginSource() : null;
|
|
61
65
|
const middlewareConfigValues = (ctx.middlewareConfigPaths ?? []).map((_configPath, index) => `(FarmMiddlewareConfigModule${index}.default || FarmMiddlewareConfigModule${index})`);
|
|
62
66
|
let code = `
|
|
@@ -64,6 +68,7 @@ import React from 'react';
|
|
|
64
68
|
import ServerErrorFallback from '/.farm/rsc-entries/error-fallback.tsx';
|
|
65
69
|
${middlewareConfigImports}
|
|
66
70
|
${mcpConfigImports}
|
|
71
|
+
${pluginsConfigImports}
|
|
67
72
|
${mcpSource ? `${mcpSource.importSource}\nimport { mergePluginAPIRoutes } from '@farm.js/core/api/runtime';` : ""}
|
|
68
73
|
import { registerAPIRouteShape } from '@farm.js/core/api/runtime';
|
|
69
74
|
import {
|
|
@@ -124,6 +129,7 @@ import {
|
|
|
124
129
|
createMarkdownMirrorResponse,
|
|
125
130
|
farmRequestWantsMarkdown,
|
|
126
131
|
} from '@farm.js/core/markdown';
|
|
132
|
+
import { stripFarmBasePath, stripFarmLocaleFromPathname } from '@farm.js/core/internal/production-runtime';
|
|
127
133
|
|
|
128
134
|
${ctx.images && ctx.images.runtime !== "none"
|
|
129
135
|
? `import { createCloudflareImageTransformer, createFarmImageHandler } from '@farm.js/core/image/server';
|
|
@@ -152,6 +158,18 @@ globalThis.__FARM_IMAGE_CONFIG__ = ${JSON.stringify(ctx.images.public)};`
|
|
|
152
158
|
const farmDeploymentId = ${JSON.stringify(ctx.deploymentId)};
|
|
153
159
|
const farmApiBasePath = ${JSON.stringify(ctx.apiBasePath ?? "/api")};
|
|
154
160
|
const farmMarkdownConfig = ${JSON.stringify(ctx.markdown ?? { enabled: false, expose: [], cache: false, includeMetadata: true })};
|
|
161
|
+
const farmRouteI18n = ${JSON.stringify(ctx.i18n ?? { enabled: false, basePath: ctx.basePath })};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A request path without the app's basePath and locale prefix, as core's servers and the
|
|
165
|
+
* middleware runner read it: '/console/fr/about' is '/about'. Markdown names a home page
|
|
166
|
+
* '<prefix>/index.md' and matches md.expose on it. Pages still match the path as received.
|
|
167
|
+
*/
|
|
168
|
+
function getFarmRoutePathname(pathname) {
|
|
169
|
+
return farmRouteI18n.enabled
|
|
170
|
+
? stripFarmLocaleFromPathname(pathname, farmRouteI18n)
|
|
171
|
+
: stripFarmBasePath(pathname, farmRouteI18n.basePath);
|
|
172
|
+
}
|
|
155
173
|
`;
|
|
156
174
|
if (ctx.llmsTxt?.enabled) {
|
|
157
175
|
code += `import {
|
|
@@ -1426,6 +1444,8 @@ async function handleFarmPageOrMarkdown(request, context) {
|
|
|
1426
1444
|
const markdown = await createMarkdownMirrorResponse({
|
|
1427
1445
|
request,
|
|
1428
1446
|
config: farmMarkdownConfig,
|
|
1447
|
+
routePathname: getFarmRoutePathname,
|
|
1448
|
+
// matchRoute() reads the path as received, as the page render below does.
|
|
1429
1449
|
routeExists: (pathname) => Boolean(matchRoute(pathname)),
|
|
1430
1450
|
renderPage: (pageRequest) => handleFarmRequest(pageRequest, context),
|
|
1431
1451
|
apiServerBasePath: farmApiBasePath,
|
|
@@ -1435,6 +1455,7 @@ async function handleFarmPageOrMarkdown(request, context) {
|
|
|
1435
1455
|
return applyMarkdownNegotiationHeaders(response, {
|
|
1436
1456
|
config: farmMarkdownConfig,
|
|
1437
1457
|
pathname: new URL(request.url).pathname,
|
|
1458
|
+
routePathname: getFarmRoutePathname,
|
|
1438
1459
|
});
|
|
1439
1460
|
}
|
|
1440
1461
|
|
|
@@ -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,CAgP1D"}
|
package/dist/rsc/entries/ssr.js
CHANGED
|
@@ -16,7 +16,7 @@ export function generateSsrEntry(ctx) {
|
|
|
16
16
|
import React from 'react';
|
|
17
17
|
import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr';
|
|
18
18
|
import { injectRSCPayload } from 'rsc-html-stream/server';
|
|
19
|
-
import { renderToPipeableStream } from 'react-dom/server';
|
|
19
|
+
import { ${ctx.workers ? "renderToReadableStream" : "renderToPipeableStream"} } from 'react-dom/server';
|
|
20
20
|
|
|
21
21
|
function debug(...args) {
|
|
22
22
|
${debugLog}
|
|
@@ -148,7 +148,17 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
148
148
|
}
|
|
149
149
|
if (!bootstrap && PROD_BOOTSTRAP !== "__FARM_BOOTSTRAP_SCRIPT__") bootstrap = PROD_BOOTSTRAP;
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
${ctx.workers
|
|
152
|
+
? ` // Workers have no Node streams, so render to a web stream. Suspense still streams: fallback
|
|
153
|
+
// (loading.tsx) first, then resolved content. The promise rejects when the shell can't render,
|
|
154
|
+
// so the request handler can render error.tsx through RSC and SSR.
|
|
155
|
+
const htmlStream = await renderToReadableStream(React.createElement(Root), {
|
|
156
|
+
...(bootstrap && { bootstrapScriptContent: bootstrap }),
|
|
157
|
+
formState: options.formState,
|
|
158
|
+
onError(error) { console.error('[RSC] SSR render error:', error); },
|
|
159
|
+
});
|
|
160
|
+
`
|
|
161
|
+
: ` // Use renderToPipeableStream so Suspense streams: fallback (loading.tsx) first, then resolved content.
|
|
152
162
|
const { PassThrough, Readable } = await import('stream');
|
|
153
163
|
const passThrough = new PassThrough();
|
|
154
164
|
// Do not commit an empty response when the shell cannot render. Reject back
|
|
@@ -162,7 +172,7 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
162
172
|
onError(error) { console.error('[RSC] SSR render error:', error); },
|
|
163
173
|
});
|
|
164
174
|
});
|
|
165
|
-
|
|
175
|
+
`}
|
|
166
176
|
const CLIENT_ENTRY_HREF = "__FARM_CLIENT_ENTRY_HREF__";
|
|
167
177
|
const PLACEHOLDER_STR = "__FARM_CLIENT_ENTRY_HREF__";
|
|
168
178
|
const injectClientScriptInStream = typeof CLIENT_ENTRY_HREF === "string" && CLIENT_ENTRY_HREF.length > 0 && CLIENT_ENTRY_HREF.indexOf(PLACEHOLDER_STR) < 0;
|
|
@@ -172,7 +182,9 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
172
182
|
// Stream HTML to the client while preserving the RSC payload for hydration.
|
|
173
183
|
debug('Streaming HTML (loading fallback then content)');
|
|
174
184
|
const streamingClientScriptInjector = injectBeforeStream('</body></html>', clientScriptTag);
|
|
175
|
-
|
|
185
|
+
${ctx.workers
|
|
186
|
+
? " const webStream = htmlStream;"
|
|
187
|
+
: ` const webStream = typeof Readable.toWeb === 'function'
|
|
176
188
|
? Readable.toWeb(passThrough)
|
|
177
189
|
: new ReadableStream({
|
|
178
190
|
start(controller) {
|
|
@@ -180,7 +192,7 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
180
192
|
passThrough.on('end', () => controller.close());
|
|
181
193
|
passThrough.on('error', (e) => controller.error(e));
|
|
182
194
|
}
|
|
183
|
-
})
|
|
195
|
+
});`}
|
|
184
196
|
// In development, the stylesheets the shell's client components import (CSS modules come from
|
|
185
197
|
// JavaScript in the browser, so without links their HTML is unstyled until scripts run).
|
|
186
198
|
const devStyles = globalThis.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
@@ -194,7 +206,7 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
194
206
|
|
|
195
207
|
// Legacy path: buffer full HTML then send (no loading streaming)
|
|
196
208
|
debug('Rendering to HTML stream (then buffering)');
|
|
197
|
-
const fullHtmlRaw = await pipeableStreamToString(passThrough);
|
|
209
|
+
const fullHtmlRaw = ${ctx.workers ? "await new Response(htmlStream).text()" : "await pipeableStreamToString(passThrough)"};
|
|
198
210
|
let fullHtml = fullHtmlRaw;
|
|
199
211
|
const bufferedDevStyles = globalThis.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
200
212
|
const bufferedHeadTags = headTags + (typeof bufferedDevStyles === 'function' ? bufferedDevStyles() : '');
|
package/dist/rsc/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
import { type Plugin, type UserConfig } from "vite";
|
|
25
|
-
import type { FarmRscPluginOptions, EntryContext, FarmRscMobileClient } from "./types.js";
|
|
25
|
+
import type { FarmRscPluginOptions, EntryContext, FarmRscClientPlugins, FarmRscServerPlugins, FarmRscMobileClient } from "./types.js";
|
|
26
26
|
import type { FarmServerActionsConfig } from "@farm.js/core/server-action-security";
|
|
27
27
|
import type { FarmAPIConfig } from "@farm.js/core/api";
|
|
28
28
|
import type { FarmMiddlewareConfig } from "@farm.js/core/middleware";
|
|
@@ -112,6 +112,12 @@ export interface FarmRscConfig {
|
|
|
112
112
|
mcp?: FarmMCPUserConfig;
|
|
113
113
|
/** @internal See `FarmRscPluginOptions.mobileClient`; set by `farm dev` and `farm build`. */
|
|
114
114
|
mobileClient?: FarmRscMobileClient;
|
|
115
|
+
/** @internal See `FarmRscPluginOptions.clientPlugins`; set by `farm dev` and `farm build`. */
|
|
116
|
+
clientPlugins?: FarmRscClientPlugins;
|
|
117
|
+
/** @internal See `FarmRscPluginOptions.serverPlugins`; set by `farm build`. */
|
|
118
|
+
serverPlugins?: FarmRscServerPlugins;
|
|
119
|
+
/** @internal See `FarmRscPluginOptions.preset`; set by `farm build`. */
|
|
120
|
+
preset?: string;
|
|
115
121
|
}
|
|
116
122
|
/**
|
|
117
123
|
* Define a Farm.js RSC configuration
|
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,
|
|
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,EACV,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9E,OAAO,EAQL,sBAAsB,EAIvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAyB,KAAK,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AA8BvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAmD9D,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAExF,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,KAAK,EA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C;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;IACxB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC,8FAA8F;IAC9F,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,+EAA+E;IAC/E,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,aAAkB,GAAG,UAAU,CA+EnE;AAubD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAoyC5E"}
|
package/dist/rsc/index.js
CHANGED
|
@@ -24,13 +24,15 @@ import { loadFarmDevModule, FarmDevEnvironmentError } from "@farm.js/core/plugin
|
|
|
24
24
|
*/
|
|
25
25
|
import { parseAst, version as viteVersion, } from "vite";
|
|
26
26
|
import { init as initModuleLexer, parse as parseModuleImports } from "es-module-lexer";
|
|
27
|
+
import { isRscWorkersPreset } from "./presets.js";
|
|
28
|
+
import { createReactProductionModePlugin } from "@farm.js/core/internal/production-node-env";
|
|
27
29
|
import { farmEnvironmentFunctionsPlugin } from "@farm.js/core/environment/vite";
|
|
28
30
|
import { collectDevStylesheetUrls, farmFontImportsPlugin, farmImageImportsPlugin, generateClientCachePersistenceCode, getPublicFarmImageConfig, resolveFarmClientCacheAdapterEntry, resolveFarmClientOptimizeDeps, resolveFarmImageConfig, resolveFarmImageProviderForRuntime, resolveFarmImageServerRuntime, readRouteRenderingDirectiveFromFile, } from "@farm.js/core/vite";
|
|
29
31
|
import { generateRscEntry } from "./entries/rsc.js";
|
|
30
32
|
import { resolveMarkdownConfig } from "@farm.js/core/markdown";
|
|
31
33
|
import { generateSsrEntry } from "./entries/ssr.js";
|
|
32
34
|
import { generateErrorFallbackEntry } from "./entries/error-fallback.js";
|
|
33
|
-
import { generateClientEntry, serverFnTransportErrorClientRuntime } from "./entries/client.js";
|
|
35
|
+
import { CLIENT_ENTRY_CORE_IMPORTS, generateClientEntry, serverFnTransportErrorClientRuntime, } from "./entries/client.js";
|
|
34
36
|
import { transformFarmRouteActionClients } from "./route-action-transform.js";
|
|
35
37
|
import { createFarmServerFnBoundaryModule, isFarmServerFnBoundaryId, transformFarmServerFns, } from "./server-fn-transform.js";
|
|
36
38
|
import { transformAutomaticOptimizedBoundaries } from "./automatic-optimized-boundary.js";
|
|
@@ -75,7 +77,8 @@ export function defineConfig(config = {}) {
|
|
|
75
77
|
return {
|
|
76
78
|
// Core Farm RSC settings
|
|
77
79
|
experimental: {
|
|
78
|
-
|
|
80
|
+
// This plugin runs the "rsc" engine: core reads a bare `true` as islands.
|
|
81
|
+
serverComponents: config.experimental?.serverComponents === false ? false : { mode: "rsc" },
|
|
79
82
|
serverActions: config.experimental?.serverActions ?? false,
|
|
80
83
|
optimizedBoundary: config.experimental?.optimizedBoundary ?? false,
|
|
81
84
|
},
|
|
@@ -131,6 +134,9 @@ export function defineConfig(config = {}) {
|
|
|
131
134
|
routesDir: config.routesDir,
|
|
132
135
|
entries: config.entries,
|
|
133
136
|
mobileClient: config.mobileClient,
|
|
137
|
+
clientPlugins: config.clientPlugins,
|
|
138
|
+
serverPlugins: config.serverPlugins,
|
|
139
|
+
preset: config.preset,
|
|
134
140
|
}),
|
|
135
141
|
...(Array.isArray(config.plugins) ? config.plugins : []),
|
|
136
142
|
],
|
|
@@ -210,6 +216,7 @@ const OPTIMIZED_BOUNDARY_ADAPTER = "@farm.js/plugin/rsc/optimized-boundary";
|
|
|
210
216
|
const STRATA_PACKAGE = "@farming-labs/strata";
|
|
211
217
|
const RSC_MIDDLEWARE_CONFIG_QUERY = "?farm-rsc-middleware";
|
|
212
218
|
const RSC_MCP_CONFIG_QUERY = "?farm-rsc-mcp";
|
|
219
|
+
const RSC_PLUGINS_CONFIG_QUERY = "?farm-rsc-plugins";
|
|
213
220
|
const FARM_CORE_PACKAGE_ROOT = path.resolve(path.dirname(require_.resolve("@farm.js/core")), "..");
|
|
214
221
|
const FARM_CONFIG_FILENAMES = [
|
|
215
222
|
"farm.config.ts",
|
|
@@ -536,6 +543,7 @@ export default function farmRsc(options = {}) {
|
|
|
536
543
|
const debug = options.debug ?? false;
|
|
537
544
|
const automaticDeploymentId = `build-${Date.now()}`;
|
|
538
545
|
const supportsBuildAppHook = Number(viteVersion.split(".")[0]) >= 7;
|
|
546
|
+
const resolveNitroPreset = () => options.preset || process.env.NITRO_PRESET || "vercel";
|
|
539
547
|
const runNitroAfterApplicationBuild = async (builder) => {
|
|
540
548
|
const nitroEnabled = builder.config?.plugins?.some((plugin) => plugin.name === "vite-plugin-nitro");
|
|
541
549
|
if (!nitroEnabled || !rscBuildRoot)
|
|
@@ -623,11 +631,20 @@ export default function farmRsc(options = {}) {
|
|
|
623
631
|
farmEnvironmentFunctionsPlugin(),
|
|
624
632
|
rscPrivateClientSourcemaps(),
|
|
625
633
|
createFarmRscMobileClientManifestPlugin(() => mobileClientRoot),
|
|
634
|
+
{
|
|
635
|
+
// A Worker bundles React and has no NODE_ENV of its own, and `wrangler pages dev` defines it
|
|
636
|
+
// as "development": keep only React's production builds, as core's Workers builds do.
|
|
637
|
+
...createReactProductionModePlugin(),
|
|
638
|
+
enforce: "pre",
|
|
639
|
+
apply: (_config, env) => env.command === "build" && isRscWorkersPreset(resolveNitroPreset()),
|
|
640
|
+
},
|
|
626
641
|
{
|
|
627
642
|
name: "@farm.js/plugin/rsc:middleware-config",
|
|
628
643
|
enforce: "pre",
|
|
629
644
|
resolveId(id) {
|
|
630
|
-
if (!id.endsWith(RSC_MIDDLEWARE_CONFIG_QUERY) &&
|
|
645
|
+
if (!id.endsWith(RSC_MIDDLEWARE_CONFIG_QUERY) &&
|
|
646
|
+
!id.endsWith(RSC_MCP_CONFIG_QUERY) &&
|
|
647
|
+
!id.endsWith(RSC_PLUGINS_CONFIG_QUERY)) {
|
|
631
648
|
return null;
|
|
632
649
|
}
|
|
633
650
|
return id.replace(/\\/g, "/");
|
|
@@ -763,6 +780,30 @@ export default function farmRsc(options = {}) {
|
|
|
763
780
|
"Declare middleware directly in defineConfig({ middleware: ... }) or move it to src/app/middleware.ts.");
|
|
764
781
|
}
|
|
765
782
|
}
|
|
783
|
+
// Loading a plugin runs its factory in the server, which is how a plugin such as `bot()`
|
|
784
|
+
// registers what its server functions use. Only the entries with server hooks and the
|
|
785
|
+
// bindings they read are bundled, as for middleware.
|
|
786
|
+
const pluginsConfigPaths = [];
|
|
787
|
+
if (options.serverPlugins && env.command === "build") {
|
|
788
|
+
for (const configPath of await resolveMiddlewareConfigPaths(root, c.layers)) {
|
|
789
|
+
const selection = options.serverPlugins[path.resolve(configPath)];
|
|
790
|
+
if (!selection)
|
|
791
|
+
continue;
|
|
792
|
+
const extracted = await loadRscConfigPropertyModule(configPath, "plugins", selection);
|
|
793
|
+
if (extracted.kind !== "module") {
|
|
794
|
+
throw new Error(`[Farm.js] Cannot read plugins for the RSC server from ${configPath}: ${extracted.kind === "absent"
|
|
795
|
+
? "the config has no plugins property"
|
|
796
|
+
: extracted.reason}. Declare plugins directly in defineConfig({ plugins: [...] }).`);
|
|
797
|
+
}
|
|
798
|
+
const moduleId = `${configPath.replace(/\\/g, "/")}${RSC_PLUGINS_CONFIG_QUERY}`;
|
|
799
|
+
middlewareConfigModules.set(moduleId, extracted.code);
|
|
800
|
+
pluginsConfigPaths.push(moduleId);
|
|
801
|
+
}
|
|
802
|
+
if (pluginsConfigPaths.length < Object.keys(options.serverPlugins).length) {
|
|
803
|
+
throw new Error("[Farm.js] The RSC server could not find every config file with plugins to load. " +
|
|
804
|
+
"Declare plugins directly in defineConfig({ plugins: [...] }) in farm.config.ts.");
|
|
805
|
+
}
|
|
806
|
+
}
|
|
766
807
|
// Read user's directory configuration
|
|
767
808
|
const api = await resolveFarmAPIConfig(c.api, {
|
|
768
809
|
root,
|
|
@@ -825,7 +866,13 @@ export default function farmRsc(options = {}) {
|
|
|
825
866
|
];
|
|
826
867
|
// The same images contract as core: without Sharp, "auto" keeps original URLs
|
|
827
868
|
// (provider "none") instead of pointing <Image> at an optimizer that cannot run.
|
|
828
|
-
const nitroPreset =
|
|
869
|
+
const nitroPreset = resolveNitroPreset();
|
|
870
|
+
// Workers have no node_modules: the server bundles include their packages, built for
|
|
871
|
+
// workerd instead of Node.
|
|
872
|
+
const workersBuild = env.command === "build" && isRscWorkersPreset(nitroPreset);
|
|
873
|
+
if (workersBuild && optimizedBoundaryEnabled) {
|
|
874
|
+
throw new Error(`[Farm.js] \`experimental.optimizedBoundary\` loads Strata, a native Node module, which Cloudflare Workers can't run (preset \`${nitroPreset}\`). Turn it off for this build, or deploy to a Node target such as \`node-server\` or \`vercel\`.`);
|
|
875
|
+
}
|
|
829
876
|
const imageConfig = resolveFarmImageConfig(resolveFarmImageProviderForRuntime(c.images, {
|
|
830
877
|
root,
|
|
831
878
|
preset: nitroPreset,
|
|
@@ -854,6 +901,7 @@ export default function farmRsc(options = {}) {
|
|
|
854
901
|
entryContext = {
|
|
855
902
|
documentLayouts,
|
|
856
903
|
pageRenderingDirectives,
|
|
904
|
+
...(workersBuild ? { workers: true } : {}),
|
|
857
905
|
images: {
|
|
858
906
|
config: imageConfig,
|
|
859
907
|
public: publicImageConfig,
|
|
@@ -886,10 +934,12 @@ export default function farmRsc(options = {}) {
|
|
|
886
934
|
}),
|
|
887
935
|
server: { trustProxy: resolveFarmServerConfig(c.server).trustProxy },
|
|
888
936
|
middlewareConfigPaths,
|
|
937
|
+
pluginsConfigPaths,
|
|
889
938
|
debug,
|
|
890
939
|
development: env.command === "serve",
|
|
891
940
|
clientCachePersistence: generateClientCachePersistenceCode(resolveFarmClientCacheAdapterEntry(root, c.cache)),
|
|
892
941
|
mobileClient,
|
|
942
|
+
clientPlugins: options.clientPlugins,
|
|
893
943
|
};
|
|
894
944
|
logInfo(`srcDir: ${entryContext.srcDir}, outDir: ${entryContext.outDir}`);
|
|
895
945
|
// Write real entry files so @vitejs/plugin-rsc can use file-based entries.
|
|
@@ -934,18 +984,23 @@ export default function farmRsc(options = {}) {
|
|
|
934
984
|
__FARM_API_BASE_URL__: JSON.stringify(api.baseURL),
|
|
935
985
|
__FARM_IMAGE_CONFIG__: JSON.stringify(entryContext.images?.public),
|
|
936
986
|
},
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
987
|
+
// A Workers build bundles React too: there is no node_modules to load it from.
|
|
988
|
+
...(workersBuild
|
|
989
|
+
? {}
|
|
990
|
+
: {
|
|
991
|
+
ssr: {
|
|
992
|
+
external: [
|
|
993
|
+
"react",
|
|
994
|
+
"react-dom",
|
|
995
|
+
"react-dom/server",
|
|
996
|
+
"react/jsx-runtime",
|
|
997
|
+
"react/jsx-dev-runtime",
|
|
998
|
+
...(optimizedBoundaryEnabled
|
|
999
|
+
? [STRATA_PACKAGE, `${STRATA_PACKAGE}/react-server`]
|
|
1000
|
+
: []),
|
|
1001
|
+
],
|
|
1002
|
+
},
|
|
1003
|
+
}),
|
|
949
1004
|
...(optimizedBoundaryEnabled
|
|
950
1005
|
? {
|
|
951
1006
|
optimizeDeps: {
|
|
@@ -1035,7 +1090,10 @@ export default function farmRsc(options = {}) {
|
|
|
1035
1090
|
rollupOptions: { input: { index: entryRsc } },
|
|
1036
1091
|
},
|
|
1037
1092
|
resolve: {
|
|
1038
|
-
conditions:
|
|
1093
|
+
conditions: workersBuild
|
|
1094
|
+
? ["react-server", "workerd", "worker", "import", "module"]
|
|
1095
|
+
: ["react-server", "node", "import"],
|
|
1096
|
+
...(workersBuild ? { noExternal: true } : {}),
|
|
1039
1097
|
// Strata is a native CommonJS loader: Node must load it, not Vite's
|
|
1040
1098
|
// module runner. ssr.external does not reach this environment.
|
|
1041
1099
|
...(optimizedBoundaryEnabled
|
|
@@ -1049,7 +1107,9 @@ export default function farmRsc(options = {}) {
|
|
|
1049
1107
|
copyPublicDir: false,
|
|
1050
1108
|
rollupOptions: { input: { index: entrySsr } },
|
|
1051
1109
|
},
|
|
1052
|
-
resolve:
|
|
1110
|
+
resolve: workersBuild
|
|
1111
|
+
? { conditions: ["workerd", "worker", "import", "module"], noExternal: true }
|
|
1112
|
+
: { conditions: ["node", "import"] },
|
|
1053
1113
|
},
|
|
1054
1114
|
client: {
|
|
1055
1115
|
build: {
|
|
@@ -1075,6 +1135,7 @@ export default function farmRsc(options = {}) {
|
|
|
1075
1135
|
"react-dom",
|
|
1076
1136
|
"react-dom/client",
|
|
1077
1137
|
"rsc-html-stream/client",
|
|
1138
|
+
...CLIENT_ENTRY_CORE_IMPORTS,
|
|
1078
1139
|
// Client components and the packages they use load only once a page renders
|
|
1079
1140
|
// (client references), so they would be found late too.
|
|
1080
1141
|
...clientOptimizeDeps.include,
|
|
@@ -13,10 +13,22 @@ type ExtractionResult = {
|
|
|
13
13
|
kind: "unsupported";
|
|
14
14
|
reason: string;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Entries to keep from a `plugins` array literal: their positions, and the array's length the
|
|
18
|
+
* evaluated config had, which must match the literal for the positions to mean the same entries.
|
|
19
|
+
*/
|
|
20
|
+
export type RscConfigArraySelection = {
|
|
21
|
+
indexes: readonly number[];
|
|
22
|
+
count: number;
|
|
23
|
+
};
|
|
16
24
|
export declare function extractRscMiddlewareConfigModule(source: string, program: AstNode): ExtractionResult;
|
|
17
|
-
/**
|
|
18
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Extracts `key` from the default-exported config, as a module that exports `{ [key] }`. With
|
|
27
|
+
* `selection`, an array literal keeps only the selected entries and the bindings they read. Any
|
|
28
|
+
* other value is kept whole.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractRscConfigPropertyModule(source: string, program: AstNode, key: "middleware" | "mcp" | "plugins", selection?: RscConfigArraySelection): ExtractionResult;
|
|
19
31
|
export declare function loadRscMiddlewareConfigModule(configPath: string): Promise<ExtractionResult>;
|
|
20
|
-
export declare function loadRscConfigPropertyModule(configPath: string, key: "middleware" | "mcp"): Promise<ExtractionResult>;
|
|
32
|
+
export declare function loadRscConfigPropertyModule(configPath: string, key: "middleware" | "mcp" | "plugins", selection?: RscConfigArraySelection): Promise<ExtractionResult>;
|
|
21
33
|
export {};
|
|
22
34
|
//# sourceMappingURL=middleware-config-module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-config-module.d.ts","sourceRoot":"","sources":["../../src/rsc/middleware-config-module.ts"],"names":[],"mappings":"AAQA,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AASF,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware-config-module.d.ts","sourceRoot":"","sources":["../../src/rsc/middleware-config-module.ts"],"names":[],"mappings":"AAQA,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AASF,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAgQpF,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,GACf,gBAAgB,CAElB;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,YAAY,GAAG,KAAK,GAAG,SAAS,EACrC,SAAS,CAAC,EAAE,uBAAuB,GAClC,gBAAgB,CA4JlB;AAiBD,wBAAsB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEjG;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,YAAY,GAAG,KAAK,GAAG,SAAS,EACrC,SAAS,CAAC,EAAE,uBAAuB,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAwB3B"}
|
|
@@ -230,8 +230,12 @@ function unsupportedStatementReason(statement, source, key) {
|
|
|
230
230
|
export function extractRscMiddlewareConfigModule(source, program) {
|
|
231
231
|
return extractRscConfigPropertyModule(source, program, "middleware");
|
|
232
232
|
}
|
|
233
|
-
/**
|
|
234
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Extracts `key` from the default-exported config, as a module that exports `{ [key] }`. With
|
|
235
|
+
* `selection`, an array literal keeps only the selected entries and the bindings they read. Any
|
|
236
|
+
* other value is kept whole.
|
|
237
|
+
*/
|
|
238
|
+
export function extractRscConfigPropertyModule(source, program, key, selection) {
|
|
235
239
|
const body = program.body ?? [];
|
|
236
240
|
const bindings = new Map();
|
|
237
241
|
const variableInitializers = new Map();
|
|
@@ -341,9 +345,19 @@ export function extractRscConfigPropertyModule(source, program, key) {
|
|
|
341
345
|
};
|
|
342
346
|
}
|
|
343
347
|
const keyValue = keyProperty.value;
|
|
348
|
+
const elements = keyValue.type === "ArrayExpression" ? keyValue.elements : null;
|
|
349
|
+
const selectedElements = selection &&
|
|
350
|
+
elements &&
|
|
351
|
+
elements.length === selection.count &&
|
|
352
|
+
elements.every((element) => isNode(element) && element.type !== "SpreadElement")
|
|
353
|
+
? selection.indexes.map((index) => elements[index])
|
|
354
|
+
: null;
|
|
355
|
+
const keptValues = selectedElements ?? [keyValue];
|
|
344
356
|
const candidateNames = new Set(bindings.keys());
|
|
345
357
|
const selectedBindings = new Set();
|
|
346
|
-
const pending =
|
|
358
|
+
const pending = keptValues.flatMap((value) => [
|
|
359
|
+
...referencedTopLevelNames(value, candidateNames),
|
|
360
|
+
]);
|
|
347
361
|
while (pending.length > 0) {
|
|
348
362
|
const name = pending.pop();
|
|
349
363
|
const binding = bindings.get(name);
|
|
@@ -359,7 +373,9 @@ export function extractRscConfigPropertyModule(source, program, key) {
|
|
|
359
373
|
const declarations = [...selectedBindings]
|
|
360
374
|
.sort((a, b) => a.order - b.order)
|
|
361
375
|
.map((binding) => binding.render());
|
|
362
|
-
const valueSource =
|
|
376
|
+
const valueSource = selectedElements
|
|
377
|
+
? `[${selectedElements.map((element) => source.slice(element.start, element.end)).join(", ")}]`
|
|
378
|
+
: source.slice(keyValue.start, keyValue.end);
|
|
363
379
|
return {
|
|
364
380
|
kind: "module",
|
|
365
381
|
code: `${declarations.join("\n")}${declarations.length ? "\n" : ""}export default { ${key}: ${valueSource} };\n`,
|
|
@@ -382,7 +398,7 @@ function sourceLang(file) {
|
|
|
382
398
|
export async function loadRscMiddlewareConfigModule(configPath) {
|
|
383
399
|
return loadRscConfigPropertyModule(configPath, "middleware");
|
|
384
400
|
}
|
|
385
|
-
export async function loadRscConfigPropertyModule(configPath, key) {
|
|
401
|
+
export async function loadRscConfigPropertyModule(configPath, key, selection) {
|
|
386
402
|
const [{ readFile }, vite] = await Promise.all([import("node:fs/promises"), import("vite")]);
|
|
387
403
|
const source = await readFile(configPath, "utf8");
|
|
388
404
|
const lang = sourceLang(configPath);
|
|
@@ -399,5 +415,5 @@ export async function loadRscConfigPropertyModule(configPath, key) {
|
|
|
399
415
|
jsx: "automatic",
|
|
400
416
|
loader: lang,
|
|
401
417
|
});
|
|
402
|
-
return extractRscConfigPropertyModule(transformed.code, vite.parseAst(transformed.code), key);
|
|
418
|
+
return extractRscConfigPropertyModule(transformed.code, vite.parseAst(transformed.code), key, selection);
|
|
403
419
|
}
|
|
@@ -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;AAuCH;;;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,CAyCrF;AAuGD;;;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;AA6OF,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8IhF"}
|
package/dist/rsc/nitro-build.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
-
import { writeFileSync, readFileSync, mkdirSync, copyFileSync, existsSync, readdirSync, lstatSync, rmSync, statSync, symlinkSync, } from "fs";
|
|
8
|
+
import { writeFileSync, readFileSync, mkdirSync, copyFileSync, existsSync, readdirSync, lstatSync, realpathSync, rmSync, statSync, symlinkSync, } from "fs";
|
|
9
9
|
import { FARM_NODE_ENV_MODULE_FILE, FARM_NODE_ENV_MODULE_SOURCE, } from "@farm.js/core/internal/production-node-env";
|
|
10
|
+
import { resolveCloudflareProcessEnvFlags } from "@farm.js/core/deployment";
|
|
10
11
|
import { resolveRscBuildOutputPath } from "./build-paths.js";
|
|
12
|
+
import { isRscWorkersPreset } from "./presets.js";
|
|
11
13
|
import { finalizeFarmRscMobileClient, patchFarmRscMobileShellClient, patchFarmRscNativeStylesheets, } from "./mobile-client.js";
|
|
12
14
|
const MANIFEST_FILENAME = "__vite_rsc_assets_manifest.js";
|
|
13
15
|
const MIN_MANIFEST_BYTES = 100; // real manifest is ~500+, stub is 64
|
|
@@ -58,10 +60,14 @@ export function rewriteRscEntryImports(serverDir, serverDistDir) {
|
|
|
58
60
|
for (const chunksDir of ["chunks", "_chunks", "_build"]) {
|
|
59
61
|
findEntryChunks(path.join(serverDir, chunksDir));
|
|
60
62
|
}
|
|
63
|
+
// Node resolves a relative import from the importer's real location, so both ends are real paths:
|
|
64
|
+
// a server dir reached through a link (macOS's /var -> /private/var) would otherwise climb too far.
|
|
65
|
+
const realServerDistDir = realpathSync(serverDistDir);
|
|
61
66
|
for (const entryChunkPath of entryChunkPaths) {
|
|
62
67
|
let code = readFileSync(entryChunkPath, "utf-8");
|
|
68
|
+
const entryDir = realpathSync(path.dirname(entryChunkPath));
|
|
63
69
|
const relativeImport = (target) => {
|
|
64
|
-
const relative = path.relative(
|
|
70
|
+
const relative = path.relative(entryDir, target).replace(/\\/g, "/");
|
|
65
71
|
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
66
72
|
};
|
|
67
73
|
// Match any path that ends with dist/rsc/index.js, dist/ssr/index.js or the NODE_ENV module
|
|
@@ -72,7 +78,7 @@ export function rewriteRscEntryImports(serverDir, serverDistDir) {
|
|
|
72
78
|
["ssr", "index.js"],
|
|
73
79
|
]) {
|
|
74
80
|
const pattern = new RegExp(`(["'\`])[^"'\`]*?dist/${environment}/${file.replace(/\./g, "\\.")}\\1`, "g");
|
|
75
|
-
code = code.replace(pattern, JSON.stringify(relativeImport(path.join(
|
|
81
|
+
code = code.replace(pattern, JSON.stringify(relativeImport(path.join(realServerDistDir, environment, file))));
|
|
76
82
|
}
|
|
77
83
|
writeFileSync(entryChunkPath, code, "utf-8");
|
|
78
84
|
}
|
|
@@ -516,6 +522,21 @@ function removeSeedOutput(nitro, fileName) {
|
|
|
516
522
|
rmSync(target, { recursive: true });
|
|
517
523
|
}
|
|
518
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* Puts the worker's vars and secrets in `process.env`, as core's Cloudflare builds do: Nitro writes
|
|
527
|
+
* a compatibility date from before Workers did that by default.
|
|
528
|
+
*/
|
|
529
|
+
function populateWorkerProcessEnv(serverDir) {
|
|
530
|
+
const wranglerPath = path.join(serverDir, "wrangler.json");
|
|
531
|
+
// `cloudflare.deployConfig: false` writes no Wrangler config.
|
|
532
|
+
if (!existsSync(wranglerPath))
|
|
533
|
+
return;
|
|
534
|
+
const wrangler = JSON.parse(readFileSync(wranglerPath, "utf-8"));
|
|
535
|
+
const flags = resolveCloudflareProcessEnvFlags(wrangler);
|
|
536
|
+
if (!flags)
|
|
537
|
+
return;
|
|
538
|
+
writeFileSync(wranglerPath, JSON.stringify({ ...wrangler, compatibility_flags: flags }, null, 2), "utf-8");
|
|
539
|
+
}
|
|
519
540
|
export async function buildRscNitro(options) {
|
|
520
541
|
const { rendererPath, publicDir, ssrPath, assetsDir, root, preset = "vercel" } = options;
|
|
521
542
|
const outputDir = options.outputDir ?? path.join(root, ".output");
|
|
@@ -525,7 +546,9 @@ export async function buildRscNitro(options) {
|
|
|
525
546
|
// Vercel's Build Output API has its own layout (functions/, static/), which the preset owns when
|
|
526
547
|
// the caller names the deployment directory (`farm build`). Without one, the output keeps the
|
|
527
548
|
// server/ and public/ layout that hand-written post-build scripts copy from.
|
|
528
|
-
|
|
549
|
+
// Cloudflare Pages runs `_worker.js` beside the static files, which the preset lays out too.
|
|
550
|
+
const workers = isRscWorkersPreset(preset);
|
|
551
|
+
const presetOwnsLayout = (options.outputDir !== undefined && preset === "vercel") || workers;
|
|
529
552
|
// The server sets NODE_ENV to "production" unless the deployment chose one, as the core
|
|
530
553
|
// node-server output does. The RSC and SSR bundles read it at runtime: left unset, React loads
|
|
531
554
|
// its development builds and Flight responses carry server component props, stacks and paths.
|
|
@@ -584,7 +607,10 @@ export async function buildRscNitro(options) {
|
|
|
584
607
|
},
|
|
585
608
|
},
|
|
586
609
|
compatibilityDate: "2024-12-01",
|
|
587
|
-
|
|
610
|
+
// Nitro's minifier prints the entry's import() specifier as a template literal, and workerd
|
|
611
|
+
// only follows string-literal module specifiers. The entry is small, and the RSC and SSR
|
|
612
|
+
// bundles aren't minified either way.
|
|
613
|
+
minify: !workers,
|
|
588
614
|
};
|
|
589
615
|
if (ssrPath) {
|
|
590
616
|
patchRscServerBundles(path.resolve(root), path.dirname(path.resolve(rendererPath)), path.dirname(path.resolve(ssrPath)), publicDir, assetsDir);
|
|
@@ -603,7 +629,9 @@ export async function buildRscNitro(options) {
|
|
|
603
629
|
}
|
|
604
630
|
await build(nitro);
|
|
605
631
|
await nitro.close();
|
|
606
|
-
|
|
632
|
+
// A Workers build includes its packages in the bundles, and Workers can't read node_modules.
|
|
633
|
+
if (!workers)
|
|
634
|
+
copyRuntimePackages(serverDir, registeredRuntimePackages);
|
|
607
635
|
// Copy dist into server so runtime relative imports resolve. Handle missing dir (e.g. buildApp order).
|
|
608
636
|
const serverDistDir = path.join(serverDir, "dist");
|
|
609
637
|
const rscSrc = path.dirname(path.resolve(rendererPath));
|
|
@@ -612,7 +640,8 @@ export async function buildRscNitro(options) {
|
|
|
612
640
|
copyDir(rscSrc, path.join(serverDistDir, "rsc"));
|
|
613
641
|
if (ssrSrc)
|
|
614
642
|
copyDir(ssrSrc, path.join(serverDistDir, "ssr"));
|
|
615
|
-
|
|
643
|
+
if (!workers)
|
|
644
|
+
await traceRscBundleDependencies(root, serverDir, rscSrc, ssrSrc);
|
|
616
645
|
// Stub manifest if missing (RSC plugin may write it after our hook runs)
|
|
617
646
|
const rscDestDir = path.join(serverDistDir, "rsc");
|
|
618
647
|
const manifestDest = path.join(rscDestDir, "__vite_rsc_assets_manifest.js");
|
|
@@ -623,6 +652,8 @@ export async function buildRscNitro(options) {
|
|
|
623
652
|
// Nitro may group the entry differently by builder. Make copied-dist imports
|
|
624
653
|
// relative to the emitted chunk so output survives moving away from the project.
|
|
625
654
|
rewriteRscEntryImports(serverDir, serverDistDir);
|
|
655
|
+
if (workers)
|
|
656
|
+
populateWorkerProcessEnv(serverDir);
|
|
626
657
|
console.log("[FARM] RSC Nitro build completed");
|
|
627
658
|
console.log(`[FARM] Output: ${outputDir}`);
|
|
628
659
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a Nitro preset deploys the server to Cloudflare Workers, where there's no
|
|
3
|
+
* `node_modules` to load packages from at runtime, so the RSC and SSR bundles must include them.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isRscWorkersPreset(preset: string | undefined): boolean;
|
|
6
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/rsc/presets.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAEtE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a Nitro preset deploys the server to Cloudflare Workers, where there's no
|
|
3
|
+
* `node_modules` to load packages from at runtime, so the RSC and SSR bundles must include them.
|
|
4
|
+
*/
|
|
5
|
+
export function isRscWorkersPreset(preset) {
|
|
6
|
+
return preset === "cloudflare" || preset === "cloudflare-pages" || preset === "cloudflare-module";
|
|
7
|
+
}
|
package/dist/rsc/types.d.ts
CHANGED
|
@@ -52,9 +52,39 @@ export interface FarmRscPluginOptions {
|
|
|
52
52
|
* navigations to the shell (`farm dev --mobile`).
|
|
53
53
|
*/
|
|
54
54
|
mobileClient?: FarmRscMobileClient;
|
|
55
|
+
/**
|
|
56
|
+
* @internal Set by `farm dev` and `farm build`: the browser half of the app's Farm `plugins`
|
|
57
|
+
* and its `src/client.ts`, as core generates it for every entry.
|
|
58
|
+
*/
|
|
59
|
+
clientPlugins?: FarmRscClientPlugins;
|
|
60
|
+
/**
|
|
61
|
+
* @internal Set by `farm build` when some of the app's Farm `plugins` have server hooks: for
|
|
62
|
+
* each config file, by absolute path, where those entries sit in its `plugins` array. The
|
|
63
|
+
* server loads them, so their factories run there.
|
|
64
|
+
*/
|
|
65
|
+
serverPlugins?: FarmRscServerPlugins;
|
|
66
|
+
/**
|
|
67
|
+
* @internal Set by `farm build`: the Nitro preset it deploys with. A Cloudflare preset builds
|
|
68
|
+
* the RSC and SSR bundles with their packages included, since Workers have no node_modules.
|
|
69
|
+
*/
|
|
70
|
+
preset?: string;
|
|
55
71
|
}
|
|
72
|
+
/** @internal See `FarmRscPluginOptions.serverPlugins`. */
|
|
73
|
+
export type FarmRscServerPlugins = Record<string, {
|
|
74
|
+
indexes: number[];
|
|
75
|
+
count: number;
|
|
76
|
+
}>;
|
|
56
77
|
/** @internal See `FarmRscPluginOptions.mobileClient`. */
|
|
57
78
|
export type FarmRscMobileClient = "entry" | "inline";
|
|
79
|
+
/**
|
|
80
|
+
* @internal Core's `generateFarmClientPluginEntryCode` output: the imports and registrations the
|
|
81
|
+
* browser entry starts the client plugin manager with. `empty` leaves the manager out.
|
|
82
|
+
*/
|
|
83
|
+
export interface FarmRscClientPlugins {
|
|
84
|
+
empty: boolean;
|
|
85
|
+
imports: string;
|
|
86
|
+
registrations: string;
|
|
87
|
+
}
|
|
58
88
|
/**
|
|
59
89
|
* Internal context passed to entry generators.
|
|
60
90
|
* Contains resolved configuration values needed to generate entry files.
|
|
@@ -88,6 +118,11 @@ export interface EntryContext {
|
|
|
88
118
|
* page's source reads request state. The prerender pass merges these with module exports.
|
|
89
119
|
*/
|
|
90
120
|
pageRenderingDirectives?: Record<string, unknown>;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the server runs in Cloudflare Workers, where SSR renders to web streams because there
|
|
123
|
+
* are no Node streams.
|
|
124
|
+
*/
|
|
125
|
+
workers?: boolean;
|
|
91
126
|
/**
|
|
92
127
|
* The resolved `images` config, its public half for `<Image>`, and the optimizer the server
|
|
93
128
|
* mounts at `images.path` (`none` when Image keeps original URLs).
|
|
@@ -125,6 +160,8 @@ export interface EntryContext {
|
|
|
125
160
|
middlewareConfigPaths?: string[];
|
|
126
161
|
/** Modules that export `{ mcp }`, read from the app's config files, in layer order. */
|
|
127
162
|
mcpConfigPaths?: string[];
|
|
163
|
+
/** Modules that export `{ plugins }`, read from the app's config files, in layer order. */
|
|
164
|
+
pluginsConfigPaths?: string[];
|
|
128
165
|
/** Resolved Markdown mirror settings (core's `md`): `.md` pages and `Accept: text/markdown`. */
|
|
129
166
|
markdown?: FarmMarkdownResolvedConfig;
|
|
130
167
|
/** Resolved `agent.llmsTxt`: the generated `/llms.txt` and `/llms-full.txt`. */
|
|
@@ -140,6 +177,8 @@ export interface EntryContext {
|
|
|
140
177
|
};
|
|
141
178
|
/** The mobile client of an app with a `mobile` block (see `FarmRscPluginOptions`). */
|
|
142
179
|
mobileClient?: FarmRscMobileClient;
|
|
180
|
+
/** Client plugin registrations (see `FarmRscPluginOptions`). Absent or empty: none. */
|
|
181
|
+
clientPlugins?: FarmRscClientPlugins;
|
|
143
182
|
}
|
|
144
183
|
/**
|
|
145
184
|
* Matched route information from the file-based router.
|
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,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A0C;IAC1C,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAE/B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAEhB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0DAA0D;IAC1D,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC;IAEzB,wFAAwF;IACxF,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAEjC,yEAAyE;IACzE,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF,0DAA0D;IAC1D,WAAW,CAAC,EAAE;QACZ,EAAE,EAAE,OAAO,CAAC;QACZ,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IAEF,6CAA6C;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB,QAAQ,CAAC,OAAO,EAAE;YAChB,qCAAqC;YACrC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YAEhC,6CAA6C;YAC7C,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEhE,kDAAkD;YAClD,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC5D,CAAC;KACH;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.68",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"nitro": "3.0.260903-beta",
|
|
64
64
|
"picocolors": "^1.0.0",
|
|
65
65
|
"rsc-html-stream": "^0.0.4",
|
|
66
|
-
"@farm.js/core": "0.1.
|
|
66
|
+
"@farm.js/core": "0.1.68"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/node": "^22.20.5",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"react-dom": "19.2.8",
|
|
85
85
|
"react-server-dom-webpack": "19.2.8",
|
|
86
86
|
"vite": ">=6.0.0",
|
|
87
|
-
"@farm.js/core": "0.1.
|
|
87
|
+
"@farm.js/core": "0.1.68"
|
|
88
88
|
},
|
|
89
89
|
"peerDependenciesMeta": {
|
|
90
90
|
"@vitejs/plugin-rsc": {
|