@depup/nitro 3.0.260311-beta-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +29361 -0
- package/dist/_build/rolldown.mjs +173 -0
- package/dist/_build/rollup.mjs +194 -0
- package/dist/_build/vite.build.mjs +18 -0
- package/dist/_chunks/nitro.mjs +1159 -0
- package/dist/_chunks/nitro2.mjs +102 -0
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +272 -0
- package/dist/_common.mjs +35 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +519 -0
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/c12+readdirp+chokidar.d.mts +230 -0
- package/dist/_libs/citty.mjs +361 -0
- package/dist/_libs/commondir+is-reference.mjs +1311 -0
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/compatx.mjs +45 -0
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +7 -0
- package/dist/_libs/estree+pluginutils.d.mts +241 -0
- package/dist/_libs/estree-walker.mjs +184 -0
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +1949 -0
- package/dist/_libs/httpxy.d.mts +82 -0
- package/dist/_libs/httpxy.mjs +671 -0
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +37 -0
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-inject.mjs +131 -0
- package/dist/_libs/plugin-json.mjs +34 -0
- package/dist/_libs/pluginutils.mjs +646 -0
- package/dist/_libs/readdirp+chokidar.mjs +1606 -0
- package/dist/_libs/remapping.mjs +115 -0
- package/dist/_libs/resolve-uri+gen-mapping.mjs +442 -0
- package/dist/_libs/rou3.d.mts +44 -0
- package/dist/_libs/rou3.mjs +496 -0
- package/dist/_libs/std-env.d.mts +12 -0
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +813 -0
- package/dist/_libs/ultrahtml.mjs +127 -0
- package/dist/_libs/unimport+unplugin.mjs +1684 -0
- package/dist/_libs/unplugin+unimport.d.mts +423 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +1759 -0
- package/dist/builder.d.mts +64 -0
- package/dist/builder.mjs +15 -0
- package/dist/cli/_chunks/build.mjs +47 -0
- package/dist/cli/_chunks/common.mjs +14 -0
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +62 -0
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +25 -0
- package/dist/cli/_chunks/prepare.mjs +17 -0
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +53 -0
- package/dist/cli/_chunks/task.mjs +14 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +22 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +139 -0
- package/dist/node_modules/@poppinss/colors/package.json +118 -0
- package/dist/node_modules/@poppinss/dumper/build/chunk-26HALFTP.js +602 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/console/main.js +441 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +725 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +44 -0
- package/dist/node_modules/@poppinss/exception/package.json +109 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1354 -0
- package/dist/node_modules/@sindresorhus/is/distribution/utilities.js +3 -0
- package/dist/node_modules/@sindresorhus/is/package.json +81 -0
- package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -0
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -0
- package/dist/node_modules/@speed-highlight/core/package.json +94 -0
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +73 -0
- package/dist/node_modules/defu/dist/defu.mjs +69 -0
- package/dist/node_modules/defu/package.json +43 -0
- package/dist/node_modules/destr/dist/index.mjs +72 -0
- package/dist/node_modules/destr/package.json +47 -0
- package/dist/node_modules/error-stack-parser-es/dist/index.mjs +38 -0
- package/dist/node_modules/error-stack-parser-es/dist/lite.mjs +167 -0
- package/dist/node_modules/error-stack-parser-es/package.json +83 -0
- package/dist/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/node_modules/get-port-please/package.json +39 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/node_modules/scule/dist/index.mjs +80 -0
- package/dist/node_modules/scule/package.json +43 -0
- package/dist/node_modules/source-map/lib/array-set.js +100 -0
- package/dist/node_modules/source-map/lib/base64-vlq.js +94 -0
- package/dist/node_modules/source-map/lib/base64.js +19 -0
- package/dist/node_modules/source-map/lib/binary-search.js +113 -0
- package/dist/node_modules/source-map/lib/mapping-list.js +83 -0
- package/dist/node_modules/source-map/lib/mappings.wasm +0 -0
- package/dist/node_modules/source-map/lib/read-wasm.js +27 -0
- package/dist/node_modules/source-map/lib/source-map-consumer.js +1081 -0
- package/dist/node_modules/source-map/lib/source-map-generator.js +439 -0
- package/dist/node_modules/source-map/lib/source-node.js +430 -0
- package/dist/node_modules/source-map/lib/url.js +13 -0
- package/dist/node_modules/source-map/lib/util.js +444 -0
- package/dist/node_modules/source-map/lib/wasm.js +138 -0
- package/dist/node_modules/source-map/package.json +79 -0
- package/dist/node_modules/source-map/source-map.js +10 -0
- package/dist/node_modules/supports-color/index.js +202 -0
- package/dist/node_modules/supports-color/package.json +64 -0
- package/dist/node_modules/ufo/dist/index.mjs +645 -0
- package/dist/node_modules/ufo/package.json +48 -0
- package/dist/node_modules/unctx/dist/index.mjs +131 -0
- package/dist/node_modules/unctx/package.json +67 -0
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +212 -0
- package/dist/node_modules/youch/build/public/error_cause/style.css +5 -0
- package/dist/node_modules/youch/build/public/error_info/script.js +13 -0
- package/dist/node_modules/youch/build/public/error_info/style.css +145 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +72 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +219 -0
- package/dist/node_modules/youch/build/public/error_stack_source/style.css +123 -0
- package/dist/node_modules/youch/build/public/header/script.js +14 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +12 -0
- package/dist/node_modules/youch/build/public/layout/style.css +435 -0
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +135 -0
- package/dist/node_modules/youch-core/build/index.js +316 -0
- package/dist/node_modules/youch-core/package.json +124 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +20 -0
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +15 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +23 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +14 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +116 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +31 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +13 -0
- package/dist/presets/azure/runtime/_utils.mjs +50 -0
- package/dist/presets/azure/runtime/azure-swa.mjs +30 -0
- package/dist/presets/bun/runtime/bun.mjs +40 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +87 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +72 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +17 -0
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +39 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +96 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +19 -0
- package/dist/presets/deno/runtime/deno-server.mjs +39 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +20 -0
- package/dist/presets/netlify/runtime/netlify.mjs +20 -0
- package/dist/presets/node/runtime/node-cluster.mjs +54 -0
- package/dist/presets/node/runtime/node-middleware.mjs +14 -0
- package/dist/presets/node/runtime/node-server.mjs +47 -0
- package/dist/presets/standard/runtime/server.mjs +4 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +27 -0
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +24 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +23 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +91 -0
- package/dist/presets/zeabur/runtime/zeabur.mjs +4 -0
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/app.d.mts +1 -0
- package/dist/runtime/app.mjs +1 -0
- package/dist/runtime/cache.d.mts +1 -0
- package/dist/runtime/cache.mjs +1 -0
- package/dist/runtime/config.d.mts +3 -0
- package/dist/runtime/config.mjs +4 -0
- package/dist/runtime/context.d.mts +1 -0
- package/dist/runtime/context.mjs +1 -0
- package/dist/runtime/database.d.mts +1 -0
- package/dist/runtime/database.mjs +1 -0
- package/dist/runtime/internal/app.d.mts +16 -0
- package/dist/runtime/internal/app.mjs +208 -0
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +41 -0
- package/dist/runtime/internal/context.d.mts +14 -0
- package/dist/runtime/internal/context.mjs +24 -0
- package/dist/runtime/internal/database.d.mts +2 -0
- package/dist/runtime/internal/database.mjs +12 -0
- package/dist/runtime/internal/empty.mjs +0 -0
- package/dist/runtime/internal/error/dev.d.mts +10 -0
- package/dist/runtime/internal/error/dev.mjs +121 -0
- package/dist/runtime/internal/error/hooks.d.mts +1 -0
- package/dist/runtime/internal/error/hooks.mjs +9 -0
- package/dist/runtime/internal/error/prod.d.mts +6 -0
- package/dist/runtime/internal/error/prod.mjs +40 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/meta.d.mts +2 -0
- package/dist/runtime/internal/meta.mjs +3 -0
- package/dist/runtime/internal/plugin.d.mts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/runtime/internal/route-rules.d.mts +9 -0
- package/dist/runtime/internal/route-rules.mjs +72 -0
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +25 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +94 -0
- package/dist/runtime/internal/routes/renderer-template.d.mts +2 -0
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +3 -0
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +19 -0
- package/dist/runtime/internal/routes/renderer-template.mjs +4 -0
- package/dist/runtime/internal/routes/scalar.d.mts +3 -0
- package/dist/runtime/internal/routes/scalar.mjs +193 -0
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +42 -0
- package/dist/runtime/internal/runtime-config.d.mts +9 -0
- package/dist/runtime/internal/runtime-config.mjs +54 -0
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +67 -0
- package/dist/runtime/internal/storage.d.mts +2 -0
- package/dist/runtime/internal/storage.mjs +6 -0
- package/dist/runtime/internal/task.d.mts +19 -0
- package/dist/runtime/internal/task.mjs +69 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +18 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +6 -0
- package/dist/runtime/meta.d.mts +5 -0
- package/dist/runtime/meta.mjs +27 -0
- package/dist/runtime/nitro.d.mts +11 -0
- package/dist/runtime/nitro.mjs +34 -0
- package/dist/runtime/runtime-config.d.mts +1 -0
- package/dist/runtime/runtime-config.mjs +1 -0
- package/dist/runtime/storage.d.mts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/task.d.mts +1 -0
- package/dist/runtime/task.mjs +1 -0
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +7 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/runtime/vite.d.mts +8 -0
- package/dist/runtime/vite.mjs +9 -0
- package/dist/types/index.d.mts +3010 -0
- package/dist/types/index.mjs +1 -0
- package/dist/vite.d.mts +52 -0
- package/dist/vite.mjs +740 -0
- package/lib/h3.d.mts +1 -0
- package/lib/h3.mjs +1 -0
- package/lib/tsconfig.json +27 -0
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +256 -0
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// src/parser.ts
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { readFile } from "fs/promises";
|
|
4
|
+
import { Exception } from "@poppinss/exception";
|
|
5
|
+
import { parse } from "error-stack-parser-es";
|
|
6
|
+
|
|
7
|
+
// src/debug.ts
|
|
8
|
+
import { debuglog } from "util";
|
|
9
|
+
var debug_default = debuglog("youch:core");
|
|
10
|
+
|
|
11
|
+
// src/source_file.ts
|
|
12
|
+
var SourceFile = class {
|
|
13
|
+
#contents;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
if ("contents" in options) {
|
|
16
|
+
this.#contents = options.contents;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Slice the file contents for the buffer size around a given
|
|
21
|
+
* line number.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const chunks = sourceFile.slice(11, 7)
|
|
26
|
+
* // Here chunks will be an array of 7 items from line number
|
|
27
|
+
* // 8 to 14
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
slice(lineNumber, bufferSize) {
|
|
31
|
+
if (!this.#contents) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
const lines = this.#contents.split(/\n|\r\n/);
|
|
35
|
+
const contentSize = lines.length;
|
|
36
|
+
const chunkSize = Math.ceil((bufferSize - 1) / 2);
|
|
37
|
+
let startIndex = chunkSize >= lineNumber ? 0 : lineNumber - chunkSize - 1;
|
|
38
|
+
if (contentSize - lineNumber < chunkSize) {
|
|
39
|
+
startIndex = Math.max(startIndex - (chunkSize - (contentSize - lineNumber)), 0);
|
|
40
|
+
}
|
|
41
|
+
const sourceIndex = lineNumber - 1;
|
|
42
|
+
const startRemainder = startIndex - sourceIndex + chunkSize;
|
|
43
|
+
const endIndex = startRemainder + chunkSize + lineNumber;
|
|
44
|
+
debug_default("slicing file contents", {
|
|
45
|
+
startIndex,
|
|
46
|
+
endIndex,
|
|
47
|
+
sourceIndex,
|
|
48
|
+
contentSize,
|
|
49
|
+
bufferSize,
|
|
50
|
+
chunkSize
|
|
51
|
+
});
|
|
52
|
+
return lines.slice(startIndex, endIndex).map((chunk, index) => {
|
|
53
|
+
return {
|
|
54
|
+
chunk,
|
|
55
|
+
lineNumber: startIndex + index + 1
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/parser.ts
|
|
62
|
+
var ErrorParser = class _ErrorParser {
|
|
63
|
+
/**
|
|
64
|
+
* FS source loader reads the file contents from the filesystem
|
|
65
|
+
* for all non-native frames
|
|
66
|
+
*/
|
|
67
|
+
static fsSourceLoader = async (frame) => {
|
|
68
|
+
if (!frame.fileName || frame.fileType !== "fs" || frame.type === "native") {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
debug_default("reading contents for source file %s", frame.fileName);
|
|
72
|
+
try {
|
|
73
|
+
return {
|
|
74
|
+
contents: await readFile(frame.fileName, "utf-8")
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
debug_default(`Unable to read source file %s, error %s`, frame.fileName, error.message);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Native frames filename identifiers for Node.js and
|
|
82
|
+
* Deno
|
|
83
|
+
*/
|
|
84
|
+
#nativeFramesIdentifiers = ["node:", "ext:"];
|
|
85
|
+
/**
|
|
86
|
+
* Native frames filename identifier for Bun. In case of
|
|
87
|
+
* bun, the filename exactly matches the keyword "native"
|
|
88
|
+
*/
|
|
89
|
+
#bunNativeIdentifier = "native";
|
|
90
|
+
/**
|
|
91
|
+
* Cache of preloaded source files along with their absolute
|
|
92
|
+
* path
|
|
93
|
+
*/
|
|
94
|
+
#sourceFiles = /* @__PURE__ */ new Map();
|
|
95
|
+
/**
|
|
96
|
+
* The offset can be used to skip initial frames from the
|
|
97
|
+
* error stack
|
|
98
|
+
*/
|
|
99
|
+
#offset;
|
|
100
|
+
/**
|
|
101
|
+
* Custom source loader to consult for reading the sourcefile
|
|
102
|
+
* contents
|
|
103
|
+
*/
|
|
104
|
+
#sourceLoader = _ErrorParser.fsSourceLoader;
|
|
105
|
+
/**
|
|
106
|
+
* Parsers are used to prepare the source value for parsing
|
|
107
|
+
*/
|
|
108
|
+
#parsers = [];
|
|
109
|
+
/**
|
|
110
|
+
* Transformers are used to post process the parsed error and
|
|
111
|
+
* attach additional information to it.
|
|
112
|
+
*/
|
|
113
|
+
#transformers = [];
|
|
114
|
+
constructor(options) {
|
|
115
|
+
options = options ?? {};
|
|
116
|
+
this.#offset = options.offset;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Normalizes the unknown error to be an Error
|
|
120
|
+
*/
|
|
121
|
+
#normalizeError(source) {
|
|
122
|
+
if (source instanceof Error) {
|
|
123
|
+
return source;
|
|
124
|
+
}
|
|
125
|
+
if (typeof source === "object" && source && "message" in source && "stack" in source) {
|
|
126
|
+
return source;
|
|
127
|
+
}
|
|
128
|
+
const error = new Exception(JSON.stringify(source));
|
|
129
|
+
error.help = 'To get as much information as possible from your errors, make sure to throw Error objects. See <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error</a> for more information.';
|
|
130
|
+
return error;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns the source chunks for a given file and the
|
|
134
|
+
* line number.
|
|
135
|
+
*/
|
|
136
|
+
async #getSource(frame) {
|
|
137
|
+
let sourceFile = this.#sourceFiles.get(frame.fileName);
|
|
138
|
+
if (sourceFile) {
|
|
139
|
+
debug_default("reading sourcefile from cache %s", frame.fileName);
|
|
140
|
+
return sourceFile.slice(frame.lineNumber ?? 1, 11);
|
|
141
|
+
}
|
|
142
|
+
const contents = await this.#sourceLoader(frame);
|
|
143
|
+
if (contents) {
|
|
144
|
+
sourceFile = new SourceFile(contents);
|
|
145
|
+
debug_default("caching sourcefile instance for %s", frame.fileName);
|
|
146
|
+
this.#sourceFiles.set(frame.fileName, sourceFile);
|
|
147
|
+
return sourceFile.slice(frame.lineNumber ?? 1, 11);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Syntax errors in JavaScript does not contain the source file
|
|
152
|
+
* location within the stack trace, since the error has
|
|
153
|
+
* happened in the language parser.
|
|
154
|
+
*
|
|
155
|
+
* However, Node.js includes the absolute path to the file within
|
|
156
|
+
* the stack trace contents as the first line. So we parse
|
|
157
|
+
* that out in this function.
|
|
158
|
+
*/
|
|
159
|
+
#parseSyntaxError(error) {
|
|
160
|
+
const [sourceIdentifier] = error.stack?.split("\n") || [];
|
|
161
|
+
const tokens = sourceIdentifier.split(":");
|
|
162
|
+
const lineNumber = Number(tokens.pop());
|
|
163
|
+
const fileName = tokens.join(":");
|
|
164
|
+
if (fileName && !Number.isNaN(lineNumber)) {
|
|
165
|
+
return [
|
|
166
|
+
{
|
|
167
|
+
fileName,
|
|
168
|
+
lineNumber,
|
|
169
|
+
source: sourceIdentifier
|
|
170
|
+
}
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Applies the offset on the frames to skip certain frames
|
|
177
|
+
* from the start
|
|
178
|
+
*/
|
|
179
|
+
#applyOffset(frames) {
|
|
180
|
+
if (this.#offset) {
|
|
181
|
+
return frames.slice(this.#offset);
|
|
182
|
+
}
|
|
183
|
+
return frames;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Replaces windows slash to unix slash
|
|
187
|
+
*/
|
|
188
|
+
#toUnixSlash(fileName) {
|
|
189
|
+
const isExtendedLengthPath = fileName.startsWith("\\\\?\\");
|
|
190
|
+
return isExtendedLengthPath ? fileName : fileName.replace(/\\/g, "/");
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Normalizes the filename to be a path with unix slash. The
|
|
194
|
+
* URL style paths are also converted to normalized file
|
|
195
|
+
* paths
|
|
196
|
+
*/
|
|
197
|
+
#normalizeFileName(fileName) {
|
|
198
|
+
if (fileName.startsWith("file:")) {
|
|
199
|
+
return this.#toUnixSlash(fileURLToPath(fileName));
|
|
200
|
+
}
|
|
201
|
+
return this.#toUnixSlash(fileName);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Returns the type of the frame.
|
|
205
|
+
*/
|
|
206
|
+
#getFrameType(fileName) {
|
|
207
|
+
return this.#nativeFramesIdentifiers.some((identifier) => fileName.includes(identifier)) || fileName === this.#bunNativeIdentifier ? "native" : fileName.includes("node_modules/") ? "module" : "app";
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns the source type of the frame.
|
|
211
|
+
*/
|
|
212
|
+
#getFrameSourceType(fileName) {
|
|
213
|
+
return fileName.startsWith("http://") ? "http" : fileName.startsWith("https://") ? "https" : "fs";
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Enhances a frame to contain additional information
|
|
217
|
+
*/
|
|
218
|
+
async #enhanceFrames(frames) {
|
|
219
|
+
let stackFrames = [];
|
|
220
|
+
for (const { source: raw, ...frame } of frames) {
|
|
221
|
+
const stackFrame = {
|
|
222
|
+
...frame,
|
|
223
|
+
raw
|
|
224
|
+
};
|
|
225
|
+
if (!stackFrame.fileName) {
|
|
226
|
+
stackFrames.push(stackFrame);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
stackFrame.fileName = this.#normalizeFileName(stackFrame.fileName);
|
|
230
|
+
stackFrame.type = this.#getFrameType(stackFrame.fileName);
|
|
231
|
+
stackFrame.fileType = this.#getFrameSourceType(stackFrame.fileName);
|
|
232
|
+
stackFrame.source = await this.#getSource(stackFrame);
|
|
233
|
+
debug_default("stack frame %O", stackFrame);
|
|
234
|
+
stackFrames.push(stackFrame);
|
|
235
|
+
}
|
|
236
|
+
return stackFrames;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Register a parser. Parsers are synchronous functions
|
|
240
|
+
* that can be used to pre-process the source value
|
|
241
|
+
* before it get parsed.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* sourceFile.useParser((source) => {
|
|
246
|
+
* if (valueCanBeParsed) {
|
|
247
|
+
* return newValue
|
|
248
|
+
* }
|
|
249
|
+
* return source
|
|
250
|
+
* })
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
useParser(parser) {
|
|
254
|
+
this.#parsers.push(parser);
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Register a transformer. Transformers can be async functions
|
|
259
|
+
* to post-process the parsed error value.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* sourceFile.useTransformer((error, source) => {
|
|
264
|
+
* // mutate "error" properties
|
|
265
|
+
* })
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
useTransformer(transformer) {
|
|
269
|
+
this.#transformers.push(transformer);
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Define a custom source loader to load the contents of the
|
|
274
|
+
* source file within the error stack.
|
|
275
|
+
*
|
|
276
|
+
* For example: You might want to register a custom source loader
|
|
277
|
+
* that makes an fetch call to the server to read the source of
|
|
278
|
+
* the file within the error stack.
|
|
279
|
+
*/
|
|
280
|
+
defineSourceLoader(loader) {
|
|
281
|
+
this.#sourceLoader = loader;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Parse an unknown value into a parsed error object.
|
|
286
|
+
*/
|
|
287
|
+
async parse(source) {
|
|
288
|
+
debug_default("parsing source %O", source);
|
|
289
|
+
source = this.#parsers.reduce((result, parser) => {
|
|
290
|
+
result = parser(result);
|
|
291
|
+
return result;
|
|
292
|
+
}, source);
|
|
293
|
+
let error = this.#normalizeError(source);
|
|
294
|
+
debug_default("error normalized to %O", error);
|
|
295
|
+
let esFrames = error instanceof SyntaxError ? this.#parseSyntaxError(error) : [];
|
|
296
|
+
esFrames = esFrames.concat(parse(error, { allowEmpty: true }));
|
|
297
|
+
esFrames = this.#applyOffset(esFrames);
|
|
298
|
+
const parsedError = {
|
|
299
|
+
message: error.message,
|
|
300
|
+
name: error.name,
|
|
301
|
+
frames: await this.#enhanceFrames(esFrames),
|
|
302
|
+
hint: "hint" in error && error.hint ? String(error.hint) : "help" in error && error.help ? String(error.help) : void 0,
|
|
303
|
+
code: "code" in error ? String(error.code) : void 0,
|
|
304
|
+
cause: error.cause,
|
|
305
|
+
stack: error.stack,
|
|
306
|
+
raw: error
|
|
307
|
+
};
|
|
308
|
+
for (const transformer of this.#transformers) {
|
|
309
|
+
await transformer(parsedError, error);
|
|
310
|
+
}
|
|
311
|
+
return parsedError;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
export {
|
|
315
|
+
ErrorParser
|
|
316
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "youch-core",
|
|
3
|
+
"description": "Error parser to parse an error instance into a collection of frames",
|
|
4
|
+
"version": "0.3.3",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"build",
|
|
8
|
+
"!build/bin",
|
|
9
|
+
"!build/examples",
|
|
10
|
+
"!build/tests"
|
|
11
|
+
],
|
|
12
|
+
"main": "build/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./build/index.js",
|
|
15
|
+
"./types": "./build/src/types.js"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"pretest": "npm run lint",
|
|
19
|
+
"test": "c8 npm run quick:test",
|
|
20
|
+
"lint": "eslint .",
|
|
21
|
+
"format": "prettier --write .",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"precompile": "npm run lint",
|
|
24
|
+
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
25
|
+
"build": "npm run compile",
|
|
26
|
+
"version": "npm run build",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"release": "release-it",
|
|
29
|
+
"quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@adonisjs/eslint-config": "^3.0.0-next.0",
|
|
33
|
+
"@adonisjs/prettier-config": "^1.4.5",
|
|
34
|
+
"@adonisjs/tsconfig": "^2.0.0-next.0",
|
|
35
|
+
"@japa/assert": "^4.0.1",
|
|
36
|
+
"@japa/expect": "^3.0.4",
|
|
37
|
+
"@japa/expect-type": "^2.0.3",
|
|
38
|
+
"@japa/file-system": "^2.3.2",
|
|
39
|
+
"@japa/runner": "^4.2.0",
|
|
40
|
+
"@poppinss/ts-exec": "^1.4.0",
|
|
41
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
42
|
+
"@types/node": "^24.0.10",
|
|
43
|
+
"ansis": "^4.1.0",
|
|
44
|
+
"axios": "^1.10.0",
|
|
45
|
+
"c8": "^10.1.3",
|
|
46
|
+
"eslint": "^9.30.1",
|
|
47
|
+
"got": "^14.4.7",
|
|
48
|
+
"prettier": "^3.6.2",
|
|
49
|
+
"release-it": "^19.0.3",
|
|
50
|
+
"strip-ansi": "^7.1.0",
|
|
51
|
+
"tinyhighlight": "^0.3.2",
|
|
52
|
+
"tsup": "^8.5.0",
|
|
53
|
+
"typescript": "^5.8.3",
|
|
54
|
+
"undici": "^7.11.0"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@poppinss/exception": "^1.2.2",
|
|
58
|
+
"error-stack-parser-es": "^1.0.5"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://github.com/poppinss/youch-core#readme",
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/poppinss/youch-core.git"
|
|
64
|
+
},
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/poppinss/youch-core/issues"
|
|
67
|
+
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"pretty-print",
|
|
70
|
+
"pretty-error"
|
|
71
|
+
],
|
|
72
|
+
"author": "Harminder Virk <virk@adonisjs.com>",
|
|
73
|
+
"license": "MIT",
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public",
|
|
76
|
+
"provenance": true
|
|
77
|
+
},
|
|
78
|
+
"tsup": {
|
|
79
|
+
"entry": [
|
|
80
|
+
"index.ts",
|
|
81
|
+
"src/types.ts"
|
|
82
|
+
],
|
|
83
|
+
"outDir": "./build",
|
|
84
|
+
"clean": true,
|
|
85
|
+
"format": "esm",
|
|
86
|
+
"dts": false,
|
|
87
|
+
"sourcemap": false,
|
|
88
|
+
"target": "esnext"
|
|
89
|
+
},
|
|
90
|
+
"release-it": {
|
|
91
|
+
"git": {
|
|
92
|
+
"requireCleanWorkingDir": true,
|
|
93
|
+
"requireUpstream": true,
|
|
94
|
+
"commitMessage": "chore(release): ${version}",
|
|
95
|
+
"tagAnnotation": "v${version}",
|
|
96
|
+
"push": true,
|
|
97
|
+
"tagName": "v${version}"
|
|
98
|
+
},
|
|
99
|
+
"github": {
|
|
100
|
+
"release": true
|
|
101
|
+
},
|
|
102
|
+
"npm": {
|
|
103
|
+
"publish": true,
|
|
104
|
+
"skipChecks": true
|
|
105
|
+
},
|
|
106
|
+
"plugins": {
|
|
107
|
+
"@release-it/conventional-changelog": {
|
|
108
|
+
"preset": {
|
|
109
|
+
"name": "angular"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"c8": {
|
|
115
|
+
"reporter": [
|
|
116
|
+
"text",
|
|
117
|
+
"html"
|
|
118
|
+
],
|
|
119
|
+
"exclude": [
|
|
120
|
+
"tests/**"
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
"prettier": "@adonisjs/prettier-config"
|
|
124
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import { useNitroApp, useNitroHooks } from "nitro/app";
|
|
3
|
+
import { startScheduleRunner } from "#nitro/runtime/task";
|
|
4
|
+
import { trapUnhandledErrors } from "#nitro/runtime/error/hooks";
|
|
5
|
+
import { resolveWebsocketHooks } from "#nitro/runtime/app";
|
|
6
|
+
const nitroApp = useNitroApp();
|
|
7
|
+
const nitroHooks = useNitroHooks();
|
|
8
|
+
trapUnhandledErrors();
|
|
9
|
+
// Scheduled tasks
|
|
10
|
+
if (import.meta._tasks) {
|
|
11
|
+
startScheduleRunner({});
|
|
12
|
+
}
|
|
13
|
+
const ws = import.meta._websocket ? await import("crossws/adapters/node").then((m) => (m.default || m)({ resolve: resolveWebsocketHooks })) : undefined;
|
|
14
|
+
export default {
|
|
15
|
+
fetch: nitroApp.fetch,
|
|
16
|
+
upgrade: ws ? (context) => {
|
|
17
|
+
ws.handleUpgrade(context.node.req, context.node.socket, context.node.head);
|
|
18
|
+
} : undefined,
|
|
19
|
+
ipc: { onClose: () => nitroHooks.callHook("close") }
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import { HTTPError } from "h3";
|
|
4
|
+
import { useNitroApp, useNitroHooks } from "nitro/app";
|
|
5
|
+
const nitroApp = useNitroApp();
|
|
6
|
+
const nitroHooks = useNitroHooks();
|
|
7
|
+
export default {
|
|
8
|
+
fetch: nitroApp.fetch,
|
|
9
|
+
close: () => nitroHooks.callHook("close")
|
|
10
|
+
};
|
|
11
|
+
nitroHooks.hook("error", (error, context) => {
|
|
12
|
+
if (!error.unhandled && error.status >= 500 && context.event?.req?.headers instanceof Headers && context.event.req.headers.get("x-nitro-prerender")) {
|
|
13
|
+
consola.error(`[prerender error]`, `[${context.event.req.method}]`, `[${context.event.req.url}]`, error);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import { useNitroApp } from "nitro/app";
|
|
3
|
+
import { isPublicAssetURL } from "#nitro/virtual/public-assets";
|
|
4
|
+
const nitroApp = useNitroApp();
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
addEventListener("fetch", (event) => {
|
|
7
|
+
const url = new URL(event.request.url);
|
|
8
|
+
if (isPublicAssetURL(url.pathname) || url.pathname.includes("/_server/")) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
// srvx compatibility
|
|
12
|
+
const req = event.request;
|
|
13
|
+
req.runtime ??= { name: "service-worker" };
|
|
14
|
+
req.runtime.serviceWorker ??= { event };
|
|
15
|
+
req.waitUntil = event.waitUntil.bind(event);
|
|
16
|
+
event.respondWith(nitroApp.fetch(req));
|
|
17
|
+
});
|
|
18
|
+
self.addEventListener("install", () => {
|
|
19
|
+
self.skipWaiting();
|
|
20
|
+
});
|
|
21
|
+
self.addEventListener("activate", (event) => {
|
|
22
|
+
event.waitUntil(self.clients.claim());
|
|
23
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import { useNitroApp } from "nitro/app";
|
|
3
|
+
import { Server } from "node:http";
|
|
4
|
+
import { toNodeHandler } from "srvx/node";
|
|
5
|
+
const nitroApp = useNitroApp();
|
|
6
|
+
const server = new Server(toNodeHandler(nitroApp.fetch));
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
server.listen(3e3, (err) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
console.error(err);
|
|
11
|
+
} else {
|
|
12
|
+
console.log(`Listening on http://localhost:3000 (AWS Amplify Hosting)`);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { stringifyQuery } from "ufo";
|
|
2
|
+
// Incoming (AWS => Web)
|
|
3
|
+
export function awsRequest(event, context) {
|
|
4
|
+
const method = awsEventMethod(event);
|
|
5
|
+
const url = awsEventURL(event);
|
|
6
|
+
const headers = awsEventHeaders(event);
|
|
7
|
+
const body = awsEventBody(event);
|
|
8
|
+
const req = new Request(url, {
|
|
9
|
+
method,
|
|
10
|
+
headers,
|
|
11
|
+
body
|
|
12
|
+
});
|
|
13
|
+
// srvx compatibility
|
|
14
|
+
req.runtime ??= { name: "aws-lambda" };
|
|
15
|
+
// @ts-expect-error (add to srvx types)
|
|
16
|
+
req.runtime.aws ??= {
|
|
17
|
+
event,
|
|
18
|
+
context
|
|
19
|
+
};
|
|
20
|
+
return new Request(url, {
|
|
21
|
+
method,
|
|
22
|
+
headers,
|
|
23
|
+
body
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function awsEventMethod(event) {
|
|
27
|
+
return event.httpMethod || event.requestContext?.http?.method || "GET";
|
|
28
|
+
}
|
|
29
|
+
function awsEventURL(event) {
|
|
30
|
+
const hostname = event.headers.host || event.headers.Host || event.requestContext?.domainName || ".";
|
|
31
|
+
const path = event.path || event.rawPath;
|
|
32
|
+
const query = awsEventQuery(event);
|
|
33
|
+
const protocol = (event.headers["X-Forwarded-Proto"] || event.headers["x-forwarded-proto"]) === "http" ? "http" : "https";
|
|
34
|
+
return new URL(`${path}${query ? `?${query}` : ""}`, `${protocol}://${hostname}`);
|
|
35
|
+
}
|
|
36
|
+
function awsEventQuery(event) {
|
|
37
|
+
if (typeof event.rawQueryString === "string") {
|
|
38
|
+
return event.rawQueryString;
|
|
39
|
+
}
|
|
40
|
+
const queryObj = {
|
|
41
|
+
...event.queryStringParameters,
|
|
42
|
+
...event.multiValueQueryStringParameters
|
|
43
|
+
};
|
|
44
|
+
return stringifyQuery(queryObj);
|
|
45
|
+
}
|
|
46
|
+
function awsEventHeaders(event) {
|
|
47
|
+
const headers = new Headers();
|
|
48
|
+
for (const [key, value] of Object.entries(event.headers)) {
|
|
49
|
+
if (value) {
|
|
50
|
+
headers.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if ("cookies" in event && event.cookies) {
|
|
54
|
+
for (const cookie of event.cookies) {
|
|
55
|
+
headers.append("cookie", cookie);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return headers;
|
|
59
|
+
}
|
|
60
|
+
function awsEventBody(event) {
|
|
61
|
+
if (!event.body) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
if (event.isBase64Encoded) {
|
|
65
|
+
return Buffer.from(event.body || "", "base64");
|
|
66
|
+
}
|
|
67
|
+
return event.body;
|
|
68
|
+
}
|
|
69
|
+
// Outgoing (Web => AWS)
|
|
70
|
+
export function awsResponseHeaders(response) {
|
|
71
|
+
const headers = Object.create(null);
|
|
72
|
+
for (const [key, value] of response.headers) {
|
|
73
|
+
if (value) {
|
|
74
|
+
headers[key] = Array.isArray(value) ? value.join(",") : String(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const cookies = response.headers.getSetCookie();
|
|
78
|
+
return cookies.length > 0 ? {
|
|
79
|
+
headers,
|
|
80
|
+
cookies,
|
|
81
|
+
multiValueHeaders: { "set-cookie": cookies }
|
|
82
|
+
} : { headers };
|
|
83
|
+
}
|
|
84
|
+
// AWS Lambda proxy integrations requires base64 encoded buffers
|
|
85
|
+
// binaryMediaTypes should be */*
|
|
86
|
+
// see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html
|
|
87
|
+
export async function awsResponseBody(response) {
|
|
88
|
+
if (!response.body) {
|
|
89
|
+
return { body: "" };
|
|
90
|
+
}
|
|
91
|
+
const buffer = await toBuffer(response.body);
|
|
92
|
+
const contentType = response.headers.get("content-type") || "";
|
|
93
|
+
return isTextType(contentType) ? { body: buffer.toString("utf8") } : {
|
|
94
|
+
body: buffer.toString("base64"),
|
|
95
|
+
isBase64Encoded: true
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function isTextType(contentType = "") {
|
|
99
|
+
return /^text\/|\/(javascript|json|xml)|utf-?8/i.test(contentType);
|
|
100
|
+
}
|
|
101
|
+
function toBuffer(data) {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
const chunks = [];
|
|
104
|
+
data.pipeTo(new WritableStream({
|
|
105
|
+
write(chunk) {
|
|
106
|
+
chunks.push(chunk);
|
|
107
|
+
},
|
|
108
|
+
close() {
|
|
109
|
+
resolve(Buffer.concat(chunks));
|
|
110
|
+
},
|
|
111
|
+
abort(reason) {
|
|
112
|
+
reject(reason);
|
|
113
|
+
}
|
|
114
|
+
})).catch(reject);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import { useNitroApp } from "nitro/app";
|
|
3
|
+
import { awsRequest, awsResponseHeaders } from "./_utils.mjs";
|
|
4
|
+
const nitroApp = useNitroApp();
|
|
5
|
+
export const handler = awslambda.streamifyResponse(async (event, responseStream, context) => {
|
|
6
|
+
const request = awsRequest(event, context);
|
|
7
|
+
const response = await nitroApp.fetch(request);
|
|
8
|
+
const httpResponseMetadata = {
|
|
9
|
+
statusCode: response.status,
|
|
10
|
+
...awsResponseHeaders(response)
|
|
11
|
+
};
|
|
12
|
+
if (!httpResponseMetadata.headers["transfer-encoding"]) {
|
|
13
|
+
httpResponseMetadata.headers["transfer-encoding"] = "chunked";
|
|
14
|
+
}
|
|
15
|
+
const body = response.body ?? new ReadableStream({ start(controller) {
|
|
16
|
+
controller.enqueue("");
|
|
17
|
+
controller.close();
|
|
18
|
+
} });
|
|
19
|
+
const writer = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
|
|
20
|
+
const reader = body.getReader();
|
|
21
|
+
await streamToNodeStream(reader, responseStream);
|
|
22
|
+
writer.end();
|
|
23
|
+
});
|
|
24
|
+
async function streamToNodeStream(reader, writer) {
|
|
25
|
+
let readResult = await reader.read();
|
|
26
|
+
while (!readResult.done) {
|
|
27
|
+
writer.write(readResult.value);
|
|
28
|
+
readResult = await reader.read();
|
|
29
|
+
}
|
|
30
|
+
writer.end();
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import { useNitroApp } from "nitro/app";
|
|
3
|
+
import { awsRequest, awsResponseHeaders, awsResponseBody } from "./_utils.mjs";
|
|
4
|
+
const nitroApp = useNitroApp();
|
|
5
|
+
export async function handler(event, context) {
|
|
6
|
+
const request = awsRequest(event, context);
|
|
7
|
+
const response = await nitroApp.fetch(request);
|
|
8
|
+
return {
|
|
9
|
+
statusCode: response.status,
|
|
10
|
+
...awsResponseHeaders(response),
|
|
11
|
+
...await awsResponseBody(response)
|
|
12
|
+
};
|
|
13
|
+
}
|