nitro 3.0.1-alpha.2 → 3.0.260415-beta

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 (297) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +2 -2
  3. package/dist/THIRD-PARTY-LICENSES.md +1646 -0
  4. package/dist/_build/common.mjs +7261 -3812
  5. package/dist/_build/rolldown.mjs +32 -42
  6. package/dist/_build/rollup.mjs +28 -48
  7. package/dist/_build/vite.build.mjs +10 -10
  8. package/dist/_chunks/nitro.mjs +102 -327
  9. package/dist/_chunks/nitro2.mjs +8 -9
  10. package/dist/_chunks/nitro3.mjs +136 -0
  11. package/dist/_chunks/nitro4.mjs +127 -0
  12. package/dist/_chunks/utils.mjs +40 -29
  13. package/dist/_common.mjs +13 -25
  14. package/dist/_dev.d.mts +0 -3
  15. package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -330
  16. package/dist/_libs/_.mjs +2 -0
  17. package/dist/_libs/_2.mjs +2 -0
  18. package/dist/_libs/_3.mjs +2 -0
  19. package/dist/_libs/_4.mjs +2 -0
  20. package/dist/_libs/_5.mjs +2 -0
  21. package/dist/_libs/_6.mjs +2 -0
  22. package/dist/_libs/_7.mjs +2 -0
  23. package/dist/_libs/c12+rc9.mjs +814 -0
  24. package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +49 -40
  25. package/dist/_libs/citty.mjs +142 -41
  26. package/dist/_libs/commondir+is-reference.mjs +60 -56
  27. package/dist/_libs/compatx.d.mts +0 -2
  28. package/dist/_libs/compatx.mjs +1 -4
  29. package/dist/_libs/esbuild.d.mts +0 -1
  30. package/dist/_libs/escape-string-regexp.mjs +1 -4
  31. package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +0 -5
  32. package/dist/_libs/estree-walker.mjs +4 -92
  33. package/dist/_libs/exsolve.d.mts +1 -0
  34. package/dist/_libs/hasown+resolve+deepmerge.mjs +160 -246
  35. package/dist/_libs/httpxy.d.mts +20 -13
  36. package/dist/_libs/httpxy.mjs +519 -95
  37. package/dist/_libs/js-tokens.d.mts +1 -0
  38. package/dist/_libs/klona.mjs +1 -4
  39. package/dist/_libs/magic-string.d.mts +0 -2
  40. package/dist/_libs/mlly.d.mts +0 -2
  41. package/dist/_libs/nypm+tinyexec.mjs +822 -0
  42. package/dist/_libs/perfect-debounce.mjs +68 -0
  43. package/dist/_libs/pkg-types.d.mts +0 -3
  44. package/dist/_libs/plugin-alias.mjs +1 -5
  45. package/dist/_libs/plugin-inject.mjs +1 -7
  46. package/dist/_libs/plugin-json.mjs +1 -5
  47. package/dist/_libs/pluginutils.mjs +3 -35
  48. package/dist/_libs/readdirp+chokidar.mjs +187 -365
  49. package/dist/_libs/remapping.mjs +1 -5
  50. package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -53
  51. package/dist/_libs/rou3.d.mts +1 -4
  52. package/dist/_libs/rou3.mjs +223 -78
  53. package/dist/_libs/std-env.d.mts +8 -2
  54. package/dist/_libs/strip-literal.d.mts +1 -0
  55. package/dist/_libs/tsconfck.mjs +21 -334
  56. package/dist/_libs/ultrahtml.mjs +3 -16
  57. package/dist/_libs/unimport+unplugin.mjs +244 -388
  58. package/dist/_libs/unplugin+unimport.d.mts +5 -15
  59. package/dist/_libs/unwasm.d.mts +0 -3
  60. package/dist/_presets.mjs +576 -488
  61. package/dist/builder.d.mts +5 -25
  62. package/dist/builder.mjs +3 -8
  63. package/dist/cli/_chunks/build.mjs +22 -25
  64. package/dist/cli/_chunks/common.mjs +1 -4
  65. package/dist/cli/_chunks/deploy.mjs +37 -0
  66. package/dist/cli/_chunks/dev.mjs +6 -11
  67. package/dist/cli/_chunks/docs.mjs +28 -0
  68. package/dist/cli/_chunks/list.mjs +4 -8
  69. package/dist/cli/_chunks/prepare.mjs +2 -6
  70. package/dist/cli/_chunks/preview.mjs +48 -0
  71. package/dist/cli/_chunks/run.mjs +7 -11
  72. package/dist/cli/_chunks/task.mjs +1 -5
  73. package/dist/cli/index.mjs +5 -6
  74. package/dist/docs/0.docs/0.index/index.md +56 -0
  75. package/dist/docs/0.docs/1.quick-start.md +110 -0
  76. package/dist/docs/0.docs/10.lifecycle.md +204 -0
  77. package/dist/docs/0.docs/11.openapi.md +291 -0
  78. package/dist/docs/0.docs/12.plugins.md +164 -0
  79. package/dist/docs/0.docs/13.tasks.md +277 -0
  80. package/dist/docs/0.docs/14.websocket.md +386 -0
  81. package/dist/docs/0.docs/15.migration.md +213 -0
  82. package/dist/docs/0.docs/16.nightly.md +31 -0
  83. package/dist/docs/0.docs/2.renderer.md +322 -0
  84. package/dist/docs/0.docs/3.routing.md +711 -0
  85. package/dist/docs/0.docs/4.server-entry.md +239 -0
  86. package/dist/docs/0.docs/5.cache.md +408 -0
  87. package/dist/docs/0.docs/6.storage.md +261 -0
  88. package/dist/docs/0.docs/7.assets.md +166 -0
  89. package/dist/docs/0.docs/8.configuration.md +256 -0
  90. package/dist/docs/0.docs/9.database.md +185 -0
  91. package/dist/docs/1.deploy/0.index/index.md +64 -0
  92. package/dist/docs/1.deploy/1.runtimes/0.node.md +63 -0
  93. package/dist/docs/1.deploy/1.runtimes/1.bun.md +15 -0
  94. package/dist/docs/1.deploy/1.runtimes/2.deno.md +19 -0
  95. package/dist/docs/1.deploy/2.providers/0.alwaysdata.md +50 -0
  96. package/dist/docs/1.deploy/2.providers/1.aws.md +47 -0
  97. package/dist/docs/1.deploy/2.providers/10.flightcontrol.md +67 -0
  98. package/dist/docs/1.deploy/2.providers/11.genezio.md +67 -0
  99. package/dist/docs/1.deploy/2.providers/12.github-pages.md +68 -0
  100. package/dist/docs/1.deploy/2.providers/13.gitlab-pages.md +37 -0
  101. package/dist/docs/1.deploy/2.providers/14.heroku.md +84 -0
  102. package/dist/docs/1.deploy/2.providers/15.iis.md +38 -0
  103. package/dist/docs/1.deploy/2.providers/16.koyeb.md +109 -0
  104. package/dist/docs/1.deploy/2.providers/17.netlify.md +47 -0
  105. package/dist/docs/1.deploy/2.providers/18.platform-sh.md +37 -0
  106. package/dist/docs/1.deploy/2.providers/19.render.md +37 -0
  107. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +81 -0
  108. package/dist/docs/1.deploy/2.providers/20.stormkit.md +24 -0
  109. package/dist/docs/1.deploy/2.providers/21.vercel.md +270 -0
  110. package/dist/docs/1.deploy/2.providers/22.zeabur.md +19 -0
  111. package/dist/docs/1.deploy/2.providers/23.zephyr.md +99 -0
  112. package/dist/docs/1.deploy/2.providers/24.zerops.md +102 -0
  113. package/dist/docs/1.deploy/2.providers/3.azure.md +72 -0
  114. package/dist/docs/1.deploy/2.providers/4.cleavr.md +33 -0
  115. package/dist/docs/1.deploy/2.providers/5.cloudflare.md +369 -0
  116. package/dist/docs/1.deploy/2.providers/6.deno-deploy.md +66 -0
  117. package/dist/docs/1.deploy/2.providers/7.digitalocean.md +46 -0
  118. package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
  119. package/dist/docs/1.deploy/2.providers/9.firebase.md +32 -0
  120. package/dist/docs/2.config/0.index/index.md +1221 -0
  121. package/dist/docs/3.examples/0.index/index.md +3 -0
  122. package/dist/docs/3.examples/1.api-routes.md +145 -0
  123. package/dist/docs/3.examples/10.hono.md +74 -0
  124. package/dist/docs/3.examples/11.import-alias.md +97 -0
  125. package/dist/docs/3.examples/12.middleware.md +91 -0
  126. package/dist/docs/3.examples/13.mono-jsx.md +68 -0
  127. package/dist/docs/3.examples/14.nano-jsx.md +70 -0
  128. package/dist/docs/3.examples/15.plugins.md +91 -0
  129. package/dist/docs/3.examples/16.renderer.md +113 -0
  130. package/dist/docs/3.examples/17.runtime-config.md +97 -0
  131. package/dist/docs/3.examples/18.server-fetch.md +87 -0
  132. package/dist/docs/3.examples/19.shiki.md +198 -0
  133. package/dist/docs/3.examples/2.auto-imports.md +92 -0
  134. package/dist/docs/3.examples/20.virtual-routes.md +74 -0
  135. package/dist/docs/3.examples/21.vite-nitro-plugin.md +79 -0
  136. package/dist/docs/3.examples/22.vite-rsc.md +1041 -0
  137. package/dist/docs/3.examples/23.vite-ssr-html.md +217 -0
  138. package/dist/docs/3.examples/24.vite-ssr-preact.md +247 -0
  139. package/dist/docs/3.examples/25.vite-ssr-react.md +226 -0
  140. package/dist/docs/3.examples/26.vite-ssr-solid.md +256 -0
  141. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +442 -0
  142. package/dist/docs/3.examples/28.vite-ssr-tss-react.md +444 -0
  143. package/dist/docs/3.examples/29.vite-ssr-vue-router.md +617 -0
  144. package/dist/docs/3.examples/3.cached-handler.md +81 -0
  145. package/dist/docs/3.examples/30.vite-trpc.md +335 -0
  146. package/dist/docs/3.examples/31.websocket.md +282 -0
  147. package/dist/docs/3.examples/4.custom-error-handler.md +98 -0
  148. package/dist/docs/3.examples/5.database.md +157 -0
  149. package/dist/docs/3.examples/6.elysia.md +70 -0
  150. package/dist/docs/3.examples/7.express.md +78 -0
  151. package/dist/docs/3.examples/8.fastify.md +79 -0
  152. package/dist/docs/3.examples/9.hello-world.md +68 -0
  153. package/dist/docs/README.md +86 -0
  154. package/dist/docs/index.md +121 -0
  155. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
  156. package/dist/node_modules/@poppinss/dumper/package.json +1 -1
  157. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
  158. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  159. package/dist/node_modules/@speed-highlight/core/package.json +1 -1
  160. package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
  161. package/dist/node_modules/cookie-es/package.json +26 -23
  162. package/dist/node_modules/croner/dist/croner.js +1 -1
  163. package/dist/node_modules/croner/package.json +11 -1
  164. package/dist/node_modules/defu/dist/defu.mjs +2 -2
  165. package/dist/node_modules/defu/package.json +33 -28
  166. package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
  167. package/dist/node_modules/rendu/dist/index.mjs +5 -112
  168. package/dist/node_modules/rendu/package.json +25 -24
  169. package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
  170. package/dist/node_modules/youch/build/index.js +204 -351
  171. package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
  172. package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
  173. package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
  174. package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
  175. package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
  176. package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
  177. package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
  178. package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
  179. package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
  180. package/dist/node_modules/youch/package.json +35 -32
  181. package/dist/presets/_nitro/runtime/nitro-dev.mjs +12 -57
  182. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
  183. package/dist/presets/_nitro/runtime/service-worker.mjs +1 -2
  184. package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
  185. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
  186. package/dist/presets/azure/runtime/_utils.mjs +5 -5
  187. package/dist/presets/azure/runtime/azure-swa.mjs +5 -5
  188. package/dist/presets/bun/runtime/bun.mjs +9 -6
  189. package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
  190. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
  191. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
  192. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
  193. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
  194. package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
  195. package/dist/presets/deno/runtime/deno-server.mjs +9 -6
  196. package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
  197. package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -3
  198. package/dist/presets/netlify/runtime/netlify.mjs +1 -1
  199. package/dist/presets/node/runtime/node-cluster.mjs +5 -4
  200. package/dist/presets/node/runtime/node-middleware.mjs +1 -1
  201. package/dist/presets/node/runtime/node-server.mjs +8 -5
  202. package/dist/presets/stormkit/runtime/stormkit.mjs +1 -2
  203. package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
  204. package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
  205. package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
  206. package/dist/presets/vercel/runtime/vercel.web.mjs +3 -5
  207. package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
  208. package/dist/presets/zephyr/runtime/server.mjs +3 -0
  209. package/dist/runtime/internal/app.mjs +12 -11
  210. package/dist/runtime/internal/cache.d.mts +0 -4
  211. package/dist/runtime/internal/cache.mjs +32 -256
  212. package/dist/runtime/internal/context.d.mts +3 -1
  213. package/dist/runtime/internal/context.mjs +1 -9
  214. package/dist/runtime/internal/error/dev.d.mts +5 -4
  215. package/dist/runtime/internal/error/dev.mjs +47 -49
  216. package/dist/runtime/internal/error/hooks.d.mts +1 -1
  217. package/dist/runtime/internal/error/prod.d.mts +2 -5
  218. package/dist/runtime/internal/error/prod.mjs +19 -33
  219. package/dist/runtime/internal/error/utils.d.mts +4 -4
  220. package/dist/runtime/internal/meta.d.mts +1 -1
  221. package/dist/runtime/internal/plugin.d.mts +2 -2
  222. package/dist/runtime/internal/route-rules.d.mts +11 -4
  223. package/dist/runtime/internal/route-rules.mjs +15 -5
  224. package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
  225. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -10
  226. package/dist/runtime/internal/routes/openapi.mjs +2 -2
  227. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  228. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
  229. package/dist/runtime/internal/routes/scalar.mjs +3 -3
  230. package/dist/runtime/internal/routes/swagger.mjs +7 -4
  231. package/dist/runtime/internal/runtime-config.d.mts +1 -1
  232. package/dist/runtime/internal/runtime-config.mjs +2 -2
  233. package/dist/runtime/internal/static.mjs +5 -4
  234. package/dist/runtime/internal/task.d.mts +3 -1
  235. package/dist/runtime/internal/task.mjs +7 -7
  236. package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
  237. package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
  238. package/dist/runtime/meta.d.mts +1 -0
  239. package/dist/runtime/meta.mjs +2 -0
  240. package/dist/runtime/nitro.d.mts +2 -0
  241. package/dist/runtime/nitro.mjs +4 -2
  242. package/dist/runtime/virtual/error-handler.mjs +1 -1
  243. package/dist/runtime/virtual/renderer-template.mjs +1 -1
  244. package/dist/runtime/virtual/server-assets.d.mts +2 -1
  245. package/dist/runtime/virtual/tracing.d.mts +5 -0
  246. package/dist/runtime/virtual/tracing.mjs +1 -0
  247. package/dist/runtime/vite.d.mts +1 -1
  248. package/dist/types/index.d.mts +215 -195
  249. package/dist/types/index.mjs +1 -11
  250. package/dist/vite.d.mts +3 -8
  251. package/dist/vite.mjs +285 -253
  252. package/lib/tsconfig.json +3 -5
  253. package/package.json +97 -80
  254. package/dist/_libs/confbox.mjs +0 -2509
  255. package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
  256. package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
  257. package/dist/node_modules/hookable/dist/index.mjs +0 -266
  258. package/dist/node_modules/hookable/package.json +0 -52
  259. package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
  260. package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
  261. package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
  262. package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
  263. package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
  264. package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
  265. package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
  266. package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
  267. package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
  268. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
  269. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
  270. package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
  271. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
  272. package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
  273. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
  274. package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
  275. package/dist/presets/azure/runtime/_utils.d.mts +0 -2
  276. package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
  277. package/dist/presets/bun/runtime/bun.d.mts +0 -3
  278. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
  279. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
  280. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
  281. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
  282. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
  283. package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
  284. package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
  285. package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
  286. package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
  287. package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
  288. package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
  289. package/dist/presets/node/runtime/node-server.d.mts +0 -3
  290. package/dist/presets/standard/runtime/server.d.mts +0 -3
  291. package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
  292. package/dist/presets/vercel/runtime/isr.d.mts +0 -2
  293. package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
  294. package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
  295. package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
  296. package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
  297. package/dist/runtime/internal/vite/node-runner.mjs +0 -359
@@ -1,31 +1,30 @@
1
- import { $ as resolveModulePath, A as compressPublicAssets, H as d, I as prettyPath, L as resolveNitroPath, M as build, R as writeFile$1, V as a, at as join, ct as resolve, et as resolveModuleURL, j as src_default, k as scanUnprefixedPublicAssets, p as runParallel, q as findWorkspaceDir, st as relative } from "../_build/common.mjs";
2
- import { n as loadConfig, r as watchConfig } from "../_libs/rc9+c12+dotenv.mjs";
1
+ import { i as loadConfig, s as watchConfig } from "../_libs/c12+rc9.mjs";
2
+ import { A as src_default, F as prettyPath, H as v, I as resolveNitroPath, K as findWorkspaceDir, L as writeFile$1, O as scanUnprefixedPublicAssets, ct as join, dt as resolve, j as build, k as compressPublicAssets, nt as resolveModulePath, p as runParallel, rt as resolveModuleURL, ut as relative, z as _ } from "../_build/common.mjs";
3
3
  import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
4
4
  import { t as klona } from "../_libs/klona.mjs";
5
5
  import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
6
6
  import { n as parse, t as TSConfckCache } from "../_libs/tsconfck.mjs";
7
7
  import { n as scanHandlers, t as scanAndSyncOptions } from "./nitro2.mjs";
8
- import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
8
+ import { i as findAllRoutes, n as addRoute, r as createRouter } from "../_libs/rou3.mjs";
9
+ import { n as initNitroRouting } from "./nitro3.mjs";
10
+ import "../_dev.mjs";
9
11
  import { n as z, t as P } from "../_libs/ultrahtml.mjs";
10
12
  import { createRequire } from "node:module";
11
- import consola$1, { consola } from "consola";
13
+ import consola, { consola as consola$1 } from "consola";
12
14
  import { Hookable, createDebugger } from "hookable";
13
- import { existsSync } from "node:fs";
15
+ import { runtimeDir, version } from "nitro/meta";
16
+ import { existsSync, readFileSync } from "node:fs";
14
17
  import { readFile } from "node:fs/promises";
15
18
  import { pathToFileURL } from "node:url";
16
19
  import { defu } from "defu";
17
20
  import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
18
- import { runtimeDir } from "nitro/meta";
19
21
  import { colors } from "consola/utils";
20
- import { hash } from "ohash";
21
- import http from "node:http";
22
22
  import { toRequest } from "h3";
23
-
24
- //#region src/config/defaults.ts
23
+ import http from "node:http";
25
24
  const NitroDefaults = {
26
25
  compatibilityDate: "latest",
27
- debug: d,
28
- logLevel: a ? 1 : 3,
26
+ debug: _,
27
+ logLevel: v ? 1 : 3,
29
28
  runtimeConfig: {
30
29
  app: {},
31
30
  nitro: {}
@@ -79,7 +78,6 @@ const NitroDefaults = {
79
78
  routes: []
80
79
  },
81
80
  builder: void 0,
82
- moduleSideEffects: ["unenv/polyfill/"],
83
81
  replace: {},
84
82
  node: true,
85
83
  sourcemap: false,
@@ -95,12 +93,9 @@ const NitroDefaults = {
95
93
  commands: {},
96
94
  framework: {
97
95
  name: "nitro",
98
- version: ""
96
+ version
99
97
  }
100
98
  };
101
-
102
- //#endregion
103
- //#region src/config/resolvers/assets.ts
104
99
  async function resolveAssetsOptions(options) {
105
100
  for (const publicAsset of options.publicAssets) {
106
101
  publicAsset.dir = resolve(options.rootDir, publicAsset.dir);
@@ -126,15 +121,9 @@ async function resolveAssetsOptions(options) {
126
121
  if (asset.maxAge && !asset.fallthrough) options.routeRules[asset.baseURL + "/**"] = defu(routeRule, { headers: { "cache-control": `public, max-age=${asset.maxAge}, immutable` } });
127
122
  }
128
123
  }
129
-
130
- //#endregion
131
- //#region src/config/resolvers/compatibility.ts
132
124
  async function resolveCompatibilityOptions(options) {
133
125
  options.compatibilityDate = resolveCompatibilityDatesFromEnv(options.compatibilityDate);
134
126
  }
135
-
136
- //#endregion
137
- //#region src/config/resolvers/database.ts
138
127
  async function resolveDatabaseOptions(options) {
139
128
  if (options.experimental.database && options.imports) {
140
129
  options.imports.presets ??= [];
@@ -152,9 +141,6 @@ async function resolveDatabaseOptions(options) {
152
141
  } };
153
142
  }
154
143
  }
155
-
156
- //#endregion
157
- //#region src/config/resolvers/export-conditions.ts
158
144
  async function resolveExportConditionsOptions(options) {
159
145
  options.exportConditions = _resolveExportConditions(options.exportConditions || [], {
160
146
  dev: options.dev,
@@ -162,21 +148,14 @@ async function resolveExportConditionsOptions(options) {
162
148
  wasm: options.wasm !== false
163
149
  });
164
150
  }
165
- function _resolveExportConditions(conditions, opts) {
166
- const resolvedConditions = [];
167
- resolvedConditions.push(opts.dev ? "development" : "production");
168
- resolvedConditions.push(...conditions);
169
- if (opts.node) resolvedConditions.push("node");
170
- else resolvedConditions.push("wintercg", "worker", "web", "browser", "workerd", "edge-light", "netlify", "edge-routine", "deno");
171
- if (opts.wasm) resolvedConditions.push("wasm", "unwasm");
172
- resolvedConditions.push("import", "default", "module");
173
- if ("Bun" in globalThis) resolvedConditions.push("bun");
174
- else if ("Deno" in globalThis) resolvedConditions.push("deno");
175
- return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
151
+ function _resolveExportConditions(userConditions, opts) {
152
+ const conditions = [...userConditions.filter((c) => !c.startsWith("!"))];
153
+ conditions.push(opts.dev ? "development" : "production");
154
+ if (opts.wasm) conditions.push("wasm", "unwasm");
155
+ if (opts.node) conditions.push("node");
156
+ const negated = new Set(userConditions.filter((c) => c.startsWith("!")).map((c) => c.slice(1)));
157
+ return [...new Set(conditions)].filter((c) => !negated.has(c));
176
158
  }
177
-
178
- //#endregion
179
- //#region src/config/resolvers/imports.ts
180
159
  async function resolveImportsOptions(options) {
181
160
  if (options.imports === false) return;
182
161
  options.imports.presets ??= [];
@@ -186,12 +165,9 @@ async function resolveImportsOptions(options) {
186
165
  options.imports.exclude.push(/[/\\]\.git[/\\]/);
187
166
  options.imports.exclude.push(options.buildDir);
188
167
  const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
189
- options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? /* @__PURE__ */ new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
168
+ options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
190
169
  }
191
170
  }
192
-
193
- //#endregion
194
- //#region src/config/resolvers/open-api.ts
195
171
  async function resolveOpenAPIOptions(options) {
196
172
  if (!options.experimental.openAPI) return;
197
173
  if (!options.dev && !options.openAPI?.production) return;
@@ -229,16 +205,9 @@ async function resolveOpenAPIOptions(options) {
229
205
  options.prerender.routes.push(...prerenderRoutes);
230
206
  }
231
207
  }
232
-
233
- //#endregion
234
- //#region src/config/resolvers/tsconfig.ts
235
208
  async function resolveTsconfig(options) {
236
209
  const root = resolve(options.rootDir || ".") + "/";
237
210
  if (!options.typescript.tsConfig) options.typescript.tsConfig = await loadTsconfig(root);
238
- if (options.experimental.tsconfigPaths && options.typescript.tsConfig.compilerOptions?.paths) options.alias = {
239
- ...tsConfigToAliasObj(options.typescript.tsConfig, root),
240
- ...options.alias
241
- };
242
211
  }
243
212
  async function loadTsconfig(root) {
244
213
  const opts = {
@@ -246,39 +215,13 @@ async function loadTsconfig(root) {
246
215
  cache: loadTsconfig["__cache"] ??= new TSConfckCache(),
247
216
  ignoreNodeModules: true
248
217
  };
249
- const tsConfigPath = join(root, "tsconfig.json");
250
- const parsed = await parse(tsConfigPath, opts).catch(() => void 0);
218
+ const parsed = await parse(join(root, "tsconfig.json"), opts).catch(() => void 0);
251
219
  if (!parsed) return {};
252
220
  const { tsconfig, tsconfigFile } = parsed;
253
221
  tsconfig.compilerOptions ??= {};
254
222
  if (!tsconfig.compilerOptions.baseUrl) tsconfig.compilerOptions.baseUrl = resolve(tsconfigFile, "..");
255
223
  return tsconfig;
256
224
  }
257
- function tsConfigToAliasObj(tsconfig, root) {
258
- const compilerOptions = tsconfig?.compilerOptions;
259
- if (!compilerOptions?.paths) return {};
260
- const paths = compilerOptions.paths;
261
- const alias = {};
262
- for (const [key, targets] of Object.entries(paths)) {
263
- let source = key;
264
- let target = targets?.[0];
265
- if (!target) continue;
266
- if (source.includes("*") || target.includes("*")) {
267
- source = source.replace(/\/\*$/, "");
268
- target = target.replace(/\/\*$/, "");
269
- if (source.includes("*") || target.includes("*")) continue;
270
- }
271
- if (target.startsWith(".")) {
272
- if (!compilerOptions.baseUrl) continue;
273
- target = resolve(root, compilerOptions.baseUrl, target) + (key.endsWith("*") ? "/" : "");
274
- }
275
- alias[source] = target;
276
- }
277
- return alias;
278
- }
279
-
280
- //#endregion
281
- //#region src/config/resolvers/paths.ts
282
225
  const RESOLVE_EXTENSIONS = [
283
226
  ".ts",
284
227
  ".js",
@@ -293,7 +236,7 @@ async function resolvePathOptions(options) {
293
236
  options.workspaceDir ||= await findWorkspaceDir(options.rootDir).catch(() => options.rootDir) + "/";
294
237
  if (options.srcDir) {
295
238
  if (options.serverDir === void 0) options.serverDir = options.srcDir;
296
- consola$1.warn(`"srcDir" option is deprecated. Please use "serverDir" instead.`);
239
+ consola.warn(`"srcDir" option is deprecated. Please use "serverDir" instead.`);
297
240
  }
298
241
  if (options.serverDir !== false) {
299
242
  if (options.serverDir === true) options.serverDir = "server";
@@ -332,7 +275,7 @@ async function resolvePathOptions(options) {
332
275
  if (detected) {
333
276
  options.serverEntry ??= { handler: "" };
334
277
  options.serverEntry.handler = detected;
335
- consola$1.info(`Detected \`${prettyPath(detected)}\` as server entry.`);
278
+ consola.info(`Detected \`${prettyPath(detected)}\` as server entry.`);
336
279
  }
337
280
  }
338
281
  if (options.serverEntry?.handler && !options.serverEntry?.format) {
@@ -359,7 +302,7 @@ async function resolvePathOptions(options) {
359
302
  if (defaultIndex) {
360
303
  options.renderer ??= {};
361
304
  options.renderer.template = defaultIndex;
362
- consola$1.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
305
+ consola.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
363
306
  }
364
307
  }
365
308
  if (options.renderer?.template && !options.renderer?.handler) {
@@ -368,9 +311,6 @@ async function resolvePathOptions(options) {
368
311
  }
369
312
  }
370
313
  }
371
-
372
- //#endregion
373
- //#region src/config/resolvers/route-rules.ts
374
314
  async function resolveRouteRulesOptions(options) {
375
315
  options.routeRules = normalizeRouteRules(options);
376
316
  }
@@ -403,7 +343,7 @@ function normalizeRouteRules(config) {
403
343
  "access-control-max-age": "0",
404
344
  ...routeRules.headers
405
345
  };
406
- if (routeConfig.swr) {
346
+ if (routeConfig.swr !== void 0 && routeConfig.swr !== false) {
407
347
  routeRules.cache = routeRules.cache || {};
408
348
  routeRules.cache.swr = true;
409
349
  if (typeof routeConfig.swr === "number") routeRules.cache.maxAge = routeConfig.swr;
@@ -413,9 +353,6 @@ function normalizeRouteRules(config) {
413
353
  }
414
354
  return normalizedRules;
415
355
  }
416
-
417
- //#endregion
418
- //#region src/config/resolvers/runtime-config.ts
419
356
  async function resolveRuntimeConfigOptions(options) {
420
357
  options.runtimeConfig = normalizeRuntimeConfig(options);
421
358
  }
@@ -450,28 +387,16 @@ function checkSerializableRuntimeConfig(obj, path = []) {
450
387
  function isPrimitiveValue(value) {
451
388
  return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
452
389
  }
453
-
454
- //#endregion
455
- //#region src/config/resolvers/storage.ts
456
390
  async function resolveStorageOptions(options) {}
457
-
458
- //#endregion
459
- //#region src/config/resolvers/url.ts
460
391
  async function resolveURLOptions(options) {
461
392
  options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
462
393
  }
463
-
464
- //#endregion
465
- //#region src/config/resolvers/error.ts
466
394
  async function resolveErrorOptions(options) {
467
395
  if (!options.errorHandler) options.errorHandler = [];
468
396
  else if (!Array.isArray(options.errorHandler)) options.errorHandler = [options.errorHandler];
469
397
  options.errorHandler = options.errorHandler.map((h) => resolveNitroPath(h, options));
470
398
  options.errorHandler.push(join(runtimeDir, `internal/error/${options.dev ? "dev" : "prod"}`));
471
399
  }
472
-
473
- //#endregion
474
- //#region src/config/resolvers/unenv.ts
475
400
  const common = {
476
401
  meta: {
477
402
  name: "nitro-common",
@@ -514,9 +439,6 @@ async function resolveUnenv(options) {
514
439
  if (!options.node) options.unenv.unshift(nodeless);
515
440
  options.unenv.unshift(common);
516
441
  }
517
-
518
- //#endregion
519
- //#region src/config/resolvers/builder.ts
520
442
  const VALID_BUILDERS = [
521
443
  "rolldown",
522
444
  "rollup",
@@ -527,8 +449,8 @@ async function resolveBuilder(options) {
527
449
  if (options.builder) {
528
450
  if (!VALID_BUILDERS.includes(options.builder)) throw new Error(`Invalid nitro builder "${options.builder}". Valid builders are: ${VALID_BUILDERS.join(", ")}.`);
529
451
  const pkg = options.builder;
530
- if (!isPkgInstalled(pkg, options.rootDir)) {
531
- if (!await consola$1.prompt(`Nitro builder package \`${pkg}\` is not installed. Would you like to install it?`, {
452
+ if (pkg !== "rolldown" && !isPkgInstalled(pkg, options.rootDir)) {
453
+ if (!await consola.prompt(`Nitro builder package \`${pkg}\` is not installed. Would you like to install it?`, {
532
454
  type: "confirm",
533
455
  default: true,
534
456
  cancel: "null"
@@ -537,42 +459,49 @@ async function resolveBuilder(options) {
537
459
  }
538
460
  return;
539
461
  }
540
- for (const pkg of [
541
- "rolldown",
542
- "rollup",
543
- "vite"
544
- ]) if (isPkgInstalled(pkg, options.rootDir)) {
545
- options.builder = pkg;
462
+ if (isPkgInstalled("vite", options.rootDir) && hasNitroViteConfig(options)) {
463
+ options.builder = "vite";
546
464
  return;
547
465
  }
548
- const pkgToInstall = await consola$1.prompt(`No nitro builder specified. Which builder would you like to install?`, {
549
- type: "select",
550
- cancel: "null",
551
- options: VALID_BUILDERS.map((b) => ({
552
- label: b,
553
- value: b
554
- }))
555
- });
556
- if (!pkgToInstall) throw new Error(`No nitro builder specified. Please install one of the following packages: ${VALID_BUILDERS.join(", ")} and set it as the builder in your nitro config or via the NITRO_BUILDER environment variable.`);
557
- await installPkg(pkgToInstall, options.rootDir);
558
- options.builder = pkgToInstall;
466
+ options.builder = "rolldown";
559
467
  }
560
- const require = createRequire(process.cwd() + "/_index.js");
468
+ const _require = createRequire(import.meta.url);
561
469
  function isPkgInstalled(pkg, root) {
562
470
  try {
563
- require.resolve(pkg, { paths: [root] });
471
+ _require.resolve(pkg, { paths: [root] });
564
472
  return true;
565
473
  } catch {
566
474
  return false;
567
475
  }
568
476
  }
569
477
  async function installPkg(pkg, root) {
570
- const { addDevDependency } = await import("../_libs/nypm+giget+tinyexec.mjs").then((n) => n.n);
478
+ const { addDevDependency } = await import("../_libs/_5.mjs");
571
479
  return addDevDependency(pkg, { cwd: root });
572
480
  }
573
-
574
- //#endregion
575
- //#region src/config/loader.ts
481
+ function hasNitroViteConfig(options) {
482
+ for (const ext of [
483
+ ".ts",
484
+ ".mts",
485
+ ".js",
486
+ ".mjs"
487
+ ]) {
488
+ const configPath = resolve(options.rootDir, `vite.config${ext}`);
489
+ if (existsSync(configPath)) try {
490
+ if (readFileSync(configPath, "utf8").includes("nitro(")) return true;
491
+ } catch {}
492
+ }
493
+ return false;
494
+ }
495
+ async function resolveTracingOptions(options) {
496
+ if (!options.tracingChannel) return;
497
+ options.tracingChannel = {
498
+ srvx: true,
499
+ h3: true,
500
+ ...typeof options.tracingChannel === "object" ? options.tracingChannel : {}
501
+ };
502
+ options.plugins = options.plugins || [];
503
+ options.plugins.push("#nitro/virtual/tracing");
504
+ }
576
505
  const configResolvers = [
577
506
  resolveCompatibilityOptions,
578
507
  resolveTsconfig,
@@ -588,7 +517,8 @@ const configResolvers = [
588
517
  resolveStorageOptions,
589
518
  resolveErrorOptions,
590
519
  resolveUnenv,
591
- resolveBuilder
520
+ resolveBuilder,
521
+ resolveTracingOptions
592
522
  ];
593
523
  async function loadOptions(configOverrides = {}, opts = {}) {
594
524
  const options = await _loadUserConfig(configOverrides, opts);
@@ -602,16 +532,14 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
602
532
  const { resolvePreset } = await import("../_presets.mjs");
603
533
  let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
604
534
  const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
535
+ const envName = opts.c12?.envName ?? (configOverrides.dev ? "development" : "production");
605
536
  const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
606
537
  name: "nitro",
607
538
  cwd: configOverrides.rootDir,
608
539
  dotenv: _dotenv,
540
+ envName,
609
541
  extend: { extendKey: ["extends", "preset"] },
610
542
  defaults: NitroDefaults,
611
- jitiOptions: { alias: {
612
- nitropack: "nitro/config",
613
- "nitro/config": "nitro/config"
614
- } },
615
543
  async overrides({ rawConfigs }) {
616
544
  const getConf = (key) => configOverrides[key] ?? rawConfigs.main?.[key] ?? rawConfigs.rc?.[key] ?? rawConfigs.packageJson?.[key];
617
545
  if (!compatibilityDate) compatibilityDate = getConf("compatibilityDate");
@@ -639,12 +567,12 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
639
567
  };
640
568
  },
641
569
  async resolve(id) {
642
- const preset$1 = await resolvePreset(id, {
570
+ const preset = await resolvePreset(id, {
643
571
  static: configOverrides.static,
644
572
  compatibilityDate: compatibilityDate || "latest",
645
573
  dev: configOverrides.dev
646
574
  });
647
- if (preset$1) return { config: klona(preset$1) };
575
+ if (preset) return { config: klona(preset) };
648
576
  },
649
577
  ...opts.c12
650
578
  });
@@ -653,21 +581,15 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
653
581
  options._c12 = loadedConfig;
654
582
  options.preset = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || preset;
655
583
  options.compatibilityDate = resolveCompatibilityDates(compatibilityDate, options.compatibilityDate);
656
- if (options.dev && options.preset !== "nitro-dev") consola$1.info(`Using \`${options.preset}\` emulation in development mode.`);
584
+ if (options.dev && options.preset !== "nitro-dev") consola.info(`Using \`${options.preset}\` emulation in development mode.`);
657
585
  return options;
658
586
  }
659
-
660
- //#endregion
661
- //#region src/config/update.ts
662
587
  async function updateNitroConfig(nitro, config) {
663
588
  nitro.options.routeRules = normalizeRouteRules(config.routeRules ? config : nitro.options);
664
589
  nitro.options.runtimeConfig = normalizeRuntimeConfig(config.runtimeConfig ? config : nitro.options);
665
590
  await nitro.hooks.callHook("rollup:reload");
666
- consola$1.success("Nitro config hot reloaded!");
591
+ consola.success("Nitro config hot reloaded!");
667
592
  }
668
-
669
- //#endregion
670
- //#region src/module.ts
671
593
  async function installModules(nitro) {
672
594
  const _modules = [...nitro.options.modules || []];
673
595
  const modules = await Promise.all(_modules.map((mod) => _resolveNitroModule(mod, nitro.options)));
@@ -682,17 +604,20 @@ async function installModules(nitro) {
682
604
  }
683
605
  async function _resolveNitroModule(mod, nitroOptions) {
684
606
  let _url;
685
- if (typeof mod === "string") mod = await import(resolveModuleURL(mod, {
686
- from: [nitroOptions.rootDir],
687
- extensions: [
688
- ".mjs",
689
- ".cjs",
690
- ".js",
691
- ".mts",
692
- ".cts",
693
- ".ts"
694
- ]
695
- })).then((m) => m.default || m);
607
+ if (typeof mod === "string") {
608
+ _url = resolveModuleURL(mod, {
609
+ from: [nitroOptions.rootDir],
610
+ extensions: [
611
+ ".mjs",
612
+ ".cjs",
613
+ ".js",
614
+ ".mts",
615
+ ".cts",
616
+ ".ts"
617
+ ]
618
+ });
619
+ mod = await import(_url).then((m) => m.default || m);
620
+ }
696
621
  if (typeof mod === "function") mod = { setup: mod };
697
622
  if ("nitro" in mod) mod = mod.nitro;
698
623
  if (!mod.setup) throw new Error("Invalid Nitro module: missing setup() function.");
@@ -701,143 +626,6 @@ async function _resolveNitroModule(mod, nitroOptions) {
701
626
  ...mod
702
627
  };
703
628
  }
704
-
705
- //#endregion
706
- //#region src/routing.ts
707
- const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
708
- function initNitroRouting(nitro) {
709
- const envConditions = new Set([
710
- nitro.options.dev ? "dev" : "prod",
711
- nitro.options.preset,
712
- nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
713
- ].filter(Boolean));
714
- const matchesEnv = (h) => {
715
- const envs = (Array.isArray(h.env) ? h.env : [h.env]).filter(Boolean);
716
- return envs.length === 0 || envs.some((env) => envConditions.has(env));
717
- };
718
- const routes = new Router(nitro.options.baseURL);
719
- const routeRules = new Router(nitro.options.baseURL);
720
- const globalMiddleware = [];
721
- const routedMiddleware = new Router(nitro.options.baseURL);
722
- const sync = () => {
723
- routeRules._update(Object.entries(nitro.options.routeRules).map(([route, data]) => ({
724
- route,
725
- method: "",
726
- data: {
727
- ...data,
728
- _route: route
729
- }
730
- })));
731
- const _routes = [
732
- ...Object.entries(nitro.options.routes).flatMap(([route, handler]) => {
733
- if (typeof handler === "string") handler = { handler };
734
- return {
735
- ...handler,
736
- route,
737
- middleware: false
738
- };
739
- }),
740
- ...nitro.options.handlers,
741
- ...nitro.scannedHandlers
742
- ].filter((h) => h && !h.middleware && matchesEnv(h));
743
- if (nitro.options.serverEntry && nitro.options.serverEntry.handler) _routes.push({
744
- route: "/**",
745
- lazy: false,
746
- format: nitro.options.serverEntry.format,
747
- handler: nitro.options.serverEntry.handler
748
- });
749
- if (nitro.options.renderer?.handler) _routes.push({
750
- route: "/**",
751
- lazy: true,
752
- handler: nitro.options.renderer?.handler
753
- });
754
- routes._update(_routes.map((h) => ({
755
- ...h,
756
- method: h.method || "",
757
- data: handlerWithImportHash(h)
758
- })), { merge: true });
759
- const _middleware = [...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => h && h.middleware && matchesEnv(h));
760
- if (nitro.options.serveStatic) _middleware.unshift({
761
- route: "/**",
762
- middleware: true,
763
- handler: join(runtimeDir, "internal/static")
764
- });
765
- globalMiddleware.splice(0, globalMiddleware.length, ..._middleware.filter((h) => isGlobalMiddleware(h)).map((m) => handlerWithImportHash(m)));
766
- routedMiddleware._update(_middleware.filter((h) => !isGlobalMiddleware(h)).map((h) => ({
767
- ...h,
768
- method: h.method || "",
769
- data: handlerWithImportHash(h)
770
- })));
771
- };
772
- nitro.routing = Object.freeze({
773
- sync,
774
- routes,
775
- routeRules,
776
- globalMiddleware,
777
- routedMiddleware
778
- });
779
- }
780
- function handlerWithImportHash(h) {
781
- const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
782
- return {
783
- ...h,
784
- _importHash: id
785
- };
786
- }
787
- var Router = class {
788
- _routes;
789
- _router;
790
- _compiled;
791
- _baseURL;
792
- constructor(baseURL) {
793
- this._update([]);
794
- this._baseURL = baseURL || "";
795
- if (this._baseURL.endsWith("/")) this._baseURL = this._baseURL.slice(0, -1);
796
- }
797
- get routes() {
798
- return this._routes;
799
- }
800
- _update(routes, opts) {
801
- this._routes = routes;
802
- this._router = createRouter();
803
- this._compiled = void 0;
804
- for (const route of routes) addRoute(this._router, route.method, this._baseURL + route.route, route.data);
805
- if (opts?.merge) mergeCatchAll(this._router);
806
- }
807
- hasRoutes() {
808
- return this._routes.length > 0;
809
- }
810
- compileToString(opts) {
811
- const key = opts ? hash(opts) : "";
812
- this._compiled ||= {};
813
- if (this._compiled[key]) return this._compiled[key];
814
- this._compiled[key] = compileRouterToString(this._router, void 0, opts);
815
- if (this.routes.length === 1 && this.routes[0].route === "/**" && this.routes[0].method === "") {
816
- const data = (opts?.serialize || JSON.stringify)(this.routes[0].data);
817
- let retCode = `{data,params:{"_":p.slice(1)}}`;
818
- if (opts?.matchAll) retCode = `[${retCode}]`;
819
- this._compiled[key] = `/* @__PURE__ */ (() => {const data=${data};return ((_m, p)=>{return ${retCode};})})()`;
820
- }
821
- return this._compiled[key];
822
- }
823
- match(method, path) {
824
- return findRoute(this._router, method, path)?.data;
825
- }
826
- matchAll(method, path) {
827
- return findAllRoutes(this._router, method, path).map((route) => route.data);
828
- }
829
- };
830
- function mergeCatchAll(router) {
831
- const handlers = router.root?.wildcard?.methods?.[""];
832
- if (!handlers || handlers.length < 2) return;
833
- handlers.splice(0, handlers.length, {
834
- ...handlers[0],
835
- data: handlers.map((h) => h.data)
836
- });
837
- }
838
-
839
- //#endregion
840
- //#region src/global.ts
841
629
  const nitroInstances = globalThis.__nitro_instances__ ||= [];
842
630
  const globalKey = "__nitro_builder__";
843
631
  function registerNitroInstance(nitro) {
@@ -852,29 +640,31 @@ function registerNitroInstance(nitro) {
852
640
  function globalInit() {
853
641
  if (globalThis[globalKey]) return;
854
642
  globalThis[globalKey] = { async fetch(req) {
855
- for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve$1) => setTimeout(resolve$1, 300));
643
+ for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve) => setTimeout(resolve, 300));
856
644
  const nitro = nitroInstances[0];
857
645
  if (!nitro) throw new Error("No Nitro instance is running.");
858
646
  return nitro.fetch(req);
859
647
  } };
860
648
  }
861
-
862
- //#endregion
863
- //#region src/nitro.ts
864
649
  async function createNitro(config = {}, opts = {}) {
650
+ const options = await loadOptions(config, opts);
865
651
  const nitro = {
866
- options: await loadOptions(config, opts),
652
+ meta: {
653
+ version,
654
+ majorVersion: 3
655
+ },
656
+ options,
867
657
  hooks: new Hookable(),
868
658
  vfs: /* @__PURE__ */ new Map(),
869
659
  routing: {},
870
- logger: consola.withTag("nitro"),
660
+ logger: consola$1.withTag("nitro"),
871
661
  scannedHandlers: [],
872
662
  fetch: () => {
873
663
  throw new Error("no dev server attached!");
874
664
  },
875
665
  close: () => Promise.resolve(nitro.hooks.callHook("close")),
876
- async updateConfig(config$1) {
877
- updateNitroConfig(nitro, config$1);
666
+ async updateConfig(config) {
667
+ updateNitroConfig(nitro, config);
878
668
  }
879
669
  };
880
670
  registerNitroInstance(nitro);
@@ -895,9 +685,6 @@ async function createNitro(config = {}, opts = {}) {
895
685
  nitro.routing.sync();
896
686
  return nitro;
897
687
  }
898
-
899
- //#endregion
900
- //#region src/prerender/utils.ts
901
688
  const allowedExtensions = new Set(["", ".json"]);
902
689
  const linkParents = /* @__PURE__ */ new Map();
903
690
  const HTML_ENTITIES = {
@@ -946,7 +733,7 @@ function formatPrerenderRoute(route) {
946
733
  const parents = linkParents.get(route.route);
947
734
  const errorColor = colors[route.error.status === 404 ? "yellow" : "red"];
948
735
  const errorLead = parents?.size ? "├──" : "└──";
949
- str += `\n │ ${errorLead} ${errorColor(route.error.message)}`;
736
+ str += `\n │ ${errorLead} ${errorColor(route.error.message || "unknown error")}`;
950
737
  if (parents?.size) str += `\n${[...parents.values()].map((link) => ` │ └── Linked from ${link}`).join("\n")}`;
951
738
  }
952
739
  if (route.skip) str += colors.gray(" (skipped)");
@@ -958,21 +745,14 @@ function matchesIgnorePattern(path, pattern) {
958
745
  if (pattern instanceof RegExp) return pattern.test(path);
959
746
  return false;
960
747
  }
961
-
962
- //#endregion
963
- //#region src/prerender/prerender.ts
964
748
  const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
965
749
  async function prerender(nitro) {
966
750
  if (nitro.options.noPublicDir) {
967
751
  nitro.logger.warn("Skipping prerender since `noPublicDir` option is enabled.");
968
752
  return;
969
753
  }
970
- if (nitro.options.builder === "vite") {
971
- nitro.logger.warn("Skipping prerender since not supported with vite builder yet...");
972
- return;
973
- }
974
754
  const routes = new Set(nitro.options.prerender.routes);
975
- const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path$1, options]) => options.prerender && !path$1.includes("*")).map((e) => e[0]);
755
+ const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path, options]) => options.prerender && !path.includes("*")).map((e) => e[0]);
976
756
  for (const route of prerenderRulePaths) routes.add(route);
977
757
  await nitro.hooks.callHook("prerender:routes", routes);
978
758
  if (routes.size === 0) if (nitro.options.prerender.crawlLinks) routes.add("/");
@@ -985,7 +765,8 @@ async function prerender(nitro) {
985
765
  static: false,
986
766
  rootDir: nitro.options.rootDir,
987
767
  logLevel: 0,
988
- preset: "nitro-prerender"
768
+ preset: "nitro-prerender",
769
+ builder: nitro.options.builder === "vite" ? "rolldown" : nitro.options.builder
989
770
  };
990
771
  await nitro.hooks.callHook("prerender:config", prerendererConfig);
991
772
  const nitroRenderer = await createNitro(prerendererConfig);
@@ -1000,12 +781,12 @@ async function prerender(nitro) {
1000
781
  const prerenderer = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href).then((m) => m.default);
1001
782
  const routeRules = createRouter();
1002
783
  for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
1003
- const _getRouteRules = (path$1) => defu({}, ...findAllRoutes(routeRules, void 0, path$1).map((r) => r.data).reverse());
784
+ const _getRouteRules = (path) => defu({}, ...findAllRoutes(routeRules, void 0, path).map((r) => r.data).reverse());
1004
785
  const generatedRoutes = /* @__PURE__ */ new Set();
1005
786
  const failedRoutes = /* @__PURE__ */ new Set();
1006
787
  const skippedRoutes = /* @__PURE__ */ new Set();
1007
788
  const displayedLengthWarns = /* @__PURE__ */ new Set();
1008
- const publicAssetBases = nitro.options.publicAssets.filter((a$1) => !!a$1.baseURL && a$1.baseURL !== "/" && !a$1.fallthrough).map((a$1) => withTrailingSlash(a$1.baseURL));
789
+ const publicAssetBases = nitro.options.publicAssets.filter((a) => !!a.baseURL && a.baseURL !== "/" && !a.fallthrough).map((a) => withTrailingSlash(a.baseURL));
1009
790
  const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
1010
791
  const canPrerender = (route = "/") => {
1011
792
  if (generatedRoutes.has(route) || skippedRoutes.has(route)) return false;
@@ -1018,7 +799,7 @@ async function prerender(nitro) {
1018
799
  return true;
1019
800
  };
1020
801
  const canWriteToDisk = (route) => {
1021
- if (route.route.includes("?")) return false;
802
+ if (route.route.includes("?") || route.route.includes("..")) return false;
1022
803
  const FS_MAX_SEGMENT = 255;
1023
804
  const FS_MAX_PATH_PUBLIC_HTML = 1024 - (nitro.options.output.publicDir.length + 10);
1024
805
  if ((route.route.length >= FS_MAX_PATH_PUBLIC_HTML || route.route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route)) {
@@ -1093,8 +874,9 @@ async function prerender(nitro) {
1093
874
  dataBuff = void 0;
1094
875
  return _route;
1095
876
  }
1096
- if (canWriteToDisk(_route)) {
1097
- await writeFile$1(join(nitro.options.output.publicDir, _route.fileName), dataBuff);
877
+ const filePath = join(nitro.options.output.publicDir, _route.fileName);
878
+ if (canWriteToDisk(_route) && filePath.startsWith(nitro.options.output.publicDir)) {
879
+ await writeFile$1(filePath, dataBuff);
1098
880
  nitro._prerenderedRoutes.push(_route);
1099
881
  } else _route.skip = true;
1100
882
  if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
@@ -1126,17 +908,12 @@ async function prerender(nitro) {
1126
908
  nitro.logger.info(`Prerendered ${nitro._prerenderedRoutes.length} routes in ${prerenderTimeInMs / 1e3} seconds`);
1127
909
  if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
1128
910
  }
1129
-
1130
- //#endregion
1131
- //#region src/task.ts
1132
- /** @experimental */
1133
911
  async function runTask(taskEvent, opts) {
1134
912
  return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
1135
913
  method: "POST",
1136
914
  body: taskEvent
1137
915
  });
1138
916
  }
1139
- /** @experimental */
1140
917
  async function listTasks(opts) {
1141
918
  return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
1142
919
  }
@@ -1150,7 +927,7 @@ async function _getTasksContext(opts) {
1150
927
  const baseURL = `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`;
1151
928
  const socketPath = buildInfo.dev.workerAddress.socketPath;
1152
929
  const devFetch = (path, options) => {
1153
- return new Promise((resolve$1, reject) => {
930
+ return new Promise((resolve, reject) => {
1154
931
  let url = withBase(path, baseURL);
1155
932
  if (options?.query) url = withQuery(url, options.query);
1156
933
  const request = http.request(url, {
@@ -1166,7 +943,7 @@ async function _getTasksContext(opts) {
1166
943
  return;
1167
944
  }
1168
945
  let data = "";
1169
- response.on("data", (chunk) => data += chunk).on("end", () => resolve$1(JSON.parse(data))).on("error", (e) => reject(e));
946
+ response.on("data", (chunk) => data += chunk).on("end", () => resolve(JSON.parse(data))).on("error", (e) => reject(e));
1170
947
  });
1171
948
  request.on("error", (e) => reject(e));
1172
949
  if (options?.body) request.write(JSON.stringify(options.body));
@@ -1186,6 +963,4 @@ function _pidIsRunning(pid) {
1186
963
  return false;
1187
964
  }
1188
965
  }
1189
-
1190
- //#endregion
1191
- export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };
966
+ export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };