nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-122334-09c1a7a8

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 (334) hide show
  1. package/dist/_build/common.mjs +763 -0
  2. package/dist/_build/rolldown.mjs +216 -0
  3. package/dist/_build/rollup.mjs +359 -0
  4. package/dist/_build/vite.build.mjs +67 -0
  5. package/dist/_build/vite.plugin.mjs +762 -0
  6. package/dist/_chunks/B-7HiF0V.mjs +1303 -0
  7. package/dist/_chunks/B3asVbT4.mjs +151 -0
  8. package/dist/_chunks/B5ooyfLk.mjs +372 -0
  9. package/dist/_chunks/DXMHy5ca.mjs +43 -0
  10. package/dist/_dev.d.mts +12 -0
  11. package/dist/_dev.mjs +675 -0
  12. package/dist/_libs/acorn.mjs +5034 -0
  13. package/dist/_libs/c12.mjs +2798 -0
  14. package/dist/_libs/chokidar.mjs +1560 -0
  15. package/dist/_libs/citty.mjs +333 -0
  16. package/dist/_libs/commondir.mjs +22 -0
  17. package/dist/_libs/compatx.mjs +46 -0
  18. package/dist/_libs/confbox.mjs +2920 -0
  19. package/dist/_libs/debug.mjs +848 -0
  20. package/dist/_libs/deepmerge.mjs +86 -0
  21. package/dist/_libs/depd.mjs +314 -0
  22. package/dist/_libs/dot-prop.mjs +138 -0
  23. package/dist/_libs/duplexer.mjs +71 -0
  24. package/dist/_libs/ee-first.mjs +68 -0
  25. package/dist/_libs/encodeurl.mjs +49 -0
  26. package/dist/_libs/escape-html.mjs +58 -0
  27. package/dist/_libs/escape-string-regexp.mjs +8 -0
  28. package/dist/_libs/estree-walker.mjs +330 -0
  29. package/dist/_libs/etag.mjs +75 -0
  30. package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
  31. package/dist/_libs/fresh.mjs +85 -0
  32. package/dist/_libs/function-bind.mjs +63 -0
  33. package/dist/_libs/gen-mapping.mjs +612 -0
  34. package/dist/_libs/giget.mjs +19076 -0
  35. package/dist/_libs/gzip-size.mjs +21 -0
  36. package/dist/_libs/hasown.mjs +14 -0
  37. package/dist/_libs/http-errors.mjs +436 -0
  38. package/dist/_libs/httpxy.mjs +410 -0
  39. package/dist/_libs/is-core-module.mjs +220 -0
  40. package/dist/_libs/is-module.mjs +13 -0
  41. package/dist/_libs/is-reference.mjs +32 -0
  42. package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
  43. package/dist/_libs/klona.mjs +90 -0
  44. package/dist/_libs/knitwork.mjs +124 -0
  45. package/dist/_libs/local-pkg.mjs +1686 -0
  46. package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
  47. package/dist/_libs/mime-db.mjs +7642 -0
  48. package/dist/_libs/mime-types.mjs +162 -0
  49. package/dist/_libs/mime.mjs +1391 -0
  50. package/dist/_libs/node-fetch-native.mjs +173 -0
  51. package/dist/_libs/on-finished.mjs +170 -0
  52. package/dist/_libs/parseurl.mjs +103 -0
  53. package/dist/_libs/path-parse.mjs +47 -0
  54. package/dist/_libs/pathe.mjs +41 -0
  55. package/dist/_libs/picomatch.mjs +1673 -0
  56. package/dist/_libs/plugin-alias.mjs +64 -0
  57. package/dist/_libs/plugin-commonjs.mjs +1489 -0
  58. package/dist/_libs/plugin-inject.mjs +135 -0
  59. package/dist/_libs/plugin-json.mjs +36 -0
  60. package/dist/_libs/plugin-node-resolve.mjs +1553 -0
  61. package/dist/_libs/plugin-replace.mjs +104 -0
  62. package/dist/_libs/pretty-bytes.mjs +116 -0
  63. package/dist/_libs/range-parser.mjs +102 -0
  64. package/dist/_libs/remapping.mjs +117 -0
  65. package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
  66. package/dist/_libs/send.mjs +857 -0
  67. package/dist/_libs/serve-static.mjs +124 -0
  68. package/dist/_libs/std-env.mjs +158 -0
  69. package/dist/_libs/strip-literal.mjs +51 -0
  70. package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
  71. package/dist/_libs/ultrahtml.mjs +138 -0
  72. package/dist/_libs/unimport.mjs +3520 -0
  73. package/dist/_libs/untyped.mjs +271 -0
  74. package/dist/_libs/unwasm.mjs +5825 -0
  75. package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
  76. package/dist/_presets.mjs +1723 -0
  77. package/dist/builder.d.mts +37 -35
  78. package/dist/builder.mjs +45 -117
  79. package/dist/cli/_chunks/build.mjs +43 -0
  80. package/dist/cli/_chunks/common.mjs +15 -0
  81. package/dist/cli/_chunks/detect-acorn.mjs +12 -0
  82. package/dist/cli/_chunks/dev.mjs +79 -0
  83. package/dist/cli/_chunks/dist.mjs +3 -0
  84. package/dist/cli/_chunks/dist2.mjs +4 -0
  85. package/dist/cli/_chunks/esm.mjs +3 -0
  86. package/dist/cli/_chunks/json5.mjs +4 -0
  87. package/dist/cli/_chunks/jsonc.mjs +4 -0
  88. package/dist/cli/_chunks/list.mjs +27 -0
  89. package/dist/cli/_chunks/multipart-parser.mjs +6 -0
  90. package/dist/cli/_chunks/prepare.mjs +19 -0
  91. package/dist/cli/_chunks/run.mjs +55 -0
  92. package/dist/cli/_chunks/task.mjs +16 -0
  93. package/dist/cli/_chunks/toml.mjs +4 -0
  94. package/dist/cli/_chunks/yaml.mjs +4 -0
  95. package/dist/cli/index.d.mts +1 -1
  96. package/dist/cli/index.mjs +19 -18
  97. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
  98. package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
  99. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
  100. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
  101. package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
  102. package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
  103. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
  104. package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
  105. package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
  106. package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
  107. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
  108. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
  109. package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
  110. package/dist/presets/azure/runtime/_utils.mjs +43 -43
  111. package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
  112. package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
  113. package/dist/presets/bun/runtime/bun.d.mts +1 -0
  114. package/dist/presets/bun/runtime/bun.mjs +18 -17
  115. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
  116. package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
  117. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
  118. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
  119. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
  120. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
  121. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
  122. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
  123. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
  124. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
  125. package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
  126. package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
  127. package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
  128. package/dist/presets/deno/runtime/deno-server.mjs +31 -39
  129. package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
  130. package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
  131. package/dist/presets/netlify/runtime/netlify.mjs +11 -17
  132. package/dist/presets/node/runtime/node-cluster.mjs +49 -48
  133. package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
  134. package/dist/presets/node/runtime/node-middleware.mjs +7 -6
  135. package/dist/presets/node/runtime/node-server.mjs +33 -23
  136. package/dist/presets/standard/runtime/server.d.mts +1 -3
  137. package/dist/presets/standard/runtime/server.mjs +1 -3
  138. package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
  139. package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
  140. package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
  141. package/dist/presets/vercel/runtime/vercel.mjs +15 -14
  142. package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
  143. package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
  144. package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
  145. package/dist/runtime/index.d.mts +12 -1
  146. package/dist/runtime/index.mjs +12 -7
  147. package/dist/runtime/internal/app.mjs +175 -162
  148. package/dist/runtime/internal/cache.d.mts +10 -4
  149. package/dist/runtime/internal/cache.mjs +247 -216
  150. package/dist/runtime/internal/context.d.mts +9 -9
  151. package/dist/runtime/internal/context.mjs +17 -10
  152. package/dist/runtime/internal/database.mjs +8 -10
  153. package/dist/runtime/internal/error/dev.d.mts +5 -4
  154. package/dist/runtime/internal/error/dev.mjs +106 -105
  155. package/dist/runtime/internal/error/prod.d.mts +2 -2
  156. package/dist/runtime/internal/error/prod.mjs +48 -52
  157. package/dist/runtime/internal/error/utils.d.mts +4 -4
  158. package/dist/runtime/internal/error/utils.mjs +1 -1
  159. package/dist/runtime/internal/index.d.mts +2 -0
  160. package/dist/runtime/internal/index.mjs +2 -0
  161. package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
  162. package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
  163. package/dist/runtime/internal/meta.d.mts +1 -1
  164. package/dist/runtime/internal/meta.mjs +1 -1
  165. package/dist/runtime/internal/plugin.d.mts +2 -2
  166. package/dist/runtime/internal/plugin.mjs +1 -1
  167. package/dist/runtime/internal/renderer.mjs +39 -31
  168. package/dist/runtime/internal/route-rules.d.mts +8 -8
  169. package/dist/runtime/internal/route-rules.mjs +53 -51
  170. package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
  171. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
  172. package/dist/runtime/internal/routes/openapi.d.mts +1 -0
  173. package/dist/runtime/internal/routes/openapi.mjs +81 -87
  174. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  175. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
  176. package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
  177. package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
  178. package/dist/runtime/internal/routes/scalar.d.mts +1 -0
  179. package/dist/runtime/internal/routes/scalar.mjs +22 -23
  180. package/dist/runtime/internal/routes/swagger.d.mts +1 -0
  181. package/dist/runtime/internal/routes/swagger.mjs +9 -11
  182. package/dist/runtime/internal/runtime-config.d.mts +4 -4
  183. package/dist/runtime/internal/runtime-config.mjs +40 -35
  184. package/dist/runtime/internal/shutdown.d.mts +2 -7
  185. package/dist/runtime/internal/shutdown.mjs +30 -29
  186. package/dist/runtime/internal/static.mjs +63 -74
  187. package/dist/runtime/internal/storage.mjs +2 -2
  188. package/dist/runtime/internal/task.d.mts +6 -6
  189. package/dist/runtime/internal/task.mjs +56 -59
  190. package/dist/runtime/internal/utils.d.mts +1 -1
  191. package/dist/runtime/internal/utils.mjs +4 -10
  192. package/dist/types/index.d.mts +2566 -3851
  193. package/dist/types/index.mjs +1 -1
  194. package/dist/vite.d.mts +61 -51
  195. package/dist/vite.mjs +55 -132
  196. package/package.json +10 -10
  197. package/dist/_build/build.mjs +0 -368
  198. package/dist/_build/build2.mjs +0 -556
  199. package/dist/_build/info.mjs +0 -1002
  200. package/dist/_build/prepare.mjs +0 -1511
  201. package/dist/_build/snapshot.mjs +0 -185
  202. package/dist/_build/vite.mjs +0 -959
  203. package/dist/_build/vite2.mjs +0 -149
  204. package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
  205. package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
  206. package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
  207. package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
  208. package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
  209. package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
  210. package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
  211. package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
  212. package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
  213. package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
  214. package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
  215. package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
  216. package/dist/_chunks/_deps/acorn.mjs +0 -6225
  217. package/dist/_chunks/_deps/c12.mjs +0 -510
  218. package/dist/_chunks/_deps/chokidar.mjs +0 -1428
  219. package/dist/_chunks/_deps/citty.mjs +0 -460
  220. package/dist/_chunks/_deps/commondir.mjs +0 -77
  221. package/dist/_chunks/_deps/compatx.mjs +0 -76
  222. package/dist/_chunks/_deps/confbox.mjs +0 -300
  223. package/dist/_chunks/_deps/debug.mjs +0 -885
  224. package/dist/_chunks/_deps/deepmerge.mjs +0 -147
  225. package/dist/_chunks/_deps/depd.mjs +0 -550
  226. package/dist/_chunks/_deps/dot-prop.mjs +0 -282
  227. package/dist/_chunks/_deps/dotenv.mjs +0 -555
  228. package/dist/_chunks/_deps/duplexer.mjs +0 -1
  229. package/dist/_chunks/_deps/ee-first.mjs +0 -104
  230. package/dist/_chunks/_deps/encodeurl.mjs +0 -69
  231. package/dist/_chunks/_deps/escape-html.mjs +0 -87
  232. package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
  233. package/dist/_chunks/_deps/estree-walker.mjs +0 -433
  234. package/dist/_chunks/_deps/etag.mjs +0 -147
  235. package/dist/_chunks/_deps/exsolve.mjs +0 -1416
  236. package/dist/_chunks/_deps/fresh.mjs +0 -145
  237. package/dist/_chunks/_deps/function-bind.mjs +0 -106
  238. package/dist/_chunks/_deps/giget.mjs +0 -451
  239. package/dist/_chunks/_deps/gzip-size.mjs +0 -19
  240. package/dist/_chunks/_deps/hasown.mjs +0 -19
  241. package/dist/_chunks/_deps/http-errors.mjs +0 -307
  242. package/dist/_chunks/_deps/httpxy.mjs +0 -580
  243. package/dist/_chunks/_deps/inherits.mjs +0 -57
  244. package/dist/_chunks/_deps/is-core-module.mjs +0 -596
  245. package/dist/_chunks/_deps/is-module.mjs +0 -25
  246. package/dist/_chunks/_deps/is-reference.mjs +0 -31
  247. package/dist/_chunks/_deps/klona.mjs +0 -137
  248. package/dist/_chunks/_deps/knitwork.mjs +0 -172
  249. package/dist/_chunks/_deps/local-pkg.mjs +0 -163
  250. package/dist/_chunks/_deps/mime-db.mjs +0 -11685
  251. package/dist/_chunks/_deps/mime-types.mjs +0 -287
  252. package/dist/_chunks/_deps/mime.mjs +0 -1172
  253. package/dist/_chunks/_deps/mlly.mjs +0 -2413
  254. package/dist/_chunks/_deps/ms.mjs +0 -172
  255. package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
  256. package/dist/_chunks/_deps/nypm.mjs +0 -219
  257. package/dist/_chunks/_deps/on-finished.mjs +0 -246
  258. package/dist/_chunks/_deps/parseurl.mjs +0 -168
  259. package/dist/_chunks/_deps/path-parse.mjs +0 -85
  260. package/dist/_chunks/_deps/pathe.mjs +0 -251
  261. package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
  262. package/dist/_chunks/_deps/picomatch.mjs +0 -2144
  263. package/dist/_chunks/_deps/pkg-types.mjs +0 -247
  264. package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
  265. package/dist/_chunks/_deps/quansync.mjs +0 -99
  266. package/dist/_chunks/_deps/range-parser.mjs +0 -171
  267. package/dist/_chunks/_deps/rc9.mjs +0 -219
  268. package/dist/_chunks/_deps/readdirp.mjs +0 -245
  269. package/dist/_chunks/_deps/resolve.mjs +0 -1260
  270. package/dist/_chunks/_deps/send.mjs +0 -1022
  271. package/dist/_chunks/_deps/serve-static.mjs +0 -228
  272. package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
  273. package/dist/_chunks/_deps/statuses.mjs +0 -457
  274. package/dist/_chunks/_deps/std-env.mjs +0 -3
  275. package/dist/_chunks/_deps/strip-literal.mjs +0 -67
  276. package/dist/_chunks/_deps/supports-color.mjs +0 -44
  277. package/dist/_chunks/_deps/tinyexec.mjs +0 -552
  278. package/dist/_chunks/_deps/toidentifier.mjs +0 -41
  279. package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
  280. package/dist/_chunks/_deps/unimport.mjs +0 -2267
  281. package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
  282. package/dist/_chunks/_deps/unplugin.mjs +0 -1294
  283. package/dist/_chunks/_deps/untyped.mjs +0 -375
  284. package/dist/_chunks/_deps/unwasm.mjs +0 -6959
  285. package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
  286. package/dist/_chunks/_presets/_all.mjs +0 -59
  287. package/dist/_chunks/_presets/_nitro.mjs +0 -74
  288. package/dist/_chunks/_presets/_resolve.mjs +0 -64
  289. package/dist/_chunks/_presets/_static.mjs +0 -69
  290. package/dist/_chunks/_presets/_types.mjs +0 -3
  291. package/dist/_chunks/_presets/_utils.mjs +0 -31
  292. package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
  293. package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
  294. package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
  295. package/dist/_chunks/_presets/azure.mjs +0 -162
  296. package/dist/_chunks/_presets/bun.mjs +0 -19
  297. package/dist/_chunks/_presets/cleavr.mjs +0 -15
  298. package/dist/_chunks/_presets/cloudflare.mjs +0 -608
  299. package/dist/_chunks/_presets/deno.mjs +0 -196
  300. package/dist/_chunks/_presets/digitalocean.mjs +0 -14
  301. package/dist/_chunks/_presets/firebase.mjs +0 -47
  302. package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
  303. package/dist/_chunks/_presets/genezio.mjs +0 -13
  304. package/dist/_chunks/_presets/heroku.mjs +0 -14
  305. package/dist/_chunks/_presets/iis.mjs +0 -194
  306. package/dist/_chunks/_presets/index.mjs +0 -62
  307. package/dist/_chunks/_presets/koyeb.mjs +0 -14
  308. package/dist/_chunks/_presets/netlify.mjs +0 -241
  309. package/dist/_chunks/_presets/node.mjs +0 -54
  310. package/dist/_chunks/_presets/platform.mjs +0 -14
  311. package/dist/_chunks/_presets/render.mjs +0 -14
  312. package/dist/_chunks/_presets/standard.mjs +0 -23
  313. package/dist/_chunks/_presets/stormkit.mjs +0 -18
  314. package/dist/_chunks/_presets/vercel.mjs +0 -375
  315. package/dist/_chunks/_presets/winterjs.mjs +0 -22
  316. package/dist/_chunks/_presets/zeabur.mjs +0 -69
  317. package/dist/_chunks/_presets/zerops.mjs +0 -27
  318. package/dist/_chunks/app.mjs +0 -600
  319. package/dist/_chunks/builder.mjs +0 -648
  320. package/dist/_chunks/server.mjs +0 -256
  321. package/dist/_cli/build.mjs +0 -49
  322. package/dist/_cli/common.mjs +0 -13
  323. package/dist/_cli/dev.mjs +0 -121
  324. package/dist/_cli/index.mjs +0 -16
  325. package/dist/_cli/list.mjs +0 -33
  326. package/dist/_cli/prepare.mjs +0 -23
  327. package/dist/_cli/run.mjs +0 -59
  328. package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
  329. package/dist/runtime/internal/empty.d.mts +0 -0
  330. package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
  331. package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
  332. package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
  333. package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
  334. /package/lib/{indexd.mts → index.d.mts} +0 -0
@@ -1,1511 +0,0 @@
1
- import consola, { consola as consola$1 } from 'consola';
2
- import { Hookable, createDebugger } from 'hookable';
3
- import { w as watchConfig, l as loadConfig } from '../_chunks/_deps/c12.mjs';
4
- import { r as resolveCompatibilityDatesFromEnv, a as resolveCompatibilityDates } from '../_chunks/_deps/compatx.mjs';
5
- import { k as klona, a as klona$1 } from '../_chunks/_deps/klona.mjs';
6
- import { runtimeDir, pkgDir } from 'nitro/runtime/meta';
7
- import { d, a } from '../_chunks/_deps/std-env.mjs';
8
- import { r as resolve, j as join, a as relative, d as dirname, n as normalize } from '../_chunks/_deps/pathe.mjs';
9
- import { existsSync, promises } from 'node:fs';
10
- import defu$1, { defu } from 'defu';
11
- import { withLeadingSlash, withoutTrailingSlash, withTrailingSlash, withBase } from 'ufo';
12
- import { e as escapeStringRegexp } from '../_chunks/_deps/escape-string-regexp.mjs';
13
- import { g as resolveModuleExportNames } from '../_chunks/_deps/mlly.mjs';
14
- import { f as findWorkspaceDir } from '../_chunks/_deps/pkg-types.mjs';
15
- import { r as resolveModulePath } from '../_chunks/_deps/exsolve.mjs';
16
- import { createJiti } from 'jiti';
17
- import { g as glob } from '../_chunks/_deps/tinyglobby.mjs';
18
- import fsp, { stat, mkdir, writeFile as writeFile$1, readFile } from 'node:fs/promises';
19
- import { ofetch } from 'ofetch';
20
- import { createStorage as createStorage$1, builtinDrivers } from 'unstorage';
21
- import { c as createRouter, a as addRoute, b as compileRouterToString, d as findRoute, f as findAllRoutes } from '../_chunks/_deps/rou3.mjs';
22
- import { hash } from 'ohash';
23
- import { c as createUnimport } from '../_chunks/_deps/unimport.mjs';
24
- import { colors } from 'consola/utils';
25
- import { g as getProperty } from '../_chunks/_deps/dot-prop.mjs';
26
- import zlib from 'node:zlib';
27
- import { m as mime } from '../_chunks/_deps/mime.mjs';
28
-
29
- const NitroDefaults = {
30
- // General
31
- compatibilityDate: "latest",
32
- debug: d,
33
- logLevel: a ? 1 : 3,
34
- runtimeConfig: { app: {}, nitro: {} },
35
- // Dirs
36
- scanDirs: [],
37
- buildDir: ".nitro",
38
- output: {
39
- dir: "{{ rootDir }}/.output",
40
- serverDir: "{{ output.dir }}/server",
41
- publicDir: "{{ output.dir }}/public"
42
- },
43
- // Features
44
- experimental: {},
45
- future: {},
46
- storage: {},
47
- devStorage: {},
48
- bundledStorage: [],
49
- publicAssets: [],
50
- serverAssets: [],
51
- plugins: [],
52
- tasks: {},
53
- scheduledTasks: {},
54
- imports: false,
55
- virtual: {},
56
- compressPublicAssets: false,
57
- ignore: [],
58
- // Dev
59
- dev: false,
60
- devServer: { watch: [] },
61
- watchOptions: { ignoreInitial: true },
62
- devProxy: {},
63
- // Logging
64
- logging: {
65
- compressedSizes: true,
66
- buildSuccess: true
67
- },
68
- // Routing
69
- baseURL: process.env.NITRO_APP_BASE_URL || "/",
70
- handlers: [],
71
- devHandlers: [],
72
- errorHandler: void 0,
73
- routeRules: {},
74
- prerender: {
75
- autoSubfolderIndex: true,
76
- concurrency: 1,
77
- interval: 0,
78
- retry: 3,
79
- retryDelay: 500,
80
- failOnError: false,
81
- crawlLinks: false,
82
- ignore: [],
83
- routes: []
84
- },
85
- // Rollup
86
- builder: void 0,
87
- moduleSideEffects: ["unenv/polyfill/", resolve(runtimeDir, "polyfill/")],
88
- replace: {},
89
- node: true,
90
- sourceMap: true,
91
- esbuild: {
92
- options: {
93
- jsxFactory: "h",
94
- jsxFragment: "Fragment"
95
- }
96
- },
97
- // Advanced
98
- typescript: {
99
- strict: true,
100
- generateRuntimeConfigTypes: false,
101
- generateTsConfig: false,
102
- tsconfigPath: "types/tsconfig.json",
103
- internalPaths: false,
104
- tsConfig: {}
105
- },
106
- nodeModulesDirs: [],
107
- hooks: {},
108
- commands: {},
109
- // Framework
110
- framework: {
111
- name: "nitro",
112
- version: ""
113
- }
114
- };
115
-
116
- async function resolveAssetsOptions(options) {
117
- for (const publicAsset of options.publicAssets) {
118
- publicAsset.dir = resolve(options.srcDir, publicAsset.dir);
119
- publicAsset.baseURL = withLeadingSlash(
120
- withoutTrailingSlash(publicAsset.baseURL || "/")
121
- );
122
- }
123
- for (const dir of options.scanDirs) {
124
- const publicDir = resolve(dir, "public");
125
- if (!existsSync(publicDir)) {
126
- continue;
127
- }
128
- if (options.publicAssets.some((asset) => asset.dir === publicDir)) {
129
- continue;
130
- }
131
- options.publicAssets.push({ dir: publicDir });
132
- }
133
- for (const serverAsset of options.serverAssets) {
134
- serverAsset.dir = resolve(options.srcDir, serverAsset.dir);
135
- }
136
- options.serverAssets.push({
137
- baseName: "server",
138
- dir: resolve(options.srcDir, "assets")
139
- });
140
- for (const asset of options.publicAssets) {
141
- asset.baseURL = asset.baseURL || "/";
142
- const isTopLevel = asset.baseURL === "/";
143
- asset.fallthrough = asset.fallthrough ?? isTopLevel;
144
- const routeRule = options.routeRules[asset.baseURL + "/**"];
145
- asset.maxAge = routeRule?.cache?.maxAge ?? asset.maxAge ?? 0;
146
- if (asset.maxAge && !asset.fallthrough) {
147
- options.routeRules[asset.baseURL + "/**"] = defu(routeRule, {
148
- headers: {
149
- "cache-control": `public, max-age=${asset.maxAge}, immutable`
150
- }
151
- });
152
- }
153
- }
154
- }
155
-
156
- async function resolveCompatibilityOptions(options) {
157
- options.compatibilityDate = resolveCompatibilityDatesFromEnv(
158
- options.compatibilityDate
159
- );
160
- }
161
-
162
- async function resolveDatabaseOptions(options) {
163
- if (options.experimental.database && options.imports) {
164
- options.imports.presets.push({
165
- from: "nitro/runtime/internal/database",
166
- imports: ["useDatabase"]
167
- });
168
- if (options.dev && !options.database && !options.devDatabase) {
169
- options.devDatabase = {
170
- default: {
171
- connector: "sqlite",
172
- options: {
173
- cwd: options.rootDir
174
- }
175
- }
176
- };
177
- } else if (options.node && !options.database) {
178
- options.database = {
179
- default: {
180
- connector: "sqlite",
181
- options: {}
182
- }
183
- };
184
- }
185
- }
186
- }
187
-
188
- async function resolveExportConditionsOptions(options) {
189
- options.exportConditions = _resolveExportConditions(
190
- options.exportConditions || [],
191
- { dev: options.dev, node: options.node, wasm: options.experimental.wasm }
192
- );
193
- }
194
- function _resolveExportConditions(conditions, opts) {
195
- const resolvedConditions = [];
196
- resolvedConditions.push(opts.dev ? "development" : "production");
197
- resolvedConditions.push(...conditions);
198
- if (opts.node) {
199
- resolvedConditions.push("node");
200
- } else {
201
- resolvedConditions.push(
202
- "wintercg",
203
- "worker",
204
- "web",
205
- "browser",
206
- "workerd",
207
- "edge-light",
208
- "netlify",
209
- "edge-routine",
210
- "deno"
211
- );
212
- }
213
- if (opts.wasm) {
214
- resolvedConditions.push("wasm", "unwasm");
215
- }
216
- resolvedConditions.push("import", "default");
217
- if ("Bun" in globalThis) {
218
- resolvedConditions.push("bun");
219
- } else if ("Deno" in globalThis) {
220
- resolvedConditions.push("deno");
221
- }
222
- return resolvedConditions.filter(
223
- (c, i) => resolvedConditions.indexOf(c) === i
224
- );
225
- }
226
-
227
- async function resolveImportsOptions(options) {
228
- if (options.imports === false) {
229
- return;
230
- }
231
- options.imports.presets ??= [];
232
- options.imports.presets.push(...getNitroImportsPreset());
233
- const h3Exports = await resolveModuleExportNames("h3", {
234
- url: import.meta.url
235
- });
236
- options.imports.presets ??= [];
237
- options.imports.presets.push({
238
- from: "h3",
239
- imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
240
- });
241
- options.imports.dirs ??= [];
242
- options.imports.dirs.push(
243
- ...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
244
- );
245
- if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
246
- options.imports.exclude.push(/[/\\]\.git[/\\]/);
247
- options.imports.exclude.push(options.buildDir);
248
- const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
249
- options.imports.exclude.push(
250
- scanDirsInNodeModules.length > 0 ? new RegExp(
251
- `node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`
252
- ) : /[/\\]node_modules[/\\]/
253
- );
254
- }
255
- }
256
- function getNitroImportsPreset() {
257
- return [
258
- {
259
- from: "nitro/runtime/internal/app",
260
- imports: ["useNitroApp"]
261
- },
262
- {
263
- from: "nitro/runtime/internal/runtime-config",
264
- imports: ["useRuntimeConfig"]
265
- },
266
- {
267
- from: "nitro/runtime/internal/plugin",
268
- imports: ["defineNitroPlugin", "nitroPlugin"]
269
- },
270
- {
271
- from: "nitro/runtime/internal/cache",
272
- imports: [
273
- "defineCachedFunction",
274
- "defineCachedEventHandler",
275
- "defineCachedHandler",
276
- "cachedFunction",
277
- "cachedEventHandler"
278
- ]
279
- },
280
- {
281
- from: "nitro/runtime/internal/storage",
282
- imports: ["useStorage"]
283
- },
284
- {
285
- from: "nitro/runtime/internal/renderer",
286
- imports: ["defineRenderHandler"]
287
- },
288
- {
289
- from: "nitro/runtime/internal/meta",
290
- imports: ["defineRouteMeta"]
291
- },
292
- {
293
- from: "nitro/runtime/internal/route-rules",
294
- imports: ["getRouteRules"]
295
- },
296
- {
297
- from: "nitro/runtime/internal/context",
298
- imports: ["useRequest"]
299
- },
300
- {
301
- from: "nitro/runtime/internal/task",
302
- imports: ["defineTask", "runTask"]
303
- },
304
- {
305
- from: "nitro/runtime/internal/error/utils",
306
- imports: ["defineNitroErrorHandler"]
307
- },
308
- {
309
- from: "nitro/deps/ofetch",
310
- imports: ["$fetch"]
311
- }
312
- ];
313
- }
314
-
315
- async function resolveOpenAPIOptions(options) {
316
- if (!options.experimental.openAPI) {
317
- return;
318
- }
319
- if (!options.dev && !options.openAPI?.production) {
320
- return;
321
- }
322
- const shouldPrerender = !options.dev && options.openAPI?.production === "prerender";
323
- const handlersEnv = shouldPrerender ? "prerender" : "";
324
- const prerenderRoutes = [];
325
- const jsonRoute = options.openAPI?.route || "/_openapi.json";
326
- prerenderRoutes.push(jsonRoute);
327
- options.handlers.push({
328
- route: jsonRoute,
329
- env: handlersEnv,
330
- handler: join(runtimeDir, "internal/routes/openapi")
331
- });
332
- if (options.openAPI?.ui?.scalar !== false) {
333
- const scalarRoute = options.openAPI?.ui?.scalar?.route || "/_scalar";
334
- prerenderRoutes.push(scalarRoute);
335
- options.handlers.push({
336
- route: options.openAPI?.ui?.scalar?.route || "/_scalar",
337
- env: handlersEnv,
338
- handler: join(runtimeDir, "internal/routes/scalar")
339
- });
340
- }
341
- if (options.openAPI?.ui?.swagger !== false) {
342
- const swaggerRoute = options.openAPI?.ui?.swagger?.route || "/_swagger";
343
- prerenderRoutes.push(swaggerRoute);
344
- options.handlers.push({
345
- route: swaggerRoute,
346
- env: handlersEnv,
347
- handler: join(runtimeDir, "internal/routes/swagger")
348
- });
349
- }
350
- if (shouldPrerender) {
351
- options.prerender ??= {};
352
- options.prerender.routes ??= [];
353
- options.prerender.routes.push(...prerenderRoutes);
354
- }
355
- }
356
-
357
- function prettyPath(p, highlight = true) {
358
- p = relative(process.cwd(), p);
359
- return highlight ? colors.cyan(p) : p;
360
- }
361
- function resolveNitroPath(path, nitroOptions, base) {
362
- if (typeof path !== "string") {
363
- throw new TypeError("Invalid path: " + path);
364
- }
365
- path = _compilePathTemplate(path)(nitroOptions);
366
- for (const base2 in nitroOptions.alias) {
367
- if (path.startsWith(base2)) {
368
- path = nitroOptions.alias[base2] + path.slice(base2.length);
369
- }
370
- }
371
- return resolve(base || nitroOptions.srcDir, path);
372
- }
373
- function _compilePathTemplate(contents) {
374
- return (params) => contents.replace(/{{ ?([\w.]+) ?}}/g, (_, match) => {
375
- const val = getProperty(params, match);
376
- if (!val) {
377
- consola.warn(
378
- `cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
379
- );
380
- }
381
- return val || `${match}`;
382
- });
383
- }
384
- async function writeFile(file, contents, log = false) {
385
- await mkdir(dirname(file), { recursive: true });
386
- await writeFile$1(
387
- file,
388
- contents,
389
- typeof contents === "string" ? "utf8" : void 0
390
- );
391
- if (log) {
392
- consola.info("Generated", prettyPath(file));
393
- }
394
- }
395
- async function isDirectory(path) {
396
- try {
397
- return (await stat(path)).isDirectory();
398
- } catch {
399
- return false;
400
- }
401
- }
402
-
403
- const RESOLVE_EXTENSIONS = [".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx"];
404
- async function resolvePathOptions(options) {
405
- options.rootDir = resolve(options.rootDir || ".") + "/";
406
- options.workspaceDir ||= await findWorkspaceDir(options.rootDir).catch(() => options.rootDir) + "/";
407
- for (const key of ["srcDir", "buildDir"]) {
408
- options[key] = resolve(options.rootDir, options[key] || ".");
409
- }
410
- options.alias ??= {};
411
- if (!options.static && !options.entry) {
412
- throw new Error(
413
- `Nitro entry is missing! Is "${options.preset}" preset correct?`
414
- );
415
- }
416
- if (options.entry) {
417
- options.entry = resolveNitroPath(options.entry, options);
418
- }
419
- options.output.dir = resolveNitroPath(
420
- options.output.dir || NitroDefaults.output.dir,
421
- options,
422
- options.rootDir
423
- ) + "/";
424
- options.output.publicDir = resolveNitroPath(
425
- options.output.publicDir || NitroDefaults.output.publicDir,
426
- options,
427
- options.rootDir
428
- ) + "/";
429
- options.output.serverDir = resolveNitroPath(
430
- options.output.serverDir || NitroDefaults.output.serverDir,
431
- options,
432
- options.rootDir
433
- ) + "/";
434
- options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
435
- options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
436
- options.nodeModulesDirs.push(resolve(pkgDir, "dist/node_modules"));
437
- options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
438
- options.nodeModulesDirs.push(resolve(pkgDir, ".."));
439
- options.nodeModulesDirs = [
440
- ...new Set(
441
- // Adding trailing slash to optimize resolve performance (path is explicitly a dir)
442
- options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir) + "/")
443
- )
444
- ];
445
- options.plugins = options.plugins.map((p) => resolveNitroPath(p, options));
446
- options.scanDirs.unshift(options.srcDir);
447
- options.scanDirs = options.scanDirs.map(
448
- (dir) => resolve(options.srcDir, dir)
449
- );
450
- options.scanDirs = [...new Set(options.scanDirs.map((dir) => dir + "/"))];
451
- if (options.serverEntry) {
452
- options.serverEntry = resolveModulePath(
453
- resolveNitroPath(options.serverEntry, options),
454
- {
455
- from: options.scanDirs,
456
- extensions: RESOLVE_EXTENSIONS
457
- }
458
- );
459
- } else {
460
- const defaultServerEntry = resolveModulePath("./server", {
461
- from: options.scanDirs,
462
- extensions: RESOLVE_EXTENSIONS,
463
- try: true
464
- });
465
- if (defaultServerEntry) {
466
- options.serverEntry = defaultServerEntry;
467
- consola.info(
468
- `Using \`${prettyPath(defaultServerEntry)}\` as server entry.`
469
- );
470
- }
471
- }
472
- if (options.renderer?.entry) {
473
- options.renderer.entry = resolveModulePath(
474
- resolveNitroPath(options.renderer?.entry, options),
475
- {
476
- from: options.scanDirs,
477
- extensions: RESOLVE_EXTENSIONS
478
- }
479
- );
480
- }
481
- if (options.renderer?.template) {
482
- options.renderer.template = resolveModulePath(
483
- resolveNitroPath(options.renderer?.template, options),
484
- {
485
- from: options.scanDirs,
486
- extensions: [".html"]
487
- }
488
- );
489
- } else if (!options.renderer?.entry) {
490
- const defaultIndex = resolveModulePath("./index.html", {
491
- from: options.scanDirs,
492
- extensions: [".html"],
493
- try: true
494
- });
495
- if (defaultIndex) {
496
- options.renderer ??= {};
497
- options.renderer.template = defaultIndex;
498
- consola.info(
499
- `Using \`${prettyPath(defaultIndex)}\` as renderer template.`
500
- );
501
- }
502
- }
503
- if (options.renderer?.template && !options.renderer?.entry) {
504
- options.renderer ??= {};
505
- options.renderer.entry = join(
506
- runtimeDir,
507
- "internal/routes/renderer-template" + (options.dev ? ".dev" : "")
508
- );
509
- }
510
- }
511
-
512
- async function resolveRouteRulesOptions(options) {
513
- options.routeRules = defu(options.routeRules, options.routes || {});
514
- options.routeRules = normalizeRouteRules(options);
515
- }
516
- function normalizeRouteRules(config) {
517
- const normalizedRules = {};
518
- for (let path in config.routeRules) {
519
- const routeConfig = config.routeRules[path];
520
- path = withLeadingSlash(path);
521
- const routeRules = {
522
- ...routeConfig,
523
- redirect: void 0,
524
- proxy: void 0
525
- };
526
- if (routeConfig.redirect) {
527
- routeRules.redirect = {
528
- // @ts-ignore
529
- to: "/",
530
- status: 307,
531
- ...typeof routeConfig.redirect === "string" ? { to: routeConfig.redirect } : routeConfig.redirect
532
- };
533
- if (path.endsWith("/**")) {
534
- routeRules.redirect._redirectStripBase = path.slice(0, -3);
535
- }
536
- }
537
- if (routeConfig.proxy) {
538
- routeRules.proxy = typeof routeConfig.proxy === "string" ? { to: routeConfig.proxy } : routeConfig.proxy;
539
- if (path.endsWith("/**")) {
540
- routeRules.proxy._proxyStripBase = path.slice(0, -3);
541
- }
542
- }
543
- if (routeConfig.cors) {
544
- routeRules.headers = {
545
- "access-control-allow-origin": "*",
546
- "access-control-allow-methods": "*",
547
- "access-control-allow-headers": "*",
548
- "access-control-max-age": "0",
549
- ...routeRules.headers
550
- };
551
- }
552
- if (routeConfig.swr) {
553
- routeRules.cache = routeRules.cache || {};
554
- routeRules.cache.swr = true;
555
- if (typeof routeConfig.swr === "number") {
556
- routeRules.cache.maxAge = routeConfig.swr;
557
- }
558
- }
559
- if (routeConfig.cache === false) {
560
- routeRules.cache = false;
561
- }
562
- normalizedRules[path] = routeRules;
563
- }
564
- return normalizedRules;
565
- }
566
-
567
- async function resolveRuntimeConfigOptions(options) {
568
- options.runtimeConfig = normalizeRuntimeConfig(options);
569
- }
570
- function normalizeRuntimeConfig(config) {
571
- provideFallbackValues(config.runtimeConfig || {});
572
- const runtimeConfig = defu$1(
573
- config.runtimeConfig,
574
- {
575
- app: {
576
- baseURL: config.baseURL
577
- },
578
- nitro: {
579
- envExpansion: config.experimental?.envExpansion,
580
- openAPI: config.openAPI
581
- }
582
- }
583
- );
584
- runtimeConfig.nitro.routeRules = config.routeRules;
585
- checkSerializableRuntimeConfig(runtimeConfig);
586
- return runtimeConfig;
587
- }
588
- function provideFallbackValues(obj) {
589
- for (const key in obj) {
590
- if (obj[key] === void 0 || obj[key] === null) {
591
- obj[key] = "";
592
- } else if (typeof obj[key] === "object") {
593
- provideFallbackValues(obj[key]);
594
- }
595
- }
596
- }
597
- function checkSerializableRuntimeConfig(obj, path = []) {
598
- if (isPrimitiveValue(obj)) {
599
- return;
600
- }
601
- for (const key in obj) {
602
- const value = obj[key];
603
- if (value === null || value === void 0 || isPrimitiveValue(value)) {
604
- continue;
605
- }
606
- if (Array.isArray(value)) {
607
- for (const [index, item] of value.entries())
608
- checkSerializableRuntimeConfig(item, [...path, `${key}[${index}]`]);
609
- } else if (typeof value === "object" && value.constructor === Object && (!value.constructor?.name || value.constructor.name === "Object")) {
610
- checkSerializableRuntimeConfig(value, [...path, key]);
611
- } else {
612
- console.warn(
613
- `Runtime config option \`${[...path, key].join(".")}\` may not be able to be serialized.`
614
- );
615
- }
616
- }
617
- }
618
- function isPrimitiveValue(value) {
619
- return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
620
- }
621
-
622
- async function resolveStorageOptions(options) {
623
- const fsMounts = {
624
- root: resolve(options.rootDir),
625
- src: resolve(options.srcDir),
626
- build: resolve(options.buildDir),
627
- cache: resolve(options.buildDir, "cache")
628
- };
629
- for (const p in fsMounts) {
630
- options.devStorage[p] = options.devStorage[p] || {
631
- driver: "fs",
632
- readOnly: p === "root" || p === "src",
633
- base: fsMounts[p]
634
- };
635
- }
636
- if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
637
- options.devStorage.data = {
638
- driver: "fs",
639
- base: resolve(options.rootDir, ".data/kv")
640
- };
641
- } else if (options.node && options.storage.data === void 0) {
642
- options.storage.data = {
643
- driver: "fsLite",
644
- base: "./.data/kv"
645
- };
646
- }
647
- }
648
-
649
- async function resolveURLOptions(options) {
650
- options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
651
- }
652
-
653
- async function resolveErrorOptions(options) {
654
- if (!options.errorHandler) {
655
- options.errorHandler = [];
656
- } else if (!Array.isArray(options.errorHandler)) {
657
- options.errorHandler = [options.errorHandler];
658
- }
659
- options.errorHandler.push(
660
- join(runtimeDir, `internal/error/${options.dev ? "dev" : "prod"}`)
661
- );
662
- }
663
-
664
- const common = {
665
- meta: {
666
- name: "nitro-common",
667
- url: import.meta.url
668
- },
669
- alias: {
670
- "buffer/": "node:buffer",
671
- "buffer/index": "node:buffer",
672
- "buffer/index.js": "node:buffer",
673
- "string_decoder/": "node:string_decoder",
674
- "process/": "node:process"
675
- }
676
- };
677
- const nodeless = {
678
- meta: {
679
- name: "nitro-nodeless",
680
- url: import.meta.url
681
- },
682
- inject: {
683
- global: "unenv/polyfill/globalthis",
684
- process: "node:process",
685
- Buffer: ["node:buffer", "Buffer"],
686
- clearImmediate: ["node:timers", "clearImmediate"],
687
- setImmediate: ["node:timers", "setImmediate"],
688
- performance: "unenv/polyfill/performance",
689
- PerformanceObserver: ["node:perf_hooks", "PerformanceObserver"],
690
- BroadcastChannel: ["node:worker_threads", "BroadcastChannel"]
691
- },
692
- polyfill: [
693
- "unenv/polyfill/globalthis-global",
694
- "unenv/polyfill/process",
695
- "unenv/polyfill/buffer",
696
- "unenv/polyfill/timers"
697
- ]
698
- };
699
- async function resolveUnenv(options) {
700
- options.unenv ??= [];
701
- if (!Array.isArray(options.unenv)) {
702
- options.unenv = [options.unenv];
703
- }
704
- options.unenv = options.unenv.filter(Boolean);
705
- if (!options.node) {
706
- options.unenv.unshift(nodeless);
707
- }
708
- options.unenv.unshift(common);
709
- }
710
-
711
- async function resolveBuilder(options) {
712
- if (!options.builder) {
713
- options.builder = process.env.NITRO_BUILDER || "rollup";
714
- }
715
- if (options.builder === "rolldown") {
716
- try {
717
- await import('rolldown');
718
- } catch {
719
- throw new Error(
720
- `Builder "rolldown" is not available. Make sure to install "rolldown" package.`
721
- );
722
- }
723
- } else if (options.builder === "vite") {
724
- try {
725
- await import('vite');
726
- } catch {
727
- throw new Error(
728
- `Builder "vite" is not available. Make sure to install "vite" package.`
729
- );
730
- }
731
- }
732
- if (!["rollup", "rolldown", "vite"].includes(options.builder)) {
733
- throw new Error(`Builder "${options.builder}" is not supported.`);
734
- }
735
- }
736
-
737
- const configResolvers = [
738
- resolveCompatibilityOptions,
739
- resolvePathOptions,
740
- resolveImportsOptions,
741
- resolveRouteRulesOptions,
742
- resolveDatabaseOptions,
743
- resolveExportConditionsOptions,
744
- resolveRuntimeConfigOptions,
745
- resolveOpenAPIOptions,
746
- resolveURLOptions,
747
- resolveAssetsOptions,
748
- resolveStorageOptions,
749
- resolveErrorOptions,
750
- resolveUnenv,
751
- resolveBuilder
752
- ];
753
- async function loadOptions(configOverrides = {}, opts = {}) {
754
- const options = await _loadUserConfig(configOverrides, opts);
755
- for (const resolver of configResolvers) {
756
- await resolver(options);
757
- }
758
- return options;
759
- }
760
- async function _loadUserConfig(configOverrides = {}, opts = {}) {
761
- configOverrides = klona(configOverrides);
762
- globalThis.defineNitroConfig = globalThis.defineNitroConfig || ((c) => c);
763
- let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.NITRO_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
764
- const { resolvePreset } = await import('../_chunks/_presets/index.mjs');
765
- let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
766
- const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
767
- const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
768
- name: "nitro",
769
- cwd: configOverrides.rootDir,
770
- dotenv: _dotenv,
771
- extend: { extendKey: ["extends", "preset"] },
772
- defaults: NitroDefaults,
773
- jitiOptions: {
774
- alias: {
775
- nitropack: "nitro/config",
776
- "nitro/config": "nitro/config"
777
- }
778
- },
779
- async overrides({ rawConfigs }) {
780
- const getConf = (key) => configOverrides[key] ?? rawConfigs.main?.[key] ?? rawConfigs.rc?.[key] ?? rawConfigs.packageJson?.[key];
781
- if (!compatibilityDate) {
782
- compatibilityDate = getConf("compatibilityDate");
783
- }
784
- const framework = getConf("framework");
785
- const isCustomFramework = framework?.name && framework.name !== "nitro";
786
- if (!preset) {
787
- preset = getConf("preset");
788
- }
789
- if (configOverrides.dev) {
790
- preset = preset && preset !== "nitro-dev" ? await resolvePreset(preset, {
791
- static: getConf("static"),
792
- dev: true,
793
- compatibilityDate: compatibilityDate || "latest"
794
- }).then((p) => p?._meta?.name || "nitro-dev").catch(() => "nitro-dev") : "nitro-dev";
795
- } else if (!preset) {
796
- preset = await resolvePreset("", {
797
- static: getConf("static"),
798
- dev: false,
799
- compatibilityDate: compatibilityDate || "latest"
800
- }).then((p) => p?._meta?.name);
801
- }
802
- return {
803
- ...configOverrides,
804
- preset,
805
- typescript: {
806
- generateRuntimeConfigTypes: !isCustomFramework,
807
- ...getConf("typescript"),
808
- ...configOverrides.typescript
809
- }
810
- };
811
- },
812
- async resolve(id) {
813
- const preset2 = await resolvePreset(id, {
814
- static: configOverrides.static,
815
- compatibilityDate: compatibilityDate || "latest",
816
- dev: configOverrides.dev
817
- });
818
- if (preset2) {
819
- return {
820
- config: klona(preset2)
821
- };
822
- }
823
- },
824
- ...opts.c12
825
- });
826
- const options = klona(loadedConfig.config);
827
- options._config = configOverrides;
828
- options._c12 = loadedConfig;
829
- const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || preset;
830
- options.preset = _presetName;
831
- options.compatibilityDate = resolveCompatibilityDates(
832
- compatibilityDate,
833
- options.compatibilityDate
834
- );
835
- if (options.dev && options.preset !== "nitro-dev") {
836
- consola.info(`Using \`${options.preset}\` emulation in development mode.`);
837
- }
838
- return options;
839
- }
840
-
841
- async function updateNitroConfig(nitro, config) {
842
- nitro.options.routeRules = normalizeRouteRules(
843
- config.routeRules ? config : nitro.options
844
- );
845
- nitro.options.runtimeConfig = normalizeRuntimeConfig(
846
- config.runtimeConfig ? config : nitro.options
847
- );
848
- await nitro.hooks.callHook("rollup:reload");
849
- consola.success("Nitro config hot reloaded!");
850
- }
851
-
852
- async function installModules(nitro) {
853
- const _modules = [...nitro.options.modules || []];
854
- const modules = await Promise.all(
855
- _modules.map((mod) => _resolveNitroModule(mod, nitro.options))
856
- );
857
- const _installedURLs = /* @__PURE__ */ new Set();
858
- for (const mod of modules) {
859
- if (mod._url) {
860
- if (_installedURLs.has(mod._url)) {
861
- continue;
862
- }
863
- _installedURLs.add(mod._url);
864
- }
865
- await mod.setup(nitro);
866
- }
867
- }
868
- async function _resolveNitroModule(mod, nitroOptions) {
869
- let _url;
870
- if (typeof mod === "string") {
871
- globalThis.defineNitroModule = // @ts-ignore
872
- globalThis.defineNitroModule || ((mod2) => mod2);
873
- const jiti = createJiti(nitroOptions.rootDir, {
874
- alias: nitroOptions.alias
875
- });
876
- const _modPath = jiti.esmResolve(mod);
877
- _url = _modPath;
878
- mod = await jiti.import(_modPath, { default: true });
879
- }
880
- if (typeof mod === "function") {
881
- mod = { setup: mod };
882
- }
883
- if (!mod.setup) {
884
- mod.setup = () => {
885
- };
886
- }
887
- return {
888
- _url,
889
- ...mod
890
- };
891
- }
892
-
893
- const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
894
- const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
895
- async function scanAndSyncOptions(nitro) {
896
- const scannedPlugins = await scanPlugins(nitro);
897
- for (const plugin of scannedPlugins) {
898
- if (!nitro.options.plugins.includes(plugin)) {
899
- nitro.options.plugins.push(plugin);
900
- }
901
- }
902
- if (nitro.options.experimental.tasks) {
903
- const scannedTasks = await scanTasks(nitro);
904
- for (const scannedTask of scannedTasks) {
905
- if (scannedTask.name in nitro.options.tasks) {
906
- if (!nitro.options.tasks[scannedTask.name].handler) {
907
- nitro.options.tasks[scannedTask.name].handler = scannedTask.handler;
908
- }
909
- } else {
910
- nitro.options.tasks[scannedTask.name] = {
911
- handler: scannedTask.handler,
912
- description: ""
913
- };
914
- }
915
- }
916
- }
917
- const scannedModules = await scanModules(nitro);
918
- nitro.options.modules = nitro.options.modules || [];
919
- for (const modPath of scannedModules) {
920
- if (!nitro.options.modules.includes(modPath)) {
921
- nitro.options.modules.push(modPath);
922
- }
923
- }
924
- }
925
- async function scanHandlers(nitro) {
926
- const middleware = await scanMiddleware(nitro);
927
- const handlers = await Promise.all([
928
- scanServerRoutes(
929
- nitro,
930
- nitro.options.apiDir || "api",
931
- nitro.options.apiBaseURL || "/api"
932
- ),
933
- scanServerRoutes(nitro, nitro.options.routesDir || "routes")
934
- ]).then((r) => r.flat());
935
- nitro.scannedHandlers = [
936
- ...middleware,
937
- ...handlers.filter((h, index, array) => {
938
- return array.findIndex(
939
- (h2) => h.route === h2.route && h.method === h2.method && h.env === h2.env
940
- ) === index;
941
- })
942
- ];
943
- return handlers;
944
- }
945
- async function scanMiddleware(nitro) {
946
- const files = await scanFiles(nitro, "middleware");
947
- return files.map((file) => {
948
- return {
949
- route: "/**",
950
- middleware: true,
951
- handler: file.fullPath
952
- };
953
- });
954
- }
955
- async function scanServerRoutes(nitro, dir, prefix = "/") {
956
- const files = await scanFiles(nitro, dir);
957
- return files.map((file) => {
958
- let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(\w+)]/g, "**:$1").replace(/\[([^/\]]+)]/g, ":$1");
959
- route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
960
- const suffixMatch = route.match(suffixRegex);
961
- let method;
962
- let env;
963
- if (suffixMatch?.index && suffixMatch?.index >= 0) {
964
- route = route.slice(0, suffixMatch.index);
965
- method = suffixMatch.groups?.method;
966
- env = suffixMatch.groups?.env;
967
- }
968
- route = route.replace(/\/index$/, "") || "/";
969
- return {
970
- handler: file.fullPath,
971
- lazy: true,
972
- middleware: false,
973
- route,
974
- method,
975
- env
976
- };
977
- });
978
- }
979
- async function scanPlugins(nitro) {
980
- const files = await scanFiles(nitro, "plugins");
981
- return files.map((f) => f.fullPath);
982
- }
983
- async function scanTasks(nitro) {
984
- const files = await scanFiles(nitro, "tasks");
985
- return files.map((f) => {
986
- const name = f.path.replace(/\/index$/, "").replace(/\.[A-Za-z]+$/, "").replace(/\//g, ":");
987
- return { name, handler: f.fullPath };
988
- });
989
- }
990
- async function scanModules(nitro) {
991
- const files = await scanFiles(nitro, "modules");
992
- return files.map((f) => f.fullPath);
993
- }
994
- async function scanFiles(nitro, name) {
995
- const files = await Promise.all(
996
- nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name))
997
- ).then((r) => r.flat());
998
- return files;
999
- }
1000
- async function scanDir(nitro, dir, name) {
1001
- const fileNames = await glob(join(name, GLOB_SCAN_PATTERN), {
1002
- cwd: dir,
1003
- dot: true,
1004
- ignore: nitro.options.ignore,
1005
- absolute: true
1006
- }).catch((error) => {
1007
- if (error?.code === "ENOTDIR") {
1008
- nitro.logger.warn(
1009
- `Ignoring \`${join(dir, name)}\`. It must be a directory.`
1010
- );
1011
- return [];
1012
- }
1013
- throw error;
1014
- });
1015
- return fileNames.map((fullPath) => {
1016
- return {
1017
- fullPath,
1018
- path: relative(join(dir, name), fullPath)
1019
- };
1020
- }).sort((a, b) => a.path.localeCompare(b.path));
1021
- }
1022
-
1023
- async function runTask(taskEvent, opts) {
1024
- const ctx = await _getTasksContext(opts);
1025
- const result = await ctx.devFetch(`/_nitro/tasks/${taskEvent.name}`, {
1026
- method: "POST",
1027
- body: taskEvent
1028
- });
1029
- return result;
1030
- }
1031
- async function listTasks(opts) {
1032
- const ctx = await _getTasksContext(opts);
1033
- const res = await ctx.devFetch("/_nitro/tasks");
1034
- return res.tasks;
1035
- }
1036
- function addNitroTasksVirtualFile(nitro) {
1037
- nitro.options.virtual["#nitro-internal-virtual/tasks"] = () => {
1038
- const _scheduledTasks = Object.entries(nitro.options.scheduledTasks || {}).map(([cron, _tasks]) => {
1039
- const tasks = (Array.isArray(_tasks) ? _tasks : [_tasks]).filter(
1040
- (name) => {
1041
- if (!nitro.options.tasks[name]) {
1042
- nitro.logger.warn(`Scheduled task \`${name}\` is not defined!`);
1043
- return false;
1044
- }
1045
- return true;
1046
- }
1047
- );
1048
- return { cron, tasks };
1049
- }).filter((e) => e.tasks.length > 0);
1050
- const scheduledTasks = _scheduledTasks.length > 0 ? _scheduledTasks : false;
1051
- return (
1052
- /* js */
1053
- `
1054
- export const scheduledTasks = ${JSON.stringify(scheduledTasks)};
1055
-
1056
- export const tasks = {
1057
- ${Object.entries(nitro.options.tasks).map(
1058
- ([name, task]) => `"${name}": {
1059
- meta: {
1060
- description: ${JSON.stringify(task.description)},
1061
- },
1062
- resolve: ${task.handler ? `() => import("${normalize(
1063
- task.handler
1064
- )}").then(r => r.default || r)` : "undefined"},
1065
- }`
1066
- ).join(",\n")}
1067
- };`
1068
- );
1069
- };
1070
- }
1071
- const _devHint = `(is dev server running?)`;
1072
- async function _getTasksContext(opts) {
1073
- const cwd = resolve(process.cwd(), opts?.cwd || ".");
1074
- const outDir = resolve(cwd, opts?.buildDir || ".nitro");
1075
- const buildInfoPath = resolve(outDir, "nitro.json");
1076
- if (!existsSync(buildInfoPath)) {
1077
- throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
1078
- }
1079
- const buildInfo = JSON.parse(
1080
- await readFile(buildInfoPath, "utf8")
1081
- );
1082
- if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) {
1083
- throw new Error(
1084
- `Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`
1085
- );
1086
- }
1087
- if (!_pidIsRunning(buildInfo.dev.pid)) {
1088
- throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
1089
- }
1090
- const devFetch = ofetch.create({
1091
- baseURL: `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`,
1092
- // @ts-expect-error
1093
- socketPath: buildInfo.dev.workerAddress.socketPath
1094
- });
1095
- return {
1096
- buildInfo,
1097
- devFetch
1098
- };
1099
- }
1100
- function _pidIsRunning(pid) {
1101
- try {
1102
- process.kill(pid, 0);
1103
- return true;
1104
- } catch {
1105
- return false;
1106
- }
1107
- }
1108
-
1109
- async function createStorage(nitro) {
1110
- const storage = createStorage$1();
1111
- const mounts = klona$1({
1112
- ...nitro.options.storage,
1113
- ...nitro.options.devStorage
1114
- });
1115
- for (const [path, opts] of Object.entries(mounts)) {
1116
- if (opts.driver) {
1117
- const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
1118
- storage.mount(path, driver(opts));
1119
- } else {
1120
- nitro.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
1121
- }
1122
- }
1123
- return storage;
1124
- }
1125
- async function snapshotStorage(nitro) {
1126
- const data = {};
1127
- const allKeys = [
1128
- ...new Set(
1129
- await Promise.all(
1130
- nitro.options.bundledStorage.map((base) => nitro.storage.getKeys(base))
1131
- ).then((r) => r.flat())
1132
- )
1133
- ];
1134
- await Promise.all(
1135
- allKeys.map(async (key) => {
1136
- data[key] = await nitro.storage.getItem(key);
1137
- })
1138
- );
1139
- return data;
1140
- }
1141
-
1142
- const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
1143
- function initNitroRouting(nitro) {
1144
- const envConditions = new Set(
1145
- [
1146
- nitro.options.dev ? "dev" : "prod",
1147
- nitro.options.preset,
1148
- nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
1149
- ].filter(Boolean)
1150
- );
1151
- const matchesEnv = (h) => {
1152
- const hEnv = Array.isArray(h.env) ? h.env : [h.env];
1153
- const envs = hEnv.filter(Boolean);
1154
- return envs.length === 0 || envs.some((env) => envConditions.has(env));
1155
- };
1156
- const routes = new Router();
1157
- const routeRules = new Router(
1158
- true
1159
- /* matchAll */
1160
- );
1161
- const globalMiddleware = [];
1162
- const routedMiddleware = new Router(
1163
- true
1164
- /* matchAll */
1165
- );
1166
- const warns = /* @__PURE__ */ new Set();
1167
- const sync = () => {
1168
- routeRules._update(
1169
- Object.entries(nitro.options.routeRules).map(([route, data]) => ({
1170
- route,
1171
- method: "",
1172
- data: {
1173
- ...data,
1174
- _route: route
1175
- }
1176
- }))
1177
- );
1178
- const _routes = [
1179
- ...nitro.scannedHandlers,
1180
- ...nitro.options.handlers
1181
- ].filter((h) => h && !h.middleware && matchesEnv(h));
1182
- if (nitro.options.renderer?.entry) {
1183
- const existingWildcard = _routes.findIndex(
1184
- (h) => /^\/\*\*(:.+)?$/.test(h.route) && (!h.method || h.method === "GET")
1185
- );
1186
- if (existingWildcard !== -1) {
1187
- const h = _routes[existingWildcard];
1188
- const warn = `The renderer will override \`${relative(".", h.handler)}\` (route: \`${h.route}\`). Use a more specific route or different HTTP method.`;
1189
- if (!warns.has(warn)) {
1190
- warns.add(warn);
1191
- nitro.logger.warn(warn);
1192
- }
1193
- _routes.splice(existingWildcard, 1);
1194
- }
1195
- _routes.push({
1196
- route: "/**",
1197
- lazy: true,
1198
- handler: nitro.options.renderer?.entry
1199
- });
1200
- }
1201
- routes._update(
1202
- _routes.map((h) => ({
1203
- ...h,
1204
- method: h.method || "",
1205
- data: handlerWithImportHash(h)
1206
- }))
1207
- );
1208
- const _middleware = [
1209
- ...nitro.scannedHandlers,
1210
- ...nitro.options.handlers
1211
- ].filter((h) => h && h.middleware && matchesEnv(h));
1212
- if (nitro.options.serveStatic) {
1213
- _middleware.unshift({
1214
- route: "/**",
1215
- middleware: true,
1216
- handler: join(runtimeDir, "internal/static")
1217
- });
1218
- }
1219
- globalMiddleware.splice(
1220
- 0,
1221
- globalMiddleware.length,
1222
- ..._middleware.filter((h) => isGlobalMiddleware(h)).map((m) => handlerWithImportHash(m))
1223
- );
1224
- routedMiddleware._update(
1225
- _middleware.filter((h) => !isGlobalMiddleware(h)).map((h) => ({
1226
- ...h,
1227
- method: h.method || "",
1228
- data: handlerWithImportHash(h)
1229
- }))
1230
- );
1231
- };
1232
- nitro.routing = Object.freeze({
1233
- sync,
1234
- routes,
1235
- routeRules,
1236
- globalMiddleware,
1237
- routedMiddleware
1238
- });
1239
- }
1240
- function handlerWithImportHash(h) {
1241
- const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
1242
- return { ...h, _importHash: id };
1243
- }
1244
- class Router {
1245
- #routes;
1246
- #router;
1247
- #compiled;
1248
- constructor(matchAll) {
1249
- this._update([]);
1250
- }
1251
- get routes() {
1252
- return this.#routes;
1253
- }
1254
- _update(routes) {
1255
- this.#routes = routes;
1256
- this.#router = createRouter();
1257
- this.#compiled = void 0;
1258
- for (const route of routes) {
1259
- addRoute(this.#router, route.method, route.route, route.data);
1260
- }
1261
- }
1262
- hasRoutes() {
1263
- return this.#routes.length > 0;
1264
- }
1265
- compileToString(opts) {
1266
- return this.#compiled || (this.#compiled = compileRouterToString(this.#router, void 0, opts));
1267
- }
1268
- match(method, path) {
1269
- return findRoute(this.#router, method, path)?.data;
1270
- }
1271
- matchAll(method, path) {
1272
- return findAllRoutes(this.#router, method, path).map(
1273
- (route) => route.data
1274
- );
1275
- }
1276
- }
1277
-
1278
- async function createNitro(config = {}, opts = {}) {
1279
- const options = await loadOptions(config, opts);
1280
- const nitro = {
1281
- options,
1282
- hooks: new Hookable(),
1283
- vfs: {},
1284
- routing: {},
1285
- logger: consola$1.withTag("nitro"),
1286
- scannedHandlers: [],
1287
- close: () => Promise.resolve(nitro.hooks.callHook("close")),
1288
- storage: void 0,
1289
- async updateConfig(config2) {
1290
- updateNitroConfig(nitro, config2);
1291
- }
1292
- };
1293
- initNitroRouting(nitro);
1294
- await scanAndSyncOptions(nitro);
1295
- nitro.storage = await createStorage(nitro);
1296
- nitro.hooks.hook("close", async () => {
1297
- await nitro.storage.dispose();
1298
- });
1299
- if (nitro.options.debug) {
1300
- createDebugger(nitro.hooks, { tag: "nitro" });
1301
- }
1302
- if (nitro.options.logLevel !== void 0) {
1303
- nitro.logger.level = nitro.options.logLevel;
1304
- }
1305
- nitro.hooks.addHooks(nitro.options.hooks);
1306
- addNitroTasksVirtualFile(nitro);
1307
- await installModules(nitro);
1308
- if (nitro.options.imports) {
1309
- nitro.unimport = createUnimport(nitro.options.imports);
1310
- await nitro.unimport.init();
1311
- nitro.options.virtual["#imports"] = () => nitro.unimport?.toExports() || "";
1312
- nitro.options.virtual["#nitro"] = 'export * from "#imports"';
1313
- }
1314
- await scanHandlers(nitro);
1315
- nitro.routing.sync();
1316
- return nitro;
1317
- }
1318
-
1319
- async function compressPublicAssets(nitro) {
1320
- const publicFiles = await glob("**", {
1321
- cwd: nitro.options.output.publicDir,
1322
- absolute: false,
1323
- dot: true,
1324
- ignore: ["**/*.gz", "**/*.br"]
1325
- });
1326
- await Promise.all(
1327
- publicFiles.map(async (fileName) => {
1328
- const filePath = resolve(nitro.options.output.publicDir, fileName);
1329
- if (existsSync(filePath + ".gz") || existsSync(filePath + ".br")) {
1330
- return;
1331
- }
1332
- const mimeType = mime.getType(fileName) || "text/plain";
1333
- const fileContents = await fsp.readFile(filePath);
1334
- if (fileContents.length < 1024 || fileName.endsWith(".map") || !isCompressibleMime(mimeType)) {
1335
- return;
1336
- }
1337
- const { gzip, brotli } = nitro.options.compressPublicAssets || {};
1338
- const encodings = [
1339
- gzip !== false && "gzip",
1340
- brotli !== false && "br"
1341
- ].filter(Boolean);
1342
- await Promise.all(
1343
- encodings.map(async (encoding) => {
1344
- const suffix = "." + (encoding === "gzip" ? "gz" : "br");
1345
- const compressedPath = filePath + suffix;
1346
- if (existsSync(compressedPath)) {
1347
- return;
1348
- }
1349
- const gzipOptions = { level: zlib.constants.Z_BEST_COMPRESSION };
1350
- const brotliOptions = {
1351
- [zlib.constants.BROTLI_PARAM_MODE]: isTextMime(mimeType) ? zlib.constants.BROTLI_MODE_TEXT : zlib.constants.BROTLI_MODE_GENERIC,
1352
- [zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
1353
- [zlib.constants.BROTLI_PARAM_SIZE_HINT]: fileContents.length
1354
- };
1355
- const compressedBuff = await new Promise(
1356
- (resolve2, reject) => {
1357
- const cb = (error, result) => error ? reject(error) : resolve2(result);
1358
- if (encoding === "gzip") {
1359
- zlib.gzip(fileContents, gzipOptions, cb);
1360
- } else {
1361
- zlib.brotliCompress(fileContents, brotliOptions, cb);
1362
- }
1363
- }
1364
- );
1365
- await fsp.writeFile(compressedPath, compressedBuff);
1366
- })
1367
- );
1368
- })
1369
- );
1370
- }
1371
- function isTextMime(mimeType) {
1372
- return /text|javascript|json|xml/.test(mimeType);
1373
- }
1374
- const COMPRESSIBLE_MIMES_RE = /* @__PURE__ */ new Set([
1375
- "application/dash+xml",
1376
- "application/eot",
1377
- "application/font",
1378
- "application/font-sfnt",
1379
- "application/javascript",
1380
- "application/json",
1381
- "application/opentype",
1382
- "application/otf",
1383
- "application/pdf",
1384
- "application/pkcs7-mime",
1385
- "application/protobuf",
1386
- "application/rss+xml",
1387
- "application/truetype",
1388
- "application/ttf",
1389
- "application/vnd.apple.mpegurl",
1390
- "application/vnd.mapbox-vector-tile",
1391
- "application/vnd.ms-fontobject",
1392
- "application/wasm",
1393
- "application/xhtml+xml",
1394
- "application/xml",
1395
- "application/x-font-opentype",
1396
- "application/x-font-truetype",
1397
- "application/x-font-ttf",
1398
- "application/x-httpd-cgi",
1399
- "application/x-javascript",
1400
- "application/x-mpegurl",
1401
- "application/x-opentype",
1402
- "application/x-otf",
1403
- "application/x-perl",
1404
- "application/x-ttf",
1405
- "font/eot",
1406
- "font/opentype",
1407
- "font/otf",
1408
- "font/ttf",
1409
- "image/svg+xml",
1410
- "text/css",
1411
- "text/csv",
1412
- "text/html",
1413
- "text/javascript",
1414
- "text/js",
1415
- "text/plain",
1416
- "text/richtext",
1417
- "text/tab-separated-values",
1418
- "text/xml",
1419
- "text/x-component",
1420
- "text/x-java-source",
1421
- "text/x-script",
1422
- "vnd.apple.mpegurl"
1423
- ]);
1424
- function isCompressibleMime(mimeType) {
1425
- return COMPRESSIBLE_MIMES_RE.has(mimeType);
1426
- }
1427
-
1428
- const NEGATION_RE = /^(!?)(.*)$/;
1429
- const PARENT_DIR_GLOB_RE = /!?\.\.\//;
1430
- async function scanUnprefixedPublicAssets(nitro) {
1431
- const scannedPaths = [];
1432
- for (const asset of nitro.options.publicAssets) {
1433
- if (asset.baseURL && asset.baseURL !== "/" && !asset.fallthrough) {
1434
- continue;
1435
- }
1436
- if (!await isDirectory(asset.dir)) {
1437
- continue;
1438
- }
1439
- const includePatterns = getIncludePatterns(nitro, asset.dir);
1440
- const publicAssets = await glob(includePatterns, {
1441
- cwd: asset.dir,
1442
- absolute: false,
1443
- dot: true
1444
- });
1445
- scannedPaths.push(
1446
- ...publicAssets.map((file) => join(asset.baseURL || "/", file))
1447
- );
1448
- }
1449
- return scannedPaths;
1450
- }
1451
- async function copyPublicAssets(nitro) {
1452
- if (nitro.options.noPublicDir) {
1453
- return;
1454
- }
1455
- for (const asset of nitro.options.publicAssets) {
1456
- const srcDir = asset.dir;
1457
- const dstDir = join(nitro.options.output.publicDir, asset.baseURL);
1458
- if (await isDirectory(srcDir)) {
1459
- const includePatterns = getIncludePatterns(nitro, srcDir);
1460
- const publicAssets = await glob(includePatterns, {
1461
- cwd: srcDir,
1462
- absolute: false,
1463
- dot: true
1464
- });
1465
- await Promise.all(
1466
- publicAssets.map(async (file) => {
1467
- const src = join(srcDir, file);
1468
- const dst = join(dstDir, file);
1469
- if (!existsSync(dst)) {
1470
- await promises.cp(src, dst);
1471
- }
1472
- })
1473
- );
1474
- }
1475
- }
1476
- if (nitro.options.compressPublicAssets) {
1477
- await compressPublicAssets(nitro);
1478
- }
1479
- nitro.logger.success(
1480
- "Generated public " + prettyPath(nitro.options.output.publicDir)
1481
- );
1482
- }
1483
- function getIncludePatterns(nitro, srcDir) {
1484
- return [
1485
- "**",
1486
- ...nitro.options.ignore.map((p) => {
1487
- const [_, negation, pattern] = p.match(NEGATION_RE) || [];
1488
- return (
1489
- // Convert ignore to include patterns
1490
- (negation ? "" : "!") + // Make non-glob patterns relative to publicAssetDir
1491
- (pattern.startsWith("*") ? pattern : relative(srcDir, resolve(nitro.options.srcDir, pattern)))
1492
- );
1493
- })
1494
- ].filter((p) => !PARENT_DIR_GLOB_RE.test(p));
1495
- }
1496
-
1497
- async function prepare(nitro) {
1498
- await prepareDir(nitro.options.output.dir);
1499
- if (!nitro.options.noPublicDir) {
1500
- await prepareDir(nitro.options.output.publicDir);
1501
- }
1502
- if (!nitro.options.static) {
1503
- await prepareDir(nitro.options.output.serverDir);
1504
- }
1505
- }
1506
- async function prepareDir(dir) {
1507
- await fsp.rm(dir, { recursive: true, force: true });
1508
- await fsp.mkdir(dir, { recursive: true });
1509
- }
1510
-
1511
- export { snapshotStorage as a, scanUnprefixedPublicAssets as b, createNitro as c, compressPublicAssets as d, copyPublicAssets as e, runTask as f, listTasks as g, prettyPath as h, isDirectory as i, loadOptions as l, prepare as p, resolveNitroPath as r, scanHandlers as s, writeFile as w };