nitro-nightly 4.0.0-20251010-091516-7cafddba → 4.0.0-20251030-121649-98b56dfe

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 (252) 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 +747 -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/_libs/fdir.mjs +514 -0
  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/_libs/js-tokens.mjs +382 -0
  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/_libs/magic-string.mjs +939 -0
  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/_libs/rou3.mjs +311 -0
  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/_libs/tinyglobby.mjs +292 -0
  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/_libs/vite-plugin-fullstack.mjs +561 -0
  76. package/dist/_presets.mjs +1723 -0
  77. package/dist/builder.d.mts +54 -0
  78. package/dist/builder.mjs +45 -0
  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 +20 -476
  97. package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
  98. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
  99. package/dist/node_modules/@speed-highlight/core/package.json +7 -3
  100. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  101. package/dist/node_modules/cookie-es/package.json +37 -0
  102. package/dist/node_modules/hookable/dist/index.mjs +243 -266
  103. package/dist/node_modules/hookable/package.json +29 -26
  104. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  105. package/dist/node_modules/rendu/package.json +47 -0
  106. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
  107. package/dist/presets/_nitro/runtime/nitro-dev.mjs +44 -38
  108. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
  109. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +9 -12
  110. package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
  111. package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
  112. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
  113. package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
  114. package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
  115. package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
  116. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
  117. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
  118. package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
  119. package/dist/presets/azure/runtime/_utils.mjs +43 -43
  120. package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
  121. package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
  122. package/dist/presets/bun/runtime/bun.d.mts +1 -0
  123. package/dist/presets/bun/runtime/bun.mjs +18 -17
  124. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
  125. package/dist/presets/cloudflare/runtime/_module-handler.mjs +79 -87
  126. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
  127. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +55 -61
  128. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
  129. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
  130. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
  131. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
  132. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
  133. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +89 -82
  134. package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
  135. package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
  136. package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
  137. package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
  138. package/dist/presets/deno/runtime/deno-server.mjs +31 -39
  139. package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
  140. package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
  141. package/dist/presets/netlify/runtime/netlify.mjs +11 -17
  142. package/dist/presets/node/runtime/node-cluster.mjs +49 -48
  143. package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
  144. package/dist/presets/node/runtime/node-middleware.mjs +7 -6
  145. package/dist/presets/node/runtime/node-server.mjs +34 -24
  146. package/dist/presets/standard/runtime/server.d.mts +1 -3
  147. package/dist/presets/standard/runtime/server.mjs +1 -3
  148. package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
  149. package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
  150. package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
  151. package/dist/presets/vercel/runtime/vercel.mjs +15 -14
  152. package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
  153. package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
  154. package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
  155. package/dist/runtime/index.d.mts +13 -2
  156. package/dist/runtime/index.mjs +13 -8
  157. package/dist/runtime/internal/app.d.mts +3 -1
  158. package/dist/runtime/internal/app.mjs +179 -140
  159. package/dist/runtime/internal/cache.d.mts +10 -4
  160. package/dist/runtime/internal/cache.mjs +247 -216
  161. package/dist/runtime/internal/context.d.mts +9 -9
  162. package/dist/runtime/internal/context.mjs +17 -10
  163. package/dist/runtime/internal/database.mjs +8 -10
  164. package/dist/runtime/internal/error/dev.d.mts +5 -4
  165. package/dist/runtime/internal/error/dev.mjs +106 -105
  166. package/dist/runtime/internal/error/prod.d.mts +5 -4
  167. package/dist/runtime/internal/error/prod.mjs +51 -59
  168. package/dist/runtime/internal/error/utils.d.mts +4 -4
  169. package/dist/runtime/internal/error/utils.mjs +1 -1
  170. package/dist/runtime/internal/index.d.mts +2 -0
  171. package/dist/runtime/internal/index.mjs +2 -0
  172. package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
  173. package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
  174. package/dist/runtime/internal/meta.d.mts +1 -1
  175. package/dist/runtime/internal/meta.mjs +1 -1
  176. package/dist/runtime/internal/plugin.d.mts +2 -2
  177. package/dist/runtime/internal/plugin.mjs +1 -1
  178. package/dist/runtime/internal/renderer.mjs +40 -32
  179. package/dist/runtime/internal/route-rules.d.mts +8 -8
  180. package/dist/runtime/internal/route-rules.mjs +53 -51
  181. package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -2
  182. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
  183. package/dist/runtime/internal/routes/openapi.d.mts +1 -0
  184. package/dist/runtime/internal/routes/openapi.mjs +81 -87
  185. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  186. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
  187. package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
  188. package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
  189. package/dist/runtime/internal/routes/scalar.d.mts +1 -0
  190. package/dist/runtime/internal/routes/scalar.mjs +22 -23
  191. package/dist/runtime/internal/routes/swagger.d.mts +1 -0
  192. package/dist/runtime/internal/routes/swagger.mjs +9 -11
  193. package/dist/runtime/internal/runtime-config.d.mts +4 -4
  194. package/dist/runtime/internal/runtime-config.mjs +40 -35
  195. package/dist/runtime/internal/shutdown.d.mts +2 -8
  196. package/dist/runtime/internal/shutdown.mjs +32 -30
  197. package/dist/runtime/internal/static.mjs +63 -74
  198. package/dist/runtime/internal/storage.mjs +2 -2
  199. package/dist/runtime/internal/task.d.mts +6 -6
  200. package/dist/runtime/internal/task.mjs +56 -60
  201. package/dist/runtime/internal/utils.d.mts +1 -1
  202. package/dist/runtime/internal/utils.mjs +4 -10
  203. package/dist/types/index.d.mts +2594 -2286
  204. package/dist/types/index.mjs +1 -1
  205. package/dist/vite.d.mts +56 -47
  206. package/dist/vite.mjs +55 -68
  207. package/lib/index.d.mts +1 -0
  208. package/lib/index.mjs +1 -0
  209. package/lib/runtime/meta.mjs +35 -0
  210. package/package.json +49 -50
  211. package/dist/_chunks/app.mjs +0 -19797
  212. package/dist/_chunks/build.mjs +0 -84
  213. package/dist/_chunks/build2.mjs +0 -318
  214. package/dist/_chunks/build3.mjs +0 -6452
  215. package/dist/_chunks/detect-acorn.mjs +0 -503
  216. package/dist/_chunks/index.mjs +0 -22242
  217. package/dist/_chunks/index2.mjs +0 -297
  218. package/dist/_chunks/index3.mjs +0 -1058
  219. package/dist/_chunks/index4.mjs +0 -1206
  220. package/dist/_chunks/info.mjs +0 -11157
  221. package/dist/_chunks/json5.mjs +0 -68
  222. package/dist/_chunks/jsonc.mjs +0 -51
  223. package/dist/_chunks/pathe.M-eThtNZ.mjs +0 -204
  224. package/dist/_chunks/plugin.mjs +0 -960
  225. package/dist/_chunks/server.mjs +0 -254
  226. package/dist/_chunks/snapshot.mjs +0 -284
  227. package/dist/_chunks/toml.mjs +0 -259
  228. package/dist/_chunks/yaml.mjs +0 -86
  229. package/dist/cli/build.mjs +0 -54
  230. package/dist/cli/common.mjs +0 -13
  231. package/dist/cli/dev.mjs +0 -95
  232. package/dist/cli/index2.mjs +0 -17
  233. package/dist/cli/list.mjs +0 -34
  234. package/dist/cli/prepare.mjs +0 -24
  235. package/dist/cli/run.mjs +0 -60
  236. package/dist/index.d.mts +0 -52
  237. package/dist/index.mjs +0 -55
  238. package/dist/node_modules/klona/dist/index.mjs +0 -81
  239. package/dist/node_modules/klona/full/index.mjs +0 -53
  240. package/dist/node_modules/klona/package.json +0 -74
  241. package/dist/node_modules/std-env/dist/index.mjs +0 -1
  242. package/dist/node_modules/std-env/package.json +0 -46
  243. package/dist/presets.mjs +0 -2460
  244. package/dist/runtime/internal/debug.d.mts +0 -2
  245. package/dist/runtime/internal/debug.mjs +0 -5
  246. package/dist/runtime/internal/empty.d.mts +0 -0
  247. package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
  248. package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
  249. package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
  250. package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
  251. package/lib/runtime-meta.mjs +0 -38
  252. /package/lib/{runtime-meta.d.mts → runtime/meta.d.mts} +0 -0
@@ -0,0 +1,747 @@
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
+ };
638
+ }
639
+ function nitroPrepare(ctx) {
640
+ return {
641
+ name: "nitro:prepare",
642
+ sharedDuringBuild: true,
643
+ applyToEnvironment: (env) => env.name === "nitro",
644
+ buildApp: {
645
+ order: "pre",
646
+ async handler() {
647
+ debug("[prepare] Preparing output directory");
648
+ const nitro$1 = ctx.nitro;
649
+ await prepare(nitro$1);
650
+ }
651
+ }
652
+ };
653
+ }
654
+ function nitroService(ctx) {
655
+ return {
656
+ name: "nitro:service",
657
+ enforce: "pre",
658
+ sharedDuringBuild: true,
659
+ applyToEnvironment: (env) => env.name === "nitro",
660
+ resolveId: { async handler(id) {
661
+ if (id === "#nitro-vite-setup") return {
662
+ id,
663
+ moduleSideEffects: true
664
+ };
665
+ if (id === "#nitro-vite-services") return id;
666
+ } },
667
+ load: { async handler(id) {
668
+ if (id === "#nitro-vite-setup") return prodSetup(ctx);
669
+ } }
670
+ };
671
+ }
672
+ function createContext(pluginConfig) {
673
+ return {
674
+ pluginConfig,
675
+ _entryPoints: {},
676
+ _manifest: {},
677
+ _serviceBundles: {}
678
+ };
679
+ }
680
+ function useNitro(ctx) {
681
+ if (!ctx.nitro) throw new Error("Nitro instance is not initialized yet.");
682
+ return ctx.nitro;
683
+ }
684
+ async function setupNitroContext(ctx, configEnv, userConfig) {
685
+ ctx.nitro = ctx.pluginConfig._nitro || await createNitro({
686
+ dev: configEnv.mode === "development",
687
+ rootDir: userConfig.root,
688
+ ...defu(ctx.pluginConfig.config, userConfig.nitro)
689
+ });
690
+ if (!ctx.pluginConfig.services?.ssr) {
691
+ ctx.pluginConfig.services ??= {};
692
+ if (userConfig.environments?.ssr === void 0) {
693
+ const ssrEntry = resolveModulePath("./entry-server", {
694
+ from: [
695
+ "",
696
+ "app",
697
+ "src"
698
+ ].flatMap((d) => ctx.nitro.options.scanDirs.map((s) => join$1(s, d) + "/")),
699
+ extensions: DEFAULT_EXTENSIONS,
700
+ try: true
701
+ });
702
+ if (ssrEntry) {
703
+ ctx.pluginConfig.services.ssr = { entry: ssrEntry };
704
+ ctx.nitro.logger.info(`Using \`${prettyPath(ssrEntry)}\` as vite ssr entry.`);
705
+ }
706
+ } else {
707
+ let ssrEntry = getEntry(userConfig.environments.ssr.build?.rollupOptions?.input);
708
+ if (typeof ssrEntry === "string") {
709
+ ssrEntry = resolveModulePath(ssrEntry, {
710
+ from: ctx.nitro.options.scanDirs,
711
+ extensions: DEFAULT_EXTENSIONS,
712
+ suffixes: ["", "/index"],
713
+ try: true
714
+ }) || ssrEntry;
715
+ ctx.pluginConfig.services.ssr = { entry: ssrEntry };
716
+ } else throw new TypeError(`Invalid input type for SSR entry point.`);
717
+ }
718
+ }
719
+ if (!ctx.nitro.options.renderer?.entry && !ctx.nitro.options.renderer?.template && ctx.pluginConfig.services.ssr?.entry) {
720
+ ctx.nitro.options.renderer ??= {};
721
+ ctx.nitro.options.renderer.entry = resolve$1(runtimeDir, "internal/vite/ssr-renderer");
722
+ }
723
+ const publicDistDir = ctx._publicDistDir = userConfig.build?.outDir || resolve$1(ctx.nitro.options.buildDir, "vite/public");
724
+ ctx.nitro.options.publicAssets.push({
725
+ dir: publicDistDir,
726
+ maxAge: 0,
727
+ baseURL: "/",
728
+ fallthrough: true
729
+ });
730
+ if (!ctx.nitro.options.dev) ctx.nitro.options.unenv.push({
731
+ meta: { name: "nitro-vite" },
732
+ polyfill: ["#nitro-vite-setup"]
733
+ });
734
+ await ctx.nitro.hooks.callHook("build:before", ctx.nitro);
735
+ ctx.rollupConfig = await getViteRollupConfig(ctx);
736
+ await ctx.nitro.hooks.callHook("rollup:before", ctx.nitro, ctx.rollupConfig.config);
737
+ if (ctx.nitro.options.dev && !ctx.devWorker) ctx.devWorker = createDevWorker(ctx);
738
+ if (ctx.nitro.options.dev && !ctx.devApp) ctx.devApp = new NitroDevApp(ctx.nitro);
739
+ }
740
+ function getEntry(input) {
741
+ if (typeof input === "string") return input;
742
+ else if (Array.isArray(input) && input.length > 0) return input[0];
743
+ else if (input && "index" in input) return input.index;
744
+ }
745
+
746
+ //#endregion
747
+ export { nitro as t };