nitro-nightly 3.0.1-20260106-202835-5325b208 → 3.0.1-20260106-205209-b085a480
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/_build/common.mjs +24899 -0
- package/dist/_build/rolldown.mjs +6 -9
- package/dist/_build/rollup.mjs +6 -8
- package/dist/_build/vite.build.mjs +1 -1
- package/dist/{_dev.mjs → _chunks/dev.mjs} +4 -7
- package/dist/{_nitro.mjs → _chunks/nitro.mjs} +16 -195
- package/dist/_chunks/nitro2.mjs +101 -0
- package/dist/_chunks/utils.mjs +278 -0
- package/dist/_libs/@hiogawa/vite-plugin-fullstack.mjs +32 -4
- package/dist/_libs/@jridgewell/gen-mapping.mjs +304 -2
- package/dist/_libs/@jridgewell/remapping.mjs +1 -2
- package/dist/_libs/@rollup/plugin-commonjs.mjs +75 -31
- package/dist/_libs/@rollup/plugin-inject.mjs +1 -3
- package/dist/_libs/@rollup/plugin-json.mjs +1 -1
- package/dist/_libs/@rollup/plugin-node-resolve.mjs +1111 -7
- package/dist/_libs/c12.mjs +597 -41
- package/dist/_libs/chokidar.mjs +235 -2
- package/dist/_libs/confbox.mjs +454 -1476
- package/dist/_libs/estree-walker.mjs +1 -144
- package/dist/_libs/giget.mjs +2235 -1377
- package/dist/_libs/httpxy.mjs +1 -1
- package/dist/_libs/unimport.mjs +1547 -1772
- package/dist/_presets.mjs +3 -9
- package/dist/builder.mjs +7 -12
- package/dist/cli/_chunks/{build2.mjs → build.mjs} +1 -1
- package/dist/cli/_chunks/dev.mjs +3 -5
- package/dist/cli/_chunks/list.mjs +1 -1
- package/dist/cli/_chunks/prepare.mjs +1 -1
- package/dist/cli/_chunks/run.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/vite.mjs +14 -1128
- package/package.json +1 -1
- package/dist/_build/rollup2.mjs +0 -56
- package/dist/_build/shared.mjs +0 -60
- package/dist/_build/shared2.mjs +0 -40
- package/dist/_build/shared3.mjs +0 -68
- package/dist/_libs/@jridgewell/resolve-uri.mjs +0 -166
- package/dist/_libs/@jridgewell/sourcemap-codec.mjs +0 -167
- package/dist/_libs/@jridgewell/trace-mapping.mjs +0 -141
- package/dist/_libs/@rolldown/pluginutils.mjs +0 -31
- package/dist/_libs/@rollup/plugin-replace.mjs +0 -104
- package/dist/_libs/@rollup/pluginutils.mjs +0 -241
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/dotenv.mjs +0 -345
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/exsolve.mjs +0 -1007
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -33
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -125
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/mlly.mjs +0 -1415
- package/dist/_libs/node-fetch-native.mjs +0 -7
- package/dist/_libs/nypm.mjs +0 -239
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -202
- package/dist/_libs/perfect-debounce.mjs +0 -89
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/pkg-types.mjs +0 -197
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/quansync.mjs +0 -90
- package/dist/_libs/rc9.mjs +0 -136
- package/dist/_libs/readdirp.mjs +0 -237
- package/dist/_libs/resolve.mjs +0 -689
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyexec.mjs +0 -627
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/unplugin-utils.mjs +0 -61
- package/dist/_libs/unplugin.mjs +0 -1225
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5895
- package/dist/_libs/webpack-virtual-modules.mjs +0 -272
- package/dist/_nitro2.mjs +0 -303
- /package/dist/{_rolldown.mjs → _common.mjs} +0 -0
package/dist/_build/rolldown.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as debounce } from "../_libs/perfect-debounce.mjs";
|
|
1
|
+
import "../_common.mjs";
|
|
2
|
+
import { Mt as join, Pt as relative, a as libChunkName, g as writeTypes, i as getChunkName, m as writeBuildInfo, n as baseBuildPlugins, o as baseBuildConfig, r as NODE_MODULES_RE } from "./common.mjs";
|
|
3
|
+
import { s as debounce } from "../_libs/c12.mjs";
|
|
5
4
|
import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { n as writeBuildInfo } from "./shared3.mjs";
|
|
5
|
+
import { n as scanHandlers } from "../_chunks/nitro2.mjs";
|
|
8
6
|
import { a as watch$1 } from "../_libs/chokidar.mjs";
|
|
9
|
-
import {
|
|
7
|
+
import { t as generateFSTree } from "../_chunks/utils.mjs";
|
|
10
8
|
import { builtinModules } from "node:module";
|
|
11
9
|
import { watch } from "node:fs";
|
|
12
10
|
import { defu } from "defu";
|
|
@@ -163,7 +161,6 @@ async function buildProduction(nitro, config) {
|
|
|
163
161
|
|
|
164
162
|
//#endregion
|
|
165
163
|
//#region src/build/rolldown/build.ts
|
|
166
|
-
var build_exports = /* @__PURE__ */ __exportAll({ rolldownBuild: () => rolldownBuild });
|
|
167
164
|
async function rolldownBuild(nitro) {
|
|
168
165
|
await nitro.hooks.callHook("build:before", nitro);
|
|
169
166
|
const config = await getRolldownConfig(nitro);
|
|
@@ -172,4 +169,4 @@ async function rolldownBuild(nitro) {
|
|
|
172
169
|
}
|
|
173
170
|
|
|
174
171
|
//#endregion
|
|
175
|
-
export { rolldownBuild
|
|
172
|
+
export { rolldownBuild };
|
package/dist/_build/rollup.mjs
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import "../_common.mjs";
|
|
2
|
+
import { Mt as join, Pt as relative, a as libChunkName, g as writeTypes, i as getChunkName, jt as isAbsolute, m as writeBuildInfo, n as baseBuildPlugins, o as baseBuildConfig, r as NODE_MODULES_RE, t as oxc } from "./common.mjs";
|
|
3
|
+
import { s as debounce } from "../_libs/c12.mjs";
|
|
4
4
|
import { t as formatCompatibilityDate } from "../_libs/compatx.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { n as writeBuildInfo } from "./shared3.mjs";
|
|
5
|
+
import { n as scanHandlers } from "../_chunks/nitro2.mjs";
|
|
7
6
|
import { a as watch$1 } from "../_libs/chokidar.mjs";
|
|
7
|
+
import { t as generateFSTree } from "../_chunks/utils.mjs";
|
|
8
8
|
import { t as alias } from "../_libs/@rollup/plugin-alias.mjs";
|
|
9
9
|
import { t as inject } from "../_libs/@rollup/plugin-inject.mjs";
|
|
10
|
-
import { a as baseBuildConfig, i as libChunkName, n as NODE_MODULES_RE, r as getChunkName, t as baseBuildPlugins } from "../vite.mjs";
|
|
11
10
|
import { t as commonjs } from "../_libs/@rollup/plugin-commonjs.mjs";
|
|
12
11
|
import { t as json } from "../_libs/@rollup/plugin-json.mjs";
|
|
13
12
|
import { t as nodeResolve } from "../_libs/@rollup/plugin-node-resolve.mjs";
|
|
14
|
-
import { t as oxc } from "./rollup2.mjs";
|
|
15
13
|
import { watch } from "node:fs";
|
|
16
14
|
import { defu } from "defu";
|
|
17
15
|
|
|
@@ -200,4 +198,4 @@ async function rollupBuild(nitro) {
|
|
|
200
198
|
}
|
|
201
199
|
|
|
202
200
|
//#endregion
|
|
203
|
-
export { rollupBuild
|
|
201
|
+
export { rollupBuild };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { r as writeDevBuildInfo } from "./_build/shared3.mjs";
|
|
6
|
-
import { n as createProxyServer } from "./_libs/httpxy.mjs";
|
|
7
|
-
import { a as watch$1 } from "./_libs/chokidar.mjs";
|
|
1
|
+
import { At as extname$1, Ft as resolve$1, Mt as join$1, dt as a, h as writeDevBuildInfo, tt as src_default, ut as T } from "../_build/common.mjs";
|
|
2
|
+
import { s as debounce } from "../_libs/c12.mjs";
|
|
3
|
+
import { n as createProxyServer } from "../_libs/httpxy.mjs";
|
|
4
|
+
import { a as watch$1 } from "../_libs/chokidar.mjs";
|
|
8
5
|
import consola$1 from "consola";
|
|
9
6
|
import { createReadStream, existsSync } from "node:fs";
|
|
10
7
|
import { readFile, rm, stat as stat$1 } from "node:fs/promises";
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import {
|
|
8
|
-
import { t as
|
|
9
|
-
import { n as
|
|
10
|
-
import {
|
|
11
|
-
import { t as glob } from "./_libs/tinyglobby.mjs";
|
|
12
|
-
import { i as scanHandlers, r as scanAndSyncOptions, t as runParallel } from "./_nitro2.mjs";
|
|
13
|
-
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "./_libs/rou3.mjs";
|
|
14
|
-
import { t as src_default } from "./_libs/mime.mjs";
|
|
15
|
-
import { n as z, t as P } from "./_libs/ultrahtml.mjs";
|
|
1
|
+
import { $ as scanUnprefixedPublicAssets, Dt as resolveModuleURL, Et as resolveModulePath, Ft as resolve, Mt as join, Pt as relative, _t as findWorkspaceDir, ct as writeFile$1, dt as a, et as compressPublicAssets, ft as d, nt as build, ot as prettyPath, st as resolveNitroPath, tt as src_default } from "../_build/common.mjs";
|
|
2
|
+
import { o as watchConfig, r as loadConfig } from "../_libs/c12.mjs";
|
|
3
|
+
import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
|
|
4
|
+
import { t as klona } from "../_libs/klona.mjs";
|
|
5
|
+
import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
|
|
6
|
+
import { n as parse, t as TSConfckCache } from "../_libs/tsconfck.mjs";
|
|
7
|
+
import { n as scanHandlers, t as scanAndSyncOptions } from "./nitro2.mjs";
|
|
8
|
+
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
|
|
9
|
+
import { n as runParallel } from "./utils.mjs";
|
|
10
|
+
import { n as z, t as P } from "../_libs/ultrahtml.mjs";
|
|
16
11
|
import { createRequire } from "node:module";
|
|
17
12
|
import consola$1, { consola } from "consola";
|
|
18
13
|
import { Hookable, createDebugger } from "hookable";
|
|
19
|
-
import { existsSync
|
|
20
|
-
import
|
|
14
|
+
import { existsSync } from "node:fs";
|
|
15
|
+
import { readFile } from "node:fs/promises";
|
|
21
16
|
import { pathToFileURL } from "node:url";
|
|
22
17
|
import { defu } from "defu";
|
|
23
18
|
import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
|
|
24
19
|
import { runtimeDir } from "nitro/meta";
|
|
25
20
|
import { colors } from "consola/utils";
|
|
26
21
|
import { hash } from "ohash";
|
|
27
|
-
import zlib from "node:zlib";
|
|
28
22
|
import http from "node:http";
|
|
29
23
|
import { toRequest } from "h3";
|
|
30
24
|
|
|
@@ -574,7 +568,7 @@ function isPkgInstalled(pkg, root) {
|
|
|
574
568
|
}
|
|
575
569
|
}
|
|
576
570
|
async function installPkg(pkg, root) {
|
|
577
|
-
const { addDevDependency } = await import("
|
|
571
|
+
const { addDevDependency } = await import("../_libs/giget.mjs").then((n) => n.i);
|
|
578
572
|
return addDevDependency(pkg, { cwd: root });
|
|
579
573
|
}
|
|
580
574
|
|
|
@@ -606,7 +600,7 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
606
600
|
configOverrides = klona(configOverrides);
|
|
607
601
|
globalThis.defineNitroConfig = globalThis.defineNitroConfig || ((c) => c);
|
|
608
602
|
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || process.env.NITRO_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE;
|
|
609
|
-
const { resolvePreset } = await import("
|
|
603
|
+
const { resolvePreset } = await import("../_presets.mjs");
|
|
610
604
|
let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
|
|
611
605
|
const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
|
|
612
606
|
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
@@ -892,7 +886,7 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
892
886
|
nitro.hooks.addHooks(nitro.options.hooks);
|
|
893
887
|
await installModules(nitro);
|
|
894
888
|
if (nitro.options.imports) {
|
|
895
|
-
const { createUnimport } = await import("
|
|
889
|
+
const { createUnimport } = await import("../_build/common.mjs").then((n) => n._);
|
|
896
890
|
nitro.unimport = createUnimport(nitro.options.imports);
|
|
897
891
|
await nitro.unimport.init();
|
|
898
892
|
nitro.options.virtual["#imports"] = () => nitro.unimport?.toExports() || "";
|
|
@@ -903,179 +897,6 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
903
897
|
return nitro;
|
|
904
898
|
}
|
|
905
899
|
|
|
906
|
-
//#endregion
|
|
907
|
-
//#region src/build/build.ts
|
|
908
|
-
async function build(nitro) {
|
|
909
|
-
switch (nitro.options.builder) {
|
|
910
|
-
case "rollup": {
|
|
911
|
-
const { rollupBuild } = await import("./_build/rollup2.mjs");
|
|
912
|
-
return rollupBuild(nitro);
|
|
913
|
-
}
|
|
914
|
-
case "rolldown": {
|
|
915
|
-
const { rolldownBuild } = await import("./_build/rolldown.mjs").then((n) => n.t);
|
|
916
|
-
return rolldownBuild(nitro);
|
|
917
|
-
}
|
|
918
|
-
case "vite": {
|
|
919
|
-
const { viteBuild } = await import("./_build/vite.build.mjs");
|
|
920
|
-
return viteBuild(nitro);
|
|
921
|
-
}
|
|
922
|
-
default: throw new Error(`Unknown builder: ${nitro.options.builder}`);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
//#endregion
|
|
927
|
-
//#region src/utils/compress.ts
|
|
928
|
-
async function compressPublicAssets(nitro) {
|
|
929
|
-
const publicFiles = await glob("**", {
|
|
930
|
-
cwd: nitro.options.output.publicDir,
|
|
931
|
-
absolute: false,
|
|
932
|
-
dot: true,
|
|
933
|
-
ignore: ["**/*.gz", "**/*.br"]
|
|
934
|
-
});
|
|
935
|
-
await Promise.all(publicFiles.map(async (fileName) => {
|
|
936
|
-
const filePath = resolve(nitro.options.output.publicDir, fileName);
|
|
937
|
-
if (existsSync(filePath + ".gz") || existsSync(filePath + ".br")) return;
|
|
938
|
-
const mimeType = src_default.getType(fileName) || "text/plain";
|
|
939
|
-
const fileContents = await fsp.readFile(filePath);
|
|
940
|
-
if (fileContents.length < 1024 || fileName.endsWith(".map") || !isCompressibleMime(mimeType)) return;
|
|
941
|
-
const { gzip, brotli } = nitro.options.compressPublicAssets || {};
|
|
942
|
-
const encodings = [gzip !== false && "gzip", brotli !== false && "br"].filter(Boolean);
|
|
943
|
-
await Promise.all(encodings.map(async (encoding) => {
|
|
944
|
-
const compressedPath = filePath + ("." + (encoding === "gzip" ? "gz" : "br"));
|
|
945
|
-
if (existsSync(compressedPath)) return;
|
|
946
|
-
const gzipOptions = { level: zlib.constants.Z_BEST_COMPRESSION };
|
|
947
|
-
const brotliOptions = {
|
|
948
|
-
[zlib.constants.BROTLI_PARAM_MODE]: isTextMime(mimeType) ? zlib.constants.BROTLI_MODE_TEXT : zlib.constants.BROTLI_MODE_GENERIC,
|
|
949
|
-
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
950
|
-
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: fileContents.length
|
|
951
|
-
};
|
|
952
|
-
const compressedBuff = await new Promise((resolve$1, reject) => {
|
|
953
|
-
const cb = (error, result) => error ? reject(error) : resolve$1(result);
|
|
954
|
-
if (encoding === "gzip") zlib.gzip(fileContents, gzipOptions, cb);
|
|
955
|
-
else zlib.brotliCompress(fileContents, brotliOptions, cb);
|
|
956
|
-
});
|
|
957
|
-
await fsp.writeFile(compressedPath, compressedBuff);
|
|
958
|
-
}));
|
|
959
|
-
}));
|
|
960
|
-
}
|
|
961
|
-
function isTextMime(mimeType) {
|
|
962
|
-
return /text|javascript|json|xml/.test(mimeType);
|
|
963
|
-
}
|
|
964
|
-
const COMPRESSIBLE_MIMES_RE = new Set([
|
|
965
|
-
"application/dash+xml",
|
|
966
|
-
"application/eot",
|
|
967
|
-
"application/font",
|
|
968
|
-
"application/font-sfnt",
|
|
969
|
-
"application/javascript",
|
|
970
|
-
"application/json",
|
|
971
|
-
"application/opentype",
|
|
972
|
-
"application/otf",
|
|
973
|
-
"application/pdf",
|
|
974
|
-
"application/pkcs7-mime",
|
|
975
|
-
"application/protobuf",
|
|
976
|
-
"application/rss+xml",
|
|
977
|
-
"application/truetype",
|
|
978
|
-
"application/ttf",
|
|
979
|
-
"application/vnd.apple.mpegurl",
|
|
980
|
-
"application/vnd.mapbox-vector-tile",
|
|
981
|
-
"application/vnd.ms-fontobject",
|
|
982
|
-
"application/wasm",
|
|
983
|
-
"application/xhtml+xml",
|
|
984
|
-
"application/xml",
|
|
985
|
-
"application/x-font-opentype",
|
|
986
|
-
"application/x-font-truetype",
|
|
987
|
-
"application/x-font-ttf",
|
|
988
|
-
"application/x-httpd-cgi",
|
|
989
|
-
"application/x-javascript",
|
|
990
|
-
"application/x-mpegurl",
|
|
991
|
-
"application/x-opentype",
|
|
992
|
-
"application/x-otf",
|
|
993
|
-
"application/x-perl",
|
|
994
|
-
"application/x-ttf",
|
|
995
|
-
"font/eot",
|
|
996
|
-
"font/opentype",
|
|
997
|
-
"font/otf",
|
|
998
|
-
"font/ttf",
|
|
999
|
-
"image/svg+xml",
|
|
1000
|
-
"text/css",
|
|
1001
|
-
"text/csv",
|
|
1002
|
-
"text/html",
|
|
1003
|
-
"text/javascript",
|
|
1004
|
-
"text/js",
|
|
1005
|
-
"text/plain",
|
|
1006
|
-
"text/richtext",
|
|
1007
|
-
"text/tab-separated-values",
|
|
1008
|
-
"text/xml",
|
|
1009
|
-
"text/x-component",
|
|
1010
|
-
"text/x-java-source",
|
|
1011
|
-
"text/x-script",
|
|
1012
|
-
"vnd.apple.mpegurl"
|
|
1013
|
-
]);
|
|
1014
|
-
function isCompressibleMime(mimeType) {
|
|
1015
|
-
return COMPRESSIBLE_MIMES_RE.has(mimeType);
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
//#endregion
|
|
1019
|
-
//#region src/build/assets.ts
|
|
1020
|
-
const NEGATION_RE = /^(!?)(.*)$/;
|
|
1021
|
-
const PARENT_DIR_GLOB_RE = /!?\.\.\//;
|
|
1022
|
-
async function scanUnprefixedPublicAssets(nitro) {
|
|
1023
|
-
const scannedPaths = [];
|
|
1024
|
-
for (const asset of nitro.options.publicAssets) {
|
|
1025
|
-
if (asset.baseURL && asset.baseURL !== "/" && !asset.fallthrough) continue;
|
|
1026
|
-
if (!await isDirectory(asset.dir)) continue;
|
|
1027
|
-
const publicAssets = await glob(getIncludePatterns(nitro, asset.dir, asset.ignore), {
|
|
1028
|
-
cwd: asset.dir,
|
|
1029
|
-
absolute: false,
|
|
1030
|
-
dot: true
|
|
1031
|
-
});
|
|
1032
|
-
scannedPaths.push(...publicAssets.map((file) => join(asset.baseURL || "/", file)));
|
|
1033
|
-
}
|
|
1034
|
-
return scannedPaths;
|
|
1035
|
-
}
|
|
1036
|
-
async function copyPublicAssets(nitro) {
|
|
1037
|
-
if (nitro.options.noPublicDir) return;
|
|
1038
|
-
for (const asset of nitro.options.publicAssets) {
|
|
1039
|
-
const assetDir = asset.dir;
|
|
1040
|
-
const dstDir = join(nitro.options.output.publicDir, asset.baseURL);
|
|
1041
|
-
if (await isDirectory(assetDir)) {
|
|
1042
|
-
const publicAssets = await glob(getIncludePatterns(nitro, assetDir, asset.ignore), {
|
|
1043
|
-
cwd: assetDir,
|
|
1044
|
-
absolute: false,
|
|
1045
|
-
dot: true
|
|
1046
|
-
});
|
|
1047
|
-
await Promise.all(publicAssets.map(async (file) => {
|
|
1048
|
-
const src = join(assetDir, file);
|
|
1049
|
-
const dst = join(dstDir, file);
|
|
1050
|
-
if (!existsSync(dst)) await promises.cp(src, dst);
|
|
1051
|
-
}));
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1055
|
-
nitro.logger.success("Generated public " + prettyPath(nitro.options.output.publicDir));
|
|
1056
|
-
}
|
|
1057
|
-
function getIncludePatterns(nitro, assetDir, ignorePatterns = nitro.options.ignore) {
|
|
1058
|
-
return ["**", ...(ignorePatterns || []).map((p) => {
|
|
1059
|
-
const [_, negation, pattern] = p.match(NEGATION_RE) || [];
|
|
1060
|
-
return (negation ? "" : "!") + (pattern.startsWith("*") ? pattern : relative(assetDir, resolve(nitro.options.rootDir, pattern)));
|
|
1061
|
-
})].filter((p) => !PARENT_DIR_GLOB_RE.test(p));
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
//#endregion
|
|
1065
|
-
//#region src/build/prepare.ts
|
|
1066
|
-
async function prepare(nitro) {
|
|
1067
|
-
await prepareDir(nitro.options.output.dir);
|
|
1068
|
-
if (!nitro.options.noPublicDir) await prepareDir(nitro.options.output.publicDir);
|
|
1069
|
-
if (!nitro.options.static) await prepareDir(nitro.options.output.serverDir);
|
|
1070
|
-
}
|
|
1071
|
-
async function prepareDir(dir) {
|
|
1072
|
-
await fsp.rm(dir, {
|
|
1073
|
-
recursive: true,
|
|
1074
|
-
force: true
|
|
1075
|
-
});
|
|
1076
|
-
await fsp.mkdir(dir, { recursive: true });
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
900
|
//#endregion
|
|
1080
901
|
//#region src/prerender/utils.ts
|
|
1081
902
|
const allowedExtensions = new Set(["", ".json"]);
|
|
@@ -1368,4 +1189,4 @@ function _pidIsRunning(pid) {
|
|
|
1368
1189
|
}
|
|
1369
1190
|
|
|
1370
1191
|
//#endregion
|
|
1371
|
-
export {
|
|
1192
|
+
export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Mt as join, Pt as relative, rt as glob } from "../_build/common.mjs";
|
|
2
|
+
import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
3
|
+
|
|
4
|
+
//#region src/scan.ts
|
|
5
|
+
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
6
|
+
const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
|
|
7
|
+
async function scanAndSyncOptions(nitro) {
|
|
8
|
+
const scannedPlugins = await scanPlugins(nitro);
|
|
9
|
+
for (const plugin of scannedPlugins) if (!nitro.options.plugins.includes(plugin)) nitro.options.plugins.push(plugin);
|
|
10
|
+
if (nitro.options.experimental.tasks) {
|
|
11
|
+
const scannedTasks = await scanTasks(nitro);
|
|
12
|
+
for (const scannedTask of scannedTasks) if (scannedTask.name in nitro.options.tasks) {
|
|
13
|
+
if (!nitro.options.tasks[scannedTask.name].handler) nitro.options.tasks[scannedTask.name].handler = scannedTask.handler;
|
|
14
|
+
} else nitro.options.tasks[scannedTask.name] = {
|
|
15
|
+
handler: scannedTask.handler,
|
|
16
|
+
description: ""
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const scannedModules = await scanModules(nitro);
|
|
20
|
+
nitro.options.modules = nitro.options.modules || [];
|
|
21
|
+
for (const modPath of scannedModules) if (!nitro.options.modules.includes(modPath)) nitro.options.modules.push(modPath);
|
|
22
|
+
}
|
|
23
|
+
async function scanHandlers(nitro) {
|
|
24
|
+
const middleware = await scanMiddleware(nitro);
|
|
25
|
+
const handlers = await Promise.all([scanServerRoutes(nitro, nitro.options.apiDir || "api", nitro.options.apiBaseURL || "/api"), scanServerRoutes(nitro, nitro.options.routesDir || "routes")]).then((r) => r.flat());
|
|
26
|
+
nitro.scannedHandlers = [...middleware, ...handlers.filter((h, index, array) => {
|
|
27
|
+
return array.findIndex((h2) => h.route === h2.route && h.method === h2.method && h.env === h2.env) === index;
|
|
28
|
+
})];
|
|
29
|
+
return handlers;
|
|
30
|
+
}
|
|
31
|
+
async function scanMiddleware(nitro) {
|
|
32
|
+
return (await scanFiles(nitro, "middleware")).map((file) => {
|
|
33
|
+
return {
|
|
34
|
+
route: "/**",
|
|
35
|
+
middleware: true,
|
|
36
|
+
handler: file.fullPath
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function scanServerRoutes(nitro, dir, prefix = "/") {
|
|
41
|
+
return (await scanFiles(nitro, dir)).map((file) => {
|
|
42
|
+
let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(\w+)]/g, "**:$1").replace(/\[([^/\]]+)]/g, ":$1");
|
|
43
|
+
route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
|
|
44
|
+
const suffixMatch = route.match(suffixRegex);
|
|
45
|
+
let method;
|
|
46
|
+
let env;
|
|
47
|
+
if (suffixMatch?.index && suffixMatch?.index >= 0) {
|
|
48
|
+
route = route.slice(0, suffixMatch.index);
|
|
49
|
+
method = suffixMatch.groups?.method;
|
|
50
|
+
env = suffixMatch.groups?.env;
|
|
51
|
+
}
|
|
52
|
+
route = route.replace(/\/index$/, "") || "/";
|
|
53
|
+
return {
|
|
54
|
+
handler: file.fullPath,
|
|
55
|
+
lazy: true,
|
|
56
|
+
middleware: false,
|
|
57
|
+
route,
|
|
58
|
+
method,
|
|
59
|
+
env
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function scanPlugins(nitro) {
|
|
64
|
+
return (await scanFiles(nitro, "plugins")).map((f) => f.fullPath);
|
|
65
|
+
}
|
|
66
|
+
async function scanTasks(nitro) {
|
|
67
|
+
return (await scanFiles(nitro, "tasks")).map((f) => {
|
|
68
|
+
return {
|
|
69
|
+
name: f.path.replace(/\/index$/, "").replace(/\.[A-Za-z]+$/, "").replace(/\//g, ":"),
|
|
70
|
+
handler: f.fullPath
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async function scanModules(nitro) {
|
|
75
|
+
return (await scanFiles(nitro, "modules")).map((f) => f.fullPath);
|
|
76
|
+
}
|
|
77
|
+
async function scanFiles(nitro, name) {
|
|
78
|
+
return await Promise.all(nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name))).then((r) => r.flat());
|
|
79
|
+
}
|
|
80
|
+
async function scanDir(nitro, dir, name) {
|
|
81
|
+
return (await glob(join(name, GLOB_SCAN_PATTERN), {
|
|
82
|
+
cwd: dir,
|
|
83
|
+
dot: true,
|
|
84
|
+
ignore: nitro.options.ignore,
|
|
85
|
+
absolute: true
|
|
86
|
+
}).catch((error) => {
|
|
87
|
+
if (error?.code === "ENOTDIR") {
|
|
88
|
+
nitro.logger.warn(`Ignoring \`${join(dir, name)}\`. It must be a directory.`);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
throw error;
|
|
92
|
+
})).map((fullPath) => {
|
|
93
|
+
return {
|
|
94
|
+
fullPath,
|
|
95
|
+
path: relative(join(dir, name), fullPath)
|
|
96
|
+
};
|
|
97
|
+
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { scanHandlers as n, scanAndSyncOptions as t };
|