@farm.js/plugin 0.1.61 → 0.1.63
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/middleware/index.d.ts +8 -1
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +16 -10
- package/dist/middleware/matching.d.ts +4 -2
- package/dist/middleware/matching.d.ts.map +1 -1
- package/dist/middleware/matching.js +7 -47
- package/dist/rsc/client-sourcemaps.d.ts +13 -0
- package/dist/rsc/client-sourcemaps.d.ts.map +1 -0
- package/dist/rsc/client-sourcemaps.js +52 -0
- package/dist/rsc/document-layouts.d.ts +16 -0
- package/dist/rsc/document-layouts.d.ts.map +1 -0
- package/dist/rsc/document-layouts.js +82 -0
- package/dist/rsc/entries/client.d.ts.map +1 -1
- package/dist/rsc/entries/client.js +92 -16
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +567 -47
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +27 -10
- package/dist/rsc/index.d.ts +38 -3
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +300 -292
- package/dist/rsc/middleware-config-module.d.ts +3 -0
- package/dist/rsc/middleware-config-module.d.ts.map +1 -1
- package/dist/rsc/middleware-config-module.js +41 -28
- package/dist/rsc/mobile-client.d.ts +67 -0
- package/dist/rsc/mobile-client.d.ts.map +1 -0
- package/dist/rsc/mobile-client.js +148 -0
- package/dist/rsc/nitro-build.d.ts.map +1 -1
- package/dist/rsc/nitro-build.js +268 -81
- package/dist/rsc/server-fn-transform.d.ts +1 -5
- package/dist/rsc/server-fn-transform.d.ts.map +1 -1
- package/dist/rsc/server-fn-transform.js +3 -338
- package/dist/rsc/types.d.ts +39 -0
- package/dist/rsc/types.d.ts.map +1 -1
- package/dist/rsc/vite-plugin-nitro.d.ts +2 -0
- package/dist/rsc/vite-plugin-nitro.d.ts.map +1 -1
- package/dist/rsc/vite-plugin-nitro.js +12 -2
- 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,CAgO1D"}
|
package/dist/rsc/entries/ssr.js
CHANGED
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export function generateSsrEntry(ctx) {
|
|
12
12
|
const debugLog = `// Debug disabled`;
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const globalsCssPath = ctx.globalCssPath ?? `/${ctx.srcDir}${routesPath}/globals.css`;
|
|
13
|
+
// Only a global stylesheet the build found: a guessed path 404s in apps that import their CSS.
|
|
14
|
+
const globalsCssPath = ctx.globalCssPath ?? "";
|
|
16
15
|
return `
|
|
17
16
|
import React from 'react';
|
|
18
17
|
import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr';
|
|
@@ -41,17 +40,26 @@ const cssLinkTag = resolvedCssHref
|
|
|
41
40
|
: '';
|
|
42
41
|
|
|
43
42
|
// Work on bytes: chunk boundaries need not align with UTF-8 code points.
|
|
44
|
-
function injectBeforeStream(markerText,
|
|
43
|
+
function injectBeforeStream(markerText, tagOrResolve) {
|
|
45
44
|
const encoder = new TextEncoder();
|
|
46
45
|
const marker = encoder.encode(markerText);
|
|
47
|
-
|
|
46
|
+
// A function is read when the marker passes, after the shell rendered.
|
|
47
|
+
let tag = typeof tagOrResolve === 'function' ? undefined : tagOrResolve;
|
|
48
|
+
let insertion = tag === undefined ? undefined : encoder.encode(tag);
|
|
49
|
+
const resolveTag = () => {
|
|
50
|
+
if (tag === undefined) {
|
|
51
|
+
tag = tagOrResolve();
|
|
52
|
+
insertion = encoder.encode(tag);
|
|
53
|
+
}
|
|
54
|
+
return tag;
|
|
55
|
+
};
|
|
48
56
|
let buffer = new Uint8Array(0);
|
|
49
57
|
let injected = false;
|
|
50
58
|
|
|
51
59
|
return new TransformStream({
|
|
52
60
|
transform(chunk, controller) {
|
|
53
61
|
const bytes = typeof chunk === 'string' ? encoder.encode(chunk) : chunk;
|
|
54
|
-
if (injected || !tag) {
|
|
62
|
+
if (injected || (typeof tagOrResolve !== 'function' && !tag)) {
|
|
55
63
|
controller.enqueue(bytes);
|
|
56
64
|
return;
|
|
57
65
|
}
|
|
@@ -69,7 +77,7 @@ function injectBeforeStream(markerText, tag) {
|
|
|
69
77
|
}
|
|
70
78
|
if (index >= 0) {
|
|
71
79
|
if (index) controller.enqueue(pending.subarray(0, index));
|
|
72
|
-
controller.enqueue(insertion);
|
|
80
|
+
if (resolveTag()) controller.enqueue(insertion);
|
|
73
81
|
controller.enqueue(pending.subarray(index));
|
|
74
82
|
buffer = new Uint8Array(0);
|
|
75
83
|
injected = true;
|
|
@@ -117,6 +125,8 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
117
125
|
// calls client references on the server (for example, a "use client" Counter).
|
|
118
126
|
const payload = await createFromReadableStream(s1);
|
|
119
127
|
const rootElement = payload.root;
|
|
128
|
+
// The route's resolved metadata as head tags (core's renderMetadataHead), then the stylesheet.
|
|
129
|
+
const headTags = (typeof payload.metadataHead === 'string' ? payload.metadataHead : '') + cssLinkTag;
|
|
120
130
|
|
|
121
131
|
function Root() {
|
|
122
132
|
return rootElement;
|
|
@@ -171,7 +181,12 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
171
181
|
passThrough.on('error', (e) => controller.error(e));
|
|
172
182
|
}
|
|
173
183
|
});
|
|
174
|
-
|
|
184
|
+
// In development, the stylesheets the shell's client components import (CSS modules come from
|
|
185
|
+
// JavaScript in the browser, so without links their HTML is unstyled until scripts run).
|
|
186
|
+
const devStyles = globalThis.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
187
|
+
let out = webStream.pipeThrough(
|
|
188
|
+
injectIntoHeadStream(typeof devStyles === 'function' ? () => headTags + devStyles() : headTags),
|
|
189
|
+
);
|
|
175
190
|
out = out.pipeThrough(injectRSCPayload(s2));
|
|
176
191
|
out = out.pipeThrough(streamingClientScriptInjector);
|
|
177
192
|
return out;
|
|
@@ -181,8 +196,10 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
181
196
|
debug('Rendering to HTML stream (then buffering)');
|
|
182
197
|
const fullHtmlRaw = await pipeableStreamToString(passThrough);
|
|
183
198
|
let fullHtml = fullHtmlRaw;
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
const bufferedDevStyles = globalThis.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
200
|
+
const bufferedHeadTags = headTags + (typeof bufferedDevStyles === 'function' ? bufferedDevStyles() : '');
|
|
201
|
+
if (bufferedHeadTags && fullHtml.includes("</head>")) {
|
|
202
|
+
fullHtml = fullHtml.replace("</head>", () => bufferedHeadTags + "</head>");
|
|
186
203
|
}
|
|
187
204
|
${ctx.actionsEnabled
|
|
188
205
|
? `// Ensure __viteRscCallServer is set before any module runs (fixes "is not a function" when form submits)
|
package/dist/rsc/index.d.ts
CHANGED
|
@@ -22,17 +22,22 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
import { type Plugin, type UserConfig } from "vite";
|
|
25
|
-
import type { FarmRscPluginOptions, EntryContext } from "./types.js";
|
|
25
|
+
import type { FarmRscPluginOptions, EntryContext, 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";
|
|
29
29
|
import type { FarmServerConfig } from "@farm.js/core/internal/production-runtime";
|
|
30
30
|
import type { FarmLayerEntry, ResolvedFarmLayer } from "@farm.js/core/server";
|
|
31
|
+
import { resolveFarmImageConfig } from "@farm.js/core/vite";
|
|
32
|
+
import { type FarmMarkdownUserConfig } from "@farm.js/core/markdown";
|
|
33
|
+
import type { FarmLlmsTxtUserConfig } from "@farm.js/core/internal/production-runtime";
|
|
34
|
+
import type { FarmMCPUserConfig } from "@farm.js/core/server";
|
|
31
35
|
export type { FarmRscPluginOptions, EntryContext };
|
|
32
36
|
export { buildRscNitro, waitForRscManifest, waitForRscOutputs } from "./nitro-build.js";
|
|
33
37
|
export type { BuildRscNitroOptions } from "./nitro-build.js";
|
|
34
38
|
export { default as nitro } from "./vite-plugin-nitro.js";
|
|
35
39
|
export type { NitroPluginOptions } from "./vite-plugin-nitro.js";
|
|
40
|
+
type FarmImageConfig = NonNullable<Parameters<typeof resolveFarmImageConfig>[0]>;
|
|
36
41
|
export interface FarmRscConfig {
|
|
37
42
|
srcDir?: string;
|
|
38
43
|
extends?: readonly FarmLayerEntry[];
|
|
@@ -42,13 +47,18 @@ export interface FarmRscConfig {
|
|
|
42
47
|
api?: FarmAPIConfig;
|
|
43
48
|
server?: FarmServerConfig;
|
|
44
49
|
middleware?: FarmMiddlewareConfig;
|
|
50
|
+
/** Same options as core's `images`: `<Image>` URLs and the optimizer at `images.path`. */
|
|
51
|
+
images?: FarmImageConfig;
|
|
45
52
|
port?: number;
|
|
46
53
|
experimental?: {
|
|
47
54
|
/**
|
|
48
|
-
* Enable React Server Components rendering.
|
|
55
|
+
* Enable React Server Components rendering. `{ mode: "rsc" }` is the same as `true`; this
|
|
56
|
+
* pipeline is the `"rsc"` engine of core's `experimental.serverComponents`.
|
|
49
57
|
* @default true
|
|
50
58
|
*/
|
|
51
|
-
serverComponents?: boolean
|
|
59
|
+
serverComponents?: boolean | {
|
|
60
|
+
mode: "rsc";
|
|
61
|
+
};
|
|
52
62
|
/**
|
|
53
63
|
* Enable React Server Actions and their public POST decoder.
|
|
54
64
|
* @default false
|
|
@@ -77,6 +87,31 @@ export interface FarmRscConfig {
|
|
|
77
87
|
};
|
|
78
88
|
/** Extra Vite plugins (e.g. rsc() with entries so client build resolves virtual:vite-rsc/client-references). */
|
|
79
89
|
plugins?: any[];
|
|
90
|
+
/**
|
|
91
|
+
* Markdown mirrors for agents: `/page.md` and `Accept: text/markdown`, with
|
|
92
|
+
* `?outline`, `?section`, `?max_tokens`, and `?actions`. Same options as core's `md`.
|
|
93
|
+
* @default true
|
|
94
|
+
*/
|
|
95
|
+
md?: FarmMarkdownUserConfig | boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Agent-facing files. `llmsTxt` serves `/llms.txt`, an index of the app's
|
|
98
|
+
* static pages that links to their Markdown mirrors, and with `full: true`
|
|
99
|
+
* also `/llms-full.txt`, which inlines them. Same options as core's
|
|
100
|
+
* `agent.llmsTxt`; `false` turns it off.
|
|
101
|
+
* @default { llmsTxt: { full: false } }
|
|
102
|
+
*/
|
|
103
|
+
agent?: {
|
|
104
|
+
llmsTxt?: boolean | FarmLlmsTxtUserConfig;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* An MCP endpoint for agents, with the same options as core's top-level
|
|
108
|
+
* `mcp`. Requires `@farm.js/mcp`. Declare it directly in this config object:
|
|
109
|
+
* the server reads it, and only the bindings it uses, from this file.
|
|
110
|
+
* `oauth` is not supported in RSC apps yet.
|
|
111
|
+
*/
|
|
112
|
+
mcp?: FarmMCPUserConfig;
|
|
113
|
+
/** @internal See `FarmRscPluginOptions.mobileClient`; set by `farm dev` and `farm build`. */
|
|
114
|
+
mobileClient?: FarmRscMobileClient;
|
|
80
115
|
}
|
|
81
116
|
/**
|
|
82
117
|
* 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,EAAE,oBAAoB,EAAE,YAAY,EAAE,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,EAAE,oBAAoB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC1F,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;AA0BvF,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,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