one 1.1.483 → 1.1.485

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 (162) hide show
  1. package/dist/cjs/cli/build.cjs +5 -41
  2. package/dist/cjs/cli/build.js +4 -44
  3. package/dist/cjs/cli/build.js.map +1 -1
  4. package/dist/cjs/cli/build.native.js +4 -42
  5. package/dist/cjs/cli/build.native.js.map +2 -2
  6. package/dist/cjs/createHandleRequest.cjs +2 -1
  7. package/dist/cjs/createHandleRequest.js +2 -1
  8. package/dist/cjs/createHandleRequest.js.map +1 -1
  9. package/dist/cjs/createHandleRequest.native.js +4 -2
  10. package/dist/cjs/createHandleRequest.native.js.map +1 -1
  11. package/dist/cjs/server/createRoutesManifest.js.map +1 -1
  12. package/dist/cjs/server/createRoutesManifest.native.js.map +1 -1
  13. package/dist/cjs/server/getServerManifest.cjs +15 -7
  14. package/dist/cjs/server/getServerManifest.js +17 -8
  15. package/dist/cjs/server/getServerManifest.js.map +1 -1
  16. package/dist/cjs/server/getServerManifest.native.js +8 -5
  17. package/dist/cjs/server/getServerManifest.native.js.map +2 -2
  18. package/dist/cjs/server/oneServe.cjs +8 -13
  19. package/dist/cjs/server/oneServe.js +11 -14
  20. package/dist/cjs/server/oneServe.js.map +1 -1
  21. package/dist/cjs/server/oneServe.native.js +20 -23
  22. package/dist/cjs/server/oneServe.native.js.map +2 -2
  23. package/dist/cjs/utils/getPathnameFromFilePath.cjs +76 -0
  24. package/dist/cjs/utils/getPathnameFromFilePath.js +70 -0
  25. package/dist/cjs/utils/getPathnameFromFilePath.js.map +6 -0
  26. package/dist/cjs/utils/getPathnameFromFilePath.native.js +73 -0
  27. package/dist/cjs/utils/getPathnameFromFilePath.native.js.map +6 -0
  28. package/dist/cjs/vercel/build/buildVercelOutputDirectory.cjs +38 -8
  29. package/dist/cjs/vercel/build/buildVercelOutputDirectory.js +48 -17
  30. package/dist/cjs/vercel/build/buildVercelOutputDirectory.js.map +1 -1
  31. package/dist/cjs/vercel/build/buildVercelOutputDirectory.native.js +50 -7
  32. package/dist/cjs/vercel/build/buildVercelOutputDirectory.native.js.map +2 -2
  33. package/dist/cjs/vercel/build/config/vc-build-output-config-base.cjs +9 -6
  34. package/dist/cjs/vercel/build/config/vc-build-output-config-base.js +7 -6
  35. package/dist/cjs/vercel/build/config/vc-build-output-config-base.js.map +1 -1
  36. package/dist/cjs/vercel/build/config/vc-build-output-config-base.native.js +4 -9
  37. package/dist/cjs/vercel/build/config/vc-build-output-config-base.native.js.map +2 -2
  38. package/dist/cjs/vercel/build/generate/createApiServerlessFunction.cjs +54 -9
  39. package/dist/cjs/vercel/build/generate/createApiServerlessFunction.js +83 -15
  40. package/dist/cjs/vercel/build/generate/createApiServerlessFunction.js.map +2 -2
  41. package/dist/cjs/vercel/build/generate/createApiServerlessFunction.native.js +73 -9
  42. package/dist/cjs/vercel/build/generate/createApiServerlessFunction.native.js.map +2 -2
  43. package/dist/cjs/vercel/build/generate/createSsrServerlessFunction.cjs +9 -6
  44. package/dist/cjs/vercel/build/generate/createSsrServerlessFunction.js +8 -6
  45. package/dist/cjs/vercel/build/generate/createSsrServerlessFunction.js.map +1 -1
  46. package/dist/cjs/vercel/build/generate/createSsrServerlessFunction.native.js +8 -6
  47. package/dist/cjs/vercel/build/generate/createSsrServerlessFunction.native.js.map +2 -2
  48. package/dist/cjs/vercel/build/getPathFromRoute.cjs +31 -0
  49. package/dist/cjs/vercel/build/getPathFromRoute.js +24 -0
  50. package/dist/cjs/vercel/build/getPathFromRoute.js.map +6 -0
  51. package/dist/cjs/vercel/build/getPathFromRoute.native.js +31 -0
  52. package/dist/cjs/vercel/build/getPathFromRoute.native.js.map +6 -0
  53. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.cjs +1 -1
  54. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js +1 -1
  55. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
  56. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +3 -1
  57. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +2 -2
  58. package/dist/esm/cli/build.js +4 -43
  59. package/dist/esm/cli/build.js.map +1 -1
  60. package/dist/esm/cli/build.mjs +4 -40
  61. package/dist/esm/cli/build.mjs.map +1 -1
  62. package/dist/esm/cli/build.native.js +4 -43
  63. package/dist/esm/cli/build.native.js.map +1 -1
  64. package/dist/esm/createHandleRequest.js +2 -1
  65. package/dist/esm/createHandleRequest.js.map +1 -1
  66. package/dist/esm/createHandleRequest.mjs +1 -1
  67. package/dist/esm/createHandleRequest.mjs.map +1 -1
  68. package/dist/esm/createHandleRequest.native.js +1 -1
  69. package/dist/esm/createHandleRequest.native.js.map +1 -1
  70. package/dist/esm/server/createRoutesManifest.js.map +1 -1
  71. package/dist/esm/server/createRoutesManifest.mjs.map +1 -1
  72. package/dist/esm/server/createRoutesManifest.native.js.map +1 -1
  73. package/dist/esm/server/getServerManifest.js +17 -8
  74. package/dist/esm/server/getServerManifest.js.map +1 -1
  75. package/dist/esm/server/getServerManifest.mjs +15 -7
  76. package/dist/esm/server/getServerManifest.mjs.map +1 -1
  77. package/dist/esm/server/getServerManifest.native.js +8 -4
  78. package/dist/esm/server/getServerManifest.native.js.map +1 -1
  79. package/dist/esm/server/oneServe.js +17 -15
  80. package/dist/esm/server/oneServe.js.map +1 -1
  81. package/dist/esm/server/oneServe.mjs +9 -14
  82. package/dist/esm/server/oneServe.mjs.map +1 -1
  83. package/dist/esm/server/oneServe.native.js +21 -24
  84. package/dist/esm/server/oneServe.native.js.map +1 -1
  85. package/dist/esm/utils/getPathnameFromFilePath.js +46 -0
  86. package/dist/esm/utils/getPathnameFromFilePath.js.map +6 -0
  87. package/dist/esm/utils/getPathnameFromFilePath.mjs +42 -0
  88. package/dist/esm/utils/getPathnameFromFilePath.mjs.map +1 -0
  89. package/dist/esm/utils/getPathnameFromFilePath.native.js +45 -0
  90. package/dist/esm/utils/getPathnameFromFilePath.native.js.map +1 -0
  91. package/dist/esm/vercel/build/buildVercelOutputDirectory.js +49 -18
  92. package/dist/esm/vercel/build/buildVercelOutputDirectory.js.map +1 -1
  93. package/dist/esm/vercel/build/buildVercelOutputDirectory.mjs +38 -8
  94. package/dist/esm/vercel/build/buildVercelOutputDirectory.mjs.map +1 -1
  95. package/dist/esm/vercel/build/buildVercelOutputDirectory.native.js +45 -8
  96. package/dist/esm/vercel/build/buildVercelOutputDirectory.native.js.map +1 -1
  97. package/dist/esm/vercel/build/config/vc-build-output-config-base.js +7 -6
  98. package/dist/esm/vercel/build/config/vc-build-output-config-base.js.map +1 -1
  99. package/dist/esm/vercel/build/config/vc-build-output-config-base.mjs +9 -6
  100. package/dist/esm/vercel/build/config/vc-build-output-config-base.mjs.map +1 -1
  101. package/dist/esm/vercel/build/config/vc-build-output-config-base.native.js +3 -6
  102. package/dist/esm/vercel/build/config/vc-build-output-config-base.native.js.map +1 -1
  103. package/dist/esm/vercel/build/generate/createApiServerlessFunction.js +88 -13
  104. package/dist/esm/vercel/build/generate/createApiServerlessFunction.js.map +1 -1
  105. package/dist/esm/vercel/build/generate/createApiServerlessFunction.mjs +53 -8
  106. package/dist/esm/vercel/build/generate/createApiServerlessFunction.mjs.map +1 -1
  107. package/dist/esm/vercel/build/generate/createApiServerlessFunction.native.js +52 -8
  108. package/dist/esm/vercel/build/generate/createApiServerlessFunction.native.js.map +1 -1
  109. package/dist/esm/vercel/build/generate/createSsrServerlessFunction.js +8 -5
  110. package/dist/esm/vercel/build/generate/createSsrServerlessFunction.js.map +1 -1
  111. package/dist/esm/vercel/build/generate/createSsrServerlessFunction.mjs +8 -5
  112. package/dist/esm/vercel/build/generate/createSsrServerlessFunction.mjs.map +1 -1
  113. package/dist/esm/vercel/build/generate/createSsrServerlessFunction.native.js +8 -5
  114. package/dist/esm/vercel/build/generate/createSsrServerlessFunction.native.js.map +1 -1
  115. package/dist/esm/vercel/build/getPathFromRoute.js +8 -0
  116. package/dist/esm/vercel/build/getPathFromRoute.js.map +6 -0
  117. package/dist/esm/vercel/build/getPathFromRoute.mjs +8 -0
  118. package/dist/esm/vercel/build/getPathFromRoute.mjs.map +1 -0
  119. package/dist/esm/vercel/build/getPathFromRoute.native.js +8 -0
  120. package/dist/esm/vercel/build/getPathFromRoute.native.js.map +1 -0
  121. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js +2 -2
  122. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
  123. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs +2 -2
  124. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs.map +1 -1
  125. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +4 -2
  126. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
  127. package/package.json +9 -8
  128. package/src/cli/build.ts +3 -57
  129. package/src/createHandleRequest.ts +1 -1
  130. package/src/server/createRoutesManifest.ts +1 -0
  131. package/src/server/getServerManifest.ts +12 -3
  132. package/src/server/oneServe.ts +23 -18
  133. package/src/utils/getPathnameFromFilePath.ts +62 -0
  134. package/src/vercel/build/buildVercelOutputDirectory.ts +55 -20
  135. package/src/vercel/build/config/vc-build-output-config-base.ts +6 -5
  136. package/src/vercel/build/generate/createApiServerlessFunction.ts +138 -12
  137. package/src/vercel/build/generate/createSsrServerlessFunction.ts +9 -6
  138. package/src/vercel/build/getPathFromRoute.ts +8 -0
  139. package/src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx +9 -2
  140. package/src/vite/types.ts +1 -0
  141. package/types/cli/build.d.ts.map +1 -1
  142. package/types/createHandleRequest.d.ts +1 -0
  143. package/types/createHandleRequest.d.ts.map +1 -1
  144. package/types/server/createRoutesManifest.d.ts +1 -0
  145. package/types/server/createRoutesManifest.d.ts.map +1 -1
  146. package/types/server/getServerManifest.d.ts +1 -0
  147. package/types/server/getServerManifest.d.ts.map +1 -1
  148. package/types/server/oneServe.d.ts.map +1 -1
  149. package/types/utils/getPathnameFromFilePath.d.ts +4 -0
  150. package/types/utils/getPathnameFromFilePath.d.ts.map +1 -0
  151. package/types/vercel/build/buildVercelOutputDirectory.d.ts.map +1 -1
  152. package/types/vercel/build/config/vc-build-output-config-base.d.ts +2 -5
  153. package/types/vercel/build/config/vc-build-output-config-base.d.ts.map +1 -1
  154. package/types/vercel/build/generate/createApiServerlessFunction.d.ts +2 -1
  155. package/types/vercel/build/generate/createApiServerlessFunction.d.ts.map +1 -1
  156. package/types/vercel/build/generate/createSsrServerlessFunction.d.ts +2 -2
  157. package/types/vercel/build/generate/createSsrServerlessFunction.d.ts.map +1 -1
  158. package/types/vercel/build/getPathFromRoute.d.ts +3 -0
  159. package/types/vercel/build/getPathFromRoute.d.ts.map +1 -0
  160. package/types/vite/plugins/generateFileSystemRouteTypesPlugin.d.ts.map +1 -1
  161. package/types/vite/types.d.ts +1 -0
  162. package/types/vite/types.d.ts.map +1 -1
@@ -39,9 +39,9 @@ var import_node_path = require("node:path"),
39
39
  import_ts_pattern = require("ts-pattern"),
40
40
  import_createApiServerlessFunction = require("./generate/createApiServerlessFunction.cjs"),
41
41
  import_createSsrServerlessFunction = require("./generate/createSsrServerlessFunction.cjs"),
42
- import_vc_config_base = require("./config/vc-config-base.cjs"),
43
42
  import_vc_package_base = require("./config/vc-package-base.cjs"),
44
- import_vc_build_output_config_base = require("./config/vc-build-output-config-base.cjs");
43
+ import_vc_build_output_config_base = require("./config/vc-build-output-config-base.cjs"),
44
+ import_getPathFromRoute = require("./getPathFromRoute.cjs");
45
45
  const {
46
46
  copy,
47
47
  ensureDir,
@@ -75,7 +75,7 @@ const buildVercelOutputDirectory = async ({
75
75
  }, o));
76
76
  for (const route of buildInfoForWriting.manifest.apiRoutes) {
77
77
  const compiledRoute = compiltedApiRoutes.find(compiled => compiled.facadeModuleId.includes(route.file.replace("./", "")));
78
- compiledRoute ? (postBuildLogs.push(`[one.build][vercel] generating serverless function for apiRoute ${route.page}`), await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route.page, compiledRoute.code, oneOptionsRoot, postBuildLogs), route.page !== route.urlCleanPath && (await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route.urlCleanPath, compiledRoute.code, oneOptionsRoot, postBuildLogs))) : console.warn(`
78
+ compiledRoute ? (postBuildLogs.push(`[one.build][vercel] generating serverless function for apiRoute ${route.page}`), await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route, compiledRoute.code, oneOptionsRoot, postBuildLogs)) : console.warn(`
79
79
  \u{1F528}[one.build][vercel] apiRoute missing code compilation for`, route.file);
80
80
  }
81
81
  }
@@ -84,7 +84,7 @@ const buildVercelOutputDirectory = async ({
84
84
  for (const route of buildInfoForWriting.manifest.pageRoutes) switch (route.type) {
85
85
  case "ssr":
86
86
  {
87
- routeToBuildInfo[route.file] && (postBuildLogs.push(`[one.build][vercel] generate serverless function for ${route.page} with ${route.type}`), await (0, import_createSsrServerlessFunction.createSsrServerlessFunction)(route.page, buildInfoForWriting, oneOptionsRoot, postBuildLogs));
87
+ routeToBuildInfo[route.file] && (postBuildLogs.push(`[one.build][vercel] generate serverless function for ${route.page} with ${route.type}`), await (0, import_createSsrServerlessFunction.createSsrServerlessFunction)(route, buildInfoForWriting, oneOptionsRoot, postBuildLogs));
88
88
  break;
89
89
  }
90
90
  default:
@@ -92,18 +92,48 @@ const buildVercelOutputDirectory = async ({
92
92
  }
93
93
  const distMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "middlewares"));
94
94
  if (existsSync(distMiddlewareDir)) {
95
- const vercelMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/functions/_middleware"));
95
+ const vercelMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/functions/_middleware.func"));
96
96
  await ensureDir(vercelMiddlewareDir), postBuildLogs.push(`[one.build][vercel] copying middlewares from ${distMiddlewareDir} to ${vercelMiddlewareDir}`), await moveAllFiles((0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "middlewares")), vercelMiddlewareDir);
97
97
  const vercelMiddlewarePackageJsonFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, "index.js"));
98
98
  postBuildLogs.push(`[one.build][vercel] writing package.json to ${vercelMiddlewarePackageJsonFilePath}`), await writeJSON(vercelMiddlewarePackageJsonFilePath, import_vc_package_base.serverlessVercelPackageJson);
99
+ const wrappedMiddlewareEntryPointFilename = "_wrapped_middleware.js",
100
+ wrappedMiddlewareEntryPointPath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, wrappedMiddlewareEntryPointFilename));
101
+ await import_fs_extra.default.writeFile(wrappedMiddlewareEntryPointPath, `
102
+ import middlewareFunction from './_middleware.js'
103
+
104
+ const next = (e) => {
105
+ const t = new Headers(null == e ? void 0 : e.headers)
106
+ t.set('x-middleware-next', '1')
107
+ return new Response(null, { ...e, headers: t })
108
+ }
109
+
110
+ const wrappedMiddlewareFunction = (request, event) => {
111
+ return middlewareFunction({ request, event, next })
112
+ }
113
+
114
+ export { wrappedMiddlewareFunction as default }
115
+ `);
99
116
  const middlewareVercelConfigFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, ".vc-config.json"));
100
117
  postBuildLogs.push(`[one.build][vercel] writing .vc-config.json to ${middlewareVercelConfigFilePath}`), await writeJSON(middlewareVercelConfigFilePath, {
101
- ...import_vc_config_base.serverlessVercelNodeJsConfig,
102
- handler: "_middleware.js"
118
+ runtime: "edge",
119
+ // Seems that middlewares only work with edge runtime
120
+ entrypoint: wrappedMiddlewareEntryPointFilename
103
121
  });
104
122
  }
105
123
  const vercelOutputStaticDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/static"));
106
124
  await ensureDir(vercelOutputStaticDir), postBuildLogs.push(`[one.build][vercel] copying static files from ${clientDir} to ${vercelOutputStaticDir}`), await moveAllFiles(clientDir, vercelOutputStaticDir);
107
125
  const vercelConfigFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output", "config.json"));
108
- await writeJSON(vercelConfigFilePath, import_vc_build_output_config_base.vercelBuildOutputConfig), postBuildLogs.push(`[one.build] wrote vercel config to: ${vercelConfigFilePath}`);
126
+ await writeJSON(vercelConfigFilePath, {
127
+ ...import_vc_build_output_config_base.vercelBuildOutputConfigBase,
128
+ routes: [...import_vc_build_output_config_base.vercelBuildOutputConfigBase.routes, ...(existsSync(distMiddlewareDir) ? [{
129
+ src: "/(.*)",
130
+ middlewarePath: "_middleware",
131
+ continue: !0
132
+ }] : []), {
133
+ handle: "rewrite"
134
+ }, ...buildInfoForWriting.manifest.allRoutes.filter(r => r.routeKeys && Object.keys(r.routeKeys).length > 0).map(r => ({
135
+ src: r.namedRegex,
136
+ dest: `${(0, import_getPathFromRoute.getPathFromRoute)(r)}?${Object.entries(r.routeKeys).map(([k, v]) => `${k}=$${v}`).join("&")}`
137
+ }))]
138
+ }), postBuildLogs.push(`[one.build] wrote vercel config to: ${vercelConfigFilePath}`);
109
139
  };
@@ -25,7 +25,7 @@ __export(buildVercelOutputDirectory_exports, {
25
25
  buildVercelOutputDirectory: () => buildVercelOutputDirectory
26
26
  });
27
27
  module.exports = __toCommonJS(buildVercelOutputDirectory_exports);
28
- var import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), import_ts_pattern = require("ts-pattern"), import_createApiServerlessFunction = require("./generate/createApiServerlessFunction"), import_createSsrServerlessFunction = require("./generate/createSsrServerlessFunction"), import_vc_config_base = require("./config/vc-config-base"), import_vc_package_base = require("./config/vc-package-base"), import_vc_build_output_config_base = require("./config/vc-build-output-config-base");
28
+ var import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), import_ts_pattern = require("ts-pattern"), import_createApiServerlessFunction = require("./generate/createApiServerlessFunction"), import_createSsrServerlessFunction = require("./generate/createSsrServerlessFunction"), import_vc_package_base = require("./config/vc-package-base"), import_vc_build_output_config_base = require("./config/vc-build-output-config-base"), import_getPathFromRoute = require("./getPathFromRoute");
29
29
  const { copy, ensureDir, existsSync, writeJSON } = import_fs_extra.default;
30
30
  async function moveAllFiles(src, dest) {
31
31
  try {
@@ -50,17 +50,7 @@ const buildVercelOutputDirectory = async ({
50
50
  const compiledRoute = compiltedApiRoutes.find((compiled) => compiled.facadeModuleId.includes(route.file.replace("./", "")));
51
51
  compiledRoute ? (postBuildLogs.push(
52
52
  `[one.build][vercel] generating serverless function for apiRoute ${route.page}`
53
- ), await (0, import_createApiServerlessFunction.createApiServerlessFunction)(
54
- route.page,
55
- compiledRoute.code,
56
- oneOptionsRoot,
57
- postBuildLogs
58
- ), route.page !== route.urlCleanPath && await (0, import_createApiServerlessFunction.createApiServerlessFunction)(
59
- route.urlCleanPath,
60
- compiledRoute.code,
61
- oneOptionsRoot,
62
- postBuildLogs
63
- )) : console.warn(`
53
+ ), await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route, compiledRoute.code, oneOptionsRoot, postBuildLogs)) : console.warn(`
64
54
  \u{1F528}[one.build][vercel] apiRoute missing code compilation for`, route.file);
65
55
  }
66
56
  }
@@ -72,7 +62,7 @@ const buildVercelOutputDirectory = async ({
72
62
  routeToBuildInfo[route.file] && (postBuildLogs.push(
73
63
  `[one.build][vercel] generate serverless function for ${route.page} with ${route.type}`
74
64
  ), await (0, import_createSsrServerlessFunction.createSsrServerlessFunction)(
75
- route.page,
65
+ route,
76
66
  buildInfoForWriting,
77
67
  oneOptionsRoot,
78
68
  postBuildLogs
@@ -85,7 +75,7 @@ const buildVercelOutputDirectory = async ({
85
75
  const distMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "middlewares"));
86
76
  if (existsSync(distMiddlewareDir)) {
87
77
  const vercelMiddlewareDir = (0, import_node_path.resolve)(
88
- (0, import_node_path.join)(oneOptionsRoot, ".vercel/output/functions/_middleware")
78
+ (0, import_node_path.join)(oneOptionsRoot, ".vercel/output/functions/_middleware.func")
89
79
  );
90
80
  await ensureDir(vercelMiddlewareDir), postBuildLogs.push(
91
81
  `[one.build][vercel] copying middlewares from ${distMiddlewareDir} to ${vercelMiddlewareDir}`
@@ -94,12 +84,34 @@ const buildVercelOutputDirectory = async ({
94
84
  postBuildLogs.push(
95
85
  `[one.build][vercel] writing package.json to ${vercelMiddlewarePackageJsonFilePath}`
96
86
  ), await writeJSON(vercelMiddlewarePackageJsonFilePath, import_vc_package_base.serverlessVercelPackageJson);
87
+ const wrappedMiddlewareEntryPointFilename = "_wrapped_middleware.js", wrappedMiddlewareEntryPointPath = (0, import_node_path.resolve)(
88
+ (0, import_node_path.join)(vercelMiddlewareDir, wrappedMiddlewareEntryPointFilename)
89
+ );
90
+ await import_fs_extra.default.writeFile(
91
+ wrappedMiddlewareEntryPointPath,
92
+ `
93
+ import middlewareFunction from './_middleware.js'
94
+
95
+ const next = (e) => {
96
+ const t = new Headers(null == e ? void 0 : e.headers)
97
+ t.set('x-middleware-next', '1')
98
+ return new Response(null, { ...e, headers: t })
99
+ }
100
+
101
+ const wrappedMiddlewareFunction = (request, event) => {
102
+ return middlewareFunction({ request, event, next })
103
+ }
104
+
105
+ export { wrappedMiddlewareFunction as default }
106
+ `
107
+ );
97
108
  const middlewareVercelConfigFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, ".vc-config.json"));
98
109
  postBuildLogs.push(
99
110
  `[one.build][vercel] writing .vc-config.json to ${middlewareVercelConfigFilePath}`
100
111
  ), await writeJSON(middlewareVercelConfigFilePath, {
101
- ...import_vc_config_base.serverlessVercelNodeJsConfig,
102
- handler: "_middleware.js"
112
+ runtime: "edge",
113
+ // Seems that middlewares only work with edge runtime
114
+ entrypoint: wrappedMiddlewareEntryPointFilename
103
115
  });
104
116
  }
105
117
  const vercelOutputStaticDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/static"));
@@ -107,6 +119,25 @@ const buildVercelOutputDirectory = async ({
107
119
  `[one.build][vercel] copying static files from ${clientDir} to ${vercelOutputStaticDir}`
108
120
  ), await moveAllFiles(clientDir, vercelOutputStaticDir);
109
121
  const vercelConfigFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output", "config.json"));
110
- await writeJSON(vercelConfigFilePath, import_vc_build_output_config_base.vercelBuildOutputConfig), postBuildLogs.push(`[one.build] wrote vercel config to: ${vercelConfigFilePath}`);
122
+ await writeJSON(vercelConfigFilePath, {
123
+ ...import_vc_build_output_config_base.vercelBuildOutputConfigBase,
124
+ routes: [
125
+ ...import_vc_build_output_config_base.vercelBuildOutputConfigBase.routes,
126
+ ...existsSync(distMiddlewareDir) ? [
127
+ {
128
+ src: "/(.*)",
129
+ middlewarePath: "_middleware",
130
+ continue: !0
131
+ }
132
+ ] : [],
133
+ {
134
+ handle: "rewrite"
135
+ },
136
+ ...buildInfoForWriting.manifest.allRoutes.filter((r) => r.routeKeys && Object.keys(r.routeKeys).length > 0).map((r) => ({
137
+ src: r.namedRegex,
138
+ dest: `${(0, import_getPathFromRoute.getPathFromRoute)(r)}?${Object.entries(r.routeKeys).map(([k, v]) => `${k}=$${v}`).join("&")}`
139
+ }))
140
+ ]
141
+ }), postBuildLogs.push(`[one.build] wrote vercel config to: ${vercelConfigFilePath}`);
111
142
  };
112
143
  //# sourceMappingURL=buildVercelOutputDirectory.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/vercel/build/buildVercelOutputDirectory.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA8B,sBAE9B,kBAAoB,iCAEpB,oBAA8B,uBAE9B,qCAA4C,mDAC5C,qCAA4C,mDAC5C,wBAA6C,oCAC7C,yBAA4C,qCAC5C,qCAAwC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xF,GACA,MAAM,aAAa,WAAW,qBAAqB;AAInD,QAAM,2BAAuB,8BAAQ,uBAAK,gBAAgB,kBAAkB,aAAa,CAAC;AAC1F,QAAM,UAAU,sBAAsB;AAAA,IACpC,GAAG;AAAA,IACH,QAAQ;AAAA,MACN,GAAG,+DAA4B;AAAA,MAC/B,GAAI,WAAW,iBAAiB,IAC5B;AAAA,QACE;AAAA,UACE,KAAK;AAAA,UACL,gBAAgB;AAAA,UAChB,UAAU;AAAA,QACZ;AAAA,MACF,IACA,CAAC;AAAA,MACL;AAAA,QACE,QAAQ;AAAA,MACV;AAAA,MACA,GAAG,oBAAoB,SAAS,UAC7B,OAAO,CAAC,MAAM,EAAE,aAAa,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAChE,IAAI,CAAC,OAAO;AAAA,QACX,KAAK,EAAE;AAAA,QACP,MAAM,OAAG,0CAAiB,CAAC,CAAC,IAAI,OAAO,QAAQ,EAAE,SAAS,EACvD,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,EAC5B,KAAK,GAAG,CAAC;AAAA,MACd,EAAE;AAAA,IACN;AAAA,EACF,CAAC,GACD,cAAc,KAAK,uCAAuC,oBAAoB,EAAE;AAClF;",
5
5
  "names": ["FSExtra"]
6
6
  }
@@ -26,7 +26,7 @@ __export(buildVercelOutputDirectory_exports, {
26
26
  buildVercelOutputDirectory: () => buildVercelOutputDirectory
27
27
  });
28
28
  module.exports = __toCommonJS(buildVercelOutputDirectory_exports);
29
- var import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), import_ts_pattern = require("ts-pattern"), import_createApiServerlessFunction = require("./generate/createApiServerlessFunction"), import_createSsrServerlessFunction = require("./generate/createSsrServerlessFunction"), import_vc_config_base = require("./config/vc-config-base"), import_vc_package_base = require("./config/vc-package-base"), import_vc_build_output_config_base = require("./config/vc-build-output-config-base"), { copy, ensureDir, existsSync, writeJSON } = import_fs_extra.default;
29
+ var import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), import_ts_pattern = require("ts-pattern"), import_createApiServerlessFunction = require("./generate/createApiServerlessFunction"), import_createSsrServerlessFunction = require("./generate/createSsrServerlessFunction"), import_vc_package_base = require("./config/vc-package-base"), import_vc_build_output_config_base = require("./config/vc-build-output-config-base"), import_getPathFromRoute = require("./getPathFromRoute"), { copy, ensureDir, existsSync, writeJSON } = import_fs_extra.default;
30
30
  async function moveAllFiles(src, dest) {
31
31
  try {
32
32
  await copy(src, dest, {
@@ -52,7 +52,7 @@ var buildVercelOutputDirectory = async function(param) {
52
52
  var flag = compiled.facadeModuleId.includes(route2.file.replace("./", ""));
53
53
  return flag;
54
54
  });
55
- compiledRoute ? (postBuildLogs.push(`[one.build][vercel] generating serverless function for apiRoute ${route2.page}`), await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route2.page, compiledRoute.code, oneOptionsRoot, postBuildLogs), route2.page !== route2.urlCleanPath && await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route2.urlCleanPath, compiledRoute.code, oneOptionsRoot, postBuildLogs)) : console.warn(`
55
+ compiledRoute ? (postBuildLogs.push(`[one.build][vercel] generating serverless function for apiRoute ${route2.page}`), await (0, import_createApiServerlessFunction.createApiServerlessFunction)(route2, compiledRoute.code, oneOptionsRoot, postBuildLogs)) : console.warn(`
56
56
  \u{1F528}[one.build][vercel] apiRoute missing code compilation for`, route2.file);
57
57
  }, _iterator = buildInfoForWriting.manifest.apiRoutes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) await _loop();
58
58
  } catch (err) {
@@ -75,7 +75,7 @@ var buildVercelOutputDirectory = async function(param) {
75
75
  switch (route.type) {
76
76
  case "ssr": {
77
77
  var builtPageRoute = routeToBuildInfo[route.file];
78
- builtPageRoute && (postBuildLogs.push(`[one.build][vercel] generate serverless function for ${route.page} with ${route.type}`), await (0, import_createSsrServerlessFunction.createSsrServerlessFunction)(route.page, buildInfoForWriting, oneOptionsRoot, postBuildLogs));
78
+ builtPageRoute && (postBuildLogs.push(`[one.build][vercel] generate serverless function for ${route.page} with ${route.type}`), await (0, import_createSsrServerlessFunction.createSsrServerlessFunction)(route, buildInfoForWriting, oneOptionsRoot, postBuildLogs));
79
79
  break;
80
80
  }
81
81
  default:
@@ -94,20 +94,63 @@ var buildVercelOutputDirectory = async function(param) {
94
94
  }
95
95
  var distMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "middlewares"));
96
96
  if (existsSync(distMiddlewareDir)) {
97
- var vercelMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/functions/_middleware"));
97
+ var vercelMiddlewareDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/functions/_middleware.func"));
98
98
  await ensureDir(vercelMiddlewareDir), postBuildLogs.push(`[one.build][vercel] copying middlewares from ${distMiddlewareDir} to ${vercelMiddlewareDir}`), await moveAllFiles((0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "middlewares")), vercelMiddlewareDir);
99
99
  var vercelMiddlewarePackageJsonFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, "index.js"));
100
100
  postBuildLogs.push(`[one.build][vercel] writing package.json to ${vercelMiddlewarePackageJsonFilePath}`), await writeJSON(vercelMiddlewarePackageJsonFilePath, import_vc_package_base.serverlessVercelPackageJson);
101
+ var wrappedMiddlewareEntryPointFilename = "_wrapped_middleware.js", wrappedMiddlewareEntryPointPath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, wrappedMiddlewareEntryPointFilename));
102
+ await import_fs_extra.default.writeFile(wrappedMiddlewareEntryPointPath, `
103
+ import middlewareFunction from './_middleware.js'
104
+
105
+ const next = (e) => {
106
+ const t = new Headers(null == e ? void 0 : e.headers)
107
+ t.set('x-middleware-next', '1')
108
+ return new Response(null, { ...e, headers: t })
109
+ }
110
+
111
+ const wrappedMiddlewareFunction = (request, event) => {
112
+ return middlewareFunction({ request, event, next })
113
+ }
114
+
115
+ export { wrappedMiddlewareFunction as default }
116
+ `);
101
117
  var middlewareVercelConfigFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(vercelMiddlewareDir, ".vc-config.json"));
102
118
  postBuildLogs.push(`[one.build][vercel] writing .vc-config.json to ${middlewareVercelConfigFilePath}`), await writeJSON(middlewareVercelConfigFilePath, {
103
- ...import_vc_config_base.serverlessVercelNodeJsConfig,
104
- handler: "_middleware.js"
119
+ runtime: "edge",
120
+ // Seems that middlewares only work with edge runtime
121
+ entrypoint: wrappedMiddlewareEntryPointFilename
105
122
  });
106
123
  }
107
124
  var vercelOutputStaticDir = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output/static"));
108
125
  await ensureDir(vercelOutputStaticDir), postBuildLogs.push(`[one.build][vercel] copying static files from ${clientDir} to ${vercelOutputStaticDir}`), await moveAllFiles(clientDir, vercelOutputStaticDir);
109
126
  var vercelConfigFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, ".vercel/output", "config.json"));
110
- await writeJSON(vercelConfigFilePath, import_vc_build_output_config_base.vercelBuildOutputConfig), postBuildLogs.push(`[one.build] wrote vercel config to: ${vercelConfigFilePath}`);
127
+ await writeJSON(vercelConfigFilePath, {
128
+ ...import_vc_build_output_config_base.vercelBuildOutputConfigBase,
129
+ routes: [
130
+ ...import_vc_build_output_config_base.vercelBuildOutputConfigBase.routes,
131
+ ...existsSync(distMiddlewareDir) ? [
132
+ {
133
+ src: "/(.*)",
134
+ middlewarePath: "_middleware",
135
+ continue: !0
136
+ }
137
+ ] : [],
138
+ {
139
+ handle: "rewrite"
140
+ },
141
+ ...buildInfoForWriting.manifest.allRoutes.filter(function(r) {
142
+ return r.routeKeys && Object.keys(r.routeKeys).length > 0;
143
+ }).map(function(r) {
144
+ return {
145
+ src: r.namedRegex,
146
+ dest: `${(0, import_getPathFromRoute.getPathFromRoute)(r)}?${Object.entries(r.routeKeys).map(function(param2) {
147
+ var [k, v] = param2;
148
+ return `${k}=$${v}`;
149
+ }).join("&")}`
150
+ };
151
+ })
152
+ ]
153
+ }), postBuildLogs.push(`[one.build] wrote vercel config to: ${vercelConfigFilePath}`);
111
154
  };
112
155
  // Annotate the CommonJS export names for ESM import in node:
113
156
  0 && (module.exports = {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/vercel/build/buildVercelOutputDirectory.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;uBAA8B,sBAE9B,kBAAoB,iCAEpB,oBAA8B,uBAE9B,qCAA4C,mDAC5C,qCAA4C,mDAC5C,wBAA6C,oCAC7C,yBAA4C,qCAC5C,qCAAwC,iDAIlC,EAAEA,MAAMC,WAAWC,YAAYC,UAAS,IAAKC,gBAAAA;AAEnD,eAAeC,aAAaC,KAAaC,MAAY;AACnD,MAAI;AACF,UAAMP,KAAKM,KAAKC,MAAM;MAAEC,WAAW;MAAMC,cAAc;IAAM,CAAA;EAC/D,SAASC,KAAK;AACZC,YAAQC,MAAM,uBAAuBF,GAAAA;EACvC;AACF;AAEO,IAAMG,6BAA6B,eAAA,OAAA;MAAO,EAC/CC,WACAC,qBACAC,WACAC,gBACAC,cAAa,IAOd,OACO,EAAEC,iBAAgB,IAAKJ;AAC7B,MAAID,WAAW;QACeA,mBAAtBM,uBAAsBN,oBAAAA,aAAAA,OAAAA,SAAAA,UAAWO,YAAM,QAAjBP,sBAAAA,SAAAA,oBAAqB,CAAA,GAAIQ,OAAO,SAACC,GAAAA;iBAC3DC,8BAAW;QAAEC,MAAMC,oBAAEC;QAAQC,gBAAgBF,oBAAEC;MAAO,GAAGJ,CAAAA;QAEtD,4BAAA,IAAA,oBAAA,IAAA,iBAAA;;AAAL;AAAK,YAAMM,SAAN,MAAA,OACGC,gBAAgBV,mBAA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,UAAA,QAAA,WAAA,OAAA;;UAAA;cAAA;;;AAyBL,MAAMgC,wBAAoBC,8BAAQN,uBAAK5B,gBAAgB,QAAQ,aAAA,CAAA;AAC/D,MAAIf,WAAWgD,iBAAAA,GAAoB;AACjC,QAAME,0BAAsBD,8BAC1BN,uBAAK5B,gBAAgB,sCAAA,CAAA;AAEvB,UAAMhB,UAAUmD,mBAAAA,GAChBlC,cAAcmB,KACZ,gDAAgDa,iBAAAA,OAAwBE,mBAAAA,EAAqB,GAE/F,MAAM/C,iBAAa8C,8BAAQN,uBAAK5B,gBAAgB,QAAQ,aAAA,CAAA,GAAiBmC,mBAAAA;AACzE,QAAMC,0CAAsCF,8BAAQN,uBAAKO,qBAAqB,UAAA,CAAA;AAC9ElC,kBAAcmB,KACZ,+CAA+CgB,mCAAAA,EAAqC,GAEtF,MAAMlD,UAAUkD,qCAAqCC,kDAAAA;AACrD,QAAMC,qCAAiCJ,8BAAQN,uBAAKO,qBAAqB,iBAAA,CAAA;AACzElC,kBAAcmB,KACZ,kDAAkDkB,8BAAAA,EAAgC,GAEpF,MAAMpD,UAAUoD,gCAAgC;MAC9C,GAAGC;MACHC,SAAS;IACX,CAAA;EACF;AAEA,MAAMC,4BAAwBP,8BAAQN,uBAAK5B,gBAAgB,uBAAA,CAAA;AAC3D,QAAMhB,UAAUyD,qBAAAA,GAEhBxC,cAAcmB,KACZ,iDAAiDrB,SAAAA,OAAgB0C,qBAAAA,EAAuB,GAE1F,MAAMrD,aAAaW,WAAW0C,qBAAAA;AAI9B,MAAMC,2BAAuBR,8BAAQN,uBAAK5B,gBAAgB,kBAAkB,aAAA,CAAA;AAC5E,QAAMd,UAAUwD,sBAAsBC,0DAAAA,GACtC1C,cAAcmB,KAAK,uCAAuCsB,oBAAAA,EAAsB;AAClF;",
5
- "names": ["copy", "ensureDir", "existsSync", "writeJSON", "FSExtra", "moveAllFiles", "src", "dest", "overwrite", "errorOnExist", "err", "console", "error", "buildVercelOutputDirectory", "apiOutput", "buildInfoForWriting", "clientDir", "oneOptionsRoot", "postBuildLogs", "routeToBuildInfo", "compiltedApiRoutes", "output", "filter", "o", "isMatching", "code", "P", "string", "facadeModuleId", "route", "compiledRoute", "find", "compiled", "flag", "includes", "file", "replace", "push", "page", "createApiServerlessFunction", "urlCleanPath", "warn", "manifest", "apiRoutes", "vercelOutputFunctionsDir", "join", "pageRoutes", "type", "builtPageRoute", "createSsrServerlessFunction", "distMiddlewareDir", "resolve", "vercelMiddlewareDir", "vercelMiddlewarePackageJsonFilePath", "serverlessVercelPackageJson", "middlewareVercelConfigFilePath", "serverlessVercelNodeJsConfig", "handler", "vercelOutputStaticDir", "vercelConfigFilePath", "vercelBuildOutputConfig"]
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;uBAA8B,sBAE9B,kBAAoB,iCAEpB,oBAA8B,uBAE9B,qCAA4C,mDAC5C,qCAA4C,mDAE5C,yBAA4C,qCAC5C,qCAA4C,iDAG5C,0BAAiC,+BAE3B,EAAEA,MAAMC,WAAWC,YAAYC,UAAS,IAAKC,gBAAAA;AAEnD,eAAeC,aAAaC,KAAaC,MAAY;AACnD,MAAI;AACF,UAAMP,KAAKM,KAAKC,MAAM;MAAEC,WAAW;MAAMC,cAAc;IAAM,CAAA;EAC/D,SAASC,KAAK;AACZC,YAAQC,MAAM,uBAAuBF,GAAAA;EACvC;AACF;AAEO,IAAMG,6BAA6B,eAAA,OAAA;MAAO,EAC/CC,WACAC,qBACAC,WACAC,gBACAC,cAAa,IAOd,OACO,EAAEC,iBAAgB,IAAKJ;AAC7B,MAAID,WAAW;QACeA,mBAAtBM,uBAAsBN,oBAAAA,aAAAA,OAAAA,SAAAA,UAAWO,YAAM,QAAjBP,sBAAAA,SAAAA,oBAAqB,CAAA,GAAIQ,OAAO,SAACC,GAAAA;iBAC3DC,8BAAW;QAAEC,MAAMC,oBAAEC;QAAQC,gBAAgBF,oBAAEC;MAAO,GAAGJ,CAAAA;QAEtD,4BAAA,IAAA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AA,IACX;QACE;UACE3C,KAAK;UACL0D,gBAAgB;UAChBC,UAAU;QACZ;UAEF,CAAA;MACJ;QACEC,QAAQ;MACV;SACGnD,oBAAoB0B,SAAS0B,UAC7B7C,OAAO,SAAC8C,GAAAA;eAAMA,EAAEC,aAAaC,OAAOC,KAAKH,EAAEC,SAAS,EAAEG,SAAS;SAC/DC,IAAI,SAACL,GAAAA;eAAO;UACX9D,KAAK8D,EAAEM;UACPnE,MAAM,OAAGoE,0CAAiBP,CAAAA,CAAAA,IAAME,OAAOM,QAAQR,EAAEC,SAAS,EACvDI,IAAI,SAAAI,QAAA;gBAAC,CAACC,GAAGC,CAAAA,IAAEF;mBAAK,GAAGC,CAAAA,KAAMC,CAAAA;aACzBnC,KAAK,GAAA,CAAA;QACV;;;EAEN,CAAA,GACA1B,cAAcmB,KAAK,uCAAuCwB,oBAAAA,EAAsB;AAClF;",
5
+ "names": ["copy", "ensureDir", "existsSync", "writeJSON", "FSExtra", "moveAllFiles", "src", "dest", "overwrite", "errorOnExist", "err", "console", "error", "buildVercelOutputDirectory", "apiOutput", "buildInfoForWriting", "clientDir", "oneOptionsRoot", "postBuildLogs", "routeToBuildInfo", "compiltedApiRoutes", "output", "filter", "o", "isMatching", "code", "P", "string", "facadeModuleId", "route", "compiledRoute", "find", "compiled", "flag", "includes", "file", "replace", "push", "page", "createApiServerlessFunction", "warn", "manifest", "apiRoutes", "vercelOutputFunctionsDir", "join", "pageRoutes", "type", "builtPageRoute", "createSsrServerlessFunction", "distMiddlewareDir", "resolve", "vercelMiddlewareDir", "vercelMiddlewarePackageJsonFilePath", "serverlessVercelPackageJson", "wrappedMiddlewareEntryPointFilename", "wrappedMiddlewareEntryPointPath", "writeFile", "middlewareVercelConfigFilePath", "runtime", "entrypoint", "vercelOutputStaticDir", "vercelConfigFilePath", "vercelBuildOutputConfigBase", "routes", "middlewarePath", "continue", "handle", "allRoutes", "r", "routeKeys", "Object", "keys", "length", "map", "namedRegex", "getPathFromRoute", "entries", "param", "k", "v"]
6
6
  }
@@ -20,14 +20,17 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
20
20
  }), mod);
21
21
  var vc_build_output_config_base_exports = {};
22
22
  __export(vc_build_output_config_base_exports, {
23
- vercelBuildOutputConfig: () => vercelBuildOutputConfig
23
+ vercelBuildOutputConfigBase: () => vercelBuildOutputConfigBase
24
24
  });
25
25
  module.exports = __toCommonJS(vc_build_output_config_base_exports);
26
- const vercelBuildOutputConfig = {
26
+ const vercelBuildOutputConfigBase = {
27
27
  version: 3,
28
28
  // https://vercel.com/docs/build-output-api/v3/configuration#routes
29
- routes: [{
30
- src: "/(.*)",
31
- status: 200
32
- }]
29
+ routes: [
30
+ // Not sure if we really need this, but having this seems to break the 'rewrite's we will add to handle dynamic routes.
31
+ // {
32
+ // src: '/(.*)',
33
+ // status: 200,
34
+ // },
35
+ ]
33
36
  };
@@ -14,17 +14,18 @@ var __export = (target, all) => {
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
15
  var vc_build_output_config_base_exports = {};
16
16
  __export(vc_build_output_config_base_exports, {
17
- vercelBuildOutputConfig: () => vercelBuildOutputConfig
17
+ vercelBuildOutputConfigBase: () => vercelBuildOutputConfigBase
18
18
  });
19
19
  module.exports = __toCommonJS(vc_build_output_config_base_exports);
20
- const vercelBuildOutputConfig = {
20
+ const vercelBuildOutputConfigBase = {
21
21
  version: 3,
22
22
  // https://vercel.com/docs/build-output-api/v3/configuration#routes
23
23
  routes: [
24
- {
25
- src: "/(.*)",
26
- status: 200
27
- }
24
+ // Not sure if we really need this, but having this seems to break the 'rewrite's we will add to handle dynamic routes.
25
+ // {
26
+ // src: '/(.*)',
27
+ // status: 200,
28
+ // },
28
29
  ]
29
30
  };
30
31
  //# sourceMappingURL=vc-build-output-config-base.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/vercel/build/config/vc-build-output-config-base.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,0BAA0B;AAAA,EACrC,SAAS;AAAA;AAAA,EAET,QAAQ;AAAA,IACN;AAAA,MACE,KAAK;AAAA,MACL,QAAQ;AAAA,IACV;AAAA,EACF;AACF;",
4
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,8BAA8B;AAAA,EACzC,SAAS;AAAA;AAAA,EAET,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR;AACF;",
5
5
  "names": []
6
6
  }
@@ -15,21 +15,16 @@ var __export = (target, all) => {
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
16
  var vc_build_output_config_base_exports = {};
17
17
  __export(vc_build_output_config_base_exports, {
18
- vercelBuildOutputConfig: () => vercelBuildOutputConfig
18
+ vercelBuildOutputConfigBase: () => vercelBuildOutputConfigBase
19
19
  });
20
20
  module.exports = __toCommonJS(vc_build_output_config_base_exports);
21
- var vercelBuildOutputConfig = {
21
+ var vercelBuildOutputConfigBase = {
22
22
  version: 3,
23
23
  // https://vercel.com/docs/build-output-api/v3/configuration#routes
24
- routes: [
25
- {
26
- src: "/(.*)",
27
- status: 200
28
- }
29
- ]
24
+ routes: []
30
25
  };
31
26
  // Annotate the CommonJS export names for ESM import in node:
32
27
  0 && (module.exports = {
33
- vercelBuildOutputConfig
28
+ vercelBuildOutputConfigBase
34
29
  });
35
30
  //# sourceMappingURL=vc-build-output-config-base.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/vercel/build/config/vc-build-output-config-base.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;AAAA;;;;;AAEO,IAAMA,0BAA0B;EACrCC,SAAS;;EAETC,QAAQ;IACN;MACEC,KAAK;MACLC,QAAQ;IACV;;AAEJ;",
5
- "names": ["vercelBuildOutputConfig", "version", "routes", "src", "status"]
4
+ "mappings": ";;;;;;;;;;;;;;;AAAA;;;;;AAEO,IAAMA,8BAA8B;EACzCC,SAAS;;EAETC,QAAQ,CAAA;AAOV;",
5
+ "names": ["vercelBuildOutputConfigBase", "version", "routes"]
6
6
  }
@@ -36,23 +36,68 @@ __export(createApiServerlessFunction_exports, {
36
36
  module.exports = __toCommonJS(createApiServerlessFunction_exports);
37
37
  var import_node_path = require("node:path"),
38
38
  import_fs_extra = __toESM(require("fs-extra"), 1),
39
+ import_resolve = require("@vxrn/resolve"),
40
+ import_parser = __toESM(require("@babel/parser"), 1),
41
+ import_traverse = __toESM(require("@babel/traverse"), 1),
42
+ import_types = __toESM(require("@babel/types"), 1),
43
+ import_generator = __toESM(require("@babel/generator"), 1),
44
+ import_fs_extra2 = __toESM(require("fs-extra"), 1),
39
45
  import_vc_package_base = require("../config/vc-package-base.cjs"),
40
- import_vc_config_base = require("../config/vc-config-base.cjs");
41
- async function createApiServerlessFunction(pageName, code, oneOptionsRoot, postBuildLogs) {
46
+ import_vc_config_base = require("../config/vc-config-base.cjs"),
47
+ import_getPathFromRoute = require("../getPathFromRoute.cjs");
48
+ async function createApiServerlessFunction(route, code, oneOptionsRoot, postBuildLogs) {
42
49
  try {
43
- postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] pageName: ${pageName}`);
44
- const funcFolder = (0, import_node_path.join)(oneOptionsRoot, `.vercel/output/functions/${pageName}.func`);
45
- await import_fs_extra.default.ensureDir(funcFolder), code.includes("react") && (postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] detected react in depenency tree for ${pageName}`), await import_fs_extra.default.copy((0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "..", "..", "node_modules", "react")), (0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "node_modules", "react"))));
50
+ const path = (0, import_getPathFromRoute.getPathFromRoute)(route);
51
+ postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] pageName: ${path}`);
52
+ const funcFolder = (0, import_node_path.join)(oneOptionsRoot, `.vercel/output/functions/${path}.func`);
53
+ if (await import_fs_extra2.default.ensureDir(funcFolder), code.includes("react")) {
54
+ postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] detected react in depenency tree for ${path}`);
55
+ const reactPath = (0, import_node_path.dirname)((0, import_resolve.resolvePath)("react/package.json", oneOptionsRoot));
56
+ await import_fs_extra2.default.copy((0, import_node_path.resolve)(reactPath), (0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "node_modules", "react")));
57
+ }
46
58
  const distAssetsFolder = (0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "assets"));
47
- postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] copy shared assets to ${distAssetsFolder}`), await import_fs_extra.default.copy((0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "api", "assets")), distAssetsFolder), await import_fs_extra.default.ensureDir((0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "entrypoint")));
59
+ postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] copy shared assets to ${distAssetsFolder}`);
60
+ const sourceAssetsFolder = (0, import_node_path.resolve)((0, import_node_path.join)(oneOptionsRoot, "dist", "api", "assets"));
61
+ (await import_fs_extra.default.pathExists(sourceAssetsFolder)) && (await import_fs_extra2.default.copy(sourceAssetsFolder, distAssetsFolder)), await import_fs_extra2.default.ensureDir((0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "entrypoint")));
48
62
  const entrypointFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "entrypoint", "index.js"));
49
- postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] writing entrypoint to ${entrypointFilePath}`), await import_fs_extra.default.writeFile(entrypointFilePath, code);
63
+ postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] writing entrypoint to ${entrypointFilePath}`), await import_fs_extra2.default.writeFile(entrypointFilePath, wrapHandlerFunctions(code));
50
64
  const packageJsonFilePath = (0, import_node_path.resolve)((0, import_node_path.join)(funcFolder, "package.json"));
51
- return postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] writing package.json to ${packageJsonFilePath}`), await import_fs_extra.default.writeJSON(packageJsonFilePath, import_vc_package_base.serverlessVercelPackageJson), postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] writing .vc-config.json to ${(0, import_node_path.join)(funcFolder, ".vc-config.json")}`), import_fs_extra.default.writeJson((0, import_node_path.join)(funcFolder, ".vc-config.json"), {
65
+ return postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] writing package.json to ${packageJsonFilePath}`), await import_fs_extra2.default.writeJSON(packageJsonFilePath, import_vc_package_base.serverlessVercelPackageJson), postBuildLogs.push(`[one.build][vercel.createSsrServerlessFunction] writing .vc-config.json to ${(0, import_node_path.join)(funcFolder, ".vc-config.json")}`), import_fs_extra2.default.writeJson((0, import_node_path.join)(funcFolder, ".vc-config.json"), {
52
66
  ...import_vc_config_base.serverlessVercelNodeJsConfig,
53
67
  handler: "entrypoint/index.js"
54
68
  });
55
69
  } catch (e) {
56
- console.error(`[one.build][vercel.createSsrServerlessFunction] failed to generate func for ${pageName}`, e);
70
+ console.error(`[one.build][vercel.createSsrServerlessFunction] failed to generate func for ${route.file}`, e);
57
71
  }
72
+ }
73
+ function wrapHandlerFunctions(code) {
74
+ const ast = import_parser.default.parse(code, {
75
+ sourceType: "module"
76
+ });
77
+ return import_traverse.default.default(ast, {
78
+ FunctionDeclaration(path) {
79
+ const {
80
+ node
81
+ } = path,
82
+ functionNamesToHandle = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"
83
+ // TODO: more possibilities?
84
+ ];
85
+ if (!node.id || !functionNamesToHandle.includes(node.id.name) || node.extra && node.extra.isWrapper || node.extra && node.extra.isWrapped) return;
86
+ const originalName = `orig_${node.id.name}`,
87
+ originalFunction = import_types.default.functionDeclaration(import_types.default.identifier(originalName), node.params, node.body, node.generator, node.async),
88
+ requestIdentifier = import_types.default.identifier("request"),
89
+ wrapperParams = [requestIdentifier],
90
+ urlIdentifier = import_types.default.identifier("url"),
91
+ paramsIdentifier = import_types.default.identifier("params"),
92
+ urlDecl = import_types.default.variableDeclaration("const", [import_types.default.variableDeclarator(urlIdentifier, import_types.default.newExpression(import_types.default.identifier("URL"), [import_types.default.memberExpression(requestIdentifier, import_types.default.identifier("url"))]))]),
93
+ paramsDecl = import_types.default.variableDeclaration("const", [import_types.default.variableDeclarator(paramsIdentifier, import_types.default.callExpression(import_types.default.memberExpression(import_types.default.identifier("Object"), import_types.default.identifier("fromEntries")), [import_types.default.callExpression(import_types.default.memberExpression(import_types.default.memberExpression(urlIdentifier, import_types.default.identifier("searchParams")), import_types.default.identifier("entries")), [])]))]),
94
+ callOrigFnStatement = import_types.default.callExpression(import_types.default.identifier(originalName), [requestIdentifier, import_types.default.objectExpression([import_types.default.objectProperty(import_types.default.identifier("params"), paramsIdentifier)])]),
95
+ wrapperFunction = import_types.default.functionDeclaration(import_types.default.identifier(node.id.name + ""), wrapperParams, import_types.default.blockStatement([urlDecl, paramsDecl, import_types.default.returnStatement(callOrigFnStatement)])
96
+ // No need to care if the wrapper function should be async,
97
+ // since we didn't use any await in the wrapper function, and we'll
98
+ // just return what the original function returns.
99
+ );
100
+ node.extra = node.extra || {}, node.extra.isWrapped = !0, wrapperFunction.extra = wrapperFunction.extra || {}, wrapperFunction.extra.isWrapper = !0, path.parentPath.isExportNamedDeclaration() ? path.replaceWithMultiple([originalFunction, import_types.default.exportNamedDeclaration(wrapperFunction, [])]) : path.replaceWithMultiple([originalFunction, wrapperFunction]);
101
+ }
102
+ }), import_generator.default.default(ast, {}).code;
58
103
  }