@farm.js/core 0.1.0-beta.50 → 0.1.0-beta.52

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 (50) hide show
  1. package/dist/{chunk-HSHA3H3U.mjs → chunk-3E2WRUR2.mjs} +15 -1
  2. package/dist/chunk-3E2WRUR2.mjs.map +1 -0
  3. package/dist/{chunk-6YIZDTX7.mjs → chunk-BTFOMBWK.mjs} +43 -5
  4. package/dist/chunk-BTFOMBWK.mjs.map +1 -0
  5. package/dist/{chunk-GM43ZLTS.mjs → chunk-JK6YAQ3E.mjs} +52 -9
  6. package/dist/chunk-JK6YAQ3E.mjs.map +1 -0
  7. package/dist/{chunk-ZAW3D2TI.mjs → chunk-M2DI67UZ.mjs} +2 -2
  8. package/dist/{chunk-DDE3BBDN.mjs → chunk-TW74WBSB.mjs} +2 -2
  9. package/dist/{chunk-DDE3BBDN.mjs.map → chunk-TW74WBSB.mjs.map} +1 -1
  10. package/dist/{chunk-QTAJIJJJ.mjs → chunk-XMUPYG2D.mjs} +2 -2
  11. package/dist/client/lifecycle.mjs +2 -2
  12. package/dist/client-plugins.cjs +1 -1
  13. package/dist/client-plugins.cjs.map +1 -1
  14. package/dist/client-plugins.mjs +2 -2
  15. package/dist/client.cjs +15 -1
  16. package/dist/client.cjs.map +1 -1
  17. package/dist/client.mjs +4 -4
  18. package/dist/index.cjs +113 -11
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.mjs +6 -6
  21. package/dist/internal/build-runtime.cjs +99 -11
  22. package/dist/internal/build-runtime.cjs.map +1 -1
  23. package/dist/internal/build-runtime.mjs +3 -3
  24. package/dist/internal/client-runtime.cjs +1 -1
  25. package/dist/internal/client-runtime.cjs.map +1 -1
  26. package/dist/internal/client-runtime.mjs +2 -2
  27. package/dist/plugin.cjs +51 -8
  28. package/dist/plugin.cjs.map +1 -1
  29. package/dist/plugin.mjs +2 -2
  30. package/dist/renderer-client.cjs +14 -0
  31. package/dist/renderer-client.cjs.map +1 -1
  32. package/dist/renderer-client.mjs +1 -1
  33. package/dist/server-query-client.cjs +14 -0
  34. package/dist/server-query-client.cjs.map +1 -1
  35. package/dist/server-query-client.mjs +2 -2
  36. package/dist/server.cjs +51 -8
  37. package/dist/server.cjs.map +1 -1
  38. package/dist/server.mjs +2 -2
  39. package/dist/version.cjs +1 -1
  40. package/dist/version.cjs.map +1 -1
  41. package/dist/version.mjs +1 -1
  42. package/dist/vite.cjs +51 -8
  43. package/dist/vite.cjs.map +1 -1
  44. package/dist/vite.mjs +2 -2
  45. package/package.json +1 -1
  46. package/dist/chunk-6YIZDTX7.mjs.map +0 -1
  47. package/dist/chunk-GM43ZLTS.mjs.map +0 -1
  48. package/dist/chunk-HSHA3H3U.mjs.map +0 -1
  49. /package/dist/{chunk-ZAW3D2TI.mjs.map → chunk-M2DI67UZ.mjs.map} +0 -0
  50. /package/dist/{chunk-QTAJIJJJ.mjs.map → chunk-XMUPYG2D.mjs.map} +0 -0
@@ -227,7 +227,7 @@ import {
227
227
  } from "./chunk-7ZMKVETU.mjs";
228
228
  import {
229
229
  FARM_VERSION
230
- } from "./chunk-DDE3BBDN.mjs";
230
+ } from "./chunk-TW74WBSB.mjs";
231
231
  import {
232
232
  __name,
233
233
  __require
@@ -6858,6 +6858,14 @@ import { pathToFileURL as pathToFileURL3 } from "url";
6858
6858
  // src/dev-static.ts
6859
6859
  import * as fs6 from "fs";
6860
6860
  import * as path11 from "path";
6861
+ function shouldBypassFarmRouterForDottedPath(pathname, routeManager, baseDirs) {
6862
+ if (!pathname.includes(".") || pathname.endsWith(".html")) return false;
6863
+ const matchesAppRoute = Boolean(
6864
+ routeManager?.matchRoute(pathname)?.route || routeManager?.matchMetadataRoute(pathname) || routeManager?.matchMetadataImage(pathname)
6865
+ );
6866
+ return !matchesAppRoute || devServableFileExists(pathname, baseDirs);
6867
+ }
6868
+ __name(shouldBypassFarmRouterForDottedPath, "shouldBypassFarmRouterForDottedPath");
6861
6869
  function devServableFileExists(pathname, baseDirs) {
6862
6870
  let decodedPathname;
6863
6871
  try {
@@ -6883,6 +6891,34 @@ function devServableFileExists(pathname, baseDirs) {
6883
6891
  }
6884
6892
  __name(devServableFileExists, "devServableFileExists");
6885
6893
 
6894
+ // src/server-query-boundary.ts
6895
+ var SERVER_FN_FACTORIES = ["createServerQuery", "createServerFn"];
6896
+ var FARM_CORE_IMPORT_RE = /import\s*(?!type\b)(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*(["'])@farm\.js\/core(?:\/[\w./-]+)?\2/g;
6897
+ function findClientServerFnViolation(code, id) {
6898
+ if (id.startsWith("\0") || id.startsWith("virtual:") || id.includes("node_modules")) return null;
6899
+ if (!code.includes("@farm.js/core")) return null;
6900
+ for (const match of code.matchAll(FARM_CORE_IMPORT_RE)) {
6901
+ const specifiers = match[1];
6902
+ for (const factory of SERVER_FN_FACTORIES) {
6903
+ if (!new RegExp(`(?:^|[\\s{,])${factory}(?:[\\s},]|$)`).test(specifiers)) continue;
6904
+ if (new RegExp(`(?<![\\w$.])${factory}\\s*(?:<[^>]*>)?\\s*\\(`).test(code)) {
6905
+ return { factory };
6906
+ }
6907
+ }
6908
+ }
6909
+ return null;
6910
+ }
6911
+ __name(findClientServerFnViolation, "findClientServerFnViolation");
6912
+ function formatServerFnBoundaryError(violation, id) {
6913
+ return [
6914
+ `${violation.factory} handlers run only on the server, but ${id} is being bundled into the client.`,
6915
+ `Importing a ${violation.factory} module from client code executes the server handler (and its Node-only imports) in the browser.`,
6916
+ `Either enable the server-function transform (add @farm.js/plugin/rsc and set experimental.serverActions: true in farm.config.ts) so client imports become server references,`,
6917
+ `or keep the query on the server: call it from server components, or expose an API route and use createAPIClient from the client.`
6918
+ ].join("\n");
6919
+ }
6920
+ __name(formatServerFnBoundaryError, "formatServerFnBoundaryError");
6921
+
6886
6922
  // src/image-vite.ts
6887
6923
  import { readFile as readFile4 } from "fs/promises";
6888
6924
  import path12 from "path";
@@ -8427,13 +8463,11 @@ window.__FARM_MANIFEST__ = ${inlineValue({
8427
8463
  if (req.url?.startsWith("/@") || req.url?.startsWith("/node_modules")) {
8428
8464
  return next();
8429
8465
  }
8430
- if (requestPathname.includes(".") && !requestPathname.endsWith(".html")) {
8431
- const matchesAppRoute = Boolean(
8432
- farmApp?.getRouteManager()?.matchRoute(requestPathname)?.route
8433
- );
8434
- if (!matchesAppRoute || devServableFileExists(requestPathname, [server.config.publicDir, server.config.root])) {
8435
- return next();
8436
- }
8466
+ if (shouldBypassFarmRouterForDottedPath(requestPathname, farmApp?.getRouteManager(), [
8467
+ server.config.publicDir,
8468
+ server.config.root
8469
+ ])) {
8470
+ return next();
8437
8471
  }
8438
8472
  if (req.url?.startsWith("/__farm/page-data")) {
8439
8473
  const urlObj = new URL(req.url, `http://${req.headers.host || "localhost:3000"}`);
@@ -9087,6 +9121,15 @@ export const manifest = getManifest();
9087
9121
  }
9088
9122
  },
9089
9123
  async transform(code, id, transformOptions) {
9124
+ if (!transformOptions?.ssr) {
9125
+ const currentConfig = farmApp?.getConfig() ?? options;
9126
+ if (currentConfig.experimental?.serverActions !== true) {
9127
+ const violation = findClientServerFnViolation(code, id);
9128
+ if (violation) {
9129
+ this.error(formatServerFnBoundaryError(violation, id));
9130
+ }
9131
+ }
9132
+ }
9090
9133
  if (typeof imageImports.transform === "function") {
9091
9134
  const imageModule = await imageImports.transform.call(this, code, id, transformOptions);
9092
9135
  if (imageModule) return imageModule;
@@ -11328,4 +11371,4 @@ export {
11328
11371
  farmPlugin,
11329
11372
  defineConfig
11330
11373
  };
11331
- //# sourceMappingURL=chunk-GM43ZLTS.mjs.map
11374
+ //# sourceMappingURL=chunk-JK6YAQ3E.mjs.map