@farm.js/plugin 0.1.0-beta.104 → 0.1.0-beta.106
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/nitro-build.d.ts +2 -0
- package/dist/rsc/nitro-build.d.ts.map +1 -1
- package/dist/rsc/nitro-build.js +46 -35
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* self-contained even when the application does not install it directly.
|
|
9
9
|
*/
|
|
10
10
|
export declare function registerRscNitroRuntimePackage(root: string, packageName: string, packageRoot: string): void;
|
|
11
|
+
/** @internal */
|
|
12
|
+
export declare function rewriteRscEntryImports(serverDir: string, serverDistDir: string): void;
|
|
11
13
|
/**
|
|
12
14
|
* Wait for the RSC plugin to write the assets manifest to dist/rsc (it may run after closeBundle(ssr)).
|
|
13
15
|
* Polls until the file exists and size > MIN_MANIFEST_BYTES or timeout.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nitro-build.d.ts","sourceRoot":"","sources":["../../src/rsc/nitro-build.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,IAAI,CAKN;
|
|
1
|
+
{"version":3,"file":"nitro-build.d.ts","sourceRoot":"","sources":["../../src/rsc/nitro-build.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH;;;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,CA8BrF;AA4ED;;;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;AA2ED,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;AAEF,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyLhF"}
|
package/dist/rsc/nitro-build.js
CHANGED
|
@@ -39,6 +39,35 @@ function copyDir(src, dest, ignoredNames = new Set()) {
|
|
|
39
39
|
copyFileSync(srcPath, destPath);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
export function rewriteRscEntryImports(serverDir, serverDistDir) {
|
|
44
|
+
const entryChunkPaths = [];
|
|
45
|
+
const findEntryChunks = (dir) => {
|
|
46
|
+
if (!existsSync(dir))
|
|
47
|
+
return;
|
|
48
|
+
for (const name of readdirSync(dir)) {
|
|
49
|
+
const candidate = path.join(dir, name);
|
|
50
|
+
if (statSync(candidate).isDirectory())
|
|
51
|
+
findEntryChunks(candidate);
|
|
52
|
+
else if (name === "rsc-entry.mjs")
|
|
53
|
+
entryChunkPaths.push(candidate);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
for (const chunksDir of ["chunks", "_chunks", "_build"]) {
|
|
57
|
+
findEntryChunks(path.join(serverDir, chunksDir));
|
|
58
|
+
}
|
|
59
|
+
for (const entryChunkPath of entryChunkPaths) {
|
|
60
|
+
let code = readFileSync(entryChunkPath, "utf-8");
|
|
61
|
+
const relativeImport = (target) => {
|
|
62
|
+
const relative = path.relative(path.dirname(entryChunkPath), target).replace(/\\/g, "/");
|
|
63
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
64
|
+
};
|
|
65
|
+
// Match any path that ends with dist/rsc/index.js or dist/ssr/index.js (minified, no spaces)
|
|
66
|
+
code = code.replace(/(["'`])[^"'`]*?dist\/rsc\/index\.js\1/g, JSON.stringify(relativeImport(path.join(serverDistDir, "rsc", "index.js"))));
|
|
67
|
+
code = code.replace(/(["'`])[^"'`]*?dist\/ssr\/index\.js\1/g, JSON.stringify(relativeImport(path.join(serverDistDir, "ssr", "index.js"))));
|
|
68
|
+
writeFileSync(entryChunkPath, code, "utf-8");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
42
71
|
function detectBundledRscRuntimes(rendererPath) {
|
|
43
72
|
const packages = new Map();
|
|
44
73
|
const rendererDir = path.dirname(path.resolve(rendererPath));
|
|
@@ -194,7 +223,8 @@ const handler = getFetchHandler(entryExports);
|
|
|
194
223
|
|
|
195
224
|
function createRscRequest(event) {
|
|
196
225
|
const node = event.node;
|
|
197
|
-
|
|
226
|
+
const request = event.req?._request || event.req;
|
|
227
|
+
if (!node?.req || !node?.res) return request;
|
|
198
228
|
|
|
199
229
|
const controller = new AbortController();
|
|
200
230
|
const cleanup = () => {
|
|
@@ -216,7 +246,7 @@ function createRscRequest(event) {
|
|
|
216
246
|
node.res.once("finish", cleanup);
|
|
217
247
|
if (node.req.aborted) abort();
|
|
218
248
|
|
|
219
|
-
return new Request(
|
|
249
|
+
return new Request(request, { signal: controller.signal });
|
|
220
250
|
}
|
|
221
251
|
|
|
222
252
|
export default defineEventHandler(async (event) => {
|
|
@@ -241,7 +271,7 @@ export default defineEventHandler(async (event) => {
|
|
|
241
271
|
}
|
|
242
272
|
export async function buildRscNitro(options) {
|
|
243
273
|
const { rendererPath, publicDir, ssrPath, assetsDir, root, outputDir = path.join(root, ".output"), preset = "vercel", } = options;
|
|
244
|
-
const { build, copyPublicAssets, createNitro, prepare } = await import("nitro");
|
|
274
|
+
const { build, copyPublicAssets, createNitro, prepare } = await import("nitro/builder");
|
|
245
275
|
console.log(`[FARM] Building RSC server with Nitro (preset: ${preset})...`);
|
|
246
276
|
const buildDir = path.join(root, ".nitro");
|
|
247
277
|
const serverDir = path.join(outputDir, "server");
|
|
@@ -263,23 +293,28 @@ export async function buildRscNitro(options) {
|
|
|
263
293
|
}
|
|
264
294
|
const config = {
|
|
265
295
|
preset,
|
|
296
|
+
// The RSC plugin supports Vite 6+, while Nitro's beta Vite builder follows
|
|
297
|
+
// its own Vite 8 peer range. The prebuilt renderer works with Rolldown and
|
|
298
|
+
// keeps the app's Vite version out of Nitro's production build contract.
|
|
299
|
+
builder: "rolldown",
|
|
266
300
|
rootDir: root,
|
|
267
|
-
|
|
301
|
+
serverDir: root,
|
|
268
302
|
buildDir,
|
|
269
303
|
dev: false,
|
|
304
|
+
alias: {
|
|
305
|
+
h3: runtimeRequire.resolve("h3"),
|
|
306
|
+
},
|
|
270
307
|
output: {
|
|
271
308
|
dir: outputDir,
|
|
272
309
|
serverDir,
|
|
273
310
|
publicDir: publicOutDir,
|
|
274
311
|
},
|
|
275
312
|
publicAssets,
|
|
276
|
-
renderer: {
|
|
313
|
+
renderer: { handler: entryPath },
|
|
277
314
|
// The prebuilt RSC/SSR bundles are copied after Nitro finishes, so Nitro's
|
|
278
315
|
// module graph cannot otherwise see their bare package imports. Trace both
|
|
279
316
|
// entry points explicitly to keep node-server output self-contained.
|
|
280
|
-
|
|
281
|
-
traceInclude: [rendererPath, ...(ssrPath ? [ssrPath] : [])],
|
|
282
|
-
},
|
|
317
|
+
traceDeps: [rendererPath, ...(ssrPath ? [ssrPath] : [])],
|
|
283
318
|
// Externalize rsc/ssr so we don't bundle (they reference Vite-generated manifest). We copy dist into server output after build.
|
|
284
319
|
rollupConfig: {
|
|
285
320
|
external: (id) => {
|
|
@@ -316,33 +351,9 @@ export async function buildRscNitro(options) {
|
|
|
316
351
|
mkdirSync(rscDestDir, { recursive: true });
|
|
317
352
|
writeFileSync(manifestDest, "export default { serverResources: {}, clientReferenceDeps: {} };", "utf-8");
|
|
318
353
|
}
|
|
319
|
-
// Nitro may group the entry
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
-
const entryChunkPaths = [];
|
|
323
|
-
const findEntryChunks = (dir) => {
|
|
324
|
-
if (!existsSync(dir))
|
|
325
|
-
return;
|
|
326
|
-
for (const name of readdirSync(dir)) {
|
|
327
|
-
const candidate = path.join(dir, name);
|
|
328
|
-
if (statSync(candidate).isDirectory())
|
|
329
|
-
findEntryChunks(candidate);
|
|
330
|
-
else if (name === "rsc-entry.mjs")
|
|
331
|
-
entryChunkPaths.push(candidate);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
findEntryChunks(path.join(serverDir, "chunks"));
|
|
335
|
-
for (const entryChunkPath of entryChunkPaths) {
|
|
336
|
-
let code = readFileSync(entryChunkPath, "utf-8");
|
|
337
|
-
const relativeImport = (target) => {
|
|
338
|
-
const relative = path.relative(path.dirname(entryChunkPath), target).replace(/\\/g, "/");
|
|
339
|
-
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
340
|
-
};
|
|
341
|
-
// Match any path that ends with dist/rsc/index.js or dist/ssr/index.js (minified, no spaces)
|
|
342
|
-
code = code.replace(/(["'`])[^"'`]*?dist\/rsc\/index\.js\1/g, JSON.stringify(relativeImport(path.join(serverDistDir, "rsc", "index.js"))));
|
|
343
|
-
code = code.replace(/(["'`])[^"'`]*?dist\/ssr\/index\.js\1/g, JSON.stringify(relativeImport(path.join(serverDistDir, "ssr", "index.js"))));
|
|
344
|
-
writeFileSync(entryChunkPath, code, "utf-8");
|
|
345
|
-
}
|
|
354
|
+
// Nitro may group the entry differently by builder. Make copied-dist imports
|
|
355
|
+
// relative to the emitted chunk so output survives moving away from the project.
|
|
356
|
+
rewriteRscEntryImports(serverDir, serverDistDir);
|
|
346
357
|
// Patch SSR bundle: inject production client CSS href and bootstrap script so HTML has styles and hydration works
|
|
347
358
|
const ssrIndexPath = path.join(serverDistDir, "ssr", "index.js");
|
|
348
359
|
const manifestPath = path.join(serverDistDir, "rsc", MANIFEST_FILENAME);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.106",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -58,10 +58,11 @@
|
|
|
58
58
|
"@farming-labs/strata": "0.1.2",
|
|
59
59
|
"better-call": "^1.0.19",
|
|
60
60
|
"es-module-lexer": "2.0.0",
|
|
61
|
-
"
|
|
61
|
+
"h3": "2.0.1-rc.32",
|
|
62
|
+
"nitro": "3.0.260903-beta",
|
|
62
63
|
"picocolors": "^1.0.0",
|
|
63
64
|
"rsc-html-stream": "^0.0.4",
|
|
64
|
-
"@farm.js/core": "0.1.0-beta.
|
|
65
|
+
"@farm.js/core": "0.1.0-beta.106"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"@types/node": "^20.19.21",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
"react-dom": "19.2.8",
|
|
83
84
|
"react-server-dom-webpack": "19.2.8",
|
|
84
85
|
"vite": ">=6.0.0",
|
|
85
|
-
"@farm.js/core": "0.1.0-beta.
|
|
86
|
+
"@farm.js/core": "0.1.0-beta.106"
|
|
86
87
|
},
|
|
87
88
|
"peerDependenciesMeta": {
|
|
88
89
|
"@vitejs/plugin-rsc": {
|