@farm.js/plugin 0.1.67 → 0.1.69
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/entries/client.d.ts +2 -0
- package/dist/rsc/entries/client.d.ts.map +1 -1
- package/dist/rsc/entries/client.js +59 -5
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +428 -50
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +18 -6
- package/dist/rsc/index.d.ts +17 -5
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +109 -25
- 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 +31 -4
- 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 -2
- package/dist/rsc/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -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, FarmRscClientPlugins, 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";
|
|
@@ -30,7 +30,7 @@ import type { FarmServerConfig } from "@farm.js/core/internal/production-runtime
|
|
|
30
30
|
import type { FarmLayerEntry, ResolvedFarmLayer } from "@farm.js/core/server";
|
|
31
31
|
import { resolveFarmImageConfig } from "@farm.js/core/vite";
|
|
32
32
|
import { type FarmMarkdownUserConfig } from "@farm.js/core/markdown";
|
|
33
|
-
import type { FarmLlmsTxtUserConfig } from "@farm.js/core/internal/production-runtime";
|
|
33
|
+
import type { FarmAgentSitemapUserConfig, FarmLlmsTxtUserConfig } from "@farm.js/core/internal/production-runtime";
|
|
34
34
|
import type { FarmMCPUserConfig } from "@farm.js/core/server";
|
|
35
35
|
export type { FarmRscPluginOptions, EntryContext };
|
|
36
36
|
export { buildRscNitro, waitForRscManifest, waitForRscOutputs } from "./nitro-build.js";
|
|
@@ -44,6 +44,12 @@ export interface FarmRscConfig {
|
|
|
44
44
|
layers?: readonly ResolvedFarmLayer[];
|
|
45
45
|
outDir?: string;
|
|
46
46
|
basePath?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Same as core's `trailingSlash`: pages answer at `/about/`, `<Link>` renders that URL, and
|
|
49
|
+
* `/about` redirects (308) to it. Without it, `/about/` redirects to `/about`.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
trailingSlash?: boolean;
|
|
47
53
|
api?: FarmAPIConfig;
|
|
48
54
|
server?: FarmServerConfig;
|
|
49
55
|
middleware?: FarmMiddlewareConfig;
|
|
@@ -96,12 +102,14 @@ export interface FarmRscConfig {
|
|
|
96
102
|
/**
|
|
97
103
|
* Agent-facing files. `llmsTxt` serves `/llms.txt`, an index of the app's
|
|
98
104
|
* static pages that links to their Markdown mirrors, and with `full: true`
|
|
99
|
-
* also `/llms-full.txt`, which inlines them.
|
|
100
|
-
* `agent.llmsTxt
|
|
101
|
-
*
|
|
105
|
+
* also `/llms-full.txt`, which inlines them. `sitemap` serves `/sitemap.xml`
|
|
106
|
+
* of the same pages. Same options as core's `agent.llmsTxt` and
|
|
107
|
+
* `agent.sitemap`; `false` turns each off.
|
|
108
|
+
* @default { llmsTxt: { full: false }, sitemap: true }
|
|
102
109
|
*/
|
|
103
110
|
agent?: {
|
|
104
111
|
llmsTxt?: boolean | FarmLlmsTxtUserConfig;
|
|
112
|
+
sitemap?: boolean | FarmAgentSitemapUserConfig;
|
|
105
113
|
};
|
|
106
114
|
/**
|
|
107
115
|
* An MCP endpoint for agents, with the same options as core's top-level
|
|
@@ -114,6 +122,10 @@ export interface FarmRscConfig {
|
|
|
114
122
|
mobileClient?: FarmRscMobileClient;
|
|
115
123
|
/** @internal See `FarmRscPluginOptions.clientPlugins`; set by `farm dev` and `farm build`. */
|
|
116
124
|
clientPlugins?: FarmRscClientPlugins;
|
|
125
|
+
/** @internal See `FarmRscPluginOptions.serverPlugins`; set by `farm build`. */
|
|
126
|
+
serverPlugins?: FarmRscServerPlugins;
|
|
127
|
+
/** @internal See `FarmRscPluginOptions.preset`; set by `farm build`. */
|
|
128
|
+
preset?: string;
|
|
117
129
|
}
|
|
118
130
|
/**
|
|
119
131
|
* 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,EACV,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rsc/index.ts"],"names":[],"mappings":"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"}
|
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 { CLIENT_ENTRY_CORE_IMPORTS, generateClientEntry, serverFnTransportErrorClientRuntime, } from "./entries/client.js";
|
|
35
|
+
import { CLIENT_ENTRY_CORE_IMPORTS, CLIENT_ENTRY_I18N_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";
|
|
@@ -55,7 +57,7 @@ const { farmMiddlewarePlugin } = require_("@farm.js/core/middleware");
|
|
|
55
57
|
const { resolveServerActionsConfig, validateServerActionRequest, createServerActionRequestErrorResponse, } = require_("@farm.js/core/server-action-security");
|
|
56
58
|
const { normalizeFarmDeploymentId } = require_("@farm.js/core/deployment");
|
|
57
59
|
const { getFarmLayerAliases, getFarmSourceRoots, resolveFarmLayers, resolveFarmMCPConfig, resolveFarmMCPPlugin, } = require_("@farm.js/core/server");
|
|
58
|
-
const { readNodeRequestBody, resolveFarmServerConfig, resolveFarmI18nConfig, createFarmRequestBodyErrorResponse, createDefaultErrorMarkup, resolveFarmLlmsTxtConfig, } = require_("@farm.js/core/internal/production-runtime");
|
|
60
|
+
const { readNodeRequestBody, resolveFarmServerConfig, resolveFarmI18nConfig, createFarmRequestBodyErrorResponse, createDefaultErrorMarkup, resolveFarmLlmsTxtConfig, resolveFarmAgentSitemap, } = require_("@farm.js/core/internal/production-runtime");
|
|
59
61
|
const { isFarmAPIPathname } = require_("@farm.js/core/api/runtime");
|
|
60
62
|
const { resolveFarmAPIConfig, resolveFarmAPIServerBasePath } = require_("@farm.js/core/api");
|
|
61
63
|
const { getResolvedEnv } = require_("@farm.js/core/env");
|
|
@@ -85,6 +87,7 @@ export function defineConfig(config = {}) {
|
|
|
85
87
|
layers: config.layers,
|
|
86
88
|
outDir: config.outDir ?? "dist",
|
|
87
89
|
basePath: config.basePath ?? "/",
|
|
90
|
+
trailingSlash: config.trailingSlash,
|
|
88
91
|
api: config.api,
|
|
89
92
|
serverActions: config.serverActions,
|
|
90
93
|
deploymentId: config.deploymentId,
|
|
@@ -133,6 +136,8 @@ export function defineConfig(config = {}) {
|
|
|
133
136
|
entries: config.entries,
|
|
134
137
|
mobileClient: config.mobileClient,
|
|
135
138
|
clientPlugins: config.clientPlugins,
|
|
139
|
+
serverPlugins: config.serverPlugins,
|
|
140
|
+
preset: config.preset,
|
|
136
141
|
}),
|
|
137
142
|
...(Array.isArray(config.plugins) ? config.plugins : []),
|
|
138
143
|
],
|
|
@@ -212,6 +217,7 @@ const OPTIMIZED_BOUNDARY_ADAPTER = "@farm.js/plugin/rsc/optimized-boundary";
|
|
|
212
217
|
const STRATA_PACKAGE = "@farming-labs/strata";
|
|
213
218
|
const RSC_MIDDLEWARE_CONFIG_QUERY = "?farm-rsc-middleware";
|
|
214
219
|
const RSC_MCP_CONFIG_QUERY = "?farm-rsc-mcp";
|
|
220
|
+
const RSC_PLUGINS_CONFIG_QUERY = "?farm-rsc-plugins";
|
|
215
221
|
const FARM_CORE_PACKAGE_ROOT = path.resolve(path.dirname(require_.resolve("@farm.js/core")), "..");
|
|
216
222
|
const FARM_CONFIG_FILENAMES = [
|
|
217
223
|
"farm.config.ts",
|
|
@@ -538,6 +544,7 @@ export default function farmRsc(options = {}) {
|
|
|
538
544
|
const debug = options.debug ?? false;
|
|
539
545
|
const automaticDeploymentId = `build-${Date.now()}`;
|
|
540
546
|
const supportsBuildAppHook = Number(viteVersion.split(".")[0]) >= 7;
|
|
547
|
+
const resolveNitroPreset = () => options.preset || process.env.NITRO_PRESET || "vercel";
|
|
541
548
|
const runNitroAfterApplicationBuild = async (builder) => {
|
|
542
549
|
const nitroEnabled = builder.config?.plugins?.some((plugin) => plugin.name === "vite-plugin-nitro");
|
|
543
550
|
if (!nitroEnabled || !rscBuildRoot)
|
|
@@ -625,11 +632,20 @@ export default function farmRsc(options = {}) {
|
|
|
625
632
|
farmEnvironmentFunctionsPlugin(),
|
|
626
633
|
rscPrivateClientSourcemaps(),
|
|
627
634
|
createFarmRscMobileClientManifestPlugin(() => mobileClientRoot),
|
|
635
|
+
{
|
|
636
|
+
// A Worker bundles React and has no NODE_ENV of its own, and `wrangler pages dev` defines it
|
|
637
|
+
// as "development": keep only React's production builds, as core's Workers builds do.
|
|
638
|
+
...createReactProductionModePlugin(),
|
|
639
|
+
enforce: "pre",
|
|
640
|
+
apply: (_config, env) => env.command === "build" && isRscWorkersPreset(resolveNitroPreset()),
|
|
641
|
+
},
|
|
628
642
|
{
|
|
629
643
|
name: "@farm.js/plugin/rsc:middleware-config",
|
|
630
644
|
enforce: "pre",
|
|
631
645
|
resolveId(id) {
|
|
632
|
-
if (!id.endsWith(RSC_MIDDLEWARE_CONFIG_QUERY) &&
|
|
646
|
+
if (!id.endsWith(RSC_MIDDLEWARE_CONFIG_QUERY) &&
|
|
647
|
+
!id.endsWith(RSC_MCP_CONFIG_QUERY) &&
|
|
648
|
+
!id.endsWith(RSC_PLUGINS_CONFIG_QUERY)) {
|
|
633
649
|
return null;
|
|
634
650
|
}
|
|
635
651
|
return id.replace(/\\/g, "/");
|
|
@@ -765,6 +781,30 @@ export default function farmRsc(options = {}) {
|
|
|
765
781
|
"Declare middleware directly in defineConfig({ middleware: ... }) or move it to src/app/middleware.ts.");
|
|
766
782
|
}
|
|
767
783
|
}
|
|
784
|
+
// Loading a plugin runs its factory in the server, which is how a plugin such as `bot()`
|
|
785
|
+
// registers what its server functions use. Only the entries with server hooks and the
|
|
786
|
+
// bindings they read are bundled, as for middleware.
|
|
787
|
+
const pluginsConfigPaths = [];
|
|
788
|
+
if (options.serverPlugins && env.command === "build") {
|
|
789
|
+
for (const configPath of await resolveMiddlewareConfigPaths(root, c.layers)) {
|
|
790
|
+
const selection = options.serverPlugins[path.resolve(configPath)];
|
|
791
|
+
if (!selection)
|
|
792
|
+
continue;
|
|
793
|
+
const extracted = await loadRscConfigPropertyModule(configPath, "plugins", selection);
|
|
794
|
+
if (extracted.kind !== "module") {
|
|
795
|
+
throw new Error(`[Farm.js] Cannot read plugins for the RSC server from ${configPath}: ${extracted.kind === "absent"
|
|
796
|
+
? "the config has no plugins property"
|
|
797
|
+
: extracted.reason}. Declare plugins directly in defineConfig({ plugins: [...] }).`);
|
|
798
|
+
}
|
|
799
|
+
const moduleId = `${configPath.replace(/\\/g, "/")}${RSC_PLUGINS_CONFIG_QUERY}`;
|
|
800
|
+
middlewareConfigModules.set(moduleId, extracted.code);
|
|
801
|
+
pluginsConfigPaths.push(moduleId);
|
|
802
|
+
}
|
|
803
|
+
if (pluginsConfigPaths.length < Object.keys(options.serverPlugins).length) {
|
|
804
|
+
throw new Error("[Farm.js] The RSC server could not find every config file with plugins to load. " +
|
|
805
|
+
"Declare plugins directly in defineConfig({ plugins: [...] }) in farm.config.ts.");
|
|
806
|
+
}
|
|
807
|
+
}
|
|
768
808
|
// Read user's directory configuration
|
|
769
809
|
const api = await resolveFarmAPIConfig(c.api, {
|
|
770
810
|
root,
|
|
@@ -811,6 +851,10 @@ export default function farmRsc(options = {}) {
|
|
|
811
851
|
// runtime cannot see from module exports: the same baked input core's server merges.
|
|
812
852
|
// Later roots override earlier ones, as the entry's merged page map does.
|
|
813
853
|
const pageRenderingDirectives = {};
|
|
854
|
+
// Core's default for an app without docs, as for llms.txt: the sitemap is on.
|
|
855
|
+
const sitemap = resolveFarmAgentSitemap(c.agent?.sitemap ?? true);
|
|
856
|
+
// Each page file's last change, for the sitemap's lastmod, as core's build reads it.
|
|
857
|
+
const pageLastModified = {};
|
|
814
858
|
for (const source of getFarmSourceRoots(c)) {
|
|
815
859
|
const routesRoot = path.resolve(root, source.srcDir, configuredRoutesDir);
|
|
816
860
|
for (const { key, file } of await findRouteFiles(routesRoot, (name) => PAGE_FILE.test(name))) {
|
|
@@ -819,6 +863,13 @@ export default function farmRsc(options = {}) {
|
|
|
819
863
|
pageRenderingDirectives[key] = directive;
|
|
820
864
|
else
|
|
821
865
|
delete pageRenderingDirectives[key];
|
|
866
|
+
if (sitemap.enabled) {
|
|
867
|
+
const modified = await fs.stat(file).then((stat) => stat.mtime.toISOString(), () => undefined);
|
|
868
|
+
if (modified)
|
|
869
|
+
pageLastModified[key] = modified;
|
|
870
|
+
else
|
|
871
|
+
delete pageLastModified[key];
|
|
872
|
+
}
|
|
822
873
|
}
|
|
823
874
|
}
|
|
824
875
|
// Root layouts that render <html> own the document (Next.js's root layout contract).
|
|
@@ -827,7 +878,13 @@ export default function farmRsc(options = {}) {
|
|
|
827
878
|
];
|
|
828
879
|
// The same images contract as core: without Sharp, "auto" keeps original URLs
|
|
829
880
|
// (provider "none") instead of pointing <Image> at an optimizer that cannot run.
|
|
830
|
-
const nitroPreset =
|
|
881
|
+
const nitroPreset = resolveNitroPreset();
|
|
882
|
+
// Workers have no node_modules: the server bundles include their packages, built for
|
|
883
|
+
// workerd instead of Node.
|
|
884
|
+
const workersBuild = env.command === "build" && isRscWorkersPreset(nitroPreset);
|
|
885
|
+
if (workersBuild && optimizedBoundaryEnabled) {
|
|
886
|
+
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\`.`);
|
|
887
|
+
}
|
|
831
888
|
const imageConfig = resolveFarmImageConfig(resolveFarmImageProviderForRuntime(c.images, {
|
|
832
889
|
root,
|
|
833
890
|
preset: nitroPreset,
|
|
@@ -846,6 +903,22 @@ export default function farmRsc(options = {}) {
|
|
|
846
903
|
if (env.command === "build" && mobileClient !== "entry") {
|
|
847
904
|
removeFarmRscMobileClientManifest(root);
|
|
848
905
|
}
|
|
906
|
+
// Resolved the same way core resolves it for the config, so RSC and
|
|
907
|
+
// non-RSC apps match middleware against the same pathname.
|
|
908
|
+
const i18n = resolveFarmI18nConfig(c.i18n, {
|
|
909
|
+
root,
|
|
910
|
+
mode: env.command === "serve" ? "development" : "production",
|
|
911
|
+
basePath: c.basePath ?? "/",
|
|
912
|
+
});
|
|
913
|
+
// A build inlines the catalogs, read and validated as core's build reads them (a strict
|
|
914
|
+
// mismatch fails the build), so the server needs no catalog files.
|
|
915
|
+
let i18nCatalogs;
|
|
916
|
+
if (i18n.enabled && env.command === "build") {
|
|
917
|
+
const { createFarmI18nRuntime } = require_("@farm.js/core/i18n/server");
|
|
918
|
+
const catalogRuntime = createFarmI18nRuntime(i18n);
|
|
919
|
+
await catalogRuntime.initialize();
|
|
920
|
+
i18nCatalogs = catalogRuntime.getCatalogs();
|
|
921
|
+
}
|
|
849
922
|
// Development always optimizes with Sharp, as core's dev server does.
|
|
850
923
|
const imageRuntime = env.command === "serve"
|
|
851
924
|
? imageConfig.provider === "none"
|
|
@@ -856,6 +929,7 @@ export default function farmRsc(options = {}) {
|
|
|
856
929
|
entryContext = {
|
|
857
930
|
documentLayouts,
|
|
858
931
|
pageRenderingDirectives,
|
|
932
|
+
...(workersBuild ? { workers: true } : {}),
|
|
859
933
|
images: {
|
|
860
934
|
config: imageConfig,
|
|
861
935
|
public: publicImageConfig,
|
|
@@ -865,6 +939,7 @@ export default function farmRsc(options = {}) {
|
|
|
865
939
|
srcDir,
|
|
866
940
|
outDir,
|
|
867
941
|
basePath: c.basePath ?? "/",
|
|
942
|
+
trailingSlash: c.trailingSlash === true,
|
|
868
943
|
apiBasePath: resolveFarmAPIServerBasePath(api),
|
|
869
944
|
routesDir: options.routesDir,
|
|
870
945
|
globalCssPath,
|
|
@@ -879,15 +954,13 @@ export default function farmRsc(options = {}) {
|
|
|
879
954
|
markdown: resolveMarkdownConfig(c.md),
|
|
880
955
|
// Core's default for an app without docs: llms.txt on, llms-full.txt off.
|
|
881
956
|
llmsTxt: resolveFarmLlmsTxtConfig(c.agent?.llmsTxt ?? { full: false }),
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
i18n
|
|
885
|
-
|
|
886
|
-
mode: env.command === "serve" ? "development" : "production",
|
|
887
|
-
basePath: c.basePath ?? "/",
|
|
888
|
-
}),
|
|
957
|
+
sitemap,
|
|
958
|
+
...(sitemap.enabled ? { pageLastModified } : {}),
|
|
959
|
+
i18n,
|
|
960
|
+
...(i18nCatalogs ? { i18nCatalogs } : {}),
|
|
889
961
|
server: { trustProxy: resolveFarmServerConfig(c.server).trustProxy },
|
|
890
962
|
middlewareConfigPaths,
|
|
963
|
+
pluginsConfigPaths,
|
|
891
964
|
debug,
|
|
892
965
|
development: env.command === "serve",
|
|
893
966
|
clientCachePersistence: generateClientCachePersistenceCode(resolveFarmClientCacheAdapterEntry(root, c.cache)),
|
|
@@ -937,18 +1010,23 @@ export default function farmRsc(options = {}) {
|
|
|
937
1010
|
__FARM_API_BASE_URL__: JSON.stringify(api.baseURL),
|
|
938
1011
|
__FARM_IMAGE_CONFIG__: JSON.stringify(entryContext.images?.public),
|
|
939
1012
|
},
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1013
|
+
// A Workers build bundles React too: there is no node_modules to load it from.
|
|
1014
|
+
...(workersBuild
|
|
1015
|
+
? {}
|
|
1016
|
+
: {
|
|
1017
|
+
ssr: {
|
|
1018
|
+
external: [
|
|
1019
|
+
"react",
|
|
1020
|
+
"react-dom",
|
|
1021
|
+
"react-dom/server",
|
|
1022
|
+
"react/jsx-runtime",
|
|
1023
|
+
"react/jsx-dev-runtime",
|
|
1024
|
+
...(optimizedBoundaryEnabled
|
|
1025
|
+
? [STRATA_PACKAGE, `${STRATA_PACKAGE}/react-server`]
|
|
1026
|
+
: []),
|
|
1027
|
+
],
|
|
1028
|
+
},
|
|
1029
|
+
}),
|
|
952
1030
|
...(optimizedBoundaryEnabled
|
|
953
1031
|
? {
|
|
954
1032
|
optimizeDeps: {
|
|
@@ -1038,7 +1116,10 @@ export default function farmRsc(options = {}) {
|
|
|
1038
1116
|
rollupOptions: { input: { index: entryRsc } },
|
|
1039
1117
|
},
|
|
1040
1118
|
resolve: {
|
|
1041
|
-
conditions:
|
|
1119
|
+
conditions: workersBuild
|
|
1120
|
+
? ["react-server", "workerd", "worker", "import", "module"]
|
|
1121
|
+
: ["react-server", "node", "import"],
|
|
1122
|
+
...(workersBuild ? { noExternal: true } : {}),
|
|
1042
1123
|
// Strata is a native CommonJS loader: Node must load it, not Vite's
|
|
1043
1124
|
// module runner. ssr.external does not reach this environment.
|
|
1044
1125
|
...(optimizedBoundaryEnabled
|
|
@@ -1052,7 +1133,9 @@ export default function farmRsc(options = {}) {
|
|
|
1052
1133
|
copyPublicDir: false,
|
|
1053
1134
|
rollupOptions: { input: { index: entrySsr } },
|
|
1054
1135
|
},
|
|
1055
|
-
resolve:
|
|
1136
|
+
resolve: workersBuild
|
|
1137
|
+
? { conditions: ["workerd", "worker", "import", "module"], noExternal: true }
|
|
1138
|
+
: { conditions: ["node", "import"] },
|
|
1056
1139
|
},
|
|
1057
1140
|
client: {
|
|
1058
1141
|
build: {
|
|
@@ -1079,6 +1162,7 @@ export default function farmRsc(options = {}) {
|
|
|
1079
1162
|
"react-dom/client",
|
|
1080
1163
|
"rsc-html-stream/client",
|
|
1081
1164
|
...CLIENT_ENTRY_CORE_IMPORTS,
|
|
1165
|
+
...(i18n.enabled ? CLIENT_ENTRY_I18N_IMPORTS : []),
|
|
1082
1166
|
// Client components and the packages they use load only once a page renders
|
|
1083
1167
|
// (client references), so they would be found late too.
|
|
1084
1168
|
...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
|
@@ -7,7 +7,9 @@ import path from "path";
|
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
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
|
|
@@ -520,6 +522,21 @@ function removeSeedOutput(nitro, fileName) {
|
|
|
520
522
|
rmSync(target, { recursive: true });
|
|
521
523
|
}
|
|
522
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
|
+
}
|
|
523
540
|
export async function buildRscNitro(options) {
|
|
524
541
|
const { rendererPath, publicDir, ssrPath, assetsDir, root, preset = "vercel" } = options;
|
|
525
542
|
const outputDir = options.outputDir ?? path.join(root, ".output");
|
|
@@ -529,7 +546,9 @@ export async function buildRscNitro(options) {
|
|
|
529
546
|
// Vercel's Build Output API has its own layout (functions/, static/), which the preset owns when
|
|
530
547
|
// the caller names the deployment directory (`farm build`). Without one, the output keeps the
|
|
531
548
|
// server/ and public/ layout that hand-written post-build scripts copy from.
|
|
532
|
-
|
|
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;
|
|
533
552
|
// The server sets NODE_ENV to "production" unless the deployment chose one, as the core
|
|
534
553
|
// node-server output does. The RSC and SSR bundles read it at runtime: left unset, React loads
|
|
535
554
|
// its development builds and Flight responses carry server component props, stacks and paths.
|
|
@@ -588,7 +607,10 @@ export async function buildRscNitro(options) {
|
|
|
588
607
|
},
|
|
589
608
|
},
|
|
590
609
|
compatibilityDate: "2024-12-01",
|
|
591
|
-
|
|
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,
|
|
592
614
|
};
|
|
593
615
|
if (ssrPath) {
|
|
594
616
|
patchRscServerBundles(path.resolve(root), path.dirname(path.resolve(rendererPath)), path.dirname(path.resolve(ssrPath)), publicDir, assetsDir);
|
|
@@ -607,7 +629,9 @@ export async function buildRscNitro(options) {
|
|
|
607
629
|
}
|
|
608
630
|
await build(nitro);
|
|
609
631
|
await nitro.close();
|
|
610
|
-
|
|
632
|
+
// A Workers build includes its packages in the bundles, and Workers can't read node_modules.
|
|
633
|
+
if (!workers)
|
|
634
|
+
copyRuntimePackages(serverDir, registeredRuntimePackages);
|
|
611
635
|
// Copy dist into server so runtime relative imports resolve. Handle missing dir (e.g. buildApp order).
|
|
612
636
|
const serverDistDir = path.join(serverDir, "dist");
|
|
613
637
|
const rscSrc = path.dirname(path.resolve(rendererPath));
|
|
@@ -616,7 +640,8 @@ export async function buildRscNitro(options) {
|
|
|
616
640
|
copyDir(rscSrc, path.join(serverDistDir, "rsc"));
|
|
617
641
|
if (ssrSrc)
|
|
618
642
|
copyDir(ssrSrc, path.join(serverDistDir, "ssr"));
|
|
619
|
-
|
|
643
|
+
if (!workers)
|
|
644
|
+
await traceRscBundleDependencies(root, serverDir, rscSrc, ssrSrc);
|
|
620
645
|
// Stub manifest if missing (RSC plugin may write it after our hook runs)
|
|
621
646
|
const rscDestDir = path.join(serverDistDir, "rsc");
|
|
622
647
|
const manifestDest = path.join(rscDestDir, "__vite_rsc_assets_manifest.js");
|
|
@@ -627,6 +652,8 @@ export async function buildRscNitro(options) {
|
|
|
627
652
|
// Nitro may group the entry differently by builder. Make copied-dist imports
|
|
628
653
|
// relative to the emitted chunk so output survives moving away from the project.
|
|
629
654
|
rewriteRscEntryImports(serverDir, serverDistDir);
|
|
655
|
+
if (workers)
|
|
656
|
+
populateWorkerProcessEnv(serverDir);
|
|
630
657
|
console.log("[FARM] RSC Nitro build completed");
|
|
631
658
|
console.log(`[FARM] Output: ${outputDir}`);
|
|
632
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
|
+
}
|