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,7 +1,5 @@
1
- import { N as glob, at as join, st as relative } from "../_build/common.mjs";
1
+ import { M as glob, ct as join, ut as relative } from "../_build/common.mjs";
2
2
  import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo";
3
-
4
- //#region src/scan.ts
5
3
  const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
6
4
  const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
7
5
  async function scanAndSyncOptions(nitro) {
@@ -23,9 +21,12 @@ async function scanAndSyncOptions(nitro) {
23
21
  async function scanHandlers(nitro) {
24
22
  const middleware = await scanMiddleware(nitro);
25
23
  const handlers = await Promise.all([scanServerRoutes(nitro, nitro.options.apiDir || "api", nitro.options.apiBaseURL || "/api"), scanServerRoutes(nitro, nitro.options.routesDir || "routes")]).then((r) => r.flat());
26
- nitro.scannedHandlers = [...middleware, ...handlers.filter((h, index, array) => {
27
- return array.findIndex((h2) => h.route === h2.route && h.method === h2.method && h.env === h2.env) === index;
24
+ const seenHandlers = /* @__PURE__ */ new Set();
25
+ nitro.scannedHandlers = [...middleware, ...handlers.filter((h) => {
26
+ const key = `${h.route}\0${h.method}\0${h.env}`;
27
+ return seenHandlers.has(key) ? false : (seenHandlers.add(key), true);
28
28
  })];
29
+ nitro.routing.sync();
29
30
  return handlers;
30
31
  }
31
32
  async function scanMiddleware(nitro) {
@@ -39,7 +40,7 @@ async function scanMiddleware(nitro) {
39
40
  }
40
41
  async function scanServerRoutes(nitro, dir, prefix = "/") {
41
42
  return (await scanFiles(nitro, dir)).map((file) => {
42
- let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(\w+)]/g, "**:$1").replace(/\[([^/\]]+)]/g, ":$1");
43
+ let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}([^\]]+)]/g, (_, p) => "**:" + p.replace(/[^\w-]/g, "_")).replace(/\[([^/\]]+)]/g, (_, p) => ":" + p.replace(/[^\w-]/g, "_"));
43
44
  route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
44
45
  const suffixMatch = route.match(suffixRegex);
45
46
  let method;
@@ -96,6 +97,4 @@ async function scanDir(nitro, dir, name) {
96
97
  };
97
98
  }).sort((a, b) => a.path.localeCompare(b.path));
98
99
  }
99
-
100
- //#endregion
101
- export { scanHandlers as n, scanAndSyncOptions as t };
100
+ export { scanHandlers as n, scanAndSyncOptions as t };
@@ -0,0 +1,136 @@
1
+ import { ct as join } from "../_build/common.mjs";
2
+ import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
3
+ import { runtimeDir } from "nitro/meta";
4
+ import { hash } from "ohash";
5
+ const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
6
+ function initNitroRouting(nitro) {
7
+ const envConditions = new Set([
8
+ nitro.options.dev ? "dev" : "prod",
9
+ nitro.options.preset,
10
+ nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
11
+ ].filter(Boolean));
12
+ const matchesEnv = (h) => {
13
+ const envs = (Array.isArray(h.env) ? h.env : [h.env]).filter(Boolean);
14
+ return envs.length === 0 || envs.some((env) => envConditions.has(env));
15
+ };
16
+ const routes = new Router(nitro.options.baseURL);
17
+ const routeRules = new Router(nitro.options.baseURL);
18
+ const globalMiddleware = [];
19
+ const routedMiddleware = new Router(nitro.options.baseURL);
20
+ const sync = () => {
21
+ routeRules._update(Object.entries(nitro.options.routeRules).map(([route, data]) => ({
22
+ route,
23
+ method: "",
24
+ data: {
25
+ ...data,
26
+ _route: route
27
+ }
28
+ })));
29
+ const _routes = [
30
+ ...Object.entries(nitro.options.routes).flatMap(([route, handler]) => {
31
+ if (typeof handler === "string") handler = { handler };
32
+ return {
33
+ ...handler,
34
+ route,
35
+ middleware: false
36
+ };
37
+ }),
38
+ ...nitro.options.handlers,
39
+ ...nitro.scannedHandlers
40
+ ].filter((h) => h && !h.middleware && matchesEnv(h));
41
+ if (nitro.options.serverEntry && nitro.options.serverEntry.handler) _routes.push({
42
+ route: "/**",
43
+ lazy: false,
44
+ format: nitro.options.serverEntry.format,
45
+ handler: nitro.options.serverEntry.handler
46
+ });
47
+ if (nitro.options.renderer?.handler) _routes.push({
48
+ route: "/**",
49
+ lazy: true,
50
+ handler: nitro.options.renderer?.handler
51
+ });
52
+ routes._update(_routes.map((h) => ({
53
+ ...h,
54
+ method: h.method || "",
55
+ data: handlerWithImportHash(h)
56
+ })), { merge: true });
57
+ const _middleware = [...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => h && h.middleware && matchesEnv(h));
58
+ if (nitro.options.serveStatic) _middleware.unshift({
59
+ route: "/**",
60
+ middleware: true,
61
+ handler: join(runtimeDir, "internal/static")
62
+ });
63
+ globalMiddleware.splice(0, globalMiddleware.length, ..._middleware.filter((h) => isGlobalMiddleware(h)).map((m) => handlerWithImportHash(m)));
64
+ routedMiddleware._update(_middleware.filter((h) => !isGlobalMiddleware(h)).map((h) => ({
65
+ ...h,
66
+ method: h.method || "",
67
+ data: handlerWithImportHash(h)
68
+ })));
69
+ };
70
+ nitro.routing = Object.freeze({
71
+ sync,
72
+ routes,
73
+ routeRules,
74
+ globalMiddleware,
75
+ routedMiddleware
76
+ });
77
+ }
78
+ function handlerWithImportHash(h) {
79
+ const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
80
+ return {
81
+ ...h,
82
+ _importHash: id
83
+ };
84
+ }
85
+ var Router = class {
86
+ _routes;
87
+ _router;
88
+ _compiled;
89
+ _baseURL;
90
+ constructor(baseURL) {
91
+ this._update([]);
92
+ this._baseURL = baseURL || "";
93
+ if (this._baseURL.endsWith("/")) this._baseURL = this._baseURL.slice(0, -1);
94
+ }
95
+ get routes() {
96
+ return this._routes;
97
+ }
98
+ _update(routes, opts) {
99
+ this._routes = routes;
100
+ this._router = createRouter();
101
+ this._compiled = void 0;
102
+ for (const route of routes) addRoute(this._router, route.method, this._baseURL + route.route, route.data);
103
+ if (opts?.merge) mergeCatchAll(this._router);
104
+ }
105
+ hasRoutes() {
106
+ return this._routes.length > 0;
107
+ }
108
+ compileToString(opts) {
109
+ const key = opts ? hash(opts) : "";
110
+ this._compiled ||= {};
111
+ if (this._compiled[key]) return this._compiled[key];
112
+ this._compiled[key] = compileRouterToString(this._router, void 0, opts);
113
+ if (this.routes.length === 1 && this.routes[0].route === "/**" && this.routes[0].method === "") {
114
+ const data = (opts?.serialize || JSON.stringify)(this.routes[0].data);
115
+ let retCode = `{data,params:{"_":p.slice(1)}}`;
116
+ if (opts?.matchAll) retCode = `[${retCode}]`;
117
+ this._compiled[key] = `/* @__PURE__ */ (() => {const data=${data};return ((_m, p)=>{return ${retCode};})})()`;
118
+ }
119
+ return this._compiled[key];
120
+ }
121
+ match(method, path) {
122
+ return findRoute(this._router, method, path)?.data;
123
+ }
124
+ matchAll(method, path) {
125
+ return findAllRoutes(this._router, method, path).map((route) => route.data);
126
+ }
127
+ };
128
+ function mergeCatchAll(router) {
129
+ const handlers = router.root?.wildcard?.methods?.[""];
130
+ if (!handlers || handlers.length < 2) return;
131
+ handlers.splice(0, handlers.length, {
132
+ ...handlers[0],
133
+ data: handlers.map((h) => h.data)
134
+ });
135
+ }
136
+ export { initNitroRouting as n, Router as t };
@@ -0,0 +1,127 @@
1
+ import { F as prettyPath, ct as join, dt as resolve, m as getBuildInfo } from "../_build/common.mjs";
2
+ import { n as proxyFetch, r as proxyUpgrade } from "../_libs/httpxy.mjs";
3
+ import consola from "consola";
4
+ import { spawn } from "node:child_process";
5
+ async function startPreview(opts) {
6
+ const { outputDir, buildInfo } = await getBuildInfo(opts.rootDir);
7
+ if (!buildInfo) throw new Error("Cannot load nitro build info. Make sure to build first.");
8
+ const info = [
9
+ ["Build Directory:", prettyPath(outputDir)],
10
+ ["Date:", buildInfo.date && new Date(buildInfo.date).toLocaleString()],
11
+ ["Nitro Version:", buildInfo.versions.nitro],
12
+ ["Nitro Preset:", buildInfo.preset],
13
+ buildInfo.framework?.name !== "nitro" && ["Framework:", buildInfo.framework?.name + (buildInfo.framework?.version ? ` (v${buildInfo.framework.version})` : "")]
14
+ ].filter((i) => i && i[1]);
15
+ consola.box({
16
+ title: " [Build Info] ",
17
+ message: info.map((i) => `- ${i[0]} ${i[1]}`).join("\n")
18
+ });
19
+ const dotEnvEntries = await loadPreviewDotEnv(opts.rootDir);
20
+ if (dotEnvEntries.length > 0) consola.box({
21
+ title: " [Environment Variables] ",
22
+ message: [
23
+ "Loaded variables from .env files (preview mode only).",
24
+ "Set platform environment variables for production:",
25
+ ...dotEnvEntries.map(([key, val]) => ` - ${key}`)
26
+ ].join("\n")
27
+ });
28
+ if (buildInfo.preset.includes("cloudflare")) {
29
+ if (!buildInfo.commands?.preview) throw new Error(`No nitro build preview command found for the "${buildInfo.preset}" preset.`);
30
+ return await runPreviewCommand({
31
+ command: buildInfo.commands.preview,
32
+ rootDir: opts.rootDir,
33
+ env: dotEnvEntries
34
+ });
35
+ }
36
+ let fetchHandler = () => Promise.resolve(new Response("Not Found", { status: 404 }));
37
+ if (buildInfo.serverEntry) {
38
+ for (const [key, val] of dotEnvEntries) if (!process.env[key]) process.env[key] = val;
39
+ const { loadServerEntry } = await import("srvx/loader");
40
+ const entry = await loadServerEntry({
41
+ entry: resolve(outputDir, buildInfo.serverEntry),
42
+ ...opts.loader
43
+ });
44
+ if (entry.fetch) fetchHandler = entry.fetch;
45
+ }
46
+ if (buildInfo.publicDir) {
47
+ const { serveStatic } = await import("srvx/static");
48
+ const staticHandler = serveStatic({ dir: join(outputDir, buildInfo.publicDir) });
49
+ const originalFetchHandler = fetchHandler;
50
+ fetchHandler = async (req) => {
51
+ const staticRes = await staticHandler(req, () => void 0);
52
+ if (staticRes) return staticRes;
53
+ return originalFetchHandler(req);
54
+ };
55
+ }
56
+ return {
57
+ fetch: fetchHandler,
58
+ async close() {}
59
+ };
60
+ }
61
+ async function loadPreviewDotEnv(root) {
62
+ const { loadDotenv } = await import("../_libs/_.mjs");
63
+ const env = await loadDotenv({
64
+ cwd: root,
65
+ fileName: [
66
+ ".env.preview",
67
+ ".env.production",
68
+ ".env"
69
+ ]
70
+ });
71
+ return Object.entries(env).filter(([_key, val]) => val);
72
+ }
73
+ async function runPreviewCommand(opts) {
74
+ const [arg0, ...args] = opts.command.split(" ");
75
+ consola.info(`Spawning preview server...`);
76
+ consola.info(opts.command);
77
+ console.log("");
78
+ const { getRandomPort, waitForPort } = await import("get-port-please");
79
+ const randomPort = await getRandomPort();
80
+ const child = spawn(arg0, [
81
+ ...args,
82
+ "--port",
83
+ String(randomPort),
84
+ "--host",
85
+ "localhost"
86
+ ], {
87
+ stdio: "inherit",
88
+ cwd: opts.rootDir,
89
+ env: {
90
+ ...process.env,
91
+ ...Object.fromEntries(opts.env ?? []),
92
+ PORT: String(randomPort)
93
+ }
94
+ });
95
+ const killChild = (signal) => {
96
+ if (child && !child.killed) child.kill(signal);
97
+ };
98
+ for (const sig of ["SIGINT", "SIGHUP"]) process.once(sig, () => {
99
+ killChild(sig);
100
+ });
101
+ child.once("exit", (code) => {
102
+ if (code && code !== 0) consola.error(`[nitro] Preview server exited with code ${code}`);
103
+ });
104
+ await waitForPort(randomPort, {
105
+ retries: 20,
106
+ delay: 500,
107
+ host: "localhost"
108
+ });
109
+ return {
110
+ fetch(req) {
111
+ return proxyFetch({
112
+ port: randomPort,
113
+ host: "localhost"
114
+ }, req);
115
+ },
116
+ async upgrade(req, socket, head, opts) {
117
+ await proxyUpgrade({
118
+ port: randomPort,
119
+ host: "localhost"
120
+ }, req, socket, head, opts);
121
+ },
122
+ async close() {
123
+ killChild("SIGTERM");
124
+ }
125
+ };
126
+ }
127
+ export { startPreview as t };
@@ -1,13 +1,11 @@
1
- import { i as __toESM, r as __require, t as __commonJSMin } from "../_common.mjs";
2
- import { N as glob, V as a, ct as resolve, nt as dirname, p as runParallel, st as relative } from "../_build/common.mjs";
3
- import fs, { promises } from "node:fs";
1
+ import { r as __require, t as __commonJSMin } from "../_common.mjs";
2
+ import { H as v, M as glob, V as m, at as dirname, dt as resolve, nt as resolveModulePath, p as runParallel, ut as relative } from "../_build/common.mjs";
3
+ import { consola as consola$1 } from "consola";
4
+ import { promises } from "node:fs";
4
5
  import { promisify } from "node:util";
5
6
  import { colors } from "consola/utils";
6
7
  import zlib from "node:zlib";
7
- import "node:stream";
8
-
9
- //#region node_modules/.pnpm/duplexer@0.1.2/node_modules/duplexer/index.js
10
- var require_duplexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
11
9
  var Stream = __require("stream");
12
10
  var writeMethods = [
13
11
  "write",
@@ -53,8 +51,8 @@ var require_duplexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
53
51
  }
54
52
  }
55
53
  function proxyStream(methodName) {
56
- reader.on(methodName, reemit$1);
57
- function reemit$1() {
54
+ reader.on(methodName, reemit);
55
+ function reemit() {
58
56
  var args = slice.call(arguments);
59
57
  args.unshift(methodName);
60
58
  stream.emit.apply(stream, args);
@@ -71,11 +69,7 @@ var require_duplexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
71
69
  stream.emit("error", err);
72
70
  }
73
71
  }
74
- }));
75
-
76
- //#endregion
77
- //#region node_modules/.pnpm/gzip-size@7.0.0/node_modules/gzip-size/index.js
78
- var import_duplexer = /* @__PURE__ */ __toESM(require_duplexer(), 1);
72
+ })))();
79
73
  const getOptions = (options) => ({
80
74
  level: 9,
81
75
  ...options
@@ -85,9 +79,6 @@ async function gzipSize(input, options) {
85
79
  if (!input) return 0;
86
80
  return (await gzip(input, getOptions(options))).length;
87
81
  }
88
-
89
- //#endregion
90
- //#region node_modules/.pnpm/pretty-bytes@7.1.0/node_modules/pretty-bytes/index.js
91
82
  const BYTE_UNITS = [
92
83
  "B",
93
84
  "kB",
@@ -200,11 +191,8 @@ function prettyBytes(number, options) {
200
191
  }
201
192
  return applyFixedWidth(result, options.fixedWidth);
202
193
  }
203
-
204
- //#endregion
205
- //#region src/utils/fs-tree.ts
206
194
  async function generateFSTree(dir, options = {}) {
207
- if (a) return;
195
+ if (v) return;
208
196
  const files = await glob("**/*.*", {
209
197
  cwd: dir,
210
198
  ignore: ["*.map"]
@@ -214,23 +202,23 @@ async function generateFSTree(dir, options = {}) {
214
202
  const path = resolve(dir, file);
215
203
  const src = await promises.readFile(path);
216
204
  const size = src.byteLength;
217
- const gzip$1 = options.compressedSizes ? await gzipSize(src) : 0;
205
+ const gzip = options.compressedSizes ? await gzipSize(src) : 0;
218
206
  items.push({
219
207
  file,
220
208
  path,
221
209
  size,
222
- gzip: gzip$1
210
+ gzip
223
211
  });
224
212
  }, { concurrency: 10 });
225
- items.sort((a$1, b) => a$1.path.localeCompare(b.path));
213
+ items.sort((a, b) => a.path.localeCompare(b.path));
226
214
  let totalSize = 0;
227
215
  let totalGzip = 0;
228
216
  let totalNodeModulesSize = 0;
229
217
  let totalNodeModulesGzip = 0;
230
218
  let treeText = "";
231
219
  for (const [index, item] of items.entries()) {
232
- let dir$1 = dirname(item.file);
233
- if (dir$1 === ".") dir$1 = "";
220
+ let dir = dirname(item.file);
221
+ if (dir === ".") dir = "";
234
222
  const rpath = relative(process.cwd(), item.path);
235
223
  const treeChar = index === items.length - 1 ? "└─" : "├─";
236
224
  if (item.file.includes("node_modules")) {
@@ -249,6 +237,29 @@ async function generateFSTree(dir, options = {}) {
249
237
  treeText += "\n";
250
238
  return treeText;
251
239
  }
252
-
253
- //#endregion
254
- export { generateFSTree as t };
240
+ async function importDep(opts, _retry) {
241
+ const resolved = resolveModulePath(opts.id, {
242
+ from: [opts.dir, import.meta.url],
243
+ cache: _retry ? false : true,
244
+ try: true
245
+ });
246
+ if (resolved) return await import(resolved);
247
+ let shouldInstall;
248
+ if (_retry || v) shouldInstall = false;
249
+ else if (m) {
250
+ consola$1.info(`\`${opts.id}\` is required for ${opts.reason}. Installing automatically in CI environment...`);
251
+ shouldInstall = true;
252
+ } else shouldInstall = await consola$1.prompt(`\`${opts.id}\` is required for ${opts.reason}, but it is not installed. Would you like to install it?`, {
253
+ type: "confirm",
254
+ default: true,
255
+ cancel: "undefined"
256
+ });
257
+ if (!shouldInstall) throw new Error(`\`${opts.id}\` is not installed. Please add it to your dependencies for ${opts.reason}.`);
258
+ const start = Date.now();
259
+ consola$1.start(`Installing \`${opts.id}\` in \`${opts.dir}\`...`);
260
+ const { addDevDependency } = await import("../_libs/_5.mjs");
261
+ await addDevDependency(opts.id, { cwd: opts.dir });
262
+ consola$1.success(`Installed \`${opts.id}\` in ${opts.dir} (${Date.now() - start}ms).`);
263
+ return importDep(opts, true);
264
+ }
265
+ export { generateFSTree as n, importDep as t };
package/dist/_common.mjs CHANGED
@@ -1,6 +1,4 @@
1
1
  import { createRequire } from "node:module";
2
-
3
- //#region rolldown:runtime
4
2
  var __create = Object.create;
5
3
  var __defProp = Object.defineProperty;
6
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -8,30 +6,22 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
8
6
  var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
8
  var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
11
- var __exportAll = (all, symbols) => {
9
+ var __exportAll = (all, no_symbols) => {
12
10
  let target = {};
13
- for (var name in all) {
14
- __defProp(target, name, {
15
- get: all[name],
16
- enumerable: true
17
- });
18
- }
19
- if (symbols) {
20
- __defProp(target, Symbol.toStringTag, { value: "Module" });
21
- }
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
22
16
  return target;
23
17
  };
24
18
  var __copyProps = (to, from, except, desc) => {
25
- if (from && typeof from === "object" || typeof from === "function") {
26
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
27
- key = keys[i];
28
- if (!__hasOwnProp.call(to, key) && key !== except) {
29
- __defProp(to, key, {
30
- get: ((k) => from[k]).bind(null, key),
31
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
32
- });
33
- }
34
- }
19
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
+ key = keys[i];
21
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
+ get: ((k) => from[k]).bind(null, key),
23
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
+ });
35
25
  }
36
26
  return to;
37
27
  };
@@ -40,6 +30,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
40
30
  enumerable: true
41
31
  }) : target, mod));
42
32
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
43
-
44
- //#endregion
45
- export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };
33
+ export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };
package/dist/_dev.d.mts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { HTTPHandler } from "h3";
2
2
  import { Nitro } from "nitro/types";
3
-
4
- //#region src/dev/app.d.ts
5
3
  declare class NitroDevApp {
6
4
  #private;
7
5
  nitro: Nitro;
8
6
  fetch: (req: Request) => Response | Promise<Response>;
9
7
  constructor(nitro: Nitro, catchAllHandler?: HTTPHandler);
10
8
  }
11
- //#endregion
12
9
  export { NitroDevApp as t };