nitro-nightly 3.0.260415-beta → 3.0.260522-beta

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 (91) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
  2. package/dist/_build/common.mjs +162 -45
  3. package/dist/_build/rolldown.mjs +6 -6
  4. package/dist/_build/rollup.mjs +11 -11
  5. package/dist/_build/vite.build.mjs +3 -3
  6. package/dist/_build/vite.dev.mjs +149 -0
  7. package/dist/_build/vite.env.mjs +177 -0
  8. package/dist/_chunks/nitro.mjs +241 -14
  9. package/dist/_chunks/nitro2.mjs +117 -90
  10. package/dist/_chunks/utils.mjs +4 -4
  11. package/dist/_common.mjs +2 -2
  12. package/dist/_dev.d.mts +1 -1
  13. package/dist/_dev.mjs +7 -6
  14. package/dist/_libs/c12+rc9.mjs +24 -11
  15. package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
  16. package/dist/_libs/citty.mjs +1 -1
  17. package/dist/_libs/common.d.mts +37 -0
  18. package/dist/_libs/commondir+is-reference.mjs +3 -3
  19. package/dist/_libs/compatx.d.mts +1 -1
  20. package/dist/_libs/compatx.mjs +1 -1
  21. package/dist/_libs/estree+pluginutils.d.mts +1 -1
  22. package/dist/_libs/estree-walker.mjs +1 -1
  23. package/dist/_libs/hasown+resolve+deepmerge.mjs +62 -49
  24. package/dist/_libs/httpxy.d.mts +2 -4
  25. package/dist/_libs/httpxy.mjs +13 -9
  26. package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
  27. package/dist/_libs/klona.mjs +1 -1
  28. package/dist/_libs/magic-string.d.mts +1 -1
  29. package/dist/_libs/mlly.d.mts +1 -1
  30. package/dist/_libs/nypm+tinyexec.mjs +137 -113
  31. package/dist/_libs/openapi-types.d.mts +730 -0
  32. package/dist/_libs/perfect-debounce.mjs +1 -1
  33. package/dist/_libs/pkg-types.d.mts +8 -5
  34. package/dist/_libs/plugin-alias.mjs +2 -2
  35. package/dist/_libs/plugin-inject.mjs +4 -2
  36. package/dist/_libs/plugin-json.mjs +2 -2
  37. package/dist/_libs/pluginutils.mjs +18 -5
  38. package/dist/_libs/readdirp+chokidar.mjs +4 -3
  39. package/dist/_libs/remapping.mjs +2 -2
  40. package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
  41. package/dist/_libs/rou3.d.mts +1 -1
  42. package/dist/_libs/rou3.mjs +1 -1
  43. package/dist/_libs/std-env.d.mts +2 -2
  44. package/dist/_libs/tsconfck.mjs +1 -1
  45. package/dist/_libs/ultrahtml.mjs +1 -1
  46. package/dist/_libs/unimport+unplugin.mjs +61 -39
  47. package/dist/_libs/unplugin+unimport.d.mts +4 -4
  48. package/dist/_libs/unwasm.d.mts +1 -1
  49. package/dist/_presets.mjs +120 -92
  50. package/dist/builder.d.mts +1 -1
  51. package/dist/builder.mjs +3 -3
  52. package/dist/cli/_chunks/build.mjs +3 -3
  53. package/dist/cli/_chunks/common.mjs +1 -1
  54. package/dist/cli/_chunks/deploy.mjs +2 -2
  55. package/dist/cli/_chunks/dev.mjs +4 -4
  56. package/dist/cli/_chunks/docs.mjs +1 -1
  57. package/dist/cli/_chunks/list.mjs +2 -2
  58. package/dist/cli/_chunks/prepare.mjs +3 -3
  59. package/dist/cli/_chunks/preview.mjs +4 -4
  60. package/dist/cli/_chunks/run.mjs +2 -2
  61. package/dist/cli/_chunks/task.mjs +1 -1
  62. package/dist/cli/index.mjs +1 -1
  63. package/dist/docs/0.docs/5.cache.md +53 -9
  64. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
  65. package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
  66. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
  67. package/dist/node_modules/ufo/dist/index.mjs +2 -2
  68. package/dist/node_modules/ufo/package.json +9 -9
  69. package/dist/presets/azure/runtime/azure-swa.mjs +2 -0
  70. package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
  71. package/dist/runtime/internal/app.mjs +4 -111
  72. package/dist/runtime/internal/route-rules.d.mts +1 -0
  73. package/dist/runtime/internal/route-rules.mjs +29 -1
  74. package/dist/runtime/internal/routes/scalar.mjs +1 -0
  75. package/dist/runtime/virtual/app.d.mts +4 -0
  76. package/dist/runtime/virtual/app.mjs +32 -0
  77. package/dist/types/index.d.mts +959 -1836
  78. package/dist/vite.d.mts +1 -1
  79. package/dist/vite.mjs +23 -331
  80. package/package.json +44 -45
  81. package/dist/THIRD-PARTY-LICENSES.md +0 -1646
  82. package/dist/_chunks/nitro3.mjs +0 -136
  83. package/dist/_chunks/nitro4.mjs +0 -127
  84. package/dist/_libs/_.mjs +0 -2
  85. package/dist/_libs/_2.mjs +0 -2
  86. package/dist/_libs/_3.mjs +0 -2
  87. package/dist/_libs/_4.mjs +0 -2
  88. package/dist/_libs/_5.mjs +0 -2
  89. package/dist/_libs/_6.mjs +0 -2
  90. package/dist/_libs/_7.mjs +0 -2
  91. package/dist/_libs/escape-string-regexp.mjs +0 -5
Binary file
@@ -1,4 +1,4 @@
1
- import { i as __toESM$1, n as __exportAll, r as __require$1, t as __commonJSMin } from "../_common.mjs";
1
+ import { __commonJSMin, __exportAll, __require as __require$1, __toESM as __toESM$1 } from "../_common.mjs";
2
2
  import { builtinModules, createRequire } from "node:module";
3
3
  import consola from "consola";
4
4
  import { pkgDir, runtimeDependencies, runtimeDir, version } from "nitro/meta";
@@ -188,7 +188,6 @@ const parse$1 = function(p) {
188
188
  name: base.slice(0, base.length - extension.length)
189
189
  };
190
190
  };
191
- globalThis.process?.platform;
192
191
  const nodeBuiltins = [
193
192
  "_http_agent",
194
193
  "_http_client",
@@ -948,8 +947,8 @@ function moduleResolve$1(specifier, base, conditions, preserveSymlinks) {
948
947
  return finalizeResolution$1(resolved, base, preserveSymlinks);
949
948
  }
950
949
  const DEFAULT_CONDITIONS_SET$2 = /* @__PURE__ */ new Set(["node", "import"]);
951
- const isWindows = process.platform === "win32";
952
- const globalCache = globalThis["__EXSOLVE_CACHE__"] ||= /* @__PURE__ */ new Map();
950
+ const isWindows = /* @__PURE__ */ (() => process.platform === "win32")();
951
+ const globalCache = /* @__PURE__ */ (() => globalThis["__EXSOLVE_CACHE__"] ||= /* @__PURE__ */ new Map())();
953
952
  function resolveModuleURL(input, options) {
954
953
  const parsedInput = _parseInput(input);
955
954
  if ("external" in parsedInput) return parsedInput.external;
@@ -3995,12 +3994,12 @@ async function findFile$1(filename, _options = {}) {
3995
3994
  if (leadingSlash) segments[0] = "/" + segments[0];
3996
3995
  let root = segments.findIndex((r) => r.match(options.rootPattern));
3997
3996
  if (root === -1) root = 0;
3998
- if (options.reverse) for (let index = root + 1; index <= segments.length; index++) for (const filename2 of filenames) {
3999
- const filePath = join$2(...segments.slice(0, index), filename2);
3997
+ if (options.reverse) for (let index = root + 1; index <= segments.length; index++) for (const filename of filenames) {
3998
+ const filePath = join$2(...segments.slice(0, index), filename);
4000
3999
  if (await options.test(filePath)) return filePath;
4001
4000
  }
4002
- else for (let index = segments.length; index > root; index--) for (const filename2 of filenames) {
4003
- const filePath = join$2(...segments.slice(0, index), filename2);
4001
+ else for (let index = segments.length; index > root; index--) for (const filename of filenames) {
4002
+ const filePath = join$2(...segments.slice(0, index), filename);
4004
4003
  if (await options.test(filePath)) return filePath;
4005
4004
  }
4006
4005
  throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
@@ -4223,6 +4222,11 @@ const l$1 = [
4223
4222
  `FIREBASE_APP_HOSTING`,
4224
4223
  `FIREBASE_APP_HOSTING`,
4225
4224
  { ci: !0 }
4225
+ ],
4226
+ [
4227
+ `EDGEONE_PAGES`,
4228
+ `EO_PAGES_CI`,
4229
+ { ci: !0 }
4226
4230
  ]
4227
4231
  ];
4228
4232
  function u$1() {
@@ -4262,7 +4266,21 @@ function I$2() {
4262
4266
  if (e) return { name: e[1] };
4263
4267
  }
4264
4268
  const R$1 = I$2()?.name || ``;
4265
- const isObject$2 = (value) => {
4269
+ function escapeRegExp$1(string) {
4270
+ return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
4271
+ }
4272
+ function pathRegExp(string) {
4273
+ if (S$3) string = string.replace(/\\/g, "/");
4274
+ let escaped = escapeRegExp$1(string);
4275
+ if (S$3) escaped = escaped.replace(/\//g, String.raw`[/\\]`);
4276
+ return escaped;
4277
+ }
4278
+ function toPathRegExp(input) {
4279
+ if (input instanceof RegExp) return input;
4280
+ if (typeof input === "string") return new RegExp(pathRegExp(input));
4281
+ throw new TypeError("Expected a string or RegExp", { cause: input });
4282
+ }
4283
+ const isObject$3 = (value) => {
4266
4284
  const type = typeof value;
4267
4285
  return value !== null && (type === "object" || type === "function");
4268
4286
  };
@@ -4383,7 +4401,7 @@ function normalizePath$3(path) {
4383
4401
  return [];
4384
4402
  }
4385
4403
  function getProperty(object, path, value) {
4386
- if (!isObject$2(object) || typeof path !== "string" && !Array.isArray(path)) return value === void 0 ? object : value;
4404
+ if (!isObject$3(object) || typeof path !== "string" && !Array.isArray(path)) return value === void 0 ? object : value;
4387
4405
  const pathArray = normalizePath$3(path);
4388
4406
  if (pathArray.length === 0) return value;
4389
4407
  for (let index = 0; index < pathArray.length; index++) {
@@ -15662,6 +15680,9 @@ const BUILTIN_MODULES = new Set(builtinModules);
15662
15680
  function normalizeSlash(path) {
15663
15681
  return path.replace(/\\/g, "/");
15664
15682
  }
15683
+ function isObject$2(value) {
15684
+ return value !== null && typeof value === "object";
15685
+ }
15665
15686
  function matchAll(regex, string, addition) {
15666
15687
  const matches = [];
15667
15688
  for (const match of string.matchAll(regex)) matches.push({
@@ -16720,6 +16741,23 @@ function _isIdentifierBeforeAngleBracket(str, i) {
16720
16741
  const wordStart = j + 1;
16721
16742
  return wordStart < i && /[A-Za-z_$]/.test(str[wordStart]);
16722
16743
  }
16744
+ function interopDefault(sourceModule, opts = {}) {
16745
+ if (!isObject$2(sourceModule) || !("default" in sourceModule)) return sourceModule;
16746
+ const defaultValue = sourceModule.default;
16747
+ if (defaultValue === void 0 || defaultValue === null) return sourceModule;
16748
+ const _defaultType = typeof defaultValue;
16749
+ if (_defaultType !== "object" && !(_defaultType === "function" && !opts.preferNamespace)) return opts.preferNamespace ? sourceModule : defaultValue;
16750
+ for (const key in sourceModule) try {
16751
+ if (!(key in defaultValue)) Object.defineProperty(defaultValue, key, {
16752
+ enumerable: key !== "default",
16753
+ configurable: key !== "default",
16754
+ get() {
16755
+ return sourceModule[key];
16756
+ }
16757
+ });
16758
+ } catch {}
16759
+ return defaultValue;
16760
+ }
16723
16761
  const ESM_RE = /(?:[\s;]|^)(?:import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
16724
16762
  const CJS_RE = /(?:[\s;]|^)(?:module\.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
16725
16763
  const COMMENT_RE = /\/\*.+?\*\/|\/\/.*(?=[nr])/g;
@@ -18769,7 +18807,7 @@ function dedupeImports(imports, warn) {
18769
18807
  }
18770
18808
  if (currImp.type || prevImp.type ? (currImp.typeFrom || currImp.from) === (prevImp.typeFrom || prevImp.from) : currImp.from === prevImp.from) {
18771
18809
  if (Boolean(currImp.type) === Boolean(prevImp.type)) {
18772
- if ((currImp.priority || 1) > (prevImp.priority || 1)) {
18810
+ if ((currImp.priority ?? 1) > (prevImp.priority ?? 1)) {
18773
18811
  deduped.delete(name);
18774
18812
  deduped.set(name, currImp);
18775
18813
  }
@@ -18777,7 +18815,7 @@ function dedupeImports(imports, warn) {
18777
18815
  const altName2 = encodeImportName(name);
18778
18816
  const prevImpComplement2 = deduped.get(altName2);
18779
18817
  if (!prevImpComplement2) deduped.set(altName2, currImp);
18780
- else if ((currImp.priority || 1) > (prevImpComplement2.priority || 1)) {
18818
+ else if ((currImp.priority ?? 1) > (prevImpComplement2.priority ?? 1)) {
18781
18819
  deduped.delete(altName2);
18782
18820
  deduped.set(altName2, currImp);
18783
18821
  }
@@ -18786,7 +18824,8 @@ function dedupeImports(imports, warn) {
18786
18824
  }
18787
18825
  const altName = encodeImportName(name);
18788
18826
  const prevImpComplement = deduped.get(altName);
18789
- const priorityDiff = (currImp.priority || 1) - Math.max(prevImp.priority || 1, prevImpComplement?.priority || 1);
18827
+ const prevPriority = prevImpComplement ? Math.max(prevImp.priority ?? 1, prevImpComplement.priority ?? 1) : prevImp.priority ?? 1;
18828
+ const priorityDiff = (currImp.priority ?? 1) - prevPriority;
18790
18829
  if (priorityDiff > 0) {
18791
18830
  deduped.delete(name);
18792
18831
  deduped.delete(altName);
@@ -18814,7 +18853,14 @@ function toExports(imports, fileDir, includeType = false, options = {}) {
18814
18853
  }
18815
18854
  return true;
18816
18855
  });
18817
- if (filtered.length) entries.push(`export { ${filtered.map((i) => stringifyImportAlias(i, false)).join(", ")} } from '${name}';`);
18856
+ const byAlias = /* @__PURE__ */ new Map();
18857
+ for (const i of filtered) {
18858
+ const key = String(i.as ?? i.name);
18859
+ const existing = byAlias.get(key);
18860
+ if (!existing || existing.type && !i.type) byAlias.set(key, i);
18861
+ }
18862
+ const deduped = Array.from(byAlias.values());
18863
+ if (deduped.length) entries.push(`export { ${deduped.map((i) => stringifyImportAlias(i, false)).join(", ")} } from '${name}';`);
18818
18864
  return entries;
18819
18865
  }).join("\n");
18820
18866
  }
@@ -19274,6 +19320,14 @@ function resolveModule(name, options = {}) {
19274
19320
  return;
19275
19321
  }
19276
19322
  }
19323
+ async function importModule(path) {
19324
+ const i = await import(path);
19325
+ if (i) return interopDefault(i);
19326
+ return i;
19327
+ }
19328
+ function isPackageExists(name, options = {}) {
19329
+ return !!resolvePackage(name, options);
19330
+ }
19277
19331
  function getPackageJsonPath(name, options = {}) {
19278
19332
  const entry = resolvePackage(name, options);
19279
19333
  if (!entry) return;
@@ -19332,7 +19386,7 @@ quansync(function* (name, cwd) {
19332
19386
  const pkg = (yield loadPackageJSON(cwd)) || {};
19333
19387
  return name in (pkg.dependencies || {}) || name in (pkg.devDependencies || {});
19334
19388
  }).sync;
19335
- const version$1 = "6.1.0";
19389
+ const version$1 = "6.3.0";
19336
19390
  function configureAddons(opts) {
19337
19391
  const addons = [];
19338
19392
  if (Array.isArray(opts.addons)) addons.push(...opts.addons);
@@ -19427,8 +19481,11 @@ function parseVirtualImportsRegex(strippedCode, importMap, virtualImports) {
19427
19481
  };
19428
19482
  }
19429
19483
  async function detectImports(code, ctx, options) {
19430
- if (options?.parser === "acorn") return import("../_libs/_6.mjs").then((r) => r.detectImportsAcorn(code, ctx, options));
19431
- return detectImportsRegex(code, ctx, options);
19484
+ switch (options?.parser) {
19485
+ case "acorn": return import("../_libs/unimport+unplugin.mjs").then((n) => n.detect_acorn_exports).then((r) => r.detectImportsAcorn(code, ctx, options));
19486
+ case "oxc": return import("../_libs/unimport+unplugin.mjs").then((n) => n.detect_oxc_exports).then((r) => r.detectImportsOxc(code, ctx, options));
19487
+ default: return detectImportsRegex(code, ctx, options);
19488
+ }
19432
19489
  }
19433
19490
  const JS_RESERVED_WORDS = /* @__PURE__ */ new Set([
19434
19491
  "abstract",
@@ -19537,7 +19594,8 @@ async function scanFilesFromDir(dir, options) {
19537
19594
  expandDirectories: false
19538
19595
  })).map((i) => normalize$2(i));
19539
19596
  const fileFilter = options?.fileFilter || (() => true);
19540
- const indexOfDirs = (file) => dirGlobs.findIndex((glob2) => import_picomatch.default.isMatch(file, glob2));
19597
+ const dirMatchers = dirGlobs.map((glob2) => (0, import_picomatch.default)(glob2));
19598
+ const indexOfDirs = (file) => dirMatchers.findIndex((match) => match(file));
19541
19599
  return files.reduce((acc, file) => {
19542
19600
  const index = indexOfDirs(file);
19543
19601
  if (acc[index]) acc[index].push(normalize$2(file));
@@ -19548,8 +19606,8 @@ async function scanFilesFromDir(dir, options) {
19548
19606
  async function scanDirExports(dirs, options) {
19549
19607
  const normalizedDirs = normalizeScanDirs(dirs, options);
19550
19608
  const files = await scanFilesFromDir(normalizedDirs, options);
19551
- const includeTypesDirs = normalizedDirs.filter((dir) => !dir.glob.startsWith("!") && dir.types);
19552
- const isIncludeTypes = (file) => includeTypesDirs.some((dir) => import_picomatch.default.isMatch(file, dir.glob));
19609
+ const includeTypesMatchers = normalizedDirs.filter((dir) => !dir.glob.startsWith("!") && dir.types).map((dir) => (0, import_picomatch.default)(dir.glob));
19610
+ const isIncludeTypes = (file) => includeTypesMatchers.some((match) => match(file));
19553
19611
  return dedupeDtsExports((await Promise.all(files.map((file) => scanExports(file, isIncludeTypes(file))))).flat());
19554
19612
  }
19555
19613
  function dedupeDtsExports(exports) {
@@ -20960,20 +21018,6 @@ async function runParallel(inputs, cb, opts) {
20960
21018
  await refillQueue();
20961
21019
  return { errors };
20962
21020
  }
20963
- function escapeRegExp$1(string) {
20964
- return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
20965
- }
20966
- function pathRegExp(string) {
20967
- if (S$3) string = string.replace(/\\/g, "/");
20968
- let escaped = escapeRegExp$1(string);
20969
- if (S$3) escaped = escaped.replace(/\//g, String.raw`[/\\]`);
20970
- return escaped;
20971
- }
20972
- function toPathRegExp(input) {
20973
- if (input instanceof RegExp) return input;
20974
- if (typeof input === "string") return new RegExp(pathRegExp(input));
20975
- throw new TypeError("Expected a string or RegExp", { cause: input });
20976
- }
20977
21021
  function baseBuildConfig(nitro) {
20978
21022
  const extensions = [
20979
21023
  ".ts",
@@ -21088,6 +21132,72 @@ function joinPkgNames(moduleIds) {
21088
21132
  function routeToFsPath(route) {
21089
21133
  return route.split("/").slice(1).map((s) => s.replace(/:(\w+)/g, "[$1]").replace(/\*+/g, "[...]").replace(/[^a-zA-Z0-9_.[\]]/g, "_")).join("/") || "index";
21090
21134
  }
21135
+ function app(nitro) {
21136
+ return {
21137
+ id: "#nitro/virtual/app",
21138
+ template: () => {
21139
+ const hasRoutes = nitro.routing.routes.hasRoutes();
21140
+ const hasRouteRules = nitro.routing.routeRules.hasRoutes();
21141
+ const hasRoutedMiddleware = nitro.routing.routedMiddleware.hasRoutes();
21142
+ const hasGlobalMiddleware = nitro.routing.globalMiddleware.length > 0;
21143
+ const hasPlugins = nitro.options.plugins.length > 0;
21144
+ const hasHooks = nitro.options.features?.runtimeHooks ?? hasPlugins;
21145
+ const hasGetMiddleware = hasRouteRules || hasRoutedMiddleware;
21146
+ const hasAsyncContext = !!nitro.options.experimental.asyncContext;
21147
+ const routingImports = [
21148
+ hasRoutes && "findRoute",
21149
+ hasRoutedMiddleware && "findRoutedMiddleware",
21150
+ hasGlobalMiddleware && "globalMiddleware"
21151
+ ].filter(Boolean);
21152
+ const imports = [];
21153
+ const code = [];
21154
+ imports.push(`import { H3Core } from "h3";`, `import errorHandler from "#nitro/virtual/error-handler";`);
21155
+ code.push(``, `export function createNitroApp() {`);
21156
+ if (hasHooks) {
21157
+ imports.push(`import { HookableCore } from "hookable";`);
21158
+ code.push(` const hooks = new HookableCore();`);
21159
+ }
21160
+ code.push(``, `const captureError = (error, errorCtx) => {`);
21161
+ if (hasHooks) code.push(` const promise = hooks.callHook("error", error, errorCtx)?.catch?.((hookError) => {`, ` console.error("Error while capturing another error", hookError);`, ` });`);
21162
+ code.push(` if (errorCtx?.event) {`, ` const errors = errorCtx.event.req.context?.nitro?.errors;`, ` if (errors) {`, ` errors.push({ error, context: errorCtx });`, ` }`);
21163
+ if (hasHooks) code.push(` if (promise && typeof errorCtx.event.req.waitUntil === "function") {`, ` errorCtx.event.req.waitUntil(promise);`, ` }`);
21164
+ code.push(` }`, ` };`);
21165
+ code.push(``, ` const h3App = createH3App({`, ` onError(error, event) {`);
21166
+ if (hasHooks) code.push(` captureError(error, { event });`);
21167
+ code.push(` return errorHandler(error, event);`, ` },`, ` });`);
21168
+ if (hasHooks) code.push(``, ` h3App.config.onRequest = (event) => {`, ` return hooks.callHook("request", event)?.catch?.((error) => {`, ` captureError(error, { event, tags: ["request"] });`, ` });`, ` };`, ` h3App.config.onResponse = (res, event) => {`, ` return hooks.callHook("response", res, event)?.catch?.((error) => {`, ` captureError(error, { event, tags: ["response"] });`, ` });`, ` };`);
21169
+ code.push(``, ` let appHandler = (req) => {`, ` req.context ||= {};`, ` req.context.nitro = req.context.nitro || { errors: [] };`, ` return h3App.fetch(req);`, ` };`);
21170
+ if (hasAsyncContext) {
21171
+ imports.push(`import { nitroAsyncContext } from "#nitro/runtime/context";`);
21172
+ code.push(``, ` const originalHandler = appHandler;`, ` appHandler = (req) => {`, ` return nitroAsyncContext.callAsync({ request: req }, () => originalHandler(req));`, ` };`);
21173
+ }
21174
+ code.push(``, ` return {`, ` fetch: appHandler,`, ` h3: h3App,`, ` hooks: ${hasHooks ? "hooks" : "undefined"},`, ` captureError,`, ` };`, `}`);
21175
+ code.push(``, `export function initNitroPlugins(app) {`);
21176
+ if (hasPlugins) {
21177
+ imports.push(`import { plugins } from "#nitro/virtual/plugins";`);
21178
+ code.push(` for (const plugin of plugins) {`, ` try {`, ` plugin(app);`, ` } catch (error) {`, ` app.captureError?.(error, { tags: ["plugin"] });`, ` throw error;`, ` }`, ` }`);
21179
+ }
21180
+ code.push(` return app;`, `}`);
21181
+ if (routingImports.length) imports.push(`import { ${routingImports.join(", ")} } from "#nitro/virtual/routing";`);
21182
+ code.push(``, `function createH3App(config) {`, ` const h3App = new H3Core(config);`);
21183
+ if (hasRoutes) code.push(` h3App["~findRoute"] = (event) => findRoute(event.req.method, event.url.pathname);`);
21184
+ if (hasGlobalMiddleware) code.push(` h3App["~middleware"].push(...globalMiddleware);`);
21185
+ if (hasGetMiddleware) {
21186
+ code.push(` h3App["~getMiddleware"] = (event, route) => {`, ` const pathname = event.url.pathname;`, ` const method = event.req.method;`, ` const middleware = [];`);
21187
+ if (hasRouteRules) {
21188
+ imports.push(`import { getRouteRules } from "#nitro/runtime/app";`);
21189
+ code.push(` const routeRules = getRouteRules(method, pathname);`, ` event.context.routeRules = routeRules?.routeRules;`, ` if (routeRules?.routeRuleMiddleware.length) {`, ` middleware.push(...routeRules.routeRuleMiddleware);`, ` }`);
21190
+ }
21191
+ if (hasGlobalMiddleware) code.push(` middleware.push(...h3App["~middleware"]);`);
21192
+ if (hasRoutedMiddleware) code.push(` middleware.push(...findRoutedMiddleware(method, pathname).map((r) => r.data));`);
21193
+ if (hasRoutes) code.push(` if (route?.data?.middleware?.length) {`, ` middleware.push(...route.data.middleware);`, ` }`);
21194
+ code.push(` return middleware;`, ` };`);
21195
+ }
21196
+ code.push(` return h3App;`, `}`);
21197
+ return [...imports, ...code].join("\n");
21198
+ }
21199
+ };
21200
+ }
21091
21201
  function database(nitro) {
21092
21202
  return {
21093
21203
  id: "#nitro/virtual/database",
@@ -21397,10 +21507,11 @@ function routing(nitro) {
21397
21507
  ...Object.values(nitro.routing.routedMiddleware.routes).map((h) => h.data),
21398
21508
  ...nitro.routing.globalMiddleware
21399
21509
  ], "_importHash");
21510
+ const traceH3 = !!nitro.options.tracingChannel?.h3;
21400
21511
  return `
21401
21512
  import * as __routeRules__ from "#nitro/runtime/route-rules";
21402
21513
  import * as srvxNode from "srvx/node"
21403
- import * as h3 from "h3";
21514
+ import * as h3 from "h3";${traceH3 ? `\nimport { wrapHandlerWithTracing } from "h3/tracing";` : ""}
21404
21515
 
21405
21516
  export const findRouteRules = ${nitro.routing.routeRules.compileToString({
21406
21517
  serialize: serializeRouteRule,
@@ -21417,7 +21528,7 @@ ${allHandlers.filter((h) => !h.lazy).map((h) => `import ${h._importHash} from "$
21417
21528
 
21418
21529
  ${allHandlers.filter((h) => h.lazy).map((h) => `const ${h._importHash} = h3.defineLazyEventHandler(() => import("${h.handler}")${h.format === "node" ? ".then(m => srvxNode.toFetchHandler(m.default))" : ""});`).join("\n")}
21419
21530
 
21420
- export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
21531
+ export const findRoute = ${nitro.routing.routes.compileToString({ serialize: (h) => serializeHandler(h, { tracing: traceH3 }) })}
21421
21532
 
21422
21533
  export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({
21423
21534
  serialize: serializeHandler,
@@ -21434,13 +21545,14 @@ export const globalMiddleware = [
21434
21545
  function uniqueBy(arr, key) {
21435
21546
  return [...new Map(arr.map((item) => [item[key], item])).values()];
21436
21547
  }
21437
- function serializeHandler(h) {
21548
+ function serializeHandler(h, opts = {}) {
21438
21549
  const meta = Array.isArray(h) ? h[0] : h;
21550
+ const handler = Array.isArray(h) ? `multiHandler(${h.map((handler) => serializeHandlerFn(handler)).join(",")})` : serializeHandlerFn(h);
21439
21551
  return `{${[
21440
21552
  `route:${JSON.stringify(meta.route)}`,
21441
21553
  meta.method && `method:${JSON.stringify(meta.method)}`,
21442
21554
  meta.meta && `meta:${JSON.stringify(meta.meta)}`,
21443
- `handler:${Array.isArray(h) ? `multiHandler(${h.map((handler) => serializeHandlerFn(handler)).join(",")})` : serializeHandlerFn(h)}`
21555
+ `handler:${opts.tracing ? `wrapHandlerWithTracing(${handler})` : handler}`
21444
21556
  ].filter(Boolean).join(",")}}`;
21445
21557
  }
21446
21558
  function serializeHandlerFn(h) {
@@ -21550,17 +21662,20 @@ function storage(nitro) {
21550
21662
  opts: driverOpts
21551
21663
  });
21552
21664
  }
21665
+ const driverImports = [...new Set(mounts.map((m) => m.driver))];
21666
+ const tracingEnabled = !!(typeof nitro.options.tracingChannel === "object" && nitro.options.tracingChannel?.unstorage);
21553
21667
  return `
21554
21668
  import { createStorage } from 'unstorage'
21669
+ ${tracingEnabled ? `import { withTracing } from 'unstorage/tracing'` : ""}
21555
21670
  import { assets } from '#nitro/virtual/server-assets'
21556
21671
 
21557
- ${[...new Set(mounts.map((m) => m.driver))].map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
21672
+ ${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
21558
21673
 
21559
21674
  export function initStorage() {
21560
21675
  const storage = createStorage({})
21561
21676
  storage.mount('/assets', assets)
21562
21677
  ${mounts.map((m) => `storage.mount('${m.path}', ${genSafeVariableName(m.driver)}(${JSON.stringify(m.opts)}))`).join("\n")}
21563
- return storage
21678
+ return ${tracingEnabled ? "withTracing(storage)" : "storage"}
21564
21679
  }
21565
21680
  `;
21566
21681
  }
@@ -21621,6 +21736,7 @@ function tracing(nitro) {
21621
21736
  }
21622
21737
  function virtualTemplates(nitro, _polyfills) {
21623
21738
  const nitroTemplates = [
21739
+ app,
21624
21740
  database,
21625
21741
  errorHandler,
21626
21742
  featureFlags,
@@ -27810,7 +27926,7 @@ function unwasm(opts) {
27810
27926
  order: "pre",
27811
27927
  filter: { id: [
27812
27928
  /* @__PURE__ */ new RegExp("^" + escapeRegExp(UMWASM_HELPERS_ID) + "$"),
27813
- /* @__PURE__ */ new RegExp("^" + UNWASM_EXTERNAL_PREFIX),
27929
+ /* @__PURE__ */ new RegExp("^\0unwasm:external:"),
27814
27930
  WASM_ID_RE
27815
27931
  ] },
27816
27932
  async handler(id, importer) {
@@ -28168,10 +28284,11 @@ function externals(opts) {
28168
28284
  if (exclude.some((r) => r.test(id))) return false;
28169
28285
  return true;
28170
28286
  };
28287
+ const resolveConditions = opts.conditions.includes("import") ? opts.conditions : [...opts.conditions, "import"];
28171
28288
  const tryResolve = (id, from) => resolveModulePath(id, {
28172
28289
  try: true,
28173
28290
  from: from && isAbsolute$2(from) ? from : opts.rootDir,
28174
- conditions: opts.conditions
28291
+ conditions: resolveConditions
28175
28292
  });
28176
28293
  const tracedPaths = /* @__PURE__ */ new Set();
28177
28294
  if (opts.trace && !resolved?.includePattern) return { name: PLUGIN_NAME };
@@ -28203,7 +28320,7 @@ function externals(opts) {
28203
28320
  let importId = toImport(id) || toImport(resolvedPath);
28204
28321
  if (!importId) return resolved;
28205
28322
  if (!tryResolve(importId, importer)) {
28206
- const guessed = await guessSubpath(resolvedPath, opts.conditions);
28323
+ const guessed = await guessSubpath(resolvedPath, resolveConditions);
28207
28324
  if (!guessed) return resolved;
28208
28325
  importId = guessed;
28209
28326
  }
@@ -28330,7 +28447,7 @@ async function baseBuildPlugins(nitro, base) {
28330
28447
  nitro.vfs = virtualPlugin.api.modules;
28331
28448
  plugins.push(virtualPlugin, virtualDeps());
28332
28449
  if (nitro.options.imports) {
28333
- const unimportPlugin = await import("../_libs/_7.mjs");
28450
+ const unimportPlugin = await import("../_libs/unimport+unplugin.mjs").then((n) => n.unplugin_exports);
28334
28451
  plugins.push(unimportPlugin.default.rollup(nitro.options.imports));
28335
28452
  }
28336
28453
  if (nitro.options.wasm !== false) plugins.push(unwasm(nitro.options.wasm || {}));
@@ -28381,4 +28498,4 @@ async function oxc(options) {
28381
28498
  }
28382
28499
  };
28383
28500
  }
28384
- export { jsonc_exports as $, src_default as A, f$1 as B, decode as C, copyPublicAssets as D, prepare as E, prettyPath as F, findNearestFile$1 as G, v$2 as H, resolveNitroPath as I, readPackageJSON$1 as J, findWorkspaceDir as K, writeFile$1 as L, glob as M, require_picomatch as N, scanUnprefixedPublicAssets as O, Builder as P, yaml_exports as Q, R$1 as R, MagicString as S, parse as T, dist_exports$1 as U, m$2 as V, findFile$1 as W, toml_exports as X, i$3 as Y, a$3 as Z, writeTypes as _, dataToEsm as a, dirname$2 as at, getMagicString as b, walk as c, join$2 as ct, libChunkName as d, resolve$3 as dt, r$5 as et, baseBuildConfig as f, writeDevBuildInfo as g, writeBuildInfo as h, createFilter as i, basename$2 as it, build as j, compressPublicAssets as k, NODE_MODULES_RE$1 as l, normalize$2 as lt, getBuildInfo as m, baseBuildPlugins as n, resolveModulePath as nt, extractAssignedNames as o, extname$4 as ot, runParallel as p, readGitConfig as q, attachScopes as r, resolveModuleURL as rt, makeLegalIdentifier as s, isAbsolute$2 as st, oxc as t, json5_exports as tt, getChunkName as u, relative$2 as ut, dist_exports as v, encode as w, stripLiteral as x, createUnimport as y, _$2 as z };
28501
+ export { Builder, MagicString, NODE_MODULES_RE$1 as NODE_MODULES_RE, R$1 as R, _$2 as _, a$3 as a, attachScopes, baseBuildConfig, baseBuildPlugins, basename$2 as basename, build, compressPublicAssets, copyPublicAssets, createFilter, createUnimport, dataToEsm, decode, dirname$2 as dirname, dist_exports, encode, escapeRegExp$1 as escapeRegExp, extname$4 as extname, extractAssignedNames, f$1 as f, findFile$1 as findFile, findNearestFile$1 as findNearestFile, findWorkspaceDir, getBuildInfo, getChunkName, getMagicString, glob, i$3 as i, importModule, isAbsolute$2 as isAbsolute, isPackageExists, join$2 as join, json5_exports, jsonc_exports, libChunkName, m$2 as m, makeLegalIdentifier, normalize$2 as normalize, oxc, parse, prepare, prettyPath, r$5 as r, readGitConfig, readPackageJSON$1 as readPackageJSON, relative$2 as relative, require_picomatch, resolve$3 as resolve, resolveModulePath, resolveModuleURL, resolveNitroPath, runParallel, scanUnprefixedPublicAssets, src_default, stripLiteral, toml_exports, v$2 as v, walk, writeBuildInfo, writeDevBuildInfo, writeFile$1 as writeFile, writeTypes, yaml_exports };
@@ -1,9 +1,9 @@
1
- import { _ as writeTypes, ct as join, d as libChunkName, f as baseBuildConfig, h as writeBuildInfo, it as basename, l as NODE_MODULES_RE, n as baseBuildPlugins, u as getChunkName, ut as relative } from "./common.mjs";
2
- import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
3
- import { n as scanHandlers } from "../_chunks/nitro2.mjs";
4
- import { n as watch } from "../_libs/readdirp+chokidar.mjs";
5
- import { t as debounce } from "../_libs/perfect-debounce.mjs";
6
- import { n as generateFSTree } from "../_chunks/utils.mjs";
1
+ import { NODE_MODULES_RE, baseBuildConfig, baseBuildPlugins, basename, getChunkName, join, libChunkName, relative, writeBuildInfo, writeTypes } from "./common.mjs";
2
+ import { formatCompatibilityDate } from "../_libs/compatx.mjs";
3
+ import { scanHandlers } from "../_chunks/nitro.mjs";
4
+ import { watch } from "../_libs/readdirp+chokidar.mjs";
5
+ import { debounce } from "../_libs/perfect-debounce.mjs";
6
+ import { generateFSTree } from "../_chunks/utils.mjs";
7
7
  import { builtinModules } from "node:module";
8
8
  import { defu } from "defu";
9
9
  const getRolldownConfig = async (nitro) => {
@@ -1,14 +1,14 @@
1
- import { _ as writeTypes, ct as join, d as libChunkName, f as baseBuildConfig, h as writeBuildInfo, it as basename, l as NODE_MODULES_RE, n as baseBuildPlugins, st as isAbsolute, t as oxc, u as getChunkName, ut as relative } from "./common.mjs";
2
- import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
3
- import { n as scanHandlers } from "../_chunks/nitro2.mjs";
4
- import { n as watch } from "../_libs/readdirp+chokidar.mjs";
5
- import { t as debounce } from "../_libs/perfect-debounce.mjs";
6
- import { t as alias } from "../_libs/plugin-alias.mjs";
7
- import { t as inject } from "../_libs/plugin-inject.mjs";
8
- import { n as generateFSTree } from "../_chunks/utils.mjs";
9
- import { t as commonjs } from "../_libs/commondir+is-reference.mjs";
10
- import { t as json } from "../_libs/plugin-json.mjs";
11
- import { t as nodeResolve } from "../_libs/hasown+resolve+deepmerge.mjs";
1
+ import { NODE_MODULES_RE, baseBuildConfig, baseBuildPlugins, basename, getChunkName, isAbsolute, join, libChunkName, oxc, relative, writeBuildInfo, writeTypes } from "./common.mjs";
2
+ import { formatCompatibilityDate } from "../_libs/compatx.mjs";
3
+ import { scanHandlers } from "../_chunks/nitro.mjs";
4
+ import { watch } from "../_libs/readdirp+chokidar.mjs";
5
+ import { debounce } from "../_libs/perfect-debounce.mjs";
6
+ import { alias } from "../_libs/plugin-alias.mjs";
7
+ import { inject } from "../_libs/plugin-inject.mjs";
8
+ import { generateFSTree } from "../_chunks/utils.mjs";
9
+ import { commonjs } from "../_libs/commondir+is-reference.mjs";
10
+ import { json } from "../_libs/plugin-json.mjs";
11
+ import { nodeResolve } from "../_libs/hasown+resolve+deepmerge.mjs";
12
12
  import { defu } from "defu";
13
13
  const getRollupConfig = async (nitro) => {
14
14
  const base = baseBuildConfig(nitro);
@@ -1,12 +1,12 @@
1
- import { H as v } from "./common.mjs";
1
+ import { resolveModulePath, v } from "./common.mjs";
2
2
  import { nitro } from "nitro/vite";
3
3
  async function viteBuild(nitro$1) {
4
4
  if (nitro$1.options.dev) throw new Error("Nitro dev CLI does not supports vite. Please use `vite dev` instead.");
5
- const { createBuilder } = await import(nitro$1.options.__vitePkg__ || "vite");
5
+ const { createBuilder } = await import(resolveModulePath(nitro$1.options.__vitePkg__ || "vite", { from: nitro$1.options.rootDir }));
6
6
  const pluginInstance = nitro({ _nitro: nitro$1 });
7
7
  globalThis.__nitro_build__ = true;
8
8
  const builder = await createBuilder({
9
- base: nitro$1.options.rootDir,
9
+ root: nitro$1.options.rootDir,
10
10
  plugins: [pluginInstance],
11
11
  logLevel: v ? "warn" : void 0
12
12
  });
@@ -0,0 +1,149 @@
1
+ import { join } from "./common.mjs";
2
+ import { scanHandlers } from "../_chunks/nitro.mjs";
3
+ import { watch as watch$1 } from "../_libs/readdirp+chokidar.mjs";
4
+ import { debounce } from "../_libs/perfect-debounce.mjs";
5
+ import { getEnvRunner } from "./vite.env.mjs";
6
+ import { watch } from "node:fs";
7
+ import { withBase } from "ufo";
8
+ import { NodeRequest, sendNodeResponse } from "srvx/node";
9
+ import "node:http";
10
+ import { DevEnvironment } from "vite";
11
+ import { createViteHotChannel } from "env-runner/vite";
12
+ const ASSET_EXT_RE = /^(?:[jt]sx?|mjs|cjs|css|s[ac]ss|less|styl|vue|svelte|astro|mdx?|map|wasm|png|jpe?g|gif|svg|webp|avif|ico|bmp|woff2?|ttf|otf|eot|mp[34]|webm|wav|ogg|m4a)$/i;
13
+ function createFetchableDevEnvironment(name, config, devServer, entry, opts) {
14
+ return new FetchableDevEnvironment(name, config, {
15
+ hot: true,
16
+ transport: createViteHotChannel(devServer, name)
17
+ }, devServer, entry, opts);
18
+ }
19
+ var FetchableDevEnvironment = class extends DevEnvironment {
20
+ devServer;
21
+ #entry;
22
+ #preventExternalize;
23
+ constructor(name, config, context, devServer, entry, opts) {
24
+ super(name, config, context);
25
+ this.devServer = devServer;
26
+ this.#entry = entry;
27
+ this.#preventExternalize = opts?.preventExternalize ?? false;
28
+ }
29
+ async fetchModule(id, importer, options) {
30
+ if (this.#preventExternalize && !id.startsWith("file://") && importer && id[0] !== "." && id[0] !== "/") {
31
+ const resolved = await this.pluginContainer.resolveId(id, importer);
32
+ if (resolved && !resolved.external) return super.fetchModule(resolved.id, importer, options);
33
+ }
34
+ return super.fetchModule(id, importer, options);
35
+ }
36
+ async dispatchFetch(request) {
37
+ return this.devServer.fetch(request);
38
+ }
39
+ async init(...args) {
40
+ await this.devServer.init?.();
41
+ await super.init(...args);
42
+ this.devServer.sendMessage({
43
+ type: "custom",
44
+ event: "nitro:vite-env",
45
+ data: {
46
+ name: this.name,
47
+ entry: this.#entry
48
+ }
49
+ });
50
+ }
51
+ };
52
+ async function configureViteDevServer(ctx, server) {
53
+ const nitro = ctx.nitro;
54
+ const nitroEnv = server.environments.nitro;
55
+ const nitroConfigFile = nitro.options._c12.configFile;
56
+ if (nitroConfigFile) server.config.configFileDependencies.push(nitroConfigFile);
57
+ if (nitro.options.features.websocket ?? nitro.options.experimental.websocket) server.httpServer.on("upgrade", (req, socket, head) => {
58
+ if (req.headers["sec-websocket-protocol"]?.startsWith("vite-")) return;
59
+ getEnvRunner(ctx).upgrade?.({ node: {
60
+ req,
61
+ socket,
62
+ head
63
+ } });
64
+ });
65
+ const reload = debounce(async () => {
66
+ await scanHandlers(nitro);
67
+ nitro.routing.sync();
68
+ nitroEnv.moduleGraph.invalidateAll();
69
+ nitroEnv.hot.send({ type: "full-reload" });
70
+ });
71
+ const scanDirs = nitro.options.scanDirs.flatMap((dir) => [
72
+ join(dir, nitro.options.apiDir || "api"),
73
+ join(dir, nitro.options.routesDir || "routes"),
74
+ join(dir, "middleware"),
75
+ join(dir, "plugins"),
76
+ join(dir, "modules")
77
+ ]);
78
+ const watchReloadEvents = new Set([
79
+ "add",
80
+ "addDir",
81
+ "unlink",
82
+ "unlinkDir"
83
+ ]);
84
+ const scanDirsWatcher = watch$1(scanDirs, { ignoreInitial: true }).on("all", (event, path, stat) => {
85
+ if (watchReloadEvents.has(event)) reload();
86
+ });
87
+ const rootDirWatcher = watch(nitro.options.rootDir, { persistent: false }, (_event, filename) => {
88
+ if (filename && /^server\.[mc]?[jt]sx?$/.test(filename)) reload();
89
+ });
90
+ nitro.hooks.hook("close", () => {
91
+ scanDirsWatcher.close();
92
+ rootDirWatcher.close();
93
+ });
94
+ nitroEnv.devServer.onMessage(async (message) => {
95
+ if (message?.__rpc === "transformHTML") try {
96
+ const html = (await server.transformIndexHtml("/", message.data)).replace("<!--ssr-outlet-->", `{{{ globalThis.__nitro_vite_envs__?.["ssr"]?.fetch($REQUEST) || "" }}}`);
97
+ nitroEnv.devServer.sendMessage({
98
+ __rpc_id: message.__rpc_id,
99
+ data: html
100
+ });
101
+ } catch (error) {
102
+ nitroEnv.devServer.sendMessage({
103
+ __rpc_id: message.__rpc_id,
104
+ error: error instanceof Error ? error.message : String(error)
105
+ });
106
+ }
107
+ });
108
+ const nitroDevMiddleware = async (nodeReq, nodeRes, next) => {
109
+ if (!nodeReq.url || /^\/@(?:vite|fs|id)\//.test(nodeReq.url) || nodeReq._nitroHandled || server.middlewares.stack.map((mw) => mw.route).some((base) => base && nodeReq.url.startsWith(base))) return next();
110
+ nodeReq._nitroHandled = true;
111
+ const baseURL = nitro.options.baseURL || "/";
112
+ const originalURL = nodeReq.url;
113
+ if (baseURL !== "/") nodeReq.url = withBase(nodeReq.url, baseURL);
114
+ try {
115
+ const req = new NodeRequest({
116
+ req: nodeReq,
117
+ res: nodeRes
118
+ });
119
+ const devAppRes = await ctx.devApp.fetch(req);
120
+ if (nodeRes.writableEnded || nodeRes.headersSent) return;
121
+ if (devAppRes.status !== 404) return await sendNodeResponse(nodeRes, devAppRes);
122
+ const envRes = await nitroEnv.dispatchFetch(req);
123
+ if (nodeRes.writableEnded || nodeRes.headersSent) return;
124
+ return await sendNodeResponse(nodeRes, envRes);
125
+ } catch (error) {
126
+ return next(error);
127
+ } finally {
128
+ if (baseURL !== "/") nodeReq.url = originalURL;
129
+ }
130
+ };
131
+ server.middlewares.use(function nitroDevMiddlewarePre(req, res, next) {
132
+ if (/^\/(?:__|@)/.test(req.url)) return next();
133
+ const match = nitro.routing.routes.match(req.method || "", new URL(withBase(req.url, nitro.options.baseURL), "http://localhost").pathname);
134
+ const matchedHandlers = match ? Array.isArray(match) ? match : [match] : [];
135
+ if (matchedHandlers.some((h) => h?.route && h.route !== "/**" && !h.route.startsWith("/**:"))) return nitroDevMiddleware(req, res, next);
136
+ res.setHeader("vary", "sec-fetch-dest, accept");
137
+ const fetchDest = req.headers["sec-fetch-dest"];
138
+ const ext = req.url.split(/[?#]/, 1)[0].match(/\.([a-z0-9]+)$/i)?.[1];
139
+ const isAssetByExt = !!ext && ASSET_EXT_RE.test(ext) && !/\btext\/html\b/.test(req.headers["accept"] || "");
140
+ const isAsset = typeof fetchDest === "string" && fetchDest !== "empty" ? !/^(?:document|iframe|frame)$/.test(fetchDest) : isAssetByExt;
141
+ if (!isAsset && (matchedHandlers.length > 0 || !ext)) return nitroDevMiddleware(req, res, next);
142
+ if (isAsset) req._nitroHandled = true;
143
+ next();
144
+ });
145
+ return () => {
146
+ server.middlewares.use(nitroDevMiddleware);
147
+ };
148
+ }
149
+ export { configureViteDevServer, createFetchableDevEnvironment };