nitro 3.0.260415-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.
Files changed (91) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
  2. package/dist/_build/common.mjs +157 -45
  3. package/dist/_build/rolldown.mjs +6 -6
  4. package/dist/_build/rollup.mjs +11 -11
  5. package/dist/_build/vite.build.mjs +3 -3
  6. package/dist/_build/vite.dev.mjs +149 -0
  7. package/dist/_build/vite.env.mjs +177 -0
  8. package/dist/_chunks/nitro.mjs +241 -14
  9. package/dist/_chunks/nitro2.mjs +117 -90
  10. package/dist/_chunks/utils.mjs +4 -4
  11. package/dist/_common.mjs +2 -2
  12. package/dist/_dev.d.mts +1 -1
  13. package/dist/_dev.mjs +7 -6
  14. package/dist/_libs/c12+rc9.mjs +24 -11
  15. package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
  16. package/dist/_libs/citty.mjs +1 -1
  17. package/dist/_libs/common.d.mts +37 -0
  18. package/dist/_libs/commondir+is-reference.mjs +3 -3
  19. package/dist/_libs/compatx.d.mts +1 -1
  20. package/dist/_libs/compatx.mjs +1 -1
  21. package/dist/_libs/estree+pluginutils.d.mts +1 -1
  22. package/dist/_libs/estree-walker.mjs +1 -1
  23. package/dist/_libs/hasown+resolve+deepmerge.mjs +62 -49
  24. package/dist/_libs/httpxy.d.mts +2 -4
  25. package/dist/_libs/httpxy.mjs +13 -9
  26. package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
  27. package/dist/_libs/klona.mjs +1 -1
  28. package/dist/_libs/magic-string.d.mts +1 -1
  29. package/dist/_libs/mlly.d.mts +1 -1
  30. package/dist/_libs/nypm+tinyexec.mjs +137 -113
  31. package/dist/_libs/openapi-types.d.mts +730 -0
  32. package/dist/_libs/perfect-debounce.mjs +1 -1
  33. package/dist/_libs/pkg-types.d.mts +8 -5
  34. package/dist/_libs/plugin-alias.mjs +2 -2
  35. package/dist/_libs/plugin-inject.mjs +4 -2
  36. package/dist/_libs/plugin-json.mjs +2 -2
  37. package/dist/_libs/pluginutils.mjs +18 -5
  38. package/dist/_libs/readdirp+chokidar.mjs +4 -3
  39. package/dist/_libs/remapping.mjs +2 -2
  40. package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
  41. package/dist/_libs/rou3.d.mts +1 -1
  42. package/dist/_libs/rou3.mjs +1 -1
  43. package/dist/_libs/std-env.d.mts +1 -1
  44. package/dist/_libs/tsconfck.mjs +1 -1
  45. package/dist/_libs/ultrahtml.mjs +1 -1
  46. package/dist/_libs/unimport+unplugin.mjs +61 -39
  47. package/dist/_libs/unplugin+unimport.d.mts +4 -4
  48. package/dist/_libs/unwasm.d.mts +1 -1
  49. package/dist/_presets.mjs +118 -91
  50. package/dist/builder.d.mts +1 -1
  51. package/dist/builder.mjs +3 -3
  52. package/dist/cli/_chunks/build.mjs +3 -3
  53. package/dist/cli/_chunks/common.mjs +1 -1
  54. package/dist/cli/_chunks/deploy.mjs +2 -2
  55. package/dist/cli/_chunks/dev.mjs +4 -4
  56. package/dist/cli/_chunks/docs.mjs +1 -1
  57. package/dist/cli/_chunks/list.mjs +2 -2
  58. package/dist/cli/_chunks/prepare.mjs +3 -3
  59. package/dist/cli/_chunks/preview.mjs +4 -4
  60. package/dist/cli/_chunks/run.mjs +2 -2
  61. package/dist/cli/_chunks/task.mjs +1 -1
  62. package/dist/cli/index.mjs +1 -1
  63. package/dist/docs/0.docs/5.cache.md +53 -9
  64. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
  65. package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
  66. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
  67. package/dist/node_modules/ufo/dist/index.mjs +2 -2
  68. package/dist/node_modules/ufo/package.json +9 -9
  69. package/dist/presets/azure/runtime/azure-swa.mjs +2 -0
  70. package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
  71. package/dist/runtime/internal/app.mjs +4 -111
  72. package/dist/runtime/internal/route-rules.d.mts +1 -0
  73. package/dist/runtime/internal/route-rules.mjs +29 -1
  74. package/dist/runtime/internal/routes/scalar.mjs +1 -0
  75. package/dist/runtime/virtual/app.d.mts +4 -0
  76. package/dist/runtime/virtual/app.mjs +32 -0
  77. package/dist/types/index.d.mts +959 -1836
  78. package/dist/vite.d.mts +1 -1
  79. package/dist/vite.mjs +23 -331
  80. package/package.json +43 -44
  81. package/dist/THIRD-PARTY-LICENSES.md +0 -1646
  82. package/dist/_chunks/nitro3.mjs +0 -136
  83. package/dist/_chunks/nitro4.mjs +0 -127
  84. package/dist/_libs/_.mjs +0 -2
  85. package/dist/_libs/_2.mjs +0 -2
  86. package/dist/_libs/_3.mjs +0 -2
  87. package/dist/_libs/_4.mjs +0 -2
  88. package/dist/_libs/_5.mjs +0 -2
  89. package/dist/_libs/_6.mjs +0 -2
  90. package/dist/_libs/_7.mjs +0 -2
  91. package/dist/_libs/escape-string-regexp.mjs +0 -5
@@ -1,136 +0,0 @@
1
- import { ct 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 };
@@ -1,127 +0,0 @@
1
- import { F as prettyPath, ct as join, dt as resolve, 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/_.mjs");
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 };
package/dist/_libs/_.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { a as loadDotenv } from "./c12+rc9.mjs";
2
- export { loadDotenv };
package/dist/_libs/_2.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { t as mergeAssets } from "./pluginutils.mjs";
2
- export { mergeAssets };
package/dist/_libs/_3.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { t as inject } from "./plugin-inject.mjs";
2
- export { inject as default };
package/dist/_libs/_4.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { n as utils_exports, t as dist_exports } from "./c12+rc9.mjs";
2
- export { dist_exports as n, utils_exports as t };
package/dist/_libs/_5.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { n as addDevDependency } from "./nypm+tinyexec.mjs";
2
- export { addDevDependency };
package/dist/_libs/_6.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { a as detectImportsAcorn } from "./unimport+unplugin.mjs";
2
- export { detectImportsAcorn };
package/dist/_libs/_7.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { r as unplugin } from "./unimport+unplugin.mjs";
2
- export { unplugin as default };
@@ -1,5 +0,0 @@
1
- function escapeStringRegexp(string) {
2
- if (typeof string !== "string") throw new TypeError("Expected a string");
3
- return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
4
- }
5
- export { escapeStringRegexp as t };