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/nitro5.mjs
DELETED
|
@@ -1,733 +0,0 @@
|
|
|
1
|
-
import { a as join, i as isAbsolute, l as relative, n as dirname, s as normalizeWindowsPath, u as resolve } from "../_libs/pathe.mjs";
|
|
2
|
-
import { l as resolveModulePath } from "../_libs/confbox+exsolve+pkg-types.mjs";
|
|
3
|
-
import { i as writeFile, r as resolveNitroPath, t as isDirectory } from "./nitro4.mjs";
|
|
4
|
-
import { t as glob } from "../_libs/fdir+picomatch+tinyglobby.mjs";
|
|
5
|
-
import { A as parseNodeModulePath, h as toExports, k as lookupNodeModuleSubpath } from "../_libs/acorn+confbox+js-tokens+magic-string+mlly+pkg-types+sourcemap-codec+strip-literal+unimport.mjs";
|
|
6
|
-
import { existsSync, promises } from "node:fs";
|
|
7
|
-
import { defu } from "defu";
|
|
8
|
-
import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
9
|
-
import { runtimeDir } from "nitro/meta";
|
|
10
|
-
import "scule";
|
|
11
|
-
|
|
12
|
-
//#region src/scan.ts
|
|
13
|
-
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
14
|
-
const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
|
|
15
|
-
async function scanAndSyncOptions(nitro) {
|
|
16
|
-
const scannedPlugins = await scanPlugins(nitro);
|
|
17
|
-
for (const plugin of scannedPlugins) if (!nitro.options.plugins.includes(plugin)) nitro.options.plugins.push(plugin);
|
|
18
|
-
if (nitro.options.experimental.tasks) {
|
|
19
|
-
const scannedTasks = await scanTasks(nitro);
|
|
20
|
-
for (const scannedTask of scannedTasks) if (scannedTask.name in nitro.options.tasks) {
|
|
21
|
-
if (!nitro.options.tasks[scannedTask.name].handler) nitro.options.tasks[scannedTask.name].handler = scannedTask.handler;
|
|
22
|
-
} else nitro.options.tasks[scannedTask.name] = {
|
|
23
|
-
handler: scannedTask.handler,
|
|
24
|
-
description: ""
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const scannedModules = await scanModules(nitro);
|
|
28
|
-
nitro.options.modules = nitro.options.modules || [];
|
|
29
|
-
for (const modPath of scannedModules) if (!nitro.options.modules.includes(modPath)) nitro.options.modules.push(modPath);
|
|
30
|
-
}
|
|
31
|
-
async function scanHandlers(nitro) {
|
|
32
|
-
const middleware = await scanMiddleware(nitro);
|
|
33
|
-
const handlers = await Promise.all([scanServerRoutes(nitro, nitro.options.apiDir || "api", nitro.options.apiBaseURL || "/api"), scanServerRoutes(nitro, nitro.options.routesDir || "routes")]).then((r) => r.flat());
|
|
34
|
-
nitro.scannedHandlers = [...middleware, ...handlers.filter((h, index, array) => {
|
|
35
|
-
return array.findIndex((h2) => h.route === h2.route && h.method === h2.method && h.env === h2.env) === index;
|
|
36
|
-
})];
|
|
37
|
-
return handlers;
|
|
38
|
-
}
|
|
39
|
-
async function scanMiddleware(nitro) {
|
|
40
|
-
return (await scanFiles(nitro, "middleware")).map((file) => {
|
|
41
|
-
return {
|
|
42
|
-
route: "/**",
|
|
43
|
-
middleware: true,
|
|
44
|
-
handler: file.fullPath
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async function scanServerRoutes(nitro, dir, prefix = "/") {
|
|
49
|
-
return (await scanFiles(nitro, dir)).map((file) => {
|
|
50
|
-
let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(\w+)]/g, "**:$1").replace(/\[([^/\]]+)]/g, ":$1");
|
|
51
|
-
route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
|
|
52
|
-
const suffixMatch = route.match(suffixRegex);
|
|
53
|
-
let method;
|
|
54
|
-
let env;
|
|
55
|
-
if (suffixMatch?.index && suffixMatch?.index >= 0) {
|
|
56
|
-
route = route.slice(0, suffixMatch.index);
|
|
57
|
-
method = suffixMatch.groups?.method;
|
|
58
|
-
env = suffixMatch.groups?.env;
|
|
59
|
-
}
|
|
60
|
-
route = route.replace(/\/index$/, "") || "/";
|
|
61
|
-
return {
|
|
62
|
-
handler: file.fullPath,
|
|
63
|
-
lazy: true,
|
|
64
|
-
middleware: false,
|
|
65
|
-
route,
|
|
66
|
-
method,
|
|
67
|
-
env
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async function scanPlugins(nitro) {
|
|
72
|
-
return (await scanFiles(nitro, "plugins")).map((f) => f.fullPath);
|
|
73
|
-
}
|
|
74
|
-
async function scanTasks(nitro) {
|
|
75
|
-
return (await scanFiles(nitro, "tasks")).map((f) => {
|
|
76
|
-
return {
|
|
77
|
-
name: f.path.replace(/\/index$/, "").replace(/\.[A-Za-z]+$/, "").replace(/\//g, ":"),
|
|
78
|
-
handler: f.fullPath
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async function scanModules(nitro) {
|
|
83
|
-
return (await scanFiles(nitro, "modules")).map((f) => f.fullPath);
|
|
84
|
-
}
|
|
85
|
-
async function scanFiles(nitro, name) {
|
|
86
|
-
return await Promise.all(nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name))).then((r) => r.flat());
|
|
87
|
-
}
|
|
88
|
-
async function scanDir(nitro, dir, name) {
|
|
89
|
-
return (await glob(join(name, GLOB_SCAN_PATTERN), {
|
|
90
|
-
cwd: dir,
|
|
91
|
-
dot: true,
|
|
92
|
-
ignore: nitro.options.ignore,
|
|
93
|
-
absolute: true
|
|
94
|
-
}).catch((error) => {
|
|
95
|
-
if (error?.code === "ENOTDIR") {
|
|
96
|
-
nitro.logger.warn(`Ignoring \`${join(dir, name)}\`. It must be a directory.`);
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
throw error;
|
|
100
|
-
})).map((fullPath) => {
|
|
101
|
-
return {
|
|
102
|
-
fullPath,
|
|
103
|
-
path: relative(join(dir, name), fullPath)
|
|
104
|
-
};
|
|
105
|
-
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/utils.mjs
|
|
110
|
-
const pathSeparators = /* @__PURE__ */ new Set([
|
|
111
|
-
"/",
|
|
112
|
-
"\\",
|
|
113
|
-
void 0
|
|
114
|
-
]);
|
|
115
|
-
const normalizedAliasSymbol = Symbol.for("pathe:normalizedAlias");
|
|
116
|
-
function normalizeAliases(_aliases) {
|
|
117
|
-
if (_aliases[normalizedAliasSymbol]) return _aliases;
|
|
118
|
-
const aliases = Object.fromEntries(Object.entries(_aliases).sort(([a], [b]) => _compareAliases(a, b)));
|
|
119
|
-
for (const key in aliases) for (const alias in aliases) {
|
|
120
|
-
if (alias === key || key.startsWith(alias)) continue;
|
|
121
|
-
if (aliases[key]?.startsWith(alias) && pathSeparators.has(aliases[key][alias.length])) aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
|
|
122
|
-
}
|
|
123
|
-
Object.defineProperty(aliases, normalizedAliasSymbol, {
|
|
124
|
-
value: true,
|
|
125
|
-
enumerable: false
|
|
126
|
-
});
|
|
127
|
-
return aliases;
|
|
128
|
-
}
|
|
129
|
-
function resolveAlias(path, aliases) {
|
|
130
|
-
const _path = normalizeWindowsPath(path);
|
|
131
|
-
aliases = normalizeAliases(aliases);
|
|
132
|
-
for (const [alias, to] of Object.entries(aliases)) {
|
|
133
|
-
if (!_path.startsWith(alias)) continue;
|
|
134
|
-
if (hasTrailingSlash(_path[(hasTrailingSlash(alias) ? alias.slice(0, -1) : alias).length])) return join(to, _path.slice(alias.length));
|
|
135
|
-
}
|
|
136
|
-
return _path;
|
|
137
|
-
}
|
|
138
|
-
function _compareAliases(a, b) {
|
|
139
|
-
return b.split("/").length - a.split("/").length;
|
|
140
|
-
}
|
|
141
|
-
function hasTrailingSlash(path = "/") {
|
|
142
|
-
const lastChar = path[path.length - 1];
|
|
143
|
-
return lastChar === "/" || lastChar === "\\";
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs
|
|
148
|
-
function getType(val) {
|
|
149
|
-
const type = typeof val;
|
|
150
|
-
if (type === "undefined" || val === null) return;
|
|
151
|
-
if (Array.isArray(val)) return "array";
|
|
152
|
-
return type;
|
|
153
|
-
}
|
|
154
|
-
function isObject(val) {
|
|
155
|
-
return val !== null && !Array.isArray(val) && typeof val === "object";
|
|
156
|
-
}
|
|
157
|
-
function nonEmpty(arr) {
|
|
158
|
-
return arr.filter(Boolean);
|
|
159
|
-
}
|
|
160
|
-
function unique(arr) {
|
|
161
|
-
return [...new Set(arr)];
|
|
162
|
-
}
|
|
163
|
-
function joinPath(a, b = "", sep = ".") {
|
|
164
|
-
return a ? a + sep + b : b;
|
|
165
|
-
}
|
|
166
|
-
function setValue(obj, path, val) {
|
|
167
|
-
const keys = path.split(".");
|
|
168
|
-
const _key = keys.pop();
|
|
169
|
-
for (const key of keys) {
|
|
170
|
-
if (!obj || typeof obj !== "object") return;
|
|
171
|
-
if (!(key in obj)) obj[key] = {};
|
|
172
|
-
obj = obj[key];
|
|
173
|
-
}
|
|
174
|
-
if (_key) {
|
|
175
|
-
if (!obj || typeof obj !== "object") return;
|
|
176
|
-
obj[_key] = val;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function getValue(obj, path) {
|
|
180
|
-
for (const key of path.split(".")) {
|
|
181
|
-
if (!obj || typeof obj !== "object" || !(key in obj)) return;
|
|
182
|
-
obj = obj[key];
|
|
183
|
-
}
|
|
184
|
-
return obj;
|
|
185
|
-
}
|
|
186
|
-
function normalizeTypes(val) {
|
|
187
|
-
const arr = unique(val.filter(Boolean));
|
|
188
|
-
if (arr.length === 0 || arr.includes("any")) return;
|
|
189
|
-
return arr.length > 1 ? arr : arr[0];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.mjs
|
|
194
|
-
async function resolveSchema(obj, defaults, options = {}) {
|
|
195
|
-
return await _resolveSchema(obj, "", {
|
|
196
|
-
root: obj,
|
|
197
|
-
defaults,
|
|
198
|
-
resolveCache: {},
|
|
199
|
-
ignoreDefaults: !!options.ignoreDefaults
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
async function _resolveSchema(input, id, ctx) {
|
|
203
|
-
if (id in ctx.resolveCache) return ctx.resolveCache[id];
|
|
204
|
-
const schemaId = "#" + id.replace(/\./g, "/");
|
|
205
|
-
if (!isObject(input)) {
|
|
206
|
-
const safeInput = Array.isArray(input) ? [...input] : input;
|
|
207
|
-
const schema2 = {
|
|
208
|
-
type: getType(input),
|
|
209
|
-
id: schemaId,
|
|
210
|
-
default: ctx.ignoreDefaults ? void 0 : safeInput
|
|
211
|
-
};
|
|
212
|
-
normalizeSchema(schema2, { ignoreDefaults: ctx.ignoreDefaults });
|
|
213
|
-
ctx.resolveCache[id] = schema2;
|
|
214
|
-
if (ctx.defaults && getValue(ctx.defaults, id) === void 0) setValue(ctx.defaults, id, schema2.default);
|
|
215
|
-
return schema2;
|
|
216
|
-
}
|
|
217
|
-
const node = { ...input };
|
|
218
|
-
const schema = ctx.resolveCache[id] = {
|
|
219
|
-
...node.$schema,
|
|
220
|
-
id: schemaId
|
|
221
|
-
};
|
|
222
|
-
for (const key in node) {
|
|
223
|
-
if (key === "$resolve" || key === "$schema" || key === "$default") continue;
|
|
224
|
-
schema.properties = schema.properties || {};
|
|
225
|
-
if (!schema.properties[key]) {
|
|
226
|
-
const child = schema.properties[key] = await _resolveSchema(node[key], joinPath(id, key), ctx);
|
|
227
|
-
if (Array.isArray(child.tags) && child.tags.includes("@required")) {
|
|
228
|
-
schema.required = schema.required || [];
|
|
229
|
-
if (!schema.required.includes(key)) schema.required.push(key);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (!ctx.ignoreDefaults) {
|
|
234
|
-
if (ctx.defaults) schema.default = getValue(ctx.defaults, id);
|
|
235
|
-
if (schema.default === void 0 && "$default" in node) schema.default = node.$default;
|
|
236
|
-
if (typeof node.$resolve === "function") schema.default = await node.$resolve(schema.default, async (key) => {
|
|
237
|
-
return (await _resolveSchema(getValue(ctx.root, key), key, ctx)).default;
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
if (ctx.defaults) setValue(ctx.defaults, id, schema.default);
|
|
241
|
-
if (!schema.type) schema.type = getType(schema.default) || (schema.properties ? "object" : "any");
|
|
242
|
-
normalizeSchema(schema, { ignoreDefaults: ctx.ignoreDefaults });
|
|
243
|
-
if (ctx.defaults && getValue(ctx.defaults, id) === void 0) setValue(ctx.defaults, id, schema.default);
|
|
244
|
-
return schema;
|
|
245
|
-
}
|
|
246
|
-
function normalizeSchema(schema, options) {
|
|
247
|
-
if (schema.type === "array" && !("items" in schema)) {
|
|
248
|
-
schema.items = { type: nonEmpty(unique(schema.default.map((i) => getType(i)))) };
|
|
249
|
-
if (schema.items.type) {
|
|
250
|
-
if (schema.items.type.length === 0) schema.items.type = "any";
|
|
251
|
-
else if (schema.items.type.length === 1) schema.items.type = schema.items.type[0];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if (!options.ignoreDefaults && schema.default === void 0 && ("properties" in schema || schema.type === "object" || schema.type === "any")) {
|
|
255
|
-
const propsWithDefaults = Object.entries(schema.properties || {}).filter(([, prop]) => "default" in prop).map(([key, value]) => [key, value.default]);
|
|
256
|
-
schema.default = Object.fromEntries(propsWithDefaults);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
//#endregion
|
|
261
|
-
//#region node_modules/.pnpm/knitwork@1.3.0/node_modules/knitwork/dist/index.mjs
|
|
262
|
-
function genString(input, options = {}) {
|
|
263
|
-
const str = JSON.stringify(input);
|
|
264
|
-
if (!options.singleQuotes) return str;
|
|
265
|
-
return `'${escapeString(str).slice(1, -1)}'`;
|
|
266
|
-
}
|
|
267
|
-
const NEEDS_ESCAPE_RE = /[\n\r'\\\u2028\u2029]/;
|
|
268
|
-
const QUOTE_NEWLINE_RE = /([\n\r'\u2028\u2029])/g;
|
|
269
|
-
const BACKSLASH_RE = /\\/g;
|
|
270
|
-
function escapeString(id) {
|
|
271
|
-
if (!NEEDS_ESCAPE_RE.test(id)) return id;
|
|
272
|
-
return id.replace(BACKSLASH_RE, "\\\\").replace(QUOTE_NEWLINE_RE, "\\$1");
|
|
273
|
-
}
|
|
274
|
-
function genSafeVariableName(name) {
|
|
275
|
-
if (reservedNames.has(name)) return `_${name}`;
|
|
276
|
-
return name.replace(/^\d/, (r) => `_${r}`).replace(/\W/g, (r) => "_" + r.charCodeAt(0));
|
|
277
|
-
}
|
|
278
|
-
const reservedNames = /* @__PURE__ */ new Set([
|
|
279
|
-
"Infinity",
|
|
280
|
-
"NaN",
|
|
281
|
-
"arguments",
|
|
282
|
-
"await",
|
|
283
|
-
"break",
|
|
284
|
-
"case",
|
|
285
|
-
"catch",
|
|
286
|
-
"class",
|
|
287
|
-
"const",
|
|
288
|
-
"continue",
|
|
289
|
-
"debugger",
|
|
290
|
-
"default",
|
|
291
|
-
"delete",
|
|
292
|
-
"do",
|
|
293
|
-
"else",
|
|
294
|
-
"enum",
|
|
295
|
-
"eval",
|
|
296
|
-
"export",
|
|
297
|
-
"extends",
|
|
298
|
-
"false",
|
|
299
|
-
"finally",
|
|
300
|
-
"for",
|
|
301
|
-
"function",
|
|
302
|
-
"if",
|
|
303
|
-
"implements",
|
|
304
|
-
"import",
|
|
305
|
-
"in",
|
|
306
|
-
"instanceof",
|
|
307
|
-
"interface",
|
|
308
|
-
"let",
|
|
309
|
-
"new",
|
|
310
|
-
"null",
|
|
311
|
-
"package",
|
|
312
|
-
"private",
|
|
313
|
-
"protected",
|
|
314
|
-
"public",
|
|
315
|
-
"return",
|
|
316
|
-
"static",
|
|
317
|
-
"super",
|
|
318
|
-
"switch",
|
|
319
|
-
"this",
|
|
320
|
-
"throw",
|
|
321
|
-
"true",
|
|
322
|
-
"try",
|
|
323
|
-
"typeof",
|
|
324
|
-
"undefined",
|
|
325
|
-
"var",
|
|
326
|
-
"void",
|
|
327
|
-
"while",
|
|
328
|
-
"with",
|
|
329
|
-
"yield"
|
|
330
|
-
]);
|
|
331
|
-
const VALID_IDENTIFIER_RE = /^[$_]?([A-Z_a-z]\w*|\d)$/;
|
|
332
|
-
function _genStatement(type, specifier, names, options = {}) {
|
|
333
|
-
const specifierString = genString(specifier, options);
|
|
334
|
-
if (!names) return `${type} ${specifierString};`;
|
|
335
|
-
const nameArray = Array.isArray(names);
|
|
336
|
-
const namesString = (nameArray ? names : [names]).map((index) => {
|
|
337
|
-
if (typeof index === "string") return { name: index };
|
|
338
|
-
if (index.name === index.as) index = { name: index.name };
|
|
339
|
-
return index;
|
|
340
|
-
}).map((index) => index.as ? `${index.name} as ${index.as}` : index.name).join(", ");
|
|
341
|
-
if (nameArray) return `${type} { ${namesString} } from ${genString(specifier, options)}${_genImportAttributes(type, options)};`;
|
|
342
|
-
return `${type} ${namesString} from ${genString(specifier, options)}${_genImportAttributes(type, options)};`;
|
|
343
|
-
}
|
|
344
|
-
function _genImportAttributes(type, options) {
|
|
345
|
-
if (type === "import type" || type === "export type") return "";
|
|
346
|
-
if (typeof options.attributes?.type === "string") return ` with { type: ${genString(options.attributes.type)} }`;
|
|
347
|
-
if (typeof options.assert?.type === "string") return ` assert { type: ${genString(options.assert.type)} }`;
|
|
348
|
-
return "";
|
|
349
|
-
}
|
|
350
|
-
function genImport(specifier, imports, options = {}) {
|
|
351
|
-
return _genStatement("import", specifier, imports, options);
|
|
352
|
-
}
|
|
353
|
-
function wrapInDelimiters(lines, indent = "", delimiters = "{}", withComma = true) {
|
|
354
|
-
if (lines.length === 0) return delimiters;
|
|
355
|
-
const [start, end] = delimiters;
|
|
356
|
-
return `${start}
|
|
357
|
-
` + lines.join(withComma ? ",\n" : "\n") + `
|
|
358
|
-
${indent}${end}`;
|
|
359
|
-
}
|
|
360
|
-
function genObjectKey(key) {
|
|
361
|
-
return VALID_IDENTIFIER_RE.test(key) ? key : genString(key);
|
|
362
|
-
}
|
|
363
|
-
function genObjectFromRaw(object, indent = "", options = {}) {
|
|
364
|
-
return genObjectFromRawEntries(Object.entries(object), indent, options);
|
|
365
|
-
}
|
|
366
|
-
function genArrayFromRaw(array, indent = "", options = {}) {
|
|
367
|
-
const newIdent = indent + " ";
|
|
368
|
-
return wrapInDelimiters(array.map((index) => `${newIdent}${genRawValue(index, newIdent, options)}`), indent, "[]");
|
|
369
|
-
}
|
|
370
|
-
function genObjectFromRawEntries(array, indent = "", options = {}) {
|
|
371
|
-
const newIdent = indent + " ";
|
|
372
|
-
return wrapInDelimiters(array.map(([key, value]) => `${newIdent}${genObjectKey(key)}: ${genRawValue(value, newIdent, options)}`), indent, "{}");
|
|
373
|
-
}
|
|
374
|
-
function genRawValue(value, indent = "", options = {}) {
|
|
375
|
-
if (value === void 0) return "undefined";
|
|
376
|
-
if (value === null) return "null";
|
|
377
|
-
if (Array.isArray(value)) return genArrayFromRaw(value, indent, options);
|
|
378
|
-
if (value && typeof value === "object") return genObjectFromRaw(value, indent, options);
|
|
379
|
-
if (options.preserveTypes && typeof value !== "function") return JSON.stringify(value);
|
|
380
|
-
return value.toString();
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
//#endregion
|
|
384
|
-
//#region node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/index.mjs
|
|
385
|
-
const GenerateTypesDefaults = {
|
|
386
|
-
interfaceName: "Untyped",
|
|
387
|
-
addExport: true,
|
|
388
|
-
addDefaults: true,
|
|
389
|
-
allowExtraKeys: void 0,
|
|
390
|
-
partial: false,
|
|
391
|
-
indentation: 0
|
|
392
|
-
};
|
|
393
|
-
const TYPE_MAP = {
|
|
394
|
-
array: "any[]",
|
|
395
|
-
bigint: "bigint",
|
|
396
|
-
boolean: "boolean",
|
|
397
|
-
number: "number",
|
|
398
|
-
object: "",
|
|
399
|
-
any: "any",
|
|
400
|
-
string: "string",
|
|
401
|
-
symbol: "Symbol",
|
|
402
|
-
function: "Function"
|
|
403
|
-
};
|
|
404
|
-
const SCHEMA_KEYS = /* @__PURE__ */ new Set([
|
|
405
|
-
"items",
|
|
406
|
-
"default",
|
|
407
|
-
"resolve",
|
|
408
|
-
"properties",
|
|
409
|
-
"title",
|
|
410
|
-
"description",
|
|
411
|
-
"$schema",
|
|
412
|
-
"type",
|
|
413
|
-
"tsType",
|
|
414
|
-
"markdownType",
|
|
415
|
-
"tags",
|
|
416
|
-
"args",
|
|
417
|
-
"id",
|
|
418
|
-
"returns"
|
|
419
|
-
]);
|
|
420
|
-
const DECLARATION_RE = /typeof import\(["'](?<source>[^)]+)["']\)(\.(?<type>\w+)|\[["'](?<type1>\w+)["']])/g;
|
|
421
|
-
function extractTypeImports(declarations) {
|
|
422
|
-
const typeImports = {};
|
|
423
|
-
const aliases = /* @__PURE__ */ new Set();
|
|
424
|
-
const imports = [];
|
|
425
|
-
for (const match of declarations.matchAll(DECLARATION_RE)) {
|
|
426
|
-
const { source, type1, type = type1 } = match.groups || {};
|
|
427
|
-
typeImports[source] = typeImports[source] || /* @__PURE__ */ new Set();
|
|
428
|
-
typeImports[source].add(type);
|
|
429
|
-
}
|
|
430
|
-
for (const source in typeImports) {
|
|
431
|
-
const sourceImports = [];
|
|
432
|
-
for (const type of typeImports[source]) {
|
|
433
|
-
let count = 0;
|
|
434
|
-
let alias = type;
|
|
435
|
-
while (aliases.has(alias)) alias = `${type}${count++}`;
|
|
436
|
-
aliases.add(alias);
|
|
437
|
-
sourceImports.push(alias === type ? type : `${type} as ${alias}`);
|
|
438
|
-
declarations = declarations.replace(new RegExp(`typeof import\\(['"]${source}['"]\\)(\\.${type}|\\[['"]${type}['"]\\])`, "g"), alias);
|
|
439
|
-
}
|
|
440
|
-
imports.push(`import type { ${sourceImports.join(", ")} } from '${source}'`);
|
|
441
|
-
}
|
|
442
|
-
return [...imports, declarations].join("\n");
|
|
443
|
-
}
|
|
444
|
-
function generateTypes(schema, opts = {}) {
|
|
445
|
-
opts = {
|
|
446
|
-
...GenerateTypesDefaults,
|
|
447
|
-
...opts
|
|
448
|
-
};
|
|
449
|
-
const baseIden = " ".repeat(opts.indentation || 0);
|
|
450
|
-
const interfaceCode = `interface ${opts.interfaceName} {
|
|
451
|
-
` + _genTypes(schema, baseIden + " ", opts).map((l) => l.trim().length > 0 ? l : "").join("\n") + `
|
|
452
|
-
${baseIden}}`;
|
|
453
|
-
if (!opts.addExport) return baseIden + interfaceCode;
|
|
454
|
-
return extractTypeImports(baseIden + `export ${interfaceCode}`);
|
|
455
|
-
}
|
|
456
|
-
function _genTypes(schema, spaces, opts) {
|
|
457
|
-
const buff = [];
|
|
458
|
-
if (!schema) return buff;
|
|
459
|
-
for (const key in schema.properties) {
|
|
460
|
-
const val = schema.properties[key];
|
|
461
|
-
buff.push(...generateJSDoc(val, opts));
|
|
462
|
-
if (val.tsType) buff.push(`${genObjectKey(key)}${isRequired(schema, key, opts) ? "" : "?"}: ${val.tsType},
|
|
463
|
-
`);
|
|
464
|
-
else if (val.type === "object") buff.push(`${genObjectKey(key)}${isRequired(schema, key, opts) ? "" : "?"}: {`, ..._genTypes(val, spaces, opts), "},\n");
|
|
465
|
-
else {
|
|
466
|
-
let type;
|
|
467
|
-
if (val.type === "array") type = `Array<${getTsType(val.items || [], opts)}>`;
|
|
468
|
-
else if (val.type === "function") type = genFunctionType(val, opts);
|
|
469
|
-
else type = getTsType(val, opts);
|
|
470
|
-
buff.push(`${genObjectKey(key)}${isRequired(schema, key, opts) ? "" : "?"}: ${type},
|
|
471
|
-
`);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (buff.length > 0) {
|
|
475
|
-
const last = buff.pop() || "";
|
|
476
|
-
buff.push(last.slice(0, Math.max(0, last.length - 1)));
|
|
477
|
-
}
|
|
478
|
-
if (opts.allowExtraKeys === true || buff.length === 0 && opts.allowExtraKeys !== false) buff.push("[key: string]: any");
|
|
479
|
-
return buff.flatMap((l) => l.split("\n")).map((l) => spaces + l);
|
|
480
|
-
}
|
|
481
|
-
function getTsType(type, opts) {
|
|
482
|
-
if (Array.isArray(type)) return [normalizeTypes(type.map((t) => getTsType(t, opts)))].flat().join("|") || "any";
|
|
483
|
-
if (!type) return "any";
|
|
484
|
-
if (type.tsType) return type.tsType;
|
|
485
|
-
if (!type.type) return "any";
|
|
486
|
-
if (Array.isArray(type.type)) return type.type.map((t) => {
|
|
487
|
-
if (t === "object" && type.type.length > 1) return `{
|
|
488
|
-
` + _genTypes(type, " ", opts).join("\n") + `
|
|
489
|
-
}`;
|
|
490
|
-
return TYPE_MAP[t];
|
|
491
|
-
}).join("|");
|
|
492
|
-
if (type.type === "array") return `Array<${getTsType(type.items || [], opts)}>`;
|
|
493
|
-
if (type.type === "object") return `{
|
|
494
|
-
` + _genTypes(type, " ", opts).join("\n") + `
|
|
495
|
-
}`;
|
|
496
|
-
return TYPE_MAP[type.type] || type.type;
|
|
497
|
-
}
|
|
498
|
-
function genFunctionType(schema, opts) {
|
|
499
|
-
return `(${genFunctionArgs(schema.args, opts)}) => ${getTsType(schema.returns || [], opts)}`;
|
|
500
|
-
}
|
|
501
|
-
function genFunctionArgs(args, opts) {
|
|
502
|
-
return args?.map((arg) => {
|
|
503
|
-
let argStr = arg.name;
|
|
504
|
-
if (arg.optional || arg.default) argStr += "?";
|
|
505
|
-
if (arg.type || arg.tsType) argStr += `: ${getTsType(arg, opts)}`;
|
|
506
|
-
return argStr;
|
|
507
|
-
}).join(", ") || "";
|
|
508
|
-
}
|
|
509
|
-
function generateJSDoc(schema, opts) {
|
|
510
|
-
opts.defaultDescription = opts.defaultDescription || opts.defaultDescrption;
|
|
511
|
-
let buff = [];
|
|
512
|
-
if (schema.title) buff.push(schema.title, "");
|
|
513
|
-
if (schema.description) buff.push(schema.description, "");
|
|
514
|
-
else if (opts.defaultDescription && schema.type !== "object") buff.push(opts.defaultDescription, "");
|
|
515
|
-
if (opts.addDefaults && schema.type !== "object" && schema.type !== "any" && !(Array.isArray(schema.default) && schema.default.length === 0)) {
|
|
516
|
-
const stringified = JSON.stringify(schema.default);
|
|
517
|
-
if (stringified) buff.push(`@default ${stringified.replace(/\*\//g, String.raw`*\/`)}`);
|
|
518
|
-
}
|
|
519
|
-
for (const key in schema) if (!SCHEMA_KEYS.has(key)) buff.push("", `@${key} ${schema[key]}`);
|
|
520
|
-
if (Array.isArray(schema.tags)) {
|
|
521
|
-
for (const tag of schema.tags) if (tag !== "@untyped") buff.push("", tag);
|
|
522
|
-
}
|
|
523
|
-
buff = buff.flatMap((i) => i.split("\n"));
|
|
524
|
-
if (buff.length > 0) return buff.length === 1 ? ["/** " + buff[0] + " */"] : [
|
|
525
|
-
"/**",
|
|
526
|
-
...buff.map((i) => ` * ${i}`),
|
|
527
|
-
"*/"
|
|
528
|
-
];
|
|
529
|
-
return [];
|
|
530
|
-
}
|
|
531
|
-
function isRequired(schema, key, opts) {
|
|
532
|
-
if (Array.isArray(schema.required) && schema.required.includes(key)) return true;
|
|
533
|
-
return !opts.partial;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
//#endregion
|
|
537
|
-
//#region src/build/types.ts
|
|
538
|
-
async function writeTypes(nitro) {
|
|
539
|
-
const types = { routes: {} };
|
|
540
|
-
const generatedTypesDir = resolve(nitro.options.rootDir, nitro.options.typescript.generatedTypesDir || "node_modules/.nitro/types");
|
|
541
|
-
const middleware = [...nitro.scannedHandlers, ...nitro.options.handlers];
|
|
542
|
-
for (const mw of middleware) {
|
|
543
|
-
if (typeof mw.handler !== "string" || !mw.route) continue;
|
|
544
|
-
const relativePath = relative(generatedTypesDir, resolveNitroPath(mw.handler, nitro.options)).replace(/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/, "");
|
|
545
|
-
const method = mw.method || "default";
|
|
546
|
-
types.routes[mw.route] ??= {};
|
|
547
|
-
types.routes[mw.route][method] ??= [];
|
|
548
|
-
types.routes[mw.route][method].push(`Simplify<Serialize<Awaited<ReturnType<typeof import('${relativePath}').default>>>>`);
|
|
549
|
-
}
|
|
550
|
-
let autoImportedTypes = [];
|
|
551
|
-
let autoImportExports = "";
|
|
552
|
-
if (nitro.unimport) {
|
|
553
|
-
await nitro.unimport.init();
|
|
554
|
-
const allImports = await nitro.unimport.getImports();
|
|
555
|
-
autoImportExports = toExports(allImports).replace(/#internal\/nitro/g, relative(generatedTypesDir, runtimeDir));
|
|
556
|
-
const resolvedImportPathMap = /* @__PURE__ */ new Map();
|
|
557
|
-
for (const i of allImports) {
|
|
558
|
-
const from = i.typeFrom || i.from;
|
|
559
|
-
if (resolvedImportPathMap.has(from)) continue;
|
|
560
|
-
let path = resolveAlias(from, nitro.options.alias);
|
|
561
|
-
if (!isAbsolute(path)) {
|
|
562
|
-
const resolvedPath = resolveModulePath(from, {
|
|
563
|
-
try: true,
|
|
564
|
-
from: nitro.options.rootDir,
|
|
565
|
-
conditions: [
|
|
566
|
-
"type",
|
|
567
|
-
"node",
|
|
568
|
-
"import"
|
|
569
|
-
],
|
|
570
|
-
suffixes: ["", "/index"],
|
|
571
|
-
extensions: [
|
|
572
|
-
".mjs",
|
|
573
|
-
".cjs",
|
|
574
|
-
".js",
|
|
575
|
-
".mts",
|
|
576
|
-
".cts",
|
|
577
|
-
".ts"
|
|
578
|
-
]
|
|
579
|
-
});
|
|
580
|
-
if (resolvedPath) {
|
|
581
|
-
const { dir, name } = parseNodeModulePath(resolvedPath);
|
|
582
|
-
if (!dir || !name) path = resolvedPath;
|
|
583
|
-
else path = join(dir, name, await lookupNodeModuleSubpath(resolvedPath) || "");
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
if (existsSync(path) && !await isDirectory(path)) path = path.replace(/\.[a-z]+$/, "");
|
|
587
|
-
if (isAbsolute(path)) path = relative(generatedTypesDir, path);
|
|
588
|
-
resolvedImportPathMap.set(from, path);
|
|
589
|
-
}
|
|
590
|
-
autoImportedTypes = [nitro.options.imports && nitro.options.imports.autoImport !== false ? (await nitro.unimport.generateTypeDeclarations({
|
|
591
|
-
exportHelper: false,
|
|
592
|
-
resolvePath: (i) => {
|
|
593
|
-
const from = i.typeFrom || i.from;
|
|
594
|
-
return resolvedImportPathMap.get(from) ?? from;
|
|
595
|
-
}
|
|
596
|
-
})).trim() : ""];
|
|
597
|
-
}
|
|
598
|
-
const generateRoutes = () => [
|
|
599
|
-
"// Generated by nitro",
|
|
600
|
-
"import type { Serialize, Simplify } from \"nitro/types\";",
|
|
601
|
-
"declare module \"nitro/types\" {",
|
|
602
|
-
" type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T",
|
|
603
|
-
" interface InternalApi {",
|
|
604
|
-
...Object.entries(types.routes).map(([path, methods]) => [
|
|
605
|
-
` '${path}': {`,
|
|
606
|
-
...Object.entries(methods).map(([method, types$1]) => ` '${method}': ${types$1.join(" | ")}`),
|
|
607
|
-
" }"
|
|
608
|
-
].join("\n")),
|
|
609
|
-
" }",
|
|
610
|
-
"}",
|
|
611
|
-
"export {}"
|
|
612
|
-
];
|
|
613
|
-
const config = [
|
|
614
|
-
"// Generated by nitro",
|
|
615
|
-
`declare module "nitro/types" {`,
|
|
616
|
-
nitro.options.typescript.generateRuntimeConfigTypes ? generateTypes(await resolveSchema(Object.fromEntries(Object.entries(nitro.options.runtimeConfig).filter(([key]) => !["app", "nitro"].includes(key)))), {
|
|
617
|
-
interfaceName: "NitroRuntimeConfig",
|
|
618
|
-
addExport: false,
|
|
619
|
-
addDefaults: false,
|
|
620
|
-
allowExtraKeys: false,
|
|
621
|
-
indentation: 2
|
|
622
|
-
}) : "",
|
|
623
|
-
`}`,
|
|
624
|
-
"export {}"
|
|
625
|
-
];
|
|
626
|
-
const declarations = [
|
|
627
|
-
"/// <reference path=\"./nitro-routes.d.ts\" />",
|
|
628
|
-
"/// <reference path=\"./nitro-config.d.ts\" />",
|
|
629
|
-
"/// <reference path=\"./nitro-imports.d.ts\" />"
|
|
630
|
-
];
|
|
631
|
-
const buildFiles = [];
|
|
632
|
-
buildFiles.push({
|
|
633
|
-
path: join(generatedTypesDir, "nitro-routes.d.ts"),
|
|
634
|
-
contents: () => generateRoutes().join("\n")
|
|
635
|
-
});
|
|
636
|
-
buildFiles.push({
|
|
637
|
-
path: join(generatedTypesDir, "nitro-config.d.ts"),
|
|
638
|
-
contents: config.join("\n")
|
|
639
|
-
});
|
|
640
|
-
buildFiles.push({
|
|
641
|
-
path: join(generatedTypesDir, "nitro-imports.d.ts"),
|
|
642
|
-
contents: [...autoImportedTypes, autoImportExports || "export {}"].join("\n")
|
|
643
|
-
});
|
|
644
|
-
buildFiles.push({
|
|
645
|
-
path: join(generatedTypesDir, "nitro.d.ts"),
|
|
646
|
-
contents: declarations.join("\n")
|
|
647
|
-
});
|
|
648
|
-
if (nitro.options.typescript.generateTsConfig) {
|
|
649
|
-
const tsConfigPath = resolve(generatedTypesDir, nitro.options.typescript.tsconfigPath || "tsconfig.json");
|
|
650
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
651
|
-
const tsConfig = defu(nitro.options.typescript.tsConfig, {
|
|
652
|
-
compilerOptions: {
|
|
653
|
-
esModuleInterop: true,
|
|
654
|
-
allowSyntheticDefaultImports: true,
|
|
655
|
-
skipLibCheck: true,
|
|
656
|
-
target: "ESNext",
|
|
657
|
-
allowJs: true,
|
|
658
|
-
resolveJsonModule: true,
|
|
659
|
-
moduleDetection: "force",
|
|
660
|
-
isolatedModules: true,
|
|
661
|
-
verbatimModuleSyntax: true,
|
|
662
|
-
allowImportingTsExtensions: true,
|
|
663
|
-
strict: nitro.options.typescript.strict,
|
|
664
|
-
noUncheckedIndexedAccess: true,
|
|
665
|
-
noImplicitOverride: true,
|
|
666
|
-
forceConsistentCasingInFileNames: true,
|
|
667
|
-
module: "Preserve",
|
|
668
|
-
jsx: "preserve",
|
|
669
|
-
jsxFactory: "h",
|
|
670
|
-
jsxFragmentFactory: "Fragment",
|
|
671
|
-
paths: { "#imports": [relativeWithDot(tsconfigDir, join(generatedTypesDir, "nitro-imports"))] }
|
|
672
|
-
},
|
|
673
|
-
include: [
|
|
674
|
-
relativeWithDot(tsconfigDir, join(generatedTypesDir, "nitro.d.ts")).replace(/^(?=[^.])/, "./"),
|
|
675
|
-
join(relativeWithDot(tsconfigDir, nitro.options.rootDir), "**/*"),
|
|
676
|
-
...!nitro.options.serverDir || nitro.options.serverDir === nitro.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, nitro.options.serverDir), "**/*")]
|
|
677
|
-
]
|
|
678
|
-
});
|
|
679
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
680
|
-
const paths = await Promise.all(tsConfig.compilerOptions.paths[alias].map(async (path) => {
|
|
681
|
-
if (!isAbsolute(path)) return path;
|
|
682
|
-
return relativeWithDot(tsconfigDir, (await promises.stat(path).catch(() => null))?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, "") : path);
|
|
683
|
-
}));
|
|
684
|
-
tsConfig.compilerOptions.paths[alias] = [...new Set(paths)];
|
|
685
|
-
}
|
|
686
|
-
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
687
|
-
if (tsConfig.exclude) tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
688
|
-
types.tsConfig = tsConfig;
|
|
689
|
-
buildFiles.push({
|
|
690
|
-
path: tsConfigPath,
|
|
691
|
-
contents: () => JSON.stringify(tsConfig, null, 2)
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
await nitro.hooks.callHook("types:extend", types);
|
|
695
|
-
await Promise.all(buildFiles.map(async (file) => {
|
|
696
|
-
await writeFile(resolve(generatedTypesDir, file.path), typeof file.contents === "string" ? file.contents : file.contents());
|
|
697
|
-
}));
|
|
698
|
-
}
|
|
699
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
700
|
-
function relativeWithDot(from, to) {
|
|
701
|
-
const rel = relative(from, to);
|
|
702
|
-
return RELATIVE_RE.test(rel) ? rel : "./" + rel;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
//#endregion
|
|
706
|
-
//#region src/utils/parallel.ts
|
|
707
|
-
async function runParallel(inputs, cb, opts) {
|
|
708
|
-
const errors = [];
|
|
709
|
-
const tasks = /* @__PURE__ */ new Set();
|
|
710
|
-
function queueNext() {
|
|
711
|
-
const route = inputs.values().next().value;
|
|
712
|
-
if (!route) return;
|
|
713
|
-
inputs.delete(route);
|
|
714
|
-
const task = (opts.interval ? new Promise((resolve$1) => setTimeout(resolve$1, opts.interval)) : Promise.resolve()).then(() => cb(route)).catch((error) => {
|
|
715
|
-
console.error(error);
|
|
716
|
-
errors.push(error);
|
|
717
|
-
});
|
|
718
|
-
tasks.add(task);
|
|
719
|
-
return task.then(() => {
|
|
720
|
-
tasks.delete(task);
|
|
721
|
-
if (inputs.size > 0) return refillQueue();
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
function refillQueue() {
|
|
725
|
-
const workers = Math.min(opts.concurrency - tasks.size, inputs.size);
|
|
726
|
-
return Promise.all(Array.from({ length: workers }, () => queueNext()));
|
|
727
|
-
}
|
|
728
|
-
await refillQueue();
|
|
729
|
-
return { errors };
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
//#endregion
|
|
733
|
-
export { genSafeVariableName as a, scanHandlers as c, genObjectFromRaw as i, writeTypes as n, genString as o, genImport as r, scanAndSyncOptions as s, runParallel as t };
|