nitro-nightly 3.0.0-beta-28969273.f7aa9de6 → 4.0.0-20251010-091516-7cafddba
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/README.md +8 -39
- package/dist/_chunks/app.mjs +19797 -0
- package/dist/_chunks/build.mjs +84 -0
- package/dist/_chunks/build2.mjs +318 -0
- package/dist/_chunks/build3.mjs +6452 -0
- package/dist/_chunks/detect-acorn.mjs +503 -0
- package/dist/_chunks/index.mjs +22242 -0
- package/dist/_chunks/index2.mjs +297 -0
- package/dist/_chunks/index3.mjs +1058 -0
- package/dist/_chunks/index4.mjs +1206 -0
- package/dist/_chunks/info.mjs +11157 -0
- package/dist/_chunks/json5.mjs +68 -0
- package/dist/_chunks/jsonc.mjs +51 -0
- package/dist/_chunks/pathe.M-eThtNZ.mjs +204 -0
- package/dist/_chunks/plugin.mjs +960 -0
- package/dist/_chunks/server.mjs +254 -0
- package/dist/_chunks/snapshot.mjs +284 -0
- package/dist/_chunks/toml.mjs +259 -0
- package/dist/_chunks/yaml.mjs +86 -0
- package/dist/cli/build.mjs +10 -3
- package/dist/cli/dev.mjs +41 -9
- package/dist/cli/index.mjs +460 -1
- package/dist/cli/index2.mjs +4 -1
- package/dist/cli/list.mjs +10 -4
- package/dist/cli/prepare.mjs +6 -3
- package/dist/cli/run.mjs +7 -4
- package/dist/index.d.mts +52 -0
- package/dist/index.mjs +55 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +169 -0
- package/dist/node_modules/@poppinss/colors/package.json +116 -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 +717 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +63 -0
- package/dist/node_modules/@poppinss/exception/package.json +106 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1313 -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 +90 -0
- package/dist/node_modules/cookie/dist/index.js +239 -0
- package/dist/node_modules/cookie/package.json +42 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +63 -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/hookable/dist/index.mjs +290 -0
- package/dist/node_modules/hookable/package.json +49 -0
- package/dist/node_modules/kleur/index.js +110 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/klona/dist/index.mjs +81 -0
- package/dist/node_modules/klona/full/index.mjs +53 -0
- package/dist/node_modules/klona/package.json +74 -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/std-env/dist/index.mjs +1 -0
- package/dist/node_modules/std-env/package.json +46 -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 +638 -0
- package/dist/node_modules/ufo/package.json +47 -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/chunk-4L7RY2JA.js +42 -0
- package/dist/node_modules/youch/build/chunk-4XB2BYKC.js +85 -0
- package/dist/node_modules/youch/build/chunk-4YEN7HVQ.js +61 -0
- package/dist/node_modules/youch/build/chunk-EUJBVOYB.js +83 -0
- package/dist/node_modules/youch/build/chunk-HFSXRSKS.js +85 -0
- package/dist/node_modules/youch/build/chunk-JAN2TFI2.js +222 -0
- package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +6 -0
- package/dist/node_modules/youch/build/chunk-PINJDICN.js +72 -0
- package/dist/node_modules/youch/build/chunk-PUHGL6HA.js +41 -0
- package/dist/node_modules/youch/build/chunk-VE4LENUR.js +45 -0
- package/dist/node_modules/youch/build/index.js +352 -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 +144 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +74 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +220 -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 +16 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +20 -0
- package/dist/node_modules/youch/build/public/layout/style.css +431 -0
- package/dist/node_modules/youch/package.json +133 -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 +48 -73
- package/dist/presets/_nitro/runtime/{nitro-prerenderer.d.ts → nitro-prerenderer.d.mts} +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +12 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +5 -15
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +2 -2
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +18 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +102 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +3 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +12 -32
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +3 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +6 -38
- package/dist/{runtime/internal/utils.azure.d.ts → presets/azure/runtime/_utils.d.mts} +1 -1
- package/dist/{runtime/internal/utils.azure.mjs → presets/azure/runtime/_utils.mjs} +3 -4
- package/dist/presets/azure/runtime/azure-swa.mjs +11 -13
- package/dist/presets/bun/runtime/bun.mjs +13 -18
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +13 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +93 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +19 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +74 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +9 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +13 -97
- package/dist/presets/cloudflare/runtime/{cloudflare-pages.d.ts → cloudflare-pages.d.mts} +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +19 -27
- package/dist/{runtime/internal/timing.d.ts → presets/cloudflare/runtime/plugin.dev.d.mts} +1 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +89 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +11 -25
- package/dist/presets/deno/runtime/deno-server.d.mts +6 -0
- package/dist/presets/deno/runtime/deno-server.mjs +15 -21
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +3 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +8 -16
- package/dist/presets/netlify/runtime/netlify.mjs +16 -45
- package/dist/presets/node/runtime/{cluster.mjs → node-cluster.mjs} +1 -3
- package/dist/presets/node/runtime/node-middleware.d.mts +4 -0
- package/dist/presets/node/runtime/{node-listener.mjs → node-middleware.mjs} +3 -4
- package/dist/presets/node/runtime/node-server.mjs +3 -4
- package/dist/presets/standard/runtime/server.d.mts +5 -0
- package/dist/presets/standard/runtime/server.mjs +6 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +8 -12
- package/dist/presets/vercel/runtime/vercel.d.mts +8 -0
- package/dist/presets/vercel/runtime/vercel.mjs +11 -11
- package/dist/presets/winterjs/runtime/winterjs.mjs +22 -4
- package/dist/presets/{node/runtime/node-server.d.ts → zeabur/runtime/zeabur.d.mts} +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +2 -6
- package/dist/presets.mjs +2460 -0
- package/dist/runtime/index.d.mts +11 -0
- package/dist/runtime/index.mjs +8 -8
- package/dist/runtime/internal/app.d.mts +2 -0
- package/dist/runtime/internal/app.mjs +129 -128
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +82 -175
- package/dist/runtime/internal/{context.d.ts → context.d.mts} +3 -3
- package/dist/runtime/internal/context.mjs +6 -6
- package/dist/runtime/internal/error/dev.d.mts +9 -0
- package/dist/runtime/internal/error/dev.mjs +122 -0
- package/dist/runtime/internal/error/prod.d.mts +8 -0
- package/dist/runtime/internal/error/prod.mjs +62 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/index.d.mts +3 -0
- package/dist/runtime/internal/index.mjs +1 -14
- package/dist/runtime/internal/renderer.d.mts +3 -0
- package/dist/runtime/internal/renderer.mjs +29 -33
- package/dist/runtime/internal/route-rules.d.mts +8 -0
- package/dist/runtime/internal/route-rules.mjs +58 -63
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +23 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +24 -9
- 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 +21 -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 +7 -4
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +5 -4
- package/dist/runtime/internal/{utils.env.d.ts → runtime-config.d.mts} +4 -2
- package/dist/runtime/internal/{utils.env.mjs → runtime-config.mjs} +16 -6
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +24 -36
- package/dist/runtime/internal/storage.mjs +2 -1
- package/dist/runtime/internal/task.mjs +6 -6
- package/dist/runtime/internal/utils.d.mts +1 -0
- package/dist/runtime/internal/utils.mjs +1 -116
- package/dist/runtime/internal/vite/dev-entry.d.mts +1 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +6 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +362 -0
- package/dist/runtime/internal/vite/prod-setup.d.mts +4 -0
- package/dist/runtime/internal/vite/prod-setup.mjs +55 -0
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +4 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +4 -0
- package/dist/types/index.d.mts +2688 -138
- package/dist/vite.d.mts +59 -0
- package/dist/vite.mjs +68 -0
- package/lib/config.d.mts +9 -0
- package/lib/deps/h3.d.mts +1 -0
- package/lib/deps/h3.mjs +1 -0
- package/lib/deps/ofetch.mjs +1 -0
- package/lib/deps/ofetch.mts +1 -0
- package/lib/meta.d.mts +5 -0
- package/lib/meta.mjs +21 -0
- package/{runtime-meta.d.ts → lib/runtime-meta.d.mts} +1 -0
- package/{runtime-meta.mjs → lib/runtime-meta.mjs} +12 -4
- package/package.json +142 -160
- package/cli.d.ts +0 -1
- package/config.d.ts +0 -1
- package/core.d.ts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/config/index.d.mts +0 -6
- package/dist/config/index.d.ts +0 -6
- package/dist/core/index.d.mts +0 -30
- package/dist/core/index.d.ts +0 -30
- package/dist/core/index.mjs +0 -2456
- package/dist/kit/index.d.mts +0 -44
- package/dist/kit/index.d.ts +0 -44
- package/dist/kit/index.mjs +0 -71
- package/dist/meta/index.d.mts +0 -3
- package/dist/meta/index.d.ts +0 -3
- package/dist/meta/index.mjs +0 -3
- package/dist/presets/_all.gen.d.ts +0 -2
- package/dist/presets/_all.gen.mjs +0 -52
- package/dist/presets/_nitro/base-worker.d.ts +0 -2
- package/dist/presets/_nitro/base-worker.mjs +0 -25
- package/dist/presets/_nitro/nitro-dev.d.ts +0 -2
- package/dist/presets/_nitro/nitro-dev.mjs +0 -19
- package/dist/presets/_nitro/nitro-prerender.d.ts +0 -2
- package/dist/presets/_nitro/nitro-prerender.mjs +0 -17
- package/dist/presets/_nitro/preset.d.ts +0 -2
- package/dist/presets/_nitro/preset.mjs +0 -5
- package/dist/presets/_nitro/service-worker.d.ts +0 -2
- package/dist/presets/_nitro/service-worker.mjs +0 -110
- package/dist/presets/_resolve.d.ts +0 -8
- package/dist/presets/_resolve.mjs +0 -44
- package/dist/presets/_static/preset.d.ts +0 -2
- package/dist/presets/_static/preset.mjs +0 -69
- package/dist/presets/_types.gen.d.ts +0 -16
- package/dist/presets/alwaysdata/preset.d.ts +0 -2
- package/dist/presets/alwaysdata/preset.mjs +0 -14
- package/dist/presets/aws-amplify/preset.d.ts +0 -3
- package/dist/presets/aws-amplify/preset.mjs +0 -27
- package/dist/presets/aws-amplify/types.d.ts +0 -141
- package/dist/presets/aws-amplify/utils.d.ts +0 -2
- package/dist/presets/aws-amplify/utils.mjs +0 -82
- package/dist/presets/aws-lambda/preset.d.ts +0 -2
- package/dist/presets/aws-lambda/preset.mjs +0 -21
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.ts +0 -14
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.ts +0 -4
- package/dist/presets/azure/preset.d.ts +0 -3
- package/dist/presets/azure/preset.mjs +0 -44
- package/dist/presets/azure/runtime/azure-functions.mjs +0 -24
- package/dist/presets/azure/runtime/azure-swa.d.ts +0 -5
- package/dist/presets/azure/types.d.ts +0 -13
- package/dist/presets/azure/types.mjs +0 -0
- package/dist/presets/azure/utils.d.ts +0 -3
- package/dist/presets/azure/utils.mjs +0 -183
- package/dist/presets/bun/preset.d.ts +0 -2
- package/dist/presets/bun/preset.mjs +0 -17
- package/dist/presets/cleavr/preset.d.ts +0 -2
- package/dist/presets/cleavr/preset.mjs +0 -12
- package/dist/presets/cloudflare/preset.d.ts +0 -3
- package/dist/presets/cloudflare/preset.mjs +0 -145
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.ts +0 -13
- package/dist/presets/cloudflare/runtime/cloudflare-worker.mjs +0 -64
- package/dist/presets/cloudflare/types.d.ts +0 -89
- package/dist/presets/cloudflare/types.mjs +0 -0
- package/dist/presets/cloudflare/types.wrangler.d.ts +0 -974
- package/dist/presets/cloudflare/types.wrangler.mjs +0 -0
- package/dist/presets/cloudflare/utils.d.ts +0 -3
- package/dist/presets/cloudflare/utils.mjs +0 -163
- package/dist/presets/deno/preset.d.ts +0 -2
- package/dist/presets/deno/preset.mjs +0 -148
- package/dist/presets/deno/runtime/_deno-env-polyfill.d.ts +0 -0
- package/dist/presets/deno/runtime/_deno-env-polyfill.mjs +0 -1
- package/dist/presets/digitalocean/preset.d.ts +0 -2
- package/dist/presets/digitalocean/preset.mjs +0 -11
- package/dist/presets/edgio/preset.d.ts +0 -2
- package/dist/presets/edgio/preset.mjs +0 -95
- package/dist/presets/firebase/preset.d.ts +0 -3
- package/dist/presets/firebase/preset.mjs +0 -50
- package/dist/presets/firebase/runtime/firebase-gen-1.d.ts +0 -2
- package/dist/presets/firebase/runtime/firebase-gen-1.mjs +0 -7
- package/dist/presets/firebase/runtime/firebase-gen-2.d.ts +0 -2
- package/dist/presets/firebase/runtime/firebase-gen-2.mjs +0 -14
- package/dist/presets/firebase/runtime/firebase-gen-default.d.ts +0 -1
- package/dist/presets/firebase/runtime/firebase-gen-default.mjs +0 -1
- package/dist/presets/firebase/types.d.ts +0 -38
- package/dist/presets/firebase/types.mjs +0 -0
- package/dist/presets/firebase/utils.d.ts +0 -3
- package/dist/presets/firebase/utils.mjs +0 -50
- package/dist/presets/flightcontrol/preset.d.ts +0 -2
- package/dist/presets/flightcontrol/preset.mjs +0 -11
- package/dist/presets/heroku/preset.d.ts +0 -2
- package/dist/presets/heroku/preset.mjs +0 -11
- package/dist/presets/iis/preset.d.ts +0 -2
- package/dist/presets/iis/preset.mjs +0 -32
- package/dist/presets/iis/utils.d.ts +0 -3
- package/dist/presets/iis/utils.mjs +0 -161
- package/dist/presets/index.d.mts +0 -1
- package/dist/presets/index.d.ts +0 -2
- package/dist/presets/index.mjs +0 -1
- package/dist/presets/koyeb/preset.d.ts +0 -2
- package/dist/presets/koyeb/preset.mjs +0 -11
- package/dist/presets/netlify/legacy/preset.d.ts +0 -2
- package/dist/presets/netlify/legacy/preset.mjs +0 -143
- package/dist/presets/netlify/legacy/runtime/_deno-env-polyfill.d.ts +0 -0
- package/dist/presets/netlify/legacy/runtime/_deno-env-polyfill.mjs +0 -1
- package/dist/presets/netlify/legacy/runtime/netlify-builder.d.ts +0 -3
- package/dist/presets/netlify/legacy/runtime/netlify-builder.mjs +0 -5
- package/dist/presets/netlify/legacy/runtime/netlify-edge.d.ts +0 -2
- package/dist/presets/netlify/legacy/runtime/netlify-edge.mjs +0 -25
- package/dist/presets/netlify/legacy/runtime/netlify-lambda.d.ts +0 -3
- package/dist/presets/netlify/legacy/runtime/netlify-lambda.mjs +0 -38
- package/dist/presets/netlify/legacy/runtime/netlify.d.ts +0 -4
- package/dist/presets/netlify/legacy/runtime/netlify.mjs +0 -22
- package/dist/presets/netlify/legacy/utils.d.ts +0 -4
- package/dist/presets/netlify/legacy/utils.mjs +0 -113
- package/dist/presets/netlify/preset.d.ts +0 -3
- package/dist/presets/netlify/preset.mjs +0 -128
- package/dist/presets/netlify/runtime/_deno-env-polyfill.d.ts +0 -0
- package/dist/presets/netlify/runtime/_deno-env-polyfill.mjs +0 -1
- package/dist/presets/netlify/runtime/netlify-edge.d.ts +0 -2
- package/dist/presets/netlify/types.d.ts +0 -12
- package/dist/presets/netlify/types.mjs +0 -0
- package/dist/presets/netlify/utils.d.ts +0 -5
- package/dist/presets/netlify/utils.mjs +0 -94
- package/dist/presets/node/preset.d.ts +0 -2
- package/dist/presets/node/preset.mjs +0 -49
- package/dist/presets/node/runtime/cli.d.ts +0 -1
- package/dist/presets/node/runtime/cli.mjs +0 -22
- package/dist/presets/node/runtime/node-listener.d.ts +0 -6
- package/dist/presets/platform.sh/preset.d.ts +0 -2
- package/dist/presets/platform.sh/preset.mjs +0 -11
- package/dist/presets/render.com/preset.d.ts +0 -2
- package/dist/presets/render.com/preset.mjs +0 -11
- package/dist/presets/stormkit/preset.d.ts +0 -2
- package/dist/presets/stormkit/preset.mjs +0 -15
- package/dist/presets/vercel/preset.d.ts +0 -3
- package/dist/presets/vercel/preset.mjs +0 -104
- package/dist/presets/vercel/runtime/vercel-edge.d.ts +0 -2
- package/dist/presets/vercel/runtime/vercel-edge.mjs +0 -22
- package/dist/presets/vercel/runtime/vercel.d.ts +0 -4
- package/dist/presets/vercel/types.d.ts +0 -78
- package/dist/presets/vercel/types.mjs +0 -0
- package/dist/presets/vercel/utils.d.ts +0 -5
- package/dist/presets/vercel/utils.mjs +0 -186
- package/dist/presets/winterjs/preset.d.ts +0 -2
- package/dist/presets/winterjs/preset.mjs +0 -20
- package/dist/presets/winterjs/runtime/winterjs.d.ts +0 -1
- package/dist/presets/zeabur/preset.d.ts +0 -2
- package/dist/presets/zeabur/preset.mjs +0 -70
- package/dist/presets/zeabur/runtime/zeabur.d.ts +0 -4
- package/dist/rollup/index.d.mts +0 -5
- package/dist/rollup/index.d.ts +0 -5
- package/dist/rollup/index.mjs +0 -1673
- package/dist/runtime/index.d.ts +0 -12
- package/dist/runtime/internal/app.d.ts +0 -3
- package/dist/runtime/internal/cache.d.ts +0 -8
- package/dist/runtime/internal/client.mjs +0 -4
- package/dist/runtime/internal/config.d.ts +0 -5
- package/dist/runtime/internal/config.mjs +0 -45
- package/dist/runtime/internal/error.d.ts +0 -4
- package/dist/runtime/internal/error.mjs +0 -73
- package/dist/runtime/internal/index.d.ts +0 -6
- package/dist/runtime/internal/renderer.d.ts +0 -2
- package/dist/runtime/internal/route-rules.d.ts +0 -14
- package/dist/runtime/internal/routes/openapi.d.ts +0 -3
- package/dist/runtime/internal/routes/scalar.d.ts +0 -2
- package/dist/runtime/internal/routes/swagger.d.ts +0 -2
- package/dist/runtime/internal/static.d.ts +0 -2
- package/dist/runtime/internal/timing.mjs +0 -29
- package/dist/runtime/internal/utils.d.ts +0 -21
- package/dist/runtime/internal/utils.lambda.d.ts +0 -10
- package/dist/runtime/internal/utils.lambda.mjs +0 -30
- package/dist/shared/nitro.bra5i6ER.d.mts +0 -620
- package/dist/shared/nitro.bra5i6ER.d.ts +0 -620
- package/dist/types/index.d.ts +0 -260
- package/kit.d.ts +0 -1
- package/meta.d.ts +0 -1
- package/presets.d.ts +0 -1
- package/rollup.d.ts +0 -1
- package/runtime.d.ts +0 -1
- package/types.d.ts +0 -1
- /package/dist/presets/_nitro/runtime/{nitro-dev.d.ts → nitro-dev.d.mts} +0 -0
- /package/dist/presets/_nitro/runtime/{service-worker.d.ts → service-worker.d.mts} +0 -0
- /package/dist/presets/aws-amplify/runtime/{aws-amplify.d.ts → aws-amplify.d.mts} +0 -0
- /package/dist/presets/azure/runtime/{azure-functions.d.ts → azure-swa.d.mts} +0 -0
- /package/dist/presets/bun/runtime/{bun.d.ts → bun.d.mts} +0 -0
- /package/dist/presets/{cloudflare/runtime/cloudflare-worker.d.ts → deno/runtime/deno-deploy.d.mts} +0 -0
- /package/dist/presets/netlify/runtime/{netlify.d.ts → netlify.d.mts} +0 -0
- /package/dist/presets/node/runtime/{cluster.d.ts → node-cluster.d.mts} +0 -0
- /package/dist/presets/{deno/runtime/deno-server.d.ts → node/runtime/node-server.d.mts} +0 -0
- /package/dist/presets/stormkit/runtime/{stormkit.d.ts → stormkit.d.mts} +0 -0
- /package/dist/presets/{deno/runtime/deno-deploy.d.ts → winterjs/runtime/winterjs.d.mts} +0 -0
- /package/dist/runtime/internal/{database.d.ts → database.d.mts} +0 -0
- /package/dist/runtime/internal/{debug.d.ts → debug.d.mts} +0 -0
- /package/dist/{presets/_types.gen.mjs → runtime/internal/empty.d.mts} +0 -0
- /package/dist/{presets/aws-amplify/types.mjs → runtime/internal/empty.mjs} +0 -0
- /package/dist/runtime/internal/lib/{http-graceful-shutdown.d.ts → http-graceful-shutdown.d.mts} +0 -0
- /package/dist/runtime/internal/{meta.d.ts → meta.d.mts} +0 -0
- /package/dist/runtime/internal/{plugin.d.ts → plugin.d.mts} +0 -0
- /package/dist/runtime/internal/{shutdown.d.ts → shutdown.d.mts} +0 -0
- /package/dist/runtime/internal/{storage.d.ts → storage.d.mts} +0 -0
- /package/dist/runtime/internal/{task.d.ts → task.d.mts} +0 -0
- /package/dist/runtime/internal/{client.d.ts → vite/dev-worker.d.mts} +0 -0
- /package/{dist/config/index.mjs → lib/config.mjs} +0 -0
package/dist/presets.mjs
ADDED
|
@@ -0,0 +1,2460 @@
|
|
|
1
|
+
import { b as glob, Q as findNearestFile, h, R as readGitConfig, S as readPackageJSON, r as resolveModulePath, T as findFile, U as fileURLToPath, V as resolveCompatibilityDatesFromEnv, f as formatCompatibilityDate } from './_chunks/index.mjs';
|
|
2
|
+
import { kebabCase } from 'scule';
|
|
3
|
+
import { provider, isTest } from 'std-env';
|
|
4
|
+
import { presetsDir, runtimeDir } from 'nitro/runtime/meta';
|
|
5
|
+
import { resolve, relative as relative$1, dirname as dirname$1, extname } from 'node:path';
|
|
6
|
+
import { j as join, d as dirname, a as relative, r as resolve$1, n as normalize } from './_chunks/pathe.M-eThtNZ.mjs';
|
|
7
|
+
import fsp, { writeFile as writeFile$1, readFile } from 'node:fs/promises';
|
|
8
|
+
import { joinURL, withoutLeadingSlash, withTrailingSlash, withLeadingSlash, hasProtocol } from 'ufo';
|
|
9
|
+
import consola from 'consola';
|
|
10
|
+
import { colors } from 'consola/utils';
|
|
11
|
+
import { existsSync, promises } from 'node:fs';
|
|
12
|
+
import { defu } from 'defu';
|
|
13
|
+
import { parseTOML as Q } from './_chunks/toml.mjs';
|
|
14
|
+
import { version } from 'nitro/meta';
|
|
15
|
+
import { stringifyYAML as gr } from './_chunks/yaml.mjs';
|
|
16
|
+
import 'hookable';
|
|
17
|
+
import 'node:url';
|
|
18
|
+
import 'node:os';
|
|
19
|
+
import 'node:assert';
|
|
20
|
+
import 'node:process';
|
|
21
|
+
import 'node:v8';
|
|
22
|
+
import 'node:util';
|
|
23
|
+
import 'jiti';
|
|
24
|
+
import 'destr';
|
|
25
|
+
import 'fs';
|
|
26
|
+
import 'path';
|
|
27
|
+
import 'os';
|
|
28
|
+
import 'crypto';
|
|
29
|
+
import './_chunks/app.mjs';
|
|
30
|
+
import 'node:worker_threads';
|
|
31
|
+
import 'fs/promises';
|
|
32
|
+
import 'events';
|
|
33
|
+
import 'node:stream';
|
|
34
|
+
import 'h3';
|
|
35
|
+
import 'url';
|
|
36
|
+
import 'tty';
|
|
37
|
+
import 'util';
|
|
38
|
+
import 'stream';
|
|
39
|
+
import 'node:http';
|
|
40
|
+
import 'node:https';
|
|
41
|
+
import 'node:events';
|
|
42
|
+
import 'undici';
|
|
43
|
+
import 'youch-core';
|
|
44
|
+
import 'youch';
|
|
45
|
+
import 'source-map';
|
|
46
|
+
import 'srvx';
|
|
47
|
+
import 'klona/full';
|
|
48
|
+
import 'node:module';
|
|
49
|
+
import 'ofetch';
|
|
50
|
+
import 'klona';
|
|
51
|
+
import 'unstorage';
|
|
52
|
+
import 'ohash';
|
|
53
|
+
import 'module';
|
|
54
|
+
import 'node:zlib';
|
|
55
|
+
|
|
56
|
+
function defineNitroPreset(preset, meta) {
|
|
57
|
+
if (typeof preset !== "function" && preset.entry && preset.entry.startsWith(".")) {
|
|
58
|
+
preset.entry = resolve(presetsDir, preset.entry);
|
|
59
|
+
}
|
|
60
|
+
return { ...preset, _meta: meta };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const baseWorker = defineNitroPreset(
|
|
64
|
+
{
|
|
65
|
+
entry: null,
|
|
66
|
+
// Abstract
|
|
67
|
+
node: false,
|
|
68
|
+
minify: true,
|
|
69
|
+
noExternals: true,
|
|
70
|
+
rollupConfig: {
|
|
71
|
+
output: {
|
|
72
|
+
format: "iife",
|
|
73
|
+
generatedCode: {
|
|
74
|
+
symbols: true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
inlineDynamicImports: true
|
|
79
|
+
// iffe does not support code-splitting
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "base-worker"
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
const worker = [baseWorker];
|
|
86
|
+
|
|
87
|
+
const nitroDev = defineNitroPreset(
|
|
88
|
+
{
|
|
89
|
+
entry: "./_nitro/runtime/nitro-dev",
|
|
90
|
+
output: {
|
|
91
|
+
dir: "{{ buildDir }}/dev",
|
|
92
|
+
serverDir: "{{ buildDir }}/dev",
|
|
93
|
+
publicDir: "{{ buildDir }}/dev"
|
|
94
|
+
},
|
|
95
|
+
handlers: [
|
|
96
|
+
{
|
|
97
|
+
route: "/_nitro/tasks/**",
|
|
98
|
+
lazy: true,
|
|
99
|
+
handler: join(runtimeDir, "internal/routes/dev-tasks")
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
externals: { noTrace: true },
|
|
103
|
+
serveStatic: true,
|
|
104
|
+
inlineDynamicImports: true,
|
|
105
|
+
// externals plugin limitation
|
|
106
|
+
sourceMap: true
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "nitro-dev",
|
|
110
|
+
dev: true
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
const dev = [nitroDev];
|
|
114
|
+
|
|
115
|
+
const nitroPrerender = defineNitroPreset(
|
|
116
|
+
{
|
|
117
|
+
entry: "./_nitro/runtime/nitro-prerenderer",
|
|
118
|
+
serveStatic: true,
|
|
119
|
+
output: {
|
|
120
|
+
serverDir: "{{ buildDir }}/prerender"
|
|
121
|
+
},
|
|
122
|
+
externals: { noTrace: true }
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "nitro-prerender"
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
const prerender = [nitroPrerender];
|
|
129
|
+
|
|
130
|
+
const _nitro = [...worker, ...dev, ...prerender];
|
|
131
|
+
|
|
132
|
+
const _static = defineNitroPreset(
|
|
133
|
+
{
|
|
134
|
+
static: true,
|
|
135
|
+
output: {
|
|
136
|
+
dir: "{{ rootDir }}/.output",
|
|
137
|
+
publicDir: "{{ output.dir }}/public"
|
|
138
|
+
},
|
|
139
|
+
prerender: {
|
|
140
|
+
crawlLinks: true
|
|
141
|
+
},
|
|
142
|
+
commands: {
|
|
143
|
+
preview: "npx serve ./public"
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "static",
|
|
148
|
+
static: true
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
const githubPages = defineNitroPreset(
|
|
152
|
+
{
|
|
153
|
+
extends: "static",
|
|
154
|
+
commands: {
|
|
155
|
+
deploy: "npx gh-pages --dotfiles -d ./public"
|
|
156
|
+
},
|
|
157
|
+
prerender: {
|
|
158
|
+
routes: [
|
|
159
|
+
"/",
|
|
160
|
+
// https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-custom-404-page-for-your-github-pages-site
|
|
161
|
+
"/404.html"
|
|
162
|
+
]
|
|
163
|
+
},
|
|
164
|
+
hooks: {
|
|
165
|
+
async compiled(nitro) {
|
|
166
|
+
await fsp.writeFile(
|
|
167
|
+
join(nitro.options.output.publicDir, ".nojekyll"),
|
|
168
|
+
""
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "github-pages",
|
|
175
|
+
static: true
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
const gitlabPages = defineNitroPreset(
|
|
179
|
+
{
|
|
180
|
+
extends: "static",
|
|
181
|
+
prerender: {
|
|
182
|
+
routes: [
|
|
183
|
+
"/",
|
|
184
|
+
// https://docs.gitlab.com/ee/user/project/pages/introduction.html#custom-error-codes-pages
|
|
185
|
+
"/404.html"
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "gitlab-pages",
|
|
191
|
+
static: true
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
const _static$1 = [_static, githubPages, gitlabPages];
|
|
195
|
+
|
|
196
|
+
const alwaysdata = defineNitroPreset(
|
|
197
|
+
{
|
|
198
|
+
extends: "node-server",
|
|
199
|
+
serveStatic: true,
|
|
200
|
+
commands: {
|
|
201
|
+
deploy: "rsync -rRt --info=progress2 ./ [account]@ssh-[account].alwaysdata.net:www/my-app"
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "alwaysdata"
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
const _alwaysdata = [alwaysdata];
|
|
209
|
+
|
|
210
|
+
async function writeAmplifyFiles(nitro) {
|
|
211
|
+
const outDir = nitro.options.output.dir;
|
|
212
|
+
const routes = [];
|
|
213
|
+
let hasWildcardPublicAsset = false;
|
|
214
|
+
if (nitro.options.awsAmplify?.imageOptimization && !nitro.options.static) {
|
|
215
|
+
const { path, cacheControl } = nitro.options.awsAmplify?.imageOptimization || {};
|
|
216
|
+
if (path) {
|
|
217
|
+
routes.push({
|
|
218
|
+
path,
|
|
219
|
+
target: {
|
|
220
|
+
kind: "ImageOptimization",
|
|
221
|
+
cacheControl
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const computeTarget = nitro.options.static ? { kind: "Static" } : { kind: "Compute", src: "default" };
|
|
227
|
+
for (const publicAsset of nitro.options.publicAssets) {
|
|
228
|
+
if (!publicAsset.baseURL || publicAsset.baseURL === "/") {
|
|
229
|
+
hasWildcardPublicAsset = true;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
routes.push({
|
|
233
|
+
path: `${publicAsset.baseURL.replace(/\/$/, "")}/*`,
|
|
234
|
+
target: {
|
|
235
|
+
kind: "Static",
|
|
236
|
+
cacheControl: publicAsset.maxAge > 0 ? `public, max-age=${publicAsset.maxAge}, immutable` : void 0
|
|
237
|
+
},
|
|
238
|
+
fallback: publicAsset.fallthrough ? computeTarget : void 0
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
if (hasWildcardPublicAsset && !nitro.options.static) {
|
|
242
|
+
routes.push({
|
|
243
|
+
path: "/*.*",
|
|
244
|
+
target: {
|
|
245
|
+
kind: "Static"
|
|
246
|
+
},
|
|
247
|
+
fallback: computeTarget
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
routes.push({
|
|
251
|
+
path: "/*",
|
|
252
|
+
target: computeTarget,
|
|
253
|
+
fallback: hasWildcardPublicAsset && nitro.options.awsAmplify?.catchAllStaticFallback ? {
|
|
254
|
+
kind: "Static"
|
|
255
|
+
} : void 0
|
|
256
|
+
});
|
|
257
|
+
for (const route of routes) {
|
|
258
|
+
if (route.path !== "/*") {
|
|
259
|
+
route.path = joinURL(nitro.options.baseURL, route.path);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const deployManifest = {
|
|
263
|
+
version: 1,
|
|
264
|
+
routes,
|
|
265
|
+
imageSettings: nitro.options.awsAmplify?.imageSettings || void 0,
|
|
266
|
+
computeResources: nitro.options.static ? void 0 : [
|
|
267
|
+
{
|
|
268
|
+
name: "default",
|
|
269
|
+
entrypoint: "server.js",
|
|
270
|
+
runtime: nitro.options.awsAmplify?.runtime || "nodejs20.x"
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
framework: {
|
|
274
|
+
name: nitro.options.framework.name || "nitro",
|
|
275
|
+
version: nitro.options.framework.version || "0.0.0"
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
await writeFile$1(
|
|
279
|
+
resolve(outDir, "deploy-manifest.json"),
|
|
280
|
+
JSON.stringify(deployManifest, null, 2)
|
|
281
|
+
);
|
|
282
|
+
if (!nitro.options.static) {
|
|
283
|
+
await writeFile$1(
|
|
284
|
+
resolve(outDir, "compute/default/server.js"),
|
|
285
|
+
`import("./index.mjs")`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const awsAmplify = defineNitroPreset(
|
|
291
|
+
{
|
|
292
|
+
entry: "./aws-amplify/runtime/aws-amplify",
|
|
293
|
+
serveStatic: true,
|
|
294
|
+
output: {
|
|
295
|
+
dir: "{{ rootDir }}/.amplify-hosting",
|
|
296
|
+
serverDir: "{{ output.dir }}/compute/default",
|
|
297
|
+
publicDir: "{{ output.dir }}/static{{ baseURL }}"
|
|
298
|
+
},
|
|
299
|
+
commands: {
|
|
300
|
+
preview: "node ./compute/default/server.js"
|
|
301
|
+
},
|
|
302
|
+
hooks: {
|
|
303
|
+
async compiled(nitro) {
|
|
304
|
+
await writeAmplifyFiles(nitro);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: "aws-amplify",
|
|
310
|
+
stdName: "aws_amplify"
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
const _awsAmplify = [awsAmplify];
|
|
314
|
+
|
|
315
|
+
const awsLambda = defineNitroPreset(
|
|
316
|
+
{
|
|
317
|
+
entry: "./aws-lambda/runtime/aws-lambda",
|
|
318
|
+
awsLambda: {
|
|
319
|
+
streaming: false
|
|
320
|
+
},
|
|
321
|
+
hooks: {
|
|
322
|
+
"rollup:before": (nitro, rollupConfig) => {
|
|
323
|
+
if (nitro.options.awsLambda?.streaming) {
|
|
324
|
+
rollupConfig.input += "-streaming";
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
name: "aws-lambda"
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
const _awsLambda = [awsLambda];
|
|
334
|
+
|
|
335
|
+
function prettyPath(p, highlight = true) {
|
|
336
|
+
p = relative(process.cwd(), p);
|
|
337
|
+
return highlight ? colors.cyan(p) : p;
|
|
338
|
+
}
|
|
339
|
+
async function writeFile(file, contents, log = false) {
|
|
340
|
+
await fsp.mkdir(dirname(file), { recursive: true });
|
|
341
|
+
await fsp.writeFile(
|
|
342
|
+
file,
|
|
343
|
+
contents,
|
|
344
|
+
typeof contents === "string" ? "utf8" : void 0
|
|
345
|
+
);
|
|
346
|
+
if (log) {
|
|
347
|
+
consola.info("Generated", prettyPath(file));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function writeSWARoutes(nitro) {
|
|
352
|
+
const host = {
|
|
353
|
+
version: "2.0"
|
|
354
|
+
};
|
|
355
|
+
const supportedNodeVersions = /* @__PURE__ */ new Set(["20", "22"]);
|
|
356
|
+
let nodeVersion = "18";
|
|
357
|
+
try {
|
|
358
|
+
const currentNodeVersion = JSON.parse(
|
|
359
|
+
await fsp.readFile(join(nitro.options.rootDir, "package.json"), "utf8")
|
|
360
|
+
).engines.node;
|
|
361
|
+
if (supportedNodeVersions.has(currentNodeVersion)) {
|
|
362
|
+
nodeVersion = currentNodeVersion;
|
|
363
|
+
}
|
|
364
|
+
} catch {
|
|
365
|
+
const currentNodeVersion = process.versions.node.slice(0, 2);
|
|
366
|
+
if (supportedNodeVersions.has(currentNodeVersion)) {
|
|
367
|
+
nodeVersion = currentNodeVersion;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const config = {
|
|
371
|
+
...nitro.options.azure?.config,
|
|
372
|
+
// Overwrite routes for now, we will add existing routes after generating routes
|
|
373
|
+
routes: [],
|
|
374
|
+
platform: {
|
|
375
|
+
apiRuntime: `node:${nodeVersion}`,
|
|
376
|
+
...nitro.options.azure?.config?.platform
|
|
377
|
+
},
|
|
378
|
+
navigationFallback: {
|
|
379
|
+
rewrite: "/api/server",
|
|
380
|
+
...nitro.options.azure?.config?.navigationFallback
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const routeFiles = nitro._prerenderedRoutes || [];
|
|
384
|
+
const indexFileExists = routeFiles.some(
|
|
385
|
+
(route) => route.fileName === "/index.html"
|
|
386
|
+
);
|
|
387
|
+
if (!indexFileExists) {
|
|
388
|
+
config.routes.unshift(
|
|
389
|
+
{
|
|
390
|
+
route: "/index.html",
|
|
391
|
+
redirect: "/"
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
route: "/",
|
|
395
|
+
rewrite: "/api/server"
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
const suffix = "/index.html".length;
|
|
400
|
+
for (const { fileName } of routeFiles) {
|
|
401
|
+
if (!fileName || !fileName.endsWith("/index.html")) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
config.routes.unshift({
|
|
405
|
+
route: fileName.slice(0, -suffix) || "/",
|
|
406
|
+
rewrite: fileName
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
for (const { fileName } of routeFiles) {
|
|
410
|
+
if (!fileName || !fileName.endsWith(".html") || fileName.endsWith("index.html")) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const route = fileName.slice(0, -".html".length);
|
|
414
|
+
const existingRouteIndex = config.routes.findIndex(
|
|
415
|
+
(_route) => _route.route === route
|
|
416
|
+
);
|
|
417
|
+
if (existingRouteIndex !== -1) {
|
|
418
|
+
config.routes.splice(existingRouteIndex, 1);
|
|
419
|
+
}
|
|
420
|
+
config.routes.unshift({
|
|
421
|
+
route,
|
|
422
|
+
rewrite: fileName
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
if (nitro.options.azure?.config && "routes" in nitro.options.azure.config && Array.isArray(nitro.options.azure.config.routes)) {
|
|
426
|
+
for (const customRoute of nitro.options.azure.config.routes.reverse()) {
|
|
427
|
+
const existingRouteMatchIndex = config.routes.findIndex(
|
|
428
|
+
(value) => value.route === customRoute.route
|
|
429
|
+
);
|
|
430
|
+
if (existingRouteMatchIndex === -1) {
|
|
431
|
+
config.routes.unshift(customRoute);
|
|
432
|
+
} else {
|
|
433
|
+
config.routes[existingRouteMatchIndex] = customRoute;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const functionDefinition = {
|
|
438
|
+
entryPoint: "handle",
|
|
439
|
+
bindings: [
|
|
440
|
+
{
|
|
441
|
+
authLevel: "anonymous",
|
|
442
|
+
type: "httpTrigger",
|
|
443
|
+
direction: "in",
|
|
444
|
+
name: "req",
|
|
445
|
+
route: "{*url}",
|
|
446
|
+
methods: ["delete", "get", "head", "options", "patch", "post", "put"]
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
type: "http",
|
|
450
|
+
direction: "out",
|
|
451
|
+
name: "res"
|
|
452
|
+
}
|
|
453
|
+
]
|
|
454
|
+
};
|
|
455
|
+
await writeFile(
|
|
456
|
+
resolve$1(nitro.options.output.serverDir, "function.json"),
|
|
457
|
+
JSON.stringify(functionDefinition, null, 2)
|
|
458
|
+
);
|
|
459
|
+
await writeFile(
|
|
460
|
+
resolve$1(nitro.options.output.serverDir, "../host.json"),
|
|
461
|
+
JSON.stringify(host, null, 2)
|
|
462
|
+
);
|
|
463
|
+
const stubPackageJson = resolve$1(
|
|
464
|
+
nitro.options.output.serverDir,
|
|
465
|
+
"../package.json"
|
|
466
|
+
);
|
|
467
|
+
await writeFile(stubPackageJson, JSON.stringify({ private: true }));
|
|
468
|
+
await writeFile(
|
|
469
|
+
resolve$1(nitro.options.rootDir, "staticwebapp.config.json"),
|
|
470
|
+
JSON.stringify(config, null, 2)
|
|
471
|
+
);
|
|
472
|
+
if (!indexFileExists) {
|
|
473
|
+
const baseURLSegments = nitro.options.baseURL.split("/").filter(Boolean);
|
|
474
|
+
const relativePrefix = baseURLSegments.map(() => "..").join("/");
|
|
475
|
+
await writeFile(
|
|
476
|
+
resolve$1(
|
|
477
|
+
nitro.options.output.publicDir,
|
|
478
|
+
relativePrefix ? `${relativePrefix}/index.html` : "index.html"
|
|
479
|
+
),
|
|
480
|
+
""
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const azureSWA = defineNitroPreset(
|
|
486
|
+
{
|
|
487
|
+
entry: "./azure/runtime/azure-swa",
|
|
488
|
+
output: {
|
|
489
|
+
serverDir: "{{ output.dir }}/server/functions",
|
|
490
|
+
publicDir: "{{ output.dir }}/public/{{ baseURL }}"
|
|
491
|
+
},
|
|
492
|
+
commands: {
|
|
493
|
+
preview: "npx @azure/static-web-apps-cli start ./public --api-location ./server"
|
|
494
|
+
},
|
|
495
|
+
hooks: {
|
|
496
|
+
async compiled(ctx) {
|
|
497
|
+
await writeSWARoutes(ctx);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
name: "azure-swa",
|
|
503
|
+
stdName: "azure_static"
|
|
504
|
+
}
|
|
505
|
+
);
|
|
506
|
+
const _azure = [azureSWA];
|
|
507
|
+
|
|
508
|
+
const bun = defineNitroPreset(
|
|
509
|
+
{
|
|
510
|
+
entry: "./bun/runtime/bun",
|
|
511
|
+
serveStatic: true,
|
|
512
|
+
// https://bun.sh/docs/runtime/modules#resolution
|
|
513
|
+
exportConditions: ["bun", "node", "import", "default"],
|
|
514
|
+
commands: {
|
|
515
|
+
preview: "bun run ./server/index.mjs"
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: "bun"
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
const _bun = [bun];
|
|
523
|
+
|
|
524
|
+
const cleavr = defineNitroPreset(
|
|
525
|
+
{
|
|
526
|
+
extends: "node-server",
|
|
527
|
+
serveStatic: true
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
name: "cleavr",
|
|
531
|
+
stdName: "cleavr"
|
|
532
|
+
}
|
|
533
|
+
);
|
|
534
|
+
const _cleavr = [cleavr];
|
|
535
|
+
|
|
536
|
+
const builtnNodeModules$1 = [
|
|
537
|
+
"node:_http_agent",
|
|
538
|
+
"node:_http_client",
|
|
539
|
+
"node:_http_common",
|
|
540
|
+
// Missing exports: CRLF, HTTPParser, freeParser, isLenient, parsers, prepareError
|
|
541
|
+
"node:_http_incoming",
|
|
542
|
+
// Missing exports: readStart, readStop
|
|
543
|
+
"node:_http_outgoing",
|
|
544
|
+
"node:_http_server",
|
|
545
|
+
"node:_stream_duplex",
|
|
546
|
+
"node:_stream_passthrough",
|
|
547
|
+
"node:_stream_readable",
|
|
548
|
+
"node:_stream_transform",
|
|
549
|
+
"node:_stream_writable",
|
|
550
|
+
"node:_tls_common",
|
|
551
|
+
"node:_tls_wrap",
|
|
552
|
+
// Missing exports: Server, createServer
|
|
553
|
+
"node:assert",
|
|
554
|
+
// Missing exports: Assert, CallTracker
|
|
555
|
+
"node:assert/strict",
|
|
556
|
+
// Missing exports: Assert, CallTracker
|
|
557
|
+
"node:async_hooks",
|
|
558
|
+
"node:buffer",
|
|
559
|
+
"node:constants",
|
|
560
|
+
// Missing exports: O_DIRECT, O_NOATIME, RTLD_DEEPBIND, SIGPOLL, SIGPWR, SIGSTKFLT, defaultCipherList
|
|
561
|
+
"node:crypto",
|
|
562
|
+
// Missing exports: argon2, argon2Sync, decapsulate, encapsulate
|
|
563
|
+
"node:diagnostics_channel",
|
|
564
|
+
"node:dns",
|
|
565
|
+
// Missing exports: resolveTlsa
|
|
566
|
+
"node:dns/promises",
|
|
567
|
+
// Missing exports: resolveTlsa
|
|
568
|
+
"node:events",
|
|
569
|
+
// Missing exports: captureRejections, init
|
|
570
|
+
"node:fs",
|
|
571
|
+
// Missing exports: Utf8Stream, mkdtempDisposableSync
|
|
572
|
+
"node:fs/promises",
|
|
573
|
+
// Missing exports: mkdtempDisposable
|
|
574
|
+
"node:http",
|
|
575
|
+
"node:http2",
|
|
576
|
+
"node:https",
|
|
577
|
+
"node:module",
|
|
578
|
+
"node:net",
|
|
579
|
+
"node:os",
|
|
580
|
+
"node:path",
|
|
581
|
+
"node:path/posix",
|
|
582
|
+
"node:path/win32",
|
|
583
|
+
"node:process",
|
|
584
|
+
"node:querystring",
|
|
585
|
+
"node:stream",
|
|
586
|
+
"node:stream/consumers",
|
|
587
|
+
"node:stream/promises",
|
|
588
|
+
"node:stream/web",
|
|
589
|
+
"node:string_decoder",
|
|
590
|
+
"node:test",
|
|
591
|
+
// Missing exports: after, afterEach, assert, before, beforeEach, describe, it, only, run, skip, snapshot, suite, test, todo
|
|
592
|
+
"node:timers",
|
|
593
|
+
"node:timers/promises",
|
|
594
|
+
"node:tls",
|
|
595
|
+
// Missing exports: getCACertificates, setDefaultCACertificates
|
|
596
|
+
"node:url",
|
|
597
|
+
// Missing exports: URLPattern, fileURLToPathBuffer
|
|
598
|
+
"node:util",
|
|
599
|
+
// Missing exports: diff, setTraceSigInt
|
|
600
|
+
"node:util/types",
|
|
601
|
+
"node:zlib"
|
|
602
|
+
// Missing exports: ZstdCompress, ZstdDecompress, createZstdCompress, createZstdDecompress, zstdCompress, zstdCompressSync, zstdDecompress, zstdDecompressSync
|
|
603
|
+
];
|
|
604
|
+
|
|
605
|
+
const unencCfNodeCompat = {
|
|
606
|
+
meta: {
|
|
607
|
+
name: "nitro:cloudflare-node-compat"
|
|
608
|
+
},
|
|
609
|
+
external: builtnNodeModules$1,
|
|
610
|
+
alias: {
|
|
611
|
+
...Object.fromEntries(
|
|
612
|
+
builtnNodeModules$1.flatMap((m) => [
|
|
613
|
+
[m, m],
|
|
614
|
+
[m.replace("node:", ""), m]
|
|
615
|
+
])
|
|
616
|
+
)
|
|
617
|
+
},
|
|
618
|
+
inject: {
|
|
619
|
+
global: "unenv/polyfill/globalthis",
|
|
620
|
+
process: "node:process",
|
|
621
|
+
clearImmediate: ["node:timers", "clearImmediate"],
|
|
622
|
+
setImmediate: ["node:timers", "setImmediate"],
|
|
623
|
+
Buffer: ["node:buffer", "Buffer"]
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
const unenvCfExternals = {
|
|
627
|
+
meta: {
|
|
628
|
+
name: "nitro:cloudflare-externals"
|
|
629
|
+
},
|
|
630
|
+
external: [
|
|
631
|
+
"cloudflare:email",
|
|
632
|
+
"cloudflare:sockets",
|
|
633
|
+
"cloudflare:workers",
|
|
634
|
+
"cloudflare:workflows"
|
|
635
|
+
]
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
async function writeCFRoutes(nitro) {
|
|
639
|
+
const _cfPagesConfig = nitro.options.cloudflare?.pages || {};
|
|
640
|
+
const routes = {
|
|
641
|
+
version: _cfPagesConfig.routes?.version || 1,
|
|
642
|
+
include: _cfPagesConfig.routes?.include || ["/*"],
|
|
643
|
+
exclude: _cfPagesConfig.routes?.exclude || []
|
|
644
|
+
};
|
|
645
|
+
const writeRoutes = () => writeFile(
|
|
646
|
+
resolve$1(nitro.options.output.dir, "_routes.json"),
|
|
647
|
+
JSON.stringify(routes, void 0, 2),
|
|
648
|
+
true
|
|
649
|
+
);
|
|
650
|
+
if (_cfPagesConfig.defaultRoutes === false) {
|
|
651
|
+
await writeRoutes();
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const explicitPublicAssets = nitro.options.publicAssets.filter(
|
|
655
|
+
(dir, index, array) => {
|
|
656
|
+
if (dir.fallthrough || !dir.baseURL) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
const normalizedBase = withoutLeadingSlash(dir.baseURL);
|
|
660
|
+
return !array.some(
|
|
661
|
+
(otherDir, otherIndex) => otherIndex !== index && normalizedBase.startsWith(
|
|
662
|
+
withoutLeadingSlash(withTrailingSlash(otherDir.baseURL))
|
|
663
|
+
)
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
routes.exclude.push(
|
|
668
|
+
...explicitPublicAssets.map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/", "*")).sort(comparePaths)
|
|
669
|
+
);
|
|
670
|
+
const publicAssetFiles = await glob("**", {
|
|
671
|
+
cwd: nitro.options.output.dir,
|
|
672
|
+
absolute: false,
|
|
673
|
+
dot: true,
|
|
674
|
+
ignore: [
|
|
675
|
+
"_worker.js",
|
|
676
|
+
"_worker.js.map",
|
|
677
|
+
"nitro.json",
|
|
678
|
+
...routes.exclude.map(
|
|
679
|
+
(path) => withoutLeadingSlash(path.replace(/\/\*$/, "/**"))
|
|
680
|
+
)
|
|
681
|
+
]
|
|
682
|
+
});
|
|
683
|
+
routes.exclude.push(
|
|
684
|
+
...publicAssetFiles.map(
|
|
685
|
+
(i) => withLeadingSlash(i).replace(/\/index\.html$/, "").replace(/\.html$/, "") || "/"
|
|
686
|
+
).sort(comparePaths)
|
|
687
|
+
);
|
|
688
|
+
routes.exclude.splice(100 - routes.include.length);
|
|
689
|
+
await writeRoutes();
|
|
690
|
+
}
|
|
691
|
+
function comparePaths(a, b) {
|
|
692
|
+
return a.split("/").length - b.split("/").length || a.localeCompare(b);
|
|
693
|
+
}
|
|
694
|
+
async function writeCFHeaders(nitro, outdir) {
|
|
695
|
+
const headersPath = join(
|
|
696
|
+
outdir === "public" ? nitro.options.output.publicDir : nitro.options.output.dir,
|
|
697
|
+
"_headers"
|
|
698
|
+
);
|
|
699
|
+
const contents = [];
|
|
700
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
701
|
+
(a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
|
|
702
|
+
);
|
|
703
|
+
for (const [path, routeRules] of rules.filter(
|
|
704
|
+
([_, routeRules2]) => routeRules2.headers
|
|
705
|
+
)) {
|
|
706
|
+
const headers = [
|
|
707
|
+
joinURL(nitro.options.baseURL, path.replace("/**", "/*")),
|
|
708
|
+
...Object.entries({ ...routeRules.headers }).map(
|
|
709
|
+
([header, value]) => ` ${header}: ${value}`
|
|
710
|
+
)
|
|
711
|
+
].join("\n");
|
|
712
|
+
contents.push(headers);
|
|
713
|
+
}
|
|
714
|
+
if (existsSync(headersPath)) {
|
|
715
|
+
const currentHeaders = await readFile(headersPath, "utf8");
|
|
716
|
+
if (/^\/\* /m.test(currentHeaders)) {
|
|
717
|
+
nitro.logger.info(
|
|
718
|
+
"Not adding Nitro fallback to `_headers` (as an existing fallback was found)."
|
|
719
|
+
);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
nitro.logger.info(
|
|
723
|
+
"Adding Nitro fallback to `_headers` to handle all unmatched routes."
|
|
724
|
+
);
|
|
725
|
+
contents.unshift(currentHeaders);
|
|
726
|
+
}
|
|
727
|
+
await writeFile(headersPath, contents.join("\n"), true);
|
|
728
|
+
}
|
|
729
|
+
async function writeCFPagesRedirects(nitro) {
|
|
730
|
+
const redirectsPath = join(nitro.options.output.dir, "_redirects");
|
|
731
|
+
const staticFallback = existsSync(
|
|
732
|
+
join(nitro.options.output.publicDir, "404.html")
|
|
733
|
+
) ? `${joinURL(nitro.options.baseURL, "/*")} ${joinURL(nitro.options.baseURL, "/404.html")} 404` : "";
|
|
734
|
+
const contents = [staticFallback];
|
|
735
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
736
|
+
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
|
|
737
|
+
);
|
|
738
|
+
for (const [key, routeRules] of rules.filter(
|
|
739
|
+
([_, routeRules2]) => routeRules2.redirect
|
|
740
|
+
)) {
|
|
741
|
+
const code = routeRules.redirect.status;
|
|
742
|
+
const from = joinURL(nitro.options.baseURL, key.replace("/**", "/*"));
|
|
743
|
+
const to = hasProtocol(routeRules.redirect.to, { acceptRelative: true }) ? routeRules.redirect.to : joinURL(nitro.options.baseURL, routeRules.redirect.to);
|
|
744
|
+
contents.unshift(`${from} ${to} ${code}`);
|
|
745
|
+
}
|
|
746
|
+
if (existsSync(redirectsPath)) {
|
|
747
|
+
const currentRedirects = await readFile(redirectsPath, "utf8");
|
|
748
|
+
if (/^\/\* /m.test(currentRedirects)) {
|
|
749
|
+
nitro.logger.info(
|
|
750
|
+
"Not adding Nitro fallback to `_redirects` (as an existing fallback was found)."
|
|
751
|
+
);
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
nitro.logger.info(
|
|
755
|
+
"Adding Nitro fallback to `_redirects` to handle all unmatched routes."
|
|
756
|
+
);
|
|
757
|
+
contents.unshift(currentRedirects);
|
|
758
|
+
}
|
|
759
|
+
await writeFile(redirectsPath, contents.join("\n"), true);
|
|
760
|
+
}
|
|
761
|
+
async function enableNodeCompat(nitro) {
|
|
762
|
+
nitro.options.cloudflare ??= {};
|
|
763
|
+
if (nitro.options.cloudflare.deployConfig === void 0 && provider === "cloudflare_workers") {
|
|
764
|
+
nitro.options.cloudflare.deployConfig = true;
|
|
765
|
+
}
|
|
766
|
+
if (nitro.options.cloudflare.nodeCompat === void 0) {
|
|
767
|
+
const { config } = await readWranglerConfig(nitro);
|
|
768
|
+
const userCompatibilityFlags = new Set(config?.compatibility_flags || []);
|
|
769
|
+
if (userCompatibilityFlags.has("nodejs_compat") || userCompatibilityFlags.has("nodejs_compat_v2") || nitro.options.cloudflare.deployConfig) {
|
|
770
|
+
nitro.options.cloudflare.nodeCompat = true;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (!nitro.options.cloudflare.nodeCompat) {
|
|
774
|
+
if (nitro.options.cloudflare.nodeCompat === void 0) {
|
|
775
|
+
nitro.logger.warn("[cloudflare] Node.js compatibility is not enabled.");
|
|
776
|
+
}
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
nitro.options.unenv.push(unencCfNodeCompat);
|
|
780
|
+
}
|
|
781
|
+
const extensionParsers = {
|
|
782
|
+
".json": h,
|
|
783
|
+
".jsonc": h,
|
|
784
|
+
".toml": Q
|
|
785
|
+
};
|
|
786
|
+
async function readWranglerConfig(nitro) {
|
|
787
|
+
const configPath = await findNearestFile(
|
|
788
|
+
["wrangler.json", "wrangler.jsonc", "wrangler.toml"],
|
|
789
|
+
{
|
|
790
|
+
startingFrom: nitro.options.rootDir
|
|
791
|
+
}
|
|
792
|
+
).catch(() => void 0);
|
|
793
|
+
if (!configPath) {
|
|
794
|
+
return {};
|
|
795
|
+
}
|
|
796
|
+
const userConfigText = await readFile(configPath, "utf8");
|
|
797
|
+
const parser = extensionParsers[extname(configPath)];
|
|
798
|
+
if (!parser) {
|
|
799
|
+
throw new Error(`Unsupported config file format: ${configPath}`);
|
|
800
|
+
}
|
|
801
|
+
const config = parser(userConfigText);
|
|
802
|
+
return { configPath, config };
|
|
803
|
+
}
|
|
804
|
+
async function writeWranglerConfig(nitro, cfTarget) {
|
|
805
|
+
if (!nitro.options.cloudflare?.deployConfig) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
const wranglerConfigDir = nitro.options.output.serverDir;
|
|
809
|
+
const wranglerConfigPath = join(wranglerConfigDir, "wrangler.json");
|
|
810
|
+
const defaults = {};
|
|
811
|
+
const overrides = {};
|
|
812
|
+
defaults.compatibility_date = nitro.options.compatibilityDate.cloudflare || nitro.options.compatibilityDate.default;
|
|
813
|
+
if (cfTarget === "pages") {
|
|
814
|
+
overrides.pages_build_output_dir = relative$1(
|
|
815
|
+
wranglerConfigDir,
|
|
816
|
+
nitro.options.output.dir
|
|
817
|
+
);
|
|
818
|
+
} else {
|
|
819
|
+
overrides.main = relative$1(
|
|
820
|
+
wranglerConfigDir,
|
|
821
|
+
join(nitro.options.output.serverDir, "index.mjs")
|
|
822
|
+
);
|
|
823
|
+
overrides.assets = {
|
|
824
|
+
binding: "ASSETS",
|
|
825
|
+
directory: relative$1(
|
|
826
|
+
wranglerConfigDir,
|
|
827
|
+
resolve$1(
|
|
828
|
+
nitro.options.output.publicDir,
|
|
829
|
+
"..".repeat(nitro.options.baseURL.split("/").filter(Boolean).length)
|
|
830
|
+
)
|
|
831
|
+
)
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
const { config: userConfig = {} } = await readWranglerConfig(nitro);
|
|
835
|
+
const ctxConfig = nitro.options.cloudflare?.wrangler || {};
|
|
836
|
+
for (const key in overrides) {
|
|
837
|
+
if (key in userConfig || key in ctxConfig) {
|
|
838
|
+
nitro.logger.warn(
|
|
839
|
+
`[cloudflare] Wrangler config \`${key}\`${key in ctxConfig ? "set by config or modules" : ""} is overridden and will be ignored.`
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
const wranglerConfig = defu(
|
|
844
|
+
overrides,
|
|
845
|
+
ctxConfig,
|
|
846
|
+
userConfig,
|
|
847
|
+
defaults
|
|
848
|
+
);
|
|
849
|
+
if (!wranglerConfig.name) {
|
|
850
|
+
wranglerConfig.name = await generateWorkerName(nitro);
|
|
851
|
+
nitro.logger.info(
|
|
852
|
+
`Using auto generated worker name: \`${wranglerConfig.name}\``
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
const compatFlags = new Set(wranglerConfig.compatibility_flags || []);
|
|
856
|
+
if (nitro.options.cloudflare?.nodeCompat) {
|
|
857
|
+
if (compatFlags.has("nodejs_compat_v2") && compatFlags.has("no_nodejs_compat_v2")) {
|
|
858
|
+
nitro.logger.warn(
|
|
859
|
+
"[cloudflare] Wrangler config `compatibility_flags` contains both `nodejs_compat_v2` and `no_nodejs_compat_v2`. Ignoring `nodejs_compat_v2`."
|
|
860
|
+
);
|
|
861
|
+
compatFlags.delete("nodejs_compat_v2");
|
|
862
|
+
}
|
|
863
|
+
if (compatFlags.has("nodejs_compat_v2")) {
|
|
864
|
+
nitro.logger.warn(
|
|
865
|
+
"[cloudflare] Please consider replacing `nodejs_compat_v2` with `nodejs_compat` in your `compatibility_flags` or USE IT AT YOUR OWN RISK as it can cause issues with nitro."
|
|
866
|
+
);
|
|
867
|
+
} else {
|
|
868
|
+
compatFlags.add("nodejs_compat");
|
|
869
|
+
compatFlags.add("no_nodejs_compat_v2");
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
wranglerConfig.compatibility_flags = [...compatFlags];
|
|
873
|
+
await writeFile(
|
|
874
|
+
wranglerConfigPath,
|
|
875
|
+
JSON.stringify(wranglerConfig, null, 2),
|
|
876
|
+
true
|
|
877
|
+
);
|
|
878
|
+
const configPath = join(
|
|
879
|
+
nitro.options.rootDir,
|
|
880
|
+
".wrangler/deploy/config.json"
|
|
881
|
+
);
|
|
882
|
+
await writeFile(
|
|
883
|
+
configPath,
|
|
884
|
+
JSON.stringify({
|
|
885
|
+
configPath: relative$1(dirname$1(configPath), wranglerConfigPath)
|
|
886
|
+
}),
|
|
887
|
+
true
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
async function generateWorkerName(nitro) {
|
|
891
|
+
const gitConfig = await readGitConfig(nitro.options.rootDir).catch(
|
|
892
|
+
() => void 0
|
|
893
|
+
);
|
|
894
|
+
const gitRepo = gitConfig?.remote?.origin?.url?.replace(/\.git$/, "").match(/[/:]([^/]+\/[^/]+)$/)?.[1];
|
|
895
|
+
const pkgJSON = await readPackageJSON(nitro.options.rootDir).catch(
|
|
896
|
+
() => void 0
|
|
897
|
+
);
|
|
898
|
+
const pkgName = pkgJSON?.name;
|
|
899
|
+
const subpath = relative$1(nitro.options.workspaceDir, nitro.options.rootDir);
|
|
900
|
+
return `${gitRepo || pkgName}/${subpath}`.toLowerCase().replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
async function cloudflareDevModule(nitro) {
|
|
904
|
+
if (!nitro.options.dev) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const wranglerPath = await resolveModulePath("wrangler", {
|
|
908
|
+
from: nitro.options.nodeModulesDirs,
|
|
909
|
+
try: true
|
|
910
|
+
});
|
|
911
|
+
if (!wranglerPath) {
|
|
912
|
+
nitro.logger.warn(
|
|
913
|
+
"Wrangler is not installed. Please install it using `npx nypm i wrangler` to enable dev emulation."
|
|
914
|
+
);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
const config = {
|
|
918
|
+
// compatibility with legacy nitro-cloudflare-dev module
|
|
919
|
+
...nitro.options.cloudflareDev,
|
|
920
|
+
...nitro.options.cloudflare?.dev
|
|
921
|
+
};
|
|
922
|
+
let configPath = config.configPath;
|
|
923
|
+
if (!configPath) {
|
|
924
|
+
configPath = await findFile(
|
|
925
|
+
["wrangler.json", "wrangler.jsonc", "wrangler.toml"],
|
|
926
|
+
{
|
|
927
|
+
startingFrom: nitro.options.srcDir
|
|
928
|
+
}
|
|
929
|
+
).catch(() => void 0);
|
|
930
|
+
}
|
|
931
|
+
const persistDir = resolve(
|
|
932
|
+
nitro.options.rootDir,
|
|
933
|
+
config.persistDir || ".wrangler/state/v3"
|
|
934
|
+
);
|
|
935
|
+
const gitIgnorePath = await findFile(".gitignore", {
|
|
936
|
+
startingFrom: nitro.options.rootDir
|
|
937
|
+
}).catch(() => void 0);
|
|
938
|
+
if (gitIgnorePath && persistDir === ".wrangler/state/v3") {
|
|
939
|
+
const gitIgnore = await promises.readFile(gitIgnorePath, "utf8");
|
|
940
|
+
if (!gitIgnore.includes(".wrangler/state/v3")) {
|
|
941
|
+
await promises.writeFile(gitIgnorePath, gitIgnore + "\n.wrangler/state/v3\n").catch(() => {
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
nitro.options.runtimeConfig.wrangler = {
|
|
946
|
+
...nitro.options.runtimeConfig.wrangler,
|
|
947
|
+
configPath,
|
|
948
|
+
persistDir,
|
|
949
|
+
environment: config.environment
|
|
950
|
+
};
|
|
951
|
+
nitro.options.externals.inline = nitro.options.externals.inline || [];
|
|
952
|
+
nitro.options.externals.inline.push(
|
|
953
|
+
fileURLToPath(new URL("runtime/", import.meta.url))
|
|
954
|
+
);
|
|
955
|
+
nitro.options.plugins = nitro.options.plugins || [];
|
|
956
|
+
nitro.options.plugins.push(
|
|
957
|
+
fileURLToPath(new URL("runtime/plugin.dev", import.meta.url))
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
const cloudflarePages = defineNitroPreset(
|
|
962
|
+
{
|
|
963
|
+
extends: "base-worker",
|
|
964
|
+
entry: "./cloudflare/runtime/cloudflare-pages",
|
|
965
|
+
exportConditions: ["workerd"],
|
|
966
|
+
commands: {
|
|
967
|
+
preview: "npx wrangler --cwd ./ pages dev",
|
|
968
|
+
deploy: "npx wrangler --cwd ./ pages deploy"
|
|
969
|
+
},
|
|
970
|
+
output: {
|
|
971
|
+
dir: "{{ rootDir }}/dist",
|
|
972
|
+
publicDir: "{{ output.dir }}/{{ baseURL }}",
|
|
973
|
+
serverDir: "{{ output.dir }}/_worker.js"
|
|
974
|
+
},
|
|
975
|
+
unenv: [unenvCfExternals],
|
|
976
|
+
alias: {
|
|
977
|
+
// Hotfix: Cloudflare appends /index.html if mime is not found and things like ico are not in standard lite.js!
|
|
978
|
+
// https://github.com/nitrojs/nitro/pull/933
|
|
979
|
+
_mime: "mime/index.js"
|
|
980
|
+
},
|
|
981
|
+
wasm: {
|
|
982
|
+
lazy: false,
|
|
983
|
+
esmImport: true
|
|
984
|
+
},
|
|
985
|
+
rollupConfig: {
|
|
986
|
+
output: {
|
|
987
|
+
entryFileNames: "index.js",
|
|
988
|
+
format: "esm",
|
|
989
|
+
inlineDynamicImports: false
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
hooks: {
|
|
993
|
+
"build:before": async (nitro) => {
|
|
994
|
+
await enableNodeCompat(nitro);
|
|
995
|
+
},
|
|
996
|
+
async compiled(nitro) {
|
|
997
|
+
await writeWranglerConfig(nitro, "pages");
|
|
998
|
+
await writeCFRoutes(nitro);
|
|
999
|
+
await writeCFHeaders(nitro, "output");
|
|
1000
|
+
await writeCFPagesRedirects(nitro);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
name: "cloudflare-pages",
|
|
1006
|
+
stdName: "cloudflare_pages"
|
|
1007
|
+
}
|
|
1008
|
+
);
|
|
1009
|
+
const cloudflarePagesStatic = defineNitroPreset(
|
|
1010
|
+
{
|
|
1011
|
+
extends: "static",
|
|
1012
|
+
output: {
|
|
1013
|
+
dir: "{{ rootDir }}/dist",
|
|
1014
|
+
publicDir: "{{ output.dir }}/{{ baseURL }}"
|
|
1015
|
+
},
|
|
1016
|
+
commands: {
|
|
1017
|
+
preview: "npx wrangler --cwd ./ pages dev",
|
|
1018
|
+
deploy: "npx wrangler --cwd ./ pages deploy"
|
|
1019
|
+
},
|
|
1020
|
+
hooks: {
|
|
1021
|
+
async compiled(nitro) {
|
|
1022
|
+
await writeCFHeaders(nitro, "output");
|
|
1023
|
+
await writeCFPagesRedirects(nitro);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
name: "cloudflare-pages-static",
|
|
1029
|
+
stdName: "cloudflare_pages",
|
|
1030
|
+
static: true
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
const cloudflareDev = defineNitroPreset(
|
|
1034
|
+
{
|
|
1035
|
+
extends: "nitro-dev",
|
|
1036
|
+
modules: [cloudflareDevModule]
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
name: "cloudflare-dev",
|
|
1040
|
+
aliases: ["cloudflare-module", "cloudflare-durable", "cloudflare-pages"],
|
|
1041
|
+
compatibilityDate: "2025-07-13",
|
|
1042
|
+
dev: true
|
|
1043
|
+
}
|
|
1044
|
+
);
|
|
1045
|
+
const cloudflareModule = defineNitroPreset(
|
|
1046
|
+
{
|
|
1047
|
+
extends: "base-worker",
|
|
1048
|
+
entry: "./cloudflare/runtime/cloudflare-module",
|
|
1049
|
+
output: {
|
|
1050
|
+
publicDir: "{{ output.dir }}/public/{{ baseURL }}"
|
|
1051
|
+
},
|
|
1052
|
+
exportConditions: ["workerd"],
|
|
1053
|
+
commands: {
|
|
1054
|
+
preview: "npx wrangler --cwd ./ dev",
|
|
1055
|
+
deploy: "npx wrangler --cwd ./ deploy"
|
|
1056
|
+
},
|
|
1057
|
+
unenv: [unenvCfExternals],
|
|
1058
|
+
rollupConfig: {
|
|
1059
|
+
output: {
|
|
1060
|
+
format: "esm",
|
|
1061
|
+
exports: "named",
|
|
1062
|
+
inlineDynamicImports: false
|
|
1063
|
+
}
|
|
1064
|
+
},
|
|
1065
|
+
wasm: {
|
|
1066
|
+
lazy: false,
|
|
1067
|
+
esmImport: true
|
|
1068
|
+
},
|
|
1069
|
+
hooks: {
|
|
1070
|
+
"build:before": async (nitro) => {
|
|
1071
|
+
await enableNodeCompat(nitro);
|
|
1072
|
+
},
|
|
1073
|
+
async compiled(nitro) {
|
|
1074
|
+
await writeWranglerConfig(nitro, "module");
|
|
1075
|
+
await writeCFHeaders(nitro, "public");
|
|
1076
|
+
await writeFile(
|
|
1077
|
+
resolve$1(nitro.options.output.dir, "package.json"),
|
|
1078
|
+
JSON.stringify({ private: true, main: "./server/index.mjs" }, null, 2)
|
|
1079
|
+
);
|
|
1080
|
+
await writeFile(
|
|
1081
|
+
resolve$1(nitro.options.output.dir, "package-lock.json"),
|
|
1082
|
+
JSON.stringify({ lockfileVersion: 1 }, null, 2)
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
name: "cloudflare-module",
|
|
1089
|
+
stdName: "cloudflare_workers"
|
|
1090
|
+
}
|
|
1091
|
+
);
|
|
1092
|
+
const cloudflareDurable = defineNitroPreset(
|
|
1093
|
+
{
|
|
1094
|
+
extends: "cloudflare-module",
|
|
1095
|
+
entry: "./cloudflare/runtime/cloudflare-durable"
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
name: "cloudflare-durable"
|
|
1099
|
+
}
|
|
1100
|
+
);
|
|
1101
|
+
const _cloudflare = [
|
|
1102
|
+
cloudflarePages,
|
|
1103
|
+
cloudflarePagesStatic,
|
|
1104
|
+
cloudflareModule,
|
|
1105
|
+
cloudflareDurable,
|
|
1106
|
+
cloudflareDev
|
|
1107
|
+
];
|
|
1108
|
+
|
|
1109
|
+
const builtnNodeModules = [
|
|
1110
|
+
"node:_http_agent",
|
|
1111
|
+
"node:_http_common",
|
|
1112
|
+
// Missing exports: freeParser, isLenient, parsers, prepareError
|
|
1113
|
+
"node:_http_outgoing",
|
|
1114
|
+
"node:_http_server",
|
|
1115
|
+
// Missing exports: Server, ServerResponse, httpServerPreClose, kConnectionsCheckingInterval, kServerResponse, setupConnectionsTracking, storeHTTPOptions
|
|
1116
|
+
"node:_stream_duplex",
|
|
1117
|
+
// Missing exports: from, fromWeb, toWeb
|
|
1118
|
+
"node:_stream_passthrough",
|
|
1119
|
+
"node:_stream_readable",
|
|
1120
|
+
// Missing exports: ReadableState, from, fromWeb, toWeb, wrap
|
|
1121
|
+
"node:_stream_transform",
|
|
1122
|
+
"node:_stream_writable",
|
|
1123
|
+
// Missing exports: WritableState, fromWeb, toWeb
|
|
1124
|
+
"node:_tls_common",
|
|
1125
|
+
// Missing exports: SecureContext, translatePeerCertificate
|
|
1126
|
+
"node:_tls_wrap",
|
|
1127
|
+
"node:assert",
|
|
1128
|
+
// Missing exports: Assert, CallTracker, partialDeepStrictEqual
|
|
1129
|
+
"node:assert/strict",
|
|
1130
|
+
// Missing exports: Assert, CallTracker, partialDeepStrictEqual
|
|
1131
|
+
"node:async_hooks",
|
|
1132
|
+
"node:buffer",
|
|
1133
|
+
// Missing exports: File, resolveObjectURL
|
|
1134
|
+
"node:child_process",
|
|
1135
|
+
"node:cluster",
|
|
1136
|
+
"node:console",
|
|
1137
|
+
// Missing exports: context, createTask
|
|
1138
|
+
"node:constants",
|
|
1139
|
+
// Missing exports: O_DIRECT, O_NOATIME, defaultCipherList
|
|
1140
|
+
"node:crypto",
|
|
1141
|
+
// Missing exports: argon2, argon2Sync, decapsulate, encapsulate
|
|
1142
|
+
"node:dgram",
|
|
1143
|
+
"node:diagnostics_channel",
|
|
1144
|
+
// Missing exports: Channel
|
|
1145
|
+
"node:dns",
|
|
1146
|
+
// Missing exports: getDefaultResultOrder, lookupService, resolveTlsa
|
|
1147
|
+
"node:dns/promises",
|
|
1148
|
+
// Missing exports: getDefaultResultOrder, lookupService, resolveTlsa
|
|
1149
|
+
"node:domain",
|
|
1150
|
+
"node:events",
|
|
1151
|
+
// Missing exports: captureRejections, getMaxListeners, init, usingDomains
|
|
1152
|
+
"node:fs",
|
|
1153
|
+
// Missing exports: FileReadStream, FileWriteStream, Utf8Stream, fchmod, fchmodSync, fchown, fchownSync, glob, globSync, lchmod, lchmodSync, lchown, lchownSync, mkdtempDisposableSync, openAsBlob
|
|
1154
|
+
"node:fs/promises",
|
|
1155
|
+
// Missing exports: glob, lchmod, lchown, lutimes, mkdtempDisposable, statfs
|
|
1156
|
+
"node:http",
|
|
1157
|
+
// Missing exports: CloseEvent, MessageEvent, WebSocket, setMaxIdleHTTPParsers
|
|
1158
|
+
"node:http2",
|
|
1159
|
+
// Missing exports: performServerHandshake
|
|
1160
|
+
"node:https",
|
|
1161
|
+
"node:inspector",
|
|
1162
|
+
// Missing exports: NetworkResources
|
|
1163
|
+
"node:inspector/promises",
|
|
1164
|
+
// Missing exports: NetworkResources
|
|
1165
|
+
"node:module",
|
|
1166
|
+
// Missing exports: SourceMap, constants, enableCompileCache, findPackageJSON, flushCompileCache, getCompileCacheDir, getSourceMapsSupport, registerHooks, runMain, setSourceMapsSupport, stripTypeScriptTypes, syncBuiltinESMExports
|
|
1167
|
+
"node:net",
|
|
1168
|
+
"node:os",
|
|
1169
|
+
"node:path",
|
|
1170
|
+
// Missing exports: matchesGlob
|
|
1171
|
+
"node:path/posix",
|
|
1172
|
+
// Missing exports: matchesGlob
|
|
1173
|
+
"node:path/win32",
|
|
1174
|
+
// Missing exports: matchesGlob
|
|
1175
|
+
"node:perf_hooks",
|
|
1176
|
+
// Missing exports: Performance, PerformanceMark, PerformanceMeasure, PerformanceObserverEntryList, PerformanceResourceTiming, createHistogram
|
|
1177
|
+
"node:process",
|
|
1178
|
+
// Missing exports: availableMemory, binding, config, constrainedMemory, debugPort, domain, execve, exitCode, features, finalization, getActiveResourcesInfo, getgroups, hasUncaughtExceptionCaptureCallback, initgroups, loadEnvFile, moduleLoadList, openStdin, ppid, reallyExit, ref, release, report, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, setegid, seteuid, setgid, setgroups, setuid, sourceMapsEnabled, threadCpuUsage, title, unref, uptime
|
|
1179
|
+
"node:punycode",
|
|
1180
|
+
"node:querystring",
|
|
1181
|
+
"node:readline",
|
|
1182
|
+
"node:readline/promises",
|
|
1183
|
+
"node:repl",
|
|
1184
|
+
// Missing exports: Recoverable, isValidSyntax, writer
|
|
1185
|
+
"node:sqlite",
|
|
1186
|
+
// Missing exports: Session, StatementSync, backup
|
|
1187
|
+
"node:stream",
|
|
1188
|
+
// Missing exports: destroy, promises
|
|
1189
|
+
"node:stream/consumers",
|
|
1190
|
+
"node:stream/promises",
|
|
1191
|
+
"node:stream/web",
|
|
1192
|
+
"node:string_decoder",
|
|
1193
|
+
"node:sys",
|
|
1194
|
+
// Missing exports: MIMEParams, MIMEType, diff, getCallSite, getSystemErrorMap, getSystemErrorMessage, parseEnv, setTraceSigInt, transferableAbortController, transferableAbortSignal
|
|
1195
|
+
"node:test",
|
|
1196
|
+
// Missing exports: assert, only, skip, snapshot, todo
|
|
1197
|
+
"node:timers",
|
|
1198
|
+
"node:timers/promises",
|
|
1199
|
+
"node:tls",
|
|
1200
|
+
// Missing exports: SecureContext, convertALPNProtocols, getCACertificates, setDefaultCACertificates
|
|
1201
|
+
"node:trace_events",
|
|
1202
|
+
"node:tty",
|
|
1203
|
+
"node:url",
|
|
1204
|
+
// Missing exports: URLPattern, fileURLToPathBuffer
|
|
1205
|
+
"node:util",
|
|
1206
|
+
// Missing exports: MIMEParams, MIMEType, diff, getCallSite, getSystemErrorMap, getSystemErrorMessage, parseEnv, setTraceSigInt, transferableAbortController, transferableAbortSignal
|
|
1207
|
+
"node:util/types",
|
|
1208
|
+
// Missing exports: isExternal
|
|
1209
|
+
"node:v8",
|
|
1210
|
+
// Missing exports: GCProfiler, getCppHeapStatistics, isStringOneByteRepresentation, promiseHooks, queryObjects, setHeapSnapshotNearHeapLimit, startupSnapshot
|
|
1211
|
+
"node:vm",
|
|
1212
|
+
"node:wasi",
|
|
1213
|
+
"node:worker_threads",
|
|
1214
|
+
// Missing exports: isInternalThread, isMarkedAsUntransferable, locks, markAsUncloneable, postMessageToThread, threadName
|
|
1215
|
+
"node:zlib"
|
|
1216
|
+
// Missing exports: ZstdCompress, ZstdDecompress, createZstdCompress, createZstdDecompress, zstdCompress, zstdCompressSync, zstdDecompress, zstdDecompressSync
|
|
1217
|
+
];
|
|
1218
|
+
|
|
1219
|
+
const unenvDeno = {
|
|
1220
|
+
meta: {
|
|
1221
|
+
name: "nitro:deno"
|
|
1222
|
+
},
|
|
1223
|
+
external: builtnNodeModules.map((m) => `node:${m}`),
|
|
1224
|
+
alias: {
|
|
1225
|
+
...Object.fromEntries(
|
|
1226
|
+
builtnNodeModules.flatMap((m) => [
|
|
1227
|
+
[m, m],
|
|
1228
|
+
[m.replace("node:", ""), m]
|
|
1229
|
+
])
|
|
1230
|
+
)
|
|
1231
|
+
},
|
|
1232
|
+
inject: {
|
|
1233
|
+
global: "unenv/polyfill/globalthis",
|
|
1234
|
+
process: "node:process",
|
|
1235
|
+
clearImmediate: ["node:timers", "clearImmediate"],
|
|
1236
|
+
setImmediate: ["node:timers", "setImmediate"],
|
|
1237
|
+
Buffer: ["node:buffer", "Buffer"]
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
const denoDeploy = defineNitroPreset(
|
|
1242
|
+
{
|
|
1243
|
+
entry: "./deno/runtime/deno-deploy",
|
|
1244
|
+
exportConditions: ["deno"],
|
|
1245
|
+
node: false,
|
|
1246
|
+
noExternals: true,
|
|
1247
|
+
serveStatic: "deno",
|
|
1248
|
+
commands: {
|
|
1249
|
+
preview: "",
|
|
1250
|
+
deploy: "cd ./ && deployctl deploy --project=<project_name> server/index.ts"
|
|
1251
|
+
},
|
|
1252
|
+
unenv: unenvDeno,
|
|
1253
|
+
rollupConfig: {
|
|
1254
|
+
preserveEntrySignatures: false,
|
|
1255
|
+
external: (id) => id.startsWith("https://") || id.startsWith("node:"),
|
|
1256
|
+
output: {
|
|
1257
|
+
entryFileNames: "index.ts",
|
|
1258
|
+
manualChunks: (id) => "index",
|
|
1259
|
+
format: "esm"
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
{
|
|
1264
|
+
name: "deno-deploy"
|
|
1265
|
+
}
|
|
1266
|
+
);
|
|
1267
|
+
const denoServer = defineNitroPreset(
|
|
1268
|
+
{
|
|
1269
|
+
entry: "./deno/runtime/deno-server",
|
|
1270
|
+
serveStatic: true,
|
|
1271
|
+
exportConditions: ["deno"],
|
|
1272
|
+
commands: {
|
|
1273
|
+
preview: "deno task --config ./deno.json start"
|
|
1274
|
+
},
|
|
1275
|
+
rollupConfig: {
|
|
1276
|
+
external: (id) => id.startsWith("https://"),
|
|
1277
|
+
output: {
|
|
1278
|
+
hoistTransitiveImports: false
|
|
1279
|
+
}
|
|
1280
|
+
},
|
|
1281
|
+
hooks: {
|
|
1282
|
+
async compiled(nitro) {
|
|
1283
|
+
const denoJSON = {
|
|
1284
|
+
tasks: {
|
|
1285
|
+
start: "deno run --allow-net --allow-read --allow-write --allow-env --unstable-byonm --unstable-node-globals ./server/index.mjs"
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
await writeFile(
|
|
1289
|
+
resolve$1(nitro.options.output.dir, "deno.json"),
|
|
1290
|
+
JSON.stringify(denoJSON, null, 2)
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
{
|
|
1296
|
+
name: "deno-server"
|
|
1297
|
+
}
|
|
1298
|
+
);
|
|
1299
|
+
const _deno = [denoDeploy, denoServer];
|
|
1300
|
+
|
|
1301
|
+
const digitalOcean = defineNitroPreset(
|
|
1302
|
+
{
|
|
1303
|
+
extends: "node-server",
|
|
1304
|
+
serveStatic: true
|
|
1305
|
+
},
|
|
1306
|
+
{
|
|
1307
|
+
name: "digital-ocean"
|
|
1308
|
+
}
|
|
1309
|
+
);
|
|
1310
|
+
const _digitalocean = [digitalOcean];
|
|
1311
|
+
|
|
1312
|
+
const firebaseAppHosting = defineNitroPreset(
|
|
1313
|
+
{
|
|
1314
|
+
extends: "node-server",
|
|
1315
|
+
serveStatic: true,
|
|
1316
|
+
hooks: {
|
|
1317
|
+
async compiled(nitro) {
|
|
1318
|
+
const serverEntry = join(nitro.options.output.serverDir, "index.mjs");
|
|
1319
|
+
await writeFile(
|
|
1320
|
+
join(nitro.options.rootDir, ".apphosting/bundle.yaml"),
|
|
1321
|
+
gr({
|
|
1322
|
+
version: "v1",
|
|
1323
|
+
runConfig: {
|
|
1324
|
+
runCommand: `node ${relative(nitro.options.rootDir, serverEntry)}`,
|
|
1325
|
+
...nitro.options.firebase?.appHosting
|
|
1326
|
+
},
|
|
1327
|
+
metadata: {
|
|
1328
|
+
framework: nitro.options.framework.name || "nitro",
|
|
1329
|
+
frameworkVersion: nitro.options.framework.version || "2.x",
|
|
1330
|
+
adapterPackageName: "nitro",
|
|
1331
|
+
adapterVersion: version
|
|
1332
|
+
},
|
|
1333
|
+
outputFiles: {
|
|
1334
|
+
serverApp: {
|
|
1335
|
+
include: [
|
|
1336
|
+
relative(nitro.options.rootDir, nitro.options.output.dir)
|
|
1337
|
+
]
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}),
|
|
1341
|
+
true
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
{
|
|
1347
|
+
name: "firebase-app-hosting",
|
|
1348
|
+
stdName: "firebase_app_hosting"
|
|
1349
|
+
}
|
|
1350
|
+
);
|
|
1351
|
+
const _firebase = [firebaseAppHosting];
|
|
1352
|
+
|
|
1353
|
+
const flightControl = defineNitroPreset(
|
|
1354
|
+
{
|
|
1355
|
+
extends: "node-server",
|
|
1356
|
+
serveStatic: true
|
|
1357
|
+
},
|
|
1358
|
+
{
|
|
1359
|
+
name: "flight-control"
|
|
1360
|
+
}
|
|
1361
|
+
);
|
|
1362
|
+
const _flightcontrol = [flightControl];
|
|
1363
|
+
|
|
1364
|
+
const genezio = defineNitroPreset(
|
|
1365
|
+
{
|
|
1366
|
+
extends: "aws_lambda"
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
name: "genezio"
|
|
1370
|
+
}
|
|
1371
|
+
);
|
|
1372
|
+
const _genezio = [genezio];
|
|
1373
|
+
|
|
1374
|
+
const heroku = defineNitroPreset(
|
|
1375
|
+
{
|
|
1376
|
+
extends: "node-server",
|
|
1377
|
+
serveStatic: true
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
name: "heroku"
|
|
1381
|
+
}
|
|
1382
|
+
);
|
|
1383
|
+
const _heroku = [heroku];
|
|
1384
|
+
|
|
1385
|
+
async function writeIISFiles(nitro) {
|
|
1386
|
+
await writeFile(
|
|
1387
|
+
resolve$1(nitro.options.output.dir, "web.config"),
|
|
1388
|
+
await iisXmlTemplate(nitro)
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1391
|
+
async function writeIISNodeFiles(nitro) {
|
|
1392
|
+
await writeFile(
|
|
1393
|
+
resolve$1(nitro.options.output.dir, "web.config"),
|
|
1394
|
+
await iisnodeXmlTemplate(nitro)
|
|
1395
|
+
);
|
|
1396
|
+
await writeFile(
|
|
1397
|
+
resolve$1(nitro.options.output.dir, "index.js"),
|
|
1398
|
+
/*js */
|
|
1399
|
+
`
|
|
1400
|
+
if (process.env.PORT.startsWith('\\\\')) {
|
|
1401
|
+
process.env.NITRO_UNIX_SOCKET = process.env.PORT
|
|
1402
|
+
delete process.env.PORT
|
|
1403
|
+
}
|
|
1404
|
+
import('./server/index.mjs');
|
|
1405
|
+
`
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
async function iisnodeXmlTemplate(nitro) {
|
|
1409
|
+
const path = resolve$1(nitro.options.rootDir, "web.config");
|
|
1410
|
+
const originalString = (
|
|
1411
|
+
/* xml */
|
|
1412
|
+
`<?xml version="1.0" encoding="utf-8"?>
|
|
1413
|
+
<!--
|
|
1414
|
+
This configuration file is required if iisnode is used to run node processes behind
|
|
1415
|
+
IIS or IIS Express. For more information, visit:
|
|
1416
|
+
https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config
|
|
1417
|
+
-->
|
|
1418
|
+
<configuration>
|
|
1419
|
+
<system.webServer>
|
|
1420
|
+
<!-- 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 -->
|
|
1421
|
+
<webSocket enabled="false" />
|
|
1422
|
+
<handlers>
|
|
1423
|
+
<!-- Indicates that the index.js file is a Node.js site to be handled by the iisnode module -->
|
|
1424
|
+
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
|
|
1425
|
+
</handlers>
|
|
1426
|
+
<rewrite>
|
|
1427
|
+
<rules>
|
|
1428
|
+
<!-- Do not interfere with requests for node-inspector debugging -->
|
|
1429
|
+
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
|
|
1430
|
+
<match url="^index.js/debug[/]?" />
|
|
1431
|
+
</rule>
|
|
1432
|
+
|
|
1433
|
+
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
|
|
1434
|
+
<rule name="StaticContent">
|
|
1435
|
+
<action type="Rewrite" url="public{PATH_INFO}" />
|
|
1436
|
+
</rule>
|
|
1437
|
+
|
|
1438
|
+
<!-- All other URLs are mapped to the Node.js site entrypoint -->
|
|
1439
|
+
<rule name="DynamicContent">
|
|
1440
|
+
<conditions>
|
|
1441
|
+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
|
|
1442
|
+
</conditions>
|
|
1443
|
+
<action type="Rewrite" url="index.js" />
|
|
1444
|
+
</rule>
|
|
1445
|
+
</rules>
|
|
1446
|
+
</rewrite>
|
|
1447
|
+
|
|
1448
|
+
<!-- 'bin' directory has no special meaning in Node.js and apps can be placed in it -->
|
|
1449
|
+
<security>
|
|
1450
|
+
<requestFiltering>
|
|
1451
|
+
<hiddenSegments>
|
|
1452
|
+
<remove segment="bin" />
|
|
1453
|
+
</hiddenSegments>
|
|
1454
|
+
<requestLimits maxAllowedContentLength="4294967295" />
|
|
1455
|
+
</requestFiltering>
|
|
1456
|
+
</security>
|
|
1457
|
+
|
|
1458
|
+
<!-- Make sure error responses are left untouched -->
|
|
1459
|
+
<httpErrors existingResponse="PassThrough" />
|
|
1460
|
+
|
|
1461
|
+
<!--
|
|
1462
|
+
You can control how Node is hosted within IIS using the following options:
|
|
1463
|
+
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
|
|
1464
|
+
* node_env: will be propagated to node as NODE_ENV environment variable
|
|
1465
|
+
* debuggingEnabled - controls whether the built-in debugger is enabled
|
|
1466
|
+
See https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
|
|
1467
|
+
-->
|
|
1468
|
+
<iisnode
|
|
1469
|
+
watchedFiles="index.js"
|
|
1470
|
+
node_env="production"
|
|
1471
|
+
debuggingEnabled="false"
|
|
1472
|
+
loggingEnabled="false"
|
|
1473
|
+
/>
|
|
1474
|
+
</system.webServer>
|
|
1475
|
+
</configuration>
|
|
1476
|
+
`
|
|
1477
|
+
);
|
|
1478
|
+
if (existsSync(path)) {
|
|
1479
|
+
const fileString = await readFile(path, "utf8");
|
|
1480
|
+
const originalWebConfig = await parseXmlDoc(originalString);
|
|
1481
|
+
const fileWebConfig = await parseXmlDoc(fileString);
|
|
1482
|
+
if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) {
|
|
1483
|
+
return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig));
|
|
1484
|
+
}
|
|
1485
|
+
if (nitro.options.iis?.overrideConfig) {
|
|
1486
|
+
return buildNewXmlDoc({ ...fileWebConfig });
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return originalString;
|
|
1490
|
+
}
|
|
1491
|
+
async function iisXmlTemplate(nitro) {
|
|
1492
|
+
const path = resolve$1(nitro.options.rootDir, "web.config");
|
|
1493
|
+
const originalString = (
|
|
1494
|
+
/* xml */
|
|
1495
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
1496
|
+
<configuration>
|
|
1497
|
+
<system.webServer>
|
|
1498
|
+
<handlers>
|
|
1499
|
+
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
|
|
1500
|
+
</handlers>
|
|
1501
|
+
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\\logs\\node.log" startupTimeLimit="20" processPath="C:\\Program Files\\nodejs\\node.exe" arguments=".\\server\\index.mjs">
|
|
1502
|
+
<environmentVariables>
|
|
1503
|
+
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
|
|
1504
|
+
<environmentVariable name="NODE_ENV" value="Production" />
|
|
1505
|
+
</environmentVariables>
|
|
1506
|
+
</httpPlatform>
|
|
1507
|
+
</system.webServer>
|
|
1508
|
+
</configuration>
|
|
1509
|
+
`
|
|
1510
|
+
);
|
|
1511
|
+
if (existsSync(path)) {
|
|
1512
|
+
const fileString = await readFile(path, "utf8");
|
|
1513
|
+
const originalWebConfig = await parseXmlDoc(originalString);
|
|
1514
|
+
const fileWebConfig = await parseXmlDoc(fileString);
|
|
1515
|
+
if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) {
|
|
1516
|
+
return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig));
|
|
1517
|
+
}
|
|
1518
|
+
if (nitro.options.iis?.overrideConfig) {
|
|
1519
|
+
return buildNewXmlDoc({ ...fileWebConfig });
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
return originalString;
|
|
1523
|
+
}
|
|
1524
|
+
async function parseXmlDoc(xml) {
|
|
1525
|
+
const { Parser } = await import('xml2js');
|
|
1526
|
+
if (xml === void 0 || !xml) {
|
|
1527
|
+
return {};
|
|
1528
|
+
}
|
|
1529
|
+
const parser = new Parser({ explicitArray: false });
|
|
1530
|
+
let parsedRecord = {};
|
|
1531
|
+
parser.parseString(xml, (_, r) => {
|
|
1532
|
+
parsedRecord = r;
|
|
1533
|
+
});
|
|
1534
|
+
return parsedRecord;
|
|
1535
|
+
}
|
|
1536
|
+
async function buildNewXmlDoc(xmlObj) {
|
|
1537
|
+
const { Builder } = await import('xml2js');
|
|
1538
|
+
const builder = new Builder();
|
|
1539
|
+
return builder.buildObject({ ...xmlObj });
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
const iisHandler = defineNitroPreset(
|
|
1543
|
+
{
|
|
1544
|
+
extends: "node-server",
|
|
1545
|
+
serveStatic: true,
|
|
1546
|
+
hooks: {
|
|
1547
|
+
async compiled(nitro) {
|
|
1548
|
+
await writeIISFiles(nitro);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
},
|
|
1552
|
+
{
|
|
1553
|
+
name: "iis-handler"
|
|
1554
|
+
}
|
|
1555
|
+
);
|
|
1556
|
+
const iisNode = defineNitroPreset(
|
|
1557
|
+
{
|
|
1558
|
+
extends: "node-server",
|
|
1559
|
+
serveStatic: true,
|
|
1560
|
+
hooks: {
|
|
1561
|
+
async compiled(nitro) {
|
|
1562
|
+
await writeIISNodeFiles(nitro);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
name: "iis-node"
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
const _iis = [iisHandler, iisNode];
|
|
1571
|
+
|
|
1572
|
+
const koyeb = defineNitroPreset(
|
|
1573
|
+
{
|
|
1574
|
+
extends: "node-server",
|
|
1575
|
+
serveStatic: true
|
|
1576
|
+
},
|
|
1577
|
+
{
|
|
1578
|
+
name: "koyeb"
|
|
1579
|
+
}
|
|
1580
|
+
);
|
|
1581
|
+
const _koyeb = [koyeb];
|
|
1582
|
+
|
|
1583
|
+
async function writeRedirects(nitro) {
|
|
1584
|
+
const redirectsPath = join(nitro.options.output.publicDir, "_redirects");
|
|
1585
|
+
let contents = "";
|
|
1586
|
+
if (nitro.options.static) {
|
|
1587
|
+
const staticFallback = existsSync(
|
|
1588
|
+
join(nitro.options.output.publicDir, "404.html")
|
|
1589
|
+
) ? "/* /404.html 404" : "";
|
|
1590
|
+
contents += staticFallback;
|
|
1591
|
+
}
|
|
1592
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
1593
|
+
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
|
|
1594
|
+
);
|
|
1595
|
+
for (const [key, routeRules] of rules.filter(
|
|
1596
|
+
([_, routeRules2]) => routeRules2.redirect
|
|
1597
|
+
)) {
|
|
1598
|
+
let code = routeRules.redirect.status;
|
|
1599
|
+
if (code === 307) {
|
|
1600
|
+
code = 302;
|
|
1601
|
+
}
|
|
1602
|
+
if (code === 308) {
|
|
1603
|
+
code = 301;
|
|
1604
|
+
}
|
|
1605
|
+
contents = `${key.replace("/**", "/*")} ${routeRules.redirect.to.replace(
|
|
1606
|
+
"/**",
|
|
1607
|
+
"/:splat"
|
|
1608
|
+
)} ${code}
|
|
1609
|
+
` + contents;
|
|
1610
|
+
}
|
|
1611
|
+
if (existsSync(redirectsPath)) {
|
|
1612
|
+
const currentRedirects = await promises.readFile(redirectsPath, "utf8");
|
|
1613
|
+
if (/^\/\* /m.test(currentRedirects)) {
|
|
1614
|
+
nitro.logger.info(
|
|
1615
|
+
"Not adding Nitro fallback to `_redirects` (as an existing fallback was found)."
|
|
1616
|
+
);
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
nitro.logger.info(
|
|
1620
|
+
"Adding Nitro fallback to `_redirects` to handle all unmatched routes."
|
|
1621
|
+
);
|
|
1622
|
+
contents = currentRedirects + "\n" + contents;
|
|
1623
|
+
}
|
|
1624
|
+
await promises.writeFile(redirectsPath, contents);
|
|
1625
|
+
}
|
|
1626
|
+
async function writeHeaders(nitro) {
|
|
1627
|
+
const headersPath = join(nitro.options.output.publicDir, "_headers");
|
|
1628
|
+
let contents = "";
|
|
1629
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
1630
|
+
(a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
|
|
1631
|
+
);
|
|
1632
|
+
for (const [path, routeRules] of rules.filter(
|
|
1633
|
+
([_, routeRules2]) => routeRules2.headers
|
|
1634
|
+
)) {
|
|
1635
|
+
const headers = [
|
|
1636
|
+
path.replace("/**", "/*"),
|
|
1637
|
+
...Object.entries({ ...routeRules.headers }).map(
|
|
1638
|
+
([header, value]) => ` ${header}: ${value}`
|
|
1639
|
+
)
|
|
1640
|
+
].join("\n");
|
|
1641
|
+
contents += headers + "\n";
|
|
1642
|
+
}
|
|
1643
|
+
if (existsSync(headersPath)) {
|
|
1644
|
+
const currentHeaders = await promises.readFile(headersPath, "utf8");
|
|
1645
|
+
if (/^\/\* /m.test(currentHeaders)) {
|
|
1646
|
+
nitro.logger.info(
|
|
1647
|
+
"Not adding Nitro fallback to `_headers` (as an existing fallback was found)."
|
|
1648
|
+
);
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
nitro.logger.info(
|
|
1652
|
+
"Adding Nitro fallback to `_headers` to handle all unmatched routes."
|
|
1653
|
+
);
|
|
1654
|
+
contents = currentHeaders + "\n" + contents;
|
|
1655
|
+
}
|
|
1656
|
+
await promises.writeFile(headersPath, contents);
|
|
1657
|
+
}
|
|
1658
|
+
function getStaticPaths(publicAssets, baseURL) {
|
|
1659
|
+
return [
|
|
1660
|
+
"/.netlify/*",
|
|
1661
|
+
// TODO: should this be also be prefixed with baseURL?
|
|
1662
|
+
...publicAssets.filter((a) => a.fallthrough !== true && a.baseURL && a.baseURL !== "/").map((a) => joinURL(baseURL, a.baseURL, "*"))
|
|
1663
|
+
];
|
|
1664
|
+
}
|
|
1665
|
+
function generateNetlifyFunction(nitro) {
|
|
1666
|
+
return (
|
|
1667
|
+
/* js */
|
|
1668
|
+
`
|
|
1669
|
+
export { default } from "./main.mjs";
|
|
1670
|
+
export const config = {
|
|
1671
|
+
name: "server handler",
|
|
1672
|
+
generator: "${getGeneratorString(nitro)}",
|
|
1673
|
+
path: "/*",
|
|
1674
|
+
nodeBundler: "none",
|
|
1675
|
+
includedFiles: ["**"],
|
|
1676
|
+
excludedPath: ${JSON.stringify(getStaticPaths(nitro.options.publicAssets, nitro.options.baseURL))},
|
|
1677
|
+
preferStatic: true,
|
|
1678
|
+
};
|
|
1679
|
+
`.trim()
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
function getGeneratorString(nitro) {
|
|
1683
|
+
return `${nitro.options.framework.name}@${nitro.options.framework.version}`;
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
const netlify = defineNitroPreset(
|
|
1687
|
+
{
|
|
1688
|
+
entry: "./netlify/runtime/netlify",
|
|
1689
|
+
output: {
|
|
1690
|
+
dir: "{{ rootDir }}/.netlify/functions-internal",
|
|
1691
|
+
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
|
|
1692
|
+
},
|
|
1693
|
+
prerender: {
|
|
1694
|
+
// Prevents an unnecessary redirect from /page/ to /page when accessing prerendered content.
|
|
1695
|
+
// Reference: https://answers.netlify.com/t/support-guide-how-can-i-alter-trailing-slash-behaviour-in-my-urls-will-enabling-pretty-urls-help/31191
|
|
1696
|
+
// Reference: https://nitro.build/config#prerender
|
|
1697
|
+
autoSubfolderIndex: false
|
|
1698
|
+
},
|
|
1699
|
+
rollupConfig: {
|
|
1700
|
+
output: {
|
|
1701
|
+
entryFileNames: "main.mjs"
|
|
1702
|
+
}
|
|
1703
|
+
},
|
|
1704
|
+
hooks: {
|
|
1705
|
+
async compiled(nitro) {
|
|
1706
|
+
await writeHeaders(nitro);
|
|
1707
|
+
await writeRedirects(nitro);
|
|
1708
|
+
await promises.writeFile(
|
|
1709
|
+
join(nitro.options.output.dir, "server", "server.mjs"),
|
|
1710
|
+
generateNetlifyFunction(nitro)
|
|
1711
|
+
);
|
|
1712
|
+
if (nitro.options.netlify) {
|
|
1713
|
+
const configPath = join(
|
|
1714
|
+
nitro.options.output.dir,
|
|
1715
|
+
"../deploy/v1/config.json"
|
|
1716
|
+
);
|
|
1717
|
+
await promises.mkdir(dirname(configPath), { recursive: true });
|
|
1718
|
+
await promises.writeFile(
|
|
1719
|
+
configPath,
|
|
1720
|
+
JSON.stringify(nitro.options.netlify),
|
|
1721
|
+
"utf8"
|
|
1722
|
+
);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
},
|
|
1727
|
+
{
|
|
1728
|
+
name: "netlify",
|
|
1729
|
+
stdName: "netlify"
|
|
1730
|
+
}
|
|
1731
|
+
);
|
|
1732
|
+
const netlifyEdge = defineNitroPreset(
|
|
1733
|
+
{
|
|
1734
|
+
extends: "base-worker",
|
|
1735
|
+
entry: "./netlify/runtime/netlify-edge",
|
|
1736
|
+
exportConditions: ["netlify"],
|
|
1737
|
+
output: {
|
|
1738
|
+
serverDir: "{{ rootDir }}/.netlify/edge-functions/server",
|
|
1739
|
+
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
|
|
1740
|
+
},
|
|
1741
|
+
prerender: {
|
|
1742
|
+
// Prevents an unnecessary redirect from /page/ to /page when accessing prerendered content.
|
|
1743
|
+
// Reference: https://answers.netlify.com/t/support-guide-how-can-i-alter-trailing-slash-behaviour-in-my-urls-will-enabling-pretty-urls-help/31191
|
|
1744
|
+
// Reference: https://nitro.build/config#prerender
|
|
1745
|
+
autoSubfolderIndex: false
|
|
1746
|
+
},
|
|
1747
|
+
rollupConfig: {
|
|
1748
|
+
output: {
|
|
1749
|
+
entryFileNames: "server.js",
|
|
1750
|
+
format: "esm"
|
|
1751
|
+
}
|
|
1752
|
+
},
|
|
1753
|
+
unenv: unenvDeno,
|
|
1754
|
+
hooks: {
|
|
1755
|
+
async compiled(nitro) {
|
|
1756
|
+
await writeHeaders(nitro);
|
|
1757
|
+
await writeRedirects(nitro);
|
|
1758
|
+
const manifest = {
|
|
1759
|
+
version: 1,
|
|
1760
|
+
functions: [
|
|
1761
|
+
{
|
|
1762
|
+
path: "/*",
|
|
1763
|
+
excludedPath: getStaticPaths(
|
|
1764
|
+
nitro.options.publicAssets,
|
|
1765
|
+
nitro.options.baseURL
|
|
1766
|
+
),
|
|
1767
|
+
name: "edge server handler",
|
|
1768
|
+
function: "server",
|
|
1769
|
+
generator: getGeneratorString(nitro)
|
|
1770
|
+
}
|
|
1771
|
+
]
|
|
1772
|
+
};
|
|
1773
|
+
const manifestPath = join(
|
|
1774
|
+
nitro.options.rootDir,
|
|
1775
|
+
".netlify/edge-functions/manifest.json"
|
|
1776
|
+
);
|
|
1777
|
+
await promises.mkdir(dirname(manifestPath), { recursive: true });
|
|
1778
|
+
await promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
},
|
|
1782
|
+
{
|
|
1783
|
+
name: "netlify-edge"
|
|
1784
|
+
}
|
|
1785
|
+
);
|
|
1786
|
+
const netlifyStatic = defineNitroPreset(
|
|
1787
|
+
{
|
|
1788
|
+
extends: "static",
|
|
1789
|
+
output: {
|
|
1790
|
+
dir: "{{ rootDir }}/dist",
|
|
1791
|
+
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
|
|
1792
|
+
},
|
|
1793
|
+
prerender: {
|
|
1794
|
+
// Prevents an unnecessary redirect from /page/ to /page when accessing prerendered content.
|
|
1795
|
+
// Reference: https://answers.netlify.com/t/support-guide-how-can-i-alter-trailing-slash-behaviour-in-my-urls-will-enabling-pretty-urls-help/31191
|
|
1796
|
+
// Reference: https://nitro.build/config#prerender
|
|
1797
|
+
autoSubfolderIndex: false
|
|
1798
|
+
},
|
|
1799
|
+
commands: {
|
|
1800
|
+
preview: "npx serve ./"
|
|
1801
|
+
},
|
|
1802
|
+
hooks: {
|
|
1803
|
+
async compiled(nitro) {
|
|
1804
|
+
await writeHeaders(nitro);
|
|
1805
|
+
await writeRedirects(nitro);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
},
|
|
1809
|
+
{
|
|
1810
|
+
name: "netlify-static",
|
|
1811
|
+
stdName: "netlify",
|
|
1812
|
+
static: true
|
|
1813
|
+
}
|
|
1814
|
+
);
|
|
1815
|
+
const _netlify = [netlify, netlifyEdge, netlifyStatic];
|
|
1816
|
+
|
|
1817
|
+
const nodeServer = defineNitroPreset(
|
|
1818
|
+
{
|
|
1819
|
+
entry: "./node/runtime/node-server",
|
|
1820
|
+
serveStatic: true,
|
|
1821
|
+
commands: {
|
|
1822
|
+
preview: "node ./server/index.mjs"
|
|
1823
|
+
}
|
|
1824
|
+
},
|
|
1825
|
+
{
|
|
1826
|
+
name: "node-server"
|
|
1827
|
+
}
|
|
1828
|
+
);
|
|
1829
|
+
const nodeMiddleware = defineNitroPreset(
|
|
1830
|
+
{
|
|
1831
|
+
entry: "./node/runtime/node-middleware"
|
|
1832
|
+
},
|
|
1833
|
+
{
|
|
1834
|
+
name: "node-middleware"
|
|
1835
|
+
}
|
|
1836
|
+
);
|
|
1837
|
+
const nodeCluster = defineNitroPreset(
|
|
1838
|
+
{
|
|
1839
|
+
extends: "node-server",
|
|
1840
|
+
serveStatic: true,
|
|
1841
|
+
entry: "./node/runtime/node-cluster",
|
|
1842
|
+
hooks: {
|
|
1843
|
+
"rollup:before"(_nitro, rollupConfig) {
|
|
1844
|
+
const manualChunks = rollupConfig.output?.manualChunks;
|
|
1845
|
+
if (manualChunks && typeof manualChunks === "function") {
|
|
1846
|
+
const serverEntry = resolveModulePath("./runtime/node-server", {
|
|
1847
|
+
from: import.meta.url,
|
|
1848
|
+
extensions: [".mjs", ".ts"]
|
|
1849
|
+
});
|
|
1850
|
+
rollupConfig.output.manualChunks = (id, meta) => {
|
|
1851
|
+
if (id.includes("node-server") && normalize(id) === serverEntry) {
|
|
1852
|
+
return "nitro/node-worker";
|
|
1853
|
+
}
|
|
1854
|
+
return manualChunks(id, meta);
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
},
|
|
1860
|
+
{
|
|
1861
|
+
name: "node-cluster"
|
|
1862
|
+
}
|
|
1863
|
+
);
|
|
1864
|
+
const _node = [nodeServer, nodeCluster, nodeMiddleware];
|
|
1865
|
+
|
|
1866
|
+
const platformSh = defineNitroPreset(
|
|
1867
|
+
{
|
|
1868
|
+
extends: "node-server",
|
|
1869
|
+
serveStatic: true
|
|
1870
|
+
},
|
|
1871
|
+
{
|
|
1872
|
+
name: "platform-sh"
|
|
1873
|
+
}
|
|
1874
|
+
);
|
|
1875
|
+
const _platformSh = [platformSh];
|
|
1876
|
+
|
|
1877
|
+
const renderCom = defineNitroPreset(
|
|
1878
|
+
{
|
|
1879
|
+
extends: "node-server",
|
|
1880
|
+
serveStatic: true
|
|
1881
|
+
},
|
|
1882
|
+
{
|
|
1883
|
+
name: "render-com"
|
|
1884
|
+
}
|
|
1885
|
+
);
|
|
1886
|
+
const _renderCom = [renderCom];
|
|
1887
|
+
|
|
1888
|
+
const standard = defineNitroPreset(
|
|
1889
|
+
{
|
|
1890
|
+
entry: "./standard/runtime/server",
|
|
1891
|
+
serveStatic: false,
|
|
1892
|
+
exportConditions: ["import", "default"],
|
|
1893
|
+
commands: {
|
|
1894
|
+
preview: "npx srvx --prod ./"
|
|
1895
|
+
},
|
|
1896
|
+
alias: {
|
|
1897
|
+
srvx: "srvx/generic",
|
|
1898
|
+
"srvx/node": "srvx/node",
|
|
1899
|
+
"srvx/generic": "srvx/generic"
|
|
1900
|
+
}
|
|
1901
|
+
},
|
|
1902
|
+
{
|
|
1903
|
+
name: "standard"
|
|
1904
|
+
}
|
|
1905
|
+
);
|
|
1906
|
+
const _standard = [standard];
|
|
1907
|
+
|
|
1908
|
+
const stormkit = defineNitroPreset(
|
|
1909
|
+
{
|
|
1910
|
+
entry: "./stormkit/runtime/stormkit",
|
|
1911
|
+
output: {
|
|
1912
|
+
dir: "{{ rootDir }}/.stormkit",
|
|
1913
|
+
publicDir: "{{ rootDir }}/.stormkit/public/{{ baseURL }}"
|
|
1914
|
+
}
|
|
1915
|
+
},
|
|
1916
|
+
{
|
|
1917
|
+
name: "stormkit",
|
|
1918
|
+
stdName: "stormkit"
|
|
1919
|
+
}
|
|
1920
|
+
);
|
|
1921
|
+
const _stormkit = [stormkit];
|
|
1922
|
+
|
|
1923
|
+
const SUPPORTED_NODE_VERSIONS = [20, 22];
|
|
1924
|
+
const FALLBACK_ROUTE = "/__fallback";
|
|
1925
|
+
const ISR_SUFFIX = "-isr";
|
|
1926
|
+
const SAFE_FS_CHAR_RE = /[^a-zA-Z0-9_.[\]/]/g;
|
|
1927
|
+
function getSystemNodeVersion() {
|
|
1928
|
+
const systemNodeVersion = Number.parseInt(
|
|
1929
|
+
process.versions.node.split(".")[0]
|
|
1930
|
+
);
|
|
1931
|
+
return Number.isNaN(systemNodeVersion) ? 22 : systemNodeVersion;
|
|
1932
|
+
}
|
|
1933
|
+
async function generateFunctionFiles(nitro) {
|
|
1934
|
+
const o11Routes = getObservabilityRoutes(nitro);
|
|
1935
|
+
const buildConfigPath = resolve$1(nitro.options.output.dir, "config.json");
|
|
1936
|
+
const buildConfig = generateBuildConfig(nitro, o11Routes);
|
|
1937
|
+
await writeFile(buildConfigPath, JSON.stringify(buildConfig, null, 2));
|
|
1938
|
+
const systemNodeVersion = getSystemNodeVersion();
|
|
1939
|
+
const usedNodeVersion = SUPPORTED_NODE_VERSIONS.find((version) => version >= systemNodeVersion) ?? SUPPORTED_NODE_VERSIONS.at(-1);
|
|
1940
|
+
const runtimeVersion = `nodejs${usedNodeVersion}.x`;
|
|
1941
|
+
const functionConfigPath = resolve$1(
|
|
1942
|
+
nitro.options.output.serverDir,
|
|
1943
|
+
".vc-config.json"
|
|
1944
|
+
);
|
|
1945
|
+
const functionConfig = {
|
|
1946
|
+
runtime: runtimeVersion,
|
|
1947
|
+
handler: "index.mjs",
|
|
1948
|
+
launcherType: "Nodejs",
|
|
1949
|
+
shouldAddHelpers: false,
|
|
1950
|
+
supportsResponseStreaming: true,
|
|
1951
|
+
...nitro.options.vercel?.functions
|
|
1952
|
+
};
|
|
1953
|
+
await writeFile(functionConfigPath, JSON.stringify(functionConfig, null, 2));
|
|
1954
|
+
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
|
|
1955
|
+
if (!value.isr) {
|
|
1956
|
+
continue;
|
|
1957
|
+
}
|
|
1958
|
+
const funcPrefix = resolve$1(
|
|
1959
|
+
nitro.options.output.serverDir,
|
|
1960
|
+
"..",
|
|
1961
|
+
normalizeRouteDest(key) + ISR_SUFFIX
|
|
1962
|
+
);
|
|
1963
|
+
await fsp.mkdir(dirname(funcPrefix), { recursive: true });
|
|
1964
|
+
await fsp.symlink(
|
|
1965
|
+
"./" + relative(dirname(funcPrefix), nitro.options.output.serverDir),
|
|
1966
|
+
funcPrefix + ".func",
|
|
1967
|
+
"junction"
|
|
1968
|
+
);
|
|
1969
|
+
await writePrerenderConfig(
|
|
1970
|
+
funcPrefix + ".prerender-config.json",
|
|
1971
|
+
value.isr,
|
|
1972
|
+
nitro.options.vercel?.config?.bypassToken
|
|
1973
|
+
);
|
|
1974
|
+
}
|
|
1975
|
+
if (o11Routes.length === 0) {
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1978
|
+
const _getRouteRules = (path) => defu(
|
|
1979
|
+
{},
|
|
1980
|
+
...nitro.routing.routeRules.matchAll("", path).reverse()
|
|
1981
|
+
);
|
|
1982
|
+
for (const route of o11Routes) {
|
|
1983
|
+
const routeRules = _getRouteRules(route.src);
|
|
1984
|
+
if (routeRules.isr) {
|
|
1985
|
+
continue;
|
|
1986
|
+
}
|
|
1987
|
+
const funcPrefix = resolve$1(
|
|
1988
|
+
nitro.options.output.serverDir,
|
|
1989
|
+
"..",
|
|
1990
|
+
route.dest
|
|
1991
|
+
);
|
|
1992
|
+
await fsp.mkdir(dirname(funcPrefix), { recursive: true });
|
|
1993
|
+
await fsp.symlink(
|
|
1994
|
+
"./" + relative(dirname(funcPrefix), nitro.options.output.serverDir),
|
|
1995
|
+
funcPrefix + ".func",
|
|
1996
|
+
"junction"
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
async function generateStaticFiles(nitro) {
|
|
2001
|
+
const buildConfigPath = resolve$1(nitro.options.output.dir, "config.json");
|
|
2002
|
+
const buildConfig = generateBuildConfig(nitro);
|
|
2003
|
+
await writeFile(buildConfigPath, JSON.stringify(buildConfig, null, 2));
|
|
2004
|
+
}
|
|
2005
|
+
function generateBuildConfig(nitro, o11Routes) {
|
|
2006
|
+
const rules = Object.entries(nitro.options.routeRules).sort(
|
|
2007
|
+
(a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
|
|
2008
|
+
);
|
|
2009
|
+
const config = defu(nitro.options.vercel?.config, {
|
|
2010
|
+
version: 3,
|
|
2011
|
+
overrides: {
|
|
2012
|
+
// Nitro static prerendered route overrides
|
|
2013
|
+
...Object.fromEntries(
|
|
2014
|
+
(nitro._prerenderedRoutes?.filter((r) => r.fileName !== r.route) || []).map(({ route, fileName }) => [
|
|
2015
|
+
withoutLeadingSlash(fileName),
|
|
2016
|
+
{ path: route.replace(/^\//, "") }
|
|
2017
|
+
])
|
|
2018
|
+
)
|
|
2019
|
+
},
|
|
2020
|
+
routes: [
|
|
2021
|
+
// Redirect and header rules
|
|
2022
|
+
...rules.filter(([_, routeRules]) => routeRules.redirect || routeRules.headers).map(([path, routeRules]) => {
|
|
2023
|
+
let route = {
|
|
2024
|
+
src: path.replace("/**", "/(.*)")
|
|
2025
|
+
};
|
|
2026
|
+
if (routeRules.redirect) {
|
|
2027
|
+
route = defu(route, {
|
|
2028
|
+
status: routeRules.redirect.status,
|
|
2029
|
+
headers: {
|
|
2030
|
+
Location: routeRules.redirect.to.replace("/**", "/$1")
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
if (routeRules.headers) {
|
|
2035
|
+
route = defu(route, { headers: routeRules.headers });
|
|
2036
|
+
}
|
|
2037
|
+
return route;
|
|
2038
|
+
}),
|
|
2039
|
+
// Public asset rules
|
|
2040
|
+
...nitro.options.publicAssets.filter((asset) => !asset.fallthrough).map((asset) => joinURL(nitro.options.baseURL, asset.baseURL || "/")).map((baseURL) => ({
|
|
2041
|
+
src: baseURL + "(.*)",
|
|
2042
|
+
headers: {
|
|
2043
|
+
"cache-control": "public,max-age=31536000,immutable"
|
|
2044
|
+
},
|
|
2045
|
+
continue: true
|
|
2046
|
+
})),
|
|
2047
|
+
{ handle: "filesystem" }
|
|
2048
|
+
]
|
|
2049
|
+
});
|
|
2050
|
+
if (nitro.options.static) {
|
|
2051
|
+
return config;
|
|
2052
|
+
}
|
|
2053
|
+
config.routes.push(
|
|
2054
|
+
...nitro.options.routeRules["/"]?.isr ? [
|
|
2055
|
+
{
|
|
2056
|
+
src: "(?<url>/)",
|
|
2057
|
+
dest: `/index${ISR_SUFFIX}?url=$url`
|
|
2058
|
+
}
|
|
2059
|
+
] : [],
|
|
2060
|
+
...rules.filter(([key, value]) => value.isr !== void 0 && key !== "/").map(([key, value]) => {
|
|
2061
|
+
const src = key.replace(/^(.*)\/\*\*/, "(?<url>$1/.*)");
|
|
2062
|
+
if (value.isr === false) {
|
|
2063
|
+
return {
|
|
2064
|
+
src,
|
|
2065
|
+
dest: FALLBACK_ROUTE
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
return {
|
|
2069
|
+
src,
|
|
2070
|
+
dest: withLeadingSlash(
|
|
2071
|
+
normalizeRouteDest(key) + ISR_SUFFIX + "?url=$url"
|
|
2072
|
+
)
|
|
2073
|
+
};
|
|
2074
|
+
}),
|
|
2075
|
+
...(o11Routes || []).map((route) => ({
|
|
2076
|
+
src: joinURL(nitro.options.baseURL, route.src),
|
|
2077
|
+
dest: withLeadingSlash(route.dest)
|
|
2078
|
+
})),
|
|
2079
|
+
...nitro.options.routeRules["/**"]?.isr ? [] : [
|
|
2080
|
+
{
|
|
2081
|
+
src: "/(.*)",
|
|
2082
|
+
dest: FALLBACK_ROUTE
|
|
2083
|
+
}
|
|
2084
|
+
]
|
|
2085
|
+
);
|
|
2086
|
+
return config;
|
|
2087
|
+
}
|
|
2088
|
+
function deprecateSWR(nitro) {
|
|
2089
|
+
if (nitro.options.future.nativeSWR) {
|
|
2090
|
+
return;
|
|
2091
|
+
}
|
|
2092
|
+
let hasLegacyOptions = false;
|
|
2093
|
+
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
|
|
2094
|
+
if (_hasProp(value, "isr")) {
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
if (value.cache === false) {
|
|
2098
|
+
value.isr = false;
|
|
2099
|
+
}
|
|
2100
|
+
if (_hasProp(value, "static")) {
|
|
2101
|
+
value.isr = !value.static;
|
|
2102
|
+
hasLegacyOptions = true;
|
|
2103
|
+
}
|
|
2104
|
+
if (value.cache && _hasProp(value.cache, "swr")) {
|
|
2105
|
+
value.isr = value.cache.swr;
|
|
2106
|
+
hasLegacyOptions = true;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
if (hasLegacyOptions && !isTest) {
|
|
2110
|
+
nitro.logger.warn(
|
|
2111
|
+
"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."
|
|
2112
|
+
);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function _hasProp(obj, prop) {
|
|
2116
|
+
return obj && typeof obj === "object" && prop in obj;
|
|
2117
|
+
}
|
|
2118
|
+
function getObservabilityRoutes(nitro) {
|
|
2119
|
+
const compatDate = nitro.options.compatibilityDate.vercel || nitro.options.compatibilityDate.default;
|
|
2120
|
+
if (compatDate < "2025-07-15") {
|
|
2121
|
+
return [];
|
|
2122
|
+
}
|
|
2123
|
+
const routePatterns = [
|
|
2124
|
+
.../* @__PURE__ */ new Set([
|
|
2125
|
+
...nitro.options.ssrRoutes || [],
|
|
2126
|
+
...[...nitro.scannedHandlers, ...nitro.options.handlers].filter((h) => !h.middleware && h.route).map((h) => h.route)
|
|
2127
|
+
])
|
|
2128
|
+
];
|
|
2129
|
+
const staticRoutes = [];
|
|
2130
|
+
const dynamicRoutes = [];
|
|
2131
|
+
const catchAllRoutes = [];
|
|
2132
|
+
for (const route of routePatterns) {
|
|
2133
|
+
if (route.includes("**")) {
|
|
2134
|
+
catchAllRoutes.push(route);
|
|
2135
|
+
} else if (route.includes(":") || route.includes("*")) {
|
|
2136
|
+
dynamicRoutes.push(route);
|
|
2137
|
+
} else {
|
|
2138
|
+
staticRoutes.push(route);
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
return [
|
|
2142
|
+
...normalizeRoutes(staticRoutes),
|
|
2143
|
+
...normalizeRoutes(dynamicRoutes),
|
|
2144
|
+
...normalizeRoutes(catchAllRoutes)
|
|
2145
|
+
];
|
|
2146
|
+
}
|
|
2147
|
+
function normalizeRoutes(routes) {
|
|
2148
|
+
return routes.sort(
|
|
2149
|
+
(a, b) => (
|
|
2150
|
+
// a.split("/").length - b.split("/").length ||
|
|
2151
|
+
b.localeCompare(a)
|
|
2152
|
+
)
|
|
2153
|
+
).map((route) => ({
|
|
2154
|
+
src: normalizeRouteSrc(route),
|
|
2155
|
+
dest: normalizeRouteDest(route)
|
|
2156
|
+
}));
|
|
2157
|
+
}
|
|
2158
|
+
function normalizeRouteSrc(route) {
|
|
2159
|
+
let idCtr = 0;
|
|
2160
|
+
return route.split("/").map((segment) => {
|
|
2161
|
+
if (segment.startsWith("**")) {
|
|
2162
|
+
return segment === "**" ? "(?:.*)" : `?(?<${namedGroup(segment.slice(3))}>.+)`;
|
|
2163
|
+
}
|
|
2164
|
+
if (segment === "*") {
|
|
2165
|
+
return `(?<_${idCtr++}>[^/]*)`;
|
|
2166
|
+
}
|
|
2167
|
+
if (segment.includes(":")) {
|
|
2168
|
+
return segment.replace(/:(\w+)/g, (_, id) => `(?<${namedGroup(id)}>[^/]+)`).replace(/\./g, String.raw`\.`);
|
|
2169
|
+
}
|
|
2170
|
+
return segment;
|
|
2171
|
+
}).join("/");
|
|
2172
|
+
}
|
|
2173
|
+
function namedGroup(input = "") {
|
|
2174
|
+
if (/\d/.test(input[0])) {
|
|
2175
|
+
input = `_${input}`;
|
|
2176
|
+
}
|
|
2177
|
+
return input.replace(/[^a-zA-Z0-9_]/g, "") || "_";
|
|
2178
|
+
}
|
|
2179
|
+
function normalizeRouteDest(route) {
|
|
2180
|
+
return route.split("/").slice(1).map((segment) => {
|
|
2181
|
+
if (segment.startsWith("**")) {
|
|
2182
|
+
return `[...${segment.replace(/[*:]/g, "")}]`;
|
|
2183
|
+
}
|
|
2184
|
+
if (segment === "*") {
|
|
2185
|
+
return "[-]";
|
|
2186
|
+
}
|
|
2187
|
+
if (segment.startsWith(":")) {
|
|
2188
|
+
return `[${segment.slice(1)}]`;
|
|
2189
|
+
}
|
|
2190
|
+
if (segment.includes(":")) {
|
|
2191
|
+
return `[${segment.replace(/:/g, "_")}]`;
|
|
2192
|
+
}
|
|
2193
|
+
return segment;
|
|
2194
|
+
}).map((segment) => segment.replace(SAFE_FS_CHAR_RE, "-")).join("/") || "index";
|
|
2195
|
+
}
|
|
2196
|
+
async function writePrerenderConfig(filename, isrConfig, bypassToken) {
|
|
2197
|
+
if (typeof isrConfig === "number") {
|
|
2198
|
+
isrConfig = { expiration: isrConfig };
|
|
2199
|
+
} else if (isrConfig === true) {
|
|
2200
|
+
isrConfig = { expiration: false };
|
|
2201
|
+
} else {
|
|
2202
|
+
isrConfig = { ...isrConfig };
|
|
2203
|
+
}
|
|
2204
|
+
const prerenderConfig = {
|
|
2205
|
+
expiration: isrConfig.expiration ?? false,
|
|
2206
|
+
bypassToken,
|
|
2207
|
+
...isrConfig
|
|
2208
|
+
};
|
|
2209
|
+
await writeFile(filename, JSON.stringify(prerenderConfig, null, 2));
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
const vercel = defineNitroPreset(
|
|
2213
|
+
{
|
|
2214
|
+
entry: "./vercel/runtime/vercel",
|
|
2215
|
+
output: {
|
|
2216
|
+
dir: "{{ rootDir }}/.vercel/output",
|
|
2217
|
+
serverDir: "{{ output.dir }}/functions/__fallback.func",
|
|
2218
|
+
publicDir: "{{ output.dir }}/static/{{ baseURL }}"
|
|
2219
|
+
},
|
|
2220
|
+
commands: {
|
|
2221
|
+
deploy: "",
|
|
2222
|
+
preview: ""
|
|
2223
|
+
},
|
|
2224
|
+
hooks: {
|
|
2225
|
+
"rollup:before": (nitro) => {
|
|
2226
|
+
deprecateSWR(nitro);
|
|
2227
|
+
},
|
|
2228
|
+
async compiled(nitro) {
|
|
2229
|
+
await generateFunctionFiles(nitro);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
},
|
|
2233
|
+
{
|
|
2234
|
+
name: "vercel",
|
|
2235
|
+
stdName: "vercel"
|
|
2236
|
+
}
|
|
2237
|
+
);
|
|
2238
|
+
const vercelStatic = defineNitroPreset(
|
|
2239
|
+
{
|
|
2240
|
+
extends: "static",
|
|
2241
|
+
output: {
|
|
2242
|
+
dir: "{{ rootDir }}/.vercel/output",
|
|
2243
|
+
publicDir: "{{ output.dir }}/static/{{ baseURL }}"
|
|
2244
|
+
},
|
|
2245
|
+
commands: {
|
|
2246
|
+
preview: "npx serve ./static"
|
|
2247
|
+
},
|
|
2248
|
+
hooks: {
|
|
2249
|
+
"rollup:before": (nitro) => {
|
|
2250
|
+
deprecateSWR(nitro);
|
|
2251
|
+
},
|
|
2252
|
+
async compiled(nitro) {
|
|
2253
|
+
await generateStaticFiles(nitro);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
},
|
|
2257
|
+
{
|
|
2258
|
+
name: "vercel-static",
|
|
2259
|
+
stdName: "vercel",
|
|
2260
|
+
static: true
|
|
2261
|
+
}
|
|
2262
|
+
);
|
|
2263
|
+
const _vercel = [vercel, vercelStatic];
|
|
2264
|
+
|
|
2265
|
+
const winterjs = defineNitroPreset(
|
|
2266
|
+
{
|
|
2267
|
+
extends: "base-worker",
|
|
2268
|
+
entry: "./winterjs/runtime/winterjs",
|
|
2269
|
+
minify: false,
|
|
2270
|
+
serveStatic: "inline",
|
|
2271
|
+
wasm: {
|
|
2272
|
+
lazy: true
|
|
2273
|
+
},
|
|
2274
|
+
commands: {
|
|
2275
|
+
preview: "wasmer run wasmer/winterjs --forward-host-env --net --mapdir app:./ app/server/index.mjs"
|
|
2276
|
+
}
|
|
2277
|
+
},
|
|
2278
|
+
{
|
|
2279
|
+
name: "winterjs"
|
|
2280
|
+
}
|
|
2281
|
+
);
|
|
2282
|
+
const _winterjs = [winterjs];
|
|
2283
|
+
|
|
2284
|
+
const zeabur = defineNitroPreset(
|
|
2285
|
+
{
|
|
2286
|
+
entry: "./zeabur/runtime/zeabur",
|
|
2287
|
+
output: {
|
|
2288
|
+
dir: "{{ rootDir }}/.zeabur/output",
|
|
2289
|
+
serverDir: "{{ output.dir }}/functions/__nitro.func",
|
|
2290
|
+
publicDir: "{{ output.dir }}/static"
|
|
2291
|
+
},
|
|
2292
|
+
hooks: {
|
|
2293
|
+
async compiled(nitro) {
|
|
2294
|
+
const buildConfigPath = resolve$1(
|
|
2295
|
+
nitro.options.output.dir,
|
|
2296
|
+
"config.json"
|
|
2297
|
+
);
|
|
2298
|
+
const cfg = {
|
|
2299
|
+
containerized: false,
|
|
2300
|
+
routes: [{ src: ".*", dest: "/__nitro" }]
|
|
2301
|
+
};
|
|
2302
|
+
await writeFile(buildConfigPath, JSON.stringify(cfg, null, 2));
|
|
2303
|
+
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
|
|
2304
|
+
if (!value.isr) {
|
|
2305
|
+
continue;
|
|
2306
|
+
}
|
|
2307
|
+
const funcPrefix = resolve$1(
|
|
2308
|
+
nitro.options.output.serverDir,
|
|
2309
|
+
".." + key
|
|
2310
|
+
);
|
|
2311
|
+
await fsp.mkdir(dirname(funcPrefix), { recursive: true });
|
|
2312
|
+
await fsp.symlink(
|
|
2313
|
+
"./" + relative(dirname(funcPrefix), nitro.options.output.serverDir),
|
|
2314
|
+
funcPrefix + ".func",
|
|
2315
|
+
"junction"
|
|
2316
|
+
);
|
|
2317
|
+
await writeFile(
|
|
2318
|
+
funcPrefix + ".prerender-config.json",
|
|
2319
|
+
JSON.stringify({ type: "Prerender" })
|
|
2320
|
+
);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
},
|
|
2325
|
+
{
|
|
2326
|
+
name: "zeabur",
|
|
2327
|
+
stdName: "zeabur"
|
|
2328
|
+
}
|
|
2329
|
+
);
|
|
2330
|
+
const zeaburStatic = defineNitroPreset(
|
|
2331
|
+
{
|
|
2332
|
+
extends: "static",
|
|
2333
|
+
output: {
|
|
2334
|
+
dir: "{{ rootDir }}/.zeabur/output",
|
|
2335
|
+
publicDir: "{{ output.dir }}/static"
|
|
2336
|
+
},
|
|
2337
|
+
commands: {
|
|
2338
|
+
preview: "npx serve ./static"
|
|
2339
|
+
}
|
|
2340
|
+
},
|
|
2341
|
+
{
|
|
2342
|
+
name: "zeabur-static",
|
|
2343
|
+
static: true
|
|
2344
|
+
}
|
|
2345
|
+
);
|
|
2346
|
+
const _zeabur = [zeabur, zeaburStatic];
|
|
2347
|
+
|
|
2348
|
+
const zerops = defineNitroPreset(
|
|
2349
|
+
{
|
|
2350
|
+
extends: "node-server",
|
|
2351
|
+
serveStatic: true
|
|
2352
|
+
},
|
|
2353
|
+
{
|
|
2354
|
+
name: "zerops"
|
|
2355
|
+
}
|
|
2356
|
+
);
|
|
2357
|
+
const zeropsStatic = defineNitroPreset(
|
|
2358
|
+
{
|
|
2359
|
+
extends: "static",
|
|
2360
|
+
output: {
|
|
2361
|
+
dir: "{{ rootDir }}/.zerops/output",
|
|
2362
|
+
publicDir: "{{ output.dir }}/static"
|
|
2363
|
+
}
|
|
2364
|
+
},
|
|
2365
|
+
{
|
|
2366
|
+
name: "zerops-static",
|
|
2367
|
+
static: true
|
|
2368
|
+
}
|
|
2369
|
+
);
|
|
2370
|
+
const _zerops = [zerops, zeropsStatic];
|
|
2371
|
+
|
|
2372
|
+
const allPresets = [
|
|
2373
|
+
..._nitro,
|
|
2374
|
+
..._static$1,
|
|
2375
|
+
..._alwaysdata,
|
|
2376
|
+
..._awsAmplify,
|
|
2377
|
+
..._awsLambda,
|
|
2378
|
+
..._azure,
|
|
2379
|
+
..._bun,
|
|
2380
|
+
..._cleavr,
|
|
2381
|
+
..._cloudflare,
|
|
2382
|
+
..._deno,
|
|
2383
|
+
..._digitalocean,
|
|
2384
|
+
..._firebase,
|
|
2385
|
+
..._flightcontrol,
|
|
2386
|
+
..._genezio,
|
|
2387
|
+
..._heroku,
|
|
2388
|
+
..._iis,
|
|
2389
|
+
..._koyeb,
|
|
2390
|
+
..._netlify,
|
|
2391
|
+
..._node,
|
|
2392
|
+
..._platformSh,
|
|
2393
|
+
..._renderCom,
|
|
2394
|
+
..._standard,
|
|
2395
|
+
..._stormkit,
|
|
2396
|
+
..._vercel,
|
|
2397
|
+
..._winterjs,
|
|
2398
|
+
..._zeabur,
|
|
2399
|
+
..._zerops
|
|
2400
|
+
];
|
|
2401
|
+
|
|
2402
|
+
const _stdProviderMap = {
|
|
2403
|
+
aws_amplify: "aws",
|
|
2404
|
+
azure_static: "azure",
|
|
2405
|
+
cloudflare_pages: "cloudflare"
|
|
2406
|
+
};
|
|
2407
|
+
async function resolvePreset(name, opts = {}) {
|
|
2408
|
+
if (name === ".") {
|
|
2409
|
+
return void 0;
|
|
2410
|
+
}
|
|
2411
|
+
const _name = kebabCase(name) || provider;
|
|
2412
|
+
const _compatDates = opts.compatibilityDate ? resolveCompatibilityDatesFromEnv(opts.compatibilityDate) : false;
|
|
2413
|
+
const matches = allPresets.filter((preset2) => {
|
|
2414
|
+
const names = [preset2._meta.name, preset2._meta.stdName, ...preset2._meta.aliases || []].filter(Boolean);
|
|
2415
|
+
if (!names.includes(_name)) {
|
|
2416
|
+
return false;
|
|
2417
|
+
}
|
|
2418
|
+
if (opts.dev && !preset2._meta.dev || !opts.dev && preset2._meta.dev) {
|
|
2419
|
+
return false;
|
|
2420
|
+
}
|
|
2421
|
+
if (_compatDates) {
|
|
2422
|
+
const _date = _compatDates[_stdProviderMap[preset2._meta.stdName]] || _compatDates[preset2._meta.stdName] || _compatDates[preset2._meta.name] || _compatDates.default;
|
|
2423
|
+
if (_date && preset2._meta.compatibilityDate && new Date(preset2._meta.compatibilityDate) > new Date(_date)) {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
return true;
|
|
2428
|
+
}).sort((a, b) => {
|
|
2429
|
+
const aDate = new Date(a._meta.compatibilityDate || 0);
|
|
2430
|
+
const bDate = new Date(b._meta.compatibilityDate || 0);
|
|
2431
|
+
return bDate > aDate ? 1 : -1;
|
|
2432
|
+
});
|
|
2433
|
+
const preset = matches.find(
|
|
2434
|
+
(p) => (p._meta.static || false) === (opts?.static || false)
|
|
2435
|
+
) || matches[0];
|
|
2436
|
+
if (typeof preset === "function") {
|
|
2437
|
+
return preset();
|
|
2438
|
+
}
|
|
2439
|
+
if (!name && !preset) {
|
|
2440
|
+
return opts?.static ? resolvePreset("static", opts) : resolvePreset("node-server", opts);
|
|
2441
|
+
}
|
|
2442
|
+
if (name && !preset) {
|
|
2443
|
+
const options = allPresets.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);
|
|
2444
|
+
if (options.length > 0) {
|
|
2445
|
+
let msg = `Preset "${name}" cannot be resolved with current compatibilityDate: ${formatCompatibilityDate(_compatDates || "")}.
|
|
2446
|
+
|
|
2447
|
+
`;
|
|
2448
|
+
for (const option of options) {
|
|
2449
|
+
msg += `
|
|
2450
|
+
- ${option._meta.name} (requires compatibilityDate >= ${option._meta.compatibilityDate})`;
|
|
2451
|
+
}
|
|
2452
|
+
const err = new Error(msg);
|
|
2453
|
+
Error.captureStackTrace?.(err, resolvePreset);
|
|
2454
|
+
throw err;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
return preset;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
export { resolvePreset };
|