nitro-nightly 3.1.0-20251028-110430-e607b753 → 3.1.0-20251028-132924-f89aefa2

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 (157) hide show
  1. package/dist/_build/build.mjs +379 -14
  2. package/dist/_build/{rollup.mjs → build2.mjs} +218 -68
  3. package/dist/_build/info.mjs +963 -7
  4. package/dist/_build/prepare.mjs +1491 -2
  5. package/dist/_build/snapshot.mjs +155 -31
  6. package/dist/_build/vite.mjs +43 -2307
  7. package/dist/_build/vite2.mjs +149 -0
  8. package/dist/{_deps → _chunks/_deps}/c12.mjs +1 -1
  9. package/dist/{_deps → _chunks/_deps}/giget.mjs +1 -1
  10. package/dist/_chunks/_deps/klona.mjs +137 -0
  11. package/dist/{_deps → _chunks/_deps}/knitwork.mjs +1 -1
  12. package/dist/{_deps → _chunks/_deps}/local-pkg.mjs +1 -1
  13. package/dist/{_deps → _chunks/_deps}/mlly.mjs +1 -1
  14. package/dist/{_deps → _chunks/_deps}/nypm.mjs +1 -1
  15. package/dist/{_deps → _chunks/_deps}/pathe.mjs +1 -1
  16. package/dist/{_deps → _chunks/_deps}/pkg-types.mjs +2 -2
  17. package/dist/{_deps → _chunks/_deps}/rou3.mjs +1 -1
  18. package/dist/_chunks/_deps/std-env.mjs +3 -0
  19. package/dist/{_deps → _chunks/_deps}/unimport.mjs +2 -2
  20. package/dist/{_deps → _chunks/_deps}/unplugin-utils.mjs +1 -1
  21. package/dist/{_deps → _chunks/_deps}/untyped.mjs +1 -1
  22. package/dist/{_deps → _chunks/_deps}/unwasm.mjs +2 -2
  23. package/dist/{_presets → _chunks/_presets}/_resolve.mjs +2 -2
  24. package/dist/{_presets → _chunks/_presets}/_utils.mjs +1 -1
  25. package/dist/{_presets → _chunks/_presets}/azure.mjs +1 -1
  26. package/dist/{_presets → _chunks/_presets}/cloudflare.mjs +4 -4
  27. package/dist/{_presets → _chunks/_presets}/deno.mjs +1 -1
  28. package/dist/{_presets → _chunks/_presets}/firebase.mjs +1 -1
  29. package/dist/{_presets → _chunks/_presets}/iis.mjs +1 -1
  30. package/dist/{_presets → _chunks/_presets}/index.mjs +1 -1
  31. package/dist/{_presets → _chunks/_presets}/vercel.mjs +3 -3
  32. package/dist/{_presets → _chunks/_presets}/zeabur.mjs +1 -1
  33. package/dist/_chunks/app.mjs +600 -0
  34. package/dist/_chunks/index.mjs +648 -0
  35. package/dist/_chunks/server.mjs +256 -0
  36. package/dist/_cli/build.mjs +2 -2
  37. package/dist/_cli/dev.mjs +46 -130
  38. package/dist/_cli/index.mjs +1 -1
  39. package/dist/_cli/list.mjs +2 -2
  40. package/dist/_cli/prepare.mjs +2 -2
  41. package/dist/_cli/run.mjs +2 -2
  42. package/dist/cli/index.mjs +1 -1
  43. package/dist/index.mjs +94 -120
  44. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  45. package/dist/node_modules/cookie-es/package.json +37 -0
  46. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  47. package/dist/node_modules/rendu/package.json +47 -0
  48. package/dist/runtime/internal/task.mjs +1 -2
  49. package/dist/types/index.d.mts +2 -1
  50. package/dist/vite.mjs +103 -114
  51. package/lib/runtime/meta.mjs +18 -25
  52. package/package.json +9 -10
  53. package/dist/_build/assets.mjs +0 -235
  54. package/dist/_build/config.mjs +0 -124
  55. package/dist/_build/plugins.mjs +0 -1041
  56. package/dist/_build/rolldown.mjs +0 -494
  57. package/dist/_build/types.mjs +0 -268
  58. package/dist/node_modules/klona/dist/index.mjs +0 -81
  59. package/dist/node_modules/klona/full/index.mjs +0 -53
  60. package/dist/node_modules/klona/package.json +0 -74
  61. package/dist/node_modules/std-env/dist/index.mjs +0 -1
  62. package/dist/node_modules/std-env/package.json +0 -46
  63. /package/dist/{_deps → _chunks/_deps}/@jridgewell/gen-mapping.mjs +0 -0
  64. /package/dist/{_deps → _chunks/_deps}/@jridgewell/remapping.mjs +0 -0
  65. /package/dist/{_deps → _chunks/_deps}/@jridgewell/resolve-uri.mjs +0 -0
  66. /package/dist/{_deps → _chunks/_deps}/@jridgewell/sourcemap-codec.mjs +0 -0
  67. /package/dist/{_deps → _chunks/_deps}/@jridgewell/trace-mapping.mjs +0 -0
  68. /package/dist/{_deps → _chunks/_deps}/@pi0/vite-plugin-fullstack.mjs +0 -0
  69. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-alias.mjs +0 -0
  70. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-commonjs.mjs +0 -0
  71. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-inject.mjs +0 -0
  72. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-json.mjs +0 -0
  73. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-node-resolve.mjs +0 -0
  74. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-replace.mjs +0 -0
  75. /package/dist/{_deps → _chunks/_deps}/@rollup/pluginutils.mjs +0 -0
  76. /package/dist/{_deps → _chunks/_deps}/acorn.mjs +0 -0
  77. /package/dist/{_deps → _chunks/_deps}/chokidar.mjs +0 -0
  78. /package/dist/{_deps → _chunks/_deps}/citty.mjs +0 -0
  79. /package/dist/{_deps → _chunks/_deps}/commondir.mjs +0 -0
  80. /package/dist/{_deps → _chunks/_deps}/compatx.mjs +0 -0
  81. /package/dist/{_deps → _chunks/_deps}/confbox.mjs +0 -0
  82. /package/dist/{_deps → _chunks/_deps}/debug.mjs +0 -0
  83. /package/dist/{_deps → _chunks/_deps}/deepmerge.mjs +0 -0
  84. /package/dist/{_deps → _chunks/_deps}/depd.mjs +0 -0
  85. /package/dist/{_deps → _chunks/_deps}/dot-prop.mjs +0 -0
  86. /package/dist/{_deps → _chunks/_deps}/dotenv.mjs +0 -0
  87. /package/dist/{_deps → _chunks/_deps}/duplexer.mjs +0 -0
  88. /package/dist/{_deps → _chunks/_deps}/ee-first.mjs +0 -0
  89. /package/dist/{_deps → _chunks/_deps}/encodeurl.mjs +0 -0
  90. /package/dist/{_deps → _chunks/_deps}/escape-html.mjs +0 -0
  91. /package/dist/{_deps → _chunks/_deps}/escape-string-regexp.mjs +0 -0
  92. /package/dist/{_deps → _chunks/_deps}/estree-walker.mjs +0 -0
  93. /package/dist/{_deps → _chunks/_deps}/etag.mjs +0 -0
  94. /package/dist/{_deps → _chunks/_deps}/exsolve.mjs +0 -0
  95. /package/dist/{_deps → _chunks/_deps}/fdir.mjs +0 -0
  96. /package/dist/{_deps → _chunks/_deps}/fresh.mjs +0 -0
  97. /package/dist/{_deps → _chunks/_deps}/function-bind.mjs +0 -0
  98. /package/dist/{_deps → _chunks/_deps}/gzip-size.mjs +0 -0
  99. /package/dist/{_deps → _chunks/_deps}/hasown.mjs +0 -0
  100. /package/dist/{_deps → _chunks/_deps}/http-errors.mjs +0 -0
  101. /package/dist/{_deps → _chunks/_deps}/httpxy.mjs +0 -0
  102. /package/dist/{_deps → _chunks/_deps}/inherits.mjs +0 -0
  103. /package/dist/{_deps → _chunks/_deps}/is-core-module.mjs +0 -0
  104. /package/dist/{_deps → _chunks/_deps}/is-module.mjs +0 -0
  105. /package/dist/{_deps → _chunks/_deps}/is-reference.mjs +0 -0
  106. /package/dist/{_deps → _chunks/_deps}/js-tokens.mjs +0 -0
  107. /package/dist/{_deps → _chunks/_deps}/magic-string.mjs +0 -0
  108. /package/dist/{_deps → _chunks/_deps}/mime-db.mjs +0 -0
  109. /package/dist/{_deps → _chunks/_deps}/mime-types.mjs +0 -0
  110. /package/dist/{_deps → _chunks/_deps}/mime.mjs +0 -0
  111. /package/dist/{_deps → _chunks/_deps}/ms.mjs +0 -0
  112. /package/dist/{_deps → _chunks/_deps}/node-fetch-native.mjs +0 -0
  113. /package/dist/{_deps → _chunks/_deps}/on-finished.mjs +0 -0
  114. /package/dist/{_deps → _chunks/_deps}/parseurl.mjs +0 -0
  115. /package/dist/{_deps → _chunks/_deps}/path-parse.mjs +0 -0
  116. /package/dist/{_deps → _chunks/_deps}/perfect-debounce.mjs +0 -0
  117. /package/dist/{_deps → _chunks/_deps}/picomatch.mjs +0 -0
  118. /package/dist/{_deps → _chunks/_deps}/pretty-bytes.mjs +0 -0
  119. /package/dist/{_deps → _chunks/_deps}/quansync.mjs +0 -0
  120. /package/dist/{_deps → _chunks/_deps}/range-parser.mjs +0 -0
  121. /package/dist/{_deps → _chunks/_deps}/rc9.mjs +0 -0
  122. /package/dist/{_deps → _chunks/_deps}/readdirp.mjs +0 -0
  123. /package/dist/{_deps → _chunks/_deps}/resolve.mjs +0 -0
  124. /package/dist/{_deps → _chunks/_deps}/send.mjs +0 -0
  125. /package/dist/{_deps → _chunks/_deps}/serve-static.mjs +0 -0
  126. /package/dist/{_deps → _chunks/_deps}/setprototypeof.mjs +0 -0
  127. /package/dist/{_deps → _chunks/_deps}/statuses.mjs +0 -0
  128. /package/dist/{_deps → _chunks/_deps}/strip-literal.mjs +0 -0
  129. /package/dist/{_deps → _chunks/_deps}/supports-color.mjs +0 -0
  130. /package/dist/{_deps → _chunks/_deps}/tinyexec.mjs +0 -0
  131. /package/dist/{_deps → _chunks/_deps}/tinyglobby.mjs +0 -0
  132. /package/dist/{_deps → _chunks/_deps}/toidentifier.mjs +0 -0
  133. /package/dist/{_deps → _chunks/_deps}/ultrahtml.mjs +0 -0
  134. /package/dist/{_deps → _chunks/_deps}/unplugin.mjs +0 -0
  135. /package/dist/{_deps → _chunks/_deps}/webpack-virtual-modules.mjs +0 -0
  136. /package/dist/{_presets → _chunks/_presets}/_all.mjs +0 -0
  137. /package/dist/{_presets → _chunks/_presets}/_nitro.mjs +0 -0
  138. /package/dist/{_presets → _chunks/_presets}/_static.mjs +0 -0
  139. /package/dist/{_presets → _chunks/_presets}/_types.mjs +0 -0
  140. /package/dist/{_presets → _chunks/_presets}/alwaysdata.mjs +0 -0
  141. /package/dist/{_presets → _chunks/_presets}/aws-amplify.mjs +0 -0
  142. /package/dist/{_presets → _chunks/_presets}/aws-lambda.mjs +0 -0
  143. /package/dist/{_presets → _chunks/_presets}/bun.mjs +0 -0
  144. /package/dist/{_presets → _chunks/_presets}/cleavr.mjs +0 -0
  145. /package/dist/{_presets → _chunks/_presets}/digitalocean.mjs +0 -0
  146. /package/dist/{_presets → _chunks/_presets}/flightcontrol.mjs +0 -0
  147. /package/dist/{_presets → _chunks/_presets}/genezio.mjs +0 -0
  148. /package/dist/{_presets → _chunks/_presets}/heroku.mjs +0 -0
  149. /package/dist/{_presets → _chunks/_presets}/koyeb.mjs +0 -0
  150. /package/dist/{_presets → _chunks/_presets}/netlify.mjs +0 -0
  151. /package/dist/{_presets → _chunks/_presets}/node.mjs +0 -0
  152. /package/dist/{_presets → _chunks/_presets}/platform.mjs +0 -0
  153. /package/dist/{_presets → _chunks/_presets}/render.mjs +0 -0
  154. /package/dist/{_presets → _chunks/_presets}/standard.mjs +0 -0
  155. /package/dist/{_presets → _chunks/_presets}/stormkit.mjs +0 -0
  156. /package/dist/{_presets → _chunks/_presets}/winterjs.mjs +0 -0
  157. /package/dist/{_presets → _chunks/_presets}/zerops.mjs +0 -0
@@ -1,9 +1,965 @@
1
+ import { r as replace$1 } from '../_chunks/_deps/@rollup/plugin-replace.mjs';
2
+ import { defineEnv } from 'unenv';
3
+ import { runtimeDir, runtimeDependencies } from 'nitro/runtime/meta';
4
+ import { j as join, r as resolve, d as dirname, e as extname, a as relative, i as isAbsolute } from '../_chunks/_deps/pathe.mjs';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { builtinModules } from 'node:module';
7
+ import { hash } from 'ohash';
8
+ import { defu } from 'defu';
9
+ import { r as resolveModulePath } from '../_chunks/_deps/exsolve.mjs';
10
+ import { u as unplugin } from '../_chunks/_deps/unimport.mjs';
11
+ import { r as rollup } from '../_chunks/_deps/unwasm.mjs';
12
+ import { connectors } from 'db0';
13
+ import { camelCase } from 'scule';
14
+ import { readFile, mkdir, unlink, symlink } from 'node:fs/promises';
15
+ import { transform } from 'esbuild';
16
+ import { promises } from 'node:fs';
17
+ import { c as createEtag } from '../_chunks/_deps/etag.mjs';
18
+ import { g as glob } from '../_chunks/_deps/tinyglobby.mjs';
19
+ import { m as mime } from '../_chunks/_deps/mime.mjs';
20
+ import { withTrailingSlash } from 'ufo';
21
+ import { normalizeKey, builtinDrivers } from 'unstorage';
22
+ import { b as genImport, a as genSafeVariableName } from '../_chunks/_deps/knitwork.mjs';
23
+ import { rollupNodeFileTrace } from 'nf3';
24
+ import { hasTemplateSyntax, compileTemplateToString, RENDER_CONTEXT_KEYS } from 'rendu';
1
25
  import { version } from 'nitro/meta';
2
- import { p as presetsWithConfig } from '../_presets/_types.mjs';
3
- import { w as writeFile } from './assets.mjs';
4
- import { mkdir, unlink, symlink } from 'node:fs/promises';
5
- import { dirname } from 'node:path';
6
- import { a as resolve } from '../_deps/pathe.mjs';
26
+ import { p as presetsWithConfig } from '../_chunks/_presets/_types.mjs';
27
+ import { w as writeFile } from './prepare.mjs';
28
+ import { dirname as dirname$1 } from 'node:path';
29
+
30
+ const NO_REPLACE_RE = /ROLLUP_NO_REPLACE|\\0raw:/;
31
+ function replace(options) {
32
+ const _plugin = replace$1(options);
33
+ return {
34
+ ..._plugin,
35
+ // https://github.com/rollup/plugins/blob/master/packages/replace/src/index.js#L94
36
+ renderChunk(code, chunk, options2) {
37
+ if (!NO_REPLACE_RE.test(code)) {
38
+ return _plugin.renderChunk.call(this, code, chunk, options2);
39
+ }
40
+ }
41
+ };
42
+ }
43
+
44
+ function baseBuildConfig(nitro) {
45
+ const buildServerDir = join(nitro.options.buildDir, "dist/server");
46
+ const presetsDir = resolve(runtimeDir, "../presets");
47
+ const extensions = [".ts", ".mjs", ".js", ".json", ".node", ".tsx", ".jsx"];
48
+ const isNodeless = nitro.options.node === false;
49
+ let NODE_ENV = nitro.options.dev ? "development" : "production";
50
+ if (nitro.options.preset === "nitro-prerender") {
51
+ NODE_ENV = "prerender";
52
+ }
53
+ const buildEnvVars = {
54
+ NODE_ENV,
55
+ prerender: nitro.options.preset === "nitro-prerender",
56
+ server: true,
57
+ client: false,
58
+ dev: String(nitro.options.dev),
59
+ DEBUG: nitro.options.dev
60
+ };
61
+ const staticFlags = {
62
+ dev: nitro.options.dev,
63
+ preset: nitro.options.preset,
64
+ prerender: nitro.options.preset === "nitro-prerender",
65
+ server: true,
66
+ client: false,
67
+ nitro: true,
68
+ baseURL: nitro.options.baseURL,
69
+ // @ts-expect-error
70
+ "versions.nitro": "",
71
+ "versions?.nitro": "",
72
+ // Internal
73
+ _asyncContext: nitro.options.experimental.asyncContext,
74
+ _websocket: nitro.options.experimental.websocket,
75
+ _tasks: nitro.options.experimental.tasks
76
+ };
77
+ const replaceDelimiters = [
78
+ String.raw`\b`,
79
+ String.raw`(?![\w.$])`
80
+ ];
81
+ const replacements = {
82
+ "typeof window": '"undefined"',
83
+ _import_meta_url_: "import.meta.url",
84
+ "globalThis.process.": "process.",
85
+ "process.env.RUNTIME_CONFIG": () => JSON.stringify(nitro.options.runtimeConfig, null, 2),
86
+ ...Object.fromEntries(
87
+ Object.entries(buildEnvVars).map(([key, val]) => [
88
+ `process.env.${key}`,
89
+ JSON.stringify(val)
90
+ ])
91
+ ),
92
+ ...Object.fromEntries(
93
+ Object.entries(buildEnvVars).map(([key, val]) => [
94
+ `import.meta.env.${key}`,
95
+ JSON.stringify(val)
96
+ ])
97
+ ),
98
+ ...Object.fromEntries(
99
+ Object.entries(staticFlags).map(([key, val]) => [
100
+ `process.${key}`,
101
+ JSON.stringify(val)
102
+ ])
103
+ ),
104
+ ...Object.fromEntries(
105
+ Object.entries(staticFlags).map(([key, val]) => [
106
+ `import.meta.${key}`,
107
+ JSON.stringify(val)
108
+ ])
109
+ ),
110
+ ...nitro.options.replace
111
+ };
112
+ const { env } = defineEnv({
113
+ nodeCompat: isNodeless,
114
+ npmShims: true,
115
+ resolve: true,
116
+ presets: nitro.options.unenv,
117
+ overrides: {
118
+ alias: nitro.options.alias
119
+ }
120
+ });
121
+ const aliases = resolveAliases({
122
+ "#internal/nitro": runtimeDir,
123
+ "nitro/runtime": runtimeDir,
124
+ "nitropack/runtime": runtimeDir,
125
+ // Backwards compatibility
126
+ ...env.alias
127
+ });
128
+ return {
129
+ buildServerDir,
130
+ presetsDir,
131
+ extensions,
132
+ isNodeless,
133
+ buildEnvVars,
134
+ staticFlags,
135
+ replaceDelimiters,
136
+ replacements,
137
+ env,
138
+ aliases
139
+ };
140
+ }
141
+ function resolveAliases(_aliases) {
142
+ const aliases = Object.fromEntries(
143
+ Object.entries(_aliases).sort(
144
+ ([a], [b]) => b.split("/").length - a.split("/").length || b.length - a.length
145
+ )
146
+ );
147
+ for (const key in aliases) {
148
+ for (const alias in aliases) {
149
+ if (!["~", "@", "#"].includes(alias[0])) {
150
+ continue;
151
+ }
152
+ if (alias === "@" && !aliases[key].startsWith("@/")) {
153
+ continue;
154
+ }
155
+ if (aliases[key].startsWith(alias)) {
156
+ aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
157
+ }
158
+ }
159
+ }
160
+ return aliases;
161
+ }
162
+
163
+ const PREFIX = "\0virtual:";
164
+ function virtual(modules, cache = {}) {
165
+ const _modules = /* @__PURE__ */ new Map();
166
+ for (const [id, mod] of Object.entries(modules)) {
167
+ cache[id] = mod;
168
+ _modules.set(id, mod);
169
+ _modules.set(resolve(id), mod);
170
+ }
171
+ return {
172
+ name: "virtual",
173
+ resolveId(id, importer) {
174
+ if (id in modules) {
175
+ return PREFIX + id;
176
+ }
177
+ if (importer) {
178
+ const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer;
179
+ const resolved = resolve(dirname(importerNoPrefix), id);
180
+ if (_modules.has(resolved)) {
181
+ return PREFIX + resolved;
182
+ }
183
+ }
184
+ return null;
185
+ },
186
+ async load(id) {
187
+ if (!id.startsWith(PREFIX)) {
188
+ return null;
189
+ }
190
+ const idNoPrefix = id.slice(PREFIX.length);
191
+ if (!_modules.has(idNoPrefix)) {
192
+ return null;
193
+ }
194
+ let m = _modules.get(idNoPrefix);
195
+ if (typeof m === "function") {
196
+ m = await m();
197
+ }
198
+ if (!m) {
199
+ return null;
200
+ }
201
+ cache[id.replace(PREFIX, "")] = m;
202
+ return {
203
+ code: m,
204
+ map: null
205
+ };
206
+ }
207
+ };
208
+ }
209
+
210
+ function database(nitro) {
211
+ if (!nitro.options.experimental.database) {
212
+ return virtual(
213
+ {
214
+ "#nitro-internal-virtual/database": () => {
215
+ return (
216
+ /* js */
217
+ `export const connectionConfigs = {};`
218
+ );
219
+ }
220
+ },
221
+ nitro.vfs
222
+ );
223
+ }
224
+ const dbConfigs = nitro.options.dev && nitro.options.devDatabase || nitro.options.database;
225
+ const connectorsNames = [
226
+ ...new Set(
227
+ Object.values(dbConfigs || {}).map((config) => config?.connector)
228
+ )
229
+ ].filter(Boolean);
230
+ for (const name of connectorsNames) {
231
+ if (!connectors[name]) {
232
+ throw new Error(`Database connector "${name}" is invalid.`);
233
+ }
234
+ }
235
+ return virtual(
236
+ {
237
+ "#nitro-internal-virtual/database": () => {
238
+ return `
239
+ ${connectorsNames.map(
240
+ (name) => `import ${camelCase(name)}Connector from "${connectors[name]}";`
241
+ ).join("\n")}
242
+
243
+ export const connectionConfigs = {
244
+ ${Object.entries(dbConfigs || {}).map(
245
+ ([name, { connector, options }]) => `${name}: {
246
+ connector: ${camelCase(connector)}Connector,
247
+ options: ${JSON.stringify(options)}
248
+ }`
249
+ ).join(",\n")}
250
+ };
251
+ `;
252
+ }
253
+ },
254
+ nitro.vfs
255
+ );
256
+ }
257
+
258
+ const RuntimeRouteRules = [
259
+ "headers",
260
+ "redirect",
261
+ "proxy",
262
+ "cache"
263
+ ];
264
+ function routing(nitro) {
265
+ return virtual(
266
+ {
267
+ // --- routing (routes, routeRules and middleware) ---
268
+ "#nitro-internal-virtual/routing": () => {
269
+ const allHandlers = uniqueBy(
270
+ [
271
+ ...Object.values(nitro.routing.routes.routes).map((h) => h.data),
272
+ ...Object.values(nitro.routing.routedMiddleware.routes).map(
273
+ (h) => h.data
274
+ ),
275
+ ...nitro.routing.globalMiddleware
276
+ ],
277
+ "_importHash"
278
+ );
279
+ const h3Imports = [
280
+ allHandlers.some((h) => !h.lazy) && "toEventHandler",
281
+ nitro.options.serverEntry && "toMiddleware",
282
+ allHandlers.some((h) => h.lazy) && "defineLazyEventHandler"
283
+ ].filter(Boolean);
284
+ return (
285
+ /* js */
286
+ `
287
+ import * as __routeRules__ from "nitro/runtime/internal/route-rules";
288
+ ${nitro.options.serverEntry ? `import __serverEntry__ from ${JSON.stringify(nitro.options.serverEntry)};` : ""}
289
+ import {${h3Imports.join(", ")}} from "nitro/deps/h3";
290
+
291
+ export const hasRouteRules = ${nitro.routing.routeRules.hasRoutes() ? "true" : "false"};
292
+ export const findRouteRules = ${nitro.routing.routeRules.compileToString({ serialize: serializeRouteRule, matchAll: true })}
293
+
294
+ ${allHandlers.filter((h) => !h.lazy).map((h) => (
295
+ /* js */
296
+ `import ${h._importHash} from "${h.handler}";`
297
+ )).join("\n")}
298
+
299
+ ${allHandlers.filter((h) => h.lazy).map(
300
+ (h) => (
301
+ /* js */
302
+ `const ${h._importHash} = defineLazyEventHandler(() => import("${h.handler}"));`
303
+ )
304
+ ).join("\n")}
305
+
306
+ export const hasRoutes = ${nitro.routing.routes.hasRoutes() ? "true" : "false"};
307
+ export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
308
+
309
+ export const hasRoutedMiddleware = ${nitro.routing.routedMiddleware.hasRoutes() ? "true" : "false"};
310
+ export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({ serialize: serializeHandler, matchAll: true })};
311
+
312
+ export const hasGlobalMiddleware = ${nitro.routing.globalMiddleware.length > 0 || nitro.options.serverEntry ? "true" : "false"};
313
+ export const globalMiddleware = [
314
+ ${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `toEventHandler(${h._importHash})`).join(",")}
315
+ ${nitro.options.serverEntry ? `,toMiddleware(__serverEntry__)` : ""}
316
+ ].filter(Boolean);
317
+ `
318
+ );
319
+ },
320
+ // --- routing-meta ---
321
+ "#nitro-internal-virtual/routing-meta": () => {
322
+ const routeHandlers = uniqueBy(
323
+ Object.values(nitro.routing.routes.routes).map((h) => h.data),
324
+ "_importHash"
325
+ );
326
+ return (
327
+ /* js */
328
+ `
329
+ ${routeHandlers.map(
330
+ (h) => (
331
+ /* js */
332
+ `import ${h._importHash}Meta from "${h.handler}?meta";`
333
+ )
334
+ ).join("\n")}
335
+ export const handlersMeta = [
336
+ ${routeHandlers.map(
337
+ (h) => (
338
+ /* js */
339
+ `{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(
340
+ h.method?.toLowerCase()
341
+ )}, meta: ${h._importHash}Meta }`
342
+ )
343
+ ).join(",\n")}
344
+ ];
345
+ `.trim()
346
+ );
347
+ }
348
+ },
349
+ nitro.vfs
350
+ );
351
+ }
352
+ function uniqueBy(arr, key) {
353
+ return [...new Map(arr.map((item) => [item[key], item])).values()];
354
+ }
355
+ function serializeHandler(h) {
356
+ return `{${[
357
+ `route:${JSON.stringify(h.route)}`,
358
+ h.method && `method:${JSON.stringify(h.method)}`,
359
+ h.meta && `meta:${JSON.stringify(h.meta)}`,
360
+ `handler:${h.lazy ? h._importHash : `toEventHandler(${h._importHash})`}`
361
+ ].filter(Boolean).join(",")}}`;
362
+ }
363
+ function serializeRouteRule(h) {
364
+ return `[${Object.entries(h).filter(([name, options]) => options !== void 0 && name[0] !== "_").map(([name, options]) => {
365
+ return `{${[
366
+ `name:${JSON.stringify(name)}`,
367
+ `route:${JSON.stringify(h._route)}`,
368
+ h._method && `method:${JSON.stringify(h._method)}`,
369
+ RuntimeRouteRules.includes(name) && `handler:__routeRules__.${name}`,
370
+ `options:${JSON.stringify(options)}`
371
+ ].filter(Boolean).join(",")}}`;
372
+ }).join(",")}]`;
373
+ }
374
+
375
+ const virtualPrefix = "\0nitro-handler-meta:";
376
+ const esbuildLoaders = {
377
+ ".ts": "ts",
378
+ ".js": "js",
379
+ ".tsx": "tsx",
380
+ ".jsx": "jsx"
381
+ };
382
+ function routeMeta(nitro) {
383
+ return {
384
+ name: "nitro:route-meta",
385
+ async resolveId(id, importer, resolveOpts) {
386
+ if (id.startsWith("\0")) {
387
+ return;
388
+ }
389
+ if (id.endsWith(`?meta`)) {
390
+ const resolved = await this.resolve(
391
+ id.replace(`?meta`, ``),
392
+ importer,
393
+ resolveOpts
394
+ );
395
+ if (!resolved) {
396
+ return;
397
+ }
398
+ return virtualPrefix + resolved.id;
399
+ }
400
+ },
401
+ load(id) {
402
+ if (id.startsWith(virtualPrefix)) {
403
+ const fullPath = id.slice(virtualPrefix.length);
404
+ return readFile(fullPath, { encoding: "utf8" });
405
+ }
406
+ },
407
+ async transform(code, id) {
408
+ if (!id.startsWith(virtualPrefix)) {
409
+ return;
410
+ }
411
+ let meta = null;
412
+ try {
413
+ const ext = extname(id);
414
+ const jsCode = await transform(code, {
415
+ loader: esbuildLoaders[ext]
416
+ }).then((r) => r.code);
417
+ const ast = this.parse(jsCode);
418
+ for (const node of ast.body) {
419
+ if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "defineRouteMeta" && node.expression.arguments.length === 1) {
420
+ meta = astToObject(node.expression.arguments[0]);
421
+ break;
422
+ }
423
+ }
424
+ } catch (error) {
425
+ nitro.logger.warn(
426
+ `[handlers-meta] Cannot extra route meta for: ${id}: ${error}`
427
+ );
428
+ }
429
+ return {
430
+ code: `export default ${JSON.stringify(meta)};`,
431
+ map: null
432
+ };
433
+ }
434
+ };
435
+ }
436
+ function astToObject(node) {
437
+ switch (node.type) {
438
+ case "ObjectExpression": {
439
+ const obj = {};
440
+ for (const prop of node.properties) {
441
+ if (prop.type === "Property") {
442
+ const key = prop.key.name ?? prop.key.value;
443
+ obj[key] = astToObject(prop.value);
444
+ }
445
+ }
446
+ return obj;
447
+ }
448
+ case "ArrayExpression": {
449
+ return node.elements.map((el) => astToObject(el)).filter(Boolean);
450
+ }
451
+ case "Literal": {
452
+ return node.value;
453
+ }
454
+ }
455
+ }
456
+
457
+ function serverMain(nitro) {
458
+ return {
459
+ name: "nitro:server-main",
460
+ renderChunk(code, chunk) {
461
+ if (chunk.isEntry) {
462
+ return {
463
+ code: `globalThis.__nitro_main__ = import.meta.url; ${code}`,
464
+ map: null
465
+ };
466
+ }
467
+ }
468
+ };
469
+ }
470
+
471
+ const readAssetHandler = {
472
+ true: "node",
473
+ node: "node",
474
+ false: "null",
475
+ deno: "deno",
476
+ inline: "inline"
477
+ };
478
+ function publicAssets(nitro) {
479
+ return virtual(
480
+ {
481
+ // #nitro-internal-virtual/public-assets-data
482
+ "#nitro-internal-virtual/public-assets-data": async () => {
483
+ const assets = {};
484
+ const files = await glob("**", {
485
+ cwd: nitro.options.output.publicDir,
486
+ absolute: false,
487
+ dot: true
488
+ });
489
+ for (const id of files) {
490
+ let mimeType = mime.getType(id.replace(/\.(gz|br)$/, "")) || "text/plain";
491
+ if (mimeType.startsWith("text")) {
492
+ mimeType += "; charset=utf-8";
493
+ }
494
+ const fullPath = resolve(nitro.options.output.publicDir, id);
495
+ const assetData = await promises.readFile(fullPath);
496
+ const etag = createEtag(assetData);
497
+ const stat = await promises.stat(fullPath);
498
+ const assetId = "/" + decodeURIComponent(id);
499
+ let encoding;
500
+ if (id.endsWith(".gz")) {
501
+ encoding = "gzip";
502
+ } else if (id.endsWith(".br")) {
503
+ encoding = "br";
504
+ }
505
+ assets[assetId] = {
506
+ type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType,
507
+ encoding,
508
+ etag,
509
+ mtime: stat.mtime.toJSON(),
510
+ size: stat.size,
511
+ path: relative(nitro.options.output.serverDir, fullPath),
512
+ data: nitro.options.serveStatic === "inline" ? assetData.toString("base64") : void 0
513
+ };
514
+ }
515
+ return `export default ${JSON.stringify(assets, null, 2)};`;
516
+ },
517
+ // #nitro-internal-virtual/public-assets-node
518
+ "#nitro-internal-virtual/public-assets-node": () => {
519
+ return `
520
+ import { promises as fsp } from 'node:fs'
521
+ import { fileURLToPath } from 'node:url'
522
+ import { resolve, dirname } from 'node:path'
523
+ import assets from '#nitro-internal-virtual/public-assets-data'
524
+ export function readAsset (id) {
525
+ const serverDir = dirname(fileURLToPath(globalThis.__nitro_main__))
526
+ return fsp.readFile(resolve(serverDir, assets[id].path))
527
+ }`;
528
+ },
529
+ // #nitro-internal-virtual/public-assets-deno
530
+ "#nitro-internal-virtual/public-assets-deno": () => {
531
+ return `
532
+ import assets from '#nitro-internal-virtual/public-assets-data'
533
+ export function readAsset (id) {
534
+ // https://deno.com/deploy/docs/serve-static-assets
535
+ const path = '.' + decodeURIComponent(new URL(\`../public\${id}\`, 'file://').pathname)
536
+ return Deno.readFile(path);
537
+ }`;
538
+ },
539
+ // #nitro-internal-virtual/public-assets-null
540
+ "#nitro-internal-virtual/public-assets-null": () => {
541
+ return `
542
+ export function readAsset (id) {
543
+ return Promise.resolve(null);
544
+ }`;
545
+ },
546
+ // #nitro-internal-virtual/public-assets-inline
547
+ "#nitro-internal-virtual/public-assets-inline": () => {
548
+ return `
549
+ import assets from '#nitro-internal-virtual/public-assets-data'
550
+ export function readAsset (id) {
551
+ if (!assets[id]) { return undefined }
552
+ if (assets[id]._data) { return assets[id]._data }
553
+ if (!assets[id].data) { return assets[id].data }
554
+ assets[id]._data = Uint8Array.from(atob(assets[id].data), (c) => c.charCodeAt(0))
555
+ return assets[id]._data
556
+ }`;
557
+ },
558
+ // #nitro-internal-virtual/public-assets
559
+ "#nitro-internal-virtual/public-assets": () => {
560
+ const publicAssetBases = Object.fromEntries(
561
+ nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [
562
+ withTrailingSlash(dir.baseURL),
563
+ { maxAge: dir.maxAge }
564
+ ])
565
+ );
566
+ const handlerName = readAssetHandler[nitro.options.serveStatic] || "null";
567
+ const readAssetImport = `#nitro-internal-virtual/public-assets-${handlerName}`;
568
+ return `
569
+ import assets from '#nitro-internal-virtual/public-assets-data'
570
+ export { readAsset } from "${readAssetImport}"
571
+ export const publicAssetBases = ${JSON.stringify(publicAssetBases)}
572
+
573
+ export function isPublicAssetURL(id = '') {
574
+ if (assets[id]) {
575
+ return true
576
+ }
577
+ for (const base in publicAssetBases) {
578
+ if (id.startsWith(base)) { return true }
579
+ }
580
+ return false
581
+ }
582
+
583
+ export function getPublicAssetMeta(id = '') {
584
+ for (const base in publicAssetBases) {
585
+ if (id.startsWith(base)) { return publicAssetBases[base] }
586
+ }
587
+ return {}
588
+ }
589
+
590
+ export function getAsset (id) {
591
+ return assets[id]
592
+ }
593
+ `;
594
+ }
595
+ },
596
+ nitro.vfs
597
+ );
598
+ }
599
+
600
+ function serverAssets(nitro) {
601
+ if (nitro.options.dev || nitro.options.preset === "nitro-prerender") {
602
+ return virtual(
603
+ { "#nitro-internal-virtual/server-assets": getAssetsDev(nitro) },
604
+ nitro.vfs
605
+ );
606
+ }
607
+ return virtual(
608
+ {
609
+ "#nitro-internal-virtual/server-assets": async () => {
610
+ const assets = {};
611
+ for (const asset of nitro.options.serverAssets) {
612
+ const files = await glob(asset.pattern || "**/*", {
613
+ cwd: asset.dir,
614
+ absolute: false,
615
+ ignore: asset.ignore
616
+ });
617
+ for (const _id of files) {
618
+ const fsPath = resolve(asset.dir, _id);
619
+ const id = asset.baseName + "/" + _id;
620
+ assets[id] = { fsPath, meta: {} };
621
+ let type = mime.getType(id) || "text/plain";
622
+ if (type.startsWith("text")) {
623
+ type += "; charset=utf-8";
624
+ }
625
+ const etag = createEtag(await promises.readFile(fsPath));
626
+ const mtime = await promises.stat(fsPath).then((s) => s.mtime.toJSON());
627
+ assets[id].meta = { type, etag, mtime };
628
+ }
629
+ }
630
+ return getAssetProd(assets);
631
+ }
632
+ },
633
+ nitro.vfs
634
+ );
635
+ }
636
+ function getAssetsDev(nitro) {
637
+ return `
638
+ import { createStorage } from 'unstorage'
639
+ import fsDriver from 'unstorage/drivers/fs'
640
+
641
+ const serverAssets = ${JSON.stringify(nitro.options.serverAssets)}
642
+
643
+ export const assets = createStorage()
644
+
645
+ for (const asset of serverAssets) {
646
+ assets.mount(asset.baseName, fsDriver({ base: asset.dir, ignore: (asset?.ignore || []) }))
647
+ }`;
648
+ }
649
+ function getAssetProd(assets) {
650
+ return `
651
+ const _assets = {
652
+ ${Object.entries(assets).map(
653
+ ([id, asset]) => ` [${JSON.stringify(
654
+ normalizeKey(id)
655
+ )}]: {
656
+ import: () => import(${JSON.stringify(
657
+ "raw:" + asset.fsPath
658
+ )}).then(r => r.default || r),
659
+ meta: ${JSON.stringify(
660
+ asset.meta
661
+ )}
662
+ }`
663
+ ).join(",\n")}
664
+ }
665
+
666
+ const normalizeKey = ${normalizeKey.toString()}
667
+
668
+ export const assets = {
669
+ getKeys() {
670
+ return Promise.resolve(Object.keys(_assets))
671
+ },
672
+ hasItem (id) {
673
+ id = normalizeKey(id)
674
+ return Promise.resolve(id in _assets)
675
+ },
676
+ getItem (id) {
677
+ id = normalizeKey(id)
678
+ return Promise.resolve(_assets[id] ? _assets[id].import() : null)
679
+ },
680
+ getMeta (id) {
681
+ id = normalizeKey(id)
682
+ return Promise.resolve(_assets[id] ? _assets[id].meta : {})
683
+ }
684
+ }
685
+ `;
686
+ }
687
+
688
+ function storage(nitro) {
689
+ const mounts = [];
690
+ const isDevOrPrerender = nitro.options.dev || nitro.options.preset === "nitro-prerender";
691
+ const storageMounts = isDevOrPrerender ? { ...nitro.options.storage, ...nitro.options.devStorage } : nitro.options.storage;
692
+ for (const path in storageMounts) {
693
+ const mount = storageMounts[path];
694
+ mounts.push({
695
+ path,
696
+ driver: builtinDrivers[mount.driver] || mount.driver,
697
+ opts: mount
698
+ });
699
+ }
700
+ const driverImports = [...new Set(mounts.map((m) => m.driver))];
701
+ const bundledStorageCode = `
702
+ import { prefixStorage } from 'unstorage'
703
+ import overlay from 'unstorage/drivers/overlay'
704
+ import memory from 'unstorage/drivers/memory'
705
+
706
+ const bundledStorage = ${JSON.stringify(nitro.options.bundledStorage)}
707
+ for (const base of bundledStorage) {
708
+ storage.mount(base, overlay({
709
+ layers: [
710
+ memory(),
711
+ // TODO
712
+ // prefixStorage(storage, base),
713
+ prefixStorage(storage, 'assets:nitro:bundled:' + base)
714
+ ]
715
+ }))
716
+ }`;
717
+ return virtual(
718
+ {
719
+ "#nitro-internal-virtual/storage": (
720
+ /* js */
721
+ `
722
+ import { createStorage } from 'unstorage'
723
+ import { assets } from '#nitro-internal-virtual/server-assets'
724
+
725
+ ${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
726
+
727
+ export function initStorage() {
728
+ const storage = createStorage({})
729
+ storage.mount('/assets', assets)
730
+ ${mounts.map(
731
+ (m) => `storage.mount('${m.path}', ${genSafeVariableName(
732
+ m.driver
733
+ )}(${JSON.stringify(m.opts)}))`
734
+ ).join("\n")}
735
+
736
+ ${!isDevOrPrerender && nitro.options.bundledStorage.length > 0 ? bundledStorageCode : ""}
737
+ return storage
738
+ }
739
+ `
740
+ )
741
+ },
742
+ nitro.vfs
743
+ );
744
+ }
745
+
746
+ function errorHandler(nitro) {
747
+ return virtual(
748
+ {
749
+ "#nitro-internal-virtual/error-handler": () => {
750
+ const errorHandlers = Array.isArray(nitro.options.errorHandler) ? nitro.options.errorHandler : [nitro.options.errorHandler];
751
+ const builtinHandler = join(
752
+ runtimeDir,
753
+ `internal/error/${nitro.options.dev ? "dev" : "prod"}`
754
+ );
755
+ return (
756
+ /* js */
757
+ `
758
+ ${errorHandlers.map((h, i) => `import errorHandler$${i} from "${h}";`).join("\n")}
759
+
760
+ const errorHandlers = [${errorHandlers.map((_, i) => `errorHandler$${i}`).join(", ")}];
761
+
762
+ import { defaultHandler } from "${builtinHandler}";
763
+
764
+ export default async function(error, event) {
765
+ for (const handler of errorHandlers) {
766
+ try {
767
+ const response = await handler(error, event, { defaultHandler });
768
+ if (response) {
769
+ return response;
770
+ }
771
+ } catch(error) {
772
+ // Handler itself thrown, log and continue
773
+ console.error(error);
774
+ }
775
+ }
776
+ // H3 will handle fallback
777
+ }
778
+ `
779
+ );
780
+ }
781
+ },
782
+ nitro.vfs
783
+ );
784
+ }
785
+
786
+ function rendererTemplate(nitro) {
787
+ return virtual(
788
+ {
789
+ "#nitro-internal-virtual/renderer-template": async () => {
790
+ if (typeof nitro.options.renderer?.template !== "string") {
791
+ return `export const rendererTemplate = () => '<!-- renderer.template is not set -->'; export const rendererTemplateFile = undefined;`;
792
+ }
793
+ if (nitro.options.dev) {
794
+ return `import { readFile } from 'node:fs/promises';export const rendererTemplate = () => readFile(${JSON.stringify(nitro.options.renderer?.template)}, "utf8"); export const rendererTemplateFile = ${JSON.stringify(
795
+ nitro.options.renderer?.template
796
+ )};`;
797
+ } else {
798
+ const html = await readFile(nitro.options.renderer?.template, "utf8");
799
+ if (hasTemplateSyntax(html)) {
800
+ const template = compileTemplateToString(html, {
801
+ contextKeys: [...RENDER_CONTEXT_KEYS]
802
+ });
803
+ return (
804
+ /* js */
805
+ `
806
+ import { renderToResponse } from 'rendu'
807
+ const template = ${template};
808
+ export const rendererTemplate = (request) => renderToResponse(template, { request })
809
+ `
810
+ );
811
+ } else {
812
+ return (
813
+ /* js */
814
+ `
815
+ import { HTTPResponse } from "nitro/deps/h3";
816
+ export const rendererTemplate = () => new HTTPResponse(${JSON.stringify(html)}, { headers: { "content-type": "text/html; charset=utf-8" } });
817
+ `
818
+ );
819
+ }
820
+ }
821
+ }
822
+ },
823
+ nitro.vfs
824
+ );
825
+ }
826
+
827
+ function baseBuildPlugins(nitro, base) {
828
+ const plugins = [];
829
+ if (nitro.options.imports) {
830
+ plugins.push(unplugin.rollup(nitro.options.imports));
831
+ }
832
+ if (nitro.options.experimental.wasm) {
833
+ plugins.push(rollup(nitro.options.wasm || {}));
834
+ }
835
+ plugins.push(serverMain());
836
+ const nitroPlugins = [...new Set(nitro.options.plugins)];
837
+ plugins.push(
838
+ virtual(
839
+ {
840
+ "#nitro-internal-virtual/plugins": (
841
+ /* js */
842
+ `
843
+ ${nitroPlugins.map(
844
+ (plugin) => `import _${hash(plugin).replace(/-/g, "")} from '${plugin}';`
845
+ ).join("\n")}
846
+
847
+ export const plugins = [
848
+ ${nitroPlugins.map((plugin) => `_${hash(plugin).replace(/-/g, "")}`).join(",\n")}
849
+ ]
850
+ `
851
+ )
852
+ },
853
+ nitro.vfs
854
+ )
855
+ );
856
+ plugins.push(serverAssets(nitro));
857
+ plugins.push(publicAssets(nitro));
858
+ plugins.push(storage(nitro));
859
+ plugins.push(database(nitro));
860
+ plugins.push(routing(nitro));
861
+ if (nitro.options.experimental.openAPI) {
862
+ plugins.push(routeMeta(nitro));
863
+ }
864
+ plugins.push(errorHandler(nitro));
865
+ plugins.push(
866
+ virtual(
867
+ {
868
+ "#nitro-internal-pollyfills": base.env.polyfill.map((p) => (
869
+ /* js */
870
+ `import '${p}';`
871
+ )).join("\n") || /* js */
872
+ `/* No polyfills */`
873
+ },
874
+ nitro.vfs
875
+ )
876
+ );
877
+ plugins.push(virtual(nitro.options.virtual, nitro.vfs));
878
+ if (nitro.options.renderer?.template) {
879
+ plugins.push(rendererTemplate(nitro));
880
+ }
881
+ if (nitro.options.noExternals) {
882
+ plugins.push({
883
+ name: "no-externals",
884
+ async resolveId(id, importer, resolveOpts) {
885
+ if (resolveOpts.custom?.skipNoExternals) {
886
+ return;
887
+ }
888
+ id = base.aliases[id] || id;
889
+ if (base.env.external.includes(id) || nitro.options.node && (id.startsWith("node:") || builtinModules.includes(id))) {
890
+ return { id, external: true };
891
+ }
892
+ const resolved = await this.resolve(id, importer, resolveOpts);
893
+ if (!resolved) {
894
+ const _resolved = resolveModulePath(id, {
895
+ try: true,
896
+ from: importer && isAbsolute(importer) ? [pathToFileURL(importer), ...nitro.options.nodeModulesDirs] : nitro.options.nodeModulesDirs,
897
+ suffixes: ["", "/index"],
898
+ extensions: [".mjs", ".cjs", ".js", ".mts", ".cts", ".ts", ".json"],
899
+ conditions: [
900
+ "default",
901
+ nitro.options.dev ? "development" : "production",
902
+ "node",
903
+ "import",
904
+ "require"
905
+ ]
906
+ });
907
+ if (_resolved) {
908
+ return { id: _resolved, external: false };
909
+ }
910
+ }
911
+ if (!resolved || resolved.external && !id.endsWith(".wasm")) {
912
+ throw new Error(
913
+ `Cannot resolve ${JSON.stringify(id)} from ${JSON.stringify(
914
+ importer
915
+ )} and externals are not allowed!`
916
+ );
917
+ }
918
+ }
919
+ });
920
+ } else {
921
+ plugins.push(
922
+ rollupNodeFileTrace(
923
+ defu(nitro.options.externals, {
924
+ outDir: nitro.options.output.serverDir,
925
+ moduleDirectories: nitro.options.nodeModulesDirs,
926
+ external: [
927
+ ...nitro.options.dev ? [nitro.options.buildDir] : [],
928
+ ...nitro.options.nodeModulesDirs
929
+ ],
930
+ inline: [
931
+ "#",
932
+ "~",
933
+ "@/",
934
+ "~~",
935
+ "@@/",
936
+ "virtual:",
937
+ "nitro/runtime",
938
+ "nitro/runtime",
939
+ dirname(nitro.options.entry),
940
+ ...nitro.options.experimental.wasm ? [(id) => id?.endsWith(".wasm")] : [],
941
+ runtimeDir,
942
+ nitro.options.srcDir,
943
+ ...nitro.options.handlers.map((m) => m.handler).filter((i) => typeof i === "string"),
944
+ ...nitro.options.dev || nitro.options.preset === "nitro-prerender" || nitro.options.experimental.bundleRuntimeDependencies === false ? [] : runtimeDependencies
945
+ ],
946
+ traceOptions: {
947
+ base: "/",
948
+ processCwd: nitro.options.rootDir,
949
+ exportsOnly: true
950
+ },
951
+ traceAlias: {
952
+ "h3-nightly": "h3",
953
+ ...nitro.options.externals?.traceAlias
954
+ },
955
+ exportConditions: nitro.options.exportConditions,
956
+ writePackageJson: true
957
+ })
958
+ )
959
+ );
960
+ }
961
+ return plugins;
962
+ }
7
963
 
8
964
  async function writeBuildInfo(nitro) {
9
965
  const buildInfoPath = resolve(nitro.options.output.dir, "nitro.json");
@@ -29,11 +985,11 @@ async function writeBuildInfo(nitro) {
29
985
  nitro.options.rootDir,
30
986
  "node_modules/.nitro/last-build"
31
987
  );
32
- await mkdir(dirname(lastBuild), { recursive: true });
988
+ await mkdir(dirname$1(lastBuild), { recursive: true });
33
989
  await unlink(lastBuild).catch(() => {
34
990
  });
35
991
  await symlink(nitro.options.output.dir, lastBuild).catch(console.warn);
36
992
  return buildInfo;
37
993
  }
38
994
 
39
- export { writeBuildInfo as w };
995
+ export { baseBuildPlugins as a, baseBuildConfig as b, replace as r, writeBuildInfo as w };