@farm.js/core 0.1.68 → 0.1.69

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 (178) hide show
  1. package/dist/{agent-mcp.d-wkVPK1GA.d.mts → agent-mcp.d-DOfBMEzP.d.mts} +1 -1
  2. package/dist/{agent-mcp.d-Uh5xr7aX.d.ts → agent-mcp.d-DnIgriX1.d.ts} +1 -1
  3. package/dist/agent-runtime.d.mts +1 -1
  4. package/dist/agent-runtime.d.ts +1 -1
  5. package/dist/{analyzer-CQDU7E3Y.mjs → analyzer-NAL5TJUP.mjs} +2 -2
  6. package/dist/analyzer-SAJSV6SP.cjs +16 -0
  7. package/dist/api/node.d.mts +3 -3
  8. package/dist/api/node.d.ts +3 -3
  9. package/dist/api/route-manager.d.mts +3 -3
  10. package/dist/api/route-manager.d.ts +3 -3
  11. package/dist/api/runtime.d.mts +2 -2
  12. package/dist/api/runtime.d.ts +2 -2
  13. package/dist/api.cjs +2 -2
  14. package/dist/api.d.mts +4 -21
  15. package/dist/api.d.ts +4 -21
  16. package/dist/api.mjs +1 -1
  17. package/dist/{app-manifest.d-BT5i2F-o.d.ts → app-manifest.d-CaAcaukR.d.ts} +1 -1
  18. package/dist/{app-manifest.d-Dd4q5CFx.d.mts → app-manifest.d-_BVbI0xp.d.mts} +1 -1
  19. package/dist/app-markdown.d.mts +2 -2
  20. package/dist/app-markdown.d.ts +2 -2
  21. package/dist/{app.d-BVOpL_f2.d.ts → app.d-BWeDqOaF.d.ts} +4 -4
  22. package/dist/{app.d-BhiDXex_.d.mts → app.d-CaPwtytN.d.mts} +4 -4
  23. package/dist/{base-path.d-BOUV5ozD.d.mts → base-path.d-CTDVF0Fc.d.mts} +2 -1
  24. package/dist/{base-path.d-BOUV5ozD.d.ts → base-path.d-CTDVF0Fc.d.ts} +2 -1
  25. package/dist/{chunk-SQ6IWJ3H.cjs → chunk-22LGTSBA.cjs} +1 -1
  26. package/dist/{chunk-T5XFZQCL.mjs → chunk-2P7UYHZP.mjs} +1 -1
  27. package/dist/{chunk-LDEXTX4I.cjs → chunk-4JRAMCUP.cjs} +11 -4
  28. package/dist/{chunk-TNK2TVRS.cjs → chunk-4W4ZWSV2.cjs} +196 -155
  29. package/dist/{chunk-MNJDNTGO.mjs → chunk-5TOWKGV3.mjs} +1 -1
  30. package/dist/{chunk-7LK5CTUM.cjs → chunk-6GQJVY4E.cjs} +18 -13
  31. package/dist/{chunk-5JKDFRTK.cjs → chunk-ABIBASLJ.cjs} +2 -2
  32. package/dist/{chunk-F6CMGWAL.mjs → chunk-ANMIR6US.mjs} +1 -1
  33. package/dist/{chunk-Z6SOXHAD.mjs → chunk-CKCKCUYO.mjs} +72 -31
  34. package/dist/{chunk-2ZOYOYEE.mjs → chunk-D5F7RPZP.mjs} +71 -1
  35. package/dist/{chunk-F36LS2C7.cjs → chunk-DHR2WDSL.cjs} +27 -27
  36. package/dist/{chunk-URN7VFO7.cjs → chunk-F6YLXK5L.cjs} +10 -11
  37. package/dist/{chunk-YTNBCXCW.cjs → chunk-GQ6QOH7T.cjs} +9 -5
  38. package/dist/{chunk-BZWTBELF.cjs → chunk-GTQOEEE7.cjs} +77 -7
  39. package/dist/{chunk-IGDYL2IA.cjs → chunk-GUMKIQJL.cjs} +2 -2
  40. package/dist/{chunk-4UAQB5LB.mjs → chunk-IYLZZTP6.mjs} +4 -4
  41. package/dist/{chunk-WUTFJOV7.cjs → chunk-JFPKARWM.cjs} +16 -8
  42. package/dist/{chunk-225APHKC.cjs → chunk-L5OZN6YW.cjs} +3 -3
  43. package/dist/{chunk-KWCZKJYU.cjs → chunk-L6NWQ3DR.cjs} +351 -277
  44. package/dist/{chunk-6OFOIMNS.mjs → chunk-MAGFDK4Q.mjs} +1 -1
  45. package/dist/{chunk-5IQ2ERQA.cjs → chunk-O47W53D3.cjs} +1 -1
  46. package/dist/{chunk-3TXKFRSO.mjs → chunk-OEL5EPOJ.mjs} +1 -1
  47. package/dist/{chunk-A3T445WK.mjs → chunk-PDQ6EGPK.mjs} +8 -1
  48. package/dist/{chunk-VRGY3X2I.mjs → chunk-PEYDQMSA.mjs} +5 -6
  49. package/dist/{chunk-KSZK34HU.mjs → chunk-PJQ5W356.mjs} +16 -8
  50. package/dist/{chunk-JSOCDYER.cjs → chunk-Q4HH5Q6A.cjs} +15 -1
  51. package/dist/{chunk-NT4W4H52.mjs → chunk-SZORL7EW.mjs} +18 -13
  52. package/dist/{chunk-Z3PW3DIR.cjs → chunk-TKYOJ5G2.cjs} +3 -3
  53. package/dist/{chunk-DIXFKAPM.mjs → chunk-UHU4QALN.mjs} +153 -79
  54. package/dist/{chunk-WPB67LE5.mjs → chunk-ULMXZYOA.mjs} +1 -1
  55. package/dist/{chunk-MZ4CRSY7.cjs → chunk-VO65MYJD.cjs} +4 -4
  56. package/dist/{chunk-DXZ57EPE.mjs → chunk-YOHHL2UE.mjs} +14 -0
  57. package/dist/{chunk-VFNAK6A5.mjs → chunk-ZR2QB45W.mjs} +7 -3
  58. package/dist/{chunk-KDO6T6OB.mjs → chunk-ZYCEEE3V.mjs} +1 -1
  59. package/dist/{client-component.d-DNVSLEPi.d.ts → client-component.d-CfJxuXZl.d.ts} +2 -2
  60. package/dist/{client-component.d-BvQOxSqh.d.mts → client-component.d-CnEeVvGG.d.mts} +2 -2
  61. package/dist/{client-plugins.d-CNDqcAuf.d.ts → client-plugins.d-D7dHV1Nf.d.ts} +15 -3
  62. package/dist/{client-plugins.d-CE1lVK2R.d.mts → client-plugins.d-Do5ULA0x.d.mts} +15 -3
  63. package/dist/client-plugins.d.mts +1 -1
  64. package/dist/client-plugins.d.ts +1 -1
  65. package/dist/client.d.mts +6 -6
  66. package/dist/client.d.ts +6 -6
  67. package/dist/config.d.mts +1 -1
  68. package/dist/config.d.ts +1 -1
  69. package/dist/desktop.d.mts +2 -2
  70. package/dist/desktop.d.ts +2 -2
  71. package/dist/{devtools-R27T3BRY.cjs → devtools-7HNDS4SY.cjs} +2 -2
  72. package/dist/{devtools-2A2GPC7B.mjs → devtools-BP4EBTKQ.mjs} +1 -1
  73. package/dist/docs.cjs +5 -3
  74. package/dist/docs.d.mts +15 -3
  75. package/dist/docs.d.ts +15 -3
  76. package/dist/docs.mjs +5 -3
  77. package/dist/environment/vite.cjs +3 -3
  78. package/dist/environment/vite.mjs +2 -2
  79. package/dist/image/server.cjs +2 -2
  80. package/dist/image/server.mjs +1 -1
  81. package/dist/image/sharp.cjs +9 -9
  82. package/dist/image/sharp.mjs +1 -1
  83. package/dist/index.cjs +17 -16
  84. package/dist/{index.d-Bt3kl19W.d.mts → index.d-B1MpEJAo.d.mts} +1 -1
  85. package/dist/{index.d-Cx_-DaKV.d.ts → index.d-CVFk37uX.d.ts} +1 -1
  86. package/dist/index.d.mts +17 -17
  87. package/dist/index.d.ts +17 -17
  88. package/dist/index.mjs +17 -16
  89. package/dist/integrations/orm.d.mts +1 -1
  90. package/dist/integrations/orm.d.ts +1 -1
  91. package/dist/integrations.d.mts +1 -1
  92. package/dist/integrations.d.ts +1 -1
  93. package/dist/internal/app-markdown-runtime.d.mts +2 -2
  94. package/dist/internal/app-markdown-runtime.d.ts +2 -2
  95. package/dist/internal/build-runtime.cjs +15 -16
  96. package/dist/internal/build-runtime.d.mts +3 -3
  97. package/dist/internal/build-runtime.d.ts +3 -3
  98. package/dist/internal/build-runtime.mjs +14 -15
  99. package/dist/internal/cli-runtime.cjs +2 -2
  100. package/dist/internal/cli-runtime.mjs +1 -1
  101. package/dist/internal/client-error-overlay.cjs +4 -4
  102. package/dist/internal/client-error-overlay.mjs +1 -1
  103. package/dist/internal/client-runtime.d.mts +5 -5
  104. package/dist/internal/client-runtime.d.ts +5 -5
  105. package/dist/internal/compression-runtime.d.mts +1 -1
  106. package/dist/internal/compression-runtime.d.ts +1 -1
  107. package/dist/internal/config-runtime.cjs +3 -3
  108. package/dist/internal/config-runtime.d.mts +3 -3
  109. package/dist/internal/config-runtime.d.ts +3 -3
  110. package/dist/internal/config-runtime.mjs +2 -2
  111. package/dist/internal/infra-analytics-runtime.cjs +6 -6
  112. package/dist/internal/infra-analytics-runtime.mjs +4 -4
  113. package/dist/internal/native-server-fns.cjs +4 -4
  114. package/dist/internal/native-server-fns.mjs +3 -3
  115. package/dist/internal/product-telemetry-runtime.cjs +3 -3
  116. package/dist/internal/product-telemetry-runtime.mjs +2 -2
  117. package/dist/internal/production-runtime.cjs +8 -4
  118. package/dist/internal/production-runtime.d.mts +19 -12
  119. package/dist/internal/production-runtime.d.ts +19 -12
  120. package/dist/internal/production-runtime.mjs +8 -4
  121. package/dist/markdown.d.mts +1 -1
  122. package/dist/markdown.d.ts +1 -1
  123. package/dist/middleware.d.mts +1 -1
  124. package/dist/middleware.d.ts +1 -1
  125. package/dist/{mount.d-Bki4pOaJ.d.mts → mount.d-CBqr-LfI.d.mts} +1 -1
  126. package/dist/{mount.d-DjR5aerM.d.ts → mount.d-CGzN61Kq.d.ts} +1 -1
  127. package/dist/{navigation-delegate.d-VDkziXTK.d.mts → navigation-delegate.d-BwCOhpj7.d.mts} +1 -1
  128. package/dist/{navigation-delegate.d-CtghaSP3.d.ts → navigation-delegate.d-CLH2dXjy.d.ts} +1 -1
  129. package/dist/navigation.d.mts +4 -4
  130. package/dist/navigation.d.ts +4 -4
  131. package/dist/{plugin-WIU4GDD4.cjs → plugin-F2O4BFTK.cjs} +2 -2
  132. package/dist/{plugin-SAS22JL7.mjs → plugin-VEBRN7A3.mjs} +1 -1
  133. package/dist/plugin.cjs +10 -10
  134. package/dist/plugin.d.mts +3 -3
  135. package/dist/plugin.d.ts +3 -3
  136. package/dist/plugin.mjs +9 -9
  137. package/dist/{render-plan.d-BSwV8PE4.d.mts → render-plan.d-CzGDjcT0.d.mts} +1 -1
  138. package/dist/{render-plan.d-i9sI4tc9.d.ts → render-plan.d-W6LmjD6y.d.ts} +1 -1
  139. package/dist/renderer-client.d.mts +4 -4
  140. package/dist/renderer-client.d.ts +4 -4
  141. package/dist/{request.d-Dgln8tuI.d.ts → request.d-CTVRZiQv.d.ts} +1 -1
  142. package/dist/{request.d-C24FNQ_7.d.mts → request.d-CgNVderU.d.mts} +1 -1
  143. package/dist/request.d.mts +2 -2
  144. package/dist/request.d.ts +2 -2
  145. package/dist/{route-rendering.d-Ds0BfwQi.d.mts → route-rendering.d-D0bmZVJA.d.mts} +1 -1
  146. package/dist/{route-rendering.d-CUylZKJA.d.ts → route-rendering.d-FDSNtCMg.d.ts} +1 -1
  147. package/dist/{router.d-B56rMOFm.d.ts → router.d-DZ3ldniI.d.ts} +1 -1
  148. package/dist/{router.d-CFPcbqzc.d.mts → router.d-GRKm_uAV.d.mts} +1 -1
  149. package/dist/routes.d.mts +1 -1
  150. package/dist/routes.d.ts +1 -1
  151. package/dist/{rsc-pipeline-3T7V6OUT.cjs → rsc-pipeline-J4KKBSCH.cjs} +4 -5
  152. package/dist/{rsc-pipeline-GA4AQWZI.mjs → rsc-pipeline-PJZOVYSY.mjs} +3 -4
  153. package/dist/{runtime-REUTNTI5.cjs → runtime-OLEO5NXF.cjs} +4 -4
  154. package/dist/{runtime-ZYCKKY7L.mjs → runtime-QDBSE4H6.mjs} +2 -2
  155. package/dist/{runtime.d-DLRO-ExG.d.mts → runtime.d-DqXihlxm.d.mts} +1 -1
  156. package/dist/{runtime.d-H7k9hOQE.d.ts → runtime.d-pqFQBU2N.d.ts} +1 -1
  157. package/dist/server-plugins.d.mts +2 -2
  158. package/dist/server-plugins.d.ts +2 -2
  159. package/dist/server.cjs +31 -31
  160. package/dist/server.d.mts +9 -9
  161. package/dist/server.d.ts +9 -9
  162. package/dist/server.mjs +12 -12
  163. package/dist/{spa-router.d-Dr7oanhl.d.ts → spa-router.d-DhOhaQ-7.d.ts} +2 -2
  164. package/dist/{spa-router.d-g4CzhEH1.d.mts → spa-router.d-Dhvy60p4.d.mts} +2 -2
  165. package/dist/testing.d.mts +1 -1
  166. package/dist/testing.d.ts +1 -1
  167. package/dist/{utils.d-BxxyDEb8.d.ts → utils.d-BVCMRRau.d.ts} +1 -1
  168. package/dist/{utils.d-HIla3pD_.d.mts → utils.d-Q8EHCpkF.d.mts} +1 -1
  169. package/dist/version.cjs +2 -2
  170. package/dist/version.mjs +1 -1
  171. package/dist/vite.cjs +10 -10
  172. package/dist/vite.d.mts +4 -4
  173. package/dist/vite.d.ts +4 -4
  174. package/dist/vite.mjs +9 -9
  175. package/package.json +2 -2
  176. package/dist/analyzer-PPAHM4AW.cjs +0 -16
  177. package/dist/chunk-HHLEYA4B.cjs +0 -17
  178. package/dist/chunk-QYNZ3CTI.mjs +0 -17
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-QOSDWGKT.mjs";
6
6
  import {
7
7
  createFarmImageHandler
8
- } from "./chunk-3TXKFRSO.mjs";
8
+ } from "./chunk-OEL5EPOJ.mjs";
9
9
  import {
10
10
  FARM_LAYOUT_ELEMENT_CLIENT_SOURCE,
11
11
  FARM_NAVIGATION_SCRIPT_SOURCE,
@@ -30,14 +30,15 @@ import {
30
30
  resolveFarmClientCacheAdapterEntry,
31
31
  resolveFarmImageProviderForRuntime,
32
32
  resolveFarmRouteRootStrategy
33
- } from "./chunk-4UAQB5LB.mjs";
33
+ } from "./chunk-IYLZZTP6.mjs";
34
34
  import {
35
35
  generateFarmClientPluginEntryCode,
36
+ hasFarmServerRuntimePlugins,
36
37
  loadTailwindVitePlugin
37
- } from "./chunk-DXZ57EPE.mjs";
38
+ } from "./chunk-YOHHL2UE.mjs";
38
39
  import {
39
40
  FARM_NODE_RESPONSE_END_PENDING
40
- } from "./chunk-KSZK34HU.mjs";
41
+ } from "./chunk-PJQ5W356.mjs";
41
42
  import {
42
43
  resolveFarmPlatform
43
44
  } from "./chunk-SMUW7UST.mjs";
@@ -78,13 +79,13 @@ import {
78
79
  resolveFarmMCPRouteLabel,
79
80
  resolveFarmMarkdownRouteLabel,
80
81
  setFarmRouteLabel
81
- } from "./chunk-VFNAK6A5.mjs";
82
+ } from "./chunk-ZR2QB45W.mjs";
82
83
  import {
83
84
  FARM_DEFAULT_MCP_PATH
84
85
  } from "./chunk-K6SXMVXO.mjs";
85
86
  import {
86
87
  isFarmPreviewDeploymentEnvironment
87
- } from "./chunk-T5XFZQCL.mjs";
88
+ } from "./chunk-2P7UYHZP.mjs";
88
89
  import {
89
90
  resolveFarmLayoutFonts
90
91
  } from "./chunk-HZOMT5DY.mjs";
@@ -119,7 +120,7 @@ import {
119
120
  rewriteFarmReactServerClientModuleImports,
120
121
  rewriteFarmReactServerImports,
121
122
  stripUseClientDirective
122
- } from "./chunk-WPB67LE5.mjs";
123
+ } from "./chunk-ULMXZYOA.mjs";
123
124
  import {
124
125
  generateFarmDocsAdapterClientRuntime,
125
126
  getFarmDocsAdapterConfigModule
@@ -277,7 +278,7 @@ import {
277
278
  } from "./chunk-2DA7CLY7.mjs";
278
279
  import {
279
280
  FARM_VERSION
280
- } from "./chunk-F6CMGWAL.mjs";
281
+ } from "./chunk-ANMIR6US.mjs";
281
282
  import {
282
283
  DEFAULT_FARM_API_BASE_PATH
283
284
  } from "./chunk-W6QLRQ3V.mjs";
@@ -1067,7 +1068,7 @@ function loadFarmWorkflowsDevRuntime() {
1067
1068
  return import("./workflows.mjs");
1068
1069
  }
1069
1070
  function loadFarmDevtoolsSnapshotRuntime() {
1070
- return import("./devtools-2A2GPC7B.mjs");
1071
+ return import("./devtools-BP4EBTKQ.mjs");
1071
1072
  }
1072
1073
  function loadFarmDevtoolsUIRuntime() {
1073
1074
  return import("./devtools-ui-CYBVFLPH.mjs");
@@ -1301,11 +1302,18 @@ function createFarmDevMiddlewareErrorResponse() {
1301
1302
  headers: { "Content-Type": "application/json", "Cache-Control": "private, no-store" }
1302
1303
  });
1303
1304
  }
1304
- function sendFarmDevRuntimeHookError(res, json) {
1305
+ function setFarmDevRuntimeHookErrorHead(res, json) {
1306
+ for (const name of res.getHeaderNames()) res.removeHeader(name);
1305
1307
  res.statusCode = 500;
1306
1308
  res.setHeader("Content-Type", json ? "application/json" : "text/plain; charset=utf-8");
1309
+ }
1310
+ function sendFarmDevRuntimeHookError(res, json) {
1311
+ setFarmDevRuntimeHookErrorHead(res, json);
1307
1312
  res.end(json ? FARM_INTERNAL_SERVER_ERROR_BODY : "Internal Server Error");
1308
1313
  }
1314
+ function opensFarmDevRuntimeSession(pm) {
1315
+ return pm.hasRuntimeRequestHooks() || hasFarmServerRuntimePlugins(pm.getPlugins());
1316
+ }
1309
1317
  var FARM_CONFIG_ROUTE_PLUGIN_NAMES = /* @__PURE__ */ new Set([
1310
1318
  FARM_CONFIG_HEADERS_PLUGIN_NAME,
1311
1319
  FARM_CONFIG_REDIRECTS_PLUGIN_NAME,
@@ -1429,12 +1437,7 @@ function interceptFarmDevPageResponse(options) {
1429
1437
  console.error("Error in afterResponse hook:", error);
1430
1438
  };
1431
1439
  const writeRuntimeHookFailure = () => {
1432
- res.statusCode = 500;
1433
- res.removeHeader("Content-Length");
1434
- res.setHeader(
1435
- "Content-Type",
1436
- options.jsonError ? "application/json" : "text/plain; charset=utf-8"
1437
- );
1440
+ setFarmDevRuntimeHookErrorHead(res, Boolean(options.jsonError));
1438
1441
  originalWriteHead(500);
1439
1442
  originalWrite(options.jsonError ? FARM_INTERNAL_SERVER_ERROR_BODY : "Internal Server Error");
1440
1443
  };
@@ -2495,6 +2498,34 @@ function farmPlugin(options = {}, initialPluginManager, deferredSetup) {
2495
2498
  isPathGuarded: isFarmDocsPathGuarded,
2496
2499
  basePath: farmConfig.basePath
2497
2500
  }) : null;
2501
+ const farmDocsListsPages = Boolean(
2502
+ farmDocsDevRuntime && pm?.getPlugins().some((plugin2) => plugin2.name === "farm:infra-analytics")
2503
+ );
2504
+ let farmDocsPagePaths;
2505
+ const getFarmDocsPagePaths = () => {
2506
+ if (!farmDocsDevRuntime || !farmDocsListsPages) return void 0;
2507
+ farmDocsPagePaths ?? (farmDocsPagePaths = farmDocsDevRuntime.listFarmDocsPagePaths(farmConfig.docs, {
2508
+ root: farmConfig.root,
2509
+ srcDir: farmConfig.srcDir,
2510
+ adapter: farmDocsDevRuntime.hasFarmDocsRuntimeAdapter(farmConfig.docs)
2511
+ }).then(
2512
+ (pages) => new Set(pages),
2513
+ (error) => {
2514
+ logger.warn(
2515
+ `Farm Infra analytics reports docs pages by the docs route, not each page's path: listing them failed (${error instanceof Error ? error.message : String(error)}).`
2516
+ );
2517
+ return void 0;
2518
+ }
2519
+ ));
2520
+ return farmDocsPagePaths;
2521
+ };
2522
+ if (farmDocsListsPages) {
2523
+ for (const event of ["add", "unlink"]) {
2524
+ server.watcher.on(event, () => {
2525
+ farmDocsPagePaths = void 0;
2526
+ });
2527
+ }
2528
+ }
2498
2529
  const wrapFarmDocsResponseWithLayouts = async (request, response) => {
2499
2530
  if (request.method === "HEAD" || response.headers.has("x-farm-docs-adapter") || !response.headers.get("content-type")?.toLowerCase().includes("text/html")) {
2500
2531
  return response;
@@ -2804,7 +2835,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
2804
2835
  status: redirect.statusCode,
2805
2836
  headers: { Location: redirect.destination }
2806
2837
  });
2807
- if (pm.hasRuntimeRequestHooks()) {
2838
+ if (opensFarmDevRuntimeSession(pm)) {
2808
2839
  const redirectResponse = response;
2809
2840
  try {
2810
2841
  response = await pm.runRuntimeRequest(
@@ -2837,6 +2868,33 @@ window.__FARM_MANIFEST__ = ${inlineValue({
2837
2868
  () => middlewareManager.execute(req, res)
2838
2869
  );
2839
2870
  };
2871
+ const sendDevErrorPage = (error) => {
2872
+ if (!res.headersSent) {
2873
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
2874
+ res.setHeader("Cache-Control", "private, no-store");
2875
+ }
2876
+ next(error);
2877
+ };
2878
+ const sendMiddlewareErrorJSON = async (runtimeSession2, error) => {
2879
+ let response = createFarmDevMiddlewareErrorResponse();
2880
+ if (runtimeSession2) {
2881
+ const errorResponse = response;
2882
+ try {
2883
+ response = await pm.completeRuntimeRequest(
2884
+ runtimeSession2,
2885
+ async (_request, runtime) => {
2886
+ await runtime.reportError(error);
2887
+ return errorResponse;
2888
+ }
2889
+ );
2890
+ } catch {
2891
+ sendFarmDevRuntimeHookError(res, runtimeHookErrorAnswersJSON);
2892
+ return 500;
2893
+ }
2894
+ }
2895
+ await sendWebResponse(res, response);
2896
+ return response.status;
2897
+ };
2840
2898
  const runAppMiddlewareInRuntimeSession = async (runtimeSession2, logResponse2) => {
2841
2899
  const interceptor = runtimeSession2 && pm?.hasRuntimeHook("after") && middlewareManager?.hasMiddleware() ? interceptFarmDevPageResponse({
2842
2900
  req,
@@ -2861,8 +2919,13 @@ window.__FARM_MANIFEST__ = ${inlineValue({
2861
2919
  try {
2862
2920
  handled = await runAppMiddlewareForContentRoute();
2863
2921
  } catch (error) {
2864
- interceptor?.release();
2865
- throw error;
2922
+ if (runtimeHookErrorAnswersJSON || res.headersSent) {
2923
+ interceptor?.release();
2924
+ throw error;
2925
+ }
2926
+ if (runtimeSession2) await pm.reportRuntimeRequestError(runtimeSession2, error);
2927
+ sendDevErrorPage(error);
2928
+ return true;
2866
2929
  }
2867
2930
  if (!handled) {
2868
2931
  interceptor?.release();
@@ -2891,7 +2954,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
2891
2954
  await sendWebResponse(res, runtimeResponse);
2892
2955
  };
2893
2956
  let runtimeSession2;
2894
- if (pm?.hasRuntimeRequestHooks()) {
2957
+ if (pm && opensFarmDevRuntimeSession(pm)) {
2895
2958
  try {
2896
2959
  const routePathname = stripFarmBasePath(requestPathname, farmConfig.basePath);
2897
2960
  const route = setFarmRouteLabel(
@@ -2927,8 +2990,14 @@ window.__FARM_MANIFEST__ = ${inlineValue({
2927
2990
  runtimeSession2?.request ?? createRequestFromNodeRequest(req, new URL(fullUrl))
2928
2991
  );
2929
2992
  } catch (error) {
2993
+ if (!responding && !res.headersSent) {
2994
+ logger.error(`Middleware error: ${error}`);
2995
+ await discard();
2996
+ await sendMiddlewareErrorJSON(runtimeSession2, error);
2997
+ return;
2998
+ }
2930
2999
  if (runtimeSession2) await pm.failRuntimeRequest(runtimeSession2, error);
2931
- if (!runtimeSession2 || !responding || res.headersSent) throw error;
3000
+ if (!runtimeSession2 || res.headersSent) throw error;
2932
3001
  console.error("[FARM] Built-in route error:", error);
2933
3002
  sendFarmDevRuntimeHookError(res, runtimeHookErrorAnswersJSON);
2934
3003
  return;
@@ -3065,7 +3134,8 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3065
3134
  stripFarmBasePath(requestPathname, farmConfig.basePath),
3066
3135
  {
3067
3136
  path: farmConfig.docs?.entry || "/docs",
3068
- roots: farmConfig.docs?.roots?.map((root) => root.entry)
3137
+ roots: farmConfig.docs?.roots?.map((root) => root.entry),
3138
+ pages: await getFarmDocsPagePaths()
3069
3139
  }
3070
3140
  )
3071
3141
  }
@@ -3455,7 +3525,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3455
3525
  });
3456
3526
  let runtimeSession2;
3457
3527
  let sessionRequestUrl;
3458
- if (pm?.hasRuntimeRequestHooks()) {
3528
+ if (pm && opensFarmDevRuntimeSession(pm)) {
3459
3529
  try {
3460
3530
  runtimeSession2 = await pm.beginRuntimeRequest(
3461
3531
  await createAPIRequest(),
@@ -3487,9 +3557,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3487
3557
  return;
3488
3558
  }
3489
3559
  logger.error(`API route error: ${error}`);
3490
- res.statusCode = 500;
3491
- res.setHeader("Content-Type", "application/json");
3492
- res.end(FARM_INTERNAL_SERVER_ERROR_BODY);
3560
+ sendFarmDevRuntimeHookError(res, true);
3493
3561
  return;
3494
3562
  }
3495
3563
  pm.copyRequestContext(runtimeSession2.request, req);
@@ -3509,25 +3577,8 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3509
3577
  throw error;
3510
3578
  }
3511
3579
  logger.error(`Middleware error: ${error}`);
3512
- let response = createFarmDevMiddlewareErrorResponse();
3513
- if (runtimeSession2) {
3514
- const errorResponse = response;
3515
- try {
3516
- response = await pm.completeRuntimeRequest(
3517
- runtimeSession2,
3518
- async (_request, runtime) => {
3519
- await runtime.reportError(error);
3520
- return errorResponse;
3521
- }
3522
- );
3523
- } catch {
3524
- logResponse(method2, urlPath2, 500, Date.now() - startTime2, "API");
3525
- sendFarmDevRuntimeHookError(res, runtimeHookErrorAnswersJSON);
3526
- return;
3527
- }
3528
- }
3529
- logResponse(method2, urlPath2, response.status, Date.now() - startTime2, "API");
3530
- await sendWebResponse(res, response);
3580
+ const status = await sendMiddlewareErrorJSON(runtimeSession2, error);
3581
+ logResponse(method2, urlPath2, status, Date.now() - startTime2, "API");
3531
3582
  return;
3532
3583
  }
3533
3584
  const createHandlerRequest = async () => {
@@ -3634,9 +3685,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3634
3685
  return;
3635
3686
  }
3636
3687
  logger.error(`API route error: ${error}`);
3637
- res.statusCode = 500;
3638
- res.setHeader("Content-Type", "application/json");
3639
- res.end(FARM_INTERNAL_SERVER_ERROR_BODY);
3688
+ sendFarmDevRuntimeHookError(res, true);
3640
3689
  return;
3641
3690
  }
3642
3691
  }
@@ -3678,9 +3727,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3678
3727
  return;
3679
3728
  }
3680
3729
  logger.error(`Docs API route error: ${error}`);
3681
- res.statusCode = 500;
3682
- res.setHeader("Content-Type", "application/json");
3683
- res.end(FARM_INTERNAL_SERVER_ERROR_BODY);
3730
+ sendFarmDevRuntimeHookError(res, true);
3684
3731
  return;
3685
3732
  }
3686
3733
  }
@@ -3704,9 +3751,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
3704
3751
  await sendWebResponse(res, response);
3705
3752
  } catch (error) {
3706
3753
  logger.error(`API route error: ${error}`);
3707
- res.statusCode = 500;
3708
- res.setHeader("Content-Type", "application/json");
3709
- res.end(FARM_INTERNAL_SERVER_ERROR_BODY);
3754
+ sendFarmDevRuntimeHookError(res, true);
3710
3755
  }
3711
3756
  return;
3712
3757
  }
@@ -4083,7 +4128,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
4083
4128
  const hasBeforeRenderHook = pm?.hasHook("beforeRender") ?? false;
4084
4129
  const hasAfterResponseHook = pm?.hasHook("afterResponse") ?? false;
4085
4130
  const hasHTMLTransformHook = (pm?.hasHook("transformHTML") ?? false) || (pm?.hasHook("afterRender") ?? false);
4086
- const hasRuntimeRequestHooks = pm?.hasRuntimeRequestHooks() ?? false;
4131
+ const opensRuntimeSession = pm ? opensFarmDevRuntimeSession(pm) : false;
4087
4132
  const hasRuntimeAfterHook = pm?.hasRuntimeHook("after") ?? false;
4088
4133
  const requestedMatch = routeManager2.matchRoute(requestedPathname);
4089
4134
  const pageBuiltInRouteLabel = (pathname2) => {
@@ -4095,7 +4140,7 @@ window.__FARM_MANIFEST__ = ${inlineValue({
4095
4140
  };
4096
4141
  let runtimeSession;
4097
4142
  let pathname = requestedPathname;
4098
- if (pm && hasRuntimeRequestHooks) {
4143
+ if (pm && opensRuntimeSession) {
4099
4144
  try {
4100
4145
  const sessionOptions = {
4101
4146
  kind: "page",
@@ -4132,20 +4177,39 @@ window.__FARM_MANIFEST__ = ${inlineValue({
4132
4177
  }
4133
4178
  }
4134
4179
  const routeMatch = pathname === requestedPathname ? requestedMatch : routeManager2.matchRoute(pathname);
4135
- if (pm && hasBeforeRouteMatchHook) {
4136
- await pm.runHookParallel("beforeRouteMatch", {
4137
- pathname,
4138
- method
4139
- });
4140
- }
4141
- if (pm && hasAfterRouteMatchHook) {
4142
- await pm.runHookParallel("afterRouteMatch", {
4143
- pathname,
4144
- matched: !!routeMatch?.route,
4145
- routePattern: routeMatch?.route?.pattern || null,
4146
- params: routeMatch?.params || {},
4147
- layoutPatterns: (routeMatch?.layouts || []).map((l) => l.pattern)
4148
- });
4180
+ const failPageHook = async (error, interceptor) => {
4181
+ interceptor?.release();
4182
+ logResponse(method, urlPath, 500, Date.now() - startTime, "PAGE");
4183
+ if (runtimeSession) {
4184
+ await pm.failRuntimeRequest(runtimeSession, error);
4185
+ } else {
4186
+ await emitPluginError("runtime", error, {
4187
+ kind: "page",
4188
+ pathname,
4189
+ durationMs: Date.now() - startTime
4190
+ });
4191
+ }
4192
+ if (!res.headersSent) sendFarmDevRuntimeHookError(res, runtimeHookErrorAnswersJSON);
4193
+ };
4194
+ try {
4195
+ if (pm && hasBeforeRouteMatchHook) {
4196
+ await pm.runHookParallel("beforeRouteMatch", {
4197
+ pathname,
4198
+ method
4199
+ });
4200
+ }
4201
+ if (pm && hasAfterRouteMatchHook) {
4202
+ await pm.runHookParallel("afterRouteMatch", {
4203
+ pathname,
4204
+ matched: !!routeMatch?.route,
4205
+ routePattern: routeMatch?.route?.pattern || null,
4206
+ params: routeMatch?.params || {},
4207
+ layoutPatterns: (routeMatch?.layouts || []).map((l) => l.pattern)
4208
+ });
4209
+ }
4210
+ } catch (error) {
4211
+ await failPageHook(error);
4212
+ return;
4149
4213
  }
4150
4214
  const renderPayload = {
4151
4215
  pathname,
@@ -4212,7 +4276,12 @@ window.__FARM_MANIFEST__ = ${inlineValue({
4212
4276
  }
4213
4277
  const renderer = farmApp.getServerRenderer();
4214
4278
  if (pm && hasBeforeRenderHook) {
4215
- await pm.runHookParallel("beforeRender", renderPayload);
4279
+ try {
4280
+ await pm.runHookParallel("beforeRender", renderPayload);
4281
+ } catch (error) {
4282
+ await failPageHook(error, responseInterceptor);
4283
+ return;
4284
+ }
4216
4285
  }
4217
4286
  await renderer.renderPage(req, res);
4218
4287
  if (!shouldInterceptResponse) {
@@ -4222,20 +4291,25 @@ window.__FARM_MANIFEST__ = ${inlineValue({
4222
4291
  const duration = Date.now() - startTime;
4223
4292
  logResponse(method, urlPath, 500, duration, "PAGE");
4224
4293
  if (pm && runtimeSession) {
4225
- await pm.failRuntimeRequest(runtimeSession, error);
4226
- }
4227
- if (!(middlewareFailed && runtimeSession)) {
4294
+ if (middlewareFailed) {
4295
+ await pm.reportRuntimeRequestError(runtimeSession, error);
4296
+ } else {
4297
+ await pm.failRuntimeRequest(runtimeSession, error);
4298
+ if (!res.headersSent && !responseInterceptor?.isEnded()) {
4299
+ responseInterceptor?.release();
4300
+ console.error("[FARM] Page error:", error);
4301
+ sendFarmDevRuntimeHookError(res, runtimeHookErrorAnswersJSON);
4302
+ return;
4303
+ }
4304
+ }
4305
+ } else {
4228
4306
  await emitPluginError("render-page", error, { pathname });
4229
4307
  }
4230
4308
  if (rendererDisabled && !res.headersSent) {
4231
4309
  sendFarmDevErrorJSON(res);
4232
4310
  return;
4233
4311
  }
4234
- if (!res.headersSent) {
4235
- res.setHeader("Content-Type", "text/html; charset=utf-8");
4236
- res.setHeader("Cache-Control", "private, no-store");
4237
- }
4238
- next(error);
4312
+ sendDevErrorPage(error);
4239
4313
  }
4240
4314
  })
4241
4315
  );
@@ -21,7 +21,7 @@ import {
21
21
  } from "./chunk-JSDV2NUN.mjs";
22
22
  import {
23
23
  FARM_VERSION
24
- } from "./chunk-F6CMGWAL.mjs";
24
+ } from "./chunk-ANMIR6US.mjs";
25
25
 
26
26
  // src/environment-vite.ts
27
27
  import { existsSync, readFileSync, realpathSync } from "fs";
@@ -21,7 +21,7 @@ var _chunkE7QOEV5Zcjs = require('./chunk-E7QOEV5Z.cjs');
21
21
  var _chunkQMNWKQL4cjs = require('./chunk-QMNWKQL4.cjs');
22
22
 
23
23
 
24
- var _chunkSQ6IWJ3Hcjs = require('./chunk-SQ6IWJ3H.cjs');
24
+ var _chunk22LGTSBAcjs = require('./chunk-22LGTSBA.cjs');
25
25
 
26
26
  // src/environment-vite.ts
27
27
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
@@ -1667,7 +1667,7 @@ var PackageClientBoundaryCache = class {
1667
1667
  }
1668
1668
  const contents = JSON.stringify({
1669
1669
  schema: SCHEMA_VERSION,
1670
- farm: _chunkSQ6IWJ3Hcjs.FARM_VERSION,
1670
+ farm: _chunk22LGTSBAcjs.FARM_VERSION,
1671
1671
  paths,
1672
1672
  entries
1673
1673
  });
@@ -1707,7 +1707,7 @@ function readStoredCache(file) {
1707
1707
  } catch (e26) {
1708
1708
  return null;
1709
1709
  }
1710
- if (!isRecord(value) || value.schema !== SCHEMA_VERSION || value.farm !== _chunkSQ6IWJ3Hcjs.FARM_VERSION) {
1710
+ if (!isRecord(value) || value.schema !== SCHEMA_VERSION || value.farm !== _chunk22LGTSBAcjs.FARM_VERSION) {
1711
1711
  return null;
1712
1712
  }
1713
1713
  const { paths, entries } = value;
@@ -1718,7 +1718,7 @@ function readStoredCache(file) {
1718
1718
  const usable = variants.filter((entry) => isStoredEntry(entry, paths.length));
1719
1719
  if (usable.length > 0) valid[key] = usable;
1720
1720
  }
1721
- return { schema: SCHEMA_VERSION, farm: _chunkSQ6IWJ3Hcjs.FARM_VERSION, paths, entries: valid };
1721
+ return { schema: SCHEMA_VERSION, farm: _chunk22LGTSBAcjs.FARM_VERSION, paths, entries: valid };
1722
1722
  }
1723
1723
  function isRecord(value) {
1724
1724
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  resolveFarmPlatform
3
3
  } from "./chunk-SMUW7UST.mjs";
4
+ import {
5
+ getFarmIntegrationPluginServerRuntime
6
+ } from "./chunk-AJNBTOVQ.mjs";
4
7
  import {
5
8
  formatOptionalPeerInstallHint,
6
9
  isMissingPackageError
@@ -278,6 +281,16 @@ function isArrayIndex(key) {
278
281
  return Number.isInteger(value) && value >= 0 && value < 4294967295 && String(value) === key;
279
282
  }
280
283
 
284
+ // src/plugin-server-runtime.ts
285
+ function hasFarmServerRuntimePlugins(plugins) {
286
+ return (plugins || []).some((plugin) => {
287
+ if (getFarmIntegrationPluginServerRuntime(plugin) === false) return false;
288
+ return Boolean(
289
+ plugin.setup || plugin.init || plugin.ready || plugin.shutdown || plugin.runtime || plugin.router || plugin.render || plugin.beforeRouteMatch || plugin.afterRouteMatch || plugin.beforeRender || plugin.afterRender || plugin.onError || plugin.transformHTML
290
+ );
291
+ });
292
+ }
293
+
281
294
  // src/build/tailwind.ts
282
295
  import path2 from "path";
283
296
 
@@ -371,5 +384,6 @@ export {
371
384
  resolveFarmAppClientEntry,
372
385
  resolveFarmClientPlugins,
373
386
  generateFarmClientPluginEntryCode,
387
+ hasFarmServerRuntimePlugins,
374
388
  loadTailwindVitePlugin
375
389
  };
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-K6SXMVXO.mjs";
5
5
  import {
6
6
  normalizeFarmProductionSiteOrigin
7
- } from "./chunk-T5XFZQCL.mjs";
7
+ } from "./chunk-2P7UYHZP.mjs";
8
8
  import {
9
9
  resolveFarmAppManifestConfig
10
10
  } from "./chunk-SQ5O7I3L.mjs";
@@ -29,7 +29,7 @@ import {
29
29
  } from "./chunk-QDWMCFTH.mjs";
30
30
  import {
31
31
  FARM_VERSION
32
- } from "./chunk-F6CMGWAL.mjs";
32
+ } from "./chunk-ANMIR6US.mjs";
33
33
  import {
34
34
  applyFarmBasePath
35
35
  } from "./chunk-SF3JB56B.mjs";
@@ -462,6 +462,7 @@ function resolveFarmMCPRouteLabel(routePathname, apiServerBasePath) {
462
462
  }
463
463
  return null;
464
464
  }
465
+ var PUBLISHED_PAGE_PATH = /^\/[a-zA-Z0-9_./-]{0,250}$/;
465
466
  function resolveFarmDocsRouteLabel(routePathname, docs) {
466
467
  const pathname = normalize(routePathname);
467
468
  const apiPath = normalize(docs.apiPath ?? "/api/docs");
@@ -475,7 +476,10 @@ function resolveFarmDocsRouteLabel(routePathname, docs) {
475
476
  if (page === entry || entry === "/" && page === "/index") {
476
477
  return markdown ? getFarmMarkdownMirrorPath(entry) : entry;
477
478
  }
478
- if (page.startsWith(`${base}/`)) return `${base}/[...slug]${markdown ? ".md" : ""}`;
479
+ if (page.startsWith(`${base}/`)) {
480
+ const label = docs.pages?.has(page) && PUBLISHED_PAGE_PATH.test(page) ? page : `${base}/[...slug]`;
481
+ return `${label}${markdown ? ".md" : ""}`;
482
+ }
479
483
  }
480
484
  return null;
481
485
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getFarmRouteLabel
3
- } from "./chunk-VFNAK6A5.mjs";
3
+ } from "./chunk-ZR2QB45W.mjs";
4
4
  import {
5
5
  classifyFarmAgent
6
6
  } from "./chunk-IFR74W6S.mjs";
@@ -1,5 +1,5 @@
1
- import { R as RouteRenderingOptions, D as DirectiveRenderingConfig, a as RouteRenderingConfig } from './route-rendering.d-CUylZKJA.js';
2
- import { i as RouteModule, b8 as SSGCollectionResult, b9 as SSGPage } from './client-plugins.d-CNDqcAuf.js';
1
+ import { R as RouteRenderingOptions, D as DirectiveRenderingConfig, a as RouteRenderingConfig } from './route-rendering.d-FDSNtCMg.js';
2
+ import { i as RouteModule, b8 as SSGCollectionResult, b9 as SSGPage } from './client-plugins.d-D7dHV1Nf.js';
3
3
  import { F as FarmIslandStrategy } from './island.d-CfGru1MO.js';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { R as RouteRenderingOptions, D as DirectiveRenderingConfig, a as RouteRenderingConfig } from './route-rendering.d-Ds0BfwQi.mjs';
2
- import { i as RouteModule, b8 as SSGCollectionResult, b9 as SSGPage } from './client-plugins.d-CE1lVK2R.mjs';
1
+ import { R as RouteRenderingOptions, D as DirectiveRenderingConfig, a as RouteRenderingConfig } from './route-rendering.d-D0bmZVJA.mjs';
2
+ import { i as RouteModule, b8 as SSGCollectionResult, b9 as SSGPage } from './client-plugins.d-Do5ULA0x.mjs';
3
3
  import { F as FarmIslandStrategy } from './island.d-CfGru1MO.mjs';
4
4
 
5
5
  /**