@depup/nitro 3.0.260311-beta-depup.0
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 +27 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +29361 -0
- package/dist/_build/rolldown.mjs +173 -0
- package/dist/_build/rollup.mjs +194 -0
- package/dist/_build/vite.build.mjs +18 -0
- package/dist/_chunks/nitro.mjs +1159 -0
- package/dist/_chunks/nitro2.mjs +102 -0
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +272 -0
- package/dist/_common.mjs +35 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +519 -0
- 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 +361 -0
- package/dist/_libs/commondir+is-reference.mjs +1311 -0
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/compatx.mjs +45 -0
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +7 -0
- package/dist/_libs/estree+pluginutils.d.mts +241 -0
- package/dist/_libs/estree-walker.mjs +184 -0
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +1949 -0
- package/dist/_libs/httpxy.d.mts +82 -0
- package/dist/_libs/httpxy.mjs +671 -0
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +37 -0
- 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 +64 -0
- package/dist/_libs/plugin-inject.mjs +131 -0
- package/dist/_libs/plugin-json.mjs +34 -0
- package/dist/_libs/pluginutils.mjs +646 -0
- package/dist/_libs/readdirp+chokidar.mjs +1606 -0
- package/dist/_libs/remapping.mjs +115 -0
- package/dist/_libs/resolve-uri+gen-mapping.mjs +442 -0
- package/dist/_libs/rou3.d.mts +44 -0
- package/dist/_libs/rou3.mjs +496 -0
- package/dist/_libs/std-env.d.mts +12 -0
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +813 -0
- package/dist/_libs/ultrahtml.mjs +127 -0
- 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 +1759 -0
- package/dist/builder.d.mts +64 -0
- package/dist/builder.mjs +15 -0
- package/dist/cli/_chunks/build.mjs +47 -0
- package/dist/cli/_chunks/common.mjs +14 -0
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +62 -0
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +25 -0
- package/dist/cli/_chunks/prepare.mjs +17 -0
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +53 -0
- package/dist/cli/_chunks/task.mjs +14 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +22 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +139 -0
- package/dist/node_modules/@poppinss/colors/package.json +118 -0
- package/dist/node_modules/@poppinss/dumper/build/chunk-26HALFTP.js +602 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/console/main.js +441 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +725 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +44 -0
- package/dist/node_modules/@poppinss/exception/package.json +109 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1354 -0
- package/dist/node_modules/@sindresorhus/is/distribution/utilities.js +3 -0
- package/dist/node_modules/@sindresorhus/is/package.json +81 -0
- package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -0
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -0
- package/dist/node_modules/@speed-highlight/core/package.json +94 -0
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +73 -0
- package/dist/node_modules/defu/dist/defu.mjs +69 -0
- package/dist/node_modules/defu/package.json +43 -0
- package/dist/node_modules/destr/dist/index.mjs +72 -0
- package/dist/node_modules/destr/package.json +47 -0
- package/dist/node_modules/error-stack-parser-es/dist/index.mjs +38 -0
- package/dist/node_modules/error-stack-parser-es/dist/lite.mjs +167 -0
- package/dist/node_modules/error-stack-parser-es/package.json +83 -0
- package/dist/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/node_modules/get-port-please/package.json +39 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/node_modules/scule/dist/index.mjs +80 -0
- package/dist/node_modules/scule/package.json +43 -0
- package/dist/node_modules/source-map/lib/array-set.js +100 -0
- package/dist/node_modules/source-map/lib/base64-vlq.js +94 -0
- package/dist/node_modules/source-map/lib/base64.js +19 -0
- package/dist/node_modules/source-map/lib/binary-search.js +113 -0
- package/dist/node_modules/source-map/lib/mapping-list.js +83 -0
- package/dist/node_modules/source-map/lib/mappings.wasm +0 -0
- package/dist/node_modules/source-map/lib/read-wasm.js +27 -0
- package/dist/node_modules/source-map/lib/source-map-consumer.js +1081 -0
- package/dist/node_modules/source-map/lib/source-map-generator.js +439 -0
- package/dist/node_modules/source-map/lib/source-node.js +430 -0
- package/dist/node_modules/source-map/lib/url.js +13 -0
- package/dist/node_modules/source-map/lib/util.js +444 -0
- package/dist/node_modules/source-map/lib/wasm.js +138 -0
- package/dist/node_modules/source-map/package.json +79 -0
- package/dist/node_modules/source-map/source-map.js +10 -0
- package/dist/node_modules/supports-color/index.js +202 -0
- package/dist/node_modules/supports-color/package.json +64 -0
- package/dist/node_modules/ufo/dist/index.mjs +645 -0
- package/dist/node_modules/ufo/package.json +48 -0
- package/dist/node_modules/unctx/dist/index.mjs +131 -0
- package/dist/node_modules/unctx/package.json +67 -0
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +212 -0
- package/dist/node_modules/youch/build/public/error_cause/style.css +5 -0
- package/dist/node_modules/youch/build/public/error_info/script.js +13 -0
- package/dist/node_modules/youch/build/public/error_info/style.css +145 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +72 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +219 -0
- package/dist/node_modules/youch/build/public/error_stack_source/style.css +123 -0
- package/dist/node_modules/youch/build/public/header/script.js +14 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +12 -0
- package/dist/node_modules/youch/build/public/layout/style.css +435 -0
- 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 +135 -0
- package/dist/node_modules/youch-core/build/index.js +316 -0
- package/dist/node_modules/youch-core/package.json +124 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +20 -0
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +15 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +23 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +14 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +116 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +31 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +13 -0
- package/dist/presets/azure/runtime/_utils.mjs +50 -0
- package/dist/presets/azure/runtime/azure-swa.mjs +30 -0
- package/dist/presets/bun/runtime/bun.mjs +40 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +87 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +72 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +17 -0
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +39 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +96 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +19 -0
- package/dist/presets/deno/runtime/deno-server.mjs +39 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +20 -0
- package/dist/presets/netlify/runtime/netlify.mjs +20 -0
- package/dist/presets/node/runtime/node-cluster.mjs +54 -0
- package/dist/presets/node/runtime/node-middleware.mjs +14 -0
- package/dist/presets/node/runtime/node-server.mjs +47 -0
- package/dist/presets/standard/runtime/server.mjs +4 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +27 -0
- 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 +24 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +23 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +91 -0
- package/dist/presets/zeabur/runtime/zeabur.mjs +4 -0
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/app.d.mts +1 -0
- package/dist/runtime/app.mjs +1 -0
- package/dist/runtime/cache.d.mts +1 -0
- package/dist/runtime/cache.mjs +1 -0
- package/dist/runtime/config.d.mts +3 -0
- package/dist/runtime/config.mjs +4 -0
- package/dist/runtime/context.d.mts +1 -0
- package/dist/runtime/context.mjs +1 -0
- package/dist/runtime/database.d.mts +1 -0
- package/dist/runtime/database.mjs +1 -0
- package/dist/runtime/internal/app.d.mts +16 -0
- package/dist/runtime/internal/app.mjs +208 -0
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +41 -0
- package/dist/runtime/internal/context.d.mts +14 -0
- package/dist/runtime/internal/context.mjs +24 -0
- package/dist/runtime/internal/database.d.mts +2 -0
- package/dist/runtime/internal/database.mjs +12 -0
- package/dist/runtime/internal/empty.mjs +0 -0
- package/dist/runtime/internal/error/dev.d.mts +10 -0
- package/dist/runtime/internal/error/dev.mjs +121 -0
- package/dist/runtime/internal/error/hooks.d.mts +1 -0
- package/dist/runtime/internal/error/hooks.mjs +9 -0
- package/dist/runtime/internal/error/prod.d.mts +6 -0
- package/dist/runtime/internal/error/prod.mjs +40 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/meta.d.mts +2 -0
- package/dist/runtime/internal/meta.mjs +3 -0
- package/dist/runtime/internal/plugin.d.mts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/runtime/internal/route-rules.d.mts +9 -0
- package/dist/runtime/internal/route-rules.mjs +72 -0
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +25 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +94 -0
- package/dist/runtime/internal/routes/renderer-template.d.mts +2 -0
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +3 -0
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +19 -0
- package/dist/runtime/internal/routes/renderer-template.mjs +4 -0
- package/dist/runtime/internal/routes/scalar.d.mts +3 -0
- package/dist/runtime/internal/routes/scalar.mjs +193 -0
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +42 -0
- package/dist/runtime/internal/runtime-config.d.mts +9 -0
- package/dist/runtime/internal/runtime-config.mjs +54 -0
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +67 -0
- package/dist/runtime/internal/storage.d.mts +2 -0
- package/dist/runtime/internal/storage.mjs +6 -0
- package/dist/runtime/internal/task.d.mts +19 -0
- package/dist/runtime/internal/task.mjs +69 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +18 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +6 -0
- package/dist/runtime/meta.d.mts +5 -0
- package/dist/runtime/meta.mjs +27 -0
- package/dist/runtime/nitro.d.mts +11 -0
- package/dist/runtime/nitro.mjs +34 -0
- package/dist/runtime/runtime-config.d.mts +1 -0
- package/dist/runtime/runtime-config.mjs +1 -0
- package/dist/runtime/storage.d.mts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/task.d.mts +1 -0
- package/dist/runtime/task.mjs +1 -0
- 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/runtime/virtual/polyfills.d.mts +3 -0
- 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.d.mts +8 -0
- package/dist/runtime/vite.mjs +9 -0
- package/dist/types/index.d.mts +3010 -0
- package/dist/types/index.mjs +1 -0
- package/dist/vite.d.mts +52 -0
- package/dist/vite.mjs +740 -0
- package/lib/h3.d.mts +1 -0
- package/lib/h3.mjs +1 -0
- package/lib/tsconfig.json +27 -0
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +256 -0
- 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
|
@@ -0,0 +1,1759 @@
|
|
|
1
|
+
import { B as f, F as prettyPath$1, G as findNearestFile, H as v, J as readPackageJSON, L as writeFile$2, M as glob, R, W as findFile, Y as i, Z as a, at as dirname$1, ct as join$1, dt as resolve$1, et as r, nt as resolveModulePath, q as readGitConfig, ut as relative$1 } from "./_build/common.mjs";
|
|
2
|
+
import { r as resolveCompatibilityDatesFromEnv, t as formatCompatibilityDate } from "./_libs/compatx.mjs";
|
|
3
|
+
import { t as importDep } from "./_chunks/utils.mjs";
|
|
4
|
+
import { builtinModules } from "node:module";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
import { existsSync, promises } from "node:fs";
|
|
7
|
+
import fsp, { readFile, writeFile } from "node:fs/promises";
|
|
8
|
+
import { dirname, extname, relative, resolve } from "node:path";
|
|
9
|
+
import { defu } from "defu";
|
|
10
|
+
import { presetsDir, runtimeDir, version } from "nitro/meta";
|
|
11
|
+
import { hasProtocol, joinURL, withLeadingSlash, withTrailingSlash, withoutLeadingSlash } from "ufo";
|
|
12
|
+
import { colors } from "consola/utils";
|
|
13
|
+
import { kebabCase } from "scule";
|
|
14
|
+
//#region src/presets/_utils/preset.ts
|
|
15
|
+
function defineNitroPreset(preset, meta) {
|
|
16
|
+
if (typeof preset !== "function" && preset.entry && preset.entry.startsWith(".")) preset.entry = resolve(presetsDir, preset.entry);
|
|
17
|
+
return {
|
|
18
|
+
...preset,
|
|
19
|
+
_meta: meta
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var base_worker_default = [defineNitroPreset({
|
|
23
|
+
entry: null,
|
|
24
|
+
node: false,
|
|
25
|
+
minify: true,
|
|
26
|
+
noExternals: true,
|
|
27
|
+
rollupConfig: { output: {
|
|
28
|
+
format: "iife",
|
|
29
|
+
generatedCode: { symbols: true }
|
|
30
|
+
} },
|
|
31
|
+
inlineDynamicImports: true
|
|
32
|
+
}, { name: "base-worker" })];
|
|
33
|
+
var nitro_dev_default = [defineNitroPreset({
|
|
34
|
+
entry: "./_nitro/runtime/nitro-dev",
|
|
35
|
+
output: {
|
|
36
|
+
dir: "{{ buildDir }}/dev",
|
|
37
|
+
serverDir: "{{ buildDir }}/dev",
|
|
38
|
+
publicDir: "{{ buildDir }}/dev"
|
|
39
|
+
},
|
|
40
|
+
handlers: [{
|
|
41
|
+
route: "/_nitro/tasks/**",
|
|
42
|
+
lazy: true,
|
|
43
|
+
handler: join$1(runtimeDir, "internal/routes/dev-tasks")
|
|
44
|
+
}],
|
|
45
|
+
externals: { noTrace: true },
|
|
46
|
+
serveStatic: true,
|
|
47
|
+
inlineDynamicImports: true,
|
|
48
|
+
sourcemap: true
|
|
49
|
+
}, {
|
|
50
|
+
name: "nitro-dev",
|
|
51
|
+
dev: true
|
|
52
|
+
})];
|
|
53
|
+
var nitro_prerender_default = [defineNitroPreset({
|
|
54
|
+
entry: "./_nitro/runtime/nitro-prerenderer",
|
|
55
|
+
serveStatic: true,
|
|
56
|
+
output: { serverDir: "{{ buildDir }}/prerender" },
|
|
57
|
+
externals: { noTrace: true }
|
|
58
|
+
}, { name: "nitro-prerender" })];
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/presets/_nitro/preset.ts
|
|
61
|
+
var preset_default$27 = [
|
|
62
|
+
...base_worker_default,
|
|
63
|
+
...nitro_dev_default,
|
|
64
|
+
...nitro_prerender_default
|
|
65
|
+
];
|
|
66
|
+
var preset_default$26 = [
|
|
67
|
+
defineNitroPreset({
|
|
68
|
+
static: true,
|
|
69
|
+
output: {
|
|
70
|
+
dir: "{{ rootDir }}/.output",
|
|
71
|
+
publicDir: "{{ output.dir }}/public"
|
|
72
|
+
},
|
|
73
|
+
prerender: { crawlLinks: true },
|
|
74
|
+
commands: { preview: "npx serve ./public" }
|
|
75
|
+
}, {
|
|
76
|
+
name: "static",
|
|
77
|
+
static: true
|
|
78
|
+
}),
|
|
79
|
+
defineNitroPreset({
|
|
80
|
+
extends: "static",
|
|
81
|
+
commands: { deploy: "npx gh-pages --dotfiles -d ./public" },
|
|
82
|
+
prerender: { routes: ["/", "/404.html"] },
|
|
83
|
+
hooks: { async compiled(nitro) {
|
|
84
|
+
await fsp.writeFile(join$1(nitro.options.output.publicDir, ".nojekyll"), "");
|
|
85
|
+
} }
|
|
86
|
+
}, {
|
|
87
|
+
name: "github-pages",
|
|
88
|
+
static: true
|
|
89
|
+
}),
|
|
90
|
+
defineNitroPreset({
|
|
91
|
+
extends: "static",
|
|
92
|
+
prerender: { routes: ["/", "/404.html"] }
|
|
93
|
+
}, {
|
|
94
|
+
name: "gitlab-pages",
|
|
95
|
+
static: true
|
|
96
|
+
})
|
|
97
|
+
];
|
|
98
|
+
var preset_default$25 = [defineNitroPreset({
|
|
99
|
+
extends: "node-server",
|
|
100
|
+
serveStatic: true,
|
|
101
|
+
commands: { deploy: "rsync -rRt --info=progress2 ./ [account]@ssh-[account].alwaysdata.net:www/my-app" }
|
|
102
|
+
}, { name: "alwaysdata" })];
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/presets/aws-amplify/utils.ts
|
|
105
|
+
async function writeAmplifyFiles(nitro) {
|
|
106
|
+
const outDir = nitro.options.output.dir;
|
|
107
|
+
const routes = [];
|
|
108
|
+
let hasWildcardPublicAsset = false;
|
|
109
|
+
if (nitro.options.awsAmplify?.imageOptimization && !nitro.options.static) {
|
|
110
|
+
const { path, cacheControl } = nitro.options.awsAmplify?.imageOptimization || {};
|
|
111
|
+
if (path) routes.push({
|
|
112
|
+
path,
|
|
113
|
+
target: {
|
|
114
|
+
kind: "ImageOptimization",
|
|
115
|
+
cacheControl
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const computeTarget = nitro.options.static ? { kind: "Static" } : {
|
|
120
|
+
kind: "Compute",
|
|
121
|
+
src: "default"
|
|
122
|
+
};
|
|
123
|
+
for (const publicAsset of nitro.options.publicAssets) {
|
|
124
|
+
if (!publicAsset.baseURL || publicAsset.baseURL === "/") {
|
|
125
|
+
hasWildcardPublicAsset = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
routes.push({
|
|
129
|
+
path: `${publicAsset.baseURL.replace(/\/$/, "")}/*`,
|
|
130
|
+
target: {
|
|
131
|
+
kind: "Static",
|
|
132
|
+
cacheControl: publicAsset.maxAge > 0 ? `public, max-age=${publicAsset.maxAge}, immutable` : void 0
|
|
133
|
+
},
|
|
134
|
+
fallback: publicAsset.fallthrough ? computeTarget : void 0
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (hasWildcardPublicAsset && !nitro.options.static) routes.push({
|
|
138
|
+
path: "/*.*",
|
|
139
|
+
target: { kind: "Static" },
|
|
140
|
+
fallback: computeTarget
|
|
141
|
+
});
|
|
142
|
+
routes.push({
|
|
143
|
+
path: "/*",
|
|
144
|
+
target: computeTarget,
|
|
145
|
+
fallback: hasWildcardPublicAsset && nitro.options.awsAmplify?.catchAllStaticFallback ? { kind: "Static" } : void 0
|
|
146
|
+
});
|
|
147
|
+
for (const route of routes) if (route.path !== "/*") route.path = joinURL(nitro.options.baseURL, route.path);
|
|
148
|
+
const deployManifest = {
|
|
149
|
+
version: 1,
|
|
150
|
+
routes,
|
|
151
|
+
imageSettings: nitro.options.awsAmplify?.imageSettings || void 0,
|
|
152
|
+
computeResources: nitro.options.static ? void 0 : [{
|
|
153
|
+
name: "default",
|
|
154
|
+
entrypoint: "server.js",
|
|
155
|
+
runtime: nitro.options.awsAmplify?.runtime || "nodejs20.x"
|
|
156
|
+
}],
|
|
157
|
+
framework: {
|
|
158
|
+
name: nitro.options.framework.name || "nitro",
|
|
159
|
+
version: nitro.options.framework.version || "0.0.0"
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
await writeFile(resolve(outDir, "deploy-manifest.json"), JSON.stringify(deployManifest, null, 2));
|
|
163
|
+
if (!nitro.options.static) await writeFile(resolve(outDir, "compute/default/server.js"), `import("./index.mjs")`);
|
|
164
|
+
}
|
|
165
|
+
var preset_default$24 = [defineNitroPreset({
|
|
166
|
+
entry: "./aws-amplify/runtime/aws-amplify",
|
|
167
|
+
manifest: { deploymentId: process.env.AWS_JOB_ID },
|
|
168
|
+
serveStatic: true,
|
|
169
|
+
output: {
|
|
170
|
+
dir: "{{ rootDir }}/.amplify-hosting",
|
|
171
|
+
serverDir: "{{ output.dir }}/compute/default",
|
|
172
|
+
publicDir: "{{ output.dir }}/static{{ baseURL }}"
|
|
173
|
+
},
|
|
174
|
+
commands: { preview: "node ./compute/default/server.js" },
|
|
175
|
+
hooks: { async compiled(nitro) {
|
|
176
|
+
await writeAmplifyFiles(nitro);
|
|
177
|
+
} }
|
|
178
|
+
}, {
|
|
179
|
+
name: "aws-amplify",
|
|
180
|
+
stdName: "aws_amplify"
|
|
181
|
+
})];
|
|
182
|
+
var preset_default$23 = [defineNitroPreset({
|
|
183
|
+
entry: "./aws-lambda/runtime/aws-lambda",
|
|
184
|
+
awsLambda: { streaming: false },
|
|
185
|
+
hooks: { "rollup:before": (nitro, rollupConfig) => {
|
|
186
|
+
if (nitro.options.awsLambda?.streaming) rollupConfig.input += "-streaming";
|
|
187
|
+
} }
|
|
188
|
+
}, { name: "aws-lambda" })];
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/presets/_utils/fs.ts
|
|
191
|
+
function prettyPath(p, highlight = true) {
|
|
192
|
+
p = relative$1(process.cwd(), p);
|
|
193
|
+
return highlight ? colors.cyan(p) : p;
|
|
194
|
+
}
|
|
195
|
+
async function writeFile$1(file, contents, log = false) {
|
|
196
|
+
await fsp.mkdir(dirname$1(file), { recursive: true });
|
|
197
|
+
await fsp.writeFile(file, contents, typeof contents === "string" ? "utf8" : void 0);
|
|
198
|
+
if (log) consola.info("Generated", prettyPath(file));
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/presets/azure/utils.ts
|
|
202
|
+
async function writeSWARoutes(nitro) {
|
|
203
|
+
const host = { version: "2.0" };
|
|
204
|
+
const supportedNodeVersions = new Set(["20", "22"]);
|
|
205
|
+
let nodeVersion = "18";
|
|
206
|
+
try {
|
|
207
|
+
const currentNodeVersion = JSON.parse(await fsp.readFile(join$1(nitro.options.rootDir, "package.json"), "utf8")).engines.node;
|
|
208
|
+
if (supportedNodeVersions.has(currentNodeVersion)) nodeVersion = currentNodeVersion;
|
|
209
|
+
} catch {
|
|
210
|
+
const currentNodeVersion = process.versions.node.slice(0, 2);
|
|
211
|
+
if (supportedNodeVersions.has(currentNodeVersion)) nodeVersion = currentNodeVersion;
|
|
212
|
+
}
|
|
213
|
+
const config = {
|
|
214
|
+
...nitro.options.azure?.config,
|
|
215
|
+
routes: [],
|
|
216
|
+
platform: {
|
|
217
|
+
apiRuntime: `node:${nodeVersion}`,
|
|
218
|
+
...nitro.options.azure?.config?.platform
|
|
219
|
+
},
|
|
220
|
+
navigationFallback: {
|
|
221
|
+
rewrite: "/api/server",
|
|
222
|
+
...nitro.options.azure?.config?.navigationFallback
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const routeFiles = nitro._prerenderedRoutes || [];
|
|
226
|
+
const indexFileExists = routeFiles.some((route) => route.fileName === "/index.html");
|
|
227
|
+
if (!indexFileExists) config.routes.unshift({
|
|
228
|
+
route: "/index.html",
|
|
229
|
+
redirect: "/"
|
|
230
|
+
}, {
|
|
231
|
+
route: "/",
|
|
232
|
+
rewrite: "/api/server"
|
|
233
|
+
});
|
|
234
|
+
const suffix = 11;
|
|
235
|
+
for (const { fileName } of routeFiles) {
|
|
236
|
+
if (!fileName || !fileName.endsWith("/index.html")) continue;
|
|
237
|
+
config.routes.unshift({
|
|
238
|
+
route: fileName.slice(0, -suffix) || "/",
|
|
239
|
+
rewrite: fileName
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
for (const { fileName } of routeFiles) {
|
|
243
|
+
if (!fileName || !fileName.endsWith(".html") || fileName.endsWith("index.html")) continue;
|
|
244
|
+
const route = fileName.slice(0, -5);
|
|
245
|
+
const existingRouteIndex = config.routes.findIndex((_route) => _route.route === route);
|
|
246
|
+
if (existingRouteIndex !== -1) config.routes.splice(existingRouteIndex, 1);
|
|
247
|
+
config.routes.unshift({
|
|
248
|
+
route,
|
|
249
|
+
rewrite: fileName
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (nitro.options.azure?.config && "routes" in nitro.options.azure.config && Array.isArray(nitro.options.azure.config.routes)) for (const customRoute of nitro.options.azure.config.routes.reverse()) {
|
|
253
|
+
const existingRouteMatchIndex = config.routes.findIndex((value) => value.route === customRoute.route);
|
|
254
|
+
if (existingRouteMatchIndex === -1) config.routes.unshift(customRoute);
|
|
255
|
+
else config.routes[existingRouteMatchIndex] = customRoute;
|
|
256
|
+
}
|
|
257
|
+
await writeFile$1(resolve$1(nitro.options.output.serverDir, "function.json"), JSON.stringify({
|
|
258
|
+
entryPoint: "handle",
|
|
259
|
+
bindings: [{
|
|
260
|
+
authLevel: "anonymous",
|
|
261
|
+
type: "httpTrigger",
|
|
262
|
+
direction: "in",
|
|
263
|
+
name: "req",
|
|
264
|
+
route: "{*url}",
|
|
265
|
+
methods: [
|
|
266
|
+
"delete",
|
|
267
|
+
"get",
|
|
268
|
+
"head",
|
|
269
|
+
"options",
|
|
270
|
+
"patch",
|
|
271
|
+
"post",
|
|
272
|
+
"put"
|
|
273
|
+
]
|
|
274
|
+
}, {
|
|
275
|
+
type: "http",
|
|
276
|
+
direction: "out",
|
|
277
|
+
name: "res"
|
|
278
|
+
}]
|
|
279
|
+
}, null, 2));
|
|
280
|
+
await writeFile$1(resolve$1(nitro.options.output.serverDir, "../host.json"), JSON.stringify(host, null, 2));
|
|
281
|
+
await writeFile$1(resolve$1(nitro.options.output.serverDir, "../package.json"), JSON.stringify({ private: true }));
|
|
282
|
+
await writeFile$1(resolve$1(nitro.options.rootDir, "staticwebapp.config.json"), JSON.stringify(config, null, 2));
|
|
283
|
+
if (!indexFileExists) {
|
|
284
|
+
const relativePrefix = nitro.options.baseURL.split("/").filter(Boolean).map(() => "..").join("/");
|
|
285
|
+
await writeFile$1(resolve$1(nitro.options.output.publicDir, relativePrefix ? `${relativePrefix}/index.html` : "index.html"), "");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
var preset_default$22 = [defineNitroPreset({
|
|
289
|
+
entry: "./azure/runtime/azure-swa",
|
|
290
|
+
output: {
|
|
291
|
+
serverDir: "{{ output.dir }}/server/functions",
|
|
292
|
+
publicDir: "{{ output.dir }}/public/{{ baseURL }}"
|
|
293
|
+
},
|
|
294
|
+
commands: { preview: "npx @azure/static-web-apps-cli start ./public --api-location ./server" },
|
|
295
|
+
hooks: { async compiled(ctx) {
|
|
296
|
+
await writeSWARoutes(ctx);
|
|
297
|
+
} }
|
|
298
|
+
}, {
|
|
299
|
+
name: "azure-swa",
|
|
300
|
+
stdName: "azure_static"
|
|
301
|
+
})];
|
|
302
|
+
var preset_default$21 = [defineNitroPreset({
|
|
303
|
+
entry: "./bun/runtime/bun",
|
|
304
|
+
serveStatic: true,
|
|
305
|
+
exportConditions: ["bun"],
|
|
306
|
+
commands: { preview: "bun run ./server/index.mjs" }
|
|
307
|
+
}, { name: "bun" })];
|
|
308
|
+
var preset_default$20 = [defineNitroPreset({
|
|
309
|
+
extends: "node-server",
|
|
310
|
+
serveStatic: true
|
|
311
|
+
}, {
|
|
312
|
+
name: "cleavr",
|
|
313
|
+
stdName: "cleavr"
|
|
314
|
+
})];
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/presets/cloudflare/unenv/node-compat.ts
|
|
317
|
+
const builtnNodeModules$1 = [
|
|
318
|
+
"node:_http_agent",
|
|
319
|
+
"node:_http_client",
|
|
320
|
+
"node:_http_common",
|
|
321
|
+
"node:_http_incoming",
|
|
322
|
+
"node:_http_outgoing",
|
|
323
|
+
"node:_http_server",
|
|
324
|
+
"node:_stream_duplex",
|
|
325
|
+
"node:_stream_passthrough",
|
|
326
|
+
"node:_stream_readable",
|
|
327
|
+
"node:_stream_transform",
|
|
328
|
+
"node:_stream_writable",
|
|
329
|
+
"node:_tls_common",
|
|
330
|
+
"node:_tls_wrap",
|
|
331
|
+
"node:assert",
|
|
332
|
+
"node:assert/strict",
|
|
333
|
+
"node:async_hooks",
|
|
334
|
+
"node:buffer",
|
|
335
|
+
"node:constants",
|
|
336
|
+
"node:crypto",
|
|
337
|
+
"node:diagnostics_channel",
|
|
338
|
+
"node:dns",
|
|
339
|
+
"node:dns/promises",
|
|
340
|
+
"node:events",
|
|
341
|
+
"node:fs",
|
|
342
|
+
"node:fs/promises",
|
|
343
|
+
"node:http",
|
|
344
|
+
"node:http2",
|
|
345
|
+
"node:https",
|
|
346
|
+
"node:module",
|
|
347
|
+
"node:net",
|
|
348
|
+
"node:os",
|
|
349
|
+
"node:path",
|
|
350
|
+
"node:path/posix",
|
|
351
|
+
"node:path/win32",
|
|
352
|
+
"node:process",
|
|
353
|
+
"node:querystring",
|
|
354
|
+
"node:stream",
|
|
355
|
+
"node:stream/consumers",
|
|
356
|
+
"node:stream/promises",
|
|
357
|
+
"node:stream/web",
|
|
358
|
+
"node:string_decoder",
|
|
359
|
+
"node:test",
|
|
360
|
+
"node:timers",
|
|
361
|
+
"node:timers/promises",
|
|
362
|
+
"node:tls",
|
|
363
|
+
"node:url",
|
|
364
|
+
"node:util",
|
|
365
|
+
"node:util/types",
|
|
366
|
+
"node:zlib"
|
|
367
|
+
];
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/presets/cloudflare/unenv/preset.ts
|
|
370
|
+
const unenvCfNodeCompat = {
|
|
371
|
+
meta: { name: "nitro:cloudflare-node-compat" },
|
|
372
|
+
external: builtnNodeModules$1,
|
|
373
|
+
alias: { ...Object.fromEntries(builtnNodeModules$1.flatMap((m) => [[m, m], [m.replace("node:", ""), m]])) },
|
|
374
|
+
inject: {
|
|
375
|
+
global: "unenv/polyfill/globalthis",
|
|
376
|
+
process: "node:process",
|
|
377
|
+
clearImmediate: ["node:timers", "clearImmediate"],
|
|
378
|
+
setImmediate: ["node:timers", "setImmediate"],
|
|
379
|
+
Buffer: ["node:buffer", "Buffer"]
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
const unenvCfExternals = {
|
|
383
|
+
meta: { name: "nitro:cloudflare-externals" },
|
|
384
|
+
external: [
|
|
385
|
+
"cloudflare:email",
|
|
386
|
+
"cloudflare:sockets",
|
|
387
|
+
"cloudflare:workers",
|
|
388
|
+
"cloudflare:workflows"
|
|
389
|
+
]
|
|
390
|
+
};
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/presets/cloudflare/utils.ts
|
|
393
|
+
async function writeCFRoutes(nitro) {
|
|
394
|
+
const _cfPagesConfig = nitro.options.cloudflare?.pages || {};
|
|
395
|
+
const routes = {
|
|
396
|
+
version: _cfPagesConfig.routes?.version || 1,
|
|
397
|
+
include: _cfPagesConfig.routes?.include || ["/*"],
|
|
398
|
+
exclude: _cfPagesConfig.routes?.exclude || []
|
|
399
|
+
};
|
|
400
|
+
const writeRoutes = () => writeFile$1(resolve$1(nitro.options.output.dir, "_routes.json"), JSON.stringify(routes, void 0, 2), true);
|
|
401
|
+
if (_cfPagesConfig.defaultRoutes === false) {
|
|
402
|
+
await writeRoutes();
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const explicitPublicAssets = nitro.options.publicAssets.filter((dir, index, array) => {
|
|
406
|
+
if (dir.fallthrough || !dir.baseURL) return false;
|
|
407
|
+
const normalizedBase = withoutLeadingSlash(dir.baseURL);
|
|
408
|
+
return !array.some((otherDir, otherIndex) => otherIndex !== index && normalizedBase.startsWith(withoutLeadingSlash(withTrailingSlash(otherDir.baseURL))));
|
|
409
|
+
});
|
|
410
|
+
routes.exclude.push(...explicitPublicAssets.map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/", "*")).sort(comparePaths));
|
|
411
|
+
const publicAssetFiles = await glob("**", {
|
|
412
|
+
cwd: nitro.options.output.dir,
|
|
413
|
+
absolute: false,
|
|
414
|
+
dot: true,
|
|
415
|
+
ignore: [
|
|
416
|
+
"_worker.js",
|
|
417
|
+
"_worker.js.map",
|
|
418
|
+
"nitro.json",
|
|
419
|
+
...routes.exclude.map((path) => withoutLeadingSlash(path.replace(/\/\*$/, "/**")))
|
|
420
|
+
]
|
|
421
|
+
});
|
|
422
|
+
routes.exclude.push(...publicAssetFiles.map((i) => withLeadingSlash(i).replace(/\/index\.html$/, "").replace(/\.html$/, "") || "/").sort(comparePaths));
|
|
423
|
+
routes.exclude.splice(100 - routes.include.length);
|
|
424
|
+
await writeRoutes();
|
|
425
|
+
}
|
|
426
|
+
function comparePaths(a, b) {
|
|
427
|
+
return a.split("/").length - b.split("/").length || a.localeCompare(b);
|
|
428
|
+
}
|
|
429
|
+
async function writeCFHeaders(nitro, outdir) {
|
|
430
|
+
const headersPath = join$1(outdir === "public" ? nitro.options.output.publicDir : nitro.options.output.dir, "_headers");
|
|
431
|
+
const contents = [];
|
|
432
|
+
const rules = Object.entries(nitro.options.routeRules).sort((a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length);
|
|
433
|
+
for (const [path, routeRules] of rules.filter(([_, routeRules]) => routeRules.headers)) {
|
|
434
|
+
const headers = [joinURL(nitro.options.baseURL, path.replace("/**", "/*")), ...Object.entries({ ...routeRules.headers }).map(([header, value]) => ` ${header}: ${value}`)].join("\n");
|
|
435
|
+
contents.push(headers);
|
|
436
|
+
}
|
|
437
|
+
if (existsSync(headersPath)) {
|
|
438
|
+
const currentHeaders = await readFile(headersPath, "utf8");
|
|
439
|
+
if (/^\/\* /m.test(currentHeaders)) {
|
|
440
|
+
nitro.logger.info("Not adding Nitro fallback to `_headers` (as an existing fallback was found).");
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
nitro.logger.info("Adding Nitro fallback to `_headers` to handle all unmatched routes.");
|
|
444
|
+
contents.unshift(currentHeaders);
|
|
445
|
+
}
|
|
446
|
+
await writeFile$1(headersPath, contents.join("\n"), true);
|
|
447
|
+
}
|
|
448
|
+
async function writeCFPagesRedirects(nitro) {
|
|
449
|
+
const redirectsPath = join$1(nitro.options.output.dir, "_redirects");
|
|
450
|
+
const contents = [existsSync(join$1(nitro.options.output.publicDir, "404.html")) ? `${joinURL(nitro.options.baseURL, "/*")} ${joinURL(nitro.options.baseURL, "/404.html")} 404` : ""];
|
|
451
|
+
const rules = Object.entries(nitro.options.routeRules).sort((a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length);
|
|
452
|
+
for (const [key, routeRules] of rules.filter(([_, routeRules]) => routeRules.redirect)) {
|
|
453
|
+
const code = routeRules.redirect.status;
|
|
454
|
+
const from = joinURL(nitro.options.baseURL, key.replace("/**", "/*"));
|
|
455
|
+
const to = hasProtocol(routeRules.redirect.to, { acceptRelative: true }) ? routeRules.redirect.to : joinURL(nitro.options.baseURL, routeRules.redirect.to);
|
|
456
|
+
contents.unshift(`${from}\t${to}\t${code}`);
|
|
457
|
+
}
|
|
458
|
+
if (existsSync(redirectsPath)) {
|
|
459
|
+
const currentRedirects = await readFile(redirectsPath, "utf8");
|
|
460
|
+
if (/^\/\* /m.test(currentRedirects)) {
|
|
461
|
+
nitro.logger.info("Not adding Nitro fallback to `_redirects` (as an existing fallback was found).");
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
nitro.logger.info("Adding Nitro fallback to `_redirects` to handle all unmatched routes.");
|
|
465
|
+
contents.unshift(currentRedirects);
|
|
466
|
+
}
|
|
467
|
+
await writeFile$1(redirectsPath, contents.join("\n"), true);
|
|
468
|
+
}
|
|
469
|
+
async function enableNodeCompat(nitro) {
|
|
470
|
+
nitro.options.cloudflare ??= {};
|
|
471
|
+
nitro.options.cloudflare.deployConfig ??= true;
|
|
472
|
+
nitro.options.cloudflare.nodeCompat ??= true;
|
|
473
|
+
if (nitro.options.cloudflare.nodeCompat) nitro.options.unenv.push(unenvCfNodeCompat);
|
|
474
|
+
}
|
|
475
|
+
const extensionParsers = {
|
|
476
|
+
".json": r,
|
|
477
|
+
".jsonc": r,
|
|
478
|
+
".toml": i
|
|
479
|
+
};
|
|
480
|
+
async function readWranglerConfig(nitro) {
|
|
481
|
+
const configPath = await findNearestFile([
|
|
482
|
+
"wrangler.json",
|
|
483
|
+
"wrangler.jsonc",
|
|
484
|
+
"wrangler.toml"
|
|
485
|
+
], { startingFrom: nitro.options.rootDir }).catch(() => void 0);
|
|
486
|
+
if (!configPath) return {};
|
|
487
|
+
const userConfigText = await readFile(configPath, "utf8");
|
|
488
|
+
const parser = extensionParsers[extname(configPath)];
|
|
489
|
+
if (!parser) throw new Error(`Unsupported config file format: ${configPath}`);
|
|
490
|
+
return {
|
|
491
|
+
configPath,
|
|
492
|
+
config: parser(userConfigText)
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
async function writeWranglerConfig(nitro, cfTarget) {
|
|
496
|
+
if (!nitro.options.cloudflare?.deployConfig) return;
|
|
497
|
+
const wranglerConfigDir = nitro.options.output.serverDir;
|
|
498
|
+
const wranglerConfigPath = join$1(wranglerConfigDir, "wrangler.json");
|
|
499
|
+
const defaults = {};
|
|
500
|
+
const overrides = {};
|
|
501
|
+
defaults.compatibility_date = nitro.options.compatibilityDate.cloudflare || nitro.options.compatibilityDate.default;
|
|
502
|
+
if (cfTarget === "pages") overrides.pages_build_output_dir = relative(wranglerConfigDir, nitro.options.output.dir);
|
|
503
|
+
else {
|
|
504
|
+
overrides.main = relative(wranglerConfigDir, join$1(nitro.options.output.serverDir, "index.mjs"));
|
|
505
|
+
overrides.assets = {
|
|
506
|
+
binding: "ASSETS",
|
|
507
|
+
directory: relative(wranglerConfigDir, resolve$1(nitro.options.output.publicDir, "..".repeat(nitro.options.baseURL.split("/").filter(Boolean).length)))
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
const { config: userConfig = {} } = await readWranglerConfig(nitro);
|
|
511
|
+
const ctxConfig = nitro.options.cloudflare?.wrangler || {};
|
|
512
|
+
for (const key in overrides) if (key in userConfig || key in ctxConfig) nitro.logger.warn(`[cloudflare] Wrangler config \`${key}\`${key in ctxConfig ? "set by config or modules" : ""} is overridden and will be ignored.`);
|
|
513
|
+
const wranglerConfig = defu(overrides, ctxConfig, userConfig, defaults);
|
|
514
|
+
if (!wranglerConfig.name) {
|
|
515
|
+
wranglerConfig.name = await generateWorkerName(nitro);
|
|
516
|
+
nitro.logger.info(`Using auto generated worker name: \`${wranglerConfig.name}\``);
|
|
517
|
+
}
|
|
518
|
+
wranglerConfig.compatibility_flags ??= [];
|
|
519
|
+
if (nitro.options.cloudflare?.nodeCompat && !wranglerConfig.compatibility_flags.includes("nodejs_compat")) wranglerConfig.compatibility_flags.push("nodejs_compat");
|
|
520
|
+
if (cfTarget === "module") {
|
|
521
|
+
if (wranglerConfig.no_bundle === void 0) wranglerConfig.no_bundle = true;
|
|
522
|
+
wranglerConfig.rules ??= [];
|
|
523
|
+
if (!wranglerConfig.rules.some((rule) => rule.type === "ESModule")) wranglerConfig.rules.push({
|
|
524
|
+
type: "ESModule",
|
|
525
|
+
globs: ["**/*.mjs", "**/*.js"]
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
if (nitro.options.experimental.tasks && Object.keys(nitro.options.scheduledTasks || {}).length > 0 && cfTarget !== "pages") {
|
|
529
|
+
const schedules = Object.keys(nitro.options.scheduledTasks);
|
|
530
|
+
wranglerConfig.triggers = defu(wranglerConfig.triggers, { crons: [] });
|
|
531
|
+
const existingCrons = new Set(wranglerConfig.triggers.crons);
|
|
532
|
+
for (const schedule of schedules) if (!existingCrons.has(schedule)) wranglerConfig.triggers.crons.push(schedule);
|
|
533
|
+
}
|
|
534
|
+
await writeFile$1(wranglerConfigPath, JSON.stringify(wranglerConfig, null, 2), true);
|
|
535
|
+
const configPath = join$1(nitro.options.rootDir, ".wrangler/deploy/config.json");
|
|
536
|
+
await writeFile$1(configPath, JSON.stringify({ configPath: relative(dirname(configPath), wranglerConfigPath) }), true);
|
|
537
|
+
}
|
|
538
|
+
async function generateWorkerName(nitro) {
|
|
539
|
+
const gitRepo = (await readGitConfig(nitro.options.rootDir).catch(() => void 0))?.remote?.origin?.url?.replace(/\.git$/, "").match(/[/:]([^/]+\/[^/]+)$/)?.[1];
|
|
540
|
+
const pkgName = (await readPackageJSON(nitro.options.rootDir).catch(() => void 0))?.name;
|
|
541
|
+
const subpath = relative(nitro.options.workspaceDir, nitro.options.rootDir);
|
|
542
|
+
return `${gitRepo || pkgName}/${subpath}`.toLowerCase().replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/presets/cloudflare/dev.ts
|
|
546
|
+
async function cloudflareDevModule(nitro) {
|
|
547
|
+
if (!nitro.options.dev) return;
|
|
548
|
+
nitro.options.unenv.push({
|
|
549
|
+
meta: { name: "nitro:cloudflare-dev" },
|
|
550
|
+
alias: { "cloudflare:workers": resolve(presetsDir, "cloudflare/runtime/shims/workers.dev.mjs") }
|
|
551
|
+
});
|
|
552
|
+
if (!await resolveModulePath("wrangler", {
|
|
553
|
+
from: nitro.options.rootDir,
|
|
554
|
+
try: true
|
|
555
|
+
})) {
|
|
556
|
+
nitro.logger.warn("Wrangler is not installed. Please install it using `npx nypm i wrangler` to enable dev emulation.");
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const config = {
|
|
560
|
+
...nitro.options.cloudflareDev,
|
|
561
|
+
...nitro.options.cloudflare?.dev
|
|
562
|
+
};
|
|
563
|
+
let configPath = config.configPath;
|
|
564
|
+
if (!configPath) configPath = await findFile([
|
|
565
|
+
"wrangler.json",
|
|
566
|
+
"wrangler.jsonc",
|
|
567
|
+
"wrangler.toml"
|
|
568
|
+
], { startingFrom: nitro.options.rootDir }).catch(() => void 0);
|
|
569
|
+
const persistDir = resolve(nitro.options.rootDir, config.persistDir || ".wrangler/state/v3");
|
|
570
|
+
const gitIgnorePath = await findFile(".gitignore", { startingFrom: nitro.options.rootDir }).catch(() => void 0);
|
|
571
|
+
if (gitIgnorePath && persistDir === ".wrangler/state/v3") {
|
|
572
|
+
const gitIgnore = await promises.readFile(gitIgnorePath, "utf8");
|
|
573
|
+
if (!gitIgnore.includes(".wrangler/state/v3")) await promises.writeFile(gitIgnorePath, gitIgnore + "\n.wrangler/state/v3\n").catch(() => {});
|
|
574
|
+
}
|
|
575
|
+
nitro.options.runtimeConfig.wrangler = {
|
|
576
|
+
...nitro.options.runtimeConfig.wrangler,
|
|
577
|
+
configPath,
|
|
578
|
+
persistDir,
|
|
579
|
+
environment: config.environment
|
|
580
|
+
};
|
|
581
|
+
nitro.options.plugins = nitro.options.plugins || [];
|
|
582
|
+
nitro.options.plugins.unshift(resolveModulePath("./cloudflare/runtime/plugin.dev", {
|
|
583
|
+
from: presetsDir,
|
|
584
|
+
extensions: [".mjs", ".ts"]
|
|
585
|
+
}));
|
|
586
|
+
}
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/presets/cloudflare/entry-exports.ts
|
|
589
|
+
const RESOLVE_EXTENSIONS = [
|
|
590
|
+
".ts",
|
|
591
|
+
".js",
|
|
592
|
+
".mts",
|
|
593
|
+
".mjs"
|
|
594
|
+
];
|
|
595
|
+
async function setupEntryExports(nitro) {
|
|
596
|
+
const exportsEntry = resolveExportsEntry(nitro);
|
|
597
|
+
if (!exportsEntry) return;
|
|
598
|
+
const originalEntry = nitro.options.entry;
|
|
599
|
+
const virtualEntryId = nitro.options.entry = "#nitro/virtual/cloudflare-server-entry";
|
|
600
|
+
nitro.options.virtual[virtualEntryId] = `
|
|
601
|
+
export * from "${exportsEntry}";
|
|
602
|
+
export * from "${originalEntry}";
|
|
603
|
+
export { default } from "${originalEntry}";
|
|
604
|
+
`;
|
|
605
|
+
}
|
|
606
|
+
function resolveExportsEntry(nitro) {
|
|
607
|
+
const entry = resolveModulePath(nitro.options.cloudflare?.exports || "./exports.cloudflare.ts", {
|
|
608
|
+
from: nitro.options.rootDir,
|
|
609
|
+
extensions: RESOLVE_EXTENSIONS,
|
|
610
|
+
try: true
|
|
611
|
+
});
|
|
612
|
+
if (!entry && nitro.options.cloudflare?.exports) nitro.logger.warn(`Your custom Cloudflare entrypoint \`${prettyPath$1(nitro.options.cloudflare.exports)}\` file does not exist.`);
|
|
613
|
+
else if (entry && !nitro.options.cloudflare?.exports) nitro.logger.info(`Detected \`${prettyPath$1(entry)}\` as Cloudflare entrypoint.`);
|
|
614
|
+
return entry;
|
|
615
|
+
}
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region src/presets/cloudflare/preset.ts
|
|
618
|
+
const cloudflarePages = defineNitroPreset({
|
|
619
|
+
extends: "base-worker",
|
|
620
|
+
entry: "./cloudflare/runtime/cloudflare-pages",
|
|
621
|
+
exportConditions: ["workerd"],
|
|
622
|
+
minify: false,
|
|
623
|
+
commands: {
|
|
624
|
+
preview: "npx wrangler --cwd ./ pages dev",
|
|
625
|
+
deploy: "npx wrangler --cwd ./ pages deploy"
|
|
626
|
+
},
|
|
627
|
+
output: {
|
|
628
|
+
dir: "{{ rootDir }}/dist",
|
|
629
|
+
publicDir: "{{ output.dir }}/{{ baseURL }}",
|
|
630
|
+
serverDir: "{{ output.dir }}/_worker.js"
|
|
631
|
+
},
|
|
632
|
+
alias: { _mime: "mime/index.js" },
|
|
633
|
+
wasm: {
|
|
634
|
+
lazy: false,
|
|
635
|
+
esmImport: true
|
|
636
|
+
},
|
|
637
|
+
rollupConfig: { output: {
|
|
638
|
+
entryFileNames: "index.js",
|
|
639
|
+
format: "esm",
|
|
640
|
+
inlineDynamicImports: false
|
|
641
|
+
} },
|
|
642
|
+
hooks: {
|
|
643
|
+
"build:before": async (nitro) => {
|
|
644
|
+
nitro.options.unenv.push(unenvCfExternals);
|
|
645
|
+
await enableNodeCompat(nitro);
|
|
646
|
+
await setupEntryExports(nitro);
|
|
647
|
+
},
|
|
648
|
+
async compiled(nitro) {
|
|
649
|
+
await writeWranglerConfig(nitro, "pages");
|
|
650
|
+
await writeCFRoutes(nitro);
|
|
651
|
+
await writeCFHeaders(nitro, "output");
|
|
652
|
+
await writeCFPagesRedirects(nitro);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}, {
|
|
656
|
+
name: "cloudflare-pages",
|
|
657
|
+
stdName: "cloudflare_pages"
|
|
658
|
+
});
|
|
659
|
+
const cloudflarePagesStatic = defineNitroPreset({
|
|
660
|
+
extends: "static",
|
|
661
|
+
output: {
|
|
662
|
+
dir: "{{ rootDir }}/dist",
|
|
663
|
+
publicDir: "{{ output.dir }}/{{ baseURL }}"
|
|
664
|
+
},
|
|
665
|
+
commands: {
|
|
666
|
+
preview: "npx wrangler --cwd ./ pages dev",
|
|
667
|
+
deploy: "npx wrangler --cwd ./ pages deploy"
|
|
668
|
+
},
|
|
669
|
+
hooks: { async compiled(nitro) {
|
|
670
|
+
await writeCFHeaders(nitro, "output");
|
|
671
|
+
await writeCFPagesRedirects(nitro);
|
|
672
|
+
} }
|
|
673
|
+
}, {
|
|
674
|
+
name: "cloudflare-pages-static",
|
|
675
|
+
stdName: "cloudflare_pages",
|
|
676
|
+
static: true
|
|
677
|
+
});
|
|
678
|
+
const cloudflareDev = defineNitroPreset({
|
|
679
|
+
extends: "nitro-dev",
|
|
680
|
+
modules: [cloudflareDevModule]
|
|
681
|
+
}, {
|
|
682
|
+
name: "cloudflare-dev",
|
|
683
|
+
aliases: [
|
|
684
|
+
"cloudflare-module",
|
|
685
|
+
"cloudflare-durable",
|
|
686
|
+
"cloudflare-pages"
|
|
687
|
+
],
|
|
688
|
+
compatibilityDate: "2025-07-13",
|
|
689
|
+
dev: true
|
|
690
|
+
});
|
|
691
|
+
var preset_default$19 = [
|
|
692
|
+
cloudflarePages,
|
|
693
|
+
cloudflarePagesStatic,
|
|
694
|
+
defineNitroPreset({
|
|
695
|
+
extends: "base-worker",
|
|
696
|
+
entry: "./cloudflare/runtime/cloudflare-module",
|
|
697
|
+
output: { publicDir: "{{ output.dir }}/public/{{ baseURL }}" },
|
|
698
|
+
exportConditions: ["workerd"],
|
|
699
|
+
minify: false,
|
|
700
|
+
commands: {
|
|
701
|
+
preview: "npx wrangler --cwd ./ dev",
|
|
702
|
+
deploy: "npx wrangler --cwd ./ deploy"
|
|
703
|
+
},
|
|
704
|
+
rollupConfig: { output: {
|
|
705
|
+
format: "esm",
|
|
706
|
+
exports: "named",
|
|
707
|
+
inlineDynamicImports: false
|
|
708
|
+
} },
|
|
709
|
+
wasm: {
|
|
710
|
+
lazy: false,
|
|
711
|
+
esmImport: true
|
|
712
|
+
},
|
|
713
|
+
hooks: {
|
|
714
|
+
"build:before": async (nitro) => {
|
|
715
|
+
nitro.options.unenv.push(unenvCfExternals);
|
|
716
|
+
await enableNodeCompat(nitro);
|
|
717
|
+
await setupEntryExports(nitro);
|
|
718
|
+
},
|
|
719
|
+
async compiled(nitro) {
|
|
720
|
+
await writeWranglerConfig(nitro, "module");
|
|
721
|
+
await writeCFHeaders(nitro, "public");
|
|
722
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "package.json"), JSON.stringify({
|
|
723
|
+
private: true,
|
|
724
|
+
main: "./server/index.mjs"
|
|
725
|
+
}, null, 2));
|
|
726
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "package-lock.json"), JSON.stringify({ lockfileVersion: 1 }, null, 2));
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}, {
|
|
730
|
+
name: "cloudflare-module",
|
|
731
|
+
stdName: "cloudflare_workers"
|
|
732
|
+
}),
|
|
733
|
+
defineNitroPreset({
|
|
734
|
+
extends: "cloudflare-module",
|
|
735
|
+
entry: "./cloudflare/runtime/cloudflare-durable"
|
|
736
|
+
}, { name: "cloudflare-durable" }),
|
|
737
|
+
cloudflareDev
|
|
738
|
+
];
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/presets/deno/unenv/node-compat.ts
|
|
741
|
+
const builtnNodeModules = [
|
|
742
|
+
"node:_http_agent",
|
|
743
|
+
"node:_http_common",
|
|
744
|
+
"node:_http_outgoing",
|
|
745
|
+
"node:_http_server",
|
|
746
|
+
"node:_stream_duplex",
|
|
747
|
+
"node:_stream_passthrough",
|
|
748
|
+
"node:_stream_readable",
|
|
749
|
+
"node:_stream_transform",
|
|
750
|
+
"node:_stream_writable",
|
|
751
|
+
"node:_tls_common",
|
|
752
|
+
"node:_tls_wrap",
|
|
753
|
+
"node:assert",
|
|
754
|
+
"node:assert/strict",
|
|
755
|
+
"node:async_hooks",
|
|
756
|
+
"node:buffer",
|
|
757
|
+
"node:child_process",
|
|
758
|
+
"node:cluster",
|
|
759
|
+
"node:console",
|
|
760
|
+
"node:constants",
|
|
761
|
+
"node:crypto",
|
|
762
|
+
"node:dgram",
|
|
763
|
+
"node:diagnostics_channel",
|
|
764
|
+
"node:dns",
|
|
765
|
+
"node:dns/promises",
|
|
766
|
+
"node:domain",
|
|
767
|
+
"node:events",
|
|
768
|
+
"node:fs",
|
|
769
|
+
"node:fs/promises",
|
|
770
|
+
"node:http",
|
|
771
|
+
"node:http2",
|
|
772
|
+
"node:https",
|
|
773
|
+
"node:inspector",
|
|
774
|
+
"node:inspector/promises",
|
|
775
|
+
"node:module",
|
|
776
|
+
"node:net",
|
|
777
|
+
"node:os",
|
|
778
|
+
"node:path",
|
|
779
|
+
"node:path/posix",
|
|
780
|
+
"node:path/win32",
|
|
781
|
+
"node:perf_hooks",
|
|
782
|
+
"node:process",
|
|
783
|
+
"node:punycode",
|
|
784
|
+
"node:querystring",
|
|
785
|
+
"node:readline",
|
|
786
|
+
"node:readline/promises",
|
|
787
|
+
"node:repl",
|
|
788
|
+
"node:sqlite",
|
|
789
|
+
"node:stream",
|
|
790
|
+
"node:stream/consumers",
|
|
791
|
+
"node:stream/promises",
|
|
792
|
+
"node:stream/web",
|
|
793
|
+
"node:string_decoder",
|
|
794
|
+
"node:sys",
|
|
795
|
+
"node:test",
|
|
796
|
+
"node:timers",
|
|
797
|
+
"node:timers/promises",
|
|
798
|
+
"node:tls",
|
|
799
|
+
"node:trace_events",
|
|
800
|
+
"node:tty",
|
|
801
|
+
"node:url",
|
|
802
|
+
"node:util",
|
|
803
|
+
"node:util/types",
|
|
804
|
+
"node:v8",
|
|
805
|
+
"node:vm",
|
|
806
|
+
"node:wasi",
|
|
807
|
+
"node:worker_threads",
|
|
808
|
+
"node:zlib"
|
|
809
|
+
];
|
|
810
|
+
//#endregion
|
|
811
|
+
//#region src/presets/deno/unenv/preset.ts
|
|
812
|
+
const unenvDeno = {
|
|
813
|
+
meta: { name: "nitro:deno" },
|
|
814
|
+
external: builtnNodeModules.map((m) => `node:${m}`),
|
|
815
|
+
alias: { ...Object.fromEntries(builtnNodeModules.flatMap((m) => [[m, m], [m.replace("node:", ""), m]])) },
|
|
816
|
+
inject: {
|
|
817
|
+
global: "unenv/polyfill/globalthis",
|
|
818
|
+
process: "node:process",
|
|
819
|
+
clearImmediate: ["node:timers", "clearImmediate"],
|
|
820
|
+
setImmediate: ["node:timers", "setImmediate"],
|
|
821
|
+
Buffer: ["node:buffer", "Buffer"]
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
var preset_default$18 = [defineNitroPreset({
|
|
825
|
+
entry: "./deno/runtime/deno-deploy",
|
|
826
|
+
manifest: { deploymentId: process.env.DENO_DEPLOYMENT_ID },
|
|
827
|
+
exportConditions: ["deno"],
|
|
828
|
+
node: false,
|
|
829
|
+
serveStatic: "deno",
|
|
830
|
+
commands: {
|
|
831
|
+
preview: "",
|
|
832
|
+
deploy: "cd ./ && deno run -A jsr:@deno/deployctl deploy server/index.ts"
|
|
833
|
+
},
|
|
834
|
+
unenv: unenvDeno,
|
|
835
|
+
rollupConfig: {
|
|
836
|
+
preserveEntrySignatures: false,
|
|
837
|
+
external: (id) => id.startsWith("https://") || id.startsWith("node:"),
|
|
838
|
+
output: {
|
|
839
|
+
entryFileNames: "index.ts",
|
|
840
|
+
manualChunks: (id) => "index",
|
|
841
|
+
format: "esm"
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}, { name: "deno-deploy" }), defineNitroPreset({
|
|
845
|
+
entry: "./deno/runtime/deno-server",
|
|
846
|
+
serveStatic: true,
|
|
847
|
+
exportConditions: ["deno"],
|
|
848
|
+
commands: { preview: "deno -A ./server/index.mjs" },
|
|
849
|
+
rollupConfig: {
|
|
850
|
+
external: (id) => id.startsWith("https://") || id.startsWith("node:") || builtinModules.includes(id),
|
|
851
|
+
output: { hoistTransitiveImports: false }
|
|
852
|
+
},
|
|
853
|
+
hooks: { async compiled(nitro) {
|
|
854
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "deno.json"), JSON.stringify({ tasks: { start: "deno run -A ./server/index.mjs" } }, null, 2));
|
|
855
|
+
} }
|
|
856
|
+
}, {
|
|
857
|
+
aliases: ["deno"],
|
|
858
|
+
name: "deno-server"
|
|
859
|
+
})];
|
|
860
|
+
var preset_default$17 = [defineNitroPreset({
|
|
861
|
+
extends: "node-server",
|
|
862
|
+
serveStatic: true
|
|
863
|
+
}, { name: "digital-ocean" })];
|
|
864
|
+
var preset_default$16 = [defineNitroPreset({
|
|
865
|
+
extends: "node-server",
|
|
866
|
+
serveStatic: true,
|
|
867
|
+
hooks: { async compiled(nitro) {
|
|
868
|
+
const serverEntry = join$1(nitro.options.output.serverDir, "index.mjs");
|
|
869
|
+
await writeFile$1(join$1(nitro.options.rootDir, ".apphosting/bundle.yaml"), a({
|
|
870
|
+
version: "v1",
|
|
871
|
+
runConfig: {
|
|
872
|
+
runCommand: `node ${relative$1(nitro.options.rootDir, serverEntry)}`,
|
|
873
|
+
...nitro.options.firebase?.appHosting
|
|
874
|
+
},
|
|
875
|
+
metadata: {
|
|
876
|
+
framework: nitro.options.framework.name || "nitro",
|
|
877
|
+
frameworkVersion: nitro.options.framework.version || "2.x",
|
|
878
|
+
adapterPackageName: "nitro",
|
|
879
|
+
adapterVersion: version
|
|
880
|
+
},
|
|
881
|
+
outputFiles: { serverApp: { include: [relative$1(nitro.options.rootDir, nitro.options.output.dir)] } }
|
|
882
|
+
}), true);
|
|
883
|
+
} }
|
|
884
|
+
}, {
|
|
885
|
+
name: "firebase-app-hosting",
|
|
886
|
+
stdName: "firebase_app_hosting"
|
|
887
|
+
})];
|
|
888
|
+
var preset_default$15 = [defineNitroPreset({
|
|
889
|
+
extends: "node-server",
|
|
890
|
+
serveStatic: true
|
|
891
|
+
}, { name: "flight-control" })];
|
|
892
|
+
var preset_default$14 = [defineNitroPreset({ extends: "aws_lambda" }, { name: "genezio" })];
|
|
893
|
+
var preset_default$13 = [defineNitroPreset({
|
|
894
|
+
extends: "node-server",
|
|
895
|
+
serveStatic: true
|
|
896
|
+
}, { name: "heroku" })];
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region src/presets/iis/utils.ts
|
|
899
|
+
async function writeIISFiles(nitro) {
|
|
900
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "web.config"), await iisXmlTemplate(nitro));
|
|
901
|
+
}
|
|
902
|
+
async function writeIISNodeFiles(nitro) {
|
|
903
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "web.config"), await iisnodeXmlTemplate(nitro));
|
|
904
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "index.js"), `
|
|
905
|
+
if (process.env.PORT.startsWith('\\\\')) {
|
|
906
|
+
process.env.NITRO_UNIX_SOCKET = process.env.PORT
|
|
907
|
+
delete process.env.PORT
|
|
908
|
+
}
|
|
909
|
+
import('./server/index.mjs');
|
|
910
|
+
`);
|
|
911
|
+
}
|
|
912
|
+
async function iisnodeXmlTemplate(nitro) {
|
|
913
|
+
const path = resolve$1(nitro.options.rootDir, "web.config");
|
|
914
|
+
const originalString = `<?xml version="1.0" encoding="utf-8"?>
|
|
915
|
+
<!--
|
|
916
|
+
This configuration file is required if iisnode is used to run node processes behind
|
|
917
|
+
IIS or IIS Express. For more information, visit:
|
|
918
|
+
https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config
|
|
919
|
+
-->
|
|
920
|
+
<configuration>
|
|
921
|
+
<system.webServer>
|
|
922
|
+
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
|
|
923
|
+
<webSocket enabled="false" />
|
|
924
|
+
<handlers>
|
|
925
|
+
<!-- Indicates that the index.js file is a Node.js site to be handled by the iisnode module -->
|
|
926
|
+
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
|
|
927
|
+
</handlers>
|
|
928
|
+
<rewrite>
|
|
929
|
+
<rules>
|
|
930
|
+
<!-- Do not interfere with requests for node-inspector debugging -->
|
|
931
|
+
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
|
|
932
|
+
<match url="^index.js/debug[/]?" />
|
|
933
|
+
</rule>
|
|
934
|
+
|
|
935
|
+
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
|
|
936
|
+
<rule name="StaticContent">
|
|
937
|
+
<action type="Rewrite" url="public{PATH_INFO}" />
|
|
938
|
+
</rule>
|
|
939
|
+
|
|
940
|
+
<!-- All other URLs are mapped to the Node.js site entrypoint -->
|
|
941
|
+
<rule name="DynamicContent">
|
|
942
|
+
<conditions>
|
|
943
|
+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
|
|
944
|
+
</conditions>
|
|
945
|
+
<action type="Rewrite" url="index.js" />
|
|
946
|
+
</rule>
|
|
947
|
+
</rules>
|
|
948
|
+
</rewrite>
|
|
949
|
+
|
|
950
|
+
<!-- 'bin' directory has no special meaning in Node.js and apps can be placed in it -->
|
|
951
|
+
<security>
|
|
952
|
+
<requestFiltering>
|
|
953
|
+
<hiddenSegments>
|
|
954
|
+
<remove segment="bin" />
|
|
955
|
+
</hiddenSegments>
|
|
956
|
+
<requestLimits maxAllowedContentLength="4294967295" />
|
|
957
|
+
</requestFiltering>
|
|
958
|
+
</security>
|
|
959
|
+
|
|
960
|
+
<!-- Make sure error responses are left untouched -->
|
|
961
|
+
<httpErrors existingResponse="PassThrough" />
|
|
962
|
+
|
|
963
|
+
<!--
|
|
964
|
+
You can control how Node is hosted within IIS using the following options:
|
|
965
|
+
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
|
|
966
|
+
* node_env: will be propagated to node as NODE_ENV environment variable
|
|
967
|
+
* debuggingEnabled - controls whether the built-in debugger is enabled
|
|
968
|
+
See https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
|
|
969
|
+
-->
|
|
970
|
+
<iisnode
|
|
971
|
+
watchedFiles="index.js"
|
|
972
|
+
node_env="production"
|
|
973
|
+
debuggingEnabled="false"
|
|
974
|
+
loggingEnabled="false"
|
|
975
|
+
/>
|
|
976
|
+
</system.webServer>
|
|
977
|
+
</configuration>
|
|
978
|
+
`;
|
|
979
|
+
if (existsSync(path)) {
|
|
980
|
+
const fileString = await readFile(path, "utf8");
|
|
981
|
+
const originalWebConfig = await parseXmlDoc(originalString);
|
|
982
|
+
const fileWebConfig = await parseXmlDoc(fileString);
|
|
983
|
+
if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig));
|
|
984
|
+
if (nitro.options.iis?.overrideConfig) return buildNewXmlDoc({ ...fileWebConfig });
|
|
985
|
+
}
|
|
986
|
+
return originalString;
|
|
987
|
+
}
|
|
988
|
+
async function iisXmlTemplate(nitro) {
|
|
989
|
+
const path = resolve$1(nitro.options.rootDir, "web.config");
|
|
990
|
+
const originalString = `<?xml version="1.0" encoding="UTF-8"?>
|
|
991
|
+
<configuration>
|
|
992
|
+
<system.webServer>
|
|
993
|
+
<handlers>
|
|
994
|
+
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
|
|
995
|
+
</handlers>
|
|
996
|
+
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\\logs\\node.log" startupTimeLimit="20" processPath="C:\\Program Files\\nodejs\\node.exe" arguments=".\\server\\index.mjs">
|
|
997
|
+
<environmentVariables>
|
|
998
|
+
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
|
|
999
|
+
<environmentVariable name="NODE_ENV" value="Production" />
|
|
1000
|
+
</environmentVariables>
|
|
1001
|
+
</httpPlatform>
|
|
1002
|
+
</system.webServer>
|
|
1003
|
+
</configuration>
|
|
1004
|
+
`;
|
|
1005
|
+
if (existsSync(path)) {
|
|
1006
|
+
const fileString = await readFile(path, "utf8");
|
|
1007
|
+
const originalWebConfig = await parseXmlDoc(originalString);
|
|
1008
|
+
const fileWebConfig = await parseXmlDoc(fileString);
|
|
1009
|
+
if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig));
|
|
1010
|
+
if (nitro.options.iis?.overrideConfig) return buildNewXmlDoc({ ...fileWebConfig });
|
|
1011
|
+
}
|
|
1012
|
+
return originalString;
|
|
1013
|
+
}
|
|
1014
|
+
async function parseXmlDoc(xml) {
|
|
1015
|
+
const { Parser } = await import("xml2js");
|
|
1016
|
+
if (xml === void 0 || !xml) return {};
|
|
1017
|
+
const parser = new Parser({ explicitArray: false });
|
|
1018
|
+
let parsedRecord = {};
|
|
1019
|
+
parser.parseString(xml, (_, r) => {
|
|
1020
|
+
parsedRecord = r;
|
|
1021
|
+
});
|
|
1022
|
+
return parsedRecord;
|
|
1023
|
+
}
|
|
1024
|
+
async function buildNewXmlDoc(xmlObj) {
|
|
1025
|
+
const { Builder } = await import("xml2js");
|
|
1026
|
+
return new Builder().buildObject({ ...xmlObj });
|
|
1027
|
+
}
|
|
1028
|
+
var preset_default$12 = [defineNitroPreset({
|
|
1029
|
+
extends: "node-server",
|
|
1030
|
+
serveStatic: true,
|
|
1031
|
+
hooks: { async compiled(nitro) {
|
|
1032
|
+
await writeIISFiles(nitro);
|
|
1033
|
+
} }
|
|
1034
|
+
}, { name: "iis-handler" }), defineNitroPreset({
|
|
1035
|
+
extends: "node-server",
|
|
1036
|
+
serveStatic: true,
|
|
1037
|
+
hooks: { async compiled(nitro) {
|
|
1038
|
+
await writeIISNodeFiles(nitro);
|
|
1039
|
+
} }
|
|
1040
|
+
}, { name: "iis-node" })];
|
|
1041
|
+
var preset_default$11 = [defineNitroPreset({
|
|
1042
|
+
extends: "node-server",
|
|
1043
|
+
serveStatic: true
|
|
1044
|
+
}, { name: "koyeb" })];
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/presets/netlify/utils.ts
|
|
1047
|
+
async function writeRedirects(nitro) {
|
|
1048
|
+
const redirectsPath = join$1(nitro.options.output.publicDir, "_redirects");
|
|
1049
|
+
let contents = "";
|
|
1050
|
+
if (nitro.options.static) {
|
|
1051
|
+
const staticFallback = existsSync(join$1(nitro.options.output.publicDir, "404.html")) ? "/* /404.html 404" : "";
|
|
1052
|
+
contents += staticFallback;
|
|
1053
|
+
}
|
|
1054
|
+
const rules = Object.entries(nitro.options.routeRules).sort((a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length);
|
|
1055
|
+
for (const [key, routeRules] of rules.filter(([_, routeRules]) => routeRules.redirect)) {
|
|
1056
|
+
let code = routeRules.redirect.status;
|
|
1057
|
+
if (code === 307) code = 302;
|
|
1058
|
+
if (code === 308) code = 301;
|
|
1059
|
+
contents = `${key.replace("/**", "/*")}\t${routeRules.redirect.to.replace("/**", "/:splat")}\t${code}\n` + contents;
|
|
1060
|
+
}
|
|
1061
|
+
if (existsSync(redirectsPath)) {
|
|
1062
|
+
const currentRedirects = await promises.readFile(redirectsPath, "utf8");
|
|
1063
|
+
if (/^\/\* /m.test(currentRedirects)) {
|
|
1064
|
+
nitro.logger.info("Not adding Nitro fallback to `_redirects` (as an existing fallback was found).");
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
nitro.logger.info("Adding Nitro fallback to `_redirects` to handle all unmatched routes.");
|
|
1068
|
+
contents = currentRedirects + "\n" + contents;
|
|
1069
|
+
}
|
|
1070
|
+
await promises.writeFile(redirectsPath, contents);
|
|
1071
|
+
}
|
|
1072
|
+
async function writeHeaders(nitro) {
|
|
1073
|
+
const headersPath = join$1(nitro.options.output.publicDir, "_headers");
|
|
1074
|
+
let contents = "";
|
|
1075
|
+
const rules = Object.entries(nitro.options.routeRules).sort((a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length);
|
|
1076
|
+
for (const [path, routeRules] of rules.filter(([_, routeRules]) => routeRules.headers)) {
|
|
1077
|
+
const headers = [path.replace("/**", "/*"), ...Object.entries({ ...routeRules.headers }).map(([header, value]) => ` ${header}: ${value}`)].join("\n");
|
|
1078
|
+
contents += headers + "\n";
|
|
1079
|
+
}
|
|
1080
|
+
if (existsSync(headersPath)) {
|
|
1081
|
+
const currentHeaders = await promises.readFile(headersPath, "utf8");
|
|
1082
|
+
if (/^\/\* /m.test(currentHeaders)) {
|
|
1083
|
+
nitro.logger.info("Not adding Nitro fallback to `_headers` (as an existing fallback was found).");
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
nitro.logger.info("Adding Nitro fallback to `_headers` to handle all unmatched routes.");
|
|
1087
|
+
contents = currentHeaders + "\n" + contents;
|
|
1088
|
+
}
|
|
1089
|
+
await promises.writeFile(headersPath, contents);
|
|
1090
|
+
}
|
|
1091
|
+
function getStaticPaths(publicAssets, baseURL) {
|
|
1092
|
+
return ["/.netlify/*", ...publicAssets.filter((a) => a.fallthrough !== true && a.baseURL && a.baseURL !== "/").map((a) => joinURL(baseURL, a.baseURL, "*"))];
|
|
1093
|
+
}
|
|
1094
|
+
function generateNetlifyFunction(nitro) {
|
|
1095
|
+
return `
|
|
1096
|
+
export { default } from "./main.mjs";
|
|
1097
|
+
export const config = {
|
|
1098
|
+
name: "server handler",
|
|
1099
|
+
generator: "${getGeneratorString(nitro)}",
|
|
1100
|
+
path: "/*",
|
|
1101
|
+
nodeBundler: "none",
|
|
1102
|
+
includedFiles: ["**"],
|
|
1103
|
+
excludedPath: ${JSON.stringify(getStaticPaths(nitro.options.publicAssets, nitro.options.baseURL))},
|
|
1104
|
+
preferStatic: true,
|
|
1105
|
+
};
|
|
1106
|
+
`.trim();
|
|
1107
|
+
}
|
|
1108
|
+
function getGeneratorString(nitro) {
|
|
1109
|
+
return `${nitro.options.framework.name}@${nitro.options.framework.version}`;
|
|
1110
|
+
}
|
|
1111
|
+
var preset_default$10 = [
|
|
1112
|
+
defineNitroPreset({
|
|
1113
|
+
entry: "./netlify/runtime/netlify",
|
|
1114
|
+
manifest: { deploymentId: process.env.DEPLOY_ID },
|
|
1115
|
+
output: {
|
|
1116
|
+
dir: "{{ rootDir }}/.netlify/functions-internal",
|
|
1117
|
+
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
|
|
1118
|
+
},
|
|
1119
|
+
prerender: { autoSubfolderIndex: false },
|
|
1120
|
+
rollupConfig: { output: { entryFileNames: "main.mjs" } },
|
|
1121
|
+
hooks: { async compiled(nitro) {
|
|
1122
|
+
await writeHeaders(nitro);
|
|
1123
|
+
await writeRedirects(nitro);
|
|
1124
|
+
await promises.writeFile(join$1(nitro.options.output.dir, "server", "server.mjs"), generateNetlifyFunction(nitro));
|
|
1125
|
+
if (nitro.options.netlify?.images) {
|
|
1126
|
+
nitro.options.netlify.config ||= {};
|
|
1127
|
+
nitro.options.netlify.config.images ||= nitro.options.netlify?.images;
|
|
1128
|
+
}
|
|
1129
|
+
if (Object.keys(nitro.options.netlify?.config || {}).length > 0) {
|
|
1130
|
+
const configPath = join$1(nitro.options.output.dir, "../deploy/v1/config.json");
|
|
1131
|
+
await promises.mkdir(dirname$1(configPath), { recursive: true });
|
|
1132
|
+
await promises.writeFile(configPath, JSON.stringify(nitro.options.netlify?.config), "utf8");
|
|
1133
|
+
}
|
|
1134
|
+
} }
|
|
1135
|
+
}, {
|
|
1136
|
+
name: "netlify",
|
|
1137
|
+
stdName: "netlify"
|
|
1138
|
+
}),
|
|
1139
|
+
defineNitroPreset({
|
|
1140
|
+
extends: "base-worker",
|
|
1141
|
+
entry: "./netlify/runtime/netlify-edge",
|
|
1142
|
+
manifest: { deploymentId: process.env.DEPLOY_ID },
|
|
1143
|
+
exportConditions: ["netlify"],
|
|
1144
|
+
output: {
|
|
1145
|
+
serverDir: "{{ rootDir }}/.netlify/edge-functions/server",
|
|
1146
|
+
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
|
|
1147
|
+
},
|
|
1148
|
+
prerender: { autoSubfolderIndex: false },
|
|
1149
|
+
rollupConfig: { output: {
|
|
1150
|
+
entryFileNames: "server.js",
|
|
1151
|
+
format: "esm"
|
|
1152
|
+
} },
|
|
1153
|
+
unenv: unenvDeno,
|
|
1154
|
+
hooks: { async compiled(nitro) {
|
|
1155
|
+
await writeHeaders(nitro);
|
|
1156
|
+
await writeRedirects(nitro);
|
|
1157
|
+
const manifest = {
|
|
1158
|
+
version: 1,
|
|
1159
|
+
functions: [{
|
|
1160
|
+
path: "/*",
|
|
1161
|
+
excludedPath: getStaticPaths(nitro.options.publicAssets, nitro.options.baseURL),
|
|
1162
|
+
name: "edge server handler",
|
|
1163
|
+
function: "server",
|
|
1164
|
+
generator: getGeneratorString(nitro)
|
|
1165
|
+
}]
|
|
1166
|
+
};
|
|
1167
|
+
const manifestPath = join$1(nitro.options.rootDir, ".netlify/edge-functions/manifest.json");
|
|
1168
|
+
await promises.mkdir(dirname$1(manifestPath), { recursive: true });
|
|
1169
|
+
await promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
1170
|
+
} }
|
|
1171
|
+
}, { name: "netlify-edge" }),
|
|
1172
|
+
defineNitroPreset({
|
|
1173
|
+
extends: "static",
|
|
1174
|
+
manifest: { deploymentId: process.env.DEPLOY_ID },
|
|
1175
|
+
output: {
|
|
1176
|
+
dir: "{{ rootDir }}/dist",
|
|
1177
|
+
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
|
|
1178
|
+
},
|
|
1179
|
+
prerender: { autoSubfolderIndex: false },
|
|
1180
|
+
commands: { preview: "npx serve ./" },
|
|
1181
|
+
hooks: { async compiled(nitro) {
|
|
1182
|
+
await writeHeaders(nitro);
|
|
1183
|
+
await writeRedirects(nitro);
|
|
1184
|
+
} }
|
|
1185
|
+
}, {
|
|
1186
|
+
name: "netlify-static",
|
|
1187
|
+
stdName: "netlify",
|
|
1188
|
+
static: true
|
|
1189
|
+
})
|
|
1190
|
+
];
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region src/presets/node/cluster.ts
|
|
1193
|
+
const nodeCluster = defineNitroPreset({
|
|
1194
|
+
extends: "node-server",
|
|
1195
|
+
serveStatic: true,
|
|
1196
|
+
entry: "./node/runtime/node-cluster",
|
|
1197
|
+
rollupConfig: { output: { entryFileNames: "worker.mjs" } },
|
|
1198
|
+
hooks: { async compiled(nitro) {
|
|
1199
|
+
await writeFile$2(resolve$1(nitro.options.output.serverDir, "index.mjs"), nodeClusterEntry());
|
|
1200
|
+
} }
|
|
1201
|
+
}, { name: "node-cluster" });
|
|
1202
|
+
function nodeClusterEntry() {
|
|
1203
|
+
return `
|
|
1204
|
+
import cluster from "node:cluster";
|
|
1205
|
+
import os from "node:os";
|
|
1206
|
+
|
|
1207
|
+
if (cluster.isPrimary) {
|
|
1208
|
+
const numberOfWorkers =
|
|
1209
|
+
Number.parseInt(process.env.NITRO_CLUSTER_WORKERS || "") ||
|
|
1210
|
+
(os.cpus().length > 0 ? os.cpus().length : 1);
|
|
1211
|
+
for (let i = 0; i < numberOfWorkers; i++) {
|
|
1212
|
+
cluster.fork({
|
|
1213
|
+
WORKER_ID: i + 1,
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
} else {
|
|
1217
|
+
import("./worker.mjs").catch((error) => {
|
|
1218
|
+
console.error(error);
|
|
1219
|
+
process.exit(1);
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
`;
|
|
1223
|
+
}
|
|
1224
|
+
var preset_default$9 = [
|
|
1225
|
+
defineNitroPreset({
|
|
1226
|
+
entry: "./node/runtime/node-server",
|
|
1227
|
+
serveStatic: true,
|
|
1228
|
+
commands: { preview: "node ./server/index.mjs" }
|
|
1229
|
+
}, {
|
|
1230
|
+
name: "node-server",
|
|
1231
|
+
aliases: ["node"]
|
|
1232
|
+
}),
|
|
1233
|
+
nodeCluster,
|
|
1234
|
+
defineNitroPreset({ entry: "./node/runtime/node-middleware" }, { name: "node-middleware" })
|
|
1235
|
+
];
|
|
1236
|
+
var preset_default$8 = [defineNitroPreset({
|
|
1237
|
+
extends: "node-server",
|
|
1238
|
+
serveStatic: true
|
|
1239
|
+
}, { name: "platform-sh" })];
|
|
1240
|
+
var preset_default$7 = [defineNitroPreset({
|
|
1241
|
+
extends: "node-server",
|
|
1242
|
+
serveStatic: true
|
|
1243
|
+
}, { name: "render-com" })];
|
|
1244
|
+
var preset_default$6 = [defineNitroPreset({
|
|
1245
|
+
entry: "./standard/runtime/server",
|
|
1246
|
+
serveStatic: false,
|
|
1247
|
+
output: { publicDir: "{{ output.dir }}/public/{{ baseURL }}" },
|
|
1248
|
+
commands: { preview: "npx srvx --prod ./" },
|
|
1249
|
+
alias: {
|
|
1250
|
+
srvx: "srvx/generic",
|
|
1251
|
+
"srvx/bun": "srvx/bun",
|
|
1252
|
+
"srvx/deno": "srvx/deno",
|
|
1253
|
+
"srvx/node": "srvx/node",
|
|
1254
|
+
"srvx/generic": "srvx/generic"
|
|
1255
|
+
}
|
|
1256
|
+
}, { name: "standard" })];
|
|
1257
|
+
var preset_default$5 = [defineNitroPreset({
|
|
1258
|
+
entry: "./stormkit/runtime/stormkit",
|
|
1259
|
+
output: {
|
|
1260
|
+
dir: "{{ rootDir }}/.stormkit",
|
|
1261
|
+
publicDir: "{{ rootDir }}/.stormkit/public/{{ baseURL }}"
|
|
1262
|
+
}
|
|
1263
|
+
}, {
|
|
1264
|
+
name: "stormkit",
|
|
1265
|
+
stdName: "stormkit"
|
|
1266
|
+
})];
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region src/presets/vercel/runtime/isr.ts
|
|
1269
|
+
const ISR_URL_PARAM = "__isr_route";
|
|
1270
|
+
//#endregion
|
|
1271
|
+
//#region src/presets/vercel/utils.ts
|
|
1272
|
+
const SUPPORTED_NODE_VERSIONS = [
|
|
1273
|
+
20,
|
|
1274
|
+
22,
|
|
1275
|
+
24
|
|
1276
|
+
];
|
|
1277
|
+
const UNSUPPORTED_PROXY_OPTIONS = [
|
|
1278
|
+
"headers",
|
|
1279
|
+
"forwardHeaders",
|
|
1280
|
+
"filterHeaders",
|
|
1281
|
+
"fetchOptions",
|
|
1282
|
+
"cookieDomainRewrite",
|
|
1283
|
+
"cookiePathRewrite",
|
|
1284
|
+
"onResponse"
|
|
1285
|
+
];
|
|
1286
|
+
const FALLBACK_ROUTE = "/__server";
|
|
1287
|
+
const ISR_SUFFIX = "-isr";
|
|
1288
|
+
const SAFE_FS_CHAR_RE = /[^a-zA-Z0-9_.[\]/]/g;
|
|
1289
|
+
function getSystemNodeVersion() {
|
|
1290
|
+
const systemNodeVersion = Number.parseInt(process.versions.node.split(".")[0]);
|
|
1291
|
+
return Number.isNaN(systemNodeVersion) ? 22 : systemNodeVersion;
|
|
1292
|
+
}
|
|
1293
|
+
async function generateFunctionFiles(nitro) {
|
|
1294
|
+
const o11Routes = getObservabilityRoutes(nitro);
|
|
1295
|
+
const buildConfigPath = resolve$1(nitro.options.output.dir, "config.json");
|
|
1296
|
+
const buildConfig = generateBuildConfig(nitro, o11Routes);
|
|
1297
|
+
await writeFile$1(buildConfigPath, JSON.stringify(buildConfig, null, 2));
|
|
1298
|
+
const functionConfigPath = resolve$1(nitro.options.output.serverDir, ".vc-config.json");
|
|
1299
|
+
const functionConfig = {
|
|
1300
|
+
handler: "index.mjs",
|
|
1301
|
+
launcherType: "Nodejs",
|
|
1302
|
+
shouldAddHelpers: false,
|
|
1303
|
+
supportsResponseStreaming: true,
|
|
1304
|
+
...nitro.options.vercel?.functions
|
|
1305
|
+
};
|
|
1306
|
+
await writeFile$1(functionConfigPath, JSON.stringify(functionConfig, null, 2));
|
|
1307
|
+
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
|
|
1308
|
+
if (!value.isr) continue;
|
|
1309
|
+
const funcPrefix = resolve$1(nitro.options.output.serverDir, "..", normalizeRouteDest(key) + ISR_SUFFIX);
|
|
1310
|
+
await fsp.mkdir(dirname$1(funcPrefix), { recursive: true });
|
|
1311
|
+
await fsp.symlink("./" + relative$1(dirname$1(funcPrefix), nitro.options.output.serverDir), funcPrefix + ".func", "junction");
|
|
1312
|
+
await writePrerenderConfig(funcPrefix + ".prerender-config.json", value.isr, nitro.options.vercel?.config?.bypassToken);
|
|
1313
|
+
}
|
|
1314
|
+
if (o11Routes.length === 0) return;
|
|
1315
|
+
const _getRouteRules = (path) => defu({}, ...nitro.routing.routeRules.matchAll("", path).reverse());
|
|
1316
|
+
for (const route of o11Routes) {
|
|
1317
|
+
if (_getRouteRules(route.src).isr) continue;
|
|
1318
|
+
const funcPrefix = resolve$1(nitro.options.output.serverDir, "..", route.dest);
|
|
1319
|
+
await fsp.mkdir(dirname$1(funcPrefix), { recursive: true });
|
|
1320
|
+
await fsp.symlink("./" + relative$1(dirname$1(funcPrefix), nitro.options.output.serverDir), funcPrefix + ".func", "junction");
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
async function generateStaticFiles(nitro) {
|
|
1324
|
+
const buildConfigPath = resolve$1(nitro.options.output.dir, "config.json");
|
|
1325
|
+
const buildConfig = generateBuildConfig(nitro);
|
|
1326
|
+
await writeFile$1(buildConfigPath, JSON.stringify(buildConfig, null, 2));
|
|
1327
|
+
}
|
|
1328
|
+
function generateBuildConfig(nitro, o11Routes) {
|
|
1329
|
+
const rules = Object.entries(nitro.options.routeRules).sort((a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length);
|
|
1330
|
+
const cdnProxyPaths = new Set(rules.filter(([_, routeRules]) => routeRules.proxy && canUseVercelRewrite(routeRules.proxy)).map(([path]) => path));
|
|
1331
|
+
const config = defu(nitro.options.vercel?.config, {
|
|
1332
|
+
version: 3,
|
|
1333
|
+
framework: {
|
|
1334
|
+
name: nitro.options.framework.name,
|
|
1335
|
+
version: nitro.options.framework.version
|
|
1336
|
+
},
|
|
1337
|
+
overrides: { ...Object.fromEntries((nitro._prerenderedRoutes?.filter((r) => r.fileName !== r.route) || []).map(({ route, fileName }) => [withoutLeadingSlash(fileName), { path: route.replace(/^\//, "") }])) },
|
|
1338
|
+
routes: [
|
|
1339
|
+
...rules.filter(([path, routeRules]) => (routeRules.redirect || routeRules.headers) && !cdnProxyPaths.has(path)).map(([path, routeRules]) => {
|
|
1340
|
+
let route = { src: path.replace("/**", "/(.*)") };
|
|
1341
|
+
if (routeRules.redirect) route = defu(route, {
|
|
1342
|
+
status: routeRules.redirect.status,
|
|
1343
|
+
headers: { Location: routeRules.redirect.to.replace("/**", "/$1") }
|
|
1344
|
+
});
|
|
1345
|
+
if (routeRules.headers) route = defu(route, { headers: routeRules.headers });
|
|
1346
|
+
return route;
|
|
1347
|
+
}),
|
|
1348
|
+
...rules.filter(([path]) => cdnProxyPaths.has(path)).map(([path, routeRules]) => {
|
|
1349
|
+
const proxy = routeRules.proxy;
|
|
1350
|
+
const route = {
|
|
1351
|
+
src: path.replace("/**", "/(.*)"),
|
|
1352
|
+
dest: proxy.to.replace("/**", "/$1")
|
|
1353
|
+
};
|
|
1354
|
+
if (routeRules.headers) route.headers = routeRules.headers;
|
|
1355
|
+
return route;
|
|
1356
|
+
}),
|
|
1357
|
+
...nitro.options.vercel?.skewProtection && nitro.options.manifest?.deploymentId ? [{
|
|
1358
|
+
src: "/.*",
|
|
1359
|
+
has: [{
|
|
1360
|
+
type: "header",
|
|
1361
|
+
key: "Sec-Fetch-Dest",
|
|
1362
|
+
value: "document"
|
|
1363
|
+
}],
|
|
1364
|
+
headers: { "Set-Cookie": `__vdpl=${nitro.options.manifest.deploymentId}; Path=${nitro.options.baseURL}; SameSite=Strict; Secure; HttpOnly` },
|
|
1365
|
+
continue: true
|
|
1366
|
+
}] : [],
|
|
1367
|
+
...nitro.options.publicAssets.filter((asset) => !asset.fallthrough).map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/")).map((baseURL) => ({
|
|
1368
|
+
src: baseURL + "(.*)",
|
|
1369
|
+
headers: { "cache-control": "public,max-age=31536000,immutable" },
|
|
1370
|
+
continue: true
|
|
1371
|
+
})),
|
|
1372
|
+
{ handle: "filesystem" }
|
|
1373
|
+
]
|
|
1374
|
+
});
|
|
1375
|
+
if (nitro.options.experimental.tasks && Object.keys(nitro.options.scheduledTasks || {}).length > 0) {
|
|
1376
|
+
const cronPath = nitro.options.vercel.cronHandlerRoute || "/_vercel/cron";
|
|
1377
|
+
config.crons = [...Object.keys(nitro.options.scheduledTasks).map((schedule) => ({
|
|
1378
|
+
path: cronPath,
|
|
1379
|
+
schedule
|
|
1380
|
+
})), ...config.crons || []];
|
|
1381
|
+
}
|
|
1382
|
+
if (nitro.options.static) return config;
|
|
1383
|
+
config.routes.push(...nitro.options.routeRules["/"]?.isr ? [{
|
|
1384
|
+
src: `(?<${ISR_URL_PARAM}>/)`,
|
|
1385
|
+
dest: `/index${ISR_SUFFIX}?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`
|
|
1386
|
+
}] : [], ...rules.filter(([key, value]) => value.isr !== void 0 && key !== "/").map(([key, value]) => {
|
|
1387
|
+
const src = `(?<${ISR_URL_PARAM}>${normalizeRouteSrc(key)})`;
|
|
1388
|
+
if (value.isr === false) return {
|
|
1389
|
+
src,
|
|
1390
|
+
dest: FALLBACK_ROUTE
|
|
1391
|
+
};
|
|
1392
|
+
return {
|
|
1393
|
+
src,
|
|
1394
|
+
dest: withLeadingSlash(normalizeRouteDest(key) + ISR_SUFFIX + `?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`)
|
|
1395
|
+
};
|
|
1396
|
+
}), ...(o11Routes || []).map((route) => ({
|
|
1397
|
+
src: joinURL(nitro.options.baseURL, route.src),
|
|
1398
|
+
dest: withLeadingSlash(route.dest)
|
|
1399
|
+
})), ...nitro.options.routeRules["/**"]?.isr ? [] : [{
|
|
1400
|
+
src: "/(.*)",
|
|
1401
|
+
dest: FALLBACK_ROUTE
|
|
1402
|
+
}]);
|
|
1403
|
+
return config;
|
|
1404
|
+
}
|
|
1405
|
+
function deprecateSWR(nitro) {
|
|
1406
|
+
if (nitro.options.future.nativeSWR) return;
|
|
1407
|
+
let hasLegacyOptions = false;
|
|
1408
|
+
for (const [_key, value] of Object.entries(nitro.options.routeRules)) {
|
|
1409
|
+
if (_hasProp(value, "isr")) continue;
|
|
1410
|
+
if (value.cache === false) value.isr = false;
|
|
1411
|
+
if (_hasProp(value, "static")) {
|
|
1412
|
+
value.isr = !value.static;
|
|
1413
|
+
hasLegacyOptions = true;
|
|
1414
|
+
}
|
|
1415
|
+
if (value.cache && _hasProp(value.cache, "swr")) {
|
|
1416
|
+
value.isr = value.cache.swr;
|
|
1417
|
+
hasLegacyOptions = true;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
if (hasLegacyOptions && !v) nitro.logger.warn("Nitro now uses `isr` option to configure ISR behavior on Vercel. Backwards-compatible support for `static` and `swr` options within the Vercel Build Options API will be removed in the future versions. Set `future.nativeSWR: true` nitro config disable this warning.");
|
|
1421
|
+
}
|
|
1422
|
+
async function resolveVercelRuntime(nitro) {
|
|
1423
|
+
let runtime = nitro.options.vercel?.functions?.runtime;
|
|
1424
|
+
if (runtime) return runtime;
|
|
1425
|
+
if ((await readVercelConfig(nitro.options.rootDir)).bunVersion || "Bun" in globalThis) runtime = "bun1.x";
|
|
1426
|
+
else {
|
|
1427
|
+
const systemNodeVersion = getSystemNodeVersion();
|
|
1428
|
+
runtime = `nodejs${SUPPORTED_NODE_VERSIONS.find((version) => version >= systemNodeVersion) ?? SUPPORTED_NODE_VERSIONS.at(-1)}.x`;
|
|
1429
|
+
}
|
|
1430
|
+
nitro.options.vercel ??= {};
|
|
1431
|
+
nitro.options.vercel.functions ??= {};
|
|
1432
|
+
nitro.options.vercel.functions.runtime = runtime;
|
|
1433
|
+
return runtime;
|
|
1434
|
+
}
|
|
1435
|
+
async function readVercelConfig(rootDir) {
|
|
1436
|
+
const vercelConfigPath = resolve$1(rootDir, "vercel.json");
|
|
1437
|
+
return await fsp.readFile(vercelConfigPath).then((config) => JSON.parse(config.toString())).catch(() => ({}));
|
|
1438
|
+
}
|
|
1439
|
+
function _hasProp(obj, prop) {
|
|
1440
|
+
return obj && typeof obj === "object" && prop in obj;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Check if a proxy rule can be offloaded to a Vercel CDN rewrite.
|
|
1444
|
+
* A proxy is eligible when it targets an external URL and uses no
|
|
1445
|
+
* ProxyOptions that Vercel's routing layer cannot handle at the edge.
|
|
1446
|
+
*/
|
|
1447
|
+
function canUseVercelRewrite(proxy) {
|
|
1448
|
+
if (!proxy?.to) return false;
|
|
1449
|
+
if (!/^https?:\/\//.test(proxy.to.replace(/\/\*\*$/, ""))) return false;
|
|
1450
|
+
for (const key of UNSUPPORTED_PROXY_OPTIONS) if (proxy[key] !== void 0) return false;
|
|
1451
|
+
return true;
|
|
1452
|
+
}
|
|
1453
|
+
function getObservabilityRoutes(nitro) {
|
|
1454
|
+
if ((nitro.options.compatibilityDate.vercel || nitro.options.compatibilityDate.default) < "2025-07-15") return [];
|
|
1455
|
+
const routePatterns = [...new Set([...nitro.options.ssrRoutes || [], ...[...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => !h.middleware && h.route).map((h) => h.route)])];
|
|
1456
|
+
const staticRoutes = [];
|
|
1457
|
+
const dynamicRoutes = [];
|
|
1458
|
+
const catchAllRoutes = [];
|
|
1459
|
+
for (const route of routePatterns) if (route.includes("**")) catchAllRoutes.push(route);
|
|
1460
|
+
else if (route.includes(":") || route.includes("*")) dynamicRoutes.push(route);
|
|
1461
|
+
else staticRoutes.push(route);
|
|
1462
|
+
return [
|
|
1463
|
+
...normalizeRoutes(staticRoutes),
|
|
1464
|
+
...normalizeRoutes(dynamicRoutes),
|
|
1465
|
+
...normalizeRoutes(catchAllRoutes)
|
|
1466
|
+
];
|
|
1467
|
+
}
|
|
1468
|
+
function normalizeRoutes(routes) {
|
|
1469
|
+
return routes.sort((a, b) => b.localeCompare(a)).map((route) => ({
|
|
1470
|
+
src: normalizeRouteSrc(route),
|
|
1471
|
+
dest: normalizeRouteDest(route)
|
|
1472
|
+
}));
|
|
1473
|
+
}
|
|
1474
|
+
function normalizeRouteSrc(route) {
|
|
1475
|
+
let idCtr = 0;
|
|
1476
|
+
return route.split("/").map((segment) => {
|
|
1477
|
+
if (segment.startsWith("**")) return segment === "**" ? "(?:.*)" : `?(?<${namedGroup(segment.slice(3))}>.+)`;
|
|
1478
|
+
if (segment === "*") return `(?<_${idCtr++}>[^/]*)`;
|
|
1479
|
+
if (segment.includes(":")) return segment.replace(/:(\w+)/g, (_, id) => `(?<${namedGroup(id)}>[^/]+)`).replace(/\./g, String.raw`\.`);
|
|
1480
|
+
return segment;
|
|
1481
|
+
}).join("/");
|
|
1482
|
+
}
|
|
1483
|
+
function namedGroup(input = "") {
|
|
1484
|
+
if (/\d/.test(input[0])) input = `_${input}`;
|
|
1485
|
+
return input.replace(/[^a-zA-Z0-9_]/g, "") || "_";
|
|
1486
|
+
}
|
|
1487
|
+
function normalizeRouteDest(route) {
|
|
1488
|
+
return route.split("/").slice(1).map((segment) => {
|
|
1489
|
+
if (segment.startsWith("**")) return `[...${segment.replace(/[*:]/g, "")}]`;
|
|
1490
|
+
if (segment === "*") return "[-]";
|
|
1491
|
+
if (segment.startsWith(":")) return `[${segment.slice(1)}]`;
|
|
1492
|
+
if (segment.includes(":")) return `[${segment.replace(/:/g, "_")}]`;
|
|
1493
|
+
return segment;
|
|
1494
|
+
}).map((segment) => segment.replace(SAFE_FS_CHAR_RE, "-")).join("/") || "index";
|
|
1495
|
+
}
|
|
1496
|
+
async function writePrerenderConfig(filename, isrConfig, bypassToken) {
|
|
1497
|
+
if (typeof isrConfig === "number") isrConfig = { expiration: isrConfig };
|
|
1498
|
+
else if (isrConfig === true) isrConfig = { expiration: false };
|
|
1499
|
+
else isrConfig = { ...isrConfig };
|
|
1500
|
+
const prerenderConfig = {
|
|
1501
|
+
expiration: isrConfig.expiration ?? false,
|
|
1502
|
+
bypassToken,
|
|
1503
|
+
...isrConfig
|
|
1504
|
+
};
|
|
1505
|
+
if (prerenderConfig.allowQuery && !prerenderConfig.allowQuery.includes("__isr_route")) prerenderConfig.allowQuery.push(ISR_URL_PARAM);
|
|
1506
|
+
await writeFile$1(filename, JSON.stringify(prerenderConfig, null, 2));
|
|
1507
|
+
}
|
|
1508
|
+
var preset_default$4 = [defineNitroPreset({
|
|
1509
|
+
entry: "./vercel/runtime/vercel.{format}",
|
|
1510
|
+
manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
|
|
1511
|
+
vercel: {
|
|
1512
|
+
skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED,
|
|
1513
|
+
cronHandlerRoute: "/_vercel/cron"
|
|
1514
|
+
},
|
|
1515
|
+
output: {
|
|
1516
|
+
dir: "{{ rootDir }}/.vercel/output",
|
|
1517
|
+
serverDir: "{{ output.dir }}/functions/__server.func",
|
|
1518
|
+
publicDir: "{{ output.dir }}/static/{{ baseURL }}"
|
|
1519
|
+
},
|
|
1520
|
+
commands: {
|
|
1521
|
+
preview: "npx srvx --static ../../static ./functions/__server.func/index.mjs",
|
|
1522
|
+
deploy: "npx vercel deploy --prebuilt"
|
|
1523
|
+
},
|
|
1524
|
+
hooks: {
|
|
1525
|
+
"build:before": async (nitro) => {
|
|
1526
|
+
const logger = nitro.logger.withTag("vercel");
|
|
1527
|
+
const runtime = await resolveVercelRuntime(nitro);
|
|
1528
|
+
if (runtime.startsWith("bun") && !nitro.options.exportConditions.includes("bun")) nitro.options.exportConditions.push("bun");
|
|
1529
|
+
logger.info(`Using \`${runtime}\` runtime.`);
|
|
1530
|
+
let serverFormat = nitro.options.vercel?.entryFormat;
|
|
1531
|
+
if (!serverFormat) serverFormat = nitro.routing.routes.routes.flatMap((r) => r.data).some((h) => h.format === "node") ? "node" : "web";
|
|
1532
|
+
logger.info(`Using \`${serverFormat}\` entry format.`);
|
|
1533
|
+
nitro.options.entry = nitro.options.entry.replace("{format}", serverFormat);
|
|
1534
|
+
if (nitro.options.experimental.tasks && Object.keys(nitro.options.scheduledTasks || {}).length > 0) nitro.options.handlers.push({
|
|
1535
|
+
route: nitro.options.vercel.cronHandlerRoute || "/_vercel/cron",
|
|
1536
|
+
lazy: true,
|
|
1537
|
+
handler: join$1(presetsDir, "vercel/runtime/cron-handler")
|
|
1538
|
+
});
|
|
1539
|
+
},
|
|
1540
|
+
"rollup:before": (nitro) => {
|
|
1541
|
+
deprecateSWR(nitro);
|
|
1542
|
+
},
|
|
1543
|
+
async compiled(nitro) {
|
|
1544
|
+
await generateFunctionFiles(nitro);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}, {
|
|
1548
|
+
name: "vercel",
|
|
1549
|
+
stdName: "vercel"
|
|
1550
|
+
}), defineNitroPreset({
|
|
1551
|
+
extends: "static",
|
|
1552
|
+
manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
|
|
1553
|
+
vercel: { skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED },
|
|
1554
|
+
output: {
|
|
1555
|
+
dir: "{{ rootDir }}/.vercel/output",
|
|
1556
|
+
publicDir: "{{ output.dir }}/static/{{ baseURL }}"
|
|
1557
|
+
},
|
|
1558
|
+
commands: { preview: "npx serve ./static" },
|
|
1559
|
+
hooks: {
|
|
1560
|
+
"rollup:before": (nitro) => {
|
|
1561
|
+
deprecateSWR(nitro);
|
|
1562
|
+
},
|
|
1563
|
+
async compiled(nitro) {
|
|
1564
|
+
await generateStaticFiles(nitro);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}, {
|
|
1568
|
+
name: "vercel-static",
|
|
1569
|
+
stdName: "vercel",
|
|
1570
|
+
static: true
|
|
1571
|
+
})];
|
|
1572
|
+
var preset_default$3 = [defineNitroPreset({
|
|
1573
|
+
extends: "base-worker",
|
|
1574
|
+
entry: "./winterjs/runtime/winterjs",
|
|
1575
|
+
minify: false,
|
|
1576
|
+
serveStatic: "inline",
|
|
1577
|
+
wasm: { lazy: true },
|
|
1578
|
+
commands: { preview: "wasmer run wasmer/winterjs --forward-host-env --net --mapdir app:./ app/server/index.mjs" }
|
|
1579
|
+
}, { name: "winterjs" })];
|
|
1580
|
+
var preset_default$2 = [defineNitroPreset({
|
|
1581
|
+
entry: "./zeabur/runtime/zeabur",
|
|
1582
|
+
output: {
|
|
1583
|
+
dir: "{{ rootDir }}/.zeabur/output",
|
|
1584
|
+
serverDir: "{{ output.dir }}/functions/__nitro.func",
|
|
1585
|
+
publicDir: "{{ output.dir }}/static"
|
|
1586
|
+
},
|
|
1587
|
+
hooks: { async compiled(nitro) {
|
|
1588
|
+
await writeFile$1(resolve$1(nitro.options.output.dir, "config.json"), JSON.stringify({
|
|
1589
|
+
containerized: false,
|
|
1590
|
+
routes: [{
|
|
1591
|
+
src: ".*",
|
|
1592
|
+
dest: "/__nitro"
|
|
1593
|
+
}]
|
|
1594
|
+
}, null, 2));
|
|
1595
|
+
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
|
|
1596
|
+
if (!value.isr) continue;
|
|
1597
|
+
const funcPrefix = resolve$1(nitro.options.output.serverDir, ".." + key);
|
|
1598
|
+
await fsp.mkdir(dirname$1(funcPrefix), { recursive: true });
|
|
1599
|
+
await fsp.symlink("./" + relative$1(dirname$1(funcPrefix), nitro.options.output.serverDir), funcPrefix + ".func", "junction");
|
|
1600
|
+
await writeFile$1(funcPrefix + ".prerender-config.json", JSON.stringify({ type: "Prerender" }));
|
|
1601
|
+
}
|
|
1602
|
+
} }
|
|
1603
|
+
}, {
|
|
1604
|
+
name: "zeabur",
|
|
1605
|
+
stdName: "zeabur"
|
|
1606
|
+
}), defineNitroPreset({
|
|
1607
|
+
extends: "static",
|
|
1608
|
+
output: {
|
|
1609
|
+
dir: "{{ rootDir }}/.zeabur/output",
|
|
1610
|
+
publicDir: "{{ output.dir }}/static"
|
|
1611
|
+
},
|
|
1612
|
+
commands: { preview: "npx serve ./static" }
|
|
1613
|
+
}, {
|
|
1614
|
+
name: "zeabur-static",
|
|
1615
|
+
static: true
|
|
1616
|
+
})];
|
|
1617
|
+
//#endregion
|
|
1618
|
+
//#region src/presets/zephyr/preset.ts
|
|
1619
|
+
const LOGGER_TAG = "zephyr-nitro-preset";
|
|
1620
|
+
var preset_default$1 = [defineNitroPreset({
|
|
1621
|
+
extends: "base-worker",
|
|
1622
|
+
entry: "./zephyr/runtime/server",
|
|
1623
|
+
output: { publicDir: "{{ output.dir }}/client/{{ baseURL }}" },
|
|
1624
|
+
exportConditions: ["node"],
|
|
1625
|
+
minify: false,
|
|
1626
|
+
rollupConfig: { output: {
|
|
1627
|
+
format: "esm",
|
|
1628
|
+
exports: "named",
|
|
1629
|
+
inlineDynamicImports: false
|
|
1630
|
+
} },
|
|
1631
|
+
wasm: {
|
|
1632
|
+
lazy: false,
|
|
1633
|
+
esmImport: true
|
|
1634
|
+
},
|
|
1635
|
+
hooks: {
|
|
1636
|
+
"build:before": (nitro) => {
|
|
1637
|
+
nitro.options.unenv.push(unenvCfExternals, unenvCfNodeCompat);
|
|
1638
|
+
},
|
|
1639
|
+
compiled: async (nitro) => {
|
|
1640
|
+
try {
|
|
1641
|
+
if (!globalThis.__nitroDeploying__ && !nitro.options.zephyr?.deployOnBuild) {
|
|
1642
|
+
nitro.logger.info(`[${LOGGER_TAG}] Zephyr deploy skipped on build.`);
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
const { deploymentUrl } = await (await importDep({
|
|
1646
|
+
id: "zephyr-agent",
|
|
1647
|
+
reason: "deploying to Zephyr",
|
|
1648
|
+
dir: nitro.options.rootDir
|
|
1649
|
+
})).uploadOutputToZephyr({
|
|
1650
|
+
rootDir: nitro.options.rootDir,
|
|
1651
|
+
outputDir: nitro.options.output.dir,
|
|
1652
|
+
baseURL: nitro.options.baseURL,
|
|
1653
|
+
publicDir: resolve$1(nitro.options.output.dir, nitro.options.output.publicDir)
|
|
1654
|
+
});
|
|
1655
|
+
if (deploymentUrl) nitro.logger.success(`[${LOGGER_TAG}] Zephyr deployment succeeded: ${deploymentUrl}`);
|
|
1656
|
+
else nitro.logger.success(`[${LOGGER_TAG}] Zephyr deployment succeeded.`);
|
|
1657
|
+
globalThis.__nitroDeployed__ = true;
|
|
1658
|
+
} catch (error) {
|
|
1659
|
+
if (error instanceof Error) throw error;
|
|
1660
|
+
throw new TypeError(`[${LOGGER_TAG}] ${String(error)}`);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}, { name: "zephyr" })];
|
|
1665
|
+
var preset_default = [defineNitroPreset({
|
|
1666
|
+
extends: "node-server",
|
|
1667
|
+
serveStatic: true
|
|
1668
|
+
}, { name: "zerops" }), defineNitroPreset({
|
|
1669
|
+
extends: "static",
|
|
1670
|
+
output: {
|
|
1671
|
+
dir: "{{ rootDir }}/.zerops/output",
|
|
1672
|
+
publicDir: "{{ output.dir }}/static"
|
|
1673
|
+
}
|
|
1674
|
+
}, {
|
|
1675
|
+
name: "zerops-static",
|
|
1676
|
+
static: true
|
|
1677
|
+
})];
|
|
1678
|
+
//#endregion
|
|
1679
|
+
//#region src/presets/_all.gen.ts
|
|
1680
|
+
var _all_gen_default = [
|
|
1681
|
+
...preset_default$27,
|
|
1682
|
+
...preset_default$26,
|
|
1683
|
+
...preset_default$25,
|
|
1684
|
+
...preset_default$24,
|
|
1685
|
+
...preset_default$23,
|
|
1686
|
+
...preset_default$22,
|
|
1687
|
+
...preset_default$21,
|
|
1688
|
+
...preset_default$20,
|
|
1689
|
+
...preset_default$19,
|
|
1690
|
+
...preset_default$18,
|
|
1691
|
+
...preset_default$17,
|
|
1692
|
+
...preset_default$16,
|
|
1693
|
+
...preset_default$15,
|
|
1694
|
+
...preset_default$14,
|
|
1695
|
+
...preset_default$13,
|
|
1696
|
+
...preset_default$12,
|
|
1697
|
+
...preset_default$11,
|
|
1698
|
+
...preset_default$10,
|
|
1699
|
+
...preset_default$9,
|
|
1700
|
+
...preset_default$8,
|
|
1701
|
+
...preset_default$7,
|
|
1702
|
+
...preset_default$6,
|
|
1703
|
+
...preset_default$5,
|
|
1704
|
+
...preset_default$4,
|
|
1705
|
+
...preset_default$3,
|
|
1706
|
+
...preset_default$2,
|
|
1707
|
+
...preset_default$1,
|
|
1708
|
+
...preset_default
|
|
1709
|
+
];
|
|
1710
|
+
//#endregion
|
|
1711
|
+
//#region src/presets/_resolve.ts
|
|
1712
|
+
const _stdProviderMap = {
|
|
1713
|
+
aws_amplify: "aws",
|
|
1714
|
+
azure_static: "azure",
|
|
1715
|
+
cloudflare_pages: "cloudflare"
|
|
1716
|
+
};
|
|
1717
|
+
async function resolvePreset(name, opts = {}) {
|
|
1718
|
+
if (name === ".") return;
|
|
1719
|
+
const _name = kebabCase(name) || f;
|
|
1720
|
+
const _compatDates = opts.compatibilityDate ? resolveCompatibilityDatesFromEnv(opts.compatibilityDate) : false;
|
|
1721
|
+
const matches = _all_gen_default.filter((preset) => {
|
|
1722
|
+
if (![
|
|
1723
|
+
preset._meta.name,
|
|
1724
|
+
preset._meta.stdName,
|
|
1725
|
+
...preset._meta.aliases || []
|
|
1726
|
+
].filter(Boolean).includes(_name)) return false;
|
|
1727
|
+
if (opts.dev && !preset._meta.dev || !opts.dev && preset._meta.dev) return false;
|
|
1728
|
+
if (_compatDates) {
|
|
1729
|
+
const _date = _compatDates[_stdProviderMap[preset._meta.stdName]] || _compatDates[preset._meta.stdName] || _compatDates[preset._meta.name] || _compatDates.default;
|
|
1730
|
+
if (_date && preset._meta.compatibilityDate && new Date(preset._meta.compatibilityDate) > new Date(_date)) return false;
|
|
1731
|
+
}
|
|
1732
|
+
return true;
|
|
1733
|
+
}).sort((a, b) => {
|
|
1734
|
+
const aDate = new Date(a._meta.compatibilityDate || 0);
|
|
1735
|
+
return new Date(b._meta.compatibilityDate || 0) > aDate ? 1 : -1;
|
|
1736
|
+
});
|
|
1737
|
+
const preset = matches.find((p) => (p._meta.static || false) === (opts?.static || false)) || matches[0];
|
|
1738
|
+
if (typeof preset === "function") return preset();
|
|
1739
|
+
if (!name && !preset) {
|
|
1740
|
+
if (opts?.static) return resolvePreset("static", opts);
|
|
1741
|
+
return resolvePreset({
|
|
1742
|
+
deno: "deno",
|
|
1743
|
+
bun: "bun"
|
|
1744
|
+
}[R] || "node", opts);
|
|
1745
|
+
}
|
|
1746
|
+
if (name && !preset) {
|
|
1747
|
+
const options = _all_gen_default.filter((p) => p._meta.name === name || p._meta.stdName === name || p._meta.aliases?.includes(name)).sort((a, b) => (a._meta.compatibilityDate || 0) > (b._meta.compatibilityDate || 0) ? 1 : -1);
|
|
1748
|
+
if (options.length > 0) {
|
|
1749
|
+
let msg = `Preset "${name}" cannot be resolved with current compatibilityDate: ${formatCompatibilityDate(_compatDates || "")}.\n\n`;
|
|
1750
|
+
for (const option of options) msg += `\n- ${option._meta.name} (requires compatibilityDate >= ${option._meta.compatibilityDate})`;
|
|
1751
|
+
const err = new Error(msg);
|
|
1752
|
+
Error.captureStackTrace?.(err, resolvePreset);
|
|
1753
|
+
throw err;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return preset;
|
|
1757
|
+
}
|
|
1758
|
+
//#endregion
|
|
1759
|
+
export { resolvePreset };
|