nitro 3.0.1-alpha.2 → 3.0.260311-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/LICENSE +6 -0
- package/README.md +2 -2
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +6977 -2556
- package/dist/_build/rolldown.mjs +32 -31
- package/dist/_build/rollup.mjs +28 -35
- package/dist/_build/vite.build.mjs +10 -8
- package/dist/_chunks/nitro.mjs +80 -112
- package/dist/_chunks/nitro2.mjs +8 -7
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +42 -24
- package/dist/_common.mjs +14 -24
- package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -320
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +52 -36
- package/dist/_libs/citty.mjs +10 -12
- package/dist/_libs/commondir+is-reference.mjs +60 -49
- package/dist/_libs/compatx.mjs +1 -2
- package/dist/_libs/esbuild.d.mts +1 -1
- package/dist/_libs/escape-string-regexp.mjs +1 -2
- package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +2 -2
- package/dist/_libs/estree-walker.mjs +1 -4
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +146 -169
- package/dist/_libs/httpxy.d.mts +12 -9
- package/dist/_libs/httpxy.mjs +299 -43
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +1 -2
- package/dist/_libs/mlly.d.mts +1 -1
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/plugin-alias.mjs +2 -4
- package/dist/_libs/plugin-inject.mjs +2 -6
- package/dist/_libs/plugin-json.mjs +2 -4
- package/dist/_libs/pluginutils.mjs +5 -11
- package/dist/_libs/readdirp+chokidar.mjs +187 -192
- package/dist/_libs/remapping.mjs +1 -3
- package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -21
- package/dist/_libs/rou3.d.mts +3 -2
- package/dist/_libs/rou3.mjs +225 -51
- package/dist/_libs/std-env.d.mts +10 -2
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +21 -40
- package/dist/_libs/ultrahtml.mjs +3 -14
- package/dist/_libs/unimport+unplugin.mjs +250 -351
- package/dist/_libs/unplugin+unimport.d.mts +7 -10
- package/dist/_presets.mjs +389 -432
- package/dist/builder.d.mts +5 -4
- package/dist/builder.mjs +12 -6
- package/dist/cli/_chunks/build.mjs +22 -23
- package/dist/cli/_chunks/common.mjs +1 -2
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +9 -9
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +4 -6
- package/dist/cli/_chunks/prepare.mjs +2 -4
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +7 -9
- package/dist/cli/_chunks/task.mjs +1 -3
- package/dist/cli/index.mjs +5 -4
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
- package/dist/node_modules/@poppinss/dumper/package.json +1 -1
- package/dist/node_modules/croner/dist/croner.js +1 -1
- package/dist/node_modules/croner/package.json +11 -1
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +204 -351
- package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +34 -31
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +9 -56
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +0 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
- package/dist/presets/bun/runtime/bun.mjs +4 -3
- package/dist/presets/deno/runtime/deno-server.mjs +4 -3
- package/dist/presets/netlify/runtime/netlify-edge.mjs +0 -1
- package/dist/presets/netlify/runtime/netlify.mjs +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +3 -2
- package/dist/presets/node/runtime/node-server.mjs +3 -2
- package/dist/presets/stormkit/runtime/stormkit.mjs +0 -1
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +2 -4
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/internal/cache.d.mts +0 -4
- package/dist/runtime/internal/cache.mjs +32 -256
- package/dist/runtime/internal/context.d.mts +3 -1
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +38 -40
- package/dist/runtime/internal/error/hooks.d.mts +1 -1
- package/dist/runtime/internal/error/prod.d.mts +2 -5
- package/dist/runtime/internal/error/prod.mjs +19 -33
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/route-rules.d.mts +9 -4
- package/dist/runtime/internal/route-rules.mjs +9 -1
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
- package/dist/runtime/internal/routes/dev-tasks.mjs +6 -2
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
- package/dist/runtime/internal/runtime-config.d.mts +1 -1
- package/dist/runtime/internal/static.mjs +5 -4
- package/dist/runtime/internal/task.d.mts +3 -1
- package/dist/runtime/internal/task.mjs +2 -2
- package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/meta.mjs +1 -0
- package/dist/runtime/nitro.d.mts +2 -0
- package/dist/runtime/nitro.mjs +2 -0
- package/dist/runtime/virtual/error-handler.mjs +1 -1
- package/dist/runtime/virtual/server-assets.d.mts +2 -1
- package/dist/runtime/vite.d.mts +1 -1
- package/dist/types/index.d.mts +68 -117
- package/dist/types/index.mjs +1 -11
- package/dist/vite.d.mts +3 -3
- package/dist/vite.mjs +236 -233
- package/package.json +83 -68
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
- package/dist/_libs/confbox.mjs +0 -2509
- package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
- package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
- package/dist/node_modules/hookable/dist/index.mjs +0 -266
- package/dist/node_modules/hookable/package.json +0 -52
- package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
- package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
- package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
- package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
- package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
- package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
- package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
- package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
- package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
- package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
- package/dist/presets/azure/runtime/_utils.d.mts +0 -2
- package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
- package/dist/presets/bun/runtime/bun.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
- package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
- package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
- package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
- package/dist/presets/node/runtime/node-server.d.mts +0 -3
- package/dist/presets/standard/runtime/server.d.mts +0 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
- package/dist/presets/vercel/runtime/isr.d.mts +0 -2
- package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
- package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
- package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
- package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
- package/dist/runtime/internal/vite/node-runner.mjs +0 -359
package/dist/_chunks/nitro.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { i as loadConfig, s as watchConfig } from "../_libs/c12+rc9.mjs";
|
|
2
|
+
import { A as src_default, F as prettyPath, H as v, I as resolveNitroPath, K as findWorkspaceDir, L as writeFile$1, O as scanUnprefixedPublicAssets, ct as join, dt as resolve, j as build, k as compressPublicAssets, nt as resolveModulePath, p as runParallel, rt as resolveModuleURL, ut as relative, z as _ } from "../_build/common.mjs";
|
|
3
3
|
import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
|
|
4
4
|
import { t as klona } from "../_libs/klona.mjs";
|
|
5
5
|
import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
|
|
@@ -8,24 +8,23 @@ import { n as scanHandlers, t as scanAndSyncOptions } from "./nitro2.mjs";
|
|
|
8
8
|
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
|
|
9
9
|
import { n as z, t as P } from "../_libs/ultrahtml.mjs";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
|
-
import consola
|
|
11
|
+
import consola, { consola as consola$1 } from "consola";
|
|
12
12
|
import { Hookable, createDebugger } from "hookable";
|
|
13
|
-
import { existsSync } from "node:fs";
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
14
|
import { readFile } from "node:fs/promises";
|
|
15
15
|
import { pathToFileURL } from "node:url";
|
|
16
16
|
import { defu } from "defu";
|
|
17
|
+
import { runtimeDir, version } from "nitro/meta";
|
|
17
18
|
import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
|
|
18
|
-
import { runtimeDir } from "nitro/meta";
|
|
19
19
|
import { colors } from "consola/utils";
|
|
20
20
|
import { hash } from "ohash";
|
|
21
|
-
import http from "node:http";
|
|
22
21
|
import { toRequest } from "h3";
|
|
23
|
-
|
|
22
|
+
import http from "node:http";
|
|
24
23
|
//#region src/config/defaults.ts
|
|
25
24
|
const NitroDefaults = {
|
|
26
25
|
compatibilityDate: "latest",
|
|
27
|
-
debug:
|
|
28
|
-
logLevel:
|
|
26
|
+
debug: _,
|
|
27
|
+
logLevel: v ? 1 : 3,
|
|
29
28
|
runtimeConfig: {
|
|
30
29
|
app: {},
|
|
31
30
|
nitro: {}
|
|
@@ -95,10 +94,9 @@ const NitroDefaults = {
|
|
|
95
94
|
commands: {},
|
|
96
95
|
framework: {
|
|
97
96
|
name: "nitro",
|
|
98
|
-
version
|
|
97
|
+
version
|
|
99
98
|
}
|
|
100
99
|
};
|
|
101
|
-
|
|
102
100
|
//#endregion
|
|
103
101
|
//#region src/config/resolvers/assets.ts
|
|
104
102
|
async function resolveAssetsOptions(options) {
|
|
@@ -126,13 +124,11 @@ async function resolveAssetsOptions(options) {
|
|
|
126
124
|
if (asset.maxAge && !asset.fallthrough) options.routeRules[asset.baseURL + "/**"] = defu(routeRule, { headers: { "cache-control": `public, max-age=${asset.maxAge}, immutable` } });
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
|
-
|
|
130
127
|
//#endregion
|
|
131
128
|
//#region src/config/resolvers/compatibility.ts
|
|
132
129
|
async function resolveCompatibilityOptions(options) {
|
|
133
130
|
options.compatibilityDate = resolveCompatibilityDatesFromEnv(options.compatibilityDate);
|
|
134
131
|
}
|
|
135
|
-
|
|
136
132
|
//#endregion
|
|
137
133
|
//#region src/config/resolvers/database.ts
|
|
138
134
|
async function resolveDatabaseOptions(options) {
|
|
@@ -152,7 +148,6 @@ async function resolveDatabaseOptions(options) {
|
|
|
152
148
|
} };
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
|
-
|
|
156
151
|
//#endregion
|
|
157
152
|
//#region src/config/resolvers/export-conditions.ts
|
|
158
153
|
async function resolveExportConditionsOptions(options) {
|
|
@@ -162,19 +157,14 @@ async function resolveExportConditionsOptions(options) {
|
|
|
162
157
|
wasm: options.wasm !== false
|
|
163
158
|
});
|
|
164
159
|
}
|
|
165
|
-
function _resolveExportConditions(
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (opts.node)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
resolvedConditions.push("import", "default", "module");
|
|
173
|
-
if ("Bun" in globalThis) resolvedConditions.push("bun");
|
|
174
|
-
else if ("Deno" in globalThis) resolvedConditions.push("deno");
|
|
175
|
-
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
|
|
160
|
+
function _resolveExportConditions(userConditions, opts) {
|
|
161
|
+
const conditions = [...userConditions.filter((c) => !c.startsWith("!"))];
|
|
162
|
+
conditions.push(opts.dev ? "development" : "production");
|
|
163
|
+
if (opts.wasm) conditions.push("wasm", "unwasm");
|
|
164
|
+
if (opts.node) conditions.push("node");
|
|
165
|
+
const negated = new Set(userConditions.filter((c) => c.startsWith("!")).map((c) => c.slice(1)));
|
|
166
|
+
return [...new Set(conditions)].filter((c) => !negated.has(c));
|
|
176
167
|
}
|
|
177
|
-
|
|
178
168
|
//#endregion
|
|
179
169
|
//#region src/config/resolvers/imports.ts
|
|
180
170
|
async function resolveImportsOptions(options) {
|
|
@@ -186,10 +176,9 @@ async function resolveImportsOptions(options) {
|
|
|
186
176
|
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
187
177
|
options.imports.exclude.push(options.buildDir);
|
|
188
178
|
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
189
|
-
options.imports.exclude.push(scanDirsInNodeModules.length > 0 ?
|
|
179
|
+
options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
|
|
190
180
|
}
|
|
191
181
|
}
|
|
192
|
-
|
|
193
182
|
//#endregion
|
|
194
183
|
//#region src/config/resolvers/open-api.ts
|
|
195
184
|
async function resolveOpenAPIOptions(options) {
|
|
@@ -229,7 +218,6 @@ async function resolveOpenAPIOptions(options) {
|
|
|
229
218
|
options.prerender.routes.push(...prerenderRoutes);
|
|
230
219
|
}
|
|
231
220
|
}
|
|
232
|
-
|
|
233
221
|
//#endregion
|
|
234
222
|
//#region src/config/resolvers/tsconfig.ts
|
|
235
223
|
async function resolveTsconfig(options) {
|
|
@@ -246,8 +234,7 @@ async function loadTsconfig(root) {
|
|
|
246
234
|
cache: loadTsconfig["__cache"] ??= new TSConfckCache(),
|
|
247
235
|
ignoreNodeModules: true
|
|
248
236
|
};
|
|
249
|
-
const
|
|
250
|
-
const parsed = await parse(tsConfigPath, opts).catch(() => void 0);
|
|
237
|
+
const parsed = await parse(join(root, "tsconfig.json"), opts).catch(() => void 0);
|
|
251
238
|
if (!parsed) return {};
|
|
252
239
|
const { tsconfig, tsconfigFile } = parsed;
|
|
253
240
|
tsconfig.compilerOptions ??= {};
|
|
@@ -276,7 +263,6 @@ function tsConfigToAliasObj(tsconfig, root) {
|
|
|
276
263
|
}
|
|
277
264
|
return alias;
|
|
278
265
|
}
|
|
279
|
-
|
|
280
266
|
//#endregion
|
|
281
267
|
//#region src/config/resolvers/paths.ts
|
|
282
268
|
const RESOLVE_EXTENSIONS = [
|
|
@@ -293,7 +279,7 @@ async function resolvePathOptions(options) {
|
|
|
293
279
|
options.workspaceDir ||= await findWorkspaceDir(options.rootDir).catch(() => options.rootDir) + "/";
|
|
294
280
|
if (options.srcDir) {
|
|
295
281
|
if (options.serverDir === void 0) options.serverDir = options.srcDir;
|
|
296
|
-
consola
|
|
282
|
+
consola.warn(`"srcDir" option is deprecated. Please use "serverDir" instead.`);
|
|
297
283
|
}
|
|
298
284
|
if (options.serverDir !== false) {
|
|
299
285
|
if (options.serverDir === true) options.serverDir = "server";
|
|
@@ -332,7 +318,7 @@ async function resolvePathOptions(options) {
|
|
|
332
318
|
if (detected) {
|
|
333
319
|
options.serverEntry ??= { handler: "" };
|
|
334
320
|
options.serverEntry.handler = detected;
|
|
335
|
-
consola
|
|
321
|
+
consola.info(`Detected \`${prettyPath(detected)}\` as server entry.`);
|
|
336
322
|
}
|
|
337
323
|
}
|
|
338
324
|
if (options.serverEntry?.handler && !options.serverEntry?.format) {
|
|
@@ -359,7 +345,7 @@ async function resolvePathOptions(options) {
|
|
|
359
345
|
if (defaultIndex) {
|
|
360
346
|
options.renderer ??= {};
|
|
361
347
|
options.renderer.template = defaultIndex;
|
|
362
|
-
consola
|
|
348
|
+
consola.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
363
349
|
}
|
|
364
350
|
}
|
|
365
351
|
if (options.renderer?.template && !options.renderer?.handler) {
|
|
@@ -368,7 +354,6 @@ async function resolvePathOptions(options) {
|
|
|
368
354
|
}
|
|
369
355
|
}
|
|
370
356
|
}
|
|
371
|
-
|
|
372
357
|
//#endregion
|
|
373
358
|
//#region src/config/resolvers/route-rules.ts
|
|
374
359
|
async function resolveRouteRulesOptions(options) {
|
|
@@ -413,7 +398,6 @@ function normalizeRouteRules(config) {
|
|
|
413
398
|
}
|
|
414
399
|
return normalizedRules;
|
|
415
400
|
}
|
|
416
|
-
|
|
417
401
|
//#endregion
|
|
418
402
|
//#region src/config/resolvers/runtime-config.ts
|
|
419
403
|
async function resolveRuntimeConfigOptions(options) {
|
|
@@ -450,17 +434,14 @@ function checkSerializableRuntimeConfig(obj, path = []) {
|
|
|
450
434
|
function isPrimitiveValue(value) {
|
|
451
435
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
452
436
|
}
|
|
453
|
-
|
|
454
437
|
//#endregion
|
|
455
438
|
//#region src/config/resolvers/storage.ts
|
|
456
439
|
async function resolveStorageOptions(options) {}
|
|
457
|
-
|
|
458
440
|
//#endregion
|
|
459
441
|
//#region src/config/resolvers/url.ts
|
|
460
442
|
async function resolveURLOptions(options) {
|
|
461
443
|
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
462
444
|
}
|
|
463
|
-
|
|
464
445
|
//#endregion
|
|
465
446
|
//#region src/config/resolvers/error.ts
|
|
466
447
|
async function resolveErrorOptions(options) {
|
|
@@ -469,7 +450,6 @@ async function resolveErrorOptions(options) {
|
|
|
469
450
|
options.errorHandler = options.errorHandler.map((h) => resolveNitroPath(h, options));
|
|
470
451
|
options.errorHandler.push(join(runtimeDir, `internal/error/${options.dev ? "dev" : "prod"}`));
|
|
471
452
|
}
|
|
472
|
-
|
|
473
453
|
//#endregion
|
|
474
454
|
//#region src/config/resolvers/unenv.ts
|
|
475
455
|
const common = {
|
|
@@ -514,7 +494,6 @@ async function resolveUnenv(options) {
|
|
|
514
494
|
if (!options.node) options.unenv.unshift(nodeless);
|
|
515
495
|
options.unenv.unshift(common);
|
|
516
496
|
}
|
|
517
|
-
|
|
518
497
|
//#endregion
|
|
519
498
|
//#region src/config/resolvers/builder.ts
|
|
520
499
|
const VALID_BUILDERS = [
|
|
@@ -527,8 +506,8 @@ async function resolveBuilder(options) {
|
|
|
527
506
|
if (options.builder) {
|
|
528
507
|
if (!VALID_BUILDERS.includes(options.builder)) throw new Error(`Invalid nitro builder "${options.builder}". Valid builders are: ${VALID_BUILDERS.join(", ")}.`);
|
|
529
508
|
const pkg = options.builder;
|
|
530
|
-
if (!isPkgInstalled(pkg, options.rootDir)) {
|
|
531
|
-
if (!await consola
|
|
509
|
+
if (pkg !== "rolldown" && !isPkgInstalled(pkg, options.rootDir)) {
|
|
510
|
+
if (!await consola.prompt(`Nitro builder package \`${pkg}\` is not installed. Would you like to install it?`, {
|
|
532
511
|
type: "confirm",
|
|
533
512
|
default: true,
|
|
534
513
|
cancel: "null"
|
|
@@ -537,40 +516,39 @@ async function resolveBuilder(options) {
|
|
|
537
516
|
}
|
|
538
517
|
return;
|
|
539
518
|
}
|
|
540
|
-
|
|
541
|
-
"
|
|
542
|
-
"rollup",
|
|
543
|
-
"vite"
|
|
544
|
-
]) if (isPkgInstalled(pkg, options.rootDir)) {
|
|
545
|
-
options.builder = pkg;
|
|
519
|
+
if (isPkgInstalled("vite", options.rootDir) && hasNitroViteConfig(options)) {
|
|
520
|
+
options.builder = "vite";
|
|
546
521
|
return;
|
|
547
522
|
}
|
|
548
|
-
|
|
549
|
-
type: "select",
|
|
550
|
-
cancel: "null",
|
|
551
|
-
options: VALID_BUILDERS.map((b) => ({
|
|
552
|
-
label: b,
|
|
553
|
-
value: b
|
|
554
|
-
}))
|
|
555
|
-
});
|
|
556
|
-
if (!pkgToInstall) throw new Error(`No nitro builder specified. Please install one of the following packages: ${VALID_BUILDERS.join(", ")} and set it as the builder in your nitro config or via the NITRO_BUILDER environment variable.`);
|
|
557
|
-
await installPkg(pkgToInstall, options.rootDir);
|
|
558
|
-
options.builder = pkgToInstall;
|
|
523
|
+
options.builder = "rolldown";
|
|
559
524
|
}
|
|
560
|
-
const
|
|
525
|
+
const _require = createRequire(import.meta.url);
|
|
561
526
|
function isPkgInstalled(pkg, root) {
|
|
562
527
|
try {
|
|
563
|
-
|
|
528
|
+
_require.resolve(pkg, { paths: [root] });
|
|
564
529
|
return true;
|
|
565
530
|
} catch {
|
|
566
531
|
return false;
|
|
567
532
|
}
|
|
568
533
|
}
|
|
569
534
|
async function installPkg(pkg, root) {
|
|
570
|
-
const { addDevDependency } = await import("../_libs/
|
|
535
|
+
const { addDevDependency } = await import("../_libs/_5.mjs");
|
|
571
536
|
return addDevDependency(pkg, { cwd: root });
|
|
572
537
|
}
|
|
573
|
-
|
|
538
|
+
function hasNitroViteConfig(options) {
|
|
539
|
+
for (const ext of [
|
|
540
|
+
".ts",
|
|
541
|
+
".mts",
|
|
542
|
+
".js",
|
|
543
|
+
".mjs"
|
|
544
|
+
]) {
|
|
545
|
+
const configPath = resolve(options.rootDir, `vite.config${ext}`);
|
|
546
|
+
if (existsSync(configPath)) try {
|
|
547
|
+
if (readFileSync(configPath, "utf8").includes("nitro(")) return true;
|
|
548
|
+
} catch {}
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
574
552
|
//#endregion
|
|
575
553
|
//#region src/config/loader.ts
|
|
576
554
|
const configResolvers = [
|
|
@@ -602,16 +580,14 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
602
580
|
const { resolvePreset } = await import("../_presets.mjs");
|
|
603
581
|
let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
|
|
604
582
|
const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
|
|
583
|
+
const envName = opts.c12?.envName ?? (configOverrides.dev ? "development" : "production");
|
|
605
584
|
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
606
585
|
name: "nitro",
|
|
607
586
|
cwd: configOverrides.rootDir,
|
|
608
587
|
dotenv: _dotenv,
|
|
588
|
+
envName,
|
|
609
589
|
extend: { extendKey: ["extends", "preset"] },
|
|
610
590
|
defaults: NitroDefaults,
|
|
611
|
-
jitiOptions: { alias: {
|
|
612
|
-
nitropack: "nitro/config",
|
|
613
|
-
"nitro/config": "nitro/config"
|
|
614
|
-
} },
|
|
615
591
|
async overrides({ rawConfigs }) {
|
|
616
592
|
const getConf = (key) => configOverrides[key] ?? rawConfigs.main?.[key] ?? rawConfigs.rc?.[key] ?? rawConfigs.packageJson?.[key];
|
|
617
593
|
if (!compatibilityDate) compatibilityDate = getConf("compatibilityDate");
|
|
@@ -639,12 +615,12 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
639
615
|
};
|
|
640
616
|
},
|
|
641
617
|
async resolve(id) {
|
|
642
|
-
const preset
|
|
618
|
+
const preset = await resolvePreset(id, {
|
|
643
619
|
static: configOverrides.static,
|
|
644
620
|
compatibilityDate: compatibilityDate || "latest",
|
|
645
621
|
dev: configOverrides.dev
|
|
646
622
|
});
|
|
647
|
-
if (preset
|
|
623
|
+
if (preset) return { config: klona(preset) };
|
|
648
624
|
},
|
|
649
625
|
...opts.c12
|
|
650
626
|
});
|
|
@@ -653,19 +629,17 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
653
629
|
options._c12 = loadedConfig;
|
|
654
630
|
options.preset = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || preset;
|
|
655
631
|
options.compatibilityDate = resolveCompatibilityDates(compatibilityDate, options.compatibilityDate);
|
|
656
|
-
if (options.dev && options.preset !== "nitro-dev") consola
|
|
632
|
+
if (options.dev && options.preset !== "nitro-dev") consola.info(`Using \`${options.preset}\` emulation in development mode.`);
|
|
657
633
|
return options;
|
|
658
634
|
}
|
|
659
|
-
|
|
660
635
|
//#endregion
|
|
661
636
|
//#region src/config/update.ts
|
|
662
637
|
async function updateNitroConfig(nitro, config) {
|
|
663
638
|
nitro.options.routeRules = normalizeRouteRules(config.routeRules ? config : nitro.options);
|
|
664
639
|
nitro.options.runtimeConfig = normalizeRuntimeConfig(config.runtimeConfig ? config : nitro.options);
|
|
665
640
|
await nitro.hooks.callHook("rollup:reload");
|
|
666
|
-
consola
|
|
641
|
+
consola.success("Nitro config hot reloaded!");
|
|
667
642
|
}
|
|
668
|
-
|
|
669
643
|
//#endregion
|
|
670
644
|
//#region src/module.ts
|
|
671
645
|
async function installModules(nitro) {
|
|
@@ -682,17 +656,20 @@ async function installModules(nitro) {
|
|
|
682
656
|
}
|
|
683
657
|
async function _resolveNitroModule(mod, nitroOptions) {
|
|
684
658
|
let _url;
|
|
685
|
-
if (typeof mod === "string")
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
659
|
+
if (typeof mod === "string") {
|
|
660
|
+
_url = resolveModuleURL(mod, {
|
|
661
|
+
from: [nitroOptions.rootDir],
|
|
662
|
+
extensions: [
|
|
663
|
+
".mjs",
|
|
664
|
+
".cjs",
|
|
665
|
+
".js",
|
|
666
|
+
".mts",
|
|
667
|
+
".cts",
|
|
668
|
+
".ts"
|
|
669
|
+
]
|
|
670
|
+
});
|
|
671
|
+
mod = await import(_url).then((m) => m.default || m);
|
|
672
|
+
}
|
|
696
673
|
if (typeof mod === "function") mod = { setup: mod };
|
|
697
674
|
if ("nitro" in mod) mod = mod.nitro;
|
|
698
675
|
if (!mod.setup) throw new Error("Invalid Nitro module: missing setup() function.");
|
|
@@ -701,7 +678,6 @@ async function _resolveNitroModule(mod, nitroOptions) {
|
|
|
701
678
|
...mod
|
|
702
679
|
};
|
|
703
680
|
}
|
|
704
|
-
|
|
705
681
|
//#endregion
|
|
706
682
|
//#region src/routing.ts
|
|
707
683
|
const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
|
|
@@ -835,7 +811,6 @@ function mergeCatchAll(router) {
|
|
|
835
811
|
data: handlers.map((h) => h.data)
|
|
836
812
|
});
|
|
837
813
|
}
|
|
838
|
-
|
|
839
814
|
//#endregion
|
|
840
815
|
//#region src/global.ts
|
|
841
816
|
const nitroInstances = globalThis.__nitro_instances__ ||= [];
|
|
@@ -852,13 +827,12 @@ function registerNitroInstance(nitro) {
|
|
|
852
827
|
function globalInit() {
|
|
853
828
|
if (globalThis[globalKey]) return;
|
|
854
829
|
globalThis[globalKey] = { async fetch(req) {
|
|
855
|
-
for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve
|
|
830
|
+
for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve) => setTimeout(resolve, 300));
|
|
856
831
|
const nitro = nitroInstances[0];
|
|
857
832
|
if (!nitro) throw new Error("No Nitro instance is running.");
|
|
858
833
|
return nitro.fetch(req);
|
|
859
834
|
} };
|
|
860
835
|
}
|
|
861
|
-
|
|
862
836
|
//#endregion
|
|
863
837
|
//#region src/nitro.ts
|
|
864
838
|
async function createNitro(config = {}, opts = {}) {
|
|
@@ -867,14 +841,14 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
867
841
|
hooks: new Hookable(),
|
|
868
842
|
vfs: /* @__PURE__ */ new Map(),
|
|
869
843
|
routing: {},
|
|
870
|
-
logger: consola.withTag("nitro"),
|
|
844
|
+
logger: consola$1.withTag("nitro"),
|
|
871
845
|
scannedHandlers: [],
|
|
872
846
|
fetch: () => {
|
|
873
847
|
throw new Error("no dev server attached!");
|
|
874
848
|
},
|
|
875
849
|
close: () => Promise.resolve(nitro.hooks.callHook("close")),
|
|
876
|
-
async updateConfig(config
|
|
877
|
-
updateNitroConfig(nitro, config
|
|
850
|
+
async updateConfig(config) {
|
|
851
|
+
updateNitroConfig(nitro, config);
|
|
878
852
|
}
|
|
879
853
|
};
|
|
880
854
|
registerNitroInstance(nitro);
|
|
@@ -895,7 +869,6 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
895
869
|
nitro.routing.sync();
|
|
896
870
|
return nitro;
|
|
897
871
|
}
|
|
898
|
-
|
|
899
872
|
//#endregion
|
|
900
873
|
//#region src/prerender/utils.ts
|
|
901
874
|
const allowedExtensions = new Set(["", ".json"]);
|
|
@@ -946,7 +919,7 @@ function formatPrerenderRoute(route) {
|
|
|
946
919
|
const parents = linkParents.get(route.route);
|
|
947
920
|
const errorColor = colors[route.error.status === 404 ? "yellow" : "red"];
|
|
948
921
|
const errorLead = parents?.size ? "├──" : "└──";
|
|
949
|
-
str += `\n │ ${errorLead} ${errorColor(route.error.message)}`;
|
|
922
|
+
str += `\n │ ${errorLead} ${errorColor(route.error.message || "unknown error")}`;
|
|
950
923
|
if (parents?.size) str += `\n${[...parents.values()].map((link) => ` │ └── Linked from ${link}`).join("\n")}`;
|
|
951
924
|
}
|
|
952
925
|
if (route.skip) str += colors.gray(" (skipped)");
|
|
@@ -958,7 +931,6 @@ function matchesIgnorePattern(path, pattern) {
|
|
|
958
931
|
if (pattern instanceof RegExp) return pattern.test(path);
|
|
959
932
|
return false;
|
|
960
933
|
}
|
|
961
|
-
|
|
962
934
|
//#endregion
|
|
963
935
|
//#region src/prerender/prerender.ts
|
|
964
936
|
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
@@ -967,12 +939,8 @@ async function prerender(nitro) {
|
|
|
967
939
|
nitro.logger.warn("Skipping prerender since `noPublicDir` option is enabled.");
|
|
968
940
|
return;
|
|
969
941
|
}
|
|
970
|
-
if (nitro.options.builder === "vite") {
|
|
971
|
-
nitro.logger.warn("Skipping prerender since not supported with vite builder yet...");
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
942
|
const routes = new Set(nitro.options.prerender.routes);
|
|
975
|
-
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path
|
|
943
|
+
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path, options]) => options.prerender && !path.includes("*")).map((e) => e[0]);
|
|
976
944
|
for (const route of prerenderRulePaths) routes.add(route);
|
|
977
945
|
await nitro.hooks.callHook("prerender:routes", routes);
|
|
978
946
|
if (routes.size === 0) if (nitro.options.prerender.crawlLinks) routes.add("/");
|
|
@@ -985,7 +953,8 @@ async function prerender(nitro) {
|
|
|
985
953
|
static: false,
|
|
986
954
|
rootDir: nitro.options.rootDir,
|
|
987
955
|
logLevel: 0,
|
|
988
|
-
preset: "nitro-prerender"
|
|
956
|
+
preset: "nitro-prerender",
|
|
957
|
+
builder: nitro.options.builder === "vite" ? "rolldown" : nitro.options.builder
|
|
989
958
|
};
|
|
990
959
|
await nitro.hooks.callHook("prerender:config", prerendererConfig);
|
|
991
960
|
const nitroRenderer = await createNitro(prerendererConfig);
|
|
@@ -1000,12 +969,12 @@ async function prerender(nitro) {
|
|
|
1000
969
|
const prerenderer = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href).then((m) => m.default);
|
|
1001
970
|
const routeRules = createRouter();
|
|
1002
971
|
for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
|
|
1003
|
-
const _getRouteRules = (path
|
|
972
|
+
const _getRouteRules = (path) => defu({}, ...findAllRoutes(routeRules, void 0, path).map((r) => r.data).reverse());
|
|
1004
973
|
const generatedRoutes = /* @__PURE__ */ new Set();
|
|
1005
974
|
const failedRoutes = /* @__PURE__ */ new Set();
|
|
1006
975
|
const skippedRoutes = /* @__PURE__ */ new Set();
|
|
1007
976
|
const displayedLengthWarns = /* @__PURE__ */ new Set();
|
|
1008
|
-
const publicAssetBases = nitro.options.publicAssets.filter((a
|
|
977
|
+
const publicAssetBases = nitro.options.publicAssets.filter((a) => !!a.baseURL && a.baseURL !== "/" && !a.fallthrough).map((a) => withTrailingSlash(a.baseURL));
|
|
1009
978
|
const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
|
|
1010
979
|
const canPrerender = (route = "/") => {
|
|
1011
980
|
if (generatedRoutes.has(route) || skippedRoutes.has(route)) return false;
|
|
@@ -1018,7 +987,7 @@ async function prerender(nitro) {
|
|
|
1018
987
|
return true;
|
|
1019
988
|
};
|
|
1020
989
|
const canWriteToDisk = (route) => {
|
|
1021
|
-
if (route.route.includes("?")) return false;
|
|
990
|
+
if (route.route.includes("?") || route.route.includes("..")) return false;
|
|
1022
991
|
const FS_MAX_SEGMENT = 255;
|
|
1023
992
|
const FS_MAX_PATH_PUBLIC_HTML = 1024 - (nitro.options.output.publicDir.length + 10);
|
|
1024
993
|
if ((route.route.length >= FS_MAX_PATH_PUBLIC_HTML || route.route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route)) {
|
|
@@ -1093,8 +1062,9 @@ async function prerender(nitro) {
|
|
|
1093
1062
|
dataBuff = void 0;
|
|
1094
1063
|
return _route;
|
|
1095
1064
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1065
|
+
const filePath = join(nitro.options.output.publicDir, _route.fileName);
|
|
1066
|
+
if (canWriteToDisk(_route) && filePath.startsWith(nitro.options.output.publicDir)) {
|
|
1067
|
+
await writeFile$1(filePath, dataBuff);
|
|
1098
1068
|
nitro._prerenderedRoutes.push(_route);
|
|
1099
1069
|
} else _route.skip = true;
|
|
1100
1070
|
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
|
|
@@ -1126,7 +1096,6 @@ async function prerender(nitro) {
|
|
|
1126
1096
|
nitro.logger.info(`Prerendered ${nitro._prerenderedRoutes.length} routes in ${prerenderTimeInMs / 1e3} seconds`);
|
|
1127
1097
|
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1128
1098
|
}
|
|
1129
|
-
|
|
1130
1099
|
//#endregion
|
|
1131
1100
|
//#region src/task.ts
|
|
1132
1101
|
/** @experimental */
|
|
@@ -1150,7 +1119,7 @@ async function _getTasksContext(opts) {
|
|
|
1150
1119
|
const baseURL = `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`;
|
|
1151
1120
|
const socketPath = buildInfo.dev.workerAddress.socketPath;
|
|
1152
1121
|
const devFetch = (path, options) => {
|
|
1153
|
-
return new Promise((resolve
|
|
1122
|
+
return new Promise((resolve, reject) => {
|
|
1154
1123
|
let url = withBase(path, baseURL);
|
|
1155
1124
|
if (options?.query) url = withQuery(url, options.query);
|
|
1156
1125
|
const request = http.request(url, {
|
|
@@ -1166,7 +1135,7 @@ async function _getTasksContext(opts) {
|
|
|
1166
1135
|
return;
|
|
1167
1136
|
}
|
|
1168
1137
|
let data = "";
|
|
1169
|
-
response.on("data", (chunk) => data += chunk).on("end", () => resolve
|
|
1138
|
+
response.on("data", (chunk) => data += chunk).on("end", () => resolve(JSON.parse(data))).on("error", (e) => reject(e));
|
|
1170
1139
|
});
|
|
1171
1140
|
request.on("error", (e) => reject(e));
|
|
1172
1141
|
if (options?.body) request.write(JSON.stringify(options.body));
|
|
@@ -1186,6 +1155,5 @@ function _pidIsRunning(pid) {
|
|
|
1186
1155
|
return false;
|
|
1187
1156
|
}
|
|
1188
1157
|
}
|
|
1189
|
-
|
|
1190
1158
|
//#endregion
|
|
1191
|
-
export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };
|
|
1159
|
+
export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };
|
package/dist/_chunks/nitro2.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as glob, ct as join, ut as relative } from "../_build/common.mjs";
|
|
2
2
|
import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
3
|
-
|
|
4
3
|
//#region src/scan.ts
|
|
5
4
|
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
6
5
|
const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
|
|
@@ -23,9 +22,12 @@ async function scanAndSyncOptions(nitro) {
|
|
|
23
22
|
async function scanHandlers(nitro) {
|
|
24
23
|
const middleware = await scanMiddleware(nitro);
|
|
25
24
|
const handlers = await Promise.all([scanServerRoutes(nitro, nitro.options.apiDir || "api", nitro.options.apiBaseURL || "/api"), scanServerRoutes(nitro, nitro.options.routesDir || "routes")]).then((r) => r.flat());
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const seenHandlers = /* @__PURE__ */ new Set();
|
|
26
|
+
nitro.scannedHandlers = [...middleware, ...handlers.filter((h) => {
|
|
27
|
+
const key = `${h.route}\0${h.method}\0${h.env}`;
|
|
28
|
+
return seenHandlers.has(key) ? false : (seenHandlers.add(key), true);
|
|
28
29
|
})];
|
|
30
|
+
nitro.routing.sync();
|
|
29
31
|
return handlers;
|
|
30
32
|
}
|
|
31
33
|
async function scanMiddleware(nitro) {
|
|
@@ -39,7 +41,7 @@ async function scanMiddleware(nitro) {
|
|
|
39
41
|
}
|
|
40
42
|
async function scanServerRoutes(nitro, dir, prefix = "/") {
|
|
41
43
|
return (await scanFiles(nitro, dir)).map((file) => {
|
|
42
|
-
let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(
|
|
44
|
+
let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}([^\]]+)]/g, (_, p) => "**:" + p.replace(/[^\w-]/g, "_")).replace(/\[([^/\]]+)]/g, (_, p) => ":" + p.replace(/[^\w-]/g, "_"));
|
|
43
45
|
route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
|
|
44
46
|
const suffixMatch = route.match(suffixRegex);
|
|
45
47
|
let method;
|
|
@@ -96,6 +98,5 @@ async function scanDir(nitro, dir, name) {
|
|
|
96
98
|
};
|
|
97
99
|
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
98
100
|
}
|
|
99
|
-
|
|
100
101
|
//#endregion
|
|
101
|
-
export { scanHandlers as n, scanAndSyncOptions as t };
|
|
102
|
+
export { scanHandlers as n, scanAndSyncOptions as t };
|