@farm.js/core 0.1.0-beta.51 → 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 (49) 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-235ZOXDY.mjs → chunk-BTFOMBWK.mjs} +2 -2
  4. package/dist/{chunk-QCSOE6HT.mjs → chunk-JK6YAQ3E.mjs} +52 -9
  5. package/dist/chunk-JK6YAQ3E.mjs.map +1 -0
  6. package/dist/{chunk-ZAW3D2TI.mjs → chunk-M2DI67UZ.mjs} +2 -2
  7. package/dist/{chunk-7XJV5RZO.mjs → chunk-TW74WBSB.mjs} +2 -2
  8. package/dist/{chunk-7XJV5RZO.mjs.map → chunk-TW74WBSB.mjs.map} +1 -1
  9. package/dist/{chunk-FRN7PNL4.mjs → chunk-XMUPYG2D.mjs} +2 -2
  10. package/dist/client/lifecycle.mjs +2 -2
  11. package/dist/client-plugins.cjs +1 -1
  12. package/dist/client-plugins.cjs.map +1 -1
  13. package/dist/client-plugins.mjs +2 -2
  14. package/dist/client.cjs +15 -1
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.mjs +4 -4
  17. package/dist/index.cjs +72 -8
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.mjs +6 -6
  20. package/dist/internal/build-runtime.cjs +58 -8
  21. package/dist/internal/build-runtime.cjs.map +1 -1
  22. package/dist/internal/build-runtime.mjs +3 -3
  23. package/dist/internal/client-runtime.cjs +1 -1
  24. package/dist/internal/client-runtime.cjs.map +1 -1
  25. package/dist/internal/client-runtime.mjs +2 -2
  26. package/dist/plugin.cjs +51 -8
  27. package/dist/plugin.cjs.map +1 -1
  28. package/dist/plugin.mjs +2 -2
  29. package/dist/renderer-client.cjs +14 -0
  30. package/dist/renderer-client.cjs.map +1 -1
  31. package/dist/renderer-client.mjs +1 -1
  32. package/dist/server-query-client.cjs +14 -0
  33. package/dist/server-query-client.cjs.map +1 -1
  34. package/dist/server-query-client.mjs +2 -2
  35. package/dist/server.cjs +51 -8
  36. package/dist/server.cjs.map +1 -1
  37. package/dist/server.mjs +2 -2
  38. package/dist/version.cjs +1 -1
  39. package/dist/version.cjs.map +1 -1
  40. package/dist/version.mjs +1 -1
  41. package/dist/vite.cjs +51 -8
  42. package/dist/vite.cjs.map +1 -1
  43. package/dist/vite.mjs +2 -2
  44. package/package.json +1 -1
  45. package/dist/chunk-HSHA3H3U.mjs.map +0 -1
  46. package/dist/chunk-QCSOE6HT.mjs.map +0 -1
  47. /package/dist/{chunk-235ZOXDY.mjs.map → chunk-BTFOMBWK.mjs.map} +0 -0
  48. /package/dist/{chunk-ZAW3D2TI.mjs.map → chunk-M2DI67UZ.mjs.map} +0 -0
  49. /package/dist/{chunk-FRN7PNL4.mjs.map → chunk-XMUPYG2D.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-5ZGPRGWV.mjs";
10
10
  import {
11
11
  build
12
- } from "./chunk-235ZOXDY.mjs";
12
+ } from "./chunk-BTFOMBWK.mjs";
13
13
  import "./chunk-SL6HTIOK.mjs";
14
14
  import "./chunk-4S3ORGFA.mjs";
15
15
  import {
@@ -144,7 +144,7 @@ import {
144
144
  } from "./chunk-SALMKQXH.mjs";
145
145
  import {
146
146
  useServerQuery
147
- } from "./chunk-ZAW3D2TI.mjs";
147
+ } from "./chunk-M2DI67UZ.mjs";
148
148
  import {
149
149
  useBlocker,
150
150
  useNavigation,
@@ -179,7 +179,7 @@ import {
179
179
  completeFarmServerQueryAction,
180
180
  fetchServerQuery,
181
181
  prefetchServerQuery
182
- } from "./chunk-HSHA3H3U.mjs";
182
+ } from "./chunk-3E2WRUR2.mjs";
183
183
  import {
184
184
  SPARouter,
185
185
  getRouter,
@@ -208,7 +208,7 @@ import {
208
208
  createClientPluginManager,
209
209
  installChunkErrorRecovery,
210
210
  isChunkLoadError
211
- } from "./chunk-FRN7PNL4.mjs";
211
+ } from "./chunk-XMUPYG2D.mjs";
212
212
  import {
213
213
  analyzeStaticRouteCandidate,
214
214
  collectSSGPages,
@@ -227,7 +227,7 @@ import {
227
227
  parseRouteRenderingDirective,
228
228
  resolveRouteRenderingConfig,
229
229
  resolveRouteRenderingConfigFromFile
230
- } from "./chunk-QCSOE6HT.mjs";
230
+ } from "./chunk-JK6YAQ3E.mjs";
231
231
  import {
232
232
  APITypeGenerator
233
233
  } from "./chunk-XJTDE4L4.mjs";
@@ -568,7 +568,7 @@ import {
568
568
  runWithFarmSpan
569
569
  } from "./chunk-7ZMKVETU.mjs";
570
570
  import "./chunk-FXG2PS27.mjs";
571
- import "./chunk-7XJV5RZO.mjs";
571
+ import "./chunk-TW74WBSB.mjs";
572
572
  import {
573
573
  createCompressionPlugin,
574
574
  createEnvPlugin,
@@ -14918,7 +14918,7 @@ var init_server3 = __esm({
14918
14918
  var version;
14919
14919
  var init_package = __esm({
14920
14920
  "package.json"() {
14921
- version = "0.1.0-beta.51";
14921
+ version = "0.1.0-beta.52";
14922
14922
  }
14923
14923
  });
14924
14924
 
@@ -20856,6 +20856,13 @@ var init_after = __esm({
20856
20856
  });
20857
20857
 
20858
20858
  // src/dev-static.ts
20859
+ function shouldBypassFarmRouterForDottedPath(pathname, routeManager, baseDirs) {
20860
+ if (!pathname.includes(".") || pathname.endsWith(".html")) return false;
20861
+ const matchesAppRoute = Boolean(
20862
+ routeManager?.matchRoute(pathname)?.route || routeManager?.matchMetadataRoute(pathname) || routeManager?.matchMetadataImage(pathname)
20863
+ );
20864
+ return !matchesAppRoute || devServableFileExists(pathname, baseDirs);
20865
+ }
20859
20866
  function devServableFileExists(pathname, baseDirs) {
20860
20867
  let decodedPathname;
20861
20868
  try {
@@ -20885,10 +20892,45 @@ var init_dev_static = __esm({
20885
20892
  "use strict";
20886
20893
  fs10 = __toESM(require("fs"));
20887
20894
  path29 = __toESM(require("path"));
20895
+ __name(shouldBypassFarmRouterForDottedPath, "shouldBypassFarmRouterForDottedPath");
20888
20896
  __name(devServableFileExists, "devServableFileExists");
20889
20897
  }
20890
20898
  });
20891
20899
 
20900
+ // src/server-query-boundary.ts
20901
+ function findClientServerFnViolation(code, id) {
20902
+ if (id.startsWith("\0") || id.startsWith("virtual:") || id.includes("node_modules")) return null;
20903
+ if (!code.includes("@farm.js/core")) return null;
20904
+ for (const match of code.matchAll(FARM_CORE_IMPORT_RE)) {
20905
+ const specifiers = match[1];
20906
+ for (const factory of SERVER_FN_FACTORIES) {
20907
+ if (!new RegExp(`(?:^|[\\s{,])${factory}(?:[\\s},]|$)`).test(specifiers)) continue;
20908
+ if (new RegExp(`(?<![\\w$.])${factory}\\s*(?:<[^>]*>)?\\s*\\(`).test(code)) {
20909
+ return { factory };
20910
+ }
20911
+ }
20912
+ }
20913
+ return null;
20914
+ }
20915
+ function formatServerFnBoundaryError(violation, id) {
20916
+ return [
20917
+ `${violation.factory} handlers run only on the server, but ${id} is being bundled into the client.`,
20918
+ `Importing a ${violation.factory} module from client code executes the server handler (and its Node-only imports) in the browser.`,
20919
+ `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,`,
20920
+ `or keep the query on the server: call it from server components, or expose an API route and use createAPIClient from the client.`
20921
+ ].join("\n");
20922
+ }
20923
+ var SERVER_FN_FACTORIES, FARM_CORE_IMPORT_RE;
20924
+ var init_server_query_boundary = __esm({
20925
+ "src/server-query-boundary.ts"() {
20926
+ "use strict";
20927
+ SERVER_FN_FACTORIES = ["createServerQuery", "createServerFn"];
20928
+ FARM_CORE_IMPORT_RE = /import\s*(?!type\b)(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*(["'])@farm\.js\/core(?:\/[\w./-]+)?\2/g;
20929
+ __name(findClientServerFnViolation, "findClientServerFnViolation");
20930
+ __name(formatServerFnBoundaryError, "formatServerFnBoundaryError");
20931
+ }
20932
+ });
20933
+
20892
20934
  // src/image-vite.ts
20893
20935
  function farmImageImportsPlugin() {
20894
20936
  return {
@@ -27648,13 +27690,11 @@ window.__FARM_MANIFEST__ = ${inlineValue({
27648
27690
  if (req.url?.startsWith("/@") || req.url?.startsWith("/node_modules")) {
27649
27691
  return next();
27650
27692
  }
27651
- if (requestPathname.includes(".") && !requestPathname.endsWith(".html")) {
27652
- const matchesAppRoute = Boolean(
27653
- farmApp?.getRouteManager()?.matchRoute(requestPathname)?.route
27654
- );
27655
- if (!matchesAppRoute || devServableFileExists(requestPathname, [server.config.publicDir, server.config.root])) {
27656
- return next();
27657
- }
27693
+ if (shouldBypassFarmRouterForDottedPath(requestPathname, farmApp?.getRouteManager(), [
27694
+ server.config.publicDir,
27695
+ server.config.root
27696
+ ])) {
27697
+ return next();
27658
27698
  }
27659
27699
  if (req.url?.startsWith("/__farm/page-data")) {
27660
27700
  const urlObj = new URL(req.url, `http://${req.headers.host || "localhost:3000"}`);
@@ -28308,6 +28348,15 @@ export const manifest = getManifest();
28308
28348
  }
28309
28349
  },
28310
28350
  async transform(code, id, transformOptions) {
28351
+ if (!transformOptions?.ssr) {
28352
+ const currentConfig = farmApp?.getConfig() ?? options;
28353
+ if (currentConfig.experimental?.serverActions !== true) {
28354
+ const violation = findClientServerFnViolation(code, id);
28355
+ if (violation) {
28356
+ this.error(formatServerFnBoundaryError(violation, id));
28357
+ }
28358
+ }
28359
+ }
28311
28360
  if (typeof imageImports.transform === "function") {
28312
28361
  const imageModule = await imageImports.transform.call(this, code, id, transformOptions);
28313
28362
  if (imageModule) return imageModule;
@@ -30531,6 +30580,7 @@ var init_vite2 = __esm({
30531
30580
  init_deferred();
30532
30581
  init_after();
30533
30582
  init_dev_static();
30583
+ init_server_query_boundary();
30534
30584
  init_deployment();
30535
30585
  init_image_config();
30536
30586
  init_image_vite();