@farm.js/plugin 0.1.31 → 0.1.35
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 +1 -1
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +13 -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/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +38 -7
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +29 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ export interface CookieOptions {
|
|
|
40
40
|
export interface CookieJar {
|
|
41
41
|
get(name: string): string | undefined;
|
|
42
42
|
set(name: string, value: string, options?: CookieOptions): void;
|
|
43
|
-
delete(name: string): void;
|
|
43
|
+
delete(name: string, options?: CookieOptions): void;
|
|
44
44
|
getAll(): Record<string, string>;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAS5D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AAE,CAAC;QAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;IAC7F,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AA0KD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAoUlF;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/middleware/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { _withAfterNodeMiddleware } from "@farm.js/core/after";
|
|
4
4
|
import { devServableFileExists } from "../dev-static.js";
|
|
5
5
|
import { resolveDevRequestURL, resolveViteHtmlFallbackUrl } from "../dev-request.js";
|
|
6
|
-
import { matchesMiddlewareConfig } from "@farm.js/core/middleware";
|
|
6
|
+
import { matchesMiddlewareConfig, serializeMiddlewareCookieDeletion, } from "@farm.js/core/middleware";
|
|
7
7
|
import { middlewareMatchesPath, parseCookies, serializeCookie } from "./matching.js";
|
|
8
8
|
// Create require for ESM compatibility
|
|
9
9
|
const require_ = createRequire(import.meta.url);
|
|
@@ -37,24 +37,27 @@ const getColors = () => {
|
|
|
37
37
|
*/
|
|
38
38
|
function createCookieJar(req, res) {
|
|
39
39
|
const cookies = parseCookies(req.headers.cookie);
|
|
40
|
-
|
|
40
|
+
// Keep any Set-Cookie an earlier handler already wrote.
|
|
41
|
+
const existing = res.getHeader("Set-Cookie");
|
|
42
|
+
const setCookies = Array.isArray(existing)
|
|
43
|
+
? existing.map(String)
|
|
44
|
+
: existing === undefined
|
|
45
|
+
? []
|
|
46
|
+
: [String(existing)];
|
|
41
47
|
return {
|
|
42
48
|
get(name) {
|
|
43
49
|
return cookies[name];
|
|
44
50
|
},
|
|
45
51
|
set(name, value, options = {}) {
|
|
46
52
|
cookies[name] = value;
|
|
47
|
-
|
|
48
|
-
setCookies.push(cookieString);
|
|
53
|
+
setCookies.push(serializeCookie(name, value, options));
|
|
49
54
|
res.setHeader("Set-Cookie", setCookies);
|
|
50
55
|
},
|
|
51
|
-
delete(name) {
|
|
56
|
+
delete(name, options = {}) {
|
|
52
57
|
delete cookies[name];
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
setCookies.push(cookieString);
|
|
58
|
+
// Path and Domain must match the cookie that was set, or the tombstone
|
|
59
|
+
// addresses a different cookie and the original survives.
|
|
60
|
+
setCookies.push(serializeMiddlewareCookieDeletion(name, options));
|
|
58
61
|
res.setHeader("Set-Cookie", setCookies);
|
|
59
62
|
},
|
|
60
63
|
getAll() {
|
|
@@ -6,7 +6,8 @@ import type { CookieOptions } from "./index.js";
|
|
|
6
6
|
* (a latin-1 value from an old link, a crawler, or a bare `%`) must not take
|
|
7
7
|
* the whole map down: an unguarded `decodeURIComponent` throws `URIError`,
|
|
8
8
|
* which fails the request before any middleware runs. Decoding falls back to
|
|
9
|
-
* the raw value per entry instead.
|
|
9
|
+
* the raw value per entry instead. This is core's parser, so dev and production
|
|
10
|
+
* agree on which duplicate wins.
|
|
10
11
|
*/
|
|
11
12
|
export declare function parseCookies(cookieHeader?: string): Record<string, string>;
|
|
12
13
|
/**
|
|
@@ -28,7 +29,8 @@ export declare function middlewareMatchesPath(pathname: string, middlewarePath:
|
|
|
28
29
|
*
|
|
29
30
|
* `Max-Age=0` is the canonical immediate-expiry directive, so the attribute is
|
|
30
31
|
* emitted whenever `maxAge` is provided — a `0` must not be dropped the way a
|
|
31
|
-
* plain truthiness check would drop it.
|
|
32
|
+
* plain truthiness check would drop it. This is core's serializer, so a dev
|
|
33
|
+
* Set-Cookie carries the attributes a browser requires, as production does.
|
|
32
34
|
*/
|
|
33
35
|
export declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|
|
34
36
|
//# sourceMappingURL=matching.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAEhG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { canonicalizeRequestPathSegments } from "@farm.js/core/middleware";
|
|
1
|
+
import { canonicalizeRequestPathSegments, parseMiddlewareCookieHeader, serializeMiddlewareCookie, } from "@farm.js/core/middleware";
|
|
2
2
|
/**
|
|
3
3
|
* Parse cookies from a Cookie header.
|
|
4
4
|
*
|
|
@@ -6,27 +6,11 @@ import { canonicalizeRequestPathSegments } from "@farm.js/core/middleware";
|
|
|
6
6
|
* (a latin-1 value from an old link, a crawler, or a bare `%`) must not take
|
|
7
7
|
* the whole map down: an unguarded `decodeURIComponent` throws `URIError`,
|
|
8
8
|
* which fails the request before any middleware runs. Decoding falls back to
|
|
9
|
-
* the raw value per entry instead.
|
|
9
|
+
* the raw value per entry instead. This is core's parser, so dev and production
|
|
10
|
+
* agree on which duplicate wins.
|
|
10
11
|
*/
|
|
11
12
|
export function parseCookies(cookieHeader) {
|
|
12
|
-
|
|
13
|
-
return {};
|
|
14
|
-
return cookieHeader.split(";").reduce((cookies, cookie) => {
|
|
15
|
-
const [name, ...rest] = cookie.split("=");
|
|
16
|
-
const value = rest.join("=").trim();
|
|
17
|
-
if (name && value) {
|
|
18
|
-
cookies[name.trim()] = decodeCookieValue(value);
|
|
19
|
-
}
|
|
20
|
-
return cookies;
|
|
21
|
-
}, {});
|
|
22
|
-
}
|
|
23
|
-
function decodeCookieValue(value) {
|
|
24
|
-
try {
|
|
25
|
-
return decodeURIComponent(value);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
13
|
+
return parseMiddlewareCookieHeader(cookieHeader);
|
|
30
14
|
}
|
|
31
15
|
/**
|
|
32
16
|
* Whether a middleware registered at `middlewarePath` applies to `pathname`.
|
|
@@ -55,33 +39,9 @@ export function middlewareMatchesPath(pathname, middlewarePath) {
|
|
|
55
39
|
*
|
|
56
40
|
* `Max-Age=0` is the canonical immediate-expiry directive, so the attribute is
|
|
57
41
|
* emitted whenever `maxAge` is provided — a `0` must not be dropped the way a
|
|
58
|
-
* plain truthiness check would drop it.
|
|
42
|
+
* plain truthiness check would drop it. This is core's serializer, so a dev
|
|
43
|
+
* Set-Cookie carries the attributes a browser requires, as production does.
|
|
59
44
|
*/
|
|
60
45
|
export function serializeCookie(name, value, options = {}) {
|
|
61
|
-
|
|
62
|
-
if (options.maxAge != null) {
|
|
63
|
-
cookie += `; Max-Age=${options.maxAge}`;
|
|
64
|
-
}
|
|
65
|
-
if (options.expires) {
|
|
66
|
-
cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
67
|
-
}
|
|
68
|
-
if (options.path) {
|
|
69
|
-
cookie += `; Path=${options.path}`;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
cookie += "; Path=/";
|
|
73
|
-
}
|
|
74
|
-
if (options.domain) {
|
|
75
|
-
cookie += `; Domain=${options.domain}`;
|
|
76
|
-
}
|
|
77
|
-
if (options.secure) {
|
|
78
|
-
cookie += "; Secure";
|
|
79
|
-
}
|
|
80
|
-
if (options.httpOnly) {
|
|
81
|
-
cookie += "; HttpOnly";
|
|
82
|
-
}
|
|
83
|
-
if (options.sameSite) {
|
|
84
|
-
cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1)}`;
|
|
85
|
-
}
|
|
86
|
-
return cookie;
|
|
46
|
+
return serializeMiddlewareCookie(name, value, options);
|
|
87
47
|
}
|
|
@@ -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;AAYhD;;;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;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAowC1D"}
|
package/dist/rsc/entries/rsc.js
CHANGED
|
@@ -449,9 +449,20 @@ const farmMiddlewareRunner = createProductionMiddlewareRunner({
|
|
|
449
449
|
.filter((entry) => entry.path !== null)
|
|
450
450
|
// Root first, as core runs them: a nested guard can rely on what its
|
|
451
451
|
// parent middleware set, and glob order is alphabetical, not by depth.
|
|
452
|
-
|
|
452
|
+
// Route groups share a URL path; the shallower file runs first, so
|
|
453
|
+
// '/middleware.ts' precedes '/(app)/middleware.ts'.
|
|
454
|
+
.sort(
|
|
455
|
+
(left, right) =>
|
|
456
|
+
middlewareRouteDepth(left.path) - middlewareRouteDepth(right.path) ||
|
|
457
|
+
left.path.localeCompare(right.path) ||
|
|
458
|
+
middlewareRouteDepth(left.filePath) - middlewareRouteDepth(right.filePath) ||
|
|
459
|
+
left.filePath.localeCompare(right.filePath),
|
|
460
|
+
),
|
|
453
461
|
i18n: ${JSON.stringify(ctx.i18n) ?? "undefined"},
|
|
454
462
|
server: ${JSON.stringify(ctx.server) ?? "undefined"},
|
|
463
|
+
apiBasePath: farmApiBasePath,
|
|
464
|
+
// matchRoute() reads url.pathname as received, so middleware guards that path too.
|
|
465
|
+
rawPathRouting: true,
|
|
455
466
|
});
|
|
456
467
|
|
|
457
468
|
debug('Discovered pages:', Object.keys(pages));
|
|
@@ -464,22 +475,37 @@ debug('Discovered API routes:', Array.from(apiRouteMap.keys()));
|
|
|
464
475
|
/**
|
|
465
476
|
* Convert an app-relative middleware file path to the route it guards, with the
|
|
466
477
|
* same rules as core's middleware discovery: a route group such as
|
|
467
|
-
* '(protected)'
|
|
478
|
+
* '(protected)' or a parallel route slot such as '@team' adds no URL segment,
|
|
479
|
+
* an intercepting folder guards the URL it intercepts, a '_private' folder
|
|
480
|
+
* routes its pages so its middleware guards them, and a dot-prefixed folder
|
|
468
481
|
* holds no routes, so its middleware never runs (null).
|
|
469
482
|
* e.g., '/middleware.ts' -> '/'
|
|
470
483
|
* e.g., '/(protected)/dashboard/middleware.ts' -> '/dashboard'
|
|
484
|
+
* e.g., '/dashboard/@team/middleware.ts' -> '/dashboard'
|
|
485
|
+
* e.g., '/feed/@modal/(.)photo/middleware.ts' -> '/feed/photo'
|
|
471
486
|
*/
|
|
472
487
|
function middlewarePathToRoute(filePath) {
|
|
473
488
|
const segments = filePath
|
|
474
489
|
.replace(/\\/middleware\\.[tj]sx?$/, '')
|
|
475
490
|
.split('/')
|
|
476
491
|
.filter(Boolean);
|
|
477
|
-
if (segments.some((segment) => segment.startsWith('
|
|
492
|
+
if (segments.some((segment) => segment.startsWith('.'))) {
|
|
478
493
|
return null;
|
|
479
494
|
}
|
|
480
|
-
const routeSegments =
|
|
481
|
-
|
|
482
|
-
|
|
495
|
+
const routeSegments = [];
|
|
496
|
+
for (const segment of segments) {
|
|
497
|
+
const marker = /^((?:\\(\\.\\.\\))+|\\(\\.\\.\\.\\)|\\(\\.\\))(.*)$/.exec(segment);
|
|
498
|
+
if (marker) {
|
|
499
|
+
if (marker[1] === '(...)') routeSegments.length = 0;
|
|
500
|
+
else if (marker[1] !== '(.)') routeSegments.splice(-(marker[1].length / 4));
|
|
501
|
+
if (marker[2]) routeSegments.push(marker[2]);
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
if ((segment.startsWith('(') && segment.endsWith(')')) || /^@[A-Za-z][A-Za-z0-9_-]*$/.test(segment)) {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
routeSegments.push(segment);
|
|
508
|
+
}
|
|
483
509
|
return routeSegments.length === 0 ? '/' : '/' + routeSegments.join('/');
|
|
484
510
|
}
|
|
485
511
|
|
|
@@ -538,7 +564,12 @@ const RouteErrorBoundary = React.Component
|
|
|
538
564
|
|
|
539
565
|
// Parse and rank once per entry initialization, not on every request. Use the
|
|
540
566
|
// same validation, decoding and specificity rules as Farm's ordinary router.
|
|
541
|
-
|
|
567
|
+
// RSC renders no parallel route slots, so a page inside '@modal/...' would otherwise
|
|
568
|
+
// answer at its literal folder path ('/feed/@modal/(.)photo/1'), past the middleware
|
|
569
|
+
// that guards the URL it intercepts.
|
|
570
|
+
const pageRoutes = Object.entries(pages)
|
|
571
|
+
.filter(([filePath]) => !filePath.split('/').some((segment) => /^@[A-Za-z][A-Za-z0-9_-]*$/.test(segment)))
|
|
572
|
+
.map(([filePath, module]) => ({
|
|
542
573
|
filePath,
|
|
543
574
|
module,
|
|
544
575
|
segments: parseRoutePath(filePath).segments,
|
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,MA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O,CAAC;QAC3B;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB;;;;;;;WAOG;QACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,CAAC;IACF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;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;CACzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,aAAkB,GAAG,UAAU,CA6DnE;AAibD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAmkC5E"}
|
package/dist/rsc/index.js
CHANGED
|
@@ -85,6 +85,7 @@ export function defineConfig(config = {}) {
|
|
|
85
85
|
md: config.md,
|
|
86
86
|
agent: config.agent,
|
|
87
87
|
mcp: config.mcp,
|
|
88
|
+
middleware: config.middleware,
|
|
88
89
|
// Vite server configuration
|
|
89
90
|
server: {
|
|
90
91
|
...config.server,
|
|
@@ -97,6 +98,8 @@ export function defineConfig(config = {}) {
|
|
|
97
98
|
farmMiddlewarePlugin({
|
|
98
99
|
srcDir: config.srcDir ?? "src",
|
|
99
100
|
basePath: config.basePath ?? "/",
|
|
101
|
+
// API routes in development run through this plugin's middleware, not the RSC entry's.
|
|
102
|
+
middleware: config.middleware,
|
|
100
103
|
debug,
|
|
101
104
|
}),
|
|
102
105
|
farmApiPlugin({
|
|
@@ -251,6 +254,28 @@ async function resolveMiddlewareConfigPaths(root, layers) {
|
|
|
251
254
|
paths.push(projectConfigPath);
|
|
252
255
|
return [...new Set(paths)];
|
|
253
256
|
}
|
|
257
|
+
// Vite's default config names: `defineConfig` from this package is written in one of them.
|
|
258
|
+
const VITE_CONFIG_FILENAMES = [
|
|
259
|
+
"vite.config.js",
|
|
260
|
+
"vite.config.mjs",
|
|
261
|
+
"vite.config.ts",
|
|
262
|
+
"vite.config.cjs",
|
|
263
|
+
"vite.config.mts",
|
|
264
|
+
"vite.config.cts",
|
|
265
|
+
];
|
|
266
|
+
async function findViteConfigPath(root) {
|
|
267
|
+
for (const fileName of VITE_CONFIG_FILENAMES) {
|
|
268
|
+
const candidate = path.join(root, fileName);
|
|
269
|
+
try {
|
|
270
|
+
if ((await fs.stat(candidate)).isFile())
|
|
271
|
+
return candidate;
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
// Continue checking supported config names.
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
254
279
|
function isOptimizedBoundaryModule(id) {
|
|
255
280
|
return (id === OPTIMIZED_BOUNDARY_ADAPTER ||
|
|
256
281
|
id === STRATA_PACKAGE ||
|
|
@@ -682,8 +707,11 @@ export default function farmRsc(options = {}) {
|
|
|
682
707
|
const middlewareConfigPaths = [];
|
|
683
708
|
if (hasFarmMiddlewareConfig(c.middleware)) {
|
|
684
709
|
const configPaths = await resolveMiddlewareConfigPaths(root, c.layers);
|
|
710
|
+
const viteConfigPath = await findViteConfigPath(root);
|
|
711
|
+
if (viteConfigPath)
|
|
712
|
+
configPaths.push(viteConfigPath);
|
|
685
713
|
if (configPaths.length === 0) {
|
|
686
|
-
throw new Error("[Farm.js] RSC config middleware requires an importable farm.config file. " +
|
|
714
|
+
throw new Error("[Farm.js] RSC config middleware requires an importable farm.config or vite.config file. " +
|
|
687
715
|
"Move the middleware to farm.config.ts or src/app/middleware.ts.");
|
|
688
716
|
}
|
|
689
717
|
for (const configPath of configPaths) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"nitro": "3.0.260903-beta",
|
|
63
63
|
"picocolors": "^1.0.0",
|
|
64
64
|
"rsc-html-stream": "^0.0.4",
|
|
65
|
-
"@farm.js/core": "0.1.
|
|
65
|
+
"@farm.js/core": "0.1.35"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^22.20.5",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react-dom": "19.2.8",
|
|
84
84
|
"react-server-dom-webpack": "19.2.8",
|
|
85
85
|
"vite": ">=6.0.0",
|
|
86
|
-
"@farm.js/core": "0.1.
|
|
86
|
+
"@farm.js/core": "0.1.35"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@vitejs/plugin-rsc": {
|