@farm.js/plugin 0.1.70 → 0.1.72

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 CHANGED
@@ -39,5 +39,5 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export declare const version = "0.1.70";
42
+ export declare const version = "0.1.72";
43
43
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export const version = "0.1.70";
42
+ export const version = "0.1.72";
43
43
  // Note: Import plugins from their respective subpaths:
44
44
  // - @farm.js/plugin/rsc
45
45
  // - @farm.js/plugin/middleware
@@ -1 +1 @@
1
- {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAgKhE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,YAAY,EACjB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,EAC1C,eAAe,EAAE,OAAO,GACvB,MAAM,CAqGR;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAo+E1D"}
1
+ {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAgKhE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,YAAY,EACjB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,EAC1C,eAAe,EAAE,OAAO,GACvB,MAAM,CAqGR;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAq7E1D"}
@@ -348,7 +348,6 @@ import {
348
348
  }
349
349
  code += `} from '@vitejs/plugin-rsc/rsc';
350
350
  import {
351
- createFarmDeploymentCookie,
352
351
  createFarmDeploymentMismatchResponse,
353
352
  getFarmDeploymentMismatch,
354
353
  } from '@farm.js/core/deployment';
@@ -358,7 +357,7 @@ import {
358
357
  applyProductionMiddlewareHeaders,
359
358
  createProductionMiddlewareRunner,
360
359
  } from '@farm.js/core/middleware';
361
- import { _withFarmGuardedResponseCache, _withFarmResponseHeaders } from '@farm.js/core/internal/production-runtime';
360
+ import { _withFarmDeploymentCookie, _withFarmGuardedResponseCache } from '@farm.js/core/internal/production-runtime';
362
361
  ${ctx.mobileClient === "entry" ? "import { _applyFarmMobileShellClient, createFarmNativeTreeResponse, resolveFarmWebRequestOrigin } from '@farm.js/core/internal/production-runtime';\n" : ctx.mobileClient === "inline" ? "import { createFarmNativeTreeResponse, resolveFarmWebRequestOrigin } from '@farm.js/core/internal/production-runtime';\n" : ""}import {
363
362
  getAllowedAPIRouteMethods,
364
363
  invokeAPIRouteEndpoint,
@@ -594,40 +593,17 @@ function debug(...args) {
594
593
  ${debugLog}
595
594
  }
596
595
 
597
- // Directives a CDN reads in place of Cache-Control, as core's CDN_CACHE_CONTROL_HEADERS lists them.
598
- const FARM_CDN_CACHE_CONTROL_HEADERS = [
599
- 'cdn-cache-control',
600
- 'vercel-cdn-cache-control',
601
- 'netlify-cdn-cache-control',
602
- 'cloudflare-cdn-cache-control',
603
- ];
604
- const FARM_PRIVATE_CACHE_DIRECTIVE = /(?:^|,)\\s*(?:private|no-store)\\s*(?:[,=]|$)/i;
605
-
606
596
  /**
607
597
  * Store the deployment ID in the deployment cookie on a page document a browser loads, so a form
608
- * posted from it before JavaScript runs names its deployment. Only a GET page document that names
609
- * this deployment and stays out of shared caches carries it: a CDN does not cache a response that
610
- * sets a cookie (and one that does would hand it to every visitor), so a publicly cached page is
611
- * sent as it was. A request naming another deployment keeps its cookie, so its forms stay refused.
612
- *
613
- * These are the rules of core's _withFarmDeploymentCookie for its production server (deployment
614
- * skew protection); reuse that helper here once core exports it. A Flight payload is fetched by
615
- * the client router, which names its deployment in a header, so it never carries the cookie.
598
+ * posted from it before JavaScript runs names its deployment. Core's _withFarmDeploymentCookie
599
+ * decides, as on its production server: only a GET page response that names this deployment and
600
+ * stays out of shared caches carries it, and a request naming another deployment keeps its cookie.
601
+ * A Flight payload is fetched by the client router, which names its deployment in a header, so it
602
+ * never carries the cookie.
616
603
  */
617
604
  function withFarmDeploymentCookie(request, response) {
618
- if (request.method.toUpperCase() !== 'GET') return response;
619
605
  if ((request.headers.get('accept') || '').includes('text/x-component')) return response;
620
- if (response.headers.get('x-farm-deployment-id') !== farmDeploymentId) return response;
621
- if (!FARM_PRIVATE_CACHE_DIRECTIVE.test(response.headers.get('cache-control') || '')) return response;
622
- if (FARM_CDN_CACHE_CONTROL_HEADERS.some((name) => response.headers.has(name))) return response;
623
- if (getFarmDeploymentMismatch(request, farmDeploymentId)) return response;
624
- return _withFarmResponseHeaders(response, (headers) => {
625
- headers.append('set-cookie', createFarmDeploymentCookie(
626
- farmDeploymentId,
627
- ${JSON.stringify(ctx.basePath)},
628
- new URL(request.url).protocol === 'https:',
629
- ));
630
- });
606
+ return _withFarmDeploymentCookie(request, response, farmDeploymentId, ${JSON.stringify(ctx.basePath)});
631
607
  }
632
608
 
633
609
  function applyActionResponseHeaders(headers, request, pageCacheControl) {
@@ -2037,8 +2013,9 @@ async function handleFarmLlmsTxtRequest(request, context) {
2037
2013
  function getFarmAgentListedPages() {
2038
2014
  const guard = {
2039
2015
  config: { middleware: farmConfigMiddleware },
2016
+ // With its module, so a root middleware.ts's own config.matcher names the pages it guards.
2040
2017
  middlewareRoutes: Object.keys(middlewares)
2041
- .map((filePath) => ({ path: middlewarePathToRoute(filePath) }))
2018
+ .map((filePath) => ({ path: middlewarePathToRoute(filePath), module: middlewares[filePath] }))
2042
2019
  .filter((route) => route.path !== null),
2043
2020
  };
2044
2021
  const listed = new Map();
@@ -2417,30 +2394,6 @@ function addFarmMetadataFileReferences(metadata, pathname) {
2417
2394
 
2418
2395
  `
2419
2396
  : ""}/**
2420
- * A Markdown request whose only cookie is the deployment cookie, without it. That cookie names a
2421
- * release, never a visitor, so a browser holding it may still read (and fill) a mirror md.cache
2422
- * shares; any other cookie keeps the mirror private. Core's withoutFarmDeploymentCookie applies
2423
- * the same rule inside createMarkdownMirrorResponse with deployment skew protection; drop this
2424
- * once that ships. The mirror renders the page with a GET, where the cookie is never read.
2425
- */
2426
- function withoutLoneFarmDeploymentCookie(request) {
2427
- const cookie = request.headers.get('cookie');
2428
- if (!cookie || !cookie.includes('__farm_deployment')) return request;
2429
- if (!farmRequestWantsMarkdown(new URL(request.url).pathname, request.headers.get('accept'))) {
2430
- return request;
2431
- }
2432
- const otherCookie = cookie.split(';').some((part) => {
2433
- const separator = part.indexOf('=');
2434
- const name = (separator === -1 ? part : part.slice(0, separator)).trim();
2435
- return name !== '' && name !== '__farm_deployment';
2436
- });
2437
- if (otherCookie) return request;
2438
- const headers = new Headers(request.headers);
2439
- headers.delete('cookie');
2440
- return new Request(request, { headers });
2441
- }
2442
-
2443
- /**
2444
2397
  * Serves a page's Markdown mirror (\`/page.md\` or \`Accept: text/markdown\`) by
2445
2398
  * rendering the page through the normal request path, so middleware and sign-in
2446
2399
  * gates apply; every other request renders as usual, and HTML pages advertise
@@ -2449,7 +2402,7 @@ function withoutLoneFarmDeploymentCookie(request) {
2449
2402
  async function handleFarmPageOrMarkdown(request, context) {
2450
2403
  if (!farmMarkdownConfig.enabled) return handleFarmRequest(request, context);
2451
2404
  const markdown = await createMarkdownMirrorResponse({
2452
- request: withoutLoneFarmDeploymentCookie(request),
2405
+ request,
2453
2406
  config: farmMarkdownConfig,
2454
2407
  routePathname: getFarmRoutePathname,
2455
2408
  // The page the render below selects for the mirrored URL, below the basePath and locale.
@@ -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,EAEhB,MAAM,MAAM,CAAC;AAUd,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,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,qBAAqB,EACtB,MAAM,2CAA2C,CAAC;AA+BnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAwD9D,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAExF,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,wBAAwB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AC;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,CAgFnE;AAudD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAu7C5E"}
package/dist/rsc/index.js CHANGED
@@ -1025,6 +1025,7 @@ export default function farmRsc(options = {}) {
1025
1025
  root,
1026
1026
  mode: env.command === "serve" ? "development" : "production",
1027
1027
  basePath: c.basePath ?? "/",
1028
+ trailingSlash: c.trailingSlash === true,
1028
1029
  });
1029
1030
  // The config redirects(), rewrites() and headers(), called once and checked as core's
1030
1031
  // config resolution checks them. An app without any generates the same entries as before.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/plugin",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
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.70"
66
+ "@farm.js/core": "0.1.72"
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.70"
87
+ "@farm.js/core": "0.1.72"
88
88
  },
89
89
  "peerDependenciesMeta": {
90
90
  "@vitejs/plugin-rsc": {