@farm.js/core 0.1.0-beta.48 → 0.1.0-beta.49

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 (92) hide show
  1. package/dist/api/route-manager.cjs.map +1 -1
  2. package/dist/api/route-manager.mjs +2 -2
  3. package/dist/api.cjs.map +1 -1
  4. package/dist/api.mjs +3 -3
  5. package/dist/{chunk-TIESOJ7Z.mjs → chunk-BOSVED4K.mjs} +2 -2
  6. package/dist/{chunk-XR7M5VXU.mjs → chunk-DF6GAB63.mjs} +2 -2
  7. package/dist/{chunk-3P63LWDM.mjs → chunk-DWG3W2FN.mjs} +2 -2
  8. package/dist/{chunk-3UUEBVR3.mjs → chunk-ECGXDMBF.mjs} +3 -3
  9. package/dist/{chunk-MP2SDRRB.mjs → chunk-HB3XKQ5X.mjs} +2 -2
  10. package/dist/{chunk-EHUGMAWL.mjs → chunk-LIBL3V6K.mjs} +3 -3
  11. package/dist/{chunk-ECLWCE4H.mjs → chunk-MHE2AMUC.mjs} +2 -2
  12. package/dist/{chunk-GXASWWJU.mjs → chunk-RS5Z5M26.mjs} +5 -2
  13. package/dist/chunk-RS5Z5M26.mjs.map +1 -0
  14. package/dist/{chunk-HEZHCCMF.mjs → chunk-UQ3PDDAK.mjs} +65 -29
  15. package/dist/chunk-UQ3PDDAK.mjs.map +1 -0
  16. package/dist/{chunk-VZKOMD6C.mjs → chunk-VVVDVGAS.mjs} +8 -8
  17. package/dist/{chunk-NKIHYEWC.mjs → chunk-X3JR4G7L.mjs} +2 -2
  18. package/dist/{chunk-NKIHYEWC.mjs.map → chunk-X3JR4G7L.mjs.map} +1 -1
  19. package/dist/{chunk-4E6VRJ6P.mjs → chunk-XY3B4K5E.mjs} +6 -3
  20. package/dist/chunk-XY3B4K5E.mjs.map +1 -0
  21. package/dist/{chunk-U5SPS2HR.mjs → chunk-YB7QPRM4.mjs} +6 -1
  22. package/dist/chunk-YB7QPRM4.mjs.map +1 -0
  23. package/dist/client/lifecycle.mjs +2 -2
  24. package/dist/client-plugins.cjs +1 -1
  25. package/dist/client-plugins.cjs.map +1 -1
  26. package/dist/client-plugins.mjs +2 -2
  27. package/dist/client.cjs +1 -1
  28. package/dist/client.cjs.map +1 -1
  29. package/dist/client.mjs +2 -2
  30. package/dist/cron.cjs +9 -1
  31. package/dist/cron.cjs.map +1 -1
  32. package/dist/cron.mjs +2 -1
  33. package/dist/{devtools-BUFIHBX3.mjs → devtools-S7KR2MMF.mjs} +5 -4
  34. package/dist/{devtools-BUFIHBX3.mjs.map → devtools-S7KR2MMF.mjs.map} +1 -1
  35. package/dist/docs.mjs +5 -4
  36. package/dist/index.cjs +66 -23
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.mts +1 -1
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.mjs +15 -13
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/internal/build-runtime.cjs +230 -189
  43. package/dist/internal/build-runtime.cjs.map +1 -1
  44. package/dist/internal/build-runtime.d.mts +1 -1
  45. package/dist/internal/build-runtime.d.ts +1 -1
  46. package/dist/internal/build-runtime.mjs +10 -10
  47. package/dist/internal/client-runtime.cjs +1 -1
  48. package/dist/internal/client-runtime.cjs.map +1 -1
  49. package/dist/internal/client-runtime.mjs +2 -2
  50. package/dist/internal/config-runtime.cjs +10 -10
  51. package/dist/internal/config-runtime.cjs.map +1 -1
  52. package/dist/internal/config-runtime.d.mts +1 -1
  53. package/dist/internal/config-runtime.d.ts +1 -1
  54. package/dist/internal/config-runtime.mjs +4 -4
  55. package/dist/middleware.cjs.map +1 -1
  56. package/dist/middleware.mjs +3 -3
  57. package/dist/{nitro-G3BP7E7F.mjs → nitro-VXD26VW2.mjs} +4 -3
  58. package/dist/{nitro-G3BP7E7F.mjs.map → nitro-VXD26VW2.mjs.map} +1 -1
  59. package/dist/plugin.cjs +171 -149
  60. package/dist/plugin.cjs.map +1 -1
  61. package/dist/plugin.mjs +7 -7
  62. package/dist/server.cjs +203 -177
  63. package/dist/server.cjs.map +1 -1
  64. package/dist/server.d.mts +1 -1
  65. package/dist/server.d.ts +1 -1
  66. package/dist/server.mjs +10 -8
  67. package/dist/server.mjs.map +1 -1
  68. package/dist/testing.mjs +2 -2
  69. package/dist/{utils-9OPxcT1T.d.mts → utils--3v-RtD3.d.mts} +7 -1
  70. package/dist/{utils-CIIoLfn9.d.ts → utils-J3ipMElz.d.ts} +7 -1
  71. package/dist/version.cjs +1 -1
  72. package/dist/version.cjs.map +1 -1
  73. package/dist/version.mjs +1 -1
  74. package/dist/vite.cjs +171 -149
  75. package/dist/vite.cjs.map +1 -1
  76. package/dist/vite.mjs +7 -7
  77. package/dist/workflows.cjs +8 -2
  78. package/dist/workflows.cjs.map +1 -1
  79. package/dist/workflows.mjs +2 -1
  80. package/package.json +1 -1
  81. package/dist/chunk-4E6VRJ6P.mjs.map +0 -1
  82. package/dist/chunk-GXASWWJU.mjs.map +0 -1
  83. package/dist/chunk-HEZHCCMF.mjs.map +0 -1
  84. package/dist/chunk-U5SPS2HR.mjs.map +0 -1
  85. /package/dist/{chunk-TIESOJ7Z.mjs.map → chunk-BOSVED4K.mjs.map} +0 -0
  86. /package/dist/{chunk-XR7M5VXU.mjs.map → chunk-DF6GAB63.mjs.map} +0 -0
  87. /package/dist/{chunk-3P63LWDM.mjs.map → chunk-DWG3W2FN.mjs.map} +0 -0
  88. /package/dist/{chunk-3UUEBVR3.mjs.map → chunk-ECGXDMBF.mjs.map} +0 -0
  89. /package/dist/{chunk-MP2SDRRB.mjs.map → chunk-HB3XKQ5X.mjs.map} +0 -0
  90. /package/dist/{chunk-EHUGMAWL.mjs.map → chunk-LIBL3V6K.mjs.map} +0 -0
  91. /package/dist/{chunk-ECLWCE4H.mjs.map → chunk-MHE2AMUC.mjs.map} +0 -0
  92. /package/dist/{chunk-VZKOMD6C.mjs.map → chunk-VVVDVGAS.mjs.map} +0 -0
@@ -3198,6 +3198,160 @@ var init_markdown = __esm({
3198
3198
  }
3199
3199
  });
3200
3200
 
3201
+ // src/utils.ts
3202
+ function parseRoutePath(filePath) {
3203
+ const segments = [];
3204
+ const normalizedPath = filePath.replace(/\\/g, "/");
3205
+ const pathParts = normalizedPath.split("/").filter(Boolean);
3206
+ const fileName = pathParts.pop() || "";
3207
+ const fileType = getRouteType(fileName);
3208
+ for (const part of pathParts) {
3209
+ if (part.startsWith("(") && part.endsWith(")")) continue;
3210
+ if (part.startsWith("[") && part.endsWith("]")) {
3211
+ let segment = part.slice(1, -1);
3212
+ const isDynamic = true;
3213
+ let isOptional = false;
3214
+ let isCatchAll = false;
3215
+ if (segment.startsWith("[") && segment.endsWith("]")) {
3216
+ isOptional = true;
3217
+ segment = segment.slice(1, -1);
3218
+ if (segment.startsWith("...")) {
3219
+ segment = segment.slice(3);
3220
+ isCatchAll = true;
3221
+ }
3222
+ } else if (segment.startsWith("...")) {
3223
+ segment = segment.slice(3);
3224
+ isCatchAll = true;
3225
+ }
3226
+ segments.push({ segment, isDynamic, isOptional, isCatchAll });
3227
+ } else {
3228
+ segments.push({
3229
+ segment: part,
3230
+ isDynamic: false,
3231
+ isOptional: false,
3232
+ isCatchAll: false
3233
+ });
3234
+ }
3235
+ }
3236
+ return {
3237
+ segments,
3238
+ filePath: normalizedPath,
3239
+ type: fileType
3240
+ };
3241
+ }
3242
+ function getRouteType(fileName) {
3243
+ const baseName = fileName.replace(/\.(tsx?|jsx?|vue|svelte|mdx?|markdown)$/, "");
3244
+ switch (baseName) {
3245
+ case "page":
3246
+ return "page";
3247
+ case "layout":
3248
+ return "layout";
3249
+ case "loading":
3250
+ return "loading";
3251
+ case "error":
3252
+ return "error";
3253
+ case "not-found":
3254
+ return "not-found";
3255
+ default:
3256
+ return "page";
3257
+ }
3258
+ }
3259
+ function matchRoute(url, segments) {
3260
+ const urlParts = url.split("/").filter(Boolean);
3261
+ const params = {};
3262
+ if (segments.length === 0) {
3263
+ return { params, matches: urlParts.length === 0 };
3264
+ }
3265
+ let urlIndex = 0;
3266
+ let segmentIndex = 0;
3267
+ while (segmentIndex < segments.length && urlIndex <= urlParts.length) {
3268
+ const segment = segments[segmentIndex];
3269
+ if (!segment.isDynamic) {
3270
+ if (urlParts[urlIndex] !== segment.segment) {
3271
+ return { params: {}, matches: false };
3272
+ }
3273
+ urlIndex++;
3274
+ segmentIndex++;
3275
+ } else if (segment.isCatchAll) {
3276
+ const remainingParts = urlParts.slice(urlIndex);
3277
+ if (remainingParts.length === 0 && !segment.isOptional) {
3278
+ return { params: {}, matches: false };
3279
+ }
3280
+ params[segment.segment] = remainingParts.join("/");
3281
+ urlIndex = urlParts.length;
3282
+ segmentIndex++;
3283
+ } else {
3284
+ if (urlIndex >= urlParts.length) {
3285
+ return { params: {}, matches: false };
3286
+ }
3287
+ params[segment.segment] = urlParts[urlIndex];
3288
+ urlIndex++;
3289
+ segmentIndex++;
3290
+ }
3291
+ }
3292
+ const matches = segmentIndex === segments.length && urlIndex === urlParts.length;
3293
+ return { params, matches };
3294
+ }
3295
+ function resolveAppPath(root, ...paths) {
3296
+ return import_path.default.resolve(root, ...paths);
3297
+ }
3298
+ function toRootRelativeUrlPath(absolutePath, projectRoot) {
3299
+ if (absolutePath === projectRoot) return "";
3300
+ if (absolutePath.startsWith(`${projectRoot}/`) || absolutePath.startsWith(`${projectRoot}\\`)) {
3301
+ return absolutePath.slice(projectRoot.length).replace(/\\/g, "/");
3302
+ }
3303
+ return void 0;
3304
+ }
3305
+ function toPosixPath(filePath) {
3306
+ return filePath.replace(/\\/g, "/");
3307
+ }
3308
+ function toViteModuleId(filePath, root) {
3309
+ if (!import_path.default.isAbsolute(filePath)) return filePath;
3310
+ const relativePath2 = import_path.default.relative(root, filePath);
3311
+ if (relativePath2 && !relativePath2.startsWith("..") && !import_path.default.isAbsolute(relativePath2)) {
3312
+ return `/${relativePath2.split(import_path.default.sep).join("/")}`;
3313
+ }
3314
+ const normalizedPath = filePath.replace(/\\/g, "/");
3315
+ return normalizedPath.startsWith("/") ? `/@fs${normalizedPath}` : `/@fs/${normalizedPath}`;
3316
+ }
3317
+ async function fileExists(filePath) {
3318
+ try {
3319
+ const fs12 = await import("fs/promises");
3320
+ await fs12.access(filePath);
3321
+ return true;
3322
+ } catch {
3323
+ return false;
3324
+ }
3325
+ }
3326
+ async function globFiles(pattern, cwd) {
3327
+ const glob = await import("fast-glob");
3328
+ return glob.default(pattern, { cwd, absolute: false });
3329
+ }
3330
+ var import_path, logger;
3331
+ var init_utils = __esm({
3332
+ "src/utils.ts"() {
3333
+ "use strict";
3334
+ import_path = __toESM(require("path"));
3335
+ __name(parseRoutePath, "parseRoutePath");
3336
+ __name(getRouteType, "getRouteType");
3337
+ __name(matchRoute, "matchRoute");
3338
+ __name(resolveAppPath, "resolveAppPath");
3339
+ __name(toRootRelativeUrlPath, "toRootRelativeUrlPath");
3340
+ __name(toPosixPath, "toPosixPath");
3341
+ __name(toViteModuleId, "toViteModuleId");
3342
+ __name(fileExists, "fileExists");
3343
+ __name(globFiles, "globFiles");
3344
+ logger = {
3345
+ info: /* @__PURE__ */ __name((message) => console.log(`[info] ${message}`), "info"),
3346
+ success: /* @__PURE__ */ __name((message) => console.log(`[success] ${message}`), "success"),
3347
+ warn: /* @__PURE__ */ __name((message) => console.warn(`\u26A0\uFE0F ${message}`), "warn"),
3348
+ error: /* @__PURE__ */ __name((message) => console.error(`\u274C ${message}`), "error"),
3349
+ ready: /* @__PURE__ */ __name((message) => console.log(`${message}`), "ready"),
3350
+ event: /* @__PURE__ */ __name((message) => console.log(` ${message}`), "event")
3351
+ };
3352
+ }
3353
+ });
3354
+
3201
3355
  // src/workflows.ts
3202
3356
  var workflows_exports = {};
3203
3357
  __export(workflows_exports, {
@@ -3366,14 +3520,14 @@ async function prepareFarmWorkflowsForNitro(config) {
3366
3520
  const tasks = {};
3367
3521
  const scheduledTasks = createScheduledTasks(workflows);
3368
3522
  for (const workflow of workflows) {
3369
- const wrapperPath = path37.join(generatedDir, `${safeFileName(workflow.id)}.mjs`);
3523
+ const wrapperPath = toPosixPath(path37.join(generatedDir, `${safeFileName(workflow.id)}.mjs`));
3370
3524
  await fs12.writeFile(wrapperPath, createNitroTaskWrapper(workflow), "utf8");
3371
3525
  tasks[workflow.id] = {
3372
3526
  handler: wrapperPath,
3373
3527
  description: workflow.description || `Farm workflow ${workflow.id}`
3374
3528
  };
3375
3529
  }
3376
- const handlerPath = path37.join(generatedDir, "http-handler.mjs");
3530
+ const handlerPath = toPosixPath(path37.join(generatedDir, "http-handler.mjs"));
3377
3531
  await fs12.writeFile(
3378
3532
  handlerPath,
3379
3533
  createNitroWorkflowHTTPHandler(
@@ -3732,6 +3886,7 @@ var init_workflows = __esm({
3732
3886
  "src/workflows.ts"() {
3733
3887
  "use strict";
3734
3888
  init_server_http();
3889
+ init_utils();
3735
3890
  DEFAULT_FARM_WORKFLOW_DIRS = ["src/jobs", "src/workflows", "src/cron"];
3736
3891
  DEFAULT_FARM_WORKFLOW_ROUTE = "/api/_farm/workflows";
3737
3892
  DEFAULT_FARM_WORKFLOW_SECRET_ENV = "CRON_SECRET";
@@ -3819,7 +3974,7 @@ async function prepareFarmCronForNitro(config) {
3819
3974
  const tasks = {};
3820
3975
  for (const job of cron.jobs) {
3821
3976
  const taskName = getFarmCronTaskName(job.name);
3822
- const wrapperPath = path37.join(generatedDir, `${safeFileName2(job.name)}.mjs`);
3977
+ const wrapperPath = toPosixPath(path37.join(generatedDir, `${safeFileName2(job.name)}.mjs`));
3823
3978
  await fs12.writeFile(wrapperPath, createNitroCronTaskWrapper(job, cron.secretEnv), "utf8");
3824
3979
  tasks[taskName] = {
3825
3980
  handler: wrapperPath,
@@ -4057,6 +4212,7 @@ var DEFAULT_FARM_CRON_SECRET_ENV, FARM_CRON_MANIFEST, CRON_FIELD_RANGES;
4057
4212
  var init_cron = __esm({
4058
4213
  "src/cron.ts"() {
4059
4214
  "use strict";
4215
+ init_utils();
4060
4216
  DEFAULT_FARM_CRON_SECRET_ENV = "CRON_SECRET";
4061
4217
  FARM_CRON_MANIFEST = "cron-manifest.json";
4062
4218
  CRON_FIELD_RANGES = [
@@ -6084,7 +6240,7 @@ function getDefaultDeployOutputDir(target, preset, distDir) {
6084
6240
  return `${distDir}/.output`;
6085
6241
  }
6086
6242
  function resolveDeployOutputPath(root, outputDir) {
6087
- return import_path.default.isAbsolute(outputDir) ? outputDir : import_path.default.join(root, outputDir);
6243
+ return import_path2.default.isAbsolute(outputDir) ? outputDir : import_path2.default.join(root, outputDir);
6088
6244
  }
6089
6245
  function resolveDeployConfig(config, overrides = {}) {
6090
6246
  const deploy = config.deploy || {};
@@ -6124,10 +6280,10 @@ function normalizeDocsContentDir(value) {
6124
6280
  }
6125
6281
  async function inferDocsContentDir(root, srcDir, entry) {
6126
6282
  const { existsSync: existsSync20 } = await import("fs");
6127
- const contentDir = import_path.default.resolve(root, srcDir, "app", entry);
6283
+ const contentDir = import_path2.default.resolve(root, srcDir, "app", entry);
6128
6284
  if (!existsSync20(contentDir)) return void 0;
6129
- const relativeContentDir = import_path.default.relative(root, contentDir);
6130
- if (relativeContentDir.startsWith("..") || import_path.default.isAbsolute(relativeContentDir)) return void 0;
6285
+ const relativeContentDir = import_path2.default.relative(root, contentDir);
6286
+ if (relativeContentDir.startsWith("..") || import_path2.default.isAbsolute(relativeContentDir)) return void 0;
6131
6287
  return normalizeDocsContentDir(relativeContentDir);
6132
6288
  }
6133
6289
  function isRecord2(value) {
@@ -6167,16 +6323,16 @@ function sanitizeDocsConfig(config) {
6167
6323
  }
6168
6324
  async function findDocsConfigPath(rootDir, configPath) {
6169
6325
  const { existsSync: existsSync20 } = await import("fs");
6170
- const root = import_path.default.resolve(rootDir || process.cwd());
6326
+ const root = import_path2.default.resolve(rootDir || process.cwd());
6171
6327
  if (configPath) {
6172
- const resolvedPath = import_path.default.isAbsolute(configPath) ? configPath : import_path.default.join(root, configPath);
6328
+ const resolvedPath = import_path2.default.isAbsolute(configPath) ? configPath : import_path2.default.join(root, configPath);
6173
6329
  if (!existsSync20(resolvedPath)) {
6174
6330
  throw new Error(`Could not find docs config at ${configPath}.`);
6175
6331
  }
6176
- return import_path.default.resolve(resolvedPath);
6332
+ return import_path2.default.resolve(resolvedPath);
6177
6333
  }
6178
6334
  for (const filename of DOCS_CONFIG_FILENAMES) {
6179
- const resolvedPath = import_path.default.join(root, filename);
6335
+ const resolvedPath = import_path2.default.join(root, filename);
6180
6336
  if (existsSync20(resolvedPath)) {
6181
6337
  return resolvedPath;
6182
6338
  }
@@ -6186,7 +6342,7 @@ async function findDocsConfigPath(rootDir, configPath) {
6186
6342
  async function loadDocsConfig(rootDir, configPath) {
6187
6343
  const fs12 = await import("fs/promises");
6188
6344
  const { pathToFileURL: pathToFileURL9 } = await import("url");
6189
- const root = import_path.default.resolve(rootDir || process.cwd());
6345
+ const root = import_path2.default.resolve(rootDir || process.cwd());
6190
6346
  const resolvedPath = await findDocsConfigPath(root, configPath);
6191
6347
  if (!resolvedPath) return void 0;
6192
6348
  try {
@@ -6195,9 +6351,9 @@ async function loadDocsConfig(rootDir, configPath) {
6195
6351
  return { config: JSON.parse(content), configPath: resolvedPath };
6196
6352
  }
6197
6353
  const { build: build3 } = await import("esbuild");
6198
- const configCacheDir = import_path.default.join(root, ".farm", ".config-loader");
6354
+ const configCacheDir = import_path2.default.join(root, ".farm", ".config-loader");
6199
6355
  await fs12.mkdir(configCacheDir, { recursive: true });
6200
- const modulePath = import_path.default.join(
6356
+ const modulePath = import_path2.default.join(
6201
6357
  configCacheDir,
6202
6358
  `docs-config-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`
6203
6359
  );
@@ -6229,7 +6385,7 @@ async function loadDocsConfig(rootDir, configPath) {
6229
6385
  configPath: resolvedPath
6230
6386
  };
6231
6387
  } catch (error) {
6232
- const relativePath2 = import_path.default.relative(root, resolvedPath) || resolvedPath;
6388
+ const relativePath2 = import_path2.default.relative(root, resolvedPath) || resolvedPath;
6233
6389
  const message = error instanceof Error ? error.message : String(error);
6234
6390
  throw new Error(`Failed to load docs config from ${relativePath2}: ${message}`);
6235
6391
  }
@@ -6443,8 +6599,8 @@ async function loadConfig(rootDir, configPath, mode = process.env.NODE_ENV === "
6443
6599
  ].filter(Boolean);
6444
6600
  for (const relativePath2 of searchPaths) {
6445
6601
  try {
6446
- const absolutePath = import_path.default.isAbsolute(relativePath2) ? relativePath2 : import_path.default.join(root, relativePath2);
6447
- const normalizedPath = import_path.default.resolve(absolutePath);
6602
+ const absolutePath = import_path2.default.isAbsolute(relativePath2) ? relativePath2 : import_path2.default.join(root, relativePath2);
6603
+ const normalizedPath = import_path2.default.resolve(absolutePath);
6448
6604
  if (!existsSync20(normalizedPath)) {
6449
6605
  continue;
6450
6606
  }
@@ -6457,7 +6613,7 @@ async function loadConfig(rootDir, configPath, mode = process.env.NODE_ENV === "
6457
6613
  }
6458
6614
  return void 0;
6459
6615
  }
6460
- var import_path, FARM_RESOLVED_CUSTOM_CONTEXT, DOCS_CONFIG_FILENAMES;
6616
+ var import_path2, FARM_RESOLVED_CUSTOM_CONTEXT, DOCS_CONFIG_FILENAMES;
6461
6617
  var init_config4 = __esm({
6462
6618
  "src/config.ts"() {
6463
6619
  "use strict";
@@ -6471,7 +6627,7 @@ var init_config4 = __esm({
6471
6627
  init_server_action_security();
6472
6628
  init_server_http();
6473
6629
  init_layers();
6474
- import_path = __toESM(require("path"));
6630
+ import_path2 = __toESM(require("path"));
6475
6631
  init_deployment();
6476
6632
  init_devtools_config();
6477
6633
  init_image_config();
@@ -6519,156 +6675,6 @@ var init_config4 = __esm({
6519
6675
  }
6520
6676
  });
6521
6677
 
6522
- // src/utils.ts
6523
- function parseRoutePath(filePath) {
6524
- const segments = [];
6525
- const normalizedPath = filePath.replace(/\\/g, "/");
6526
- const pathParts = normalizedPath.split("/").filter(Boolean);
6527
- const fileName = pathParts.pop() || "";
6528
- const fileType = getRouteType(fileName);
6529
- for (const part of pathParts) {
6530
- if (part.startsWith("(") && part.endsWith(")")) continue;
6531
- if (part.startsWith("[") && part.endsWith("]")) {
6532
- let segment = part.slice(1, -1);
6533
- const isDynamic = true;
6534
- let isOptional = false;
6535
- let isCatchAll = false;
6536
- if (segment.startsWith("[") && segment.endsWith("]")) {
6537
- isOptional = true;
6538
- segment = segment.slice(1, -1);
6539
- if (segment.startsWith("...")) {
6540
- segment = segment.slice(3);
6541
- isCatchAll = true;
6542
- }
6543
- } else if (segment.startsWith("...")) {
6544
- segment = segment.slice(3);
6545
- isCatchAll = true;
6546
- }
6547
- segments.push({ segment, isDynamic, isOptional, isCatchAll });
6548
- } else {
6549
- segments.push({
6550
- segment: part,
6551
- isDynamic: false,
6552
- isOptional: false,
6553
- isCatchAll: false
6554
- });
6555
- }
6556
- }
6557
- return {
6558
- segments,
6559
- filePath: normalizedPath,
6560
- type: fileType
6561
- };
6562
- }
6563
- function getRouteType(fileName) {
6564
- const baseName = fileName.replace(/\.(tsx?|jsx?|vue|svelte|mdx?|markdown)$/, "");
6565
- switch (baseName) {
6566
- case "page":
6567
- return "page";
6568
- case "layout":
6569
- return "layout";
6570
- case "loading":
6571
- return "loading";
6572
- case "error":
6573
- return "error";
6574
- case "not-found":
6575
- return "not-found";
6576
- default:
6577
- return "page";
6578
- }
6579
- }
6580
- function matchRoute(url, segments) {
6581
- const urlParts = url.split("/").filter(Boolean);
6582
- const params = {};
6583
- if (segments.length === 0) {
6584
- return { params, matches: urlParts.length === 0 };
6585
- }
6586
- let urlIndex = 0;
6587
- let segmentIndex = 0;
6588
- while (segmentIndex < segments.length && urlIndex <= urlParts.length) {
6589
- const segment = segments[segmentIndex];
6590
- if (!segment.isDynamic) {
6591
- if (urlParts[urlIndex] !== segment.segment) {
6592
- return { params: {}, matches: false };
6593
- }
6594
- urlIndex++;
6595
- segmentIndex++;
6596
- } else if (segment.isCatchAll) {
6597
- const remainingParts = urlParts.slice(urlIndex);
6598
- if (remainingParts.length === 0 && !segment.isOptional) {
6599
- return { params: {}, matches: false };
6600
- }
6601
- params[segment.segment] = remainingParts.join("/");
6602
- urlIndex = urlParts.length;
6603
- segmentIndex++;
6604
- } else {
6605
- if (urlIndex >= urlParts.length) {
6606
- return { params: {}, matches: false };
6607
- }
6608
- params[segment.segment] = urlParts[urlIndex];
6609
- urlIndex++;
6610
- segmentIndex++;
6611
- }
6612
- }
6613
- const matches = segmentIndex === segments.length && urlIndex === urlParts.length;
6614
- return { params, matches };
6615
- }
6616
- function resolveAppPath(root, ...paths) {
6617
- return import_path2.default.resolve(root, ...paths);
6618
- }
6619
- function toRootRelativeUrlPath(absolutePath, projectRoot) {
6620
- if (absolutePath === projectRoot) return "";
6621
- if (absolutePath.startsWith(`${projectRoot}/`) || absolutePath.startsWith(`${projectRoot}\\`)) {
6622
- return absolutePath.slice(projectRoot.length).replace(/\\/g, "/");
6623
- }
6624
- return void 0;
6625
- }
6626
- function toViteModuleId(filePath, root) {
6627
- if (!import_path2.default.isAbsolute(filePath)) return filePath;
6628
- const relativePath2 = import_path2.default.relative(root, filePath);
6629
- if (relativePath2 && !relativePath2.startsWith("..") && !import_path2.default.isAbsolute(relativePath2)) {
6630
- return `/${relativePath2.split(import_path2.default.sep).join("/")}`;
6631
- }
6632
- const normalizedPath = filePath.replace(/\\/g, "/");
6633
- return normalizedPath.startsWith("/") ? `/@fs${normalizedPath}` : `/@fs/${normalizedPath}`;
6634
- }
6635
- async function fileExists(filePath) {
6636
- try {
6637
- const fs12 = await import("fs/promises");
6638
- await fs12.access(filePath);
6639
- return true;
6640
- } catch {
6641
- return false;
6642
- }
6643
- }
6644
- async function globFiles(pattern, cwd) {
6645
- const glob = await import("fast-glob");
6646
- return glob.default(pattern, { cwd, absolute: false });
6647
- }
6648
- var import_path2, logger;
6649
- var init_utils = __esm({
6650
- "src/utils.ts"() {
6651
- "use strict";
6652
- import_path2 = __toESM(require("path"));
6653
- __name(parseRoutePath, "parseRoutePath");
6654
- __name(getRouteType, "getRouteType");
6655
- __name(matchRoute, "matchRoute");
6656
- __name(resolveAppPath, "resolveAppPath");
6657
- __name(toRootRelativeUrlPath, "toRootRelativeUrlPath");
6658
- __name(toViteModuleId, "toViteModuleId");
6659
- __name(fileExists, "fileExists");
6660
- __name(globFiles, "globFiles");
6661
- logger = {
6662
- info: /* @__PURE__ */ __name((message) => console.log(`[info] ${message}`), "info"),
6663
- success: /* @__PURE__ */ __name((message) => console.log(`[success] ${message}`), "success"),
6664
- warn: /* @__PURE__ */ __name((message) => console.warn(`\u26A0\uFE0F ${message}`), "warn"),
6665
- error: /* @__PURE__ */ __name((message) => console.error(`\u274C ${message}`), "error"),
6666
- ready: /* @__PURE__ */ __name((message) => console.log(`${message}`), "ready"),
6667
- event: /* @__PURE__ */ __name((message) => console.log(` ${message}`), "event")
6668
- };
6669
- }
6670
- });
6671
-
6672
6678
  // src/tracing.ts
6673
6679
  function normalizeFarmTracingConfig(config) {
6674
6680
  if (!config) {
@@ -14912,7 +14918,7 @@ var init_server3 = __esm({
14912
14918
  var version;
14913
14919
  var init_package = __esm({
14914
14920
  "package.json"() {
14915
- version = "0.1.0-beta.48";
14921
+ version = "0.1.0-beta.49";
14916
14922
  }
14917
14923
  });
14918
14924
 
@@ -35407,6 +35413,10 @@ function generateFarmDocsRuntimeConfigExpression(docs) {
35407
35413
  : ${JSON.stringify(docs)}`;
35408
35414
  }
35409
35415
  __name(generateFarmDocsRuntimeConfigExpression, "generateFarmDocsRuntimeConfigExpression");
35416
+ function toVirtualEntryImportSpecifier(modulePath) {
35417
+ return JSON.stringify(modulePath.replace(/\\/g, "/"));
35418
+ }
35419
+ __name(toVirtualEntryImportSpecifier, "toVirtualEntryImportSpecifier");
35410
35420
  function generateVirtualEntryCode(apiRoutes, pageRoutes, layoutRoutes, routeSlots, errorRoutes, metadataImageRoutes, applicationMetadataRoutes, middlewareRoutes, redirectRoutes, configuredRewriteRoutes, configuredHeaderRoutes, notFoundPath, instrumentationPath, config, configModulePath, hasServerRuntimeIntegrations, hasRuntimeIntegrationConfig, hasConfiguredRuntimePlugins, preset, i18nCatalogs) {
35411
35421
  const hasPluginRuntime = hasRuntimeIntegrationConfig || hasConfiguredRuntimePlugins;
35412
35422
  const adapterOwnsDocsRuntime = Boolean(
@@ -35423,7 +35433,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35423
35433
  const apiRegistrations = [];
35424
35434
  apiRoutes.forEach((route, index) => {
35425
35435
  const varName = `apiRoute${index}`;
35426
- apiImports.push(`import * as ${varName} from "${route.filePath}";`);
35436
+ apiImports.push(
35437
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(route.filePath)};`
35438
+ );
35427
35439
  apiRegistrations.push(`
35428
35440
  {
35429
35441
  path: ${JSON.stringify(route.path)},
@@ -35456,7 +35468,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35456
35468
  }`);
35457
35469
  return;
35458
35470
  }
35459
- pageImports.push(`import * as ${varName} from "${route.modulePath}";`);
35471
+ pageImports.push(
35472
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(route.modulePath)};`
35473
+ );
35460
35474
  const clientMetadata = getClientModuleMetadata(route.modulePath, config.root);
35461
35475
  pageRegistrations.push(`
35462
35476
  {
@@ -35475,7 +35489,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35475
35489
  layoutRoutes.forEach((layout2, index) => {
35476
35490
  const varName = `layoutRoute${index}`;
35477
35491
  const clientMetadata = getClientModuleMetadata(layout2.modulePath, config.root);
35478
- layoutImports.push(`import * as ${varName} from "${layout2.modulePath}";`);
35492
+ layoutImports.push(
35493
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(layout2.modulePath)};`
35494
+ );
35479
35495
  layoutRegistrations.push(`
35480
35496
  {
35481
35497
  pattern: ${JSON.stringify(layout2.pattern)},
@@ -35488,7 +35504,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35488
35504
  const routeSlotRegistrations = [];
35489
35505
  routeSlots.forEach((slot, index) => {
35490
35506
  const varName = `routeSlot${index}`;
35491
- routeSlotImports.push(`import * as ${varName} from "${slot.modulePath}";`);
35507
+ routeSlotImports.push(
35508
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(slot.modulePath)};`
35509
+ );
35492
35510
  routeSlotRegistrations.push(`
35493
35511
  {
35494
35512
  name: ${JSON.stringify(slot.name)},
@@ -35504,7 +35522,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35504
35522
  const errorRegistrations = [];
35505
35523
  errorRoutes.forEach((errorRoute, index) => {
35506
35524
  const varName = `errorRoute${index}`;
35507
- errorImports.push(`import * as ${varName} from "${errorRoute.modulePath}";`);
35525
+ errorImports.push(
35526
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(errorRoute.modulePath)};`
35527
+ );
35508
35528
  errorRegistrations.push(`
35509
35529
  {
35510
35530
  pattern: ${JSON.stringify(errorRoute.pattern)},
@@ -35514,9 +35534,11 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35514
35534
  const metadataImageImports = [];
35515
35535
  const metadataImageRegistrations = [];
35516
35536
  metadataImageRoutes.forEach((image, index) => {
35517
- if (image.sourceType === "module") {
35537
+ if (image.sourceType === "module" && image.modulePath) {
35518
35538
  const varName = `metadataImageRoute${index}`;
35519
- metadataImageImports.push(`import * as ${varName} from "${image.modulePath}";`);
35539
+ metadataImageImports.push(
35540
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(image.modulePath)};`
35541
+ );
35520
35542
  metadataImageRegistrations.push(`
35521
35543
  {
35522
35544
  pattern: ${JSON.stringify(image.pattern)},
@@ -35533,7 +35555,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35533
35555
  const applicationMetadataRegistrations = [];
35534
35556
  applicationMetadataRoutes.forEach((metadata, index) => {
35535
35557
  const varName = `applicationMetadataRoute${index}`;
35536
- applicationMetadataImports.push(`import * as ${varName} from "${metadata.modulePath}";`);
35558
+ applicationMetadataImports.push(
35559
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(metadata.modulePath)};`
35560
+ );
35537
35561
  applicationMetadataRegistrations.push(`
35538
35562
  {
35539
35563
  pattern: ${JSON.stringify(metadata.pattern)},
@@ -35546,7 +35570,9 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35546
35570
  const middlewareRegistrations = [];
35547
35571
  middlewareRoutes.forEach((middlewareRoute, index) => {
35548
35572
  const varName = `fileMiddleware${index}`;
35549
- middlewareImports.push(`import * as ${varName} from "${middlewareRoute.filePath}";`);
35573
+ middlewareImports.push(
35574
+ `import * as ${varName} from ${toVirtualEntryImportSpecifier(middlewareRoute.filePath)};`
35575
+ );
35550
35576
  middlewareRegistrations.push(`
35551
35577
  {
35552
35578
  path: ${JSON.stringify(middlewareRoute.path)},
@@ -35554,7 +35580,7 @@ import * as ReactDOMServer from "react-dom/server";` : `import React, * as React
35554
35580
  module: ${varName},
35555
35581
  }`);
35556
35582
  });
35557
- const notFoundImport = notFoundPath ? `import * as CustomNotFound from "${notFoundPath}";` : "";
35583
+ const notFoundImport = notFoundPath ? `import * as CustomNotFound from ${toVirtualEntryImportSpecifier(notFoundPath)};` : "";
35558
35584
  const apiRouteHelpersImport = apiRoutes.length > 0 ? `import { invokeAPIRouteEndpoint, matchAPIRoute } from "@farm.js/core/api/runtime";` : "";
35559
35585
  const productionRuntimeImport = `import {
35560
35586
  _runWithAfterRequest,
@@ -35613,10 +35639,10 @@ import { fileURLToPath as farmDocsFileURLToPath } from "node:url";` : "";
35613
35639
  const markdownHandlerImport = config.md?.enabled ? `import { applyMarkdownNegotiationHeaders, createMarkdownMirrorResponse } from "@farm.js/core/markdown";` : "";
35614
35640
  const appMarkdownImport = hasMarkdownPages ? `import { createFarmMarkdownRouteModule, createFarmMarkdownSourceResponse } from "@farm.js/core/app-markdown";` : "const createFarmMarkdownSourceResponse = null;";
35615
35641
  const mdxComponentsPath = typeof config.mdx?.components === "string" ? import_path13.default.isAbsolute(config.mdx.components) ? config.mdx.components : import_path13.default.join(config.root, config.mdx.components) : null;
35616
- const mdxComponentsImport = mdxComponentsPath ? `import * as FarmMdxComponentsModule from "${mdxComponentsPath.replace(/\\/g, "/")}";` : "";
35642
+ const mdxComponentsImport = mdxComponentsPath ? `import * as FarmMdxComponentsModule from ${toVirtualEntryImportSpecifier(mdxComponentsPath)};` : "";
35617
35643
  const layerConfigPaths = (config.layers || []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile)).filter((configFile) => configFile !== configModulePath);
35618
35644
  const layerConfigImports = layerConfigPaths.map(
35619
- (configFile, index) => `import * as FarmLayerConfigModule${index} from "${configFile.replace(/\\/g, "/")}";`
35645
+ (configFile, index) => `import * as FarmLayerConfigModule${index} from ${toVirtualEntryImportSpecifier(configFile)};`
35620
35646
  ).join("\n");
35621
35647
  const layerConfigValues = layerConfigPaths.map(
35622
35648
  (_configFile, index) => `(FarmLayerConfigModule${index}.default || FarmLayerConfigModule${index})`
@@ -35628,9 +35654,9 @@ import { fileURLToPath as farmDocsFileURLToPath } from "node:url";` : "";
35628
35654
  ])
35629
35655
  );
35630
35656
  const integrationRuntimeImport = integrationRuntimeExports.length ? `import { ${integrationRuntimeExports.join(", ")} } from "@farm.js/core/integrations";` : "";
35631
- const instrumentationImport = instrumentationPath ? `import * as FarmInstrumentationModule from "${instrumentationPath.replace(/\\/g, "/")}";` : "";
35657
+ const instrumentationImport = instrumentationPath ? `import * as FarmInstrumentationModule from ${toVirtualEntryImportSpecifier(instrumentationPath)};` : "";
35632
35658
  const integrationImports = `
35633
- ${configModulePath ? `import * as FarmUserConfigModule from "${configModulePath}";` : ""}
35659
+ ${configModulePath ? `import * as FarmUserConfigModule from ${toVirtualEntryImportSpecifier(configModulePath)};` : ""}
35634
35660
  ${layerConfigImports}
35635
35661
  ${integrationRuntimeImport}
35636
35662
  `;
@@ -38797,7 +38823,7 @@ export default async function farmNitroEventHandler(event) {
38797
38823
  ] : [],
38798
38824
  {
38799
38825
  route: "/**",
38800
- handler: nitroEntryPath
38826
+ handler: toPosixPath(nitroEntryPath)
38801
38827
  }
38802
38828
  ],
38803
38829
  routeRules: {
@@ -39045,6 +39071,20 @@ async function registerPrebuiltSSRPackageImport(serverDir, ssrEntryFile, fs12) {
39045
39071
  `);
39046
39072
  }
39047
39073
  __name(registerPrebuiltSSRPackageImport, "registerPrebuiltSSRPackageImport");
39074
+ async function moveVercelOutputPath(src, dest, fs12) {
39075
+ try {
39076
+ await fs12.rename(src, dest);
39077
+ return;
39078
+ } catch (error) {
39079
+ const code = error?.code;
39080
+ if (code !== "EPERM" && code !== "EACCES" && code !== "EXDEV" && code !== "ENOTEMPTY") {
39081
+ throw error;
39082
+ }
39083
+ }
39084
+ await fs12.cp(src, dest, { recursive: true, force: true });
39085
+ await fs12.rm(src, { recursive: true, force: true });
39086
+ }
39087
+ __name(moveVercelOutputPath, "moveVercelOutputPath");
39048
39088
  async function postProcessVercelOutput(root, outputDir, fs12, config, farmWorkflows, routeRuntimeManifest) {
39049
39089
  const serverDir = import_path13.default.join(outputDir, "server");
39050
39090
  const functionsDir = import_path13.default.join(outputDir, "functions");
@@ -39056,12 +39096,13 @@ async function postProcessVercelOutput(root, outputDir, fs12, config, farmWorkfl
39056
39096
  for (const file of serverContents) {
39057
39097
  const src = import_path13.default.join(serverDir, file);
39058
39098
  const dest = import_path13.default.join(nitroFuncDir, file);
39059
- await fs12.rename(src, dest);
39099
+ await moveVercelOutputPath(src, dest, fs12);
39060
39100
  }
39061
- await fs12.rmdir(serverDir);
39101
+ await fs12.rm(serverDir, { recursive: true, force: true });
39062
39102
  try {
39063
- await fs12.rename(publicDir, staticDir);
39064
- } catch {
39103
+ await moveVercelOutputPath(publicDir, staticDir, fs12);
39104
+ } catch (error) {
39105
+ if (error?.code !== "ENOENT") throw error;
39065
39106
  }
39066
39107
  await copyFarmDocsContentForVercel(config, root, nitroFuncDir, fs12);
39067
39108
  await copyPrismaClientForVercel(root, nitroFuncDir, fs12);