nitro 3.0.260311-beta → 3.0.260429-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 (211) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md +32 -2
  2. package/dist/_build/common.mjs +669 -1627
  3. package/dist/_build/rolldown.mjs +1 -12
  4. package/dist/_build/rollup.mjs +2 -15
  5. package/dist/_build/vite.build.mjs +1 -3
  6. package/dist/_chunks/nitro.mjs +28 -221
  7. package/dist/_chunks/nitro2.mjs +1 -3
  8. package/dist/_chunks/nitro3.mjs +128 -121
  9. package/dist/_chunks/nitro4.mjs +127 -0
  10. package/dist/_chunks/utils.mjs +2 -9
  11. package/dist/_common.mjs +1 -3
  12. package/dist/_dev.d.mts +0 -3
  13. package/dist/_dev.mjs +3 -12
  14. package/dist/_libs/c12+rc9.mjs +45 -31
  15. package/dist/_libs/c12+readdirp+chokidar.d.mts +0 -7
  16. package/dist/_libs/citty.mjs +134 -31
  17. package/dist/_libs/commondir+is-reference.mjs +2 -9
  18. package/dist/_libs/compatx.d.mts +0 -2
  19. package/dist/_libs/compatx.mjs +0 -2
  20. package/dist/_libs/esbuild.d.mts +0 -1
  21. package/dist/_libs/estree+pluginutils.d.mts +0 -5
  22. package/dist/_libs/estree-walker.mjs +3 -88
  23. package/dist/_libs/hasown+resolve+deepmerge.mjs +69 -119
  24. package/dist/_libs/httpxy.d.mts +6 -4
  25. package/dist/_libs/httpxy.mjs +286 -118
  26. package/dist/_libs/klona.mjs +0 -2
  27. package/dist/_libs/magic-string.d.mts +0 -2
  28. package/dist/_libs/mlly.d.mts +0 -2
  29. package/dist/_libs/nypm+tinyexec.mjs +161 -153
  30. package/dist/_libs/perfect-debounce.mjs +0 -20
  31. package/dist/_libs/pkg-types.d.mts +7 -7
  32. package/dist/_libs/plugin-alias.mjs +0 -2
  33. package/dist/_libs/plugin-inject.mjs +3 -3
  34. package/dist/_libs/plugin-json.mjs +0 -2
  35. package/dist/_libs/pluginutils.mjs +4 -28
  36. package/dist/_libs/readdirp+chokidar.mjs +2 -174
  37. package/dist/_libs/remapping.mjs +0 -2
  38. package/dist/_libs/resolve-uri+gen-mapping.mjs +0 -32
  39. package/dist/_libs/rou3.d.mts +0 -4
  40. package/dist/_libs/rou3.mjs +0 -29
  41. package/dist/_libs/std-env.d.mts +1 -3
  42. package/dist/_libs/tsconfck.mjs +0 -294
  43. package/dist/_libs/ultrahtml.mjs +0 -2
  44. package/dist/_libs/{unimport+unplugin.mjs → unimport+unplugin+oxc-parser.mjs} +50 -81
  45. package/dist/_libs/unplugin+unimport.d.mts +1 -8
  46. package/dist/_libs/unwasm.d.mts +0 -3
  47. package/dist/_presets.mjs +213 -81
  48. package/dist/builder.d.mts +1 -22
  49. package/dist/builder.mjs +0 -11
  50. package/dist/cli/_chunks/build.mjs +1 -3
  51. package/dist/cli/_chunks/common.mjs +0 -2
  52. package/dist/cli/_chunks/deploy.mjs +1 -4
  53. package/dist/cli/_chunks/dev.mjs +1 -6
  54. package/dist/cli/_chunks/docs.mjs +1 -3
  55. package/dist/cli/_chunks/list.mjs +1 -3
  56. package/dist/cli/_chunks/prepare.mjs +1 -3
  57. package/dist/cli/_chunks/preview.mjs +2 -5
  58. package/dist/cli/_chunks/run.mjs +1 -3
  59. package/dist/cli/_chunks/task.mjs +0 -2
  60. package/dist/cli/index.mjs +0 -2
  61. package/{skills/nitro/docs/docs/quick-start.md → dist/docs/0.docs/1.quick-start.md} +4 -4
  62. package/{skills/nitro/docs/docs/lifecycle.md → dist/docs/0.docs/10.lifecycle.md} +4 -4
  63. package/dist/docs/0.docs/11.openapi.md +291 -0
  64. package/{skills/nitro/docs/docs/plugins.md → dist/docs/0.docs/12.plugins.md} +2 -2
  65. package/{skills/nitro/docs/docs/tasks.md → dist/docs/0.docs/13.tasks.md} +6 -6
  66. package/dist/docs/0.docs/14.websocket.md +386 -0
  67. package/{skills/nitro/docs/docs/migration.md → dist/docs/0.docs/15.migration.md} +2 -4
  68. package/{skills/nitro/docs/docs/renderer.md → dist/docs/0.docs/2.renderer.md} +8 -8
  69. package/{skills/nitro/docs/docs/routing.md → dist/docs/0.docs/3.routing.md} +34 -34
  70. package/{skills/nitro/docs/docs/server-entry.md → dist/docs/0.docs/4.server-entry.md} +6 -6
  71. package/{skills/nitro/docs/docs/cache.md → dist/docs/0.docs/5.cache.md} +65 -21
  72. package/{skills/nitro/docs/docs/storage.md → dist/docs/0.docs/6.storage.md} +6 -6
  73. package/{skills/nitro/docs/docs/assets.md → dist/docs/0.docs/7.assets.md} +8 -8
  74. package/{skills/nitro/docs/docs/configuration.md → dist/docs/0.docs/8.configuration.md} +16 -16
  75. package/{skills/nitro/docs/docs/database.md → dist/docs/0.docs/9.database.md} +6 -6
  76. package/{skills/nitro/docs/deploy → dist/docs/1.deploy/0.index}/index.md +3 -3
  77. package/{skills/nitro/docs/deploy/providers/aws.md → dist/docs/1.deploy/2.providers/1.aws.md} +4 -4
  78. package/{skills/nitro/docs/deploy/providers/iis.md → dist/docs/1.deploy/2.providers/15.iis.md} +2 -2
  79. package/{skills/nitro/docs/deploy/providers/aws-amplify.md → dist/docs/1.deploy/2.providers/2.aws-amplify.md} +2 -2
  80. package/{skills/nitro/docs/deploy/providers/vercel.md → dist/docs/1.deploy/2.providers/21.vercel.md} +98 -7
  81. package/{skills/nitro/docs/deploy/providers/zephyr.md → dist/docs/1.deploy/2.providers/23.zephyr.md} +2 -2
  82. package/{skills/nitro/docs/deploy/providers/cloudflare.md → dist/docs/1.deploy/2.providers/5.cloudflare.md} +9 -15
  83. package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
  84. package/{skills/nitro/docs/config → dist/docs/2.config/0.index}/index.md +165 -91
  85. package/{skills/nitro/docs/examples/hono.md → dist/docs/3.examples/10.hono.md} +1 -1
  86. package/{skills/nitro/docs/examples/import-alias.md → dist/docs/3.examples/11.import-alias.md} +1 -4
  87. package/{skills/nitro/docs/examples/mono-jsx.md → dist/docs/3.examples/13.mono-jsx.md} +2 -2
  88. package/{skills/nitro/docs/examples/plugins.md → dist/docs/3.examples/15.plugins.md} +4 -4
  89. package/{skills/nitro/docs/examples/shiki.md → dist/docs/3.examples/19.shiki.md} +1 -1
  90. package/{skills/nitro/docs/examples/auto-imports.md → dist/docs/3.examples/2.auto-imports.md} +0 -1
  91. package/{skills/nitro/docs/examples/vite-nitro-plugin.md → dist/docs/3.examples/21.vite-nitro-plugin.md} +1 -1
  92. package/{skills/nitro/docs/examples/vite-rsc.md → dist/docs/3.examples/22.vite-rsc.md} +4 -4
  93. package/{skills/nitro/docs/examples/vite-ssr-html.md → dist/docs/3.examples/23.vite-ssr-html.md} +3 -3
  94. package/{skills/nitro/docs/examples/vite-ssr-preact.md → dist/docs/3.examples/24.vite-ssr-preact.md} +6 -6
  95. package/{skills/nitro/docs/examples/vite-ssr-react.md → dist/docs/3.examples/25.vite-ssr-react.md} +3 -3
  96. package/{skills/nitro/docs/examples/vite-ssr-solid.md → dist/docs/3.examples/26.vite-ssr-solid.md} +3 -3
  97. package/{skills/nitro/docs/examples/vite-ssr-tsr-react.md → dist/docs/3.examples/27.vite-ssr-tsr-react.md} +6 -6
  98. package/{skills/nitro/docs/examples/vite-ssr-tss-react.md → dist/docs/3.examples/28.vite-ssr-tss-react.md} +11 -11
  99. package/{skills/nitro/docs/examples/vite-ssr-vue-router.md → dist/docs/3.examples/29.vite-ssr-vue-router.md} +6 -5
  100. package/{skills/nitro/docs/examples/vite-trpc.md → dist/docs/3.examples/30.vite-trpc.md} +3 -3
  101. package/{skills/nitro/docs/examples/elysia.md → dist/docs/3.examples/6.elysia.md} +1 -1
  102. package/{skills/nitro/docs/examples/fastify.md → dist/docs/3.examples/8.fastify.md} +1 -1
  103. package/dist/docs/README.md +86 -0
  104. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
  105. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  106. package/dist/node_modules/@speed-highlight/core/package.json +1 -1
  107. package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
  108. package/dist/node_modules/cookie-es/package.json +26 -23
  109. package/dist/node_modules/defu/dist/defu.mjs +2 -2
  110. package/dist/node_modules/defu/package.json +33 -28
  111. package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
  112. package/dist/node_modules/rendu/dist/index.mjs +5 -112
  113. package/dist/node_modules/rendu/package.json +25 -24
  114. package/dist/node_modules/ufo/dist/index.mjs +2 -2
  115. package/dist/node_modules/ufo/package.json +9 -9
  116. package/dist/node_modules/youch/package.json +2 -2
  117. package/dist/presets/_nitro/runtime/nitro-dev.mjs +3 -1
  118. package/dist/presets/_nitro/runtime/service-worker.mjs +1 -1
  119. package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
  120. package/dist/presets/azure/runtime/_utils.mjs +5 -5
  121. package/dist/presets/azure/runtime/azure-swa.mjs +7 -5
  122. package/dist/presets/bun/runtime/bun.mjs +5 -3
  123. package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
  124. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
  125. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
  126. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
  127. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
  128. package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
  129. package/dist/presets/deno/runtime/deno-server.mjs +5 -3
  130. package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
  131. package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -2
  132. package/dist/presets/node/runtime/node-cluster.mjs +2 -2
  133. package/dist/presets/node/runtime/node-middleware.mjs +1 -1
  134. package/dist/presets/node/runtime/node-server.mjs +5 -3
  135. package/dist/presets/stormkit/runtime/stormkit.mjs +1 -1
  136. package/dist/presets/vercel/runtime/cron-handler.mjs +1 -1
  137. package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
  138. package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
  139. package/dist/presets/vercel/runtime/vercel.web.mjs +1 -1
  140. package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
  141. package/dist/runtime/internal/app.mjs +12 -11
  142. package/dist/runtime/internal/context.mjs +1 -9
  143. package/dist/runtime/internal/error/dev.mjs +10 -10
  144. package/dist/runtime/internal/route-rules.d.mts +4 -1
  145. package/dist/runtime/internal/route-rules.mjs +38 -8
  146. package/dist/runtime/internal/routes/dev-tasks.mjs +13 -12
  147. package/dist/runtime/internal/routes/openapi.mjs +2 -2
  148. package/dist/runtime/internal/routes/scalar.mjs +4 -3
  149. package/dist/runtime/internal/routes/swagger.mjs +7 -4
  150. package/dist/runtime/internal/runtime-config.mjs +2 -2
  151. package/dist/runtime/internal/task.mjs +5 -5
  152. package/dist/runtime/meta.d.mts +1 -0
  153. package/dist/runtime/meta.mjs +1 -0
  154. package/dist/runtime/nitro.mjs +3 -3
  155. package/dist/runtime/virtual/renderer-template.mjs +1 -1
  156. package/dist/runtime/virtual/tracing.d.mts +5 -0
  157. package/dist/runtime/virtual/tracing.mjs +1 -0
  158. package/dist/types/index.d.mts +1074 -147
  159. package/dist/vite.d.mts +1 -6
  160. package/dist/vite.mjs +67 -32
  161. package/lib/tsconfig.json +3 -5
  162. package/package.json +62 -59
  163. package/dist/_libs/_.mjs +0 -3
  164. package/dist/_libs/_2.mjs +0 -2
  165. package/dist/_libs/_3.mjs +0 -3
  166. package/dist/_libs/_4.mjs +0 -2
  167. package/dist/_libs/_5.mjs +0 -3
  168. package/dist/_libs/_6.mjs +0 -4
  169. package/dist/_libs/_7.mjs +0 -5
  170. package/dist/_libs/escape-string-regexp.mjs +0 -7
  171. package/skills/nitro/SKILL.md +0 -10
  172. package/skills/nitro/docs/TOC.md +0 -83
  173. package/skills/nitro/docs/_navigation.json +0 -679
  174. /package/{skills/nitro/docs/docs → dist/docs/0.docs/0.index}/index.md +0 -0
  175. /package/{skills/nitro/docs/docs/nightly.md → dist/docs/0.docs/16.nightly.md} +0 -0
  176. /package/{skills/nitro/docs/deploy/runtimes/node.md → dist/docs/1.deploy/1.runtimes/0.node.md} +0 -0
  177. /package/{skills/nitro/docs/deploy/runtimes/bun.md → dist/docs/1.deploy/1.runtimes/1.bun.md} +0 -0
  178. /package/{skills/nitro/docs/deploy/runtimes/deno.md → dist/docs/1.deploy/1.runtimes/2.deno.md} +0 -0
  179. /package/{skills/nitro/docs/deploy/providers/alwaysdata.md → dist/docs/1.deploy/2.providers/0.alwaysdata.md} +0 -0
  180. /package/{skills/nitro/docs/deploy/providers/flightcontrol.md → dist/docs/1.deploy/2.providers/10.flightcontrol.md} +0 -0
  181. /package/{skills/nitro/docs/deploy/providers/genezio.md → dist/docs/1.deploy/2.providers/11.genezio.md} +0 -0
  182. /package/{skills/nitro/docs/deploy/providers/github-pages.md → dist/docs/1.deploy/2.providers/12.github-pages.md} +0 -0
  183. /package/{skills/nitro/docs/deploy/providers/gitlab-pages.md → dist/docs/1.deploy/2.providers/13.gitlab-pages.md} +0 -0
  184. /package/{skills/nitro/docs/deploy/providers/heroku.md → dist/docs/1.deploy/2.providers/14.heroku.md} +0 -0
  185. /package/{skills/nitro/docs/deploy/providers/koyeb.md → dist/docs/1.deploy/2.providers/16.koyeb.md} +0 -0
  186. /package/{skills/nitro/docs/deploy/providers/netlify.md → dist/docs/1.deploy/2.providers/17.netlify.md} +0 -0
  187. /package/{skills/nitro/docs/deploy/providers/platform-sh.md → dist/docs/1.deploy/2.providers/18.platform-sh.md} +0 -0
  188. /package/{skills/nitro/docs/deploy/providers/render.md → dist/docs/1.deploy/2.providers/19.render.md} +0 -0
  189. /package/{skills/nitro/docs/deploy/providers/stormkit.md → dist/docs/1.deploy/2.providers/20.stormkit.md} +0 -0
  190. /package/{skills/nitro/docs/deploy/providers/zeabur.md → dist/docs/1.deploy/2.providers/22.zeabur.md} +0 -0
  191. /package/{skills/nitro/docs/deploy/providers/zerops.md → dist/docs/1.deploy/2.providers/24.zerops.md} +0 -0
  192. /package/{skills/nitro/docs/deploy/providers/azure.md → dist/docs/1.deploy/2.providers/3.azure.md} +0 -0
  193. /package/{skills/nitro/docs/deploy/providers/cleavr.md → dist/docs/1.deploy/2.providers/4.cleavr.md} +0 -0
  194. /package/{skills/nitro/docs/deploy/providers/deno-deploy.md → dist/docs/1.deploy/2.providers/6.deno-deploy.md} +0 -0
  195. /package/{skills/nitro/docs/deploy/providers/digitalocean.md → dist/docs/1.deploy/2.providers/7.digitalocean.md} +0 -0
  196. /package/{skills/nitro/docs/deploy/providers/firebase.md → dist/docs/1.deploy/2.providers/9.firebase.md} +0 -0
  197. /package/{skills/nitro/docs/examples → dist/docs/3.examples/0.index}/index.md +0 -0
  198. /package/{skills/nitro/docs/examples/api-routes.md → dist/docs/3.examples/1.api-routes.md} +0 -0
  199. /package/{skills/nitro/docs/examples/middleware.md → dist/docs/3.examples/12.middleware.md} +0 -0
  200. /package/{skills/nitro/docs/examples/nano-jsx.md → dist/docs/3.examples/14.nano-jsx.md} +0 -0
  201. /package/{skills/nitro/docs/examples/renderer.md → dist/docs/3.examples/16.renderer.md} +0 -0
  202. /package/{skills/nitro/docs/examples/runtime-config.md → dist/docs/3.examples/17.runtime-config.md} +0 -0
  203. /package/{skills/nitro/docs/examples/server-fetch.md → dist/docs/3.examples/18.server-fetch.md} +0 -0
  204. /package/{skills/nitro/docs/examples/virtual-routes.md → dist/docs/3.examples/20.virtual-routes.md} +0 -0
  205. /package/{skills/nitro/docs/examples/cached-handler.md → dist/docs/3.examples/3.cached-handler.md} +0 -0
  206. /package/{skills/nitro/docs/examples/websocket.md → dist/docs/3.examples/31.websocket.md} +0 -0
  207. /package/{skills/nitro/docs/examples/custom-error-handler.md → dist/docs/3.examples/4.custom-error-handler.md} +0 -0
  208. /package/{skills/nitro/docs/examples/database.md → dist/docs/3.examples/5.database.md} +0 -0
  209. /package/{skills/nitro/docs/examples/express.md → dist/docs/3.examples/7.express.md} +0 -0
  210. /package/{skills/nitro/docs/examples/hello-world.md → dist/docs/3.examples/9.hello-world.md} +0 -0
  211. /package/{skills/nitro → dist}/docs/index.md +0 -0
@@ -1,129 +1,136 @@
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
- //#region src/preview.ts
6
- async function startPreview(opts) {
7
- const { outputDir, buildInfo } = await getBuildInfo(opts.rootDir);
8
- if (!buildInfo) throw new Error("Cannot load nitro build info. Make sure to build first.");
9
- const info = [
10
- ["Build Directory:", prettyPath(outputDir)],
11
- ["Date:", buildInfo.date && new Date(buildInfo.date).toLocaleString()],
12
- ["Nitro Version:", buildInfo.versions.nitro],
13
- ["Nitro Preset:", buildInfo.preset],
14
- buildInfo.framework?.name !== "nitro" && ["Framework:", buildInfo.framework?.name + (buildInfo.framework?.version ? ` (v${buildInfo.framework.version})` : "")]
15
- ].filter((i) => i && i[1]);
16
- consola.box({
17
- title: " [Build Info] ",
18
- message: info.map((i) => `- ${i[0]} ${i[1]}`).join("\n")
19
- });
20
- const dotEnvEntries = await loadPreviewDotEnv(opts.rootDir);
21
- if (dotEnvEntries.length > 0) consola.box({
22
- title: " [Environment Variables] ",
23
- message: [
24
- "Loaded variables from .env files (preview mode only).",
25
- "Set platform environment variables for production:",
26
- ...dotEnvEntries.map(([key, val]) => ` - ${key}`)
27
- ].join("\n")
28
- });
29
- if (buildInfo.preset.includes("cloudflare")) {
30
- if (!buildInfo.commands?.preview) throw new Error(`No nitro build preview command found for the "${buildInfo.preset}" preset.`);
31
- return await runPreviewCommand({
32
- command: buildInfo.commands.preview,
33
- rootDir: opts.rootDir,
34
- env: dotEnvEntries
1
+ import { lt 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
35
46
  });
36
- }
37
- let fetchHandler = () => Promise.resolve(new Response("Not Found", { status: 404 }));
38
- if (buildInfo.serverEntry) {
39
- for (const [key, val] of dotEnvEntries) if (!process.env[key]) process.env[key] = val;
40
- const { loadServerEntry } = await import("srvx/loader");
41
- const entry = await loadServerEntry({
42
- entry: resolve(outputDir, buildInfo.serverEntry),
43
- ...opts.loader
47
+ if (nitro.options.renderer?.handler) _routes.push({
48
+ route: "/**",
49
+ lazy: true,
50
+ handler: nitro.options.renderer?.handler
44
51
  });
45
- if (entry.fetch) fetchHandler = entry.fetch;
46
- }
47
- if (buildInfo.publicDir) {
48
- const { serveStatic } = await import("srvx/static");
49
- const staticHandler = serveStatic({ dir: join(outputDir, buildInfo.publicDir) });
50
- const originalFetchHandler = fetchHandler;
51
- fetchHandler = async (req) => {
52
- const staticRes = await staticHandler(req, () => void 0);
53
- if (staticRes) return staticRes;
54
- return originalFetchHandler(req);
55
- };
56
- }
57
- return {
58
- fetch: fetchHandler,
59
- async close() {}
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
+ })));
60
69
  };
61
- }
62
- async function loadPreviewDotEnv(root) {
63
- const { loadDotenv } = await import("../_libs/_.mjs");
64
- const env = await loadDotenv({
65
- cwd: root,
66
- fileName: [
67
- ".env.preview",
68
- ".env.production",
69
- ".env"
70
- ]
70
+ nitro.routing = Object.freeze({
71
+ sync,
72
+ routes,
73
+ routeRules,
74
+ globalMiddleware,
75
+ routedMiddleware
71
76
  });
72
- return Object.entries(env).filter(([_key, val]) => val);
73
77
  }
74
- async function runPreviewCommand(opts) {
75
- const [arg0, ...args] = opts.command.split(" ");
76
- consola.info(`Spawning preview server...`);
77
- consola.info(opts.command);
78
- console.log("");
79
- const { getRandomPort, waitForPort } = await import("get-port-please");
80
- const randomPort = await getRandomPort();
81
- const child = spawn(arg0, [
82
- ...args,
83
- "--port",
84
- String(randomPort),
85
- "--host",
86
- "localhost"
87
- ], {
88
- stdio: "inherit",
89
- cwd: opts.rootDir,
90
- env: {
91
- ...process.env,
92
- ...Object.fromEntries(opts.env ?? []),
93
- PORT: String(randomPort)
94
- }
95
- });
96
- const killChild = (signal) => {
97
- if (child && !child.killed) child.kill(signal);
98
- };
99
- for (const sig of ["SIGINT", "SIGHUP"]) process.once(sig, () => {
100
- killChild(sig);
101
- });
102
- child.once("exit", (code) => {
103
- if (code && code !== 0) consola.error(`[nitro] Preview server exited with code ${code}`);
104
- });
105
- await waitForPort(randomPort, {
106
- retries: 20,
107
- delay: 500,
108
- host: "localhost"
109
- });
78
+ function handlerWithImportHash(h) {
79
+ const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
110
80
  return {
111
- fetch(req) {
112
- return proxyFetch({
113
- port: randomPort,
114
- host: "localhost"
115
- }, req);
116
- },
117
- async upgrade(req, socket, head, opts) {
118
- await proxyUpgrade({
119
- port: randomPort,
120
- host: "localhost"
121
- }, req, socket, head, opts);
122
- },
123
- async close() {
124
- killChild("SIGTERM");
125
- }
81
+ ...h,
82
+ _importHash: id
126
83
  };
127
84
  }
128
- //#endregion
129
- export { startPreview as t };
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, ft as resolve, lt as join, 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/c12+rc9.mjs").then((n) => n.n);
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,5 +1,5 @@
1
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";
2
+ import { H as m, M as glob, U as v, dt as relative, ft as resolve, ot as dirname, p as runParallel, rt as resolveModulePath } from "../_build/common.mjs";
3
3
  import { consola as consola$1 } from "consola";
4
4
  import { promises } from "node:fs";
5
5
  import { promisify } from "node:util";
@@ -79,8 +79,6 @@ async function gzipSize(input, options) {
79
79
  if (!input) return 0;
80
80
  return (await gzip(input, getOptions(options))).length;
81
81
  }
82
- //#endregion
83
- //#region node_modules/.pnpm/pretty-bytes@7.1.0/node_modules/pretty-bytes/index.js
84
82
  const BYTE_UNITS = [
85
83
  "B",
86
84
  "kB",
@@ -193,8 +191,6 @@ function prettyBytes(number, options) {
193
191
  }
194
192
  return applyFixedWidth(result, options.fixedWidth);
195
193
  }
196
- //#endregion
197
- //#region src/utils/fs-tree.ts
198
194
  async function generateFSTree(dir, options = {}) {
199
195
  if (v) return;
200
196
  const files = await glob("**/*.*", {
@@ -241,8 +237,6 @@ async function generateFSTree(dir, options = {}) {
241
237
  treeText += "\n";
242
238
  return treeText;
243
239
  }
244
- //#endregion
245
- //#region src/utils/dep.ts
246
240
  async function importDep(opts, _retry) {
247
241
  const resolved = resolveModulePath(opts.id, {
248
242
  from: [opts.dir, import.meta.url],
@@ -263,10 +257,9 @@ async function importDep(opts, _retry) {
263
257
  if (!shouldInstall) throw new Error(`\`${opts.id}\` is not installed. Please add it to your dependencies for ${opts.reason}.`);
264
258
  const start = Date.now();
265
259
  consola$1.start(`Installing \`${opts.id}\` in \`${opts.dir}\`...`);
266
- const { addDevDependency } = await import("../_libs/_5.mjs");
260
+ const { addDevDependency } = await import("../_libs/nypm+tinyexec.mjs").then((n) => n.t);
267
261
  await addDevDependency(opts.id, { cwd: opts.dir });
268
262
  consola$1.success(`Installed \`${opts.id}\` in ${opts.dir} (${Date.now() - start}ms).`);
269
263
  return importDep(opts, true);
270
264
  }
271
- //#endregion
272
265
  export { generateFSTree as n, importDep as t };
package/dist/_common.mjs CHANGED
@@ -1,12 +1,11 @@
1
1
  import { createRequire } from "node:module";
2
- //#region \0rolldown/runtime.js
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getProtoOf = Object.getPrototypeOf;
8
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
8
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
10
9
  var __exportAll = (all, no_symbols) => {
11
10
  let target = {};
12
11
  for (var name in all) __defProp(target, name, {
@@ -31,5 +30,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
30
  enumerable: true
32
31
  }) : target, mod));
33
32
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
34
- //#endregion
35
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 };
package/dist/_dev.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as src_default, H as v, V as m, ct as join$1, dt as resolve$1, g as writeDevBuildInfo, ot as extname$1 } from "./_build/common.mjs";
1
+ import { A as src_default, H as m, U as v, ft as resolve$1, g as writeDevBuildInfo, lt as join$1, st as extname$1 } from "./_build/common.mjs";
2
2
  import { n as watch$1 } from "./_libs/readdirp+chokidar.mjs";
3
3
  import { t as debounce } from "./_libs/perfect-debounce.mjs";
4
4
  import { t as createProxyServer } from "./_libs/httpxy.mjs";
@@ -12,12 +12,12 @@ import { RunnerManager, loadRunner } from "env-runner";
12
12
  import { H3, HTTPError, defineHandler, fromNodeHandler, getRequestIP, getRequestURL, serveStatic, toEventHandler } from "h3";
13
13
  import { serve } from "srvx/node";
14
14
  import { FastResponse } from "srvx";
15
- //#region src/dev/vfs.ts
16
15
  function createVFSHandler(nitro) {
17
16
  return defineHandler(async (event) => {
18
17
  const { socket } = event.runtime?.node?.req || {};
19
18
  const ip = getRequestIP(event, { xForwardedFor: !socket?.remoteAddress && !socket?.localAddress && Object.keys(socket?.address?.() || {}).length === 0 && socket?.readable && socket?.writable && !socket?.remotePort });
20
- if (!(ip && /^::1$|^127\.\d+\.\d+\.\d+$/.test(ip))) throw new HTTPError({
19
+ const v4 = ip?.toLowerCase().startsWith("::ffff:") ? ip.slice(7) : ip;
20
+ if (!(v4 && /^(?:::1|127\.\d+\.\d+\.\d+)$/.test(v4))) throw new HTTPError({
21
21
  statusText: `Forbidden IP: "${ip || "?"}"`,
22
22
  status: 403
23
23
  });
@@ -142,13 +142,9 @@ const editorTemplate = (options) => `
142
142
  }, 0);
143
143
  <\/script>
144
144
  `;
145
- //#endregion
146
- //#region src/runtime/internal/error/utils.ts
147
145
  function defineNitroErrorHandler(handler) {
148
146
  return handler;
149
147
  }
150
- //#endregion
151
- //#region src/runtime/internal/error/dev.ts
152
148
  const errorHandler = defineNitroErrorHandler(async function defaultNitroErrorHandler(error, event) {
153
149
  const res = await defaultHandler(error, event);
154
150
  return new FastResponse(typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2), res);
@@ -241,8 +237,6 @@ function fmtFrame(frame) {
241
237
  const src = `${frame.fileName || ""}:${frame.lineNumber}:${frame.columnNumber})`;
242
238
  return frame.functionName ? `at ${frame.functionName} (${src}` : `at ${src}`;
243
239
  }
244
- //#endregion
245
- //#region src/dev/app.ts
246
240
  var NitroDevApp = class {
247
241
  nitro;
248
242
  fetch;
@@ -354,8 +348,6 @@ function createHTTPProxy(defaults = {}) {
354
348
  }
355
349
  };
356
350
  }
357
- //#endregion
358
- //#region src/dev/server.ts
359
351
  function createDevServer(nitro) {
360
352
  return new NitroDevServer(nitro);
361
353
  }
@@ -515,5 +507,4 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
515
507
  });
516
508
  }
517
509
  };
518
- //#endregion
519
510
  export { createDevServer as n, NitroDevApp as r, NitroDevServer as t };