nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-122334-09c1a7a8
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 +762 -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 +61 -51
- 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
package/dist/_chunks/builder.mjs
DELETED
|
@@ -1,648 +0,0 @@
|
|
|
1
|
-
import { r as resolveNitroPath, i as isDirectory, w as writeFile, c as createNitro, b as scanUnprefixedPublicAssets, d as compressPublicAssets } from '../_build/prepare.mjs';
|
|
2
|
-
import { existsSync, promises } from 'node:fs';
|
|
3
|
-
import { defu } from 'defu';
|
|
4
|
-
import { i as parseNodeModulePath, l as lookupNodeModuleSubpath } from './_deps/mlly.mjs';
|
|
5
|
-
import { r as resolveModulePath } from './_deps/exsolve.mjs';
|
|
6
|
-
import { runtimeDir } from 'nitro/runtime/meta';
|
|
7
|
-
import { r as resolve, a as relative, c as resolveAlias, i as isAbsolute, j as join, d as dirname } from './_deps/pathe.mjs';
|
|
8
|
-
import { g as generateTypes, r as resolveSchema } from './_deps/untyped.mjs';
|
|
9
|
-
import { t as toExports } from './_deps/unimport.mjs';
|
|
10
|
-
import './server.mjs';
|
|
11
|
-
import { pathToFileURL } from 'node:url';
|
|
12
|
-
import { colors } from 'consola/utils';
|
|
13
|
-
import { m as mime } from './_deps/mime.mjs';
|
|
14
|
-
import { a as addRoute, f as findAllRoutes, c as createRouter } from './_deps/rou3.mjs';
|
|
15
|
-
import { parseURL, withTrailingSlash, withBase, joinURL, withoutBase } from 'ufo';
|
|
16
|
-
import { z, P } from './_deps/ultrahtml.mjs';
|
|
17
|
-
|
|
18
|
-
async function build(nitro) {
|
|
19
|
-
switch (nitro.options.builder) {
|
|
20
|
-
case "rollup": {
|
|
21
|
-
const { rollupBuild } = await import('../_build/build2.mjs');
|
|
22
|
-
return rollupBuild(nitro);
|
|
23
|
-
}
|
|
24
|
-
case "rolldown": {
|
|
25
|
-
const { rolldownBuild } = await import('../_build/build.mjs');
|
|
26
|
-
return rolldownBuild(nitro);
|
|
27
|
-
}
|
|
28
|
-
case "vite": {
|
|
29
|
-
const { viteBuild } = await import('../_build/vite2.mjs');
|
|
30
|
-
return viteBuild(nitro);
|
|
31
|
-
}
|
|
32
|
-
default: {
|
|
33
|
-
throw new Error(`Unknown builder: ${nitro.options.builder}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function writeTypes(nitro) {
|
|
39
|
-
const types = {
|
|
40
|
-
routes: {}
|
|
41
|
-
};
|
|
42
|
-
const typesDir = resolve(nitro.options.buildDir, "types");
|
|
43
|
-
const middleware = [...nitro.scannedHandlers, ...nitro.options.handlers];
|
|
44
|
-
for (const mw of middleware) {
|
|
45
|
-
if (typeof mw.handler !== "string" || !mw.route) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const relativePath = relative(
|
|
49
|
-
typesDir,
|
|
50
|
-
resolveNitroPath(mw.handler, nitro.options)
|
|
51
|
-
).replace(/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/, "");
|
|
52
|
-
const method = mw.method || "default";
|
|
53
|
-
types.routes[mw.route] ??= {};
|
|
54
|
-
types.routes[mw.route][method] ??= [];
|
|
55
|
-
types.routes[mw.route][method].push(
|
|
56
|
-
`Simplify<Serialize<Awaited<ReturnType<typeof import('${relativePath}').default>>>>`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
let autoImportedTypes = [];
|
|
60
|
-
let autoImportExports = "";
|
|
61
|
-
if (nitro.unimport) {
|
|
62
|
-
await nitro.unimport.init();
|
|
63
|
-
const allImports = await nitro.unimport.getImports();
|
|
64
|
-
autoImportExports = toExports(allImports).replace(
|
|
65
|
-
/#internal\/nitro/g,
|
|
66
|
-
relative(typesDir, runtimeDir)
|
|
67
|
-
);
|
|
68
|
-
const resolvedImportPathMap = /* @__PURE__ */ new Map();
|
|
69
|
-
for (const i of allImports) {
|
|
70
|
-
const from = i.typeFrom || i.from;
|
|
71
|
-
if (resolvedImportPathMap.has(from)) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
let path = resolveAlias(from, nitro.options.alias);
|
|
75
|
-
if (!isAbsolute(path)) {
|
|
76
|
-
const resolvedPath = resolveModulePath(from, {
|
|
77
|
-
try: true,
|
|
78
|
-
from: nitro.options.nodeModulesDirs,
|
|
79
|
-
conditions: ["type", "node", "import"],
|
|
80
|
-
suffixes: ["", "/index"],
|
|
81
|
-
extensions: [".mjs", ".cjs", ".js", ".mts", ".cts", ".ts"]
|
|
82
|
-
});
|
|
83
|
-
if (resolvedPath) {
|
|
84
|
-
const { dir, name } = parseNodeModulePath(resolvedPath);
|
|
85
|
-
if (!dir || !name) {
|
|
86
|
-
path = resolvedPath;
|
|
87
|
-
} else {
|
|
88
|
-
const subpath = await lookupNodeModuleSubpath(resolvedPath);
|
|
89
|
-
path = join(dir, name, subpath || "");
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (existsSync(path) && !await isDirectory(path)) {
|
|
94
|
-
path = path.replace(/\.[a-z]+$/, "");
|
|
95
|
-
}
|
|
96
|
-
if (isAbsolute(path)) {
|
|
97
|
-
path = relative(typesDir, path);
|
|
98
|
-
}
|
|
99
|
-
resolvedImportPathMap.set(from, path);
|
|
100
|
-
}
|
|
101
|
-
autoImportedTypes = [
|
|
102
|
-
nitro.options.imports && nitro.options.imports.autoImport !== false ? (await nitro.unimport.generateTypeDeclarations({
|
|
103
|
-
exportHelper: false,
|
|
104
|
-
resolvePath: (i) => {
|
|
105
|
-
const from = i.typeFrom || i.from;
|
|
106
|
-
return resolvedImportPathMap.get(from) ?? from;
|
|
107
|
-
}
|
|
108
|
-
})).trim() : ""
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
const generateRoutes = () => [
|
|
112
|
-
"// Generated by nitro",
|
|
113
|
-
'import type { Serialize, Simplify } from "nitro/types";',
|
|
114
|
-
'declare module "nitro/types" {',
|
|
115
|
-
" type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T",
|
|
116
|
-
" interface InternalApi {",
|
|
117
|
-
...Object.entries(types.routes).map(
|
|
118
|
-
([path, methods]) => [
|
|
119
|
-
` '${path}': {`,
|
|
120
|
-
...Object.entries(methods).map(
|
|
121
|
-
([method, types2]) => ` '${method}': ${types2.join(" | ")}`
|
|
122
|
-
),
|
|
123
|
-
" }"
|
|
124
|
-
].join("\n")
|
|
125
|
-
),
|
|
126
|
-
" }",
|
|
127
|
-
"}",
|
|
128
|
-
// Makes this a module for augmentation purposes
|
|
129
|
-
"export {}"
|
|
130
|
-
];
|
|
131
|
-
const config = [
|
|
132
|
-
"// Generated by nitro",
|
|
133
|
-
/* ts */
|
|
134
|
-
`declare module "nitro/types" {`,
|
|
135
|
-
nitro.options.typescript.generateRuntimeConfigTypes ? generateTypes(
|
|
136
|
-
await resolveSchema(
|
|
137
|
-
Object.fromEntries(
|
|
138
|
-
Object.entries(nitro.options.runtimeConfig).filter(
|
|
139
|
-
([key]) => !["app", "nitro"].includes(key)
|
|
140
|
-
)
|
|
141
|
-
)
|
|
142
|
-
),
|
|
143
|
-
{
|
|
144
|
-
interfaceName: "NitroRuntimeConfig",
|
|
145
|
-
addExport: false,
|
|
146
|
-
addDefaults: false,
|
|
147
|
-
allowExtraKeys: false,
|
|
148
|
-
indentation: 2
|
|
149
|
-
}
|
|
150
|
-
) : "",
|
|
151
|
-
`}`,
|
|
152
|
-
// Makes this a module for augmentation purposes
|
|
153
|
-
"export {}"
|
|
154
|
-
];
|
|
155
|
-
const declarations = [
|
|
156
|
-
// local nitropack augmentations
|
|
157
|
-
'/// <reference path="./nitro-routes.d.ts" />',
|
|
158
|
-
'/// <reference path="./nitro-config.d.ts" />',
|
|
159
|
-
// global server auto-imports
|
|
160
|
-
'/// <reference path="./nitro-imports.d.ts" />'
|
|
161
|
-
];
|
|
162
|
-
const buildFiles = [];
|
|
163
|
-
buildFiles.push({
|
|
164
|
-
path: join(typesDir, "nitro-routes.d.ts"),
|
|
165
|
-
contents: () => generateRoutes().join("\n")
|
|
166
|
-
});
|
|
167
|
-
buildFiles.push({
|
|
168
|
-
path: join(typesDir, "nitro-config.d.ts"),
|
|
169
|
-
contents: config.join("\n")
|
|
170
|
-
});
|
|
171
|
-
buildFiles.push({
|
|
172
|
-
path: join(typesDir, "nitro-imports.d.ts"),
|
|
173
|
-
contents: [...autoImportedTypes, autoImportExports || "export {}"].join(
|
|
174
|
-
"\n"
|
|
175
|
-
)
|
|
176
|
-
});
|
|
177
|
-
buildFiles.push({
|
|
178
|
-
path: join(typesDir, "nitro.d.ts"),
|
|
179
|
-
contents: declarations.join("\n")
|
|
180
|
-
});
|
|
181
|
-
if (nitro.options.typescript.generateTsConfig) {
|
|
182
|
-
const tsConfigPath = resolve(
|
|
183
|
-
nitro.options.buildDir,
|
|
184
|
-
nitro.options.typescript.tsconfigPath
|
|
185
|
-
);
|
|
186
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
187
|
-
const tsConfig = defu(nitro.options.typescript.tsConfig, {
|
|
188
|
-
compilerOptions: {
|
|
189
|
-
/* Base options: */
|
|
190
|
-
esModuleInterop: true,
|
|
191
|
-
allowSyntheticDefaultImports: true,
|
|
192
|
-
skipLibCheck: true,
|
|
193
|
-
target: "ESNext",
|
|
194
|
-
allowJs: true,
|
|
195
|
-
resolveJsonModule: true,
|
|
196
|
-
moduleDetection: "force",
|
|
197
|
-
isolatedModules: true,
|
|
198
|
-
verbatimModuleSyntax: true,
|
|
199
|
-
allowImportingTsExtensions: true,
|
|
200
|
-
/* Strictness */
|
|
201
|
-
strict: nitro.options.typescript.strict,
|
|
202
|
-
noUncheckedIndexedAccess: true,
|
|
203
|
-
noImplicitOverride: true,
|
|
204
|
-
forceConsistentCasingInFileNames: true,
|
|
205
|
-
/* If NOT transpiling with TypeScript: */
|
|
206
|
-
module: "Preserve",
|
|
207
|
-
jsx: "preserve",
|
|
208
|
-
jsxFactory: "h",
|
|
209
|
-
jsxFragmentFactory: "Fragment",
|
|
210
|
-
paths: {
|
|
211
|
-
"#imports": [
|
|
212
|
-
relativeWithDot(tsconfigDir, join(typesDir, "nitro-imports"))
|
|
213
|
-
],
|
|
214
|
-
...nitro.options.typescript.internalPaths ? {
|
|
215
|
-
"nitro/runtime": [
|
|
216
|
-
relativeWithDot(tsconfigDir, join(runtimeDir, "index"))
|
|
217
|
-
],
|
|
218
|
-
"#internal/nitro": [
|
|
219
|
-
relativeWithDot(tsconfigDir, join(runtimeDir, "index"))
|
|
220
|
-
],
|
|
221
|
-
"nitro/runtime/*": [
|
|
222
|
-
relativeWithDot(tsconfigDir, join(runtimeDir, "*"))
|
|
223
|
-
],
|
|
224
|
-
"#internal/nitro/*": [
|
|
225
|
-
relativeWithDot(tsconfigDir, join(runtimeDir, "*"))
|
|
226
|
-
]
|
|
227
|
-
} : {}
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
include: [
|
|
231
|
-
relativeWithDot(tsconfigDir, join(typesDir, "nitro.d.ts")).replace(
|
|
232
|
-
/^(?=[^.])/,
|
|
233
|
-
"./"
|
|
234
|
-
),
|
|
235
|
-
join(relativeWithDot(tsconfigDir, nitro.options.rootDir), "**/*"),
|
|
236
|
-
...nitro.options.srcDir === nitro.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, nitro.options.srcDir), "**/*")]
|
|
237
|
-
]
|
|
238
|
-
});
|
|
239
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
240
|
-
const paths = await Promise.all(
|
|
241
|
-
tsConfig.compilerOptions.paths[alias].map(async (path) => {
|
|
242
|
-
if (!isAbsolute(path)) {
|
|
243
|
-
return path;
|
|
244
|
-
}
|
|
245
|
-
const stats = await promises.stat(path).catch(
|
|
246
|
-
() => null
|
|
247
|
-
/* file does not exist */
|
|
248
|
-
);
|
|
249
|
-
return relativeWithDot(
|
|
250
|
-
tsconfigDir,
|
|
251
|
-
stats?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, "") : path
|
|
252
|
-
);
|
|
253
|
-
})
|
|
254
|
-
);
|
|
255
|
-
tsConfig.compilerOptions.paths[alias] = [...new Set(paths)];
|
|
256
|
-
}
|
|
257
|
-
tsConfig.include = [
|
|
258
|
-
...new Set(
|
|
259
|
-
tsConfig.include.map(
|
|
260
|
-
(p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p
|
|
261
|
-
)
|
|
262
|
-
)
|
|
263
|
-
];
|
|
264
|
-
if (tsConfig.exclude) {
|
|
265
|
-
tsConfig.exclude = [
|
|
266
|
-
...new Set(
|
|
267
|
-
tsConfig.exclude.map(
|
|
268
|
-
(p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p
|
|
269
|
-
)
|
|
270
|
-
)
|
|
271
|
-
];
|
|
272
|
-
}
|
|
273
|
-
types.tsConfig = tsConfig;
|
|
274
|
-
buildFiles.push({
|
|
275
|
-
path: tsConfigPath,
|
|
276
|
-
contents: () => JSON.stringify(tsConfig, null, 2)
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
await nitro.hooks.callHook("types:extend", types);
|
|
280
|
-
await Promise.all(
|
|
281
|
-
buildFiles.map(async (file) => {
|
|
282
|
-
await writeFile(
|
|
283
|
-
resolve(nitro.options.buildDir, file.path),
|
|
284
|
-
typeof file.contents === "string" ? file.contents : file.contents()
|
|
285
|
-
);
|
|
286
|
-
})
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
290
|
-
function relativeWithDot(from, to) {
|
|
291
|
-
const rel = relative(from, to);
|
|
292
|
-
return RELATIVE_RE.test(rel) ? rel : "./" + rel;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async function runParallel(inputs, cb, opts) {
|
|
296
|
-
const tasks = /* @__PURE__ */ new Set();
|
|
297
|
-
function queueNext() {
|
|
298
|
-
const route = inputs.values().next().value;
|
|
299
|
-
if (!route) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
inputs.delete(route);
|
|
303
|
-
const task = (opts.interval ? new Promise((resolve) => setTimeout(resolve, opts.interval)) : Promise.resolve()).then(() => cb(route)).catch((error) => {
|
|
304
|
-
console.error(error);
|
|
305
|
-
});
|
|
306
|
-
tasks.add(task);
|
|
307
|
-
return task.then(() => {
|
|
308
|
-
tasks.delete(task);
|
|
309
|
-
if (inputs.size > 0) {
|
|
310
|
-
return refillQueue();
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
function refillQueue() {
|
|
315
|
-
const workers = Math.min(opts.concurrency - tasks.size, inputs.size);
|
|
316
|
-
return Promise.all(Array.from({ length: workers }, () => queueNext()));
|
|
317
|
-
}
|
|
318
|
-
await refillQueue();
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const allowedExtensions = /* @__PURE__ */ new Set(["", ".json"]);
|
|
322
|
-
const linkParents$1 = /* @__PURE__ */ new Map();
|
|
323
|
-
const HTML_ENTITIES = {
|
|
324
|
-
"<": "<",
|
|
325
|
-
">": ">",
|
|
326
|
-
"&": "&",
|
|
327
|
-
"'": "'",
|
|
328
|
-
""": '"'
|
|
329
|
-
};
|
|
330
|
-
function escapeHtml(text) {
|
|
331
|
-
return text.replace(
|
|
332
|
-
/&(lt|gt|amp|apos|quot);/g,
|
|
333
|
-
(ch) => HTML_ENTITIES[ch] || ch
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
async function extractLinks(html, from, res, crawlLinks) {
|
|
337
|
-
const links = [];
|
|
338
|
-
const _links = [];
|
|
339
|
-
if (crawlLinks) {
|
|
340
|
-
await z(P(html), (node) => {
|
|
341
|
-
if (!node.attributes?.href) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
const link = escapeHtml(node.attributes.href);
|
|
345
|
-
if (!decodeURIComponent(link).startsWith("#") && allowedExtensions.has(getExtension(link))) {
|
|
346
|
-
_links.push(link);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
const header = res.headers.get("x-nitro-prerender") || "";
|
|
351
|
-
_links.push(...header.split(",").map((i) => decodeURIComponent(i.trim())));
|
|
352
|
-
for (const link of _links.filter(Boolean)) {
|
|
353
|
-
const _link = parseURL(link);
|
|
354
|
-
if (_link.protocol || _link.host) {
|
|
355
|
-
continue;
|
|
356
|
-
}
|
|
357
|
-
if (!_link.pathname.startsWith("/")) {
|
|
358
|
-
const fromURL = new URL(from, "http://localhost");
|
|
359
|
-
_link.pathname = new URL(_link.pathname, fromURL).pathname;
|
|
360
|
-
}
|
|
361
|
-
links.push(_link.pathname + _link.search);
|
|
362
|
-
}
|
|
363
|
-
for (const link of links) {
|
|
364
|
-
const _parents = linkParents$1.get(link);
|
|
365
|
-
if (_parents) {
|
|
366
|
-
_parents.add(from);
|
|
367
|
-
} else {
|
|
368
|
-
linkParents$1.set(link, /* @__PURE__ */ new Set([from]));
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return links;
|
|
372
|
-
}
|
|
373
|
-
const EXT_REGEX = /\.[\da-z]+$/;
|
|
374
|
-
function getExtension(link) {
|
|
375
|
-
const pathname = parseURL(link).pathname;
|
|
376
|
-
return (pathname.match(EXT_REGEX) || [])[0] || "";
|
|
377
|
-
}
|
|
378
|
-
function formatPrerenderRoute(route) {
|
|
379
|
-
let str = ` \u251C\u2500 ${route.route} (${route.generateTimeMS}ms)`;
|
|
380
|
-
if (route.error) {
|
|
381
|
-
const parents = linkParents$1.get(route.route);
|
|
382
|
-
const errorColor = colors[route.error.status === 404 ? "yellow" : "red"];
|
|
383
|
-
const errorLead = parents?.size ? "\u251C\u2500\u2500" : "\u2514\u2500\u2500";
|
|
384
|
-
str += `
|
|
385
|
-
\u2502 ${errorLead} ${errorColor(route.error.message)}`;
|
|
386
|
-
if (parents?.size) {
|
|
387
|
-
str += `
|
|
388
|
-
${[...parents.values()].map((link) => ` \u2502 \u2514\u2500\u2500 Linked from ${link}`).join("\n")}`;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
if (route.skip) {
|
|
392
|
-
str += colors.gray(" (skipped)");
|
|
393
|
-
}
|
|
394
|
-
return colors.gray(str);
|
|
395
|
-
}
|
|
396
|
-
function matchesIgnorePattern(path, pattern) {
|
|
397
|
-
if (typeof pattern === "string") {
|
|
398
|
-
return path.startsWith(pattern);
|
|
399
|
-
}
|
|
400
|
-
if (typeof pattern === "function") {
|
|
401
|
-
return pattern(path) === true;
|
|
402
|
-
}
|
|
403
|
-
if (pattern instanceof RegExp) {
|
|
404
|
-
return pattern.test(path);
|
|
405
|
-
}
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
410
|
-
const linkParents = /* @__PURE__ */ new Map();
|
|
411
|
-
async function prerender(nitro) {
|
|
412
|
-
if (nitro.options.noPublicDir) {
|
|
413
|
-
nitro.logger.warn(
|
|
414
|
-
"Skipping prerender since `noPublicDir` option is enabled."
|
|
415
|
-
);
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
if (nitro.options.builder === "vite") {
|
|
419
|
-
nitro.logger.warn(
|
|
420
|
-
"Skipping prerender since not supported with vite builder yet..."
|
|
421
|
-
);
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
const routes = new Set(nitro.options.prerender.routes);
|
|
425
|
-
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path2, options]) => options.prerender && !path2.includes("*")).map((e) => e[0]);
|
|
426
|
-
for (const route of prerenderRulePaths) {
|
|
427
|
-
routes.add(route);
|
|
428
|
-
}
|
|
429
|
-
await nitro.hooks.callHook("prerender:routes", routes);
|
|
430
|
-
if (routes.size === 0) {
|
|
431
|
-
if (nitro.options.prerender.crawlLinks) {
|
|
432
|
-
routes.add("/");
|
|
433
|
-
} else {
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
nitro.logger.info("Initializing prerenderer");
|
|
438
|
-
nitro._prerenderedRoutes = [];
|
|
439
|
-
nitro._prerenderMeta = nitro._prerenderMeta || {};
|
|
440
|
-
const prerendererConfig = {
|
|
441
|
-
...nitro.options._config,
|
|
442
|
-
static: false,
|
|
443
|
-
rootDir: nitro.options.rootDir,
|
|
444
|
-
logLevel: 0,
|
|
445
|
-
preset: "nitro-prerender"
|
|
446
|
-
};
|
|
447
|
-
await nitro.hooks.callHook("prerender:config", prerendererConfig);
|
|
448
|
-
const nitroRenderer = await createNitro(prerendererConfig);
|
|
449
|
-
const prerenderStartTime = Date.now();
|
|
450
|
-
await nitro.hooks.callHook("prerender:init", nitroRenderer);
|
|
451
|
-
let path = relative(nitro.options.output.dir, nitro.options.output.publicDir);
|
|
452
|
-
if (!path.startsWith(".")) {
|
|
453
|
-
path = `./${path}`;
|
|
454
|
-
}
|
|
455
|
-
nitroRenderer.options.commands.preview = `npx serve ${path}`;
|
|
456
|
-
nitroRenderer.options.output.dir = nitro.options.output.dir;
|
|
457
|
-
await build(nitroRenderer);
|
|
458
|
-
const serverFilename = typeof nitroRenderer.options.rollupConfig?.output?.entryFileNames === "string" ? nitroRenderer.options.rollupConfig.output.entryFileNames : "index.mjs";
|
|
459
|
-
const serverEntrypoint = resolve(
|
|
460
|
-
nitroRenderer.options.output.serverDir,
|
|
461
|
-
serverFilename
|
|
462
|
-
);
|
|
463
|
-
const { closePrerenderer, appFetch } = await import(pathToFileURL(serverEntrypoint).href);
|
|
464
|
-
const routeRules = createRouter();
|
|
465
|
-
for (const [route, rules] of Object.entries(nitro.options.routeRules)) {
|
|
466
|
-
addRoute(routeRules, void 0, route, rules);
|
|
467
|
-
}
|
|
468
|
-
const _getRouteRules = (path2) => defu(
|
|
469
|
-
{},
|
|
470
|
-
...findAllRoutes(routeRules, void 0, path2).map((r) => r.data).reverse()
|
|
471
|
-
);
|
|
472
|
-
const generatedRoutes = /* @__PURE__ */ new Set();
|
|
473
|
-
const failedRoutes = /* @__PURE__ */ new Set();
|
|
474
|
-
const skippedRoutes = /* @__PURE__ */ new Set();
|
|
475
|
-
const displayedLengthWarns = /* @__PURE__ */ new Set();
|
|
476
|
-
const publicAssetBases = nitro.options.publicAssets.filter(
|
|
477
|
-
(a) => !!a.baseURL && a.baseURL !== "/" && !a.fallthrough
|
|
478
|
-
).map((a) => withTrailingSlash(a.baseURL));
|
|
479
|
-
const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
|
|
480
|
-
const canPrerender = (route = "/") => {
|
|
481
|
-
if (generatedRoutes.has(route) || skippedRoutes.has(route)) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
for (const pattern of nitro.options.prerender.ignore) {
|
|
485
|
-
if (matchesIgnorePattern(route, pattern)) {
|
|
486
|
-
return false;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (publicAssetBases.some((base) => route.startsWith(base))) {
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
if (scannedPublicAssets.has(route)) {
|
|
493
|
-
return false;
|
|
494
|
-
}
|
|
495
|
-
if (_getRouteRules(route).prerender === false) {
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
return true;
|
|
499
|
-
};
|
|
500
|
-
const canWriteToDisk = (route) => {
|
|
501
|
-
if (route.route.includes("?")) {
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
const FS_MAX_SEGMENT = 255;
|
|
505
|
-
const FS_MAX_PATH = 1024;
|
|
506
|
-
const FS_MAX_PATH_PUBLIC_HTML = FS_MAX_PATH - (nitro.options.output.publicDir.length + 10);
|
|
507
|
-
if ((route.route.length >= FS_MAX_PATH_PUBLIC_HTML || route.route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route)) {
|
|
508
|
-
displayedLengthWarns.add(route);
|
|
509
|
-
const _route = route.route.slice(0, 60) + "...";
|
|
510
|
-
if (route.route.length >= FS_MAX_PATH_PUBLIC_HTML) {
|
|
511
|
-
nitro.logger.warn(
|
|
512
|
-
`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}\`.`
|
|
513
|
-
);
|
|
514
|
-
} else {
|
|
515
|
-
nitro.logger.warn(
|
|
516
|
-
`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.`
|
|
517
|
-
);
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
return true;
|
|
522
|
-
};
|
|
523
|
-
const generateRoute = async (route) => {
|
|
524
|
-
const start = Date.now();
|
|
525
|
-
route = decodeURI(route);
|
|
526
|
-
if (!canPrerender(route)) {
|
|
527
|
-
skippedRoutes.add(route);
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
generatedRoutes.add(route);
|
|
531
|
-
const _route = { route };
|
|
532
|
-
const encodedRoute = encodeURI(route);
|
|
533
|
-
const res = await appFetch(withBase(encodedRoute, nitro.options.baseURL), {
|
|
534
|
-
headers: [["x-nitro-prerender", encodedRoute]]
|
|
535
|
-
// TODO
|
|
536
|
-
// retry: nitro.options.prerender.retry,
|
|
537
|
-
// retryDelay: nitro.options.prerender.retryDelay,
|
|
538
|
-
});
|
|
539
|
-
let dataBuff = Buffer.from(await res.arrayBuffer());
|
|
540
|
-
Object.defineProperty(_route, "contents", {
|
|
541
|
-
get: () => {
|
|
542
|
-
return dataBuff ? dataBuff.toString("utf8") : void 0;
|
|
543
|
-
},
|
|
544
|
-
set(value) {
|
|
545
|
-
if (dataBuff) {
|
|
546
|
-
dataBuff = Buffer.from(value);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
Object.defineProperty(_route, "data", {
|
|
551
|
-
get: () => {
|
|
552
|
-
return dataBuff ? dataBuff.buffer : void 0;
|
|
553
|
-
},
|
|
554
|
-
set(value) {
|
|
555
|
-
if (dataBuff) {
|
|
556
|
-
dataBuff = Buffer.from(value);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
const redirectCodes = [301, 302, 303, 304, 307, 308];
|
|
561
|
-
if (![200, ...redirectCodes].includes(res.status)) {
|
|
562
|
-
_route.error = new Error(`[${res.status}] ${res.statusText}`);
|
|
563
|
-
_route.error.status = res.status;
|
|
564
|
-
_route.error.statusText = res.statusText;
|
|
565
|
-
}
|
|
566
|
-
_route.generateTimeMS = Date.now() - start;
|
|
567
|
-
const contentType = res.headers.get("content-type") || "";
|
|
568
|
-
const isImplicitHTML = !route.endsWith(".html") && contentType.includes("html") && !JsonSigRx.test(dataBuff.subarray(0, 32).toString("utf8"));
|
|
569
|
-
const routeWithIndex = route.endsWith("/") ? route + "index" : route;
|
|
570
|
-
const htmlPath = route.endsWith("/") || nitro.options.prerender.autoSubfolderIndex ? joinURL(route, "index.html") : route + ".html";
|
|
571
|
-
_route.fileName = withoutBase(
|
|
572
|
-
isImplicitHTML ? htmlPath : routeWithIndex,
|
|
573
|
-
nitro.options.baseURL
|
|
574
|
-
);
|
|
575
|
-
const inferredContentType = mime.getType(_route.fileName) || "text/plain";
|
|
576
|
-
_route.contentType = contentType || inferredContentType;
|
|
577
|
-
await nitro.hooks.callHook("prerender:generate", _route, nitro);
|
|
578
|
-
if (_route.contentType !== inferredContentType) {
|
|
579
|
-
nitro._prerenderMeta[_route.fileName] ||= {};
|
|
580
|
-
nitro._prerenderMeta[_route.fileName].contentType = _route.contentType;
|
|
581
|
-
}
|
|
582
|
-
if (_route.error) {
|
|
583
|
-
failedRoutes.add(_route);
|
|
584
|
-
}
|
|
585
|
-
if (_route.skip || _route.error) {
|
|
586
|
-
await nitro.hooks.callHook("prerender:route", _route);
|
|
587
|
-
nitro.logger.log(formatPrerenderRoute(_route));
|
|
588
|
-
dataBuff = void 0;
|
|
589
|
-
return _route;
|
|
590
|
-
}
|
|
591
|
-
if (canWriteToDisk(_route)) {
|
|
592
|
-
const filePath = join(nitro.options.output.publicDir, _route.fileName);
|
|
593
|
-
await writeFile(filePath, dataBuff);
|
|
594
|
-
nitro._prerenderedRoutes.push(_route);
|
|
595
|
-
} else {
|
|
596
|
-
_route.skip = true;
|
|
597
|
-
}
|
|
598
|
-
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
|
|
599
|
-
const extractedLinks = await extractLinks(
|
|
600
|
-
dataBuff.toString("utf8"),
|
|
601
|
-
route,
|
|
602
|
-
res,
|
|
603
|
-
nitro.options.prerender.crawlLinks
|
|
604
|
-
);
|
|
605
|
-
for (const _link of extractedLinks) {
|
|
606
|
-
if (canPrerender(_link)) {
|
|
607
|
-
routes.add(_link);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
await nitro.hooks.callHook("prerender:route", _route);
|
|
612
|
-
nitro.logger.log(formatPrerenderRoute(_route));
|
|
613
|
-
dataBuff = void 0;
|
|
614
|
-
return _route;
|
|
615
|
-
};
|
|
616
|
-
nitro.logger.info(
|
|
617
|
-
nitro.options.prerender.crawlLinks ? `Prerendering ${routes.size} initial routes with crawler` : `Prerendering ${routes.size} routes`
|
|
618
|
-
);
|
|
619
|
-
await runParallel(routes, generateRoute, {
|
|
620
|
-
concurrency: nitro.options.prerender.concurrency,
|
|
621
|
-
interval: nitro.options.prerender.interval
|
|
622
|
-
});
|
|
623
|
-
await closePrerenderer();
|
|
624
|
-
await nitro.hooks.callHook("prerender:done", {
|
|
625
|
-
prerenderedRoutes: nitro._prerenderedRoutes,
|
|
626
|
-
failedRoutes: [...failedRoutes]
|
|
627
|
-
});
|
|
628
|
-
if (nitro.options.prerender.failOnError && failedRoutes.size > 0) {
|
|
629
|
-
nitro.logger.log("\nErrors prerendering:");
|
|
630
|
-
for (const route of failedRoutes) {
|
|
631
|
-
const parents = linkParents.get(route.route);
|
|
632
|
-
parents?.size ? `
|
|
633
|
-
${[...parents.values()].map((link) => colors.gray(` \u2502 \u2514\u2500\u2500 Linked from ${link}`)).join("\n")}` : "";
|
|
634
|
-
nitro.logger.log(formatPrerenderRoute(route));
|
|
635
|
-
}
|
|
636
|
-
nitro.logger.log("");
|
|
637
|
-
throw new Error("Exiting due to prerender errors.");
|
|
638
|
-
}
|
|
639
|
-
const prerenderTimeInMs = Date.now() - prerenderStartTime;
|
|
640
|
-
nitro.logger.info(
|
|
641
|
-
`Prerendered ${nitro._prerenderedRoutes.length} routes in ${prerenderTimeInMs / 1e3} seconds`
|
|
642
|
-
);
|
|
643
|
-
if (nitro.options.compressPublicAssets) {
|
|
644
|
-
await compressPublicAssets(nitro);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
export { build as b, prerender as p, runParallel as r, writeTypes as w };
|