nitro 3.0.1-alpha.0 → 3.0.1-alpha.2

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 (316) hide show
  1. package/README.md +2 -0
  2. package/dist/_build/common.mjs +24940 -0
  3. package/dist/_build/rolldown.mjs +172 -0
  4. package/dist/_build/rollup.mjs +201 -0
  5. package/dist/_build/vite.build.mjs +16 -0
  6. package/dist/_chunks/dev.mjs +707 -0
  7. package/dist/_chunks/nitro.mjs +1191 -0
  8. package/dist/_chunks/nitro2.mjs +101 -0
  9. package/dist/_chunks/utils.mjs +254 -0
  10. package/dist/_common.mjs +45 -0
  11. package/dist/_dev.d.mts +12 -0
  12. package/dist/_libs/c12+giget+readdirp+chokidar.d.mts +214 -0
  13. package/dist/_libs/citty.mjs +363 -0
  14. package/dist/_libs/commondir+is-reference.mjs +1300 -0
  15. package/dist/_libs/compatx.d.mts +47 -0
  16. package/dist/_libs/compatx.mjs +46 -0
  17. package/dist/_libs/confbox.mjs +2509 -0
  18. package/dist/_libs/esbuild.d.mts +20 -0
  19. package/dist/_libs/escape-string-regexp.mjs +8 -0
  20. package/dist/_libs/estree-walker.mjs +187 -0
  21. package/dist/_libs/hasown+resolve+deepmerge.mjs +1972 -0
  22. package/dist/_libs/httpxy.d.mts +79 -0
  23. package/dist/_libs/httpxy.mjs +415 -0
  24. package/dist/_libs/klona.mjs +38 -0
  25. package/dist/_libs/magic-string.d.mts +220 -0
  26. package/dist/_libs/mlly.d.mts +57 -0
  27. package/dist/_libs/nypm+giget+tinyexec.mjs +3603 -0
  28. package/dist/_libs/pkg-types.d.mts +23 -0
  29. package/dist/_libs/plugin-alias.mjs +66 -0
  30. package/dist/_libs/plugin-inject.mjs +135 -0
  31. package/dist/_libs/plugin-json.mjs +36 -0
  32. package/dist/_libs/pluginutils+plugin-commonjs.d.mts +241 -0
  33. package/dist/_libs/pluginutils.mjs +652 -0
  34. package/dist/_libs/rc9+c12+dotenv.mjs +972 -0
  35. package/dist/_libs/readdirp+chokidar.mjs +1611 -0
  36. package/dist/_libs/remapping.mjs +117 -0
  37. package/dist/_libs/resolve-uri+gen-mapping.mjs +448 -0
  38. package/dist/_libs/rou3.d.mts +43 -0
  39. package/dist/_libs/rou3.mjs +322 -0
  40. package/dist/_libs/std-env.d.mts +4 -0
  41. package/dist/_libs/tsconfck.mjs +832 -0
  42. package/dist/_libs/ultrahtml.mjs +138 -0
  43. package/dist/_libs/unimport+unplugin.mjs +1785 -0
  44. package/dist/_libs/unplugin+unimport.d.mts +426 -0
  45. package/dist/_libs/unwasm.d.mts +29 -0
  46. package/dist/_presets.mjs +1802 -0
  47. package/dist/builder.d.mts +63 -0
  48. package/dist/builder.mjs +9 -0
  49. package/dist/cli/_chunks/build.mjs +48 -0
  50. package/dist/cli/_chunks/common.mjs +15 -0
  51. package/dist/cli/_chunks/dev.mjs +62 -0
  52. package/dist/cli/_chunks/list.mjs +27 -0
  53. package/dist/cli/_chunks/prepare.mjs +19 -0
  54. package/dist/cli/_chunks/run.mjs +55 -0
  55. package/dist/cli/_chunks/task.mjs +16 -0
  56. package/dist/cli/index.d.mts +1 -1
  57. package/dist/cli/index.mjs +20 -476
  58. package/dist/node_modules/@poppinss/colors/build/index.js +130 -160
  59. package/dist/node_modules/@poppinss/colors/package.json +20 -18
  60. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +1 -1
  61. package/dist/node_modules/@poppinss/dumper/package.json +1 -1
  62. package/dist/node_modules/@poppinss/exception/build/index.js +36 -55
  63. package/dist/node_modules/@poppinss/exception/package.json +19 -16
  64. package/dist/node_modules/@sindresorhus/is/distribution/index.js +47 -6
  65. package/dist/node_modules/@sindresorhus/is/package.json +1 -1
  66. package/dist/node_modules/@speed-highlight/core/dist/index.js +2 -2
  67. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  68. package/dist/node_modules/@speed-highlight/core/package.json +8 -4
  69. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  70. package/dist/node_modules/cookie-es/package.json +37 -0
  71. package/dist/node_modules/hookable/dist/index.mjs +244 -268
  72. package/dist/node_modules/hookable/package.json +29 -26
  73. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  74. package/dist/node_modules/rendu/package.json +47 -0
  75. package/dist/node_modules/ufo/dist/index.mjs +16 -9
  76. package/dist/node_modules/ufo/package.json +15 -14
  77. package/dist/node_modules/unctx/package.json +16 -16
  78. package/dist/node_modules/youch/build/{chunk-4XB2BYKC.js → chunk-7QV3D5YX.js} +2 -4
  79. package/dist/node_modules/youch/build/{chunk-PUHGL6HA.js → chunk-AUGPHE32.js} +2 -4
  80. package/dist/node_modules/youch/build/{chunk-VE4LENUR.js → chunk-CM7DWJNZ.js} +4 -5
  81. package/dist/node_modules/youch/build/{chunk-JAN2TFI2.js → chunk-EJH674NB.js} +6 -5
  82. package/dist/node_modules/youch/build/{chunk-EUJBVOYB.js → chunk-OIJ3WD7L.js} +2 -4
  83. package/dist/node_modules/youch/build/{chunk-HFSXRSKS.js → chunk-P36L72PL.js} +5 -3
  84. package/dist/node_modules/youch/build/{chunk-4YEN7HVQ.js → chunk-PE3GG3TN.js} +5 -1
  85. package/dist/node_modules/youch/build/{chunk-PINJDICN.js → chunk-X53OIOJH.js} +2 -4
  86. package/dist/node_modules/youch/build/index.js +22 -15
  87. package/dist/node_modules/youch/build/public/error_info/style.css +1 -0
  88. package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
  89. package/dist/node_modules/youch/build/public/error_stack/script.js +20 -22
  90. package/dist/node_modules/youch/build/public/error_stack/style.css +2 -3
  91. package/dist/node_modules/youch/build/public/header/script.js +0 -2
  92. package/dist/node_modules/youch/build/public/layout/script.js +0 -8
  93. package/dist/node_modules/youch/build/public/layout/style.css +4 -0
  94. package/dist/node_modules/youch/package.json +16 -17
  95. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +2 -1
  96. package/dist/presets/_nitro/runtime/nitro-dev.mjs +47 -42
  97. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +3 -3
  98. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +11 -15
  99. package/dist/presets/_nitro/runtime/service-worker.d.mts +2 -1
  100. package/dist/presets/_nitro/runtime/service-worker.mjs +17 -14
  101. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +2 -1
  102. package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +8 -7
  103. package/dist/presets/aws-lambda/runtime/_utils.d.mts +3 -13
  104. package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
  105. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +2 -3
  106. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -29
  107. package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +1 -1
  108. package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +9 -9
  109. package/dist/presets/azure/runtime/_utils.mjs +43 -43
  110. package/dist/presets/azure/runtime/azure-swa.d.mts +3 -3
  111. package/dist/presets/azure/runtime/azure-swa.mjs +25 -23
  112. package/dist/presets/bun/runtime/bun.d.mts +3 -1
  113. package/dist/presets/bun/runtime/bun.mjs +34 -22
  114. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +12 -9
  115. package/dist/presets/cloudflare/runtime/_module-handler.mjs +84 -90
  116. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +7 -15
  117. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +62 -64
  118. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +2 -8
  119. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +15 -18
  120. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +13 -13
  121. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -43
  122. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
  123. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +89 -82
  124. package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
  125. package/dist/presets/deno/runtime/deno-deploy.d.mts +5 -1
  126. package/dist/presets/deno/runtime/deno-deploy.mjs +15 -13
  127. package/dist/presets/deno/runtime/deno-server.d.mts +1 -4
  128. package/dist/presets/deno/runtime/deno-server.mjs +32 -53
  129. package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -2
  130. package/dist/presets/netlify/runtime/netlify-edge.mjs +18 -14
  131. package/dist/presets/netlify/runtime/netlify.d.mts +3 -2
  132. package/dist/presets/netlify/runtime/netlify.mjs +15 -19
  133. package/dist/presets/node/runtime/node-cluster.d.mts +3 -1
  134. package/dist/presets/node/runtime/node-cluster.mjs +49 -54
  135. package/dist/presets/node/runtime/node-middleware.d.mts +3 -4
  136. package/dist/presets/node/runtime/node-middleware.mjs +9 -9
  137. package/dist/presets/node/runtime/node-server.d.mts +1 -1
  138. package/dist/presets/node/runtime/node-server.mjs +36 -34
  139. package/dist/presets/standard/runtime/server.d.mts +2 -4
  140. package/dist/presets/standard/runtime/server.mjs +3 -5
  141. package/dist/presets/stormkit/runtime/stormkit.d.mts +14 -14
  142. package/dist/presets/stormkit/runtime/stormkit.mjs +22 -22
  143. package/dist/presets/vercel/runtime/isr.d.mts +2 -0
  144. package/dist/presets/vercel/runtime/isr.mjs +19 -0
  145. package/dist/presets/vercel/runtime/vercel.node.d.mts +3 -0
  146. package/dist/presets/vercel/runtime/vercel.node.mjs +24 -0
  147. package/dist/presets/vercel/runtime/vercel.web.d.mts +8 -0
  148. package/dist/presets/vercel/runtime/vercel.web.mjs +25 -0
  149. package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -1
  150. package/dist/presets/winterjs/runtime/winterjs.mjs +74 -70
  151. package/dist/presets/zeabur/runtime/zeabur.d.mts +2 -2
  152. package/dist/presets/zeabur/runtime/zeabur.mjs +2 -2
  153. package/dist/runtime/app.d.mts +1 -0
  154. package/dist/runtime/app.mjs +1 -0
  155. package/dist/runtime/cache.d.mts +1 -0
  156. package/dist/runtime/cache.mjs +1 -0
  157. package/dist/runtime/config.d.mts +3 -0
  158. package/dist/runtime/config.mjs +4 -0
  159. package/dist/runtime/context.d.mts +1 -0
  160. package/dist/runtime/context.mjs +1 -0
  161. package/dist/runtime/database.d.mts +1 -0
  162. package/dist/runtime/database.mjs +1 -0
  163. package/dist/runtime/internal/app.d.mts +15 -1
  164. package/dist/runtime/internal/app.mjs +199 -144
  165. package/dist/runtime/internal/cache.d.mts +9 -5
  166. package/dist/runtime/internal/cache.mjs +248 -219
  167. package/dist/runtime/internal/context.d.mts +9 -9
  168. package/dist/runtime/internal/context.mjs +17 -10
  169. package/dist/runtime/internal/database.mjs +9 -11
  170. package/dist/runtime/internal/error/dev.d.mts +4 -4
  171. package/dist/runtime/internal/error/dev.mjs +106 -105
  172. package/dist/runtime/internal/error/hooks.d.mts +1 -0
  173. package/dist/runtime/internal/error/hooks.mjs +9 -0
  174. package/dist/runtime/internal/error/prod.d.mts +5 -4
  175. package/dist/runtime/internal/error/prod.mjs +51 -59
  176. package/dist/runtime/internal/error/utils.d.mts +4 -4
  177. package/dist/runtime/internal/error/utils.mjs +1 -1
  178. package/dist/runtime/internal/meta.d.mts +1 -1
  179. package/dist/runtime/internal/meta.mjs +1 -1
  180. package/dist/runtime/internal/plugin.d.mts +2 -2
  181. package/dist/runtime/internal/plugin.mjs +1 -1
  182. package/dist/runtime/internal/route-rules.d.mts +4 -8
  183. package/dist/runtime/internal/route-rules.mjs +54 -52
  184. package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -2
  185. package/dist/runtime/internal/routes/dev-tasks.mjs +17 -19
  186. package/dist/runtime/internal/routes/openapi.mjs +82 -88
  187. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  188. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
  189. package/dist/runtime/internal/routes/renderer-template.dev.mjs +15 -17
  190. package/dist/runtime/internal/routes/renderer-template.mjs +2 -2
  191. package/dist/runtime/internal/routes/scalar.mjs +22 -23
  192. package/dist/runtime/internal/routes/swagger.mjs +9 -11
  193. package/dist/runtime/internal/runtime-config.d.mts +4 -4
  194. package/dist/runtime/internal/runtime-config.mjs +44 -39
  195. package/dist/runtime/internal/static.mjs +63 -74
  196. package/dist/runtime/internal/storage.mjs +3 -3
  197. package/dist/runtime/internal/task.d.mts +6 -6
  198. package/dist/runtime/internal/task.mjs +57 -61
  199. package/dist/runtime/internal/vite/dev-entry.mjs +11 -2
  200. package/dist/runtime/internal/vite/{dev-worker.mjs → node-runner.mjs} +54 -57
  201. package/dist/runtime/internal/vite/ssr-renderer.mjs +3 -1
  202. package/{lib/runtime-meta.d.mts → dist/runtime/meta.d.mts} +2 -2
  203. package/dist/runtime/meta.mjs +26 -0
  204. package/dist/runtime/nitro.d.mts +9 -0
  205. package/dist/runtime/nitro.mjs +32 -0
  206. package/dist/runtime/runtime-config.d.mts +1 -0
  207. package/dist/runtime/runtime-config.mjs +1 -0
  208. package/dist/runtime/storage.d.mts +1 -0
  209. package/dist/runtime/storage.mjs +1 -0
  210. package/dist/runtime/task.d.mts +1 -0
  211. package/dist/runtime/task.mjs +1 -0
  212. package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
  213. package/dist/runtime/virtual/database.d.mts +8 -0
  214. package/dist/runtime/virtual/database.mjs +2 -0
  215. package/dist/runtime/virtual/error-handler.d.mts +6 -0
  216. package/dist/runtime/virtual/error-handler.mjs +9 -0
  217. package/dist/runtime/virtual/feature-flags.d.mts +7 -0
  218. package/dist/runtime/virtual/feature-flags.mjs +7 -0
  219. package/dist/runtime/virtual/plugins.d.mts +3 -0
  220. package/dist/runtime/virtual/plugins.mjs +2 -0
  221. package/dist/runtime/virtual/polyfills.d.mts +3 -0
  222. package/dist/runtime/virtual/polyfills.mjs +2 -0
  223. package/dist/runtime/virtual/public-assets.d.mts +9 -0
  224. package/dist/runtime/virtual/public-assets.mjs +8 -0
  225. package/dist/runtime/virtual/renderer-template.d.mts +4 -0
  226. package/dist/runtime/virtual/renderer-template.mjs +7 -0
  227. package/dist/runtime/virtual/routing-meta.d.mts +7 -0
  228. package/dist/runtime/virtual/routing-meta.mjs +2 -0
  229. package/dist/runtime/virtual/routing.d.mts +8 -0
  230. package/dist/runtime/virtual/routing.mjs +11 -0
  231. package/dist/runtime/virtual/runtime-config.d.mts +3 -0
  232. package/dist/runtime/virtual/runtime-config.mjs +5 -0
  233. package/dist/runtime/virtual/server-assets.d.mts +6 -0
  234. package/dist/runtime/virtual/server-assets.mjs +12 -0
  235. package/dist/runtime/virtual/storage.d.mts +3 -0
  236. package/dist/runtime/virtual/storage.mjs +5 -0
  237. package/dist/runtime/virtual/tasks.d.mts +10 -0
  238. package/dist/runtime/virtual/tasks.mjs +3 -0
  239. package/dist/runtime/vite.d.mts +8 -0
  240. package/dist/runtime/vite.mjs +9 -0
  241. package/dist/types/index.d.mts +2561 -2312
  242. package/dist/types/index.mjs +10 -0
  243. package/dist/vite.d.mts +44 -51
  244. package/dist/vite.mjs +737 -68
  245. package/lib/tsconfig.json +27 -0
  246. package/lib/vite.types.d.mts +26 -0
  247. package/lib/vite.types.mjs +2 -0
  248. package/package.json +118 -101
  249. package/dist/_chunks/app.mjs +0 -19797
  250. package/dist/_chunks/build.mjs +0 -84
  251. package/dist/_chunks/build2.mjs +0 -318
  252. package/dist/_chunks/build3.mjs +0 -6452
  253. package/dist/_chunks/detect-acorn.mjs +0 -503
  254. package/dist/_chunks/index.mjs +0 -22242
  255. package/dist/_chunks/index2.mjs +0 -297
  256. package/dist/_chunks/index3.mjs +0 -1058
  257. package/dist/_chunks/index4.mjs +0 -1206
  258. package/dist/_chunks/info.mjs +0 -11157
  259. package/dist/_chunks/json5.mjs +0 -68
  260. package/dist/_chunks/jsonc.mjs +0 -51
  261. package/dist/_chunks/pathe.M-eThtNZ.mjs +0 -204
  262. package/dist/_chunks/plugin.mjs +0 -960
  263. package/dist/_chunks/server.mjs +0 -254
  264. package/dist/_chunks/snapshot.mjs +0 -284
  265. package/dist/_chunks/toml.mjs +0 -259
  266. package/dist/_chunks/yaml.mjs +0 -86
  267. package/dist/cli/build.mjs +0 -54
  268. package/dist/cli/common.mjs +0 -13
  269. package/dist/cli/dev.mjs +0 -95
  270. package/dist/cli/index2.mjs +0 -17
  271. package/dist/cli/list.mjs +0 -34
  272. package/dist/cli/prepare.mjs +0 -24
  273. package/dist/cli/run.mjs +0 -60
  274. package/dist/index.d.mts +0 -52
  275. package/dist/index.mjs +0 -55
  276. package/dist/node_modules/cookie/dist/index.js +0 -239
  277. package/dist/node_modules/cookie/package.json +0 -42
  278. package/dist/node_modules/kleur/index.js +0 -110
  279. package/dist/node_modules/klona/dist/index.mjs +0 -81
  280. package/dist/node_modules/klona/full/index.mjs +0 -53
  281. package/dist/node_modules/klona/package.json +0 -74
  282. package/dist/node_modules/std-env/dist/index.mjs +0 -1
  283. package/dist/node_modules/std-env/package.json +0 -46
  284. package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +0 -6
  285. package/dist/presets/vercel/runtime/vercel.d.mts +0 -8
  286. package/dist/presets/vercel/runtime/vercel.mjs +0 -17
  287. package/dist/presets.mjs +0 -2460
  288. package/dist/runtime/index.d.mts +0 -11
  289. package/dist/runtime/index.mjs +0 -17
  290. package/dist/runtime/internal/debug.d.mts +0 -2
  291. package/dist/runtime/internal/debug.mjs +0 -5
  292. package/dist/runtime/internal/empty.d.mts +0 -0
  293. package/dist/runtime/internal/index.d.mts +0 -3
  294. package/dist/runtime/internal/index.mjs +0 -3
  295. package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +0 -16
  296. package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +0 -213
  297. package/dist/runtime/internal/renderer.d.mts +0 -3
  298. package/dist/runtime/internal/renderer.mjs +0 -36
  299. package/dist/runtime/internal/shutdown.d.mts +0 -9
  300. package/dist/runtime/internal/shutdown.mjs +0 -34
  301. package/dist/runtime/internal/utils.d.mts +0 -1
  302. package/dist/runtime/internal/utils.mjs +0 -15
  303. package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
  304. package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
  305. package/dist/runtime/internal/vite/prod-setup.mjs +0 -55
  306. package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
  307. package/lib/config.d.mts +0 -9
  308. package/lib/config.mjs +0 -5
  309. package/lib/deps/ofetch.mjs +0 -1
  310. package/lib/deps/ofetch.mts +0 -1
  311. package/lib/meta.d.mts +0 -5
  312. package/lib/meta.mjs +0 -21
  313. package/lib/runtime-meta.mjs +0 -38
  314. /package/dist/runtime/{internal/vite/dev-worker.d.mts → virtual/_runtime_warn.d.mts} +0 -0
  315. /package/lib/{deps/h3.d.mts → h3.d.mts} +0 -0
  316. /package/lib/{deps/h3.mjs → h3.mjs} +0 -0
@@ -0,0 +1,1802 @@
1
+ import "./_common.mjs";
2
+ import { $ as resolveModulePath, G as findFile, I as prettyPath$1, J as readGitConfig, K as findNearestFile, N as glob, R as writeFile$2, U as p, V as a, X as h, Y as readPackageJSON, at as join$1, ct as resolve$1, nt as dirname$1, st as relative$1, z as K } from "./_build/common.mjs";
3
+ import { i as gr, n as Q } from "./_libs/confbox.mjs";
4
+ import { r as resolveCompatibilityDatesFromEnv, t as formatCompatibilityDate } from "./_libs/compatx.mjs";
5
+ import { builtinModules } from "node:module";
6
+ import consola$1 from "consola";
7
+ import { existsSync, promises } from "node:fs";
8
+ import fsp, { readFile, writeFile } from "node:fs/promises";
9
+ import { dirname, extname, relative, resolve } from "node:path";
10
+ import { defu } from "defu";
11
+ import { hasProtocol, joinURL, withLeadingSlash, withTrailingSlash, withoutLeadingSlash } from "ufo";
12
+ import { presetsDir, runtimeDir, version } from "nitro/meta";
13
+ import { colors } from "consola/utils";
14
+ import { kebabCase } from "scule";
15
+
16
+ //#region src/presets/_utils/preset.ts
17
+ function defineNitroPreset(preset, meta) {
18
+ if (typeof preset !== "function" && preset.entry && preset.entry.startsWith(".")) preset.entry = resolve(presetsDir, preset.entry);
19
+ return {
20
+ ...preset,
21
+ _meta: meta
22
+ };
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/presets/_nitro/base-worker.ts
27
+ const baseWorker = defineNitroPreset({
28
+ entry: null,
29
+ node: false,
30
+ minify: true,
31
+ noExternals: true,
32
+ rollupConfig: { output: {
33
+ format: "iife",
34
+ generatedCode: { symbols: true }
35
+ } },
36
+ inlineDynamicImports: true
37
+ }, { name: "base-worker" });
38
+ var base_worker_default = [baseWorker];
39
+
40
+ //#endregion
41
+ //#region src/presets/_nitro/nitro-dev.ts
42
+ const nitroDev = defineNitroPreset({
43
+ entry: "./_nitro/runtime/nitro-dev",
44
+ output: {
45
+ dir: "{{ buildDir }}/dev",
46
+ serverDir: "{{ buildDir }}/dev",
47
+ publicDir: "{{ buildDir }}/dev"
48
+ },
49
+ handlers: [{
50
+ route: "/_nitro/tasks/**",
51
+ lazy: true,
52
+ handler: join$1(runtimeDir, "internal/routes/dev-tasks")
53
+ }],
54
+ externals: { noTrace: true },
55
+ serveStatic: true,
56
+ inlineDynamicImports: true,
57
+ sourcemap: true
58
+ }, {
59
+ name: "nitro-dev",
60
+ dev: true
61
+ });
62
+ var nitro_dev_default = [nitroDev];
63
+
64
+ //#endregion
65
+ //#region src/presets/_nitro/nitro-prerender.ts
66
+ const nitroPrerender = defineNitroPreset({
67
+ entry: "./_nitro/runtime/nitro-prerenderer",
68
+ serveStatic: true,
69
+ output: { serverDir: "{{ buildDir }}/prerender" },
70
+ externals: { noTrace: true }
71
+ }, { name: "nitro-prerender" });
72
+ var nitro_prerender_default = [nitroPrerender];
73
+
74
+ //#endregion
75
+ //#region src/presets/_nitro/preset.ts
76
+ var preset_default$26 = [
77
+ ...base_worker_default,
78
+ ...nitro_dev_default,
79
+ ...nitro_prerender_default
80
+ ];
81
+
82
+ //#endregion
83
+ //#region src/presets/_static/preset.ts
84
+ const _static = defineNitroPreset({
85
+ static: true,
86
+ output: {
87
+ dir: "{{ rootDir }}/.output",
88
+ publicDir: "{{ output.dir }}/public"
89
+ },
90
+ prerender: { crawlLinks: true },
91
+ commands: { preview: "npx serve ./public" }
92
+ }, {
93
+ name: "static",
94
+ static: true
95
+ });
96
+ const githubPages = defineNitroPreset({
97
+ extends: "static",
98
+ commands: { deploy: "npx gh-pages --dotfiles -d ./public" },
99
+ prerender: { routes: ["/", "/404.html"] },
100
+ hooks: { async compiled(nitro) {
101
+ await fsp.writeFile(join$1(nitro.options.output.publicDir, ".nojekyll"), "");
102
+ } }
103
+ }, {
104
+ name: "github-pages",
105
+ static: true
106
+ });
107
+ const gitlabPages = defineNitroPreset({
108
+ extends: "static",
109
+ prerender: { routes: ["/", "/404.html"] }
110
+ }, {
111
+ name: "gitlab-pages",
112
+ static: true
113
+ });
114
+ var preset_default$25 = [
115
+ _static,
116
+ githubPages,
117
+ gitlabPages
118
+ ];
119
+
120
+ //#endregion
121
+ //#region src/presets/alwaysdata/preset.ts
122
+ const alwaysdata = defineNitroPreset({
123
+ extends: "node-server",
124
+ serveStatic: true,
125
+ commands: { deploy: "rsync -rRt --info=progress2 ./ [account]@ssh-[account].alwaysdata.net:www/my-app" }
126
+ }, { name: "alwaysdata" });
127
+ var preset_default$24 = [alwaysdata];
128
+
129
+ //#endregion
130
+ //#region src/presets/aws-amplify/utils.ts
131
+ async function writeAmplifyFiles(nitro) {
132
+ const outDir = nitro.options.output.dir;
133
+ const routes = [];
134
+ let hasWildcardPublicAsset = false;
135
+ if (nitro.options.awsAmplify?.imageOptimization && !nitro.options.static) {
136
+ const { path: path$1, cacheControl } = nitro.options.awsAmplify?.imageOptimization || {};
137
+ if (path$1) routes.push({
138
+ path: path$1,
139
+ target: {
140
+ kind: "ImageOptimization",
141
+ cacheControl
142
+ }
143
+ });
144
+ }
145
+ const computeTarget = nitro.options.static ? { kind: "Static" } : {
146
+ kind: "Compute",
147
+ src: "default"
148
+ };
149
+ for (const publicAsset of nitro.options.publicAssets) {
150
+ if (!publicAsset.baseURL || publicAsset.baseURL === "/") {
151
+ hasWildcardPublicAsset = true;
152
+ continue;
153
+ }
154
+ routes.push({
155
+ path: `${publicAsset.baseURL.replace(/\/$/, "")}/*`,
156
+ target: {
157
+ kind: "Static",
158
+ cacheControl: publicAsset.maxAge > 0 ? `public, max-age=${publicAsset.maxAge}, immutable` : void 0
159
+ },
160
+ fallback: publicAsset.fallthrough ? computeTarget : void 0
161
+ });
162
+ }
163
+ if (hasWildcardPublicAsset && !nitro.options.static) routes.push({
164
+ path: "/*.*",
165
+ target: { kind: "Static" },
166
+ fallback: computeTarget
167
+ });
168
+ routes.push({
169
+ path: "/*",
170
+ target: computeTarget,
171
+ fallback: hasWildcardPublicAsset && nitro.options.awsAmplify?.catchAllStaticFallback ? { kind: "Static" } : void 0
172
+ });
173
+ for (const route of routes) if (route.path !== "/*") route.path = joinURL(nitro.options.baseURL, route.path);
174
+ const deployManifest = {
175
+ version: 1,
176
+ routes,
177
+ imageSettings: nitro.options.awsAmplify?.imageSettings || void 0,
178
+ computeResources: nitro.options.static ? void 0 : [{
179
+ name: "default",
180
+ entrypoint: "server.js",
181
+ runtime: nitro.options.awsAmplify?.runtime || "nodejs20.x"
182
+ }],
183
+ framework: {
184
+ name: nitro.options.framework.name || "nitro",
185
+ version: nitro.options.framework.version || "0.0.0"
186
+ }
187
+ };
188
+ await writeFile(resolve(outDir, "deploy-manifest.json"), JSON.stringify(deployManifest, null, 2));
189
+ if (!nitro.options.static) await writeFile(resolve(outDir, "compute/default/server.js"), `import("./index.mjs")`);
190
+ }
191
+
192
+ //#endregion
193
+ //#region src/presets/aws-amplify/preset.ts
194
+ const awsAmplify = defineNitroPreset({
195
+ entry: "./aws-amplify/runtime/aws-amplify",
196
+ manifest: { deploymentId: process.env.AWS_JOB_ID },
197
+ serveStatic: true,
198
+ output: {
199
+ dir: "{{ rootDir }}/.amplify-hosting",
200
+ serverDir: "{{ output.dir }}/compute/default",
201
+ publicDir: "{{ output.dir }}/static{{ baseURL }}"
202
+ },
203
+ commands: { preview: "node ./compute/default/server.js" },
204
+ hooks: { async compiled(nitro) {
205
+ await writeAmplifyFiles(nitro);
206
+ } }
207
+ }, {
208
+ name: "aws-amplify",
209
+ stdName: "aws_amplify"
210
+ });
211
+ var preset_default$23 = [awsAmplify];
212
+
213
+ //#endregion
214
+ //#region src/presets/aws-lambda/preset.ts
215
+ const awsLambda = defineNitroPreset({
216
+ entry: "./aws-lambda/runtime/aws-lambda",
217
+ awsLambda: { streaming: false },
218
+ hooks: { "rollup:before": (nitro, rollupConfig) => {
219
+ if (nitro.options.awsLambda?.streaming) rollupConfig.input += "-streaming";
220
+ } }
221
+ }, { name: "aws-lambda" });
222
+ var preset_default$22 = [awsLambda];
223
+
224
+ //#endregion
225
+ //#region src/presets/_utils/fs.ts
226
+ function prettyPath(p$1, highlight = true) {
227
+ p$1 = relative$1(process.cwd(), p$1);
228
+ return highlight ? colors.cyan(p$1) : p$1;
229
+ }
230
+ async function writeFile$1(file, contents, log = false) {
231
+ await fsp.mkdir(dirname$1(file), { recursive: true });
232
+ await fsp.writeFile(file, contents, typeof contents === "string" ? "utf8" : void 0);
233
+ if (log) consola$1.info("Generated", prettyPath(file));
234
+ }
235
+
236
+ //#endregion
237
+ //#region src/presets/azure/utils.ts
238
+ async function writeSWARoutes(nitro) {
239
+ const host = { version: "2.0" };
240
+ const supportedNodeVersions = new Set(["20", "22"]);
241
+ let nodeVersion = "18";
242
+ try {
243
+ const currentNodeVersion = JSON.parse(await fsp.readFile(join$1(nitro.options.rootDir, "package.json"), "utf8")).engines.node;
244
+ if (supportedNodeVersions.has(currentNodeVersion)) nodeVersion = currentNodeVersion;
245
+ } catch {
246
+ const currentNodeVersion = process.versions.node.slice(0, 2);
247
+ if (supportedNodeVersions.has(currentNodeVersion)) nodeVersion = currentNodeVersion;
248
+ }
249
+ const config = {
250
+ ...nitro.options.azure?.config,
251
+ routes: [],
252
+ platform: {
253
+ apiRuntime: `node:${nodeVersion}`,
254
+ ...nitro.options.azure?.config?.platform
255
+ },
256
+ navigationFallback: {
257
+ rewrite: "/api/server",
258
+ ...nitro.options.azure?.config?.navigationFallback
259
+ }
260
+ };
261
+ const routeFiles = nitro._prerenderedRoutes || [];
262
+ const indexFileExists = routeFiles.some((route) => route.fileName === "/index.html");
263
+ if (!indexFileExists) config.routes.unshift({
264
+ route: "/index.html",
265
+ redirect: "/"
266
+ }, {
267
+ route: "/",
268
+ rewrite: "/api/server"
269
+ });
270
+ const suffix = 11;
271
+ for (const { fileName } of routeFiles) {
272
+ if (!fileName || !fileName.endsWith("/index.html")) continue;
273
+ config.routes.unshift({
274
+ route: fileName.slice(0, -suffix) || "/",
275
+ rewrite: fileName
276
+ });
277
+ }
278
+ for (const { fileName } of routeFiles) {
279
+ if (!fileName || !fileName.endsWith(".html") || fileName.endsWith("index.html")) continue;
280
+ const route = fileName.slice(0, -5);
281
+ const existingRouteIndex = config.routes.findIndex((_route) => _route.route === route);
282
+ if (existingRouteIndex !== -1) config.routes.splice(existingRouteIndex, 1);
283
+ config.routes.unshift({
284
+ route,
285
+ rewrite: fileName
286
+ });
287
+ }
288
+ if (nitro.options.azure?.config && "routes" in nitro.options.azure.config && Array.isArray(nitro.options.azure.config.routes)) for (const customRoute of nitro.options.azure.config.routes.reverse()) {
289
+ const existingRouteMatchIndex = config.routes.findIndex((value) => value.route === customRoute.route);
290
+ if (existingRouteMatchIndex === -1) config.routes.unshift(customRoute);
291
+ else config.routes[existingRouteMatchIndex] = customRoute;
292
+ }
293
+ await writeFile$1(resolve$1(nitro.options.output.serverDir, "function.json"), JSON.stringify({
294
+ entryPoint: "handle",
295
+ bindings: [{
296
+ authLevel: "anonymous",
297
+ type: "httpTrigger",
298
+ direction: "in",
299
+ name: "req",
300
+ route: "{*url}",
301
+ methods: [
302
+ "delete",
303
+ "get",
304
+ "head",
305
+ "options",
306
+ "patch",
307
+ "post",
308
+ "put"
309
+ ]
310
+ }, {
311
+ type: "http",
312
+ direction: "out",
313
+ name: "res"
314
+ }]
315
+ }, null, 2));
316
+ await writeFile$1(resolve$1(nitro.options.output.serverDir, "../host.json"), JSON.stringify(host, null, 2));
317
+ await writeFile$1(resolve$1(nitro.options.output.serverDir, "../package.json"), JSON.stringify({ private: true }));
318
+ await writeFile$1(resolve$1(nitro.options.rootDir, "staticwebapp.config.json"), JSON.stringify(config, null, 2));
319
+ if (!indexFileExists) {
320
+ const relativePrefix = nitro.options.baseURL.split("/").filter(Boolean).map(() => "..").join("/");
321
+ await writeFile$1(resolve$1(nitro.options.output.publicDir, relativePrefix ? `${relativePrefix}/index.html` : "index.html"), "");
322
+ }
323
+ }
324
+
325
+ //#endregion
326
+ //#region src/presets/azure/preset.ts
327
+ const azureSWA = defineNitroPreset({
328
+ entry: "./azure/runtime/azure-swa",
329
+ output: {
330
+ serverDir: "{{ output.dir }}/server/functions",
331
+ publicDir: "{{ output.dir }}/public/{{ baseURL }}"
332
+ },
333
+ commands: { preview: "npx @azure/static-web-apps-cli start ./public --api-location ./server" },
334
+ hooks: { async compiled(ctx) {
335
+ await writeSWARoutes(ctx);
336
+ } }
337
+ }, {
338
+ name: "azure-swa",
339
+ stdName: "azure_static"
340
+ });
341
+ var preset_default$21 = [azureSWA];
342
+
343
+ //#endregion
344
+ //#region src/presets/bun/preset.ts
345
+ const bun = defineNitroPreset({
346
+ entry: "./bun/runtime/bun",
347
+ serveStatic: true,
348
+ exportConditions: [
349
+ "bun",
350
+ "node",
351
+ "import",
352
+ "default"
353
+ ],
354
+ commands: { preview: "bun run ./server/index.mjs" }
355
+ }, { name: "bun" });
356
+ var preset_default$20 = [bun];
357
+
358
+ //#endregion
359
+ //#region src/presets/cleavr/preset.ts
360
+ const cleavr = defineNitroPreset({
361
+ extends: "node-server",
362
+ serveStatic: true
363
+ }, {
364
+ name: "cleavr",
365
+ stdName: "cleavr"
366
+ });
367
+ var preset_default$19 = [cleavr];
368
+
369
+ //#endregion
370
+ //#region src/presets/cloudflare/unenv/node-compat.ts
371
+ const builtnNodeModules$1 = [
372
+ "node:_http_agent",
373
+ "node:_http_client",
374
+ "node:_http_common",
375
+ "node:_http_incoming",
376
+ "node:_http_outgoing",
377
+ "node:_http_server",
378
+ "node:_stream_duplex",
379
+ "node:_stream_passthrough",
380
+ "node:_stream_readable",
381
+ "node:_stream_transform",
382
+ "node:_stream_writable",
383
+ "node:_tls_common",
384
+ "node:_tls_wrap",
385
+ "node:assert",
386
+ "node:assert/strict",
387
+ "node:async_hooks",
388
+ "node:buffer",
389
+ "node:constants",
390
+ "node:crypto",
391
+ "node:diagnostics_channel",
392
+ "node:dns",
393
+ "node:dns/promises",
394
+ "node:events",
395
+ "node:fs",
396
+ "node:fs/promises",
397
+ "node:http",
398
+ "node:http2",
399
+ "node:https",
400
+ "node:module",
401
+ "node:net",
402
+ "node:os",
403
+ "node:path",
404
+ "node:path/posix",
405
+ "node:path/win32",
406
+ "node:process",
407
+ "node:querystring",
408
+ "node:stream",
409
+ "node:stream/consumers",
410
+ "node:stream/promises",
411
+ "node:stream/web",
412
+ "node:string_decoder",
413
+ "node:test",
414
+ "node:timers",
415
+ "node:timers/promises",
416
+ "node:tls",
417
+ "node:url",
418
+ "node:util",
419
+ "node:util/types",
420
+ "node:zlib"
421
+ ];
422
+
423
+ //#endregion
424
+ //#region src/presets/cloudflare/unenv/preset.ts
425
+ const unenvCfNodeCompat = {
426
+ meta: { name: "nitro:cloudflare-node-compat" },
427
+ external: builtnNodeModules$1,
428
+ alias: { ...Object.fromEntries(builtnNodeModules$1.flatMap((m) => [[m, m], [m.replace("node:", ""), m]])) },
429
+ inject: {
430
+ global: "unenv/polyfill/globalthis",
431
+ process: "node:process",
432
+ clearImmediate: ["node:timers", "clearImmediate"],
433
+ setImmediate: ["node:timers", "setImmediate"],
434
+ Buffer: ["node:buffer", "Buffer"]
435
+ }
436
+ };
437
+ const unenvCfExternals = {
438
+ meta: { name: "nitro:cloudflare-externals" },
439
+ external: [
440
+ "cloudflare:email",
441
+ "cloudflare:sockets",
442
+ "cloudflare:workers",
443
+ "cloudflare:workflows"
444
+ ]
445
+ };
446
+
447
+ //#endregion
448
+ //#region src/presets/cloudflare/utils.ts
449
+ async function writeCFRoutes(nitro) {
450
+ const _cfPagesConfig = nitro.options.cloudflare?.pages || {};
451
+ const routes = {
452
+ version: _cfPagesConfig.routes?.version || 1,
453
+ include: _cfPagesConfig.routes?.include || ["/*"],
454
+ exclude: _cfPagesConfig.routes?.exclude || []
455
+ };
456
+ const writeRoutes = () => writeFile$1(resolve$1(nitro.options.output.dir, "_routes.json"), JSON.stringify(routes, void 0, 2), true);
457
+ if (_cfPagesConfig.defaultRoutes === false) {
458
+ await writeRoutes();
459
+ return;
460
+ }
461
+ const explicitPublicAssets = nitro.options.publicAssets.filter((dir, index, array) => {
462
+ if (dir.fallthrough || !dir.baseURL) return false;
463
+ const normalizedBase = withoutLeadingSlash(dir.baseURL);
464
+ return !array.some((otherDir, otherIndex) => otherIndex !== index && normalizedBase.startsWith(withoutLeadingSlash(withTrailingSlash(otherDir.baseURL))));
465
+ });
466
+ routes.exclude.push(...explicitPublicAssets.map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/", "*")).sort(comparePaths));
467
+ const publicAssetFiles = await glob("**", {
468
+ cwd: nitro.options.output.dir,
469
+ absolute: false,
470
+ dot: true,
471
+ ignore: [
472
+ "_worker.js",
473
+ "_worker.js.map",
474
+ "nitro.json",
475
+ ...routes.exclude.map((path$1) => withoutLeadingSlash(path$1.replace(/\/\*$/, "/**")))
476
+ ]
477
+ });
478
+ routes.exclude.push(...publicAssetFiles.map((i) => withLeadingSlash(i).replace(/\/index\.html$/, "").replace(/\.html$/, "") || "/").sort(comparePaths));
479
+ routes.exclude.splice(100 - routes.include.length);
480
+ await writeRoutes();
481
+ }
482
+ function comparePaths(a$1, b) {
483
+ return a$1.split("/").length - b.split("/").length || a$1.localeCompare(b);
484
+ }
485
+ async function writeCFHeaders(nitro, outdir) {
486
+ const headersPath = join$1(outdir === "public" ? nitro.options.output.publicDir : nitro.options.output.dir, "_headers");
487
+ const contents = [];
488
+ const rules = Object.entries(nitro.options.routeRules).sort((a$1, b) => b[0].split(/\/(?!\*)/).length - a$1[0].split(/\/(?!\*)/).length);
489
+ for (const [path$1, routeRules] of rules.filter(([_, routeRules$1]) => routeRules$1.headers)) {
490
+ const headers = [joinURL(nitro.options.baseURL, path$1.replace("/**", "/*")), ...Object.entries({ ...routeRules.headers }).map(([header, value]) => ` ${header}: ${value}`)].join("\n");
491
+ contents.push(headers);
492
+ }
493
+ if (existsSync(headersPath)) {
494
+ const currentHeaders = await readFile(headersPath, "utf8");
495
+ if (/^\/\* /m.test(currentHeaders)) {
496
+ nitro.logger.info("Not adding Nitro fallback to `_headers` (as an existing fallback was found).");
497
+ return;
498
+ }
499
+ nitro.logger.info("Adding Nitro fallback to `_headers` to handle all unmatched routes.");
500
+ contents.unshift(currentHeaders);
501
+ }
502
+ await writeFile$1(headersPath, contents.join("\n"), true);
503
+ }
504
+ async function writeCFPagesRedirects(nitro) {
505
+ const redirectsPath = join$1(nitro.options.output.dir, "_redirects");
506
+ const contents = [existsSync(join$1(nitro.options.output.publicDir, "404.html")) ? `${joinURL(nitro.options.baseURL, "/*")} ${joinURL(nitro.options.baseURL, "/404.html")} 404` : ""];
507
+ const rules = Object.entries(nitro.options.routeRules).sort((a$1, b) => a$1[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length);
508
+ for (const [key, routeRules] of rules.filter(([_, routeRules$1]) => routeRules$1.redirect)) {
509
+ const code = routeRules.redirect.status;
510
+ const from = joinURL(nitro.options.baseURL, key.replace("/**", "/*"));
511
+ const to = hasProtocol(routeRules.redirect.to, { acceptRelative: true }) ? routeRules.redirect.to : joinURL(nitro.options.baseURL, routeRules.redirect.to);
512
+ contents.unshift(`${from}\t${to}\t${code}`);
513
+ }
514
+ if (existsSync(redirectsPath)) {
515
+ const currentRedirects = await readFile(redirectsPath, "utf8");
516
+ if (/^\/\* /m.test(currentRedirects)) {
517
+ nitro.logger.info("Not adding Nitro fallback to `_redirects` (as an existing fallback was found).");
518
+ return;
519
+ }
520
+ nitro.logger.info("Adding Nitro fallback to `_redirects` to handle all unmatched routes.");
521
+ contents.unshift(currentRedirects);
522
+ }
523
+ await writeFile$1(redirectsPath, contents.join("\n"), true);
524
+ }
525
+ async function enableNodeCompat(nitro) {
526
+ nitro.options.cloudflare ??= {};
527
+ nitro.options.cloudflare.deployConfig ??= true;
528
+ nitro.options.cloudflare.nodeCompat ??= true;
529
+ if (nitro.options.cloudflare.nodeCompat) nitro.options.unenv.push(unenvCfNodeCompat);
530
+ }
531
+ const extensionParsers = {
532
+ ".json": h,
533
+ ".jsonc": h,
534
+ ".toml": Q
535
+ };
536
+ async function readWranglerConfig(nitro) {
537
+ const configPath = await findNearestFile([
538
+ "wrangler.json",
539
+ "wrangler.jsonc",
540
+ "wrangler.toml"
541
+ ], { startingFrom: nitro.options.rootDir }).catch(() => void 0);
542
+ if (!configPath) return {};
543
+ const userConfigText = await readFile(configPath, "utf8");
544
+ const parser = extensionParsers[extname(configPath)];
545
+ if (!parser) throw new Error(`Unsupported config file format: ${configPath}`);
546
+ return {
547
+ configPath,
548
+ config: parser(userConfigText)
549
+ };
550
+ }
551
+ async function writeWranglerConfig(nitro, cfTarget) {
552
+ if (!nitro.options.cloudflare?.deployConfig) return;
553
+ const wranglerConfigDir = nitro.options.output.serverDir;
554
+ const wranglerConfigPath = join$1(wranglerConfigDir, "wrangler.json");
555
+ const defaults = {};
556
+ const overrides = {};
557
+ defaults.compatibility_date = nitro.options.compatibilityDate.cloudflare || nitro.options.compatibilityDate.default;
558
+ if (cfTarget === "pages") overrides.pages_build_output_dir = relative(wranglerConfigDir, nitro.options.output.dir);
559
+ else {
560
+ overrides.main = relative(wranglerConfigDir, join$1(nitro.options.output.serverDir, "index.mjs"));
561
+ overrides.assets = {
562
+ binding: "ASSETS",
563
+ directory: relative(wranglerConfigDir, resolve$1(nitro.options.output.publicDir, "..".repeat(nitro.options.baseURL.split("/").filter(Boolean).length)))
564
+ };
565
+ }
566
+ const { config: userConfig = {} } = await readWranglerConfig(nitro);
567
+ const ctxConfig = nitro.options.cloudflare?.wrangler || {};
568
+ for (const key in overrides) if (key in userConfig || key in ctxConfig) nitro.logger.warn(`[cloudflare] Wrangler config \`${key}\`${key in ctxConfig ? "set by config or modules" : ""} is overridden and will be ignored.`);
569
+ const wranglerConfig = defu(overrides, ctxConfig, userConfig, defaults);
570
+ if (!wranglerConfig.name) {
571
+ wranglerConfig.name = await generateWorkerName(nitro);
572
+ nitro.logger.info(`Using auto generated worker name: \`${wranglerConfig.name}\``);
573
+ }
574
+ wranglerConfig.compatibility_flags ??= [];
575
+ if (nitro.options.cloudflare?.nodeCompat && !wranglerConfig.compatibility_flags.includes("nodejs_compat")) wranglerConfig.compatibility_flags.push("nodejs_compat");
576
+ if (cfTarget === "module") {
577
+ if (wranglerConfig.no_bundle === void 0) wranglerConfig.no_bundle = true;
578
+ wranglerConfig.rules ??= [];
579
+ if (!wranglerConfig.rules.some((rule) => rule.type === "ESModule")) wranglerConfig.rules.push({
580
+ type: "ESModule",
581
+ globs: ["**/*.mjs", "**/*.js"]
582
+ });
583
+ }
584
+ await writeFile$1(wranglerConfigPath, JSON.stringify(wranglerConfig, null, 2), true);
585
+ const configPath = join$1(nitro.options.rootDir, ".wrangler/deploy/config.json");
586
+ await writeFile$1(configPath, JSON.stringify({ configPath: relative(dirname(configPath), wranglerConfigPath) }), true);
587
+ }
588
+ async function generateWorkerName(nitro) {
589
+ const gitRepo = (await readGitConfig(nitro.options.rootDir).catch(() => void 0))?.remote?.origin?.url?.replace(/\.git$/, "").match(/[/:]([^/]+\/[^/]+)$/)?.[1];
590
+ const pkgName = (await readPackageJSON(nitro.options.rootDir).catch(() => void 0))?.name;
591
+ const subpath = relative(nitro.options.workspaceDir, nitro.options.rootDir);
592
+ return `${gitRepo || pkgName}/${subpath}`.toLowerCase().replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
593
+ }
594
+
595
+ //#endregion
596
+ //#region src/presets/cloudflare/dev.ts
597
+ async function cloudflareDevModule(nitro) {
598
+ if (!nitro.options.dev) return;
599
+ nitro.options.unenv.push({
600
+ meta: { name: "nitro:cloudflare-dev" },
601
+ alias: { "cloudflare:workers": resolve(presetsDir, "cloudflare/runtime/shims/workers.dev.mjs") }
602
+ });
603
+ if (!await resolveModulePath("wrangler", {
604
+ from: nitro.options.rootDir,
605
+ try: true
606
+ })) {
607
+ nitro.logger.warn("Wrangler is not installed. Please install it using `npx nypm i wrangler` to enable dev emulation.");
608
+ return;
609
+ }
610
+ const config = {
611
+ ...nitro.options.cloudflareDev,
612
+ ...nitro.options.cloudflare?.dev
613
+ };
614
+ let configPath = config.configPath;
615
+ if (!configPath) configPath = await findFile([
616
+ "wrangler.json",
617
+ "wrangler.jsonc",
618
+ "wrangler.toml"
619
+ ], { startingFrom: nitro.options.rootDir }).catch(() => void 0);
620
+ const persistDir = resolve(nitro.options.rootDir, config.persistDir || ".wrangler/state/v3");
621
+ const gitIgnorePath = await findFile(".gitignore", { startingFrom: nitro.options.rootDir }).catch(() => void 0);
622
+ if (gitIgnorePath && persistDir === ".wrangler/state/v3") {
623
+ const gitIgnore = await promises.readFile(gitIgnorePath, "utf8");
624
+ if (!gitIgnore.includes(".wrangler/state/v3")) await promises.writeFile(gitIgnorePath, gitIgnore + "\n.wrangler/state/v3\n").catch(() => {});
625
+ }
626
+ nitro.options.runtimeConfig.wrangler = {
627
+ ...nitro.options.runtimeConfig.wrangler,
628
+ configPath,
629
+ persistDir,
630
+ environment: config.environment
631
+ };
632
+ nitro.options.plugins = nitro.options.plugins || [];
633
+ nitro.options.plugins.unshift(resolveModulePath("./cloudflare/runtime/plugin.dev", {
634
+ from: presetsDir,
635
+ extensions: [".mjs", ".ts"]
636
+ }));
637
+ }
638
+
639
+ //#endregion
640
+ //#region src/presets/cloudflare/entry-exports.ts
641
+ const RESOLVE_EXTENSIONS = [
642
+ ".ts",
643
+ ".js",
644
+ ".mts",
645
+ ".mjs"
646
+ ];
647
+ async function setupEntryExports(nitro) {
648
+ const exportsEntry = resolveExportsEntry(nitro);
649
+ if (!exportsEntry) return;
650
+ const originalEntry = nitro.options.entry;
651
+ const virtualEntryId = nitro.options.entry = "#nitro/virtual/cloudflare-server-entry";
652
+ nitro.options.virtual[virtualEntryId] = `
653
+ export * from "${exportsEntry}";
654
+ export * from "${originalEntry}";
655
+ export { default } from "${originalEntry}";
656
+ `;
657
+ }
658
+ function resolveExportsEntry(nitro) {
659
+ const entry = resolveModulePath(nitro.options.cloudflare?.exports || "./exports.cloudflare.ts", {
660
+ from: nitro.options.rootDir,
661
+ extensions: RESOLVE_EXTENSIONS,
662
+ try: true
663
+ });
664
+ if (!entry && nitro.options.cloudflare?.exports) nitro.logger.warn(`Your custom Cloudflare entrypoint \`${prettyPath$1(nitro.options.cloudflare.exports)}\` file does not exist.`);
665
+ else if (entry && !nitro.options.cloudflare?.exports) nitro.logger.info(`Detected \`${prettyPath$1(entry)}\` as Cloudflare entrypoint.`);
666
+ return entry;
667
+ }
668
+
669
+ //#endregion
670
+ //#region src/presets/cloudflare/preset.ts
671
+ const cloudflarePages = defineNitroPreset({
672
+ extends: "base-worker",
673
+ entry: "./cloudflare/runtime/cloudflare-pages",
674
+ exportConditions: ["workerd"],
675
+ minify: false,
676
+ commands: {
677
+ preview: "npx wrangler --cwd ./ pages dev",
678
+ deploy: "npx wrangler --cwd ./ pages deploy"
679
+ },
680
+ output: {
681
+ dir: "{{ rootDir }}/dist",
682
+ publicDir: "{{ output.dir }}/{{ baseURL }}",
683
+ serverDir: "{{ output.dir }}/_worker.js"
684
+ },
685
+ alias: { _mime: "mime/index.js" },
686
+ wasm: {
687
+ lazy: false,
688
+ esmImport: true
689
+ },
690
+ rollupConfig: { output: {
691
+ entryFileNames: "index.js",
692
+ format: "esm",
693
+ inlineDynamicImports: false
694
+ } },
695
+ hooks: {
696
+ "build:before": async (nitro) => {
697
+ nitro.options.unenv.push(unenvCfExternals);
698
+ await enableNodeCompat(nitro);
699
+ await setupEntryExports(nitro);
700
+ },
701
+ async compiled(nitro) {
702
+ await writeWranglerConfig(nitro, "pages");
703
+ await writeCFRoutes(nitro);
704
+ await writeCFHeaders(nitro, "output");
705
+ await writeCFPagesRedirects(nitro);
706
+ }
707
+ }
708
+ }, {
709
+ name: "cloudflare-pages",
710
+ stdName: "cloudflare_pages"
711
+ });
712
+ const cloudflarePagesStatic = defineNitroPreset({
713
+ extends: "static",
714
+ output: {
715
+ dir: "{{ rootDir }}/dist",
716
+ publicDir: "{{ output.dir }}/{{ baseURL }}"
717
+ },
718
+ commands: {
719
+ preview: "npx wrangler --cwd ./ pages dev",
720
+ deploy: "npx wrangler --cwd ./ pages deploy"
721
+ },
722
+ hooks: { async compiled(nitro) {
723
+ await writeCFHeaders(nitro, "output");
724
+ await writeCFPagesRedirects(nitro);
725
+ } }
726
+ }, {
727
+ name: "cloudflare-pages-static",
728
+ stdName: "cloudflare_pages",
729
+ static: true
730
+ });
731
+ const cloudflareDev = defineNitroPreset({
732
+ extends: "nitro-dev",
733
+ modules: [cloudflareDevModule]
734
+ }, {
735
+ name: "cloudflare-dev",
736
+ aliases: [
737
+ "cloudflare-module",
738
+ "cloudflare-durable",
739
+ "cloudflare-pages"
740
+ ],
741
+ compatibilityDate: "2025-07-13",
742
+ dev: true
743
+ });
744
+ const cloudflareModule = defineNitroPreset({
745
+ extends: "base-worker",
746
+ entry: "./cloudflare/runtime/cloudflare-module",
747
+ output: { publicDir: "{{ output.dir }}/public/{{ baseURL }}" },
748
+ exportConditions: ["workerd"],
749
+ minify: false,
750
+ commands: {
751
+ preview: "npx wrangler --cwd ./ dev",
752
+ deploy: "npx wrangler --cwd ./ deploy"
753
+ },
754
+ rollupConfig: { output: {
755
+ format: "esm",
756
+ exports: "named",
757
+ inlineDynamicImports: false
758
+ } },
759
+ wasm: {
760
+ lazy: false,
761
+ esmImport: true
762
+ },
763
+ hooks: {
764
+ "build:before": async (nitro) => {
765
+ nitro.options.unenv.push(unenvCfExternals);
766
+ await enableNodeCompat(nitro);
767
+ await setupEntryExports(nitro);
768
+ },
769
+ async compiled(nitro) {
770
+ await writeWranglerConfig(nitro, "module");
771
+ await writeCFHeaders(nitro, "public");
772
+ await writeFile$1(resolve$1(nitro.options.output.dir, "package.json"), JSON.stringify({
773
+ private: true,
774
+ main: "./server/index.mjs"
775
+ }, null, 2));
776
+ await writeFile$1(resolve$1(nitro.options.output.dir, "package-lock.json"), JSON.stringify({ lockfileVersion: 1 }, null, 2));
777
+ }
778
+ }
779
+ }, {
780
+ name: "cloudflare-module",
781
+ stdName: "cloudflare_workers"
782
+ });
783
+ const cloudflareDurable = defineNitroPreset({
784
+ extends: "cloudflare-module",
785
+ entry: "./cloudflare/runtime/cloudflare-durable"
786
+ }, { name: "cloudflare-durable" });
787
+ var preset_default$18 = [
788
+ cloudflarePages,
789
+ cloudflarePagesStatic,
790
+ cloudflareModule,
791
+ cloudflareDurable,
792
+ cloudflareDev
793
+ ];
794
+
795
+ //#endregion
796
+ //#region src/presets/deno/unenv/node-compat.ts
797
+ const builtnNodeModules = [
798
+ "node:_http_agent",
799
+ "node:_http_common",
800
+ "node:_http_outgoing",
801
+ "node:_http_server",
802
+ "node:_stream_duplex",
803
+ "node:_stream_passthrough",
804
+ "node:_stream_readable",
805
+ "node:_stream_transform",
806
+ "node:_stream_writable",
807
+ "node:_tls_common",
808
+ "node:_tls_wrap",
809
+ "node:assert",
810
+ "node:assert/strict",
811
+ "node:async_hooks",
812
+ "node:buffer",
813
+ "node:child_process",
814
+ "node:cluster",
815
+ "node:console",
816
+ "node:constants",
817
+ "node:crypto",
818
+ "node:dgram",
819
+ "node:diagnostics_channel",
820
+ "node:dns",
821
+ "node:dns/promises",
822
+ "node:domain",
823
+ "node:events",
824
+ "node:fs",
825
+ "node:fs/promises",
826
+ "node:http",
827
+ "node:http2",
828
+ "node:https",
829
+ "node:inspector",
830
+ "node:inspector/promises",
831
+ "node:module",
832
+ "node:net",
833
+ "node:os",
834
+ "node:path",
835
+ "node:path/posix",
836
+ "node:path/win32",
837
+ "node:perf_hooks",
838
+ "node:process",
839
+ "node:punycode",
840
+ "node:querystring",
841
+ "node:readline",
842
+ "node:readline/promises",
843
+ "node:repl",
844
+ "node:sqlite",
845
+ "node:stream",
846
+ "node:stream/consumers",
847
+ "node:stream/promises",
848
+ "node:stream/web",
849
+ "node:string_decoder",
850
+ "node:sys",
851
+ "node:test",
852
+ "node:timers",
853
+ "node:timers/promises",
854
+ "node:tls",
855
+ "node:trace_events",
856
+ "node:tty",
857
+ "node:url",
858
+ "node:util",
859
+ "node:util/types",
860
+ "node:v8",
861
+ "node:vm",
862
+ "node:wasi",
863
+ "node:worker_threads",
864
+ "node:zlib"
865
+ ];
866
+
867
+ //#endregion
868
+ //#region src/presets/deno/unenv/preset.ts
869
+ const unenvDeno = {
870
+ meta: { name: "nitro:deno" },
871
+ external: builtnNodeModules.map((m) => `node:${m}`),
872
+ alias: { ...Object.fromEntries(builtnNodeModules.flatMap((m) => [[m, m], [m.replace("node:", ""), m]])) },
873
+ inject: {
874
+ global: "unenv/polyfill/globalthis",
875
+ process: "node:process",
876
+ clearImmediate: ["node:timers", "clearImmediate"],
877
+ setImmediate: ["node:timers", "setImmediate"],
878
+ Buffer: ["node:buffer", "Buffer"]
879
+ }
880
+ };
881
+
882
+ //#endregion
883
+ //#region src/presets/deno/preset.ts
884
+ const denoDeploy = defineNitroPreset({
885
+ entry: "./deno/runtime/deno-deploy",
886
+ manifest: { deploymentId: process.env.DENO_DEPLOYMENT_ID },
887
+ exportConditions: ["deno"],
888
+ node: false,
889
+ serveStatic: "deno",
890
+ commands: {
891
+ preview: "",
892
+ deploy: "cd ./ && deployctl deploy --project=<project_name> server/index.ts"
893
+ },
894
+ unenv: unenvDeno,
895
+ rollupConfig: {
896
+ preserveEntrySignatures: false,
897
+ external: (id) => id.startsWith("https://") || id.startsWith("node:"),
898
+ output: {
899
+ entryFileNames: "index.ts",
900
+ manualChunks: (id) => "index",
901
+ format: "esm"
902
+ }
903
+ }
904
+ }, { name: "deno-deploy" });
905
+ const denoServer = defineNitroPreset({
906
+ entry: "./deno/runtime/deno-server",
907
+ serveStatic: true,
908
+ exportConditions: ["deno"],
909
+ commands: { preview: "deno -A ./server/index.mjs" },
910
+ rollupConfig: {
911
+ external: (id) => id.startsWith("https://") || id.startsWith("node:") || builtinModules.includes(id),
912
+ output: { hoistTransitiveImports: false }
913
+ },
914
+ hooks: { async compiled(nitro) {
915
+ await writeFile$1(resolve$1(nitro.options.output.dir, "deno.json"), JSON.stringify({ tasks: { start: "deno run -A ./server/index.mjs" } }, null, 2));
916
+ } }
917
+ }, {
918
+ aliases: ["deno"],
919
+ name: "deno-server"
920
+ });
921
+ var preset_default$17 = [denoDeploy, denoServer];
922
+
923
+ //#endregion
924
+ //#region src/presets/digitalocean/preset.ts
925
+ const digitalOcean = defineNitroPreset({
926
+ extends: "node-server",
927
+ serveStatic: true
928
+ }, { name: "digital-ocean" });
929
+ var preset_default$16 = [digitalOcean];
930
+
931
+ //#endregion
932
+ //#region src/presets/firebase/preset.ts
933
+ const firebaseAppHosting = defineNitroPreset({
934
+ extends: "node-server",
935
+ serveStatic: true,
936
+ hooks: { async compiled(nitro) {
937
+ const serverEntry = join$1(nitro.options.output.serverDir, "index.mjs");
938
+ await writeFile$1(join$1(nitro.options.rootDir, ".apphosting/bundle.yaml"), gr({
939
+ version: "v1",
940
+ runConfig: {
941
+ runCommand: `node ${relative$1(nitro.options.rootDir, serverEntry)}`,
942
+ ...nitro.options.firebase?.appHosting
943
+ },
944
+ metadata: {
945
+ framework: nitro.options.framework.name || "nitro",
946
+ frameworkVersion: nitro.options.framework.version || "2.x",
947
+ adapterPackageName: "nitro",
948
+ adapterVersion: version
949
+ },
950
+ outputFiles: { serverApp: { include: [relative$1(nitro.options.rootDir, nitro.options.output.dir)] } }
951
+ }), true);
952
+ } }
953
+ }, {
954
+ name: "firebase-app-hosting",
955
+ stdName: "firebase_app_hosting"
956
+ });
957
+ var preset_default$15 = [firebaseAppHosting];
958
+
959
+ //#endregion
960
+ //#region src/presets/flightcontrol/preset.ts
961
+ const flightControl = defineNitroPreset({
962
+ extends: "node-server",
963
+ serveStatic: true
964
+ }, { name: "flight-control" });
965
+ var preset_default$14 = [flightControl];
966
+
967
+ //#endregion
968
+ //#region src/presets/genezio/preset.ts
969
+ const genezio = defineNitroPreset({ extends: "aws_lambda" }, { name: "genezio" });
970
+ var preset_default$13 = [genezio];
971
+
972
+ //#endregion
973
+ //#region src/presets/heroku/preset.ts
974
+ const heroku = defineNitroPreset({
975
+ extends: "node-server",
976
+ serveStatic: true
977
+ }, { name: "heroku" });
978
+ var preset_default$12 = [heroku];
979
+
980
+ //#endregion
981
+ //#region src/presets/iis/utils.ts
982
+ async function writeIISFiles(nitro) {
983
+ await writeFile$1(resolve$1(nitro.options.output.dir, "web.config"), await iisXmlTemplate(nitro));
984
+ }
985
+ async function writeIISNodeFiles(nitro) {
986
+ await writeFile$1(resolve$1(nitro.options.output.dir, "web.config"), await iisnodeXmlTemplate(nitro));
987
+ await writeFile$1(resolve$1(nitro.options.output.dir, "index.js"), `
988
+ if (process.env.PORT.startsWith('\\\\')) {
989
+ process.env.NITRO_UNIX_SOCKET = process.env.PORT
990
+ delete process.env.PORT
991
+ }
992
+ import('./server/index.mjs');
993
+ `);
994
+ }
995
+ async function iisnodeXmlTemplate(nitro) {
996
+ const path$1 = resolve$1(nitro.options.rootDir, "web.config");
997
+ const originalString = `<?xml version="1.0" encoding="utf-8"?>
998
+ <!--
999
+ This configuration file is required if iisnode is used to run node processes behind
1000
+ IIS or IIS Express. For more information, visit:
1001
+ https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config
1002
+ -->
1003
+ <configuration>
1004
+ <system.webServer>
1005
+ <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
1006
+ <webSocket enabled="false" />
1007
+ <handlers>
1008
+ <!-- Indicates that the index.js file is a Node.js site to be handled by the iisnode module -->
1009
+ <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
1010
+ </handlers>
1011
+ <rewrite>
1012
+ <rules>
1013
+ <!-- Do not interfere with requests for node-inspector debugging -->
1014
+ <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
1015
+ <match url="^index.js/debug[/]?" />
1016
+ </rule>
1017
+
1018
+ <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
1019
+ <rule name="StaticContent">
1020
+ <action type="Rewrite" url="public{PATH_INFO}" />
1021
+ </rule>
1022
+
1023
+ <!-- All other URLs are mapped to the Node.js site entrypoint -->
1024
+ <rule name="DynamicContent">
1025
+ <conditions>
1026
+ <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
1027
+ </conditions>
1028
+ <action type="Rewrite" url="index.js" />
1029
+ </rule>
1030
+ </rules>
1031
+ </rewrite>
1032
+
1033
+ <!-- 'bin' directory has no special meaning in Node.js and apps can be placed in it -->
1034
+ <security>
1035
+ <requestFiltering>
1036
+ <hiddenSegments>
1037
+ <remove segment="bin" />
1038
+ </hiddenSegments>
1039
+ <requestLimits maxAllowedContentLength="4294967295" />
1040
+ </requestFiltering>
1041
+ </security>
1042
+
1043
+ <!-- Make sure error responses are left untouched -->
1044
+ <httpErrors existingResponse="PassThrough" />
1045
+
1046
+ <!--
1047
+ You can control how Node is hosted within IIS using the following options:
1048
+ * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
1049
+ * node_env: will be propagated to node as NODE_ENV environment variable
1050
+ * debuggingEnabled - controls whether the built-in debugger is enabled
1051
+ See https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
1052
+ -->
1053
+ <iisnode
1054
+ watchedFiles="index.js"
1055
+ node_env="production"
1056
+ debuggingEnabled="false"
1057
+ loggingEnabled="false"
1058
+ />
1059
+ </system.webServer>
1060
+ </configuration>
1061
+ `;
1062
+ if (existsSync(path$1)) {
1063
+ const fileString = await readFile(path$1, "utf8");
1064
+ const originalWebConfig = await parseXmlDoc(originalString);
1065
+ const fileWebConfig = await parseXmlDoc(fileString);
1066
+ if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig));
1067
+ if (nitro.options.iis?.overrideConfig) return buildNewXmlDoc({ ...fileWebConfig });
1068
+ }
1069
+ return originalString;
1070
+ }
1071
+ async function iisXmlTemplate(nitro) {
1072
+ const path$1 = resolve$1(nitro.options.rootDir, "web.config");
1073
+ const originalString = `<?xml version="1.0" encoding="UTF-8"?>
1074
+ <configuration>
1075
+ <system.webServer>
1076
+ <handlers>
1077
+ <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
1078
+ </handlers>
1079
+ <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\\logs\\node.log" startupTimeLimit="20" processPath="C:\\Program Files\\nodejs\\node.exe" arguments=".\\server\\index.mjs">
1080
+ <environmentVariables>
1081
+ <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
1082
+ <environmentVariable name="NODE_ENV" value="Production" />
1083
+ </environmentVariables>
1084
+ </httpPlatform>
1085
+ </system.webServer>
1086
+ </configuration>
1087
+ `;
1088
+ if (existsSync(path$1)) {
1089
+ const fileString = await readFile(path$1, "utf8");
1090
+ const originalWebConfig = await parseXmlDoc(originalString);
1091
+ const fileWebConfig = await parseXmlDoc(fileString);
1092
+ if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig));
1093
+ if (nitro.options.iis?.overrideConfig) return buildNewXmlDoc({ ...fileWebConfig });
1094
+ }
1095
+ return originalString;
1096
+ }
1097
+ async function parseXmlDoc(xml) {
1098
+ const { Parser } = await import("xml2js");
1099
+ if (xml === void 0 || !xml) return {};
1100
+ const parser = new Parser({ explicitArray: false });
1101
+ let parsedRecord = {};
1102
+ parser.parseString(xml, (_, r) => {
1103
+ parsedRecord = r;
1104
+ });
1105
+ return parsedRecord;
1106
+ }
1107
+ async function buildNewXmlDoc(xmlObj) {
1108
+ const { Builder } = await import("xml2js");
1109
+ return new Builder().buildObject({ ...xmlObj });
1110
+ }
1111
+
1112
+ //#endregion
1113
+ //#region src/presets/iis/preset.ts
1114
+ const iisHandler = defineNitroPreset({
1115
+ extends: "node-server",
1116
+ serveStatic: true,
1117
+ hooks: { async compiled(nitro) {
1118
+ await writeIISFiles(nitro);
1119
+ } }
1120
+ }, { name: "iis-handler" });
1121
+ const iisNode = defineNitroPreset({
1122
+ extends: "node-server",
1123
+ serveStatic: true,
1124
+ hooks: { async compiled(nitro) {
1125
+ await writeIISNodeFiles(nitro);
1126
+ } }
1127
+ }, { name: "iis-node" });
1128
+ var preset_default$11 = [iisHandler, iisNode];
1129
+
1130
+ //#endregion
1131
+ //#region src/presets/koyeb/preset.ts
1132
+ const koyeb = defineNitroPreset({
1133
+ extends: "node-server",
1134
+ serveStatic: true
1135
+ }, { name: "koyeb" });
1136
+ var preset_default$10 = [koyeb];
1137
+
1138
+ //#endregion
1139
+ //#region src/presets/netlify/utils.ts
1140
+ async function writeRedirects(nitro) {
1141
+ const redirectsPath = join$1(nitro.options.output.publicDir, "_redirects");
1142
+ let contents = "";
1143
+ if (nitro.options.static) {
1144
+ const staticFallback = existsSync(join$1(nitro.options.output.publicDir, "404.html")) ? "/* /404.html 404" : "";
1145
+ contents += staticFallback;
1146
+ }
1147
+ const rules = Object.entries(nitro.options.routeRules).sort((a$1, b) => a$1[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length);
1148
+ for (const [key, routeRules] of rules.filter(([_, routeRules$1]) => routeRules$1.redirect)) {
1149
+ let code = routeRules.redirect.status;
1150
+ if (code === 307) code = 302;
1151
+ if (code === 308) code = 301;
1152
+ contents = `${key.replace("/**", "/*")}\t${routeRules.redirect.to.replace("/**", "/:splat")}\t${code}\n` + contents;
1153
+ }
1154
+ if (existsSync(redirectsPath)) {
1155
+ const currentRedirects = await promises.readFile(redirectsPath, "utf8");
1156
+ if (/^\/\* /m.test(currentRedirects)) {
1157
+ nitro.logger.info("Not adding Nitro fallback to `_redirects` (as an existing fallback was found).");
1158
+ return;
1159
+ }
1160
+ nitro.logger.info("Adding Nitro fallback to `_redirects` to handle all unmatched routes.");
1161
+ contents = currentRedirects + "\n" + contents;
1162
+ }
1163
+ await promises.writeFile(redirectsPath, contents);
1164
+ }
1165
+ async function writeHeaders(nitro) {
1166
+ const headersPath = join$1(nitro.options.output.publicDir, "_headers");
1167
+ let contents = "";
1168
+ const rules = Object.entries(nitro.options.routeRules).sort((a$1, b) => b[0].split(/\/(?!\*)/).length - a$1[0].split(/\/(?!\*)/).length);
1169
+ for (const [path$1, routeRules] of rules.filter(([_, routeRules$1]) => routeRules$1.headers)) {
1170
+ const headers = [path$1.replace("/**", "/*"), ...Object.entries({ ...routeRules.headers }).map(([header, value]) => ` ${header}: ${value}`)].join("\n");
1171
+ contents += headers + "\n";
1172
+ }
1173
+ if (existsSync(headersPath)) {
1174
+ const currentHeaders = await promises.readFile(headersPath, "utf8");
1175
+ if (/^\/\* /m.test(currentHeaders)) {
1176
+ nitro.logger.info("Not adding Nitro fallback to `_headers` (as an existing fallback was found).");
1177
+ return;
1178
+ }
1179
+ nitro.logger.info("Adding Nitro fallback to `_headers` to handle all unmatched routes.");
1180
+ contents = currentHeaders + "\n" + contents;
1181
+ }
1182
+ await promises.writeFile(headersPath, contents);
1183
+ }
1184
+ function getStaticPaths(publicAssets, baseURL) {
1185
+ return ["/.netlify/*", ...publicAssets.filter((a$1) => a$1.fallthrough !== true && a$1.baseURL && a$1.baseURL !== "/").map((a$1) => joinURL(baseURL, a$1.baseURL, "*"))];
1186
+ }
1187
+ function generateNetlifyFunction(nitro) {
1188
+ return `
1189
+ export { default } from "./main.mjs";
1190
+ export const config = {
1191
+ name: "server handler",
1192
+ generator: "${getGeneratorString(nitro)}",
1193
+ path: "/*",
1194
+ nodeBundler: "none",
1195
+ includedFiles: ["**"],
1196
+ excludedPath: ${JSON.stringify(getStaticPaths(nitro.options.publicAssets, nitro.options.baseURL))},
1197
+ preferStatic: true,
1198
+ };
1199
+ `.trim();
1200
+ }
1201
+ function getGeneratorString(nitro) {
1202
+ return `${nitro.options.framework.name}@${nitro.options.framework.version}`;
1203
+ }
1204
+
1205
+ //#endregion
1206
+ //#region src/presets/netlify/preset.ts
1207
+ const netlify = defineNitroPreset({
1208
+ entry: "./netlify/runtime/netlify",
1209
+ manifest: { deploymentId: process.env.DEPLOY_ID },
1210
+ output: {
1211
+ dir: "{{ rootDir }}/.netlify/functions-internal",
1212
+ publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
1213
+ },
1214
+ prerender: { autoSubfolderIndex: false },
1215
+ rollupConfig: { output: { entryFileNames: "main.mjs" } },
1216
+ hooks: { async compiled(nitro) {
1217
+ await writeHeaders(nitro);
1218
+ await writeRedirects(nitro);
1219
+ await promises.writeFile(join$1(nitro.options.output.dir, "server", "server.mjs"), generateNetlifyFunction(nitro));
1220
+ if (nitro.options.netlify?.images) {
1221
+ nitro.options.netlify.config ||= {};
1222
+ nitro.options.netlify.config.images ||= nitro.options.netlify?.images;
1223
+ }
1224
+ if (Object.keys(nitro.options.netlify?.config || {}).length > 0) {
1225
+ const configPath = join$1(nitro.options.output.dir, "../deploy/v1/config.json");
1226
+ await promises.mkdir(dirname$1(configPath), { recursive: true });
1227
+ await promises.writeFile(configPath, JSON.stringify(nitro.options.netlify?.config), "utf8");
1228
+ }
1229
+ } }
1230
+ }, {
1231
+ name: "netlify",
1232
+ stdName: "netlify"
1233
+ });
1234
+ const netlifyEdge = defineNitroPreset({
1235
+ extends: "base-worker",
1236
+ entry: "./netlify/runtime/netlify-edge",
1237
+ manifest: { deploymentId: process.env.DEPLOY_ID },
1238
+ exportConditions: ["netlify"],
1239
+ output: {
1240
+ serverDir: "{{ rootDir }}/.netlify/edge-functions/server",
1241
+ publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
1242
+ },
1243
+ prerender: { autoSubfolderIndex: false },
1244
+ rollupConfig: { output: {
1245
+ entryFileNames: "server.js",
1246
+ format: "esm"
1247
+ } },
1248
+ unenv: unenvDeno,
1249
+ hooks: { async compiled(nitro) {
1250
+ await writeHeaders(nitro);
1251
+ await writeRedirects(nitro);
1252
+ const manifest = {
1253
+ version: 1,
1254
+ functions: [{
1255
+ path: "/*",
1256
+ excludedPath: getStaticPaths(nitro.options.publicAssets, nitro.options.baseURL),
1257
+ name: "edge server handler",
1258
+ function: "server",
1259
+ generator: getGeneratorString(nitro)
1260
+ }]
1261
+ };
1262
+ const manifestPath = join$1(nitro.options.rootDir, ".netlify/edge-functions/manifest.json");
1263
+ await promises.mkdir(dirname$1(manifestPath), { recursive: true });
1264
+ await promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
1265
+ } }
1266
+ }, { name: "netlify-edge" });
1267
+ const netlifyStatic = defineNitroPreset({
1268
+ extends: "static",
1269
+ manifest: { deploymentId: process.env.DEPLOY_ID },
1270
+ output: {
1271
+ dir: "{{ rootDir }}/dist",
1272
+ publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
1273
+ },
1274
+ prerender: { autoSubfolderIndex: false },
1275
+ commands: { preview: "npx serve ./" },
1276
+ hooks: { async compiled(nitro) {
1277
+ await writeHeaders(nitro);
1278
+ await writeRedirects(nitro);
1279
+ } }
1280
+ }, {
1281
+ name: "netlify-static",
1282
+ stdName: "netlify",
1283
+ static: true
1284
+ });
1285
+ var preset_default$9 = [
1286
+ netlify,
1287
+ netlifyEdge,
1288
+ netlifyStatic
1289
+ ];
1290
+
1291
+ //#endregion
1292
+ //#region src/presets/node/cluster.ts
1293
+ const nodeCluster = defineNitroPreset({
1294
+ extends: "node-server",
1295
+ serveStatic: true,
1296
+ entry: "./node/runtime/node-cluster",
1297
+ rollupConfig: { output: { entryFileNames: "worker.mjs" } },
1298
+ hooks: { async compiled(nitro) {
1299
+ await writeFile$2(resolve$1(nitro.options.output.serverDir, "index.mjs"), nodeClusterEntry());
1300
+ } }
1301
+ }, { name: "node-cluster" });
1302
+ function nodeClusterEntry() {
1303
+ return `
1304
+ import cluster from "node:cluster";
1305
+ import os from "node:os";
1306
+
1307
+ if (cluster.isPrimary) {
1308
+ const numberOfWorkers =
1309
+ Number.parseInt(process.env.NITRO_CLUSTER_WORKERS || "") ||
1310
+ (os.cpus().length > 0 ? os.cpus().length : 1);
1311
+ for (let i = 0; i < numberOfWorkers; i++) {
1312
+ cluster.fork({
1313
+ WORKER_ID: i + 1,
1314
+ });
1315
+ }
1316
+ } else {
1317
+ import("./worker.mjs").catch((error) => {
1318
+ console.error(error);
1319
+ process.exit(1);
1320
+ });
1321
+ }
1322
+ `;
1323
+ }
1324
+
1325
+ //#endregion
1326
+ //#region src/presets/node/preset.ts
1327
+ const nodeServer = defineNitroPreset({
1328
+ entry: "./node/runtime/node-server",
1329
+ serveStatic: true,
1330
+ commands: { preview: "node ./server/index.mjs" }
1331
+ }, {
1332
+ name: "node-server",
1333
+ aliases: ["node"]
1334
+ });
1335
+ const nodeMiddleware = defineNitroPreset({ entry: "./node/runtime/node-middleware" }, { name: "node-middleware" });
1336
+ var preset_default$8 = [
1337
+ nodeServer,
1338
+ nodeCluster,
1339
+ nodeMiddleware
1340
+ ];
1341
+
1342
+ //#endregion
1343
+ //#region src/presets/platform.sh/preset.ts
1344
+ const platformSh = defineNitroPreset({
1345
+ extends: "node-server",
1346
+ serveStatic: true
1347
+ }, { name: "platform-sh" });
1348
+ var preset_default$7 = [platformSh];
1349
+
1350
+ //#endregion
1351
+ //#region src/presets/render.com/preset.ts
1352
+ const renderCom = defineNitroPreset({
1353
+ extends: "node-server",
1354
+ serveStatic: true
1355
+ }, { name: "render-com" });
1356
+ var preset_default$6 = [renderCom];
1357
+
1358
+ //#endregion
1359
+ //#region src/presets/standard/preset.ts
1360
+ const standard = defineNitroPreset({
1361
+ entry: "./standard/runtime/server",
1362
+ serveStatic: false,
1363
+ output: { publicDir: "{{ output.dir }}/public/{{ baseURL }}" },
1364
+ commands: { preview: "npx srvx --prod ./" },
1365
+ alias: {
1366
+ srvx: "srvx/generic",
1367
+ "srvx/bun": "srvx/bun",
1368
+ "srvx/deno": "srvx/deno",
1369
+ "srvx/node": "srvx/node",
1370
+ "srvx/generic": "srvx/generic"
1371
+ }
1372
+ }, { name: "standard" });
1373
+ var preset_default$5 = [standard];
1374
+
1375
+ //#endregion
1376
+ //#region src/presets/stormkit/preset.ts
1377
+ const stormkit = defineNitroPreset({
1378
+ entry: "./stormkit/runtime/stormkit",
1379
+ output: {
1380
+ dir: "{{ rootDir }}/.stormkit",
1381
+ publicDir: "{{ rootDir }}/.stormkit/public/{{ baseURL }}"
1382
+ }
1383
+ }, {
1384
+ name: "stormkit",
1385
+ stdName: "stormkit"
1386
+ });
1387
+ var preset_default$4 = [stormkit];
1388
+
1389
+ //#endregion
1390
+ //#region src/presets/vercel/runtime/isr.ts
1391
+ const ISR_URL_PARAM = "__isr_route";
1392
+
1393
+ //#endregion
1394
+ //#region src/presets/vercel/utils.ts
1395
+ const SUPPORTED_NODE_VERSIONS = [20, 22];
1396
+ const FALLBACK_ROUTE = "/__server";
1397
+ const ISR_SUFFIX = "-isr";
1398
+ const SAFE_FS_CHAR_RE = /[^a-zA-Z0-9_.[\]/]/g;
1399
+ function getSystemNodeVersion() {
1400
+ const systemNodeVersion = Number.parseInt(process.versions.node.split(".")[0]);
1401
+ return Number.isNaN(systemNodeVersion) ? 22 : systemNodeVersion;
1402
+ }
1403
+ async function generateFunctionFiles(nitro) {
1404
+ const o11Routes = getObservabilityRoutes(nitro);
1405
+ const buildConfigPath = resolve$1(nitro.options.output.dir, "config.json");
1406
+ const buildConfig = generateBuildConfig(nitro, o11Routes);
1407
+ await writeFile$1(buildConfigPath, JSON.stringify(buildConfig, null, 2));
1408
+ const functionConfigPath = resolve$1(nitro.options.output.serverDir, ".vc-config.json");
1409
+ const functionConfig = {
1410
+ handler: "index.mjs",
1411
+ launcherType: "Nodejs",
1412
+ shouldAddHelpers: false,
1413
+ supportsResponseStreaming: true,
1414
+ ...nitro.options.vercel?.functions
1415
+ };
1416
+ await writeFile$1(functionConfigPath, JSON.stringify(functionConfig, null, 2));
1417
+ for (const [key, value] of Object.entries(nitro.options.routeRules)) {
1418
+ if (!value.isr) continue;
1419
+ const funcPrefix = resolve$1(nitro.options.output.serverDir, "..", normalizeRouteDest(key) + ISR_SUFFIX);
1420
+ await fsp.mkdir(dirname$1(funcPrefix), { recursive: true });
1421
+ await fsp.symlink("./" + relative$1(dirname$1(funcPrefix), nitro.options.output.serverDir), funcPrefix + ".func", "junction");
1422
+ await writePrerenderConfig(funcPrefix + ".prerender-config.json", value.isr, nitro.options.vercel?.config?.bypassToken);
1423
+ }
1424
+ if (o11Routes.length === 0) return;
1425
+ const _getRouteRules = (path$1) => defu({}, ...nitro.routing.routeRules.matchAll("", path$1).reverse());
1426
+ for (const route of o11Routes) {
1427
+ if (_getRouteRules(route.src).isr) continue;
1428
+ const funcPrefix = resolve$1(nitro.options.output.serverDir, "..", route.dest);
1429
+ await fsp.mkdir(dirname$1(funcPrefix), { recursive: true });
1430
+ await fsp.symlink("./" + relative$1(dirname$1(funcPrefix), nitro.options.output.serverDir), funcPrefix + ".func", "junction");
1431
+ }
1432
+ }
1433
+ async function generateStaticFiles(nitro) {
1434
+ const buildConfigPath = resolve$1(nitro.options.output.dir, "config.json");
1435
+ const buildConfig = generateBuildConfig(nitro);
1436
+ await writeFile$1(buildConfigPath, JSON.stringify(buildConfig, null, 2));
1437
+ }
1438
+ function generateBuildConfig(nitro, o11Routes) {
1439
+ const rules = Object.entries(nitro.options.routeRules).sort((a$1, b) => b[0].split(/\/(?!\*)/).length - a$1[0].split(/\/(?!\*)/).length);
1440
+ const config = defu(nitro.options.vercel?.config, {
1441
+ version: 3,
1442
+ overrides: { ...Object.fromEntries((nitro._prerenderedRoutes?.filter((r) => r.fileName !== r.route) || []).map(({ route, fileName }) => [withoutLeadingSlash(fileName), { path: route.replace(/^\//, "") }])) },
1443
+ routes: [
1444
+ ...rules.filter(([_, routeRules]) => routeRules.redirect || routeRules.headers).map(([path$1, routeRules]) => {
1445
+ let route = { src: path$1.replace("/**", "/(.*)") };
1446
+ if (routeRules.redirect) route = defu(route, {
1447
+ status: routeRules.redirect.status,
1448
+ headers: { Location: routeRules.redirect.to.replace("/**", "/$1") }
1449
+ });
1450
+ if (routeRules.headers) route = defu(route, { headers: routeRules.headers });
1451
+ return route;
1452
+ }),
1453
+ ...nitro.options.vercel?.skewProtection && nitro.options.manifest?.deploymentId ? [{
1454
+ src: "/.*",
1455
+ has: [{
1456
+ type: "header",
1457
+ key: "Sec-Fetch-Dest",
1458
+ value: "document"
1459
+ }],
1460
+ headers: { "Set-Cookie": `__vdpl=${nitro.options.manifest.deploymentId}; Path=${nitro.options.baseURL}; SameSite=Strict; Secure; HttpOnly` },
1461
+ continue: true
1462
+ }] : [],
1463
+ ...nitro.options.publicAssets.filter((asset) => !asset.fallthrough).map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/")).map((baseURL) => ({
1464
+ src: baseURL + "(.*)",
1465
+ headers: { "cache-control": "public,max-age=31536000,immutable" },
1466
+ continue: true
1467
+ })),
1468
+ { handle: "filesystem" }
1469
+ ]
1470
+ });
1471
+ if (nitro.options.static) return config;
1472
+ config.routes.push(...nitro.options.routeRules["/"]?.isr ? [{
1473
+ src: `(?<${ISR_URL_PARAM}>/)`,
1474
+ dest: `/index${ISR_SUFFIX}?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`
1475
+ }] : [], ...rules.filter(([key, value]) => value.isr !== void 0 && key !== "/").map(([key, value]) => {
1476
+ const src = `(?<${ISR_URL_PARAM}>${normalizeRouteSrc(key)})`;
1477
+ if (value.isr === false) return {
1478
+ src,
1479
+ dest: FALLBACK_ROUTE
1480
+ };
1481
+ return {
1482
+ src,
1483
+ dest: withLeadingSlash(normalizeRouteDest(key) + ISR_SUFFIX + `?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`)
1484
+ };
1485
+ }), ...(o11Routes || []).map((route) => ({
1486
+ src: joinURL(nitro.options.baseURL, route.src),
1487
+ dest: withLeadingSlash(route.dest)
1488
+ })), ...nitro.options.routeRules["/**"]?.isr ? [] : [{
1489
+ src: "/(.*)",
1490
+ dest: FALLBACK_ROUTE
1491
+ }]);
1492
+ return config;
1493
+ }
1494
+ function deprecateSWR(nitro) {
1495
+ if (nitro.options.future.nativeSWR) return;
1496
+ let hasLegacyOptions = false;
1497
+ for (const [_key, value] of Object.entries(nitro.options.routeRules)) {
1498
+ if (_hasProp(value, "isr")) continue;
1499
+ if (value.cache === false) value.isr = false;
1500
+ if (_hasProp(value, "static")) {
1501
+ value.isr = !value.static;
1502
+ hasLegacyOptions = true;
1503
+ }
1504
+ if (value.cache && _hasProp(value.cache, "swr")) {
1505
+ value.isr = value.cache.swr;
1506
+ hasLegacyOptions = true;
1507
+ }
1508
+ }
1509
+ if (hasLegacyOptions && !a) nitro.logger.warn("Nitro now uses `isr` option to configure ISR behavior on Vercel. Backwards-compatible support for `static` and `swr` options within the Vercel Build Options API will be removed in the future versions. Set `future.nativeSWR: true` nitro config disable this warning.");
1510
+ }
1511
+ async function resolveVercelRuntime(nitro) {
1512
+ let runtime = nitro.options.vercel?.functions?.runtime;
1513
+ if (runtime) return runtime;
1514
+ if ((await readVercelConfig(nitro.options.rootDir)).bunVersion || "Bun" in globalThis) runtime = "bun1.x";
1515
+ else {
1516
+ const systemNodeVersion = getSystemNodeVersion();
1517
+ runtime = `nodejs${SUPPORTED_NODE_VERSIONS.find((version$1) => version$1 >= systemNodeVersion) ?? SUPPORTED_NODE_VERSIONS.at(-1)}.x`;
1518
+ }
1519
+ nitro.options.vercel ??= {};
1520
+ nitro.options.vercel.functions ??= {};
1521
+ nitro.options.vercel.functions.runtime = runtime;
1522
+ return runtime;
1523
+ }
1524
+ async function readVercelConfig(rootDir) {
1525
+ const vercelConfigPath = resolve$1(rootDir, "vercel.json");
1526
+ return await fsp.readFile(vercelConfigPath).then((config) => JSON.parse(config.toString())).catch(() => ({}));
1527
+ }
1528
+ function _hasProp(obj, prop) {
1529
+ return obj && typeof obj === "object" && prop in obj;
1530
+ }
1531
+ function getObservabilityRoutes(nitro) {
1532
+ if ((nitro.options.compatibilityDate.vercel || nitro.options.compatibilityDate.default) < "2025-07-15") return [];
1533
+ const routePatterns = [...new Set([...nitro.options.ssrRoutes || [], ...[...nitro.scannedHandlers, ...nitro.options.handlers].filter((h$1) => !h$1.middleware && h$1.route).map((h$1) => h$1.route)])];
1534
+ const staticRoutes = [];
1535
+ const dynamicRoutes = [];
1536
+ const catchAllRoutes = [];
1537
+ for (const route of routePatterns) if (route.includes("**")) catchAllRoutes.push(route);
1538
+ else if (route.includes(":") || route.includes("*")) dynamicRoutes.push(route);
1539
+ else staticRoutes.push(route);
1540
+ return [
1541
+ ...normalizeRoutes(staticRoutes),
1542
+ ...normalizeRoutes(dynamicRoutes),
1543
+ ...normalizeRoutes(catchAllRoutes)
1544
+ ];
1545
+ }
1546
+ function normalizeRoutes(routes) {
1547
+ return routes.sort((a$1, b) => b.localeCompare(a$1)).map((route) => ({
1548
+ src: normalizeRouteSrc(route),
1549
+ dest: normalizeRouteDest(route)
1550
+ }));
1551
+ }
1552
+ function normalizeRouteSrc(route) {
1553
+ let idCtr = 0;
1554
+ return route.split("/").map((segment) => {
1555
+ if (segment.startsWith("**")) return segment === "**" ? "(?:.*)" : `?(?<${namedGroup(segment.slice(3))}>.+)`;
1556
+ if (segment === "*") return `(?<_${idCtr++}>[^/]*)`;
1557
+ if (segment.includes(":")) return segment.replace(/:(\w+)/g, (_, id) => `(?<${namedGroup(id)}>[^/]+)`).replace(/\./g, String.raw`\.`);
1558
+ return segment;
1559
+ }).join("/");
1560
+ }
1561
+ function namedGroup(input = "") {
1562
+ if (/\d/.test(input[0])) input = `_${input}`;
1563
+ return input.replace(/[^a-zA-Z0-9_]/g, "") || "_";
1564
+ }
1565
+ function normalizeRouteDest(route) {
1566
+ return route.split("/").slice(1).map((segment) => {
1567
+ if (segment.startsWith("**")) return `[...${segment.replace(/[*:]/g, "")}]`;
1568
+ if (segment === "*") return "[-]";
1569
+ if (segment.startsWith(":")) return `[${segment.slice(1)}]`;
1570
+ if (segment.includes(":")) return `[${segment.replace(/:/g, "_")}]`;
1571
+ return segment;
1572
+ }).map((segment) => segment.replace(SAFE_FS_CHAR_RE, "-")).join("/") || "index";
1573
+ }
1574
+ async function writePrerenderConfig(filename, isrConfig, bypassToken) {
1575
+ if (typeof isrConfig === "number") isrConfig = { expiration: isrConfig };
1576
+ else if (isrConfig === true) isrConfig = { expiration: false };
1577
+ else isrConfig = { ...isrConfig };
1578
+ const prerenderConfig = {
1579
+ expiration: isrConfig.expiration ?? false,
1580
+ bypassToken,
1581
+ ...isrConfig
1582
+ };
1583
+ if (prerenderConfig.allowQuery && !prerenderConfig.allowQuery.includes(ISR_URL_PARAM)) prerenderConfig.allowQuery.push(ISR_URL_PARAM);
1584
+ await writeFile$1(filename, JSON.stringify(prerenderConfig, null, 2));
1585
+ }
1586
+
1587
+ //#endregion
1588
+ //#region src/presets/vercel/preset.ts
1589
+ const vercel = defineNitroPreset({
1590
+ entry: "./vercel/runtime/vercel.{format}",
1591
+ manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
1592
+ vercel: { skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED },
1593
+ output: {
1594
+ dir: "{{ rootDir }}/.vercel/output",
1595
+ serverDir: "{{ output.dir }}/functions/__server.func",
1596
+ publicDir: "{{ output.dir }}/static/{{ baseURL }}"
1597
+ },
1598
+ commands: {
1599
+ preview: "npx srvx --static ../../static ./functions/__server.func/index.mjs",
1600
+ deploy: "npx vercel deploy --prebuilt"
1601
+ },
1602
+ hooks: {
1603
+ "build:before": async (nitro) => {
1604
+ const logger = nitro.logger.withTag("vercel");
1605
+ const runtime = await resolveVercelRuntime(nitro);
1606
+ if (runtime.startsWith("bun") && !nitro.options.exportConditions.includes("bun")) nitro.options.exportConditions.push("bun");
1607
+ logger.info(`Using \`${runtime}\` runtime.`);
1608
+ let serverFormat = nitro.options.vercel?.entryFormat;
1609
+ if (!serverFormat) serverFormat = nitro.routing.routes.routes.flatMap((r) => r.data).some((h$1) => h$1.format === "node") ? "node" : "web";
1610
+ logger.info(`Using \`${serverFormat}\` entry format.`);
1611
+ nitro.options.entry = nitro.options.entry.replace("{format}", serverFormat);
1612
+ },
1613
+ "rollup:before": (nitro) => {
1614
+ deprecateSWR(nitro);
1615
+ },
1616
+ async compiled(nitro) {
1617
+ await generateFunctionFiles(nitro);
1618
+ }
1619
+ }
1620
+ }, {
1621
+ name: "vercel",
1622
+ stdName: "vercel"
1623
+ });
1624
+ const vercelStatic = defineNitroPreset({
1625
+ extends: "static",
1626
+ manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
1627
+ vercel: { skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED },
1628
+ output: {
1629
+ dir: "{{ rootDir }}/.vercel/output",
1630
+ publicDir: "{{ output.dir }}/static/{{ baseURL }}"
1631
+ },
1632
+ commands: { preview: "npx serve ./static" },
1633
+ hooks: {
1634
+ "rollup:before": (nitro) => {
1635
+ deprecateSWR(nitro);
1636
+ },
1637
+ async compiled(nitro) {
1638
+ await generateStaticFiles(nitro);
1639
+ }
1640
+ }
1641
+ }, {
1642
+ name: "vercel-static",
1643
+ stdName: "vercel",
1644
+ static: true
1645
+ });
1646
+ var preset_default$3 = [vercel, vercelStatic];
1647
+
1648
+ //#endregion
1649
+ //#region src/presets/winterjs/preset.ts
1650
+ const winterjs = defineNitroPreset({
1651
+ extends: "base-worker",
1652
+ entry: "./winterjs/runtime/winterjs",
1653
+ minify: false,
1654
+ serveStatic: "inline",
1655
+ wasm: { lazy: true },
1656
+ commands: { preview: "wasmer run wasmer/winterjs --forward-host-env --net --mapdir app:./ app/server/index.mjs" }
1657
+ }, { name: "winterjs" });
1658
+ var preset_default$2 = [winterjs];
1659
+
1660
+ //#endregion
1661
+ //#region src/presets/zeabur/preset.ts
1662
+ const zeabur = defineNitroPreset({
1663
+ entry: "./zeabur/runtime/zeabur",
1664
+ output: {
1665
+ dir: "{{ rootDir }}/.zeabur/output",
1666
+ serverDir: "{{ output.dir }}/functions/__nitro.func",
1667
+ publicDir: "{{ output.dir }}/static"
1668
+ },
1669
+ hooks: { async compiled(nitro) {
1670
+ await writeFile$1(resolve$1(nitro.options.output.dir, "config.json"), JSON.stringify({
1671
+ containerized: false,
1672
+ routes: [{
1673
+ src: ".*",
1674
+ dest: "/__nitro"
1675
+ }]
1676
+ }, null, 2));
1677
+ for (const [key, value] of Object.entries(nitro.options.routeRules)) {
1678
+ if (!value.isr) continue;
1679
+ const funcPrefix = resolve$1(nitro.options.output.serverDir, ".." + key);
1680
+ await fsp.mkdir(dirname$1(funcPrefix), { recursive: true });
1681
+ await fsp.symlink("./" + relative$1(dirname$1(funcPrefix), nitro.options.output.serverDir), funcPrefix + ".func", "junction");
1682
+ await writeFile$1(funcPrefix + ".prerender-config.json", JSON.stringify({ type: "Prerender" }));
1683
+ }
1684
+ } }
1685
+ }, {
1686
+ name: "zeabur",
1687
+ stdName: "zeabur"
1688
+ });
1689
+ const zeaburStatic = defineNitroPreset({
1690
+ extends: "static",
1691
+ output: {
1692
+ dir: "{{ rootDir }}/.zeabur/output",
1693
+ publicDir: "{{ output.dir }}/static"
1694
+ },
1695
+ commands: { preview: "npx serve ./static" }
1696
+ }, {
1697
+ name: "zeabur-static",
1698
+ static: true
1699
+ });
1700
+ var preset_default$1 = [zeabur, zeaburStatic];
1701
+
1702
+ //#endregion
1703
+ //#region src/presets/zerops/preset.ts
1704
+ const zerops = defineNitroPreset({
1705
+ extends: "node-server",
1706
+ serveStatic: true
1707
+ }, { name: "zerops" });
1708
+ const zeropsStatic = defineNitroPreset({
1709
+ extends: "static",
1710
+ output: {
1711
+ dir: "{{ rootDir }}/.zerops/output",
1712
+ publicDir: "{{ output.dir }}/static"
1713
+ }
1714
+ }, {
1715
+ name: "zerops-static",
1716
+ static: true
1717
+ });
1718
+ var preset_default = [zerops, zeropsStatic];
1719
+
1720
+ //#endregion
1721
+ //#region src/presets/_all.gen.ts
1722
+ var _all_gen_default = [
1723
+ ...preset_default$26,
1724
+ ...preset_default$25,
1725
+ ...preset_default$24,
1726
+ ...preset_default$23,
1727
+ ...preset_default$22,
1728
+ ...preset_default$21,
1729
+ ...preset_default$20,
1730
+ ...preset_default$19,
1731
+ ...preset_default$18,
1732
+ ...preset_default$17,
1733
+ ...preset_default$16,
1734
+ ...preset_default$15,
1735
+ ...preset_default$14,
1736
+ ...preset_default$13,
1737
+ ...preset_default$12,
1738
+ ...preset_default$11,
1739
+ ...preset_default$10,
1740
+ ...preset_default$9,
1741
+ ...preset_default$8,
1742
+ ...preset_default$7,
1743
+ ...preset_default$6,
1744
+ ...preset_default$5,
1745
+ ...preset_default$4,
1746
+ ...preset_default$3,
1747
+ ...preset_default$2,
1748
+ ...preset_default$1,
1749
+ ...preset_default
1750
+ ];
1751
+
1752
+ //#endregion
1753
+ //#region src/presets/_resolve.ts
1754
+ const _stdProviderMap = {
1755
+ aws_amplify: "aws",
1756
+ azure_static: "azure",
1757
+ cloudflare_pages: "cloudflare"
1758
+ };
1759
+ async function resolvePreset(name, opts = {}) {
1760
+ if (name === ".") return;
1761
+ const _name = kebabCase(name) || p;
1762
+ const _compatDates = opts.compatibilityDate ? resolveCompatibilityDatesFromEnv(opts.compatibilityDate) : false;
1763
+ const matches = _all_gen_default.filter((preset$1) => {
1764
+ if (![
1765
+ preset$1._meta.name,
1766
+ preset$1._meta.stdName,
1767
+ ...preset$1._meta.aliases || []
1768
+ ].filter(Boolean).includes(_name)) return false;
1769
+ if (opts.dev && !preset$1._meta.dev || !opts.dev && preset$1._meta.dev) return false;
1770
+ if (_compatDates) {
1771
+ const _date = _compatDates[_stdProviderMap[preset$1._meta.stdName]] || _compatDates[preset$1._meta.stdName] || _compatDates[preset$1._meta.name] || _compatDates.default;
1772
+ if (_date && preset$1._meta.compatibilityDate && new Date(preset$1._meta.compatibilityDate) > new Date(_date)) return false;
1773
+ }
1774
+ return true;
1775
+ }).sort((a$1, b) => {
1776
+ const aDate = new Date(a$1._meta.compatibilityDate || 0);
1777
+ return new Date(b._meta.compatibilityDate || 0) > aDate ? 1 : -1;
1778
+ });
1779
+ const preset = matches.find((p$1) => (p$1._meta.static || false) === (opts?.static || false)) || matches[0];
1780
+ if (typeof preset === "function") return preset();
1781
+ if (!name && !preset) {
1782
+ if (opts?.static) return resolvePreset("static", opts);
1783
+ return resolvePreset({
1784
+ deno: "deno",
1785
+ bun: "bun"
1786
+ }[K] || "node", opts);
1787
+ }
1788
+ if (name && !preset) {
1789
+ const options = _all_gen_default.filter((p$1) => p$1._meta.name === name || p$1._meta.stdName === name || p$1._meta.aliases?.includes(name)).sort((a$1, b) => (a$1._meta.compatibilityDate || 0) > (b._meta.compatibilityDate || 0) ? 1 : -1);
1790
+ if (options.length > 0) {
1791
+ let msg = `Preset "${name}" cannot be resolved with current compatibilityDate: ${formatCompatibilityDate(_compatDates || "")}.\n\n`;
1792
+ for (const option of options) msg += `\n- ${option._meta.name} (requires compatibilityDate >= ${option._meta.compatibilityDate})`;
1793
+ const err = new Error(msg);
1794
+ Error.captureStackTrace?.(err, resolvePreset);
1795
+ throw err;
1796
+ }
1797
+ }
1798
+ return preset;
1799
+ }
1800
+
1801
+ //#endregion
1802
+ export { resolvePreset };