nitro 3.0.1-alpha.1 → 3.0.260311-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/README.md +4 -2
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +29347 -54
- package/dist/_build/rolldown.mjs +53 -86
- package/dist/_build/rollup.mjs +42 -137
- package/dist/_build/vite.build.mjs +12 -50
- package/dist/_chunks/{B-D1JOIz.mjs → nitro.mjs} +211 -407
- package/dist/_chunks/nitro2.mjs +102 -0
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +272 -0
- package/dist/{_chunks/Bqks5huO.mjs → _common.mjs} +11 -7
- package/dist/_dev.mjs +140 -326
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/c12+readdirp+chokidar.d.mts +230 -0
- package/dist/_libs/citty.mjs +141 -113
- package/dist/_libs/{plugin-commonjs.mjs → commondir+is-reference.mjs} +79 -259
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/compatx.mjs +1 -2
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +1 -2
- package/dist/_libs/estree+pluginutils.d.mts +241 -0
- package/dist/_libs/estree-walker.mjs +1 -147
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/{plugin-node-resolve.mjs → hasown+resolve+deepmerge.mjs} +612 -216
- package/dist/_libs/httpxy.d.mts +82 -0
- package/dist/_libs/httpxy.mjs +299 -38
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +1 -2
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +4 -4
- package/dist/_libs/plugin-inject.mjs +3 -7
- package/dist/_libs/plugin-json.mjs +3 -5
- package/dist/_libs/{vite-plugin-fullstack.mjs → pluginutils.mjs} +241 -156
- package/dist/_libs/{chokidar.mjs → readdirp+chokidar.mjs} +268 -223
- package/dist/_libs/remapping.mjs +2 -4
- package/dist/_libs/{gen-mapping.mjs → resolve-uri+gen-mapping.mjs} +16 -186
- package/dist/_libs/rou3.d.mts +44 -0
- package/dist/_libs/rou3.mjs +231 -54
- package/dist/_libs/std-env.d.mts +12 -0
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +20 -39
- package/dist/_libs/ultrahtml.mjs +3 -14
- package/dist/_libs/unimport+unplugin.mjs +1684 -0
- package/dist/_libs/unplugin+unimport.d.mts +423 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +475 -468
- package/dist/builder.d.mts +8 -7
- package/dist/builder.mjs +7 -25
- package/dist/cli/_chunks/build.mjs +22 -23
- package/dist/cli/_chunks/common.mjs +1 -2
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +9 -15
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +4 -6
- package/dist/cli/_chunks/prepare.mjs +2 -4
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +7 -9
- package/dist/cli/_chunks/task.mjs +1 -3
- package/dist/cli/index.mjs +5 -4
- package/dist/node_modules/@poppinss/colors/build/index.js +130 -160
- package/dist/node_modules/@poppinss/colors/package.json +20 -18
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
- package/dist/node_modules/@poppinss/dumper/package.json +1 -1
- package/dist/node_modules/@poppinss/exception/build/index.js +36 -55
- package/dist/node_modules/@poppinss/exception/package.json +19 -16
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +46 -5
- package/dist/node_modules/@sindresorhus/is/package.json +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
- package/dist/node_modules/@speed-highlight/core/package.json +2 -2
- package/dist/node_modules/croner/dist/croner.js +1 -1
- package/dist/node_modules/croner/package.json +11 -1
- package/dist/node_modules/ufo/dist/index.mjs +16 -9
- package/dist/node_modules/ufo/package.json +15 -14
- package/dist/node_modules/unctx/package.json +16 -16
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +204 -352
- package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
- package/dist/node_modules/youch/build/public/error_info/style.css +1 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +2 -3
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +34 -31
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +13 -61
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +2 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +2 -3
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +11 -11
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +1 -1
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/bun/runtime/bun.mjs +11 -11
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +19 -17
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +17 -16
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +8 -9
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +12 -18
- package/dist/presets/deno/runtime/deno-deploy.mjs +4 -5
- package/dist/presets/deno/runtime/deno-server.mjs +9 -9
- package/dist/presets/netlify/runtime/netlify-edge.mjs +3 -3
- package/dist/presets/netlify/runtime/netlify.mjs +3 -1
- package/dist/presets/node/runtime/node-cluster.mjs +8 -8
- package/dist/presets/node/runtime/node-middleware.mjs +4 -5
- package/dist/presets/node/runtime/node-server.mjs +8 -8
- package/dist/presets/standard/runtime/server.mjs +1 -1
- package/dist/presets/stormkit/runtime/stormkit.mjs +1 -2
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +16 -7
- package/dist/presets/vercel/runtime/vercel.web.mjs +14 -11
- package/dist/presets/winterjs/runtime/winterjs.mjs +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +1 -1
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/app.d.mts +1 -1
- package/dist/runtime/app.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +7 -3
- package/dist/runtime/internal/app.mjs +29 -22
- package/dist/runtime/internal/cache.d.mts +0 -4
- package/dist/runtime/internal/cache.mjs +32 -256
- package/dist/runtime/internal/context.d.mts +3 -1
- package/dist/runtime/internal/database.mjs +1 -1
- package/dist/runtime/internal/error/dev.d.mts +5 -5
- package/dist/runtime/internal/error/dev.mjs +39 -41
- package/dist/runtime/internal/error/hooks.d.mts +1 -1
- package/dist/runtime/internal/error/prod.d.mts +2 -5
- package/dist/runtime/internal/error/prod.mjs +19 -33
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/route-rules.d.mts +9 -8
- package/dist/runtime/internal/route-rules.mjs +9 -1
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
- package/dist/runtime/internal/routes/dev-tasks.mjs +7 -3
- package/dist/runtime/internal/routes/openapi.d.mts +0 -1
- package/dist/runtime/internal/routes/openapi.mjs +3 -3
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +1 -1
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +0 -1
- package/dist/runtime/internal/routes/scalar.mjs +4 -4
- package/dist/runtime/internal/routes/swagger.d.mts +0 -1
- package/dist/runtime/internal/routes/swagger.mjs +3 -3
- package/dist/runtime/internal/runtime-config.d.mts +1 -1
- package/dist/runtime/internal/runtime-config.mjs +8 -8
- package/dist/runtime/internal/static.mjs +6 -5
- package/dist/runtime/internal/storage.mjs +1 -1
- package/dist/runtime/internal/task.d.mts +3 -1
- package/dist/runtime/internal/task.mjs +3 -3
- package/dist/runtime/internal/vite/dev-entry.mjs +8 -6
- package/dist/runtime/internal/vite/dev-worker.mjs +166 -216
- package/dist/runtime/meta.d.mts +1 -1
- package/dist/runtime/meta.mjs +2 -1
- package/dist/runtime/nitro.d.mts +2 -3
- package/dist/runtime/nitro.mjs +3 -1
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/{presets/_nitro/runtime/nitro-prerenderer.d.mts → runtime/virtual/polyfills.d.mts} +1 -1
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +7 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/runtime/{vite-runtime.d.mts → vite.d.mts} +1 -1
- package/dist/types/index.d.mts +315 -443
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +10 -15
- package/dist/vite.mjs +733 -37
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +129 -85
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
- package/dist/_build/common2.mjs +0 -772
- package/dist/_build/vite.plugin.mjs +0 -768
- package/dist/_chunks/ANM1K1bE.mjs +0 -304
- package/dist/_chunks/BX9-zVkM.mjs +0 -59
- package/dist/_chunks/C7CbzoI1.mjs +0 -39
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/c12.mjs +0 -2858
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/confbox.mjs +0 -2920
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/giget.mjs +0 -19289
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -32
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -1686
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/node-fetch-native.mjs +0 -173
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -41
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/plugin-replace.mjs +0 -104
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/unimport.mjs +0 -3520
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5836
- package/dist/cli/_chunks/detect-acorn.mjs +0 -12
- package/dist/cli/_chunks/dist.mjs +0 -3
- package/dist/cli/_chunks/dist2.mjs +0 -3
- package/dist/cli/_chunks/dist3.mjs +0 -3
- package/dist/cli/_chunks/dist4.mjs +0 -4
- package/dist/cli/_chunks/dist5.mjs +0 -4
- package/dist/cli/_chunks/esm.mjs +0 -3
- package/dist/cli/_chunks/json5.mjs +0 -4
- package/dist/cli/_chunks/jsonc.mjs +0 -4
- package/dist/cli/_chunks/multipart-parser.mjs +0 -6
- package/dist/cli/_chunks/toml.mjs +0 -4
- package/dist/cli/_chunks/yaml.mjs +0 -4
- package/dist/node_modules/hookable/dist/index.mjs +0 -267
- package/dist/node_modules/hookable/package.json +0 -52
- package/dist/node_modules/kleur/index.js +0 -110
- package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
- package/dist/node_modules/youch/build/chunk-4XB2BYKC.js +0 -85
- package/dist/node_modules/youch/build/chunk-4YEN7HVQ.js +0 -61
- package/dist/node_modules/youch/build/chunk-EUJBVOYB.js +0 -83
- package/dist/node_modules/youch/build/chunk-F4I6KX4R.js +0 -46
- package/dist/node_modules/youch/build/chunk-HFSXRSKS.js +0 -85
- package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +0 -6
- package/dist/node_modules/youch/build/chunk-PINJDICN.js +0 -72
- package/dist/node_modules/youch/build/chunk-PUHGL6HA.js +0 -41
- package/dist/node_modules/youch/build/chunk-YYEJ3AGB.js +0 -225
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
- package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -13
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
- package/dist/presets/azure/runtime/_utils.d.mts +0 -2
- package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
- package/dist/presets/bun/runtime/bun.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
- package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -4
- package/dist/presets/netlify/runtime/netlify.d.mts +0 -3
- package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
- package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
- package/dist/presets/node/runtime/node-server.d.mts +0 -3
- package/dist/presets/standard/runtime/server.d.mts +0 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
- package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
- package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
- package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -3
- package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
- package/lib/deps/ofetch.mjs +0 -1
- package/lib/deps/ofetch.mts +0 -1
- /package/dist/runtime/{vite-runtime.mjs → vite.mjs} +0 -0
- /package/lib/{deps/h3.d.mts → h3.d.mts} +0 -0
- /package/lib/{deps/h3.mjs → h3.mjs} +0 -0
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import {
|
|
3
|
-
import { a as createUnimport } from "../_libs/unimport.mjs";
|
|
4
|
-
import { t as glob } from "../_libs/tinyglobby.mjs";
|
|
1
|
+
import { i as loadConfig, s as watchConfig } from "../_libs/c12+rc9.mjs";
|
|
2
|
+
import { A as src_default, F as prettyPath, H as v, I as resolveNitroPath, K as findWorkspaceDir, L as writeFile$1, O as scanUnprefixedPublicAssets, ct as join, dt as resolve, j as build, k as compressPublicAssets, nt as resolveModulePath, p as runParallel, rt as resolveModuleURL, ut as relative, z as _ } from "../_build/common.mjs";
|
|
5
3
|
import { n as resolveCompatibilityDates, r as resolveCompatibilityDatesFromEnv } from "../_libs/compatx.mjs";
|
|
6
4
|
import { t as klona } from "../_libs/klona.mjs";
|
|
7
|
-
import { i as d, r as a } from "../_libs/std-env.mjs";
|
|
8
5
|
import { t as escapeStringRegexp } from "../_libs/escape-string-regexp.mjs";
|
|
9
6
|
import { n as parse, t as TSConfckCache } from "../_libs/tsconfck.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { i as scanHandlers, r as scanAndSyncOptions, t as runParallel } from "./ANM1K1bE.mjs";
|
|
7
|
+
import { n as scanHandlers, t as scanAndSyncOptions } from "./nitro2.mjs";
|
|
12
8
|
import { a as findRoute, i as findAllRoutes, n as addRoute, r as createRouter, t as compileRouterToString } from "../_libs/rou3.mjs";
|
|
13
|
-
import { t as src_default } from "../_libs/mime.mjs";
|
|
14
9
|
import { n as z, t as P } from "../_libs/ultrahtml.mjs";
|
|
15
10
|
import { createRequire } from "node:module";
|
|
16
|
-
import consola
|
|
11
|
+
import consola, { consola as consola$1 } from "consola";
|
|
17
12
|
import { Hookable, createDebugger } from "hookable";
|
|
18
|
-
import { existsSync,
|
|
19
|
-
import {
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
20
15
|
import { pathToFileURL } from "node:url";
|
|
21
|
-
import fsp, { readFile } from "node:fs/promises";
|
|
22
16
|
import { defu } from "defu";
|
|
23
|
-
import {
|
|
17
|
+
import { runtimeDir, version } from "nitro/meta";
|
|
18
|
+
import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
|
|
24
19
|
import { colors } from "consola/utils";
|
|
25
|
-
import { ofetch } from "ofetch";
|
|
26
20
|
import { hash } from "ohash";
|
|
27
|
-
import zlib from "node:zlib";
|
|
28
21
|
import { toRequest } from "h3";
|
|
29
|
-
|
|
22
|
+
import http from "node:http";
|
|
30
23
|
//#region src/config/defaults.ts
|
|
31
24
|
const NitroDefaults = {
|
|
32
25
|
compatibilityDate: "latest",
|
|
33
|
-
debug:
|
|
34
|
-
logLevel:
|
|
26
|
+
debug: _,
|
|
27
|
+
logLevel: v ? 1 : 3,
|
|
35
28
|
runtimeConfig: {
|
|
36
29
|
app: {},
|
|
37
30
|
nitro: {}
|
|
@@ -58,6 +51,7 @@ const NitroDefaults = {
|
|
|
58
51
|
virtual: {},
|
|
59
52
|
compressPublicAssets: false,
|
|
60
53
|
ignore: [],
|
|
54
|
+
wasm: {},
|
|
61
55
|
dev: false,
|
|
62
56
|
devServer: { watch: [] },
|
|
63
57
|
watchOptions: { ignoreInitial: true },
|
|
@@ -88,6 +82,7 @@ const NitroDefaults = {
|
|
|
88
82
|
replace: {},
|
|
89
83
|
node: true,
|
|
90
84
|
sourcemap: false,
|
|
85
|
+
traceDeps: [],
|
|
91
86
|
typescript: {
|
|
92
87
|
strict: true,
|
|
93
88
|
generateRuntimeConfigTypes: false,
|
|
@@ -95,15 +90,13 @@ const NitroDefaults = {
|
|
|
95
90
|
tsconfigPath: "tsconfig.json",
|
|
96
91
|
tsConfig: void 0
|
|
97
92
|
},
|
|
98
|
-
nodeModulesDirs: [],
|
|
99
93
|
hooks: {},
|
|
100
94
|
commands: {},
|
|
101
95
|
framework: {
|
|
102
96
|
name: "nitro",
|
|
103
|
-
version
|
|
97
|
+
version
|
|
104
98
|
}
|
|
105
99
|
};
|
|
106
|
-
|
|
107
100
|
//#endregion
|
|
108
101
|
//#region src/config/resolvers/assets.ts
|
|
109
102
|
async function resolveAssetsOptions(options) {
|
|
@@ -131,17 +124,16 @@ async function resolveAssetsOptions(options) {
|
|
|
131
124
|
if (asset.maxAge && !asset.fallthrough) options.routeRules[asset.baseURL + "/**"] = defu(routeRule, { headers: { "cache-control": `public, max-age=${asset.maxAge}, immutable` } });
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
|
-
|
|
135
127
|
//#endregion
|
|
136
128
|
//#region src/config/resolvers/compatibility.ts
|
|
137
129
|
async function resolveCompatibilityOptions(options) {
|
|
138
130
|
options.compatibilityDate = resolveCompatibilityDatesFromEnv(options.compatibilityDate);
|
|
139
131
|
}
|
|
140
|
-
|
|
141
132
|
//#endregion
|
|
142
133
|
//#region src/config/resolvers/database.ts
|
|
143
134
|
async function resolveDatabaseOptions(options) {
|
|
144
135
|
if (options.experimental.database && options.imports) {
|
|
136
|
+
options.imports.presets ??= [];
|
|
145
137
|
options.imports.presets.push({
|
|
146
138
|
from: "nitro/database",
|
|
147
139
|
imports: ["useDatabase"]
|
|
@@ -156,29 +148,23 @@ async function resolveDatabaseOptions(options) {
|
|
|
156
148
|
} };
|
|
157
149
|
}
|
|
158
150
|
}
|
|
159
|
-
|
|
160
151
|
//#endregion
|
|
161
152
|
//#region src/config/resolvers/export-conditions.ts
|
|
162
153
|
async function resolveExportConditionsOptions(options) {
|
|
163
154
|
options.exportConditions = _resolveExportConditions(options.exportConditions || [], {
|
|
164
155
|
dev: options.dev,
|
|
165
156
|
node: options.node,
|
|
166
|
-
wasm: options.
|
|
157
|
+
wasm: options.wasm !== false
|
|
167
158
|
});
|
|
168
159
|
}
|
|
169
|
-
function _resolveExportConditions(
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (opts.node)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
resolvedConditions.push("import", "default");
|
|
177
|
-
if ("Bun" in globalThis) resolvedConditions.push("bun");
|
|
178
|
-
else if ("Deno" in globalThis) resolvedConditions.push("deno");
|
|
179
|
-
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
|
|
160
|
+
function _resolveExportConditions(userConditions, opts) {
|
|
161
|
+
const conditions = [...userConditions.filter((c) => !c.startsWith("!"))];
|
|
162
|
+
conditions.push(opts.dev ? "development" : "production");
|
|
163
|
+
if (opts.wasm) conditions.push("wasm", "unwasm");
|
|
164
|
+
if (opts.node) conditions.push("node");
|
|
165
|
+
const negated = new Set(userConditions.filter((c) => c.startsWith("!")).map((c) => c.slice(1)));
|
|
166
|
+
return [...new Set(conditions)].filter((c) => !negated.has(c));
|
|
180
167
|
}
|
|
181
|
-
|
|
182
168
|
//#endregion
|
|
183
169
|
//#region src/config/resolvers/imports.ts
|
|
184
170
|
async function resolveImportsOptions(options) {
|
|
@@ -190,10 +176,9 @@ async function resolveImportsOptions(options) {
|
|
|
190
176
|
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
191
177
|
options.imports.exclude.push(options.buildDir);
|
|
192
178
|
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
193
|
-
options.imports.exclude.push(scanDirsInNodeModules.length > 0 ?
|
|
179
|
+
options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeStringRegexp(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
|
|
194
180
|
}
|
|
195
181
|
}
|
|
196
|
-
|
|
197
182
|
//#endregion
|
|
198
183
|
//#region src/config/resolvers/open-api.ts
|
|
199
184
|
async function resolveOpenAPIOptions(options) {
|
|
@@ -233,13 +218,12 @@ async function resolveOpenAPIOptions(options) {
|
|
|
233
218
|
options.prerender.routes.push(...prerenderRoutes);
|
|
234
219
|
}
|
|
235
220
|
}
|
|
236
|
-
|
|
237
221
|
//#endregion
|
|
238
222
|
//#region src/config/resolvers/tsconfig.ts
|
|
239
223
|
async function resolveTsconfig(options) {
|
|
240
224
|
const root = resolve(options.rootDir || ".") + "/";
|
|
241
225
|
if (!options.typescript.tsConfig) options.typescript.tsConfig = await loadTsconfig(root);
|
|
242
|
-
if (options.experimental.tsconfigPaths
|
|
226
|
+
if (options.experimental.tsconfigPaths && options.typescript.tsConfig.compilerOptions?.paths) options.alias = {
|
|
243
227
|
...tsConfigToAliasObj(options.typescript.tsConfig, root),
|
|
244
228
|
...options.alias
|
|
245
229
|
};
|
|
@@ -250,8 +234,7 @@ async function loadTsconfig(root) {
|
|
|
250
234
|
cache: loadTsconfig["__cache"] ??= new TSConfckCache(),
|
|
251
235
|
ignoreNodeModules: true
|
|
252
236
|
};
|
|
253
|
-
const
|
|
254
|
-
const parsed = await parse(tsConfigPath, opts).catch(() => void 0);
|
|
237
|
+
const parsed = await parse(join(root, "tsconfig.json"), opts).catch(() => void 0);
|
|
255
238
|
if (!parsed) return {};
|
|
256
239
|
const { tsconfig, tsconfigFile } = parsed;
|
|
257
240
|
tsconfig.compilerOptions ??= {};
|
|
@@ -280,7 +263,6 @@ function tsConfigToAliasObj(tsconfig, root) {
|
|
|
280
263
|
}
|
|
281
264
|
return alias;
|
|
282
265
|
}
|
|
283
|
-
|
|
284
266
|
//#endregion
|
|
285
267
|
//#region src/config/resolvers/paths.ts
|
|
286
268
|
const RESOLVE_EXTENSIONS = [
|
|
@@ -297,7 +279,7 @@ async function resolvePathOptions(options) {
|
|
|
297
279
|
options.workspaceDir ||= await findWorkspaceDir(options.rootDir).catch(() => options.rootDir) + "/";
|
|
298
280
|
if (options.srcDir) {
|
|
299
281
|
if (options.serverDir === void 0) options.serverDir = options.srcDir;
|
|
300
|
-
consola
|
|
282
|
+
consola.warn(`"srcDir" option is deprecated. Please use "serverDir" instead.`);
|
|
301
283
|
}
|
|
302
284
|
if (options.serverDir !== false) {
|
|
303
285
|
if (options.serverDir === true) options.serverDir = "server";
|
|
@@ -309,12 +291,6 @@ async function resolvePathOptions(options) {
|
|
|
309
291
|
options.output.dir = resolveNitroPath(options.output.dir || NitroDefaults.output.dir, options, options.rootDir) + "/";
|
|
310
292
|
options.output.publicDir = resolveNitroPath(options.output.publicDir || NitroDefaults.output.publicDir, options, options.rootDir) + "/";
|
|
311
293
|
options.output.serverDir = resolveNitroPath(options.output.serverDir || NitroDefaults.output.serverDir, options, options.rootDir) + "/";
|
|
312
|
-
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
313
|
-
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
314
|
-
options.nodeModulesDirs.push(resolve(pkgDir, "dist/node_modules"));
|
|
315
|
-
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
316
|
-
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
317
|
-
options.nodeModulesDirs = [...new Set(options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir) + "/"))];
|
|
318
294
|
options.plugins = options.plugins.map((p) => resolveNitroPath(p, options));
|
|
319
295
|
if (options.serverDir) options.scanDirs.unshift(options.serverDir);
|
|
320
296
|
options.scanDirs = options.scanDirs.map((dir) => resolve(options.rootDir, dir));
|
|
@@ -330,45 +306,54 @@ async function resolvePathOptions(options) {
|
|
|
330
306
|
h.handler = resolveNitroPath(h.handler, options);
|
|
331
307
|
return [route, h];
|
|
332
308
|
}));
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
309
|
+
if (options.serverEntry !== false) {
|
|
310
|
+
if (typeof options?.serverEntry === "string") options.serverEntry = { handler: options.serverEntry };
|
|
311
|
+
if (options.serverEntry?.handler) options.serverEntry.handler = resolveNitroPath(options.serverEntry.handler, options);
|
|
312
|
+
else {
|
|
313
|
+
const detected = resolveModulePath("./server", {
|
|
314
|
+
try: true,
|
|
315
|
+
from: options.rootDir,
|
|
316
|
+
extensions: RESOLVE_EXTENSIONS.flatMap((ext) => [ext, `.node${ext}`])
|
|
317
|
+
});
|
|
318
|
+
if (detected) {
|
|
319
|
+
options.serverEntry ??= { handler: "" };
|
|
320
|
+
options.serverEntry.handler = detected;
|
|
321
|
+
consola.info(`Detected \`${prettyPath(detected)}\` as server entry.`);
|
|
343
322
|
}
|
|
344
323
|
}
|
|
324
|
+
if (options.serverEntry?.handler && !options.serverEntry?.format) {
|
|
325
|
+
const isNode = /\.(node)\.\w+$/.test(options.serverEntry.handler);
|
|
326
|
+
options.serverEntry.format = isNode ? "node" : "web";
|
|
327
|
+
}
|
|
345
328
|
}
|
|
346
|
-
if (options.renderer
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
else if (!options.renderer?.handler) {
|
|
355
|
-
const defaultIndex = resolveModulePath("./index.html", {
|
|
329
|
+
if (options.renderer === false) options.renderer = void 0;
|
|
330
|
+
else {
|
|
331
|
+
if (options.renderer?.handler) options.renderer.handler = resolveModulePath(resolveNitroPath(options.renderer?.handler, options), {
|
|
332
|
+
from: [options.rootDir, ...options.scanDirs],
|
|
333
|
+
extensions: RESOLVE_EXTENSIONS
|
|
334
|
+
});
|
|
335
|
+
if (options.renderer?.template) options.renderer.template = resolveModulePath(resolveNitroPath(options.renderer?.template, options), {
|
|
356
336
|
from: [options.rootDir, ...options.scanDirs],
|
|
357
|
-
extensions: [".html"]
|
|
358
|
-
try: true
|
|
337
|
+
extensions: [".html"]
|
|
359
338
|
});
|
|
360
|
-
if (
|
|
339
|
+
else if (!options.renderer?.handler) {
|
|
340
|
+
const defaultIndex = resolveModulePath("./index.html", {
|
|
341
|
+
from: [options.rootDir, ...options.scanDirs],
|
|
342
|
+
extensions: [".html"],
|
|
343
|
+
try: true
|
|
344
|
+
});
|
|
345
|
+
if (defaultIndex) {
|
|
346
|
+
options.renderer ??= {};
|
|
347
|
+
options.renderer.template = defaultIndex;
|
|
348
|
+
consola.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (options.renderer?.template && !options.renderer?.handler) {
|
|
361
352
|
options.renderer ??= {};
|
|
362
|
-
options.renderer.
|
|
363
|
-
consola$1.info(`Using \`${prettyPath(defaultIndex)}\` as renderer template.`);
|
|
353
|
+
options.renderer.handler = join(runtimeDir, "internal/routes/renderer-template" + (options.dev ? ".dev" : ""));
|
|
364
354
|
}
|
|
365
355
|
}
|
|
366
|
-
if (options.renderer?.template && !options.renderer?.handler) {
|
|
367
|
-
options.renderer ??= {};
|
|
368
|
-
options.renderer.handler = join(runtimeDir, "internal/routes/renderer-template" + (options.dev ? ".dev" : ""));
|
|
369
|
-
}
|
|
370
356
|
}
|
|
371
|
-
|
|
372
357
|
//#endregion
|
|
373
358
|
//#region src/config/resolvers/route-rules.ts
|
|
374
359
|
async function resolveRouteRulesOptions(options) {
|
|
@@ -413,7 +398,6 @@ function normalizeRouteRules(config) {
|
|
|
413
398
|
}
|
|
414
399
|
return normalizedRules;
|
|
415
400
|
}
|
|
416
|
-
|
|
417
401
|
//#endregion
|
|
418
402
|
//#region src/config/resolvers/runtime-config.ts
|
|
419
403
|
async function resolveRuntimeConfigOptions(options) {
|
|
@@ -428,6 +412,7 @@ function normalizeRuntimeConfig(config) {
|
|
|
428
412
|
openAPI: config.openAPI
|
|
429
413
|
}
|
|
430
414
|
});
|
|
415
|
+
runtimeConfig.nitro ??= {};
|
|
431
416
|
runtimeConfig.nitro.routeRules = config.routeRules;
|
|
432
417
|
checkSerializableRuntimeConfig(runtimeConfig);
|
|
433
418
|
return runtimeConfig;
|
|
@@ -449,17 +434,14 @@ function checkSerializableRuntimeConfig(obj, path = []) {
|
|
|
449
434
|
function isPrimitiveValue(value) {
|
|
450
435
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
451
436
|
}
|
|
452
|
-
|
|
453
437
|
//#endregion
|
|
454
438
|
//#region src/config/resolvers/storage.ts
|
|
455
439
|
async function resolveStorageOptions(options) {}
|
|
456
|
-
|
|
457
440
|
//#endregion
|
|
458
441
|
//#region src/config/resolvers/url.ts
|
|
459
442
|
async function resolveURLOptions(options) {
|
|
460
443
|
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
461
444
|
}
|
|
462
|
-
|
|
463
445
|
//#endregion
|
|
464
446
|
//#region src/config/resolvers/error.ts
|
|
465
447
|
async function resolveErrorOptions(options) {
|
|
@@ -468,7 +450,6 @@ async function resolveErrorOptions(options) {
|
|
|
468
450
|
options.errorHandler = options.errorHandler.map((h) => resolveNitroPath(h, options));
|
|
469
451
|
options.errorHandler.push(join(runtimeDir, `internal/error/${options.dev ? "dev" : "prod"}`));
|
|
470
452
|
}
|
|
471
|
-
|
|
472
453
|
//#endregion
|
|
473
454
|
//#region src/config/resolvers/unenv.ts
|
|
474
455
|
const common = {
|
|
@@ -513,22 +494,20 @@ async function resolveUnenv(options) {
|
|
|
513
494
|
if (!options.node) options.unenv.unshift(nodeless);
|
|
514
495
|
options.unenv.unshift(common);
|
|
515
496
|
}
|
|
516
|
-
|
|
517
497
|
//#endregion
|
|
518
498
|
//#region src/config/resolvers/builder.ts
|
|
519
499
|
const VALID_BUILDERS = [
|
|
520
|
-
"rollup",
|
|
521
500
|
"rolldown",
|
|
522
|
-
"
|
|
523
|
-
"
|
|
501
|
+
"rollup",
|
|
502
|
+
"vite"
|
|
524
503
|
];
|
|
525
504
|
async function resolveBuilder(options) {
|
|
526
505
|
options.builder ??= process.env.NITRO_BUILDER;
|
|
527
506
|
if (options.builder) {
|
|
528
507
|
if (!VALID_BUILDERS.includes(options.builder)) throw new Error(`Invalid nitro builder "${options.builder}". Valid builders are: ${VALID_BUILDERS.join(", ")}.`);
|
|
529
|
-
const pkg = options.builder
|
|
530
|
-
if (!isPkgInstalled(pkg, options.rootDir)) {
|
|
531
|
-
if (!await consola
|
|
508
|
+
const pkg = options.builder;
|
|
509
|
+
if (pkg !== "rolldown" && !isPkgInstalled(pkg, options.rootDir)) {
|
|
510
|
+
if (!await consola.prompt(`Nitro builder package \`${pkg}\` is not installed. Would you like to install it?`, {
|
|
532
511
|
type: "confirm",
|
|
533
512
|
default: true,
|
|
534
513
|
cancel: "null"
|
|
@@ -537,40 +516,39 @@ async function resolveBuilder(options) {
|
|
|
537
516
|
}
|
|
538
517
|
return;
|
|
539
518
|
}
|
|
540
|
-
|
|
541
|
-
"
|
|
542
|
-
"rollup",
|
|
543
|
-
"vite"
|
|
544
|
-
]) if (isPkgInstalled(pkg, options.rootDir)) {
|
|
545
|
-
options.builder = pkg;
|
|
519
|
+
if (isPkgInstalled("vite", options.rootDir) && hasNitroViteConfig(options)) {
|
|
520
|
+
options.builder = "vite";
|
|
546
521
|
return;
|
|
547
522
|
}
|
|
548
|
-
|
|
549
|
-
type: "select",
|
|
550
|
-
cancel: "null",
|
|
551
|
-
options: VALID_BUILDERS.map((b) => ({
|
|
552
|
-
label: b,
|
|
553
|
-
value: b
|
|
554
|
-
}))
|
|
555
|
-
});
|
|
556
|
-
if (!pkgToInstall) throw new Error(`No nitro builder specified. Please install one of the following packages: ${VALID_BUILDERS.join(", ")} and set it as the builder in your nitro config or via the NITRO_BUILDER environment variable.`);
|
|
557
|
-
await installPkg(pkgToInstall, options.rootDir);
|
|
558
|
-
options.builder = pkgToInstall;
|
|
523
|
+
options.builder = "rolldown";
|
|
559
524
|
}
|
|
560
|
-
const
|
|
525
|
+
const _require = createRequire(import.meta.url);
|
|
561
526
|
function isPkgInstalled(pkg, root) {
|
|
562
527
|
try {
|
|
563
|
-
|
|
528
|
+
_require.resolve(pkg, { paths: [root] });
|
|
564
529
|
return true;
|
|
565
530
|
} catch {
|
|
566
531
|
return false;
|
|
567
532
|
}
|
|
568
533
|
}
|
|
569
534
|
async function installPkg(pkg, root) {
|
|
570
|
-
const { addDevDependency } = await import("../
|
|
571
|
-
return addDevDependency(pkg
|
|
535
|
+
const { addDevDependency } = await import("../_libs/_5.mjs");
|
|
536
|
+
return addDevDependency(pkg, { cwd: root });
|
|
537
|
+
}
|
|
538
|
+
function hasNitroViteConfig(options) {
|
|
539
|
+
for (const ext of [
|
|
540
|
+
".ts",
|
|
541
|
+
".mts",
|
|
542
|
+
".js",
|
|
543
|
+
".mjs"
|
|
544
|
+
]) {
|
|
545
|
+
const configPath = resolve(options.rootDir, `vite.config${ext}`);
|
|
546
|
+
if (existsSync(configPath)) try {
|
|
547
|
+
if (readFileSync(configPath, "utf8").includes("nitro(")) return true;
|
|
548
|
+
} catch {}
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
572
551
|
}
|
|
573
|
-
|
|
574
552
|
//#endregion
|
|
575
553
|
//#region src/config/loader.ts
|
|
576
554
|
const configResolvers = [
|
|
@@ -602,16 +580,14 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
602
580
|
const { resolvePreset } = await import("../_presets.mjs");
|
|
603
581
|
let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
|
|
604
582
|
const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
|
|
583
|
+
const envName = opts.c12?.envName ?? (configOverrides.dev ? "development" : "production");
|
|
605
584
|
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
606
585
|
name: "nitro",
|
|
607
586
|
cwd: configOverrides.rootDir,
|
|
608
587
|
dotenv: _dotenv,
|
|
588
|
+
envName,
|
|
609
589
|
extend: { extendKey: ["extends", "preset"] },
|
|
610
590
|
defaults: NitroDefaults,
|
|
611
|
-
jitiOptions: { alias: {
|
|
612
|
-
nitropack: "nitro/config",
|
|
613
|
-
"nitro/config": "nitro/config"
|
|
614
|
-
} },
|
|
615
591
|
async overrides({ rawConfigs }) {
|
|
616
592
|
const getConf = (key) => configOverrides[key] ?? rawConfigs.main?.[key] ?? rawConfigs.rc?.[key] ?? rawConfigs.packageJson?.[key];
|
|
617
593
|
if (!compatibilityDate) compatibilityDate = getConf("compatibilityDate");
|
|
@@ -639,12 +615,12 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
639
615
|
};
|
|
640
616
|
},
|
|
641
617
|
async resolve(id) {
|
|
642
|
-
const preset
|
|
618
|
+
const preset = await resolvePreset(id, {
|
|
643
619
|
static: configOverrides.static,
|
|
644
620
|
compatibilityDate: compatibilityDate || "latest",
|
|
645
621
|
dev: configOverrides.dev
|
|
646
622
|
});
|
|
647
|
-
if (preset
|
|
623
|
+
if (preset) return { config: klona(preset) };
|
|
648
624
|
},
|
|
649
625
|
...opts.c12
|
|
650
626
|
});
|
|
@@ -653,19 +629,17 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
653
629
|
options._c12 = loadedConfig;
|
|
654
630
|
options.preset = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || preset;
|
|
655
631
|
options.compatibilityDate = resolveCompatibilityDates(compatibilityDate, options.compatibilityDate);
|
|
656
|
-
if (options.dev && options.preset !== "nitro-dev") consola
|
|
632
|
+
if (options.dev && options.preset !== "nitro-dev") consola.info(`Using \`${options.preset}\` emulation in development mode.`);
|
|
657
633
|
return options;
|
|
658
634
|
}
|
|
659
|
-
|
|
660
635
|
//#endregion
|
|
661
636
|
//#region src/config/update.ts
|
|
662
637
|
async function updateNitroConfig(nitro, config) {
|
|
663
638
|
nitro.options.routeRules = normalizeRouteRules(config.routeRules ? config : nitro.options);
|
|
664
639
|
nitro.options.runtimeConfig = normalizeRuntimeConfig(config.runtimeConfig ? config : nitro.options);
|
|
665
640
|
await nitro.hooks.callHook("rollup:reload");
|
|
666
|
-
consola
|
|
641
|
+
consola.success("Nitro config hot reloaded!");
|
|
667
642
|
}
|
|
668
|
-
|
|
669
643
|
//#endregion
|
|
670
644
|
//#region src/module.ts
|
|
671
645
|
async function installModules(nitro) {
|
|
@@ -682,17 +656,20 @@ async function installModules(nitro) {
|
|
|
682
656
|
}
|
|
683
657
|
async function _resolveNitroModule(mod, nitroOptions) {
|
|
684
658
|
let _url;
|
|
685
|
-
if (typeof mod === "string")
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
659
|
+
if (typeof mod === "string") {
|
|
660
|
+
_url = resolveModuleURL(mod, {
|
|
661
|
+
from: [nitroOptions.rootDir],
|
|
662
|
+
extensions: [
|
|
663
|
+
".mjs",
|
|
664
|
+
".cjs",
|
|
665
|
+
".js",
|
|
666
|
+
".mts",
|
|
667
|
+
".cts",
|
|
668
|
+
".ts"
|
|
669
|
+
]
|
|
670
|
+
});
|
|
671
|
+
mod = await import(_url).then((m) => m.default || m);
|
|
672
|
+
}
|
|
696
673
|
if (typeof mod === "function") mod = { setup: mod };
|
|
697
674
|
if ("nitro" in mod) mod = mod.nitro;
|
|
698
675
|
if (!mod.setup) throw new Error("Invalid Nitro module: missing setup() function.");
|
|
@@ -701,72 +678,6 @@ async function _resolveNitroModule(mod, nitroOptions) {
|
|
|
701
678
|
...mod
|
|
702
679
|
};
|
|
703
680
|
}
|
|
704
|
-
|
|
705
|
-
//#endregion
|
|
706
|
-
//#region src/task.ts
|
|
707
|
-
/** @experimental */
|
|
708
|
-
async function runTask(taskEvent, opts) {
|
|
709
|
-
return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
|
|
710
|
-
method: "POST",
|
|
711
|
-
body: taskEvent
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
/** @experimental */
|
|
715
|
-
async function listTasks(opts) {
|
|
716
|
-
return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
|
|
717
|
-
}
|
|
718
|
-
function addNitroTasksVirtualFile(nitro) {
|
|
719
|
-
nitro.options.virtual["#nitro-internal-virtual/tasks"] = () => {
|
|
720
|
-
const _scheduledTasks = Object.entries(nitro.options.scheduledTasks || {}).map(([cron, _tasks]) => {
|
|
721
|
-
return {
|
|
722
|
-
cron,
|
|
723
|
-
tasks: (Array.isArray(_tasks) ? _tasks : [_tasks]).filter((name) => {
|
|
724
|
-
if (!nitro.options.tasks[name]) {
|
|
725
|
-
nitro.logger.warn(`Scheduled task \`${name}\` is not defined!`);
|
|
726
|
-
return false;
|
|
727
|
-
}
|
|
728
|
-
return true;
|
|
729
|
-
})
|
|
730
|
-
};
|
|
731
|
-
}).filter((e) => e.tasks.length > 0);
|
|
732
|
-
const scheduledTasks = _scheduledTasks.length > 0 ? _scheduledTasks : false;
|
|
733
|
-
return `
|
|
734
|
-
export const scheduledTasks = ${JSON.stringify(scheduledTasks)};
|
|
735
|
-
|
|
736
|
-
export const tasks = {
|
|
737
|
-
${Object.entries(nitro.options.tasks).map(([name, task]) => `"${name}": {
|
|
738
|
-
meta: {
|
|
739
|
-
description: ${JSON.stringify(task.description)},
|
|
740
|
-
},
|
|
741
|
-
resolve: ${task.handler ? `() => import("${normalize(task.handler)}").then(r => r.default || r)` : "undefined"},
|
|
742
|
-
}`).join(",\n")}
|
|
743
|
-
};`;
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
const _devHint = `(is dev server running?)`;
|
|
747
|
-
async function _getTasksContext(opts) {
|
|
748
|
-
const buildInfoPath = resolve(resolve(resolve(process.cwd(), opts?.cwd || "."), opts?.buildDir || "node_modules/.nitro"), "nitro.dev.json");
|
|
749
|
-
if (!existsSync(buildInfoPath)) throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
|
|
750
|
-
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
751
|
-
if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) throw new Error(`Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`);
|
|
752
|
-
if (!_pidIsRunning(buildInfo.dev.pid)) throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
|
|
753
|
-
return {
|
|
754
|
-
buildInfo,
|
|
755
|
-
devFetch: ofetch.create({
|
|
756
|
-
baseURL: `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`,
|
|
757
|
-
socketPath: buildInfo.dev.workerAddress.socketPath
|
|
758
|
-
})
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
function _pidIsRunning(pid) {
|
|
762
|
-
try {
|
|
763
|
-
process.kill(pid, 0);
|
|
764
|
-
return true;
|
|
765
|
-
} catch {
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
681
|
//#endregion
|
|
771
682
|
//#region src/routing.ts
|
|
772
683
|
const isGlobalMiddleware = (h) => !h.method && (!h.route || h.route === "/**");
|
|
@@ -805,6 +716,12 @@ function initNitroRouting(nitro) {
|
|
|
805
716
|
...nitro.options.handlers,
|
|
806
717
|
...nitro.scannedHandlers
|
|
807
718
|
].filter((h) => h && !h.middleware && matchesEnv(h));
|
|
719
|
+
if (nitro.options.serverEntry && nitro.options.serverEntry.handler) _routes.push({
|
|
720
|
+
route: "/**",
|
|
721
|
+
lazy: false,
|
|
722
|
+
format: nitro.options.serverEntry.format,
|
|
723
|
+
handler: nitro.options.serverEntry.handler
|
|
724
|
+
});
|
|
808
725
|
if (nitro.options.renderer?.handler) _routes.push({
|
|
809
726
|
route: "/**",
|
|
810
727
|
lazy: true,
|
|
@@ -867,10 +784,17 @@ var Router = class {
|
|
|
867
784
|
return this._routes.length > 0;
|
|
868
785
|
}
|
|
869
786
|
compileToString(opts) {
|
|
870
|
-
|
|
871
|
-
this._compiled
|
|
872
|
-
if (this.
|
|
873
|
-
|
|
787
|
+
const key = opts ? hash(opts) : "";
|
|
788
|
+
this._compiled ||= {};
|
|
789
|
+
if (this._compiled[key]) return this._compiled[key];
|
|
790
|
+
this._compiled[key] = compileRouterToString(this._router, void 0, opts);
|
|
791
|
+
if (this.routes.length === 1 && this.routes[0].route === "/**" && this.routes[0].method === "") {
|
|
792
|
+
const data = (opts?.serialize || JSON.stringify)(this.routes[0].data);
|
|
793
|
+
let retCode = `{data,params:{"_":p.slice(1)}}`;
|
|
794
|
+
if (opts?.matchAll) retCode = `[${retCode}]`;
|
|
795
|
+
this._compiled[key] = `/* @__PURE__ */ (() => {const data=${data};return ((_m, p)=>{return ${retCode};})})()`;
|
|
796
|
+
}
|
|
797
|
+
return this._compiled[key];
|
|
874
798
|
}
|
|
875
799
|
match(method, path) {
|
|
876
800
|
return findRoute(this._router, method, path)?.data;
|
|
@@ -887,7 +811,6 @@ function mergeCatchAll(router) {
|
|
|
887
811
|
data: handlers.map((h) => h.data)
|
|
888
812
|
});
|
|
889
813
|
}
|
|
890
|
-
|
|
891
814
|
//#endregion
|
|
892
815
|
//#region src/global.ts
|
|
893
816
|
const nitroInstances = globalThis.__nitro_instances__ ||= [];
|
|
@@ -904,29 +827,28 @@ function registerNitroInstance(nitro) {
|
|
|
904
827
|
function globalInit() {
|
|
905
828
|
if (globalThis[globalKey]) return;
|
|
906
829
|
globalThis[globalKey] = { async fetch(req) {
|
|
907
|
-
for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve
|
|
830
|
+
for (let r = 0; r < 10 && nitroInstances.length === 0; r++) await new Promise((resolve) => setTimeout(resolve, 300));
|
|
908
831
|
const nitro = nitroInstances[0];
|
|
909
832
|
if (!nitro) throw new Error("No Nitro instance is running.");
|
|
910
833
|
return nitro.fetch(req);
|
|
911
834
|
} };
|
|
912
835
|
}
|
|
913
|
-
|
|
914
836
|
//#endregion
|
|
915
837
|
//#region src/nitro.ts
|
|
916
838
|
async function createNitro(config = {}, opts = {}) {
|
|
917
839
|
const nitro = {
|
|
918
840
|
options: await loadOptions(config, opts),
|
|
919
841
|
hooks: new Hookable(),
|
|
920
|
-
vfs:
|
|
842
|
+
vfs: /* @__PURE__ */ new Map(),
|
|
921
843
|
routing: {},
|
|
922
|
-
logger: consola.withTag("nitro"),
|
|
844
|
+
logger: consola$1.withTag("nitro"),
|
|
923
845
|
scannedHandlers: [],
|
|
924
846
|
fetch: () => {
|
|
925
847
|
throw new Error("no dev server attached!");
|
|
926
848
|
},
|
|
927
849
|
close: () => Promise.resolve(nitro.hooks.callHook("close")),
|
|
928
|
-
async updateConfig(config
|
|
929
|
-
updateNitroConfig(nitro, config
|
|
850
|
+
async updateConfig(config) {
|
|
851
|
+
updateNitroConfig(nitro, config);
|
|
930
852
|
}
|
|
931
853
|
};
|
|
932
854
|
registerNitroInstance(nitro);
|
|
@@ -935,9 +857,9 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
935
857
|
if (nitro.options.debug) createDebugger(nitro.hooks, { tag: "nitro" });
|
|
936
858
|
if (nitro.options.logLevel !== void 0) nitro.logger.level = nitro.options.logLevel;
|
|
937
859
|
nitro.hooks.addHooks(nitro.options.hooks);
|
|
938
|
-
addNitroTasksVirtualFile(nitro);
|
|
939
860
|
await installModules(nitro);
|
|
940
861
|
if (nitro.options.imports) {
|
|
862
|
+
const { createUnimport } = await import("../_build/common.mjs").then((n) => n.v);
|
|
941
863
|
nitro.unimport = createUnimport(nitro.options.imports);
|
|
942
864
|
await nitro.unimport.init();
|
|
943
865
|
nitro.options.virtual["#imports"] = () => nitro.unimport?.toExports() || "";
|
|
@@ -947,181 +869,6 @@ async function createNitro(config = {}, opts = {}) {
|
|
|
947
869
|
nitro.routing.sync();
|
|
948
870
|
return nitro;
|
|
949
871
|
}
|
|
950
|
-
|
|
951
|
-
//#endregion
|
|
952
|
-
//#region src/build/build.ts
|
|
953
|
-
async function build(nitro) {
|
|
954
|
-
switch (nitro.options.builder) {
|
|
955
|
-
case "rollup": {
|
|
956
|
-
const { rollupBuild } = await import("../_build/rollup.mjs");
|
|
957
|
-
return rollupBuild(nitro);
|
|
958
|
-
}
|
|
959
|
-
case "rolldown": {
|
|
960
|
-
const { rolldownBuild } = await import("../_build/rolldown.mjs");
|
|
961
|
-
return rolldownBuild(nitro);
|
|
962
|
-
}
|
|
963
|
-
case "vite":
|
|
964
|
-
case "rolldown-vite": {
|
|
965
|
-
const { viteBuild } = await import("../_build/vite.build.mjs");
|
|
966
|
-
return viteBuild(nitro);
|
|
967
|
-
}
|
|
968
|
-
default: throw new Error(`Unknown builder: ${nitro.options.builder}`);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
//#endregion
|
|
973
|
-
//#region src/utils/compress.ts
|
|
974
|
-
async function compressPublicAssets(nitro) {
|
|
975
|
-
const publicFiles = await glob("**", {
|
|
976
|
-
cwd: nitro.options.output.publicDir,
|
|
977
|
-
absolute: false,
|
|
978
|
-
dot: true,
|
|
979
|
-
ignore: ["**/*.gz", "**/*.br"]
|
|
980
|
-
});
|
|
981
|
-
await Promise.all(publicFiles.map(async (fileName) => {
|
|
982
|
-
const filePath = resolve(nitro.options.output.publicDir, fileName);
|
|
983
|
-
if (existsSync(filePath + ".gz") || existsSync(filePath + ".br")) return;
|
|
984
|
-
const mimeType = src_default.getType(fileName) || "text/plain";
|
|
985
|
-
const fileContents = await fsp.readFile(filePath);
|
|
986
|
-
if (fileContents.length < 1024 || fileName.endsWith(".map") || !isCompressibleMime(mimeType)) return;
|
|
987
|
-
const { gzip, brotli } = nitro.options.compressPublicAssets || {};
|
|
988
|
-
const encodings = [gzip !== false && "gzip", brotli !== false && "br"].filter(Boolean);
|
|
989
|
-
await Promise.all(encodings.map(async (encoding) => {
|
|
990
|
-
const compressedPath = filePath + ("." + (encoding === "gzip" ? "gz" : "br"));
|
|
991
|
-
if (existsSync(compressedPath)) return;
|
|
992
|
-
const gzipOptions = { level: zlib.constants.Z_BEST_COMPRESSION };
|
|
993
|
-
const brotliOptions = {
|
|
994
|
-
[zlib.constants.BROTLI_PARAM_MODE]: isTextMime(mimeType) ? zlib.constants.BROTLI_MODE_TEXT : zlib.constants.BROTLI_MODE_GENERIC,
|
|
995
|
-
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
|
|
996
|
-
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: fileContents.length
|
|
997
|
-
};
|
|
998
|
-
const compressedBuff = await new Promise((resolve$1, reject) => {
|
|
999
|
-
const cb = (error, result) => error ? reject(error) : resolve$1(result);
|
|
1000
|
-
if (encoding === "gzip") zlib.gzip(fileContents, gzipOptions, cb);
|
|
1001
|
-
else zlib.brotliCompress(fileContents, brotliOptions, cb);
|
|
1002
|
-
});
|
|
1003
|
-
await fsp.writeFile(compressedPath, compressedBuff);
|
|
1004
|
-
}));
|
|
1005
|
-
}));
|
|
1006
|
-
}
|
|
1007
|
-
function isTextMime(mimeType) {
|
|
1008
|
-
return /text|javascript|json|xml/.test(mimeType);
|
|
1009
|
-
}
|
|
1010
|
-
const COMPRESSIBLE_MIMES_RE = new Set([
|
|
1011
|
-
"application/dash+xml",
|
|
1012
|
-
"application/eot",
|
|
1013
|
-
"application/font",
|
|
1014
|
-
"application/font-sfnt",
|
|
1015
|
-
"application/javascript",
|
|
1016
|
-
"application/json",
|
|
1017
|
-
"application/opentype",
|
|
1018
|
-
"application/otf",
|
|
1019
|
-
"application/pdf",
|
|
1020
|
-
"application/pkcs7-mime",
|
|
1021
|
-
"application/protobuf",
|
|
1022
|
-
"application/rss+xml",
|
|
1023
|
-
"application/truetype",
|
|
1024
|
-
"application/ttf",
|
|
1025
|
-
"application/vnd.apple.mpegurl",
|
|
1026
|
-
"application/vnd.mapbox-vector-tile",
|
|
1027
|
-
"application/vnd.ms-fontobject",
|
|
1028
|
-
"application/wasm",
|
|
1029
|
-
"application/xhtml+xml",
|
|
1030
|
-
"application/xml",
|
|
1031
|
-
"application/x-font-opentype",
|
|
1032
|
-
"application/x-font-truetype",
|
|
1033
|
-
"application/x-font-ttf",
|
|
1034
|
-
"application/x-httpd-cgi",
|
|
1035
|
-
"application/x-javascript",
|
|
1036
|
-
"application/x-mpegurl",
|
|
1037
|
-
"application/x-opentype",
|
|
1038
|
-
"application/x-otf",
|
|
1039
|
-
"application/x-perl",
|
|
1040
|
-
"application/x-ttf",
|
|
1041
|
-
"font/eot",
|
|
1042
|
-
"font/opentype",
|
|
1043
|
-
"font/otf",
|
|
1044
|
-
"font/ttf",
|
|
1045
|
-
"image/svg+xml",
|
|
1046
|
-
"text/css",
|
|
1047
|
-
"text/csv",
|
|
1048
|
-
"text/html",
|
|
1049
|
-
"text/javascript",
|
|
1050
|
-
"text/js",
|
|
1051
|
-
"text/plain",
|
|
1052
|
-
"text/richtext",
|
|
1053
|
-
"text/tab-separated-values",
|
|
1054
|
-
"text/xml",
|
|
1055
|
-
"text/x-component",
|
|
1056
|
-
"text/x-java-source",
|
|
1057
|
-
"text/x-script",
|
|
1058
|
-
"vnd.apple.mpegurl"
|
|
1059
|
-
]);
|
|
1060
|
-
function isCompressibleMime(mimeType) {
|
|
1061
|
-
return COMPRESSIBLE_MIMES_RE.has(mimeType);
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
//#endregion
|
|
1065
|
-
//#region src/build/assets.ts
|
|
1066
|
-
const NEGATION_RE = /^(!?)(.*)$/;
|
|
1067
|
-
const PARENT_DIR_GLOB_RE = /!?\.\.\//;
|
|
1068
|
-
async function scanUnprefixedPublicAssets(nitro) {
|
|
1069
|
-
const scannedPaths = [];
|
|
1070
|
-
for (const asset of nitro.options.publicAssets) {
|
|
1071
|
-
if (asset.baseURL && asset.baseURL !== "/" && !asset.fallthrough) continue;
|
|
1072
|
-
if (!await isDirectory(asset.dir)) continue;
|
|
1073
|
-
const publicAssets = await glob(getIncludePatterns(nitro, asset.dir), {
|
|
1074
|
-
cwd: asset.dir,
|
|
1075
|
-
absolute: false,
|
|
1076
|
-
dot: true
|
|
1077
|
-
});
|
|
1078
|
-
scannedPaths.push(...publicAssets.map((file) => join(asset.baseURL || "/", file)));
|
|
1079
|
-
}
|
|
1080
|
-
return scannedPaths;
|
|
1081
|
-
}
|
|
1082
|
-
async function copyPublicAssets(nitro) {
|
|
1083
|
-
if (nitro.options.noPublicDir) return;
|
|
1084
|
-
for (const asset of nitro.options.publicAssets) {
|
|
1085
|
-
const assetDir = asset.dir;
|
|
1086
|
-
const dstDir = join(nitro.options.output.publicDir, asset.baseURL);
|
|
1087
|
-
if (await isDirectory(assetDir)) {
|
|
1088
|
-
const publicAssets = await glob(getIncludePatterns(nitro, assetDir), {
|
|
1089
|
-
cwd: assetDir,
|
|
1090
|
-
absolute: false,
|
|
1091
|
-
dot: true
|
|
1092
|
-
});
|
|
1093
|
-
await Promise.all(publicAssets.map(async (file) => {
|
|
1094
|
-
const src = join(assetDir, file);
|
|
1095
|
-
const dst = join(dstDir, file);
|
|
1096
|
-
if (!existsSync(dst)) await promises.cp(src, dst);
|
|
1097
|
-
}));
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1101
|
-
nitro.logger.success("Generated public " + prettyPath(nitro.options.output.publicDir));
|
|
1102
|
-
}
|
|
1103
|
-
function getIncludePatterns(nitro, assetDir) {
|
|
1104
|
-
return ["**", ...nitro.options.ignore.map((p) => {
|
|
1105
|
-
const [_, negation, pattern] = p.match(NEGATION_RE) || [];
|
|
1106
|
-
return (negation ? "" : "!") + (pattern.startsWith("*") ? pattern : relative(assetDir, resolve(nitro.options.rootDir, pattern)));
|
|
1107
|
-
})].filter((p) => !PARENT_DIR_GLOB_RE.test(p));
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
//#endregion
|
|
1111
|
-
//#region src/build/prepare.ts
|
|
1112
|
-
async function prepare(nitro) {
|
|
1113
|
-
await prepareDir(nitro.options.output.dir);
|
|
1114
|
-
if (!nitro.options.noPublicDir) await prepareDir(nitro.options.output.publicDir);
|
|
1115
|
-
if (!nitro.options.static) await prepareDir(nitro.options.output.serverDir);
|
|
1116
|
-
}
|
|
1117
|
-
async function prepareDir(dir) {
|
|
1118
|
-
await fsp.rm(dir, {
|
|
1119
|
-
recursive: true,
|
|
1120
|
-
force: true
|
|
1121
|
-
});
|
|
1122
|
-
await fsp.mkdir(dir, { recursive: true });
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
872
|
//#endregion
|
|
1126
873
|
//#region src/prerender/utils.ts
|
|
1127
874
|
const allowedExtensions = new Set(["", ".json"]);
|
|
@@ -1172,7 +919,7 @@ function formatPrerenderRoute(route) {
|
|
|
1172
919
|
const parents = linkParents.get(route.route);
|
|
1173
920
|
const errorColor = colors[route.error.status === 404 ? "yellow" : "red"];
|
|
1174
921
|
const errorLead = parents?.size ? "├──" : "└──";
|
|
1175
|
-
str += `\n │ ${errorLead} ${errorColor(route.error.message)}`;
|
|
922
|
+
str += `\n │ ${errorLead} ${errorColor(route.error.message || "unknown error")}`;
|
|
1176
923
|
if (parents?.size) str += `\n${[...parents.values()].map((link) => ` │ └── Linked from ${link}`).join("\n")}`;
|
|
1177
924
|
}
|
|
1178
925
|
if (route.skip) str += colors.gray(" (skipped)");
|
|
@@ -1184,7 +931,6 @@ function matchesIgnorePattern(path, pattern) {
|
|
|
1184
931
|
if (pattern instanceof RegExp) return pattern.test(path);
|
|
1185
932
|
return false;
|
|
1186
933
|
}
|
|
1187
|
-
|
|
1188
934
|
//#endregion
|
|
1189
935
|
//#region src/prerender/prerender.ts
|
|
1190
936
|
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
@@ -1193,12 +939,8 @@ async function prerender(nitro) {
|
|
|
1193
939
|
nitro.logger.warn("Skipping prerender since `noPublicDir` option is enabled.");
|
|
1194
940
|
return;
|
|
1195
941
|
}
|
|
1196
|
-
if (nitro.options.builder === "vite") {
|
|
1197
|
-
nitro.logger.warn("Skipping prerender since not supported with vite builder yet...");
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
942
|
const routes = new Set(nitro.options.prerender.routes);
|
|
1201
|
-
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path
|
|
943
|
+
const prerenderRulePaths = Object.entries(nitro.options.routeRules).filter(([path, options]) => options.prerender && !path.includes("*")).map((e) => e[0]);
|
|
1202
944
|
for (const route of prerenderRulePaths) routes.add(route);
|
|
1203
945
|
await nitro.hooks.callHook("prerender:routes", routes);
|
|
1204
946
|
if (routes.size === 0) if (nitro.options.prerender.crawlLinks) routes.add("/");
|
|
@@ -1211,7 +953,8 @@ async function prerender(nitro) {
|
|
|
1211
953
|
static: false,
|
|
1212
954
|
rootDir: nitro.options.rootDir,
|
|
1213
955
|
logLevel: 0,
|
|
1214
|
-
preset: "nitro-prerender"
|
|
956
|
+
preset: "nitro-prerender",
|
|
957
|
+
builder: nitro.options.builder === "vite" ? "rolldown" : nitro.options.builder
|
|
1215
958
|
};
|
|
1216
959
|
await nitro.hooks.callHook("prerender:config", prerendererConfig);
|
|
1217
960
|
const nitroRenderer = await createNitro(prerendererConfig);
|
|
@@ -1226,23 +969,25 @@ async function prerender(nitro) {
|
|
|
1226
969
|
const prerenderer = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href).then((m) => m.default);
|
|
1227
970
|
const routeRules = createRouter();
|
|
1228
971
|
for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
|
|
1229
|
-
const _getRouteRules = (path
|
|
972
|
+
const _getRouteRules = (path) => defu({}, ...findAllRoutes(routeRules, void 0, path).map((r) => r.data).reverse());
|
|
1230
973
|
const generatedRoutes = /* @__PURE__ */ new Set();
|
|
1231
974
|
const failedRoutes = /* @__PURE__ */ new Set();
|
|
1232
975
|
const skippedRoutes = /* @__PURE__ */ new Set();
|
|
1233
976
|
const displayedLengthWarns = /* @__PURE__ */ new Set();
|
|
1234
|
-
const publicAssetBases = nitro.options.publicAssets.filter((a
|
|
977
|
+
const publicAssetBases = nitro.options.publicAssets.filter((a) => !!a.baseURL && a.baseURL !== "/" && !a.fallthrough).map((a) => withTrailingSlash(a.baseURL));
|
|
1235
978
|
const scannedPublicAssets = nitro.options.prerender.ignoreUnprefixedPublicAssets ? new Set(await scanUnprefixedPublicAssets(nitro)) : /* @__PURE__ */ new Set();
|
|
1236
979
|
const canPrerender = (route = "/") => {
|
|
1237
980
|
if (generatedRoutes.has(route) || skippedRoutes.has(route)) return false;
|
|
1238
|
-
|
|
981
|
+
if (nitro.options.prerender.ignore) {
|
|
982
|
+
for (const pattern of nitro.options.prerender.ignore) if (matchesIgnorePattern(route, pattern)) return false;
|
|
983
|
+
}
|
|
1239
984
|
if (publicAssetBases.some((base) => route.startsWith(base))) return false;
|
|
1240
985
|
if (scannedPublicAssets.has(route)) return false;
|
|
1241
986
|
if (_getRouteRules(route).prerender === false) return false;
|
|
1242
987
|
return true;
|
|
1243
988
|
};
|
|
1244
989
|
const canWriteToDisk = (route) => {
|
|
1245
|
-
if (route.route.includes("?")) return false;
|
|
990
|
+
if (route.route.includes("?") || route.route.includes("..")) return false;
|
|
1246
991
|
const FS_MAX_SEGMENT = 255;
|
|
1247
992
|
const FS_MAX_PATH_PUBLIC_HTML = 1024 - (nitro.options.output.publicDir.length + 10);
|
|
1248
993
|
if ((route.route.length >= FS_MAX_PATH_PUBLIC_HTML || route.route.split("/").some((s) => s.length > FS_MAX_SEGMENT)) && !displayedLengthWarns.has(route)) {
|
|
@@ -1317,12 +1062,13 @@ async function prerender(nitro) {
|
|
|
1317
1062
|
dataBuff = void 0;
|
|
1318
1063
|
return _route;
|
|
1319
1064
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1065
|
+
const filePath = join(nitro.options.output.publicDir, _route.fileName);
|
|
1066
|
+
if (canWriteToDisk(_route) && filePath.startsWith(nitro.options.output.publicDir)) {
|
|
1067
|
+
await writeFile$1(filePath, dataBuff);
|
|
1322
1068
|
nitro._prerenderedRoutes.push(_route);
|
|
1323
1069
|
} else _route.skip = true;
|
|
1324
1070
|
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
|
|
1325
|
-
const extractedLinks = await extractLinks(dataBuff.toString("utf8"), route, res, nitro.options.prerender.crawlLinks);
|
|
1071
|
+
const extractedLinks = await extractLinks(dataBuff.toString("utf8"), route, res, nitro.options.prerender.crawlLinks ?? false);
|
|
1326
1072
|
for (const _link of extractedLinks) if (canPrerender(_link)) routes.add(_link);
|
|
1327
1073
|
}
|
|
1328
1074
|
await nitro.hooks.callHook("prerender:route", _route);
|
|
@@ -1332,7 +1078,7 @@ async function prerender(nitro) {
|
|
|
1332
1078
|
};
|
|
1333
1079
|
nitro.logger.info(nitro.options.prerender.crawlLinks ? `Prerendering ${routes.size} initial routes with crawler` : `Prerendering ${routes.size} routes`);
|
|
1334
1080
|
await runParallel(routes, generateRoute, {
|
|
1335
|
-
concurrency: nitro.options.prerender.concurrency,
|
|
1081
|
+
concurrency: nitro.options.prerender.concurrency || 1,
|
|
1336
1082
|
interval: nitro.options.prerender.interval
|
|
1337
1083
|
});
|
|
1338
1084
|
await prerenderer.close();
|
|
@@ -1350,6 +1096,64 @@ async function prerender(nitro) {
|
|
|
1350
1096
|
nitro.logger.info(`Prerendered ${nitro._prerenderedRoutes.length} routes in ${prerenderTimeInMs / 1e3} seconds`);
|
|
1351
1097
|
if (nitro.options.compressPublicAssets) await compressPublicAssets(nitro);
|
|
1352
1098
|
}
|
|
1353
|
-
|
|
1354
1099
|
//#endregion
|
|
1355
|
-
|
|
1100
|
+
//#region src/task.ts
|
|
1101
|
+
/** @experimental */
|
|
1102
|
+
async function runTask(taskEvent, opts) {
|
|
1103
|
+
return await (await _getTasksContext(opts)).devFetch(`/_nitro/tasks/${taskEvent.name}`, {
|
|
1104
|
+
method: "POST",
|
|
1105
|
+
body: taskEvent
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
/** @experimental */
|
|
1109
|
+
async function listTasks(opts) {
|
|
1110
|
+
return (await (await _getTasksContext(opts)).devFetch("/_nitro/tasks")).tasks;
|
|
1111
|
+
}
|
|
1112
|
+
const _devHint = `(is dev server running?)`;
|
|
1113
|
+
async function _getTasksContext(opts) {
|
|
1114
|
+
const buildInfoPath = resolve(resolve(resolve(process.cwd(), opts?.cwd || "."), opts?.buildDir || "node_modules/.nitro"), "nitro.dev.json");
|
|
1115
|
+
if (!existsSync(buildInfoPath)) throw new Error(`Missing info file: \`${buildInfoPath}\` ${_devHint}`);
|
|
1116
|
+
const buildInfo = JSON.parse(await readFile(buildInfoPath, "utf8"));
|
|
1117
|
+
if (!buildInfo.dev?.pid || !buildInfo.dev?.workerAddress) throw new Error(`Missing dev server info in: \`${buildInfoPath}\` ${_devHint}`);
|
|
1118
|
+
if (!_pidIsRunning(buildInfo.dev.pid)) throw new Error(`Dev server is not running (pid: ${buildInfo.dev.pid})`);
|
|
1119
|
+
const baseURL = `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`;
|
|
1120
|
+
const socketPath = buildInfo.dev.workerAddress.socketPath;
|
|
1121
|
+
const devFetch = (path, options) => {
|
|
1122
|
+
return new Promise((resolve, reject) => {
|
|
1123
|
+
let url = withBase(path, baseURL);
|
|
1124
|
+
if (options?.query) url = withQuery(url, options.query);
|
|
1125
|
+
const request = http.request(url, {
|
|
1126
|
+
socketPath,
|
|
1127
|
+
method: options?.method,
|
|
1128
|
+
headers: {
|
|
1129
|
+
Accept: "application/json",
|
|
1130
|
+
"Content-Type": "application/json"
|
|
1131
|
+
}
|
|
1132
|
+
}, (response) => {
|
|
1133
|
+
if (!response.statusCode || response.statusCode >= 400 && response.statusCode < 600) {
|
|
1134
|
+
reject(new Error(response.statusMessage));
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
let data = "";
|
|
1138
|
+
response.on("data", (chunk) => data += chunk).on("end", () => resolve(JSON.parse(data))).on("error", (e) => reject(e));
|
|
1139
|
+
});
|
|
1140
|
+
request.on("error", (e) => reject(e));
|
|
1141
|
+
if (options?.body) request.write(JSON.stringify(options.body));
|
|
1142
|
+
request.end();
|
|
1143
|
+
});
|
|
1144
|
+
};
|
|
1145
|
+
return {
|
|
1146
|
+
buildInfo,
|
|
1147
|
+
devFetch
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
function _pidIsRunning(pid) {
|
|
1151
|
+
try {
|
|
1152
|
+
process.kill(pid, 0);
|
|
1153
|
+
return true;
|
|
1154
|
+
} catch {
|
|
1155
|
+
return false;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
//#endregion
|
|
1159
|
+
export { loadOptions as a, createNitro as i, runTask as n, prerender as r, listTasks as t };
|