nitro 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.
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_build/common.mjs +157 -45
- package/dist/_build/rolldown.mjs +6 -6
- package/dist/_build/rollup.mjs +11 -11
- package/dist/_build/vite.build.mjs +3 -3
- package/dist/_build/vite.dev.mjs +149 -0
- package/dist/_build/vite.env.mjs +177 -0
- package/dist/_chunks/nitro.mjs +241 -14
- package/dist/_chunks/nitro2.mjs +117 -90
- package/dist/_chunks/utils.mjs +4 -4
- package/dist/_common.mjs +2 -2
- package/dist/_dev.d.mts +1 -1
- package/dist/_dev.mjs +7 -6
- package/dist/_libs/c12+rc9.mjs +24 -11
- package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
- package/dist/_libs/citty.mjs +1 -1
- package/dist/_libs/common.d.mts +37 -0
- package/dist/_libs/commondir+is-reference.mjs +3 -3
- package/dist/_libs/compatx.d.mts +1 -1
- package/dist/_libs/compatx.mjs +1 -1
- package/dist/_libs/estree+pluginutils.d.mts +1 -1
- package/dist/_libs/estree-walker.mjs +1 -1
- package/dist/_libs/hasown+resolve+deepmerge.mjs +62 -49
- package/dist/_libs/httpxy.d.mts +2 -4
- package/dist/_libs/httpxy.mjs +13 -9
- package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
- package/dist/_libs/klona.mjs +1 -1
- package/dist/_libs/magic-string.d.mts +1 -1
- package/dist/_libs/mlly.d.mts +1 -1
- package/dist/_libs/nypm+tinyexec.mjs +137 -113
- package/dist/_libs/openapi-types.d.mts +730 -0
- package/dist/_libs/perfect-debounce.mjs +1 -1
- package/dist/_libs/pkg-types.d.mts +8 -5
- package/dist/_libs/plugin-alias.mjs +2 -2
- package/dist/_libs/plugin-inject.mjs +4 -2
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils.mjs +18 -5
- package/dist/_libs/readdirp+chokidar.mjs +4 -3
- package/dist/_libs/remapping.mjs +2 -2
- package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
- package/dist/_libs/rou3.d.mts +1 -1
- package/dist/_libs/rou3.mjs +1 -1
- package/dist/_libs/std-env.d.mts +1 -1
- package/dist/_libs/tsconfck.mjs +1 -1
- package/dist/_libs/ultrahtml.mjs +1 -1
- package/dist/_libs/unimport+unplugin.mjs +61 -39
- package/dist/_libs/unplugin+unimport.d.mts +4 -4
- package/dist/_libs/unwasm.d.mts +1 -1
- package/dist/_presets.mjs +118 -91
- package/dist/builder.d.mts +1 -1
- package/dist/builder.mjs +3 -3
- package/dist/cli/_chunks/build.mjs +3 -3
- package/dist/cli/_chunks/common.mjs +1 -1
- package/dist/cli/_chunks/deploy.mjs +2 -2
- package/dist/cli/_chunks/dev.mjs +4 -4
- package/dist/cli/_chunks/docs.mjs +1 -1
- package/dist/cli/_chunks/list.mjs +2 -2
- package/dist/cli/_chunks/prepare.mjs +3 -3
- package/dist/cli/_chunks/preview.mjs +4 -4
- package/dist/cli/_chunks/run.mjs +2 -2
- package/dist/cli/_chunks/task.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/docs/0.docs/5.cache.md +53 -9
- package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
- package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
- package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
- package/dist/node_modules/ufo/dist/index.mjs +2 -2
- package/dist/node_modules/ufo/package.json +9 -9
- package/dist/presets/azure/runtime/azure-swa.mjs +2 -0
- package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
- package/dist/runtime/internal/app.mjs +4 -111
- package/dist/runtime/internal/route-rules.d.mts +1 -0
- package/dist/runtime/internal/route-rules.mjs +29 -1
- package/dist/runtime/internal/routes/scalar.mjs +1 -0
- package/dist/runtime/virtual/app.d.mts +4 -0
- package/dist/runtime/virtual/app.mjs +32 -0
- package/dist/types/index.d.mts +959 -1836
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +23 -331
- package/package.json +43 -44
- package/dist/THIRD-PARTY-LICENSES.md +0 -1646
- package/dist/_chunks/nitro3.mjs +0 -136
- package/dist/_chunks/nitro4.mjs +0 -127
- package/dist/_libs/_.mjs +0 -2
- package/dist/_libs/_2.mjs +0 -2
- package/dist/_libs/_3.mjs +0 -2
- package/dist/_libs/_4.mjs +0 -2
- package/dist/_libs/_5.mjs +0 -2
- package/dist/_libs/_6.mjs +0 -2
- package/dist/_libs/_7.mjs +0 -2
- package/dist/_libs/escape-string-regexp.mjs +0 -5
|
Binary file
|
package/dist/_build/common.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
3999
|
-
const filePath = join$2(...segments.slice(0, index),
|
|
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
|
|
4003
|
-
const filePath = join$2(...segments.slice(0, index),
|
|
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`);
|
|
@@ -4267,7 +4266,21 @@ function I$2() {
|
|
|
4267
4266
|
if (e) return { name: e[1] };
|
|
4268
4267
|
}
|
|
4269
4268
|
const R$1 = I$2()?.name || ``;
|
|
4270
|
-
|
|
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) => {
|
|
4271
4284
|
const type = typeof value;
|
|
4272
4285
|
return value !== null && (type === "object" || type === "function");
|
|
4273
4286
|
};
|
|
@@ -4388,7 +4401,7 @@ function normalizePath$3(path) {
|
|
|
4388
4401
|
return [];
|
|
4389
4402
|
}
|
|
4390
4403
|
function getProperty(object, path, value) {
|
|
4391
|
-
if (!isObject$
|
|
4404
|
+
if (!isObject$3(object) || typeof path !== "string" && !Array.isArray(path)) return value === void 0 ? object : value;
|
|
4392
4405
|
const pathArray = normalizePath$3(path);
|
|
4393
4406
|
if (pathArray.length === 0) return value;
|
|
4394
4407
|
for (let index = 0; index < pathArray.length; index++) {
|
|
@@ -15667,6 +15680,9 @@ const BUILTIN_MODULES = new Set(builtinModules);
|
|
|
15667
15680
|
function normalizeSlash(path) {
|
|
15668
15681
|
return path.replace(/\\/g, "/");
|
|
15669
15682
|
}
|
|
15683
|
+
function isObject$2(value) {
|
|
15684
|
+
return value !== null && typeof value === "object";
|
|
15685
|
+
}
|
|
15670
15686
|
function matchAll(regex, string, addition) {
|
|
15671
15687
|
const matches = [];
|
|
15672
15688
|
for (const match of string.matchAll(regex)) matches.push({
|
|
@@ -16725,6 +16741,23 @@ function _isIdentifierBeforeAngleBracket(str, i) {
|
|
|
16725
16741
|
const wordStart = j + 1;
|
|
16726
16742
|
return wordStart < i && /[A-Za-z_$]/.test(str[wordStart]);
|
|
16727
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
|
+
}
|
|
16728
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;
|
|
16729
16762
|
const CJS_RE = /(?:[\s;]|^)(?:module\.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
|
|
16730
16763
|
const COMMENT_RE = /\/\*.+?\*\/|\/\/.*(?=[nr])/g;
|
|
@@ -18774,7 +18807,7 @@ function dedupeImports(imports, warn) {
|
|
|
18774
18807
|
}
|
|
18775
18808
|
if (currImp.type || prevImp.type ? (currImp.typeFrom || currImp.from) === (prevImp.typeFrom || prevImp.from) : currImp.from === prevImp.from) {
|
|
18776
18809
|
if (Boolean(currImp.type) === Boolean(prevImp.type)) {
|
|
18777
|
-
if ((currImp.priority
|
|
18810
|
+
if ((currImp.priority ?? 1) > (prevImp.priority ?? 1)) {
|
|
18778
18811
|
deduped.delete(name);
|
|
18779
18812
|
deduped.set(name, currImp);
|
|
18780
18813
|
}
|
|
@@ -18782,7 +18815,7 @@ function dedupeImports(imports, warn) {
|
|
|
18782
18815
|
const altName2 = encodeImportName(name);
|
|
18783
18816
|
const prevImpComplement2 = deduped.get(altName2);
|
|
18784
18817
|
if (!prevImpComplement2) deduped.set(altName2, currImp);
|
|
18785
|
-
else if ((currImp.priority
|
|
18818
|
+
else if ((currImp.priority ?? 1) > (prevImpComplement2.priority ?? 1)) {
|
|
18786
18819
|
deduped.delete(altName2);
|
|
18787
18820
|
deduped.set(altName2, currImp);
|
|
18788
18821
|
}
|
|
@@ -18791,7 +18824,8 @@ function dedupeImports(imports, warn) {
|
|
|
18791
18824
|
}
|
|
18792
18825
|
const altName = encodeImportName(name);
|
|
18793
18826
|
const prevImpComplement = deduped.get(altName);
|
|
18794
|
-
const
|
|
18827
|
+
const prevPriority = prevImpComplement ? Math.max(prevImp.priority ?? 1, prevImpComplement.priority ?? 1) : prevImp.priority ?? 1;
|
|
18828
|
+
const priorityDiff = (currImp.priority ?? 1) - prevPriority;
|
|
18795
18829
|
if (priorityDiff > 0) {
|
|
18796
18830
|
deduped.delete(name);
|
|
18797
18831
|
deduped.delete(altName);
|
|
@@ -18819,7 +18853,14 @@ function toExports(imports, fileDir, includeType = false, options = {}) {
|
|
|
18819
18853
|
}
|
|
18820
18854
|
return true;
|
|
18821
18855
|
});
|
|
18822
|
-
|
|
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}';`);
|
|
18823
18864
|
return entries;
|
|
18824
18865
|
}).join("\n");
|
|
18825
18866
|
}
|
|
@@ -19279,6 +19320,14 @@ function resolveModule(name, options = {}) {
|
|
|
19279
19320
|
return;
|
|
19280
19321
|
}
|
|
19281
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
|
+
}
|
|
19282
19331
|
function getPackageJsonPath(name, options = {}) {
|
|
19283
19332
|
const entry = resolvePackage(name, options);
|
|
19284
19333
|
if (!entry) return;
|
|
@@ -19337,7 +19386,7 @@ quansync(function* (name, cwd) {
|
|
|
19337
19386
|
const pkg = (yield loadPackageJSON(cwd)) || {};
|
|
19338
19387
|
return name in (pkg.dependencies || {}) || name in (pkg.devDependencies || {});
|
|
19339
19388
|
}).sync;
|
|
19340
|
-
const version$1 = "6.
|
|
19389
|
+
const version$1 = "6.3.0";
|
|
19341
19390
|
function configureAddons(opts) {
|
|
19342
19391
|
const addons = [];
|
|
19343
19392
|
if (Array.isArray(opts.addons)) addons.push(...opts.addons);
|
|
@@ -19432,8 +19481,11 @@ function parseVirtualImportsRegex(strippedCode, importMap, virtualImports) {
|
|
|
19432
19481
|
};
|
|
19433
19482
|
}
|
|
19434
19483
|
async function detectImports(code, ctx, options) {
|
|
19435
|
-
|
|
19436
|
-
|
|
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
|
+
}
|
|
19437
19489
|
}
|
|
19438
19490
|
const JS_RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
19439
19491
|
"abstract",
|
|
@@ -19542,7 +19594,8 @@ async function scanFilesFromDir(dir, options) {
|
|
|
19542
19594
|
expandDirectories: false
|
|
19543
19595
|
})).map((i) => normalize$2(i));
|
|
19544
19596
|
const fileFilter = options?.fileFilter || (() => true);
|
|
19545
|
-
const
|
|
19597
|
+
const dirMatchers = dirGlobs.map((glob2) => (0, import_picomatch.default)(glob2));
|
|
19598
|
+
const indexOfDirs = (file) => dirMatchers.findIndex((match) => match(file));
|
|
19546
19599
|
return files.reduce((acc, file) => {
|
|
19547
19600
|
const index = indexOfDirs(file);
|
|
19548
19601
|
if (acc[index]) acc[index].push(normalize$2(file));
|
|
@@ -19553,8 +19606,8 @@ async function scanFilesFromDir(dir, options) {
|
|
|
19553
19606
|
async function scanDirExports(dirs, options) {
|
|
19554
19607
|
const normalizedDirs = normalizeScanDirs(dirs, options);
|
|
19555
19608
|
const files = await scanFilesFromDir(normalizedDirs, options);
|
|
19556
|
-
const
|
|
19557
|
-
const isIncludeTypes = (file) =>
|
|
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));
|
|
19558
19611
|
return dedupeDtsExports((await Promise.all(files.map((file) => scanExports(file, isIncludeTypes(file))))).flat());
|
|
19559
19612
|
}
|
|
19560
19613
|
function dedupeDtsExports(exports) {
|
|
@@ -20965,20 +21018,6 @@ async function runParallel(inputs, cb, opts) {
|
|
|
20965
21018
|
await refillQueue();
|
|
20966
21019
|
return { errors };
|
|
20967
21020
|
}
|
|
20968
|
-
function escapeRegExp$1(string) {
|
|
20969
|
-
return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
|
|
20970
|
-
}
|
|
20971
|
-
function pathRegExp(string) {
|
|
20972
|
-
if (S$3) string = string.replace(/\\/g, "/");
|
|
20973
|
-
let escaped = escapeRegExp$1(string);
|
|
20974
|
-
if (S$3) escaped = escaped.replace(/\//g, String.raw`[/\\]`);
|
|
20975
|
-
return escaped;
|
|
20976
|
-
}
|
|
20977
|
-
function toPathRegExp(input) {
|
|
20978
|
-
if (input instanceof RegExp) return input;
|
|
20979
|
-
if (typeof input === "string") return new RegExp(pathRegExp(input));
|
|
20980
|
-
throw new TypeError("Expected a string or RegExp", { cause: input });
|
|
20981
|
-
}
|
|
20982
21021
|
function baseBuildConfig(nitro) {
|
|
20983
21022
|
const extensions = [
|
|
20984
21023
|
".ts",
|
|
@@ -21093,6 +21132,72 @@ function joinPkgNames(moduleIds) {
|
|
|
21093
21132
|
function routeToFsPath(route) {
|
|
21094
21133
|
return route.split("/").slice(1).map((s) => s.replace(/:(\w+)/g, "[$1]").replace(/\*+/g, "[...]").replace(/[^a-zA-Z0-9_.[\]]/g, "_")).join("/") || "index";
|
|
21095
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
|
+
}
|
|
21096
21201
|
function database(nitro) {
|
|
21097
21202
|
return {
|
|
21098
21203
|
id: "#nitro/virtual/database",
|
|
@@ -21402,10 +21507,11 @@ function routing(nitro) {
|
|
|
21402
21507
|
...Object.values(nitro.routing.routedMiddleware.routes).map((h) => h.data),
|
|
21403
21508
|
...nitro.routing.globalMiddleware
|
|
21404
21509
|
], "_importHash");
|
|
21510
|
+
const traceH3 = !!nitro.options.tracingChannel?.h3;
|
|
21405
21511
|
return `
|
|
21406
21512
|
import * as __routeRules__ from "#nitro/runtime/route-rules";
|
|
21407
21513
|
import * as srvxNode from "srvx/node"
|
|
21408
|
-
import * as h3 from "h3"
|
|
21514
|
+
import * as h3 from "h3";${traceH3 ? `\nimport { wrapHandlerWithTracing } from "h3/tracing";` : ""}
|
|
21409
21515
|
|
|
21410
21516
|
export const findRouteRules = ${nitro.routing.routeRules.compileToString({
|
|
21411
21517
|
serialize: serializeRouteRule,
|
|
@@ -21422,7 +21528,7 @@ ${allHandlers.filter((h) => !h.lazy).map((h) => `import ${h._importHash} from "$
|
|
|
21422
21528
|
|
|
21423
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")}
|
|
21424
21530
|
|
|
21425
|
-
export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
|
|
21531
|
+
export const findRoute = ${nitro.routing.routes.compileToString({ serialize: (h) => serializeHandler(h, { tracing: traceH3 }) })}
|
|
21426
21532
|
|
|
21427
21533
|
export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({
|
|
21428
21534
|
serialize: serializeHandler,
|
|
@@ -21439,13 +21545,14 @@ export const globalMiddleware = [
|
|
|
21439
21545
|
function uniqueBy(arr, key) {
|
|
21440
21546
|
return [...new Map(arr.map((item) => [item[key], item])).values()];
|
|
21441
21547
|
}
|
|
21442
|
-
function serializeHandler(h) {
|
|
21548
|
+
function serializeHandler(h, opts = {}) {
|
|
21443
21549
|
const meta = Array.isArray(h) ? h[0] : h;
|
|
21550
|
+
const handler = Array.isArray(h) ? `multiHandler(${h.map((handler) => serializeHandlerFn(handler)).join(",")})` : serializeHandlerFn(h);
|
|
21444
21551
|
return `{${[
|
|
21445
21552
|
`route:${JSON.stringify(meta.route)}`,
|
|
21446
21553
|
meta.method && `method:${JSON.stringify(meta.method)}`,
|
|
21447
21554
|
meta.meta && `meta:${JSON.stringify(meta.meta)}`,
|
|
21448
|
-
`handler:${
|
|
21555
|
+
`handler:${opts.tracing ? `wrapHandlerWithTracing(${handler})` : handler}`
|
|
21449
21556
|
].filter(Boolean).join(",")}}`;
|
|
21450
21557
|
}
|
|
21451
21558
|
function serializeHandlerFn(h) {
|
|
@@ -21555,17 +21662,20 @@ function storage(nitro) {
|
|
|
21555
21662
|
opts: driverOpts
|
|
21556
21663
|
});
|
|
21557
21664
|
}
|
|
21665
|
+
const driverImports = [...new Set(mounts.map((m) => m.driver))];
|
|
21666
|
+
const tracingEnabled = !!(typeof nitro.options.tracingChannel === "object" && nitro.options.tracingChannel?.unstorage);
|
|
21558
21667
|
return `
|
|
21559
21668
|
import { createStorage } from 'unstorage'
|
|
21669
|
+
${tracingEnabled ? `import { withTracing } from 'unstorage/tracing'` : ""}
|
|
21560
21670
|
import { assets } from '#nitro/virtual/server-assets'
|
|
21561
21671
|
|
|
21562
|
-
${
|
|
21672
|
+
${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
|
|
21563
21673
|
|
|
21564
21674
|
export function initStorage() {
|
|
21565
21675
|
const storage = createStorage({})
|
|
21566
21676
|
storage.mount('/assets', assets)
|
|
21567
21677
|
${mounts.map((m) => `storage.mount('${m.path}', ${genSafeVariableName(m.driver)}(${JSON.stringify(m.opts)}))`).join("\n")}
|
|
21568
|
-
return storage
|
|
21678
|
+
return ${tracingEnabled ? "withTracing(storage)" : "storage"}
|
|
21569
21679
|
}
|
|
21570
21680
|
`;
|
|
21571
21681
|
}
|
|
@@ -21626,6 +21736,7 @@ function tracing(nitro) {
|
|
|
21626
21736
|
}
|
|
21627
21737
|
function virtualTemplates(nitro, _polyfills) {
|
|
21628
21738
|
const nitroTemplates = [
|
|
21739
|
+
app,
|
|
21629
21740
|
database,
|
|
21630
21741
|
errorHandler,
|
|
21631
21742
|
featureFlags,
|
|
@@ -27815,7 +27926,7 @@ function unwasm(opts) {
|
|
|
27815
27926
|
order: "pre",
|
|
27816
27927
|
filter: { id: [
|
|
27817
27928
|
/* @__PURE__ */ new RegExp("^" + escapeRegExp(UMWASM_HELPERS_ID) + "$"),
|
|
27818
|
-
/* @__PURE__ */ new RegExp("
|
|
27929
|
+
/* @__PURE__ */ new RegExp("^\0unwasm:external:"),
|
|
27819
27930
|
WASM_ID_RE
|
|
27820
27931
|
] },
|
|
27821
27932
|
async handler(id, importer) {
|
|
@@ -28173,10 +28284,11 @@ function externals(opts) {
|
|
|
28173
28284
|
if (exclude.some((r) => r.test(id))) return false;
|
|
28174
28285
|
return true;
|
|
28175
28286
|
};
|
|
28287
|
+
const resolveConditions = opts.conditions.includes("import") ? opts.conditions : [...opts.conditions, "import"];
|
|
28176
28288
|
const tryResolve = (id, from) => resolveModulePath(id, {
|
|
28177
28289
|
try: true,
|
|
28178
28290
|
from: from && isAbsolute$2(from) ? from : opts.rootDir,
|
|
28179
|
-
conditions:
|
|
28291
|
+
conditions: resolveConditions
|
|
28180
28292
|
});
|
|
28181
28293
|
const tracedPaths = /* @__PURE__ */ new Set();
|
|
28182
28294
|
if (opts.trace && !resolved?.includePattern) return { name: PLUGIN_NAME };
|
|
@@ -28208,7 +28320,7 @@ function externals(opts) {
|
|
|
28208
28320
|
let importId = toImport(id) || toImport(resolvedPath);
|
|
28209
28321
|
if (!importId) return resolved;
|
|
28210
28322
|
if (!tryResolve(importId, importer)) {
|
|
28211
|
-
const guessed = await guessSubpath(resolvedPath,
|
|
28323
|
+
const guessed = await guessSubpath(resolvedPath, resolveConditions);
|
|
28212
28324
|
if (!guessed) return resolved;
|
|
28213
28325
|
importId = guessed;
|
|
28214
28326
|
}
|
|
@@ -28335,7 +28447,7 @@ async function baseBuildPlugins(nitro, base) {
|
|
|
28335
28447
|
nitro.vfs = virtualPlugin.api.modules;
|
|
28336
28448
|
plugins.push(virtualPlugin, virtualDeps());
|
|
28337
28449
|
if (nitro.options.imports) {
|
|
28338
|
-
const unimportPlugin = await import("../_libs/
|
|
28450
|
+
const unimportPlugin = await import("../_libs/unimport+unplugin.mjs").then((n) => n.unplugin_exports);
|
|
28339
28451
|
plugins.push(unimportPlugin.default.rollup(nitro.options.imports));
|
|
28340
28452
|
}
|
|
28341
28453
|
if (nitro.options.wasm !== false) plugins.push(unwasm(nitro.options.wasm || {}));
|
|
@@ -28386,4 +28498,4 @@ async function oxc(options) {
|
|
|
28386
28498
|
}
|
|
28387
28499
|
};
|
|
28388
28500
|
}
|
|
28389
|
-
export {
|
|
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 };
|
package/dist/_build/rolldown.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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) => {
|
package/dist/_build/rollup.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
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 };
|