nitro-nightly 3.0.1-20251127-003817-dd47a8df → 3.0.1-20251127-112821-2989d6be
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 +1 -1
- package/dist/_build/rollup.mjs +1 -1
- package/dist/_build/vite.build.mjs +2 -2
- package/dist/_build/vite.plugin.mjs +2 -2
- package/dist/_chunks/{BT4o98A6.mjs → CGEOOxsU.mjs} +623 -499
- package/dist/_chunks/{QnObqKaP.mjs → _yl3G_3Y.mjs} +41 -70
- package/dist/_dev.mjs +4 -9
- package/dist/builder.mjs +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -1
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +1 -1
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -1
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +1 -1
- package/dist/presets/azure/runtime/azure-swa.d.mts +1 -1
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/bun/runtime/bun.d.mts +1 -1
- package/dist/presets/bun/runtime/bun.mjs +1 -1
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +1 -1
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-deploy.mjs +1 -1
- package/dist/presets/deno/runtime/deno-server.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-server.mjs +1 -1
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +1 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +1 -1
- package/dist/presets/netlify/runtime/netlify.d.mts +1 -1
- package/dist/presets/netlify/runtime/netlify.mjs +1 -1
- package/dist/presets/node/runtime/node-cluster.d.mts +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +1 -1
- package/dist/presets/node/runtime/node-middleware.d.mts +1 -1
- package/dist/presets/node/runtime/node-middleware.mjs +1 -1
- package/dist/presets/node/runtime/node-server.d.mts +1 -1
- package/dist/presets/node/runtime/node-server.mjs +1 -1
- package/dist/presets/standard/runtime/server.d.mts +1 -1
- package/dist/presets/standard/runtime/server.mjs +1 -1
- package/dist/presets/stormkit/runtime/stormkit.d.mts +1 -1
- package/dist/presets/stormkit/runtime/stormkit.mjs +1 -1
- package/dist/presets/vercel/runtime/vercel.node.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.node.mjs +1 -1
- package/dist/presets/vercel/runtime/vercel.web.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.web.mjs +1 -1
- package/dist/presets/winterjs/runtime/winterjs.d.mts +1 -1
- package/dist/presets/winterjs/runtime/winterjs.mjs +1 -1
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +1 -1
- package/dist/runtime/internal/vite/dev-entry.mjs +1 -1
- package/dist/types/index.d.mts +6 -4
- package/dist/vite.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as __toESM } from "./OEiRXl0H.mjs";
|
|
2
|
-
import { O as relative, k as resolve, w as join, x as dirname } from "../_libs/c12.mjs";
|
|
2
|
+
import { O as relative, T as normalize, k as resolve, w as join, x as dirname } from "../_libs/c12.mjs";
|
|
3
3
|
import { c 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";
|
|
@@ -17,11 +17,11 @@ import { defu } from "defu";
|
|
|
17
17
|
import { pkgDir, presetsDir, runtimeDependencies, runtimeDir } from "nitro/meta";
|
|
18
18
|
import { hash } from "ohash";
|
|
19
19
|
import { defineEnv } from "unenv";
|
|
20
|
-
import { connectors } from "db0";
|
|
21
20
|
import { transformSync } from "oxc-transform";
|
|
22
|
-
import { builtinDrivers, normalizeKey } from "unstorage";
|
|
23
21
|
import { rollupNodeFileTrace } from "nf3";
|
|
22
|
+
import { connectors } from "db0";
|
|
24
23
|
import { RENDER_CONTEXT_KEYS, compileTemplateToString, hasTemplateSyntax } from "rendu";
|
|
24
|
+
import { builtinDrivers, normalizeKey } from "unstorage";
|
|
25
25
|
|
|
26
26
|
//#region src/build/config.ts
|
|
27
27
|
function baseBuildConfig(nitro) {
|
|
@@ -137,159 +137,6 @@ function routeToFsPath(route) {
|
|
|
137
137
|
return route.split("/").slice(1).map((s) => `${s.replace(/[:*]+/g, "$").replace(/[^$a-zA-Z0-9_.[\]/]/g, "_")}`).join("/") || "index";
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/build/plugins/virtual.ts
|
|
142
|
-
const PREFIX = "\0virtual:";
|
|
143
|
-
function virtual(modules, cache = {}, opts) {
|
|
144
|
-
const _modules = /* @__PURE__ */ new Map();
|
|
145
|
-
for (const [id, mod] of Object.entries(modules)) {
|
|
146
|
-
cache[id] = mod;
|
|
147
|
-
_modules.set(id, mod);
|
|
148
|
-
_modules.set(resolve(id), mod);
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
name: "virtual",
|
|
152
|
-
resolveId(id, importer) {
|
|
153
|
-
if (id in modules) return {
|
|
154
|
-
id: PREFIX + id,
|
|
155
|
-
...opts
|
|
156
|
-
};
|
|
157
|
-
if (importer) {
|
|
158
|
-
const resolved = resolve(dirname(importer.startsWith(PREFIX) ? importer.slice(9) : importer), id);
|
|
159
|
-
if (_modules.has(resolved)) return PREFIX + resolved;
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
},
|
|
163
|
-
async load(id) {
|
|
164
|
-
if (!id.startsWith(PREFIX)) return null;
|
|
165
|
-
const idNoPrefix = id.slice(9);
|
|
166
|
-
if (!_modules.has(idNoPrefix)) return null;
|
|
167
|
-
let m = _modules.get(idNoPrefix);
|
|
168
|
-
if (typeof m === "function") m = await m();
|
|
169
|
-
if (!m) return null;
|
|
170
|
-
cache[id.replace(PREFIX, "")] = m;
|
|
171
|
-
return {
|
|
172
|
-
code: m,
|
|
173
|
-
map: null
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region src/build/plugins/database.ts
|
|
181
|
-
function database(nitro) {
|
|
182
|
-
if (!nitro.options.experimental.database) return virtual({ "#nitro-internal-virtual/database": () => {
|
|
183
|
-
return `export const connectionConfigs = {};`;
|
|
184
|
-
} }, nitro.vfs);
|
|
185
|
-
const dbConfigs = nitro.options.dev && nitro.options.devDatabase || nitro.options.database;
|
|
186
|
-
const connectorsNames = [...new Set(Object.values(dbConfigs || {}).map((config) => config?.connector))].filter(Boolean);
|
|
187
|
-
for (const name of connectorsNames) if (!connectors[name]) throw new Error(`Database connector "${name}" is invalid.`);
|
|
188
|
-
return virtual({ "#nitro-internal-virtual/database": () => {
|
|
189
|
-
return `
|
|
190
|
-
${connectorsNames.map((name) => `import ${camelCase(name)}Connector from "${connectors[name]}";`).join("\n")}
|
|
191
|
-
|
|
192
|
-
export const connectionConfigs = {
|
|
193
|
-
${Object.entries(dbConfigs || {}).map(([name, { connector, options }]) => `${name}: {
|
|
194
|
-
connector: ${camelCase(connector)}Connector,
|
|
195
|
-
options: ${JSON.stringify(options)}
|
|
196
|
-
}`).join(",\n")}
|
|
197
|
-
};
|
|
198
|
-
`;
|
|
199
|
-
} }, nitro.vfs);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
//#endregion
|
|
203
|
-
//#region src/build/plugins/routing.ts
|
|
204
|
-
const RuntimeRouteRules = [
|
|
205
|
-
"headers",
|
|
206
|
-
"redirect",
|
|
207
|
-
"proxy",
|
|
208
|
-
"cache"
|
|
209
|
-
];
|
|
210
|
-
function routing(nitro) {
|
|
211
|
-
return virtual({
|
|
212
|
-
"#nitro-internal-virtual/routing": () => {
|
|
213
|
-
const allHandlers = uniqueBy([
|
|
214
|
-
...Object.values(nitro.routing.routes.routes).flatMap((h) => h.data),
|
|
215
|
-
...Object.values(nitro.routing.routedMiddleware.routes).map((h) => h.data),
|
|
216
|
-
...nitro.routing.globalMiddleware
|
|
217
|
-
], "_importHash");
|
|
218
|
-
return `
|
|
219
|
-
import * as __routeRules__ from "nitro/~internal/runtime/route-rules";
|
|
220
|
-
import * as srvxNode from "srvx/node"
|
|
221
|
-
import * as h3 from "h3";
|
|
222
|
-
|
|
223
|
-
export const findRouteRules = ${nitro.routing.routeRules.compileToString({
|
|
224
|
-
serialize: serializeRouteRule,
|
|
225
|
-
matchAll: true
|
|
226
|
-
})}
|
|
227
|
-
|
|
228
|
-
const multiHandler = (...handlers) => {
|
|
229
|
-
const final = handlers.pop()
|
|
230
|
-
const middleware = handlers.filter(Boolean).map(h => h3.toMiddleware(h));
|
|
231
|
-
return (ev) => h3.callMiddleware(ev, middleware, final);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
${allHandlers.filter((h) => !h.lazy).map((h) => `import ${h._importHash} from "${h.handler}";`).join("\n")}
|
|
235
|
-
|
|
236
|
-
${allHandlers.filter((h) => h.lazy).map((h) => `const ${h._importHash} = h3.defineLazyEventHandler(() => import("${h.handler}")${h.format === "node" ? ".then(m => srvxNode.toFetchHandler(m.default))" : ""});`).join("\n")}
|
|
237
|
-
|
|
238
|
-
export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
|
|
239
|
-
|
|
240
|
-
export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({
|
|
241
|
-
serialize: serializeHandler,
|
|
242
|
-
matchAll: true
|
|
243
|
-
})};
|
|
244
|
-
|
|
245
|
-
export const globalMiddleware = [
|
|
246
|
-
${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `h3.toEventHandler(${h._importHash})`).join(",")}
|
|
247
|
-
].filter(Boolean);
|
|
248
|
-
`;
|
|
249
|
-
},
|
|
250
|
-
"#nitro-internal-virtual/routing-meta": () => {
|
|
251
|
-
const routeHandlers = uniqueBy(Object.values(nitro.routing.routes.routes).flatMap((h) => h.data), "_importHash");
|
|
252
|
-
return `
|
|
253
|
-
${routeHandlers.map((h) => `import ${h._importHash}Meta from "${h.handler}?meta";`).join("\n")}
|
|
254
|
-
export const handlersMeta = [
|
|
255
|
-
${routeHandlers.map((h) => `{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(h.method?.toLowerCase())}, meta: ${h._importHash}Meta }`).join(",\n")}
|
|
256
|
-
];
|
|
257
|
-
`.trim();
|
|
258
|
-
}
|
|
259
|
-
}, nitro.vfs);
|
|
260
|
-
}
|
|
261
|
-
function uniqueBy(arr, key) {
|
|
262
|
-
return [...new Map(arr.map((item) => [item[key], item])).values()];
|
|
263
|
-
}
|
|
264
|
-
function serializeHandler(h) {
|
|
265
|
-
const meta = Array.isArray(h) ? h[0] : h;
|
|
266
|
-
return `{${[
|
|
267
|
-
`route:${JSON.stringify(meta.route)}`,
|
|
268
|
-
meta.method && `method:${JSON.stringify(meta.method)}`,
|
|
269
|
-
meta.meta && `meta:${JSON.stringify(meta.meta)}`,
|
|
270
|
-
`handler:${Array.isArray(h) ? `multiHandler(${h.map((handler) => serializeHandlerFn(handler)).join(",")})` : serializeHandlerFn(h)}`
|
|
271
|
-
].filter(Boolean).join(",")}}`;
|
|
272
|
-
}
|
|
273
|
-
function serializeHandlerFn(h) {
|
|
274
|
-
let code = h._importHash;
|
|
275
|
-
if (!h.lazy) {
|
|
276
|
-
if (h.format === "node") code = `srvxNode.toFetchHandler(${code})`;
|
|
277
|
-
code = `h3.toEventHandler(${code})`;
|
|
278
|
-
}
|
|
279
|
-
return code;
|
|
280
|
-
}
|
|
281
|
-
function serializeRouteRule(h) {
|
|
282
|
-
return `[${Object.entries(h).filter(([name, options]) => options !== void 0 && name[0] !== "_").map(([name, options]) => {
|
|
283
|
-
return `{${[
|
|
284
|
-
`name:${JSON.stringify(name)}`,
|
|
285
|
-
`route:${JSON.stringify(h._route)}`,
|
|
286
|
-
h._method && `method:${JSON.stringify(h._method)}`,
|
|
287
|
-
RuntimeRouteRules.includes(name) && `handler:__routeRules__.${name}`,
|
|
288
|
-
`options:${JSON.stringify(options)}`
|
|
289
|
-
].filter(Boolean).join(",")}}`;
|
|
290
|
-
}).join(",")}]`;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
140
|
//#endregion
|
|
294
141
|
//#region src/build/plugins/route-meta.ts
|
|
295
142
|
const virtualPrefix = "\0nitro-handler-meta:";
|
|
@@ -357,228 +204,195 @@ function serverMain(nitro) {
|
|
|
357
204
|
}
|
|
358
205
|
|
|
359
206
|
//#endregion
|
|
360
|
-
//#region src/
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
"
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
assets[assetId] = {
|
|
390
|
-
type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType,
|
|
391
|
-
encoding,
|
|
392
|
-
etag,
|
|
393
|
-
mtime: stat$2.mtime.toJSON(),
|
|
394
|
-
size: stat$2.size,
|
|
395
|
-
path: relative(nitro.options.output.serverDir, fullPath),
|
|
396
|
-
data: nitro.options.serveStatic === "inline" ? assetData.toString("base64") : void 0
|
|
207
|
+
//#region src/utils/regex.ts
|
|
208
|
+
function escapeRegExp(string) {
|
|
209
|
+
return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/build/plugins/virtual.ts
|
|
214
|
+
const PREFIX = "\0virtual:";
|
|
215
|
+
function virtual(input) {
|
|
216
|
+
const modules = /* @__PURE__ */ new Map();
|
|
217
|
+
for (const mod of input) {
|
|
218
|
+
const render = () => typeof mod.template === "function" ? mod.template() : mod.template;
|
|
219
|
+
modules.set(mod.id, {
|
|
220
|
+
module: mod,
|
|
221
|
+
render
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
name: "nitro:virtual",
|
|
226
|
+
api: { modules },
|
|
227
|
+
resolveId: {
|
|
228
|
+
order: "pre",
|
|
229
|
+
filter: { id: { include: /* @__PURE__ */ new RegExp(`^(${[...modules.keys()].map((id) => escapeRegExp(id)).join("|")})$`) } },
|
|
230
|
+
handler: (id) => {
|
|
231
|
+
const mod = modules.get(id);
|
|
232
|
+
if (!mod) return null;
|
|
233
|
+
return {
|
|
234
|
+
id: PREFIX + id,
|
|
235
|
+
moduleSideEffects: mod.module.moduleSideEffects ?? false
|
|
397
236
|
};
|
|
398
237
|
}
|
|
399
|
-
return `export default ${JSON.stringify(assets, null, 2)};`;
|
|
400
|
-
},
|
|
401
|
-
"#nitro-internal-virtual/public-assets-node": () => {
|
|
402
|
-
return `
|
|
403
|
-
import { promises as fsp } from 'node:fs'
|
|
404
|
-
import { fileURLToPath } from 'node:url'
|
|
405
|
-
import { resolve, dirname } from 'node:path'
|
|
406
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
407
|
-
export function readAsset (id) {
|
|
408
|
-
const serverDir = dirname(fileURLToPath(globalThis.__nitro_main__))
|
|
409
|
-
return fsp.readFile(resolve(serverDir, assets[id].path))
|
|
410
|
-
}`;
|
|
411
|
-
},
|
|
412
|
-
"#nitro-internal-virtual/public-assets-deno": () => {
|
|
413
|
-
return `
|
|
414
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
415
|
-
export function readAsset (id) {
|
|
416
|
-
// https://deno.com/deploy/docs/serve-static-assets
|
|
417
|
-
const path = '.' + decodeURIComponent(new URL(\`../public\${id}\`, 'file://').pathname)
|
|
418
|
-
return Deno.readFile(path);
|
|
419
|
-
}`;
|
|
420
|
-
},
|
|
421
|
-
"#nitro-internal-virtual/public-assets-null": () => {
|
|
422
|
-
return `
|
|
423
|
-
export function readAsset (id) {
|
|
424
|
-
return Promise.resolve(null);
|
|
425
|
-
}`;
|
|
426
238
|
},
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const publicAssetBases = Object.fromEntries(nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [withTrailingSlash(joinURL(nitro.options.baseURL, dir.baseURL || "/")), { maxAge: dir.maxAge }]));
|
|
440
|
-
return `
|
|
441
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
442
|
-
export { readAsset } from "${`#nitro-internal-virtual/public-assets-${readAssetHandler[nitro.options.serveStatic] || "null"}`}"
|
|
443
|
-
export const publicAssetBases = ${JSON.stringify(publicAssetBases)}
|
|
444
|
-
|
|
445
|
-
export function isPublicAssetURL(id = '') {
|
|
446
|
-
if (assets[id]) {
|
|
447
|
-
return true
|
|
448
|
-
}
|
|
449
|
-
for (const base in publicAssetBases) {
|
|
450
|
-
if (id.startsWith(base)) { return true }
|
|
451
|
-
}
|
|
452
|
-
return false
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
export function getPublicAssetMeta(id = '') {
|
|
456
|
-
for (const base in publicAssetBases) {
|
|
457
|
-
if (id.startsWith(base)) { return publicAssetBases[base] }
|
|
458
|
-
}
|
|
459
|
-
return {}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export function getAsset (id) {
|
|
463
|
-
return assets[id]
|
|
464
|
-
}
|
|
465
|
-
`;
|
|
239
|
+
load: {
|
|
240
|
+
order: "pre",
|
|
241
|
+
filter: { id: /* @__PURE__ */ new RegExp(`^${escapeRegExp(PREFIX)}`) },
|
|
242
|
+
handler: async (id) => {
|
|
243
|
+
const idNoPrefix = id.slice(9);
|
|
244
|
+
const mod = modules.get(idNoPrefix);
|
|
245
|
+
if (!mod) throw new Error(`Virtual module ${idNoPrefix} not found.`);
|
|
246
|
+
return {
|
|
247
|
+
code: await mod.render(),
|
|
248
|
+
map: null
|
|
249
|
+
};
|
|
250
|
+
}
|
|
466
251
|
}
|
|
467
|
-
}
|
|
252
|
+
};
|
|
468
253
|
}
|
|
469
254
|
|
|
470
255
|
//#endregion
|
|
471
|
-
//#region src/build/plugins/
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
assets[id] = {
|
|
487
|
-
fsPath,
|
|
488
|
-
meta: {}
|
|
489
|
-
};
|
|
490
|
-
let type = src_default.getType(id) || "text/plain";
|
|
491
|
-
if (type.startsWith("text")) type += "; charset=utf-8";
|
|
492
|
-
const etag = (0, import_etag.default)(await promises.readFile(fsPath));
|
|
493
|
-
const mtime = await promises.stat(fsPath).then((s) => s.mtime.toJSON());
|
|
494
|
-
assets[id].meta = {
|
|
495
|
-
type,
|
|
496
|
-
etag,
|
|
497
|
-
mtime
|
|
498
|
-
};
|
|
256
|
+
//#region src/build/plugins/resolve.ts
|
|
257
|
+
const subpathMap = {
|
|
258
|
+
"nitro/h3": "h3",
|
|
259
|
+
"nitro/deps/h3": "h3",
|
|
260
|
+
"nitro/deps/ofetch": "ofetch"
|
|
261
|
+
};
|
|
262
|
+
function nitroResolveIds() {
|
|
263
|
+
return {
|
|
264
|
+
name: "nitro:resolve-ids",
|
|
265
|
+
resolveId: {
|
|
266
|
+
order: "pre",
|
|
267
|
+
handler(id, importer, rOpts) {
|
|
268
|
+
if (importer && importer.startsWith("\0virtual:#nitro-internal-virtual")) return this.resolve(id, runtimeDir, { skipSelf: true });
|
|
269
|
+
const mappedId = subpathMap[id];
|
|
270
|
+
if (mappedId) return this.resolve(mappedId, runtimeDir, { skipSelf: true });
|
|
499
271
|
}
|
|
500
272
|
}
|
|
501
|
-
|
|
502
|
-
} }, nitro.vfs);
|
|
273
|
+
};
|
|
503
274
|
}
|
|
504
|
-
function getAssetsDev(nitro) {
|
|
505
|
-
return `
|
|
506
|
-
import { createStorage } from 'unstorage'
|
|
507
|
-
import fsDriver from 'unstorage/drivers/fs'
|
|
508
|
-
|
|
509
|
-
const serverAssets = ${JSON.stringify(nitro.options.serverAssets)}
|
|
510
275
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/build/plugins/sourcemap-min.ts
|
|
278
|
+
function sourcemapMinify() {
|
|
279
|
+
return {
|
|
280
|
+
name: "nitro:sourcemap-minify",
|
|
281
|
+
generateBundle(_options, bundle) {
|
|
282
|
+
for (const [key, asset] of Object.entries(bundle)) {
|
|
283
|
+
if (!key.endsWith(".map") || !("source" in asset) || typeof asset.source !== "string") continue;
|
|
284
|
+
const sourcemap = JSON.parse(asset.source);
|
|
285
|
+
delete sourcemap.sourcesContent;
|
|
286
|
+
delete sourcemap.x_google_ignoreList;
|
|
287
|
+
if ((sourcemap.sources || []).some((s) => s.includes("node_modules"))) sourcemap.mappings = "";
|
|
288
|
+
asset.source = JSON.stringify(sourcemap);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
516
292
|
}
|
|
517
|
-
function getAssetProd(assets) {
|
|
518
|
-
return `
|
|
519
|
-
const _assets = {\n${Object.entries(assets).map(([id, asset]) => ` [${JSON.stringify(normalizeKey(id))}]: {\n import: () => import(${JSON.stringify("raw:" + asset.fsPath)}).then(r => r.default || r),\n meta: ${JSON.stringify(asset.meta)}\n }`).join(",\n")}\n}
|
|
520
|
-
|
|
521
|
-
const normalizeKey = ${normalizeKey.toString()}
|
|
522
293
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/build/plugins/raw.ts
|
|
296
|
+
const HELPER_ID = "virtual:raw-helpers";
|
|
297
|
+
const RESOLVED_RAW_PREFIX = "virtual:raw:";
|
|
298
|
+
function raw() {
|
|
299
|
+
return {
|
|
300
|
+
name: "raw",
|
|
301
|
+
resolveId: {
|
|
302
|
+
order: "pre",
|
|
303
|
+
async handler(id, importer, resolveOpts) {
|
|
304
|
+
if (id === HELPER_ID) return id;
|
|
305
|
+
if (id.startsWith("raw:")) return { id: RESOLVED_RAW_PREFIX + (await this.resolve(id.slice(4), importer, resolveOpts))?.id };
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
load: {
|
|
309
|
+
order: "pre",
|
|
310
|
+
handler(id) {
|
|
311
|
+
if (id === HELPER_ID) return getHelpers();
|
|
312
|
+
if (id.startsWith(RESOLVED_RAW_PREFIX)) return promises.readFile(id.slice(12), isBinary(id) ? "binary" : "utf8");
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
transform: {
|
|
316
|
+
order: "pre",
|
|
317
|
+
handler(code, id) {
|
|
318
|
+
if (!id.startsWith(RESOLVED_RAW_PREFIX)) return;
|
|
319
|
+
const path = id.slice(12);
|
|
320
|
+
if (isBinary(id)) return {
|
|
321
|
+
code: `import {base64ToUint8Array } from "${HELPER_ID}" \n export default base64ToUint8Array("${Buffer.from(code, "binary").toString("base64")}")`,
|
|
322
|
+
map: rawAssetMap(path)
|
|
323
|
+
};
|
|
324
|
+
return {
|
|
325
|
+
code: `export default ${JSON.stringify(code)}`,
|
|
326
|
+
map: rawAssetMap(path),
|
|
327
|
+
moduleType: "js"
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function isBinary(id) {
|
|
334
|
+
const idMime = src_default.getType(id) || "";
|
|
335
|
+
if (idMime.startsWith("text/")) return false;
|
|
336
|
+
if (/application\/(json|sql|xml|yaml)/.test(idMime)) return false;
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
function getHelpers() {
|
|
340
|
+
return String.raw`
|
|
341
|
+
export function base64ToUint8Array(str) {
|
|
342
|
+
const data = atob(str);
|
|
343
|
+
const size = data.length;
|
|
344
|
+
const bytes = new Uint8Array(size);
|
|
345
|
+
for (let i = 0; i < size; i++) {
|
|
346
|
+
bytes[i] = data.charCodeAt(i);
|
|
538
347
|
}
|
|
348
|
+
return bytes;
|
|
539
349
|
}
|
|
540
|
-
`;
|
|
350
|
+
`;
|
|
351
|
+
}
|
|
352
|
+
function rawAssetMap(id) {
|
|
353
|
+
return {
|
|
354
|
+
version: 3,
|
|
355
|
+
file: id,
|
|
356
|
+
sources: [id],
|
|
357
|
+
sourcesContent: [],
|
|
358
|
+
names: [],
|
|
359
|
+
mappings: ""
|
|
360
|
+
};
|
|
541
361
|
}
|
|
542
362
|
|
|
543
363
|
//#endregion
|
|
544
|
-
//#region src/build/
|
|
545
|
-
function
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
driver: builtinDrivers[mount.driver] || mount.driver,
|
|
556
|
-
opts: mount
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
const driverImports = [...new Set(mounts.map((m) => m.driver))];
|
|
560
|
-
return virtual({ "#nitro-internal-virtual/storage": `
|
|
561
|
-
import { createStorage } from 'unstorage'
|
|
562
|
-
import { assets } from '#nitro-internal-virtual/server-assets'
|
|
563
|
-
|
|
564
|
-
${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
|
|
364
|
+
//#region src/build/virtual/database.ts
|
|
365
|
+
function database(nitro) {
|
|
366
|
+
return {
|
|
367
|
+
id: "#nitro-internal-virtual/database",
|
|
368
|
+
template: () => {
|
|
369
|
+
if (!nitro.options.experimental.database) return `export const connectionConfigs = {};`;
|
|
370
|
+
const dbConfigs = nitro.options.dev && nitro.options.devDatabase || nitro.options.database;
|
|
371
|
+
const connectorsNames = [...new Set(Object.values(dbConfigs || {}).map((config) => config?.connector))].filter(Boolean);
|
|
372
|
+
for (const name of connectorsNames) if (!connectors[name]) throw new Error(`Database connector "${name}" is invalid.`);
|
|
373
|
+
return `
|
|
374
|
+
${connectorsNames.map((name) => `import ${camelCase(name)}Connector from "${connectors[name]}";`).join("\n")}
|
|
565
375
|
|
|
566
|
-
export
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
376
|
+
export const connectionConfigs = {
|
|
377
|
+
${Object.entries(dbConfigs || {}).filter(([, config]) => !!config?.connector).map(([name, { connector, options }]) => `${name}: {
|
|
378
|
+
connector: ${camelCase(connector)}Connector,
|
|
379
|
+
options: ${JSON.stringify(options)}
|
|
380
|
+
}`).join(",\n")}
|
|
381
|
+
};
|
|
382
|
+
`;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
573
385
|
}
|
|
574
386
|
|
|
575
387
|
//#endregion
|
|
576
|
-
//#region src/build/
|
|
388
|
+
//#region src/build/virtual/error-handler.ts
|
|
577
389
|
function errorHandler(nitro) {
|
|
578
|
-
return
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
390
|
+
return {
|
|
391
|
+
id: "#nitro-internal-virtual/error-handler",
|
|
392
|
+
template: () => {
|
|
393
|
+
const errorHandlers = Array.isArray(nitro.options.errorHandler) ? nitro.options.errorHandler : [nitro.options.errorHandler];
|
|
394
|
+
const builtinHandler = join(runtimeDir, `internal/error/${nitro.options.dev ? "dev" : "prod"}`);
|
|
395
|
+
return `
|
|
582
396
|
${errorHandlers.map((h, i) => `import errorHandler$${i} from "${h}";`).join("\n")}
|
|
583
397
|
|
|
584
398
|
const errorHandlers = [${errorHandlers.map((_, i) => `errorHandler$${i}`).join(", ")}];
|
|
@@ -600,207 +414,517 @@ export default async function(error, event) {
|
|
|
600
414
|
// H3 will handle fallback
|
|
601
415
|
}
|
|
602
416
|
`;
|
|
603
|
-
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/build/virtual/feature-flags.ts
|
|
423
|
+
function featureFlags(nitro) {
|
|
424
|
+
return {
|
|
425
|
+
id: "#nitro-internal-virtual/feature-flags",
|
|
426
|
+
template: () => {
|
|
427
|
+
const featureFlags$1 = {
|
|
428
|
+
hasRoutes: nitro.routing.routes.hasRoutes(),
|
|
429
|
+
hasRouteRules: nitro.routing.routeRules.hasRoutes(),
|
|
430
|
+
hasRoutedMiddleware: nitro.routing.routedMiddleware.hasRoutes(),
|
|
431
|
+
hasGlobalMiddleware: nitro.routing.globalMiddleware.length > 0,
|
|
432
|
+
hasPlugins: nitro.options.plugins.length > 0,
|
|
433
|
+
hasHooks: nitro.options.features?.runtimeHooks ?? nitro.options.plugins.length > 0,
|
|
434
|
+
hasWebSocket: nitro.options.features?.websocket ?? nitro.options.experimental.websocket ?? false
|
|
435
|
+
};
|
|
436
|
+
return Object.entries(featureFlags$1).map(([key, value]) => `export const ${key} = ${Boolean(value)};`).join("\n");
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/build/virtual/plugins.ts
|
|
443
|
+
function plugins(nitro) {
|
|
444
|
+
return {
|
|
445
|
+
id: "#nitro-internal-virtual/plugins",
|
|
446
|
+
template: () => {
|
|
447
|
+
const nitroPlugins = [...new Set(nitro.options.plugins)];
|
|
448
|
+
return `
|
|
449
|
+
${nitroPlugins.map((plugin) => `import _${hash(plugin).replace(/-/g, "")} from "${plugin}";`).join("\n")}
|
|
450
|
+
|
|
451
|
+
export const plugins = [
|
|
452
|
+
${nitroPlugins.map((plugin) => `_${hash(plugin).replace(/-/g, "")}`).join(",\n")}
|
|
453
|
+
]
|
|
454
|
+
`;
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/build/virtual/polyfills.ts
|
|
461
|
+
function polyfills(_nitro, polyfills$1) {
|
|
462
|
+
return {
|
|
463
|
+
id: "#nitro-internal-polyfills",
|
|
464
|
+
moduleSideEffects: true,
|
|
465
|
+
template: () => {
|
|
466
|
+
return polyfills$1.map((p) => `import '${p}';`).join("\n") || `/* No polyfills */`;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/build/virtual/public-assets.ts
|
|
473
|
+
var import_etag$1 = /* @__PURE__ */ __toESM(require_etag(), 1);
|
|
474
|
+
const readAssetHandler = {
|
|
475
|
+
true: "node",
|
|
476
|
+
node: "node",
|
|
477
|
+
false: "null",
|
|
478
|
+
deno: "deno",
|
|
479
|
+
inline: "inline"
|
|
480
|
+
};
|
|
481
|
+
function publicAssets(nitro) {
|
|
482
|
+
return [
|
|
483
|
+
{
|
|
484
|
+
id: "#nitro-internal-virtual/public-assets-data",
|
|
485
|
+
template: async () => {
|
|
486
|
+
const assets = {};
|
|
487
|
+
const files = await glob("**", {
|
|
488
|
+
cwd: nitro.options.output.publicDir,
|
|
489
|
+
absolute: false,
|
|
490
|
+
dot: true
|
|
491
|
+
});
|
|
492
|
+
for (const id of files) {
|
|
493
|
+
let mimeType = src_default.getType(id.replace(/\.(gz|br)$/, "")) || "text/plain";
|
|
494
|
+
if (mimeType.startsWith("text")) mimeType += "; charset=utf-8";
|
|
495
|
+
const fullPath = resolve(nitro.options.output.publicDir, id);
|
|
496
|
+
const assetData = await promises.readFile(fullPath);
|
|
497
|
+
const etag = (0, import_etag$1.default)(assetData);
|
|
498
|
+
const stat$2 = await promises.stat(fullPath);
|
|
499
|
+
const assetId = joinURL(nitro.options.baseURL, decodeURIComponent(id));
|
|
500
|
+
let encoding;
|
|
501
|
+
if (id.endsWith(".gz")) encoding = "gzip";
|
|
502
|
+
else if (id.endsWith(".br")) encoding = "br";
|
|
503
|
+
assets[assetId] = {
|
|
504
|
+
type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType,
|
|
505
|
+
encoding,
|
|
506
|
+
etag,
|
|
507
|
+
mtime: stat$2.mtime.toJSON(),
|
|
508
|
+
size: stat$2.size,
|
|
509
|
+
path: relative(nitro.options.output.serverDir, fullPath),
|
|
510
|
+
data: nitro.options.serveStatic === "inline" ? assetData.toString("base64") : void 0
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
return `export default ${JSON.stringify(assets, null, 2)};`;
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
id: "#nitro-internal-virtual/public-assets",
|
|
518
|
+
template: () => {
|
|
519
|
+
const publicAssetBases = Object.fromEntries(nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [withTrailingSlash(joinURL(nitro.options.baseURL, dir.baseURL || "/")), { maxAge: dir.maxAge }]));
|
|
520
|
+
return `
|
|
521
|
+
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
522
|
+
export { readAsset } from "${`#nitro-internal-virtual/public-assets-${readAssetHandler[nitro.options.serveStatic] || "null"}`}"
|
|
523
|
+
export const publicAssetBases = ${JSON.stringify(publicAssetBases)}
|
|
524
|
+
|
|
525
|
+
export function isPublicAssetURL(id = '') {
|
|
526
|
+
if (assets[id]) {
|
|
527
|
+
return true
|
|
528
|
+
}
|
|
529
|
+
for (const base in publicAssetBases) {
|
|
530
|
+
if (id.startsWith(base)) { return true }
|
|
531
|
+
}
|
|
532
|
+
return false
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export function getPublicAssetMeta(id = '') {
|
|
536
|
+
for (const base in publicAssetBases) {
|
|
537
|
+
if (id.startsWith(base)) { return publicAssetBases[base] }
|
|
538
|
+
}
|
|
539
|
+
return {}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export function getAsset (id) {
|
|
543
|
+
return assets[id]
|
|
544
|
+
}
|
|
545
|
+
`;
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
id: "#nitro-internal-virtual/public-assets-node",
|
|
550
|
+
template: () => {
|
|
551
|
+
return `
|
|
552
|
+
import { promises as fsp } from 'node:fs'
|
|
553
|
+
import { fileURLToPath } from 'node:url'
|
|
554
|
+
import { resolve, dirname } from 'node:path'
|
|
555
|
+
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
556
|
+
export function readAsset (id) {
|
|
557
|
+
const serverDir = dirname(fileURLToPath(globalThis.__nitro_main__))
|
|
558
|
+
return fsp.readFile(resolve(serverDir, assets[id].path))
|
|
559
|
+
}`;
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
id: "#nitro-internal-virtual/public-assets-deno",
|
|
564
|
+
template: () => {
|
|
565
|
+
return `
|
|
566
|
+
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
567
|
+
export function readAsset (id) {
|
|
568
|
+
// https://deno.com/deploy/docs/serve-static-assets
|
|
569
|
+
const path = '.' + decodeURIComponent(new URL(\`../public\${id}\`, 'file://').pathname)
|
|
570
|
+
return Deno.readFile(path);
|
|
571
|
+
}`;
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
id: "#nitro-internal-virtual/public-assets-null",
|
|
576
|
+
template: () => {
|
|
577
|
+
return `
|
|
578
|
+
export function readAsset (id) {
|
|
579
|
+
return Promise.resolve(null);
|
|
580
|
+
}`;
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
id: "#nitro-internal-virtual/public-assets-inline",
|
|
585
|
+
template: () => {
|
|
586
|
+
return `
|
|
587
|
+
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
588
|
+
export function readAsset (id) {
|
|
589
|
+
if (!assets[id]) { return undefined }
|
|
590
|
+
if (assets[id]._data) { return assets[id]._data }
|
|
591
|
+
if (!assets[id].data) { return assets[id].data }
|
|
592
|
+
assets[id]._data = Uint8Array.from(atob(assets[id].data), (c) => c.charCodeAt(0))
|
|
593
|
+
return assets[id]._data
|
|
594
|
+
}`;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
];
|
|
604
598
|
}
|
|
605
599
|
|
|
606
600
|
//#endregion
|
|
607
|
-
//#region src/build/
|
|
601
|
+
//#region src/build/virtual/renderer-template.ts
|
|
608
602
|
function rendererTemplate(nitro) {
|
|
609
|
-
return
|
|
610
|
-
|
|
611
|
-
|
|
603
|
+
return {
|
|
604
|
+
id: "#nitro-internal-virtual/renderer-template",
|
|
605
|
+
template: async () => {
|
|
606
|
+
const template = nitro.options.renderer?.template;
|
|
607
|
+
if (typeof template !== "string") return `
|
|
612
608
|
export const rendererTemplate = () => '<!-- renderer.template is not set -->';
|
|
613
609
|
export const rendererTemplateFile = undefined;
|
|
614
610
|
export const isStaticTemplate = true;`;
|
|
615
|
-
|
|
611
|
+
if (nitro.options.dev) return `
|
|
616
612
|
import { readFile } from 'node:fs/promises';
|
|
617
613
|
export const rendererTemplate = () => readFile(${JSON.stringify(template)}, "utf8");
|
|
618
614
|
export const rendererTemplateFile = ${JSON.stringify(template)};
|
|
619
615
|
export const isStaticTemplate = ${JSON.stringify(nitro.options.renderer?.static)};
|
|
620
616
|
`;
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
617
|
+
else {
|
|
618
|
+
const html = await readFile(template, "utf8");
|
|
619
|
+
if (nitro.options.renderer?.static ?? !hasTemplateSyntax(html)) return `
|
|
624
620
|
import { HTTPResponse } from "h3";
|
|
625
621
|
export const rendererTemplate = () => new HTTPResponse(${JSON.stringify(html)}, { headers: { "content-type": "text/html; charset=utf-8" } });
|
|
626
622
|
`;
|
|
627
|
-
|
|
623
|
+
else return `
|
|
628
624
|
import { renderToResponse } from 'rendu'
|
|
629
625
|
import { serverFetch } from 'nitro/app'
|
|
630
626
|
const template = ${compileTemplateToString(html, { contextKeys: [...RENDER_CONTEXT_KEYS] })};
|
|
631
627
|
export const rendererTemplate = (request) => renderToResponse(template, { request, context: { serverFetch } })
|
|
632
628
|
`;
|
|
629
|
+
}
|
|
633
630
|
}
|
|
634
|
-
}
|
|
631
|
+
};
|
|
635
632
|
}
|
|
636
633
|
|
|
637
634
|
//#endregion
|
|
638
|
-
//#region src/build/
|
|
639
|
-
function
|
|
640
|
-
return
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
}
|
|
635
|
+
//#region src/build/virtual/routing-meta.ts
|
|
636
|
+
function routingMeta(nitro) {
|
|
637
|
+
return {
|
|
638
|
+
id: "#nitro-internal-virtual/routing-meta",
|
|
639
|
+
template: () => {
|
|
640
|
+
const routeHandlers = uniqueBy$1(Object.values(nitro.routing.routes.routes).flatMap((h) => h.data), "_importHash");
|
|
641
|
+
return `
|
|
642
|
+
${routeHandlers.map((h) => `import ${h._importHash}Meta from "${h.handler}?meta";`).join("\n")}
|
|
643
|
+
export const handlersMeta = [
|
|
644
|
+
${routeHandlers.map((h) => `{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(h.method?.toLowerCase())}, meta: ${h._importHash}Meta }`).join(",\n")}
|
|
645
|
+
];
|
|
646
|
+
`.trim();
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
function uniqueBy$1(arr, key) {
|
|
651
|
+
return [...new Map(arr.map((item) => [item[key], item])).values()];
|
|
652
652
|
}
|
|
653
653
|
|
|
654
654
|
//#endregion
|
|
655
|
-
//#region src/build/
|
|
656
|
-
const
|
|
657
|
-
"
|
|
658
|
-
"
|
|
659
|
-
"
|
|
660
|
-
|
|
661
|
-
|
|
655
|
+
//#region src/build/virtual/routing.ts
|
|
656
|
+
const RuntimeRouteRules = [
|
|
657
|
+
"headers",
|
|
658
|
+
"redirect",
|
|
659
|
+
"proxy",
|
|
660
|
+
"cache"
|
|
661
|
+
];
|
|
662
|
+
function routing(nitro) {
|
|
662
663
|
return {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
664
|
+
id: "#nitro-internal-virtual/routing",
|
|
665
|
+
template: () => {
|
|
666
|
+
const allHandlers = uniqueBy([
|
|
667
|
+
...Object.values(nitro.routing.routes.routes).flatMap((h) => h.data),
|
|
668
|
+
...Object.values(nitro.routing.routedMiddleware.routes).map((h) => h.data),
|
|
669
|
+
...nitro.routing.globalMiddleware
|
|
670
|
+
], "_importHash");
|
|
671
|
+
return `
|
|
672
|
+
import * as __routeRules__ from "nitro/~internal/runtime/route-rules";
|
|
673
|
+
import * as srvxNode from "srvx/node"
|
|
674
|
+
import * as h3 from "h3";
|
|
675
|
+
|
|
676
|
+
export const findRouteRules = ${nitro.routing.routeRules.compileToString({
|
|
677
|
+
serialize: serializeRouteRule,
|
|
678
|
+
matchAll: true
|
|
679
|
+
})}
|
|
680
|
+
|
|
681
|
+
const multiHandler = (...handlers) => {
|
|
682
|
+
const final = handlers.pop()
|
|
683
|
+
const middleware = handlers.filter(Boolean).map(h => h3.toMiddleware(h));
|
|
684
|
+
return (ev) => h3.callMiddleware(ev, middleware, final);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
${allHandlers.filter((h) => !h.lazy).map((h) => `import ${h._importHash} from "${h.handler}";`).join("\n")}
|
|
688
|
+
|
|
689
|
+
${allHandlers.filter((h) => h.lazy).map((h) => `const ${h._importHash} = h3.defineLazyEventHandler(() => import("${h.handler}")${h.format === "node" ? ".then(m => srvxNode.toFetchHandler(m.default))" : ""});`).join("\n")}
|
|
690
|
+
|
|
691
|
+
export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
|
|
692
|
+
|
|
693
|
+
export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({
|
|
694
|
+
serialize: serializeHandler,
|
|
695
|
+
matchAll: true
|
|
696
|
+
})};
|
|
697
|
+
|
|
698
|
+
export const globalMiddleware = [
|
|
699
|
+
${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `h3.toEventHandler(${h._importHash})`).join(",")}
|
|
700
|
+
].filter(Boolean);
|
|
701
|
+
`;
|
|
671
702
|
}
|
|
672
703
|
};
|
|
673
704
|
}
|
|
705
|
+
function uniqueBy(arr, key) {
|
|
706
|
+
return [...new Map(arr.map((item) => [item[key], item])).values()];
|
|
707
|
+
}
|
|
708
|
+
function serializeHandler(h) {
|
|
709
|
+
const meta = Array.isArray(h) ? h[0] : h;
|
|
710
|
+
return `{${[
|
|
711
|
+
`route:${JSON.stringify(meta.route)}`,
|
|
712
|
+
meta.method && `method:${JSON.stringify(meta.method)}`,
|
|
713
|
+
meta.meta && `meta:${JSON.stringify(meta.meta)}`,
|
|
714
|
+
`handler:${Array.isArray(h) ? `multiHandler(${h.map((handler) => serializeHandlerFn(handler)).join(",")})` : serializeHandlerFn(h)}`
|
|
715
|
+
].filter(Boolean).join(",")}}`;
|
|
716
|
+
}
|
|
717
|
+
function serializeHandlerFn(h) {
|
|
718
|
+
let code = h._importHash;
|
|
719
|
+
if (!h.lazy) {
|
|
720
|
+
if (h.format === "node") code = `srvxNode.toFetchHandler(${code})`;
|
|
721
|
+
code = `h3.toEventHandler(${code})`;
|
|
722
|
+
}
|
|
723
|
+
return code;
|
|
724
|
+
}
|
|
725
|
+
function serializeRouteRule(h) {
|
|
726
|
+
return `[${Object.entries(h).filter(([name, options]) => options !== void 0 && name[0] !== "_").map(([name, options]) => {
|
|
727
|
+
return `{${[
|
|
728
|
+
`name:${JSON.stringify(name)}`,
|
|
729
|
+
`route:${JSON.stringify(h._route)}`,
|
|
730
|
+
h._method && `method:${JSON.stringify(h._method)}`,
|
|
731
|
+
RuntimeRouteRules.includes(name) && `handler:__routeRules__.${name}`,
|
|
732
|
+
`options:${JSON.stringify(options)}`
|
|
733
|
+
].filter(Boolean).join(",")}}`;
|
|
734
|
+
}).join(",")}]`;
|
|
735
|
+
}
|
|
674
736
|
|
|
675
737
|
//#endregion
|
|
676
|
-
//#region src/build/
|
|
677
|
-
function
|
|
738
|
+
//#region src/build/virtual/runtime-config.ts
|
|
739
|
+
function runtimeConfig(nitro) {
|
|
678
740
|
return {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
if (!key.endsWith(".map") || !("source" in asset) || typeof asset.source !== "string") continue;
|
|
683
|
-
const sourcemap = JSON.parse(asset.source);
|
|
684
|
-
delete sourcemap.sourcesContent;
|
|
685
|
-
delete sourcemap.x_google_ignoreList;
|
|
686
|
-
if ((sourcemap.sources || []).some((s) => s.includes("node_modules"))) sourcemap.mappings = "";
|
|
687
|
-
asset.source = JSON.stringify(sourcemap);
|
|
688
|
-
}
|
|
741
|
+
id: "#nitro-internal-virtual/runtime-config",
|
|
742
|
+
template: () => {
|
|
743
|
+
return `export const runtimeConfig = ${JSON.stringify(nitro.options.runtimeConfig || {})};`;
|
|
689
744
|
}
|
|
690
745
|
};
|
|
691
746
|
}
|
|
692
747
|
|
|
693
748
|
//#endregion
|
|
694
|
-
//#region src/build/
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
function raw() {
|
|
749
|
+
//#region src/build/virtual/server-assets.ts
|
|
750
|
+
var import_etag = /* @__PURE__ */ __toESM(require_etag(), 1);
|
|
751
|
+
function serverAssets(nitro) {
|
|
698
752
|
return {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
753
|
+
id: "#nitro-internal-virtual/server-assets",
|
|
754
|
+
template: async () => {
|
|
755
|
+
if (nitro.options.dev || nitro.options.preset === "nitro-prerender") return `
|
|
756
|
+
import { createStorage } from 'unstorage'
|
|
757
|
+
import fsDriver from 'unstorage/drivers/fs'
|
|
758
|
+
const serverAssets = ${JSON.stringify(nitro.options.serverAssets)}
|
|
759
|
+
export const assets = createStorage()
|
|
760
|
+
for (const asset of serverAssets) {
|
|
761
|
+
assets.mount(asset.baseName, fsDriver({ base: asset.dir, ignore: (asset?.ignore || []) }))
|
|
762
|
+
}`;
|
|
763
|
+
const assets = {};
|
|
764
|
+
for (const asset of nitro.options.serverAssets) {
|
|
765
|
+
const files = await glob(asset.pattern || "**/*", {
|
|
766
|
+
cwd: asset.dir,
|
|
767
|
+
absolute: false,
|
|
768
|
+
ignore: asset.ignore
|
|
769
|
+
});
|
|
770
|
+
for (const _id of files) {
|
|
771
|
+
const fsPath = resolve(asset.dir, _id);
|
|
772
|
+
const id = asset.baseName + "/" + _id;
|
|
773
|
+
assets[id] = {
|
|
774
|
+
fsPath,
|
|
775
|
+
meta: {}
|
|
776
|
+
};
|
|
777
|
+
let type = src_default.getType(id) || "text/plain";
|
|
778
|
+
if (type.startsWith("text")) type += "; charset=utf-8";
|
|
779
|
+
const etag = (0, import_etag.default)(await promises.readFile(fsPath));
|
|
780
|
+
const mtime = await promises.stat(fsPath).then((s) => s.mtime.toJSON());
|
|
781
|
+
assets[id].meta = {
|
|
782
|
+
type,
|
|
783
|
+
etag,
|
|
784
|
+
mtime
|
|
785
|
+
};
|
|
786
|
+
}
|
|
728
787
|
}
|
|
788
|
+
return `
|
|
789
|
+
const _assets = {\n${Object.entries(assets).map(([id, asset]) => ` [${JSON.stringify(normalizeKey(id))}]: {\n import: () => import(${JSON.stringify("raw:" + asset.fsPath)}).then(r => r.default || r),\n meta: ${JSON.stringify(asset.meta)}\n }`).join(",\n")}\n}
|
|
790
|
+
|
|
791
|
+
const normalizeKey = ${normalizeKey.toString()}
|
|
792
|
+
|
|
793
|
+
export const assets = {
|
|
794
|
+
getKeys() {
|
|
795
|
+
return Promise.resolve(Object.keys(_assets))
|
|
796
|
+
},
|
|
797
|
+
hasItem (id) {
|
|
798
|
+
id = normalizeKey(id)
|
|
799
|
+
return Promise.resolve(id in _assets)
|
|
800
|
+
},
|
|
801
|
+
getItem (id) {
|
|
802
|
+
id = normalizeKey(id)
|
|
803
|
+
return Promise.resolve(_assets[id] ? _assets[id].import() : null)
|
|
804
|
+
},
|
|
805
|
+
getMeta (id) {
|
|
806
|
+
id = normalizeKey(id)
|
|
807
|
+
return Promise.resolve(_assets[id] ? _assets[id].meta : {})
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
`;
|
|
729
811
|
}
|
|
730
812
|
};
|
|
731
813
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
return
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
814
|
+
|
|
815
|
+
//#endregion
|
|
816
|
+
//#region src/build/virtual/storage.ts
|
|
817
|
+
function storage(nitro) {
|
|
818
|
+
return {
|
|
819
|
+
id: "#nitro-internal-virtual/storage",
|
|
820
|
+
template: () => {
|
|
821
|
+
const mounts = [];
|
|
822
|
+
const storageMounts = nitro.options.dev || nitro.options.preset === "nitro-prerender" ? {
|
|
823
|
+
...nitro.options.storage,
|
|
824
|
+
...nitro.options.devStorage
|
|
825
|
+
} : nitro.options.storage;
|
|
826
|
+
for (const path in storageMounts) {
|
|
827
|
+
const { driver: driverName, ...driverOpts } = storageMounts[path];
|
|
828
|
+
mounts.push({
|
|
829
|
+
path,
|
|
830
|
+
driver: builtinDrivers[driverName] || driverName,
|
|
831
|
+
opts: driverOpts
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
return `
|
|
835
|
+
import { createStorage } from 'unstorage'
|
|
836
|
+
import { assets } from '#nitro-internal-virtual/server-assets'
|
|
837
|
+
|
|
838
|
+
${[...new Set(mounts.map((m) => m.driver))].map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
|
|
839
|
+
|
|
840
|
+
export function initStorage() {
|
|
841
|
+
const storage = createStorage({})
|
|
842
|
+
storage.mount('/assets', assets)
|
|
843
|
+
${mounts.map((m) => `storage.mount('${m.path}', ${genSafeVariableName(m.driver)}(${JSON.stringify(m.opts)}))`).join("\n")}
|
|
844
|
+
return storage
|
|
748
845
|
}
|
|
749
|
-
|
|
846
|
+
`;
|
|
847
|
+
}
|
|
848
|
+
};
|
|
750
849
|
}
|
|
751
|
-
|
|
850
|
+
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region src/build/virtual/tasks.ts
|
|
853
|
+
function tasks(nitro) {
|
|
752
854
|
return {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
855
|
+
id: "#nitro-internal-virtual/tasks",
|
|
856
|
+
template: () => {
|
|
857
|
+
const _scheduledTasks = Object.entries(nitro.options.scheduledTasks || {}).map(([cron, _tasks]) => {
|
|
858
|
+
return {
|
|
859
|
+
cron,
|
|
860
|
+
tasks: (Array.isArray(_tasks) ? _tasks : [_tasks]).filter((name) => {
|
|
861
|
+
if (!nitro.options.tasks[name]) {
|
|
862
|
+
nitro.logger.warn(`Scheduled task \`${name}\` is not defined!`);
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
return true;
|
|
866
|
+
})
|
|
867
|
+
};
|
|
868
|
+
}).filter((e) => e.tasks.length > 0);
|
|
869
|
+
const scheduledTasks = _scheduledTasks.length > 0 ? _scheduledTasks : false;
|
|
870
|
+
return `
|
|
871
|
+
export const scheduledTasks = ${JSON.stringify(scheduledTasks)};
|
|
872
|
+
|
|
873
|
+
export const tasks = {
|
|
874
|
+
${Object.entries(nitro.options.tasks).map(([name, task]) => `"${name}": {
|
|
875
|
+
meta: {
|
|
876
|
+
description: ${JSON.stringify(task.description)},
|
|
877
|
+
},
|
|
878
|
+
resolve: ${task.handler ? `() => import("${normalize(task.handler)}").then(r => r.default || r)` : "undefined"},
|
|
879
|
+
}`).join(",\n")}
|
|
880
|
+
};`;
|
|
881
|
+
}
|
|
759
882
|
};
|
|
760
883
|
}
|
|
761
884
|
|
|
762
885
|
//#endregion
|
|
763
|
-
//#region src/build/
|
|
764
|
-
function
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
886
|
+
//#region src/build/virtual/_all.ts
|
|
887
|
+
function virtualTemplates(nitro, _polyfills) {
|
|
888
|
+
const nitroTemplates = [
|
|
889
|
+
database,
|
|
890
|
+
errorHandler,
|
|
891
|
+
featureFlags,
|
|
892
|
+
plugins,
|
|
893
|
+
polyfills,
|
|
894
|
+
publicAssets,
|
|
895
|
+
rendererTemplate,
|
|
896
|
+
routingMeta,
|
|
897
|
+
routing,
|
|
898
|
+
runtimeConfig,
|
|
899
|
+
serverAssets,
|
|
900
|
+
storage,
|
|
901
|
+
tasks
|
|
902
|
+
].flatMap((t) => t(nitro, _polyfills));
|
|
903
|
+
const customTemplates = Object.entries(nitro.options.virtual).map(([id, template]) => ({
|
|
904
|
+
id,
|
|
905
|
+
template
|
|
906
|
+
}));
|
|
907
|
+
return [...nitroTemplates, ...customTemplates];
|
|
768
908
|
}
|
|
769
909
|
|
|
770
910
|
//#endregion
|
|
771
911
|
//#region src/build/plugins.ts
|
|
772
912
|
function baseBuildPlugins(nitro, base) {
|
|
773
|
-
const plugins = [];
|
|
774
|
-
if (nitro.options.imports) plugins.push(unplugin.rollup(nitro.options.imports));
|
|
775
|
-
if (nitro.options.wasm !== false) plugins.push(unwasm(nitro.options.wasm || {}));
|
|
776
|
-
plugins.push(serverMain(nitro));
|
|
777
|
-
|
|
778
|
-
plugins.push(
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
` }, nitro.vfs));
|
|
785
|
-
plugins.push(featureFlags(nitro));
|
|
786
|
-
plugins.push(nitroResolveIds());
|
|
787
|
-
plugins.push(serverAssets(nitro));
|
|
788
|
-
plugins.push(publicAssets(nitro));
|
|
789
|
-
plugins.push(storage(nitro));
|
|
790
|
-
plugins.push(database(nitro));
|
|
791
|
-
plugins.push(routing(nitro));
|
|
792
|
-
plugins.push(raw());
|
|
793
|
-
if (nitro.options.experimental.openAPI) plugins.push(routeMeta(nitro));
|
|
794
|
-
plugins.push(runtimeConfig(nitro));
|
|
795
|
-
plugins.push(errorHandler(nitro));
|
|
796
|
-
plugins.push(virtual({ "#nitro-internal-pollyfills": base.env.polyfill.map((p) => `import '${p}';`).join("\n") || `/* No polyfills */` }, nitro.vfs, { moduleSideEffects: true }));
|
|
797
|
-
plugins.push(virtual(nitro.options.virtual, nitro.vfs));
|
|
798
|
-
if (nitro.options.renderer?.template) plugins.push(rendererTemplate(nitro));
|
|
799
|
-
plugins.push(replace({
|
|
913
|
+
const plugins$1 = [];
|
|
914
|
+
if (nitro.options.imports) plugins$1.push(unplugin.rollup(nitro.options.imports));
|
|
915
|
+
if (nitro.options.wasm !== false) plugins$1.push(unwasm(nitro.options.wasm || {}));
|
|
916
|
+
plugins$1.push(serverMain(nitro));
|
|
917
|
+
plugins$1.push(nitroResolveIds());
|
|
918
|
+
plugins$1.push(raw());
|
|
919
|
+
if (nitro.options.experimental.openAPI) plugins$1.push(routeMeta(nitro));
|
|
920
|
+
const virtualPlugin = virtual(virtualTemplates(nitro, [...base.env.polyfill]));
|
|
921
|
+
nitro.vfs = virtualPlugin.api.modules;
|
|
922
|
+
plugins$1.push(virtualPlugin);
|
|
923
|
+
plugins$1.push(replace({
|
|
800
924
|
preventAssignment: true,
|
|
801
925
|
values: base.replacements
|
|
802
926
|
}));
|
|
803
|
-
if (!nitro.options.noExternals) plugins.push(rollupNodeFileTrace(defu(nitro.options.externals, {
|
|
927
|
+
if (!nitro.options.noExternals) plugins$1.push(rollupNodeFileTrace(defu(nitro.options.externals, {
|
|
804
928
|
outDir: nitro.options.output.serverDir,
|
|
805
929
|
moduleDirectories: nitro.options.nodeModulesDirs,
|
|
806
930
|
external: nitro.options.nodeModulesDirs,
|
|
@@ -817,8 +941,8 @@ function baseBuildPlugins(nitro, base) {
|
|
|
817
941
|
exportConditions: nitro.options.exportConditions,
|
|
818
942
|
writePackageJson: true
|
|
819
943
|
})));
|
|
820
|
-
if (nitro.options.sourcemap && !nitro.options.dev && nitro.options.experimental.sourcemapMinify !== false) plugins.push(sourcemapMinify());
|
|
821
|
-
return plugins;
|
|
944
|
+
if (nitro.options.sourcemap && !nitro.options.dev && nitro.options.experimental.sourcemapMinify !== false) plugins$1.push(sourcemapMinify());
|
|
945
|
+
return plugins$1;
|
|
822
946
|
}
|
|
823
947
|
|
|
824
948
|
//#endregion
|