nitro-nightly 3.0.1-20260120-020848-6786d069 → 3.0.1-20260120-133849-ca1a9dee
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 +24931 -0
- package/dist/_build/rolldown.mjs +6 -11
- package/dist/_build/rollup.mjs +201 -0
- package/dist/_build/vite.build.mjs +1 -1
- package/dist/_chunks/dev.mjs +4 -6
- package/dist/_chunks/nitro.mjs +1183 -24
- package/dist/_chunks/nitro2.mjs +91 -248
- package/dist/_chunks/utils.mjs +254 -0
- package/dist/_common.mjs +45 -0
- package/dist/_libs/c12+giget+readdirp+chokidar.d.mts +214 -0
- package/dist/_libs/citty.mjs +140 -110
- package/dist/_libs/commondir+is-reference.mjs +1300 -0
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/confbox.mjs +2488 -70
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +187 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +1972 -0
- package/dist/_libs/httpxy.d.mts +79 -0
- package/dist/_libs/httpxy.mjs +6 -1
- package/dist/_libs/klona.mjs +38 -0
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+giget+tinyexec.mjs +3603 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/{plugin-alias+plugin-inject.mjs → plugin-inject.mjs} +2 -65
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/pluginutils+plugin-commonjs.d.mts +241 -0
- package/dist/_libs/pluginutils.mjs +652 -0
- package/dist/_libs/{c12+dotenv+rc9.mjs → rc9+c12+dotenv.mjs} +105 -12
- package/dist/_libs/{chokidar+readdirp.mjs → readdirp+chokidar.mjs} +8 -1
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/_libs/resolve-uri+gen-mapping.mjs +448 -0
- package/dist/_libs/rou3.d.mts +43 -0
- package/dist/_libs/rou3.mjs +322 -0
- package/dist/_libs/std-env.d.mts +4 -0
- package/dist/_libs/tsconfck.mjs +832 -0
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/{gen-mapping+remapping+resolve-uri+trace-mapping+unimport+unplugin+unplugin-utils+webpack-virtual-modules.mjs → unimport+unplugin.mjs} +228 -593
- package/dist/_libs/unplugin+unimport.d.mts +426 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +3 -8
- package/dist/builder.mjs +6 -8
- package/dist/cli/_chunks/build.mjs +1 -1
- package/dist/cli/_chunks/dev.mjs +2 -3
- 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/_chunks/task.mjs +16 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -5
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -1
- package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -1
- package/dist/runtime/internal/error/dev.d.mts +0 -1
- package/dist/runtime/internal/route-rules.d.mts +0 -4
- package/dist/runtime/internal/routes/openapi.d.mts +0 -1
- package/dist/runtime/internal/routes/scalar.d.mts +0 -1
- package/dist/runtime/internal/routes/swagger.d.mts +0 -1
- package/dist/runtime/internal/runtime-config.d.mts +0 -1
- package/dist/runtime/nitro.d.mts +0 -3
- package/dist/runtime/virtual/renderer-template.d.mts +0 -1
- package/dist/types/index.d.mts +25 -1394
- package/dist/vite.mjs +18 -641
- package/package.json +5 -5
- package/dist/_chunks/nitro3.mjs +0 -2696
- package/dist/_chunks/nitro4.mjs +0 -176
- package/dist/_chunks/nitro5.mjs +0 -733
- package/dist/_chunks/nitro6.mjs +0 -1458
- package/dist/_chunks/nitro7.mjs +0 -7561
- package/dist/_chunks/nitro8.mjs +0 -3524
- package/dist/_chunks/nitro9.mjs +0 -1729
- package/dist/_libs/_.mjs +0 -3
- package/dist/_libs/_2.mjs +0 -3
- package/dist/_libs/_3.mjs +0 -4
- package/dist/_libs/_4.mjs +0 -6
- package/dist/_libs/_5.mjs +0 -3
- package/dist/_libs/_6.mjs +0 -3
- package/dist/_libs/acorn+confbox+js-tokens+magic-string+mlly+pkg-types+sourcemap-codec+strip-literal+unimport.mjs +0 -8900
- package/dist/_libs/confbox+exsolve+pkg-types.mjs +0 -1249
- package/dist/_libs/confbox2.mjs +0 -786
- package/dist/_libs/confbox3.mjs +0 -404
- package/dist/_libs/confbox4.mjs +0 -3
- package/dist/_libs/estree-walker+unimport.mjs +0 -378
- package/dist/_libs/fdir+picomatch+tinyglobby.mjs +0 -2471
- package/dist/_libs/giget+node-fetch-native.mjs +0 -2692
- package/dist/_libs/local-pkg+quansync+unimport.mjs +0 -1526
- package/dist/_libs/nypm+tinyexec.mjs +0 -858
- package/dist/_libs/pathe.mjs +0 -164
- package/dist/_libs/perfect-debounce.mjs +0 -89
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/unimport.mjs +0 -9
- package/dist/_libs/vite-plugin-fullstack.mjs +0 -26
package/dist/_chunks/nitro3.mjs
DELETED
|
@@ -1,2696 +0,0 @@
|
|
|
1
|
-
import { a as join$1, l as relative$1, u as resolve$1 } from "../_libs/pathe.mjs";
|
|
2
|
-
import { a as watchConfig, n as loadConfig } from "../_libs/c12+dotenv+rc9.mjs";
|
|
3
|
-
import { l as resolveModulePath, r as findWorkspaceDir, u as resolveModuleURL } from "../_libs/confbox+exsolve+pkg-types.mjs";
|
|
4
|
-
import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
|
|
5
|
-
import { a as d, i as a } from "../_libs/std-env.mjs";
|
|
6
|
-
import { i as writeFile$1, n as prettyPath, r as resolveNitroPath, t as isDirectory } from "./nitro4.mjs";
|
|
7
|
-
import { t as glob } from "../_libs/fdir+picomatch+tinyglobby.mjs";
|
|
8
|
-
import { c as scanHandlers, s as scanAndSyncOptions, t as runParallel } from "./nitro5.mjs";
|
|
9
|
-
import { i as src_default } from "./nitro6.mjs";
|
|
10
|
-
import { createRequire } from "node:module";
|
|
11
|
-
import consola$1, { consola } from "consola";
|
|
12
|
-
import { Hookable, createDebugger } from "hookable";
|
|
13
|
-
import fs, { existsSync, promises } from "node:fs";
|
|
14
|
-
import fsp, { readFile } from "node:fs/promises";
|
|
15
|
-
import { pathToFileURL } from "node:url";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import { defu } from "defu";
|
|
18
|
-
import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
|
|
19
|
-
import { runtimeDir } from "nitro/meta";
|
|
20
|
-
import { createRequire as createRequire$1 } from "module";
|
|
21
|
-
import { colors } from "consola/utils";
|
|
22
|
-
import { hash } from "ohash";
|
|
23
|
-
import zlib from "node:zlib";
|
|
24
|
-
import http from "node:http";
|
|
25
|
-
import { toRequest } from "h3";
|
|
26
|
-
|
|
27
|
-
//#region node_modules/.pnpm/klona@2.0.6/node_modules/klona/full/index.mjs
|
|
28
|
-
function set(obj, key, val) {
|
|
29
|
-
if (typeof val.value === "object") val.value = klona(val.value);
|
|
30
|
-
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") Object.defineProperty(obj, key, val);
|
|
31
|
-
else obj[key] = val.value;
|
|
32
|
-
}
|
|
33
|
-
function klona(x$1) {
|
|
34
|
-
if (typeof x$1 !== "object") return x$1;
|
|
35
|
-
var i = 0, k, list, tmp, str = Object.prototype.toString.call(x$1);
|
|
36
|
-
if (str === "[object Object]") tmp = Object.create(x$1.__proto__ || null);
|
|
37
|
-
else if (str === "[object Array]") tmp = Array(x$1.length);
|
|
38
|
-
else if (str === "[object Set]") {
|
|
39
|
-
tmp = /* @__PURE__ */ new Set();
|
|
40
|
-
x$1.forEach(function(val) {
|
|
41
|
-
tmp.add(klona(val));
|
|
42
|
-
});
|
|
43
|
-
} else if (str === "[object Map]") {
|
|
44
|
-
tmp = /* @__PURE__ */ new Map();
|
|
45
|
-
x$1.forEach(function(val, key) {
|
|
46
|
-
tmp.set(klona(key), klona(val));
|
|
47
|
-
});
|
|
48
|
-
} else if (str === "[object Date]") tmp = /* @__PURE__ */ new Date(+x$1);
|
|
49
|
-
else if (str === "[object RegExp]") tmp = new RegExp(x$1.source, x$1.flags);
|
|
50
|
-
else if (str === "[object DataView]") tmp = new x$1.constructor(klona(x$1.buffer));
|
|
51
|
-
else if (str === "[object ArrayBuffer]") tmp = x$1.slice(0);
|
|
52
|
-
else if (str.slice(-6) === "Array]") tmp = new x$1.constructor(x$1);
|
|
53
|
-
if (tmp) {
|
|
54
|
-
for (list = Object.getOwnPropertySymbols(x$1); i < list.length; i++) set(tmp, list[i], Object.getOwnPropertyDescriptor(x$1, list[i]));
|
|
55
|
-
for (i = 0, list = Object.getOwnPropertyNames(x$1); i < list.length; i++) {
|
|
56
|
-
if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x$1[k]) continue;
|
|
57
|
-
set(tmp, k, Object.getOwnPropertyDescriptor(x$1, k));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return tmp || x$1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/config/defaults.ts
|
|
65
|
-
const NitroDefaults = {
|
|
66
|
-
compatibilityDate: "latest",
|
|
67
|
-
debug: d,
|
|
68
|
-
logLevel: a ? 1 : 3,
|
|
69
|
-
runtimeConfig: {
|
|
70
|
-
app: {},
|
|
71
|
-
nitro: {}
|
|
72
|
-
},
|
|
73
|
-
serverDir: false,
|
|
74
|
-
scanDirs: [],
|
|
75
|
-
buildDir: `node_modules/.nitro`,
|
|
76
|
-
output: {
|
|
77
|
-
dir: "{{ rootDir }}/.output",
|
|
78
|
-
serverDir: "{{ output.dir }}/server",
|
|
79
|
-
publicDir: "{{ output.dir }}/public"
|
|
80
|
-
},
|
|
81
|
-
features: {},
|
|
82
|
-
experimental: {},
|
|
83
|
-
future: {},
|
|
84
|
-
storage: {},
|
|
85
|
-
devStorage: {},
|
|
86
|
-
publicAssets: [],
|
|
87
|
-
serverAssets: [],
|
|
88
|
-
plugins: [],
|
|
89
|
-
tasks: {},
|
|
90
|
-
scheduledTasks: {},
|
|
91
|
-
imports: false,
|
|
92
|
-
virtual: {},
|
|
93
|
-
compressPublicAssets: false,
|
|
94
|
-
ignore: [],
|
|
95
|
-
wasm: {},
|
|
96
|
-
dev: false,
|
|
97
|
-
devServer: { watch: [] },
|
|
98
|
-
watchOptions: { ignoreInitial: true },
|
|
99
|
-
devProxy: {},
|
|
100
|
-
logging: {
|
|
101
|
-
compressedSizes: true,
|
|
102
|
-
buildSuccess: true
|
|
103
|
-
},
|
|
104
|
-
baseURL: process.env.NITRO_APP_BASE_URL || "/",
|
|
105
|
-
handlers: [],
|
|
106
|
-
devHandlers: [],
|
|
107
|
-
errorHandler: void 0,
|
|
108
|
-
routes: {},
|
|
109
|
-
routeRules: {},
|
|
110
|
-
prerender: {
|
|
111
|
-
autoSubfolderIndex: true,
|
|
112
|
-
concurrency: 1,
|
|
113
|
-
interval: 0,
|
|
114
|
-
retry: 3,
|
|
115
|
-
retryDelay: 500,
|
|
116
|
-
failOnError: false,
|
|
117
|
-
crawlLinks: false,
|
|
118
|
-
ignore: [],
|
|
119
|
-
routes: []
|
|
120
|
-
},
|
|
121
|
-
builder: void 0,
|
|
122
|
-
moduleSideEffects: ["unenv/polyfill/"],
|
|
123
|
-
replace: {},
|
|
124
|
-
node: true,
|
|
125
|
-
sourcemap: false,
|
|
126
|
-
traceDeps: [],
|
|
127
|
-
typescript: {
|
|
128
|
-
strict: true,
|
|
129
|
-
generateRuntimeConfigTypes: false,
|
|
130
|
-
generateTsConfig: false,
|
|
131
|
-
tsconfigPath: "tsconfig.json",
|
|
132
|
-
tsConfig: void 0
|
|
133
|
-
},
|
|
134
|
-
hooks: {},
|
|
135
|
-
commands: {},
|
|
136
|
-
framework: {
|
|
137
|
-
name: "nitro",
|
|
138
|
-
version: ""
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/config/resolvers/assets.ts
|
|
144
|
-
async function resolveAssetsOptions(options) {
|
|
145
|
-
for (const publicAsset of options.publicAssets) {
|
|
146
|
-
publicAsset.dir = resolve$1(options.rootDir, publicAsset.dir);
|
|
147
|
-
publicAsset.baseURL = withLeadingSlash(withoutTrailingSlash(publicAsset.baseURL || "/"));
|
|
148
|
-
}
|
|
149
|
-
for (const dir of [options.rootDir, ...options.scanDirs]) {
|
|
150
|
-
const publicDir = resolve$1(dir, "public");
|
|
151
|
-
if (!existsSync(publicDir)) continue;
|
|
152
|
-
if (options.publicAssets.some((asset) => asset.dir === publicDir)) continue;
|
|
153
|
-
options.publicAssets.push({ dir: publicDir });
|
|
154
|
-
}
|
|
155
|
-
for (const serverAsset of options.serverAssets) serverAsset.dir = resolve$1(options.rootDir, serverAsset.dir);
|
|
156
|
-
options.serverAssets.push({
|
|
157
|
-
baseName: "server",
|
|
158
|
-
dir: resolve$1(options.rootDir, "assets")
|
|
159
|
-
});
|
|
160
|
-
for (const asset of options.publicAssets) {
|
|
161
|
-
asset.baseURL = asset.baseURL || "/";
|
|
162
|
-
const isTopLevel = asset.baseURL === "/";
|
|
163
|
-
asset.fallthrough = asset.fallthrough ?? isTopLevel;
|
|
164
|
-
const routeRule = options.routeRules[asset.baseURL + "/**"];
|
|
165
|
-
asset.maxAge = (routeRule?.cache)?.maxAge ?? asset.maxAge ?? 0;
|
|
166
|
-
if (asset.maxAge && !asset.fallthrough) options.routeRules[asset.baseURL + "/**"] = defu(routeRule, { headers: { "cache-control": `public, max-age=${asset.maxAge}, immutable` } });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region src/config/resolvers/compatibility.ts
|
|
172
|
-
async function resolveCompatibilityOptions(options) {
|
|
173
|
-
options.compatibilityDate = resolveCompatibilityDatesFromEnv(options.compatibilityDate);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/config/resolvers/database.ts
|
|
178
|
-
async function resolveDatabaseOptions(options) {
|
|
179
|
-
if (options.experimental.database && options.imports) {
|
|
180
|
-
options.imports.presets ??= [];
|
|
181
|
-
options.imports.presets.push({
|
|
182
|
-
from: "nitro/database",
|
|
183
|
-
imports: ["useDatabase"]
|
|
184
|
-
});
|
|
185
|
-
if (options.dev && !options.database && !options.devDatabase) options.devDatabase = { default: {
|
|
186
|
-
connector: "sqlite",
|
|
187
|
-
options: { cwd: options.rootDir }
|
|
188
|
-
} };
|
|
189
|
-
else if (options.node && !options.database) options.database = { default: {
|
|
190
|
-
connector: "sqlite",
|
|
191
|
-
options: {}
|
|
192
|
-
} };
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/config/resolvers/export-conditions.ts
|
|
198
|
-
async function resolveExportConditionsOptions(options) {
|
|
199
|
-
options.exportConditions = _resolveExportConditions(options.exportConditions || [], {
|
|
200
|
-
dev: options.dev,
|
|
201
|
-
node: options.node,
|
|
202
|
-
wasm: options.wasm !== false
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
function _resolveExportConditions(conditions, opts) {
|
|
206
|
-
const resolvedConditions = [];
|
|
207
|
-
resolvedConditions.push(opts.dev ? "development" : "production");
|
|
208
|
-
resolvedConditions.push(...conditions);
|
|
209
|
-
if (opts.node) resolvedConditions.push("node");
|
|
210
|
-
else resolvedConditions.push("wintercg", "worker", "web", "browser", "workerd", "edge-light", "netlify", "edge-routine", "deno");
|
|
211
|
-
if (opts.wasm) resolvedConditions.push("wasm", "unwasm");
|
|
212
|
-
resolvedConditions.push("import", "default", "module");
|
|
213
|
-
if ("Bun" in globalThis) resolvedConditions.push("bun");
|
|
214
|
-
else if ("Deno" in globalThis) resolvedConditions.push("deno");
|
|
215
|
-
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
//#endregion
|
|
219
|
-
//#region node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
|
|
220
|
-
function escapeStringRegexp(string) {
|
|
221
|
-
if (typeof string !== "string") throw new TypeError("Expected a string");
|
|
222
|
-
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
//#endregion
|
|
226
|
-
//#region src/config/resolvers/imports.ts
|
|
227
|
-
async function resolveImportsOptions(options) {
|
|
228
|
-
if (options.imports === false) return;
|
|
229
|
-
options.imports.presets ??= [];
|
|
230
|
-
options.imports.dirs ??= [];
|
|
231
|
-
options.imports.dirs.push(...options.scanDirs.map((dir) => join$1(dir, "utils/**/*")));
|
|
232
|
-
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
233
|
-
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
234
|
-
options.imports.exclude.push(options.buildDir);
|
|
235
|
-
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
236
|
-
options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? /* @__PURE__ */ new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/config/resolvers/open-api.ts
|
|
242
|
-
async function resolveOpenAPIOptions(options) {
|
|
243
|
-
if (!options.experimental.openAPI) return;
|
|
244
|
-
if (!options.dev && !options.openAPI?.production) return;
|
|
245
|
-
const shouldPrerender = !options.dev && options.openAPI?.production === "prerender";
|
|
246
|
-
const handlersEnv = shouldPrerender ? "prerender" : "";
|
|
247
|
-
const prerenderRoutes = [];
|
|
248
|
-
const jsonRoute = options.openAPI?.route || "/_openapi.json";
|
|
249
|
-
prerenderRoutes.push(jsonRoute);
|
|
250
|
-
options.handlers.push({
|
|
251
|
-
route: jsonRoute,
|
|
252
|
-
env: handlersEnv,
|
|
253
|
-
handler: join$1(runtimeDir, "internal/routes/openapi")
|
|
254
|
-
});
|
|
255
|
-
if (options.openAPI?.ui?.scalar !== false) {
|
|
256
|
-
const scalarRoute = options.openAPI?.ui?.scalar?.route || "/_scalar";
|
|
257
|
-
prerenderRoutes.push(scalarRoute);
|
|
258
|
-
options.handlers.push({
|
|
259
|
-
route: options.openAPI?.ui?.scalar?.route || "/_scalar",
|
|
260
|
-
env: handlersEnv,
|
|
261
|
-
handler: join$1(runtimeDir, "internal/routes/scalar")
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
if (options.openAPI?.ui?.swagger !== false) {
|
|
265
|
-
const swaggerRoute = options.openAPI?.ui?.swagger?.route || "/_swagger";
|
|
266
|
-
prerenderRoutes.push(swaggerRoute);
|
|
267
|
-
options.handlers.push({
|
|
268
|
-
route: swaggerRoute,
|
|
269
|
-
env: handlersEnv,
|
|
270
|
-
handler: join$1(runtimeDir, "internal/routes/swagger")
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
if (shouldPrerender) {
|
|
274
|
-
options.prerender ??= {};
|
|
275
|
-
options.prerender.routes ??= [];
|
|
276
|
-
options.prerender.routes.push(...prerenderRoutes);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
//#endregion
|
|
281
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/util.js
|
|
282
|
-
const POSIX_SEP_RE = new RegExp("\\" + path.posix.sep, "g");
|
|
283
|
-
const NATIVE_SEP_RE = new RegExp("\\" + path.sep, "g");
|
|
284
|
-
/** @type {Map<string,RegExp>}*/
|
|
285
|
-
const PATTERN_REGEX_CACHE = /* @__PURE__ */ new Map();
|
|
286
|
-
const GLOB_ALL_PATTERN = `**/*`;
|
|
287
|
-
const TS_EXTENSIONS = [
|
|
288
|
-
".ts",
|
|
289
|
-
".tsx",
|
|
290
|
-
".mts",
|
|
291
|
-
".cts"
|
|
292
|
-
];
|
|
293
|
-
const TSJS_EXTENSIONS = TS_EXTENSIONS.concat([
|
|
294
|
-
".js",
|
|
295
|
-
".jsx",
|
|
296
|
-
".mjs",
|
|
297
|
-
".cjs"
|
|
298
|
-
]);
|
|
299
|
-
const TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext) => ext.substring(1)).join("|")})`;
|
|
300
|
-
const TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext) => ext.substring(1)).join("|")})`;
|
|
301
|
-
const IS_POSIX = path.posix.sep === path.sep;
|
|
302
|
-
/**
|
|
303
|
-
* @template T
|
|
304
|
-
* @returns {{resolve:(result:T)=>void, reject:(error:any)=>void, promise: Promise<T>}}
|
|
305
|
-
*/
|
|
306
|
-
function makePromise() {
|
|
307
|
-
let resolve$2, reject;
|
|
308
|
-
return {
|
|
309
|
-
promise: new Promise((res, rej) => {
|
|
310
|
-
resolve$2 = res;
|
|
311
|
-
reject = rej;
|
|
312
|
-
}),
|
|
313
|
-
resolve: resolve$2,
|
|
314
|
-
reject
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* @param {string} filename
|
|
319
|
-
* @param {import('./cache.js').TSConfckCache} [cache]
|
|
320
|
-
* @returns {Promise<string|void>}
|
|
321
|
-
*/
|
|
322
|
-
async function resolveTSConfigJson(filename, cache) {
|
|
323
|
-
if (path.extname(filename) !== ".json") return;
|
|
324
|
-
const tsconfig = path.resolve(filename);
|
|
325
|
-
if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) return tsconfig;
|
|
326
|
-
return promises.stat(tsconfig).then((stat$2) => {
|
|
327
|
-
if (stat$2.isFile() || stat$2.isFIFO()) return tsconfig;
|
|
328
|
-
else throw new Error(`${filename} exists but is not a regular file.`);
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
*
|
|
333
|
-
* @param {string} dir an absolute directory path
|
|
334
|
-
* @returns {boolean} if dir path includes a node_modules segment
|
|
335
|
-
*/
|
|
336
|
-
const isInNodeModules = IS_POSIX ? (dir) => dir.includes("/node_modules/") : (dir) => dir.match(/[/\\]node_modules[/\\]/);
|
|
337
|
-
/**
|
|
338
|
-
* convert posix separator to native separator
|
|
339
|
-
*
|
|
340
|
-
* eg.
|
|
341
|
-
* windows: C:/foo/bar -> c:\foo\bar
|
|
342
|
-
* linux: /foo/bar -> /foo/bar
|
|
343
|
-
*
|
|
344
|
-
* @param {string} filename with posix separators
|
|
345
|
-
* @returns {string} filename with native separators
|
|
346
|
-
*/
|
|
347
|
-
const posix2native = IS_POSIX ? (filename) => filename : (filename) => filename.replace(POSIX_SEP_RE, path.sep);
|
|
348
|
-
/**
|
|
349
|
-
* convert native separator to posix separator
|
|
350
|
-
*
|
|
351
|
-
* eg.
|
|
352
|
-
* windows: C:\foo\bar -> c:/foo/bar
|
|
353
|
-
* linux: /foo/bar -> /foo/bar
|
|
354
|
-
*
|
|
355
|
-
* @param {string} filename - filename with native separators
|
|
356
|
-
* @returns {string} filename with posix separators
|
|
357
|
-
*/
|
|
358
|
-
const native2posix = IS_POSIX ? (filename) => filename : (filename) => filename.replace(NATIVE_SEP_RE, path.posix.sep);
|
|
359
|
-
/**
|
|
360
|
-
* converts params to native separator, resolves path and converts native back to posix
|
|
361
|
-
*
|
|
362
|
-
* needed on windows to handle posix paths in tsconfig
|
|
363
|
-
*
|
|
364
|
-
* @param dir {string|null} directory to resolve from
|
|
365
|
-
* @param filename {string} filename or pattern to resolve
|
|
366
|
-
* @returns string
|
|
367
|
-
*/
|
|
368
|
-
const resolve2posix = IS_POSIX ? (dir, filename) => dir ? path.resolve(dir, filename) : path.resolve(filename) : (dir, filename) => native2posix(dir ? path.resolve(posix2native(dir), posix2native(filename)) : path.resolve(posix2native(filename)));
|
|
369
|
-
/**
|
|
370
|
-
*
|
|
371
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
372
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
373
|
-
* @returns {string[]}
|
|
374
|
-
*/
|
|
375
|
-
function resolveReferencedTSConfigFiles(result, options) {
|
|
376
|
-
const dir = path.dirname(result.tsconfigFile);
|
|
377
|
-
return result.tsconfig.references.map((ref) => {
|
|
378
|
-
return resolve2posix(dir, ref.path.endsWith(".json") ? ref.path : path.join(ref.path, options?.configName ?? "tsconfig.json"));
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* @param {string} filename
|
|
383
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
384
|
-
* @returns {import('./public.d.ts').TSConfckParseResult}
|
|
385
|
-
*/
|
|
386
|
-
function resolveSolutionTSConfig(filename, result) {
|
|
387
|
-
const extensions = result.tsconfig.compilerOptions?.allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
|
|
388
|
-
if (result.referenced && extensions.some((ext) => filename.endsWith(ext)) && !isIncluded(filename, result)) {
|
|
389
|
-
const solutionTSConfig = result.referenced.find((referenced) => isIncluded(filename, referenced));
|
|
390
|
-
if (solutionTSConfig) return solutionTSConfig;
|
|
391
|
-
}
|
|
392
|
-
return result;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
*
|
|
396
|
-
* @param {string} filename
|
|
397
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
398
|
-
* @returns {boolean}
|
|
399
|
-
*/
|
|
400
|
-
function isIncluded(filename, result) {
|
|
401
|
-
const dir = native2posix(path.dirname(result.tsconfigFile));
|
|
402
|
-
const files = (result.tsconfig.files || []).map((file) => resolve2posix(dir, file));
|
|
403
|
-
const absoluteFilename = resolve2posix(null, filename);
|
|
404
|
-
if (files.includes(filename)) return true;
|
|
405
|
-
const allowJs = result.tsconfig.compilerOptions?.allowJs;
|
|
406
|
-
if (isGlobMatch(absoluteFilename, dir, result.tsconfig.include || (result.tsconfig.files ? [] : [GLOB_ALL_PATTERN]), allowJs)) return !isGlobMatch(absoluteFilename, dir, result.tsconfig.exclude || [], allowJs);
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* test filenames agains glob patterns in tsconfig
|
|
411
|
-
*
|
|
412
|
-
* @param filename {string} posix style abolute path to filename to test
|
|
413
|
-
* @param dir {string} posix style absolute path to directory of tsconfig containing patterns
|
|
414
|
-
* @param patterns {string[]} glob patterns to match against
|
|
415
|
-
* @param allowJs {boolean} allowJs setting in tsconfig to include js extensions in checks
|
|
416
|
-
* @returns {boolean} true when at least one pattern matches filename
|
|
417
|
-
*/
|
|
418
|
-
function isGlobMatch(filename, dir, patterns, allowJs) {
|
|
419
|
-
const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
|
|
420
|
-
return patterns.some((pattern) => {
|
|
421
|
-
let lastWildcardIndex = pattern.length;
|
|
422
|
-
let hasWildcard = false;
|
|
423
|
-
let hasExtension = false;
|
|
424
|
-
let hasSlash = false;
|
|
425
|
-
let lastSlashIndex = -1;
|
|
426
|
-
for (let i = pattern.length - 1; i > -1; i--) {
|
|
427
|
-
const c = pattern[i];
|
|
428
|
-
if (!hasWildcard) {
|
|
429
|
-
if (c === "*" || c === "?") {
|
|
430
|
-
lastWildcardIndex = i;
|
|
431
|
-
hasWildcard = true;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
if (!hasSlash) {
|
|
435
|
-
if (c === ".") hasExtension = true;
|
|
436
|
-
else if (c === "/") {
|
|
437
|
-
lastSlashIndex = i;
|
|
438
|
-
hasSlash = true;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
if (hasWildcard && hasSlash) break;
|
|
442
|
-
}
|
|
443
|
-
if (!hasExtension && (!hasWildcard || lastWildcardIndex < lastSlashIndex)) {
|
|
444
|
-
pattern += `${pattern.endsWith("/") ? "" : "/"}${GLOB_ALL_PATTERN}`;
|
|
445
|
-
lastWildcardIndex = pattern.length - 1;
|
|
446
|
-
hasWildcard = true;
|
|
447
|
-
}
|
|
448
|
-
if (lastWildcardIndex < pattern.length - 1 && !filename.endsWith(pattern.slice(lastWildcardIndex + 1))) return false;
|
|
449
|
-
if (pattern.endsWith("*") && !extensions.some((ext) => filename.endsWith(ext))) return false;
|
|
450
|
-
if (pattern === GLOB_ALL_PATTERN) return filename.startsWith(`${dir}/`);
|
|
451
|
-
const resolvedPattern = resolve2posix(dir, pattern);
|
|
452
|
-
let firstWildcardIndex = -1;
|
|
453
|
-
for (let i = 0; i < resolvedPattern.length; i++) if (resolvedPattern[i] === "*" || resolvedPattern[i] === "?") {
|
|
454
|
-
firstWildcardIndex = i;
|
|
455
|
-
hasWildcard = true;
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
if (firstWildcardIndex > 1 && !filename.startsWith(resolvedPattern.slice(0, firstWildcardIndex - 1))) return false;
|
|
459
|
-
if (!hasWildcard) return filename === resolvedPattern;
|
|
460
|
-
else if (firstWildcardIndex + GLOB_ALL_PATTERN.length === resolvedPattern.length - (pattern.length - 1 - lastWildcardIndex) && resolvedPattern.slice(firstWildcardIndex, firstWildcardIndex + GLOB_ALL_PATTERN.length) === GLOB_ALL_PATTERN) return true;
|
|
461
|
-
if (PATTERN_REGEX_CACHE.has(resolvedPattern)) return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
|
|
462
|
-
const regex = pattern2regex(resolvedPattern, allowJs);
|
|
463
|
-
PATTERN_REGEX_CACHE.set(resolvedPattern, regex);
|
|
464
|
-
return regex.test(filename);
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* @param {string} resolvedPattern
|
|
469
|
-
* @param {boolean} allowJs
|
|
470
|
-
* @returns {RegExp}
|
|
471
|
-
*/
|
|
472
|
-
function pattern2regex(resolvedPattern, allowJs) {
|
|
473
|
-
let regexStr = "^";
|
|
474
|
-
for (let i = 0; i < resolvedPattern.length; i++) {
|
|
475
|
-
const char = resolvedPattern[i];
|
|
476
|
-
if (char === "?") {
|
|
477
|
-
regexStr += "[^\\/]";
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
if (char === "*") {
|
|
481
|
-
if (resolvedPattern[i + 1] === "*" && resolvedPattern[i + 2] === "/") {
|
|
482
|
-
i += 2;
|
|
483
|
-
regexStr += "(?:[^\\/]*\\/)*";
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
regexStr += "[^\\/]*";
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
if ("/.+^${}()|[]\\".includes(char)) regexStr += `\\`;
|
|
490
|
-
regexStr += char;
|
|
491
|
-
}
|
|
492
|
-
if (resolvedPattern.endsWith("*")) regexStr += allowJs ? TSJS_EXTENSIONS_RE_GROUP : TS_EXTENSIONS_RE_GROUP;
|
|
493
|
-
regexStr += "$";
|
|
494
|
-
return new RegExp(regexStr);
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* replace tokens like ${configDir}
|
|
498
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
499
|
-
*/
|
|
500
|
-
function replaceTokens(result) {
|
|
501
|
-
if (result.tsconfig) result.tsconfig = JSON.parse(JSON.stringify(result.tsconfig).replaceAll(/"\${configDir}/g, `"${native2posix(path.dirname(result.tsconfigFile))}`));
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
//#endregion
|
|
505
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/find.js
|
|
506
|
-
/**
|
|
507
|
-
* find the closest tsconfig.json file
|
|
508
|
-
*
|
|
509
|
-
* @param {string} filename - path to file to find tsconfig for (absolute or relative to cwd)
|
|
510
|
-
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
511
|
-
* @returns {Promise<string|null>} absolute path to closest tsconfig.json or null if not found
|
|
512
|
-
*/
|
|
513
|
-
async function find(filename, options) {
|
|
514
|
-
let dir = path.dirname(path.resolve(filename));
|
|
515
|
-
if (options?.ignoreNodeModules && isInNodeModules(dir)) return null;
|
|
516
|
-
const cache = options?.cache;
|
|
517
|
-
const configName = options?.configName ?? "tsconfig.json";
|
|
518
|
-
if (cache?.hasConfigPath(dir, configName)) return cache.getConfigPath(dir, configName);
|
|
519
|
-
const { promise, resolve: resolve$2, reject } = makePromise();
|
|
520
|
-
if (options?.root && !path.isAbsolute(options.root)) options.root = path.resolve(options.root);
|
|
521
|
-
findUp(dir, {
|
|
522
|
-
promise,
|
|
523
|
-
resolve: resolve$2,
|
|
524
|
-
reject
|
|
525
|
-
}, options);
|
|
526
|
-
return promise;
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
*
|
|
530
|
-
* @param {string} dir
|
|
531
|
-
* @param {{promise:Promise<string|null>,resolve:(result:string|null)=>void,reject:(err:any)=>void}} madePromise
|
|
532
|
-
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
533
|
-
*/
|
|
534
|
-
function findUp(dir, { resolve: resolve$2, reject, promise }, options) {
|
|
535
|
-
const { cache, root, configName } = options ?? {};
|
|
536
|
-
if (cache) if (cache.hasConfigPath(dir, configName)) {
|
|
537
|
-
let cached;
|
|
538
|
-
try {
|
|
539
|
-
cached = cache.getConfigPath(dir, configName);
|
|
540
|
-
} catch (e) {
|
|
541
|
-
reject(e);
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
if (cached?.then) cached.then(resolve$2).catch(reject);
|
|
545
|
-
else resolve$2(cached);
|
|
546
|
-
} else cache.setConfigPath(dir, promise, configName);
|
|
547
|
-
const tsconfig = path.join(dir, options?.configName ?? "tsconfig.json");
|
|
548
|
-
fs.stat(tsconfig, (err, stats) => {
|
|
549
|
-
if (stats && (stats.isFile() || stats.isFIFO())) resolve$2(tsconfig);
|
|
550
|
-
else if (err?.code !== "ENOENT") reject(err);
|
|
551
|
-
else {
|
|
552
|
-
let parent;
|
|
553
|
-
if (root === dir || (parent = path.dirname(dir)) === dir) resolve$2(null);
|
|
554
|
-
else findUp(parent, {
|
|
555
|
-
promise,
|
|
556
|
-
resolve: resolve$2,
|
|
557
|
-
reject
|
|
558
|
-
}, options);
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/find-all.js
|
|
565
|
-
/**
|
|
566
|
-
* @typedef WalkState
|
|
567
|
-
* @interface
|
|
568
|
-
* @property {string[]} files - files
|
|
569
|
-
* @property {number} calls - number of ongoing calls
|
|
570
|
-
* @property {(dir: string)=>boolean} skip - function to skip dirs
|
|
571
|
-
* @property {boolean} err - error flag
|
|
572
|
-
* @property {string[]} configNames - config file names
|
|
573
|
-
*/
|
|
574
|
-
const sep$1 = path.sep;
|
|
575
|
-
|
|
576
|
-
//#endregion
|
|
577
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/to-json.js
|
|
578
|
-
/**
|
|
579
|
-
* convert content of tsconfig.json to regular json
|
|
580
|
-
*
|
|
581
|
-
* @param {string} tsconfigJson - content of tsconfig.json
|
|
582
|
-
* @returns {string} content as regular json, comments and dangling commas have been replaced with whitespace
|
|
583
|
-
*/
|
|
584
|
-
function toJson(tsconfigJson) {
|
|
585
|
-
const stripped = stripDanglingComma(stripJsonComments(stripBom(tsconfigJson)));
|
|
586
|
-
if (stripped.trim() === "") return "{}";
|
|
587
|
-
else return stripped;
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* replace dangling commas from pseudo-json string with single space
|
|
591
|
-
* implementation heavily inspired by strip-json-comments
|
|
592
|
-
*
|
|
593
|
-
* @param {string} pseudoJson
|
|
594
|
-
* @returns {string}
|
|
595
|
-
*/
|
|
596
|
-
function stripDanglingComma(pseudoJson) {
|
|
597
|
-
let insideString = false;
|
|
598
|
-
let offset = 0;
|
|
599
|
-
let result = "";
|
|
600
|
-
let danglingCommaPos = null;
|
|
601
|
-
for (let i = 0; i < pseudoJson.length; i++) {
|
|
602
|
-
const currentCharacter = pseudoJson[i];
|
|
603
|
-
if (currentCharacter === "\"") {
|
|
604
|
-
if (!isEscaped(pseudoJson, i)) insideString = !insideString;
|
|
605
|
-
}
|
|
606
|
-
if (insideString) {
|
|
607
|
-
danglingCommaPos = null;
|
|
608
|
-
continue;
|
|
609
|
-
}
|
|
610
|
-
if (currentCharacter === ",") {
|
|
611
|
-
danglingCommaPos = i;
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
if (danglingCommaPos) {
|
|
615
|
-
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
616
|
-
result += pseudoJson.slice(offset, danglingCommaPos) + " ";
|
|
617
|
-
offset = danglingCommaPos + 1;
|
|
618
|
-
danglingCommaPos = null;
|
|
619
|
-
} else if (!currentCharacter.match(/\s/)) danglingCommaPos = null;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
return result + pseudoJson.substring(offset);
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
*
|
|
626
|
-
* @param {string} jsonString
|
|
627
|
-
* @param {number} quotePosition
|
|
628
|
-
* @returns {boolean}
|
|
629
|
-
*/
|
|
630
|
-
function isEscaped(jsonString, quotePosition) {
|
|
631
|
-
let index = quotePosition - 1;
|
|
632
|
-
let backslashCount = 0;
|
|
633
|
-
while (jsonString[index] === "\\") {
|
|
634
|
-
index -= 1;
|
|
635
|
-
backslashCount += 1;
|
|
636
|
-
}
|
|
637
|
-
return Boolean(backslashCount % 2);
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
*
|
|
641
|
-
* @param {string} string
|
|
642
|
-
* @param {number?} start
|
|
643
|
-
* @param {number?} end
|
|
644
|
-
*/
|
|
645
|
-
function strip(string, start, end) {
|
|
646
|
-
return string.slice(start, end).replace(/\S/g, " ");
|
|
647
|
-
}
|
|
648
|
-
const singleComment = Symbol("singleComment");
|
|
649
|
-
const multiComment = Symbol("multiComment");
|
|
650
|
-
/**
|
|
651
|
-
* @param {string} jsonString
|
|
652
|
-
* @returns {string}
|
|
653
|
-
*/
|
|
654
|
-
function stripJsonComments(jsonString) {
|
|
655
|
-
let isInsideString = false;
|
|
656
|
-
/** @type {false | symbol} */
|
|
657
|
-
let isInsideComment = false;
|
|
658
|
-
let offset = 0;
|
|
659
|
-
let result = "";
|
|
660
|
-
for (let index = 0; index < jsonString.length; index++) {
|
|
661
|
-
const currentCharacter = jsonString[index];
|
|
662
|
-
const nextCharacter = jsonString[index + 1];
|
|
663
|
-
if (!isInsideComment && currentCharacter === "\"") {
|
|
664
|
-
if (!isEscaped(jsonString, index)) isInsideString = !isInsideString;
|
|
665
|
-
}
|
|
666
|
-
if (isInsideString) continue;
|
|
667
|
-
if (!isInsideComment && currentCharacter + nextCharacter === "//") {
|
|
668
|
-
result += jsonString.slice(offset, index);
|
|
669
|
-
offset = index;
|
|
670
|
-
isInsideComment = singleComment;
|
|
671
|
-
index++;
|
|
672
|
-
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
|
|
673
|
-
index++;
|
|
674
|
-
isInsideComment = false;
|
|
675
|
-
result += strip(jsonString, offset, index);
|
|
676
|
-
offset = index;
|
|
677
|
-
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
678
|
-
isInsideComment = false;
|
|
679
|
-
result += strip(jsonString, offset, index);
|
|
680
|
-
offset = index;
|
|
681
|
-
} else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
|
|
682
|
-
result += jsonString.slice(offset, index);
|
|
683
|
-
offset = index;
|
|
684
|
-
isInsideComment = multiComment;
|
|
685
|
-
index++;
|
|
686
|
-
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
|
|
687
|
-
index++;
|
|
688
|
-
isInsideComment = false;
|
|
689
|
-
result += strip(jsonString, offset, index + 1);
|
|
690
|
-
offset = index + 1;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
return result + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* @param {string} string
|
|
697
|
-
* @returns {string}
|
|
698
|
-
*/
|
|
699
|
-
function stripBom(string) {
|
|
700
|
-
if (string.charCodeAt(0) === 65279) return string.slice(1);
|
|
701
|
-
return string;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
//#endregion
|
|
705
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/parse.js
|
|
706
|
-
const not_found_result = {
|
|
707
|
-
tsconfigFile: null,
|
|
708
|
-
tsconfig: {}
|
|
709
|
-
};
|
|
710
|
-
/**
|
|
711
|
-
* parse the closest tsconfig.json file
|
|
712
|
-
*
|
|
713
|
-
* @param {string} filename - path to a tsconfig .json or a source file or directory (absolute or relative to cwd)
|
|
714
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} [options] - options
|
|
715
|
-
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
716
|
-
* @throws {TSConfckParseError}
|
|
717
|
-
*/
|
|
718
|
-
async function parse(filename, options) {
|
|
719
|
-
/** @type {import('./cache.js').TSConfckCache} */
|
|
720
|
-
const cache = options?.cache;
|
|
721
|
-
if (cache?.hasParseResult(filename)) return getParsedDeep(filename, cache, options);
|
|
722
|
-
const { resolve: resolve$2, reject, promise } = makePromise();
|
|
723
|
-
cache?.setParseResult(filename, promise, true);
|
|
724
|
-
try {
|
|
725
|
-
let tsconfigFile = await resolveTSConfigJson(filename, cache) || await find(filename, options);
|
|
726
|
-
if (!tsconfigFile) {
|
|
727
|
-
resolve$2(not_found_result);
|
|
728
|
-
return promise;
|
|
729
|
-
}
|
|
730
|
-
let result;
|
|
731
|
-
if (filename !== tsconfigFile && cache?.hasParseResult(tsconfigFile)) result = await getParsedDeep(tsconfigFile, cache, options);
|
|
732
|
-
else {
|
|
733
|
-
result = await parseFile(tsconfigFile, cache, filename === tsconfigFile);
|
|
734
|
-
await Promise.all([parseExtends(result, cache), parseReferences(result, options)]);
|
|
735
|
-
}
|
|
736
|
-
replaceTokens(result);
|
|
737
|
-
resolve$2(resolveSolutionTSConfig(filename, result));
|
|
738
|
-
} catch (e) {
|
|
739
|
-
reject(e);
|
|
740
|
-
}
|
|
741
|
-
return promise;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* ensure extends and references are parsed
|
|
745
|
-
*
|
|
746
|
-
* @param {string} filename - cached file
|
|
747
|
-
* @param {import('./cache.js').TSConfckCache} cache - cache
|
|
748
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} options - options
|
|
749
|
-
*/
|
|
750
|
-
async function getParsedDeep(filename, cache, options) {
|
|
751
|
-
const result = await cache.getParseResult(filename);
|
|
752
|
-
if (result.tsconfig.extends && !result.extended || result.tsconfig.references && !result.referenced) {
|
|
753
|
-
const promise = Promise.all([parseExtends(result, cache), parseReferences(result, options)]).then(() => result);
|
|
754
|
-
cache.setParseResult(filename, promise, true);
|
|
755
|
-
return promise;
|
|
756
|
-
}
|
|
757
|
-
return result;
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
*
|
|
761
|
-
* @param {string} tsconfigFile - path to tsconfig file
|
|
762
|
-
* @param {import('./cache.js').TSConfckCache} [cache] - cache
|
|
763
|
-
* @param {boolean} [skipCache] - skip cache
|
|
764
|
-
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
765
|
-
*/
|
|
766
|
-
async function parseFile(tsconfigFile, cache, skipCache) {
|
|
767
|
-
if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) return cache.getParseResult(tsconfigFile);
|
|
768
|
-
const promise = promises.readFile(tsconfigFile, "utf-8").then(toJson).then((json) => {
|
|
769
|
-
const parsed = JSON.parse(json);
|
|
770
|
-
applyDefaults(parsed, tsconfigFile);
|
|
771
|
-
return {
|
|
772
|
-
tsconfigFile,
|
|
773
|
-
tsconfig: normalizeTSConfig(parsed, path.dirname(tsconfigFile))
|
|
774
|
-
};
|
|
775
|
-
}).catch((e) => {
|
|
776
|
-
throw new TSConfckParseError(`parsing ${tsconfigFile} failed: ${e}`, "PARSE_FILE", tsconfigFile, e);
|
|
777
|
-
});
|
|
778
|
-
if (!skipCache && (!cache?.hasParseResult(tsconfigFile) || !cache.getParseResult(tsconfigFile)._isRootFile_)) cache?.setParseResult(tsconfigFile, promise);
|
|
779
|
-
return promise;
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* normalize to match the output of ts.parseJsonConfigFileContent
|
|
783
|
-
*
|
|
784
|
-
* @param {any} tsconfig - typescript tsconfig output
|
|
785
|
-
* @param {string} dir - directory
|
|
786
|
-
*/
|
|
787
|
-
function normalizeTSConfig(tsconfig, dir) {
|
|
788
|
-
const baseUrl = tsconfig.compilerOptions?.baseUrl;
|
|
789
|
-
if (baseUrl && !baseUrl.startsWith("${") && !path.isAbsolute(baseUrl)) tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
|
|
790
|
-
return tsconfig;
|
|
791
|
-
}
|
|
792
|
-
/**
|
|
793
|
-
*
|
|
794
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
795
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
796
|
-
* @returns {Promise<void>}
|
|
797
|
-
*/
|
|
798
|
-
async function parseReferences(result, options) {
|
|
799
|
-
if (!result.tsconfig.references) return;
|
|
800
|
-
const referencedFiles = resolveReferencedTSConfigFiles(result, options);
|
|
801
|
-
const referenced = await Promise.all(referencedFiles.map((file) => parseFile(file, options?.cache)));
|
|
802
|
-
await Promise.all(referenced.map((ref) => parseExtends(ref, options?.cache)));
|
|
803
|
-
referenced.forEach((ref) => {
|
|
804
|
-
ref.solution = result;
|
|
805
|
-
replaceTokens(ref);
|
|
806
|
-
});
|
|
807
|
-
result.referenced = referenced;
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
811
|
-
* @param {import('./cache.js').TSConfckCache}[cache]
|
|
812
|
-
* @returns {Promise<void>}
|
|
813
|
-
*/
|
|
814
|
-
async function parseExtends(result, cache) {
|
|
815
|
-
if (!result.tsconfig.extends) return;
|
|
816
|
-
/** @type {import('./public.d.ts').TSConfckParseResult[]} */
|
|
817
|
-
const extended = [{
|
|
818
|
-
tsconfigFile: result.tsconfigFile,
|
|
819
|
-
tsconfig: JSON.parse(JSON.stringify(result.tsconfig))
|
|
820
|
-
}];
|
|
821
|
-
let pos = 0;
|
|
822
|
-
/** @type {string[]} */
|
|
823
|
-
const extendsPath = [];
|
|
824
|
-
let currentBranchDepth = 0;
|
|
825
|
-
while (pos < extended.length) {
|
|
826
|
-
const extending = extended[pos];
|
|
827
|
-
extendsPath.push(extending.tsconfigFile);
|
|
828
|
-
if (extending.tsconfig.extends) {
|
|
829
|
-
currentBranchDepth += 1;
|
|
830
|
-
/** @type {string[]} */
|
|
831
|
-
let resolvedExtends;
|
|
832
|
-
if (!Array.isArray(extending.tsconfig.extends)) resolvedExtends = [resolveExtends(extending.tsconfig.extends, extending.tsconfigFile)];
|
|
833
|
-
else resolvedExtends = extending.tsconfig.extends.reverse().map((ex) => resolveExtends(ex, extending.tsconfigFile));
|
|
834
|
-
const circularExtends = resolvedExtends.find((tsconfigFile) => extendsPath.includes(tsconfigFile));
|
|
835
|
-
if (circularExtends) throw new TSConfckParseError(`Circular dependency in "extends": ${extendsPath.concat([circularExtends]).join(" -> ")}`, "EXTENDS_CIRCULAR", result.tsconfigFile);
|
|
836
|
-
extended.splice(pos + 1, 0, ...await Promise.all(resolvedExtends.map((file) => parseFile(file, cache))));
|
|
837
|
-
} else {
|
|
838
|
-
extendsPath.splice(-currentBranchDepth);
|
|
839
|
-
currentBranchDepth = 0;
|
|
840
|
-
}
|
|
841
|
-
pos = pos + 1;
|
|
842
|
-
}
|
|
843
|
-
result.extended = extended;
|
|
844
|
-
for (const ext of result.extended.slice(1)) extendTSConfig(result, ext);
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
*
|
|
848
|
-
* @param {string} extended
|
|
849
|
-
* @param {string} from
|
|
850
|
-
* @returns {string}
|
|
851
|
-
*/
|
|
852
|
-
function resolveExtends(extended, from) {
|
|
853
|
-
if ([".", ".."].includes(extended)) extended = extended + "/tsconfig.json";
|
|
854
|
-
const req = createRequire$1(from);
|
|
855
|
-
let error;
|
|
856
|
-
try {
|
|
857
|
-
return req.resolve(extended);
|
|
858
|
-
} catch (e) {
|
|
859
|
-
error = e;
|
|
860
|
-
}
|
|
861
|
-
if (extended[0] !== "." && !path.isAbsolute(extended)) try {
|
|
862
|
-
return req.resolve(`${extended}/tsconfig.json`);
|
|
863
|
-
} catch (e) {
|
|
864
|
-
error = e;
|
|
865
|
-
}
|
|
866
|
-
throw new TSConfckParseError(`failed to resolve "extends":"${extended}" in ${from}`, "EXTENDS_RESOLVE", from, error);
|
|
867
|
-
}
|
|
868
|
-
const EXTENDABLE_KEYS = [
|
|
869
|
-
"compilerOptions",
|
|
870
|
-
"files",
|
|
871
|
-
"include",
|
|
872
|
-
"exclude",
|
|
873
|
-
"watchOptions",
|
|
874
|
-
"compileOnSave",
|
|
875
|
-
"typeAcquisition",
|
|
876
|
-
"buildOptions"
|
|
877
|
-
];
|
|
878
|
-
/**
|
|
879
|
-
*
|
|
880
|
-
* @param {import('./public.d.ts').TSConfckParseResult} extending
|
|
881
|
-
* @param {import('./public.d.ts').TSConfckParseResult} extended
|
|
882
|
-
* @returns void
|
|
883
|
-
*/
|
|
884
|
-
function extendTSConfig(extending, extended) {
|
|
885
|
-
const extendingConfig = extending.tsconfig;
|
|
886
|
-
const extendedConfig = extended.tsconfig;
|
|
887
|
-
const relativePath = native2posix(path.relative(path.dirname(extending.tsconfigFile), path.dirname(extended.tsconfigFile)));
|
|
888
|
-
for (const key of Object.keys(extendedConfig).filter((key$1) => EXTENDABLE_KEYS.includes(key$1))) if (key === "compilerOptions") {
|
|
889
|
-
if (!extendingConfig.compilerOptions) extendingConfig.compilerOptions = {};
|
|
890
|
-
for (const option of Object.keys(extendedConfig.compilerOptions)) {
|
|
891
|
-
if (Object.prototype.hasOwnProperty.call(extendingConfig.compilerOptions, option)) continue;
|
|
892
|
-
extendingConfig.compilerOptions[option] = rebaseRelative(option, extendedConfig.compilerOptions[option], relativePath);
|
|
893
|
-
}
|
|
894
|
-
} else if (extendingConfig[key] === void 0) if (key === "watchOptions") {
|
|
895
|
-
extendingConfig.watchOptions = {};
|
|
896
|
-
for (const option of Object.keys(extendedConfig.watchOptions)) extendingConfig.watchOptions[option] = rebaseRelative(option, extendedConfig.watchOptions[option], relativePath);
|
|
897
|
-
} else extendingConfig[key] = rebaseRelative(key, extendedConfig[key], relativePath);
|
|
898
|
-
}
|
|
899
|
-
const REBASE_KEYS = [
|
|
900
|
-
"files",
|
|
901
|
-
"include",
|
|
902
|
-
"exclude",
|
|
903
|
-
"baseUrl",
|
|
904
|
-
"rootDir",
|
|
905
|
-
"rootDirs",
|
|
906
|
-
"typeRoots",
|
|
907
|
-
"outDir",
|
|
908
|
-
"outFile",
|
|
909
|
-
"declarationDir",
|
|
910
|
-
"excludeDirectories",
|
|
911
|
-
"excludeFiles"
|
|
912
|
-
];
|
|
913
|
-
/** @typedef {string | string[]} PathValue */
|
|
914
|
-
/**
|
|
915
|
-
*
|
|
916
|
-
* @param {string} key
|
|
917
|
-
* @param {PathValue} value
|
|
918
|
-
* @param {string} prependPath
|
|
919
|
-
* @returns {PathValue}
|
|
920
|
-
*/
|
|
921
|
-
function rebaseRelative(key, value, prependPath) {
|
|
922
|
-
if (!REBASE_KEYS.includes(key)) return value;
|
|
923
|
-
if (Array.isArray(value)) return value.map((x$1) => rebasePath(x$1, prependPath));
|
|
924
|
-
else return rebasePath(value, prependPath);
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
*
|
|
928
|
-
* @param {string} value
|
|
929
|
-
* @param {string} prependPath
|
|
930
|
-
* @returns {string}
|
|
931
|
-
*/
|
|
932
|
-
function rebasePath(value, prependPath) {
|
|
933
|
-
if (path.isAbsolute(value) || value.startsWith("${configDir}")) return value;
|
|
934
|
-
else return path.posix.normalize(path.posix.join(prependPath, value));
|
|
935
|
-
}
|
|
936
|
-
var TSConfckParseError = class TSConfckParseError extends Error {
|
|
937
|
-
/**
|
|
938
|
-
* error code
|
|
939
|
-
* @type {string}
|
|
940
|
-
*/
|
|
941
|
-
code;
|
|
942
|
-
/**
|
|
943
|
-
* error cause
|
|
944
|
-
* @type { Error | undefined}
|
|
945
|
-
*/
|
|
946
|
-
cause;
|
|
947
|
-
/**
|
|
948
|
-
* absolute path of tsconfig file where the error happened
|
|
949
|
-
* @type {string}
|
|
950
|
-
*/
|
|
951
|
-
tsconfigFile;
|
|
952
|
-
/**
|
|
953
|
-
*
|
|
954
|
-
* @param {string} message - error message
|
|
955
|
-
* @param {string} code - error code
|
|
956
|
-
* @param {string} tsconfigFile - path to tsconfig file
|
|
957
|
-
* @param {Error?} cause - cause of this error
|
|
958
|
-
*/
|
|
959
|
-
constructor(message, code, tsconfigFile, cause) {
|
|
960
|
-
super(message);
|
|
961
|
-
Object.setPrototypeOf(this, TSConfckParseError.prototype);
|
|
962
|
-
this.name = TSConfckParseError.name;
|
|
963
|
-
this.code = code;
|
|
964
|
-
this.cause = cause;
|
|
965
|
-
this.tsconfigFile = tsconfigFile;
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
/**
|
|
969
|
-
*
|
|
970
|
-
* @param {any} tsconfig
|
|
971
|
-
* @param {string} tsconfigFile
|
|
972
|
-
*/
|
|
973
|
-
function applyDefaults(tsconfig, tsconfigFile) {
|
|
974
|
-
if (isJSConfig(tsconfigFile)) tsconfig.compilerOptions = {
|
|
975
|
-
...DEFAULT_JSCONFIG_COMPILER_OPTIONS,
|
|
976
|
-
...tsconfig.compilerOptions
|
|
977
|
-
};
|
|
978
|
-
}
|
|
979
|
-
const DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
|
|
980
|
-
allowJs: true,
|
|
981
|
-
maxNodeModuleJsDepth: 2,
|
|
982
|
-
allowSyntheticDefaultImports: true,
|
|
983
|
-
skipLibCheck: true,
|
|
984
|
-
noEmit: true
|
|
985
|
-
};
|
|
986
|
-
/**
|
|
987
|
-
* @param {string} configFileName
|
|
988
|
-
*/
|
|
989
|
-
function isJSConfig(configFileName) {
|
|
990
|
-
return path.basename(configFileName) === "jsconfig.json";
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
//#endregion
|
|
994
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/parse-native.js
|
|
995
|
-
/** @typedef TSDiagnosticError {
|
|
996
|
-
code: number;
|
|
997
|
-
category: number;
|
|
998
|
-
messageText: string;
|
|
999
|
-
start?: number;
|
|
1000
|
-
} TSDiagnosticError */
|
|
1001
|
-
|
|
1002
|
-
//#endregion
|
|
1003
|
-
//#region node_modules/.pnpm/tsconfck@3.1.6_typescript@5.9.3/node_modules/tsconfck/src/cache.js
|
|
1004
|
-
/** @template T */
|
|
1005
|
-
var TSConfckCache = class {
|
|
1006
|
-
/**
|
|
1007
|
-
* clear cache, use this if you have a long running process and tsconfig files have been added,changed or deleted
|
|
1008
|
-
*/
|
|
1009
|
-
clear() {
|
|
1010
|
-
this.#configPaths.clear();
|
|
1011
|
-
this.#parsed.clear();
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* has cached closest config for files in dir
|
|
1015
|
-
* @param {string} dir
|
|
1016
|
-
* @param {string} [configName=tsconfig.json]
|
|
1017
|
-
* @returns {boolean}
|
|
1018
|
-
*/
|
|
1019
|
-
hasConfigPath(dir, configName = "tsconfig.json") {
|
|
1020
|
-
return this.#configPaths.has(`${dir}/${configName}`);
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* get cached closest tsconfig for files in dir
|
|
1024
|
-
* @param {string} dir
|
|
1025
|
-
* @param {string} [configName=tsconfig.json]
|
|
1026
|
-
* @returns {Promise<string|null>|string|null}
|
|
1027
|
-
* @throws {unknown} if cached value is an error
|
|
1028
|
-
*/
|
|
1029
|
-
getConfigPath(dir, configName = "tsconfig.json") {
|
|
1030
|
-
const key = `${dir}/${configName}`;
|
|
1031
|
-
const value = this.#configPaths.get(key);
|
|
1032
|
-
if (value == null || value.length || value.then) return value;
|
|
1033
|
-
else throw value;
|
|
1034
|
-
}
|
|
1035
|
-
/**
|
|
1036
|
-
* has parsed tsconfig for file
|
|
1037
|
-
* @param {string} file
|
|
1038
|
-
* @returns {boolean}
|
|
1039
|
-
*/
|
|
1040
|
-
hasParseResult(file) {
|
|
1041
|
-
return this.#parsed.has(file);
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* get parsed tsconfig for file
|
|
1045
|
-
* @param {string} file
|
|
1046
|
-
* @returns {Promise<T>|T}
|
|
1047
|
-
* @throws {unknown} if cached value is an error
|
|
1048
|
-
*/
|
|
1049
|
-
getParseResult(file) {
|
|
1050
|
-
const value = this.#parsed.get(file);
|
|
1051
|
-
if (value.then || value.tsconfig) return value;
|
|
1052
|
-
else throw value;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* @internal
|
|
1056
|
-
* @private
|
|
1057
|
-
* @param file
|
|
1058
|
-
* @param {boolean} isRootFile a flag to check if current file which involking the parse() api, used to distinguish the normal cache which only parsed by parseFile()
|
|
1059
|
-
* @param {Promise<T>} result
|
|
1060
|
-
*/
|
|
1061
|
-
setParseResult(file, result, isRootFile = false) {
|
|
1062
|
-
Object.defineProperty(result, "_isRootFile_", {
|
|
1063
|
-
value: isRootFile,
|
|
1064
|
-
writable: false,
|
|
1065
|
-
enumerable: false,
|
|
1066
|
-
configurable: false
|
|
1067
|
-
});
|
|
1068
|
-
this.#parsed.set(file, result);
|
|
1069
|
-
result.then((parsed) => {
|
|
1070
|
-
if (this.#parsed.get(file) === result) this.#parsed.set(file, parsed);
|
|
1071
|
-
}).catch((e) => {
|
|
1072
|
-
if (this.#parsed.get(file) === result) this.#parsed.set(file, e);
|
|
1073
|
-
});
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* @internal
|
|
1077
|
-
* @private
|
|
1078
|
-
* @param {string} dir
|
|
1079
|
-
* @param {Promise<string|null>} configPath
|
|
1080
|
-
* @param {string} [configName=tsconfig.json]
|
|
1081
|
-
*/
|
|
1082
|
-
setConfigPath(dir, configPath, configName = "tsconfig.json") {
|
|
1083
|
-
const key = `${dir}/${configName}`;
|
|
1084
|
-
this.#configPaths.set(key, configPath);
|
|
1085
|
-
configPath.then((path$1) => {
|
|
1086
|
-
if (this.#configPaths.get(key) === configPath) this.#configPaths.set(key, path$1);
|
|
1087
|
-
}).catch((e) => {
|
|
1088
|
-
if (this.#configPaths.get(key) === configPath) this.#configPaths.set(key, e);
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* map directories to their closest tsconfig.json
|
|
1093
|
-
* @internal
|
|
1094
|
-
* @private
|
|
1095
|
-
* @type{Map<string,(Promise<string|null>|string|null)>}
|
|
1096
|
-
*/
|
|
1097
|
-
#configPaths = /* @__PURE__ */ new Map();
|
|
1098
|
-
/**
|
|
1099
|
-
* map files to their parsed tsconfig result
|
|
1100
|
-
* @internal
|
|
1101
|
-
* @private
|
|
1102
|
-
* @type {Map<string,(Promise<T>|T)> }
|
|
1103
|
-
*/
|
|
1104
|
-
#parsed = /* @__PURE__ */ new Map();
|
|
1105
|
-
};
|
|
1106
|
-
|
|
1107
|
-
//#endregion
|
|
1108
|
-
//#region src/config/resolvers/tsconfig.ts
|
|
1109
|
-
async function resolveTsconfig(options) {
|
|
1110
|
-
const root = resolve$1(options.rootDir || ".") + "/";
|
|
1111
|
-
if (!options.typescript.tsConfig) options.typescript.tsConfig = await loadTsconfig(root);
|
|
1112
|
-
if (options.experimental.tsconfigPaths && options.typescript.tsConfig.compilerOptions?.paths) options.alias = {
|
|
1113
|
-
...tsConfigToAliasObj(options.typescript.tsConfig, root),
|
|
1114
|
-
...options.alias
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
async function loadTsconfig(root) {
|
|
1118
|
-
const opts = {
|
|
1119
|
-
root,
|
|
1120
|
-
cache: loadTsconfig["__cache"] ??= new TSConfckCache(),
|
|
1121
|
-
ignoreNodeModules: true
|
|
1122
|
-
};
|
|
1123
|
-
const tsConfigPath = join$1(root, "tsconfig.json");
|
|
1124
|
-
const parsed = await parse(tsConfigPath, opts).catch(() => void 0);
|
|
1125
|
-
if (!parsed) return {};
|
|
1126
|
-
const { tsconfig, tsconfigFile } = parsed;
|
|
1127
|
-
tsconfig.compilerOptions ??= {};
|
|
1128
|
-
if (!tsconfig.compilerOptions.baseUrl) tsconfig.compilerOptions.baseUrl = resolve$1(tsconfigFile, "..");
|
|
1129
|
-
return tsconfig;
|
|
1130
|
-
}
|
|
1131
|
-
function tsConfigToAliasObj(tsconfig, root) {
|
|
1132
|
-
const compilerOptions = tsconfig?.compilerOptions;
|
|
1133
|
-
if (!compilerOptions?.paths) return {};
|
|
1134
|
-
const paths = compilerOptions.paths;
|
|
1135
|
-
const alias = {};
|
|
1136
|
-
for (const [key, targets] of Object.entries(paths)) {
|
|
1137
|
-
let source = key;
|
|
1138
|
-
let target = targets?.[0];
|
|
1139
|
-
if (!target) continue;
|
|
1140
|
-
if (source.includes("*") || target.includes("*")) {
|
|
1141
|
-
source = source.replace(/\/\*$/, "");
|
|
1142
|
-
target = target.replace(/\/\*$/, "");
|
|
1143
|
-
if (source.includes("*") || target.includes("*")) continue;
|
|
1144
|
-
}
|
|
1145
|
-
if (target.startsWith(".")) {
|
|
1146
|
-
if (!compilerOptions.baseUrl) continue;
|
|
1147
|
-
target = resolve$1(root, compilerOptions.baseUrl, target) + (key.endsWith("*") ? "/" : "");
|
|
1148
|
-
}
|
|
1149
|
-
alias[source] = target;
|
|
1150
|
-
}
|
|
1151
|
-
return alias;
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
//#endregion
|
|
1155
|
-
//#region src/config/resolvers/paths.ts
|
|
1156
|
-
const RESOLVE_EXTENSIONS = [
|
|
1157
|
-
".ts",
|
|
1158
|
-
".js",
|
|
1159
|
-
".mts",
|
|
1160
|
-
".mjs",
|
|
1161
|
-
".tsx",
|
|
1162
|
-
".jsx"
|
|
1163
|
-
];
|
|
1164
|
-
async function resolvePathOptions(options) {
|
|
1165
|
-
options.rootDir = resolve$1(options.rootDir || ".") + "/";
|
|
1166
|
-
options.buildDir = resolve$1(options.rootDir, options.buildDir || ".") + "/";
|
|
1167
|
-
options.workspaceDir ||= await findWorkspaceDir(options.rootDir).catch(() => options.rootDir) + "/";
|
|
1168
|
-
if (options.srcDir) {
|
|
1169
|
-
if (options.serverDir === void 0) options.serverDir = options.srcDir;
|
|
1170
|
-
consola$1.warn(`"srcDir" option is deprecated. Please use "serverDir" instead.`);
|
|
1171
|
-
}
|
|
1172
|
-
if (options.serverDir !== false) {
|
|
1173
|
-
if (options.serverDir === true) options.serverDir = "server";
|
|
1174
|
-
options.serverDir = resolve$1(options.rootDir, options.serverDir || ".") + "/";
|
|
1175
|
-
}
|
|
1176
|
-
options.alias ??= {};
|
|
1177
|
-
if (!options.static && !options.entry) throw new Error(`Nitro entry is missing! Is "${options.preset}" preset correct?`);
|
|
1178
|
-
if (options.entry) options.entry = resolveNitroPath(options.entry, options);
|
|
1179
|
-
options.output.dir = resolveNitroPath(options.output.dir || NitroDefaults.output.dir, options, options.rootDir) + "/";
|
|
1180
|
-
options.output.publicDir = resolveNitroPath(options.output.publicDir || NitroDefaults.output.publicDir, options, options.rootDir) + "/";
|
|
1181
|
-
options.output.serverDir = resolveNitroPath(options.output.serverDir || NitroDefaults.output.serverDir, options, options.rootDir) + "/";
|
|
1182
|
-
options.plugins = options.plugins.map((p$1) => resolveNitroPath(p$1, options));
|
|
1183
|
-
if (options.serverDir) options.scanDirs.unshift(options.serverDir);
|
|
1184
|
-
options.scanDirs = options.scanDirs.map((dir) => resolve$1(options.rootDir, dir));
|
|
1185
|
-
options.scanDirs = [...new Set(options.scanDirs.map((dir) => dir + "/"))];
|
|
1186
|
-
options.handlers = options.handlers.map((h) => {
|
|
1187
|
-
return {
|
|
1188
|
-
...h,
|
|
1189
|
-
handler: resolveNitroPath(h.handler, options)
|
|
1190
|
-
};
|
|
1191
|
-
});
|
|
1192
|
-
options.routes = Object.fromEntries(Object.entries(options.routes).map(([route, h]) => {
|
|
1193
|
-
if (typeof h === "string") h = { handler: h };
|
|
1194
|
-
h.handler = resolveNitroPath(h.handler, options);
|
|
1195
|
-
return [route, h];
|
|
1196
|
-
}));
|
|
1197
|
-
if (options.serverEntry !== false) {
|
|
1198
|
-
if (typeof options?.serverEntry === "string") options.serverEntry = { handler: options.serverEntry };
|
|
1199
|
-
if (options.serverEntry?.handler) options.serverEntry.handler = resolveNitroPath(options.serverEntry.handler, options);
|
|
1200
|
-
else {
|
|
1201
|
-
const detected = resolveModulePath("./server", {
|
|
1202
|
-
try: true,
|
|
1203
|
-
from: options.rootDir,
|
|
1204
|
-
extensions: RESOLVE_EXTENSIONS.flatMap((ext) => [ext, `.node${ext}`])
|
|
1205
|
-
});
|
|
1206
|
-
if (detected) {
|
|
1207
|
-
options.serverEntry ??= { handler: "" };
|
|
1208
|
-
options.serverEntry.handler = detected;
|
|
1209
|
-
consola$1.info(`Detected \`${prettyPath(detected)}\` as server entry.`);
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
if (options.serverEntry?.handler && !options.serverEntry?.format) {
|
|
1213
|
-
const isNode = /\.(node)\.\w+$/.test(options.serverEntry.handler);
|
|
1214
|
-
options.serverEntry.format = isNode ? "node" : "web";
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
if (options.renderer === false) options.renderer = void 0;
|
|
1218
|
-
else {
|
|
1219
|
-
if (options.renderer?.handler) options.renderer.handler = resolveModulePath(resolveNitroPath(options.renderer?.handler, options), {
|
|
1220
|
-
from: [options.rootDir, ...options.scanDirs],
|
|
1221
|
-
extensions: RESOLVE_EXTENSIONS
|
|
1222
|
-
});
|
|
1223
|
-
if (options.renderer?.template) options.renderer.template = resolveModulePath(resolveNitroPath(options.renderer?.template, options), {
|
|
1224
|
-
from: [options.rootDir, ...options.scanDirs],
|
|
1225
|
-
extensions: [".html"]
|
|
1226
|
-
});
|
|
1227
|
-
else if (!options.renderer?.handler) {
|
|
1228
|
-
const defaultIndex = resolveModulePath("./index.html", {
|
|
1229
|
-
from: [options.rootDir, ...options.scanDirs],
|
|
1230
|
-
extensions: [".html"],
|
|
1231
|
-
try: true
|
|
1232
|
-
});
|
|
1233
|
-
if (defaultIndex) {
|
|
1234
|
-
options.renderer ??= {};
|
|
1235
|
-
options.renderer.template = defaultIndex;
|
|
1236
|
-
consola$1.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
if (options.renderer?.template && !options.renderer?.handler) {
|
|
1240
|
-
options.renderer ??= {};
|
|
1241
|
-
options.renderer.handler = join$1(runtimeDir, "internal/routes/renderer-template" + (options.dev ? ".dev" : ""));
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
//#endregion
|
|
1247
|
-
//#region src/config/resolvers/route-rules.ts
|
|
1248
|
-
async function resolveRouteRulesOptions(options) {
|
|
1249
|
-
options.routeRules = normalizeRouteRules(options);
|
|
1250
|
-
}
|
|
1251
|
-
function normalizeRouteRules(config) {
|
|
1252
|
-
const normalizedRules = {};
|
|
1253
|
-
for (let path$1 in config.routeRules) {
|
|
1254
|
-
const routeConfig = config.routeRules[path$1];
|
|
1255
|
-
path$1 = withLeadingSlash(path$1);
|
|
1256
|
-
const routeRules = {
|
|
1257
|
-
...routeConfig,
|
|
1258
|
-
redirect: void 0,
|
|
1259
|
-
proxy: void 0
|
|
1260
|
-
};
|
|
1261
|
-
if (routeConfig.redirect) {
|
|
1262
|
-
routeRules.redirect = {
|
|
1263
|
-
to: "/",
|
|
1264
|
-
status: 307,
|
|
1265
|
-
...typeof routeConfig.redirect === "string" ? { to: routeConfig.redirect } : routeConfig.redirect
|
|
1266
|
-
};
|
|
1267
|
-
if (path$1.endsWith("/**")) routeRules.redirect._redirectStripBase = path$1.slice(0, -3);
|
|
1268
|
-
}
|
|
1269
|
-
if (routeConfig.proxy) {
|
|
1270
|
-
routeRules.proxy = typeof routeConfig.proxy === "string" ? { to: routeConfig.proxy } : routeConfig.proxy;
|
|
1271
|
-
if (path$1.endsWith("/**")) routeRules.proxy._proxyStripBase = path$1.slice(0, -3);
|
|
1272
|
-
}
|
|
1273
|
-
if (routeConfig.cors) routeRules.headers = {
|
|
1274
|
-
"access-control-allow-origin": "*",
|
|
1275
|
-
"access-control-allow-methods": "*",
|
|
1276
|
-
"access-control-allow-headers": "*",
|
|
1277
|
-
"access-control-max-age": "0",
|
|
1278
|
-
...routeRules.headers
|
|
1279
|
-
};
|
|
1280
|
-
if (routeConfig.swr) {
|
|
1281
|
-
routeRules.cache = routeRules.cache || {};
|
|
1282
|
-
routeRules.cache.swr = true;
|
|
1283
|
-
if (typeof routeConfig.swr === "number") routeRules.cache.maxAge = routeConfig.swr;
|
|
1284
|
-
}
|
|
1285
|
-
if (routeConfig.cache === false) routeRules.cache = false;
|
|
1286
|
-
normalizedRules[path$1] = routeRules;
|
|
1287
|
-
}
|
|
1288
|
-
return normalizedRules;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
//#endregion
|
|
1292
|
-
//#region src/config/resolvers/runtime-config.ts
|
|
1293
|
-
async function resolveRuntimeConfigOptions(options) {
|
|
1294
|
-
options.runtimeConfig = normalizeRuntimeConfig(options);
|
|
1295
|
-
}
|
|
1296
|
-
function normalizeRuntimeConfig(config) {
|
|
1297
|
-
provideFallbackValues(config.runtimeConfig || {});
|
|
1298
|
-
const runtimeConfig = defu(config.runtimeConfig, {
|
|
1299
|
-
app: { baseURL: config.baseURL },
|
|
1300
|
-
nitro: {
|
|
1301
|
-
envExpansion: config.experimental?.envExpansion,
|
|
1302
|
-
openAPI: config.openAPI
|
|
1303
|
-
}
|
|
1304
|
-
});
|
|
1305
|
-
runtimeConfig.nitro ??= {};
|
|
1306
|
-
runtimeConfig.nitro.routeRules = config.routeRules;
|
|
1307
|
-
checkSerializableRuntimeConfig(runtimeConfig);
|
|
1308
|
-
return runtimeConfig;
|
|
1309
|
-
}
|
|
1310
|
-
function provideFallbackValues(obj) {
|
|
1311
|
-
for (const key in obj) if (obj[key] === void 0 || obj[key] === null) obj[key] = "";
|
|
1312
|
-
else if (typeof obj[key] === "object") provideFallbackValues(obj[key]);
|
|
1313
|
-
}
|
|
1314
|
-
function checkSerializableRuntimeConfig(obj, path$1 = []) {
|
|
1315
|
-
if (isPrimitiveValue(obj)) return;
|
|
1316
|
-
for (const key in obj) {
|
|
1317
|
-
const value = obj[key];
|
|
1318
|
-
if (value === null || value === void 0 || isPrimitiveValue(value)) continue;
|
|
1319
|
-
if (Array.isArray(value)) for (const [index, item] of value.entries()) checkSerializableRuntimeConfig(item, [...path$1, `${key}[${index}]`]);
|
|
1320
|
-
else if (typeof value === "object" && value.constructor === Object && (!value.constructor?.name || value.constructor.name === "Object")) checkSerializableRuntimeConfig(value, [...path$1, key]);
|
|
1321
|
-
else console.warn(`Runtime config option \`${[...path$1, key].join(".")}\` may not be able to be serialized.`);
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
function isPrimitiveValue(value) {
|
|
1325
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
//#endregion
|
|
1329
|
-
//#region src/config/resolvers/storage.ts
|
|
1330
|
-
async function resolveStorageOptions(options) {}
|
|
1331
|
-
|
|
1332
|
-
//#endregion
|
|
1333
|
-
//#region src/config/resolvers/url.ts
|
|
1334
|
-
async function resolveURLOptions(options) {
|
|
1335
|
-
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
//#endregion
|
|
1339
|
-
//#region src/config/resolvers/error.ts
|
|
1340
|
-
async function resolveErrorOptions(options) {
|
|
1341
|
-
if (!options.errorHandler) options.errorHandler = [];
|
|
1342
|
-
else if (!Array.isArray(options.errorHandler)) options.errorHandler = [options.errorHandler];
|
|
1343
|
-
options.errorHandler = options.errorHandler.map((h) => resolveNitroPath(h, options));
|
|
1344
|
-
options.errorHandler.push(join$1(runtimeDir, `internal/error/${options.dev ? "dev" : "prod"}`));
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
//#endregion
|
|
1348
|
-
//#region src/config/resolvers/unenv.ts
|
|
1349
|
-
const common = {
|
|
1350
|
-
meta: {
|
|
1351
|
-
name: "nitro-common",
|
|
1352
|
-
url: import.meta.url
|
|
1353
|
-
},
|
|
1354
|
-
alias: {
|
|
1355
|
-
"buffer/": "node:buffer",
|
|
1356
|
-
"buffer/index": "node:buffer",
|
|
1357
|
-
"buffer/index.js": "node:buffer",
|
|
1358
|
-
"string_decoder/": "node:string_decoder",
|
|
1359
|
-
"process/": "node:process"
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
const nodeless = {
|
|
1363
|
-
meta: {
|
|
1364
|
-
name: "nitro-nodeless",
|
|
1365
|
-
url: import.meta.url
|
|
1366
|
-
},
|
|
1367
|
-
inject: {
|
|
1368
|
-
global: "unenv/polyfill/globalthis",
|
|
1369
|
-
process: "node:process",
|
|
1370
|
-
Buffer: ["node:buffer", "Buffer"],
|
|
1371
|
-
clearImmediate: ["node:timers", "clearImmediate"],
|
|
1372
|
-
setImmediate: ["node:timers", "setImmediate"],
|
|
1373
|
-
performance: "unenv/polyfill/performance",
|
|
1374
|
-
PerformanceObserver: ["node:perf_hooks", "PerformanceObserver"],
|
|
1375
|
-
BroadcastChannel: ["node:worker_threads", "BroadcastChannel"]
|
|
1376
|
-
},
|
|
1377
|
-
polyfill: [
|
|
1378
|
-
"unenv/polyfill/globalthis-global",
|
|
1379
|
-
"unenv/polyfill/process",
|
|
1380
|
-
"unenv/polyfill/buffer",
|
|
1381
|
-
"unenv/polyfill/timers"
|
|
1382
|
-
]
|
|
1383
|
-
};
|
|
1384
|
-
async function resolveUnenv(options) {
|
|
1385
|
-
options.unenv ??= [];
|
|
1386
|
-
if (!Array.isArray(options.unenv)) options.unenv = [options.unenv];
|
|
1387
|
-
options.unenv = options.unenv.filter(Boolean);
|
|
1388
|
-
if (!options.node) options.unenv.unshift(nodeless);
|
|
1389
|
-
options.unenv.unshift(common);
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
//#endregion
|
|
1393
|
-
//#region src/config/resolvers/builder.ts
|
|
1394
|
-
const VALID_BUILDERS = [
|
|
1395
|
-
"rolldown",
|
|
1396
|
-
"rollup",
|
|
1397
|
-
"vite"
|
|
1398
|
-
];
|
|
1399
|
-
async function resolveBuilder(options) {
|
|
1400
|
-
options.builder ??= process.env.NITRO_BUILDER;
|
|
1401
|
-
if (options.builder) {
|
|
1402
|
-
if (!VALID_BUILDERS.includes(options.builder)) throw new Error(`Invalid nitro builder "${options.builder}". Valid builders are: ${VALID_BUILDERS.join(", ")}.`);
|
|
1403
|
-
const pkg = options.builder;
|
|
1404
|
-
if (!isPkgInstalled(pkg, options.rootDir)) {
|
|
1405
|
-
if (!await consola$1.prompt(`Nitro builder package \`${pkg}\` is not installed. Would you like to install it?`, {
|
|
1406
|
-
type: "confirm",
|
|
1407
|
-
default: true,
|
|
1408
|
-
cancel: "null"
|
|
1409
|
-
})) throw new Error(`Nitro builder package "${options.builder}" is not installed. Please install it in your project dependencies.`);
|
|
1410
|
-
await installPkg(pkg, options.rootDir);
|
|
1411
|
-
}
|
|
1412
|
-
return;
|
|
1413
|
-
}
|
|
1414
|
-
for (const pkg of [
|
|
1415
|
-
"rolldown",
|
|
1416
|
-
"rollup",
|
|
1417
|
-
"vite"
|
|
1418
|
-
]) if (isPkgInstalled(pkg, options.rootDir)) {
|
|
1419
|
-
options.builder = pkg;
|
|
1420
|
-
return;
|
|
1421
|
-
}
|
|
1422
|
-
const pkgToInstall = await consola$1.prompt(`No nitro builder specified. Which builder would you like to install?`, {
|
|
1423
|
-
type: "select",
|
|
1424
|
-
cancel: "null",
|
|
1425
|
-
options: VALID_BUILDERS.map((b$1) => ({
|
|
1426
|
-
label: b$1,
|
|
1427
|
-
value: b$1
|
|
1428
|
-
}))
|
|
1429
|
-
});
|
|
1430
|
-
if (!pkgToInstall) throw new Error(`No nitro builder specified. Please install one of the following packages: ${VALID_BUILDERS.join(", ")} and set it as the builder in your nitro config or via the NITRO_BUILDER environment variable.`);
|
|
1431
|
-
await installPkg(pkgToInstall, options.rootDir);
|
|
1432
|
-
options.builder = pkgToInstall;
|
|
1433
|
-
}
|
|
1434
|
-
const require = createRequire(process.cwd() + "/_index.js");
|
|
1435
|
-
function isPkgInstalled(pkg, root) {
|
|
1436
|
-
try {
|
|
1437
|
-
require.resolve(pkg, { paths: [root] });
|
|
1438
|
-
return true;
|
|
1439
|
-
} catch {
|
|
1440
|
-
return false;
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
async function installPkg(pkg, root) {
|
|
1444
|
-
const { addDevDependency } = await import("../_libs/nypm+tinyexec.mjs");
|
|
1445
|
-
return addDevDependency(pkg, { cwd: root });
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
//#endregion
|
|
1449
|
-
//#region src/config/loader.ts
|
|
1450
|
-
const configResolvers = [
|
|
1451
|
-
resolveCompatibilityOptions,
|
|
1452
|
-
resolveTsconfig,
|
|
1453
|
-
resolvePathOptions,
|
|
1454
|
-
resolveImportsOptions,
|
|
1455
|
-
resolveRouteRulesOptions,
|
|
1456
|
-
resolveDatabaseOptions,
|
|
1457
|
-
resolveExportConditionsOptions,
|
|
1458
|
-
resolveRuntimeConfigOptions,
|
|
1459
|
-
resolveOpenAPIOptions,
|
|
1460
|
-
resolveURLOptions,
|
|
1461
|
-
resolveAssetsOptions,
|
|
1462
|
-
resolveStorageOptions,
|
|
1463
|
-
resolveErrorOptions,
|
|
1464
|
-
resolveUnenv,
|
|
1465
|
-
resolveBuilder
|
|
1466
|
-
];
|
|
1467
|
-
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
1468
|
-
const options = await _loadUserConfig(configOverrides, opts);
|
|
1469
|
-
for (const resolver of configResolvers) await resolver(options);
|
|
1470
|
-
return options;
|
|
1471
|
-
}
|
|
1472
|
-
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
1473
|
-
configOverrides = klona(configOverrides);
|
|
1474
|
-
globalThis.defineNitroConfig = globalThis.defineNitroConfig || ((c) => c);
|
|
1475
|
-
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || process.env.NITRO_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE;
|
|
1476
|
-
const { resolvePreset } = await import("../_presets.mjs");
|
|
1477
|
-
let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
|
|
1478
|
-
const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
|
|
1479
|
-
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
1480
|
-
name: "nitro",
|
|
1481
|
-
cwd: configOverrides.rootDir,
|
|
1482
|
-
dotenv: _dotenv,
|
|
1483
|
-
extend: { extendKey: ["extends", "preset"] },
|
|
1484
|
-
defaults: NitroDefaults,
|
|
1485
|
-
jitiOptions: { alias: {
|
|
1486
|
-
nitropack: "nitro/config",
|
|
1487
|
-
"nitro/config": "nitro/config"
|
|
1488
|
-
} },
|
|
1489
|
-
async overrides({ rawConfigs }) {
|
|
1490
|
-
const getConf = (key) => configOverrides[key] ?? rawConfigs.main?.[key] ?? rawConfigs.rc?.[key] ?? rawConfigs.packageJson?.[key];
|
|
1491
|
-
if (!compatibilityDate) compatibilityDate = getConf("compatibilityDate");
|
|
1492
|
-
const framework = getConf("framework");
|
|
1493
|
-
const isCustomFramework = framework?.name && framework.name !== "nitro";
|
|
1494
|
-
if (!preset) preset = getConf("preset");
|
|
1495
|
-
if (configOverrides.dev) preset = preset && preset !== "nitro-dev" ? await resolvePreset(preset, {
|
|
1496
|
-
static: getConf("static"),
|
|
1497
|
-
dev: true,
|
|
1498
|
-
compatibilityDate: compatibilityDate || "latest"
|
|
1499
|
-
}).then((p$1) => p$1?._meta?.name || "nitro-dev").catch(() => "nitro-dev") : "nitro-dev";
|
|
1500
|
-
else if (!preset) preset = await resolvePreset("", {
|
|
1501
|
-
static: getConf("static"),
|
|
1502
|
-
dev: false,
|
|
1503
|
-
compatibilityDate: compatibilityDate || "latest"
|
|
1504
|
-
}).then((p$1) => p$1?._meta?.name);
|
|
1505
|
-
return {
|
|
1506
|
-
...configOverrides,
|
|
1507
|
-
preset,
|
|
1508
|
-
typescript: {
|
|
1509
|
-
generateRuntimeConfigTypes: !isCustomFramework,
|
|
1510
|
-
...getConf("typescript"),
|
|
1511
|
-
...configOverrides.typescript
|
|
1512
|
-
}
|
|
1513
|
-
};
|
|
1514
|
-
},
|
|
1515
|
-
async resolve(id) {
|
|
1516
|
-
const preset$1 = await resolvePreset(id, {
|
|
1517
|
-
static: configOverrides.static,
|
|
1518
|
-
compatibilityDate: compatibilityDate || "latest",
|
|
1519
|
-
dev: configOverrides.dev
|
|
1520
|
-
});
|
|
1521
|
-
if (preset$1) return { config: klona(preset$1) };
|
|
1522
|
-
},
|
|
1523
|
-
...opts.c12
|
|
1524
|
-
});
|
|
1525
|
-
const options = klona(loadedConfig.config);
|
|
1526
|
-
options._config = configOverrides;
|
|
1527
|
-
options._c12 = loadedConfig;
|
|
1528
|
-
options.preset = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || preset;
|
|
1529
|
-
options.compatibilityDate = resolveCompatibilityDates(compatibilityDate, options.compatibilityDate);
|
|
1530
|
-
if (options.dev && options.preset !== "nitro-dev") consola$1.info(`Using \`${options.preset}\` emulation in development mode.`);
|
|
1531
|
-
return options;
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
//#endregion
|
|
1535
|
-
//#region src/config/update.ts
|
|
1536
|
-
async function updateNitroConfig(nitro, config) {
|
|
1537
|
-
nitro.options.routeRules = normalizeRouteRules(config.routeRules ? config : nitro.options);
|
|
1538
|
-
nitro.options.runtimeConfig = normalizeRuntimeConfig(config.runtimeConfig ? config : nitro.options);
|
|
1539
|
-
await nitro.hooks.callHook("rollup:reload");
|
|
1540
|
-
consola$1.success("Nitro config hot reloaded!");
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
//#endregion
|
|
1544
|
-
//#region src/module.ts
|
|
1545
|
-
async function installModules(nitro) {
|
|
1546
|
-
const _modules = [...nitro.options.modules || []];
|
|
1547
|
-
const modules = await Promise.all(_modules.map((mod) => _resolveNitroModule(mod, nitro.options)));
|
|
1548
|
-
const _installedURLs = /* @__PURE__ */ new Set();
|
|
1549
|
-
for (const mod of modules) {
|
|
1550
|
-
if (mod._url) {
|
|
1551
|
-
if (_installedURLs.has(mod._url)) continue;
|
|
1552
|
-
_installedURLs.add(mod._url);
|
|
1553
|
-
}
|
|
1554
|
-
await mod.setup(nitro);
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
async function _resolveNitroModule(mod, nitroOptions) {
|
|
1558
|
-
let _url;
|
|
1559
|
-
if (typeof mod === "string") mod = await import(resolveModuleURL(mod, {
|
|
1560
|
-
from: [nitroOptions.rootDir],
|
|
1561
|
-
extensions: [
|
|
1562
|
-
".mjs",
|
|
1563
|
-
".cjs",
|
|
1564
|
-
".js",
|
|
1565
|
-
".mts",
|
|
1566
|
-
".cts",
|
|
1567
|
-
".ts"
|
|
1568
|
-
]
|
|
1569
|
-
})).then((m) => m.default || m);
|
|
1570
|
-
if (typeof mod === "function") mod = { setup: mod };
|
|
1571
|
-
if ("nitro" in mod) mod = mod.nitro;
|
|
1572
|
-
if (!mod.setup) throw new Error("Invalid Nitro module: missing setup() function.");
|
|
1573
|
-
return {
|
|
1574
|
-
_url,
|
|
1575
|
-
...mod
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
//#endregion
|
|
1580
|
-
//#region node_modules/.pnpm/rou3@0.7.12/node_modules/rou3/dist/index.mjs
|
|
1581
|
-
const NullProtoObj = /* @__PURE__ */ (() => {
|
|
1582
|
-
const e = function() {};
|
|
1583
|
-
return e.prototype = Object.create(null), Object.freeze(e.prototype), e;
|
|
1584
|
-
})();
|
|
1585
|
-
/**
|
|
1586
|
-
* Create a new router context.
|
|
1587
|
-
*/
|
|
1588
|
-
function createRouter() {
|
|
1589
|
-
return {
|
|
1590
|
-
root: { key: "" },
|
|
1591
|
-
static: new NullProtoObj()
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
function splitPath(path$1) {
|
|
1595
|
-
const [_, ...s] = path$1.split("/");
|
|
1596
|
-
return s[s.length - 1] === "" ? s.slice(0, -1) : s;
|
|
1597
|
-
}
|
|
1598
|
-
function getMatchParams(segments, paramsMap) {
|
|
1599
|
-
const params = new NullProtoObj();
|
|
1600
|
-
for (const [index, name] of paramsMap) {
|
|
1601
|
-
const segment = index < 0 ? segments.slice(-(index + 1)).join("/") : segments[index];
|
|
1602
|
-
if (typeof name === "string") params[name] = segment;
|
|
1603
|
-
else {
|
|
1604
|
-
const match = segment.match(name);
|
|
1605
|
-
if (match) for (const key in match.groups) params[key] = match.groups[key];
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
return params;
|
|
1609
|
-
}
|
|
1610
|
-
/**
|
|
1611
|
-
* Add a route to the router context.
|
|
1612
|
-
*/
|
|
1613
|
-
function addRoute(ctx, method = "", path$1, data) {
|
|
1614
|
-
method = method.toUpperCase();
|
|
1615
|
-
if (path$1.charCodeAt(0) !== 47) path$1 = `/${path$1}`;
|
|
1616
|
-
path$1 = path$1.replace(/\\:/g, "%3A");
|
|
1617
|
-
const segments = splitPath(path$1);
|
|
1618
|
-
let node = ctx.root;
|
|
1619
|
-
let _unnamedParamIndex = 0;
|
|
1620
|
-
const paramsMap = [];
|
|
1621
|
-
const paramsRegexp = [];
|
|
1622
|
-
for (let i = 0; i < segments.length; i++) {
|
|
1623
|
-
let segment = segments[i];
|
|
1624
|
-
if (segment.startsWith("**")) {
|
|
1625
|
-
if (!node.wildcard) node.wildcard = { key: "**" };
|
|
1626
|
-
node = node.wildcard;
|
|
1627
|
-
paramsMap.push([
|
|
1628
|
-
-(i + 1),
|
|
1629
|
-
segment.split(":")[1] || "_",
|
|
1630
|
-
segment.length === 2
|
|
1631
|
-
]);
|
|
1632
|
-
break;
|
|
1633
|
-
}
|
|
1634
|
-
if (segment === "*" || segment.includes(":")) {
|
|
1635
|
-
if (!node.param) node.param = { key: "*" };
|
|
1636
|
-
node = node.param;
|
|
1637
|
-
if (segment === "*") paramsMap.push([
|
|
1638
|
-
i,
|
|
1639
|
-
`_${_unnamedParamIndex++}`,
|
|
1640
|
-
true
|
|
1641
|
-
]);
|
|
1642
|
-
else if (segment.includes(":", 1)) {
|
|
1643
|
-
const regexp = getParamRegexp(segment);
|
|
1644
|
-
paramsRegexp[i] = regexp;
|
|
1645
|
-
node.hasRegexParam = true;
|
|
1646
|
-
paramsMap.push([
|
|
1647
|
-
i,
|
|
1648
|
-
regexp,
|
|
1649
|
-
false
|
|
1650
|
-
]);
|
|
1651
|
-
} else paramsMap.push([
|
|
1652
|
-
i,
|
|
1653
|
-
segment.slice(1),
|
|
1654
|
-
false
|
|
1655
|
-
]);
|
|
1656
|
-
continue;
|
|
1657
|
-
}
|
|
1658
|
-
if (segment === "\\*") segment = segments[i] = "*";
|
|
1659
|
-
else if (segment === "\\*\\*") segment = segments[i] = "**";
|
|
1660
|
-
const child = node.static?.[segment];
|
|
1661
|
-
if (child) node = child;
|
|
1662
|
-
else {
|
|
1663
|
-
const staticNode = { key: segment };
|
|
1664
|
-
if (!node.static) node.static = new NullProtoObj();
|
|
1665
|
-
node.static[segment] = staticNode;
|
|
1666
|
-
node = staticNode;
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
const hasParams = paramsMap.length > 0;
|
|
1670
|
-
if (!node.methods) node.methods = new NullProtoObj();
|
|
1671
|
-
node.methods[method] ??= [];
|
|
1672
|
-
node.methods[method].push({
|
|
1673
|
-
data: data || null,
|
|
1674
|
-
paramsRegexp,
|
|
1675
|
-
paramsMap: hasParams ? paramsMap : void 0
|
|
1676
|
-
});
|
|
1677
|
-
if (!hasParams) ctx.static["/" + segments.join("/")] = node;
|
|
1678
|
-
}
|
|
1679
|
-
function getParamRegexp(segment) {
|
|
1680
|
-
const regex = segment.replace(/:(\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\./g, "\\.");
|
|
1681
|
-
return /* @__PURE__ */ new RegExp(`^${regex}$`);
|
|
1682
|
-
}
|
|
1683
|
-
/**
|
|
1684
|
-
* Find a route by path.
|
|
1685
|
-
*/
|
|
1686
|
-
function findRoute(ctx, method = "", path$1, opts) {
|
|
1687
|
-
if (path$1.charCodeAt(path$1.length - 1) === 47) path$1 = path$1.slice(0, -1);
|
|
1688
|
-
const staticNode = ctx.static[path$1];
|
|
1689
|
-
if (staticNode && staticNode.methods) {
|
|
1690
|
-
const staticMatch = staticNode.methods[method] || staticNode.methods[""];
|
|
1691
|
-
if (staticMatch !== void 0) return staticMatch[0];
|
|
1692
|
-
}
|
|
1693
|
-
const segments = splitPath(path$1);
|
|
1694
|
-
const match = _lookupTree(ctx, ctx.root, method, segments, 0)?.[0];
|
|
1695
|
-
if (match === void 0) return;
|
|
1696
|
-
if (opts?.params === false) return match;
|
|
1697
|
-
return {
|
|
1698
|
-
data: match.data,
|
|
1699
|
-
params: match.paramsMap ? getMatchParams(segments, match.paramsMap) : void 0
|
|
1700
|
-
};
|
|
1701
|
-
}
|
|
1702
|
-
function _lookupTree(ctx, node, method, segments, index) {
|
|
1703
|
-
if (index === segments.length) {
|
|
1704
|
-
if (node.methods) {
|
|
1705
|
-
const match = node.methods[method] || node.methods[""];
|
|
1706
|
-
if (match) return match;
|
|
1707
|
-
}
|
|
1708
|
-
if (node.param && node.param.methods) {
|
|
1709
|
-
const match = node.param.methods[method] || node.param.methods[""];
|
|
1710
|
-
if (match) {
|
|
1711
|
-
const pMap = match[0].paramsMap;
|
|
1712
|
-
if (pMap?.[pMap?.length - 1]?.[2]) return match;
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
if (node.wildcard && node.wildcard.methods) {
|
|
1716
|
-
const match = node.wildcard.methods[method] || node.wildcard.methods[""];
|
|
1717
|
-
if (match) {
|
|
1718
|
-
const pMap = match[0].paramsMap;
|
|
1719
|
-
if (pMap?.[pMap?.length - 1]?.[2]) return match;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
return;
|
|
1723
|
-
}
|
|
1724
|
-
const segment = segments[index];
|
|
1725
|
-
if (node.static) {
|
|
1726
|
-
const staticChild = node.static[segment];
|
|
1727
|
-
if (staticChild) {
|
|
1728
|
-
const match = _lookupTree(ctx, staticChild, method, segments, index + 1);
|
|
1729
|
-
if (match) return match;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
if (node.param) {
|
|
1733
|
-
const match = _lookupTree(ctx, node.param, method, segments, index + 1);
|
|
1734
|
-
if (match) {
|
|
1735
|
-
if (node.param.hasRegexParam) {
|
|
1736
|
-
const exactMatch = match.find((m) => m.paramsRegexp[index]?.test(segment)) || match.find((m) => !m.paramsRegexp[index]);
|
|
1737
|
-
return exactMatch ? [exactMatch] : void 0;
|
|
1738
|
-
}
|
|
1739
|
-
return match;
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
if (node.wildcard && node.wildcard.methods) return node.wildcard.methods[method] || node.wildcard.methods[""];
|
|
1743
|
-
}
|
|
1744
|
-
/**
|
|
1745
|
-
* Find all route patterns that match the given path.
|
|
1746
|
-
*/
|
|
1747
|
-
function findAllRoutes(ctx, method = "", path$1, opts) {
|
|
1748
|
-
if (path$1.charCodeAt(path$1.length - 1) === 47) path$1 = path$1.slice(0, -1);
|
|
1749
|
-
const segments = splitPath(path$1);
|
|
1750
|
-
const matches = _findAll(ctx, ctx.root, method, segments, 0);
|
|
1751
|
-
if (opts?.params === false) return matches;
|
|
1752
|
-
return matches.map((m) => {
|
|
1753
|
-
return {
|
|
1754
|
-
data: m.data,
|
|
1755
|
-
params: m.paramsMap ? getMatchParams(segments, m.paramsMap) : void 0
|
|
1756
|
-
};
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
function _findAll(ctx, node, method, segments, index, matches = []) {
|
|
1760
|
-
const segment = segments[index];
|
|
1761
|
-
if (node.wildcard && node.wildcard.methods) {
|
|
1762
|
-
const match = node.wildcard.methods[method] || node.wildcard.methods[""];
|
|
1763
|
-
if (match) matches.push(...match);
|
|
1764
|
-
}
|
|
1765
|
-
if (node.param) {
|
|
1766
|
-
_findAll(ctx, node.param, method, segments, index + 1, matches);
|
|
1767
|
-
if (index === segments.length && node.param.methods) {
|
|
1768
|
-
const match = node.param.methods[method] || node.param.methods[""];
|
|
1769
|
-
if (match) {
|
|
1770
|
-
const pMap = match[0].paramsMap;
|
|
1771
|
-
if (pMap?.[pMap?.length - 1]?.[2]) matches.push(...match);
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
const staticChild = node.static?.[segment];
|
|
1776
|
-
if (staticChild) _findAll(ctx, staticChild, method, segments, index + 1, matches);
|
|
1777
|
-
if (index === segments.length && node.methods) {
|
|
1778
|
-
const match = node.methods[method] || node.methods[""];
|
|
1779
|
-
if (match) matches.push(...match);
|
|
1780
|
-
}
|
|
1781
|
-
return matches;
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
//#endregion
|
|
1785
|
-
//#region node_modules/.pnpm/rou3@0.7.12/node_modules/rou3/dist/compiler.mjs
|
|
1786
|
-
/**
|
|
1787
|
-
* Compile the router instance into a compact runnable code.
|
|
1788
|
-
*
|
|
1789
|
-
* **IMPORTANT:** Route data must be serializable to JSON (i.e., no functions or classes) or implement the `toJSON()` method to render custom code or you can pass custom `serialize` function in options.
|
|
1790
|
-
*
|
|
1791
|
-
* @example
|
|
1792
|
-
* import { createRouter, addRoute } from "rou3";
|
|
1793
|
-
* import { compileRouterToString } from "rou3/compiler";
|
|
1794
|
-
* const router = createRouter();
|
|
1795
|
-
* // [add some routes with serializable data]
|
|
1796
|
-
* const compilerCode = compileRouterToString(router, "findRoute");
|
|
1797
|
-
* // "const findRoute=(m, p) => {}"
|
|
1798
|
-
*/
|
|
1799
|
-
function compileRouterToString(router, functionName, opts) {
|
|
1800
|
-
const ctx = {
|
|
1801
|
-
opts: opts || {},
|
|
1802
|
-
router,
|
|
1803
|
-
data: [],
|
|
1804
|
-
compileToString: true
|
|
1805
|
-
};
|
|
1806
|
-
let compiled = `(m,p)=>{${compileRouteMatch(ctx)}}`;
|
|
1807
|
-
if (ctx.data.length > 0) compiled = `/* @__PURE__ */ (() => { ${`const ${ctx.data.map((v, i) => `$${i}=${v}`).join(",")};`}; return ${compiled}})()`;
|
|
1808
|
-
return functionName ? `const ${functionName}=${compiled};` : compiled;
|
|
1809
|
-
}
|
|
1810
|
-
function compileRouteMatch(ctx) {
|
|
1811
|
-
let code = "";
|
|
1812
|
-
const staticNodes = /* @__PURE__ */ new Set();
|
|
1813
|
-
for (const key in ctx.router.static) {
|
|
1814
|
-
const node = ctx.router.static[key];
|
|
1815
|
-
if (node?.methods) {
|
|
1816
|
-
staticNodes.add(node);
|
|
1817
|
-
code += `if(p===${JSON.stringify(key.replace(/\/$/, "") || "/")}){${compileMethodMatch(ctx, node.methods, [], -1)}}`;
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
const match = compileNode(ctx, ctx.router.root, [], 0, staticNodes);
|
|
1821
|
-
if (match) code += `let s=p.split("/"),l=s.length-1;${match}`;
|
|
1822
|
-
if (!code) return ctx.opts?.matchAll ? `return [];` : "";
|
|
1823
|
-
return `${ctx.opts?.matchAll ? `let r=[];` : ""}if(p.charCodeAt(p.length-1)===47)p=p.slice(0,-1)||"/";${code}${ctx.opts?.matchAll ? "return r;" : ""}`;
|
|
1824
|
-
}
|
|
1825
|
-
function compileMethodMatch(ctx, methods, params, currentIdx) {
|
|
1826
|
-
let code = "";
|
|
1827
|
-
for (const key in methods) {
|
|
1828
|
-
const matchers = methods[key];
|
|
1829
|
-
if (matchers && matchers?.length > 0) {
|
|
1830
|
-
if (key !== "") code += `if(m==="${key}")${matchers.length > 1 ? "{" : ""}`;
|
|
1831
|
-
const _matchers = matchers.map((m) => compileFinalMatch(ctx, m, currentIdx, params)).sort((a$1, b$1) => b$1.weight - a$1.weight);
|
|
1832
|
-
for (const matcher of _matchers) code += matcher.code;
|
|
1833
|
-
if (key !== "") code += matchers.length > 1 ? "}" : "";
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
return code;
|
|
1837
|
-
}
|
|
1838
|
-
function compileFinalMatch(ctx, data, currentIdx, params) {
|
|
1839
|
-
let ret = `{data:${serializeData(ctx, data.data)}`;
|
|
1840
|
-
const conditions = [];
|
|
1841
|
-
const { paramsMap, paramsRegexp } = data;
|
|
1842
|
-
if (paramsMap && paramsMap.length > 0) {
|
|
1843
|
-
if (!paramsMap[paramsMap.length - 1][2] && currentIdx !== -1) conditions.push(`l>=${currentIdx}`);
|
|
1844
|
-
for (let i = 0; i < paramsRegexp.length; i++) {
|
|
1845
|
-
const regexp = paramsRegexp[i];
|
|
1846
|
-
if (!regexp) continue;
|
|
1847
|
-
conditions.push(`${regexp.toString()}.test(s[${i + 1}])`);
|
|
1848
|
-
}
|
|
1849
|
-
ret += ",params:{";
|
|
1850
|
-
for (let i = 0; i < paramsMap.length; i++) {
|
|
1851
|
-
const map = paramsMap[i];
|
|
1852
|
-
ret += typeof map[1] === "string" ? `${JSON.stringify(map[1])}:${params[i]},` : `...(${map[1].toString()}.exec(${params[i]}))?.groups,`;
|
|
1853
|
-
}
|
|
1854
|
-
ret += "}";
|
|
1855
|
-
}
|
|
1856
|
-
return {
|
|
1857
|
-
code: (conditions.length > 0 ? `if(${conditions.join("&&")})` : "") + (ctx.opts?.matchAll ? `r.unshift(${ret}});` : `return ${ret}};`),
|
|
1858
|
-
weight: conditions.length
|
|
1859
|
-
};
|
|
1860
|
-
}
|
|
1861
|
-
function compileNode(ctx, node, params, startIdx, staticNodes) {
|
|
1862
|
-
let code = "";
|
|
1863
|
-
if (node.methods && !staticNodes.has(node)) {
|
|
1864
|
-
const match = compileMethodMatch(ctx, node.methods, params, node.key === "*" ? startIdx : -1);
|
|
1865
|
-
if (match) {
|
|
1866
|
-
const hasLastOptionalParam = node.key === "*";
|
|
1867
|
-
code += `if(l===${startIdx}${hasLastOptionalParam ? `||l===${startIdx - 1}` : ""}){${match}}`;
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
if (node.static) for (const key in node.static) {
|
|
1871
|
-
const match = compileNode(ctx, node.static[key], params, startIdx + 1, staticNodes);
|
|
1872
|
-
if (match) code += `if(s[${startIdx + 1}]===${JSON.stringify(key)}){${match}}`;
|
|
1873
|
-
}
|
|
1874
|
-
if (node.param) {
|
|
1875
|
-
const match = compileNode(ctx, node.param, [...params, `s[${startIdx + 1}]`], startIdx + 1, staticNodes);
|
|
1876
|
-
if (match) code += match;
|
|
1877
|
-
}
|
|
1878
|
-
if (node.wildcard) {
|
|
1879
|
-
const { wildcard } = node;
|
|
1880
|
-
if (wildcard.static || wildcard.param || wildcard.wildcard) throw new Error("Compiler mode does not support patterns after wildcard");
|
|
1881
|
-
if (wildcard.methods) {
|
|
1882
|
-
const match = compileMethodMatch(ctx, wildcard.methods, [...params, `s.slice(${startIdx + 1}).join('/')`], startIdx);
|
|
1883
|
-
if (match) code += match;
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
return code;
|
|
1887
|
-
}
|
|
1888
|
-
function serializeData(ctx, value) {
|
|
1889
|
-
if (ctx.compileToString) if (ctx.opts?.serialize) value = ctx.opts.serialize(value);
|
|
1890
|
-
else if (typeof value?.toJSON === "function") value = value.toJSON();
|
|
1891
|
-
else value = JSON.stringify(value);
|
|
1892
|
-
let index = ctx.data.indexOf(value);
|
|
1893
|
-
if (index === -1) {
|
|
1894
|
-
ctx.data.push(value);
|
|
1895
|
-
index = ctx.data.length - 1;
|
|
1896
|
-
}
|
|
1897
|
-
return `$${index}`;
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
//#endregion
|
|
1901
|
-
//#region src/routing.ts
|
|
1902
|
-
const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
|
|
1903
|
-
function initNitroRouting(nitro) {
|
|
1904
|
-
const envConditions = new Set([
|
|
1905
|
-
nitro.options.dev ? "dev" : "prod",
|
|
1906
|
-
nitro.options.preset,
|
|
1907
|
-
nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
|
|
1908
|
-
].filter(Boolean));
|
|
1909
|
-
const matchesEnv = (h) => {
|
|
1910
|
-
const envs = (Array.isArray(h.env) ? h.env : [h.env]).filter(Boolean);
|
|
1911
|
-
return envs.length === 0 || envs.some((env) => envConditions.has(env));
|
|
1912
|
-
};
|
|
1913
|
-
const routes = new Router(nitro.options.baseURL);
|
|
1914
|
-
const routeRules = new Router(nitro.options.baseURL);
|
|
1915
|
-
const globalMiddleware = [];
|
|
1916
|
-
const routedMiddleware = new Router(nitro.options.baseURL);
|
|
1917
|
-
const sync = () => {
|
|
1918
|
-
routeRules._update(Object.entries(nitro.options.routeRules).map(([route, data]) => ({
|
|
1919
|
-
route,
|
|
1920
|
-
method: "",
|
|
1921
|
-
data: {
|
|
1922
|
-
...data,
|
|
1923
|
-
_route: route
|
|
1924
|
-
}
|
|
1925
|
-
})));
|
|
1926
|
-
const _routes = [
|
|
1927
|
-
...Object.entries(nitro.options.routes).flatMap(([route, handler]) => {
|
|
1928
|
-
if (typeof handler === "string") handler = { handler };
|
|
1929
|
-
return {
|
|
1930
|
-
...handler,
|
|
1931
|
-
route,
|
|
1932
|
-
middleware: false
|
|
1933
|
-
};
|
|
1934
|
-
}),
|
|
1935
|
-
...nitro.options.handlers,
|
|
1936
|
-
...nitro.scannedHandlers
|
|
1937
|
-
].filter((h) => h && !h.middleware && matchesEnv(h));
|
|
1938
|
-
if (nitro.options.serverEntry && nitro.options.serverEntry.handler) _routes.push({
|
|
1939
|
-
route: "/**",
|
|
1940
|
-
lazy: false,
|
|
1941
|
-
format: nitro.options.serverEntry.format,
|
|
1942
|
-
handler: nitro.options.serverEntry.handler
|
|
1943
|
-
});
|
|
1944
|
-
if (nitro.options.renderer?.handler) _routes.push({
|
|
1945
|
-
route: "/**",
|
|
1946
|
-
lazy: true,
|
|
1947
|
-
handler: nitro.options.renderer?.handler
|
|
1948
|
-
});
|
|
1949
|
-
routes._update(_routes.map((h) => ({
|
|
1950
|
-
...h,
|
|
1951
|
-
method: h.method || "",
|
|
1952
|
-
data: handlerWithImportHash(h)
|
|
1953
|
-
})), { merge: true });
|
|
1954
|
-
const _middleware = [...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => h && h.middleware && matchesEnv(h));
|
|
1955
|
-
if (nitro.options.serveStatic) _middleware.unshift({
|
|
1956
|
-
route: "/**",
|
|
1957
|
-
middleware: true,
|
|
1958
|
-
handler: join$1(runtimeDir, "internal/static")
|
|
1959
|
-
});
|
|
1960
|
-
globalMiddleware.splice(0, globalMiddleware.length, ..._middleware.filter((h) => isGlobalMiddleware(h)).map((m) => handlerWithImportHash(m)));
|
|
1961
|
-
routedMiddleware._update(_middleware.filter((h) => !isGlobalMiddleware(h)).map((h) => ({
|
|
1962
|
-
...h,
|
|
1963
|
-
method: h.method || "",
|
|
1964
|
-
data: handlerWithImportHash(h)
|
|
1965
|
-
})));
|
|
1966
|
-
};
|
|
1967
|
-
nitro.routing = Object.freeze({
|
|
1968
|
-
sync,
|
|
1969
|
-
routes,
|
|
1970
|
-
routeRules,
|
|
1971
|
-
globalMiddleware,
|
|
1972
|
-
routedMiddleware
|
|
1973
|
-
});
|
|
1974
|
-
}
|
|
1975
|
-
function handlerWithImportHash(h) {
|
|
1976
|
-
const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
|
|
1977
|
-
return {
|
|
1978
|
-
...h,
|
|
1979
|
-
_importHash: id
|
|
1980
|
-
};
|
|
1981
|
-
}
|
|
1982
|
-
var Router = class {
|
|
1983
|
-
_routes;
|
|
1984
|
-
_router;
|
|
1985
|
-
_compiled;
|
|
1986
|
-
_baseURL;
|
|
1987
|
-
constructor(baseURL) {
|
|
1988
|
-
this._update([]);
|
|
1989
|
-
this._baseURL = baseURL || "";
|
|
1990
|
-
if (this._baseURL.endsWith("/")) this._baseURL = this._baseURL.slice(0, -1);
|
|
1991
|
-
}
|
|
1992
|
-
get routes() {
|
|
1993
|
-
return this._routes;
|
|
1994
|
-
}
|
|
1995
|
-
_update(routes, opts) {
|
|
1996
|
-
this._routes = routes;
|
|
1997
|
-
this._router = createRouter();
|
|
1998
|
-
this._compiled = void 0;
|
|
1999
|
-
for (const route of routes) addRoute(this._router, route.method, this._baseURL + route.route, route.data);
|
|
2000
|
-
if (opts?.merge) mergeCatchAll(this._router);
|
|
2001
|
-
}
|
|
2002
|
-
hasRoutes() {
|
|
2003
|
-
return this._routes.length > 0;
|
|
2004
|
-
}
|
|
2005
|
-
compileToString(opts) {
|
|
2006
|
-
const key = opts ? hash(opts) : "";
|
|
2007
|
-
this._compiled ||= {};
|
|
2008
|
-
if (this._compiled[key]) return this._compiled[key];
|
|
2009
|
-
this._compiled[key] = compileRouterToString(this._router, void 0, opts);
|
|
2010
|
-
if (this.routes.length === 1 && this.routes[0].route === "/**" && this.routes[0].method === "") {
|
|
2011
|
-
const data = (opts?.serialize || JSON.stringify)(this.routes[0].data);
|
|
2012
|
-
let retCode = `{data,params:{"_":p.slice(1)}}`;
|
|
2013
|
-
if (opts?.matchAll) retCode = `[${retCode}]`;
|
|
2014
|
-
this._compiled[key] = `/* @__PURE__ */ (() => {const data=${data};return ((_m, p)=>{return ${retCode};})})()`;
|
|
2015
|
-
}
|
|
2016
|
-
return this._compiled[key];
|
|
2017
|
-
}
|
|
2018
|
-
match(method, path$1) {
|
|
2019
|
-
return findRoute(this._router, method, path$1)?.data;
|
|
2020
|
-
}
|
|
2021
|
-
matchAll(method, path$1) {
|
|
2022
|
-
return findAllRoutes(this._router, method, path$1).map((route) => route.data);
|
|
2023
|
-
}
|
|
2024
|
-
};
|
|
2025
|
-
function mergeCatchAll(router) {
|
|
2026
|
-
const handlers = router.root?.wildcard?.methods?.[""];
|
|
2027
|
-
if (!handlers || handlers.length < 2) return;
|
|
2028
|
-
handlers.splice(0, handlers.length, {
|
|
2029
|
-
...handlers[0],
|
|
2030
|
-
data: handlers.map((h) => h.data)
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
//#endregion
|
|
2035
|
-
//#region src/global.ts
|
|
2036
|
-
const nitroInstances = globalThis.__nitro_instances__ ||= [];
|
|
2037
|
-
const globalKey = "__nitro_builder__";
|
|
2038
|
-
function registerNitroInstance(nitro) {
|
|
2039
|
-
if (nitroInstances.includes(nitro)) return;
|
|
2040
|
-
globalInit();
|
|
2041
|
-
nitroInstances.unshift(nitro);
|
|
2042
|
-
nitro.hooks.hookOnce("close", () => {
|
|
2043
|
-
nitroInstances.splice(nitroInstances.indexOf(nitro), 1);
|
|
2044
|
-
if (nitroInstances.length === 0) delete globalThis[globalKey];
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
function globalInit() {
|
|
2048
|
-
if (globalThis[globalKey]) return;
|
|
2049
|
-
globalThis[globalKey] = { async fetch(req) {
|
|
2050
|
-
for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve$2) => setTimeout(resolve$2, 300));
|
|
2051
|
-
const nitro = nitroInstances[0];
|
|
2052
|
-
if (!nitro) throw new Error("No Nitro instance is running.");
|
|
2053
|
-
return nitro.fetch(req);
|
|
2054
|
-
} };
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
|
-
//#endregion
|
|
2058
|
-
//#region src/nitro.ts
|
|
2059
|
-
async function createNitro(config = {}, opts = {}) {
|
|
2060
|
-
const nitro = {
|
|
2061
|
-
options: await loadOptions(config, opts),
|
|
2062
|
-
hooks: new Hookable(),
|
|
2063
|
-
vfs: /* @__PURE__ */ new Map(),
|
|
2064
|
-
routing: {},
|
|
2065
|
-
logger: consola.withTag("nitro"),
|
|
2066
|
-
scannedHandlers: [],
|
|
2067
|
-
fetch: () => {
|
|
2068
|
-
throw new Error("no dev server attached!");
|
|
2069
|
-
},
|
|
2070
|
-
close: () => Promise.resolve(nitro.hooks.callHook("close")),
|
|
2071
|
-
async updateConfig(config$1) {
|
|
2072
|
-
updateNitroConfig(nitro, config$1);
|
|
2073
|
-
}
|
|
2074
|
-
};
|
|
2075
|
-
registerNitroInstance(nitro);
|
|
2076
|
-
initNitroRouting(nitro);
|
|
2077
|
-
await scanAndSyncOptions(nitro);
|
|
2078
|
-
if (nitro.options.debug) createDebugger(nitro.hooks, { tag: "nitro" });
|
|
2079
|
-
if (nitro.options.logLevel !== void 0) nitro.logger.level = nitro.options.logLevel;
|
|
2080
|
-
nitro.hooks.addHooks(nitro.options.hooks);
|
|
2081
|
-
await installModules(nitro);
|
|
2082
|
-
if (nitro.options.imports) {
|
|
2083
|
-
const { createUnimport } = await import("../_libs/_4.mjs");
|
|
2084
|
-
nitro.unimport = createUnimport(nitro.options.imports);
|
|
2085
|
-
await nitro.unimport.init();
|
|
2086
|
-
nitro.options.virtual["#imports"] = () => nitro.unimport?.toExports() || "";
|
|
2087
|
-
nitro.options.virtual["#nitro"] = "export * from \"#imports\"";
|
|
2088
|
-
}
|
|
2089
|
-
await scanHandlers(nitro);
|
|
2090
|
-
nitro.routing.sync();
|
|
2091
|
-
return nitro;
|
|
2092
|
-
}
|
|
2093
|
-
|
|
2094
|
-
//#endregion
|
|
2095
|
-
//#region src/build/build.ts
|
|
2096
|
-
async function build(nitro) {
|
|
2097
|
-
switch (nitro.options.builder) {
|
|
2098
|
-
case "rollup": {
|
|
2099
|
-
const { rollupBuild } = await import("./nitro8.mjs");
|
|
2100
|
-
return rollupBuild(nitro);
|
|
2101
|
-
}
|
|
2102
|
-
case "rolldown": {
|
|
2103
|
-
const { rolldownBuild } = await import("../_build/rolldown.mjs");
|
|
2104
|
-
return rolldownBuild(nitro);
|
|
2105
|
-
}
|
|
2106
|
-
case "vite": {
|
|
2107
|
-
const { viteBuild } = await import("../_build/vite.build.mjs");
|
|
2108
|
-
return viteBuild(nitro);
|
|
2109
|
-
}
|
|
2110
|
-
default: throw new Error(`Unknown builder: ${nitro.options.builder}`);
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
//#endregion
|
|
2115
|
-
//#region src/utils/compress.ts
|
|
2116
|
-
async function compressPublicAssets(nitro) {
|
|
2117
|
-
const publicFiles = await glob("**", {
|
|
2118
|
-
cwd: nitro.options.output.publicDir,
|
|
2119
|
-
absolute: false,
|
|
2120
|
-
dot: true,
|
|
2121
|
-
ignore: ["**/*.gz", "**/*.br"]
|
|
2122
|
-
});
|
|
2123
|
-
await Promise.all(publicFiles.map(async (fileName) => {
|
|
2124
|
-
const filePath = resolve$1(nitro.options.output.publicDir, fileName);
|
|
2125
|
-
if (existsSync(filePath + ".gz") || existsSync(filePath + ".br")) return;
|
|
2126
|
-
const mimeType = src_default.getType(fileName) || "text/plain";
|
|
2127
|
-
const fileContents = await fsp.readFile(filePath);
|
|
2128
|
-
if (fileContents.length < 1024 || fileName.endsWith(".map") || !isCompressibleMime(mimeType)) return;
|
|
2129
|
-
const { gzip, brotli } = nitro.options.compressPublicAssets || {};
|
|
2130
|
-
const encodings = [gzip !== false && "gzip", brotli !== false && "br"].filter(Boolean);
|
|
2131
|
-
await Promise.all(encodings.map(async (encoding) => {
|
|
2132
|
-
const compressedPath = filePath + ("." + (encoding === "gzip" ? "gz" : "br"));
|
|
2133
|
-
if (existsSync(compressedPath)) return;
|
|
2134
|
-
const gzipOptions = { level: zlib.constants.Z_BEST_COMPRESSION };
|
|
2135
|
-
const brotliOptions = {
|
|
2136
|
-
[zlib.constants.BROTLI_PARAM_MODE]: isTextMime(mimeType) ? zlib.constants.BROTLI_MODE_TEXT : zlib.constants.BROTLI_MODE_GENERIC,
|
|
2137
|
-
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
2138
|
-
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: fileContents.length
|
|
2139
|
-
};
|
|
2140
|
-
const compressedBuff = await new Promise((resolve$2, reject) => {
|
|
2141
|
-
const cb = (error, result) => error ? reject(error) : resolve$2(result);
|
|
2142
|
-
if (encoding === "gzip") zlib.gzip(fileContents, gzipOptions, cb);
|
|
2143
|
-
else zlib.brotliCompress(fileContents, brotliOptions, cb);
|
|
2144
|
-
});
|
|
2145
|
-
await fsp.writeFile(compressedPath, compressedBuff);
|
|
2146
|
-
}));
|
|
2147
|
-
}));
|
|
2148
|
-
}
|
|
2149
|
-
function isTextMime(mimeType) {
|
|
2150
|
-
return /text|javascript|json|xml/.test(mimeType);
|
|
2151
|
-
}
|
|
2152
|
-
const COMPRESSIBLE_MIMES_RE = new Set([
|
|
2153
|
-
"application/dash+xml",
|
|
2154
|
-
"application/eot",
|
|
2155
|
-
"application/font",
|
|
2156
|
-
"application/font-sfnt",
|
|
2157
|
-
"application/javascript",
|
|
2158
|
-
"application/json",
|
|
2159
|
-
"application/opentype",
|
|
2160
|
-
"application/otf",
|
|
2161
|
-
"application/pdf",
|
|
2162
|
-
"application/pkcs7-mime",
|
|
2163
|
-
"application/protobuf",
|
|
2164
|
-
"application/rss+xml",
|
|
2165
|
-
"application/truetype",
|
|
2166
|
-
"application/ttf",
|
|
2167
|
-
"application/vnd.apple.mpegurl",
|
|
2168
|
-
"application/vnd.mapbox-vector-tile",
|
|
2169
|
-
"application/vnd.ms-fontobject",
|
|
2170
|
-
"application/wasm",
|
|
2171
|
-
"application/xhtml+xml",
|
|
2172
|
-
"application/xml",
|
|
2173
|
-
"application/x-font-opentype",
|
|
2174
|
-
"application/x-font-truetype",
|
|
2175
|
-
"application/x-font-ttf",
|
|
2176
|
-
"application/x-httpd-cgi",
|
|
2177
|
-
"application/x-javascript",
|
|
2178
|
-
"application/x-mpegurl",
|
|
2179
|
-
"application/x-opentype",
|
|
2180
|
-
"application/x-otf",
|
|
2181
|
-
"application/x-perl",
|
|
2182
|
-
"application/x-ttf",
|
|
2183
|
-
"font/eot",
|
|
2184
|
-
"font/opentype",
|
|
2185
|
-
"font/otf",
|
|
2186
|
-
"font/ttf",
|
|
2187
|
-
"image/svg+xml",
|
|
2188
|
-
"text/css",
|
|
2189
|
-
"text/csv",
|
|
2190
|
-
"text/html",
|
|
2191
|
-
"text/javascript",
|
|
2192
|
-
"text/js",
|
|
2193
|
-
"text/plain",
|
|
2194
|
-
"text/richtext",
|
|
2195
|
-
"text/tab-separated-values",
|
|
2196
|
-
"text/xml",
|
|
2197
|
-
"text/x-component",
|
|
2198
|
-
"text/x-java-source",
|
|
2199
|
-
"text/x-script",
|
|
2200
|
-
"vnd.apple.mpegurl"
|
|
2201
|
-
]);
|
|
2202
|
-
function isCompressibleMime(mimeType) {
|
|
2203
|
-
return COMPRESSIBLE_MIMES_RE.has(mimeType);
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
|
-
//#endregion
|
|
2207
|
-
//#region src/build/assets.ts
|
|
2208
|
-
const NEGATION_RE = /^(!?)(.*)$/;
|
|
2209
|
-
const PARENT_DIR_GLOB_RE = /!?\.\.\//;
|
|
2210
|
-
async function scanUnprefixedPublicAssets(nitro) {
|
|
2211
|
-
const scannedPaths = [];
|
|
2212
|
-
for (const asset of nitro.options.publicAssets) {
|
|
2213
|
-
if (asset.baseURL && asset.baseURL !== "/" && !asset.fallthrough) continue;
|
|
2214
|
-
if (!await isDirectory(asset.dir)) continue;
|
|
2215
|
-
const publicAssets = await glob(getIncludePatterns(nitro, asset.dir, asset.ignore), {
|
|
2216
|
-
cwd: asset.dir,
|
|
2217
|
-
absolute: false,
|
|
2218
|
-
dot: true
|
|
2219
|
-
});
|
|
2220
|
-
scannedPaths.push(...publicAssets.map((file) => join$1(asset.baseURL || "/", file)));
|
|
2221
|
-
}
|
|
2222
|
-
return scannedPaths;
|
|
2223
|
-
}
|
|
2224
|
-
async function copyPublicAssets(nitro) {
|
|
2225
|
-
if (nitro.options.noPublicDir) return;
|
|
2226
|
-
for (const asset of nitro.options.publicAssets) {
|
|
2227
|
-
const assetDir = asset.dir;
|
|
2228
|
-
const dstDir = join$1(nitro.options.output.publicDir, asset.baseURL);
|
|
2229
|
-
if (await isDirectory(assetDir)) {
|
|
2230
|
-
const publicAssets = await glob(getIncludePatterns(nitro, assetDir, asset.ignore), {
|
|
2231
|
-
cwd: assetDir,
|
|
2232
|
-
absolute: false,
|
|
2233
|
-
dot: true
|
|
2234
|
-
});
|
|
2235
|
-
await Promise.all(publicAssets.map(async (file) => {
|
|
2236
|
-
const src = join$1(assetDir, file);
|
|
2237
|
-
const dst = join$1(dstDir, file);
|
|
2238
|
-
if (!existsSync(dst)) await promises.cp(src, dst);
|
|
2239
|
-
}));
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
2243
|
-
nitro.logger.success("Generated public " + prettyPath(nitro.options.output.publicDir));
|
|
2244
|
-
}
|
|
2245
|
-
function getIncludePatterns(nitro, assetDir, ignorePatterns = nitro.options.ignore) {
|
|
2246
|
-
return ["**", ...(ignorePatterns || []).map((p$1) => {
|
|
2247
|
-
const [_, negation, pattern] = p$1.match(NEGATION_RE) || [];
|
|
2248
|
-
return (negation ? "" : "!") + (pattern.startsWith("*") ? pattern : relative$1(assetDir, resolve$1(nitro.options.rootDir, pattern)));
|
|
2249
|
-
})].filter((p$1) => !PARENT_DIR_GLOB_RE.test(p$1));
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
//#endregion
|
|
2253
|
-
//#region src/build/prepare.ts
|
|
2254
|
-
async function prepare(nitro) {
|
|
2255
|
-
await prepareDir(nitro.options.output.dir);
|
|
2256
|
-
if (!nitro.options.noPublicDir) await prepareDir(nitro.options.output.publicDir);
|
|
2257
|
-
if (!nitro.options.static) await prepareDir(nitro.options.output.serverDir);
|
|
2258
|
-
}
|
|
2259
|
-
async function prepareDir(dir) {
|
|
2260
|
-
await fsp.rm(dir, {
|
|
2261
|
-
recursive: true,
|
|
2262
|
-
force: true
|
|
2263
|
-
});
|
|
2264
|
-
await fsp.mkdir(dir, { recursive: true });
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
//#endregion
|
|
2268
|
-
//#region node_modules/.pnpm/ultrahtml@1.6.0/node_modules/ultrahtml/dist/index.js
|
|
2269
|
-
var S = Symbol("Fragment"), D = new Set([
|
|
2270
|
-
"area",
|
|
2271
|
-
"base",
|
|
2272
|
-
"br",
|
|
2273
|
-
"col",
|
|
2274
|
-
"embed",
|
|
2275
|
-
"hr",
|
|
2276
|
-
"img",
|
|
2277
|
-
"input",
|
|
2278
|
-
"keygen",
|
|
2279
|
-
"link",
|
|
2280
|
-
"meta",
|
|
2281
|
-
"param",
|
|
2282
|
-
"source",
|
|
2283
|
-
"track",
|
|
2284
|
-
"wbr"
|
|
2285
|
-
]), x = new Set(["script", "style"]), o = /(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm, b = /[\@\.a-z0-9_\:\-]/i;
|
|
2286
|
-
function I(e) {
|
|
2287
|
-
let t = {};
|
|
2288
|
-
if (e) {
|
|
2289
|
-
let i = "none", r, n = "", a$1, l;
|
|
2290
|
-
for (let c = 0; c < e.length; c++) {
|
|
2291
|
-
let d$1 = e[c];
|
|
2292
|
-
i === "none" ? b.test(d$1) ? (r && (t[r] = n, r = void 0, n = ""), a$1 = c, i = "key") : d$1 === "=" && r && (i = "value") : i === "key" ? b.test(d$1) || (r = e.substring(a$1, c), d$1 === "=" ? i = "value" : i = "none") : d$1 === l && c > 0 && e[c - 1] !== "\\" ? l && (n = e.substring(a$1, c), l = void 0, i = "none") : (d$1 === "\"" || d$1 === "'") && !l && (a$1 = c + 1, l = d$1);
|
|
2293
|
-
}
|
|
2294
|
-
i === "key" && a$1 != null && a$1 < e.length && (r = e.substring(a$1, e.length)), r && (t[r] = n);
|
|
2295
|
-
}
|
|
2296
|
-
return t;
|
|
2297
|
-
}
|
|
2298
|
-
function P(e) {
|
|
2299
|
-
let t = typeof e == "string" ? e : e.value, i, r, n, a$1, l, c, d$1, m, s, u = [];
|
|
2300
|
-
o.lastIndex = 0, r = i = {
|
|
2301
|
-
type: 0,
|
|
2302
|
-
children: []
|
|
2303
|
-
};
|
|
2304
|
-
let g = 0;
|
|
2305
|
-
function h() {
|
|
2306
|
-
a$1 = t.substring(g, o.lastIndex - n[0].length), a$1 && r.children.push({
|
|
2307
|
-
type: 2,
|
|
2308
|
-
value: a$1,
|
|
2309
|
-
parent: r
|
|
2310
|
-
});
|
|
2311
|
-
}
|
|
2312
|
-
for (; n = o.exec(t);) {
|
|
2313
|
-
if (c = n[5] || n[8], d$1 = n[6] || n[9], m = n[7] || n[10], x.has(r.name) && n[2] !== r.name) {
|
|
2314
|
-
l = o.lastIndex - n[0].length, r.children.length > 0 && (r.children[0].value += n[0]);
|
|
2315
|
-
continue;
|
|
2316
|
-
} else if (c === "<!--") {
|
|
2317
|
-
if (l = o.lastIndex - n[0].length, x.has(r.name)) continue;
|
|
2318
|
-
s = {
|
|
2319
|
-
type: 3,
|
|
2320
|
-
value: d$1,
|
|
2321
|
-
parent: r,
|
|
2322
|
-
loc: [{
|
|
2323
|
-
start: l,
|
|
2324
|
-
end: l + c.length
|
|
2325
|
-
}, {
|
|
2326
|
-
start: o.lastIndex - m.length,
|
|
2327
|
-
end: o.lastIndex
|
|
2328
|
-
}]
|
|
2329
|
-
}, u.push(s), s.parent.children.push(s);
|
|
2330
|
-
} else if (c === "<!") l = o.lastIndex - n[0].length, s = {
|
|
2331
|
-
type: 4,
|
|
2332
|
-
value: d$1,
|
|
2333
|
-
parent: r,
|
|
2334
|
-
loc: [{
|
|
2335
|
-
start: l,
|
|
2336
|
-
end: l + c.length
|
|
2337
|
-
}, {
|
|
2338
|
-
start: o.lastIndex - m.length,
|
|
2339
|
-
end: o.lastIndex
|
|
2340
|
-
}]
|
|
2341
|
-
}, u.push(s), s.parent.children.push(s);
|
|
2342
|
-
else if (n[1] !== "/") if (h(), x.has(r.name)) {
|
|
2343
|
-
g = o.lastIndex, h();
|
|
2344
|
-
continue;
|
|
2345
|
-
} else s = {
|
|
2346
|
-
type: 1,
|
|
2347
|
-
name: n[2] + "",
|
|
2348
|
-
attributes: I(n[3]),
|
|
2349
|
-
parent: r,
|
|
2350
|
-
children: [],
|
|
2351
|
-
loc: [{
|
|
2352
|
-
start: o.lastIndex - n[0].length,
|
|
2353
|
-
end: o.lastIndex
|
|
2354
|
-
}]
|
|
2355
|
-
}, u.push(s), s.parent.children.push(s), n[4] && n[4].indexOf("/") > -1 || D.has(s.name) ? (s.loc[1] = s.loc[0], s.isSelfClosingTag = !0) : r = s;
|
|
2356
|
-
else h(), n[2] + "" === r.name ? (s = r, r = s.parent, s.loc.push({
|
|
2357
|
-
start: o.lastIndex - n[0].length,
|
|
2358
|
-
end: o.lastIndex
|
|
2359
|
-
}), a$1 = t.substring(s.loc[0].end, s.loc[1].start), s.children.length === 0 && s.children.push({
|
|
2360
|
-
type: 2,
|
|
2361
|
-
value: a$1,
|
|
2362
|
-
parent: r
|
|
2363
|
-
})) : n[2] + "" === u[u.length - 1].name && u[u.length - 1].isSelfClosingTag === !0 && (s = u[u.length - 1], s.loc.push({
|
|
2364
|
-
start: o.lastIndex - n[0].length,
|
|
2365
|
-
end: o.lastIndex
|
|
2366
|
-
}));
|
|
2367
|
-
g = o.lastIndex;
|
|
2368
|
-
}
|
|
2369
|
-
return a$1 = t.slice(g), r.children.push({
|
|
2370
|
-
type: 2,
|
|
2371
|
-
value: a$1,
|
|
2372
|
-
parent: r
|
|
2373
|
-
}), i;
|
|
2374
|
-
}
|
|
2375
|
-
var T = class {
|
|
2376
|
-
constructor(t) {
|
|
2377
|
-
this.callback = t;
|
|
2378
|
-
}
|
|
2379
|
-
async visit(t, i, r) {
|
|
2380
|
-
if (await this.callback(t, i, r), Array.isArray(t.children)) {
|
|
2381
|
-
let n = [];
|
|
2382
|
-
for (let a$1 = 0; a$1 < t.children.length; a$1++) {
|
|
2383
|
-
let l = t.children[a$1];
|
|
2384
|
-
n.push(this.visit(l, t, a$1));
|
|
2385
|
-
}
|
|
2386
|
-
await Promise.all(n);
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
}, O = class {
|
|
2390
|
-
constructor(t) {
|
|
2391
|
-
this.callback = t;
|
|
2392
|
-
}
|
|
2393
|
-
visit(t, i, r) {
|
|
2394
|
-
if (this.callback(t, i, r), Array.isArray(t.children)) for (let n = 0; n < t.children.length; n++) {
|
|
2395
|
-
let a$1 = t.children[n];
|
|
2396
|
-
this.visit(a$1, t, n);
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
}, p = Symbol("HTMLString"), M = Symbol("AttrString"), f = Symbol("RenderFn");
|
|
2400
|
-
function z(e, t) {
|
|
2401
|
-
return new T(t).visit(e);
|
|
2402
|
-
}
|
|
2403
|
-
|
|
2404
|
-
//#endregion
|
|
2405
|
-
//#region src/prerender/utils.ts
|
|
2406
|
-
const allowedExtensions = new Set(["", ".json"]);
|
|
2407
|
-
const linkParents = /* @__PURE__ */ new Map();
|
|
2408
|
-
const HTML_ENTITIES = {
|
|
2409
|
-
"<": "<",
|
|
2410
|
-
">": ">",
|
|
2411
|
-
"&": "&",
|
|
2412
|
-
"'": "'",
|
|
2413
|
-
""": "\""
|
|
2414
|
-
};
|
|
2415
|
-
function escapeHtml(text) {
|
|
2416
|
-
return text.replace(/&(lt|gt|amp|apos|quot);/g, (ch) => HTML_ENTITIES[ch] || ch);
|
|
2417
|
-
}
|
|
2418
|
-
async function extractLinks(html, from, res, crawlLinks) {
|
|
2419
|
-
const links = [];
|
|
2420
|
-
const _links = [];
|
|
2421
|
-
if (crawlLinks) await z(P(html), (node) => {
|
|
2422
|
-
if (!node.attributes?.href) return;
|
|
2423
|
-
const link = escapeHtml(node.attributes.href);
|
|
2424
|
-
if (!decodeURIComponent(link).startsWith("#") && allowedExtensions.has(getExtension(link))) _links.push(link);
|
|
2425
|
-
});
|
|
2426
|
-
const header = res.headers.get("x-nitro-prerender") || "";
|
|
2427
|
-
_links.push(...header.split(",").map((i) => decodeURIComponent(i.trim())));
|
|
2428
|
-
for (const link of _links.filter(Boolean)) {
|
|
2429
|
-
const _link = parseURL(link);
|
|
2430
|
-
if (_link.protocol || _link.host) continue;
|
|
2431
|
-
if (!_link.pathname.startsWith("/")) {
|
|
2432
|
-
const fromURL = new URL(from, "http://localhost");
|
|
2433
|
-
_link.pathname = new URL(_link.pathname, fromURL).pathname;
|
|
2434
|
-
}
|
|
2435
|
-
links.push(_link.pathname + _link.search);
|
|
2436
|
-
}
|
|
2437
|
-
for (const link of links) {
|
|
2438
|
-
const _parents = linkParents.get(link);
|
|
2439
|
-
if (_parents) _parents.add(from);
|
|
2440
|
-
else linkParents.set(link, new Set([from]));
|
|
2441
|
-
}
|
|
2442
|
-
return links;
|
|
2443
|
-
}
|
|
2444
|
-
const EXT_REGEX = /\.[\da-z]+$/;
|
|
2445
|
-
function getExtension(link) {
|
|
2446
|
-
return (parseURL(link).pathname.match(EXT_REGEX) || [])[0] || "";
|
|
2447
|
-
}
|
|
2448
|
-
function formatPrerenderRoute(route) {
|
|
2449
|
-
let str = ` ├─ ${route.route} (${route.generateTimeMS}ms)`;
|
|
2450
|
-
if (route.error) {
|
|
2451
|
-
const parents = linkParents.get(route.route);
|
|
2452
|
-
const errorColor = colors[route.error.status === 404 ? "yellow" : "red"];
|
|
2453
|
-
const errorLead = parents?.size ? "├──" : "└──";
|
|
2454
|
-
str += `\n │ ${errorLead} ${errorColor(route.error.message)}`;
|
|
2455
|
-
if (parents?.size) str += `\n${[...parents.values()].map((link) => ` │ └── Linked from ${link}`).join("\n")}`;
|
|
2456
|
-
}
|
|
2457
|
-
if (route.skip) str += colors.gray(" (skipped)");
|
|
2458
|
-
return colors.gray(str);
|
|
2459
|
-
}
|
|
2460
|
-
function matchesIgnorePattern(path$1, pattern) {
|
|
2461
|
-
if (typeof pattern === "string") return path$1.startsWith(pattern);
|
|
2462
|
-
if (typeof pattern === "function") return pattern(path$1) === true;
|
|
2463
|
-
if (pattern instanceof RegExp) return pattern.test(path$1);
|
|
2464
|
-
return false;
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
//#endregion
|
|
2468
|
-
//#region src/prerender/prerender.ts
|
|
2469
|
-
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
2470
|
-
async function prerender(nitro) {
|
|
2471
|
-
if (nitro.options.noPublicDir) {
|
|
2472
|
-
nitro.logger.warn("Skipping prerender since `noPublicDir` option is enabled.");
|
|
2473
|
-
return;
|
|
2474
|
-
}
|
|
2475
|
-
if (nitro.options.builder === "vite") {
|
|
2476
|
-
nitro.logger.warn("Skipping prerender since not supported with vite builder yet...");
|
|
2477
|
-
return;
|
|
2478
|
-
}
|
|
2479
|
-
const routes = new Set(nitro.options.prerender.routes);
|
|
2480
|
-
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path$2, options]) => options.prerender && !path$2.includes("*")).map((e) => e[0]);
|
|
2481
|
-
for (const route of prerenderRulePaths) routes.add(route);
|
|
2482
|
-
await nitro.hooks.callHook("prerender:routes", routes);
|
|
2483
|
-
if (routes.size === 0) if (nitro.options.prerender.crawlLinks) routes.add("/");
|
|
2484
|
-
else return;
|
|
2485
|
-
nitro.logger.info("Initializing prerenderer");
|
|
2486
|
-
nitro._prerenderedRoutes = [];
|
|
2487
|
-
nitro._prerenderMeta = nitro._prerenderMeta || {};
|
|
2488
|
-
const prerendererConfig = {
|
|
2489
|
-
...nitro.options._config,
|
|
2490
|
-
static: false,
|
|
2491
|
-
rootDir: nitro.options.rootDir,
|
|
2492
|
-
logLevel: 0,
|
|
2493
|
-
preset: "nitro-prerender"
|
|
2494
|
-
};
|
|
2495
|
-
await nitro.hooks.callHook("prerender:config", prerendererConfig);
|
|
2496
|
-
const nitroRenderer = await createNitro(prerendererConfig);
|
|
2497
|
-
const prerenderStartTime = Date.now();
|
|
2498
|
-
await nitro.hooks.callHook("prerender:init", nitroRenderer);
|
|
2499
|
-
let path$1 = relative$1(nitro.options.output.dir, nitro.options.output.publicDir);
|
|
2500
|
-
if (!path$1.startsWith(".")) path$1 = `./${path$1}`;
|
|
2501
|
-
nitroRenderer.options.commands.preview = `npx serve ${path$1}`;
|
|
2502
|
-
nitroRenderer.options.output.dir = nitro.options.output.dir;
|
|
2503
|
-
await build(nitroRenderer);
|
|
2504
|
-
const serverFilename = typeof nitroRenderer.options.rollupConfig?.output?.entryFileNames === "string" ? nitroRenderer.options.rollupConfig.output.entryFileNames : "index.mjs";
|
|
2505
|
-
const prerenderer = await import(pathToFileURL(resolve$1(nitroRenderer.options.output.serverDir, serverFilename)).href).then((m) => m.default);
|
|
2506
|
-
const routeRules = createRouter();
|
|
2507
|
-
for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
|
|
2508
|
-
const _getRouteRules = (path$2) => defu({}, ...findAllRoutes(routeRules, void 0, path$2).map((r) => r.data).reverse());
|
|
2509
|
-
const generatedRoutes = /* @__PURE__ */ new Set();
|
|
2510
|
-
const failedRoutes = /* @__PURE__ */ new Set();
|
|
2511
|
-
const skippedRoutes = /* @__PURE__ */ new Set();
|
|
2512
|
-
const displayedLengthWarns = /* @__PURE__ */ new Set();
|
|
2513
|
-
const publicAssetBases = nitro.options.publicAssets.filter((a$1) => !!a$1.baseURL && a$1.baseURL !== "/" && !a$1.fallthrough).map((a$1) => withTrailingSlash(a$1.baseURL));
|
|
2514
|
-
const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
|
|
2515
|
-
const canPrerender = (route = "/") => {
|
|
2516
|
-
if (generatedRoutes.has(route) || skippedRoutes.has(route)) return false;
|
|
2517
|
-
if (nitro.options.prerender.ignore) {
|
|
2518
|
-
for (const pattern of nitro.options.prerender.ignore) if (matchesIgnorePattern(route, pattern)) return false;
|
|
2519
|
-
}
|
|
2520
|
-
if (publicAssetBases.some((base) => route.startsWith(base))) return false;
|
|
2521
|
-
if (scannedPublicAssets.has(route)) return false;
|
|
2522
|
-
if (_getRouteRules(route).prerender === false) return false;
|
|
2523
|
-
return true;
|
|
2524
|
-
};
|
|
2525
|
-
const canWriteToDisk = (route) => {
|
|
2526
|
-
if (route.route.includes("?")) return false;
|
|
2527
|
-
const FS_MAX_SEGMENT = 255;
|
|
2528
|
-
const FS_MAX_PATH_PUBLIC_HTML = 1024 - (nitro.options.output.publicDir.length + 10);
|
|
2529
|
-
if ((route.route.length >= FS_MAX_PATH_PUBLIC_HTML || route.route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route)) {
|
|
2530
|
-
displayedLengthWarns.add(route);
|
|
2531
|
-
const _route = route.route.slice(0, 60) + "...";
|
|
2532
|
-
if (route.route.length >= FS_MAX_PATH_PUBLIC_HTML) nitro.logger.warn(`Prerendering long route "${_route}" (${route.route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH_PUBLIC_HTML}-character limit when writing to \`${nitro.options.output.publicDir}\`.`);
|
|
2533
|
-
else {
|
|
2534
|
-
nitro.logger.warn(`Skipping prerender of the route "${_route}" since it exceeds the ${FS_MAX_SEGMENT}-character limit in one of the path segments and can cause filesystem issues.`);
|
|
2535
|
-
return false;
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
return true;
|
|
2539
|
-
};
|
|
2540
|
-
const generateRoute = async (route) => {
|
|
2541
|
-
const start = Date.now();
|
|
2542
|
-
route = decodeURI(route);
|
|
2543
|
-
if (!canPrerender(route)) {
|
|
2544
|
-
skippedRoutes.add(route);
|
|
2545
|
-
return;
|
|
2546
|
-
}
|
|
2547
|
-
generatedRoutes.add(route);
|
|
2548
|
-
const _route = { route };
|
|
2549
|
-
const encodedRoute = encodeURI(route);
|
|
2550
|
-
const req = toRequest(withBase(encodedRoute, nitro.options.baseURL), { headers: [["x-nitro-prerender", encodedRoute]] });
|
|
2551
|
-
const res = await prerenderer.fetch(req);
|
|
2552
|
-
let dataBuff = Buffer.from(await res.arrayBuffer());
|
|
2553
|
-
Object.defineProperty(_route, "contents", {
|
|
2554
|
-
get: () => {
|
|
2555
|
-
return dataBuff ? dataBuff.toString("utf8") : void 0;
|
|
2556
|
-
},
|
|
2557
|
-
set(value) {
|
|
2558
|
-
if (dataBuff) dataBuff = Buffer.from(value);
|
|
2559
|
-
}
|
|
2560
|
-
});
|
|
2561
|
-
Object.defineProperty(_route, "data", {
|
|
2562
|
-
get: () => {
|
|
2563
|
-
return dataBuff ? dataBuff.buffer : void 0;
|
|
2564
|
-
},
|
|
2565
|
-
set(value) {
|
|
2566
|
-
if (dataBuff) dataBuff = Buffer.from(value);
|
|
2567
|
-
}
|
|
2568
|
-
});
|
|
2569
|
-
if (![200, ...[
|
|
2570
|
-
301,
|
|
2571
|
-
302,
|
|
2572
|
-
303,
|
|
2573
|
-
304,
|
|
2574
|
-
307,
|
|
2575
|
-
308
|
|
2576
|
-
]].includes(res.status)) {
|
|
2577
|
-
_route.error = /* @__PURE__ */ new Error(`[${res.status}] ${res.statusText}`);
|
|
2578
|
-
_route.error.status = res.status;
|
|
2579
|
-
_route.error.statusText = res.statusText;
|
|
2580
|
-
}
|
|
2581
|
-
_route.generateTimeMS = Date.now() - start;
|
|
2582
|
-
const contentType = res.headers.get("content-type") || "";
|
|
2583
|
-
const isImplicitHTML = !route.endsWith(".html") && contentType.includes("html") && !JsonSigRx.test(dataBuff.subarray(0, 32).toString("utf8"));
|
|
2584
|
-
const routeWithIndex = route.endsWith("/") ? route + "index" : route;
|
|
2585
|
-
const htmlPath = route.endsWith("/") || nitro.options.prerender.autoSubfolderIndex ? joinURL(route, "index.html") : route + ".html";
|
|
2586
|
-
_route.fileName = withoutBase(isImplicitHTML ? htmlPath : routeWithIndex, nitro.options.baseURL);
|
|
2587
|
-
const inferredContentType = src_default.getType(_route.fileName) || "text/plain";
|
|
2588
|
-
_route.contentType = contentType || inferredContentType;
|
|
2589
|
-
await nitro.hooks.callHook("prerender:generate", _route, nitro);
|
|
2590
|
-
if (_route.contentType !== inferredContentType) {
|
|
2591
|
-
nitro._prerenderMeta[_route.fileName] ||= {};
|
|
2592
|
-
nitro._prerenderMeta[_route.fileName].contentType = _route.contentType;
|
|
2593
|
-
}
|
|
2594
|
-
if (_route.error) failedRoutes.add(_route);
|
|
2595
|
-
if (_route.skip || _route.error) {
|
|
2596
|
-
await nitro.hooks.callHook("prerender:route", _route);
|
|
2597
|
-
nitro.logger.log(formatPrerenderRoute(_route));
|
|
2598
|
-
dataBuff = void 0;
|
|
2599
|
-
return _route;
|
|
2600
|
-
}
|
|
2601
|
-
if (canWriteToDisk(_route)) {
|
|
2602
|
-
await writeFile$1(join$1(nitro.options.output.publicDir, _route.fileName), dataBuff);
|
|
2603
|
-
nitro._prerenderedRoutes.push(_route);
|
|
2604
|
-
} else _route.skip = true;
|
|
2605
|
-
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
|
|
2606
|
-
const extractedLinks = await extractLinks(dataBuff.toString("utf8"), route, res, nitro.options.prerender.crawlLinks ?? false);
|
|
2607
|
-
for (const _link of extractedLinks) if (canPrerender(_link)) routes.add(_link);
|
|
2608
|
-
}
|
|
2609
|
-
await nitro.hooks.callHook("prerender:route", _route);
|
|
2610
|
-
nitro.logger.log(formatPrerenderRoute(_route));
|
|
2611
|
-
dataBuff = void 0;
|
|
2612
|
-
return _route;
|
|
2613
|
-
};
|
|
2614
|
-
nitro.logger.info(nitro.options.prerender.crawlLinks ? `Prerendering ${routes.size} initial routes with crawler` : `Prerendering ${routes.size} routes`);
|
|
2615
|
-
await runParallel(routes, generateRoute, {
|
|
2616
|
-
concurrency: nitro.options.prerender.concurrency || 1,
|
|
2617
|
-
interval: nitro.options.prerender.interval
|
|
2618
|
-
});
|
|
2619
|
-
await prerenderer.close();
|
|
2620
|
-
await nitro.hooks.callHook("prerender:done", {
|
|
2621
|
-
prerenderedRoutes: nitro._prerenderedRoutes,
|
|
2622
|
-
failedRoutes: [...failedRoutes]
|
|
2623
|
-
});
|
|
2624
|
-
if (nitro.options.prerender.failOnError && failedRoutes.size > 0) {
|
|
2625
|
-
nitro.logger.log("\nErrors prerendering:");
|
|
2626
|
-
for (const route of failedRoutes) nitro.logger.log(formatPrerenderRoute(route));
|
|
2627
|
-
nitro.logger.log("");
|
|
2628
|
-
throw new Error("Exiting due to prerender errors.");
|
|
2629
|
-
}
|
|
2630
|
-
const prerenderTimeInMs = Date.now() - prerenderStartTime;
|
|
2631
|
-
nitro.logger.info(`Prerendered ${nitro._prerenderedRoutes.length} routes in ${prerenderTimeInMs / 1e3} seconds`);
|
|
2632
|
-
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
2633
|
-
}
|
|
2634
|
-
|
|
2635
|
-
//#endregion
|
|
2636
|
-
//#region src/task.ts
|
|
2637
|
-
/** @experimental */
|
|
2638
|
-
async function runTask(taskEvent, opts) {
|
|
2639
|
-
return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
|
|
2640
|
-
method: "POST",
|
|
2641
|
-
body: taskEvent
|
|
2642
|
-
});
|
|
2643
|
-
}
|
|
2644
|
-
/** @experimental */
|
|
2645
|
-
async function listTasks(opts) {
|
|
2646
|
-
return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
|
|
2647
|
-
}
|
|
2648
|
-
const _devHint = `(is dev server running?)`;
|
|
2649
|
-
async function _getTasksContext(opts) {
|
|
2650
|
-
const buildInfoPath = resolve$1(resolve$1(resolve$1(process.cwd(), opts?.cwd || "."), opts?.buildDir || "node_modules/.nitro"), "nitro.dev.json");
|
|
2651
|
-
if (!existsSync(buildInfoPath)) throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
|
|
2652
|
-
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
2653
|
-
if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) throw new Error(`Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`);
|
|
2654
|
-
if (!_pidIsRunning(buildInfo.dev.pid)) throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
|
|
2655
|
-
const baseURL = `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`;
|
|
2656
|
-
const socketPath = buildInfo.dev.workerAddress.socketPath;
|
|
2657
|
-
const devFetch = (path$1, options) => {
|
|
2658
|
-
return new Promise((resolve$2, reject) => {
|
|
2659
|
-
let url = withBase(path$1, baseURL);
|
|
2660
|
-
if (options?.query) url = withQuery(url, options.query);
|
|
2661
|
-
const request = http.request(url, {
|
|
2662
|
-
socketPath,
|
|
2663
|
-
method: options?.method,
|
|
2664
|
-
headers: {
|
|
2665
|
-
Accept: "application/json",
|
|
2666
|
-
"Content-Type": "application/json"
|
|
2667
|
-
}
|
|
2668
|
-
}, (response) => {
|
|
2669
|
-
if (!response.statusCode || response.statusCode >= 400 && response.statusCode < 600) {
|
|
2670
|
-
reject(new Error(response.statusMessage));
|
|
2671
|
-
return;
|
|
2672
|
-
}
|
|
2673
|
-
let data = "";
|
|
2674
|
-
response.on("data", (chunk) => data += chunk).on("end", () => resolve$2(JSON.parse(data))).on("error", (e) => reject(e));
|
|
2675
|
-
});
|
|
2676
|
-
request.on("error", (e) => reject(e));
|
|
2677
|
-
if (options?.body) request.write(JSON.stringify(options.body));
|
|
2678
|
-
request.end();
|
|
2679
|
-
});
|
|
2680
|
-
};
|
|
2681
|
-
return {
|
|
2682
|
-
buildInfo,
|
|
2683
|
-
devFetch
|
|
2684
|
-
};
|
|
2685
|
-
}
|
|
2686
|
-
function _pidIsRunning(pid) {
|
|
2687
|
-
try {
|
|
2688
|
-
process.kill(pid, 0);
|
|
2689
|
-
return true;
|
|
2690
|
-
} catch {
|
|
2691
|
-
return false;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
|
|
2695
|
-
//#endregion
|
|
2696
|
-
export { copyPublicAssets as a, loadOptions as c, prepare as i, runTask as n, build as o, prerender as r, createNitro as s, listTasks as t };
|