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,494 +0,0 @@
1
- import { s as sanitizeFilePath } from '../_deps/mlly.mjs';
2
- import { r as resolveModulePath } from '../_deps/exsolve.mjs';
3
- import { runtimeDir } from 'nitro/runtime/meta';
4
- import { b as baseBuildConfig } from './config.mjs';
5
- import { b as baseBuildPlugins, r as replace, a as raw } from './plugins.mjs';
6
- import { builtinModules } from 'node:module';
7
- import { defu } from 'defu';
8
- import { j as join, r as relative, a as resolve, d as dirname, n as normalize } from '../_deps/pathe.mjs';
9
- import { watch } from '../_deps/chokidar.mjs';
10
- import { promises, watch as watch$1 } from 'node:fs';
11
- import { d as debounce } from '../_deps/perfect-debounce.mjs';
12
- import { g as glob } from '../_deps/tinyglobby.mjs';
13
- import { withLeadingSlash, withoutTrailingSlash, withBase } from 'ufo';
14
- import { upperFirst } from 'scule';
15
- import { w as writeTypes } from './types.mjs';
16
- import { f as formatCompatibilityDate } from '../_deps/compatx.mjs';
17
- import { colors } from 'consola/utils';
18
- import { g as gzipSize } from '../_deps/gzip-size.mjs';
19
- import { p as prettyBytes } from '../_deps/pretty-bytes.mjs';
20
- import { isTest } from 'std-env';
21
- import { s as snapshot } from './snapshot.mjs';
22
- import { w as writeBuildInfo } from './info.mjs';
23
-
24
- const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
25
- const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
26
- async function scanAndSyncOptions(nitro) {
27
- const scannedPlugins = await scanPlugins(nitro);
28
- for (const plugin of scannedPlugins) {
29
- if (!nitro.options.plugins.includes(plugin)) {
30
- nitro.options.plugins.push(plugin);
31
- }
32
- }
33
- if (nitro.options.experimental.tasks) {
34
- const scannedTasks = await scanTasks(nitro);
35
- for (const scannedTask of scannedTasks) {
36
- if (scannedTask.name in nitro.options.tasks) {
37
- if (!nitro.options.tasks[scannedTask.name].handler) {
38
- nitro.options.tasks[scannedTask.name].handler = scannedTask.handler;
39
- }
40
- } else {
41
- nitro.options.tasks[scannedTask.name] = {
42
- handler: scannedTask.handler,
43
- description: ""
44
- };
45
- }
46
- }
47
- }
48
- const scannedModules = await scanModules(nitro);
49
- nitro.options.modules = nitro.options.modules || [];
50
- for (const modPath of scannedModules) {
51
- if (!nitro.options.modules.includes(modPath)) {
52
- nitro.options.modules.push(modPath);
53
- }
54
- }
55
- }
56
- async function scanHandlers(nitro) {
57
- const middleware = await scanMiddleware(nitro);
58
- const handlers = await Promise.all([
59
- scanServerRoutes(
60
- nitro,
61
- nitro.options.apiDir || "api",
62
- nitro.options.apiBaseURL || "/api"
63
- ),
64
- scanServerRoutes(nitro, nitro.options.routesDir || "routes")
65
- ]).then((r) => r.flat());
66
- nitro.scannedHandlers = [
67
- ...middleware,
68
- ...handlers.filter((h, index, array) => {
69
- return array.findIndex(
70
- (h2) => h.route === h2.route && h.method === h2.method && h.env === h2.env
71
- ) === index;
72
- })
73
- ];
74
- return handlers;
75
- }
76
- async function scanMiddleware(nitro) {
77
- const files = await scanFiles(nitro, "middleware");
78
- return files.map((file) => {
79
- return {
80
- route: "/**",
81
- middleware: true,
82
- handler: file.fullPath
83
- };
84
- });
85
- }
86
- async function scanServerRoutes(nitro, dir, prefix = "/") {
87
- const files = await scanFiles(nitro, dir);
88
- return files.map((file) => {
89
- let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(\w+)]/g, "**:$1").replace(/\[([^/\]]+)]/g, ":$1");
90
- route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
91
- const suffixMatch = route.match(suffixRegex);
92
- let method;
93
- let env;
94
- if (suffixMatch?.index && suffixMatch?.index >= 0) {
95
- route = route.slice(0, suffixMatch.index);
96
- method = suffixMatch.groups?.method;
97
- env = suffixMatch.groups?.env;
98
- }
99
- route = route.replace(/\/index$/, "") || "/";
100
- return {
101
- handler: file.fullPath,
102
- lazy: true,
103
- middleware: false,
104
- route,
105
- method,
106
- env
107
- };
108
- });
109
- }
110
- async function scanPlugins(nitro) {
111
- const files = await scanFiles(nitro, "plugins");
112
- return files.map((f) => f.fullPath);
113
- }
114
- async function scanTasks(nitro) {
115
- const files = await scanFiles(nitro, "tasks");
116
- return files.map((f) => {
117
- const name = f.path.replace(/\/index$/, "").replace(/\.[A-Za-z]+$/, "").replace(/\//g, ":");
118
- return { name, handler: f.fullPath };
119
- });
120
- }
121
- async function scanModules(nitro) {
122
- const files = await scanFiles(nitro, "modules");
123
- return files.map((f) => f.fullPath);
124
- }
125
- async function scanFiles(nitro, name) {
126
- const files = await Promise.all(
127
- nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name))
128
- ).then((r) => r.flat());
129
- return files;
130
- }
131
- async function scanDir(nitro, dir, name) {
132
- const fileNames = await glob(join(name, GLOB_SCAN_PATTERN), {
133
- cwd: dir,
134
- dot: true,
135
- ignore: nitro.options.ignore,
136
- absolute: true
137
- }).catch((error) => {
138
- if (error?.code === "ENOTDIR") {
139
- nitro.logger.warn(
140
- `Ignoring \`${join(dir, name)}\`. It must be a directory.`
141
- );
142
- return [];
143
- }
144
- throw error;
145
- });
146
- return fileNames.map((fullPath) => {
147
- return {
148
- fullPath,
149
- path: relative(join(dir, name), fullPath)
150
- };
151
- }).sort((a, b) => a.path.localeCompare(b.path));
152
- }
153
-
154
- async function runParallel(inputs, cb, opts) {
155
- const tasks = /* @__PURE__ */ new Set();
156
- function queueNext() {
157
- const route = inputs.values().next().value;
158
- if (!route) {
159
- return;
160
- }
161
- inputs.delete(route);
162
- const task = (opts.interval ? new Promise((resolve) => setTimeout(resolve, opts.interval)) : Promise.resolve()).then(() => cb(route)).catch((error) => {
163
- console.error(error);
164
- });
165
- tasks.add(task);
166
- return task.then(() => {
167
- tasks.delete(task);
168
- if (inputs.size > 0) {
169
- return refillQueue();
170
- }
171
- });
172
- }
173
- function refillQueue() {
174
- const workers = Math.min(opts.concurrency - tasks.size, inputs.size);
175
- return Promise.all(Array.from({ length: workers }, () => queueNext()));
176
- }
177
- await refillQueue();
178
- }
179
-
180
- function nitroServerName(nitro) {
181
- return nitro.options.framework.name === "nitro" ? "Nitro Server" : `${upperFirst(nitro.options.framework.name)} Nitro server`;
182
- }
183
-
184
- async function generateFSTree(dir, options = {}) {
185
- if (isTest) {
186
- return;
187
- }
188
- const files = await glob("**/*.*", { cwd: dir, ignore: ["*.map"] });
189
- const items = [];
190
- await runParallel(
191
- new Set(files),
192
- async (file) => {
193
- const path = resolve(dir, file);
194
- const src = await promises.readFile(path);
195
- const size = src.byteLength;
196
- const gzip = options.compressedSizes ? await gzipSize(src) : 0;
197
- items.push({ file, path, size, gzip });
198
- },
199
- { concurrency: 10 }
200
- );
201
- items.sort((a, b) => a.path.localeCompare(b.path));
202
- let totalSize = 0;
203
- let totalGzip = 0;
204
- let totalNodeModulesSize = 0;
205
- let totalNodeModulesGzip = 0;
206
- let treeText = "";
207
- for (const [index, item] of items.entries()) {
208
- dirname(item.file);
209
- const rpath = relative(process.cwd(), item.path);
210
- const treeChar = index === items.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
211
- const isNodeModules = item.file.includes("node_modules");
212
- if (isNodeModules) {
213
- totalNodeModulesSize += item.size;
214
- totalNodeModulesGzip += item.gzip;
215
- continue;
216
- }
217
- treeText += colors.gray(
218
- ` ${treeChar} ${rpath} (${prettyBytes(item.size)})`
219
- );
220
- if (options.compressedSizes) {
221
- treeText += colors.gray(` (${prettyBytes(item.gzip)} gzip)`);
222
- }
223
- treeText += "\n";
224
- totalSize += item.size;
225
- totalGzip += item.gzip;
226
- }
227
- treeText += `${colors.cyan("\u03A3 Total size:")} ${prettyBytes(
228
- totalSize + totalNodeModulesSize
229
- )}`;
230
- if (options.compressedSizes) {
231
- treeText += ` (${prettyBytes(totalGzip + totalNodeModulesGzip)} gzip)`;
232
- }
233
- treeText += "\n";
234
- return treeText;
235
- }
236
-
237
- const getRolldownConfig = (nitro) => {
238
- const base = baseBuildConfig(nitro);
239
- const chunkNamePrefixes = [
240
- [nitro.options.buildDir, "build"],
241
- [base.buildServerDir, "app"],
242
- [runtimeDir, "nitro"],
243
- [base.presetsDir, "nitro"],
244
- ["\0raw:", "raw"],
245
- ["\0nitro-wasm:", "wasm"],
246
- ["\0", "virtual"]
247
- ];
248
- let config = {
249
- cwd: nitro.options.rootDir,
250
- input: nitro.options.entry,
251
- external: [
252
- ...base.env.external,
253
- ...builtinModules,
254
- ...builtinModules.map((m) => `node:${m}`)
255
- ],
256
- plugins: [
257
- ...baseBuildPlugins(nitro, base),
258
- // https://github.com/rolldown/rolldown/issues/4257
259
- replace({
260
- delimiters: base.replaceDelimiters,
261
- preventAssignment: true,
262
- values: base.replacements
263
- }),
264
- raw()
265
- ],
266
- resolve: {
267
- alias: base.aliases,
268
- extensions: base.extensions,
269
- mainFields: ["main"],
270
- // "module" is intentionally not supported because of externals
271
- conditionNames: nitro.options.exportConditions
272
- },
273
- // @ts-expect-error (readonly values)
274
- inject: base.env.inject,
275
- jsx: {
276
- mode: "classic",
277
- factory: nitro.options.esbuild?.options?.jsxFactory,
278
- fragment: nitro.options.esbuild?.options?.jsxFragment
279
- },
280
- onwarn(warning, warn) {
281
- if (!["CIRCULAR_DEPENDENCY", "EVAL"].includes(warning.code || "") && !warning.message.includes("Unsupported source map comment")) {
282
- warn(warning);
283
- }
284
- },
285
- treeshake: {
286
- moduleSideEffects(id) {
287
- const normalizedId = normalize(id);
288
- const idWithoutNodeModules = normalizedId.split("node_modules/").pop();
289
- if (!idWithoutNodeModules) {
290
- return false;
291
- }
292
- if (normalizedId.startsWith(runtimeDir) || idWithoutNodeModules.startsWith(runtimeDir)) {
293
- return true;
294
- }
295
- return nitro.options.moduleSideEffects.some(
296
- (m) => normalizedId.startsWith(m) || idWithoutNodeModules.startsWith(m)
297
- );
298
- }
299
- },
300
- output: {
301
- dir: nitro.options.output.serverDir,
302
- entryFileNames: "index.mjs",
303
- chunkFileNames(chunk) {
304
- const id = normalize(chunk.moduleIds.at(-1) || "");
305
- for (const [dir, name] of chunkNamePrefixes) {
306
- if (id.startsWith(dir)) {
307
- return `chunks/${name}/[name].mjs`;
308
- }
309
- }
310
- const routeHandler = nitro.options.handlers.find(
311
- (h) => id.startsWith(h.handler)
312
- ) || nitro.scannedHandlers.find((h) => id.startsWith(h.handler));
313
- if (routeHandler?.route) {
314
- const path = routeHandler.route.replace(/:([^/]+)/g, "_$1").replace(/\/[^/]+$/g, "") || "/";
315
- return `chunks/routes${path}/[name].mjs`;
316
- }
317
- const taskHandler = Object.entries(nitro.options.tasks).find(
318
- ([_, task]) => task.handler === id
319
- );
320
- if (taskHandler) {
321
- return `chunks/tasks/[name].mjs`;
322
- }
323
- return `chunks/_/[name].mjs`;
324
- },
325
- inlineDynamicImports: nitro.options.inlineDynamicImports,
326
- format: "esm",
327
- exports: "auto",
328
- intro: "",
329
- outro: "",
330
- sanitizeFileName: sanitizeFilePath,
331
- sourcemap: nitro.options.sourceMap,
332
- sourcemapIgnoreList(relativePath) {
333
- return relativePath.includes("node_modules");
334
- }
335
- }
336
- };
337
- config.plugins.push({
338
- name: "nitro:rolldown-resolves",
339
- async resolveId(id, parent, options) {
340
- if (parent?.startsWith("\0virtual:#nitro-internal-virtual")) {
341
- const internalRes = await this.resolve(id, import.meta.url, {
342
- ...options,
343
- custom: { ...options.custom, skipNoExternals: true }
344
- });
345
- if (internalRes) {
346
- return internalRes;
347
- }
348
- return resolveModulePath(id, {
349
- from: [nitro.options.rootDir, import.meta.url],
350
- try: true
351
- }) || resolveModulePath("./" + id, {
352
- from: [nitro.options.rootDir, import.meta.url],
353
- try: true
354
- });
355
- }
356
- }
357
- });
358
- config = defu(nitro.options.rollupConfig, config);
359
- return config;
360
- };
361
-
362
- async function watchDev(nitro, config) {
363
- const rolldown = await import('rolldown');
364
- let watcher;
365
- async function load() {
366
- if (watcher) {
367
- await watcher.close();
368
- }
369
- await scanHandlers(nitro);
370
- nitro.routing.sync();
371
- watcher = startWatcher(nitro, config);
372
- await writeTypes(nitro);
373
- }
374
- const reload = debounce(load);
375
- const scanDirs = nitro.options.scanDirs.flatMap((dir) => [
376
- join(dir, nitro.options.apiDir || "api"),
377
- join(dir, nitro.options.routesDir || "routes"),
378
- join(dir, "middleware"),
379
- join(dir, "plugins"),
380
- join(dir, "modules")
381
- ]);
382
- const watchReloadEvents = /* @__PURE__ */ new Set(["add", "addDir", "unlink", "unlinkDir"]);
383
- const scanDirsWatcher = watch(scanDirs, {
384
- ignoreInitial: true
385
- }).on("all", (event) => {
386
- if (watchReloadEvents.has(event)) {
387
- reload();
388
- }
389
- });
390
- const srcDirWatcher = watch$1(
391
- nitro.options.srcDir,
392
- { persistent: false },
393
- (_event, filename) => {
394
- if (filename && /^server\.[mc]?[jt]sx?$/.test(filename)) {
395
- reload();
396
- }
397
- }
398
- );
399
- nitro.hooks.hook("close", () => {
400
- watcher.close();
401
- scanDirsWatcher.close();
402
- srcDirWatcher.close();
403
- });
404
- nitro.hooks.hook("rollup:reload", () => reload());
405
- await load();
406
- function startWatcher(nitro2, config2) {
407
- const watcher2 = rolldown.watch(config2);
408
- let start;
409
- watcher2.on("event", (event) => {
410
- switch (event.code) {
411
- case "START": {
412
- start = Date.now();
413
- nitro2.hooks.callHook("dev:start");
414
- break;
415
- }
416
- case "BUNDLE_END": {
417
- nitro2.hooks.callHook("compiled", nitro2);
418
- if (nitro2.options.logging.buildSuccess) {
419
- nitro2.logger.success(
420
- `${nitroServerName(nitro2)} built with rolldown`,
421
- start ? `in ${Date.now() - start}ms` : ""
422
- );
423
- }
424
- nitro2.hooks.callHook("dev:reload");
425
- break;
426
- }
427
- case "ERROR": {
428
- nitro2.hooks.callHook("dev:error", event.error);
429
- }
430
- }
431
- });
432
- return watcher2;
433
- }
434
- }
435
-
436
- async function buildProduction(nitro, config) {
437
- const rolldown = await import('rolldown');
438
- await scanHandlers(nitro);
439
- await writeTypes(nitro);
440
- await snapshot(nitro);
441
- if (!nitro.options.static) {
442
- nitro.logger.info(
443
- `Building ${nitroServerName(nitro)} (rolldown, preset: \`${nitro.options.preset}\`, compatibility date: \`${formatCompatibilityDate(nitro.options.compatibilityDate)}\`)`
444
- );
445
- const build = await rolldown.rolldown(config);
446
- await build.write(config.output);
447
- }
448
- const buildInfo = await writeBuildInfo(nitro);
449
- if (!nitro.options.static) {
450
- if (nitro.options.logging.buildSuccess) {
451
- nitro.logger.success(`${nitroServerName(nitro)} built`);
452
- }
453
- if (nitro.options.logLevel > 1) {
454
- process.stdout.write(
455
- await generateFSTree(nitro.options.output.serverDir, {
456
- compressedSizes: nitro.options.logging.compressedSizes
457
- }) || ""
458
- );
459
- }
460
- }
461
- await nitro.hooks.callHook("compiled", nitro);
462
- const rOutput = relative(process.cwd(), nitro.options.output.dir);
463
- const rewriteRelativePaths = (input) => {
464
- return input.replace(/([\s:])\.\/(\S*)/g, `$1${rOutput}/$2`);
465
- };
466
- if (buildInfo.commands.preview) {
467
- nitro.logger.success(
468
- `You can preview this build using \`${rewriteRelativePaths(
469
- buildInfo.commands.preview
470
- )}\``
471
- );
472
- }
473
- if (buildInfo.commands.deploy) {
474
- nitro.logger.success(
475
- `You can deploy this build using \`${rewriteRelativePaths(
476
- buildInfo.commands.deploy
477
- )}\``
478
- );
479
- }
480
- }
481
-
482
- async function rolldownBuild(nitro) {
483
- await nitro.hooks.callHook("build:before", nitro);
484
- const config = getRolldownConfig(nitro);
485
- await nitro.hooks.callHook("rollup:before", nitro, config);
486
- return nitro.options.dev ? watchDev(nitro, config) : buildProduction(nitro, config);
487
- }
488
-
489
- const build = {
490
- __proto__: null,
491
- rolldownBuild: rolldownBuild
492
- };
493
-
494
- export { scanAndSyncOptions as a, build as b, generateFSTree as g, nitroServerName as n, runParallel as r, scanHandlers as s };