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/rollup/index.mjs
DELETED
|
@@ -1,1673 +0,0 @@
|
|
|
1
|
-
import { builtinModules, createRequire } from 'node:module';
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import alias from '@rollup/plugin-alias';
|
|
4
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
5
|
-
import inject from '@rollup/plugin-inject';
|
|
6
|
-
import json from '@rollup/plugin-json';
|
|
7
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
8
|
-
import { defu } from 'defu';
|
|
9
|
-
import { isValidNodeImport, normalizeid, parseNodeModulePath, lookupNodeModuleSubpath, resolvePath, sanitizeFilePath } from 'mlly';
|
|
10
|
-
import { runtimeDir, runtimeDependencies } from 'nitro/runtime/meta';
|
|
11
|
-
import { hash } from 'ohash';
|
|
12
|
-
import { resolve, dirname, extname, relative, normalize, isAbsolute, join } from 'pathe';
|
|
13
|
-
import { visualizer } from 'rollup-plugin-visualizer';
|
|
14
|
-
import { isWindows } from 'std-env';
|
|
15
|
-
import * as unenv from 'unenv';
|
|
16
|
-
import unimportPlugin from 'unimport/unplugin';
|
|
17
|
-
import { rollup } from 'unwasm/plugin';
|
|
18
|
-
import { connectors } from 'db0';
|
|
19
|
-
import { camelCase } from 'scule';
|
|
20
|
-
import { createFilter } from '@rollup/pluginutils';
|
|
21
|
-
import { transform } from 'esbuild';
|
|
22
|
-
import { existsSync, promises } from 'node:fs';
|
|
23
|
-
import { platform } from 'node:os';
|
|
24
|
-
import { nodeFileTrace } from '@vercel/nft';
|
|
25
|
-
import { isDirectory } from 'nitro/kit';
|
|
26
|
-
import { readPackageJSON, writePackageJSON } from 'pkg-types';
|
|
27
|
-
import semver from 'semver';
|
|
28
|
-
import { readFile } from 'node:fs/promises';
|
|
29
|
-
import * as _etag from 'etag';
|
|
30
|
-
import _etag__default from 'etag';
|
|
31
|
-
import { globby } from 'globby';
|
|
32
|
-
import mime from 'mime';
|
|
33
|
-
import { withTrailingSlash } from 'ufo';
|
|
34
|
-
import _replace from '@rollup/plugin-replace';
|
|
35
|
-
import { normalizeKey, builtinDrivers } from 'unstorage';
|
|
36
|
-
import { genImport, genSafeVariableName } from 'knitwork';
|
|
37
|
-
|
|
38
|
-
const PREFIX = "\0virtual:";
|
|
39
|
-
function virtual(modules, cache = {}) {
|
|
40
|
-
const _modules = /* @__PURE__ */ new Map();
|
|
41
|
-
for (const [id, mod] of Object.entries(modules)) {
|
|
42
|
-
cache[id] = mod;
|
|
43
|
-
_modules.set(id, mod);
|
|
44
|
-
_modules.set(resolve(id), mod);
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
name: "virtual",
|
|
48
|
-
resolveId(id, importer) {
|
|
49
|
-
if (id in modules) {
|
|
50
|
-
return PREFIX + id;
|
|
51
|
-
}
|
|
52
|
-
if (importer) {
|
|
53
|
-
const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer;
|
|
54
|
-
const resolved = resolve(dirname(importerNoPrefix), id);
|
|
55
|
-
if (_modules.has(resolved)) {
|
|
56
|
-
return PREFIX + resolved;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
},
|
|
61
|
-
async load(id) {
|
|
62
|
-
if (!id.startsWith(PREFIX)) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
const idNoPrefix = id.slice(PREFIX.length);
|
|
66
|
-
if (!_modules.has(idNoPrefix)) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
let m = _modules.get(idNoPrefix);
|
|
70
|
-
if (typeof m === "function") {
|
|
71
|
-
m = await m();
|
|
72
|
-
}
|
|
73
|
-
if (!m) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
cache[id.replace(PREFIX, "")] = m;
|
|
77
|
-
return {
|
|
78
|
-
code: m,
|
|
79
|
-
map: null
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function database(nitro) {
|
|
86
|
-
if (!nitro.options.experimental.database) {
|
|
87
|
-
return virtual(
|
|
88
|
-
{
|
|
89
|
-
"#nitro-internal-virtual/database": () => {
|
|
90
|
-
return (
|
|
91
|
-
/* js */
|
|
92
|
-
`export const connectionConfigs = {};`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
nitro.vfs
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
const dbConfigs = nitro.options.dev && nitro.options.devDatabase || nitro.options.database;
|
|
100
|
-
const connectorsNames = [
|
|
101
|
-
...new Set(
|
|
102
|
-
Object.values(dbConfigs || {}).map((config) => config?.connector)
|
|
103
|
-
)
|
|
104
|
-
].filter(Boolean);
|
|
105
|
-
for (const name of connectorsNames) {
|
|
106
|
-
if (!connectors[name]) {
|
|
107
|
-
throw new Error(`Database connector "${name}" is invalid.`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return virtual(
|
|
111
|
-
{
|
|
112
|
-
"#nitro-internal-virtual/database": () => {
|
|
113
|
-
return `
|
|
114
|
-
${connectorsNames.map(
|
|
115
|
-
(name) => `import ${camelCase(name)}Connector from "${connectors[name]}";`
|
|
116
|
-
).join("\n")}
|
|
117
|
-
|
|
118
|
-
export const connectionConfigs = {
|
|
119
|
-
${Object.entries(dbConfigs || {}).map(
|
|
120
|
-
([name, { connector, options }]) => `${name}: {
|
|
121
|
-
connector: ${camelCase(connector)}Connector,
|
|
122
|
-
options: ${JSON.stringify(options)}
|
|
123
|
-
}`
|
|
124
|
-
).join(",\n")}
|
|
125
|
-
};
|
|
126
|
-
`;
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
nitro.vfs
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const defaultLoaders = {
|
|
134
|
-
".ts": "ts",
|
|
135
|
-
".js": "js",
|
|
136
|
-
".tsx": "tsx",
|
|
137
|
-
".jsx": "jsx"
|
|
138
|
-
};
|
|
139
|
-
function esbuild(options) {
|
|
140
|
-
const {
|
|
141
|
-
include,
|
|
142
|
-
exclude,
|
|
143
|
-
sourceMap,
|
|
144
|
-
loaders: loadersConfig,
|
|
145
|
-
minify,
|
|
146
|
-
...transformOptions
|
|
147
|
-
} = options;
|
|
148
|
-
const loaders = { ...defaultLoaders };
|
|
149
|
-
if (loadersConfig) {
|
|
150
|
-
for (const key of Object.keys(loadersConfig)) {
|
|
151
|
-
const value = loadersConfig[key];
|
|
152
|
-
if (typeof value === "string") {
|
|
153
|
-
loaders[key] = value;
|
|
154
|
-
} else if (value === false) {
|
|
155
|
-
delete loaders[key];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const extensions = Object.keys(loaders);
|
|
160
|
-
const INCLUDE_REGEXP = new RegExp(
|
|
161
|
-
`\\.(${extensions.map((ext) => ext.slice(1)).join("|")})$`
|
|
162
|
-
);
|
|
163
|
-
const EXCLUDE_REGEXP = /node_modules/;
|
|
164
|
-
const filter = createFilter(
|
|
165
|
-
include || INCLUDE_REGEXP,
|
|
166
|
-
exclude || EXCLUDE_REGEXP
|
|
167
|
-
);
|
|
168
|
-
return {
|
|
169
|
-
name: "esbuild",
|
|
170
|
-
async transform(code, id) {
|
|
171
|
-
if (!filter(id)) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
const ext = extname(id);
|
|
175
|
-
const loader = loaders[ext];
|
|
176
|
-
if (!loader) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
const result = await transform(code, {
|
|
180
|
-
sourcemap: sourceMap === "hidden" ? "external" : sourceMap,
|
|
181
|
-
...transformOptions,
|
|
182
|
-
loader,
|
|
183
|
-
sourcefile: id
|
|
184
|
-
});
|
|
185
|
-
printWarnings(id, result, this);
|
|
186
|
-
return result.code && {
|
|
187
|
-
code: result.code,
|
|
188
|
-
map: result.map || null
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
async renderChunk(code) {
|
|
192
|
-
if (minify) {
|
|
193
|
-
const result = await transform(code, {
|
|
194
|
-
loader: "js",
|
|
195
|
-
minify: true,
|
|
196
|
-
target: transformOptions.target
|
|
197
|
-
});
|
|
198
|
-
if (result.code) {
|
|
199
|
-
return {
|
|
200
|
-
code: result.code,
|
|
201
|
-
map: result.map || null
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function printWarnings(id, result, plugin) {
|
|
210
|
-
if (result.warnings) {
|
|
211
|
-
for (const warning of result.warnings) {
|
|
212
|
-
let message = "[esbuild]";
|
|
213
|
-
if (warning.location) {
|
|
214
|
-
message += ` (${relative(process.cwd(), id)}:${warning.location.line}:${warning.location.column})`;
|
|
215
|
-
}
|
|
216
|
-
message += ` ${warning.text}`;
|
|
217
|
-
plugin.warn(message);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function externals(opts) {
|
|
223
|
-
const trackedExternals = /* @__PURE__ */ new Set();
|
|
224
|
-
const _resolveCache = /* @__PURE__ */ new Map();
|
|
225
|
-
const _resolve = async (id) => {
|
|
226
|
-
if (id.startsWith("\0")) {
|
|
227
|
-
return id;
|
|
228
|
-
}
|
|
229
|
-
let resolved = _resolveCache.get(id);
|
|
230
|
-
if (resolved) {
|
|
231
|
-
return resolved;
|
|
232
|
-
}
|
|
233
|
-
resolved = await resolvePath(id, {
|
|
234
|
-
conditions: opts.exportConditions,
|
|
235
|
-
url: opts.moduleDirectories
|
|
236
|
-
});
|
|
237
|
-
_resolveCache.set(id, resolved);
|
|
238
|
-
return resolved;
|
|
239
|
-
};
|
|
240
|
-
const inlineMatchers = (opts.inline || []).map((p) => normalizeMatcher(p)).sort((a, b) => (b.score || 0) - (a.score || 0));
|
|
241
|
-
const externalMatchers = (opts.external || []).map((p) => normalizeMatcher(p)).sort((a, b) => (b.score || 0) - (a.score || 0));
|
|
242
|
-
const isExplicitInline = (id, importer) => {
|
|
243
|
-
if (id.startsWith("\0")) {
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
const inlineMatch = inlineMatchers.find((m) => m(id, importer));
|
|
247
|
-
const externalMatch = externalMatchers.find((m) => m(id, importer));
|
|
248
|
-
if (inlineMatch && (!externalMatch || externalMatch && (inlineMatch.score || 0) > (externalMatch.score || 0))) {
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
return {
|
|
253
|
-
name: "node-externals",
|
|
254
|
-
async resolveId(originalId, importer, options) {
|
|
255
|
-
if (!originalId || originalId.startsWith("\0") || originalId.includes("?") || originalId.startsWith("#")) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
if (originalId.startsWith(".")) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
const id = normalize(originalId);
|
|
262
|
-
if (isExplicitInline(id, importer)) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
const resolved = await this.resolve(originalId, importer, options) || {
|
|
266
|
-
id
|
|
267
|
-
};
|
|
268
|
-
if (isExplicitInline(resolved.id, importer)) {
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
if (!isAbsolute(resolved.id) || !existsSync(resolved.id) || await isDirectory(resolved.id)) {
|
|
272
|
-
resolved.id = await _resolve(resolved.id).catch(() => resolved.id);
|
|
273
|
-
}
|
|
274
|
-
if (!await isValidNodeImport(resolved.id).catch(() => false)) {
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
if (opts.trace === false) {
|
|
278
|
-
return {
|
|
279
|
-
...resolved,
|
|
280
|
-
id: isAbsolute(resolved.id) ? normalizeid(resolved.id) : resolved.id,
|
|
281
|
-
external: true
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
const { name: pkgName } = parseNodeModulePath(resolved.id);
|
|
285
|
-
if (!pkgName) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
if (pkgName !== originalId) {
|
|
289
|
-
if (!isAbsolute(originalId)) {
|
|
290
|
-
const fullPath = await _resolve(originalId);
|
|
291
|
-
trackedExternals.add(fullPath);
|
|
292
|
-
return {
|
|
293
|
-
id: originalId,
|
|
294
|
-
external: true
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
const packageEntry = await _resolve(pkgName).catch(() => null);
|
|
298
|
-
if (packageEntry !== id) {
|
|
299
|
-
const guessedSubpath = await lookupNodeModuleSubpath(id).catch(() => null);
|
|
300
|
-
const resolvedGuess = guessedSubpath && await _resolve(join(pkgName, guessedSubpath)).catch(() => null);
|
|
301
|
-
if (resolvedGuess === id) {
|
|
302
|
-
trackedExternals.add(resolvedGuess);
|
|
303
|
-
return {
|
|
304
|
-
id: join(pkgName, guessedSubpath),
|
|
305
|
-
external: true
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
trackedExternals.add(resolved.id);
|
|
312
|
-
return {
|
|
313
|
-
id: pkgName,
|
|
314
|
-
external: true
|
|
315
|
-
};
|
|
316
|
-
},
|
|
317
|
-
async buildEnd() {
|
|
318
|
-
if (opts.trace === false) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
for (const pkgName of opts.traceInclude || []) {
|
|
322
|
-
const path = await this.resolve(pkgName);
|
|
323
|
-
if (path?.id) {
|
|
324
|
-
trackedExternals.add(path.id.replace(/\?.+/, ""));
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
const _fileTrace = await nodeFileTrace([...trackedExternals], {
|
|
328
|
-
// https://github.com/unjs/nitro/pull/1562
|
|
329
|
-
conditions: (opts.exportConditions || []).filter(
|
|
330
|
-
(c) => !["require", "import", "default"].includes(c)
|
|
331
|
-
),
|
|
332
|
-
...opts.traceOptions
|
|
333
|
-
});
|
|
334
|
-
const _resolveTracedPath = (p) => promises.realpath(resolve(opts.traceOptions?.base || ".", p));
|
|
335
|
-
const tracedFiles = Object.fromEntries(
|
|
336
|
-
await Promise.all(
|
|
337
|
-
[..._fileTrace.reasons.entries()].map(async ([_path, reasons]) => {
|
|
338
|
-
if (reasons.ignored) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
const path = await _resolveTracedPath(_path);
|
|
342
|
-
if (!path.includes("node_modules")) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (!await isFile(path)) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const {
|
|
349
|
-
dir: baseDir,
|
|
350
|
-
name: pkgName,
|
|
351
|
-
subpath
|
|
352
|
-
} = parseNodeModulePath(path);
|
|
353
|
-
if (!baseDir || !pkgName) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
const pkgPath = join(baseDir, pkgName);
|
|
357
|
-
const parents = await Promise.all(
|
|
358
|
-
[...reasons.parents].map((p) => _resolveTracedPath(p))
|
|
359
|
-
);
|
|
360
|
-
const tracedFile = {
|
|
361
|
-
path,
|
|
362
|
-
parents,
|
|
363
|
-
subpath,
|
|
364
|
-
pkgName,
|
|
365
|
-
pkgPath
|
|
366
|
-
};
|
|
367
|
-
return [path, tracedFile];
|
|
368
|
-
})
|
|
369
|
-
).then((r) => r.filter(Boolean))
|
|
370
|
-
);
|
|
371
|
-
const tracedPackages = {};
|
|
372
|
-
for (const tracedFile of Object.values(tracedFiles)) {
|
|
373
|
-
const pkgName = tracedFile.pkgName;
|
|
374
|
-
let tracedPackage = tracedPackages[pkgName];
|
|
375
|
-
let pkgJSON = await readPackageJSON(tracedFile.pkgPath, {
|
|
376
|
-
cache: true
|
|
377
|
-
}).catch(
|
|
378
|
-
() => {
|
|
379
|
-
}
|
|
380
|
-
// TODO: Only catch ENOENT
|
|
381
|
-
);
|
|
382
|
-
if (!pkgJSON) {
|
|
383
|
-
pkgJSON = { name: pkgName, version: "0.0.0" };
|
|
384
|
-
}
|
|
385
|
-
if (!tracedPackage) {
|
|
386
|
-
tracedPackage = {
|
|
387
|
-
name: pkgName,
|
|
388
|
-
versions: {}
|
|
389
|
-
};
|
|
390
|
-
tracedPackages[pkgName] = tracedPackage;
|
|
391
|
-
}
|
|
392
|
-
let tracedPackageVersion = tracedPackage.versions[pkgJSON.version || "0.0.0"];
|
|
393
|
-
if (!tracedPackageVersion) {
|
|
394
|
-
tracedPackageVersion = {
|
|
395
|
-
path: tracedFile.pkgPath,
|
|
396
|
-
files: [],
|
|
397
|
-
pkgJSON
|
|
398
|
-
};
|
|
399
|
-
tracedPackage.versions[pkgJSON.version || "0.0.0"] = tracedPackageVersion;
|
|
400
|
-
}
|
|
401
|
-
tracedPackageVersion.files.push(tracedFile.path);
|
|
402
|
-
tracedFile.pkgName = pkgName;
|
|
403
|
-
if (pkgJSON.version) {
|
|
404
|
-
tracedFile.pkgVersion = pkgJSON.version;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
const usedAliases = {};
|
|
408
|
-
const writePackage = async (name, version, _pkgPath) => {
|
|
409
|
-
const pkg = tracedPackages[name];
|
|
410
|
-
const pkgPath = _pkgPath || pkg.name;
|
|
411
|
-
for (const src of pkg.versions[version].files) {
|
|
412
|
-
const { subpath } = parseNodeModulePath(src);
|
|
413
|
-
if (!subpath) {
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
const dst = join(opts.outDir, "node_modules", pkgPath, subpath);
|
|
417
|
-
await promises.mkdir(dirname(dst), { recursive: true });
|
|
418
|
-
await promises.copyFile(src, dst);
|
|
419
|
-
}
|
|
420
|
-
const pkgJSON = pkg.versions[version].pkgJSON;
|
|
421
|
-
applyProductionCondition(pkgJSON.exports);
|
|
422
|
-
const pkgJSONPath = join(
|
|
423
|
-
opts.outDir,
|
|
424
|
-
"node_modules",
|
|
425
|
-
pkgPath,
|
|
426
|
-
"package.json"
|
|
427
|
-
);
|
|
428
|
-
await promises.mkdir(dirname(pkgJSONPath), { recursive: true });
|
|
429
|
-
await promises.writeFile(
|
|
430
|
-
pkgJSONPath,
|
|
431
|
-
JSON.stringify(pkgJSON, null, 2),
|
|
432
|
-
"utf8"
|
|
433
|
-
);
|
|
434
|
-
if (opts.traceAlias && pkgPath in opts.traceAlias) {
|
|
435
|
-
usedAliases[opts.traceAlias[pkgPath]] = version;
|
|
436
|
-
await linkPackage(pkgPath, opts.traceAlias[pkgPath]);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
const isWindows = platform() === "win32";
|
|
440
|
-
const linkPackage = async (from, to) => {
|
|
441
|
-
const src = join(opts.outDir, "node_modules", from);
|
|
442
|
-
const dst = join(opts.outDir, "node_modules", to);
|
|
443
|
-
const dstStat = await promises.lstat(dst).catch(() => null);
|
|
444
|
-
const exists = dstStat?.isSymbolicLink();
|
|
445
|
-
if (exists) {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
await promises.mkdir(dirname(dst), { recursive: true });
|
|
449
|
-
await promises.symlink(
|
|
450
|
-
relative(dirname(dst), src),
|
|
451
|
-
dst,
|
|
452
|
-
isWindows ? "junction" : "dir"
|
|
453
|
-
).catch((error) => {
|
|
454
|
-
console.error("Cannot link", from, "to", to, error);
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
const findPackageParents = (pkg, version) => {
|
|
458
|
-
const versionFiles = pkg.versions[version].files.map(
|
|
459
|
-
(path) => tracedFiles[path]
|
|
460
|
-
);
|
|
461
|
-
const parentPkgs = [
|
|
462
|
-
...new Set(
|
|
463
|
-
versionFiles.flatMap(
|
|
464
|
-
(file) => file.parents.map((parentPath) => {
|
|
465
|
-
const parentFile = tracedFiles[parentPath];
|
|
466
|
-
if (parentFile.pkgName === pkg.name) {
|
|
467
|
-
return null;
|
|
468
|
-
}
|
|
469
|
-
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
|
470
|
-
}).filter(Boolean)
|
|
471
|
-
)
|
|
472
|
-
)
|
|
473
|
-
];
|
|
474
|
-
return parentPkgs;
|
|
475
|
-
};
|
|
476
|
-
const multiVersionPkgs = {};
|
|
477
|
-
const singleVersionPackages = [];
|
|
478
|
-
for (const tracedPackage of Object.values(tracedPackages)) {
|
|
479
|
-
const versions = Object.keys(tracedPackage.versions);
|
|
480
|
-
if (versions.length === 1) {
|
|
481
|
-
singleVersionPackages.push(tracedPackage.name);
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
multiVersionPkgs[tracedPackage.name] = {};
|
|
485
|
-
for (const version of versions) {
|
|
486
|
-
multiVersionPkgs[tracedPackage.name][version] = findPackageParents(
|
|
487
|
-
tracedPackage,
|
|
488
|
-
version
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
await Promise.all(
|
|
493
|
-
singleVersionPackages.map((pkgName) => {
|
|
494
|
-
const pkg = tracedPackages[pkgName];
|
|
495
|
-
const version = Object.keys(pkg.versions)[0];
|
|
496
|
-
return writePackage(pkgName, version);
|
|
497
|
-
})
|
|
498
|
-
);
|
|
499
|
-
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
|
500
|
-
const versionEntries = Object.entries(pkgVersions).sort(
|
|
501
|
-
([v1, p1], [v2, p2]) => {
|
|
502
|
-
if (p1.length === 0) {
|
|
503
|
-
return -1;
|
|
504
|
-
}
|
|
505
|
-
if (p2.length === 0) {
|
|
506
|
-
return 1;
|
|
507
|
-
}
|
|
508
|
-
return compareVersions(v1, v2);
|
|
509
|
-
}
|
|
510
|
-
);
|
|
511
|
-
for (const [version, parentPkgs] of versionEntries) {
|
|
512
|
-
await writePackage(pkgName, version, `.nitro/${pkgName}@${version}`);
|
|
513
|
-
await linkPackage(`.nitro/${pkgName}@${version}`, `${pkgName}`);
|
|
514
|
-
for (const parentPkg of parentPkgs) {
|
|
515
|
-
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
|
516
|
-
await (multiVersionPkgs[parentPkgName] ? linkPackage(
|
|
517
|
-
`.nitro/${pkgName}@${version}`,
|
|
518
|
-
`.nitro/${parentPkg}/node_modules/${pkgName}`
|
|
519
|
-
) : linkPackage(
|
|
520
|
-
`.nitro/${pkgName}@${version}`,
|
|
521
|
-
`${parentPkgName}/node_modules/${pkgName}`
|
|
522
|
-
));
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
const userPkg = await readPackageJSON(
|
|
527
|
-
opts.rootDir || process.cwd()
|
|
528
|
-
).catch(() => ({}));
|
|
529
|
-
await writePackageJSON(resolve(opts.outDir, "package.json"), {
|
|
530
|
-
name: (userPkg.name || "server") + "-prod",
|
|
531
|
-
version: userPkg.version || "0.0.0",
|
|
532
|
-
type: "module",
|
|
533
|
-
private: true,
|
|
534
|
-
dependencies: Object.fromEntries(
|
|
535
|
-
[
|
|
536
|
-
...Object.values(tracedPackages).map((pkg) => [
|
|
537
|
-
pkg.name,
|
|
538
|
-
Object.keys(pkg.versions)[0]
|
|
539
|
-
]),
|
|
540
|
-
...Object.entries(usedAliases)
|
|
541
|
-
].sort(([a], [b]) => a.localeCompare(b))
|
|
542
|
-
)
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
function compareVersions(v1 = "0.0.0", v2 = "0.0.0") {
|
|
548
|
-
try {
|
|
549
|
-
return semver.lt(v1, v2, { loose: true }) ? 1 : -1;
|
|
550
|
-
} catch {
|
|
551
|
-
return v1.localeCompare(v2);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
function applyProductionCondition(exports) {
|
|
555
|
-
if (!exports || typeof exports === "string" || Array.isArray(exports)) {
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
if ("production" in exports) {
|
|
559
|
-
if (typeof exports.production === "string") {
|
|
560
|
-
exports.default = exports.production;
|
|
561
|
-
} else {
|
|
562
|
-
Object.assign(exports, exports.production);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
for (const key in exports) {
|
|
566
|
-
applyProductionCondition(exports[key]);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
async function isFile(file) {
|
|
570
|
-
try {
|
|
571
|
-
const stat = await promises.stat(file);
|
|
572
|
-
return stat.isFile();
|
|
573
|
-
} catch (error) {
|
|
574
|
-
if (error?.code === "ENOENT") {
|
|
575
|
-
return false;
|
|
576
|
-
}
|
|
577
|
-
throw error;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
function normalizeMatcher(input) {
|
|
581
|
-
if (typeof input === "function") {
|
|
582
|
-
input.score = input.score ?? 1e4;
|
|
583
|
-
return input;
|
|
584
|
-
}
|
|
585
|
-
if (input instanceof RegExp) {
|
|
586
|
-
const matcher = (id) => input.test(id);
|
|
587
|
-
matcher.score = input.toString().length;
|
|
588
|
-
Object.defineProperty(matcher, "name", { value: `match(${input})` });
|
|
589
|
-
return matcher;
|
|
590
|
-
}
|
|
591
|
-
if (typeof input === "string") {
|
|
592
|
-
const pattern = normalize(input);
|
|
593
|
-
const matcher = (id) => {
|
|
594
|
-
const idWithoutNodeModules = id.split("node_modules/").pop();
|
|
595
|
-
return id.startsWith(pattern) || idWithoutNodeModules?.startsWith(pattern);
|
|
596
|
-
};
|
|
597
|
-
matcher.score = input.length;
|
|
598
|
-
if (!isAbsolute(input) && input[0] !== ".") {
|
|
599
|
-
matcher.score += 1e3;
|
|
600
|
-
}
|
|
601
|
-
Object.defineProperty(matcher, "name", { value: `match(${pattern})` });
|
|
602
|
-
return matcher;
|
|
603
|
-
}
|
|
604
|
-
throw new Error(`Invalid matcher or pattern: ${input}`);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
function handlers(nitro) {
|
|
608
|
-
const getHandlers = () => {
|
|
609
|
-
const handlers2 = [
|
|
610
|
-
...nitro.scannedHandlers,
|
|
611
|
-
...nitro.options.handlers
|
|
612
|
-
];
|
|
613
|
-
const envConditions = new Set(
|
|
614
|
-
[
|
|
615
|
-
nitro.options.dev ? "dev" : "prod",
|
|
616
|
-
nitro.options.preset,
|
|
617
|
-
nitro.options.preset === "nitro-prerender" ? "prerender" : void 0
|
|
618
|
-
].filter(Boolean)
|
|
619
|
-
);
|
|
620
|
-
return handlers2.filter((h) => {
|
|
621
|
-
const envs = (Array.isArray(h.env) ? h.env : [h.env]).filter(
|
|
622
|
-
Boolean
|
|
623
|
-
);
|
|
624
|
-
return envs.length === 0 || envs.some((env) => envConditions.has(env));
|
|
625
|
-
});
|
|
626
|
-
};
|
|
627
|
-
return virtual(
|
|
628
|
-
{
|
|
629
|
-
"#nitro-internal-virtual/server-handlers": () => {
|
|
630
|
-
const handlers2 = getHandlers();
|
|
631
|
-
if (nitro.options.serveStatic) {
|
|
632
|
-
handlers2.unshift({
|
|
633
|
-
middleware: true,
|
|
634
|
-
handler: join(runtimeDir, "internal/static")
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
if (nitro.options.renderer) {
|
|
638
|
-
handlers2.push({
|
|
639
|
-
route: "/**",
|
|
640
|
-
lazy: true,
|
|
641
|
-
handler: nitro.options.renderer
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
extendMiddlewareWithRuleOverlaps(handlers2, nitro.options.routeRules);
|
|
645
|
-
const imports = unique(
|
|
646
|
-
handlers2.filter((h) => !h.lazy).map((h) => h.handler)
|
|
647
|
-
);
|
|
648
|
-
const lazyImports = unique(
|
|
649
|
-
handlers2.filter((h) => h.lazy).map((h) => h.handler)
|
|
650
|
-
);
|
|
651
|
-
const code = (
|
|
652
|
-
/* js */
|
|
653
|
-
`
|
|
654
|
-
${imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`).join("\n")}
|
|
655
|
-
|
|
656
|
-
${lazyImports.map(
|
|
657
|
-
(handler) => `const ${getImportId(handler, true)} = () => import('${handler}');`
|
|
658
|
-
).join("\n")}
|
|
659
|
-
|
|
660
|
-
export const handlers = [
|
|
661
|
-
${handlers2.map(
|
|
662
|
-
(h) => ` { route: '${h.route || ""}', handler: ${getImportId(
|
|
663
|
-
h.handler,
|
|
664
|
-
h.lazy
|
|
665
|
-
)}, lazy: ${!!h.lazy}, middleware: ${!!h.middleware}, method: ${JSON.stringify(
|
|
666
|
-
h.method?.toLowerCase()
|
|
667
|
-
)} }`
|
|
668
|
-
).join(",\n")}
|
|
669
|
-
];
|
|
670
|
-
`.trim()
|
|
671
|
-
);
|
|
672
|
-
return code;
|
|
673
|
-
},
|
|
674
|
-
"#nitro-internal-virtual/server-handlers-meta": () => {
|
|
675
|
-
const handlers2 = getHandlers();
|
|
676
|
-
return (
|
|
677
|
-
/* js */
|
|
678
|
-
`
|
|
679
|
-
${handlers2.map(
|
|
680
|
-
(h) => `import ${getImportId(h.handler)}Meta from "${h.handler}?meta";`
|
|
681
|
-
).join("\n")}
|
|
682
|
-
export const handlersMeta = [
|
|
683
|
-
${handlers2.map(
|
|
684
|
-
(h) => (
|
|
685
|
-
/* js */
|
|
686
|
-
`{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(
|
|
687
|
-
h.method?.toLowerCase()
|
|
688
|
-
)}, meta: ${getImportId(h.handler)}Meta }`
|
|
689
|
-
)
|
|
690
|
-
).join(",\n")}
|
|
691
|
-
];
|
|
692
|
-
`
|
|
693
|
-
);
|
|
694
|
-
}
|
|
695
|
-
},
|
|
696
|
-
nitro.vfs
|
|
697
|
-
);
|
|
698
|
-
}
|
|
699
|
-
function unique(arr) {
|
|
700
|
-
return [...new Set(arr)];
|
|
701
|
-
}
|
|
702
|
-
function getImportId(p, lazy) {
|
|
703
|
-
return (lazy ? "_lazy_" : "_") + hash(p).slice(0, 6);
|
|
704
|
-
}
|
|
705
|
-
const WILDCARD_PATH_RE = /\/\*\*.*$/;
|
|
706
|
-
function extendMiddlewareWithRuleOverlaps(handlers2, routeRules) {
|
|
707
|
-
const rules = Object.entries(routeRules);
|
|
708
|
-
for (const [path, rule] of rules) {
|
|
709
|
-
if (!rule.cache) {
|
|
710
|
-
const isNested = rules.some(
|
|
711
|
-
([p, r]) => r.cache && WILDCARD_PATH_RE.test(p) && path.startsWith(p.replace(WILDCARD_PATH_RE, ""))
|
|
712
|
-
);
|
|
713
|
-
if (!isNested) {
|
|
714
|
-
continue;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
for (const [index, handler] of handlers2.entries()) {
|
|
718
|
-
if (!handler.route || handler.middleware) {
|
|
719
|
-
continue;
|
|
720
|
-
}
|
|
721
|
-
if (handler.route === path) {
|
|
722
|
-
break;
|
|
723
|
-
}
|
|
724
|
-
if (!WILDCARD_PATH_RE.test(handler.route)) {
|
|
725
|
-
continue;
|
|
726
|
-
}
|
|
727
|
-
if (!path.startsWith(handler.route.replace(WILDCARD_PATH_RE, ""))) {
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
|
-
handlers2.splice(index, 0, {
|
|
731
|
-
...handler,
|
|
732
|
-
route: path
|
|
733
|
-
});
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
const virtualPrefix = "\0nitro-handler-meta:";
|
|
740
|
-
const esbuildLoaders = {
|
|
741
|
-
".ts": "ts",
|
|
742
|
-
".js": "js",
|
|
743
|
-
".tsx": "tsx",
|
|
744
|
-
".jsx": "jsx"
|
|
745
|
-
};
|
|
746
|
-
function handlersMeta(nitro) {
|
|
747
|
-
return {
|
|
748
|
-
name: "nitro:handlers-meta",
|
|
749
|
-
async resolveId(id) {
|
|
750
|
-
if (id.startsWith("\0")) {
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
if (id.endsWith(`?meta`)) {
|
|
754
|
-
const resolved = await this.resolve(id.replace(`?meta`, ``));
|
|
755
|
-
if (!resolved) {
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
return virtualPrefix + resolved.id;
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
load(id) {
|
|
762
|
-
if (id.startsWith(virtualPrefix)) {
|
|
763
|
-
const fullPath = id.slice(virtualPrefix.length);
|
|
764
|
-
return readFile(fullPath, { encoding: "utf8" });
|
|
765
|
-
}
|
|
766
|
-
},
|
|
767
|
-
async transform(code, id) {
|
|
768
|
-
if (!id.startsWith(virtualPrefix)) {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
let meta = null;
|
|
772
|
-
try {
|
|
773
|
-
const ext = extname(id);
|
|
774
|
-
const jsCode = await transform(code, {
|
|
775
|
-
loader: esbuildLoaders[ext]
|
|
776
|
-
}).then((r) => r.code);
|
|
777
|
-
const ast = this.parse(jsCode);
|
|
778
|
-
for (const node of ast.body) {
|
|
779
|
-
if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "defineRouteMeta" && node.expression.arguments.length === 1) {
|
|
780
|
-
meta = astToObject(node.expression.arguments[0]);
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
} catch (error) {
|
|
785
|
-
console.warn(
|
|
786
|
-
`[nitro] [handlers-meta] Cannot extra route meta for: ${id}: ${error}`
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
return {
|
|
790
|
-
code: `export default ${JSON.stringify(meta)};`,
|
|
791
|
-
map: null
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
function astToObject(node) {
|
|
797
|
-
switch (node.type) {
|
|
798
|
-
case "ObjectExpression": {
|
|
799
|
-
const obj = {};
|
|
800
|
-
for (const prop of node.properties) {
|
|
801
|
-
if (prop.type === "Property") {
|
|
802
|
-
const key = prop.key.name ?? prop.key.value;
|
|
803
|
-
obj[key] = astToObject(prop.value);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
return obj;
|
|
807
|
-
}
|
|
808
|
-
case "ArrayExpression": {
|
|
809
|
-
return node.elements.map((el) => astToObject(el)).filter(Boolean);
|
|
810
|
-
}
|
|
811
|
-
case "Literal": {
|
|
812
|
-
return node.value;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
const ImportMetaRe = /import\.meta|globalThis._importMeta_/;
|
|
818
|
-
function importMeta(nitro) {
|
|
819
|
-
return {
|
|
820
|
-
name: "import-meta",
|
|
821
|
-
renderChunk(code, chunk) {
|
|
822
|
-
const isEntry = chunk.isEntry;
|
|
823
|
-
if (!isEntry && (!ImportMetaRe.test(code) || code.includes("ROLLUP_NO_REPLACE"))) {
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
const url = nitro.options.node && isEntry && !code.includes("ROLLUP_NO_REPLACE") ? "_import_meta_url_" : '"file:///_entry.js"';
|
|
827
|
-
const envImport = nitro.options.node ? "import process from 'node:process';" : "";
|
|
828
|
-
const env = nitro.options.node ? "process.env" : "{}";
|
|
829
|
-
const ref = "globalThis._importMeta_";
|
|
830
|
-
const stub = `{url:${url},env:${env}}`;
|
|
831
|
-
const stubInit = isEntry ? `${ref}=${stub};` : `${ref}=${ref}||${stub};`;
|
|
832
|
-
return {
|
|
833
|
-
code: envImport + stubInit + code,
|
|
834
|
-
map: null
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
const readAssetHandler = {
|
|
841
|
-
true: "node",
|
|
842
|
-
node: "node",
|
|
843
|
-
false: "null",
|
|
844
|
-
deno: "deno",
|
|
845
|
-
inline: "inline"
|
|
846
|
-
};
|
|
847
|
-
function publicAssets(nitro) {
|
|
848
|
-
return virtual(
|
|
849
|
-
{
|
|
850
|
-
// #nitro-internal-virtual/public-assets-data
|
|
851
|
-
"#nitro-internal-virtual/public-assets-data": async () => {
|
|
852
|
-
const assets = {};
|
|
853
|
-
const files = await globby("**", {
|
|
854
|
-
cwd: nitro.options.output.publicDir,
|
|
855
|
-
absolute: false,
|
|
856
|
-
dot: true
|
|
857
|
-
});
|
|
858
|
-
for (const id of files) {
|
|
859
|
-
let mimeType = mime.getType(id.replace(/\.(gz|br)$/, "")) || "text/plain";
|
|
860
|
-
if (mimeType.startsWith("text")) {
|
|
861
|
-
mimeType += "; charset=utf-8";
|
|
862
|
-
}
|
|
863
|
-
const fullPath = resolve(nitro.options.output.publicDir, id);
|
|
864
|
-
const assetData = await promises.readFile(fullPath);
|
|
865
|
-
const etag = _etag__default(assetData);
|
|
866
|
-
const stat = await promises.stat(fullPath);
|
|
867
|
-
const assetId = "/" + decodeURIComponent(id);
|
|
868
|
-
let encoding;
|
|
869
|
-
if (id.endsWith(".gz")) {
|
|
870
|
-
encoding = "gzip";
|
|
871
|
-
} else if (id.endsWith(".br")) {
|
|
872
|
-
encoding = "br";
|
|
873
|
-
}
|
|
874
|
-
assets[assetId] = {
|
|
875
|
-
type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType,
|
|
876
|
-
encoding,
|
|
877
|
-
etag,
|
|
878
|
-
mtime: stat.mtime.toJSON(),
|
|
879
|
-
size: stat.size,
|
|
880
|
-
path: relative(nitro.options.output.serverDir, fullPath),
|
|
881
|
-
data: nitro.options.serveStatic === "inline" ? assetData.toString("base64") : void 0
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
return `export default ${JSON.stringify(assets, null, 2)};`;
|
|
885
|
-
},
|
|
886
|
-
// #nitro-internal-virtual/public-assets-node
|
|
887
|
-
"#nitro-internal-virtual/public-assets-node": () => {
|
|
888
|
-
return `
|
|
889
|
-
import { promises as fsp } from 'node:fs'
|
|
890
|
-
import { fileURLToPath } from 'node:url'
|
|
891
|
-
import { resolve, dirname } from 'pathe'
|
|
892
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
893
|
-
export function readAsset (id) {
|
|
894
|
-
const serverDir = dirname(fileURLToPath(import.meta.url))
|
|
895
|
-
return fsp.readFile(resolve(serverDir, assets[id].path))
|
|
896
|
-
}`;
|
|
897
|
-
},
|
|
898
|
-
// #nitro-internal-virtual/public-assets-deno
|
|
899
|
-
"#nitro-internal-virtual/public-assets-deno": () => {
|
|
900
|
-
return `
|
|
901
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
902
|
-
export function readAsset (id) {
|
|
903
|
-
// https://deno.com/deploy/docs/serve-static-assets
|
|
904
|
-
const path = '.' + decodeURIComponent(new URL(\`../public\${id}\`, 'file://').pathname)
|
|
905
|
-
return Deno.readFile(path);
|
|
906
|
-
}`;
|
|
907
|
-
},
|
|
908
|
-
// #nitro-internal-virtual/public-assets-null
|
|
909
|
-
"#nitro-internal-virtual/public-assets-null": () => {
|
|
910
|
-
return `
|
|
911
|
-
export function readAsset (id) {
|
|
912
|
-
return Promise.resolve(null);
|
|
913
|
-
}`;
|
|
914
|
-
},
|
|
915
|
-
// #nitro-internal-virtual/public-assets-inline
|
|
916
|
-
"#nitro-internal-virtual/public-assets-inline": () => {
|
|
917
|
-
return `
|
|
918
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
919
|
-
export function readAsset (id) {
|
|
920
|
-
if (!assets[id]) { return undefined }
|
|
921
|
-
if (assets[id]._data) { return assets[id]._data }
|
|
922
|
-
if (!assets[id].data) { return assets[id].data }
|
|
923
|
-
assets[id]._data = Uint8Array.from(atob(assets[id].data), (c) => c.charCodeAt(0))
|
|
924
|
-
return assets[id]._data
|
|
925
|
-
}`;
|
|
926
|
-
},
|
|
927
|
-
// #nitro-internal-virtual/public-assets
|
|
928
|
-
"#nitro-internal-virtual/public-assets": () => {
|
|
929
|
-
const publicAssetBases = Object.fromEntries(
|
|
930
|
-
nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [
|
|
931
|
-
withTrailingSlash(dir.baseURL),
|
|
932
|
-
{ maxAge: dir.maxAge }
|
|
933
|
-
])
|
|
934
|
-
);
|
|
935
|
-
const handlerName = readAssetHandler[nitro.options.serveStatic] || "null";
|
|
936
|
-
const readAssetImport = `#nitro-internal-virtual/public-assets-${handlerName}`;
|
|
937
|
-
return `
|
|
938
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
939
|
-
export { readAsset } from "${readAssetImport}"
|
|
940
|
-
export const publicAssetBases = ${JSON.stringify(publicAssetBases)}
|
|
941
|
-
|
|
942
|
-
export function isPublicAssetURL(id = '') {
|
|
943
|
-
if (assets[id]) {
|
|
944
|
-
return true
|
|
945
|
-
}
|
|
946
|
-
for (const base in publicAssetBases) {
|
|
947
|
-
if (id.startsWith(base)) { return true }
|
|
948
|
-
}
|
|
949
|
-
return false
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
export function getPublicAssetMeta(id = '') {
|
|
953
|
-
for (const base in publicAssetBases) {
|
|
954
|
-
if (id.startsWith(base)) { return publicAssetBases[base] }
|
|
955
|
-
}
|
|
956
|
-
return {}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
export function getAsset (id) {
|
|
960
|
-
return assets[id]
|
|
961
|
-
}
|
|
962
|
-
`;
|
|
963
|
-
}
|
|
964
|
-
},
|
|
965
|
-
nitro.vfs
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
const HELPER_ID = "\0raw-helpers";
|
|
970
|
-
function raw(opts = {}) {
|
|
971
|
-
const extensions = /* @__PURE__ */ new Set([
|
|
972
|
-
".md",
|
|
973
|
-
".mdx",
|
|
974
|
-
".txt",
|
|
975
|
-
".css",
|
|
976
|
-
".htm",
|
|
977
|
-
".html",
|
|
978
|
-
...opts.extensions || []
|
|
979
|
-
]);
|
|
980
|
-
return {
|
|
981
|
-
name: "raw",
|
|
982
|
-
async resolveId(id, importer) {
|
|
983
|
-
if (id === HELPER_ID) {
|
|
984
|
-
return id;
|
|
985
|
-
}
|
|
986
|
-
if (id[0] === "\0") {
|
|
987
|
-
return;
|
|
988
|
-
}
|
|
989
|
-
let isRawId = id.startsWith("raw:");
|
|
990
|
-
if (isRawId) {
|
|
991
|
-
id = id.slice(4);
|
|
992
|
-
} else if (extensions.has(extname(id))) {
|
|
993
|
-
isRawId = true;
|
|
994
|
-
}
|
|
995
|
-
if (!isRawId) {
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
const resolvedId = (await this.resolve(id, importer, { skipSelf: true }))?.id;
|
|
999
|
-
if (!resolvedId || resolvedId.startsWith("\0")) {
|
|
1000
|
-
return resolvedId;
|
|
1001
|
-
}
|
|
1002
|
-
return { id: "\0raw:" + resolvedId };
|
|
1003
|
-
},
|
|
1004
|
-
load(id) {
|
|
1005
|
-
if (id === HELPER_ID) {
|
|
1006
|
-
return getHelpers();
|
|
1007
|
-
}
|
|
1008
|
-
if (id.startsWith("\0raw:")) {
|
|
1009
|
-
return promises.readFile(id.slice(5), isBinary(id) ? "binary" : "utf8");
|
|
1010
|
-
}
|
|
1011
|
-
},
|
|
1012
|
-
transform(code, id) {
|
|
1013
|
-
if (!id.startsWith("\0raw:")) {
|
|
1014
|
-
return;
|
|
1015
|
-
}
|
|
1016
|
-
if (isBinary(id)) {
|
|
1017
|
-
const serialized = Buffer.from(code, "binary").toString("base64");
|
|
1018
|
-
return {
|
|
1019
|
-
code: `// ROLLUP_NO_REPLACE
|
|
1020
|
-
import {base64ToUint8Array } from "${HELPER_ID}"
|
|
1021
|
-
export default base64ToUint8Array("${serialized}")`,
|
|
1022
|
-
map: null
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
return {
|
|
1026
|
-
code: `// ROLLUP_NO_REPLACE
|
|
1027
|
-
export default ${JSON.stringify(code)}`,
|
|
1028
|
-
map: null
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
function isBinary(id) {
|
|
1034
|
-
const idMime = mime.getType(id) || "";
|
|
1035
|
-
if (idMime.startsWith("text/")) {
|
|
1036
|
-
return false;
|
|
1037
|
-
}
|
|
1038
|
-
if (/application\/(json|xml|yaml)/.test(idMime)) {
|
|
1039
|
-
return false;
|
|
1040
|
-
}
|
|
1041
|
-
return true;
|
|
1042
|
-
}
|
|
1043
|
-
function getHelpers() {
|
|
1044
|
-
const js = String.raw;
|
|
1045
|
-
return js`
|
|
1046
|
-
export function base64ToUint8Array(str) {
|
|
1047
|
-
const data = atob(str);
|
|
1048
|
-
const size = data.length;
|
|
1049
|
-
const bytes = new Uint8Array(size);
|
|
1050
|
-
for (let i = 0; i < size; i++) {
|
|
1051
|
-
bytes[i] = data.charCodeAt(i);
|
|
1052
|
-
}
|
|
1053
|
-
return bytes;
|
|
1054
|
-
}
|
|
1055
|
-
`;
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
const NO_REPLACE_RE = /ROLLUP_NO_REPLACE/;
|
|
1059
|
-
function replace(options) {
|
|
1060
|
-
const _plugin = _replace(options);
|
|
1061
|
-
return {
|
|
1062
|
-
..._plugin,
|
|
1063
|
-
// https://github.com/rollup/plugins/blob/master/packages/replace/src/index.js#L94
|
|
1064
|
-
renderChunk(code, chunk, options2) {
|
|
1065
|
-
if (!NO_REPLACE_RE.test(code)) {
|
|
1066
|
-
return _plugin.renderChunk.call(this, code, chunk, options2);
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
const createEtag = _etag.default || _etag;
|
|
1073
|
-
function serverAssets(nitro) {
|
|
1074
|
-
if (nitro.options.dev || nitro.options.preset === "nitro-prerender") {
|
|
1075
|
-
return virtual(
|
|
1076
|
-
{ "#nitro-internal-virtual/server-assets": getAssetsDev(nitro) },
|
|
1077
|
-
nitro.vfs
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
return virtual(
|
|
1081
|
-
{
|
|
1082
|
-
"#nitro-internal-virtual/server-assets": async () => {
|
|
1083
|
-
const assets = {};
|
|
1084
|
-
for (const asset of nitro.options.serverAssets) {
|
|
1085
|
-
const files = await globby("**/*.*", {
|
|
1086
|
-
cwd: asset.dir,
|
|
1087
|
-
absolute: false,
|
|
1088
|
-
ignore: asset.ignore
|
|
1089
|
-
});
|
|
1090
|
-
for (const _id of files) {
|
|
1091
|
-
const fsPath = resolve(asset.dir, _id);
|
|
1092
|
-
const id = asset.baseName + "/" + _id;
|
|
1093
|
-
assets[id] = { fsPath, meta: {} };
|
|
1094
|
-
let type = mime.getType(id) || "text/plain";
|
|
1095
|
-
if (type.startsWith("text")) {
|
|
1096
|
-
type += "; charset=utf-8";
|
|
1097
|
-
}
|
|
1098
|
-
const etag = createEtag(await promises.readFile(fsPath));
|
|
1099
|
-
const mtime = await promises.stat(fsPath).then((s) => s.mtime.toJSON());
|
|
1100
|
-
assets[id].meta = { type, etag, mtime };
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
return getAssetProd(assets);
|
|
1104
|
-
}
|
|
1105
|
-
},
|
|
1106
|
-
nitro.vfs
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
function getAssetsDev(nitro) {
|
|
1110
|
-
return `
|
|
1111
|
-
import { createStorage } from 'unstorage'
|
|
1112
|
-
import fsDriver from 'unstorage/drivers/fs'
|
|
1113
|
-
|
|
1114
|
-
const serverAssets = ${JSON.stringify(nitro.options.serverAssets)}
|
|
1115
|
-
|
|
1116
|
-
export const assets = createStorage()
|
|
1117
|
-
|
|
1118
|
-
for (const asset of serverAssets) {
|
|
1119
|
-
assets.mount(asset.baseName, fsDriver({ base: asset.dir, ignore: (asset?.ignore || []) }))
|
|
1120
|
-
}`;
|
|
1121
|
-
}
|
|
1122
|
-
function getAssetProd(assets) {
|
|
1123
|
-
return `
|
|
1124
|
-
const _assets = {
|
|
1125
|
-
${Object.entries(assets).map(
|
|
1126
|
-
([id, asset]) => ` [${JSON.stringify(
|
|
1127
|
-
normalizeKey(id)
|
|
1128
|
-
)}]: {
|
|
1129
|
-
import: () => import(${JSON.stringify(
|
|
1130
|
-
"raw:" + asset.fsPath
|
|
1131
|
-
)}).then(r => r.default || r),
|
|
1132
|
-
meta: ${JSON.stringify(
|
|
1133
|
-
asset.meta
|
|
1134
|
-
)}
|
|
1135
|
-
}`
|
|
1136
|
-
).join(",\n")}
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
const normalizeKey = ${normalizeKey.toString()}
|
|
1140
|
-
|
|
1141
|
-
export const assets = {
|
|
1142
|
-
getKeys() {
|
|
1143
|
-
return Promise.resolve(Object.keys(_assets))
|
|
1144
|
-
},
|
|
1145
|
-
hasItem (id) {
|
|
1146
|
-
id = normalizeKey(id)
|
|
1147
|
-
return Promise.resolve(id in _assets)
|
|
1148
|
-
},
|
|
1149
|
-
getItem (id) {
|
|
1150
|
-
id = normalizeKey(id)
|
|
1151
|
-
return Promise.resolve(_assets[id] ? _assets[id].import() : null)
|
|
1152
|
-
},
|
|
1153
|
-
getMeta (id) {
|
|
1154
|
-
id = normalizeKey(id)
|
|
1155
|
-
return Promise.resolve(_assets[id] ? _assets[id].meta : {})
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
`;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
function sourcemapMininify() {
|
|
1162
|
-
return {
|
|
1163
|
-
name: "nitro:sourcemap-minify",
|
|
1164
|
-
generateBundle(_options, bundle) {
|
|
1165
|
-
for (const [key, asset] of Object.entries(bundle)) {
|
|
1166
|
-
if (!key.endsWith(".map") || !("source" in asset) || typeof asset.source !== "string") {
|
|
1167
|
-
continue;
|
|
1168
|
-
}
|
|
1169
|
-
const sourcemap = JSON.parse(asset.source);
|
|
1170
|
-
if (!(sourcemap.sources || []).some((s) => s.includes("node_modules"))) {
|
|
1171
|
-
continue;
|
|
1172
|
-
}
|
|
1173
|
-
sourcemap.mappings = "";
|
|
1174
|
-
asset.source = JSON.stringify(sourcemap);
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
function storage(nitro) {
|
|
1181
|
-
const mounts = [];
|
|
1182
|
-
const isDevOrPrerender = nitro.options.dev || nitro.options.preset === "nitro-prerender";
|
|
1183
|
-
const storageMounts = isDevOrPrerender ? { ...nitro.options.storage, ...nitro.options.devStorage } : nitro.options.storage;
|
|
1184
|
-
for (const path in storageMounts) {
|
|
1185
|
-
const mount = storageMounts[path];
|
|
1186
|
-
mounts.push({
|
|
1187
|
-
path,
|
|
1188
|
-
driver: builtinDrivers[mount.driver] || mount.driver,
|
|
1189
|
-
opts: mount
|
|
1190
|
-
});
|
|
1191
|
-
}
|
|
1192
|
-
const driverImports = [...new Set(mounts.map((m) => m.driver))];
|
|
1193
|
-
const bundledStorageCode = `
|
|
1194
|
-
import { prefixStorage } from 'unstorage'
|
|
1195
|
-
import overlay from 'unstorage/drivers/overlay'
|
|
1196
|
-
import memory from 'unstorage/drivers/memory'
|
|
1197
|
-
|
|
1198
|
-
const bundledStorage = ${JSON.stringify(nitro.options.bundledStorage)}
|
|
1199
|
-
for (const base of bundledStorage) {
|
|
1200
|
-
storage.mount(base, overlay({
|
|
1201
|
-
layers: [
|
|
1202
|
-
memory(),
|
|
1203
|
-
// TODO
|
|
1204
|
-
// prefixStorage(storage, base),
|
|
1205
|
-
prefixStorage(storage, 'assets:nitro:bundled:' + base)
|
|
1206
|
-
]
|
|
1207
|
-
}))
|
|
1208
|
-
}`;
|
|
1209
|
-
return virtual(
|
|
1210
|
-
{
|
|
1211
|
-
"#nitro-internal-virtual/storage": `
|
|
1212
|
-
import { createStorage } from 'unstorage'
|
|
1213
|
-
import { assets } from '#nitro-internal-virtual/server-assets'
|
|
1214
|
-
|
|
1215
|
-
${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
|
|
1216
|
-
|
|
1217
|
-
export const storage = createStorage({})
|
|
1218
|
-
|
|
1219
|
-
storage.mount('/assets', assets)
|
|
1220
|
-
|
|
1221
|
-
${mounts.map(
|
|
1222
|
-
(m) => `storage.mount('${m.path}', ${genSafeVariableName(
|
|
1223
|
-
m.driver
|
|
1224
|
-
)}(${JSON.stringify(m.opts)}))`
|
|
1225
|
-
).join("\n")}
|
|
1226
|
-
|
|
1227
|
-
${!isDevOrPrerender && nitro.options.bundledStorage.length > 0 ? bundledStorageCode : ""}
|
|
1228
|
-
`
|
|
1229
|
-
},
|
|
1230
|
-
nitro.vfs
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
const TIMING = "globalThis.__timing__";
|
|
1235
|
-
const iife = (code) => `(function() { ${code.trim()} })();`.replace(/\n/g, "");
|
|
1236
|
-
const HELPER = iife(`
|
|
1237
|
-
const start = () => Date.now();
|
|
1238
|
-
const end = s => Date.now() - s;
|
|
1239
|
-
const _s = {};
|
|
1240
|
-
const metrics = [];
|
|
1241
|
-
const logStart = id => { _s[id] = Date.now(); };
|
|
1242
|
-
const logEnd = id => { const t = end(_s[id]); delete _s[id]; metrics.push([id, t]); if (t > 0) { console.debug('>', id + ' (' + t + 'ms)'); } };
|
|
1243
|
-
${TIMING} = { start, end, metrics, logStart, logEnd };
|
|
1244
|
-
`);
|
|
1245
|
-
const HELPERIMPORT = "import './timing.js';";
|
|
1246
|
-
function timing(_opts = {}) {
|
|
1247
|
-
return {
|
|
1248
|
-
name: "timing",
|
|
1249
|
-
generateBundle() {
|
|
1250
|
-
this.emitFile({
|
|
1251
|
-
type: "asset",
|
|
1252
|
-
fileName: "timing.js",
|
|
1253
|
-
source: HELPER
|
|
1254
|
-
});
|
|
1255
|
-
},
|
|
1256
|
-
renderChunk(code, chunk) {
|
|
1257
|
-
let name = chunk.fileName || "";
|
|
1258
|
-
name = name.replace(extname(name), "");
|
|
1259
|
-
const logName = name === "index" ? "Nitro Start" : "Load " + name;
|
|
1260
|
-
return {
|
|
1261
|
-
code: (chunk.isEntry ? HELPERIMPORT : "") + `${TIMING}.logStart('${logName}');` + code + `;${TIMING}.logEnd('${logName}');`,
|
|
1262
|
-
map: null
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
function resolveAliases(_aliases) {
|
|
1269
|
-
const aliases = Object.fromEntries(
|
|
1270
|
-
Object.entries(_aliases).sort(
|
|
1271
|
-
([a], [b]) => b.split("/").length - a.split("/").length || b.length - a.length
|
|
1272
|
-
)
|
|
1273
|
-
);
|
|
1274
|
-
for (const key in aliases) {
|
|
1275
|
-
for (const alias in aliases) {
|
|
1276
|
-
if (!["~", "@", "#"].includes(alias[0])) {
|
|
1277
|
-
continue;
|
|
1278
|
-
}
|
|
1279
|
-
if (alias === "@" && !aliases[key].startsWith("@/")) {
|
|
1280
|
-
continue;
|
|
1281
|
-
}
|
|
1282
|
-
if (aliases[key].startsWith(alias)) {
|
|
1283
|
-
aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
return aliases;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
const getRollupConfig = (nitro) => {
|
|
1291
|
-
const extensions = [
|
|
1292
|
-
".ts",
|
|
1293
|
-
".mjs",
|
|
1294
|
-
".js",
|
|
1295
|
-
".json",
|
|
1296
|
-
".node",
|
|
1297
|
-
".tsx",
|
|
1298
|
-
".jsx"
|
|
1299
|
-
];
|
|
1300
|
-
const nodePreset = nitro.options.node === false ? unenv.nodeless : unenv.node;
|
|
1301
|
-
const builtinPreset = {
|
|
1302
|
-
alias: {
|
|
1303
|
-
// General
|
|
1304
|
-
...nitro.options.dev ? {} : {
|
|
1305
|
-
debug: "unenv/runtime/npm/debug",
|
|
1306
|
-
"consola/core": "consola/core",
|
|
1307
|
-
consola: "unenv/runtime/npm/consola"
|
|
1308
|
-
},
|
|
1309
|
-
...nitro.options.alias
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
const env = unenv.env(nodePreset, builtinPreset, nitro.options.unenv);
|
|
1313
|
-
const buildServerDir = join(nitro.options.buildDir, "dist/server");
|
|
1314
|
-
const presetsDir = resolve(runtimeDir, "../presets");
|
|
1315
|
-
const chunkNamePrefixes = [
|
|
1316
|
-
[nitro.options.buildDir, "build"],
|
|
1317
|
-
[buildServerDir, "app"],
|
|
1318
|
-
[runtimeDir, "nitro"],
|
|
1319
|
-
[presetsDir, "nitro"],
|
|
1320
|
-
["\0raw:", "raw"],
|
|
1321
|
-
["\0nitro-wasm:", "wasm"],
|
|
1322
|
-
["\0", "virtual"]
|
|
1323
|
-
];
|
|
1324
|
-
function getChunkGroup(id) {
|
|
1325
|
-
if (id.startsWith(runtimeDir) || id.startsWith(presetsDir)) {
|
|
1326
|
-
return "nitro";
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
function getChunkName(id) {
|
|
1330
|
-
for (const [dir, name] of chunkNamePrefixes) {
|
|
1331
|
-
if (id.startsWith(dir)) {
|
|
1332
|
-
return `chunks/${name}/[name].mjs`;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
const routeHandler = nitro.options.handlers.find((h) => id.startsWith(h.handler)) || nitro.scannedHandlers.find((h) => id.startsWith(h.handler));
|
|
1336
|
-
if (routeHandler?.route) {
|
|
1337
|
-
const path = routeHandler.route.replace(/:([^/]+)/g, "_$1").replace(/\/[^/]+$/g, "") || "/";
|
|
1338
|
-
return `chunks/routes${path}/[name].mjs`;
|
|
1339
|
-
}
|
|
1340
|
-
const taskHandler = Object.entries(nitro.options.tasks).find(
|
|
1341
|
-
([_, task]) => task.handler === id
|
|
1342
|
-
);
|
|
1343
|
-
if (taskHandler) {
|
|
1344
|
-
return `chunks/tasks/[name].mjs`;
|
|
1345
|
-
}
|
|
1346
|
-
return `chunks/_/[name].mjs`;
|
|
1347
|
-
}
|
|
1348
|
-
const rollupConfig = defu(nitro.options.rollupConfig, {
|
|
1349
|
-
input: nitro.options.entry,
|
|
1350
|
-
output: {
|
|
1351
|
-
dir: nitro.options.output.serverDir,
|
|
1352
|
-
entryFileNames: "index.mjs",
|
|
1353
|
-
chunkFileNames(chunk) {
|
|
1354
|
-
const lastModule = normalize(chunk.moduleIds.at(-1) || "");
|
|
1355
|
-
return getChunkName(lastModule);
|
|
1356
|
-
},
|
|
1357
|
-
manualChunks(id) {
|
|
1358
|
-
return getChunkGroup(id);
|
|
1359
|
-
},
|
|
1360
|
-
inlineDynamicImports: nitro.options.inlineDynamicImports,
|
|
1361
|
-
format: "esm",
|
|
1362
|
-
exports: "auto",
|
|
1363
|
-
intro: "",
|
|
1364
|
-
outro: "",
|
|
1365
|
-
generatedCode: {
|
|
1366
|
-
constBindings: true
|
|
1367
|
-
},
|
|
1368
|
-
sanitizeFileName: sanitizeFilePath,
|
|
1369
|
-
sourcemap: nitro.options.sourceMap,
|
|
1370
|
-
sourcemapExcludeSources: true,
|
|
1371
|
-
sourcemapIgnoreList(relativePath, sourcemapPath) {
|
|
1372
|
-
return relativePath.includes("node_modules");
|
|
1373
|
-
}
|
|
1374
|
-
},
|
|
1375
|
-
external: env.external,
|
|
1376
|
-
plugins: [],
|
|
1377
|
-
onwarn(warning, rollupWarn) {
|
|
1378
|
-
if (!["CIRCULAR_DEPENDENCY", "EVAL"].includes(warning.code || "") && !warning.message.includes("Unsupported source map comment")) {
|
|
1379
|
-
rollupWarn(warning);
|
|
1380
|
-
}
|
|
1381
|
-
},
|
|
1382
|
-
treeshake: {
|
|
1383
|
-
moduleSideEffects(id) {
|
|
1384
|
-
const normalizedId = normalize(id);
|
|
1385
|
-
const idWithoutNodeModules = normalizedId.split("node_modules/").pop();
|
|
1386
|
-
if (!idWithoutNodeModules) {
|
|
1387
|
-
return false;
|
|
1388
|
-
}
|
|
1389
|
-
if (normalizedId.startsWith(runtimeDir) || idWithoutNodeModules.startsWith(runtimeDir)) {
|
|
1390
|
-
return true;
|
|
1391
|
-
}
|
|
1392
|
-
return nitro.options.moduleSideEffects.some(
|
|
1393
|
-
(m) => normalizedId.startsWith(m) || idWithoutNodeModules.startsWith(m)
|
|
1394
|
-
);
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
if (rollupConfig.output.inlineDynamicImports) {
|
|
1399
|
-
delete rollupConfig.output.manualChunks;
|
|
1400
|
-
}
|
|
1401
|
-
if (nitro.options.timing) {
|
|
1402
|
-
rollupConfig.plugins.push(timing());
|
|
1403
|
-
}
|
|
1404
|
-
if (nitro.options.imports) {
|
|
1405
|
-
rollupConfig.plugins.push(
|
|
1406
|
-
unimportPlugin.rollup(nitro.options.imports)
|
|
1407
|
-
);
|
|
1408
|
-
}
|
|
1409
|
-
rollupConfig.plugins.push(raw());
|
|
1410
|
-
if (nitro.options.experimental.wasm) {
|
|
1411
|
-
rollupConfig.plugins.push(rollup(nitro.options.wasm || {}));
|
|
1412
|
-
}
|
|
1413
|
-
let NODE_ENV = nitro.options.dev ? "development" : "production";
|
|
1414
|
-
if (nitro.options.preset === "nitro-prerender") {
|
|
1415
|
-
NODE_ENV = "prerender";
|
|
1416
|
-
}
|
|
1417
|
-
const buildEnvVars = {
|
|
1418
|
-
NODE_ENV,
|
|
1419
|
-
prerender: nitro.options.preset === "nitro-prerender",
|
|
1420
|
-
server: true,
|
|
1421
|
-
client: false,
|
|
1422
|
-
dev: String(nitro.options.dev),
|
|
1423
|
-
DEBUG: nitro.options.dev
|
|
1424
|
-
};
|
|
1425
|
-
const staticFlags = {
|
|
1426
|
-
dev: nitro.options.dev,
|
|
1427
|
-
preset: nitro.options.preset,
|
|
1428
|
-
prerender: nitro.options.preset === "nitro-prerender",
|
|
1429
|
-
server: true,
|
|
1430
|
-
client: false,
|
|
1431
|
-
nitro: true,
|
|
1432
|
-
// @ts-expect-error
|
|
1433
|
-
"versions.nitro": "",
|
|
1434
|
-
"versions?.nitro": "",
|
|
1435
|
-
// Internal
|
|
1436
|
-
_asyncContext: nitro.options.experimental.asyncContext,
|
|
1437
|
-
_websocket: nitro.options.experimental.websocket,
|
|
1438
|
-
_tasks: nitro.options.experimental.tasks
|
|
1439
|
-
};
|
|
1440
|
-
rollupConfig.plugins.push(importMeta(nitro));
|
|
1441
|
-
rollupConfig.plugins.push(
|
|
1442
|
-
replace({
|
|
1443
|
-
preventAssignment: true,
|
|
1444
|
-
values: {
|
|
1445
|
-
"typeof window": '"undefined"',
|
|
1446
|
-
_import_meta_url_: "import.meta.url",
|
|
1447
|
-
"globalThis.process.": "process.",
|
|
1448
|
-
"process.env.RUNTIME_CONFIG": () => JSON.stringify(nitro.options.runtimeConfig, null, 2),
|
|
1449
|
-
...Object.fromEntries(
|
|
1450
|
-
[".", ";", ")", "[", "]", "}", " "].map((d) => [
|
|
1451
|
-
`import.meta${d}`,
|
|
1452
|
-
`globalThis._importMeta_${d}`
|
|
1453
|
-
])
|
|
1454
|
-
),
|
|
1455
|
-
...Object.fromEntries(
|
|
1456
|
-
[";", "(", "{", "}", " ", " ", "\n"].map((d) => [
|
|
1457
|
-
`${d}global.`,
|
|
1458
|
-
`${d}globalThis.`
|
|
1459
|
-
])
|
|
1460
|
-
),
|
|
1461
|
-
...Object.fromEntries(
|
|
1462
|
-
Object.entries(buildEnvVars).map(([key, val]) => [
|
|
1463
|
-
`process.env.${key}`,
|
|
1464
|
-
JSON.stringify(val)
|
|
1465
|
-
])
|
|
1466
|
-
),
|
|
1467
|
-
...Object.fromEntries(
|
|
1468
|
-
Object.entries(buildEnvVars).map(([key, val]) => [
|
|
1469
|
-
`import.meta.env.${key}`,
|
|
1470
|
-
JSON.stringify(val)
|
|
1471
|
-
])
|
|
1472
|
-
),
|
|
1473
|
-
...Object.fromEntries(
|
|
1474
|
-
Object.entries(staticFlags).map(([key, val]) => [
|
|
1475
|
-
`process.${key}`,
|
|
1476
|
-
JSON.stringify(val)
|
|
1477
|
-
])
|
|
1478
|
-
),
|
|
1479
|
-
...Object.fromEntries(
|
|
1480
|
-
Object.entries(staticFlags).map(([key, val]) => [
|
|
1481
|
-
`import.meta.${key}`,
|
|
1482
|
-
JSON.stringify(val)
|
|
1483
|
-
])
|
|
1484
|
-
),
|
|
1485
|
-
...nitro.options.replace
|
|
1486
|
-
}
|
|
1487
|
-
})
|
|
1488
|
-
);
|
|
1489
|
-
rollupConfig.plugins.push(
|
|
1490
|
-
esbuild({
|
|
1491
|
-
target: "es2019",
|
|
1492
|
-
sourceMap: nitro.options.sourceMap,
|
|
1493
|
-
...nitro.options.esbuild?.options
|
|
1494
|
-
})
|
|
1495
|
-
);
|
|
1496
|
-
rollupConfig.plugins.push(serverAssets(nitro));
|
|
1497
|
-
rollupConfig.plugins.push(publicAssets(nitro));
|
|
1498
|
-
rollupConfig.plugins.push(storage(nitro));
|
|
1499
|
-
rollupConfig.plugins.push(database(nitro));
|
|
1500
|
-
rollupConfig.plugins.push(handlers(nitro));
|
|
1501
|
-
if (nitro.options.experimental.openAPI) {
|
|
1502
|
-
rollupConfig.plugins.push(handlersMeta());
|
|
1503
|
-
}
|
|
1504
|
-
rollupConfig.plugins.push(
|
|
1505
|
-
virtual(
|
|
1506
|
-
{
|
|
1507
|
-
"#nitro-internal-pollyfills": env.polyfill.map((p) => `import '${p}';`).join("\n")
|
|
1508
|
-
},
|
|
1509
|
-
nitro.vfs
|
|
1510
|
-
)
|
|
1511
|
-
);
|
|
1512
|
-
rollupConfig.plugins.push(virtual(nitro.options.virtual, nitro.vfs));
|
|
1513
|
-
const nitroPlugins = [...new Set(nitro.options.plugins)];
|
|
1514
|
-
rollupConfig.plugins.push(
|
|
1515
|
-
virtual(
|
|
1516
|
-
{
|
|
1517
|
-
"#nitro-internal-virtual/plugins": `
|
|
1518
|
-
${nitroPlugins.map((plugin) => `import _${hash(plugin)} from '${plugin}';`).join("\n")}
|
|
1519
|
-
|
|
1520
|
-
export const plugins = [
|
|
1521
|
-
${nitroPlugins.map((plugin) => `_${hash(plugin)}`).join(",\n")}
|
|
1522
|
-
]
|
|
1523
|
-
`
|
|
1524
|
-
},
|
|
1525
|
-
nitro.vfs
|
|
1526
|
-
)
|
|
1527
|
-
);
|
|
1528
|
-
let buildDir = nitro.options.buildDir;
|
|
1529
|
-
if (isWindows && nitro.options.externals?.trace === false && nitro.options.dev) {
|
|
1530
|
-
buildDir = pathToFileURL(buildDir).href;
|
|
1531
|
-
}
|
|
1532
|
-
rollupConfig.plugins.push(
|
|
1533
|
-
alias({
|
|
1534
|
-
entries: resolveAliases({
|
|
1535
|
-
"#build": buildDir,
|
|
1536
|
-
"#nitro-internal-virtual/error-handler": nitro.options.errorHandler,
|
|
1537
|
-
"#internal/nitro": runtimeDir,
|
|
1538
|
-
"nitropack/runtime": runtimeDir,
|
|
1539
|
-
"nitro/runtime": runtimeDir,
|
|
1540
|
-
"~": nitro.options.srcDir,
|
|
1541
|
-
"@/": nitro.options.srcDir,
|
|
1542
|
-
"~~": nitro.options.rootDir,
|
|
1543
|
-
"@@/": nitro.options.rootDir,
|
|
1544
|
-
...env.alias
|
|
1545
|
-
})
|
|
1546
|
-
})
|
|
1547
|
-
);
|
|
1548
|
-
if (nitro.options.noExternals) {
|
|
1549
|
-
rollupConfig.plugins.push({
|
|
1550
|
-
name: "no-externals",
|
|
1551
|
-
async resolveId(id, from, options) {
|
|
1552
|
-
if (nitro.options.node && (id.startsWith("node:") || builtinModules.includes(id))) {
|
|
1553
|
-
return { id, external: true };
|
|
1554
|
-
}
|
|
1555
|
-
const resolved = await this.resolve(id, from, options);
|
|
1556
|
-
if (!resolved) {
|
|
1557
|
-
const _resolved = await resolvePath(id, {
|
|
1558
|
-
url: nitro.options.nodeModulesDirs,
|
|
1559
|
-
conditions: [
|
|
1560
|
-
"default",
|
|
1561
|
-
nitro.options.dev ? "development" : "production",
|
|
1562
|
-
"node",
|
|
1563
|
-
"import",
|
|
1564
|
-
"require"
|
|
1565
|
-
]
|
|
1566
|
-
}).catch(() => null);
|
|
1567
|
-
if (_resolved) {
|
|
1568
|
-
return { id: _resolved, external: false };
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
if (!resolved || resolved.external && !id.endsWith(".wasm")) {
|
|
1572
|
-
throw new Error(
|
|
1573
|
-
`Cannot resolve ${JSON.stringify(id)} from ${JSON.stringify(
|
|
1574
|
-
from
|
|
1575
|
-
)} and externals are not allowed!`
|
|
1576
|
-
);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
});
|
|
1580
|
-
} else {
|
|
1581
|
-
rollupConfig.plugins.push(
|
|
1582
|
-
externals(
|
|
1583
|
-
defu(nitro.options.externals, {
|
|
1584
|
-
outDir: nitro.options.output.serverDir,
|
|
1585
|
-
moduleDirectories: nitro.options.nodeModulesDirs,
|
|
1586
|
-
external: [
|
|
1587
|
-
...nitro.options.dev ? [nitro.options.buildDir] : [],
|
|
1588
|
-
...nitro.options.nodeModulesDirs
|
|
1589
|
-
],
|
|
1590
|
-
inline: [
|
|
1591
|
-
"#",
|
|
1592
|
-
"~",
|
|
1593
|
-
"@/",
|
|
1594
|
-
"~~",
|
|
1595
|
-
"@@/",
|
|
1596
|
-
"virtual:",
|
|
1597
|
-
"nitro/runtime",
|
|
1598
|
-
"nitro/runtime",
|
|
1599
|
-
dirname(nitro.options.entry),
|
|
1600
|
-
...nitro.options.experimental.wasm ? [(id) => id?.endsWith(".wasm")] : [],
|
|
1601
|
-
runtimeDir,
|
|
1602
|
-
nitro.options.srcDir,
|
|
1603
|
-
...nitro.options.handlers.map((m) => m.handler).filter((i) => typeof i === "string"),
|
|
1604
|
-
...nitro.options.dev || nitro.options.preset === "nitro-prerender" || nitro.options.experimental.bundleRuntimeDependencies === false ? [] : runtimeDependencies
|
|
1605
|
-
],
|
|
1606
|
-
traceOptions: {
|
|
1607
|
-
base: "/",
|
|
1608
|
-
processCwd: nitro.options.rootDir,
|
|
1609
|
-
exportsOnly: true
|
|
1610
|
-
},
|
|
1611
|
-
traceAlias: {
|
|
1612
|
-
"h3-nightly": "h3",
|
|
1613
|
-
...nitro.options.externals?.traceAlias
|
|
1614
|
-
},
|
|
1615
|
-
exportConditions: nitro.options.exportConditions
|
|
1616
|
-
})
|
|
1617
|
-
)
|
|
1618
|
-
);
|
|
1619
|
-
}
|
|
1620
|
-
rollupConfig.plugins.push(
|
|
1621
|
-
nodeResolve({
|
|
1622
|
-
extensions,
|
|
1623
|
-
preferBuiltins: !!nitro.options.node,
|
|
1624
|
-
rootDir: nitro.options.rootDir,
|
|
1625
|
-
modulePaths: nitro.options.nodeModulesDirs,
|
|
1626
|
-
// 'module' is intentionally not supported because of externals
|
|
1627
|
-
mainFields: ["main"],
|
|
1628
|
-
exportConditions: nitro.options.exportConditions
|
|
1629
|
-
})
|
|
1630
|
-
);
|
|
1631
|
-
rollupConfig.plugins.push(
|
|
1632
|
-
commonjs({
|
|
1633
|
-
esmExternals: (id) => !id.startsWith("unenv/"),
|
|
1634
|
-
requireReturnsDefault: "auto",
|
|
1635
|
-
...nitro.options.commonJS
|
|
1636
|
-
})
|
|
1637
|
-
);
|
|
1638
|
-
rollupConfig.plugins.push(json());
|
|
1639
|
-
rollupConfig.plugins.push(inject(env.inject));
|
|
1640
|
-
if (nitro.options.minify) {
|
|
1641
|
-
const _terser = createRequire(import.meta.url)("@rollup/plugin-terser");
|
|
1642
|
-
const terser = _terser.default || _terser;
|
|
1643
|
-
rollupConfig.plugins.push(
|
|
1644
|
-
terser({
|
|
1645
|
-
mangle: {
|
|
1646
|
-
keep_fnames: true,
|
|
1647
|
-
keep_classnames: true
|
|
1648
|
-
},
|
|
1649
|
-
format: {
|
|
1650
|
-
comments: false
|
|
1651
|
-
}
|
|
1652
|
-
})
|
|
1653
|
-
);
|
|
1654
|
-
}
|
|
1655
|
-
if (nitro.options.sourceMap && !nitro.options.dev && nitro.options.experimental.sourcemapMinify !== false) {
|
|
1656
|
-
rollupConfig.plugins.push(sourcemapMininify());
|
|
1657
|
-
}
|
|
1658
|
-
if (nitro.options.analyze) {
|
|
1659
|
-
rollupConfig.plugins.push(
|
|
1660
|
-
visualizer({
|
|
1661
|
-
...nitro.options.analyze,
|
|
1662
|
-
filename: (nitro.options.analyze.filename || "stats.html").replace(
|
|
1663
|
-
"{name}",
|
|
1664
|
-
"nitro"
|
|
1665
|
-
),
|
|
1666
|
-
title: "Nitro Server bundle stats"
|
|
1667
|
-
})
|
|
1668
|
-
);
|
|
1669
|
-
}
|
|
1670
|
-
return rollupConfig;
|
|
1671
|
-
};
|
|
1672
|
-
|
|
1673
|
-
export { getRollupConfig };
|