nitro 3.0.1-alpha.2 → 3.0.260415-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +2 -2
  3. package/dist/THIRD-PARTY-LICENSES.md +1646 -0
  4. package/dist/_build/common.mjs +7261 -3812
  5. package/dist/_build/rolldown.mjs +32 -42
  6. package/dist/_build/rollup.mjs +28 -48
  7. package/dist/_build/vite.build.mjs +10 -10
  8. package/dist/_chunks/nitro.mjs +102 -327
  9. package/dist/_chunks/nitro2.mjs +8 -9
  10. package/dist/_chunks/nitro3.mjs +136 -0
  11. package/dist/_chunks/nitro4.mjs +127 -0
  12. package/dist/_chunks/utils.mjs +40 -29
  13. package/dist/_common.mjs +13 -25
  14. package/dist/_dev.d.mts +0 -3
  15. package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -330
  16. package/dist/_libs/_.mjs +2 -0
  17. package/dist/_libs/_2.mjs +2 -0
  18. package/dist/_libs/_3.mjs +2 -0
  19. package/dist/_libs/_4.mjs +2 -0
  20. package/dist/_libs/_5.mjs +2 -0
  21. package/dist/_libs/_6.mjs +2 -0
  22. package/dist/_libs/_7.mjs +2 -0
  23. package/dist/_libs/c12+rc9.mjs +814 -0
  24. package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +49 -40
  25. package/dist/_libs/citty.mjs +142 -41
  26. package/dist/_libs/commondir+is-reference.mjs +60 -56
  27. package/dist/_libs/compatx.d.mts +0 -2
  28. package/dist/_libs/compatx.mjs +1 -4
  29. package/dist/_libs/esbuild.d.mts +0 -1
  30. package/dist/_libs/escape-string-regexp.mjs +1 -4
  31. package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +0 -5
  32. package/dist/_libs/estree-walker.mjs +4 -92
  33. package/dist/_libs/exsolve.d.mts +1 -0
  34. package/dist/_libs/hasown+resolve+deepmerge.mjs +160 -246
  35. package/dist/_libs/httpxy.d.mts +20 -13
  36. package/dist/_libs/httpxy.mjs +519 -95
  37. package/dist/_libs/js-tokens.d.mts +1 -0
  38. package/dist/_libs/klona.mjs +1 -4
  39. package/dist/_libs/magic-string.d.mts +0 -2
  40. package/dist/_libs/mlly.d.mts +0 -2
  41. package/dist/_libs/nypm+tinyexec.mjs +822 -0
  42. package/dist/_libs/perfect-debounce.mjs +68 -0
  43. package/dist/_libs/pkg-types.d.mts +0 -3
  44. package/dist/_libs/plugin-alias.mjs +1 -5
  45. package/dist/_libs/plugin-inject.mjs +1 -7
  46. package/dist/_libs/plugin-json.mjs +1 -5
  47. package/dist/_libs/pluginutils.mjs +3 -35
  48. package/dist/_libs/readdirp+chokidar.mjs +187 -365
  49. package/dist/_libs/remapping.mjs +1 -5
  50. package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -53
  51. package/dist/_libs/rou3.d.mts +1 -4
  52. package/dist/_libs/rou3.mjs +223 -78
  53. package/dist/_libs/std-env.d.mts +8 -2
  54. package/dist/_libs/strip-literal.d.mts +1 -0
  55. package/dist/_libs/tsconfck.mjs +21 -334
  56. package/dist/_libs/ultrahtml.mjs +3 -16
  57. package/dist/_libs/unimport+unplugin.mjs +244 -388
  58. package/dist/_libs/unplugin+unimport.d.mts +5 -15
  59. package/dist/_libs/unwasm.d.mts +0 -3
  60. package/dist/_presets.mjs +576 -488
  61. package/dist/builder.d.mts +5 -25
  62. package/dist/builder.mjs +3 -8
  63. package/dist/cli/_chunks/build.mjs +22 -25
  64. package/dist/cli/_chunks/common.mjs +1 -4
  65. package/dist/cli/_chunks/deploy.mjs +37 -0
  66. package/dist/cli/_chunks/dev.mjs +6 -11
  67. package/dist/cli/_chunks/docs.mjs +28 -0
  68. package/dist/cli/_chunks/list.mjs +4 -8
  69. package/dist/cli/_chunks/prepare.mjs +2 -6
  70. package/dist/cli/_chunks/preview.mjs +48 -0
  71. package/dist/cli/_chunks/run.mjs +7 -11
  72. package/dist/cli/_chunks/task.mjs +1 -5
  73. package/dist/cli/index.mjs +5 -6
  74. package/dist/docs/0.docs/0.index/index.md +56 -0
  75. package/dist/docs/0.docs/1.quick-start.md +110 -0
  76. package/dist/docs/0.docs/10.lifecycle.md +204 -0
  77. package/dist/docs/0.docs/11.openapi.md +291 -0
  78. package/dist/docs/0.docs/12.plugins.md +164 -0
  79. package/dist/docs/0.docs/13.tasks.md +277 -0
  80. package/dist/docs/0.docs/14.websocket.md +386 -0
  81. package/dist/docs/0.docs/15.migration.md +213 -0
  82. package/dist/docs/0.docs/16.nightly.md +31 -0
  83. package/dist/docs/0.docs/2.renderer.md +322 -0
  84. package/dist/docs/0.docs/3.routing.md +711 -0
  85. package/dist/docs/0.docs/4.server-entry.md +239 -0
  86. package/dist/docs/0.docs/5.cache.md +408 -0
  87. package/dist/docs/0.docs/6.storage.md +261 -0
  88. package/dist/docs/0.docs/7.assets.md +166 -0
  89. package/dist/docs/0.docs/8.configuration.md +256 -0
  90. package/dist/docs/0.docs/9.database.md +185 -0
  91. package/dist/docs/1.deploy/0.index/index.md +64 -0
  92. package/dist/docs/1.deploy/1.runtimes/0.node.md +63 -0
  93. package/dist/docs/1.deploy/1.runtimes/1.bun.md +15 -0
  94. package/dist/docs/1.deploy/1.runtimes/2.deno.md +19 -0
  95. package/dist/docs/1.deploy/2.providers/0.alwaysdata.md +50 -0
  96. package/dist/docs/1.deploy/2.providers/1.aws.md +47 -0
  97. package/dist/docs/1.deploy/2.providers/10.flightcontrol.md +67 -0
  98. package/dist/docs/1.deploy/2.providers/11.genezio.md +67 -0
  99. package/dist/docs/1.deploy/2.providers/12.github-pages.md +68 -0
  100. package/dist/docs/1.deploy/2.providers/13.gitlab-pages.md +37 -0
  101. package/dist/docs/1.deploy/2.providers/14.heroku.md +84 -0
  102. package/dist/docs/1.deploy/2.providers/15.iis.md +38 -0
  103. package/dist/docs/1.deploy/2.providers/16.koyeb.md +109 -0
  104. package/dist/docs/1.deploy/2.providers/17.netlify.md +47 -0
  105. package/dist/docs/1.deploy/2.providers/18.platform-sh.md +37 -0
  106. package/dist/docs/1.deploy/2.providers/19.render.md +37 -0
  107. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +81 -0
  108. package/dist/docs/1.deploy/2.providers/20.stormkit.md +24 -0
  109. package/dist/docs/1.deploy/2.providers/21.vercel.md +270 -0
  110. package/dist/docs/1.deploy/2.providers/22.zeabur.md +19 -0
  111. package/dist/docs/1.deploy/2.providers/23.zephyr.md +99 -0
  112. package/dist/docs/1.deploy/2.providers/24.zerops.md +102 -0
  113. package/dist/docs/1.deploy/2.providers/3.azure.md +72 -0
  114. package/dist/docs/1.deploy/2.providers/4.cleavr.md +33 -0
  115. package/dist/docs/1.deploy/2.providers/5.cloudflare.md +369 -0
  116. package/dist/docs/1.deploy/2.providers/6.deno-deploy.md +66 -0
  117. package/dist/docs/1.deploy/2.providers/7.digitalocean.md +46 -0
  118. package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
  119. package/dist/docs/1.deploy/2.providers/9.firebase.md +32 -0
  120. package/dist/docs/2.config/0.index/index.md +1221 -0
  121. package/dist/docs/3.examples/0.index/index.md +3 -0
  122. package/dist/docs/3.examples/1.api-routes.md +145 -0
  123. package/dist/docs/3.examples/10.hono.md +74 -0
  124. package/dist/docs/3.examples/11.import-alias.md +97 -0
  125. package/dist/docs/3.examples/12.middleware.md +91 -0
  126. package/dist/docs/3.examples/13.mono-jsx.md +68 -0
  127. package/dist/docs/3.examples/14.nano-jsx.md +70 -0
  128. package/dist/docs/3.examples/15.plugins.md +91 -0
  129. package/dist/docs/3.examples/16.renderer.md +113 -0
  130. package/dist/docs/3.examples/17.runtime-config.md +97 -0
  131. package/dist/docs/3.examples/18.server-fetch.md +87 -0
  132. package/dist/docs/3.examples/19.shiki.md +198 -0
  133. package/dist/docs/3.examples/2.auto-imports.md +92 -0
  134. package/dist/docs/3.examples/20.virtual-routes.md +74 -0
  135. package/dist/docs/3.examples/21.vite-nitro-plugin.md +79 -0
  136. package/dist/docs/3.examples/22.vite-rsc.md +1041 -0
  137. package/dist/docs/3.examples/23.vite-ssr-html.md +217 -0
  138. package/dist/docs/3.examples/24.vite-ssr-preact.md +247 -0
  139. package/dist/docs/3.examples/25.vite-ssr-react.md +226 -0
  140. package/dist/docs/3.examples/26.vite-ssr-solid.md +256 -0
  141. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +442 -0
  142. package/dist/docs/3.examples/28.vite-ssr-tss-react.md +444 -0
  143. package/dist/docs/3.examples/29.vite-ssr-vue-router.md +617 -0
  144. package/dist/docs/3.examples/3.cached-handler.md +81 -0
  145. package/dist/docs/3.examples/30.vite-trpc.md +335 -0
  146. package/dist/docs/3.examples/31.websocket.md +282 -0
  147. package/dist/docs/3.examples/4.custom-error-handler.md +98 -0
  148. package/dist/docs/3.examples/5.database.md +157 -0
  149. package/dist/docs/3.examples/6.elysia.md +70 -0
  150. package/dist/docs/3.examples/7.express.md +78 -0
  151. package/dist/docs/3.examples/8.fastify.md +79 -0
  152. package/dist/docs/3.examples/9.hello-world.md +68 -0
  153. package/dist/docs/README.md +86 -0
  154. package/dist/docs/index.md +121 -0
  155. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
  156. package/dist/node_modules/@poppinss/dumper/package.json +1 -1
  157. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
  158. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  159. package/dist/node_modules/@speed-highlight/core/package.json +1 -1
  160. package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
  161. package/dist/node_modules/cookie-es/package.json +26 -23
  162. package/dist/node_modules/croner/dist/croner.js +1 -1
  163. package/dist/node_modules/croner/package.json +11 -1
  164. package/dist/node_modules/defu/dist/defu.mjs +2 -2
  165. package/dist/node_modules/defu/package.json +33 -28
  166. package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
  167. package/dist/node_modules/rendu/dist/index.mjs +5 -112
  168. package/dist/node_modules/rendu/package.json +25 -24
  169. package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
  170. package/dist/node_modules/youch/build/index.js +204 -351
  171. package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
  172. package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
  173. package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
  174. package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
  175. package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
  176. package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
  177. package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
  178. package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
  179. package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
  180. package/dist/node_modules/youch/package.json +35 -32
  181. package/dist/presets/_nitro/runtime/nitro-dev.mjs +12 -57
  182. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
  183. package/dist/presets/_nitro/runtime/service-worker.mjs +1 -2
  184. package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
  185. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
  186. package/dist/presets/azure/runtime/_utils.mjs +5 -5
  187. package/dist/presets/azure/runtime/azure-swa.mjs +5 -5
  188. package/dist/presets/bun/runtime/bun.mjs +9 -6
  189. package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
  190. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
  191. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
  192. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
  193. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
  194. package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
  195. package/dist/presets/deno/runtime/deno-server.mjs +9 -6
  196. package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
  197. package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -3
  198. package/dist/presets/netlify/runtime/netlify.mjs +1 -1
  199. package/dist/presets/node/runtime/node-cluster.mjs +5 -4
  200. package/dist/presets/node/runtime/node-middleware.mjs +1 -1
  201. package/dist/presets/node/runtime/node-server.mjs +8 -5
  202. package/dist/presets/stormkit/runtime/stormkit.mjs +1 -2
  203. package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
  204. package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
  205. package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
  206. package/dist/presets/vercel/runtime/vercel.web.mjs +3 -5
  207. package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
  208. package/dist/presets/zephyr/runtime/server.mjs +3 -0
  209. package/dist/runtime/internal/app.mjs +12 -11
  210. package/dist/runtime/internal/cache.d.mts +0 -4
  211. package/dist/runtime/internal/cache.mjs +32 -256
  212. package/dist/runtime/internal/context.d.mts +3 -1
  213. package/dist/runtime/internal/context.mjs +1 -9
  214. package/dist/runtime/internal/error/dev.d.mts +5 -4
  215. package/dist/runtime/internal/error/dev.mjs +47 -49
  216. package/dist/runtime/internal/error/hooks.d.mts +1 -1
  217. package/dist/runtime/internal/error/prod.d.mts +2 -5
  218. package/dist/runtime/internal/error/prod.mjs +19 -33
  219. package/dist/runtime/internal/error/utils.d.mts +4 -4
  220. package/dist/runtime/internal/meta.d.mts +1 -1
  221. package/dist/runtime/internal/plugin.d.mts +2 -2
  222. package/dist/runtime/internal/route-rules.d.mts +11 -4
  223. package/dist/runtime/internal/route-rules.mjs +15 -5
  224. package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
  225. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -10
  226. package/dist/runtime/internal/routes/openapi.mjs +2 -2
  227. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  228. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
  229. package/dist/runtime/internal/routes/scalar.mjs +3 -3
  230. package/dist/runtime/internal/routes/swagger.mjs +7 -4
  231. package/dist/runtime/internal/runtime-config.d.mts +1 -1
  232. package/dist/runtime/internal/runtime-config.mjs +2 -2
  233. package/dist/runtime/internal/static.mjs +5 -4
  234. package/dist/runtime/internal/task.d.mts +3 -1
  235. package/dist/runtime/internal/task.mjs +7 -7
  236. package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
  237. package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
  238. package/dist/runtime/meta.d.mts +1 -0
  239. package/dist/runtime/meta.mjs +2 -0
  240. package/dist/runtime/nitro.d.mts +2 -0
  241. package/dist/runtime/nitro.mjs +4 -2
  242. package/dist/runtime/virtual/error-handler.mjs +1 -1
  243. package/dist/runtime/virtual/renderer-template.mjs +1 -1
  244. package/dist/runtime/virtual/server-assets.d.mts +2 -1
  245. package/dist/runtime/virtual/tracing.d.mts +5 -0
  246. package/dist/runtime/virtual/tracing.mjs +1 -0
  247. package/dist/runtime/vite.d.mts +1 -1
  248. package/dist/types/index.d.mts +215 -195
  249. package/dist/types/index.mjs +1 -11
  250. package/dist/vite.d.mts +3 -8
  251. package/dist/vite.mjs +285 -253
  252. package/lib/tsconfig.json +3 -5
  253. package/package.json +97 -80
  254. package/dist/_libs/confbox.mjs +0 -2509
  255. package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
  256. package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
  257. package/dist/node_modules/hookable/dist/index.mjs +0 -266
  258. package/dist/node_modules/hookable/package.json +0 -52
  259. package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
  260. package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
  261. package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
  262. package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
  263. package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
  264. package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
  265. package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
  266. package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
  267. package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
  268. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
  269. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
  270. package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
  271. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
  272. package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
  273. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
  274. package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
  275. package/dist/presets/azure/runtime/_utils.d.mts +0 -2
  276. package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
  277. package/dist/presets/bun/runtime/bun.d.mts +0 -3
  278. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
  279. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
  280. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
  281. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
  282. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
  283. package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
  284. package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
  285. package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
  286. package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
  287. package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
  288. package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
  289. package/dist/presets/node/runtime/node-server.d.mts +0 -3
  290. package/dist/presets/standard/runtime/server.d.mts +0 -3
  291. package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
  292. package/dist/presets/vercel/runtime/isr.d.mts +0 -2
  293. package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
  294. package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
  295. package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
  296. package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
  297. package/dist/runtime/internal/vite/node-runner.mjs +0 -359
@@ -0,0 +1,72 @@
1
+ import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js";
2
+ import { i as wordWrap, n as htmlEscape, t as colors } from "../../../helpers-B9BQYaS6.js";
3
+ const ERROR_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="24" height="24" fill="none"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 7v6m0 4.01.01-.011M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z"/></svg>`;
4
+ const HINT_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="24" height="24" fill="none"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m21 2-1 1M3 2l1 1m17 13-1-1M3 16l1-1m5 3h6m-5 3h4M12 3C8 3 5.952 4.95 6 8c.023 1.487.5 2.5 1.5 3.5S9 13 9 15h6c0-2 .5-2.5 1.5-3.5h0c1-1 1.477-2.013 1.5-3.5.048-3.05-2-5-6-5Z"/></svg>`;
5
+ const COPY_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z" /><path d="M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1" /></svg>`;
6
+ function buildErrorWithStacktrace(error) {
7
+ const cwd = process.cwd();
8
+ const lines = [];
9
+ lines.push(`${error.name}: ${error.message}`);
10
+ if (error.hint) lines.push(`Hint: ${error.hint.replace(/(<([^>]+)>)/gi, "")}`);
11
+ if (error.frames.length > 0) {
12
+ lines.push("");
13
+ lines.push("Stack trace:");
14
+ for (const frame of error.frames) {
15
+ const fileName = frame.fileName?.replace(`${cwd}/`, "") || "<anonymous>";
16
+ const func = frame.functionName ? `at ${frame.functionName} ` : "at ";
17
+ lines.push(` ${func}(${fileName}:${frame.lineNumber}:${frame.columnNumber})`);
18
+ }
19
+ }
20
+ return lines.join("\n");
21
+ }
22
+ function htmlAttributeEscape(value) {
23
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
24
+ }
25
+ var ErrorInfo = class extends BaseComponent {
26
+ cssFile = new URL("./error_info/style.css", publicDirURL);
27
+ scriptFile = new URL("./error_info/script.js", publicDirURL);
28
+ async toHTML(props) {
29
+ const stacktraceText = buildErrorWithStacktrace(props.error);
30
+ return `<section>
31
+ <h4 id="error-name">${htmlEscape(props.error.name)}</h4>
32
+ <h1 id="error-title">${htmlEscape(props.title)}</h1>
33
+ </section>
34
+ <section>
35
+ <div class="card">
36
+ <div class="card-body">
37
+ <h2 id="error-message">
38
+ <span>${ERROR_ICON_SVG}</span>
39
+ <span>${htmlEscape(props.error.message)}</span>
40
+ <button
41
+ id="copy-error-btn"
42
+ data-error-text="${htmlAttributeEscape(stacktraceText)}"
43
+ onclick="copyErrorMessage(this)"
44
+ title="Copy error with stack trace"
45
+ aria-label="Copy error with stack trace to clipboard"
46
+ >
47
+ ${COPY_ICON_SVG}
48
+ </button>
49
+ </h2>
50
+ ${props.error.hint ? `<div id="error-hint">
51
+ <span>${HINT_ICON_SVG}</span>
52
+ <span>${props.error.hint}</span>
53
+ </div>` : ""}
54
+ </div>
55
+ </div>
56
+ </section>`;
57
+ }
58
+ async toANSI(props) {
59
+ return `${colors.red(`ℹ ${wordWrap(`${props.error.name}: ${props.error.message}`, {
60
+ width: process.stdout.columns,
61
+ indent: " ",
62
+ newLine: "\n",
63
+ escape: (value) => value
64
+ })}`)}${props.error.hint ? `\n\n${colors.blue("◉")} ${colors.dim().italic(wordWrap(props.error.hint.replace(/(<([^>]+)>)/gi, ""), {
65
+ width: process.stdout.columns,
66
+ indent: " ",
67
+ newLine: "\n",
68
+ escape: (value) => value
69
+ }))}` : ""}`;
70
+ }
71
+ };
72
+ export { ErrorInfo };
@@ -0,0 +1,65 @@
1
+ import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js";
2
+ import { n as htmlEscape } from "../../../helpers-B9BQYaS6.js";
3
+ import { dump, themes } from "@poppinss/dumper/html";
4
+ var ErrorMetadata = class extends BaseComponent {
5
+ cssFile = new URL("./error_metadata/style.css", publicDirURL);
6
+ #primitives = [
7
+ "string",
8
+ "boolean",
9
+ "number",
10
+ "undefined"
11
+ ];
12
+ #formatRowValue(value, dumpValue, cspNonce) {
13
+ if (dumpValue === true) return dump(value, {
14
+ styles: themes.cssVariables,
15
+ cspNonce
16
+ });
17
+ if (this.#primitives.includes(typeof value) || value === null) return typeof value === "string" ? htmlEscape(value) : value;
18
+ return dump(value, {
19
+ styles: themes.cssVariables,
20
+ cspNonce
21
+ });
22
+ }
23
+ #renderRows(rows, cspNonce) {
24
+ return `<table class="card-table">
25
+ <tbody>
26
+ ${rows.map((row) => {
27
+ return `<tr>
28
+ <td class="table-key">${row.key}</td>
29
+ <td class="table-value">
30
+ ${this.#formatRowValue(row.value, row.dump, cspNonce)}
31
+ </td>
32
+ </tr>`;
33
+ }).join("\n")}
34
+ </tbody>
35
+ </table>`;
36
+ }
37
+ #renderSection(section, rows, cspNonce) {
38
+ return `<div>
39
+ <h4 class="card-subtitle">${section}</h4>
40
+ ${Array.isArray(rows) ? this.#renderRows(rows, cspNonce) : `<span>${this.#formatRowValue(rows.value, rows.dump, cspNonce)}</span>`}
41
+ </div>`;
42
+ }
43
+ #renderGroup(group, sections, cspNonce) {
44
+ return `<section class="metadata-group">
45
+ <div class="card">
46
+ <div class="card-heading">
47
+ <h3 class="card-title">${group}</h3>
48
+ </div>
49
+ <div class="card-body">
50
+ ${Object.keys(sections).map((section) => this.#renderSection(section, sections[section], cspNonce)).join("\n")}
51
+ </div>
52
+ </div>
53
+ </section>`;
54
+ }
55
+ async toHTML(props) {
56
+ const groups = props.metadata.toJSON();
57
+ const groupsNames = Object.keys(groups);
58
+ if (!groupsNames.length) return "";
59
+ return groupsNames.map((group) => this.#renderGroup(group, groups[group], props.cspNonce)).join("\n");
60
+ }
61
+ async toANSI() {
62
+ return "";
63
+ }
64
+ };
65
+ export { ErrorMetadata };
@@ -0,0 +1,152 @@
1
+ import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js";
2
+ import { n as htmlEscape, t as colors } from "../../../helpers-B9BQYaS6.js";
3
+ import { dump, themes } from "@poppinss/dumper/html";
4
+ import { dump as dump$1 } from "@poppinss/dumper/console";
5
+ const CHEVIRON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
6
+ <path d="M6 9l6 6l6 -6"></path>
7
+ </svg>`;
8
+ const EDITORS = {
9
+ textmate: "txmt://open?url=file://%f&line=%l",
10
+ macvim: "mvim://open?url=file://%f&line=%l",
11
+ emacs: "emacs://open?url=file://%f&line=%l",
12
+ sublime: "subl://open?url=file://%f&line=%l",
13
+ phpstorm: "phpstorm://open?file=%f&line=%l",
14
+ atom: "atom://core/open/file?filename=%f&line=%l",
15
+ vscode: "vscode://file/%f:%l"
16
+ };
17
+ var ErrorStack = class extends BaseComponent {
18
+ cssFile = new URL("./error_stack/style.css", publicDirURL);
19
+ scriptFile = new URL("./error_stack/script.js", publicDirURL);
20
+ #getRelativeFileName(filePath) {
21
+ return filePath.replace(`${process.cwd()}/`, "");
22
+ }
23
+ #getFirstExpandedFrameIndex(frames) {
24
+ let expandAtIndex = frames.findIndex((frame) => frame.type === "app");
25
+ if (expandAtIndex === -1) expandAtIndex = frames.findIndex((frame) => frame.type === "module");
26
+ return expandAtIndex;
27
+ }
28
+ #getEditorLink(ide, frame) {
29
+ const editorURL = EDITORS[ide] || ide;
30
+ if (!editorURL || frame.type === "native") return { text: this.#getRelativeFileName(frame.fileName) };
31
+ return {
32
+ href: editorURL.replace("%f", frame.fileName).replace("%l", String(frame.lineNumber)),
33
+ text: this.#getRelativeFileName(frame.fileName)
34
+ };
35
+ }
36
+ #renderFrameLocation(frame, ide) {
37
+ const { text, href } = this.#getEditorLink(ide, frame);
38
+ const fileName = `<a${href ? ` href="${href}"` : ""} class="stack-frame-filepath" title="${text}">
39
+ ${htmlEscape(text)}
40
+ </a>`;
41
+ const functionName = frame.functionName ? `<span>in <code title="${frame.functionName}">
42
+ ${htmlEscape(frame.functionName)}
43
+ </code></span>` : "";
44
+ const loc = `<span>at line <code>${frame.lineNumber}:${frame.columnNumber}</code></span>`;
45
+ if (frame.type !== "native" && frame.source) return `<button class="stack-frame-location">
46
+ ${fileName} ${functionName} ${loc}
47
+ </button>`;
48
+ return `<div class="stack-frame-location">
49
+ ${fileName} ${functionName} ${loc}
50
+ </div>`;
51
+ }
52
+ async #renderStackFrame(frame, index, expandAtIndex, props) {
53
+ const label = frame.type === "app" ? "<span class=\"frame-label\">In App</span>" : "";
54
+ const expandedClass = expandAtIndex === index ? " expanded" : "";
55
+ const toggleButton = frame.type !== "native" && frame.source ? `<button class="stack-frame-toggle-indicator">${CHEVIRON}</button>` : "";
56
+ return `<li class="stack-frame stack-frame-${frame.type}${expandedClass}">
57
+ <div class="stack-frame-contents">
58
+ ${this.#renderFrameLocation(frame, props.ide)}
59
+ <div class="stack-frame-extras">
60
+ ${label}
61
+ ${toggleButton}
62
+ </div>
63
+ </div>
64
+ <div class="stack-frame-source">
65
+ ${await props.sourceCodeRenderer(props.error, frame)}
66
+ </div>
67
+ </li>`;
68
+ }
69
+ async #printStackFrame(frame, index, expandAtIndex, props) {
70
+ const loc = `${this.#getRelativeFileName(frame.fileName)}:${frame.lineNumber}:${frame.columnNumber}`;
71
+ if (index === expandAtIndex) {
72
+ const functionName = frame.functionName ? `at ${frame.functionName} ` : "";
73
+ const codeSnippet = await props.sourceCodeRenderer(props.error, frame);
74
+ return ` ⁃ ${functionName}${colors.yellow(`(${loc})`)}${codeSnippet}`;
75
+ }
76
+ if (frame.type === "native") {
77
+ const functionName = frame.functionName ? `at ${colors.italic(frame.functionName)} ` : "";
78
+ return colors.dim(` ⁃ ${functionName}(${colors.italic(loc)})`);
79
+ }
80
+ return ` ⁃ ${frame.functionName ? `at ${frame.functionName} ` : ""}${colors.yellow(`(${loc})`)}`;
81
+ }
82
+ async toHTML(props) {
83
+ return `<section>
84
+ <div class="card">
85
+ <div class="card-heading">
86
+ <div>
87
+ <h3 class="card-title">
88
+ Stack Trace
89
+ </h3>
90
+ </div>
91
+ </div>
92
+ <div class="card-body">
93
+ <div id="stack-frames-wrapper">
94
+ <div id="stack-frames-header">
95
+ <div id="all-frames-toggle-wrapper">
96
+ <label id="all-frames-toggle">
97
+ <input type="checkbox" />
98
+ <span> View All Frames </span>
99
+ </label>
100
+ </div>
101
+
102
+ <div>
103
+ <div class="toggle-switch">
104
+ <button id="formatted-frames-toggle" class="active"> Pretty </button>
105
+ <button id="raw-frames-toggle"> Raw </button>
106
+ </div>
107
+ </div>
108
+ </div>
109
+
110
+ <div id="stack-frames-body">
111
+ <div id="stack-frames-formatted" class="visible">
112
+ <ul id="stack-frames">
113
+ ${(await Promise.all(props.error.frames.map((frame, index) => {
114
+ return this.#renderStackFrame(frame, index, this.#getFirstExpandedFrameIndex(props.error.frames), props);
115
+ }))).join("\n")}
116
+ </ul>
117
+ </div>
118
+ <div id="stack-frames-raw">
119
+ ${dump(props.error.raw, {
120
+ styles: themes.cssVariables,
121
+ expand: true,
122
+ cspNonce: props.cspNonce,
123
+ inspectObjectPrototype: false,
124
+ inspectStaticMembers: false,
125
+ inspectArrayPrototype: false
126
+ })}
127
+ </div>
128
+ </div>
129
+ <div>
130
+ </div>
131
+ </div>
132
+ </section>`;
133
+ }
134
+ async toANSI(props) {
135
+ const displayRaw = process.env.YOUCH_RAW;
136
+ if (displayRaw) {
137
+ const depth = Number.isNaN(Number(displayRaw)) ? 2 : Number(displayRaw);
138
+ return `\n\n${colors.red("[RAW]")}\n${dump$1(props.error.raw, {
139
+ depth,
140
+ inspectObjectPrototype: false,
141
+ inspectStaticMembers: false,
142
+ inspectArrayPrototype: false
143
+ })}`;
144
+ }
145
+ const frames = await Promise.all(props.error.frames.map((frame, index) => {
146
+ return this.#printStackFrame(frame, index, this.#getFirstExpandedFrameIndex(props.error.frames), props);
147
+ }));
148
+ if (frames.length) return `\n\n${frames.join("\n")}`;
149
+ return "";
150
+ }
151
+ };
152
+ export { ErrorStack };
@@ -0,0 +1,46 @@
1
+ import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js";
2
+ import { r as stripAnsi, t as colors } from "../../../helpers-B9BQYaS6.js";
3
+ import { extname } from "node:path";
4
+ import { highlightText } from "@speed-highlight/core";
5
+ import { highlightText as highlightText$1 } from "@speed-highlight/core/terminal";
6
+ const GUTTER = "┃";
7
+ const POINTER = "❯";
8
+ const LANGS_MAP = {
9
+ ".tsx": "ts",
10
+ ".jsx": "js",
11
+ ".js": "js",
12
+ ".ts": "ts",
13
+ ".css": "css",
14
+ ".json": "json",
15
+ ".html": "html",
16
+ ".astro": "ts",
17
+ ".vue": "ts"
18
+ };
19
+ var ErrorStackSource = class extends BaseComponent {
20
+ cssFile = new URL("./error_stack_source/style.css", publicDirURL);
21
+ async toHTML(props) {
22
+ const frame = props.frame;
23
+ if (frame.type === "native" || !frame.source || !frame.fileName) return "";
24
+ const language = LANGS_MAP[extname(frame.fileName)] ?? "plain";
25
+ const highlight = `<div class="line-highlight" style="margin-top: ${`${frame.source.findIndex((chunk) => {
26
+ return chunk.lineNumber === frame.lineNumber;
27
+ }) * 24}px`}"></div>`;
28
+ let code = await highlightText(frame.source.map((chunk) => chunk.chunk).join("\n"), language, true);
29
+ code = code.replace("<div class=\"shj-numbers\">", `<div class="shj-numbers" style="counter-set: line ${frame.source[0].lineNumber - 1}">`);
30
+ return `<pre><code class="shj-lang-js">${highlight}${code}</code></pre>`;
31
+ }
32
+ async toANSI(props) {
33
+ const frame = props.frame;
34
+ if (frame.type === "native" || !frame.source || !frame.fileName) return "";
35
+ const language = LANGS_MAP[extname(frame.fileName)] ?? "plain";
36
+ const largestLineNumber = Math.max(...frame.source.map(({ lineNumber }) => lineNumber));
37
+ const lineNumberCols = String(largestLineNumber).length;
38
+ return `\n\n${(await highlightText$1(frame.source.map(({ chunk }) => chunk).join("\n"), language)).split("\n").map((line, index) => {
39
+ const lineNumber = frame.source[index].lineNumber;
40
+ const alignedLineNumber = String(lineNumber).padStart(lineNumberCols, " ");
41
+ if (lineNumber === props.frame.lineNumber) return ` ${colors.bgRed(`${POINTER} ${alignedLineNumber} ${GUTTER} ${stripAnsi(line)}`)}`;
42
+ return ` ${colors.dim(alignedLineNumber)} ${colors.dim(GUTTER)} ${line}`;
43
+ }).join("\n")}\n`;
44
+ }
45
+ };
46
+ export { ErrorStackSource };
@@ -0,0 +1,24 @@
1
+ import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js";
2
+ const DARK_MODE_SVG = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="15" height="15" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M0 0h24v24H0z" stroke="none"/><path d="M12 3h.393a7.5 7.5 0 0 0 7.92 12.446A9 9 0 1 1 12 2.992z"/></svg>`;
3
+ const LIGHT_MODE_SVG = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="15" height="15" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M0 0h24v24H0z" stroke="none"/><circle cx="12" cy="12" r="4"/><path d="M3 12h1m8-9v1m8 8h1m-9 8v1M5.6 5.6l.7.7m12.1-.7-.7.7m0 11.4.7.7m-12.1-.7-.7.7"/></svg>`;
4
+ var Header = class extends BaseComponent {
5
+ cssFile = new URL("./header/style.css", publicDirURL);
6
+ scriptFile = new URL("./header/script.js", publicDirURL);
7
+ async toHTML() {
8
+ return `<header id="header">
9
+ <div id="header-actions">
10
+ <div id="toggle-theme-container">
11
+ <input type="checkbox" id="toggle-theme-checkbox" />
12
+ <label id="toggle-theme-label" for="toggle-theme-checkbox">
13
+ <span id="light-theme-indicator" title="Light mode">${LIGHT_MODE_SVG}</span>
14
+ <span id="dark-theme-indicator" title="Dark mode">${DARK_MODE_SVG}</span>
15
+ </label>
16
+ </div>
17
+ </div>
18
+ </header>`;
19
+ }
20
+ async toANSI() {
21
+ return "";
22
+ }
23
+ };
24
+ export { Header };
@@ -0,0 +1,27 @@
1
+ import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js";
2
+ var Layout = class extends BaseComponent {
3
+ cssFile = new URL("./layout/style.css", publicDirURL);
4
+ scriptFile = new URL("./layout/script.js", publicDirURL);
5
+ async toHTML(props) {
6
+ return `<!DOCTYPE html>
7
+ <html lang="en">
8
+ <head>
9
+ <meta charset="UTF-8" />
10
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
11
+ <title>${props.title}</title>
12
+ <!-- STYLES -->
13
+ <!-- GLOBAL SCRIPT -->
14
+ </head>
15
+ <body>
16
+ <div id="layout">
17
+ ${await props.children()}
18
+ </div>
19
+ <!-- SCRIPTS -->
20
+ </body>
21
+ </html>`;
22
+ }
23
+ async toANSI(props) {
24
+ return `\n${await props.children()}\n`;
25
+ }
26
+ };
27
+ export { Layout };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "youch",
3
3
  "description": "Pretty print JavaScript errors on the Web and the Terminal",
4
- "version": "4.1.0-beta.13",
4
+ "version": "4.1.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "build",
@@ -23,7 +23,7 @@
23
23
  "typecheck": "tsc --noEmit",
24
24
  "precompile": "npm run lint",
25
25
  "copy:assets": "copyfiles --up=1 src/public/**/* build",
26
- "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
26
+ "compile": "tsdown && tsc --emitDeclarationOnly --declaration",
27
27
  "build": "npm run compile && npm run copy:assets",
28
28
  "version": "npm run build",
29
29
  "prepublishOnly": "npm run build",
@@ -31,40 +31,40 @@
31
31
  "quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts"
32
32
  },
33
33
  "devDependencies": {
34
- "@adonisjs/eslint-config": "^3.0.0-next.0",
34
+ "@adonisjs/eslint-config": "^3.0.0",
35
35
  "@adonisjs/prettier-config": "^1.4.5",
36
- "@adonisjs/tsconfig": "^2.0.0-next.0",
37
- "@aws-sdk/client-s3": "^3.922.0",
38
- "@aws-sdk/s3-request-presigner": "^3.922.0",
39
- "@japa/assert": "^4.1.1",
40
- "@japa/expect": "^3.0.6",
41
- "@japa/expect-type": "^2.0.3",
42
- "@japa/file-system": "^2.3.2",
43
- "@japa/runner": "^4.4.0",
44
- "@japa/snapshot": "^2.0.9",
45
- "@poppinss/exception": "^1.2.2",
46
- "@poppinss/ts-exec": "^1.4.1",
47
- "@release-it/conventional-changelog": "^10.0.1",
48
- "@types/jsdom": "^27.0.0",
49
- "@types/node": "^24.10.0",
50
- "@types/pg": "^8.15.6",
51
- "axios": "^1.13.1",
36
+ "@adonisjs/tsconfig": "^2.0.0",
37
+ "@aws-sdk/client-s3": "^3.996.0",
38
+ "@aws-sdk/s3-request-presigner": "^3.996.0",
39
+ "@japa/assert": "^4.2.0",
40
+ "@japa/expect": "^3.0.7",
41
+ "@japa/expect-type": "^2.0.4",
42
+ "@japa/file-system": "^3.0.0",
43
+ "@japa/runner": "^5.3.0",
44
+ "@japa/snapshot": "^2.0.10",
45
+ "@poppinss/exception": "^1.2.3",
46
+ "@poppinss/ts-exec": "^1.4.4",
47
+ "@release-it/conventional-changelog": "^10.0.5",
48
+ "@types/jsdom": "^28.0.0",
49
+ "@types/node": "^25.3.0",
50
+ "@types/pg": "^8.16.0",
51
+ "axios": "^1.13.5",
52
52
  "c8": "^10.1.3",
53
53
  "copyfiles": "^2.4.1",
54
- "eslint": "^9.39.0",
55
- "flydrive": "^1.3.0",
56
- "jsdom": "^27.1.0",
57
- "pg": "^8.16.3",
58
- "prettier": "^3.6.2",
59
- "release-it": "^19.0.5",
60
- "tsup": "^8.5.0",
54
+ "eslint": "^10.0.2",
55
+ "flydrive": "^2.0.0",
56
+ "jsdom": "^28.1.0",
57
+ "pg": "^8.18.0",
58
+ "prettier": "^3.8.1",
59
+ "release-it": "^19.2.4",
60
+ "tsdown": "^0.20.3",
61
61
  "typescript": "^5.9.3"
62
62
  },
63
63
  "dependencies": {
64
- "@poppinss/colors": "^4.1.5",
65
- "@poppinss/dumper": "^0.6.5",
66
- "@speed-highlight/core": "^1.2.9",
67
- "cookie-es": "^2.0.0",
64
+ "@poppinss/colors": "^4.1.6",
65
+ "@poppinss/dumper": "^0.7.0",
66
+ "@speed-highlight/core": "^1.2.14",
67
+ "cookie-es": "^3.0.1",
68
68
  "youch-core": "^0.3.3"
69
69
  },
70
70
  "homepage": "https://github.com/poppinss/youch#readme",
@@ -82,7 +82,7 @@
82
82
  "access": "public",
83
83
  "provenance": true
84
84
  },
85
- "tsup": {
85
+ "tsdown": {
86
86
  "entry": [
87
87
  "index.ts",
88
88
  "src/types.ts",
@@ -91,8 +91,11 @@
91
91
  "outDir": "./build",
92
92
  "clean": true,
93
93
  "format": "esm",
94
+ "minify": "dce-only",
95
+ "fixedExtension": false,
94
96
  "dts": false,
95
- "sourcemap": false,
97
+ "treeshake": false,
98
+ "sourcemaps": false,
96
99
  "target": "esnext"
97
100
  },
98
101
  "release-it": {
@@ -1,67 +1,22 @@
1
1
  import "#nitro/virtual/polyfills";
2
- import { Server } from "node:http";
3
- import { parentPort, threadId } from "node:worker_threads";
4
- import wsAdapter from "crossws/adapters/node";
5
- import { toNodeHandler } from "srvx/node";
6
- import { getSocketAddress, isSocketSupported } from "get-port-please";
7
2
  import { useNitroApp, useNitroHooks } from "nitro/app";
8
3
  import { startScheduleRunner } from "#nitro/runtime/task";
9
4
  import { trapUnhandledErrors } from "#nitro/runtime/error/hooks";
10
5
  import { resolveWebsocketHooks } from "#nitro/runtime/app";
11
- // Listen for shutdown signal from runner
12
- parentPort?.on("message", (msg) => {
13
- if (msg && msg.event === "shutdown") {
14
- shutdown();
15
- }
16
- });
6
+ import { tracingSrvxPlugins } from "#nitro/virtual/tracing";
17
7
  const nitroApp = useNitroApp();
18
8
  const nitroHooks = useNitroHooks();
19
9
  trapUnhandledErrors();
20
- const server = new Server(toNodeHandler(nitroApp.fetch));
21
- let listener;
22
- listen().catch((error) => {
23
- console.error("Dev worker failed to listen:", error);
24
- return shutdown();
25
- });
26
- // https://crossws.unjs.io/adapters/node
27
- if (import.meta._websocket) {
28
- const { handleUpgrade } = wsAdapter({ resolve: resolveWebsocketHooks });
29
- server.on("upgrade", handleUpgrade);
30
- }
31
- // Scheduled tasks
10
+
32
11
  if (import.meta._tasks) {
33
- startScheduleRunner();
34
- }
35
- // --- utils ---
36
- async function listen() {
37
- const listenAddr = await isSocketSupported() ? getSocketAddress({
38
- name: `nitro-dev-${threadId}`,
39
- pid: true,
40
- random: true
41
- }) : {
42
- port: 0,
43
- host: "localhost"
44
- };
45
- return new Promise((resolve, reject) => {
46
- try {
47
- listener = server.listen(listenAddr, () => {
48
- const address = server.address();
49
- parentPort?.postMessage({
50
- event: "listen",
51
- address: typeof address === "string" ? { socketPath: address } : {
52
- host: "localhost",
53
- port: address?.port
54
- }
55
- });
56
- resolve();
57
- });
58
- } catch (error) {
59
- reject(error);
60
- }
61
- });
62
- }
63
- async function shutdown() {
64
- server.closeAllConnections?.();
65
- await Promise.all([new Promise((resolve) => listener?.close(resolve)), nitroHooks.callHook("close")]).catch(console.error);
66
- parentPort?.postMessage({ event: "exit" });
12
+ startScheduleRunner({});
67
13
  }
14
+ const ws = import.meta._websocket ? await import("crossws/adapters/node").then((m) => (m.default || m)({ resolve: resolveWebsocketHooks })) : undefined;
15
+ export default {
16
+ fetch: nitroApp.fetch,
17
+ plugins: [...tracingSrvxPlugins],
18
+ upgrade: ws ? (context) => {
19
+ ws.handleUpgrade(context.node.req, context.node.socket, context.node.head);
20
+ } : undefined,
21
+ ipc: { onClose: () => nitroHooks.callHook("close") }
22
+ };
@@ -1,5 +1,6 @@
1
1
  import "#nitro/virtual/polyfills";
2
2
  import consola from "consola";
3
+ import { HTTPError } from "h3";
3
4
  import { useNitroApp, useNitroHooks } from "nitro/app";
4
5
  const nitroApp = useNitroApp();
5
6
  const nitroHooks = useNitroHooks();
@@ -8,10 +8,9 @@ addEventListener("fetch", (event) => {
8
8
  if (isPublicAssetURL(url.pathname) || url.pathname.includes("/_server/")) {
9
9
  return;
10
10
  }
11
- // srvx compatibility
11
+
12
12
  const req = event.request;
13
13
  req.runtime ??= { name: "service-worker" };
14
- // @ts-expect-error (add to srvx types)
15
14
  req.runtime.serviceWorker ??= { event };
16
15
  req.waitUntil = event.waitUntil.bind(event);
17
16
  event.respondWith(nitroApp.fetch(req));
@@ -1,5 +1,5 @@
1
1
  import { stringifyQuery } from "ufo";
2
- // Incoming (AWS => Web)
2
+
3
3
  export function awsRequest(event, context) {
4
4
  const method = awsEventMethod(event);
5
5
  const url = awsEventURL(event);
@@ -10,7 +10,7 @@ export function awsRequest(event, context) {
10
10
  headers,
11
11
  body
12
12
  });
13
- // srvx compatibility
13
+
14
14
  req.runtime ??= { name: "aws-lambda" };
15
15
  // @ts-expect-error (add to srvx types)
16
16
  req.runtime.aws ??= {
@@ -66,7 +66,7 @@ function awsEventBody(event) {
66
66
  }
67
67
  return event.body;
68
68
  }
69
- // Outgoing (Web => AWS)
69
+
70
70
  export function awsResponseHeaders(response) {
71
71
  const headers = Object.create(null);
72
72
  for (const [key, value] of response.headers) {
@@ -81,9 +81,9 @@ export function awsResponseHeaders(response) {
81
81
  multiValueHeaders: { "set-cookie": cookies }
82
82
  } : { headers };
83
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
84
+
85
+
86
+
87
87
  export async function awsResponseBody(response) {
88
88
  if (!response.body) {
89
89
  return { body: "" };
@@ -5,11 +5,13 @@ const nitroApp = useNitroApp();
5
5
  export const handler = awslambda.streamifyResponse(async (event, responseStream, context) => {
6
6
  const request = awsRequest(event, context);
7
7
  const response = await nitroApp.fetch(request);
8
- response.headers.set("transfer-encoding", "chunked");
9
8
  const httpResponseMetadata = {
10
9
  statusCode: response.status,
11
10
  ...awsResponseHeaders(response)
12
11
  };
12
+ if (!httpResponseMetadata.headers["transfer-encoding"]) {
13
+ httpResponseMetadata.headers["transfer-encoding"] = "chunked";
14
+ }
13
15
  const body = response.body ?? new ReadableStream({ start(controller) {
14
16
  controller.enqueue("");
15
17
  controller.close();