nitro-nightly 3.0.1-20251104-085747-6a78f735 → 3.0.1-20251105-084427-e1d71095

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 (72) hide show
  1. package/dist/_build/common.mjs +8 -7
  2. package/dist/_build/rolldown.mjs +3 -3
  3. package/dist/_build/rollup.mjs +3 -3
  4. package/dist/_build/vite.build.mjs +3 -17
  5. package/dist/_build/vite.plugin.mjs +24 -23
  6. package/dist/_chunks/{DPnDpScB.mjs → 4aR05Iov.mjs} +1 -1
  7. package/dist/_chunks/{DnETaDxL.mjs → Bm-nZkJm.mjs} +1 -1
  8. package/dist/_chunks/{DXMHy5ca.mjs → Bqks5huO.mjs} +1 -13
  9. package/dist/_chunks/{vJX08MVt.mjs → nW-_zcmc.mjs} +36 -11
  10. package/dist/_dev.mjs +54 -11
  11. package/dist/_libs/c12.mjs +1 -1
  12. package/dist/_libs/commondir.mjs +1 -1
  13. package/dist/_libs/deepmerge.mjs +1 -1
  14. package/dist/_libs/duplexer.mjs +1 -1
  15. package/dist/_libs/etag.mjs +1 -1
  16. package/dist/_libs/function-bind.mjs +1 -1
  17. package/dist/_libs/giget.mjs +3 -3
  18. package/dist/_libs/gzip-size.mjs +1 -1
  19. package/dist/_libs/hasown.mjs +1 -1
  20. package/dist/_libs/is-core-module.mjs +1 -1
  21. package/dist/_libs/is-module.mjs +1 -1
  22. package/dist/_libs/is-reference.mjs +1 -1
  23. package/dist/_libs/js-tokens.mjs +1 -1
  24. package/dist/_libs/node-fetch-native.mjs +1 -1
  25. package/dist/_libs/path-parse.mjs +1 -1
  26. package/dist/_libs/picomatch.mjs +1 -1
  27. package/dist/_libs/plugin-commonjs.mjs +1 -1
  28. package/dist/_libs/plugin-node-resolve.mjs +1 -1
  29. package/dist/_libs/strip-literal.mjs +1 -1
  30. package/dist/_libs/tinyglobby.mjs +1 -1
  31. package/dist/_libs/unimport.mjs +1 -1
  32. package/dist/_presets.mjs +1 -0
  33. package/dist/builder.mjs +2 -17
  34. package/dist/cli/_chunks/dev.mjs +1 -15
  35. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
  36. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -2
  37. package/dist/presets/azure/runtime/azure-swa.mjs +2 -1
  38. package/dist/runtime/index.d.mts +1 -1
  39. package/dist/runtime/index.mjs +1 -1
  40. package/dist/runtime/internal/app.d.mts +7 -0
  41. package/dist/runtime/internal/app.mjs +22 -18
  42. package/dist/runtime/internal/cache.mjs +4 -4
  43. package/dist/runtime/internal/error/hooks.mjs +1 -1
  44. package/dist/runtime/internal/routes/dev-tasks.mjs +1 -1
  45. package/dist/runtime/internal/routes/renderer-template.dev.mjs +5 -1
  46. package/dist/runtime/internal/vite/dev-worker.mjs +4 -57
  47. package/dist/runtime/internal/vite/ssr-renderer.mjs +3 -1
  48. package/dist/runtime/nitro.d.mts +11 -0
  49. package/dist/runtime/nitro.mjs +31 -0
  50. package/dist/runtime/vite.d.mts +8 -0
  51. package/dist/runtime/vite.mjs +9 -0
  52. package/dist/types/index.d.mts +4 -5
  53. package/dist/vite.mjs +3 -17
  54. package/lib/config.mjs +1 -1
  55. package/package.json +3 -5
  56. package/dist/_libs/debug.mjs +0 -848
  57. package/dist/_libs/depd.mjs +0 -314
  58. package/dist/_libs/ee-first.mjs +0 -68
  59. package/dist/_libs/encodeurl.mjs +0 -49
  60. package/dist/_libs/escape-html.mjs +0 -58
  61. package/dist/_libs/fresh.mjs +0 -85
  62. package/dist/_libs/http-errors.mjs +0 -436
  63. package/dist/_libs/mime-db.mjs +0 -7642
  64. package/dist/_libs/mime-types.mjs +0 -162
  65. package/dist/_libs/on-finished.mjs +0 -170
  66. package/dist/_libs/parseurl.mjs +0 -103
  67. package/dist/_libs/range-parser.mjs +0 -102
  68. package/dist/_libs/send.mjs +0 -857
  69. package/dist/_libs/serve-static.mjs +0 -124
  70. package/dist/runtime/internal/vite/prod-setup.mjs +0 -53
  71. package/lib/index.d.mts +0 -1
  72. package/lib/index.mjs +0 -1
@@ -1,17 +1,17 @@
1
- import { s as __toESM } from "../_chunks/DXMHy5ca.mjs";
1
+ import { i as __toESM } from "../_chunks/Bqks5huO.mjs";
2
2
  import { T as resolve$1, _ as dirname$1, b as join$1, v as extname$1, w as relative$1 } from "../_libs/c12.mjs";
3
3
  import { i as unplugin } from "../_libs/unimport.mjs";
4
4
  import { t as glob } from "../_libs/tinyglobby.mjs";
5
- import { u as writeFile$1 } from "../_chunks/DnETaDxL.mjs";
5
+ import { u as writeFile$1 } from "../_chunks/Bm-nZkJm.mjs";
6
6
  import { t as src_default } from "../_libs/mime.mjs";
7
7
  import { i as genSafeVariableName, t as genImport } from "../_libs/knitwork.mjs";
8
- import { t as require_etag } from "../_libs/etag.mjs";
9
8
  import { t as replace } from "../_libs/plugin-replace.mjs";
10
9
  import { t as rollup } from "../_libs/unwasm.mjs";
10
+ import { t as require_etag } from "../_libs/etag.mjs";
11
11
  import { dirname } from "node:path";
12
12
  import { camelCase } from "scule";
13
13
  import { promises } from "node:fs";
14
- import { withTrailingSlash } from "ufo";
14
+ import { joinURL, withTrailingSlash } from "ufo";
15
15
  import { mkdir, readFile, symlink, unlink } from "node:fs/promises";
16
16
  import { defu } from "defu";
17
17
  import { runtimeDependencies, runtimeDir } from "nitro/runtime/meta";
@@ -375,7 +375,7 @@ function publicAssets(nitro) {
375
375
  const assetData = await promises.readFile(fullPath);
376
376
  const etag = (0, import_etag$1.default)(assetData);
377
377
  const stat$1 = await promises.stat(fullPath);
378
- const assetId = "/" + decodeURIComponent(id);
378
+ const assetId = joinURL(nitro.options.baseURL, decodeURIComponent(id));
379
379
  let encoding;
380
380
  if (id.endsWith(".gz")) encoding = "gzip";
381
381
  else if (id.endsWith(".br")) encoding = "br";
@@ -429,7 +429,7 @@ export function readAsset (id) {
429
429
  }`;
430
430
  },
431
431
  "#nitro-internal-virtual/public-assets": () => {
432
- const publicAssetBases = Object.fromEntries(nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [withTrailingSlash(dir.baseURL), { maxAge: dir.maxAge }]));
432
+ const publicAssetBases = Object.fromEntries(nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [withTrailingSlash(joinURL(nitro.options.baseURL, dir.baseURL || "/")), { maxAge: dir.maxAge }]));
433
433
  return `
434
434
  import assets from '#nitro-internal-virtual/public-assets-data'
435
435
  export { readAsset } from "${`#nitro-internal-virtual/public-assets-${readAssetHandler[nitro.options.serveStatic] || "null"}`}"
@@ -625,8 +625,9 @@ function rendererTemplate(nitro) {
625
625
  const html = await readFile(nitro.options.renderer?.template, "utf8");
626
626
  if (hasTemplateSyntax(html)) return `
627
627
  import { renderToResponse } from 'rendu'
628
+ import { serverFetch } from 'nitro/runtime'
628
629
  const template = ${compileTemplateToString(html, { contextKeys: [...RENDER_CONTEXT_KEYS] })};
629
- export const rendererTemplate = (request) => renderToResponse(template, { request })
630
+ export const rendererTemplate = (request) => renderToResponse(template, { request, context: { serverFetch } })
630
631
  `;
631
632
  else return `
632
633
  import { HTTPResponse } from "h3";
@@ -14,20 +14,20 @@ import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
14
14
  import "../_libs/klona.mjs";
15
15
  import "../_libs/std-env.mjs";
16
16
  import "../_libs/dot-prop.mjs";
17
- import { n as writeTypes, o as scanHandlers } from "../_chunks/DnETaDxL.mjs";
17
+ import { n as writeTypes, o as scanHandlers } from "../_chunks/Bm-nZkJm.mjs";
18
18
  import "../_libs/mime.mjs";
19
19
  import "../_libs/pathe.mjs";
20
20
  import "../_libs/untyped.mjs";
21
21
  import "../_libs/knitwork.mjs";
22
22
  import { i as watch$1 } from "../_libs/chokidar.mjs";
23
- import "../_libs/etag.mjs";
24
23
  import "../_libs/estree-walker.mjs";
25
24
  import "../_libs/plugin-commonjs.mjs";
26
25
  import "../_libs/plugin-replace.mjs";
27
26
  import { i as replace, n as baseBuildPlugins, r as baseBuildConfig, t as writeBuildInfo } from "./common.mjs";
28
27
  import "../_libs/remapping.mjs";
29
28
  import "../_libs/unwasm.mjs";
30
- import { i as raw, n as generateFSTree, r as nitroServerName, t as snapshot } from "../_chunks/DPnDpScB.mjs";
29
+ import "../_libs/etag.mjs";
30
+ import { i as raw, n as generateFSTree, r as nitroServerName, t as snapshot } from "../_chunks/4aR05Iov.mjs";
31
31
  import "../_libs/duplexer.mjs";
32
32
  import "../_libs/gzip-size.mjs";
33
33
  import "../_libs/pretty-bytes.mjs";
@@ -14,13 +14,12 @@ import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
14
14
  import "../_libs/klona.mjs";
15
15
  import "../_libs/std-env.mjs";
16
16
  import "../_libs/dot-prop.mjs";
17
- import { n as writeTypes, o as scanHandlers } from "../_chunks/DnETaDxL.mjs";
17
+ import { n as writeTypes, o as scanHandlers } from "../_chunks/Bm-nZkJm.mjs";
18
18
  import "../_libs/mime.mjs";
19
19
  import "../_libs/pathe.mjs";
20
20
  import "../_libs/untyped.mjs";
21
21
  import "../_libs/knitwork.mjs";
22
22
  import { i as watch$1 } from "../_libs/chokidar.mjs";
23
- import "../_libs/etag.mjs";
24
23
  import { t as alias } from "../_libs/plugin-alias.mjs";
25
24
  import "../_libs/estree-walker.mjs";
26
25
  import { t as commonjs } from "../_libs/plugin-commonjs.mjs";
@@ -29,7 +28,8 @@ import "../_libs/plugin-replace.mjs";
29
28
  import { i as replace, n as baseBuildPlugins, r as baseBuildConfig, t as writeBuildInfo } from "./common.mjs";
30
29
  import "../_libs/remapping.mjs";
31
30
  import "../_libs/unwasm.mjs";
32
- import { i as raw, n as generateFSTree, r as nitroServerName, t as snapshot } from "../_chunks/DPnDpScB.mjs";
31
+ import "../_libs/etag.mjs";
32
+ import { i as raw, n as generateFSTree, r as nitroServerName, t as snapshot } from "../_chunks/4aR05Iov.mjs";
33
33
  import "../_libs/duplexer.mjs";
34
34
  import "../_libs/gzip-size.mjs";
35
35
  import "../_libs/pretty-bytes.mjs";
@@ -13,10 +13,10 @@ import "../_libs/tinyglobby.mjs";
13
13
  import "../_libs/compatx.mjs";
14
14
  import "../_libs/klona.mjs";
15
15
  import { n as a } from "../_libs/std-env.mjs";
16
- import "../_chunks/vJX08MVt.mjs";
16
+ import "../_chunks/nW-_zcmc.mjs";
17
17
  import "../_libs/escape-string-regexp.mjs";
18
18
  import "../_libs/dot-prop.mjs";
19
- import "../_chunks/DnETaDxL.mjs";
19
+ import "../_chunks/Bm-nZkJm.mjs";
20
20
  import "../_libs/rou3.mjs";
21
21
  import "../_libs/mime.mjs";
22
22
  import "../_libs/pathe.mjs";
@@ -25,21 +25,6 @@ import "../_libs/knitwork.mjs";
25
25
  import "../_libs/httpxy.mjs";
26
26
  import "../_dev.mjs";
27
27
  import "../_libs/chokidar.mjs";
28
- import "../_libs/encodeurl.mjs";
29
- import "../_libs/escape-html.mjs";
30
- import "../_libs/parseurl.mjs";
31
- import "../_libs/depd.mjs";
32
- import "../_libs/http-errors.mjs";
33
- import "../_libs/debug.mjs";
34
- import "../_libs/etag.mjs";
35
- import "../_libs/fresh.mjs";
36
- import "../_libs/mime-db.mjs";
37
- import "../_libs/mime-types.mjs";
38
- import "../_libs/ee-first.mjs";
39
- import "../_libs/on-finished.mjs";
40
- import "../_libs/range-parser.mjs";
41
- import "../_libs/send.mjs";
42
- import "../_libs/serve-static.mjs";
43
28
  import "../_libs/ultrahtml.mjs";
44
29
  import "../_libs/plugin-alias.mjs";
45
30
  import "../_libs/estree-walker.mjs";
@@ -49,6 +34,7 @@ import "../_libs/plugin-replace.mjs";
49
34
  import "./common.mjs";
50
35
  import "../_libs/remapping.mjs";
51
36
  import "../_libs/unwasm.mjs";
37
+ import "../_libs/etag.mjs";
52
38
  import { t as nitro } from "./vite.plugin.mjs";
53
39
  import "../_libs/vite-plugin-fullstack.mjs";
54
40
 
@@ -2,8 +2,8 @@ import { T as resolve$1, _ as dirname$1, b as join$1, f as resolveModulePath, g
2
2
  import { f as sanitizeFilePath } from "../_libs/local-pkg.mjs";
3
3
  import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
4
4
  import { n as a, t as T } from "../_libs/std-env.mjs";
5
- import { a as createNitro, n as prepare, r as copyPublicAssets } from "../_chunks/vJX08MVt.mjs";
6
- import { c as prettyPath, o as scanHandlers } from "../_chunks/DnETaDxL.mjs";
5
+ import { a as createNitro, n as prepare, r as copyPublicAssets } from "../_chunks/nW-_zcmc.mjs";
6
+ import { c as prettyPath, o as scanHandlers } from "../_chunks/Bm-nZkJm.mjs";
7
7
  import { t as createProxyServer } from "../_libs/httpxy.mjs";
8
8
  import { i as NodeDevWorker, r as NitroDevApp } from "../_dev.mjs";
9
9
  import { i as watch$1 } from "../_libs/chokidar.mjs";
@@ -170,7 +170,7 @@ async function buildEnvironments(ctx, builder) {
170
170
  if (nitroOptions.renderer?.template && nitroOptions.renderer?.template === clientInput) {
171
171
  const outputPath = resolve$1(nitroOptions.output.publicDir, basename$1(clientInput));
172
172
  if (existsSync(outputPath)) {
173
- const html = await readFile(outputPath, "utf8").then((r) => r.replace("<!--ssr-outlet-->", `{{{ fetch($REQUEST, { viteEnv: "ssr" }) }}}`));
173
+ const html = await readFile(outputPath, "utf8").then((r) => r.replace("<!--ssr-outlet-->", `{{{ globalThis.__nitro_vite_envs__?.["ssr"]?.fetch($REQUEST) || "" }}}`));
174
174
  await rm(outputPath);
175
175
  const tmp = resolve$1(nitroOptions.buildDir, "vite/index.html");
176
176
  await mkdir(dirname$1(tmp), { recursive: true });
@@ -197,15 +197,7 @@ async function buildEnvironments(ctx, builder) {
197
197
  }
198
198
  function prodSetup(ctx) {
199
199
  const services = ctx.pluginConfig.services || {};
200
- const serviceEntries = Object.keys(services).map((name) => {
201
- let entry;
202
- if (ctx.pluginConfig.experimental?.virtualBundle) entry = ctx._entryPoints[name];
203
- else entry = resolve$1(ctx.nitro.options.buildDir, "vite/services", name, ctx._entryPoints[name]);
204
- return [name, entry];
205
- });
206
200
  return `
207
- import { setupVite } from "${resolve$1(runtimeDir, "internal/vite/prod-setup.mjs")}";
208
-
209
201
  function lazyService(loader) {
210
202
  let promise, mod
211
203
  return {
@@ -220,10 +212,15 @@ function lazyService(loader) {
220
212
  }
221
213
 
222
214
  const services = {
223
- ${serviceEntries.map(([name, entry]) => `[${JSON.stringify(name)}]: lazyService(() => import(${JSON.stringify(entry)}))`).join(",\n")}
215
+ ${Object.keys(services).map((name) => {
216
+ let entry;
217
+ if (ctx.pluginConfig.experimental?.virtualBundle) entry = ctx._entryPoints[name];
218
+ else entry = resolve$1(ctx.nitro.options.buildDir, "vite/services", name, ctx._entryPoints[name]);
219
+ return [name, entry];
220
+ }).map(([name, entry]) => `[${JSON.stringify(name)}]: lazyService(() => import(${JSON.stringify(entry)}))`).join(",\n")}
224
221
  };
225
222
 
226
- setupVite({ services });
223
+ globalThis.__nitro_vite_envs__ = services;
227
224
  `;
228
225
  }
229
226
 
@@ -320,7 +317,7 @@ async function configureViteDevServer(ctx, server) {
320
317
  rootDirWatcher.close();
321
318
  });
322
319
  const hostIPC = { async transformHTML(html) {
323
- return server.transformIndexHtml("/", html).then((r) => r.replace("<!--ssr-outlet-->", `{{{ fetch($REQUEST, { viteEnv: "ssr" }) }}}`));
320
+ return server.transformIndexHtml("/", html).then((r) => r.replace("<!--ssr-outlet-->", `{{{ globalThis.__nitro_vite_envs__?.["ssr"]?.fetch($REQUEST) || "" }}}`));
324
321
  } };
325
322
  nitroEnv$1.devServer.onMessage(async (payload) => {
326
323
  if (payload.type === "custom" && payload.event === "nitro:vite-invoke") {
@@ -626,18 +623,19 @@ function nitroMain(ctx) {
626
623
  debug("[main] Configuring dev server");
627
624
  return configureViteDevServer(ctx, server);
628
625
  },
629
- hotUpdate(options) {
630
- if (this.environment.name === "client" || ctx.pluginConfig.experimental?.serverReload === false) return;
626
+ async hotUpdate({ server, modules, timestamp }) {
627
+ const env = this.environment;
628
+ if (ctx.pluginConfig.experimental?.serverReload === false || env.config.consumer === "client") return;
629
+ const clientEnvs = Object.values(server.environments).filter((env$1) => env$1.config.consumer === "client");
631
630
  let hasServerOnlyModule = false;
632
631
  const invalidated = /* @__PURE__ */ new Set();
633
- for (const mod of options.modules) {
634
- if (!mod.id) continue;
635
- if (options.server.environments.client.moduleGraph.getModuleById(mod.id)) continue;
636
- this.environment.moduleGraph.invalidateModule(mod, invalidated, options.timestamp, false);
632
+ for (const mod of modules) if (mod.id && !clientEnvs.some((env$1) => env$1.moduleGraph.getModuleById(mod.id))) {
637
633
  hasServerOnlyModule = true;
634
+ env.moduleGraph.invalidateModule(mod, invalidated, timestamp, false);
638
635
  }
639
636
  if (hasServerOnlyModule) {
640
- options.server.ws.send({ type: "full-reload" });
637
+ env.hot.send({ type: "full-reload" });
638
+ server.ws.send({ type: "full-reload" });
641
639
  return [];
642
640
  }
643
641
  }
@@ -688,7 +686,7 @@ function useNitro(ctx) {
688
686
  }
689
687
  async function setupNitroContext(ctx, configEnv, userConfig) {
690
688
  const nitroConfig = {
691
- dev: configEnv.mode === "development",
689
+ dev: configEnv.command === "serve",
692
690
  rootDir: userConfig.root,
693
691
  ...defu(ctx.pluginConfig.config, userConfig.nitro)
694
692
  };
@@ -745,7 +743,10 @@ async function setupNitroContext(ctx, configEnv, userConfig) {
745
743
  await ctx.nitro.hooks.callHook("build:before", ctx.nitro);
746
744
  ctx.rollupConfig = await getViteRollupConfig(ctx);
747
745
  await ctx.nitro.hooks.callHook("rollup:before", ctx.nitro, ctx.rollupConfig.config);
748
- if (ctx.nitro.options.dev && !ctx.devWorker) ctx.devWorker = createDevWorker(ctx);
746
+ if (ctx.nitro.options.dev && !ctx.devWorker) {
747
+ ctx.devWorker = createDevWorker(ctx);
748
+ ctx.nitro.fetch = (req) => ctx.devWorker.fetch(req);
749
+ }
749
750
  if (ctx.nitro.options.dev && !ctx.devApp) ctx.devApp = new NitroDevApp(ctx.nitro);
750
751
  }
751
752
  function getEntry(input) {
@@ -1,7 +1,7 @@
1
1
  import { T as resolve, _ as dirname, b as join, v as extname, w as relative } from "../_libs/c12.mjs";
2
2
  import { t as glob } from "../_libs/tinyglobby.mjs";
3
3
  import { n as a } from "../_libs/std-env.mjs";
4
- import { i as snapshotStorage, t as runParallel } from "./DnETaDxL.mjs";
4
+ import { i as snapshotStorage, t as runParallel } from "./Bm-nZkJm.mjs";
5
5
  import { t as src_default } from "../_libs/mime.mjs";
6
6
  import { t as gzipSize } from "../_libs/gzip-size.mjs";
7
7
  import { t as prettyBytes } from "../_libs/pretty-bytes.mjs";
@@ -1,4 +1,4 @@
1
- import { s as __toESM } from "./DXMHy5ca.mjs";
1
+ import { i as __toESM } from "./Bqks5huO.mjs";
2
2
  import { T as resolve, _ as dirname, b as join, f as resolveModulePath, w as relative, y as isAbsolute } from "../_libs/c12.mjs";
3
3
  import { c as parseNodeModulePath, s as lookupNodeModuleSubpath } from "../_libs/local-pkg.mjs";
4
4
  import { s as toExports } from "../_libs/unimport.mjs";
@@ -7,20 +7,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
8
  var __getProtoOf = Object.getPrototypeOf;
9
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __esm = (fn, res) => function() {
11
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
- };
13
10
  var __commonJS = (cb, mod) => function() {
14
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
12
  };
16
- var __export = (all) => {
17
- let target = {};
18
- for (var name in all) __defProp(target, name, {
19
- get: all[name],
20
- enumerable: true
21
- });
22
- return target;
23
- };
24
13
  var __copyProps = (to, from, except, desc) => {
25
14
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
15
  key = keys[i];
@@ -35,9 +24,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
35
24
  value: mod,
36
25
  enumerable: true
37
26
  }) : target, mod));
38
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
27
  var __toDynamicImportESM = (isNodeMode) => (mod) => __toESM(mod.default, isNodeMode);
40
28
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
41
29
 
42
30
  //#endregion
43
- export { __toCommonJS as a, __require as i, __esm as n, __toDynamicImportESM as o, __export as r, __toESM as s, __commonJS as t };
31
+ export { __toESM as i, __require as n, __toDynamicImportESM as r, __commonJS as t };
@@ -1,4 +1,4 @@
1
- import { s as __toESM } from "./DXMHy5ca.mjs";
1
+ import { i as __toESM } from "./Bqks5huO.mjs";
2
2
  import { T as resolve, b as join, f as resolveModulePath, o as findWorkspaceDir, r as loadConfig, t as watchConfig, w as relative, x as normalize } from "../_libs/c12.mjs";
3
3
  import { d as resolveModuleExportNames } from "../_libs/local-pkg.mjs";
4
4
  import { o as createUnimport } from "../_libs/unimport.mjs";
@@ -7,7 +7,7 @@ import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv }
7
7
  import { n as klona } from "../_libs/klona.mjs";
8
8
  import { n as a, r as d } from "../_libs/std-env.mjs";
9
9
  import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
10
- import { a as scanAndSyncOptions, c as prettyPath, l as resolveNitroPath, o as scanHandlers, r as createStorage, s as isDirectory, t as runParallel, u as writeFile$1 } from "./DnETaDxL.mjs";
10
+ import { a as scanAndSyncOptions, c as prettyPath, l as resolveNitroPath, o as scanHandlers, r as createStorage, s as isDirectory, t as runParallel, u as writeFile$1 } from "./Bm-nZkJm.mjs";
11
11
  import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
12
12
  import { t as src_default } from "../_libs/mime.mjs";
13
13
  import { n as z, t as P } from "../_libs/ultrahtml.mjs";
@@ -17,13 +17,13 @@ import { existsSync, promises } from "node:fs";
17
17
  import { joinURL, parseURL, withBase, withLeadingSlash, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
18
18
  import { pathToFileURL } from "node:url";
19
19
  import fsp, { readFile } from "node:fs/promises";
20
- import { createJiti } from "jiti";
21
20
  import { defu } from "defu";
22
21
  import { pkgDir, runtimeDir } from "nitro/runtime/meta";
23
22
  import { colors } from "consola/utils";
24
23
  import { ofetch } from "ofetch";
25
24
  import { hash } from "ohash";
26
25
  import zlib from "node:zlib";
26
+ import { toRequest } from "h3";
27
27
 
28
28
  //#region src/config/defaults.ts
29
29
  const NitroDefaults = {
@@ -693,11 +693,8 @@ async function installModules(nitro) {
693
693
  async function _resolveNitroModule(mod, nitroOptions) {
694
694
  let _url;
695
695
  if (typeof mod === "string") {
696
- globalThis.defineNitroModule = globalThis.defineNitroModule || ((mod$1) => mod$1);
697
- const jiti = createJiti(nitroOptions.rootDir, { alias: nitroOptions.alias });
698
- const _modPath = jiti.esmResolve(mod);
699
- _url = _modPath;
700
- mod = await jiti.import(_modPath, { default: true });
696
+ _url = pathToFileURL(resolveNitroPath(mod, nitroOptions)).href;
697
+ mod = (await import(_url)).then((m) => m.default || m);
701
698
  }
702
699
  if (typeof mod === "function") mod = { setup: mod };
703
700
  if ("nitro" in mod) mod = mod.nitro;
@@ -894,6 +891,29 @@ function mergeCatchAll(router) {
894
891
  });
895
892
  }
896
893
 
894
+ //#endregion
895
+ //#region src/global.ts
896
+ const nitroInstances = globalThis.__nitro_instances__ ||= [];
897
+ const globalKey = "__nitro_builder__";
898
+ function registerNitroInstance(nitro) {
899
+ if (nitroInstances.includes(nitro)) return;
900
+ globalInit();
901
+ nitroInstances.unshift(nitro);
902
+ nitro.hooks.hookOnce("close", () => {
903
+ nitroInstances.splice(nitroInstances.indexOf(nitro), 1);
904
+ if (nitroInstances.length === 0) delete globalThis[globalKey];
905
+ });
906
+ }
907
+ function globalInit() {
908
+ if (globalThis[globalKey]) return;
909
+ globalThis[globalKey] = { async fetch(req) {
910
+ for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve$1) => setTimeout(resolve$1, 300));
911
+ const nitro = nitroInstances[0];
912
+ if (!nitro) throw new Error("No Nitro instance is running.");
913
+ return nitro.fetch(req);
914
+ } };
915
+ }
916
+
897
917
  //#endregion
898
918
  //#region src/nitro.ts
899
919
  async function createNitro(config = {}, opts = {}) {
@@ -904,12 +924,16 @@ async function createNitro(config = {}, opts = {}) {
904
924
  routing: {},
905
925
  logger: consola.withTag("nitro"),
906
926
  scannedHandlers: [],
927
+ fetch: () => {
928
+ throw new Error("no dev server attached!");
929
+ },
907
930
  close: () => Promise.resolve(nitro.hooks.callHook("close")),
908
931
  storage: void 0,
909
932
  async updateConfig(config$1) {
910
933
  updateNitroConfig(nitro, config$1);
911
934
  }
912
935
  };
936
+ registerNitroInstance(nitro);
913
937
  initNitroRouting(nitro);
914
938
  await scanAndSyncOptions(nitro);
915
939
  nitro.storage = await createStorage(nitro);
@@ -1208,7 +1232,7 @@ async function prerender(nitro) {
1208
1232
  nitroRenderer.options.output.dir = nitro.options.output.dir;
1209
1233
  await build(nitroRenderer);
1210
1234
  const serverFilename = typeof nitroRenderer.options.rollupConfig?.output?.entryFileNames === "string" ? nitroRenderer.options.rollupConfig.output.entryFileNames : "index.mjs";
1211
- const { closePrerenderer, appFetch } = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href);
1235
+ const prerenderer = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href).then((m) => m.default);
1212
1236
  const routeRules = createRouter();
1213
1237
  for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
1214
1238
  const _getRouteRules = (path$1) => defu({}, ...findAllRoutes(routeRules, void 0, path$1).map((r) => r.data).reverse());
@@ -1251,7 +1275,8 @@ async function prerender(nitro) {
1251
1275
  generatedRoutes.add(route);
1252
1276
  const _route = { route };
1253
1277
  const encodedRoute = encodeURI(route);
1254
- const res = await appFetch(withBase(encodedRoute, nitro.options.baseURL), { headers: [["x-nitro-prerender", encodedRoute]] });
1278
+ const req = toRequest(withBase(encodedRoute, nitro.options.baseURL), { headers: [["x-nitro-prerender", encodedRoute]] });
1279
+ const res = await prerenderer.fetch(req);
1255
1280
  let dataBuff = Buffer.from(await res.arrayBuffer());
1256
1281
  Object.defineProperty(_route, "contents", {
1257
1282
  get: () => {
@@ -1319,7 +1344,7 @@ async function prerender(nitro) {
1319
1344
  concurrency: nitro.options.prerender.concurrency,
1320
1345
  interval: nitro.options.prerender.interval
1321
1346
  });
1322
- await closePrerenderer();
1347
+ await prerenderer.close();
1323
1348
  await nitro.hooks.callHook("prerender:done", {
1324
1349
  prerenderedRoutes: nitro._prerenderedRoutes,
1325
1350
  failedRoutes: [...failedRoutes]
package/dist/_dev.mjs CHANGED
@@ -1,16 +1,16 @@
1
- import { s as __toESM } from "./_chunks/DXMHy5ca.mjs";
2
- import { T as resolve$1, n as debounce } from "./_libs/c12.mjs";
1
+ import { T as resolve$1, b as join$1, n as debounce, v as extname$1 } from "./_libs/c12.mjs";
3
2
  import { n as a, t as T } from "./_libs/std-env.mjs";
3
+ import { t as src_default } from "./_libs/mime.mjs";
4
4
  import { t as createProxyServer } from "./_libs/httpxy.mjs";
5
5
  import { i as watch$1 } from "./_libs/chokidar.mjs";
6
- import { t as require_serve_static } from "./_libs/serve-static.mjs";
7
6
  import consola$1 from "consola";
8
7
  import { dirname, resolve } from "node:path";
9
- import { existsSync } from "node:fs";
8
+ import { createReadStream, existsSync } from "node:fs";
10
9
  import { joinURL } from "ufo";
11
- import { readFile, rm, writeFile } from "node:fs/promises";
10
+ import { readFile, rm, stat, writeFile } from "node:fs/promises";
11
+ import { createBrotliCompress, createGzip } from "node:zlib";
12
12
  import { Worker } from "node:worker_threads";
13
- import { H3, HTTPError, defineHandler, fromNodeHandler, getRequestIP, getRequestURL, toEventHandler, withBase as withBase$1 } from "h3";
13
+ import { H3, HTTPError, defineHandler, fromNodeHandler, getRequestIP, getRequestURL, serveStatic, toEventHandler } from "h3";
14
14
  import { Agent } from "undici";
15
15
  import { version } from "nitro/meta";
16
16
  import { serve } from "srvx/node";
@@ -447,7 +447,6 @@ function fmtFrame(frame) {
447
447
 
448
448
  //#endregion
449
449
  //#region src/dev/app.ts
450
- var import_serve_static = /* @__PURE__ */ __toESM(require_serve_static(), 1);
451
450
  var NitroDevApp = class {
452
451
  nitro;
453
452
  fetch;
@@ -477,10 +476,12 @@ var NitroDevApp = class {
477
476
  }
478
477
  app.get("/_vfs/**", createVFSHandler(this.nitro));
479
478
  for (const asset of this.nitro.options.publicAssets) {
480
- const assetRoute = joinURL(this.nitro.options.runtimeConfig.app.baseURL, asset.baseURL || "/", "**");
481
- let handler = fromNodeHandler((0, import_serve_static.default)(asset.dir, { dotfiles: "allow" }));
482
- if (asset.baseURL?.length || false) handler = withBase$1(asset.baseURL, handler);
483
- app.use(assetRoute, handler);
479
+ const assetBase = joinURL(this.nitro.options.baseURL, asset.baseURL || "/");
480
+ app.use(joinURL(assetBase, "**"), (event) => serveStaticDir(event, {
481
+ dir: asset.dir,
482
+ base: assetBase,
483
+ fallthrough: asset.fallthrough
484
+ }));
484
485
  }
485
486
  const routes = Object.keys(this.nitro.options.devProxy).sort().reverse();
486
487
  for (const route of routes) {
@@ -493,6 +494,47 @@ var NitroDevApp = class {
493
494
  return app;
494
495
  }
495
496
  };
497
+ function serveStaticDir(event, opts) {
498
+ const dir = resolve$1(opts.dir) + "/";
499
+ const r = (id) => {
500
+ if (!id.startsWith(opts.base) || !extname$1(id)) return;
501
+ const resolved = join$1(dir, id.slice(opts.base.length));
502
+ if (resolved.startsWith(dir)) return resolved;
503
+ };
504
+ return serveStatic(event, {
505
+ fallthrough: opts.fallthrough,
506
+ getMeta: async (id) => {
507
+ const path$1 = r(id);
508
+ if (!path$1) return;
509
+ const s = await stat(path$1).catch(() => null);
510
+ if (!s?.isFile()) return;
511
+ const ext = extname$1(path$1);
512
+ return {
513
+ size: s.size,
514
+ mtime: s.mtime,
515
+ type: src_default.getType(ext) || "application/octet-stream"
516
+ };
517
+ },
518
+ getContents(id) {
519
+ const path$1 = r(id);
520
+ if (!path$1) return;
521
+ const stream = createReadStream(path$1);
522
+ const acceptEncoding = event.req.headers.get("accept-encoding") || "";
523
+ if (acceptEncoding.includes("br")) {
524
+ event.res.headers.set("Content-Encoding", "br");
525
+ event.res.headers.delete("Content-Length");
526
+ event.res.headers.set("Vary", "Accept-Encoding");
527
+ return stream.pipe(createBrotliCompress());
528
+ } else if (acceptEncoding.includes("gzip")) {
529
+ event.res.headers.set("Content-Encoding", "gzip");
530
+ event.res.headers.delete("Content-Length");
531
+ event.res.headers.set("Vary", "Accept-Encoding");
532
+ return stream.pipe(createGzip());
533
+ }
534
+ return stream;
535
+ }
536
+ });
537
+ }
496
538
 
497
539
  //#endregion
498
540
  //#region src/dev/server.ts
@@ -520,6 +562,7 @@ var NitroDevServer = class NitroDevServer extends NitroDevApp {
520
562
  const value = this[key];
521
563
  if (typeof value === "function" && key !== "constructor") this[key] = value.bind(this);
522
564
  }
565
+ nitro.fetch = this.fetch.bind(this);
523
566
  this.#entry = resolve$1(nitro.options.output.dir, nitro.options.output.serverDir, "index.mjs");
524
567
  nitro.hooks.hook("close", () => this.close());
525
568
  nitro.hooks.hook("dev:start", () => {
@@ -1,4 +1,4 @@
1
- import { i as __require, s as __toESM, t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { i as __toESM, n as __require, t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
  import path, { isAbsolute, resolve } from "node:path";
3
3
  import process$1 from "node:process";
4
4
  import fs, { existsSync, lstatSync, promises, readFileSync, realpathSync, statSync } from "node:fs";
@@ -1,4 +1,4 @@
1
- import { i as __require, t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { n as __require, t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/commondir@1.0.1/node_modules/commondir/index.js
4
4
  var require_commondir = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/commondir@1.0.1/node_modules/commondir/index.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js
4
4
  var require_cjs = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { i as __require, t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { n as __require, t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/duplexer@0.1.2/node_modules/duplexer/index.js
4
4
  var require_duplexer = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/duplexer@0.1.2/node_modules/duplexer/index.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { i as __require, t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { n as __require, t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/etag@1.8.1/node_modules/etag/index.js
4
4
  var require_etag = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/etag@1.8.1/node_modules/etag/index.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/function-bind@1.1.2/node_modules/function-bind/implementation.js
4
4
  var require_implementation = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/function-bind@1.1.2/node_modules/function-bind/implementation.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { i as __require, o as __toDynamicImportESM, s as __toESM, t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { i as __toESM, n as __require, r as __toDynamicImportESM, t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
  import { T as resolve$1, _ as dirname$1, b as join$1, g as basename$1, x as normalize$1 } from "./c12.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { createWriteStream, existsSync, readdirSync, renameSync } from "node:fs";
@@ -11,14 +11,14 @@ import { defu } from "defu";
11
11
  import Ds from "crypto";
12
12
  import nt from "events";
13
13
  import { pipeline } from "node:stream";
14
- import a$a from "util";
15
- import ot, { PassThrough } from "stream";
16
14
  import "node:child_process";
17
15
  import j$1 from "assert";
16
+ import ot, { PassThrough } from "stream";
18
17
  import ht from "string_decoder";
19
18
  import P from "buffer";
20
19
  import O$2 from "zlib";
21
20
  import nt$1, { cwd } from "process";
21
+ import a$a from "util";
22
22
  import { spawn as spawn$1 } from "child_process";
23
23
  import me from "readline";
24
24
 
@@ -1,4 +1,4 @@
1
- import { s as __toESM } from "../_chunks/DXMHy5ca.mjs";
1
+ import { i as __toESM } from "../_chunks/Bqks5huO.mjs";
2
2
  import { t as require_duplexer } from "./duplexer.mjs";
3
3
  import fs from "node:fs";
4
4
  import { promisify } from "node:util";
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
  import { t as require_function_bind } from "./function-bind.mjs";
3
3
 
4
4
  //#region node_modules/.pnpm/hasown@2.0.2/node_modules/hasown/index.js
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
  import { t as require_hasown } from "./hasown.mjs";
3
3
 
4
4
  //#region node_modules/.pnpm/is-core-module@2.16.1/node_modules/is-core-module/core.json
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/is-module@1.0.0/node_modules/is-module/index.js
4
4
  var require_is_module = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/is-module@1.0.0/node_modules/is-module/index.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/is-reference@1.2.1/node_modules/is-reference/dist/is-reference.js
4
4
  var require_is_reference = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/is-reference@1.2.1/node_modules/is-reference/dist/is-reference.js": ((exports, module) => {
@@ -1,4 +1,4 @@
1
- import { t as __commonJS } from "../_chunks/DXMHy5ca.mjs";
1
+ import { t as __commonJS } from "../_chunks/Bqks5huO.mjs";
2
2
 
3
3
  //#region node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.js
4
4
  var require_js_tokens = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.js": ((exports, module) => {