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
@@ -0,0 +1,762 @@
1
+ import { T as resolve$1, _ as dirname$1, b as join$1, f as resolveModulePath, g as basename$1, n as debounce, w as relative$1, x as normalize$1, y as isAbsolute$1 } from "../_libs/c12.mjs";
2
+ import { f as sanitizeFilePath } from "../_libs/local-pkg.mjs";
3
+ import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
4
+ import { n as a, t as T } from "../_libs/std-env.mjs";
5
+ import { a as createNitro, n as prepare, r as copyPublicAssets } from "../_chunks/B-7HiF0V.mjs";
6
+ import { c as prettyPath, o as scanHandlers } from "../_chunks/B5ooyfLk.mjs";
7
+ import { t as createProxyServer } from "../_libs/httpxy.mjs";
8
+ import { i as NodeDevWorker, r as NitroDevApp } from "../_dev.mjs";
9
+ import { i as watch$1 } from "../_libs/chokidar.mjs";
10
+ import { t as alias } from "../_libs/plugin-alias.mjs";
11
+ import { t as inject } from "../_libs/plugin-inject.mjs";
12
+ import { i as replace, n as baseBuildPlugins, r as baseBuildConfig, t as writeBuildInfo } from "./common.mjs";
13
+ import { t as assetsPlugin } from "../_libs/vite-plugin-fullstack.mjs";
14
+ import consola$1 from "consola";
15
+ import { join, resolve } from "node:path";
16
+ import { existsSync, watch } from "node:fs";
17
+ import { mkdir, readFile, readlink, rm, writeFile } from "node:fs/promises";
18
+ import { defu } from "defu";
19
+ import { runtimeDependencies, runtimeDir } from "nitro/runtime/meta";
20
+ import { colors } from "consola/utils";
21
+ import { NodeRequest, sendNodeResponse } from "srvx/node";
22
+ import { DevEnvironment } from "vite";
23
+ import { getRandomPort } from "get-port-please";
24
+ import { spawn } from "node:child_process";
25
+
26
+ //#region src/build/vite/rollup.ts
27
+ /**
28
+ * Removed from base rollup config:
29
+ * - nodeResolve
30
+ * - commonjs
31
+ * - esbuild
32
+ * - sourcemapMininify
33
+ * - json
34
+ * - raw
35
+ *
36
+ * TODO: Reuse with rollup:
37
+ * - chunkFileNames
38
+ * - moduleSideEffects
39
+ */
40
+ const getViteRollupConfig = (ctx) => {
41
+ const nitro$1 = ctx.nitro;
42
+ const base = baseBuildConfig(nitro$1);
43
+ const chunkNamePrefixes = [
44
+ [nitro$1.options.buildDir, "build"],
45
+ [base.buildServerDir, "app"],
46
+ [runtimeDir, "nitro"],
47
+ [base.presetsDir, "nitro"],
48
+ ["\0nitro-wasm:", "wasm"],
49
+ ["\0", "virtual"]
50
+ ];
51
+ function getChunkGroup(id) {
52
+ if (id.startsWith(runtimeDir) || id.startsWith(base.presetsDir)) return "nitro";
53
+ }
54
+ let config = {
55
+ input: nitro$1.options.entry,
56
+ external: [...base.env.external],
57
+ plugins: [
58
+ ctx.pluginConfig.experimental?.virtualBundle && virtualBundlePlugin(ctx._serviceBundles),
59
+ ...baseBuildPlugins(nitro$1, base),
60
+ alias({ entries: base.aliases }),
61
+ replace({
62
+ delimiters: base.replaceDelimiters,
63
+ preventAssignment: true,
64
+ values: base.replacements
65
+ }),
66
+ inject(base.env.inject)
67
+ ].filter(Boolean),
68
+ treeshake: { moduleSideEffects(id) {
69
+ const normalizedId = normalize$1(id);
70
+ const idWithoutNodeModules = normalizedId.split("node_modules/").pop();
71
+ if (!idWithoutNodeModules) return false;
72
+ if (normalizedId.startsWith(runtimeDir) || idWithoutNodeModules.startsWith(runtimeDir)) return true;
73
+ return nitro$1.options.moduleSideEffects.some((m) => normalizedId.startsWith(m) || idWithoutNodeModules.startsWith(m));
74
+ } },
75
+ output: {
76
+ dir: nitro$1.options.output.serverDir,
77
+ entryFileNames: "index.mjs",
78
+ chunkFileNames(chunk) {
79
+ const id = normalize$1(chunk.moduleIds.at(-1) || "");
80
+ for (const [dir, name] of chunkNamePrefixes) if (id.startsWith(dir)) return `chunks/${name}/[name].mjs`;
81
+ const routeHandler = nitro$1.options.handlers.find((h) => id.startsWith(h.handler)) || nitro$1.scannedHandlers.find((h) => id.startsWith(h.handler));
82
+ if (routeHandler?.route) return `chunks/routes/${routeHandler.route.replace(/:([^/]+)/g, "_$1").replace(/\/[^/]+$/g, "") || "/"}/[name].mjs`.replace(/\/+/g, "/");
83
+ if (Object.entries(nitro$1.options.tasks).find(([_, task]) => task.handler === id)) return `chunks/tasks/[name].mjs`;
84
+ return `chunks/_/[name].mjs`;
85
+ },
86
+ manualChunks(id) {
87
+ return getChunkGroup(id);
88
+ },
89
+ inlineDynamicImports: nitro$1.options.inlineDynamicImports,
90
+ format: "esm",
91
+ exports: "auto",
92
+ intro: "",
93
+ outro: "",
94
+ generatedCode: { constBindings: true },
95
+ sanitizeFileName: sanitizeFilePath,
96
+ sourcemapExcludeSources: true,
97
+ sourcemapIgnoreList(relativePath) {
98
+ return relativePath.includes("node_modules");
99
+ }
100
+ }
101
+ };
102
+ config = defu(nitro$1.options.rollupConfig, config);
103
+ if (config.output.inlineDynamicImports) delete config.output.manualChunks;
104
+ return {
105
+ config,
106
+ base
107
+ };
108
+ };
109
+ function virtualBundlePlugin(bundles) {
110
+ let _modules = null;
111
+ const getModules = () => {
112
+ if (_modules) return _modules;
113
+ _modules = /* @__PURE__ */ new Map();
114
+ for (const bundle of Object.values(bundles)) for (const [fileName, content] of Object.entries(bundle)) if (content.type === "chunk") {
115
+ const virtualModule = {
116
+ code: content.code,
117
+ map: null
118
+ };
119
+ const maybeMap = bundle[`${fileName}.map`];
120
+ if (maybeMap && maybeMap.type === "asset") virtualModule.map = maybeMap.source;
121
+ _modules.set(fileName, virtualModule);
122
+ _modules.set(resolve$1(fileName), virtualModule);
123
+ }
124
+ return _modules;
125
+ };
126
+ return {
127
+ name: "virtual-bundle",
128
+ resolveId(id, importer) {
129
+ const modules = getModules();
130
+ if (modules.has(id)) return resolve$1(id);
131
+ if (importer) {
132
+ const resolved = resolve$1(dirname$1(importer), id);
133
+ if (modules.has(resolved)) return resolved;
134
+ }
135
+ return null;
136
+ },
137
+ load(id) {
138
+ const m = getModules().get(id);
139
+ if (!m) return null;
140
+ return m;
141
+ }
142
+ };
143
+ }
144
+
145
+ //#endregion
146
+ //#region src/build/vite/prod.ts
147
+ const BuilderNames = {
148
+ nitro: colors.magenta("Nitro"),
149
+ client: colors.green("Client"),
150
+ ssr: colors.blue("SSR")
151
+ };
152
+ async function buildEnvironments(ctx, builder) {
153
+ const nitro$1 = ctx.nitro;
154
+ for (const [envName, env] of Object.entries(builder.environments)) {
155
+ const fmtName = BuilderNames[envName] || (envName.length <= 3 ? envName.toUpperCase() : envName[0].toUpperCase() + envName.slice(1));
156
+ if (envName === "nitro" || !env.config.build.rollupOptions.input || env.isBuilt) {
157
+ if (![
158
+ "nitro",
159
+ "ssr",
160
+ "client"
161
+ ].includes(envName)) nitro$1.logger.info(env.isBuilt ? `Skipping ${fmtName} (already built)` : `Skipping ${fmtName} (no input defined)`);
162
+ continue;
163
+ }
164
+ if (!a && !T) console.log();
165
+ nitro$1.logger.start(`Building [${fmtName}]`);
166
+ await builder.build(env);
167
+ }
168
+ const nitroOptions = ctx.nitro.options;
169
+ const clientInput = builder.environments.client?.config?.build?.rollupOptions?.input;
170
+ if (nitroOptions.renderer?.template && nitroOptions.renderer?.template === clientInput) {
171
+ const outputPath = resolve$1(nitroOptions.output.publicDir, basename$1(clientInput));
172
+ if (existsSync(outputPath)) {
173
+ const html = await readFile(outputPath, "utf8").then((r) => r.replace("<!--ssr-outlet-->", `{{{ fetch($REQUEST, { viteEnv: "ssr" }) }}}`));
174
+ await rm(outputPath);
175
+ const tmp = resolve$1(nitroOptions.buildDir, "vite/index.html");
176
+ await mkdir(dirname$1(tmp), { recursive: true });
177
+ await writeFile(tmp, html, "utf8");
178
+ nitroOptions.renderer.template = tmp;
179
+ }
180
+ }
181
+ await builder.writeAssetsManifest?.();
182
+ if (!a && !T) console.log();
183
+ const buildInfo = [["preset", nitro$1.options.preset], ["compatibility", formatCompatibilityDate(nitro$1.options.compatibilityDate)]].filter((e) => e[1]);
184
+ nitro$1.logger.start(`Building [${BuilderNames.nitro}] ${colors.dim(`(${buildInfo.map(([k, v]) => `${k}: \`${v}\``).join(", ")})`)}`);
185
+ await copyPublicAssets(nitro$1);
186
+ await builder.build(builder.environments.nitro);
187
+ await nitro$1.close();
188
+ await nitro$1.hooks.callHook("compiled", nitro$1);
189
+ await writeBuildInfo(nitro$1);
190
+ const rOutput = relative$1(process.cwd(), nitro$1.options.output.dir);
191
+ const rewriteRelativePaths = (input) => {
192
+ return input.replace(/([\s:])\.\/(\S*)/g, `$1${rOutput}/$2`);
193
+ };
194
+ if (!a && !T) console.log();
195
+ if (nitro$1.options.commands.preview) nitro$1.logger.success(`You can preview this build using \`${rewriteRelativePaths(nitro$1.options.commands.preview)}\``);
196
+ if (nitro$1.options.commands.deploy) nitro$1.logger.success(`You can deploy this build using \`${rewriteRelativePaths(nitro$1.options.commands.deploy)}\``);
197
+ }
198
+ function prodSetup(ctx) {
199
+ const services = ctx.pluginConfig.services || {};
200
+ const serviceEntries = Object.keys(services).map((name) => {
201
+ let entry;
202
+ if (ctx.pluginConfig.experimental?.virtualBundle) entry = ctx._entryPoints[name];
203
+ else entry = resolve$1(ctx.nitro.options.buildDir, "vite/services", name, ctx._entryPoints[name]);
204
+ return [name, entry];
205
+ });
206
+ return `
207
+ import { setupVite } from "${resolve$1(runtimeDir, "internal/vite/prod-setup.mjs")}";
208
+
209
+ const manifest = ${JSON.stringify(ctx._manifest || {})};
210
+
211
+ function lazyService(loader) {
212
+ let promise, mod
213
+ return {
214
+ fetch(req) {
215
+ if (mod) { return mod.fetch(req) }
216
+ if (!promise) {
217
+ promise = loader().then(_mod => (mod = _mod.default || _mod))
218
+ }
219
+ return promise.then(mod => mod.fetch(req))
220
+ }
221
+ }
222
+ }
223
+
224
+ const services = {
225
+ ${serviceEntries.map(([name, entry]) => `[${JSON.stringify(name)}]: lazyService(() => import(${JSON.stringify(entry)}))`).join(",\n")}
226
+ };
227
+
228
+ setupVite({ manifest, services });
229
+ `;
230
+ }
231
+
232
+ //#endregion
233
+ //#region src/build/vite/dev.ts
234
+ function createFetchableDevEnvironment(name, config, devServer, entry) {
235
+ return new FetchableDevEnvironment(name, config, {
236
+ hot: true,
237
+ transport: createTransport(name, devServer)
238
+ }, devServer, entry);
239
+ }
240
+ var FetchableDevEnvironment = class extends DevEnvironment {
241
+ devServer;
242
+ constructor(name, config, context, devServer, entry) {
243
+ super(name, config, context);
244
+ this.devServer = devServer;
245
+ this.devServer.sendMessage({
246
+ type: "custom",
247
+ event: "nitro:vite-env",
248
+ data: {
249
+ name,
250
+ entry
251
+ }
252
+ });
253
+ }
254
+ async dispatchFetch(request) {
255
+ return this.devServer.fetch(request);
256
+ }
257
+ async init(...args) {
258
+ await this.devServer.init?.();
259
+ return super.init(...args);
260
+ }
261
+ };
262
+ function createTransport(name, hooks) {
263
+ const listeners = /* @__PURE__ */ new WeakMap();
264
+ return {
265
+ send: (data) => hooks.sendMessage({
266
+ ...data,
267
+ viteEnv: name
268
+ }),
269
+ on: (event, handler) => {
270
+ if (event === "connection") return;
271
+ const listener = (value) => {
272
+ if (value?.type === "custom" && value.event === event && value.viteEnv === name) handler(value.data, { send: (payload) => hooks.sendMessage({
273
+ ...payload,
274
+ viteEnv: name
275
+ }) });
276
+ };
277
+ listeners.set(handler, listener);
278
+ hooks.onMessage(listener);
279
+ },
280
+ off: (event, handler) => {
281
+ if (event === "connection") return;
282
+ const listener = listeners.get(handler);
283
+ if (listener) {
284
+ hooks.offMessage(listener);
285
+ listeners.delete(handler);
286
+ }
287
+ }
288
+ };
289
+ }
290
+ async function configureViteDevServer(ctx, server) {
291
+ const nitro$1 = ctx.nitro;
292
+ const nitroEnv$1 = server.environments.nitro;
293
+ const nitroConfigFile = nitro$1.options._c12.configFile;
294
+ if (nitroConfigFile) server.config.configFileDependencies.push(nitroConfigFile);
295
+ const reload = debounce(async () => {
296
+ await scanHandlers(nitro$1);
297
+ nitro$1.routing.sync();
298
+ nitroEnv$1.moduleGraph.invalidateAll();
299
+ nitroEnv$1.hot.send({ type: "full-reload" });
300
+ });
301
+ const scanDirs = nitro$1.options.scanDirs.flatMap((dir) => [
302
+ join$1(dir, nitro$1.options.apiDir || "api"),
303
+ join$1(dir, nitro$1.options.routesDir || "routes"),
304
+ join$1(dir, "middleware"),
305
+ join$1(dir, "plugins"),
306
+ join$1(dir, "modules")
307
+ ]);
308
+ const watchReloadEvents = new Set([
309
+ "add",
310
+ "addDir",
311
+ "unlink",
312
+ "unlinkDir"
313
+ ]);
314
+ const scanDirsWatcher = watch$1(scanDirs, { ignoreInitial: true }).on("all", (event, path$1, stat$1) => {
315
+ if (watchReloadEvents.has(event)) reload();
316
+ });
317
+ const srcDirWatcher = watch(nitro$1.options.srcDir, { persistent: false }, (_event, filename) => {
318
+ if (filename && /^server\.[mc]?[jt]sx?$/.test(filename)) reload();
319
+ });
320
+ nitro$1.hooks.hook("close", () => {
321
+ scanDirsWatcher.close();
322
+ srcDirWatcher.close();
323
+ });
324
+ const hostIPC = { async transformHTML(html) {
325
+ return server.transformIndexHtml("/", html).then((r) => r.replace("<!--ssr-outlet-->", `{{{ fetch($REQUEST, { viteEnv: "ssr" }) }}}`));
326
+ } };
327
+ nitroEnv$1.devServer.onMessage(async (payload) => {
328
+ if (payload.type === "custom" && payload.event === "nitro:vite-invoke") {
329
+ const res = await hostIPC[payload.data.name](payload.data.data).then((data) => ({ data })).catch((error) => ({ error }));
330
+ nitroEnv$1.devServer.sendMessage({
331
+ type: "custom",
332
+ event: "nitro:vite-invoke-response",
333
+ data: {
334
+ id: payload.data.id,
335
+ data: res
336
+ }
337
+ });
338
+ }
339
+ });
340
+ const nitroDevMiddleware = async (nodeReq, nodeRes, next) => {
341
+ if (/^\/@(?:vite|fs|id)\//.test(nodeReq.url) || nodeReq._nitroHandled) return next();
342
+ nodeReq._nitroHandled = true;
343
+ const req = new NodeRequest({
344
+ req: nodeReq,
345
+ res: nodeRes
346
+ });
347
+ const devAppRes = await ctx.devApp.fetch(req);
348
+ if (nodeRes.writableEnded || nodeRes.headersSent) return;
349
+ if (devAppRes.status !== 404) return await sendNodeResponse(nodeRes, devAppRes);
350
+ const envRes = await nitroEnv$1.dispatchFetch(req);
351
+ if (nodeRes.writableEnded || nodeRes.headersSent) return;
352
+ if (envRes.status !== 404) return await sendNodeResponse(nodeRes, envRes);
353
+ return next();
354
+ };
355
+ server.middlewares.use(function nitroDevMiddlewarePre(req, res, next) {
356
+ const fetchDest = req.headers["sec-fetch-dest"];
357
+ if (fetchDest) res.setHeader("vary", "sec-fetch-dest");
358
+ if (!((req.url || "").match(/\.([a-z0-9]+)(?:[?#]|$)/i)?.[1] || "") && (!fetchDest || /^(document|iframe|frame|empty)$/.test(fetchDest))) nitroDevMiddleware(req, res, next);
359
+ else next();
360
+ });
361
+ return () => {
362
+ server.middlewares.use(nitroDevMiddleware);
363
+ };
364
+ }
365
+
366
+ //#endregion
367
+ //#region src/build/vite/env.ts
368
+ function createDevWorker(ctx) {
369
+ return new NodeDevWorker({
370
+ name: "nitro-vite",
371
+ entry: resolve(runtimeDir, "internal/vite/dev-worker.mjs"),
372
+ hooks: {},
373
+ data: {
374
+ server: true,
375
+ globals: { __NITRO_RUNTIME_CONFIG__: ctx.nitro.options.runtimeConfig }
376
+ }
377
+ });
378
+ }
379
+ function createNitroEnvironment(ctx) {
380
+ return {
381
+ consumer: "server",
382
+ build: {
383
+ rollupOptions: ctx.rollupConfig.config,
384
+ minify: ctx.nitro.options.minify,
385
+ emptyOutDir: false,
386
+ commonjsOptions: {
387
+ strictRequires: "auto",
388
+ esmExternals: (id) => !id.startsWith("unenv/"),
389
+ requireReturnsDefault: "auto",
390
+ ...ctx.nitro.options.commonJS
391
+ }
392
+ },
393
+ resolve: {
394
+ noExternal: ctx.nitro.options.dev ? new RegExp(runtimeDependencies.join("|")) : true,
395
+ conditions: ctx.nitro.options.exportConditions,
396
+ externalConditions: ctx.nitro.options.exportConditions
397
+ },
398
+ dev: { createEnvironment: (envName, envConfig) => createFetchableDevEnvironment(envName, envConfig, ctx.devWorker, resolve(runtimeDir, "internal/vite/dev-entry.mjs")) }
399
+ };
400
+ }
401
+ function createServiceEnvironment(ctx, name, serviceConfig) {
402
+ return {
403
+ consumer: "server",
404
+ build: {
405
+ rollupOptions: { input: serviceConfig.entry },
406
+ minify: ctx.nitro.options.minify,
407
+ outDir: join(ctx.nitro.options.buildDir, "vite", "services", name),
408
+ emptyOutDir: true
409
+ },
410
+ resolve: {
411
+ conditions: ctx.nitro.options.exportConditions,
412
+ externalConditions: ctx.nitro.options.exportConditions
413
+ },
414
+ dev: { createEnvironment: (envName, envConfig) => createFetchableDevEnvironment(envName, envConfig, ctx.devWorker, tryResolve(serviceConfig.entry)) }
415
+ };
416
+ }
417
+ function createServiceEnvironments(ctx) {
418
+ return Object.fromEntries(Object.entries(ctx.pluginConfig.services || {}).map(([name, config]) => [name, createServiceEnvironment(ctx, name, config)]));
419
+ }
420
+ function tryResolve(id) {
421
+ if (/^[~#/\0]/.test(id) || isAbsolute$1(id)) return id;
422
+ return resolveModulePath(id, {
423
+ suffixes: ["", "/index"],
424
+ extensions: [
425
+ "",
426
+ ".ts",
427
+ ".mjs",
428
+ ".cjs",
429
+ ".js",
430
+ ".mts",
431
+ ".cts"
432
+ ],
433
+ try: true
434
+ }) || id;
435
+ }
436
+
437
+ //#endregion
438
+ //#region src/build/vite/preview.ts
439
+ function nitroPreviewPlugin(ctx) {
440
+ return {
441
+ name: "nitro:preview",
442
+ apply: (_config, configEnv) => !!configEnv.isPreview,
443
+ config(config) {
444
+ return { preview: { port: config.preview?.port || 3e3 } };
445
+ },
446
+ async configurePreviewServer(server) {
447
+ const buildInfoPath = resolve$1(server.config.root, "node_modules/.nitro/last-build", "nitro.json");
448
+ if (!existsSync(buildInfoPath)) {
449
+ console.warn(`[nitro] No build found. Please build your project before previewing.`);
450
+ return;
451
+ }
452
+ const realBuildDir = await readlink("node_modules/.nitro/last-build");
453
+ const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
454
+ const info = [
455
+ ["Build Directory:", prettyPath(realBuildDir)],
456
+ ["Date:", buildInfo.date && new Date(buildInfo.date).toLocaleString()],
457
+ ["Nitro Version:", buildInfo.versions.nitro],
458
+ ["Nitro Preset:", buildInfo.preset],
459
+ buildInfo.framework?.name !== "nitro" && ["Framework:", buildInfo.framework?.name + (buildInfo.framework?.version ? ` (v${buildInfo.framework.version})` : "")]
460
+ ].filter((i) => i && i[1]);
461
+ consola$1.box({
462
+ title: " [Build Info] ",
463
+ message: info.map((i) => `- ${i[0]} ${i[1]}`).join("\n")
464
+ });
465
+ if (!buildInfo.commands?.preview) {
466
+ consola$1.warn("[nitro] No preview command found for this preset..");
467
+ return;
468
+ }
469
+ const randomPort = await getRandomPort();
470
+ consola$1.info(`Spawning preview server...`);
471
+ const [command, ...args] = buildInfo.commands.preview.split(" ");
472
+ let child;
473
+ consola$1.info(buildInfo.commands?.preview);
474
+ child = spawn(command, args, {
475
+ stdio: "inherit",
476
+ cwd: realBuildDir,
477
+ env: {
478
+ ...process.env,
479
+ PORT: String(randomPort)
480
+ }
481
+ });
482
+ process.on("exit", () => {
483
+ child?.kill();
484
+ child = void 0;
485
+ });
486
+ child.on("exit", (code) => {
487
+ if (code && code !== 0) consola$1.error(`[nitro] Preview server exited with code ${code}`);
488
+ });
489
+ const proxy = createProxyServer({ target: `http://localhost:${randomPort}` });
490
+ server.middlewares.use((req, res, next) => {
491
+ if (child && !child.killed) proxy.web(req, res).catch(next);
492
+ else res.end(`Nitro preview server is not running.`);
493
+ });
494
+ }
495
+ };
496
+ }
497
+
498
+ //#endregion
499
+ //#region src/build/vite/plugin.ts
500
+ const DEFAULT_EXTENSIONS = [
501
+ ".ts",
502
+ ".js",
503
+ ".mts",
504
+ ".mjs",
505
+ ".tsx",
506
+ ".jsx"
507
+ ];
508
+ const debug = process.env.NITRO_DEBUG ? (...args) => console.log("[nitro]", ...args) : () => {};
509
+ function nitro(pluginConfig = {}) {
510
+ const ctx = createContext(pluginConfig);
511
+ return [
512
+ nitroInit(ctx),
513
+ nitroEnv(ctx),
514
+ nitroMain(ctx),
515
+ nitroPrepare(ctx),
516
+ nitroService(ctx),
517
+ nitroPreviewPlugin(ctx),
518
+ pluginConfig.experimental?.assetsImport !== false && assetsPlugin({ experimental: { clientBuildFallback: false } })
519
+ ];
520
+ }
521
+ function nitroInit(ctx) {
522
+ return {
523
+ name: "nitro:init",
524
+ sharedDuringBuild: true,
525
+ apply: (_config, configEnv) => !configEnv.isPreview,
526
+ async config(config, configEnv) {
527
+ if (!ctx._initialized) {
528
+ debug("[init] Initializing nitro");
529
+ ctx._initialized = true;
530
+ await setupNitroContext(ctx, configEnv, config);
531
+ }
532
+ },
533
+ applyToEnvironment(env) {
534
+ if (env.name === "nitro" && ctx.nitro?.options.dev) {
535
+ debug("[init] Adding rollup plugins for dev");
536
+ return [...ctx.rollupConfig?.config.plugins || []];
537
+ }
538
+ }
539
+ };
540
+ }
541
+ function nitroEnv(ctx) {
542
+ return {
543
+ name: "nitro:env",
544
+ sharedDuringBuild: true,
545
+ apply: (_config, configEnv) => !configEnv.isPreview,
546
+ async config(userConfig, _configEnv) {
547
+ debug("[env] Extending config (environments)");
548
+ const environments = {
549
+ ...createServiceEnvironments(ctx),
550
+ nitro: createNitroEnvironment(ctx)
551
+ };
552
+ environments.client = {
553
+ consumer: userConfig.environments?.client?.consumer ?? "client",
554
+ build: { rollupOptions: { input: userConfig.environments?.client?.build?.rollupOptions?.input ?? useNitro(ctx).options.renderer?.template } }
555
+ };
556
+ debug("[env] Environments:", Object.keys(environments).join(", "));
557
+ return { environments };
558
+ },
559
+ configEnvironment(name, config) {
560
+ if (config.consumer === "client") {
561
+ debug("[env] Configuring client environment", name === "client" ? "" : ` (${name})`);
562
+ config.build.emptyOutDir = false;
563
+ config.build.outDir = useNitro(ctx).options.output.publicDir;
564
+ } else if (ctx.pluginConfig.experimental?.virtualBundle && name in (ctx.pluginConfig.services || {})) {
565
+ debug("[env] Configuring service environment for virtual:", name);
566
+ config.build ??= {};
567
+ config.build.write = config.build.write ?? false;
568
+ }
569
+ }
570
+ };
571
+ }
572
+ function nitroMain(ctx) {
573
+ return {
574
+ name: "nitro:main",
575
+ sharedDuringBuild: true,
576
+ apply: (_config, configEnv) => !configEnv.isPreview,
577
+ async config(userConfig, _configEnv) {
578
+ debug("[main] Extending config (appType, resolve, server)");
579
+ if (!ctx.rollupConfig) throw new Error("Nitro rollup config is not initialized yet.");
580
+ return {
581
+ appType: userConfig.appType || "custom",
582
+ resolve: { alias: ctx.rollupConfig.base.aliases },
583
+ builder: { sharedConfigBuild: true },
584
+ server: {
585
+ port: Number.parseInt(process.env.PORT || "") || userConfig.server?.port || useNitro(ctx).options.devServer?.port || 3e3,
586
+ cors: false
587
+ }
588
+ };
589
+ },
590
+ configResolved(config) {
591
+ if (config.command === "build") {
592
+ debug("[main] Inferring caching routes");
593
+ for (const env of Object.values(config.environments)) if (env.consumer === "client") {
594
+ const rule = ctx.nitro.options.routeRules[`/${env.build.assetsDir}/**`] ??= {};
595
+ if (!rule.headers?.["cache-control"]) rule.headers = {
596
+ ...rule.headers,
597
+ "cache-control": `public, max-age=31536000, immutable`
598
+ };
599
+ }
600
+ }
601
+ debug("[main] Syncing nitro routes");
602
+ ctx.nitro.routing.sync();
603
+ },
604
+ buildApp: {
605
+ order: "post",
606
+ handler(builder) {
607
+ debug("[main] Building environments");
608
+ return buildEnvironments(ctx, builder);
609
+ }
610
+ },
611
+ generateBundle: { handler(_options, bundle) {
612
+ const environment = this.environment;
613
+ debug("[main] Generating manifest and entry points for environment:", environment.name);
614
+ const { root } = environment.config;
615
+ const services = ctx.pluginConfig.services || {};
616
+ const isRegisteredService = Object.keys(services).includes(environment.name);
617
+ let entryFile;
618
+ for (const [_name, file] of Object.entries(bundle)) if (file.type === "chunk") {
619
+ if (isRegisteredService && file.isEntry) if (entryFile === void 0) entryFile = file.fileName;
620
+ else this.warn(`Multiple entry points found for service "${environment.name}"`);
621
+ const filteredModuleIds = file.moduleIds.filter((id) => id.startsWith(root));
622
+ for (const id of filteredModuleIds) {
623
+ const originalFile = relative$1(root, id);
624
+ ctx._manifest[originalFile] = { file: file.fileName };
625
+ }
626
+ }
627
+ if (isRegisteredService) {
628
+ if (entryFile === void 0) this.error(`No entry point found for service "${this.environment.name}".`);
629
+ ctx._entryPoints[this.environment.name] = entryFile;
630
+ ctx._serviceBundles[this.environment.name] = bundle;
631
+ }
632
+ } },
633
+ configureServer: (server) => {
634
+ debug("[main] Configuring dev server");
635
+ return configureViteDevServer(ctx, server);
636
+ },
637
+ hotUpdate(options) {
638
+ if (this.environment.name === "client" || ctx.pluginConfig.experimental?.serverReload === false) return;
639
+ let hasServerOnlyModule = false;
640
+ const invalidated = /* @__PURE__ */ new Set();
641
+ for (const mod of options.modules) {
642
+ if (!mod.id) continue;
643
+ if (options.server.environments.client.moduleGraph.getModuleById(mod.id)) continue;
644
+ this.environment.moduleGraph.invalidateModule(mod, invalidated, options.timestamp, false);
645
+ hasServerOnlyModule = true;
646
+ }
647
+ if (hasServerOnlyModule) {
648
+ options.server.ws.send({ type: "full-reload" });
649
+ return [];
650
+ }
651
+ }
652
+ };
653
+ }
654
+ function nitroPrepare(ctx) {
655
+ return {
656
+ name: "nitro:prepare",
657
+ sharedDuringBuild: true,
658
+ applyToEnvironment: (env) => env.name === "nitro",
659
+ buildApp: {
660
+ order: "pre",
661
+ async handler() {
662
+ debug("[prepare] Preparing output directory");
663
+ const nitro$1 = ctx.nitro;
664
+ await prepare(nitro$1);
665
+ }
666
+ }
667
+ };
668
+ }
669
+ function nitroService(ctx) {
670
+ return {
671
+ name: "nitro:service",
672
+ enforce: "pre",
673
+ sharedDuringBuild: true,
674
+ applyToEnvironment: (env) => env.name === "nitro",
675
+ resolveId: { async handler(id) {
676
+ if (id === "#nitro-vite-setup") return {
677
+ id,
678
+ moduleSideEffects: true
679
+ };
680
+ if (id === "#nitro-vite-services") return id;
681
+ } },
682
+ load: { async handler(id) {
683
+ if (id === "#nitro-vite-setup") return prodSetup(ctx);
684
+ } }
685
+ };
686
+ }
687
+ function createContext(pluginConfig) {
688
+ return {
689
+ pluginConfig,
690
+ _entryPoints: {},
691
+ _manifest: {},
692
+ _serviceBundles: {}
693
+ };
694
+ }
695
+ function useNitro(ctx) {
696
+ if (!ctx.nitro) throw new Error("Nitro instance is not initialized yet.");
697
+ return ctx.nitro;
698
+ }
699
+ async function setupNitroContext(ctx, configEnv, userConfig) {
700
+ ctx.nitro = ctx.pluginConfig._nitro || await createNitro({
701
+ dev: configEnv.mode === "development",
702
+ rootDir: userConfig.root,
703
+ ...defu(ctx.pluginConfig.config, userConfig.nitro)
704
+ });
705
+ if (!ctx.pluginConfig.services?.ssr) {
706
+ ctx.pluginConfig.services ??= {};
707
+ if (userConfig.environments?.ssr === void 0) {
708
+ const ssrEntry = resolveModulePath("./entry-server", {
709
+ from: [
710
+ "",
711
+ "app",
712
+ "src"
713
+ ].flatMap((d) => ctx.nitro.options.scanDirs.map((s) => join$1(s, d) + "/")),
714
+ extensions: DEFAULT_EXTENSIONS,
715
+ try: true
716
+ });
717
+ if (ssrEntry) {
718
+ ctx.pluginConfig.services.ssr = { entry: ssrEntry };
719
+ ctx.nitro.logger.info(`Using \`${prettyPath(ssrEntry)}\` as vite ssr entry.`);
720
+ }
721
+ } else {
722
+ let ssrEntry = getEntry(userConfig.environments.ssr.build?.rollupOptions?.input);
723
+ if (typeof ssrEntry === "string") {
724
+ ssrEntry = resolveModulePath(ssrEntry, {
725
+ from: ctx.nitro.options.scanDirs,
726
+ extensions: DEFAULT_EXTENSIONS,
727
+ suffixes: ["", "/index"],
728
+ try: true
729
+ }) || ssrEntry;
730
+ ctx.pluginConfig.services.ssr = { entry: ssrEntry };
731
+ } else throw new TypeError(`Invalid input type for SSR entry point.`);
732
+ }
733
+ }
734
+ if (!ctx.nitro.options.renderer?.entry && !ctx.nitro.options.renderer?.template && ctx.pluginConfig.services.ssr?.entry) {
735
+ ctx.nitro.options.renderer ??= {};
736
+ ctx.nitro.options.renderer.entry = resolve$1(runtimeDir, "internal/vite/ssr-renderer");
737
+ }
738
+ const publicDistDir = ctx._publicDistDir = userConfig.build?.outDir || resolve$1(ctx.nitro.options.buildDir, "vite/public");
739
+ ctx.nitro.options.publicAssets.push({
740
+ dir: publicDistDir,
741
+ maxAge: 0,
742
+ baseURL: "/",
743
+ fallthrough: true
744
+ });
745
+ if (!ctx.nitro.options.dev) ctx.nitro.options.unenv.push({
746
+ meta: { name: "nitro-vite" },
747
+ polyfill: ["#nitro-vite-setup"]
748
+ });
749
+ await ctx.nitro.hooks.callHook("build:before", ctx.nitro);
750
+ ctx.rollupConfig = await getViteRollupConfig(ctx);
751
+ await ctx.nitro.hooks.callHook("rollup:before", ctx.nitro, ctx.rollupConfig.config);
752
+ if (ctx.nitro.options.dev && !ctx.devWorker) ctx.devWorker = createDevWorker(ctx);
753
+ if (ctx.nitro.options.dev && !ctx.devApp) ctx.devApp = new NitroDevApp(ctx.nitro);
754
+ }
755
+ function getEntry(input) {
756
+ if (typeof input === "string") return input;
757
+ else if (Array.isArray(input) && input.length > 0) return input[0];
758
+ else if (input && "index" in input) return input.index;
759
+ }
760
+
761
+ //#endregion
762
+ export { nitro as t };