@wular/pnext 0.1.6 → 0.1.8

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 (337) hide show
  1. package/bin/pnext +9 -2
  2. package/dist/server/_chunks/aliases-pycbtjt1.js +46 -0
  3. package/dist/server/_chunks/analyze-4d9e00g9.js +449 -0
  4. package/dist/server/_chunks/boot-bhemypxz.js +38 -0
  5. package/dist/server/_chunks/build-c991dv65.js +86 -0
  6. package/dist/server/_chunks/build-kh5e3x48.js +3341 -0
  7. package/dist/server/_chunks/build-tier-0a96kmx3.js +2456 -0
  8. package/dist/server/_chunks/compile-040r79gj.js +22 -0
  9. package/dist/server/_chunks/config-0tvz03a6.js +24 -0
  10. package/dist/server/_chunks/config-27rj7830.js +36 -0
  11. package/dist/server/_chunks/create-9rvwshsp.js +135 -0
  12. package/dist/server/_chunks/dev-ex9exynt.js +220 -0
  13. package/dist/server/_chunks/esbuild-yyktfrtt.js +15 -0
  14. package/dist/server/_chunks/generate-myw9hef7.js +22 -0
  15. package/dist/server/_chunks/index-0r5eqfc7.js +279 -0
  16. package/dist/server/_chunks/index-0yjv5v47.js +105 -0
  17. package/dist/server/_chunks/index-11xpbfej.js +17 -0
  18. package/dist/server/_chunks/index-141vcwk6.js +109 -0
  19. package/dist/server/_chunks/index-1pzm1hdy.js +4130 -0
  20. package/dist/server/_chunks/index-29pq0kax.js +590 -0
  21. package/dist/server/_chunks/index-2vz0wzdn.js +59 -0
  22. package/dist/server/_chunks/index-2wfv4kvx.js +182 -0
  23. package/dist/server/_chunks/index-38xpdxwd.js +194 -0
  24. package/dist/server/_chunks/index-3e075kny.js +128 -0
  25. package/dist/server/_chunks/index-3ycf5ckv.js +472 -0
  26. package/dist/server/_chunks/index-4399bvd2.js +18 -0
  27. package/dist/server/_chunks/index-4da76t62.js +297 -0
  28. package/dist/server/_chunks/index-4t92hdxd.js +172 -0
  29. package/dist/server/_chunks/index-4zzebszd.js +10 -0
  30. package/dist/server/_chunks/index-52k54ykj.js +95 -0
  31. package/dist/server/_chunks/index-5hr4062s.js +70 -0
  32. package/dist/server/_chunks/index-68m3mwbd.js +84 -0
  33. package/dist/server/_chunks/index-6b009mt0.js +56 -0
  34. package/dist/server/_chunks/index-6gex3pfa.js +15 -0
  35. package/dist/server/_chunks/index-6kp9r0d9.js +11 -0
  36. package/dist/server/_chunks/index-6q7zvrap.js +134 -0
  37. package/dist/server/_chunks/index-71885zaq.js +284 -0
  38. package/dist/server/_chunks/index-73z4esab.js +38 -0
  39. package/dist/server/_chunks/index-79ngvam8.js +60 -0
  40. package/dist/server/_chunks/index-7wc9n8be.js +25 -0
  41. package/dist/server/_chunks/index-8ct7rqy3.js +198 -0
  42. package/dist/server/_chunks/index-8kcxdfya.js +206 -0
  43. package/dist/server/_chunks/index-9ch50vtq.js +18 -0
  44. package/dist/server/_chunks/index-9f49w76j.js +213 -0
  45. package/dist/server/_chunks/index-9hz3s0m8.js +851 -0
  46. package/dist/server/_chunks/index-akkrvjn6.js +535 -0
  47. package/dist/server/_chunks/index-b6wtkdp4.js +24 -0
  48. package/dist/server/_chunks/index-b7j671dj.js +207 -0
  49. package/dist/server/_chunks/index-bcws5eh2.js +35 -0
  50. package/dist/server/_chunks/index-bzd2ef7t.js +10 -0
  51. package/dist/server/_chunks/index-cjgqs13g.js +65 -0
  52. package/dist/server/_chunks/index-ckkdpht5.js +41 -0
  53. package/dist/server/_chunks/index-cn86z041.js +296 -0
  54. package/dist/server/_chunks/index-cvr4z22m.js +92 -0
  55. package/dist/server/_chunks/index-cyfednwb.js +87 -0
  56. package/dist/server/_chunks/index-d158y67j.js +152 -0
  57. package/dist/server/_chunks/index-d1jsmhhk.js +955 -0
  58. package/dist/server/_chunks/index-dg0f05zs.js +199 -0
  59. package/dist/server/_chunks/index-dgr390q7.js +9438 -0
  60. package/dist/server/_chunks/index-drwv61cc.js +185 -0
  61. package/dist/server/_chunks/index-e3a6yx84.js +18 -0
  62. package/dist/server/_chunks/index-e88tyv35.js +45 -0
  63. package/dist/server/_chunks/index-en7n9f7m.js +22 -0
  64. package/dist/server/_chunks/index-entm8bmz.js +28 -0
  65. package/dist/server/_chunks/index-evhd413j.js +57 -0
  66. package/dist/server/_chunks/index-ezgj0tr1.js +88 -0
  67. package/dist/server/_chunks/index-fjv96re1.js +5295 -0
  68. package/dist/server/_chunks/index-fn1chkkd.js +214 -0
  69. package/dist/server/_chunks/index-fp8r0sqs.js +64 -0
  70. package/dist/server/_chunks/index-gcmj16xy.js +92 -0
  71. package/dist/server/_chunks/index-gkndxkxf.js +736 -0
  72. package/dist/server/_chunks/index-grta8ap3.js +238 -0
  73. package/dist/server/_chunks/index-h2a70tg4.js +7 -0
  74. package/dist/server/_chunks/index-h4xy648y.js +51 -0
  75. package/dist/server/_chunks/index-hdbwtdv2.js +352 -0
  76. package/dist/server/_chunks/index-he6n2bvp.js +1270 -0
  77. package/dist/server/_chunks/index-j0m1jxqa.js +1253 -0
  78. package/dist/server/_chunks/index-j2zrcp1k.js +66 -0
  79. package/dist/server/_chunks/index-j681c48a.js +2530 -0
  80. package/dist/server/_chunks/index-jbj7ehef.js +50 -0
  81. package/dist/server/_chunks/index-jcsjq3d1.js +20 -0
  82. package/dist/server/_chunks/index-jks0x0a1.js +14 -0
  83. package/dist/server/_chunks/index-jn9rbhrx.js +1599 -0
  84. package/dist/server/_chunks/index-jt8e1pje.js +12 -0
  85. package/dist/server/_chunks/index-kdhxpwyq.js +483 -0
  86. package/dist/server/_chunks/index-knp0s912.js +7 -0
  87. package/dist/server/_chunks/index-kqyy1d4f.js +50 -0
  88. package/dist/server/_chunks/index-kresp2n8.js +445 -0
  89. package/dist/server/_chunks/index-m63czgq5.js +590 -0
  90. package/dist/server/_chunks/index-ms9v9tnx.js +31 -0
  91. package/dist/server/_chunks/index-n4hxpng2.js +11 -0
  92. package/dist/server/_chunks/index-n629dy38.js +1071 -0
  93. package/dist/server/_chunks/index-nf3df4jy.js +266 -0
  94. package/dist/server/_chunks/index-nqh3xhdc.js +57 -0
  95. package/dist/server/_chunks/index-pym1cezq.js +39 -0
  96. package/dist/server/_chunks/index-q3r9z8mq.js +213 -0
  97. package/dist/server/_chunks/index-q738kkhj.js +100 -0
  98. package/dist/server/_chunks/index-qcrvt6er.js +112 -0
  99. package/dist/server/_chunks/index-qjj6gddn.js +54 -0
  100. package/dist/server/_chunks/index-qpwsgt3a.js +158 -0
  101. package/dist/server/_chunks/index-r97ptz1q.js +97 -0
  102. package/dist/server/_chunks/index-ras0sdab.js +26 -0
  103. package/dist/server/_chunks/index-rcs322t1.js +19 -0
  104. package/dist/server/_chunks/index-rgj5mx84.js +101 -0
  105. package/dist/server/_chunks/index-rjegyfx4.js +1435 -0
  106. package/dist/server/_chunks/index-rt9qq1va.js +4 -0
  107. package/dist/server/_chunks/index-rthrsed5.js +356 -0
  108. package/dist/server/_chunks/index-sq3kvz3g.js +200 -0
  109. package/dist/server/_chunks/index-stbk3jhn.js +31 -0
  110. package/dist/server/_chunks/index-tf4j19ge.js +130 -0
  111. package/dist/server/_chunks/index-tgcakdxc.js +125 -0
  112. package/dist/server/_chunks/index-tgsfjmep.js +74 -0
  113. package/dist/server/_chunks/index-tq1f96v7.js +51 -0
  114. package/dist/server/_chunks/index-tq3b39a5.js +107 -0
  115. package/dist/server/_chunks/index-typcbcsv.js +819 -0
  116. package/dist/server/_chunks/index-v1ags1na.js +132 -0
  117. package/dist/server/_chunks/index-vmr35jjw.js +170 -0
  118. package/dist/server/_chunks/index-vvq7rqtn.js +329 -0
  119. package/dist/server/_chunks/index-vz0km5qk.js +33 -0
  120. package/dist/server/_chunks/index-w6h8m6vp.js +138 -0
  121. package/dist/server/_chunks/index-web361b8.js +138 -0
  122. package/dist/server/_chunks/index-wm36rj4v.js +311 -0
  123. package/dist/server/_chunks/index-x0y005nh.js +283 -0
  124. package/dist/server/_chunks/index-x2m17v9c.js +6166 -0
  125. package/dist/server/_chunks/index-x3yn4ywm.js +22 -0
  126. package/dist/server/_chunks/index-x9c55pzy.js +871 -0
  127. package/dist/server/_chunks/index-xh1nbk46.js +1299 -0
  128. package/dist/server/_chunks/index-xvj80c3a.js +30 -0
  129. package/dist/server/_chunks/index-xywjg2vc.js +100 -0
  130. package/dist/server/_chunks/index-y4d02znn.js +66 -0
  131. package/dist/server/_chunks/index-y7mzvq2q.js +110 -0
  132. package/dist/server/_chunks/index-ye9hmsvf.js +47 -0
  133. package/dist/server/_chunks/index-yhxkxghe.js +56 -0
  134. package/dist/server/_chunks/index-yrjkqtfj.js +86 -0
  135. package/dist/server/_chunks/index-z88qv16t.js +11 -0
  136. package/dist/server/_chunks/index-zfrwq472.js +154 -0
  137. package/dist/server/_chunks/index-zqpqyg8p.js +666 -0
  138. package/dist/server/_chunks/loader-5en7wpt5.js +80 -0
  139. package/dist/server/_chunks/modules-t92favpj.js +76 -0
  140. package/dist/server/_chunks/pipeline-4t9q43ht.js +836 -0
  141. package/dist/server/_chunks/production-385bw8df.js +55 -0
  142. package/dist/server/_chunks/proxy-config-60gprphe.js +23 -0
  143. package/dist/server/_chunks/proxy-gfhmktbk.js +35 -0
  144. package/dist/server/_chunks/router-xnrva921.js +501 -0
  145. package/dist/server/_chunks/routes-ht868pdc.js +66 -0
  146. package/dist/server/_chunks/run-d40d63ag.js +697 -0
  147. package/dist/server/_chunks/server-2p8fgqq2.js +1839 -0
  148. package/dist/server/_chunks/tsconfig-defaults-bcn34eqb.js +21 -0
  149. package/dist/server/_chunks/typegen-dvtcjtaw.js +37 -0
  150. package/dist/server/api/client-cache.js +14 -0
  151. package/dist/server/cli/index.js +375 -0
  152. package/dist/server/cli/start.js +158 -0
  153. package/dist/server/client/reference.js +16 -0
  154. package/dist/server/compat/next/cache.js +56 -0
  155. package/dist/server/compat/next/canonical-url.js +13 -0
  156. package/dist/server/compat/next/client-cache.js +57 -0
  157. package/dist/server/compat/next/client-navigation.js +232 -0
  158. package/dist/server/compat/next/client-only.js +1 -0
  159. package/dist/server/compat/next/client-script.js +178 -0
  160. package/dist/server/compat/next/client-server.js +34 -0
  161. package/dist/server/compat/next/config-headers.js +34 -0
  162. package/dist/server/compat/next/config-loader.js +25 -0
  163. package/dist/server/compat/next/config.js +10 -0
  164. package/dist/server/compat/next/constants.js +18 -0
  165. package/dist/server/compat/next/custom-server.js +10 -0
  166. package/dist/server/compat/next/dist/client/components/app-router-headers.js +48 -0
  167. package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +27 -0
  168. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +25 -0
  169. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +25 -0
  170. package/dist/server/compat/next/dynamic.js +21 -0
  171. package/dist/server/compat/next/error.js +112 -0
  172. package/dist/server/compat/next/font/cache.js +16 -0
  173. package/dist/server/compat/next/font/google.js +3 -0
  174. package/dist/server/compat/next/font/index.js +1 -0
  175. package/dist/server/compat/next/font/local.js +24 -0
  176. package/dist/server/compat/next/font/runtime-client.js +33 -0
  177. package/dist/server/compat/next/font/runtime.js +43 -0
  178. package/dist/server/compat/next/font/shared.js +22 -0
  179. package/dist/server/compat/next/form.js +129 -0
  180. package/dist/server/compat/next/head.js +10 -0
  181. package/dist/server/compat/next/headers.js +30 -0
  182. package/dist/server/compat/next/image/client.js +11 -0
  183. package/dist/server/compat/next/image/config.js +18 -0
  184. package/dist/server/compat/next/image/optimizer.js +25 -0
  185. package/dist/server/compat/next/image/patterns.js +12 -0
  186. package/dist/server/compat/next/image/props.js +16 -0
  187. package/dist/server/compat/next/image/shared.js +86 -0
  188. package/dist/server/compat/next/image/static-metadata.js +32 -0
  189. package/dist/server/compat/next/image/validate.js +8 -0
  190. package/dist/server/compat/next/image.js +59 -0
  191. package/dist/server/compat/next/index.js +1 -0
  192. package/dist/server/compat/next/legacy-image.js +78 -0
  193. package/dist/server/compat/next/legacy-request-apis.js +24 -0
  194. package/dist/server/compat/next/link-transform.js +15 -0
  195. package/dist/server/compat/next/link.js +14 -0
  196. package/dist/server/compat/next/navigation.js +191 -0
  197. package/dist/server/compat/next/offline.js +45 -0
  198. package/dist/server/compat/next/og.js +8 -0
  199. package/dist/server/compat/next/preferred-region.js +8 -0
  200. package/dist/server/compat/next/redirects.js +32 -0
  201. package/dist/server/compat/next/resource-hints.js +30 -0
  202. package/dist/server/compat/next/rewrites.js +43 -0
  203. package/dist/server/compat/next/root-params.js +121 -0
  204. package/dist/server/compat/next/route-state.js +23 -0
  205. package/dist/server/compat/next/router.js +103 -0
  206. package/dist/server/compat/next/script.js +37 -0
  207. package/dist/server/compat/next/server-only.js +1 -0
  208. package/dist/server/compat/next/server.js +131 -0
  209. package/dist/server/compat/next/svgr.js +14 -0
  210. package/dist/server/compat/next/telemetry.js +10 -0
  211. package/dist/server/compat/next/usage.js +13 -0
  212. package/dist/server/compat/next/user-agent.js +12 -0
  213. package/dist/server/compat/next/web-vitals.js +35 -0
  214. package/dist/server/compat/react/action-state.js +11 -0
  215. package/dist/server/compat/react/client-lite.js +83 -0
  216. package/dist/server/compat/react/client.js +131 -0
  217. package/dist/server/compat/react/compiler-runtime.js +42 -0
  218. package/dist/server/compat/react/dom-client.js +106 -0
  219. package/dist/server/compat/react/dom-react-server.js +37 -0
  220. package/dist/server/compat/react/dom-server.js +40 -0
  221. package/dist/server/compat/react/dom.js +52 -0
  222. package/dist/server/compat/react/hooks-extra.js +12 -0
  223. package/dist/server/compat/react/internals.js +14 -0
  224. package/dist/server/compat/react/parity.js +11 -0
  225. package/dist/server/compat/react/preact.js +113 -0
  226. package/dist/server/compat/react/react-server.js +133 -0
  227. package/dist/server/compat/react/router-shim.js +8 -0
  228. package/dist/server/compat/react/server-component-use.js +14 -0
  229. package/dist/server/compat/react/server-inserted-html.js +14 -0
  230. package/dist/server/compat/react/server.js +194 -0
  231. package/dist/server/compat/react/style-values.js +10 -0
  232. package/dist/server/compat/react/use.js +10 -0
  233. package/dist/server/compat/react/view-transition.js +12 -0
  234. package/dist/server/generation.json +1 -0
  235. package/package.json +4 -1
  236. package/reference/compat.md +1 -1
  237. package/reference/config.md +2 -2
  238. package/reference/dev.md +1 -1
  239. package/reference/getting-started.md +1 -1
  240. package/reference/rendering.md +4 -4
  241. package/src/api/dynamic.tsx +86 -4
  242. package/src/api/server.ts +24 -6
  243. package/src/cli/adapters/vercel-warm.ts +327 -62
  244. package/src/cli/adapters/vercel.ts +164 -1054
  245. package/src/cli/analyze.ts +3 -2
  246. package/src/cli/build/cache.ts +6 -6
  247. package/src/cli/build.ts +78 -45
  248. package/src/cli/index.ts +21 -3
  249. package/src/cli/serve/immutable.ts +31 -0
  250. package/src/cli/serve/pipeline.ts +97 -93
  251. package/src/cli/serve/standalone-worker.ts +8 -0
  252. package/src/cli/serve/standalone.ts +703 -0
  253. package/src/cli/start.ts +31 -8
  254. package/src/client/build.ts +1 -1
  255. package/src/client/chunk-fold.ts +19 -6
  256. package/src/client/react-tier.ts +3 -2
  257. package/src/client/reference-stub.ts +23 -36
  258. package/src/compat/actions/client-plugin.ts +4 -2
  259. package/src/compat/actions/config.ts +6 -5
  260. package/src/compat/actions/extensions.ts +5 -5
  261. package/src/compat/aliases.ts +8 -1
  262. package/src/compat/bundler/config.ts +88 -0
  263. package/src/compat/bundler/optimize-package-imports.ts +86 -26
  264. package/src/compat/bundler/relay-transform.ts +15 -3
  265. package/src/compat/bundler/require-context.ts +2 -1
  266. package/src/compat/bundler/webpack-loaders.ts +3 -2
  267. package/src/compat/bundler/worker.ts +2 -2
  268. package/src/compat/cache-control.ts +16 -8
  269. package/src/compat/css/inline-css.ts +1 -1
  270. package/src/compat/css/modules.ts +18 -5
  271. package/src/compat/export/build-complete.ts +1 -1
  272. package/src/compat/export/emit.ts +4 -4
  273. package/src/compat/export/standalone.ts +30 -65
  274. package/src/compat/image-optimizer/optimize.ts +1 -1
  275. package/src/compat/lifecycle/error-funnel.ts +1 -1
  276. package/src/compat/lifecycle/instrumentation-client.ts +4 -3
  277. package/src/compat/lifecycle/instrumentation.ts +117 -24
  278. package/src/compat/lifecycle/testmode.ts +3 -2
  279. package/src/compat/metadata-artifacts.ts +1 -1
  280. package/src/compat/next/config-loader.ts +140 -13
  281. package/src/compat/next/dynamic.tsx +10 -23
  282. package/src/compat/next/font/cache.ts +2 -1
  283. package/src/compat/next/font/runtime.ts +23 -3
  284. package/src/compat/next/og.ts +3 -3
  285. package/src/compat/next/usage.ts +3 -2
  286. package/src/compat/pages/api.ts +83 -14
  287. package/src/compat/pages/router.ts +30 -14
  288. package/src/compat/register/bundler.ts +3 -1
  289. package/src/compat/register/image.ts +1 -1
  290. package/src/compat/register/middleware.ts +1 -1
  291. package/src/compat/register/otel.ts +5 -9
  292. package/src/compat/register/render.ts +3 -1
  293. package/src/compat/register/use-cache.ts +3 -1
  294. package/src/compat/release.ts +46 -0
  295. package/src/compat/segment/serve.ts +1 -1
  296. package/src/compat/typecheck/check.ts +6 -4
  297. package/src/compat/validation/validate.ts +10 -7
  298. package/src/config.ts +76 -9
  299. package/src/css/assets.ts +213 -0
  300. package/src/css/build.ts +190 -247
  301. package/src/dev/client-chunk-store.ts +2 -1
  302. package/src/dev/restart/client-key.ts +2 -1
  303. package/src/dev/restart/global-css.ts +2 -1
  304. package/src/dev/restart/route-bundle-key.ts +2 -1
  305. package/src/dev/restart/route-facts.ts +2 -1
  306. package/src/dev/server.ts +34 -14
  307. package/src/extensions.ts +4 -0
  308. package/src/out-paths.ts +10 -0
  309. package/src/render/hooks.ts +13 -0
  310. package/src/render/renderer.ts +53 -33
  311. package/src/request/context.ts +9 -0
  312. package/src/resolve/dynamic.ts +7 -1
  313. package/src/resolve/engine.ts +2 -12
  314. package/src/resolve/imports.ts +12 -52
  315. package/src/resolve/package-json.ts +56 -0
  316. package/src/resolve/scan-facts.ts +250 -1
  317. package/src/routing/href.ts +10 -3
  318. package/src/routing/match.ts +287 -0
  319. package/src/routing/metadata-files.ts +20 -6
  320. package/src/routing/proxy-config.ts +137 -0
  321. package/src/routing/proxy.ts +35 -134
  322. package/src/routing/routes.ts +22 -281
  323. package/src/runtime/fingerprint.ts +23 -8
  324. package/src/runtime/load.ts +170 -0
  325. package/src/runtime/loader.ts +218 -44
  326. package/src/runtime/module-cache.ts +15 -1
  327. package/src/runtime/modules.ts +405 -82
  328. package/src/runtime/prebundle.ts +101 -0
  329. package/src/runtime/production.ts +456 -0
  330. package/src/runtime/release-graph.ts +342 -0
  331. package/src/runtime/vendor-build.ts +750 -17
  332. package/src/runtime/vendor.ts +16 -3
  333. package/src/types.ts +4 -3
  334. package/src/utils/directive.ts +40 -0
  335. package/src/utils/fs.ts +95 -4
  336. package/src/utils/resource-query.ts +12 -0
  337. package/src/cli/serve/entry.ts +0 -45
@@ -0,0 +1,182 @@
1
+ // @bun
2
+ import { join as __pnextJoin } from "node:path";
3
+ const __PNEXT_PACKAGE_ROOT__ = __pnextJoin(import.meta.dirname, "../../..");
4
+ import {
5
+ currentRequest,
6
+ getWorkUnit
7
+ } from "./index-grta8ap3.js";
8
+
9
+ // src/compat/lifecycle/testmode.ts
10
+ import { PassThrough } from "stream";
11
+ import { createRequire } from "module";
12
+ var requireNode = createRequire(Bun.pathToFileURL(__PNEXT_PACKAGE_ROOT__ + "/src/compat/lifecycle/testmode.ts").href);
13
+ var TEST_PROXY_KEY = Symbol.for("pnext.testProxy");
14
+ function readTestProxyInfo(headers) {
15
+ const portHeader = headers.get("next-test-proxy-port");
16
+ if (!portHeader)
17
+ return;
18
+ return { proxyPort: Number(portHeader), testData: headers.get("next-test-data") ?? "" };
19
+ }
20
+ function activateTestProxy(headers) {
21
+ const info = readTestProxyInfo(headers);
22
+ if (!info)
23
+ return;
24
+ const unit = getWorkUnit();
25
+ if (!unit)
26
+ return;
27
+ (unit.compat ??= {})[TEST_PROXY_KEY] = info;
28
+ }
29
+ function currentTestProxyInfo() {
30
+ const workUnitInfo = getWorkUnit()?.compat?.[TEST_PROXY_KEY];
31
+ if (workUnitInfo)
32
+ return workUnitInfo;
33
+ const request = currentRequest();
34
+ if (!request)
35
+ return;
36
+ return readTestProxyInfo(request.headers);
37
+ }
38
+ async function buildProxyRequest(testData, request) {
39
+ return {
40
+ testData,
41
+ api: "fetch",
42
+ request: {
43
+ url: request.url,
44
+ method: request.method,
45
+ headers: [...Array.from(request.headers), ["next-test-stack", getTestStack()]],
46
+ body: request.body ? Buffer.from(await request.arrayBuffer()).toString("base64") : null,
47
+ cache: request.cache,
48
+ credentials: request.credentials,
49
+ integrity: request.integrity,
50
+ mode: request.mode === "navigate" ? "cors" : request.mode,
51
+ redirect: request.redirect,
52
+ referrer: request.referrer,
53
+ referrerPolicy: request.referrerPolicy
54
+ }
55
+ };
56
+ }
57
+ function getTestStack() {
58
+ let stack = (new Error().stack ?? "").split(`
59
+ `);
60
+ for (let i = 1;i < stack.length; i++) {
61
+ const line = stack[i];
62
+ if (line && line.length > 0) {
63
+ stack = stack.slice(i);
64
+ break;
65
+ }
66
+ }
67
+ stack = stack.filter((item) => !item.includes("/next/dist/"));
68
+ stack = stack.slice(0, 5);
69
+ stack = stack.map((line) => line.replace("webpack-internal:///(rsc)/", "").trim());
70
+ return stack.join(" ");
71
+ }
72
+ async function handleProxiedFetch(originalFetch, info, request) {
73
+ const proxyRequest = await buildProxyRequest(info.testData, request);
74
+ const resp = await originalFetch(`http://localhost:${info.proxyPort}`, {
75
+ method: "POST",
76
+ body: JSON.stringify(proxyRequest),
77
+ next: { internal: true }
78
+ });
79
+ if (!resp.ok)
80
+ throw new Error(`Proxy request failed: ${resp.status}`);
81
+ const proxyResponse = await resp.json();
82
+ switch (proxyResponse.api) {
83
+ case "continue":
84
+ return originalFetch(request);
85
+ case "fetch": {
86
+ const r = proxyResponse.response;
87
+ return new Response(r.body ? Buffer.from(r.body, "base64") : null, {
88
+ status: r.status,
89
+ headers: new Headers(r.headers)
90
+ });
91
+ }
92
+ default:
93
+ throw new Error(`Proxy request aborted [${request.method} ${request.url}]`);
94
+ }
95
+ }
96
+ function buildResponseMessage(responsePromise, callback) {
97
+ const stream = new PassThrough;
98
+ const message = stream;
99
+ responsePromise.then(async (response) => {
100
+ const headers = {};
101
+ const rawHeaders = [];
102
+ for (const [name, value] of response.headers) {
103
+ headers[name.toLowerCase()] = value;
104
+ rawHeaders.push(name, value);
105
+ }
106
+ message.statusCode = response.status;
107
+ message.statusMessage = response.statusText;
108
+ message.headers = headers;
109
+ message.rawHeaders = rawHeaders;
110
+ message.complete = true;
111
+ callback?.(message);
112
+ const body = await response.arrayBuffer();
113
+ stream.end(Buffer.from(body));
114
+ }).catch((error) => {
115
+ stream.emit("error", error);
116
+ stream.end();
117
+ });
118
+ return message;
119
+ }
120
+ function getStringForGetInput(input) {
121
+ if (typeof input === "string" || input instanceof URL)
122
+ return input.toString();
123
+ const candidate = input;
124
+ if (typeof candidate.href === "string" && /^[a-z][a-z\d+.-]*:\/\//i.test(candidate.href))
125
+ return candidate.href;
126
+ const protocol = typeof candidate.protocol === "string" ? candidate.protocol : "http:";
127
+ const host = typeof candidate.host === "string" ? candidate.host : typeof candidate.hostname === "string" ? candidate.hostname : undefined;
128
+ if (!host)
129
+ return;
130
+ const port = typeof candidate.port === "number" ? `:${candidate.port}` : typeof candidate.port === "string" ? `:${candidate.port}` : "";
131
+ const path = typeof candidate.path === "string" ? candidate.path : typeof candidate.pathname === "string" ? candidate.pathname : "/";
132
+ const search = typeof candidate.search === "string" ? candidate.search : "";
133
+ return `${protocol}//${host}${port}${path}${search}`;
134
+ }
135
+ function patchableGet(originalGet, originalFetch) {
136
+ return (input, options) => {
137
+ const callback = typeof options === "function" ? options : undefined;
138
+ const url = getStringForGetInput(input);
139
+ const info = currentTestProxyInfo();
140
+ if (!url || !info) {
141
+ if (typeof options === "function") {
142
+ return originalGet(input, options);
143
+ }
144
+ if (options === undefined) {
145
+ return originalGet(input);
146
+ }
147
+ return originalGet(input, options);
148
+ }
149
+ const request = new Request(url, {
150
+ method: typeof options === "object" && options && "method" in options && typeof options.method === "string" ? options.method : "GET",
151
+ headers: typeof options === "object" && options && "headers" in options ? options.headers : undefined
152
+ });
153
+ return buildResponseMessage(handleProxiedFetch(originalFetch, info, request), callback);
154
+ };
155
+ }
156
+ var patched = false;
157
+ function installTestProxyFetch() {
158
+ if (patched)
159
+ return;
160
+ patched = true;
161
+ const originalFetch = globalThis.fetch.bind(globalThis);
162
+ const testFetch = function testFetch2(input, init) {
163
+ const nextInit = init?.next;
164
+ if (nextInit?.internal) {
165
+ return originalFetch(input, init);
166
+ }
167
+ const info = currentTestProxyInfo();
168
+ if (!info)
169
+ return originalFetch(input, init);
170
+ return handleProxiedFetch(originalFetch, info, new Request(input, init));
171
+ };
172
+ testFetch.preconnect = originalFetch.preconnect?.bind(originalFetch);
173
+ globalThis.fetch = testFetch;
174
+ const httpModule = requireNode("node:http");
175
+ const httpsModule = requireNode("node:https");
176
+ const originalHttpGet = httpModule.get;
177
+ const originalHttpsGet = httpsModule.get;
178
+ httpModule.get = patchableGet(originalHttpGet, originalFetch);
179
+ httpsModule.get = patchableGet(originalHttpsGet, originalFetch);
180
+ }
181
+
182
+ export { activateTestProxy, installTestProxyFetch };
@@ -0,0 +1,194 @@
1
+ // @bun
2
+ import {
3
+ scanRoutes
4
+ } from "./index-jn9rbhrx.js";
5
+ import {
6
+ ensureDir,
7
+ includeTypes,
8
+ toPosixPath,
9
+ writeFileAtomic
10
+ } from "./index-4da76t62.js";
11
+ import {
12
+ bootstrapCompatBoot,
13
+ generateCompatRouteTypes
14
+ } from "./index-tq3b39a5.js";
15
+ import {
16
+ loadConfig
17
+ } from "./index-71885zaq.js";
18
+
19
+ // src/cli/typegen.ts
20
+ import { existsSync } from "fs";
21
+ import { readFile, rm, writeFile } from "fs/promises";
22
+ import path from "path";
23
+ async function typegenProject(root) {
24
+ const config = await loadConfig(root);
25
+ await bootstrapCompatBoot(config);
26
+ const routes = await scanRoutes(config.appPath, config.workspaceRoot);
27
+ const result = await writeTypegen(config, routes);
28
+ await generateCompatRouteTypes(config, routes);
29
+ return result;
30
+ }
31
+ async function writeTypegen(config, allRoutes) {
32
+ const routes = allRoutes.filter((route) => !route.interception && !route.synthetic);
33
+ const file = path.join(config.typesPath, "pnext.gen.d.ts");
34
+ const source = typegenSource(routes);
35
+ await writeIfChanged(file, source);
36
+ await writeCoreEnv(config, file, allRoutes);
37
+ const aliases = await writeRouteAliases(config, routes);
38
+ const checks = await writeChecks(config, routes);
39
+ return { file, routes: routes.length, checks, aliases };
40
+ }
41
+ function typegenSource(routes) {
42
+ const entries = routes.map((route) => routeEntry(route)).join(`
43
+ `);
44
+ return `// This file is generated by PNext. Do not edit.
45
+ import '@wular/pnext';
46
+
47
+ declare module '@wular/pnext' {
48
+ interface PNextRoutes {
49
+ ${entries}
50
+ }
51
+ }
52
+ `;
53
+ }
54
+ function routeEntry(route) {
55
+ return ` '${routeKey(route.route)}': {
56
+ kind: '${route.kind}';
57
+ params: ${paramsType(route)};
58
+ mode: '${route.mode}';
59
+ hydrated: ${route.client ? "true" : "false"};
60
+ };`;
61
+ }
62
+ async function writeChecks(config, routes) {
63
+ const checksDir = config.checksPath;
64
+ await rm(path.join(config.typesPath, "checks"), { recursive: true, force: true });
65
+ await rm(checksDir, { recursive: true, force: true });
66
+ await ensureDir(checksDir);
67
+ const checked = routes.filter((route) => !route.metadataRoute);
68
+ await Promise.all(checked.map((route) => {
69
+ const file = path.join(checksDir, `${route.id}.check.ts`);
70
+ return writeIfChanged(file, checkSource(checksDir, route));
71
+ }));
72
+ return checked.length;
73
+ }
74
+ async function writeRouteAliases(config, routes) {
75
+ const aliasesDir = path.join(config.typesPath, "app");
76
+ await rm(aliasesDir, { recursive: true, force: true });
77
+ await ensureDir(aliasesDir);
78
+ await Promise.all(routes.map((route) => {
79
+ const file = path.join(aliasesDir, `${routeAliasPath(config, route)}.d.ts`);
80
+ return writeIfChanged(file, routeAliasSource(route));
81
+ }));
82
+ return routes.length;
83
+ }
84
+ function routeAliasSource(route) {
85
+ const routeType = routeKey(route.route);
86
+ return `// This file is generated by PNext. Do not edit.
87
+ import type {
88
+ PageProps as PNextPageProps,
89
+ RouteContext as PNextRouteContext,
90
+ RouteParams as PNextRouteParams,
91
+ StaticParams as PNextStaticParams,
92
+ } from '@wular/pnext';
93
+
94
+ export type Params = PNextRouteParams<'${routeType}'>;
95
+ export type PageProps = PNextPageProps<'${routeType}'>;
96
+ export type RouteContext = PNextRouteContext<'${routeType}'>;
97
+ export type StaticParams = PNextStaticParams<'${routeType}'>;
98
+ `;
99
+ }
100
+ function routeAliasPath(config, route) {
101
+ const relative = toPosixPath(path.relative(config.appPath, route.file));
102
+ const extension = path.extname(relative);
103
+ return relative.slice(0, -extension.length);
104
+ }
105
+ function checkSource(checksDir, route) {
106
+ const routeImport = routeImportPath(checksDir, route.file);
107
+ const routeType = routeKey(route.route);
108
+ const moduleType = route.kind === "page" ? `PNextPageModule<'${routeType}'>` : `PNextRouteHandlerModule<'${routeType}'>`;
109
+ return `// This file is generated by PNext. Do not edit.
110
+ import type { PNextPageModule, PNextRouteHandlerModule } from '@wular/pnext/internal';
111
+ import * as routeModule from '${routeImport}';
112
+
113
+ const check: ${moduleType} = routeModule;
114
+ void check;
115
+ `;
116
+ }
117
+ function routeImportPath(fromDir, file) {
118
+ const extension = path.extname(file);
119
+ const withoutExtension = file.slice(0, -extension.length);
120
+ const relative = toPosixPath(path.relative(fromDir, withoutExtension));
121
+ return relative.startsWith(".") ? relative : `./${relative}`;
122
+ }
123
+ function routeKey(route) {
124
+ return route.replace(/:([a-zA-Z0-9_]+)\*/g, "[...$1]").replace(/:([a-zA-Z0-9_]+)/g, "[$1]");
125
+ }
126
+ function paramsType(route) {
127
+ const entries = route.params.map((param) => `${JSON.stringify(param)}: string`);
128
+ if (route.catchAll)
129
+ entries.push(`${JSON.stringify(route.catchAll)}: string[]`);
130
+ return entries.length > 0 ? `{ ${entries.join("; ")} }` : "Record<string, never>";
131
+ }
132
+ async function writeIfChanged(file, source) {
133
+ try {
134
+ if (existsSync(file) && await readFile(file, "utf8") === source)
135
+ return;
136
+ } catch {}
137
+ await ensureDir(path.dirname(file));
138
+ await writeFile(file, source);
139
+ }
140
+ async function writeCoreEnv(config, typesFile, routes) {
141
+ if (config.compat?.next)
142
+ return;
143
+ const file = path.join(config.root, "tsconfig.json");
144
+ const exists = existsSync(file);
145
+ if (!exists && !routes.some((route) => route.sourceFiles.some((file2) => /\.[cm]?tsx?$/.test(file2))))
146
+ return;
147
+ const reference = toPosixPath(path.relative(config.root, typesFile));
148
+ await writeIfChanged(path.join(config.root, "pnext-env.d.ts"), `/// <reference types="@wular/pnext" />
149
+ /// <reference path="${reference}" />
150
+
151
+ // This file is generated by PNext. Do not edit.
152
+ `);
153
+ if (!exists)
154
+ return;
155
+ let source;
156
+ let tsconfig;
157
+ try {
158
+ source = await readFile(file, "utf8");
159
+ tsconfig = Bun.JSONC.parse(source);
160
+ } catch {
161
+ return;
162
+ }
163
+ if (!tsconfig || !Array.isArray(tsconfig.include))
164
+ return;
165
+ const typesGlob = `${toPosixPath(path.relative(config.root, config.typesPath))}/**/*.ts`;
166
+ const added = includeTypes(tsconfig, ["pnext-env.d.ts", typesGlob], []);
167
+ if (added.length)
168
+ await writeFileAtomic(file, updateTypeSelection(source, added));
169
+ }
170
+ function updateTypeSelection(source, added) {
171
+ const tokens = [
172
+ ...source.matchAll(/"(?:\\[\s\S]|[^"\\])*"|\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|[^\s]/g)
173
+ ].filter((token) => !token[0].startsWith("//") && !token[0].startsWith("/*"));
174
+ let depth = 0;
175
+ for (let index = 0;index < tokens.length; index++) {
176
+ const token = tokens[index];
177
+ if (depth === 1 && token[0].startsWith('"') && JSON.parse(token[0]) === "include" && tokens[index + 1]?.[0] === ":") {
178
+ let end = index + 3;
179
+ while (tokens[end]?.[0] !== "]")
180
+ end++;
181
+ const close = tokens[end];
182
+ const previous = tokens[end - 1][0];
183
+ const insertion = `${previous === "[" || previous === "," ? "" : ","} ${added.map((value) => JSON.stringify(value)).join(", ")}`;
184
+ return source.slice(0, close.index) + insertion + source.slice(close.index);
185
+ }
186
+ if (token[0] === "[" || token[0] === "{")
187
+ depth++;
188
+ if (token[0] === "]" || token[0] === "}")
189
+ depth--;
190
+ }
191
+ return source;
192
+ }
193
+
194
+ export { typegenProject, writeTypegen };
@@ -0,0 +1,128 @@
1
+ // @bun
2
+ import {
3
+ findProxyFile
4
+ } from "./index-3ycf5ckv.js";
5
+ import {
6
+ loadNative
7
+ } from "./index-7wc9n8be.js";
8
+ import {
9
+ __require
10
+ } from "./index-rt9qq1va.js";
11
+
12
+ // src/routing/proxy-config.ts
13
+ import { readFileSync } from "fs";
14
+ import path from "path";
15
+ var parseSync = (...args) => loadNative(() => __require("oxc-parser")).parseSync(...args);
16
+ function releasedProxy(config) {
17
+ const file = findProxyFile(config);
18
+ if (!file)
19
+ return;
20
+ try {
21
+ return { file, config: staticProxyConfig(file, readFileSync(file, "utf8")) };
22
+ } catch {
23
+ return { file };
24
+ }
25
+ }
26
+ function staticProxyConfig(file, source) {
27
+ const result = parseSync(file, source, { lang: parserLang(file) });
28
+ if (result.errors.length > 0)
29
+ return;
30
+ for (const statement of result.program.body) {
31
+ if (statement.type !== "ExportNamedDeclaration")
32
+ continue;
33
+ const declaration = statement.declaration;
34
+ if (declaration?.type !== "VariableDeclaration")
35
+ continue;
36
+ for (const declarator of declaration.declarations ?? []) {
37
+ if (declarator.id?.type !== "Identifier" || declarator.id.name !== "config")
38
+ continue;
39
+ const value = staticValue(declarator.init);
40
+ return isProxyConfigShape(value) ? value : undefined;
41
+ }
42
+ }
43
+ return;
44
+ }
45
+ function parserLang(file) {
46
+ const ext = path.extname(file);
47
+ if (ext === ".tsx")
48
+ return "tsx";
49
+ if (ext === ".jsx")
50
+ return "jsx";
51
+ return ext === ".js" || ext === ".mjs" ? "js" : "ts";
52
+ }
53
+ function staticValue(node) {
54
+ if (!node)
55
+ return;
56
+ switch (node.type) {
57
+ case "TSAsExpression":
58
+ case "TSSatisfiesExpression":
59
+ case "TSNonNullExpression":
60
+ return staticValue(node.expression);
61
+ case "Literal":
62
+ case "StringLiteral":
63
+ case "NumericLiteral":
64
+ case "BooleanLiteral":
65
+ return node.value === null ? undefined : node.value;
66
+ case "TemplateLiteral":
67
+ return node.expressions?.length === 0 ? node.quasis?.[0]?.value?.cooked ?? undefined : undefined;
68
+ case "ArrayExpression": {
69
+ const items = [];
70
+ for (const element of node.elements ?? []) {
71
+ const value = staticValue(element);
72
+ if (value === undefined)
73
+ return;
74
+ items.push(value);
75
+ }
76
+ return items;
77
+ }
78
+ case "ObjectExpression": {
79
+ const object = {};
80
+ for (const property of node.properties ?? []) {
81
+ if (property.type !== "Property" && property.type !== "ObjectProperty")
82
+ return;
83
+ if (property.computed)
84
+ return;
85
+ const key = property.key?.type === "Identifier" ? property.key.name : property.key?.value;
86
+ if (typeof key !== "string")
87
+ return;
88
+ const value = staticValue(property.value);
89
+ if (value === undefined)
90
+ return;
91
+ object[key] = value;
92
+ }
93
+ return object;
94
+ }
95
+ default:
96
+ return;
97
+ }
98
+ }
99
+ function isProxyConfigShape(value) {
100
+ if (typeof value !== "object" || value === null)
101
+ return false;
102
+ const matcher = value.matcher;
103
+ if (matcher === undefined)
104
+ return true;
105
+ const items = Array.isArray(matcher) ? matcher : [matcher];
106
+ return items.every((item) => {
107
+ if (typeof item === "string")
108
+ return true;
109
+ if (typeof item !== "object" || item === null)
110
+ return false;
111
+ const { source, has, missing } = item;
112
+ if (typeof source !== "string")
113
+ return false;
114
+ return [has, missing].every((list) => list === undefined || Array.isArray(list) && list.every(isConditionShape));
115
+ });
116
+ }
117
+ function isConditionShape(value) {
118
+ if (typeof value !== "object" || value === null)
119
+ return false;
120
+ const { type, key, value: expected } = value;
121
+ if (type !== "header" && type !== "query" && type !== "cookie" && type !== "host")
122
+ return false;
123
+ if (key !== undefined && typeof key !== "string")
124
+ return false;
125
+ return expected === undefined || typeof expected === "string";
126
+ }
127
+
128
+ export { releasedProxy, staticProxyConfig };