nitro 3.0.260429-beta → 3.0.260522-beta
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/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_build/common.mjs +119 -21
- package/dist/_build/rolldown.mjs +6 -6
- package/dist/_build/rollup.mjs +11 -11
- package/dist/_build/vite.build.mjs +3 -3
- package/dist/_build/vite.dev.mjs +149 -0
- package/dist/_build/vite.env.mjs +177 -0
- package/dist/_chunks/nitro.mjs +239 -12
- package/dist/_chunks/nitro2.mjs +117 -90
- package/dist/_chunks/utils.mjs +4 -4
- package/dist/_common.mjs +1 -1
- package/dist/_dev.d.mts +1 -1
- package/dist/_dev.mjs +5 -5
- package/dist/_libs/c12+rc9.mjs +11 -10
- package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
- package/dist/_libs/citty.mjs +1 -1
- package/dist/_libs/common.d.mts +37 -0
- package/dist/_libs/commondir+is-reference.mjs +3 -3
- package/dist/_libs/compatx.d.mts +1 -1
- package/dist/_libs/compatx.mjs +1 -1
- package/dist/_libs/estree+pluginutils.d.mts +1 -1
- package/dist/_libs/estree-walker.mjs +1 -1
- package/dist/_libs/hasown+resolve+deepmerge.mjs +15 -15
- package/dist/_libs/httpxy.d.mts +1 -1
- package/dist/_libs/httpxy.mjs +8 -4
- package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
- package/dist/_libs/klona.mjs +1 -1
- package/dist/_libs/magic-string.d.mts +1 -1
- package/dist/_libs/mlly.d.mts +1 -1
- package/dist/_libs/nypm+tinyexec.mjs +92 -99
- package/dist/_libs/openapi-types.d.mts +730 -0
- package/dist/_libs/perfect-debounce.mjs +1 -1
- package/dist/_libs/pkg-types.d.mts +1 -1
- package/dist/_libs/plugin-alias.mjs +2 -2
- package/dist/_libs/plugin-inject.mjs +3 -3
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils.mjs +16 -5
- package/dist/_libs/readdirp+chokidar.mjs +2 -2
- package/dist/_libs/remapping.mjs +2 -2
- package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
- package/dist/_libs/rou3.d.mts +1 -1
- package/dist/_libs/rou3.mjs +1 -1
- package/dist/_libs/std-env.d.mts +1 -1
- package/dist/_libs/tsconfck.mjs +1 -1
- package/dist/_libs/ultrahtml.mjs +1 -1
- package/dist/_libs/{unimport+unplugin+oxc-parser.mjs → unimport+unplugin.mjs} +18 -8
- package/dist/_libs/unplugin+unimport.d.mts +3 -3
- package/dist/_libs/unwasm.d.mts +1 -1
- package/dist/_presets.mjs +117 -91
- package/dist/builder.d.mts +1 -1
- package/dist/builder.mjs +3 -3
- package/dist/cli/_chunks/build.mjs +3 -3
- package/dist/cli/_chunks/common.mjs +1 -1
- package/dist/cli/_chunks/deploy.mjs +2 -2
- package/dist/cli/_chunks/dev.mjs +4 -4
- package/dist/cli/_chunks/docs.mjs +1 -1
- package/dist/cli/_chunks/list.mjs +2 -2
- package/dist/cli/_chunks/prepare.mjs +3 -3
- package/dist/cli/_chunks/preview.mjs +4 -4
- package/dist/cli/_chunks/run.mjs +2 -2
- package/dist/cli/_chunks/task.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
- package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
- package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
- package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
- package/dist/runtime/internal/app.mjs +4 -111
- package/dist/runtime/virtual/app.d.mts +4 -0
- package/dist/runtime/virtual/app.mjs +32 -0
- package/dist/types/index.d.mts +21 -1756
- package/dist/vite.mjs +23 -337
- package/package.json +37 -39
- package/dist/THIRD-PARTY-LICENSES.md +0 -1676
- package/dist/_chunks/nitro3.mjs +0 -136
- package/dist/_chunks/nitro4.mjs +0 -127
package/dist/_chunks/nitro3.mjs
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { lt as join } from "../_build/common.mjs";
|
|
2
|
-
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
|
|
3
|
-
import { runtimeDir } from "nitro/meta";
|
|
4
|
-
import { hash } from "ohash";
|
|
5
|
-
const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
|
|
6
|
-
function initNitroRouting(nitro) {
|
|
7
|
-
const envConditions = new Set([
|
|
8
|
-
nitro.options.dev ? "dev" : "prod",
|
|
9
|
-
nitro.options.preset,
|
|
10
|
-
nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
|
|
11
|
-
].filter(Boolean));
|
|
12
|
-
const matchesEnv = (h) => {
|
|
13
|
-
const envs = (Array.isArray(h.env) ? h.env : [h.env]).filter(Boolean);
|
|
14
|
-
return envs.length === 0 || envs.some((env) => envConditions.has(env));
|
|
15
|
-
};
|
|
16
|
-
const routes = new Router(nitro.options.baseURL);
|
|
17
|
-
const routeRules = new Router(nitro.options.baseURL);
|
|
18
|
-
const globalMiddleware = [];
|
|
19
|
-
const routedMiddleware = new Router(nitro.options.baseURL);
|
|
20
|
-
const sync = () => {
|
|
21
|
-
routeRules._update(Object.entries(nitro.options.routeRules).map(([route, data]) => ({
|
|
22
|
-
route,
|
|
23
|
-
method: "",
|
|
24
|
-
data: {
|
|
25
|
-
...data,
|
|
26
|
-
_route: route
|
|
27
|
-
}
|
|
28
|
-
})));
|
|
29
|
-
const _routes = [
|
|
30
|
-
...Object.entries(nitro.options.routes).flatMap(([route, handler]) => {
|
|
31
|
-
if (typeof handler === "string") handler = { handler };
|
|
32
|
-
return {
|
|
33
|
-
...handler,
|
|
34
|
-
route,
|
|
35
|
-
middleware: false
|
|
36
|
-
};
|
|
37
|
-
}),
|
|
38
|
-
...nitro.options.handlers,
|
|
39
|
-
...nitro.scannedHandlers
|
|
40
|
-
].filter((h) => h && !h.middleware && matchesEnv(h));
|
|
41
|
-
if (nitro.options.serverEntry && nitro.options.serverEntry.handler) _routes.push({
|
|
42
|
-
route: "/**",
|
|
43
|
-
lazy: false,
|
|
44
|
-
format: nitro.options.serverEntry.format,
|
|
45
|
-
handler: nitro.options.serverEntry.handler
|
|
46
|
-
});
|
|
47
|
-
if (nitro.options.renderer?.handler) _routes.push({
|
|
48
|
-
route: "/**",
|
|
49
|
-
lazy: true,
|
|
50
|
-
handler: nitro.options.renderer?.handler
|
|
51
|
-
});
|
|
52
|
-
routes._update(_routes.map((h) => ({
|
|
53
|
-
...h,
|
|
54
|
-
method: h.method || "",
|
|
55
|
-
data: handlerWithImportHash(h)
|
|
56
|
-
})), { merge: true });
|
|
57
|
-
const _middleware = [...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => h && h.middleware && matchesEnv(h));
|
|
58
|
-
if (nitro.options.serveStatic) _middleware.unshift({
|
|
59
|
-
route: "/**",
|
|
60
|
-
middleware: true,
|
|
61
|
-
handler: join(runtimeDir, "internal/static")
|
|
62
|
-
});
|
|
63
|
-
globalMiddleware.splice(0, globalMiddleware.length, ..._middleware.filter((h) => isGlobalMiddleware(h)).map((m) => handlerWithImportHash(m)));
|
|
64
|
-
routedMiddleware._update(_middleware.filter((h) => !isGlobalMiddleware(h)).map((h) => ({
|
|
65
|
-
...h,
|
|
66
|
-
method: h.method || "",
|
|
67
|
-
data: handlerWithImportHash(h)
|
|
68
|
-
})));
|
|
69
|
-
};
|
|
70
|
-
nitro.routing = Object.freeze({
|
|
71
|
-
sync,
|
|
72
|
-
routes,
|
|
73
|
-
routeRules,
|
|
74
|
-
globalMiddleware,
|
|
75
|
-
routedMiddleware
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function handlerWithImportHash(h) {
|
|
79
|
-
const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
|
|
80
|
-
return {
|
|
81
|
-
...h,
|
|
82
|
-
_importHash: id
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
var Router = class {
|
|
86
|
-
_routes;
|
|
87
|
-
_router;
|
|
88
|
-
_compiled;
|
|
89
|
-
_baseURL;
|
|
90
|
-
constructor(baseURL) {
|
|
91
|
-
this._update([]);
|
|
92
|
-
this._baseURL = baseURL || "";
|
|
93
|
-
if (this._baseURL.endsWith("/")) this._baseURL = this._baseURL.slice(0, -1);
|
|
94
|
-
}
|
|
95
|
-
get routes() {
|
|
96
|
-
return this._routes;
|
|
97
|
-
}
|
|
98
|
-
_update(routes, opts) {
|
|
99
|
-
this._routes = routes;
|
|
100
|
-
this._router = createRouter();
|
|
101
|
-
this._compiled = void 0;
|
|
102
|
-
for (const route of routes) addRoute(this._router, route.method, this._baseURL + route.route, route.data);
|
|
103
|
-
if (opts?.merge) mergeCatchAll(this._router);
|
|
104
|
-
}
|
|
105
|
-
hasRoutes() {
|
|
106
|
-
return this._routes.length > 0;
|
|
107
|
-
}
|
|
108
|
-
compileToString(opts) {
|
|
109
|
-
const key = opts ? hash(opts) : "";
|
|
110
|
-
this._compiled ||= {};
|
|
111
|
-
if (this._compiled[key]) return this._compiled[key];
|
|
112
|
-
this._compiled[key] = compileRouterToString(this._router, void 0, opts);
|
|
113
|
-
if (this.routes.length === 1 && this.routes[0].route === "/**" && this.routes[0].method === "") {
|
|
114
|
-
const data = (opts?.serialize || JSON.stringify)(this.routes[0].data);
|
|
115
|
-
let retCode = `{data,params:{"_":p.slice(1)}}`;
|
|
116
|
-
if (opts?.matchAll) retCode = `[${retCode}]`;
|
|
117
|
-
this._compiled[key] = `/* @__PURE__ */ (() => {const data=${data};return ((_m, p)=>{return ${retCode};})})()`;
|
|
118
|
-
}
|
|
119
|
-
return this._compiled[key];
|
|
120
|
-
}
|
|
121
|
-
match(method, path) {
|
|
122
|
-
return findRoute(this._router, method, path)?.data;
|
|
123
|
-
}
|
|
124
|
-
matchAll(method, path) {
|
|
125
|
-
return findAllRoutes(this._router, method, path).map((route) => route.data);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
function mergeCatchAll(router) {
|
|
129
|
-
const handlers = router.root?.wildcard?.methods?.[""];
|
|
130
|
-
if (!handlers || handlers.length < 2) return;
|
|
131
|
-
handlers.splice(0, handlers.length, {
|
|
132
|
-
...handlers[0],
|
|
133
|
-
data: handlers.map((h) => h.data)
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
export { initNitroRouting as n, Router as t };
|
package/dist/_chunks/nitro4.mjs
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { F as prettyPath, ft as resolve, lt as join, m as getBuildInfo } from "../_build/common.mjs";
|
|
2
|
-
import { n as proxyFetch, r as proxyUpgrade } from "../_libs/httpxy.mjs";
|
|
3
|
-
import consola from "consola";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
5
|
-
async function startPreview(opts) {
|
|
6
|
-
const { outputDir, buildInfo } = await getBuildInfo(opts.rootDir);
|
|
7
|
-
if (!buildInfo) throw new Error("Cannot load nitro build info. Make sure to build first.");
|
|
8
|
-
const info = [
|
|
9
|
-
["Build Directory:", prettyPath(outputDir)],
|
|
10
|
-
["Date:", buildInfo.date && new Date(buildInfo.date).toLocaleString()],
|
|
11
|
-
["Nitro Version:", buildInfo.versions.nitro],
|
|
12
|
-
["Nitro Preset:", buildInfo.preset],
|
|
13
|
-
buildInfo.framework?.name !== "nitro" && ["Framework:", buildInfo.framework?.name + (buildInfo.framework?.version ? ` (v${buildInfo.framework.version})` : "")]
|
|
14
|
-
].filter((i) => i && i[1]);
|
|
15
|
-
consola.box({
|
|
16
|
-
title: " [Build Info] ",
|
|
17
|
-
message: info.map((i) => `- ${i[0]} ${i[1]}`).join("\n")
|
|
18
|
-
});
|
|
19
|
-
const dotEnvEntries = await loadPreviewDotEnv(opts.rootDir);
|
|
20
|
-
if (dotEnvEntries.length > 0) consola.box({
|
|
21
|
-
title: " [Environment Variables] ",
|
|
22
|
-
message: [
|
|
23
|
-
"Loaded variables from .env files (preview mode only).",
|
|
24
|
-
"Set platform environment variables for production:",
|
|
25
|
-
...dotEnvEntries.map(([key, val]) => ` - ${key}`)
|
|
26
|
-
].join("\n")
|
|
27
|
-
});
|
|
28
|
-
if (buildInfo.preset.includes("cloudflare")) {
|
|
29
|
-
if (!buildInfo.commands?.preview) throw new Error(`No nitro build preview command found for the "${buildInfo.preset}" preset.`);
|
|
30
|
-
return await runPreviewCommand({
|
|
31
|
-
command: buildInfo.commands.preview,
|
|
32
|
-
rootDir: opts.rootDir,
|
|
33
|
-
env: dotEnvEntries
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
let fetchHandler = () => Promise.resolve(new Response("Not Found", { status: 404 }));
|
|
37
|
-
if (buildInfo.serverEntry) {
|
|
38
|
-
for (const [key, val] of dotEnvEntries) if (!process.env[key]) process.env[key] = val;
|
|
39
|
-
const { loadServerEntry } = await import("srvx/loader");
|
|
40
|
-
const entry = await loadServerEntry({
|
|
41
|
-
entry: resolve(outputDir, buildInfo.serverEntry),
|
|
42
|
-
...opts.loader
|
|
43
|
-
});
|
|
44
|
-
if (entry.fetch) fetchHandler = entry.fetch;
|
|
45
|
-
}
|
|
46
|
-
if (buildInfo.publicDir) {
|
|
47
|
-
const { serveStatic } = await import("srvx/static");
|
|
48
|
-
const staticHandler = serveStatic({ dir: join(outputDir, buildInfo.publicDir) });
|
|
49
|
-
const originalFetchHandler = fetchHandler;
|
|
50
|
-
fetchHandler = async (req) => {
|
|
51
|
-
const staticRes = await staticHandler(req, () => void 0);
|
|
52
|
-
if (staticRes) return staticRes;
|
|
53
|
-
return originalFetchHandler(req);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
fetch: fetchHandler,
|
|
58
|
-
async close() {}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async function loadPreviewDotEnv(root) {
|
|
62
|
-
const { loadDotenv } = await import("../_libs/c12+rc9.mjs").then((n) => n.n);
|
|
63
|
-
const env = await loadDotenv({
|
|
64
|
-
cwd: root,
|
|
65
|
-
fileName: [
|
|
66
|
-
".env.preview",
|
|
67
|
-
".env.production",
|
|
68
|
-
".env"
|
|
69
|
-
]
|
|
70
|
-
});
|
|
71
|
-
return Object.entries(env).filter(([_key, val]) => val);
|
|
72
|
-
}
|
|
73
|
-
async function runPreviewCommand(opts) {
|
|
74
|
-
const [arg0, ...args] = opts.command.split(" ");
|
|
75
|
-
consola.info(`Spawning preview server...`);
|
|
76
|
-
consola.info(opts.command);
|
|
77
|
-
console.log("");
|
|
78
|
-
const { getRandomPort, waitForPort } = await import("get-port-please");
|
|
79
|
-
const randomPort = await getRandomPort();
|
|
80
|
-
const child = spawn(arg0, [
|
|
81
|
-
...args,
|
|
82
|
-
"--port",
|
|
83
|
-
String(randomPort),
|
|
84
|
-
"--host",
|
|
85
|
-
"localhost"
|
|
86
|
-
], {
|
|
87
|
-
stdio: "inherit",
|
|
88
|
-
cwd: opts.rootDir,
|
|
89
|
-
env: {
|
|
90
|
-
...process.env,
|
|
91
|
-
...Object.fromEntries(opts.env ?? []),
|
|
92
|
-
PORT: String(randomPort)
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
const killChild = (signal) => {
|
|
96
|
-
if (child && !child.killed) child.kill(signal);
|
|
97
|
-
};
|
|
98
|
-
for (const sig of ["SIGINT", "SIGHUP"]) process.once(sig, () => {
|
|
99
|
-
killChild(sig);
|
|
100
|
-
});
|
|
101
|
-
child.once("exit", (code) => {
|
|
102
|
-
if (code && code !== 0) consola.error(`[nitro] Preview server exited with code ${code}`);
|
|
103
|
-
});
|
|
104
|
-
await waitForPort(randomPort, {
|
|
105
|
-
retries: 20,
|
|
106
|
-
delay: 500,
|
|
107
|
-
host: "localhost"
|
|
108
|
-
});
|
|
109
|
-
return {
|
|
110
|
-
fetch(req) {
|
|
111
|
-
return proxyFetch({
|
|
112
|
-
port: randomPort,
|
|
113
|
-
host: "localhost"
|
|
114
|
-
}, req);
|
|
115
|
-
},
|
|
116
|
-
async upgrade(req, socket, head, opts) {
|
|
117
|
-
await proxyUpgrade({
|
|
118
|
-
port: randomPort,
|
|
119
|
-
host: "localhost"
|
|
120
|
-
}, req, socket, head, opts);
|
|
121
|
-
},
|
|
122
|
-
async close() {
|
|
123
|
-
killChild("SIGTERM");
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
export { startPreview as t };
|