nitro-nightly 3.0.1-20251203-124705-dbc1cd2d → 3.0.1-20251204-002632-497db05f
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/rolldown.mjs +5 -5
- package/dist/_build/rollup.mjs +5 -5
- package/dist/_build/vite.build.mjs +6 -6
- package/dist/_build/vite.plugin.mjs +24 -22
- package/dist/_chunks/{_yl3G_3Y.mjs → CvxEFBdh.mjs} +4 -2
- package/dist/_chunks/{C3_uRBf2.mjs → D-63lyig.mjs} +2 -2
- package/dist/{_dev.mjs → _chunks/Ddq6HHrM.mjs} +22 -23
- package/dist/_chunks/{XHOrB-Xs.mjs → Ddt06bL8.mjs} +1 -1
- package/dist/_chunks/{rU_kdJ2P.mjs → Dkk4dpNb.mjs} +447 -284
- package/dist/_libs/local-pkg.mjs +1 -1
- package/dist/_libs/std-env.mjs +1 -1
- package/dist/_libs/unimport.mjs +1 -1
- package/dist/_libs/unwasm.mjs +15 -5
- package/dist/_presets.mjs +1 -6
- package/dist/builder.d.mts +4 -4
- package/dist/builder.mjs +3 -3
- package/dist/cli/_chunks/dev.mjs +1 -1
- package/dist/runtime/internal/vite/{dev-worker.mjs → node-runner.mjs} +31 -6
- package/dist/runtime/meta.d.mts +1 -1
- package/dist/runtime/meta.mjs +1 -1
- package/dist/types/index.d.mts +40 -42
- package/dist/vite.mjs +5 -5
- package/package.json +8 -4
|
@@ -1,28 +1,46 @@
|
|
|
1
1
|
import { i as __toESM } from "./QkUO_zA6.mjs";
|
|
2
|
-
import { O as relative, T as normalize,
|
|
3
|
-
import {
|
|
2
|
+
import { C as isAbsolute, O as relative, T as normalize, h as resolveModulePath, k as resolve, w as join } from "../_libs/c12.mjs";
|
|
3
|
+
import { s as parseNodeModulePath } from "../_libs/local-pkg.mjs";
|
|
4
4
|
import { i as unplugin } from "../_libs/unimport.mjs";
|
|
5
5
|
import { t as glob } from "../_libs/tinyglobby.mjs";
|
|
6
|
+
import { i as a, r as T, t as A } from "../_libs/std-env.mjs";
|
|
6
7
|
import { t as src_default } from "../_libs/mime.mjs";
|
|
7
8
|
import { i as genSafeVariableName, t as genImport } from "../_libs/knitwork.mjs";
|
|
8
|
-
import { t as unwasm } from "../_libs/unwasm.mjs";
|
|
9
|
-
import { t as replace } from "../_libs/plugin-replace.mjs";
|
|
10
9
|
import { t as require_etag } from "../_libs/etag.mjs";
|
|
10
|
+
import { t as replace } from "../_libs/plugin-replace.mjs";
|
|
11
|
+
import { t as unwasm } from "../_libs/unwasm.mjs";
|
|
12
|
+
import { builtinModules, createRequire } from "node:module";
|
|
13
|
+
import { consola } from "consola";
|
|
11
14
|
import { camelCase } from "scule";
|
|
12
15
|
import { promises } from "node:fs";
|
|
13
16
|
import { joinURL, withTrailingSlash } from "ufo";
|
|
14
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
18
|
import { readFile } from "node:fs/promises";
|
|
16
|
-
import {
|
|
17
|
-
import { pkgDir, presetsDir, runtimeDependencies, runtimeDir } from "nitro/meta";
|
|
19
|
+
import { pkgDir, runtimeDir } from "nitro/meta";
|
|
18
20
|
import { hash } from "ohash";
|
|
19
21
|
import { defineEnv } from "unenv";
|
|
20
|
-
import { transformSync } from "oxc-transform";
|
|
21
|
-
import { rollupNodeFileTrace } from "nf3";
|
|
22
22
|
import { connectors } from "db0";
|
|
23
23
|
import { RENDER_CONTEXT_KEYS, compileTemplateToString, hasTemplateSyntax } from "rendu";
|
|
24
24
|
import { builtinDrivers, normalizeKey } from "unstorage";
|
|
25
|
+
import { transformSync } from "oxc-transform";
|
|
26
|
+
|
|
27
|
+
//#region src/utils/regex.ts
|
|
28
|
+
function escapeRegExp(string) {
|
|
29
|
+
return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
|
|
30
|
+
}
|
|
31
|
+
function pathRegExp(string) {
|
|
32
|
+
if (A) string = string.replace(/\\/g, "/");
|
|
33
|
+
let escaped = escapeRegExp(string);
|
|
34
|
+
if (A) escaped = escaped.replace(/\//g, String.raw`[/\\]`);
|
|
35
|
+
return escaped;
|
|
36
|
+
}
|
|
37
|
+
function toPathRegExp(input) {
|
|
38
|
+
if (input instanceof RegExp) return input;
|
|
39
|
+
if (typeof input === "string") return new RegExp(pathRegExp(input));
|
|
40
|
+
throw new TypeError("Expected a string or RegExp", { cause: input });
|
|
41
|
+
}
|
|
25
42
|
|
|
43
|
+
//#endregion
|
|
26
44
|
//#region src/build/config.ts
|
|
27
45
|
function baseBuildConfig(nitro) {
|
|
28
46
|
const extensions = [
|
|
@@ -50,22 +68,6 @@ function baseBuildConfig(nitro) {
|
|
|
50
68
|
...Object.fromEntries(Object.entries(importMetaInjections).map(([key, val]) => [`import.meta.${key}`, JSON.stringify(val)])),
|
|
51
69
|
...nitro.options.replace
|
|
52
70
|
};
|
|
53
|
-
const noExternal = [
|
|
54
|
-
"#",
|
|
55
|
-
"~",
|
|
56
|
-
"@/",
|
|
57
|
-
"~~",
|
|
58
|
-
"@@/",
|
|
59
|
-
"virtual:",
|
|
60
|
-
"nitro",
|
|
61
|
-
pkgDir,
|
|
62
|
-
nitro.options.serverDir,
|
|
63
|
-
nitro.options.buildDir,
|
|
64
|
-
dirname(nitro.options.entry),
|
|
65
|
-
...nitro.options.wasm === false ? [] : [(id) => id.endsWith(".wasm")],
|
|
66
|
-
...nitro.options.handlers.map((m) => m.handler).filter((i) => typeof i === "string"),
|
|
67
|
-
...nitro.options.dev || nitro.options.preset === "nitro-prerender" ? [] : runtimeDependencies
|
|
68
|
-
].filter(Boolean);
|
|
69
71
|
const { env } = defineEnv({
|
|
70
72
|
nodeCompat: isNodeless,
|
|
71
73
|
resolve: true,
|
|
@@ -73,17 +75,27 @@ function baseBuildConfig(nitro) {
|
|
|
73
75
|
overrides: { alias: nitro.options.alias }
|
|
74
76
|
});
|
|
75
77
|
return {
|
|
76
|
-
presetsDir,
|
|
77
78
|
extensions,
|
|
78
79
|
isNodeless,
|
|
79
80
|
replacements,
|
|
80
81
|
env,
|
|
81
82
|
aliases: resolveAliases({ ...env.alias }),
|
|
82
|
-
noExternal
|
|
83
|
+
noExternal: getNoExternals(nitro)
|
|
83
84
|
};
|
|
84
85
|
}
|
|
86
|
+
function getNoExternals(nitro) {
|
|
87
|
+
const noExternal = [
|
|
88
|
+
/\.[mc]?tsx?$/,
|
|
89
|
+
/^(?:[\0#~.]|virtual:)/,
|
|
90
|
+
/* @__PURE__ */ new RegExp("^" + pathRegExp(pkgDir) + "(?!.*node_modules)"),
|
|
91
|
+
...[nitro.options.rootDir, ...nitro.options.scanDirs.filter((dir) => dir.includes("node_modules") || !dir.startsWith(nitro.options.rootDir))].map((dir) => /* @__PURE__ */ new RegExp("^" + pathRegExp(dir) + "(?!.*node_modules)"))
|
|
92
|
+
];
|
|
93
|
+
if (nitro.options.wasm !== false) noExternal.push(/\.wasm$/);
|
|
94
|
+
if (Array.isArray(nitro.options.noExternals)) noExternal.push(...nitro.options.noExternals.filter(Boolean).map((item) => toPathRegExp(item)));
|
|
95
|
+
return noExternal.sort((a$1, b) => a$1.source.length - b.source.length);
|
|
96
|
+
}
|
|
85
97
|
function resolveAliases(_aliases) {
|
|
86
|
-
const aliases = Object.fromEntries(Object.entries(_aliases).sort(([a], [b]) => b.split("/").length - a.split("/").length || b.length - a.length));
|
|
98
|
+
const aliases = Object.fromEntries(Object.entries(_aliases).sort(([a$1], [b]) => b.split("/").length - a$1.split("/").length || b.length - a$1.length));
|
|
87
99
|
for (const key in aliases) for (const alias in aliases) {
|
|
88
100
|
if (![
|
|
89
101
|
"~",
|
|
@@ -137,243 +149,6 @@ function routeToFsPath(route) {
|
|
|
137
149
|
return route.split("/").slice(1).map((s) => `${s.replace(/[:*]+/g, "$").replace(/[^$a-zA-Z0-9_.[\]/]/g, "_")}`).join("/") || "index";
|
|
138
150
|
}
|
|
139
151
|
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/utils/regex.ts
|
|
142
|
-
function escapeRegExp(string) {
|
|
143
|
-
return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region src/build/plugins/route-meta.ts
|
|
148
|
-
const PREFIX$2 = "\0nitro:route-meta:";
|
|
149
|
-
function routeMeta(nitro) {
|
|
150
|
-
return {
|
|
151
|
-
name: "nitro:route-meta",
|
|
152
|
-
resolveId: {
|
|
153
|
-
filter: { id: /^(?!\u0000)(.+)\?meta$/ },
|
|
154
|
-
async handler(id, importer, resolveOpts) {
|
|
155
|
-
if (id.endsWith("?meta")) {
|
|
156
|
-
const resolved = await this.resolve(id.replace("?meta", ""), importer, resolveOpts);
|
|
157
|
-
if (!resolved) return;
|
|
158
|
-
return PREFIX$2 + resolved.id;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
load: {
|
|
163
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX$2)}`) },
|
|
164
|
-
handler(id) {
|
|
165
|
-
if (id.startsWith(PREFIX$2)) return readFile(id.slice(18), { encoding: "utf8" });
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
transform: {
|
|
169
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX$2)}`) },
|
|
170
|
-
async handler(code, id) {
|
|
171
|
-
let meta = null;
|
|
172
|
-
try {
|
|
173
|
-
const jsCode = transformSync(id, code).code;
|
|
174
|
-
const ast = this.parse(jsCode);
|
|
175
|
-
for (const node of ast.body) if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "defineRouteMeta" && node.expression.arguments.length === 1) {
|
|
176
|
-
meta = astToObject(node.expression.arguments[0]);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
} catch (error) {
|
|
180
|
-
nitro.logger.warn(`[handlers-meta] Cannot extra route meta for: ${id}: ${error}`);
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
code: `export default ${JSON.stringify(meta)};`,
|
|
184
|
-
map: null
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function astToObject(node) {
|
|
191
|
-
switch (node.type) {
|
|
192
|
-
case "ObjectExpression": {
|
|
193
|
-
const obj = {};
|
|
194
|
-
for (const prop of node.properties) if (prop.type === "Property") {
|
|
195
|
-
const key = prop.key.name ?? prop.key.value;
|
|
196
|
-
obj[key] = astToObject(prop.value);
|
|
197
|
-
}
|
|
198
|
-
return obj;
|
|
199
|
-
}
|
|
200
|
-
case "ArrayExpression": return node.elements.map((el) => astToObject(el)).filter(Boolean);
|
|
201
|
-
case "Literal": return node.value;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/build/plugins/server-main.ts
|
|
207
|
-
function serverMain(nitro) {
|
|
208
|
-
return {
|
|
209
|
-
name: "nitro:server-main",
|
|
210
|
-
renderChunk(code, chunk) {
|
|
211
|
-
if (chunk.isEntry) return {
|
|
212
|
-
code: `globalThis.__nitro_main__ = import.meta.url; ${code}`,
|
|
213
|
-
map: null
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
//#endregion
|
|
220
|
-
//#region src/build/plugins/virtual.ts
|
|
221
|
-
const PREFIX$1 = "\0nitro:virtual:";
|
|
222
|
-
function virtual(input) {
|
|
223
|
-
const modules = /* @__PURE__ */ new Map();
|
|
224
|
-
for (const mod of input) {
|
|
225
|
-
const render = () => typeof mod.template === "function" ? mod.template() : mod.template;
|
|
226
|
-
modules.set(mod.id, {
|
|
227
|
-
module: mod,
|
|
228
|
-
render
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return {
|
|
232
|
-
name: "nitro:virtual",
|
|
233
|
-
api: { modules },
|
|
234
|
-
resolveId: {
|
|
235
|
-
order: "pre",
|
|
236
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^(${[...modules.keys()].map((id) => escapeRegExp(id)).join("|")})$`) },
|
|
237
|
-
handler: (id) => {
|
|
238
|
-
const mod = modules.get(id);
|
|
239
|
-
if (!mod) return null;
|
|
240
|
-
return {
|
|
241
|
-
id: PREFIX$1 + id,
|
|
242
|
-
moduleSideEffects: mod.module.moduleSideEffects ?? false
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
load: {
|
|
247
|
-
order: "pre",
|
|
248
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX$1)}`) },
|
|
249
|
-
handler: async (id) => {
|
|
250
|
-
const idNoPrefix = id.slice(15);
|
|
251
|
-
const mod = modules.get(idNoPrefix);
|
|
252
|
-
if (!mod) throw new Error(`Virtual module ${idNoPrefix} not found.`);
|
|
253
|
-
return {
|
|
254
|
-
code: await mod.render(),
|
|
255
|
-
map: null
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/build/plugins/resolve.ts
|
|
264
|
-
const subpathMap = {
|
|
265
|
-
"nitro/h3": "h3",
|
|
266
|
-
"nitro/deps/h3": "h3",
|
|
267
|
-
"nitro/deps/ofetch": "ofetch"
|
|
268
|
-
};
|
|
269
|
-
function nitroResolveIds() {
|
|
270
|
-
return {
|
|
271
|
-
name: "nitro:resolve-ids",
|
|
272
|
-
resolveId: {
|
|
273
|
-
order: "pre",
|
|
274
|
-
handler(id, importer, rOpts) {
|
|
275
|
-
if (importer && importer.startsWith("\0nitro:virtual:#nitro-internal-virtual")) return this.resolve(id, runtimeDir, { skipSelf: true });
|
|
276
|
-
const mappedId = subpathMap[id];
|
|
277
|
-
if (mappedId) return this.resolve(mappedId, runtimeDir, { skipSelf: true });
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region src/build/plugins/sourcemap-min.ts
|
|
285
|
-
function sourcemapMinify() {
|
|
286
|
-
return {
|
|
287
|
-
name: "nitro:sourcemap-minify",
|
|
288
|
-
generateBundle(_options, bundle) {
|
|
289
|
-
for (const [key, asset] of Object.entries(bundle)) {
|
|
290
|
-
if (!key.endsWith(".map") || !("source" in asset) || typeof asset.source !== "string") continue;
|
|
291
|
-
const sourcemap = JSON.parse(asset.source);
|
|
292
|
-
delete sourcemap.sourcesContent;
|
|
293
|
-
delete sourcemap.x_google_ignoreList;
|
|
294
|
-
if ((sourcemap.sources || []).some((s) => s.includes("node_modules"))) sourcemap.mappings = "";
|
|
295
|
-
asset.source = JSON.stringify(sourcemap);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
//#endregion
|
|
302
|
-
//#region src/build/plugins/raw.ts
|
|
303
|
-
const HELPER_ID = "\0nitro-raw-helpers";
|
|
304
|
-
const RESOLVED_PREFIX = "\0nitro:raw:";
|
|
305
|
-
const PREFIX = "raw:";
|
|
306
|
-
function raw() {
|
|
307
|
-
return {
|
|
308
|
-
name: "nitro:raw",
|
|
309
|
-
resolveId: {
|
|
310
|
-
order: "pre",
|
|
311
|
-
filter: { id: [/* @__PURE__ */ new RegExp(`^${HELPER_ID}$`), /* @__PURE__ */ new RegExp(`^${PREFIX}`)] },
|
|
312
|
-
async handler(id, importer, resolveOpts) {
|
|
313
|
-
if (id === HELPER_ID) return id;
|
|
314
|
-
if (id.startsWith(PREFIX)) {
|
|
315
|
-
const resolvedId = (await this.resolve(id.slice(4), importer, resolveOpts))?.id;
|
|
316
|
-
if (!resolvedId) return null;
|
|
317
|
-
return { id: RESOLVED_PREFIX + resolvedId };
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
load: {
|
|
322
|
-
order: "pre",
|
|
323
|
-
filter: { id: [/* @__PURE__ */ new RegExp(`^${HELPER_ID}$`), /* @__PURE__ */ new RegExp(`^${RESOLVED_PREFIX}`)] },
|
|
324
|
-
handler(id) {
|
|
325
|
-
if (id === HELPER_ID) return getHelpers();
|
|
326
|
-
if (id.startsWith(RESOLVED_PREFIX)) return promises.readFile(id.slice(11), isBinary(id) ? "binary" : "utf8");
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
transform: {
|
|
330
|
-
order: "pre",
|
|
331
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^${RESOLVED_PREFIX}`) },
|
|
332
|
-
handler(code, id) {
|
|
333
|
-
const path = id.slice(11);
|
|
334
|
-
if (isBinary(id)) return {
|
|
335
|
-
code: `import {base64ToUint8Array } from "${HELPER_ID}" \n export default base64ToUint8Array("${Buffer.from(code, "binary").toString("base64")}")`,
|
|
336
|
-
map: rawAssetMap(path)
|
|
337
|
-
};
|
|
338
|
-
return {
|
|
339
|
-
code: `export default ${JSON.stringify(code)}`,
|
|
340
|
-
map: rawAssetMap(path),
|
|
341
|
-
moduleType: "js"
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
function isBinary(id) {
|
|
348
|
-
const idMime = src_default.getType(id) || "";
|
|
349
|
-
if (idMime.startsWith("text/")) return false;
|
|
350
|
-
if (/application\/(json|sql|xml|yaml)/.test(idMime)) return false;
|
|
351
|
-
return true;
|
|
352
|
-
}
|
|
353
|
-
function getHelpers() {
|
|
354
|
-
return `
|
|
355
|
-
export function base64ToUint8Array(str) {
|
|
356
|
-
const data = atob(str);
|
|
357
|
-
const size = data.length;
|
|
358
|
-
const bytes = new Uint8Array(size);
|
|
359
|
-
for (let i = 0; i < size; i++) {
|
|
360
|
-
bytes[i] = data.charCodeAt(i);
|
|
361
|
-
}
|
|
362
|
-
return bytes;
|
|
363
|
-
}
|
|
364
|
-
`;
|
|
365
|
-
}
|
|
366
|
-
function rawAssetMap(id) {
|
|
367
|
-
return {
|
|
368
|
-
version: 3,
|
|
369
|
-
file: id,
|
|
370
|
-
sources: [id],
|
|
371
|
-
sourcesContent: [],
|
|
372
|
-
names: [],
|
|
373
|
-
mappings: ""
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
|
|
377
152
|
//#endregion
|
|
378
153
|
//#region src/build/virtual/database.ts
|
|
379
154
|
function database(nitro) {
|
|
@@ -922,8 +697,403 @@ function virtualTemplates(nitro, _polyfills) {
|
|
|
922
697
|
}
|
|
923
698
|
|
|
924
699
|
//#endregion
|
|
925
|
-
//#region src/build/plugins.ts
|
|
926
|
-
|
|
700
|
+
//#region src/build/plugins/route-meta.ts
|
|
701
|
+
const PREFIX$2 = "\0nitro:route-meta:";
|
|
702
|
+
function routeMeta(nitro) {
|
|
703
|
+
return {
|
|
704
|
+
name: "nitro:route-meta",
|
|
705
|
+
resolveId: {
|
|
706
|
+
filter: { id: /^(?!\u0000)(.+)\?meta$/ },
|
|
707
|
+
async handler(id, importer, resolveOpts) {
|
|
708
|
+
if (id.endsWith("?meta")) {
|
|
709
|
+
const resolved = await this.resolve(id.replace("?meta", ""), importer, resolveOpts);
|
|
710
|
+
if (!resolved) return;
|
|
711
|
+
return PREFIX$2 + resolved.id;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
load: {
|
|
716
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX$2)}`) },
|
|
717
|
+
handler(id) {
|
|
718
|
+
if (id.startsWith(PREFIX$2)) return readFile(id.slice(18), { encoding: "utf8" });
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
transform: {
|
|
722
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX$2)}`) },
|
|
723
|
+
async handler(code, id) {
|
|
724
|
+
let meta = null;
|
|
725
|
+
try {
|
|
726
|
+
const jsCode = transformSync(id, code).code;
|
|
727
|
+
const ast = this.parse(jsCode);
|
|
728
|
+
for (const node of ast.body) if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "defineRouteMeta" && node.expression.arguments.length === 1) {
|
|
729
|
+
meta = astToObject(node.expression.arguments[0]);
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
} catch (error) {
|
|
733
|
+
nitro.logger.warn(`[handlers-meta] Cannot extra route meta for: ${id}: ${error}`);
|
|
734
|
+
}
|
|
735
|
+
return {
|
|
736
|
+
code: `export default ${JSON.stringify(meta)};`,
|
|
737
|
+
map: null
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function astToObject(node) {
|
|
744
|
+
switch (node.type) {
|
|
745
|
+
case "ObjectExpression": {
|
|
746
|
+
const obj = {};
|
|
747
|
+
for (const prop of node.properties) if (prop.type === "Property") {
|
|
748
|
+
const key = prop.key.name ?? prop.key.value;
|
|
749
|
+
obj[key] = astToObject(prop.value);
|
|
750
|
+
}
|
|
751
|
+
return obj;
|
|
752
|
+
}
|
|
753
|
+
case "ArrayExpression": return node.elements.map((el) => astToObject(el)).filter(Boolean);
|
|
754
|
+
case "Literal": return node.value;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
//#endregion
|
|
759
|
+
//#region src/build/plugins/server-main.ts
|
|
760
|
+
function serverMain(nitro) {
|
|
761
|
+
return {
|
|
762
|
+
name: "nitro:server-main",
|
|
763
|
+
renderChunk(code, chunk) {
|
|
764
|
+
if (chunk.isEntry) return {
|
|
765
|
+
code: `globalThis.__nitro_main__ = import.meta.url; ${code}`,
|
|
766
|
+
map: null
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/build/plugins/virtual.ts
|
|
774
|
+
const PREFIX$1 = "\0nitro:virtual:";
|
|
775
|
+
function virtual(input) {
|
|
776
|
+
const modules = /* @__PURE__ */ new Map();
|
|
777
|
+
for (const mod of input) {
|
|
778
|
+
const render = () => typeof mod.template === "function" ? mod.template() : mod.template;
|
|
779
|
+
modules.set(mod.id, {
|
|
780
|
+
module: mod,
|
|
781
|
+
render
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
name: "nitro:virtual",
|
|
786
|
+
api: { modules },
|
|
787
|
+
resolveId: {
|
|
788
|
+
order: "pre",
|
|
789
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^(${[...modules.keys()].map((id) => pathRegExp(id)).join("|")})$`) },
|
|
790
|
+
handler: (id) => {
|
|
791
|
+
const mod = modules.get(id);
|
|
792
|
+
if (!mod) return null;
|
|
793
|
+
return {
|
|
794
|
+
id: PREFIX$1 + id,
|
|
795
|
+
moduleSideEffects: mod.module.moduleSideEffects ?? false
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
load: {
|
|
800
|
+
order: "pre",
|
|
801
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX$1)}`) },
|
|
802
|
+
handler: async (id) => {
|
|
803
|
+
const idNoPrefix = id.slice(15);
|
|
804
|
+
const mod = modules.get(idNoPrefix);
|
|
805
|
+
if (!mod) throw new Error(`Virtual module ${idNoPrefix} not found.`);
|
|
806
|
+
return {
|
|
807
|
+
code: await mod.render(),
|
|
808
|
+
map: null
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
//#endregion
|
|
816
|
+
//#region src/build/plugins/resolve.ts
|
|
817
|
+
const subpathMap = {
|
|
818
|
+
"nitro/h3": "h3",
|
|
819
|
+
"nitro/deps/h3": "h3",
|
|
820
|
+
"nitro/deps/ofetch": "ofetch"
|
|
821
|
+
};
|
|
822
|
+
function nitroResolveIds() {
|
|
823
|
+
return {
|
|
824
|
+
name: "nitro:resolve-ids",
|
|
825
|
+
resolveId: {
|
|
826
|
+
order: "pre",
|
|
827
|
+
handler(id, importer, rOpts) {
|
|
828
|
+
if (importer && importer.startsWith("\0nitro:virtual:#nitro-internal-virtual")) return this.resolve(id, runtimeDir, { skipSelf: true });
|
|
829
|
+
const mappedId = subpathMap[id];
|
|
830
|
+
if (mappedId) return this.resolve(mappedId, runtimeDir, { skipSelf: true });
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
//#endregion
|
|
837
|
+
//#region src/build/plugins/sourcemap-min.ts
|
|
838
|
+
function sourcemapMinify() {
|
|
839
|
+
return {
|
|
840
|
+
name: "nitro:sourcemap-minify",
|
|
841
|
+
generateBundle(_options, bundle) {
|
|
842
|
+
for (const [key, asset] of Object.entries(bundle)) {
|
|
843
|
+
if (!key.endsWith(".map") || !("source" in asset) || typeof asset.source !== "string") continue;
|
|
844
|
+
const sourcemap = JSON.parse(asset.source);
|
|
845
|
+
delete sourcemap.sourcesContent;
|
|
846
|
+
delete sourcemap.x_google_ignoreList;
|
|
847
|
+
if ((sourcemap.sources || []).some((s) => s.includes("node_modules"))) sourcemap.mappings = "";
|
|
848
|
+
asset.source = JSON.stringify(sourcemap);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region src/build/plugins/raw.ts
|
|
856
|
+
const HELPER_ID = "\0nitro-raw-helpers";
|
|
857
|
+
const RESOLVED_PREFIX = "\0nitro:raw:";
|
|
858
|
+
const PREFIX = "raw:";
|
|
859
|
+
function raw() {
|
|
860
|
+
return {
|
|
861
|
+
name: "nitro:raw",
|
|
862
|
+
resolveId: {
|
|
863
|
+
order: "pre",
|
|
864
|
+
filter: { id: [/* @__PURE__ */ new RegExp(`^${HELPER_ID}$`), /* @__PURE__ */ new RegExp(`^${PREFIX}`)] },
|
|
865
|
+
async handler(id, importer, resolveOpts) {
|
|
866
|
+
if (id === HELPER_ID) return id;
|
|
867
|
+
if (id.startsWith(PREFIX)) {
|
|
868
|
+
const resolvedId = (await this.resolve(id.slice(4), importer, resolveOpts))?.id;
|
|
869
|
+
if (!resolvedId) return null;
|
|
870
|
+
return { id: RESOLVED_PREFIX + resolvedId };
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
load: {
|
|
875
|
+
order: "pre",
|
|
876
|
+
filter: { id: [/* @__PURE__ */ new RegExp(`^${HELPER_ID}$`), /* @__PURE__ */ new RegExp(`^${RESOLVED_PREFIX}`)] },
|
|
877
|
+
handler(id) {
|
|
878
|
+
if (id === HELPER_ID) return getHelpers();
|
|
879
|
+
if (id.startsWith(RESOLVED_PREFIX)) return promises.readFile(id.slice(11), isBinary(id) ? "binary" : "utf8");
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
transform: {
|
|
883
|
+
order: "pre",
|
|
884
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^${RESOLVED_PREFIX}`) },
|
|
885
|
+
handler(code, id) {
|
|
886
|
+
const path = id.slice(11);
|
|
887
|
+
if (isBinary(id)) return {
|
|
888
|
+
code: `import {base64ToUint8Array } from "${HELPER_ID}" \n export default base64ToUint8Array("${Buffer.from(code, "binary").toString("base64")}")`,
|
|
889
|
+
map: rawAssetMap(path)
|
|
890
|
+
};
|
|
891
|
+
return {
|
|
892
|
+
code: `export default ${JSON.stringify(code)}`,
|
|
893
|
+
map: rawAssetMap(path),
|
|
894
|
+
moduleType: "js"
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
function isBinary(id) {
|
|
901
|
+
const idMime = src_default.getType(id) || "";
|
|
902
|
+
if (idMime.startsWith("text/")) return false;
|
|
903
|
+
if (/application\/(json|sql|xml|yaml)/.test(idMime)) return false;
|
|
904
|
+
return true;
|
|
905
|
+
}
|
|
906
|
+
function getHelpers() {
|
|
907
|
+
return `
|
|
908
|
+
export function base64ToUint8Array(str) {
|
|
909
|
+
const data = atob(str);
|
|
910
|
+
const size = data.length;
|
|
911
|
+
const bytes = new Uint8Array(size);
|
|
912
|
+
for (let i = 0; i < size; i++) {
|
|
913
|
+
bytes[i] = data.charCodeAt(i);
|
|
914
|
+
}
|
|
915
|
+
return bytes;
|
|
916
|
+
}
|
|
917
|
+
`;
|
|
918
|
+
}
|
|
919
|
+
function rawAssetMap(id) {
|
|
920
|
+
return {
|
|
921
|
+
version: 3,
|
|
922
|
+
file: id,
|
|
923
|
+
sources: [id],
|
|
924
|
+
sourcesContent: [],
|
|
925
|
+
names: [],
|
|
926
|
+
mappings: ""
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/utils/dep.ts
|
|
932
|
+
async function importDep(opts, _retry) {
|
|
933
|
+
const resolved = resolveModulePath(opts.id, {
|
|
934
|
+
from: [opts.dir, import.meta.url],
|
|
935
|
+
cache: _retry ? false : true,
|
|
936
|
+
try: true
|
|
937
|
+
});
|
|
938
|
+
if (resolved) return await import(resolved);
|
|
939
|
+
let shouldInstall;
|
|
940
|
+
if (_retry || a) shouldInstall = false;
|
|
941
|
+
else if (T) {
|
|
942
|
+
consola.info(`\`${opts.id}\` is required for ${opts.reason}. Installing automatically in CI environment...`);
|
|
943
|
+
shouldInstall = true;
|
|
944
|
+
} else shouldInstall = await consola.prompt(`\`${opts.id}\` is required for ${opts.reason}, but it is not installed. Would you like to install it?`, {
|
|
945
|
+
type: "confirm",
|
|
946
|
+
default: true,
|
|
947
|
+
cancel: "undefined"
|
|
948
|
+
});
|
|
949
|
+
if (!shouldInstall) throw new Error(`\`${opts.id}\` is not installed. Please add it to your dependencies for ${opts.reason}.`);
|
|
950
|
+
const start = Date.now();
|
|
951
|
+
consola.start(`Installing \`${opts.id}\` in \`${opts.dir}\`...`);
|
|
952
|
+
const { addDevDependency } = await import("../cli/_chunks/dist4.mjs");
|
|
953
|
+
await addDevDependency(opts.id, { cwd: opts.dir });
|
|
954
|
+
consola.success(`Installed \`${opts.id}\` in ${opts.dir} (${Date.now() - start}ms).`);
|
|
955
|
+
return importDep(opts, true);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
//#endregion
|
|
959
|
+
//#region src/build/plugins/externals.ts
|
|
960
|
+
const PLUGIN_NAME = "nitro:externals";
|
|
961
|
+
function externals(opts) {
|
|
962
|
+
const include = opts?.include ? opts.include.map((p) => toPathRegExp(p)) : void 0;
|
|
963
|
+
const exclude = [/^(?:[\0#~.]|[a-z0-9]{2,}:)|\?/, ...(opts?.exclude || []).map((p) => toPathRegExp(p))];
|
|
964
|
+
const filter = (id) => {
|
|
965
|
+
if (include && !include.some((r) => r.test(id))) return false;
|
|
966
|
+
if (exclude.some((r) => r.test(id))) return false;
|
|
967
|
+
return true;
|
|
968
|
+
};
|
|
969
|
+
const tryResolve = (id, from) => resolveModulePath(id, {
|
|
970
|
+
try: true,
|
|
971
|
+
from: from && isAbsolute(from) ? from : opts.rootDir,
|
|
972
|
+
conditions: opts.conditions
|
|
973
|
+
});
|
|
974
|
+
const tracedPaths = /* @__PURE__ */ new Set();
|
|
975
|
+
return {
|
|
976
|
+
name: PLUGIN_NAME,
|
|
977
|
+
resolveId: {
|
|
978
|
+
order: "pre",
|
|
979
|
+
filter: { id: {
|
|
980
|
+
exclude,
|
|
981
|
+
include
|
|
982
|
+
} },
|
|
983
|
+
async handler(id, importer, rOpts) {
|
|
984
|
+
if (builtinModules.includes(id)) return {
|
|
985
|
+
resolvedBy: PLUGIN_NAME,
|
|
986
|
+
external: true,
|
|
987
|
+
id: id.includes(":") ? id : `node:${id}`
|
|
988
|
+
};
|
|
989
|
+
if (rOpts.custom?.["node-resolve"]) return null;
|
|
990
|
+
let resolved = await this.resolve(id, importer, rOpts);
|
|
991
|
+
const cjsResolved = resolved?.meta?.commonjs?.resolved;
|
|
992
|
+
if (cjsResolved) {
|
|
993
|
+
if (!filter(cjsResolved.id)) return resolved;
|
|
994
|
+
resolved = cjsResolved;
|
|
995
|
+
}
|
|
996
|
+
if (!resolved?.id || !filter(resolved.id)) return resolved;
|
|
997
|
+
let resolvedPath = resolved.id;
|
|
998
|
+
if (!isAbsolute(resolvedPath)) resolvedPath = tryResolve(resolvedPath, importer) || resolvedPath;
|
|
999
|
+
if (opts.trace) {
|
|
1000
|
+
let importId = toImport(id) || toImport(resolvedPath);
|
|
1001
|
+
if (!importId) return resolved;
|
|
1002
|
+
if (!tryResolve(importId, importer)) {
|
|
1003
|
+
const guessed = await guessSubpath(resolvedPath, opts.conditions);
|
|
1004
|
+
if (!guessed) return resolved;
|
|
1005
|
+
importId = guessed;
|
|
1006
|
+
}
|
|
1007
|
+
tracedPaths.add(resolvedPath);
|
|
1008
|
+
return {
|
|
1009
|
+
...resolved,
|
|
1010
|
+
resolvedBy: PLUGIN_NAME,
|
|
1011
|
+
external: true,
|
|
1012
|
+
id: importId
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
return {
|
|
1016
|
+
...resolved,
|
|
1017
|
+
resolvedBy: PLUGIN_NAME,
|
|
1018
|
+
external: true,
|
|
1019
|
+
id: isAbsolute(resolvedPath) ? pathToFileURL(resolvedPath).href : resolvedPath
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
buildEnd: {
|
|
1024
|
+
order: "post",
|
|
1025
|
+
async handler() {
|
|
1026
|
+
if (!opts.trace || tracedPaths.size === 0) return;
|
|
1027
|
+
const { traceNodeModules } = await importDep({
|
|
1028
|
+
id: "nf3",
|
|
1029
|
+
dir: opts.rootDir,
|
|
1030
|
+
reason: "tracing external dependencies"
|
|
1031
|
+
});
|
|
1032
|
+
await traceNodeModules([...tracedPaths], {
|
|
1033
|
+
...opts.trace,
|
|
1034
|
+
exportConditions: opts.conditions,
|
|
1035
|
+
rootDir: opts.rootDir,
|
|
1036
|
+
writePackageJson: true,
|
|
1037
|
+
traceOptions: {
|
|
1038
|
+
base: "/",
|
|
1039
|
+
exportsOnly: true,
|
|
1040
|
+
processCwd: opts.rootDir
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
const NODE_MODULES_RE = /^(?<dir>.+\/node_modules\/)(?<name>[^/@]+|@[^/]+\/[^/]+)(?:\/(?<subpath>.+))?$/;
|
|
1048
|
+
const IMPORT_RE = /^(?!\.)(?<name>[^/@]+|@[^/]+\/[^/]+)(?:\/(?<subpath>.+))?$/;
|
|
1049
|
+
function toImport(id) {
|
|
1050
|
+
if (isAbsolute(id)) {
|
|
1051
|
+
const { name, subpath } = NODE_MODULES_RE.exec(id)?.groups || {};
|
|
1052
|
+
if (name && subpath) return join(name, subpath);
|
|
1053
|
+
} else if (IMPORT_RE.test(id)) return id;
|
|
1054
|
+
}
|
|
1055
|
+
function guessSubpath(path, conditions) {
|
|
1056
|
+
const { dir, name, subpath } = NODE_MODULES_RE.exec(path)?.groups || {};
|
|
1057
|
+
if (!dir || !name || !subpath) return;
|
|
1058
|
+
const exports = getPkgJSON(join(dir, name) + "/")?.exports;
|
|
1059
|
+
if (!exports || typeof exports !== "object") return;
|
|
1060
|
+
for (const e of flattenExports(exports)) {
|
|
1061
|
+
if (!conditions.includes(e.condition || "default")) continue;
|
|
1062
|
+
if (e.fsPath === subpath) return join(name, e.subpath);
|
|
1063
|
+
if (e.fsPath.includes("*")) {
|
|
1064
|
+
const fsPathRe = /* @__PURE__ */ new RegExp("^" + escapeRegExp(e.fsPath).replace(String.raw`\*`, "(.+?)") + "$");
|
|
1065
|
+
if (fsPathRe.test(subpath)) {
|
|
1066
|
+
const matched = fsPathRe.exec(subpath)?.[1];
|
|
1067
|
+
if (matched) return join(name, e.subpath.replace("*", matched));
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function getPkgJSON(dir) {
|
|
1073
|
+
const cache = getPkgJSON._cache ||= /* @__PURE__ */ new Map();
|
|
1074
|
+
if (cache.has(dir)) return cache.get(dir);
|
|
1075
|
+
try {
|
|
1076
|
+
const pkg = createRequire(dir)("./package.json");
|
|
1077
|
+
cache.set(dir, pkg);
|
|
1078
|
+
return pkg;
|
|
1079
|
+
} catch {}
|
|
1080
|
+
}
|
|
1081
|
+
function flattenExports(exports = {}, parentSubpath = "./") {
|
|
1082
|
+
return Object.entries(exports).flatMap(([key, value]) => {
|
|
1083
|
+
const [subpath, condition] = key.startsWith(".") ? [key.slice(1)] : [void 0, key];
|
|
1084
|
+
const _subPath = join(parentSubpath, subpath || "");
|
|
1085
|
+
if (typeof value === "string") return [{
|
|
1086
|
+
subpath: _subPath,
|
|
1087
|
+
fsPath: value.replace(/^\.\//, ""),
|
|
1088
|
+
condition
|
|
1089
|
+
}];
|
|
1090
|
+
return typeof value === "object" ? flattenExports(value, _subPath) : [];
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
//#endregion
|
|
1095
|
+
//#region src/build/plugins.ts
|
|
1096
|
+
function baseBuildPlugins(nitro, base) {
|
|
927
1097
|
const plugins$1 = [];
|
|
928
1098
|
if (nitro.options.imports) plugins$1.push(unplugin.rollup(nitro.options.imports));
|
|
929
1099
|
if (nitro.options.wasm !== false) plugins$1.push(unwasm(nitro.options.wasm || {}));
|
|
@@ -938,23 +1108,16 @@ function baseBuildPlugins(nitro, base) {
|
|
|
938
1108
|
preventAssignment: true,
|
|
939
1109
|
values: base.replacements
|
|
940
1110
|
}));
|
|
941
|
-
if (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
traceAlias: {
|
|
952
|
-
"h3-nightly": "h3",
|
|
953
|
-
...nitro.options.externals?.traceAlias
|
|
954
|
-
},
|
|
955
|
-
exportConditions: nitro.options.exportConditions,
|
|
956
|
-
writePackageJson: true
|
|
957
|
-
})));
|
|
1111
|
+
if (nitro.options.node && nitro.options.noExternals !== true) {
|
|
1112
|
+
const isDevOrPrerender = nitro.options.dev || nitro.options.preset === "nitro-prerender";
|
|
1113
|
+
plugins$1.push(externals({
|
|
1114
|
+
rootDir: nitro.options.rootDir,
|
|
1115
|
+
conditions: nitro.options.exportConditions || ["default"],
|
|
1116
|
+
exclude: [...base.noExternal],
|
|
1117
|
+
include: isDevOrPrerender ? void 0 : nitro.options.traceDeps,
|
|
1118
|
+
trace: isDevOrPrerender ? false : { outDir: nitro.options.output.serverDir }
|
|
1119
|
+
}));
|
|
1120
|
+
}
|
|
958
1121
|
if (nitro.options.sourcemap && !nitro.options.dev && nitro.options.experimental.sourcemapMinify !== false) plugins$1.push(sourcemapMinify());
|
|
959
1122
|
return plugins$1;
|
|
960
1123
|
}
|