vinext 0.0.30 → 0.0.32

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 (435) hide show
  1. package/README.md +15 -7
  2. package/dist/build/prerender.d.ts +188 -0
  3. package/dist/build/prerender.js +675 -0
  4. package/dist/build/prerender.js.map +1 -0
  5. package/dist/build/report.d.ts +45 -46
  6. package/dist/build/report.js +581 -276
  7. package/dist/build/report.js.map +1 -1
  8. package/dist/build/run-prerender.d.ts +62 -0
  9. package/dist/build/run-prerender.js +183 -0
  10. package/dist/build/run-prerender.js.map +1 -0
  11. package/dist/build/server-manifest.d.ts +19 -0
  12. package/dist/build/server-manifest.js +29 -0
  13. package/dist/build/server-manifest.js.map +1 -0
  14. package/dist/build/static-export.d.ts +51 -66
  15. package/dist/build/static-export.js +51 -545
  16. package/dist/build/static-export.js.map +1 -1
  17. package/dist/check.d.ts +26 -24
  18. package/dist/check.js +681 -571
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +432 -491
  22. package/dist/cli.js.map +1 -1
  23. package/dist/client/entry.d.ts +1 -2
  24. package/dist/client/entry.js +49 -62
  25. package/dist/client/entry.js.map +1 -1
  26. package/dist/client/validate-module-path.d.ts +4 -1
  27. package/dist/client/validate-module-path.js +23 -28
  28. package/dist/client/validate-module-path.js.map +1 -1
  29. package/dist/client/vinext-next-data.d.ts +15 -20
  30. package/dist/client/vinext-next-data.js +0 -1
  31. package/dist/cloudflare/index.d.ts +3 -8
  32. package/dist/cloudflare/index.js +3 -8
  33. package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
  34. package/dist/cloudflare/kv-cache-handler.js +354 -380
  35. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  36. package/dist/cloudflare/tpr.d.ts +36 -34
  37. package/dist/cloudflare/tpr.js +460 -603
  38. package/dist/cloudflare/tpr.js.map +1 -1
  39. package/dist/config/config-matchers.d.ts +31 -40
  40. package/dist/config/config-matchers.js +727 -936
  41. package/dist/config/config-matchers.js.map +1 -1
  42. package/dist/config/dotenv.d.ts +18 -11
  43. package/dist/config/dotenv.js +79 -84
  44. package/dist/config/dotenv.js.map +1 -1
  45. package/dist/config/next-config.d.ts +156 -146
  46. package/dist/config/next-config.js +376 -464
  47. package/dist/config/next-config.js.map +1 -1
  48. package/dist/deploy.d.ts +87 -96
  49. package/dist/deploy.js +490 -628
  50. package/dist/deploy.js.map +1 -1
  51. package/dist/entries/app-browser-entry.d.ts +4 -1
  52. package/dist/entries/app-browser-entry.js +12 -8
  53. package/dist/entries/app-browser-entry.js.map +1 -1
  54. package/dist/entries/app-rsc-entry.d.ts +33 -20
  55. package/dist/entries/app-rsc-entry.js +444 -212
  56. package/dist/entries/app-rsc-entry.js.map +1 -1
  57. package/dist/entries/app-ssr-entry.d.ts +9 -1
  58. package/dist/entries/app-ssr-entry.js +61 -28
  59. package/dist/entries/app-ssr-entry.js.map +1 -1
  60. package/dist/entries/pages-client-entry.d.ts +6 -2
  61. package/dist/entries/pages-client-entry.js +30 -33
  62. package/dist/entries/pages-client-entry.js.map +1 -1
  63. package/dist/entries/pages-entry-helpers.d.ts +5 -1
  64. package/dist/entries/pages-entry-helpers.js +17 -14
  65. package/dist/entries/pages-entry-helpers.js.map +1 -1
  66. package/dist/entries/pages-server-entry.d.ts +6 -2
  67. package/dist/entries/pages-server-entry.js +86 -114
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +92 -60
  70. package/dist/index.js +2151 -3133
  71. package/dist/index.js.map +1 -1
  72. package/dist/init.d.ts +40 -37
  73. package/dist/init.js +201 -258
  74. package/dist/init.js.map +1 -1
  75. package/dist/plugins/async-hooks-stub.d.ts +7 -3
  76. package/dist/plugins/async-hooks-stub.js +39 -42
  77. package/dist/plugins/async-hooks-stub.js.map +1 -1
  78. package/dist/plugins/client-reference-dedup.d.ts +7 -3
  79. package/dist/plugins/client-reference-dedup.js +63 -88
  80. package/dist/plugins/client-reference-dedup.js.map +1 -1
  81. package/dist/routing/app-router.d.ts +100 -96
  82. package/dist/routing/app-router.js +560 -670
  83. package/dist/routing/app-router.js.map +1 -1
  84. package/dist/routing/file-matcher.d.ts +18 -15
  85. package/dist/routing/file-matcher.js +65 -65
  86. package/dist/routing/file-matcher.js.map +1 -1
  87. package/dist/routing/pages-router.d.ts +23 -24
  88. package/dist/routing/pages-router.js +147 -172
  89. package/dist/routing/pages-router.js.map +1 -1
  90. package/dist/routing/route-trie.d.ts +23 -20
  91. package/dist/routing/route-trie.js +131 -151
  92. package/dist/routing/route-trie.js.map +1 -1
  93. package/dist/routing/route-validation.d.ts +5 -2
  94. package/dist/routing/route-validation.js +98 -130
  95. package/dist/routing/route-validation.js.map +1 -1
  96. package/dist/routing/utils.d.ts +10 -7
  97. package/dist/routing/utils.js +75 -111
  98. package/dist/routing/utils.js.map +1 -1
  99. package/dist/server/api-handler.d.ts +8 -13
  100. package/dist/server/api-handler.js +160 -193
  101. package/dist/server/api-handler.js.map +1 -1
  102. package/dist/server/app-router-entry.d.ts +6 -16
  103. package/dist/server/app-router-entry.js +26 -54
  104. package/dist/server/app-router-entry.js.map +1 -1
  105. package/dist/server/dev-module-runner.d.ts +11 -64
  106. package/dist/server/dev-module-runner.js +89 -101
  107. package/dist/server/dev-module-runner.js.map +1 -1
  108. package/dist/server/dev-origin-check.d.ts +12 -10
  109. package/dist/server/dev-origin-check.js +98 -108
  110. package/dist/server/dev-origin-check.js.map +1 -1
  111. package/dist/server/dev-server.d.ts +19 -15
  112. package/dist/server/dev-server.js +543 -871
  113. package/dist/server/dev-server.js.map +1 -1
  114. package/dist/server/html.d.ts +4 -1
  115. package/dist/server/html.js +25 -26
  116. package/dist/server/html.js.map +1 -1
  117. package/dist/server/image-optimization.d.ts +31 -28
  118. package/dist/server/image-optimization.js +181 -210
  119. package/dist/server/image-optimization.js.map +1 -1
  120. package/dist/server/instrumentation.d.ts +34 -59
  121. package/dist/server/instrumentation.js +112 -125
  122. package/dist/server/instrumentation.js.map +1 -1
  123. package/dist/server/isr-cache.d.ts +16 -26
  124. package/dist/server/isr-cache.js +106 -128
  125. package/dist/server/isr-cache.js.map +1 -1
  126. package/dist/server/metadata-routes.d.ts +85 -88
  127. package/dist/server/metadata-routes.js +270 -317
  128. package/dist/server/metadata-routes.js.map +1 -1
  129. package/dist/server/middleware-codegen.d.ts +7 -4
  130. package/dist/server/middleware-codegen.js +61 -61
  131. package/dist/server/middleware-codegen.js.map +1 -1
  132. package/dist/server/middleware-request-headers.d.ts +8 -6
  133. package/dist/server/middleware-request-headers.js +47 -65
  134. package/dist/server/middleware-request-headers.js.map +1 -1
  135. package/dist/server/middleware.d.ts +32 -47
  136. package/dist/server/middleware.js +261 -409
  137. package/dist/server/middleware.js.map +1 -1
  138. package/dist/server/normalize-path.d.ts +4 -1
  139. package/dist/server/normalize-path.js +33 -47
  140. package/dist/server/normalize-path.js.map +1 -1
  141. package/dist/server/pages-i18n.d.ts +38 -30
  142. package/dist/server/pages-i18n.js +112 -139
  143. package/dist/server/pages-i18n.js.map +1 -1
  144. package/dist/server/prod-server.d.ts +19 -31
  145. package/dist/server/prod-server.js +715 -945
  146. package/dist/server/prod-server.js.map +1 -1
  147. package/dist/server/request-log.d.ts +18 -12
  148. package/dist/server/request-log.js +45 -52
  149. package/dist/server/request-log.js.map +1 -1
  150. package/dist/server/request-pipeline.d.ts +9 -17
  151. package/dist/server/request-pipeline.js +133 -184
  152. package/dist/server/request-pipeline.js.map +1 -1
  153. package/dist/server/worker-utils.d.ts +4 -1
  154. package/dist/server/worker-utils.js +31 -37
  155. package/dist/server/worker-utils.js.map +1 -1
  156. package/dist/shims/amp.d.ts +5 -2
  157. package/dist/shims/amp.js +19 -15
  158. package/dist/shims/amp.js.map +1 -1
  159. package/dist/shims/app.d.ts +8 -10
  160. package/dist/shims/app.js +0 -1
  161. package/dist/shims/cache-runtime.d.ts +20 -45
  162. package/dist/shims/cache-runtime.js +271 -422
  163. package/dist/shims/cache-runtime.js.map +1 -1
  164. package/dist/shims/cache.d.ts +130 -121
  165. package/dist/shims/cache.js +339 -427
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/client-only.d.ts +1 -18
  168. package/dist/shims/client-only.js +0 -17
  169. package/dist/shims/compat-router.d.ts +6 -1
  170. package/dist/shims/compat-router.js +23 -19
  171. package/dist/shims/compat-router.js.map +1 -1
  172. package/dist/shims/config.d.ts +7 -5
  173. package/dist/shims/config.js +16 -23
  174. package/dist/shims/config.js.map +1 -1
  175. package/dist/shims/constants.d.ts +119 -118
  176. package/dist/shims/constants.js +159 -164
  177. package/dist/shims/constants.js.map +1 -1
  178. package/dist/shims/document.d.ts +20 -16
  179. package/dist/shims/document.js +41 -22
  180. package/dist/shims/document.js.map +1 -1
  181. package/dist/shims/dynamic.d.ts +13 -22
  182. package/dist/shims/dynamic.js +122 -136
  183. package/dist/shims/dynamic.js.map +1 -1
  184. package/dist/shims/error-boundary.d.ts +22 -15
  185. package/dist/shims/error-boundary.js +81 -79
  186. package/dist/shims/error-boundary.js.map +1 -1
  187. package/dist/shims/error.d.ts +11 -12
  188. package/dist/shims/error.js +35 -39
  189. package/dist/shims/error.js.map +1 -1
  190. package/dist/shims/fetch-cache.d.ts +16 -14
  191. package/dist/shims/fetch-cache.js +439 -645
  192. package/dist/shims/fetch-cache.js.map +1 -1
  193. package/dist/shims/font-google-base.d.ts +28 -26
  194. package/dist/shims/font-google-base.js +238 -325
  195. package/dist/shims/font-google-base.js.map +1 -1
  196. package/dist/shims/font-google.d.ts +3 -3
  197. package/dist/shims/font-google.generated.d.ts +1928 -1924
  198. package/dist/shims/font-google.generated.js +1928 -2133
  199. package/dist/shims/font-google.generated.js.map +1 -1
  200. package/dist/shims/font-google.js +3 -3
  201. package/dist/shims/font-local.d.ts +28 -26
  202. package/dist/shims/font-local.js +204 -260
  203. package/dist/shims/font-local.js.map +1 -1
  204. package/dist/shims/form.d.ts +13 -27
  205. package/dist/shims/form.js +128 -180
  206. package/dist/shims/form.js.map +1 -1
  207. package/dist/shims/head-state.d.ts +8 -13
  208. package/dist/shims/head-state.js +25 -42
  209. package/dist/shims/head-state.js.map +1 -1
  210. package/dist/shims/head.d.ts +17 -20
  211. package/dist/shims/head.js +194 -250
  212. package/dist/shims/head.js.map +1 -1
  213. package/dist/shims/headers.d.ts +84 -78
  214. package/dist/shims/headers.js +447 -575
  215. package/dist/shims/headers.js.map +1 -1
  216. package/dist/shims/i18n-context.d.ts +16 -20
  217. package/dist/shims/i18n-context.js +35 -48
  218. package/dist/shims/i18n-context.js.map +1 -1
  219. package/dist/shims/i18n-state.d.ts +8 -14
  220. package/dist/shims/i18n-state.js +34 -42
  221. package/dist/shims/i18n-state.js.map +1 -1
  222. package/dist/shims/image-config.d.ts +11 -8
  223. package/dist/shims/image-config.js +50 -83
  224. package/dist/shims/image-config.js.map +1 -1
  225. package/dist/shims/image.d.ts +37 -46
  226. package/dist/shims/image.js +283 -308
  227. package/dist/shims/image.js.map +1 -1
  228. package/dist/shims/internal/api-utils.d.ts +7 -4
  229. package/dist/shims/internal/api-utils.js +0 -6
  230. package/dist/shims/internal/app-router-context.d.ts +22 -17
  231. package/dist/shims/internal/app-router-context.js +17 -13
  232. package/dist/shims/internal/app-router-context.js.map +1 -1
  233. package/dist/shims/internal/cookies.d.ts +2 -9
  234. package/dist/shims/internal/cookies.js +2 -9
  235. package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
  236. package/dist/shims/internal/parse-cookie-header.js +29 -29
  237. package/dist/shims/internal/parse-cookie-header.js.map +1 -1
  238. package/dist/shims/internal/router-context.d.ts +7 -1
  239. package/dist/shims/internal/router-context.js +11 -7
  240. package/dist/shims/internal/router-context.js.map +1 -1
  241. package/dist/shims/internal/utils.d.ts +40 -37
  242. package/dist/shims/internal/utils.js +24 -30
  243. package/dist/shims/internal/utils.js.map +1 -1
  244. package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
  245. package/dist/shims/internal/work-unit-async-storage.js +14 -11
  246. package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
  247. package/dist/shims/layout-segment-context.d.ts +11 -14
  248. package/dist/shims/layout-segment-context.js +24 -23
  249. package/dist/shims/layout-segment-context.js.map +1 -1
  250. package/dist/shims/legacy-image.d.ts +39 -46
  251. package/dist/shims/legacy-image.js +47 -42
  252. package/dist/shims/legacy-image.js.map +1 -1
  253. package/dist/shims/link.d.ts +32 -36
  254. package/dist/shims/link.js +255 -391
  255. package/dist/shims/link.js.map +1 -1
  256. package/dist/shims/metadata.d.ts +210 -202
  257. package/dist/shims/metadata.js +545 -546
  258. package/dist/shims/metadata.js.map +1 -1
  259. package/dist/shims/navigation-state.d.ts +10 -18
  260. package/dist/shims/navigation-state.js +66 -74
  261. package/dist/shims/navigation-state.js.map +1 -1
  262. package/dist/shims/navigation.d.ts +59 -63
  263. package/dist/shims/navigation.js +505 -704
  264. package/dist/shims/navigation.js.map +1 -1
  265. package/dist/shims/og.d.ts +2 -20
  266. package/dist/shims/og.js +2 -19
  267. package/dist/shims/readonly-url-search-params.d.ts +8 -5
  268. package/dist/shims/readonly-url-search-params.js +26 -22
  269. package/dist/shims/readonly-url-search-params.js.map +1 -1
  270. package/dist/shims/request-context.d.ts +8 -5
  271. package/dist/shims/request-context.js +50 -60
  272. package/dist/shims/request-context.js.map +1 -1
  273. package/dist/shims/request-state-types.d.ts +11 -11
  274. package/dist/shims/request-state-types.js +0 -1
  275. package/dist/shims/router-state.d.ts +13 -10
  276. package/dist/shims/router-state.js +34 -43
  277. package/dist/shims/router-state.js.map +1 -1
  278. package/dist/shims/router.d.ts +81 -85
  279. package/dist/shims/router.js +506 -628
  280. package/dist/shims/router.js.map +1 -1
  281. package/dist/shims/script.d.ts +39 -48
  282. package/dist/shims/script.js +107 -160
  283. package/dist/shims/script.js.map +1 -1
  284. package/dist/shims/server-only.d.ts +1 -19
  285. package/dist/shims/server-only.js +0 -18
  286. package/dist/shims/server.d.ts +213 -164
  287. package/dist/shims/server.js +545 -478
  288. package/dist/shims/server.js.map +1 -1
  289. package/dist/shims/unified-request-context.d.ts +20 -20
  290. package/dist/shims/unified-request-context.js +81 -99
  291. package/dist/shims/unified-request-context.js.map +1 -1
  292. package/dist/shims/url-safety.d.ts +4 -1
  293. package/dist/shims/url-safety.js +15 -11
  294. package/dist/shims/url-safety.js.map +1 -1
  295. package/dist/shims/url-utils.d.ts +8 -5
  296. package/dist/shims/url-utils.js +62 -93
  297. package/dist/shims/url-utils.js.map +1 -1
  298. package/dist/shims/web-vitals.d.ts +10 -8
  299. package/dist/shims/web-vitals.js +9 -15
  300. package/dist/shims/web-vitals.js.map +1 -1
  301. package/dist/utils/base-path.d.ts +5 -2
  302. package/dist/utils/base-path.js +21 -19
  303. package/dist/utils/base-path.js.map +1 -1
  304. package/dist/utils/domain-locale.d.ts +17 -9
  305. package/dist/utils/domain-locale.js +36 -56
  306. package/dist/utils/domain-locale.js.map +1 -1
  307. package/dist/utils/hash.d.ts +4 -1
  308. package/dist/utils/hash.js +19 -17
  309. package/dist/utils/hash.js.map +1 -1
  310. package/dist/utils/manifest-paths.d.ts +6 -3
  311. package/dist/utils/manifest-paths.js +15 -16
  312. package/dist/utils/manifest-paths.js.map +1 -1
  313. package/dist/utils/project.d.ts +13 -11
  314. package/dist/utils/project.js +169 -216
  315. package/dist/utils/project.js.map +1 -1
  316. package/dist/utils/query.d.ts +8 -6
  317. package/dist/utils/query.js +57 -67
  318. package/dist/utils/query.js.map +1 -1
  319. package/package.json +10 -9
  320. package/dist/build/report.d.ts.map +0 -1
  321. package/dist/build/static-export.d.ts.map +0 -1
  322. package/dist/check.d.ts.map +0 -1
  323. package/dist/cli.d.ts.map +0 -1
  324. package/dist/client/entry.d.ts.map +0 -1
  325. package/dist/client/validate-module-path.d.ts.map +0 -1
  326. package/dist/client/vinext-next-data.d.ts.map +0 -1
  327. package/dist/client/vinext-next-data.js.map +0 -1
  328. package/dist/cloudflare/index.d.ts.map +0 -1
  329. package/dist/cloudflare/index.js.map +0 -1
  330. package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
  331. package/dist/cloudflare/tpr.d.ts.map +0 -1
  332. package/dist/config/config-matchers.d.ts.map +0 -1
  333. package/dist/config/dotenv.d.ts.map +0 -1
  334. package/dist/config/next-config.d.ts.map +0 -1
  335. package/dist/deploy.d.ts.map +0 -1
  336. package/dist/entries/app-browser-entry.d.ts.map +0 -1
  337. package/dist/entries/app-rsc-entry.d.ts.map +0 -1
  338. package/dist/entries/app-ssr-entry.d.ts.map +0 -1
  339. package/dist/entries/pages-client-entry.d.ts.map +0 -1
  340. package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
  341. package/dist/entries/pages-server-entry.d.ts.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/init.d.ts.map +0 -1
  344. package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
  345. package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
  346. package/dist/routing/app-router.d.ts.map +0 -1
  347. package/dist/routing/file-matcher.d.ts.map +0 -1
  348. package/dist/routing/pages-router.d.ts.map +0 -1
  349. package/dist/routing/route-trie.d.ts.map +0 -1
  350. package/dist/routing/route-validation.d.ts.map +0 -1
  351. package/dist/routing/utils.d.ts.map +0 -1
  352. package/dist/server/api-handler.d.ts.map +0 -1
  353. package/dist/server/app-router-entry.d.ts.map +0 -1
  354. package/dist/server/dev-module-runner.d.ts.map +0 -1
  355. package/dist/server/dev-origin-check.d.ts.map +0 -1
  356. package/dist/server/dev-server.d.ts.map +0 -1
  357. package/dist/server/html.d.ts.map +0 -1
  358. package/dist/server/image-optimization.d.ts.map +0 -1
  359. package/dist/server/instrumentation.d.ts.map +0 -1
  360. package/dist/server/isr-cache.d.ts.map +0 -1
  361. package/dist/server/metadata-routes.d.ts.map +0 -1
  362. package/dist/server/middleware-codegen.d.ts.map +0 -1
  363. package/dist/server/middleware-request-headers.d.ts.map +0 -1
  364. package/dist/server/middleware.d.ts.map +0 -1
  365. package/dist/server/normalize-path.d.ts.map +0 -1
  366. package/dist/server/pages-i18n.d.ts.map +0 -1
  367. package/dist/server/prod-server.d.ts.map +0 -1
  368. package/dist/server/request-log.d.ts.map +0 -1
  369. package/dist/server/request-pipeline.d.ts.map +0 -1
  370. package/dist/server/worker-utils.d.ts.map +0 -1
  371. package/dist/shims/amp.d.ts.map +0 -1
  372. package/dist/shims/app.d.ts.map +0 -1
  373. package/dist/shims/app.js.map +0 -1
  374. package/dist/shims/cache-runtime.d.ts.map +0 -1
  375. package/dist/shims/cache.d.ts.map +0 -1
  376. package/dist/shims/client-only.d.ts.map +0 -1
  377. package/dist/shims/client-only.js.map +0 -1
  378. package/dist/shims/compat-router.d.ts.map +0 -1
  379. package/dist/shims/config.d.ts.map +0 -1
  380. package/dist/shims/constants.d.ts.map +0 -1
  381. package/dist/shims/document.d.ts.map +0 -1
  382. package/dist/shims/dynamic.d.ts.map +0 -1
  383. package/dist/shims/error-boundary.d.ts.map +0 -1
  384. package/dist/shims/error.d.ts.map +0 -1
  385. package/dist/shims/fetch-cache.d.ts.map +0 -1
  386. package/dist/shims/font-google-base.d.ts.map +0 -1
  387. package/dist/shims/font-google.d.ts.map +0 -1
  388. package/dist/shims/font-google.generated.d.ts.map +0 -1
  389. package/dist/shims/font-google.js.map +0 -1
  390. package/dist/shims/font-local.d.ts.map +0 -1
  391. package/dist/shims/form.d.ts.map +0 -1
  392. package/dist/shims/head-state.d.ts.map +0 -1
  393. package/dist/shims/head.d.ts.map +0 -1
  394. package/dist/shims/headers.d.ts.map +0 -1
  395. package/dist/shims/i18n-context.d.ts.map +0 -1
  396. package/dist/shims/i18n-state.d.ts.map +0 -1
  397. package/dist/shims/image-config.d.ts.map +0 -1
  398. package/dist/shims/image.d.ts.map +0 -1
  399. package/dist/shims/internal/api-utils.d.ts.map +0 -1
  400. package/dist/shims/internal/api-utils.js.map +0 -1
  401. package/dist/shims/internal/app-router-context.d.ts.map +0 -1
  402. package/dist/shims/internal/cookies.d.ts.map +0 -1
  403. package/dist/shims/internal/cookies.js.map +0 -1
  404. package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
  405. package/dist/shims/internal/router-context.d.ts.map +0 -1
  406. package/dist/shims/internal/utils.d.ts.map +0 -1
  407. package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
  408. package/dist/shims/layout-segment-context.d.ts.map +0 -1
  409. package/dist/shims/legacy-image.d.ts.map +0 -1
  410. package/dist/shims/link.d.ts.map +0 -1
  411. package/dist/shims/metadata.d.ts.map +0 -1
  412. package/dist/shims/navigation-state.d.ts.map +0 -1
  413. package/dist/shims/navigation.d.ts.map +0 -1
  414. package/dist/shims/og.d.ts.map +0 -1
  415. package/dist/shims/og.js.map +0 -1
  416. package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
  417. package/dist/shims/request-context.d.ts.map +0 -1
  418. package/dist/shims/request-state-types.d.ts.map +0 -1
  419. package/dist/shims/request-state-types.js.map +0 -1
  420. package/dist/shims/router-state.d.ts.map +0 -1
  421. package/dist/shims/router.d.ts.map +0 -1
  422. package/dist/shims/script.d.ts.map +0 -1
  423. package/dist/shims/server-only.d.ts.map +0 -1
  424. package/dist/shims/server-only.js.map +0 -1
  425. package/dist/shims/server.d.ts.map +0 -1
  426. package/dist/shims/unified-request-context.d.ts.map +0 -1
  427. package/dist/shims/url-safety.d.ts.map +0 -1
  428. package/dist/shims/url-utils.d.ts.map +0 -1
  429. package/dist/shims/web-vitals.d.ts.map +0 -1
  430. package/dist/utils/base-path.d.ts.map +0 -1
  431. package/dist/utils/domain-locale.d.ts.map +0 -1
  432. package/dist/utils/hash.d.ts.map +0 -1
  433. package/dist/utils/manifest-paths.d.ts.map +0 -1
  434. package/dist/utils/project.d.ts.map +0 -1
  435. package/dist/utils/query.d.ts.map +0 -1
@@ -1,441 +1,293 @@
1
- /**
2
- * proxy.ts / middleware.ts runner
3
- *
4
- * Loads and executes the user's proxy.ts (Next.js 16) or middleware.ts file
5
- * before routing. Runs in Node (not Edge Runtime), per the vinext design.
6
- *
7
- * In Next.js 16, proxy.ts replaces middleware.ts:
8
- * - proxy.ts: default export OR named `proxy` function, runs on Node.js runtime
9
- * - middleware.ts: deprecated but still supported for Edge runtime use cases
10
- *
11
- * The proxy/middleware receives a NextRequest and can:
12
- * - Return NextResponse.next() to continue to the route
13
- * - Return NextResponse.redirect() to redirect
14
- * - Return NextResponse.rewrite() to rewrite the URL
15
- * - Set/modify headers and cookies
16
- * - Return a Response directly (e.g., for auth guards)
17
- *
18
- * Supports the `config.matcher` export for path filtering.
19
- */
1
+ import { normalizePathnameForRouteMatchStrict } from "../routing/utils.js";
2
+ import { shouldKeepMiddlewareHeader } from "./middleware-request-headers.js";
3
+ import { checkHasConditions, requestContextFromRequest, safeRegExp } from "../config/config-matchers.js";
4
+ import { NextFetchEvent, NextRequest } from "../shims/server.js";
5
+ import { normalizePath } from "./normalize-path.js";
20
6
  import fs from "node:fs";
21
7
  import path from "node:path";
22
- import { checkHasConditions, requestContextFromRequest, safeRegExp, } from "../config/config-matchers.js";
23
- import { NextRequest, NextFetchEvent } from "../shims/server.js";
24
- import { normalizePath } from "./normalize-path.js";
25
- import { shouldKeepMiddlewareHeader } from "./middleware-request-headers.js";
26
- import { normalizePathnameForRouteMatchStrict } from "../routing/utils.js";
8
+ //#region src/server/middleware.ts
27
9
  /**
28
- * Determine whether a middleware/proxy file path refers to a proxy file.
29
- * proxy.ts files accept `proxy` or `default` exports.
30
- * middleware.ts files accept `middleware` or `default` exports.
31
- *
32
- * Matches Next.js behavior where each file type only accepts its own
33
- * named export or a default export:
34
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/middleware.ts
35
- */
36
- export function isProxyFile(filePath) {
37
- const base = path.basename(filePath).replace(/\.\w+$/, "");
38
- return base === "proxy";
10
+ * Determine whether a middleware/proxy file path refers to a proxy file.
11
+ * proxy.ts files accept `proxy` or `default` exports.
12
+ * middleware.ts files accept `middleware` or `default` exports.
13
+ *
14
+ * Matches Next.js behavior where each file type only accepts its own
15
+ * named export or a default export:
16
+ * https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/middleware.ts
17
+ */
18
+ function isProxyFile(filePath) {
19
+ return path.basename(filePath).replace(/\.\w+$/, "") === "proxy";
39
20
  }
40
21
  /**
41
- * Resolve the middleware/proxy handler function from a module's exports.
42
- * Matches Next.js behavior: for proxy files, check `proxy` then `default`;
43
- * for middleware files, check `middleware` then `default`.
44
- *
45
- * Throws if the file exists but doesn't export a valid function, matching
46
- * Next.js's ProxyMissingExportError behavior.
47
- *
48
- * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/middleware.ts
49
- * @see https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts
50
- */
51
- export function resolveMiddlewareHandler(mod, filePath) {
52
- const isProxy = isProxyFile(filePath);
53
- const handler = isProxy ? (mod.proxy ?? mod.default) : (mod.middleware ?? mod.default);
54
- if (typeof handler !== "function") {
55
- const fileType = isProxy ? "Proxy" : "Middleware";
56
- const expectedExport = isProxy ? "proxy" : "middleware";
57
- throw new Error(`The ${fileType} file "${filePath}" must export a function named \`${expectedExport}\` or a \`default\` function.`);
58
- }
59
- return handler;
22
+ * Resolve the middleware/proxy handler function from a module's exports.
23
+ * Matches Next.js behavior: for proxy files, check `proxy` then `default`;
24
+ * for middleware files, check `middleware` then `default`.
25
+ *
26
+ * Throws if the file exists but doesn't export a valid function, matching
27
+ * Next.js's ProxyMissingExportError behavior.
28
+ *
29
+ * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/middleware.ts
30
+ * @see https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts
31
+ */
32
+ function resolveMiddlewareHandler(mod, filePath) {
33
+ const isProxy = isProxyFile(filePath);
34
+ const handler = isProxy ? mod.proxy ?? mod.default : mod.middleware ?? mod.default;
35
+ if (typeof handler !== "function") {
36
+ const fileType = isProxy ? "Proxy" : "Middleware";
37
+ const expectedExport = isProxy ? "proxy" : "middleware";
38
+ throw new Error(`The ${fileType} file "${filePath}" must export a function named \`${expectedExport}\` or a \`default\` function.`);
39
+ }
40
+ return handler;
60
41
  }
42
+ const MIDDLEWARE_LOCATIONS = ["", "src/"];
61
43
  /**
62
- * Possible proxy/middleware file names.
63
- * proxy.ts (Next.js 16) is checked first, then middleware.ts (deprecated).
64
- */
65
- const PROXY_FILES = [
66
- "proxy.ts",
67
- "proxy.js",
68
- "proxy.mjs",
69
- "src/proxy.ts",
70
- "src/proxy.js",
71
- "src/proxy.mjs",
72
- ];
73
- const MIDDLEWARE_FILES = [
74
- "middleware.ts",
75
- "middleware.tsx",
76
- "middleware.js",
77
- "middleware.mjs",
78
- "src/middleware.ts",
79
- "src/middleware.tsx",
80
- "src/middleware.js",
81
- "src/middleware.mjs",
82
- ];
83
- /**
84
- * Find the proxy or middleware file in the project root.
85
- * Checks for proxy.ts (Next.js 16) first, then falls back to middleware.ts.
86
- * If middleware.ts is found, logs a deprecation warning.
87
- */
88
- export function findMiddlewareFile(root) {
89
- // Check proxy.ts first (Next.js 16 replacement for middleware.ts)
90
- for (const file of PROXY_FILES) {
91
- const fullPath = path.join(root, file);
92
- if (fs.existsSync(fullPath)) {
93
- return fullPath;
94
- }
95
- }
96
- // Fall back to middleware.ts (deprecated in Next.js 16)
97
- for (const file of MIDDLEWARE_FILES) {
98
- const fullPath = path.join(root, file);
99
- if (fs.existsSync(fullPath)) {
100
- console.warn("[vinext] middleware.ts is deprecated in Next.js 16. " +
101
- "Rename to proxy.ts and export a default or named proxy function.");
102
- return fullPath;
103
- }
104
- }
105
- return null;
44
+ * Find the proxy or middleware file in the project root.
45
+ * Checks for proxy.ts (Next.js 16) first, then falls back to middleware.ts.
46
+ * If middleware.ts is found, logs a deprecation warning.
47
+ */
48
+ function findMiddlewareFile(root, fileMatcher) {
49
+ for (const dir of MIDDLEWARE_LOCATIONS) for (const ext of fileMatcher.dottedExtensions) {
50
+ const fullPath = path.join(root, dir, `proxy${ext}`);
51
+ if (fs.existsSync(fullPath)) return fullPath;
52
+ }
53
+ for (const dir of MIDDLEWARE_LOCATIONS) for (const ext of fileMatcher.dottedExtensions) {
54
+ const fullPath = path.join(root, dir, `middleware${ext}`);
55
+ if (fs.existsSync(fullPath)) {
56
+ console.warn("[vinext] middleware.ts is deprecated in Next.js 16. Rename to proxy.ts and export a default or named proxy function.");
57
+ return fullPath;
58
+ }
59
+ }
60
+ return null;
106
61
  }
107
62
  const EMPTY_MIDDLEWARE_REQUEST_CONTEXT = {
108
- headers: new Headers(),
109
- cookies: {},
110
- query: new URLSearchParams(),
111
- host: "",
63
+ headers: new Headers(),
64
+ cookies: {},
65
+ query: new URLSearchParams(),
66
+ host: ""
112
67
  };
113
68
  /**
114
- * Check if a pathname matches the middleware matcher config.
115
- * If no matcher is configured, middleware runs on all paths
116
- * except static files and internal Next.js paths.
117
- */
118
- export function matchesMiddleware(pathname, matcher, request, i18nConfig) {
119
- if (!matcher) {
120
- // Next.js default: middleware runs on ALL paths when no matcher is configured.
121
- // Users opt out of specific paths by configuring a matcher pattern.
122
- return true;
123
- }
124
- if (typeof matcher === "string") {
125
- return matchMatcherPattern(pathname, matcher, i18nConfig);
126
- }
127
- if (!Array.isArray(matcher)) {
128
- return false;
129
- }
130
- const requestContext = request
131
- ? requestContextFromRequest(request)
132
- : EMPTY_MIDDLEWARE_REQUEST_CONTEXT;
133
- for (const m of matcher) {
134
- if (typeof m === "string") {
135
- if (matchMatcherPattern(pathname, m, i18nConfig)) {
136
- return true;
137
- }
138
- continue;
139
- }
140
- if (isValidMiddlewareMatcherObject(m)) {
141
- if (!matchObjectMatcher(pathname, m, i18nConfig)) {
142
- continue;
143
- }
144
- if (!checkHasConditions(m.has, m.missing, requestContext)) {
145
- continue;
146
- }
147
- return true;
148
- }
149
- }
150
- return false;
69
+ * Check if a pathname matches the middleware matcher config.
70
+ * If no matcher is configured, middleware runs on all paths
71
+ * except static files and internal Next.js paths.
72
+ */
73
+ function matchesMiddleware(pathname, matcher, request, i18nConfig) {
74
+ if (!matcher) return true;
75
+ if (typeof matcher === "string") return matchMatcherPattern(pathname, matcher, i18nConfig);
76
+ if (!Array.isArray(matcher)) return false;
77
+ const requestContext = request ? requestContextFromRequest(request) : EMPTY_MIDDLEWARE_REQUEST_CONTEXT;
78
+ for (const m of matcher) {
79
+ if (typeof m === "string") {
80
+ if (matchMatcherPattern(pathname, m, i18nConfig)) return true;
81
+ continue;
82
+ }
83
+ if (isValidMiddlewareMatcherObject(m)) {
84
+ if (!matchObjectMatcher(pathname, m, i18nConfig)) continue;
85
+ if (!checkHasConditions(m.has, m.missing, requestContext)) continue;
86
+ return true;
87
+ }
88
+ }
89
+ return false;
151
90
  }
152
- // Keep this in sync with __isValidMiddlewareMatcherObject in middleware-codegen.ts.
153
91
  function isValidMiddlewareMatcherObject(value) {
154
- if (!value || typeof value !== "object" || Array.isArray(value))
155
- return false;
156
- const matcher = value;
157
- if (typeof matcher.source !== "string")
158
- return false;
159
- for (const key of Object.keys(matcher)) {
160
- if (key !== "source" && key !== "locale" && key !== "has" && key !== "missing") {
161
- return false;
162
- }
163
- }
164
- if ("locale" in matcher && matcher.locale !== undefined && matcher.locale !== false)
165
- return false;
166
- if ("has" in matcher && matcher.has !== undefined && !Array.isArray(matcher.has))
167
- return false;
168
- if ("missing" in matcher && matcher.missing !== undefined && !Array.isArray(matcher.missing)) {
169
- return false;
170
- }
171
- return true;
92
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
93
+ const matcher = value;
94
+ if (typeof matcher.source !== "string") return false;
95
+ for (const key of Object.keys(matcher)) if (key !== "source" && key !== "locale" && key !== "has" && key !== "missing") return false;
96
+ if ("locale" in matcher && matcher.locale !== void 0 && matcher.locale !== false) return false;
97
+ if ("has" in matcher && matcher.has !== void 0 && !Array.isArray(matcher.has)) return false;
98
+ if ("missing" in matcher && matcher.missing !== void 0 && !Array.isArray(matcher.missing)) return false;
99
+ return true;
172
100
  }
173
101
  function matchMatcherPattern(pathname, pattern, i18nConfig) {
174
- if (!i18nConfig)
175
- return matchPattern(pathname, pattern);
176
- const localeStrippedPathname = stripLocalePrefix(pathname, i18nConfig);
177
- return matchPattern(localeStrippedPathname ?? pathname, pattern);
102
+ if (!i18nConfig) return matchPattern(pathname, pattern);
103
+ return matchPattern(stripLocalePrefix(pathname, i18nConfig) ?? pathname, pattern);
178
104
  }
179
105
  function matchObjectMatcher(pathname, matcher, i18nConfig) {
180
- return matcher.locale === false
181
- ? matchPattern(pathname, matcher.source)
182
- : matchMatcherPattern(pathname, matcher.source, i18nConfig);
106
+ return matcher.locale === false ? matchPattern(pathname, matcher.source) : matchMatcherPattern(pathname, matcher.source, i18nConfig);
183
107
  }
184
108
  function stripLocalePrefix(pathname, i18nConfig) {
185
- if (pathname === "/")
186
- return null;
187
- const segments = pathname.split("/");
188
- const firstSegment = segments[1];
189
- if (!firstSegment || !i18nConfig.locales.includes(firstSegment)) {
190
- return null;
191
- }
192
- const stripped = "/" + segments.slice(2).join("/");
193
- return stripped === "/" ? "/" : stripped.replace(/\/+$/, "") || "/";
109
+ if (pathname === "/") return null;
110
+ const segments = pathname.split("/");
111
+ const firstSegment = segments[1];
112
+ if (!firstSegment || !i18nConfig.locales.includes(firstSegment)) return null;
113
+ const stripped = "/" + segments.slice(2).join("/");
114
+ return stripped === "/" ? "/" : stripped.replace(/\/+$/, "") || "/";
194
115
  }
195
116
  /**
196
- * Cache for compiled middleware matcher regexes.
197
- *
198
- * Middleware matcher patterns are static — they come from `config.matcher`
199
- * in the user's middleware/proxy file and never change at runtime. Without
200
- * caching, every request re-runs the full tokeniser + isSafeRegex scan +
201
- * new RegExp() for every matcher pattern. This is the same problem that
202
- * config-matchers.ts solved with `_compiledPatternCache` (which eliminated
203
- * ~2.4s of CPU self-time in profiling).
204
- *
205
- * Value is `null` when safeRegExp rejected the pattern (ReDoS risk), so we
206
- * skip it on subsequent requests without re-running the scanner.
207
- */
208
- const _mwPatternCache = new Map();
117
+ * Cache for compiled middleware matcher regexes.
118
+ *
119
+ * Middleware matcher patterns are static — they come from `config.matcher`
120
+ * in the user's middleware/proxy file and never change at runtime. Without
121
+ * caching, every request re-runs the full tokeniser + isSafeRegex scan +
122
+ * new RegExp() for every matcher pattern. This is the same problem that
123
+ * config-matchers.ts solved with `_compiledPatternCache` (which eliminated
124
+ * ~2.4s of CPU self-time in profiling).
125
+ *
126
+ * Value is `null` when safeRegExp rejected the pattern (ReDoS risk), so we
127
+ * skip it on subsequent requests without re-running the scanner.
128
+ */
129
+ const _mwPatternCache = /* @__PURE__ */ new Map();
209
130
  /**
210
- * Match a single pattern against a pathname.
211
- * Supports Next.js matcher patterns:
212
- * /about -> exact match
213
- * /dashboard/:path* -> prefix match with params
214
- * /api/:path+ -> one or more segments
215
- * /((?!api|_next).*) -> regex patterns
216
- */
217
- export function matchPattern(pathname, pattern) {
218
- let cached = _mwPatternCache.get(pattern);
219
- if (cached === undefined) {
220
- cached = compileMatcherPattern(pattern);
221
- _mwPatternCache.set(pattern, cached);
222
- }
223
- if (cached === null)
224
- return pathname === pattern;
225
- return cached.test(pathname);
131
+ * Match a single pattern against a pathname.
132
+ * Supports Next.js matcher patterns:
133
+ * /about -> exact match
134
+ * /dashboard/:path* -> prefix match with params
135
+ * /api/:path+ -> one or more segments
136
+ * /((?!api|_next).*) -> regex patterns
137
+ */
138
+ function matchPattern(pathname, pattern) {
139
+ let cached = _mwPatternCache.get(pattern);
140
+ if (cached === void 0) {
141
+ cached = compileMatcherPattern(pattern);
142
+ _mwPatternCache.set(pattern, cached);
143
+ }
144
+ if (cached === null) return pathname === pattern;
145
+ return cached.test(pathname);
226
146
  }
227
147
  /**
228
- * Extract a parenthesized constraint from `str` starting at `re.lastIndex`.
229
- * Returns the constraint string (without parens) and advances `re.lastIndex`
230
- * past the closing `)`, or returns null if the next char is not `(`.
231
- */
148
+ * Extract a parenthesized constraint from `str` starting at `re.lastIndex`.
149
+ * Returns the constraint string (without parens) and advances `re.lastIndex`
150
+ * past the closing `)`, or returns null if the next char is not `(`.
151
+ */
232
152
  function extractConstraint(str, re) {
233
- if (str[re.lastIndex] !== "(")
234
- return null;
235
- const start = re.lastIndex + 1;
236
- let depth = 1;
237
- let i = start;
238
- while (i < str.length && depth > 0) {
239
- if (str[i] === "(")
240
- depth++;
241
- else if (str[i] === ")")
242
- depth--;
243
- i++;
244
- }
245
- if (depth !== 0)
246
- return null;
247
- re.lastIndex = i;
248
- return str.slice(start, i - 1);
153
+ if (str[re.lastIndex] !== "(") return null;
154
+ const start = re.lastIndex + 1;
155
+ let depth = 1;
156
+ let i = start;
157
+ while (i < str.length && depth > 0) {
158
+ if (str[i] === "(") depth++;
159
+ else if (str[i] === ")") depth--;
160
+ i++;
161
+ }
162
+ if (depth !== 0) return null;
163
+ re.lastIndex = i;
164
+ return str.slice(start, i - 1);
249
165
  }
250
166
  /**
251
- * Compile a matcher pattern into a RegExp (or null if rejected by safeRegExp).
252
- */
167
+ * Compile a matcher pattern into a RegExp (or null if rejected by safeRegExp).
168
+ */
253
169
  function compileMatcherPattern(pattern) {
254
- // Check if pattern uses :param(constraint) syntax (e.g. :id(\d+), :locale(en|es|fr))
255
- // Also matches :param*(constraint) and :param+(constraint) for catch-all variants.
256
- const hasConstraints = /:[\w-]+[*+]?\(/.test(pattern);
257
- // Pure regex patterns: contain parens or escapes that aren't param constraints.
258
- // E.g. /((?!api|_next|favicon\.ico).*)
259
- if (!hasConstraints && (pattern.includes("(") || pattern.includes("\\"))) {
260
- return safeRegExp("^" + pattern + "$");
261
- }
262
- // Convert Next.js path patterns to regex in a single pass.
263
- // Matches /:param*, /:param+, :param, dots, and literal text.
264
- // Param names may contain hyphens (e.g. [[...sign-in]]).
265
- let regexStr = "";
266
- const tokenRe = /\/:([\w-]+)\*|\/:([\w-]+)\+|:([\w-]+)|[.]|[^/:.]+|./g;
267
- let tok;
268
- while ((tok = tokenRe.exec(pattern)) !== null) {
269
- if (tok[1] !== undefined) {
270
- // /:param* optionally match slash + zero or more segments
271
- const constraint = hasConstraints ? extractConstraint(pattern, tokenRe) : null;
272
- regexStr += constraint !== null ? `(?:/(${constraint}))?` : "(?:/.*)?";
273
- }
274
- else if (tok[2] !== undefined) {
275
- // /:param+ match slash + one or more segments
276
- const constraint = hasConstraints ? extractConstraint(pattern, tokenRe) : null;
277
- regexStr += constraint !== null ? `(?:/(${constraint}))` : "(?:/.+)";
278
- }
279
- else if (tok[3] !== undefined) {
280
- // :param — check for inline constraint (e.g. :id(\d+)) and optional ? marker
281
- const constraint = hasConstraints ? extractConstraint(pattern, tokenRe) : null;
282
- const isOptional = pattern[tokenRe.lastIndex] === "?";
283
- if (isOptional)
284
- tokenRe.lastIndex += 1;
285
- const group = constraint !== null ? `(${constraint})` : "([^/]+)";
286
- if (isOptional && regexStr.endsWith("/")) {
287
- // Make the preceding / and the param group optional together:
288
- // /:locale(en|es|fr)?/about → (?:/(en|es|fr))?/about
289
- regexStr = regexStr.slice(0, -1) + `(?:/${group})?`;
290
- }
291
- else if (isOptional) {
292
- regexStr += `${group}?`;
293
- }
294
- else {
295
- regexStr += group;
296
- }
297
- }
298
- else if (tok[0] === ".") {
299
- regexStr += "\\.";
300
- }
301
- else {
302
- regexStr += tok[0];
303
- }
304
- }
305
- return safeRegExp("^" + regexStr + "$");
170
+ const hasConstraints = /:[\w-]+[*+]?\(/.test(pattern);
171
+ if (!hasConstraints && (pattern.includes("(") || pattern.includes("\\"))) return safeRegExp("^" + pattern + "$");
172
+ let regexStr = "";
173
+ const tokenRe = /\/:([\w-]+)\*|\/:([\w-]+)\+|:([\w-]+)|[.]|[^/:.]+|./g;
174
+ let tok;
175
+ while ((tok = tokenRe.exec(pattern)) !== null) if (tok[1] !== void 0) {
176
+ const constraint = hasConstraints ? extractConstraint(pattern, tokenRe) : null;
177
+ regexStr += constraint !== null ? `(?:/(${constraint}))?` : "(?:/.*)?";
178
+ } else if (tok[2] !== void 0) {
179
+ const constraint = hasConstraints ? extractConstraint(pattern, tokenRe) : null;
180
+ regexStr += constraint !== null ? `(?:/(${constraint}))` : "(?:/.+)";
181
+ } else if (tok[3] !== void 0) {
182
+ const constraint = hasConstraints ? extractConstraint(pattern, tokenRe) : null;
183
+ const isOptional = pattern[tokenRe.lastIndex] === "?";
184
+ if (isOptional) tokenRe.lastIndex += 1;
185
+ const group = constraint !== null ? `(${constraint})` : "([^/]+)";
186
+ if (isOptional && regexStr.endsWith("/")) regexStr = regexStr.slice(0, -1) + `(?:/${group})?`;
187
+ else if (isOptional) regexStr += `${group}?`;
188
+ else regexStr += group;
189
+ } else if (tok[0] === ".") regexStr += "\\.";
190
+ else regexStr += tok[0];
191
+ return safeRegExp("^" + regexStr + "$");
306
192
  }
307
193
  /**
308
- * Load and execute middleware for a given request.
309
- *
310
- * @param runner - A ModuleRunner used to load the middleware module.
311
- * Must be a long-lived instance created once (e.g. in configureServer) via
312
- * createDirectRunner() — NOT recreated per request. Using server.ssrLoadModule
313
- * directly crashes with `outsideEmitter` when @cloudflare/vite-plugin is
314
- * present because SSRCompatModuleRunner reads environment.hot.api synchronously.
315
- * @param middlewarePath - Absolute path to the middleware file
316
- * @param request - The incoming Request object
317
- * @returns Middleware result describing what action to take
318
- */
319
- export async function runMiddleware(runner, middlewarePath, request, i18nConfig) {
320
- // Load the middleware module via the direct-call ModuleRunner.
321
- // This bypasses the hot channel entirely and is safe with all Vite plugin
322
- // combinations, including @cloudflare/vite-plugin.
323
- const mod = (await runner.import(middlewarePath));
324
- // Resolve the handler based on file type (proxy.ts vs middleware.ts).
325
- // Throws if the file doesn't export a valid function, matching Next.js behavior.
326
- // https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts
327
- const middlewareFn = resolveMiddlewareHandler(mod, middlewarePath);
328
- // Check matcher config
329
- const config = mod.config;
330
- const matcher = config?.matcher;
331
- const url = new URL(request.url);
332
- // Normalize the pathname before middleware matching to prevent bypasses
333
- // via percent-encoding (/%61dmin → /admin) or double slashes (/dashboard//settings).
334
- let decodedPathname;
335
- try {
336
- decodedPathname = normalizePathnameForRouteMatchStrict(url.pathname);
337
- }
338
- catch {
339
- // Malformed percent-encoding (e.g. /%E0%A4%A) — return 400 instead of throwing.
340
- return { continue: false, response: new Response("Bad Request", { status: 400 }) };
341
- }
342
- const normalizedPathname = normalizePath(decodedPathname);
343
- if (!matchesMiddleware(normalizedPathname, matcher, request, i18nConfig)) {
344
- return { continue: true };
345
- }
346
- // Construct a new Request with the fully decoded + normalized pathname so
347
- // middleware always sees the same canonical path that the router uses.
348
- let mwRequest = request;
349
- if (normalizedPathname !== url.pathname) {
350
- const mwUrl = new URL(url);
351
- mwUrl.pathname = normalizedPathname;
352
- mwRequest = new Request(mwUrl, request);
353
- }
354
- // Wrap in NextRequest so middleware gets .nextUrl, .cookies, .geo, .ip, etc.
355
- const nextRequest = mwRequest instanceof NextRequest ? mwRequest : new NextRequest(mwRequest);
356
- const fetchEvent = new NextFetchEvent({ page: normalizedPathname });
357
- // Execute the middleware
358
- let response;
359
- try {
360
- response = await middlewareFn(nextRequest, fetchEvent);
361
- }
362
- catch (e) {
363
- console.error("[vinext] Middleware error:", e);
364
- const message = process.env.NODE_ENV === "production"
365
- ? "Internal Server Error"
366
- : "Middleware Error: " + (e?.message ?? String(e));
367
- return {
368
- continue: false,
369
- response: new Response(message, {
370
- status: 500,
371
- }),
372
- };
373
- }
374
- // Drain waitUntil promises (fire-and-forget: we don't block the response
375
- // on these — matches platform semantics where waitUntil runs after response).
376
- fetchEvent.drainWaitUntil();
377
- // No response = continue
378
- if (!response) {
379
- return { continue: true };
380
- }
381
- // Check for x-middleware-next header (NextResponse.next())
382
- if (response.headers.get("x-middleware-next") === "1") {
383
- // Keep request-override headers so downstream route handling can rebuild
384
- // the middleware-mutated request before internal headers are stripped.
385
- const responseHeaders = new Headers();
386
- for (const [key, value] of response.headers) {
387
- if (!key.startsWith("x-middleware-") || shouldKeepMiddlewareHeader(key)) {
388
- responseHeaders.append(key, value);
389
- }
390
- }
391
- return { continue: true, responseHeaders };
392
- }
393
- // Check for redirect (3xx status)
394
- if (response.status >= 300 && response.status < 400) {
395
- const location = response.headers.get("Location") ?? response.headers.get("location");
396
- if (location) {
397
- // Collect non-internal headers (e.g. Set-Cookie) to forward with the redirect.
398
- const responseHeaders = new Headers();
399
- for (const [key, value] of response.headers) {
400
- if (!key.startsWith("x-middleware-") && key.toLowerCase() !== "location") {
401
- responseHeaders.append(key, value);
402
- }
403
- }
404
- return {
405
- continue: false,
406
- redirectUrl: location,
407
- redirectStatus: response.status,
408
- responseHeaders,
409
- };
410
- }
411
- }
412
- // Check for rewrite (x-middleware-rewrite header)
413
- const rewriteUrl = response.headers.get("x-middleware-rewrite");
414
- if (rewriteUrl) {
415
- // Continue to the route but with a rewritten URL.
416
- const responseHeaders = new Headers();
417
- for (const [key, value] of response.headers) {
418
- if (!key.startsWith("x-middleware-") || shouldKeepMiddlewareHeader(key)) {
419
- responseHeaders.append(key, value);
420
- }
421
- }
422
- // Parse the rewrite URL — may be absolute or relative
423
- let rewritePath;
424
- try {
425
- const rewriteParsed = new URL(rewriteUrl, request.url);
426
- rewritePath = rewriteParsed.pathname + rewriteParsed.search;
427
- }
428
- catch {
429
- rewritePath = rewriteUrl;
430
- }
431
- return {
432
- continue: true,
433
- rewriteUrl: rewritePath,
434
- rewriteStatus: response.status !== 200 ? response.status : undefined,
435
- responseHeaders,
436
- };
437
- }
438
- // Middleware returned a full Response (e.g., blocking, custom body)
439
- return { continue: false, response };
194
+ * Load and execute middleware for a given request.
195
+ *
196
+ * @param runner - A ModuleRunner used to load the middleware module.
197
+ * Must be a long-lived instance created once (e.g. in configureServer) via
198
+ * createDirectRunner() — NOT recreated per request. Using server.ssrLoadModule
199
+ * directly crashes with `outsideEmitter` when @cloudflare/vite-plugin is
200
+ * present because SSRCompatModuleRunner reads environment.hot.api synchronously.
201
+ * @param middlewarePath - Absolute path to the middleware file
202
+ * @param request - The incoming Request object
203
+ * @returns Middleware result describing what action to take
204
+ */
205
+ async function runMiddleware(runner, middlewarePath, request, i18nConfig, basePath) {
206
+ const mod = await runner.import(middlewarePath);
207
+ const middlewareFn = resolveMiddlewareHandler(mod, middlewarePath);
208
+ const matcher = mod.config?.matcher;
209
+ const url = new URL(request.url);
210
+ let decodedPathname;
211
+ try {
212
+ decodedPathname = normalizePathnameForRouteMatchStrict(url.pathname);
213
+ } catch {
214
+ return {
215
+ continue: false,
216
+ response: new Response("Bad Request", { status: 400 })
217
+ };
218
+ }
219
+ const normalizedPathname = normalizePath(decodedPathname);
220
+ if (!matchesMiddleware(normalizedPathname, matcher, request, i18nConfig)) return { continue: true };
221
+ let mwRequest = request;
222
+ if (normalizedPathname !== url.pathname) {
223
+ const mwUrl = new URL(url);
224
+ mwUrl.pathname = normalizedPathname;
225
+ mwRequest = new Request(mwUrl, request);
226
+ }
227
+ const nextConfig = basePath || i18nConfig ? {
228
+ basePath: basePath ?? "",
229
+ i18n: i18nConfig ?? void 0
230
+ } : void 0;
231
+ const nextRequest = mwRequest instanceof NextRequest ? mwRequest : new NextRequest(mwRequest, nextConfig ? { nextConfig } : void 0);
232
+ const fetchEvent = new NextFetchEvent({ page: normalizedPathname });
233
+ let response;
234
+ try {
235
+ response = await middlewareFn(nextRequest, fetchEvent);
236
+ } catch (e) {
237
+ console.error("[vinext] Middleware error:", e);
238
+ const message = process.env.NODE_ENV === "production" ? "Internal Server Error" : "Middleware Error: " + (e?.message ?? String(e));
239
+ return {
240
+ continue: false,
241
+ response: new Response(message, { status: 500 })
242
+ };
243
+ }
244
+ fetchEvent.drainWaitUntil();
245
+ if (!response) return { continue: true };
246
+ if (response.headers.get("x-middleware-next") === "1") {
247
+ const responseHeaders = new Headers();
248
+ for (const [key, value] of response.headers) if (!key.startsWith("x-middleware-") || shouldKeepMiddlewareHeader(key)) responseHeaders.append(key, value);
249
+ return {
250
+ continue: true,
251
+ responseHeaders
252
+ };
253
+ }
254
+ if (response.status >= 300 && response.status < 400) {
255
+ const location = response.headers.get("Location") ?? response.headers.get("location");
256
+ if (location) {
257
+ const responseHeaders = new Headers();
258
+ for (const [key, value] of response.headers) if (!key.startsWith("x-middleware-") && key.toLowerCase() !== "location") responseHeaders.append(key, value);
259
+ return {
260
+ continue: false,
261
+ redirectUrl: location,
262
+ redirectStatus: response.status,
263
+ responseHeaders
264
+ };
265
+ }
266
+ }
267
+ const rewriteUrl = response.headers.get("x-middleware-rewrite");
268
+ if (rewriteUrl) {
269
+ const responseHeaders = new Headers();
270
+ for (const [key, value] of response.headers) if (!key.startsWith("x-middleware-") || shouldKeepMiddlewareHeader(key)) responseHeaders.append(key, value);
271
+ let rewritePath;
272
+ try {
273
+ const rewriteParsed = new URL(rewriteUrl, request.url);
274
+ rewritePath = rewriteParsed.pathname + rewriteParsed.search;
275
+ } catch {
276
+ rewritePath = rewriteUrl;
277
+ }
278
+ return {
279
+ continue: true,
280
+ rewriteUrl: rewritePath,
281
+ rewriteStatus: response.status !== 200 ? response.status : void 0,
282
+ responseHeaders
283
+ };
284
+ }
285
+ return {
286
+ continue: false,
287
+ response
288
+ };
440
289
  }
290
+ //#endregion
291
+ export { findMiddlewareFile, isProxyFile, matchPattern, matchesMiddleware, resolveMiddlewareHandler, runMiddleware };
292
+
441
293
  //# sourceMappingURL=middleware.js.map