nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-121649-98b56dfe
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/common.mjs +763 -0
- package/dist/_build/rolldown.mjs +216 -0
- package/dist/_build/rollup.mjs +359 -0
- package/dist/_build/vite.build.mjs +67 -0
- package/dist/_build/vite.plugin.mjs +747 -0
- package/dist/_chunks/B-7HiF0V.mjs +1303 -0
- package/dist/_chunks/B3asVbT4.mjs +151 -0
- package/dist/_chunks/B5ooyfLk.mjs +372 -0
- package/dist/_chunks/DXMHy5ca.mjs +43 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +675 -0
- package/dist/_libs/acorn.mjs +5034 -0
- package/dist/_libs/c12.mjs +2798 -0
- package/dist/_libs/chokidar.mjs +1560 -0
- package/dist/_libs/citty.mjs +333 -0
- package/dist/_libs/commondir.mjs +22 -0
- package/dist/_libs/compatx.mjs +46 -0
- package/dist/_libs/confbox.mjs +2920 -0
- package/dist/_libs/debug.mjs +848 -0
- package/dist/_libs/deepmerge.mjs +86 -0
- package/dist/_libs/depd.mjs +314 -0
- package/dist/_libs/dot-prop.mjs +138 -0
- package/dist/_libs/duplexer.mjs +71 -0
- package/dist/_libs/ee-first.mjs +68 -0
- package/dist/_libs/encodeurl.mjs +49 -0
- package/dist/_libs/escape-html.mjs +58 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +330 -0
- package/dist/_libs/etag.mjs +75 -0
- package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
- package/dist/_libs/fresh.mjs +85 -0
- package/dist/_libs/function-bind.mjs +63 -0
- package/dist/_libs/gen-mapping.mjs +612 -0
- package/dist/_libs/giget.mjs +19076 -0
- package/dist/_libs/gzip-size.mjs +21 -0
- package/dist/_libs/hasown.mjs +14 -0
- package/dist/_libs/http-errors.mjs +436 -0
- package/dist/_libs/httpxy.mjs +410 -0
- package/dist/_libs/is-core-module.mjs +220 -0
- package/dist/_libs/is-module.mjs +13 -0
- package/dist/_libs/is-reference.mjs +32 -0
- package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
- package/dist/_libs/klona.mjs +90 -0
- package/dist/_libs/knitwork.mjs +124 -0
- package/dist/_libs/local-pkg.mjs +1686 -0
- package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
- package/dist/_libs/mime-db.mjs +7642 -0
- package/dist/_libs/mime-types.mjs +162 -0
- package/dist/_libs/mime.mjs +1391 -0
- package/dist/_libs/node-fetch-native.mjs +173 -0
- package/dist/_libs/on-finished.mjs +170 -0
- package/dist/_libs/parseurl.mjs +103 -0
- package/dist/_libs/path-parse.mjs +47 -0
- package/dist/_libs/pathe.mjs +41 -0
- package/dist/_libs/picomatch.mjs +1673 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-commonjs.mjs +1489 -0
- package/dist/_libs/plugin-inject.mjs +135 -0
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/plugin-node-resolve.mjs +1553 -0
- package/dist/_libs/plugin-replace.mjs +104 -0
- package/dist/_libs/pretty-bytes.mjs +116 -0
- package/dist/_libs/range-parser.mjs +102 -0
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
- package/dist/_libs/send.mjs +857 -0
- package/dist/_libs/serve-static.mjs +124 -0
- package/dist/_libs/std-env.mjs +158 -0
- package/dist/_libs/strip-literal.mjs +51 -0
- package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/unimport.mjs +3520 -0
- package/dist/_libs/untyped.mjs +271 -0
- package/dist/_libs/unwasm.mjs +5825 -0
- package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
- package/dist/_presets.mjs +1723 -0
- package/dist/builder.d.mts +37 -35
- package/dist/builder.mjs +45 -117
- package/dist/cli/_chunks/build.mjs +43 -0
- package/dist/cli/_chunks/common.mjs +15 -0
- package/dist/cli/_chunks/detect-acorn.mjs +12 -0
- package/dist/cli/_chunks/dev.mjs +79 -0
- package/dist/cli/_chunks/dist.mjs +3 -0
- package/dist/cli/_chunks/dist2.mjs +4 -0
- package/dist/cli/_chunks/esm.mjs +3 -0
- package/dist/cli/_chunks/json5.mjs +4 -0
- package/dist/cli/_chunks/jsonc.mjs +4 -0
- package/dist/cli/_chunks/list.mjs +27 -0
- package/dist/cli/_chunks/multipart-parser.mjs +6 -0
- package/dist/cli/_chunks/prepare.mjs +19 -0
- package/dist/cli/_chunks/run.mjs +55 -0
- package/dist/cli/_chunks/task.mjs +16 -0
- package/dist/cli/_chunks/toml.mjs +4 -0
- package/dist/cli/_chunks/yaml.mjs +4 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +19 -18
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
- package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
- package/dist/presets/azure/runtime/_utils.mjs +43 -43
- package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
- package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
- package/dist/presets/bun/runtime/bun.d.mts +1 -0
- package/dist/presets/bun/runtime/bun.mjs +18 -17
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
- package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
- package/dist/presets/deno/runtime/deno-server.mjs +31 -39
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
- package/dist/presets/netlify/runtime/netlify.mjs +11 -17
- package/dist/presets/node/runtime/node-cluster.mjs +49 -48
- package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
- package/dist/presets/node/runtime/node-middleware.mjs +7 -6
- package/dist/presets/node/runtime/node-server.mjs +33 -23
- package/dist/presets/standard/runtime/server.d.mts +1 -3
- package/dist/presets/standard/runtime/server.mjs +1 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
- package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
- package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
- package/dist/presets/vercel/runtime/vercel.mjs +15 -14
- package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/runtime/index.d.mts +12 -1
- package/dist/runtime/index.mjs +12 -7
- package/dist/runtime/internal/app.mjs +175 -162
- package/dist/runtime/internal/cache.d.mts +10 -4
- package/dist/runtime/internal/cache.mjs +247 -216
- package/dist/runtime/internal/context.d.mts +9 -9
- package/dist/runtime/internal/context.mjs +17 -10
- package/dist/runtime/internal/database.mjs +8 -10
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +106 -105
- package/dist/runtime/internal/error/prod.d.mts +2 -2
- package/dist/runtime/internal/error/prod.mjs +48 -52
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/error/utils.mjs +1 -1
- package/dist/runtime/internal/index.d.mts +2 -0
- package/dist/runtime/internal/index.mjs +2 -0
- package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
- package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/meta.mjs +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/plugin.mjs +1 -1
- package/dist/runtime/internal/renderer.mjs +39 -31
- package/dist/runtime/internal/route-rules.d.mts +8 -8
- package/dist/runtime/internal/route-rules.mjs +53 -51
- package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
- package/dist/runtime/internal/routes/openapi.d.mts +1 -0
- package/dist/runtime/internal/routes/openapi.mjs +81 -87
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +1 -0
- package/dist/runtime/internal/routes/scalar.mjs +22 -23
- package/dist/runtime/internal/routes/swagger.d.mts +1 -0
- package/dist/runtime/internal/routes/swagger.mjs +9 -11
- package/dist/runtime/internal/runtime-config.d.mts +4 -4
- package/dist/runtime/internal/runtime-config.mjs +40 -35
- package/dist/runtime/internal/shutdown.d.mts +2 -7
- package/dist/runtime/internal/shutdown.mjs +30 -29
- package/dist/runtime/internal/static.mjs +63 -74
- package/dist/runtime/internal/storage.mjs +2 -2
- package/dist/runtime/internal/task.d.mts +6 -6
- package/dist/runtime/internal/task.mjs +56 -59
- package/dist/runtime/internal/utils.d.mts +1 -1
- package/dist/runtime/internal/utils.mjs +4 -10
- package/dist/types/index.d.mts +2566 -3851
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +56 -52
- package/dist/vite.mjs +55 -132
- package/package.json +10 -10
- package/dist/_build/build.mjs +0 -368
- package/dist/_build/build2.mjs +0 -556
- package/dist/_build/info.mjs +0 -1002
- package/dist/_build/prepare.mjs +0 -1511
- package/dist/_build/snapshot.mjs +0 -185
- package/dist/_build/vite.mjs +0 -959
- package/dist/_build/vite2.mjs +0 -149
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
- package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
- package/dist/_chunks/_deps/acorn.mjs +0 -6225
- package/dist/_chunks/_deps/c12.mjs +0 -510
- package/dist/_chunks/_deps/chokidar.mjs +0 -1428
- package/dist/_chunks/_deps/citty.mjs +0 -460
- package/dist/_chunks/_deps/commondir.mjs +0 -77
- package/dist/_chunks/_deps/compatx.mjs +0 -76
- package/dist/_chunks/_deps/confbox.mjs +0 -300
- package/dist/_chunks/_deps/debug.mjs +0 -885
- package/dist/_chunks/_deps/deepmerge.mjs +0 -147
- package/dist/_chunks/_deps/depd.mjs +0 -550
- package/dist/_chunks/_deps/dot-prop.mjs +0 -282
- package/dist/_chunks/_deps/dotenv.mjs +0 -555
- package/dist/_chunks/_deps/duplexer.mjs +0 -1
- package/dist/_chunks/_deps/ee-first.mjs +0 -104
- package/dist/_chunks/_deps/encodeurl.mjs +0 -69
- package/dist/_chunks/_deps/escape-html.mjs +0 -87
- package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
- package/dist/_chunks/_deps/estree-walker.mjs +0 -433
- package/dist/_chunks/_deps/etag.mjs +0 -147
- package/dist/_chunks/_deps/exsolve.mjs +0 -1416
- package/dist/_chunks/_deps/fresh.mjs +0 -145
- package/dist/_chunks/_deps/function-bind.mjs +0 -106
- package/dist/_chunks/_deps/giget.mjs +0 -451
- package/dist/_chunks/_deps/gzip-size.mjs +0 -19
- package/dist/_chunks/_deps/hasown.mjs +0 -19
- package/dist/_chunks/_deps/http-errors.mjs +0 -307
- package/dist/_chunks/_deps/httpxy.mjs +0 -580
- package/dist/_chunks/_deps/inherits.mjs +0 -57
- package/dist/_chunks/_deps/is-core-module.mjs +0 -596
- package/dist/_chunks/_deps/is-module.mjs +0 -25
- package/dist/_chunks/_deps/is-reference.mjs +0 -31
- package/dist/_chunks/_deps/klona.mjs +0 -137
- package/dist/_chunks/_deps/knitwork.mjs +0 -172
- package/dist/_chunks/_deps/local-pkg.mjs +0 -163
- package/dist/_chunks/_deps/mime-db.mjs +0 -11685
- package/dist/_chunks/_deps/mime-types.mjs +0 -287
- package/dist/_chunks/_deps/mime.mjs +0 -1172
- package/dist/_chunks/_deps/mlly.mjs +0 -2413
- package/dist/_chunks/_deps/ms.mjs +0 -172
- package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
- package/dist/_chunks/_deps/nypm.mjs +0 -219
- package/dist/_chunks/_deps/on-finished.mjs +0 -246
- package/dist/_chunks/_deps/parseurl.mjs +0 -168
- package/dist/_chunks/_deps/path-parse.mjs +0 -85
- package/dist/_chunks/_deps/pathe.mjs +0 -251
- package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
- package/dist/_chunks/_deps/picomatch.mjs +0 -2144
- package/dist/_chunks/_deps/pkg-types.mjs +0 -247
- package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
- package/dist/_chunks/_deps/quansync.mjs +0 -99
- package/dist/_chunks/_deps/range-parser.mjs +0 -171
- package/dist/_chunks/_deps/rc9.mjs +0 -219
- package/dist/_chunks/_deps/readdirp.mjs +0 -245
- package/dist/_chunks/_deps/resolve.mjs +0 -1260
- package/dist/_chunks/_deps/send.mjs +0 -1022
- package/dist/_chunks/_deps/serve-static.mjs +0 -228
- package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
- package/dist/_chunks/_deps/statuses.mjs +0 -457
- package/dist/_chunks/_deps/std-env.mjs +0 -3
- package/dist/_chunks/_deps/strip-literal.mjs +0 -67
- package/dist/_chunks/_deps/supports-color.mjs +0 -44
- package/dist/_chunks/_deps/tinyexec.mjs +0 -552
- package/dist/_chunks/_deps/toidentifier.mjs +0 -41
- package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
- package/dist/_chunks/_deps/unimport.mjs +0 -2267
- package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
- package/dist/_chunks/_deps/unplugin.mjs +0 -1294
- package/dist/_chunks/_deps/untyped.mjs +0 -375
- package/dist/_chunks/_deps/unwasm.mjs +0 -6959
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
- package/dist/_chunks/_presets/_all.mjs +0 -59
- package/dist/_chunks/_presets/_nitro.mjs +0 -74
- package/dist/_chunks/_presets/_resolve.mjs +0 -64
- package/dist/_chunks/_presets/_static.mjs +0 -69
- package/dist/_chunks/_presets/_types.mjs +0 -3
- package/dist/_chunks/_presets/_utils.mjs +0 -31
- package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
- package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
- package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
- package/dist/_chunks/_presets/azure.mjs +0 -162
- package/dist/_chunks/_presets/bun.mjs +0 -19
- package/dist/_chunks/_presets/cleavr.mjs +0 -15
- package/dist/_chunks/_presets/cloudflare.mjs +0 -608
- package/dist/_chunks/_presets/deno.mjs +0 -196
- package/dist/_chunks/_presets/digitalocean.mjs +0 -14
- package/dist/_chunks/_presets/firebase.mjs +0 -47
- package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
- package/dist/_chunks/_presets/genezio.mjs +0 -13
- package/dist/_chunks/_presets/heroku.mjs +0 -14
- package/dist/_chunks/_presets/iis.mjs +0 -194
- package/dist/_chunks/_presets/index.mjs +0 -62
- package/dist/_chunks/_presets/koyeb.mjs +0 -14
- package/dist/_chunks/_presets/netlify.mjs +0 -241
- package/dist/_chunks/_presets/node.mjs +0 -54
- package/dist/_chunks/_presets/platform.mjs +0 -14
- package/dist/_chunks/_presets/render.mjs +0 -14
- package/dist/_chunks/_presets/standard.mjs +0 -23
- package/dist/_chunks/_presets/stormkit.mjs +0 -18
- package/dist/_chunks/_presets/vercel.mjs +0 -375
- package/dist/_chunks/_presets/winterjs.mjs +0 -22
- package/dist/_chunks/_presets/zeabur.mjs +0 -69
- package/dist/_chunks/_presets/zerops.mjs +0 -27
- package/dist/_chunks/app.mjs +0 -600
- package/dist/_chunks/builder.mjs +0 -648
- package/dist/_chunks/server.mjs +0 -256
- package/dist/_cli/build.mjs +0 -49
- package/dist/_cli/common.mjs +0 -13
- package/dist/_cli/dev.mjs +0 -121
- package/dist/_cli/index.mjs +0 -16
- package/dist/_cli/list.mjs +0 -33
- package/dist/_cli/prepare.mjs +0 -23
- package/dist/_cli/run.mjs +0 -59
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
- package/dist/runtime/internal/empty.d.mts +0 -0
- package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
- package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
- package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
- /package/lib/{indexd.mts → index.d.mts} +0 -0
|
@@ -0,0 +1,1303 @@
|
|
|
1
|
+
import { s as __toESM } from "./DXMHy5ca.mjs";
|
|
2
|
+
import { T as resolve, b as join, f as resolveModulePath, o as findWorkspaceDir, r as loadConfig, t as watchConfig, w as relative, x as normalize } from "../_libs/c12.mjs";
|
|
3
|
+
import { d as resolveModuleExportNames } from "../_libs/local-pkg.mjs";
|
|
4
|
+
import { s as createUnimport } from "../_libs/unimport.mjs";
|
|
5
|
+
import { t as glob } from "../_libs/tinyglobby.mjs";
|
|
6
|
+
import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
|
|
7
|
+
import { n as klona } from "../_libs/klona.mjs";
|
|
8
|
+
import { n as a, r as d } from "../_libs/std-env.mjs";
|
|
9
|
+
import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
|
|
10
|
+
import { a as scanAndSyncOptions, c as prettyPath, l as resolveNitroPath, o as scanHandlers, r as createStorage, s as isDirectory, t as runParallel, u as writeFile$1 } from "./B5ooyfLk.mjs";
|
|
11
|
+
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
|
|
12
|
+
import { t as src_default } from "../_libs/mime.mjs";
|
|
13
|
+
import { n as z, t as P } from "../_libs/ultrahtml.mjs";
|
|
14
|
+
import consola$1, { consola } from "consola";
|
|
15
|
+
import { Hookable, createDebugger } from "hookable";
|
|
16
|
+
import { existsSync, promises } from "node:fs";
|
|
17
|
+
import { joinURL, parseURL, withBase, withLeadingSlash, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
|
|
18
|
+
import { pathToFileURL } from "node:url";
|
|
19
|
+
import fsp, { readFile } from "node:fs/promises";
|
|
20
|
+
import { createJiti } from "jiti";
|
|
21
|
+
import { defu } from "defu";
|
|
22
|
+
import { pkgDir, runtimeDir } from "nitro/runtime/meta";
|
|
23
|
+
import { colors } from "consola/utils";
|
|
24
|
+
import { ofetch } from "ofetch";
|
|
25
|
+
import { hash } from "ohash";
|
|
26
|
+
import zlib from "node:zlib";
|
|
27
|
+
|
|
28
|
+
//#region src/config/defaults.ts
|
|
29
|
+
const NitroDefaults = {
|
|
30
|
+
compatibilityDate: "latest",
|
|
31
|
+
debug: d,
|
|
32
|
+
logLevel: a ? 1 : 3,
|
|
33
|
+
runtimeConfig: {
|
|
34
|
+
app: {},
|
|
35
|
+
nitro: {}
|
|
36
|
+
},
|
|
37
|
+
scanDirs: [],
|
|
38
|
+
buildDir: ".nitro",
|
|
39
|
+
output: {
|
|
40
|
+
dir: "{{ rootDir }}/.output",
|
|
41
|
+
serverDir: "{{ output.dir }}/server",
|
|
42
|
+
publicDir: "{{ output.dir }}/public"
|
|
43
|
+
},
|
|
44
|
+
experimental: {},
|
|
45
|
+
future: {},
|
|
46
|
+
storage: {},
|
|
47
|
+
devStorage: {},
|
|
48
|
+
bundledStorage: [],
|
|
49
|
+
publicAssets: [],
|
|
50
|
+
serverAssets: [],
|
|
51
|
+
plugins: [],
|
|
52
|
+
tasks: {},
|
|
53
|
+
scheduledTasks: {},
|
|
54
|
+
imports: false,
|
|
55
|
+
virtual: {},
|
|
56
|
+
compressPublicAssets: false,
|
|
57
|
+
ignore: [],
|
|
58
|
+
dev: false,
|
|
59
|
+
devServer: { watch: [] },
|
|
60
|
+
watchOptions: { ignoreInitial: true },
|
|
61
|
+
devProxy: {},
|
|
62
|
+
logging: {
|
|
63
|
+
compressedSizes: true,
|
|
64
|
+
buildSuccess: true
|
|
65
|
+
},
|
|
66
|
+
baseURL: process.env.NITRO_APP_BASE_URL || "/",
|
|
67
|
+
handlers: [],
|
|
68
|
+
devHandlers: [],
|
|
69
|
+
errorHandler: void 0,
|
|
70
|
+
routeRules: {},
|
|
71
|
+
prerender: {
|
|
72
|
+
autoSubfolderIndex: true,
|
|
73
|
+
concurrency: 1,
|
|
74
|
+
interval: 0,
|
|
75
|
+
retry: 3,
|
|
76
|
+
retryDelay: 500,
|
|
77
|
+
failOnError: false,
|
|
78
|
+
crawlLinks: false,
|
|
79
|
+
ignore: [],
|
|
80
|
+
routes: []
|
|
81
|
+
},
|
|
82
|
+
builder: void 0,
|
|
83
|
+
moduleSideEffects: ["unenv/polyfill/", resolve(runtimeDir, "polyfill/")],
|
|
84
|
+
replace: {},
|
|
85
|
+
node: true,
|
|
86
|
+
sourceMap: true,
|
|
87
|
+
esbuild: { options: {
|
|
88
|
+
jsxFactory: "h",
|
|
89
|
+
jsxFragment: "Fragment"
|
|
90
|
+
} },
|
|
91
|
+
typescript: {
|
|
92
|
+
strict: true,
|
|
93
|
+
generateRuntimeConfigTypes: false,
|
|
94
|
+
generateTsConfig: false,
|
|
95
|
+
tsconfigPath: "types/tsconfig.json",
|
|
96
|
+
internalPaths: false,
|
|
97
|
+
tsConfig: {}
|
|
98
|
+
},
|
|
99
|
+
nodeModulesDirs: [],
|
|
100
|
+
hooks: {},
|
|
101
|
+
commands: {},
|
|
102
|
+
framework: {
|
|
103
|
+
name: "nitro",
|
|
104
|
+
version: ""
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/config/resolvers/assets.ts
|
|
110
|
+
async function resolveAssetsOptions(options) {
|
|
111
|
+
for (const publicAsset of options.publicAssets) {
|
|
112
|
+
publicAsset.dir = resolve(options.srcDir, publicAsset.dir);
|
|
113
|
+
publicAsset.baseURL = withLeadingSlash(withoutTrailingSlash(publicAsset.baseURL || "/"));
|
|
114
|
+
}
|
|
115
|
+
for (const dir of options.scanDirs) {
|
|
116
|
+
const publicDir = resolve(dir, "public");
|
|
117
|
+
if (!existsSync(publicDir)) continue;
|
|
118
|
+
if (options.publicAssets.some((asset) => asset.dir === publicDir)) continue;
|
|
119
|
+
options.publicAssets.push({ dir: publicDir });
|
|
120
|
+
}
|
|
121
|
+
for (const serverAsset of options.serverAssets) serverAsset.dir = resolve(options.srcDir, serverAsset.dir);
|
|
122
|
+
options.serverAssets.push({
|
|
123
|
+
baseName: "server",
|
|
124
|
+
dir: resolve(options.srcDir, "assets")
|
|
125
|
+
});
|
|
126
|
+
for (const asset of options.publicAssets) {
|
|
127
|
+
asset.baseURL = asset.baseURL || "/";
|
|
128
|
+
const isTopLevel = asset.baseURL === "/";
|
|
129
|
+
asset.fallthrough = asset.fallthrough ?? isTopLevel;
|
|
130
|
+
const routeRule = options.routeRules[asset.baseURL + "/**"];
|
|
131
|
+
asset.maxAge = (routeRule?.cache)?.maxAge ?? asset.maxAge ?? 0;
|
|
132
|
+
if (asset.maxAge && !asset.fallthrough) options.routeRules[asset.baseURL + "/**"] = defu(routeRule, { headers: { "cache-control": `public, max-age=${asset.maxAge}, immutable` } });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/config/resolvers/compatibility.ts
|
|
138
|
+
async function resolveCompatibilityOptions(options) {
|
|
139
|
+
options.compatibilityDate = resolveCompatibilityDatesFromEnv(options.compatibilityDate);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/config/resolvers/database.ts
|
|
144
|
+
async function resolveDatabaseOptions(options) {
|
|
145
|
+
if (options.experimental.database && options.imports) {
|
|
146
|
+
options.imports.presets.push({
|
|
147
|
+
from: "nitro/runtime/internal/database",
|
|
148
|
+
imports: ["useDatabase"]
|
|
149
|
+
});
|
|
150
|
+
if (options.dev && !options.database && !options.devDatabase) options.devDatabase = { default: {
|
|
151
|
+
connector: "sqlite",
|
|
152
|
+
options: { cwd: options.rootDir }
|
|
153
|
+
} };
|
|
154
|
+
else if (options.node && !options.database) options.database = { default: {
|
|
155
|
+
connector: "sqlite",
|
|
156
|
+
options: {}
|
|
157
|
+
} };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/config/resolvers/export-conditions.ts
|
|
163
|
+
async function resolveExportConditionsOptions(options) {
|
|
164
|
+
options.exportConditions = _resolveExportConditions(options.exportConditions || [], {
|
|
165
|
+
dev: options.dev,
|
|
166
|
+
node: options.node,
|
|
167
|
+
wasm: options.experimental.wasm
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function _resolveExportConditions(conditions, opts) {
|
|
171
|
+
const resolvedConditions = [];
|
|
172
|
+
resolvedConditions.push(opts.dev ? "development" : "production");
|
|
173
|
+
resolvedConditions.push(...conditions);
|
|
174
|
+
if (opts.node) resolvedConditions.push("node");
|
|
175
|
+
else resolvedConditions.push("wintercg", "worker", "web", "browser", "workerd", "edge-light", "netlify", "edge-routine", "deno");
|
|
176
|
+
if (opts.wasm) resolvedConditions.push("wasm", "unwasm");
|
|
177
|
+
resolvedConditions.push("import", "default");
|
|
178
|
+
if ("Bun" in globalThis) resolvedConditions.push("bun");
|
|
179
|
+
else if ("Deno" in globalThis) resolvedConditions.push("deno");
|
|
180
|
+
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/config/resolvers/imports.ts
|
|
185
|
+
async function resolveImportsOptions(options) {
|
|
186
|
+
if (options.imports === false) return;
|
|
187
|
+
options.imports.presets ??= [];
|
|
188
|
+
options.imports.presets.push(...getNitroImportsPreset());
|
|
189
|
+
const h3Exports = await resolveModuleExportNames("h3", { url: import.meta.url });
|
|
190
|
+
options.imports.presets ??= [];
|
|
191
|
+
options.imports.presets.push({
|
|
192
|
+
from: "h3",
|
|
193
|
+
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
194
|
+
});
|
|
195
|
+
options.imports.dirs ??= [];
|
|
196
|
+
options.imports.dirs.push(...options.scanDirs.map((dir) => join(dir, "utils/**/*")));
|
|
197
|
+
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
198
|
+
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
199
|
+
options.imports.exclude.push(options.buildDir);
|
|
200
|
+
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
201
|
+
options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? /* @__PURE__ */ new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function getNitroImportsPreset() {
|
|
205
|
+
return [
|
|
206
|
+
{
|
|
207
|
+
from: "nitro/runtime/internal/app",
|
|
208
|
+
imports: ["useNitroApp"]
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
from: "nitro/runtime/internal/runtime-config",
|
|
212
|
+
imports: ["useRuntimeConfig"]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
from: "nitro/runtime/internal/plugin",
|
|
216
|
+
imports: ["defineNitroPlugin", "nitroPlugin"]
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
from: "nitro/runtime/internal/cache",
|
|
220
|
+
imports: [
|
|
221
|
+
"defineCachedFunction",
|
|
222
|
+
"defineCachedEventHandler",
|
|
223
|
+
"defineCachedHandler",
|
|
224
|
+
"cachedFunction",
|
|
225
|
+
"cachedEventHandler"
|
|
226
|
+
]
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
from: "nitro/runtime/internal/storage",
|
|
230
|
+
imports: ["useStorage"]
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
from: "nitro/runtime/internal/renderer",
|
|
234
|
+
imports: ["defineRenderHandler"]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
from: "nitro/runtime/internal/meta",
|
|
238
|
+
imports: ["defineRouteMeta"]
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
from: "nitro/runtime/internal/route-rules",
|
|
242
|
+
imports: ["getRouteRules"]
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
from: "nitro/runtime/internal/context",
|
|
246
|
+
imports: ["useRequest"]
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
from: "nitro/runtime/internal/task",
|
|
250
|
+
imports: ["defineTask", "runTask"]
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
from: "nitro/runtime/internal/error/utils",
|
|
254
|
+
imports: ["defineNitroErrorHandler"]
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
from: "nitro/deps/ofetch",
|
|
258
|
+
imports: ["$fetch"]
|
|
259
|
+
}
|
|
260
|
+
];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/config/resolvers/open-api.ts
|
|
265
|
+
async function resolveOpenAPIOptions(options) {
|
|
266
|
+
if (!options.experimental.openAPI) return;
|
|
267
|
+
if (!options.dev && !options.openAPI?.production) return;
|
|
268
|
+
const shouldPrerender = !options.dev && options.openAPI?.production === "prerender";
|
|
269
|
+
const handlersEnv = shouldPrerender ? "prerender" : "";
|
|
270
|
+
const prerenderRoutes = [];
|
|
271
|
+
const jsonRoute = options.openAPI?.route || "/_openapi.json";
|
|
272
|
+
prerenderRoutes.push(jsonRoute);
|
|
273
|
+
options.handlers.push({
|
|
274
|
+
route: jsonRoute,
|
|
275
|
+
env: handlersEnv,
|
|
276
|
+
handler: join(runtimeDir, "internal/routes/openapi")
|
|
277
|
+
});
|
|
278
|
+
if (options.openAPI?.ui?.scalar !== false) {
|
|
279
|
+
const scalarRoute = options.openAPI?.ui?.scalar?.route || "/_scalar";
|
|
280
|
+
prerenderRoutes.push(scalarRoute);
|
|
281
|
+
options.handlers.push({
|
|
282
|
+
route: options.openAPI?.ui?.scalar?.route || "/_scalar",
|
|
283
|
+
env: handlersEnv,
|
|
284
|
+
handler: join(runtimeDir, "internal/routes/scalar")
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
if (options.openAPI?.ui?.swagger !== false) {
|
|
288
|
+
const swaggerRoute = options.openAPI?.ui?.swagger?.route || "/_swagger";
|
|
289
|
+
prerenderRoutes.push(swaggerRoute);
|
|
290
|
+
options.handlers.push({
|
|
291
|
+
route: swaggerRoute,
|
|
292
|
+
env: handlersEnv,
|
|
293
|
+
handler: join(runtimeDir, "internal/routes/swagger")
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
if (shouldPrerender) {
|
|
297
|
+
options.prerender ??= {};
|
|
298
|
+
options.prerender.routes ??= [];
|
|
299
|
+
options.prerender.routes.push(...prerenderRoutes);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/config/resolvers/paths.ts
|
|
305
|
+
const RESOLVE_EXTENSIONS = [
|
|
306
|
+
".ts",
|
|
307
|
+
".js",
|
|
308
|
+
".mts",
|
|
309
|
+
".mjs",
|
|
310
|
+
".tsx",
|
|
311
|
+
".jsx"
|
|
312
|
+
];
|
|
313
|
+
async function resolvePathOptions(options) {
|
|
314
|
+
options.rootDir = resolve(options.rootDir || ".") + "/";
|
|
315
|
+
options.workspaceDir ||= await findWorkspaceDir(options.rootDir).catch(() => options.rootDir) + "/";
|
|
316
|
+
for (const key of ["srcDir", "buildDir"]) options[key] = resolve(options.rootDir, options[key] || ".");
|
|
317
|
+
options.alias ??= {};
|
|
318
|
+
if (!options.static && !options.entry) throw new Error(`Nitro entry is missing! Is "${options.preset}" preset correct?`);
|
|
319
|
+
if (options.entry) options.entry = resolveNitroPath(options.entry, options);
|
|
320
|
+
options.output.dir = resolveNitroPath(options.output.dir || NitroDefaults.output.dir, options, options.rootDir) + "/";
|
|
321
|
+
options.output.publicDir = resolveNitroPath(options.output.publicDir || NitroDefaults.output.publicDir, options, options.rootDir) + "/";
|
|
322
|
+
options.output.serverDir = resolveNitroPath(options.output.serverDir || NitroDefaults.output.serverDir, options, options.rootDir) + "/";
|
|
323
|
+
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
324
|
+
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
325
|
+
options.nodeModulesDirs.push(resolve(pkgDir, "dist/node_modules"));
|
|
326
|
+
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
327
|
+
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
328
|
+
options.nodeModulesDirs = [...new Set(options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir) + "/"))];
|
|
329
|
+
options.plugins = options.plugins.map((p) => resolveNitroPath(p, options));
|
|
330
|
+
options.scanDirs.unshift(options.srcDir);
|
|
331
|
+
options.scanDirs = options.scanDirs.map((dir) => resolve(options.srcDir, dir));
|
|
332
|
+
options.scanDirs = [...new Set(options.scanDirs.map((dir) => dir + "/"))];
|
|
333
|
+
if (options.serverEntry) options.serverEntry = resolveModulePath(resolveNitroPath(options.serverEntry, options), {
|
|
334
|
+
from: options.scanDirs,
|
|
335
|
+
extensions: RESOLVE_EXTENSIONS
|
|
336
|
+
});
|
|
337
|
+
else {
|
|
338
|
+
const defaultServerEntry = resolveModulePath("./server", {
|
|
339
|
+
from: options.scanDirs,
|
|
340
|
+
extensions: RESOLVE_EXTENSIONS,
|
|
341
|
+
try: true
|
|
342
|
+
});
|
|
343
|
+
if (defaultServerEntry) {
|
|
344
|
+
options.serverEntry = defaultServerEntry;
|
|
345
|
+
consola$1.info(`Using \`${prettyPath(defaultServerEntry)}\` as server entry.`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (options.renderer?.entry) options.renderer.entry = resolveModulePath(resolveNitroPath(options.renderer?.entry, options), {
|
|
349
|
+
from: options.scanDirs,
|
|
350
|
+
extensions: RESOLVE_EXTENSIONS
|
|
351
|
+
});
|
|
352
|
+
if (options.renderer?.template) options.renderer.template = resolveModulePath(resolveNitroPath(options.renderer?.template, options), {
|
|
353
|
+
from: options.scanDirs,
|
|
354
|
+
extensions: [".html"]
|
|
355
|
+
});
|
|
356
|
+
else if (!options.renderer?.entry) {
|
|
357
|
+
const defaultIndex = resolveModulePath("./index.html", {
|
|
358
|
+
from: options.scanDirs,
|
|
359
|
+
extensions: [".html"],
|
|
360
|
+
try: true
|
|
361
|
+
});
|
|
362
|
+
if (defaultIndex) {
|
|
363
|
+
options.renderer ??= {};
|
|
364
|
+
options.renderer.template = defaultIndex;
|
|
365
|
+
consola$1.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (options.renderer?.template && !options.renderer?.entry) {
|
|
369
|
+
options.renderer ??= {};
|
|
370
|
+
options.renderer.entry = join(runtimeDir, "internal/routes/renderer-template" + (options.dev ? ".dev" : ""));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/config/resolvers/route-rules.ts
|
|
376
|
+
async function resolveRouteRulesOptions(options) {
|
|
377
|
+
options.routeRules = defu(options.routeRules, options.routes || {});
|
|
378
|
+
options.routeRules = normalizeRouteRules(options);
|
|
379
|
+
}
|
|
380
|
+
function normalizeRouteRules(config) {
|
|
381
|
+
const normalizedRules = {};
|
|
382
|
+
for (let path in config.routeRules) {
|
|
383
|
+
const routeConfig = config.routeRules[path];
|
|
384
|
+
path = withLeadingSlash(path);
|
|
385
|
+
const routeRules = {
|
|
386
|
+
...routeConfig,
|
|
387
|
+
redirect: void 0,
|
|
388
|
+
proxy: void 0
|
|
389
|
+
};
|
|
390
|
+
if (routeConfig.redirect) {
|
|
391
|
+
routeRules.redirect = {
|
|
392
|
+
to: "/",
|
|
393
|
+
status: 307,
|
|
394
|
+
...typeof routeConfig.redirect === "string" ? { to: routeConfig.redirect } : routeConfig.redirect
|
|
395
|
+
};
|
|
396
|
+
if (path.endsWith("/**")) routeRules.redirect._redirectStripBase = path.slice(0, -3);
|
|
397
|
+
}
|
|
398
|
+
if (routeConfig.proxy) {
|
|
399
|
+
routeRules.proxy = typeof routeConfig.proxy === "string" ? { to: routeConfig.proxy } : routeConfig.proxy;
|
|
400
|
+
if (path.endsWith("/**")) routeRules.proxy._proxyStripBase = path.slice(0, -3);
|
|
401
|
+
}
|
|
402
|
+
if (routeConfig.cors) routeRules.headers = {
|
|
403
|
+
"access-control-allow-origin": "*",
|
|
404
|
+
"access-control-allow-methods": "*",
|
|
405
|
+
"access-control-allow-headers": "*",
|
|
406
|
+
"access-control-max-age": "0",
|
|
407
|
+
...routeRules.headers
|
|
408
|
+
};
|
|
409
|
+
if (routeConfig.swr) {
|
|
410
|
+
routeRules.cache = routeRules.cache || {};
|
|
411
|
+
routeRules.cache.swr = true;
|
|
412
|
+
if (typeof routeConfig.swr === "number") routeRules.cache.maxAge = routeConfig.swr;
|
|
413
|
+
}
|
|
414
|
+
if (routeConfig.cache === false) routeRules.cache = false;
|
|
415
|
+
normalizedRules[path] = routeRules;
|
|
416
|
+
}
|
|
417
|
+
return normalizedRules;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/config/resolvers/runtime-config.ts
|
|
422
|
+
async function resolveRuntimeConfigOptions(options) {
|
|
423
|
+
options.runtimeConfig = normalizeRuntimeConfig(options);
|
|
424
|
+
}
|
|
425
|
+
function normalizeRuntimeConfig(config) {
|
|
426
|
+
provideFallbackValues(config.runtimeConfig || {});
|
|
427
|
+
const runtimeConfig = defu(config.runtimeConfig, {
|
|
428
|
+
app: { baseURL: config.baseURL },
|
|
429
|
+
nitro: {
|
|
430
|
+
envExpansion: config.experimental?.envExpansion,
|
|
431
|
+
openAPI: config.openAPI
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
runtimeConfig.nitro.routeRules = config.routeRules;
|
|
435
|
+
checkSerializableRuntimeConfig(runtimeConfig);
|
|
436
|
+
return runtimeConfig;
|
|
437
|
+
}
|
|
438
|
+
function provideFallbackValues(obj) {
|
|
439
|
+
for (const key in obj) if (obj[key] === void 0 || obj[key] === null) obj[key] = "";
|
|
440
|
+
else if (typeof obj[key] === "object") provideFallbackValues(obj[key]);
|
|
441
|
+
}
|
|
442
|
+
function checkSerializableRuntimeConfig(obj, path = []) {
|
|
443
|
+
if (isPrimitiveValue(obj)) return;
|
|
444
|
+
for (const key in obj) {
|
|
445
|
+
const value = obj[key];
|
|
446
|
+
if (value === null || value === void 0 || isPrimitiveValue(value)) continue;
|
|
447
|
+
if (Array.isArray(value)) for (const [index, item] of value.entries()) checkSerializableRuntimeConfig(item, [...path, `${key}[${index}]`]);
|
|
448
|
+
else if (typeof value === "object" && value.constructor === Object && (!value.constructor?.name || value.constructor.name === "Object")) checkSerializableRuntimeConfig(value, [...path, key]);
|
|
449
|
+
else console.warn(`Runtime config option \`${[...path, key].join(".")}\` may not be able to be serialized.`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function isPrimitiveValue(value) {
|
|
453
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/config/resolvers/storage.ts
|
|
458
|
+
async function resolveStorageOptions(options) {
|
|
459
|
+
const fsMounts = {
|
|
460
|
+
root: resolve(options.rootDir),
|
|
461
|
+
src: resolve(options.srcDir),
|
|
462
|
+
build: resolve(options.buildDir),
|
|
463
|
+
cache: resolve(options.buildDir, "cache")
|
|
464
|
+
};
|
|
465
|
+
for (const p in fsMounts) options.devStorage[p] = options.devStorage[p] || {
|
|
466
|
+
driver: "fs",
|
|
467
|
+
readOnly: p === "root" || p === "src",
|
|
468
|
+
base: fsMounts[p]
|
|
469
|
+
};
|
|
470
|
+
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) options.devStorage.data = {
|
|
471
|
+
driver: "fs",
|
|
472
|
+
base: resolve(options.rootDir, ".data/kv")
|
|
473
|
+
};
|
|
474
|
+
else if (options.node && options.storage.data === void 0) options.storage.data = {
|
|
475
|
+
driver: "fsLite",
|
|
476
|
+
base: "./.data/kv"
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/config/resolvers/url.ts
|
|
482
|
+
async function resolveURLOptions(options) {
|
|
483
|
+
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/config/resolvers/error.ts
|
|
488
|
+
async function resolveErrorOptions(options) {
|
|
489
|
+
if (!options.errorHandler) options.errorHandler = [];
|
|
490
|
+
else if (!Array.isArray(options.errorHandler)) options.errorHandler = [options.errorHandler];
|
|
491
|
+
options.errorHandler.push(join(runtimeDir, `internal/error/${options.dev ? "dev" : "prod"}`));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/config/resolvers/unenv.ts
|
|
496
|
+
const common = {
|
|
497
|
+
meta: {
|
|
498
|
+
name: "nitro-common",
|
|
499
|
+
url: import.meta.url
|
|
500
|
+
},
|
|
501
|
+
alias: {
|
|
502
|
+
"buffer/": "node:buffer",
|
|
503
|
+
"buffer/index": "node:buffer",
|
|
504
|
+
"buffer/index.js": "node:buffer",
|
|
505
|
+
"string_decoder/": "node:string_decoder",
|
|
506
|
+
"process/": "node:process"
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const nodeless = {
|
|
510
|
+
meta: {
|
|
511
|
+
name: "nitro-nodeless",
|
|
512
|
+
url: import.meta.url
|
|
513
|
+
},
|
|
514
|
+
inject: {
|
|
515
|
+
global: "unenv/polyfill/globalthis",
|
|
516
|
+
process: "node:process",
|
|
517
|
+
Buffer: ["node:buffer", "Buffer"],
|
|
518
|
+
clearImmediate: ["node:timers", "clearImmediate"],
|
|
519
|
+
setImmediate: ["node:timers", "setImmediate"],
|
|
520
|
+
performance: "unenv/polyfill/performance",
|
|
521
|
+
PerformanceObserver: ["node:perf_hooks", "PerformanceObserver"],
|
|
522
|
+
BroadcastChannel: ["node:worker_threads", "BroadcastChannel"]
|
|
523
|
+
},
|
|
524
|
+
polyfill: [
|
|
525
|
+
"unenv/polyfill/globalthis-global",
|
|
526
|
+
"unenv/polyfill/process",
|
|
527
|
+
"unenv/polyfill/buffer",
|
|
528
|
+
"unenv/polyfill/timers"
|
|
529
|
+
]
|
|
530
|
+
};
|
|
531
|
+
async function resolveUnenv(options) {
|
|
532
|
+
options.unenv ??= [];
|
|
533
|
+
if (!Array.isArray(options.unenv)) options.unenv = [options.unenv];
|
|
534
|
+
options.unenv = options.unenv.filter(Boolean);
|
|
535
|
+
if (!options.node) options.unenv.unshift(nodeless);
|
|
536
|
+
options.unenv.unshift(common);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/config/resolvers/builder.ts
|
|
541
|
+
async function resolveBuilder(options) {
|
|
542
|
+
if (!options.builder) options.builder = process.env.NITRO_BUILDER || "rollup";
|
|
543
|
+
if (options.builder === "rolldown") try {
|
|
544
|
+
await import("rolldown");
|
|
545
|
+
} catch {
|
|
546
|
+
throw new Error(`Builder "rolldown" is not available. Make sure to install "rolldown" package.`);
|
|
547
|
+
}
|
|
548
|
+
else if (options.builder === "vite") try {
|
|
549
|
+
await import("vite");
|
|
550
|
+
} catch {
|
|
551
|
+
throw new Error(`Builder "vite" is not available. Make sure to install "vite" package.`);
|
|
552
|
+
}
|
|
553
|
+
if (![
|
|
554
|
+
"rollup",
|
|
555
|
+
"rolldown",
|
|
556
|
+
"vite"
|
|
557
|
+
].includes(options.builder)) throw new Error(`Builder "${options.builder}" is not supported.`);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/config/loader.ts
|
|
562
|
+
const configResolvers = [
|
|
563
|
+
resolveCompatibilityOptions,
|
|
564
|
+
resolvePathOptions,
|
|
565
|
+
resolveImportsOptions,
|
|
566
|
+
resolveRouteRulesOptions,
|
|
567
|
+
resolveDatabaseOptions,
|
|
568
|
+
resolveExportConditionsOptions,
|
|
569
|
+
resolveRuntimeConfigOptions,
|
|
570
|
+
resolveOpenAPIOptions,
|
|
571
|
+
resolveURLOptions,
|
|
572
|
+
resolveAssetsOptions,
|
|
573
|
+
resolveStorageOptions,
|
|
574
|
+
resolveErrorOptions,
|
|
575
|
+
resolveUnenv,
|
|
576
|
+
resolveBuilder
|
|
577
|
+
];
|
|
578
|
+
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
579
|
+
const options = await _loadUserConfig(configOverrides, opts);
|
|
580
|
+
for (const resolver of configResolvers) await resolver(options);
|
|
581
|
+
return options;
|
|
582
|
+
}
|
|
583
|
+
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
584
|
+
configOverrides = klona(configOverrides);
|
|
585
|
+
globalThis.defineNitroConfig = globalThis.defineNitroConfig || ((c) => c);
|
|
586
|
+
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || process.env.NITRO_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE;
|
|
587
|
+
const { resolvePreset } = await import("../_presets.mjs");
|
|
588
|
+
let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
|
|
589
|
+
const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
|
|
590
|
+
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
591
|
+
name: "nitro",
|
|
592
|
+
cwd: configOverrides.rootDir,
|
|
593
|
+
dotenv: _dotenv,
|
|
594
|
+
extend: { extendKey: ["extends", "preset"] },
|
|
595
|
+
defaults: NitroDefaults,
|
|
596
|
+
jitiOptions: { alias: {
|
|
597
|
+
nitropack: "nitro/config",
|
|
598
|
+
"nitro/config": "nitro/config"
|
|
599
|
+
} },
|
|
600
|
+
async overrides({ rawConfigs }) {
|
|
601
|
+
const getConf = (key) => configOverrides[key] ?? rawConfigs.main?.[key] ?? rawConfigs.rc?.[key] ?? rawConfigs.packageJson?.[key];
|
|
602
|
+
if (!compatibilityDate) compatibilityDate = getConf("compatibilityDate");
|
|
603
|
+
const framework = getConf("framework");
|
|
604
|
+
const isCustomFramework = framework?.name && framework.name !== "nitro";
|
|
605
|
+
if (!preset) preset = getConf("preset");
|
|
606
|
+
if (configOverrides.dev) preset = preset && preset !== "nitro-dev" ? await resolvePreset(preset, {
|
|
607
|
+
static: getConf("static"),
|
|
608
|
+
dev: true,
|
|
609
|
+
compatibilityDate: compatibilityDate || "latest"
|
|
610
|
+
}).then((p) => p?._meta?.name || "nitro-dev").catch(() => "nitro-dev") : "nitro-dev";
|
|
611
|
+
else if (!preset) preset = await resolvePreset("", {
|
|
612
|
+
static: getConf("static"),
|
|
613
|
+
dev: false,
|
|
614
|
+
compatibilityDate: compatibilityDate || "latest"
|
|
615
|
+
}).then((p) => p?._meta?.name);
|
|
616
|
+
return {
|
|
617
|
+
...configOverrides,
|
|
618
|
+
preset,
|
|
619
|
+
typescript: {
|
|
620
|
+
generateRuntimeConfigTypes: !isCustomFramework,
|
|
621
|
+
...getConf("typescript"),
|
|
622
|
+
...configOverrides.typescript
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
},
|
|
626
|
+
async resolve(id) {
|
|
627
|
+
const preset$1 = await resolvePreset(id, {
|
|
628
|
+
static: configOverrides.static,
|
|
629
|
+
compatibilityDate: compatibilityDate || "latest",
|
|
630
|
+
dev: configOverrides.dev
|
|
631
|
+
});
|
|
632
|
+
if (preset$1) return { config: klona(preset$1) };
|
|
633
|
+
},
|
|
634
|
+
...opts.c12
|
|
635
|
+
});
|
|
636
|
+
const options = klona(loadedConfig.config);
|
|
637
|
+
options._config = configOverrides;
|
|
638
|
+
options._c12 = loadedConfig;
|
|
639
|
+
options.preset = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || preset;
|
|
640
|
+
options.compatibilityDate = resolveCompatibilityDates(compatibilityDate, options.compatibilityDate);
|
|
641
|
+
if (options.dev && options.preset !== "nitro-dev") consola$1.info(`Using \`${options.preset}\` emulation in development mode.`);
|
|
642
|
+
return options;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region src/config/update.ts
|
|
647
|
+
async function updateNitroConfig(nitro, config) {
|
|
648
|
+
nitro.options.routeRules = normalizeRouteRules(config.routeRules ? config : nitro.options);
|
|
649
|
+
nitro.options.runtimeConfig = normalizeRuntimeConfig(config.runtimeConfig ? config : nitro.options);
|
|
650
|
+
await nitro.hooks.callHook("rollup:reload");
|
|
651
|
+
consola$1.success("Nitro config hot reloaded!");
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
//#endregion
|
|
655
|
+
//#region src/module.ts
|
|
656
|
+
async function installModules(nitro) {
|
|
657
|
+
const _modules = [...nitro.options.modules || []];
|
|
658
|
+
const modules = await Promise.all(_modules.map((mod) => _resolveNitroModule(mod, nitro.options)));
|
|
659
|
+
const _installedURLs = /* @__PURE__ */ new Set();
|
|
660
|
+
for (const mod of modules) {
|
|
661
|
+
if (mod._url) {
|
|
662
|
+
if (_installedURLs.has(mod._url)) continue;
|
|
663
|
+
_installedURLs.add(mod._url);
|
|
664
|
+
}
|
|
665
|
+
await mod.setup(nitro);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
async function _resolveNitroModule(mod, nitroOptions) {
|
|
669
|
+
let _url;
|
|
670
|
+
if (typeof mod === "string") {
|
|
671
|
+
globalThis.defineNitroModule = globalThis.defineNitroModule || ((mod$1) => mod$1);
|
|
672
|
+
const jiti = createJiti(nitroOptions.rootDir, { alias: nitroOptions.alias });
|
|
673
|
+
const _modPath = jiti.esmResolve(mod);
|
|
674
|
+
_url = _modPath;
|
|
675
|
+
mod = await jiti.import(_modPath, { default: true });
|
|
676
|
+
}
|
|
677
|
+
if (typeof mod === "function") mod = { setup: mod };
|
|
678
|
+
if (!mod.setup) mod.setup = () => {};
|
|
679
|
+
return {
|
|
680
|
+
_url,
|
|
681
|
+
...mod
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/task.ts
|
|
687
|
+
/** @experimental */
|
|
688
|
+
async function runTask(taskEvent, opts) {
|
|
689
|
+
return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
|
|
690
|
+
method: "POST",
|
|
691
|
+
body: taskEvent
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
/** @experimental */
|
|
695
|
+
async function listTasks(opts) {
|
|
696
|
+
return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
|
|
697
|
+
}
|
|
698
|
+
function addNitroTasksVirtualFile(nitro) {
|
|
699
|
+
nitro.options.virtual["#nitro-internal-virtual/tasks"] = () => {
|
|
700
|
+
const _scheduledTasks = Object.entries(nitro.options.scheduledTasks || {}).map(([cron, _tasks]) => {
|
|
701
|
+
return {
|
|
702
|
+
cron,
|
|
703
|
+
tasks: (Array.isArray(_tasks) ? _tasks : [_tasks]).filter((name) => {
|
|
704
|
+
if (!nitro.options.tasks[name]) {
|
|
705
|
+
nitro.logger.warn(`Scheduled task \`${name}\` is not defined!`);
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
return true;
|
|
709
|
+
})
|
|
710
|
+
};
|
|
711
|
+
}).filter((e) => e.tasks.length > 0);
|
|
712
|
+
const scheduledTasks = _scheduledTasks.length > 0 ? _scheduledTasks : false;
|
|
713
|
+
return `
|
|
714
|
+
export const scheduledTasks = ${JSON.stringify(scheduledTasks)};
|
|
715
|
+
|
|
716
|
+
export const tasks = {
|
|
717
|
+
${Object.entries(nitro.options.tasks).map(([name, task]) => `"${name}": {
|
|
718
|
+
meta: {
|
|
719
|
+
description: ${JSON.stringify(task.description)},
|
|
720
|
+
},
|
|
721
|
+
resolve: ${task.handler ? `() => import("${normalize(task.handler)}").then(r => r.default || r)` : "undefined"},
|
|
722
|
+
}`).join(",\n")}
|
|
723
|
+
};`;
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const _devHint = `(is dev server running?)`;
|
|
727
|
+
async function _getTasksContext(opts) {
|
|
728
|
+
const buildInfoPath = resolve(resolve(resolve(process.cwd(), opts?.cwd || "."), opts?.buildDir || ".nitro"), "nitro.json");
|
|
729
|
+
if (!existsSync(buildInfoPath)) throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
|
|
730
|
+
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
731
|
+
if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) throw new Error(`Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`);
|
|
732
|
+
if (!_pidIsRunning(buildInfo.dev.pid)) throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
|
|
733
|
+
return {
|
|
734
|
+
buildInfo,
|
|
735
|
+
devFetch: ofetch.create({
|
|
736
|
+
baseURL: `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`,
|
|
737
|
+
socketPath: buildInfo.dev.workerAddress.socketPath
|
|
738
|
+
})
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function _pidIsRunning(pid) {
|
|
742
|
+
try {
|
|
743
|
+
process.kill(pid, 0);
|
|
744
|
+
return true;
|
|
745
|
+
} catch {
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region src/routing.ts
|
|
752
|
+
const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
|
|
753
|
+
function initNitroRouting(nitro) {
|
|
754
|
+
const envConditions = new Set([
|
|
755
|
+
nitro.options.dev ? "dev" : "prod",
|
|
756
|
+
nitro.options.preset,
|
|
757
|
+
nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
|
|
758
|
+
].filter(Boolean));
|
|
759
|
+
const matchesEnv = (h) => {
|
|
760
|
+
const envs = (Array.isArray(h.env) ? h.env : [h.env]).filter(Boolean);
|
|
761
|
+
return envs.length === 0 || envs.some((env) => envConditions.has(env));
|
|
762
|
+
};
|
|
763
|
+
const routes = new Router();
|
|
764
|
+
const routeRules = new Router(true);
|
|
765
|
+
const globalMiddleware = [];
|
|
766
|
+
const routedMiddleware = new Router(true);
|
|
767
|
+
const warns = /* @__PURE__ */ new Set();
|
|
768
|
+
const sync = () => {
|
|
769
|
+
routeRules._update(Object.entries(nitro.options.routeRules).map(([route, data]) => ({
|
|
770
|
+
route,
|
|
771
|
+
method: "",
|
|
772
|
+
data: {
|
|
773
|
+
...data,
|
|
774
|
+
_route: route
|
|
775
|
+
}
|
|
776
|
+
})));
|
|
777
|
+
const _routes = [...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => h && !h.middleware && matchesEnv(h));
|
|
778
|
+
if (nitro.options.renderer?.entry) {
|
|
779
|
+
const existingWildcard = _routes.findIndex((h) => /^\/\*\*(:.+)?$/.test(h.route) && (!h.method || h.method === "GET"));
|
|
780
|
+
if (existingWildcard !== -1) {
|
|
781
|
+
const h = _routes[existingWildcard];
|
|
782
|
+
const warn = `The renderer will override \`${relative(".", h.handler)}\` (route: \`${h.route}\`). Use a more specific route or different HTTP method.`;
|
|
783
|
+
if (!warns.has(warn)) {
|
|
784
|
+
warns.add(warn);
|
|
785
|
+
nitro.logger.warn(warn);
|
|
786
|
+
}
|
|
787
|
+
_routes.splice(existingWildcard, 1);
|
|
788
|
+
}
|
|
789
|
+
_routes.push({
|
|
790
|
+
route: "/**",
|
|
791
|
+
lazy: true,
|
|
792
|
+
handler: nitro.options.renderer?.entry
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
routes._update(_routes.map((h) => ({
|
|
796
|
+
...h,
|
|
797
|
+
method: h.method || "",
|
|
798
|
+
data: handlerWithImportHash(h)
|
|
799
|
+
})));
|
|
800
|
+
const _middleware = [...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => h && h.middleware && matchesEnv(h));
|
|
801
|
+
if (nitro.options.serveStatic) _middleware.unshift({
|
|
802
|
+
route: "/**",
|
|
803
|
+
middleware: true,
|
|
804
|
+
handler: join(runtimeDir, "internal/static")
|
|
805
|
+
});
|
|
806
|
+
globalMiddleware.splice(0, globalMiddleware.length, ..._middleware.filter((h) => isGlobalMiddleware(h)).map((m) => handlerWithImportHash(m)));
|
|
807
|
+
routedMiddleware._update(_middleware.filter((h) => !isGlobalMiddleware(h)).map((h) => ({
|
|
808
|
+
...h,
|
|
809
|
+
method: h.method || "",
|
|
810
|
+
data: handlerWithImportHash(h)
|
|
811
|
+
})));
|
|
812
|
+
};
|
|
813
|
+
nitro.routing = Object.freeze({
|
|
814
|
+
sync,
|
|
815
|
+
routes,
|
|
816
|
+
routeRules,
|
|
817
|
+
globalMiddleware,
|
|
818
|
+
routedMiddleware
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
function handlerWithImportHash(h) {
|
|
822
|
+
const id = (h.lazy ? "_lazy_" : "_") + hash(h.handler).replace(/-/g, "").slice(0, 6);
|
|
823
|
+
return {
|
|
824
|
+
...h,
|
|
825
|
+
_importHash: id
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
var Router = class {
|
|
829
|
+
#routes;
|
|
830
|
+
#router;
|
|
831
|
+
#compiled;
|
|
832
|
+
constructor(matchAll) {
|
|
833
|
+
this._update([]);
|
|
834
|
+
}
|
|
835
|
+
get routes() {
|
|
836
|
+
return this.#routes;
|
|
837
|
+
}
|
|
838
|
+
_update(routes) {
|
|
839
|
+
this.#routes = routes;
|
|
840
|
+
this.#router = createRouter();
|
|
841
|
+
this.#compiled = void 0;
|
|
842
|
+
for (const route of routes) addRoute(this.#router, route.method, route.route, route.data);
|
|
843
|
+
}
|
|
844
|
+
hasRoutes() {
|
|
845
|
+
return this.#routes.length > 0;
|
|
846
|
+
}
|
|
847
|
+
compileToString(opts) {
|
|
848
|
+
return this.#compiled || (this.#compiled = compileRouterToString(this.#router, void 0, opts));
|
|
849
|
+
}
|
|
850
|
+
match(method, path) {
|
|
851
|
+
return findRoute(this.#router, method, path)?.data;
|
|
852
|
+
}
|
|
853
|
+
matchAll(method, path) {
|
|
854
|
+
return findAllRoutes(this.#router, method, path).map((route) => route.data);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
//#endregion
|
|
859
|
+
//#region src/nitro.ts
|
|
860
|
+
async function createNitro(config = {}, opts = {}) {
|
|
861
|
+
const nitro = {
|
|
862
|
+
options: await loadOptions(config, opts),
|
|
863
|
+
hooks: new Hookable(),
|
|
864
|
+
vfs: {},
|
|
865
|
+
routing: {},
|
|
866
|
+
logger: consola.withTag("nitro"),
|
|
867
|
+
scannedHandlers: [],
|
|
868
|
+
close: () => Promise.resolve(nitro.hooks.callHook("close")),
|
|
869
|
+
storage: void 0,
|
|
870
|
+
async updateConfig(config$1) {
|
|
871
|
+
updateNitroConfig(nitro, config$1);
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
initNitroRouting(nitro);
|
|
875
|
+
await scanAndSyncOptions(nitro);
|
|
876
|
+
nitro.storage = await createStorage(nitro);
|
|
877
|
+
nitro.hooks.hook("close", async () => {
|
|
878
|
+
await nitro.storage.dispose();
|
|
879
|
+
});
|
|
880
|
+
if (nitro.options.debug) createDebugger(nitro.hooks, { tag: "nitro" });
|
|
881
|
+
if (nitro.options.logLevel !== void 0) nitro.logger.level = nitro.options.logLevel;
|
|
882
|
+
nitro.hooks.addHooks(nitro.options.hooks);
|
|
883
|
+
addNitroTasksVirtualFile(nitro);
|
|
884
|
+
await installModules(nitro);
|
|
885
|
+
if (nitro.options.imports) {
|
|
886
|
+
nitro.unimport = createUnimport(nitro.options.imports);
|
|
887
|
+
await nitro.unimport.init();
|
|
888
|
+
nitro.options.virtual["#imports"] = () => nitro.unimport?.toExports() || "";
|
|
889
|
+
nitro.options.virtual["#nitro"] = "export * from \"#imports\"";
|
|
890
|
+
}
|
|
891
|
+
await scanHandlers(nitro);
|
|
892
|
+
nitro.routing.sync();
|
|
893
|
+
return nitro;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
//#endregion
|
|
897
|
+
//#region src/build/build.ts
|
|
898
|
+
async function build(nitro) {
|
|
899
|
+
switch (nitro.options.builder) {
|
|
900
|
+
case "rollup": {
|
|
901
|
+
const { rollupBuild } = await import("../_build/rollup.mjs");
|
|
902
|
+
return rollupBuild(nitro);
|
|
903
|
+
}
|
|
904
|
+
case "rolldown": {
|
|
905
|
+
const { rolldownBuild } = await import("../_build/rolldown.mjs");
|
|
906
|
+
return rolldownBuild(nitro);
|
|
907
|
+
}
|
|
908
|
+
case "vite": {
|
|
909
|
+
const { viteBuild } = await import("../_build/vite.build.mjs");
|
|
910
|
+
return viteBuild(nitro);
|
|
911
|
+
}
|
|
912
|
+
default: throw new Error(`Unknown builder: ${nitro.options.builder}`);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
//#endregion
|
|
917
|
+
//#region src/utils/compress.ts
|
|
918
|
+
async function compressPublicAssets(nitro) {
|
|
919
|
+
const publicFiles = await glob("**", {
|
|
920
|
+
cwd: nitro.options.output.publicDir,
|
|
921
|
+
absolute: false,
|
|
922
|
+
dot: true,
|
|
923
|
+
ignore: ["**/*.gz", "**/*.br"]
|
|
924
|
+
});
|
|
925
|
+
await Promise.all(publicFiles.map(async (fileName) => {
|
|
926
|
+
const filePath = resolve(nitro.options.output.publicDir, fileName);
|
|
927
|
+
if (existsSync(filePath + ".gz") || existsSync(filePath + ".br")) return;
|
|
928
|
+
const mimeType = src_default.getType(fileName) || "text/plain";
|
|
929
|
+
const fileContents = await fsp.readFile(filePath);
|
|
930
|
+
if (fileContents.length < 1024 || fileName.endsWith(".map") || !isCompressibleMime(mimeType)) return;
|
|
931
|
+
const { gzip, brotli } = nitro.options.compressPublicAssets || {};
|
|
932
|
+
const encodings = [gzip !== false && "gzip", brotli !== false && "br"].filter(Boolean);
|
|
933
|
+
await Promise.all(encodings.map(async (encoding) => {
|
|
934
|
+
const compressedPath = filePath + ("." + (encoding === "gzip" ? "gz" : "br"));
|
|
935
|
+
if (existsSync(compressedPath)) return;
|
|
936
|
+
const gzipOptions = { level: zlib.constants.Z_BEST_COMPRESSION };
|
|
937
|
+
const brotliOptions = {
|
|
938
|
+
[zlib.constants.BROTLI_PARAM_MODE]: isTextMime(mimeType) ? zlib.constants.BROTLI_MODE_TEXT : zlib.constants.BROTLI_MODE_GENERIC,
|
|
939
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
940
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: fileContents.length
|
|
941
|
+
};
|
|
942
|
+
const compressedBuff = await new Promise((resolve$1, reject) => {
|
|
943
|
+
const cb = (error, result) => error ? reject(error) : resolve$1(result);
|
|
944
|
+
if (encoding === "gzip") zlib.gzip(fileContents, gzipOptions, cb);
|
|
945
|
+
else zlib.brotliCompress(fileContents, brotliOptions, cb);
|
|
946
|
+
});
|
|
947
|
+
await fsp.writeFile(compressedPath, compressedBuff);
|
|
948
|
+
}));
|
|
949
|
+
}));
|
|
950
|
+
}
|
|
951
|
+
function isTextMime(mimeType) {
|
|
952
|
+
return /text|javascript|json|xml/.test(mimeType);
|
|
953
|
+
}
|
|
954
|
+
const COMPRESSIBLE_MIMES_RE = new Set([
|
|
955
|
+
"application/dash+xml",
|
|
956
|
+
"application/eot",
|
|
957
|
+
"application/font",
|
|
958
|
+
"application/font-sfnt",
|
|
959
|
+
"application/javascript",
|
|
960
|
+
"application/json",
|
|
961
|
+
"application/opentype",
|
|
962
|
+
"application/otf",
|
|
963
|
+
"application/pdf",
|
|
964
|
+
"application/pkcs7-mime",
|
|
965
|
+
"application/protobuf",
|
|
966
|
+
"application/rss+xml",
|
|
967
|
+
"application/truetype",
|
|
968
|
+
"application/ttf",
|
|
969
|
+
"application/vnd.apple.mpegurl",
|
|
970
|
+
"application/vnd.mapbox-vector-tile",
|
|
971
|
+
"application/vnd.ms-fontobject",
|
|
972
|
+
"application/wasm",
|
|
973
|
+
"application/xhtml+xml",
|
|
974
|
+
"application/xml",
|
|
975
|
+
"application/x-font-opentype",
|
|
976
|
+
"application/x-font-truetype",
|
|
977
|
+
"application/x-font-ttf",
|
|
978
|
+
"application/x-httpd-cgi",
|
|
979
|
+
"application/x-javascript",
|
|
980
|
+
"application/x-mpegurl",
|
|
981
|
+
"application/x-opentype",
|
|
982
|
+
"application/x-otf",
|
|
983
|
+
"application/x-perl",
|
|
984
|
+
"application/x-ttf",
|
|
985
|
+
"font/eot",
|
|
986
|
+
"font/opentype",
|
|
987
|
+
"font/otf",
|
|
988
|
+
"font/ttf",
|
|
989
|
+
"image/svg+xml",
|
|
990
|
+
"text/css",
|
|
991
|
+
"text/csv",
|
|
992
|
+
"text/html",
|
|
993
|
+
"text/javascript",
|
|
994
|
+
"text/js",
|
|
995
|
+
"text/plain",
|
|
996
|
+
"text/richtext",
|
|
997
|
+
"text/tab-separated-values",
|
|
998
|
+
"text/xml",
|
|
999
|
+
"text/x-component",
|
|
1000
|
+
"text/x-java-source",
|
|
1001
|
+
"text/x-script",
|
|
1002
|
+
"vnd.apple.mpegurl"
|
|
1003
|
+
]);
|
|
1004
|
+
function isCompressibleMime(mimeType) {
|
|
1005
|
+
return COMPRESSIBLE_MIMES_RE.has(mimeType);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
//#endregion
|
|
1009
|
+
//#region src/build/assets.ts
|
|
1010
|
+
const NEGATION_RE = /^(!?)(.*)$/;
|
|
1011
|
+
const PARENT_DIR_GLOB_RE = /!?\.\.\//;
|
|
1012
|
+
async function scanUnprefixedPublicAssets(nitro) {
|
|
1013
|
+
const scannedPaths = [];
|
|
1014
|
+
for (const asset of nitro.options.publicAssets) {
|
|
1015
|
+
if (asset.baseURL && asset.baseURL !== "/" && !asset.fallthrough) continue;
|
|
1016
|
+
if (!await isDirectory(asset.dir)) continue;
|
|
1017
|
+
const publicAssets = await glob(getIncludePatterns(nitro, asset.dir), {
|
|
1018
|
+
cwd: asset.dir,
|
|
1019
|
+
absolute: false,
|
|
1020
|
+
dot: true
|
|
1021
|
+
});
|
|
1022
|
+
scannedPaths.push(...publicAssets.map((file) => join(asset.baseURL || "/", file)));
|
|
1023
|
+
}
|
|
1024
|
+
return scannedPaths;
|
|
1025
|
+
}
|
|
1026
|
+
async function copyPublicAssets(nitro) {
|
|
1027
|
+
if (nitro.options.noPublicDir) return;
|
|
1028
|
+
for (const asset of nitro.options.publicAssets) {
|
|
1029
|
+
const srcDir = asset.dir;
|
|
1030
|
+
const dstDir = join(nitro.options.output.publicDir, asset.baseURL);
|
|
1031
|
+
if (await isDirectory(srcDir)) {
|
|
1032
|
+
const publicAssets = await glob(getIncludePatterns(nitro, srcDir), {
|
|
1033
|
+
cwd: srcDir,
|
|
1034
|
+
absolute: false,
|
|
1035
|
+
dot: true
|
|
1036
|
+
});
|
|
1037
|
+
await Promise.all(publicAssets.map(async (file) => {
|
|
1038
|
+
const src = join(srcDir, file);
|
|
1039
|
+
const dst = join(dstDir, file);
|
|
1040
|
+
if (!existsSync(dst)) await promises.cp(src, dst);
|
|
1041
|
+
}));
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1045
|
+
nitro.logger.success("Generated public " + prettyPath(nitro.options.output.publicDir));
|
|
1046
|
+
}
|
|
1047
|
+
function getIncludePatterns(nitro, srcDir) {
|
|
1048
|
+
return ["**", ...nitro.options.ignore.map((p) => {
|
|
1049
|
+
const [_, negation, pattern] = p.match(NEGATION_RE) || [];
|
|
1050
|
+
return (negation ? "" : "!") + (pattern.startsWith("*") ? pattern : relative(srcDir, resolve(nitro.options.srcDir, pattern)));
|
|
1051
|
+
})].filter((p) => !PARENT_DIR_GLOB_RE.test(p));
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
//#endregion
|
|
1055
|
+
//#region src/build/prepare.ts
|
|
1056
|
+
async function prepare(nitro) {
|
|
1057
|
+
await prepareDir(nitro.options.output.dir);
|
|
1058
|
+
if (!nitro.options.noPublicDir) await prepareDir(nitro.options.output.publicDir);
|
|
1059
|
+
if (!nitro.options.static) await prepareDir(nitro.options.output.serverDir);
|
|
1060
|
+
}
|
|
1061
|
+
async function prepareDir(dir) {
|
|
1062
|
+
await fsp.rm(dir, {
|
|
1063
|
+
recursive: true,
|
|
1064
|
+
force: true
|
|
1065
|
+
});
|
|
1066
|
+
await fsp.mkdir(dir, { recursive: true });
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/prerender/utils.ts
|
|
1071
|
+
const allowedExtensions = new Set(["", ".json"]);
|
|
1072
|
+
const linkParents$1 = /* @__PURE__ */ new Map();
|
|
1073
|
+
const HTML_ENTITIES = {
|
|
1074
|
+
"<": "<",
|
|
1075
|
+
">": ">",
|
|
1076
|
+
"&": "&",
|
|
1077
|
+
"'": "'",
|
|
1078
|
+
""": "\""
|
|
1079
|
+
};
|
|
1080
|
+
function escapeHtml(text) {
|
|
1081
|
+
return text.replace(/&(lt|gt|amp|apos|quot);/g, (ch) => HTML_ENTITIES[ch] || ch);
|
|
1082
|
+
}
|
|
1083
|
+
async function extractLinks(html, from, res, crawlLinks) {
|
|
1084
|
+
const links = [];
|
|
1085
|
+
const _links = [];
|
|
1086
|
+
if (crawlLinks) await z(P(html), (node) => {
|
|
1087
|
+
if (!node.attributes?.href) return;
|
|
1088
|
+
const link = escapeHtml(node.attributes.href);
|
|
1089
|
+
if (!decodeURIComponent(link).startsWith("#") && allowedExtensions.has(getExtension(link))) _links.push(link);
|
|
1090
|
+
});
|
|
1091
|
+
const header = res.headers.get("x-nitro-prerender") || "";
|
|
1092
|
+
_links.push(...header.split(",").map((i) => decodeURIComponent(i.trim())));
|
|
1093
|
+
for (const link of _links.filter(Boolean)) {
|
|
1094
|
+
const _link = parseURL(link);
|
|
1095
|
+
if (_link.protocol || _link.host) continue;
|
|
1096
|
+
if (!_link.pathname.startsWith("/")) {
|
|
1097
|
+
const fromURL = new URL(from, "http://localhost");
|
|
1098
|
+
_link.pathname = new URL(_link.pathname, fromURL).pathname;
|
|
1099
|
+
}
|
|
1100
|
+
links.push(_link.pathname + _link.search);
|
|
1101
|
+
}
|
|
1102
|
+
for (const link of links) {
|
|
1103
|
+
const _parents = linkParents$1.get(link);
|
|
1104
|
+
if (_parents) _parents.add(from);
|
|
1105
|
+
else linkParents$1.set(link, new Set([from]));
|
|
1106
|
+
}
|
|
1107
|
+
return links;
|
|
1108
|
+
}
|
|
1109
|
+
const EXT_REGEX = /\.[\da-z]+$/;
|
|
1110
|
+
function getExtension(link) {
|
|
1111
|
+
return (parseURL(link).pathname.match(EXT_REGEX) || [])[0] || "";
|
|
1112
|
+
}
|
|
1113
|
+
function formatPrerenderRoute(route) {
|
|
1114
|
+
let str = ` ├─ ${route.route} (${route.generateTimeMS}ms)`;
|
|
1115
|
+
if (route.error) {
|
|
1116
|
+
const parents = linkParents$1.get(route.route);
|
|
1117
|
+
const errorColor = colors[route.error.status === 404 ? "yellow" : "red"];
|
|
1118
|
+
const errorLead = parents?.size ? "├──" : "└──";
|
|
1119
|
+
str += `\n │ ${errorLead} ${errorColor(route.error.message)}`;
|
|
1120
|
+
if (parents?.size) str += `\n${[...parents.values()].map((link) => ` │ └── Linked from ${link}`).join("\n")}`;
|
|
1121
|
+
}
|
|
1122
|
+
if (route.skip) str += colors.gray(" (skipped)");
|
|
1123
|
+
return colors.gray(str);
|
|
1124
|
+
}
|
|
1125
|
+
function matchesIgnorePattern(path, pattern) {
|
|
1126
|
+
if (typeof pattern === "string") return path.startsWith(pattern);
|
|
1127
|
+
if (typeof pattern === "function") return pattern(path) === true;
|
|
1128
|
+
if (pattern instanceof RegExp) return pattern.test(path);
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region src/prerender/prerender.ts
|
|
1134
|
+
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
1135
|
+
const linkParents = /* @__PURE__ */ new Map();
|
|
1136
|
+
async function prerender(nitro) {
|
|
1137
|
+
if (nitro.options.noPublicDir) {
|
|
1138
|
+
nitro.logger.warn("Skipping prerender since `noPublicDir` option is enabled.");
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
if (nitro.options.builder === "vite") {
|
|
1142
|
+
nitro.logger.warn("Skipping prerender since not supported with vite builder yet...");
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
const routes = new Set(nitro.options.prerender.routes);
|
|
1146
|
+
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path$1, options]) => options.prerender && !path$1.includes("*")).map((e) => e[0]);
|
|
1147
|
+
for (const route of prerenderRulePaths) routes.add(route);
|
|
1148
|
+
await nitro.hooks.callHook("prerender:routes", routes);
|
|
1149
|
+
if (routes.size === 0) if (nitro.options.prerender.crawlLinks) routes.add("/");
|
|
1150
|
+
else return;
|
|
1151
|
+
nitro.logger.info("Initializing prerenderer");
|
|
1152
|
+
nitro._prerenderedRoutes = [];
|
|
1153
|
+
nitro._prerenderMeta = nitro._prerenderMeta || {};
|
|
1154
|
+
const prerendererConfig = {
|
|
1155
|
+
...nitro.options._config,
|
|
1156
|
+
static: false,
|
|
1157
|
+
rootDir: nitro.options.rootDir,
|
|
1158
|
+
logLevel: 0,
|
|
1159
|
+
preset: "nitro-prerender"
|
|
1160
|
+
};
|
|
1161
|
+
await nitro.hooks.callHook("prerender:config", prerendererConfig);
|
|
1162
|
+
const nitroRenderer = await createNitro(prerendererConfig);
|
|
1163
|
+
const prerenderStartTime = Date.now();
|
|
1164
|
+
await nitro.hooks.callHook("prerender:init", nitroRenderer);
|
|
1165
|
+
let path = relative(nitro.options.output.dir, nitro.options.output.publicDir);
|
|
1166
|
+
if (!path.startsWith(".")) path = `./${path}`;
|
|
1167
|
+
nitroRenderer.options.commands.preview = `npx serve ${path}`;
|
|
1168
|
+
nitroRenderer.options.output.dir = nitro.options.output.dir;
|
|
1169
|
+
await build(nitroRenderer);
|
|
1170
|
+
const serverFilename = typeof nitroRenderer.options.rollupConfig?.output?.entryFileNames === "string" ? nitroRenderer.options.rollupConfig.output.entryFileNames : "index.mjs";
|
|
1171
|
+
const { closePrerenderer, appFetch } = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href);
|
|
1172
|
+
const routeRules = createRouter();
|
|
1173
|
+
for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
|
|
1174
|
+
const _getRouteRules = (path$1) => defu({}, ...findAllRoutes(routeRules, void 0, path$1).map((r) => r.data).reverse());
|
|
1175
|
+
const generatedRoutes = /* @__PURE__ */ new Set();
|
|
1176
|
+
const failedRoutes = /* @__PURE__ */ new Set();
|
|
1177
|
+
const skippedRoutes = /* @__PURE__ */ new Set();
|
|
1178
|
+
const displayedLengthWarns = /* @__PURE__ */ new Set();
|
|
1179
|
+
const publicAssetBases = nitro.options.publicAssets.filter((a$1) => !!a$1.baseURL && a$1.baseURL !== "/" && !a$1.fallthrough).map((a$1) => withTrailingSlash(a$1.baseURL));
|
|
1180
|
+
const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
|
|
1181
|
+
const canPrerender = (route = "/") => {
|
|
1182
|
+
if (generatedRoutes.has(route) || skippedRoutes.has(route)) return false;
|
|
1183
|
+
for (const pattern of nitro.options.prerender.ignore) if (matchesIgnorePattern(route, pattern)) return false;
|
|
1184
|
+
if (publicAssetBases.some((base) => route.startsWith(base))) return false;
|
|
1185
|
+
if (scannedPublicAssets.has(route)) return false;
|
|
1186
|
+
if (_getRouteRules(route).prerender === false) return false;
|
|
1187
|
+
return true;
|
|
1188
|
+
};
|
|
1189
|
+
const canWriteToDisk = (route) => {
|
|
1190
|
+
if (route.route.includes("?")) return false;
|
|
1191
|
+
const FS_MAX_SEGMENT = 255;
|
|
1192
|
+
const FS_MAX_PATH_PUBLIC_HTML = 1024 - (nitro.options.output.publicDir.length + 10);
|
|
1193
|
+
if ((route.route.length >= FS_MAX_PATH_PUBLIC_HTML || route.route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route)) {
|
|
1194
|
+
displayedLengthWarns.add(route);
|
|
1195
|
+
const _route = route.route.slice(0, 60) + "...";
|
|
1196
|
+
if (route.route.length >= FS_MAX_PATH_PUBLIC_HTML) nitro.logger.warn(`Prerendering long route "${_route}" (${route.route.length}) can cause filesystem issues since it exceeds ${FS_MAX_PATH_PUBLIC_HTML}-character limit when writing to \`${nitro.options.output.publicDir}\`.`);
|
|
1197
|
+
else {
|
|
1198
|
+
nitro.logger.warn(`Skipping prerender of the route "${_route}" since it exceeds the ${FS_MAX_SEGMENT}-character limit in one of the path segments and can cause filesystem issues.`);
|
|
1199
|
+
return false;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
return true;
|
|
1203
|
+
};
|
|
1204
|
+
const generateRoute = async (route) => {
|
|
1205
|
+
const start = Date.now();
|
|
1206
|
+
route = decodeURI(route);
|
|
1207
|
+
if (!canPrerender(route)) {
|
|
1208
|
+
skippedRoutes.add(route);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
generatedRoutes.add(route);
|
|
1212
|
+
const _route = { route };
|
|
1213
|
+
const encodedRoute = encodeURI(route);
|
|
1214
|
+
const res = await appFetch(withBase(encodedRoute, nitro.options.baseURL), { headers: [["x-nitro-prerender", encodedRoute]] });
|
|
1215
|
+
let dataBuff = Buffer.from(await res.arrayBuffer());
|
|
1216
|
+
Object.defineProperty(_route, "contents", {
|
|
1217
|
+
get: () => {
|
|
1218
|
+
return dataBuff ? dataBuff.toString("utf8") : void 0;
|
|
1219
|
+
},
|
|
1220
|
+
set(value) {
|
|
1221
|
+
if (dataBuff) dataBuff = Buffer.from(value);
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
Object.defineProperty(_route, "data", {
|
|
1225
|
+
get: () => {
|
|
1226
|
+
return dataBuff ? dataBuff.buffer : void 0;
|
|
1227
|
+
},
|
|
1228
|
+
set(value) {
|
|
1229
|
+
if (dataBuff) dataBuff = Buffer.from(value);
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
if (![200, ...[
|
|
1233
|
+
301,
|
|
1234
|
+
302,
|
|
1235
|
+
303,
|
|
1236
|
+
304,
|
|
1237
|
+
307,
|
|
1238
|
+
308
|
|
1239
|
+
]].includes(res.status)) {
|
|
1240
|
+
_route.error = /* @__PURE__ */ new Error(`[${res.status}] ${res.statusText}`);
|
|
1241
|
+
_route.error.status = res.status;
|
|
1242
|
+
_route.error.statusText = res.statusText;
|
|
1243
|
+
}
|
|
1244
|
+
_route.generateTimeMS = Date.now() - start;
|
|
1245
|
+
const contentType = res.headers.get("content-type") || "";
|
|
1246
|
+
const isImplicitHTML = !route.endsWith(".html") && contentType.includes("html") && !JsonSigRx.test(dataBuff.subarray(0, 32).toString("utf8"));
|
|
1247
|
+
const routeWithIndex = route.endsWith("/") ? route + "index" : route;
|
|
1248
|
+
const htmlPath = route.endsWith("/") || nitro.options.prerender.autoSubfolderIndex ? joinURL(route, "index.html") : route + ".html";
|
|
1249
|
+
_route.fileName = withoutBase(isImplicitHTML ? htmlPath : routeWithIndex, nitro.options.baseURL);
|
|
1250
|
+
const inferredContentType = src_default.getType(_route.fileName) || "text/plain";
|
|
1251
|
+
_route.contentType = contentType || inferredContentType;
|
|
1252
|
+
await nitro.hooks.callHook("prerender:generate", _route, nitro);
|
|
1253
|
+
if (_route.contentType !== inferredContentType) {
|
|
1254
|
+
nitro._prerenderMeta[_route.fileName] ||= {};
|
|
1255
|
+
nitro._prerenderMeta[_route.fileName].contentType = _route.contentType;
|
|
1256
|
+
}
|
|
1257
|
+
if (_route.error) failedRoutes.add(_route);
|
|
1258
|
+
if (_route.skip || _route.error) {
|
|
1259
|
+
await nitro.hooks.callHook("prerender:route", _route);
|
|
1260
|
+
nitro.logger.log(formatPrerenderRoute(_route));
|
|
1261
|
+
dataBuff = void 0;
|
|
1262
|
+
return _route;
|
|
1263
|
+
}
|
|
1264
|
+
if (canWriteToDisk(_route)) {
|
|
1265
|
+
await writeFile$1(join(nitro.options.output.publicDir, _route.fileName), dataBuff);
|
|
1266
|
+
nitro._prerenderedRoutes.push(_route);
|
|
1267
|
+
} else _route.skip = true;
|
|
1268
|
+
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
|
|
1269
|
+
const extractedLinks = await extractLinks(dataBuff.toString("utf8"), route, res, nitro.options.prerender.crawlLinks);
|
|
1270
|
+
for (const _link of extractedLinks) if (canPrerender(_link)) routes.add(_link);
|
|
1271
|
+
}
|
|
1272
|
+
await nitro.hooks.callHook("prerender:route", _route);
|
|
1273
|
+
nitro.logger.log(formatPrerenderRoute(_route));
|
|
1274
|
+
dataBuff = void 0;
|
|
1275
|
+
return _route;
|
|
1276
|
+
};
|
|
1277
|
+
nitro.logger.info(nitro.options.prerender.crawlLinks ? `Prerendering ${routes.size} initial routes with crawler` : `Prerendering ${routes.size} routes`);
|
|
1278
|
+
await runParallel(routes, generateRoute, {
|
|
1279
|
+
concurrency: nitro.options.prerender.concurrency,
|
|
1280
|
+
interval: nitro.options.prerender.interval
|
|
1281
|
+
});
|
|
1282
|
+
await closePrerenderer();
|
|
1283
|
+
await nitro.hooks.callHook("prerender:done", {
|
|
1284
|
+
prerenderedRoutes: nitro._prerenderedRoutes,
|
|
1285
|
+
failedRoutes: [...failedRoutes]
|
|
1286
|
+
});
|
|
1287
|
+
if (nitro.options.prerender.failOnError && failedRoutes.size > 0) {
|
|
1288
|
+
nitro.logger.log("\nErrors prerendering:");
|
|
1289
|
+
for (const route of failedRoutes) {
|
|
1290
|
+
const parents = linkParents.get(route.route);
|
|
1291
|
+
parents?.size && `${[...parents.values()].map((link) => colors.gray(` │ └── Linked from ${link}`)).join("\n")}`;
|
|
1292
|
+
nitro.logger.log(formatPrerenderRoute(route));
|
|
1293
|
+
}
|
|
1294
|
+
nitro.logger.log("");
|
|
1295
|
+
throw new Error("Exiting due to prerender errors.");
|
|
1296
|
+
}
|
|
1297
|
+
const prerenderTimeInMs = Date.now() - prerenderStartTime;
|
|
1298
|
+
nitro.logger.info(`Prerendered ${nitro._prerenderedRoutes.length} routes in ${prerenderTimeInMs / 1e3} seconds`);
|
|
1299
|
+
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
//#endregion
|
|
1303
|
+
export { createNitro as a, loadOptions as c, build as i, prepare as n, listTasks as o, copyPublicAssets as r, runTask as s, prerender as t };
|