@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.
Files changed (40) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/middleware/index.d.ts +8 -1
  4. package/dist/middleware/index.d.ts.map +1 -1
  5. package/dist/middleware/index.js +16 -10
  6. package/dist/middleware/matching.d.ts +4 -2
  7. package/dist/middleware/matching.d.ts.map +1 -1
  8. package/dist/middleware/matching.js +7 -47
  9. package/dist/rsc/client-sourcemaps.d.ts +13 -0
  10. package/dist/rsc/client-sourcemaps.d.ts.map +1 -0
  11. package/dist/rsc/client-sourcemaps.js +52 -0
  12. package/dist/rsc/document-layouts.d.ts +16 -0
  13. package/dist/rsc/document-layouts.d.ts.map +1 -0
  14. package/dist/rsc/document-layouts.js +82 -0
  15. package/dist/rsc/entries/client.d.ts.map +1 -1
  16. package/dist/rsc/entries/client.js +92 -16
  17. package/dist/rsc/entries/rsc.d.ts.map +1 -1
  18. package/dist/rsc/entries/rsc.js +567 -47
  19. package/dist/rsc/entries/ssr.d.ts.map +1 -1
  20. package/dist/rsc/entries/ssr.js +27 -10
  21. package/dist/rsc/index.d.ts +38 -3
  22. package/dist/rsc/index.d.ts.map +1 -1
  23. package/dist/rsc/index.js +300 -292
  24. package/dist/rsc/middleware-config-module.d.ts +3 -0
  25. package/dist/rsc/middleware-config-module.d.ts.map +1 -1
  26. package/dist/rsc/middleware-config-module.js +41 -28
  27. package/dist/rsc/mobile-client.d.ts +67 -0
  28. package/dist/rsc/mobile-client.d.ts.map +1 -0
  29. package/dist/rsc/mobile-client.js +148 -0
  30. package/dist/rsc/nitro-build.d.ts.map +1 -1
  31. package/dist/rsc/nitro-build.js +268 -81
  32. package/dist/rsc/server-fn-transform.d.ts +1 -5
  33. package/dist/rsc/server-fn-transform.d.ts.map +1 -1
  34. package/dist/rsc/server-fn-transform.js +3 -338
  35. package/dist/rsc/types.d.ts +39 -0
  36. package/dist/rsc/types.d.ts.map +1 -1
  37. package/dist/rsc/vite-plugin-nitro.d.ts +2 -0
  38. package/dist/rsc/vite-plugin-nitro.d.ts.map +1 -1
  39. package/dist/rsc/vite-plugin-nitro.js +12 -2
  40. package/package.json +3 -3
@@ -1,338 +1,3 @@
1
- const SERVER_FUNCTION_FACTORY_IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?(\{[^}]*\})\s+from\s*["']@farm.js\/core(?:\/(?:server-fn|server-query))?["']\s*;?/g;
2
- const EXPORT_SERVER_FUNCTION_FACTORY_RE = /\bexport\s+(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)\s*(?:<[^<>]*(?:<[^<>]*>[^<>]*)*>)?\s*\(/g;
3
- const EXPORT_DEFAULT_SERVER_FUNCTION_FACTORY_RE = /\bexport\s+default\s+([A-Za-z_$][\w$]*)\s*(?:<[^<>]*(?:<[^<>]*>[^<>]*)*>)?\s*\(/g;
4
- // Any assignment counts as a declaration, not only `const x = factory(...)`:
5
- // splitting `let save; save = createServerFn(...)` must not hide the binding
6
- // from the fail-closed export checks below.
7
- const SERVER_FUNCTION_DECLARATION_RE = /(?<![.\w$])([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)\s*(?:<[^<>]*(?:<[^<>]*>[^<>]*)*>)?\s*\(/g;
8
- const LOCAL_EXPORT_CLAUSE_RE = /\bexport\s*\{([^}]*)\}/g;
9
- const EXPORT_DEFAULT_ALIAS_RE = /\bexport\s+default\s+([A-Za-z_$][\w$]*)\s*(?:;|(?=[\r\n])|$)/g;
10
- const EXPORT_BINDING_ALIAS_RE = /\bexport\s+(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)\s*(?:;|(?=[,\r\n])|$)/g;
11
- const MODULE_EXT_RE = /\.[cm]?[jt]sx?$/;
12
- const DECLARATION_RE = /(^|\n)\s*["']([^"']+)["']\s*;?/g;
13
- export function transformFarmServerFns(code, id) {
14
- if (!isTransformableModule(id) ||
15
- (!code.includes("createServerFn") && !code.includes("createServerQuery"))) {
16
- return null;
17
- }
18
- const factoryNames = findServerFunctionFactoryImportNames(code);
19
- if (factoryNames.size === 0)
20
- return null;
21
- const reExport = findServerFnReExport(code, factoryNames);
22
- if (reExport) {
23
- const factoryName = reExport.factory === "fn" ? "createServerFn" : "createServerQuery";
24
- const escape = reExport.form === "clause"
25
- ? "with an export clause"
26
- : reExport.form === "default"
27
- ? "as the default export"
28
- : "through another exported binding";
29
- const inlineForm = reExport.form === "default"
30
- ? `export default ${factoryName}(...)`
31
- : `export const ${reExport.exportName} = ${factoryName}(...)`;
32
- throw new Error(`Server function "${reExport.localName}" cannot be re-exported ${escape}. ` +
33
- `Export it inline instead: ${inlineForm}.`);
34
- }
35
- const replacements = findServerFnExportReplacements(code, factoryNames);
36
- if (replacements.length === 0)
37
- return null;
38
- if (hasModuleDirective(code, "use client")) {
39
- throw new Error("createServerFn and createServerQuery exports must live in a server module. Move them out of the 'use client' file.");
40
- }
41
- let output = code;
42
- for (const replacement of [...replacements].sort((a, b) => b.start - a.start)) {
43
- output = output.slice(0, replacement.start) + replacement.code + output.slice(replacement.end);
44
- }
45
- if (!hasModuleDirective(output, "use server")) {
46
- output = `"use server";\n${output}`;
47
- }
48
- return {
49
- code: output,
50
- exports: replacements.map((replacement) => replacement.exportName),
51
- };
52
- }
53
- function isTransformableModule(id) {
54
- const cleanId = id.split("?", 1)[0];
55
- return MODULE_EXT_RE.test(cleanId) && !/\.d\.[cm]?ts$/.test(cleanId);
56
- }
57
- function findServerFunctionFactoryImportNames(code) {
58
- const names = new Map();
59
- for (const match of code.matchAll(SERVER_FUNCTION_FACTORY_IMPORT_RE)) {
60
- const importClause = match[1] ?? "";
61
- const namedStart = importClause.indexOf("{");
62
- const namedEnd = importClause.lastIndexOf("}");
63
- if (namedStart === -1 || namedEnd === -1 || namedEnd <= namedStart)
64
- continue;
65
- const namedImports = importClause.slice(namedStart + 1, namedEnd).split(",");
66
- for (const specifier of namedImports) {
67
- const normalized = specifier.trim().replace(/^type\s+/, "");
68
- const specifierMatch = normalized.match(/^(createServerFn|createServerQuery)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);
69
- if (specifierMatch) {
70
- const factory = specifierMatch[1];
71
- names.set(specifierMatch[2] ?? factory, factory === "createServerFn" ? "fn" : "query");
72
- }
73
- }
74
- }
75
- return names;
76
- }
77
- function findServerFnReExport(code, factoryNames) {
78
- // Comments and string contents must not hide or fake an export: a comment
79
- // inside `export { /* … */ save }` previously made the specifier unparsable
80
- // and the module shipped untransformed.
81
- const scannable = stripCommentsAndStrings(code);
82
- const declarations = new Map();
83
- for (const match of scannable.matchAll(SERVER_FUNCTION_DECLARATION_RE)) {
84
- const localName = match[1];
85
- const factoryName = match[2];
86
- const factory = factoryName ? factoryNames.get(factoryName) : undefined;
87
- if (localName && factory)
88
- declarations.set(localName, factory);
89
- }
90
- if (declarations.size === 0)
91
- return null;
92
- for (const match of scannable.matchAll(LOCAL_EXPORT_CLAUSE_RE)) {
93
- const clause = match[1] ?? "";
94
- const clauseEnd = (match.index ?? 0) + match[0].length;
95
- if (scannable.slice(clauseEnd).trimStart().startsWith("from"))
96
- continue;
97
- for (const specifier of clause.split(",")) {
98
- const parts = specifier.trim().split(/\s+as\s+/);
99
- const localName = parts[0]?.trim();
100
- if (!localName || !declarations.has(localName))
101
- continue;
102
- return {
103
- localName,
104
- exportName: parts[1]?.trim() || localName,
105
- factory: declarations.get(localName),
106
- form: "clause",
107
- };
108
- }
109
- }
110
- // `export default save;` — the export-default replacement only recognizes a
111
- // direct factory call, so a bare identifier slipped through untransformed.
112
- for (const match of scannable.matchAll(EXPORT_DEFAULT_ALIAS_RE)) {
113
- const localName = match[1];
114
- if (!localName || !declarations.has(localName))
115
- continue;
116
- return {
117
- localName,
118
- exportName: "default",
119
- factory: declarations.get(localName),
120
- form: "default",
121
- };
122
- }
123
- // `export const persist = save;` — same escape through a renamed binding.
124
- for (const match of scannable.matchAll(EXPORT_BINDING_ALIAS_RE)) {
125
- const exportName = match[1];
126
- const localName = match[2];
127
- if (!exportName || !localName || !declarations.has(localName))
128
- continue;
129
- return {
130
- localName,
131
- exportName,
132
- factory: declarations.get(localName),
133
- form: "binding",
134
- };
135
- }
136
- return null;
137
- }
138
- /**
139
- * Blank out comments and string/template contents, preserving length, so the
140
- * export scans above see only real syntax. Quotes themselves are kept; the
141
- * characters between them become spaces.
142
- */
143
- function stripCommentsAndStrings(code) {
144
- const output = code.split("");
145
- let quote = null;
146
- let lineComment = false;
147
- let blockComment = false;
148
- let escaped = false;
149
- for (let index = 0; index < code.length; index++) {
150
- const char = code[index];
151
- const next = code[index + 1];
152
- if (lineComment) {
153
- if (char === "\n" || char === "\r")
154
- lineComment = false;
155
- else
156
- output[index] = " ";
157
- continue;
158
- }
159
- if (blockComment) {
160
- if (char === "*" && next === "/") {
161
- blockComment = false;
162
- output[index] = " ";
163
- output[index + 1] = " ";
164
- index++;
165
- }
166
- else if (char !== "\n") {
167
- output[index] = " ";
168
- }
169
- continue;
170
- }
171
- if (quote) {
172
- if (escaped) {
173
- escaped = false;
174
- output[index] = " ";
175
- continue;
176
- }
177
- if (char === "\\") {
178
- escaped = true;
179
- output[index] = " ";
180
- continue;
181
- }
182
- if (char === quote) {
183
- quote = null;
184
- continue;
185
- }
186
- if (char !== "\n")
187
- output[index] = " ";
188
- continue;
189
- }
190
- if (char === "/" && next === "/") {
191
- lineComment = true;
192
- output[index] = " ";
193
- continue;
194
- }
195
- if (char === "/" && next === "*") {
196
- blockComment = true;
197
- output[index] = " ";
198
- continue;
199
- }
200
- if (char === "'" || char === '"' || char === "`") {
201
- quote = char;
202
- }
203
- }
204
- return output.join("");
205
- }
206
- function findServerFnExportReplacements(code, factoryNames) {
207
- const replacements = [];
208
- for (const match of code.matchAll(EXPORT_SERVER_FUNCTION_FACTORY_RE)) {
209
- const exportName = match[1];
210
- const calleeName = match[2];
211
- const factory = calleeName ? factoryNames.get(calleeName) : undefined;
212
- if (!exportName || !calleeName || !factory)
213
- continue;
214
- const openParenIndex = (match.index ?? 0) + match[0].length - 1;
215
- const callEnd = findMatchingParen(code, openParenIndex);
216
- if (callEnd === -1)
217
- continue;
218
- let declarationEnd = callEnd + 1;
219
- while (/\s/.test(code[declarationEnd] ?? ""))
220
- declarationEnd++;
221
- if (code[declarationEnd] === ";")
222
- declarationEnd++;
223
- const calleeIndex = code.indexOf(calleeName, match.index);
224
- const callExpression = code.slice(calleeIndex, callEnd + 1);
225
- const privateName = `$$farm_server_${factory}_${exportName}`;
226
- replacements.push({
227
- start: match.index ?? 0,
228
- end: declarationEnd,
229
- exportName,
230
- code: `const ${privateName} = ${callExpression};\nexport async function ${exportName}(input) {\n return ${privateName}(input);\n}\n${copyServerFunctionDescriptor(exportName, privateName)}`,
231
- });
232
- }
233
- // `export default createServerFn(...)` needs the same treatment. Without it the
234
- // module gets no "use server" directive and its handler ships to the client.
235
- for (const match of code.matchAll(EXPORT_DEFAULT_SERVER_FUNCTION_FACTORY_RE)) {
236
- const calleeName = match[1];
237
- const factory = calleeName ? factoryNames.get(calleeName) : undefined;
238
- if (!calleeName || !factory)
239
- continue;
240
- const openParenIndex = (match.index ?? 0) + match[0].length - 1;
241
- const callEnd = findMatchingParen(code, openParenIndex);
242
- if (callEnd === -1)
243
- continue;
244
- let declarationEnd = callEnd + 1;
245
- while (/\s/.test(code[declarationEnd] ?? ""))
246
- declarationEnd++;
247
- if (code[declarationEnd] === ";")
248
- declarationEnd++;
249
- const calleeIndex = code.indexOf(calleeName, match.index);
250
- const callExpression = code.slice(calleeIndex, callEnd + 1);
251
- const privateName = `$$farm_server_${factory}_default`;
252
- replacements.push({
253
- start: match.index ?? 0,
254
- end: declarationEnd,
255
- exportName: "default",
256
- code: `const ${privateName} = ${callExpression};\nexport default async function ${privateName}_export(input) {\n return ${privateName}(input);\n}\n${copyServerFunctionDescriptor(`${privateName}_export`, privateName)}`,
257
- });
258
- }
259
- return replacements;
260
- }
261
- /**
262
- * The exported wrapper replaces the factory's function, so it would lose the internal descriptor
263
- * that MCP and other non-browser callers read. Copy only that descriptor: the other server
264
- * function markers stay on the private binding, as before.
265
- */
266
- function copyServerFunctionDescriptor(target, source) {
267
- const key = 'Symbol.for("farm.server-function.descriptor")';
268
- return `Object.defineProperty(${target}, ${key}, { value: ${source}[${key}] });`;
269
- }
270
- function hasModuleDirective(code, directive) {
271
- for (const match of code.matchAll(DECLARATION_RE)) {
272
- const value = match[2];
273
- if (value === directive)
274
- return true;
275
- if (value !== "use strict" && value !== "use client" && value !== "use server")
276
- return false;
277
- }
278
- return false;
279
- }
280
- function findMatchingParen(code, openParenIndex) {
281
- let depth = 0;
282
- let quote = null;
283
- let lineComment = false;
284
- let blockComment = false;
285
- let escaped = false;
286
- for (let index = openParenIndex; index < code.length; index++) {
287
- const char = code[index];
288
- const next = code[index + 1];
289
- if (lineComment) {
290
- if (char === "\n" || char === "\r")
291
- lineComment = false;
292
- continue;
293
- }
294
- if (blockComment) {
295
- if (char === "*" && next === "/") {
296
- blockComment = false;
297
- index++;
298
- }
299
- continue;
300
- }
301
- if (quote) {
302
- if (escaped) {
303
- escaped = false;
304
- continue;
305
- }
306
- if (char === "\\") {
307
- escaped = true;
308
- continue;
309
- }
310
- if (char === quote) {
311
- quote = null;
312
- }
313
- continue;
314
- }
315
- if (char === "/" && next === "/") {
316
- lineComment = true;
317
- index++;
318
- continue;
319
- }
320
- if (char === "/" && next === "*") {
321
- blockComment = true;
322
- index++;
323
- continue;
324
- }
325
- if (char === "'" || char === '"' || char === "`") {
326
- quote = char;
327
- continue;
328
- }
329
- if (char === "(")
330
- depth++;
331
- if (char === ")") {
332
- depth--;
333
- if (depth === 0)
334
- return index;
335
- }
336
- }
337
- return -1;
338
- }
1
+ // Server functions become "use server" boundaries in both engines: the transform lives in core,
2
+ // which islands mode runs without this plugin.
3
+ export * from "@farm.js/core/internal/server-fn-transform";
@@ -1,3 +1,5 @@
1
+ import type { FarmMarkdownResolvedConfig } from "@farm.js/core/markdown";
2
+ import type { ResolvedFarmLlmsTxtConfig } from "@farm.js/core/internal/production-runtime";
1
3
  import type { ResolvedFarmI18nConfig } from "@farm.js/core/i18n";
2
4
  import type { FarmServerActionsConfig, ResolvedFarmServerActionsConfig } from "@farm.js/core/server-action-security";
3
5
  /**
@@ -43,7 +45,16 @@ export interface FarmRscPluginOptions {
43
45
  * @default false
44
46
  */
45
47
  debug?: boolean;
48
+ /**
49
+ * @internal Set by `farm dev` and `farm build` for an app with a `mobile` block (RFC 0004).
50
+ * `"entry"`: the build adds a mobile client entry, which the server points the documents a
51
+ * mobile shell asks for (`X-Farm-Shell`) at. `"inline"`: the browser entry itself hands in-app
52
+ * navigations to the shell (`farm dev --mobile`).
53
+ */
54
+ mobileClient?: FarmRscMobileClient;
46
55
  }
56
+ /** @internal See `FarmRscPluginOptions.mobileClient`. */
57
+ export type FarmRscMobileClient = "entry" | "inline";
47
58
  /**
48
59
  * Internal context passed to entry generators.
49
60
  * Contains resolved configuration values needed to generate entry files.
@@ -67,6 +78,26 @@ export interface EntryContext {
67
78
  base: string;
68
79
  glob: string;
69
80
  }>;
81
+ /**
82
+ * Route-relative keys of the layouts that render the `<html>` document themselves
83
+ * (`/layout.tsx`). Below such a root layout the app owns the document, as in Next.js.
84
+ */
85
+ documentLayouts?: string[];
86
+ /**
87
+ * Route-relative page keys to their parsed rendering directive (`"use ssg"`) and whether the
88
+ * page's source reads request state. The prerender pass merges these with module exports.
89
+ */
90
+ pageRenderingDirectives?: Record<string, unknown>;
91
+ /**
92
+ * The resolved `images` config, its public half for `<Image>`, and the optimizer the server
93
+ * mounts at `images.path` (`none` when Image keeps original URLs).
94
+ */
95
+ images?: {
96
+ config: unknown;
97
+ public: unknown;
98
+ path: string;
99
+ runtime: "none" | "node" | "cloudflare";
100
+ };
70
101
  /** Whether server actions are enabled */
71
102
  actionsEnabled: boolean;
72
103
  /** Normalized server action request security policy. */
@@ -92,6 +123,12 @@ export interface EntryContext {
92
123
  * Farm's normal config merge order.
93
124
  */
94
125
  middlewareConfigPaths?: string[];
126
+ /** Modules that export `{ mcp }`, read from the app's config files, in layer order. */
127
+ mcpConfigPaths?: string[];
128
+ /** Resolved Markdown mirror settings (core's `md`): `.md` pages and `Accept: text/markdown`. */
129
+ markdown?: FarmMarkdownResolvedConfig;
130
+ /** Resolved `agent.llmsTxt`: the generated `/llms.txt` and `/llms-full.txt`. */
131
+ llmsTxt?: ResolvedFarmLlmsTxtConfig;
95
132
  /** Whether debug mode is enabled */
96
133
  debug: boolean;
97
134
  /** True only for the Vite serve command, never for a production build. */
@@ -101,6 +138,8 @@ export interface EntryContext {
101
138
  imports: string;
102
139
  init: string;
103
140
  };
141
+ /** The mobile client of an app with a `mobile` block (see `FarmRscPluginOptions`). */
142
+ mobileClient?: FarmRscMobileClient;
104
143
  }
105
144
  /**
106
145
  * Matched route information from the file-based router.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rsc/types.ts"],"names":[],"mappings":"AAAA,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;;;;OAI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IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAE/B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAEhB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0DAA0D;IAC1D,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC;IAEzB,wFAAwF;IACxF,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAEjC,yEAAyE;IACzE,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF,0DAA0D;IAC1D,WAAW,CAAC,EAAE;QACZ,EAAE,EAAE,OAAO,CAAC;QACZ,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IAEF,6CAA6C;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB,QAAQ,CAAC,OAAO,EAAE;YAChB,qCAAqC;YACrC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YAEhC,6CAA6C;YAC7C,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEhE,kDAAkD;YAClD,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC5D,CAAC;KACH;CACF"}
@@ -36,6 +36,8 @@ export interface NitroPluginOptions {
36
36
  };
37
37
  config?: {
38
38
  preset?: string;
39
+ /** Deployment output directory (default `.output`). */
40
+ outputDir?: string;
39
41
  };
40
42
  /** Base output dir when not using .nitro/vite/dist (fallback). */
41
43
  outDir?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-nitro.d.ts","sourceRoot":"","sources":["../../src/rsc/vite-plugin-nitro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAenC,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAqEtE;AAED,kFAAkF;AAClF,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkC1D"}
1
+ {"version":3,"file":"vite-plugin-nitro.d.ts","sourceRoot":"","sources":["../../src/rsc/vite-plugin-nitro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAenC,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,uDAAuD;QACvD,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CA8EtE;AAED,kFAAkF;AAClF,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAmC1D"}
@@ -48,10 +48,18 @@ export default function nitro(options = {}) {
48
48
  delete globalThis.__FARM_NITRO_SERVER_BUNDLE;
49
49
  delete globalThis.__FARM_NITRO_PATHS;
50
50
  delete globalThis.__FARM_NITRO_BUILD_PROMISE;
51
+ // The server entries are always index.js, which the Nitro step loads: Vite names an ESM
52
+ // server entry index.mjs when the app's package.json is not "type": "module". The Nitro
53
+ // output's package.json is "type": "module", so .js loads as ESM there.
54
+ const serverOutput = { output: { entryFileNames: "[name].js" } };
51
55
  return {
52
56
  environments: {
53
- rsc: { build: { outDir: path.join(NITRO_VITE_DIST, "rsc") } },
54
- ssr: { build: { outDir: path.join(NITRO_VITE_DIST, "ssr") } },
57
+ rsc: {
58
+ build: { outDir: path.join(NITRO_VITE_DIST, "rsc"), rolldownOptions: serverOutput },
59
+ },
60
+ ssr: {
61
+ build: { outDir: path.join(NITRO_VITE_DIST, "ssr"), rolldownOptions: serverOutput },
62
+ },
55
63
  client: { build: { outDir: path.join(NITRO_VITE_DIST, "client") } },
56
64
  },
57
65
  };
@@ -88,6 +96,7 @@ export default function nitro(options = {}) {
88
96
  clientOutDir,
89
97
  serverEntryName,
90
98
  preset: options.config?.preset ?? process.env.NITRO_PRESET ?? "vercel",
99
+ outputDir: options.config?.outputDir,
91
100
  clientAssetsDir,
92
101
  };
93
102
  }
@@ -144,5 +153,6 @@ async function runCapturedNitroBuild(paths, bundle) {
144
153
  ssrPath: resolveRscBuildOutputPath(root, paths.ssrOutDir, "index.js"),
145
154
  assetsDir: paths.clientAssetsDir ?? "assets",
146
155
  preset,
156
+ outputDir: paths.outputDir,
147
157
  });
148
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/plugin",
3
- "version": "0.1.61",
3
+ "version": "0.1.63",
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.61"
66
+ "@farm.js/core": "0.1.63"
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.61"
87
+ "@farm.js/core": "0.1.63"
88
88
  },
89
89
  "peerDependenciesMeta": {
90
90
  "@vitejs/plugin-rsc": {