@farm.js/plugin 0.1.67 → 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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +5 -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 +5 -1
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +73 -16
- 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 +23 -0
- package/dist/rsc/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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 {
|
|
@@ -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";
|
|
@@ -114,6 +114,10 @@ export interface FarmRscConfig {
|
|
|
114
114
|
mobileClient?: FarmRscMobileClient;
|
|
115
115
|
/** @internal See `FarmRscPluginOptions.clientPlugins`; set by `farm dev` and `farm build`. */
|
|
116
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;
|
|
117
121
|
}
|
|
118
122
|
/**
|
|
119
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,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":"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,kBAA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QACR,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,gHAAgH;IAChH,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB;;;;OAIG;IACH,EAAE,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACtC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAA;KAAE,CAAC;IACtD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,iBAAiB,CAAC;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,6 +24,8 @@ 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";
|
|
@@ -133,6 +135,8 @@ export function defineConfig(config = {}) {
|
|
|
133
135
|
entries: config.entries,
|
|
134
136
|
mobileClient: config.mobileClient,
|
|
135
137
|
clientPlugins: config.clientPlugins,
|
|
138
|
+
serverPlugins: config.serverPlugins,
|
|
139
|
+
preset: config.preset,
|
|
136
140
|
}),
|
|
137
141
|
...(Array.isArray(config.plugins) ? config.plugins : []),
|
|
138
142
|
],
|
|
@@ -212,6 +216,7 @@ const OPTIMIZED_BOUNDARY_ADAPTER = "@farm.js/plugin/rsc/optimized-boundary";
|
|
|
212
216
|
const STRATA_PACKAGE = "@farming-labs/strata";
|
|
213
217
|
const RSC_MIDDLEWARE_CONFIG_QUERY = "?farm-rsc-middleware";
|
|
214
218
|
const RSC_MCP_CONFIG_QUERY = "?farm-rsc-mcp";
|
|
219
|
+
const RSC_PLUGINS_CONFIG_QUERY = "?farm-rsc-plugins";
|
|
215
220
|
const FARM_CORE_PACKAGE_ROOT = path.resolve(path.dirname(require_.resolve("@farm.js/core")), "..");
|
|
216
221
|
const FARM_CONFIG_FILENAMES = [
|
|
217
222
|
"farm.config.ts",
|
|
@@ -538,6 +543,7 @@ export default function farmRsc(options = {}) {
|
|
|
538
543
|
const debug = options.debug ?? false;
|
|
539
544
|
const automaticDeploymentId = `build-${Date.now()}`;
|
|
540
545
|
const supportsBuildAppHook = Number(viteVersion.split(".")[0]) >= 7;
|
|
546
|
+
const resolveNitroPreset = () => options.preset || process.env.NITRO_PRESET || "vercel";
|
|
541
547
|
const runNitroAfterApplicationBuild = async (builder) => {
|
|
542
548
|
const nitroEnabled = builder.config?.plugins?.some((plugin) => plugin.name === "vite-plugin-nitro");
|
|
543
549
|
if (!nitroEnabled || !rscBuildRoot)
|
|
@@ -625,11 +631,20 @@ export default function farmRsc(options = {}) {
|
|
|
625
631
|
farmEnvironmentFunctionsPlugin(),
|
|
626
632
|
rscPrivateClientSourcemaps(),
|
|
627
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
|
+
},
|
|
628
641
|
{
|
|
629
642
|
name: "@farm.js/plugin/rsc:middleware-config",
|
|
630
643
|
enforce: "pre",
|
|
631
644
|
resolveId(id) {
|
|
632
|
-
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)) {
|
|
633
648
|
return null;
|
|
634
649
|
}
|
|
635
650
|
return id.replace(/\\/g, "/");
|
|
@@ -765,6 +780,30 @@ export default function farmRsc(options = {}) {
|
|
|
765
780
|
"Declare middleware directly in defineConfig({ middleware: ... }) or move it to src/app/middleware.ts.");
|
|
766
781
|
}
|
|
767
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
|
+
}
|
|
768
807
|
// Read user's directory configuration
|
|
769
808
|
const api = await resolveFarmAPIConfig(c.api, {
|
|
770
809
|
root,
|
|
@@ -827,7 +866,13 @@ export default function farmRsc(options = {}) {
|
|
|
827
866
|
];
|
|
828
867
|
// The same images contract as core: without Sharp, "auto" keeps original URLs
|
|
829
868
|
// (provider "none") instead of pointing <Image> at an optimizer that cannot run.
|
|
830
|
-
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
|
+
}
|
|
831
876
|
const imageConfig = resolveFarmImageConfig(resolveFarmImageProviderForRuntime(c.images, {
|
|
832
877
|
root,
|
|
833
878
|
preset: nitroPreset,
|
|
@@ -856,6 +901,7 @@ export default function farmRsc(options = {}) {
|
|
|
856
901
|
entryContext = {
|
|
857
902
|
documentLayouts,
|
|
858
903
|
pageRenderingDirectives,
|
|
904
|
+
...(workersBuild ? { workers: true } : {}),
|
|
859
905
|
images: {
|
|
860
906
|
config: imageConfig,
|
|
861
907
|
public: publicImageConfig,
|
|
@@ -888,6 +934,7 @@ export default function farmRsc(options = {}) {
|
|
|
888
934
|
}),
|
|
889
935
|
server: { trustProxy: resolveFarmServerConfig(c.server).trustProxy },
|
|
890
936
|
middlewareConfigPaths,
|
|
937
|
+
pluginsConfigPaths,
|
|
891
938
|
debug,
|
|
892
939
|
development: env.command === "serve",
|
|
893
940
|
clientCachePersistence: generateClientCachePersistenceCode(resolveFarmClientCacheAdapterEntry(root, c.cache)),
|
|
@@ -937,18 +984,23 @@ export default function farmRsc(options = {}) {
|
|
|
937
984
|
__FARM_API_BASE_URL__: JSON.stringify(api.baseURL),
|
|
938
985
|
__FARM_IMAGE_CONFIG__: JSON.stringify(entryContext.images?.public),
|
|
939
986
|
},
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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
|
+
}),
|
|
952
1004
|
...(optimizedBoundaryEnabled
|
|
953
1005
|
? {
|
|
954
1006
|
optimizeDeps: {
|
|
@@ -1038,7 +1090,10 @@ export default function farmRsc(options = {}) {
|
|
|
1038
1090
|
rollupOptions: { input: { index: entryRsc } },
|
|
1039
1091
|
},
|
|
1040
1092
|
resolve: {
|
|
1041
|
-
conditions:
|
|
1093
|
+
conditions: workersBuild
|
|
1094
|
+
? ["react-server", "workerd", "worker", "import", "module"]
|
|
1095
|
+
: ["react-server", "node", "import"],
|
|
1096
|
+
...(workersBuild ? { noExternal: true } : {}),
|
|
1042
1097
|
// Strata is a native CommonJS loader: Node must load it, not Vite's
|
|
1043
1098
|
// module runner. ssr.external does not reach this environment.
|
|
1044
1099
|
...(optimizedBoundaryEnabled
|
|
@@ -1052,7 +1107,9 @@ export default function farmRsc(options = {}) {
|
|
|
1052
1107
|
copyPublicDir: false,
|
|
1053
1108
|
rollupOptions: { input: { index: entrySsr } },
|
|
1054
1109
|
},
|
|
1055
|
-
resolve:
|
|
1110
|
+
resolve: workersBuild
|
|
1111
|
+
? { conditions: ["workerd", "worker", "import", "module"], noExternal: true }
|
|
1112
|
+
: { conditions: ["node", "import"] },
|
|
1056
1113
|
},
|
|
1057
1114
|
client: {
|
|
1058
1115
|
build: {
|
|
@@ -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
|
+
}
|
package/dist/rsc/types.d.ts
CHANGED
|
@@ -57,7 +57,23 @@ export interface FarmRscPluginOptions {
|
|
|
57
57
|
* and its `src/client.ts`, as core generates it for every entry.
|
|
58
58
|
*/
|
|
59
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;
|
|
60
71
|
}
|
|
72
|
+
/** @internal See `FarmRscPluginOptions.serverPlugins`. */
|
|
73
|
+
export type FarmRscServerPlugins = Record<string, {
|
|
74
|
+
indexes: number[];
|
|
75
|
+
count: number;
|
|
76
|
+
}>;
|
|
61
77
|
/** @internal See `FarmRscPluginOptions.mobileClient`. */
|
|
62
78
|
export type FarmRscMobileClient = "entry" | "inline";
|
|
63
79
|
/**
|
|
@@ -102,6 +118,11 @@ export interface EntryContext {
|
|
|
102
118
|
* page's source reads request state. The prerender pass merges these with module exports.
|
|
103
119
|
*/
|
|
104
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;
|
|
105
126
|
/**
|
|
106
127
|
* The resolved `images` config, its public half for `<Image>`, and the optimizer the server
|
|
107
128
|
* mounts at `images.path` (`none` when Image keeps original URLs).
|
|
@@ -139,6 +160,8 @@ export interface EntryContext {
|
|
|
139
160
|
middlewareConfigPaths?: string[];
|
|
140
161
|
/** Modules that export `{ mcp }`, read from the app's config files, in layer order. */
|
|
141
162
|
mcpConfigPaths?: string[];
|
|
163
|
+
/** Modules that export `{ plugins }`, read from the app's config files, in layer order. */
|
|
164
|
+
pluginsConfigPaths?: string[];
|
|
142
165
|
/** Resolved Markdown mirror settings (core's `md`): `.md` pages and `Accept: text/markdown`. */
|
|
143
166
|
markdown?: FarmMarkdownResolvedConfig;
|
|
144
167
|
/** Resolved `agent.llmsTxt`: the generated `/llms.txt` and `/llms-full.txt`. */
|
package/dist/rsc/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rsc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EACV,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,aAAa,CAAC,EAAE,uBAAuB,CAAC;IAExC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,2CAA2C;QAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAEnC;;;OAGG;IACH,aAAa,CAAC,EAAE,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rsc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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;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": {
|