nitro-nightly 3.1.0-20251028-004953-57503e42 → 3.1.0-20251028-090722-437659e4

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 (155) hide show
  1. package/dist/_build/assets.mjs +235 -0
  2. package/dist/_build/build.mjs +21 -0
  3. package/dist/_build/config.mjs +124 -0
  4. package/dist/_build/info.mjs +39 -0
  5. package/dist/_build/plugins.mjs +1041 -0
  6. package/dist/_build/prepare.mjs +17 -0
  7. package/dist/{_chunks/build2.mjs → _build/rolldown.mjs} +238 -64
  8. package/dist/_build/rollup.mjs +404 -0
  9. package/dist/_build/snapshot.mjs +61 -0
  10. package/dist/_build/types.mjs +268 -0
  11. package/dist/_build/vite.mjs +3266 -0
  12. package/dist/{cli → _cli}/build.mjs +2 -3
  13. package/dist/_cli/dev.mjs +205 -0
  14. package/dist/{cli/index2.mjs → _cli/index.mjs} +1 -2
  15. package/dist/{cli → _cli}/list.mjs +2 -3
  16. package/dist/{cli → _cli}/prepare.mjs +2 -3
  17. package/dist/{cli → _cli}/run.mjs +2 -3
  18. package/dist/_deps/@jridgewell/gen-mapping.mjs +189 -0
  19. package/dist/_deps/@jridgewell/remapping.mjs +137 -0
  20. package/dist/_deps/@jridgewell/resolve-uri.mjs +231 -0
  21. package/dist/_deps/@jridgewell/sourcemap-codec.mjs +173 -0
  22. package/dist/_deps/@jridgewell/trace-mapping.mjs +170 -0
  23. package/dist/_deps/@pi0/vite-plugin-fullstack.mjs +575 -0
  24. package/dist/_deps/@rollup/plugin-alias.mjs +89 -0
  25. package/dist/_deps/@rollup/plugin-commonjs.mjs +2376 -0
  26. package/dist/{_chunks/index2.mjs → _deps/@rollup/plugin-inject.mjs} +5 -90
  27. package/dist/_deps/@rollup/plugin-json.mjs +37 -0
  28. package/dist/_deps/@rollup/plugin-node-resolve.mjs +1386 -0
  29. package/dist/_deps/@rollup/plugin-replace.mjs +133 -0
  30. package/dist/_deps/@rollup/pluginutils.mjs +346 -0
  31. package/dist/_deps/acorn.mjs +6225 -0
  32. package/dist/_deps/c12.mjs +510 -0
  33. package/dist/_deps/chokidar.mjs +1428 -0
  34. package/dist/_deps/citty.mjs +460 -0
  35. package/dist/_deps/commondir.mjs +77 -0
  36. package/dist/_deps/compatx.mjs +76 -0
  37. package/dist/_deps/confbox.mjs +300 -0
  38. package/dist/_deps/debug.mjs +885 -0
  39. package/dist/_deps/deepmerge.mjs +147 -0
  40. package/dist/_deps/depd.mjs +550 -0
  41. package/dist/_deps/dot-prop.mjs +282 -0
  42. package/dist/_deps/dotenv.mjs +555 -0
  43. package/dist/_deps/duplexer.mjs +1 -0
  44. package/dist/_deps/ee-first.mjs +104 -0
  45. package/dist/_deps/encodeurl.mjs +69 -0
  46. package/dist/_deps/escape-html.mjs +87 -0
  47. package/dist/_deps/escape-string-regexp.mjs +13 -0
  48. package/dist/_deps/estree-walker.mjs +433 -0
  49. package/dist/_deps/etag.mjs +147 -0
  50. package/dist/_deps/exsolve.mjs +1416 -0
  51. package/dist/_deps/fdir.mjs +569 -0
  52. package/dist/_deps/fresh.mjs +145 -0
  53. package/dist/_deps/function-bind.mjs +106 -0
  54. package/dist/{_chunks/index4.mjs → _deps/giget.mjs} +21 -776
  55. package/dist/_deps/gzip-size.mjs +19 -0
  56. package/dist/_deps/hasown.mjs +19 -0
  57. package/dist/_deps/http-errors.mjs +307 -0
  58. package/dist/_deps/httpxy.mjs +580 -0
  59. package/dist/_deps/inherits.mjs +57 -0
  60. package/dist/_deps/is-core-module.mjs +596 -0
  61. package/dist/_deps/is-module.mjs +25 -0
  62. package/dist/_deps/is-reference.mjs +31 -0
  63. package/dist/_deps/js-tokens.mjs +411 -0
  64. package/dist/_deps/knitwork.mjs +172 -0
  65. package/dist/_deps/local-pkg.mjs +163 -0
  66. package/dist/_deps/magic-string.mjs +1296 -0
  67. package/dist/_deps/mime-db.mjs +11685 -0
  68. package/dist/_deps/mime-types.mjs +287 -0
  69. package/dist/_deps/mime.mjs +1172 -0
  70. package/dist/_deps/mlly.mjs +2413 -0
  71. package/dist/_deps/ms.mjs +172 -0
  72. package/dist/_deps/node-fetch-native.mjs +3 -0
  73. package/dist/_deps/nypm.mjs +219 -0
  74. package/dist/_deps/on-finished.mjs +246 -0
  75. package/dist/_deps/parseurl.mjs +168 -0
  76. package/dist/_deps/path-parse.mjs +85 -0
  77. package/dist/{_chunks/pathe.M-eThtNZ.mjs → _deps/pathe.mjs} +48 -1
  78. package/dist/_deps/perfect-debounce.mjs +88 -0
  79. package/dist/_deps/picomatch.mjs +2144 -0
  80. package/dist/_deps/pkg-types.mjs +247 -0
  81. package/dist/_deps/pretty-bytes.mjs +180 -0
  82. package/dist/_deps/quansync.mjs +99 -0
  83. package/dist/_deps/range-parser.mjs +171 -0
  84. package/dist/_deps/rc9.mjs +219 -0
  85. package/dist/_deps/readdirp.mjs +245 -0
  86. package/dist/_deps/resolve.mjs +1260 -0
  87. package/dist/_deps/rou3.mjs +326 -0
  88. package/dist/_deps/send.mjs +1022 -0
  89. package/dist/_deps/serve-static.mjs +228 -0
  90. package/dist/_deps/setprototypeof.mjs +26 -0
  91. package/dist/_deps/statuses.mjs +457 -0
  92. package/dist/_deps/strip-literal.mjs +67 -0
  93. package/dist/_deps/supports-color.mjs +44 -0
  94. package/dist/_deps/tinyexec.mjs +552 -0
  95. package/dist/_deps/tinyglobby.mjs +293 -0
  96. package/dist/_deps/toidentifier.mjs +41 -0
  97. package/dist/_deps/ultrahtml.mjs +3 -0
  98. package/dist/_deps/unimport.mjs +2267 -0
  99. package/dist/_deps/unplugin-utils.mjs +65 -0
  100. package/dist/_deps/unplugin.mjs +1294 -0
  101. package/dist/_deps/untyped.mjs +375 -0
  102. package/dist/{_chunks/info.mjs → _deps/unwasm.mjs} +8 -4122
  103. package/dist/_deps/webpack-virtual-modules.mjs +360 -0
  104. package/dist/_presets/_all.mjs +59 -0
  105. package/dist/_presets/_nitro.mjs +74 -0
  106. package/dist/_presets/_resolve.mjs +64 -0
  107. package/dist/_presets/_static.mjs +69 -0
  108. package/dist/_presets/_types.mjs +3 -0
  109. package/dist/_presets/_utils.mjs +31 -0
  110. package/dist/_presets/alwaysdata.mjs +17 -0
  111. package/dist/_presets/aws-amplify.mjs +111 -0
  112. package/dist/_presets/aws-lambda.mjs +23 -0
  113. package/dist/_presets/azure.mjs +162 -0
  114. package/dist/_presets/bun.mjs +19 -0
  115. package/dist/_presets/cleavr.mjs +15 -0
  116. package/dist/_presets/cloudflare.mjs +608 -0
  117. package/dist/_presets/deno.mjs +196 -0
  118. package/dist/_presets/digitalocean.mjs +14 -0
  119. package/dist/_presets/firebase.mjs +47 -0
  120. package/dist/_presets/flightcontrol.mjs +14 -0
  121. package/dist/_presets/genezio.mjs +13 -0
  122. package/dist/_presets/heroku.mjs +14 -0
  123. package/dist/_presets/iis.mjs +194 -0
  124. package/dist/_presets/index.mjs +62 -0
  125. package/dist/_presets/koyeb.mjs +14 -0
  126. package/dist/_presets/netlify.mjs +241 -0
  127. package/dist/_presets/node.mjs +54 -0
  128. package/dist/_presets/platform.mjs +14 -0
  129. package/dist/_presets/render.mjs +14 -0
  130. package/dist/_presets/standard.mjs +23 -0
  131. package/dist/_presets/stormkit.mjs +18 -0
  132. package/dist/_presets/vercel.mjs +365 -0
  133. package/dist/_presets/winterjs.mjs +22 -0
  134. package/dist/_presets/zeabur.mjs +69 -0
  135. package/dist/_presets/zerops.mjs +27 -0
  136. package/dist/cli/index.mjs +7 -464
  137. package/dist/index.mjs +122 -34
  138. package/dist/vite.mjs +118 -44
  139. package/package.json +1 -1
  140. package/dist/_chunks/app.mjs +0 -19797
  141. package/dist/_chunks/build.mjs +0 -86
  142. package/dist/_chunks/build3.mjs +0 -6538
  143. package/dist/_chunks/detect-acorn.mjs +0 -503
  144. package/dist/_chunks/index.mjs +0 -22256
  145. package/dist/_chunks/index3.mjs +0 -1062
  146. package/dist/_chunks/json5.mjs +0 -68
  147. package/dist/_chunks/jsonc.mjs +0 -51
  148. package/dist/_chunks/plugin.mjs +0 -1560
  149. package/dist/_chunks/server.mjs +0 -254
  150. package/dist/_chunks/snapshot.mjs +0 -376
  151. package/dist/_chunks/toml.mjs +0 -259
  152. package/dist/_chunks/yaml.mjs +0 -86
  153. package/dist/cli/dev.mjs +0 -95
  154. package/dist/presets.mjs +0 -2494
  155. /package/dist/{cli → _cli}/common.mjs +0 -0
@@ -0,0 +1,404 @@
1
+ import { createRequire } from 'node:module';
2
+ import defu$1, { defu } from 'defu';
3
+ import { s as sanitizeFilePath } from '../_deps/mlly.mjs';
4
+ import { runtimeDir } from 'nitro/runtime/meta';
5
+ import { a as alias } from '../_deps/@rollup/plugin-alias.mjs';
6
+ import { c as commonjs } from '../_deps/@rollup/plugin-commonjs.mjs';
7
+ import { i as inject } from '../_deps/@rollup/plugin-inject.mjs';
8
+ import { j as json } from '../_deps/@rollup/plugin-json.mjs';
9
+ import { n as nodeResolve } from '../_deps/@rollup/plugin-node-resolve.mjs';
10
+ import { b as baseBuildPlugins, e as esbuild, r as replace, a as raw, s as sourcemapMininify } from './plugins.mjs';
11
+ import { b as baseBuildConfig } from './config.mjs';
12
+ import { n as normalize, i as isAbsolute, r as relative, j as join } from '../_deps/pathe.mjs';
13
+ import { watch } from '../_deps/chokidar.mjs';
14
+ import { watch as watch$1 } from 'node:fs';
15
+ import { d as debounce } from '../_deps/perfect-debounce.mjs';
16
+ import { s as scanHandlers, n as nitroServerName, g as generateFSTree } from './rolldown.mjs';
17
+ import { w as writeTypes } from './types.mjs';
18
+ import { f as formatCompatibilityDate } from '../_deps/compatx.mjs';
19
+ import { s as snapshot } from './snapshot.mjs';
20
+ import { w as writeBuildInfo } from './info.mjs';
21
+ import '../_deps/acorn.mjs';
22
+ import 'ufo';
23
+ import '../_deps/pkg-types.mjs';
24
+ import '../_deps/confbox.mjs';
25
+ import '../_deps/exsolve.mjs';
26
+ import 'node:url';
27
+ import 'node:path';
28
+ import 'node:assert';
29
+ import 'node:process';
30
+ import 'node:v8';
31
+ import 'node:util';
32
+ import 'node:fs/promises';
33
+ import 'path';
34
+ import '../_deps/@rollup/pluginutils.mjs';
35
+ import '../_deps/estree-walker.mjs';
36
+ import '../_deps/picomatch.mjs';
37
+ import '../_deps/commondir.mjs';
38
+ import 'fs';
39
+ import '../_deps/fdir.mjs';
40
+ import 'module';
41
+ import '../_deps/magic-string.mjs';
42
+ import '../_deps/@jridgewell/sourcemap-codec.mjs';
43
+ import '../_deps/is-reference.mjs';
44
+ import '../_deps/deepmerge.mjs';
45
+ import '../_deps/is-module.mjs';
46
+ import 'util';
47
+ import 'url';
48
+ import '../_deps/resolve.mjs';
49
+ import 'os';
50
+ import '../_deps/path-parse.mjs';
51
+ import '../_deps/is-core-module.mjs';
52
+ import '../_deps/hasown.mjs';
53
+ import '../_deps/function-bind.mjs';
54
+ import '../_deps/@rollup/plugin-replace.mjs';
55
+ import 'ohash';
56
+ import '../_deps/unimport.mjs';
57
+ import 'scule';
58
+ import 'node:os';
59
+ import '../_deps/unplugin.mjs';
60
+ import 'node:buffer';
61
+ import '../_deps/@jridgewell/remapping.mjs';
62
+ import '../_deps/@jridgewell/trace-mapping.mjs';
63
+ import '../_deps/@jridgewell/resolve-uri.mjs';
64
+ import '../_deps/@jridgewell/gen-mapping.mjs';
65
+ import 'node:querystring';
66
+ import '../_deps/webpack-virtual-modules.mjs';
67
+ import 'constants';
68
+ import '../_deps/unplugin-utils.mjs';
69
+ import '../_deps/tinyglobby.mjs';
70
+ import '../_deps/local-pkg.mjs';
71
+ import '../_deps/quansync.mjs';
72
+ import '../_deps/strip-literal.mjs';
73
+ import '../_deps/js-tokens.mjs';
74
+ import '../_deps/unwasm.mjs';
75
+ import 'node:crypto';
76
+ import '../_deps/knitwork.mjs';
77
+ import 'db0';
78
+ import 'esbuild';
79
+ import '../_deps/etag.mjs';
80
+ import 'crypto';
81
+ import '../_deps/mime.mjs';
82
+ import 'unstorage';
83
+ import 'nf3';
84
+ import 'rendu';
85
+ import 'unenv';
86
+ import 'fs/promises';
87
+ import 'events';
88
+ import '../_deps/readdirp.mjs';
89
+ import 'node:stream';
90
+ import 'consola/utils';
91
+ import '../_deps/gzip-size.mjs';
92
+ import 'node:zlib';
93
+ import 'stream';
94
+ import '../_deps/pretty-bytes.mjs';
95
+ import 'std-env';
96
+ import './assets.mjs';
97
+ import 'consola';
98
+ import '../_deps/dot-prop.mjs';
99
+ import '../_deps/untyped.mjs';
100
+ import 'klona';
101
+ import 'nitro/meta';
102
+ import '../_presets/_types.mjs';
103
+
104
+ const getRollupConfig = (nitro) => {
105
+ const base = baseBuildConfig(nitro);
106
+ const chunkNamePrefixes = [
107
+ [nitro.options.buildDir, "build"],
108
+ [base.buildServerDir, "app"],
109
+ [runtimeDir, "nitro"],
110
+ [base.presetsDir, "nitro"],
111
+ ["\0raw:", "raw"],
112
+ ["\0nitro-wasm:", "wasm"],
113
+ ["\0", "virtual"]
114
+ ];
115
+ function getChunkGroup(id) {
116
+ if (id.startsWith(runtimeDir) || id.startsWith(base.presetsDir)) {
117
+ return "nitro";
118
+ }
119
+ }
120
+ let config = {
121
+ input: nitro.options.entry,
122
+ external: [...base.env.external],
123
+ plugins: [
124
+ ...baseBuildPlugins(nitro, base),
125
+ esbuild({
126
+ target: "esnext",
127
+ sourceMap: nitro.options.sourceMap,
128
+ ...nitro.options.esbuild?.options
129
+ }),
130
+ alias({ entries: base.aliases }),
131
+ replace({
132
+ delimiters: base.replaceDelimiters,
133
+ preventAssignment: true,
134
+ values: base.replacements
135
+ }),
136
+ nodeResolve({
137
+ extensions: base.extensions,
138
+ preferBuiltins: !!nitro.options.node,
139
+ rootDir: nitro.options.rootDir,
140
+ modulePaths: nitro.options.nodeModulesDirs,
141
+ // 'module' is intentionally not supported because of externals
142
+ mainFields: ["main"],
143
+ exportConditions: nitro.options.exportConditions
144
+ }),
145
+ commonjs({
146
+ strictRequires: "auto",
147
+ // TODO: set to true (default) in v3
148
+ esmExternals: (id) => !id.startsWith("unenv/"),
149
+ requireReturnsDefault: "auto",
150
+ ...nitro.options.commonJS
151
+ }),
152
+ json(),
153
+ inject(base.env.inject),
154
+ raw()
155
+ ],
156
+ onwarn(warning, rollupWarn) {
157
+ if (!["CIRCULAR_DEPENDENCY", "EVAL"].includes(warning.code || "") && !warning.message.includes("Unsupported source map comment")) {
158
+ rollupWarn(warning);
159
+ }
160
+ },
161
+ treeshake: {
162
+ moduleSideEffects(id) {
163
+ const normalizedId = normalize(id);
164
+ const idWithoutNodeModules = normalizedId.split("node_modules/").pop();
165
+ if (!idWithoutNodeModules) {
166
+ return false;
167
+ }
168
+ if (normalizedId.startsWith(runtimeDir) || idWithoutNodeModules.startsWith(runtimeDir)) {
169
+ return true;
170
+ }
171
+ return nitro.options.moduleSideEffects.some(
172
+ (m) => normalizedId.startsWith(m) || idWithoutNodeModules.startsWith(m)
173
+ );
174
+ }
175
+ },
176
+ output: {
177
+ dir: nitro.options.output.serverDir,
178
+ entryFileNames: "index.mjs",
179
+ chunkFileNames(chunk) {
180
+ const id = normalize(chunk.moduleIds.at(-1) || "");
181
+ for (const [dir, name] of chunkNamePrefixes) {
182
+ if (id.startsWith(dir)) {
183
+ return `chunks/${name}/[name].mjs`;
184
+ }
185
+ }
186
+ const routeHandler = nitro.options.handlers.find(
187
+ (h) => id.startsWith(h.handler)
188
+ ) || nitro.scannedHandlers.find((h) => id.startsWith(h.handler));
189
+ if (routeHandler?.route) {
190
+ const path = routeHandler.route.replace(/:([^/]+)/g, "_$1").replace(/\/[^/]+$/g, "") || "/";
191
+ return `chunks/routes${path}/[name].mjs`;
192
+ }
193
+ const taskHandler = Object.entries(nitro.options.tasks).find(
194
+ ([_, task]) => task.handler === id
195
+ );
196
+ if (taskHandler) {
197
+ return `chunks/tasks/[name].mjs`;
198
+ }
199
+ return `chunks/_/[name].mjs`;
200
+ },
201
+ manualChunks(id) {
202
+ return getChunkGroup(id);
203
+ },
204
+ inlineDynamicImports: nitro.options.inlineDynamicImports,
205
+ format: "esm",
206
+ exports: "auto",
207
+ intro: "",
208
+ outro: "",
209
+ generatedCode: {
210
+ constBindings: true
211
+ },
212
+ sanitizeFileName: sanitizeFilePath,
213
+ sourcemap: nitro.options.sourceMap,
214
+ sourcemapExcludeSources: true,
215
+ sourcemapIgnoreList(relativePath) {
216
+ return relativePath.includes("node_modules");
217
+ }
218
+ }
219
+ };
220
+ config = defu(nitro.options.rollupConfig, config);
221
+ if (config.output.inlineDynamicImports) {
222
+ delete config.output.manualChunks;
223
+ }
224
+ if (nitro.options.minify) {
225
+ const _terser = createRequire(import.meta.url)("@rollup/plugin-terser");
226
+ const terser = _terser.default || _terser;
227
+ config.plugins.push(
228
+ terser({
229
+ mangle: {
230
+ keep_fnames: true,
231
+ keep_classnames: true
232
+ },
233
+ format: {
234
+ comments: false
235
+ }
236
+ })
237
+ );
238
+ }
239
+ if (nitro.options.sourceMap && !nitro.options.dev && nitro.options.experimental.sourcemapMinify !== false) {
240
+ config.plugins.push(sourcemapMininify());
241
+ }
242
+ return config;
243
+ };
244
+
245
+ function formatRollupError(_error) {
246
+ try {
247
+ const logs = [_error.toString()];
248
+ const errors = _error?.errors || [_error];
249
+ for (const error of errors) {
250
+ const id = error.path || error.id || _error.id;
251
+ let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
252
+ const location = error.loc || error.location;
253
+ if (location) {
254
+ path += `:${location.line}:${location.column}`;
255
+ }
256
+ const text = error.text || error.frame;
257
+ logs.push(
258
+ `Rollup error while processing \`${path}\`` + text ? "\n\n" + text : ""
259
+ );
260
+ }
261
+ return logs.join("\n");
262
+ } catch {
263
+ return _error?.toString();
264
+ }
265
+ }
266
+
267
+ async function watchDev(nitro, rollupConfig) {
268
+ const rollup = await import('rollup');
269
+ let rollupWatcher;
270
+ async function load() {
271
+ if (rollupWatcher) {
272
+ await rollupWatcher.close();
273
+ }
274
+ await scanHandlers(nitro);
275
+ nitro.routing.sync();
276
+ rollupWatcher = startRollupWatcher(nitro, rollupConfig);
277
+ await writeTypes(nitro);
278
+ }
279
+ const reload = debounce(load);
280
+ const scanDirs = nitro.options.scanDirs.flatMap((dir) => [
281
+ join(dir, nitro.options.apiDir || "api"),
282
+ join(dir, nitro.options.routesDir || "routes"),
283
+ join(dir, "middleware"),
284
+ join(dir, "plugins"),
285
+ join(dir, "modules")
286
+ ]);
287
+ const watchReloadEvents = /* @__PURE__ */ new Set(["add", "addDir", "unlink", "unlinkDir"]);
288
+ const scanDirsWatcher = watch(scanDirs, {
289
+ ignoreInitial: true
290
+ }).on("all", (event, path, stat) => {
291
+ if (watchReloadEvents.has(event)) {
292
+ reload();
293
+ }
294
+ });
295
+ const srcDirWatcher = watch$1(
296
+ nitro.options.srcDir,
297
+ { persistent: false },
298
+ (_event, filename) => {
299
+ if (filename && /^server\.[mc]?[jt]sx?$/.test(filename)) {
300
+ reload();
301
+ }
302
+ }
303
+ );
304
+ nitro.hooks.hook("close", () => {
305
+ rollupWatcher.close();
306
+ scanDirsWatcher.close();
307
+ srcDirWatcher.close();
308
+ });
309
+ nitro.hooks.hook("rollup:reload", () => reload());
310
+ await load();
311
+ function startRollupWatcher(nitro2, rollupConfig2) {
312
+ const watcher = rollup.watch(
313
+ defu$1(rollupConfig2, {
314
+ watch: {
315
+ chokidar: nitro2.options.watchOptions
316
+ }
317
+ })
318
+ );
319
+ let start;
320
+ watcher.on("event", (event) => {
321
+ switch (event.code) {
322
+ case "START": {
323
+ start = Date.now();
324
+ nitro2.hooks.callHook("dev:start");
325
+ break;
326
+ }
327
+ case "BUNDLE_END": {
328
+ nitro2.hooks.callHook("compiled", nitro2);
329
+ if (nitro2.options.logging.buildSuccess) {
330
+ nitro2.logger.success(
331
+ `${nitroServerName(nitro2)} built with rollup`,
332
+ start ? `in ${Date.now() - start}ms` : ""
333
+ );
334
+ }
335
+ nitro2.hooks.callHook("dev:reload");
336
+ break;
337
+ }
338
+ case "ERROR": {
339
+ nitro2.logger.error(formatRollupError(event.error));
340
+ nitro2.hooks.callHook("dev:error", event.error);
341
+ }
342
+ }
343
+ });
344
+ return watcher;
345
+ }
346
+ }
347
+
348
+ async function buildProduction(nitro, rollupConfig) {
349
+ const rollup = await import('rollup');
350
+ await scanHandlers(nitro);
351
+ await writeTypes(nitro);
352
+ await snapshot(nitro);
353
+ if (!nitro.options.static) {
354
+ nitro.logger.info(
355
+ `Building ${nitroServerName(nitro)} (rollup, preset: \`${nitro.options.preset}\`, compatibility date: \`${formatCompatibilityDate(nitro.options.compatibilityDate)}\`)`
356
+ );
357
+ const build = await rollup.rollup(rollupConfig).catch((error) => {
358
+ nitro.logger.error(formatRollupError(error));
359
+ throw error;
360
+ });
361
+ await build.write(rollupConfig.output);
362
+ }
363
+ const buildInfo = await writeBuildInfo(nitro);
364
+ if (!nitro.options.static) {
365
+ if (nitro.options.logging.buildSuccess) {
366
+ nitro.logger.success(`${nitroServerName(nitro)} built`);
367
+ }
368
+ if (nitro.options.logLevel > 1) {
369
+ process.stdout.write(
370
+ await generateFSTree(nitro.options.output.serverDir, {
371
+ compressedSizes: nitro.options.logging.compressedSizes
372
+ }) || ""
373
+ );
374
+ }
375
+ }
376
+ await nitro.hooks.callHook("compiled", nitro);
377
+ const rOutput = relative(process.cwd(), nitro.options.output.dir);
378
+ const rewriteRelativePaths = (input) => {
379
+ return input.replace(/([\s:])\.\/(\S*)/g, `$1${rOutput}/$2`);
380
+ };
381
+ if (buildInfo.commands.preview) {
382
+ nitro.logger.success(
383
+ `You can preview this build using \`${rewriteRelativePaths(
384
+ buildInfo.commands.preview
385
+ )}\``
386
+ );
387
+ }
388
+ if (buildInfo.commands.deploy) {
389
+ nitro.logger.success(
390
+ `You can deploy this build using \`${rewriteRelativePaths(
391
+ buildInfo.commands.deploy
392
+ )}\``
393
+ );
394
+ }
395
+ }
396
+
397
+ async function rollupBuild(nitro) {
398
+ await nitro.hooks.callHook("build:before", nitro);
399
+ const config = getRollupConfig(nitro);
400
+ await nitro.hooks.callHook("rollup:before", nitro, config);
401
+ return nitro.options.dev ? watchDev(nitro, config) : buildProduction(nitro, config);
402
+ }
403
+
404
+ export { rollupBuild };
@@ -0,0 +1,61 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { klona } from 'klona';
3
+ import { createStorage as createStorage$1, builtinDrivers } from 'unstorage';
4
+ import { a as resolve, j as join, d as dirname } from '../_deps/pathe.mjs';
5
+
6
+ async function createStorage(nitro) {
7
+ const storage = createStorage$1();
8
+ const mounts = klona({
9
+ ...nitro.options.storage,
10
+ ...nitro.options.devStorage
11
+ });
12
+ for (const [path, opts] of Object.entries(mounts)) {
13
+ if (opts.driver) {
14
+ const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
15
+ storage.mount(path, driver(opts));
16
+ } else {
17
+ nitro.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
18
+ }
19
+ }
20
+ return storage;
21
+ }
22
+ async function snapshotStorage(nitro) {
23
+ const data = {};
24
+ const allKeys = [
25
+ ...new Set(
26
+ await Promise.all(
27
+ nitro.options.bundledStorage.map((base) => nitro.storage.getKeys(base))
28
+ ).then((r) => r.flat())
29
+ )
30
+ ];
31
+ await Promise.all(
32
+ allKeys.map(async (key) => {
33
+ data[key] = await nitro.storage.getItem(key);
34
+ })
35
+ );
36
+ return data;
37
+ }
38
+
39
+ async function snapshot(nitro) {
40
+ if (nitro.options.bundledStorage.length === 0 || nitro.options.preset === "nitro-prerender") {
41
+ return;
42
+ }
43
+ const storageDir = resolve(nitro.options.buildDir, "snapshot");
44
+ nitro.options.serverAssets.push({
45
+ baseName: "nitro:bundled",
46
+ dir: storageDir
47
+ });
48
+ const data = await snapshotStorage(nitro);
49
+ await Promise.all(
50
+ Object.entries(data).map(async ([path, contents]) => {
51
+ if (typeof contents !== "string") {
52
+ contents = JSON.stringify(contents);
53
+ }
54
+ const fsPath = join(storageDir, path.replace(/:/g, "/"));
55
+ await mkdir(dirname(fsPath), { recursive: true });
56
+ await writeFile(fsPath, contents, "utf8");
57
+ })
58
+ );
59
+ }
60
+
61
+ export { createStorage as c, snapshot as s };