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
@@ -0,0 +1,675 @@
1
+ import { createValidFileMatcher } from "../routing/file-matcher.js";
2
+ import { headersContextFromRequest, runWithHeadersContext } from "../shims/headers.js";
3
+ import { NoOpCacheHandler, getCacheHandler, setCacheHandler } from "../shims/cache.js";
4
+ import { classifyAppRoute, classifyPagesRoute } from "./report.js";
5
+ import { readPrerenderSecret } from "./server-manifest.js";
6
+ import { startProdServer } from "../server/prod-server.js";
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import os from "node:os";
10
+ //#region src/build/prerender.ts
11
+ /**
12
+ * Prerendering phase for vinext build.
13
+ *
14
+ * Classifies every route, renders static and ISR routes to HTML/JSON/RSC files,
15
+ * and writes a `vinext-prerender.json` build index.
16
+ *
17
+ * Two public functions:
18
+ * prerenderPages() — Pages Router
19
+ * prerenderApp() — App Router
20
+ *
21
+ * Both return a `PrerenderResult` with one entry per route. The caller
22
+ * (cli.ts) can merge these into the build report.
23
+ *
24
+ * Modes:
25
+ * 'default' — skips SSR routes (served at request time); ISR routes rendered
26
+ * 'export' — SSR routes are build errors; ISR treated as static (no revalidate)
27
+ */
28
+ /** Sentinel path used to trigger 404 rendering without a real route match. */
29
+ const NOT_FOUND_SENTINEL_PATH = "/__vinext_nonexistent_for_404__";
30
+ const DEFAULT_CONCURRENCY = Math.min(os.availableParallelism(), 8);
31
+ /**
32
+ * Run an array of async tasks with bounded concurrency.
33
+ * Results are returned in the same order as `items`.
34
+ */
35
+ async function runWithConcurrency(items, concurrency, fn) {
36
+ const results = Array.from({ length: items.length });
37
+ let nextIndex = 0;
38
+ async function worker() {
39
+ while (nextIndex < items.length) {
40
+ const i = nextIndex++;
41
+ results[i] = await fn(items[i], i);
42
+ }
43
+ }
44
+ if (items.length === 0) return results;
45
+ const workers = Array.from({ length: Math.min(concurrency, items.length) }, worker);
46
+ await Promise.all(workers);
47
+ return results;
48
+ }
49
+ function findFileWithExtensions(basePath, matcher) {
50
+ return matcher.dottedExtensions.some((ext) => fs.existsSync(basePath + ext));
51
+ }
52
+ /**
53
+ * Build a URL path from a route pattern and params.
54
+ * "/posts/:id" + { id: "42" } → "/posts/42"
55
+ * "/docs/:slug+" + { slug: ["a", "b"] } → "/docs/a/b"
56
+ */
57
+ function buildUrlFromParams(pattern, params) {
58
+ const parts = pattern.split("/").filter(Boolean);
59
+ const result = [];
60
+ for (const part of parts) if (part.endsWith("+") || part.endsWith("*")) {
61
+ const value = params[part.slice(1, -1)];
62
+ if (Array.isArray(value)) result.push(...value.map((s) => encodeURIComponent(s)));
63
+ else if (value) result.push(encodeURIComponent(String(value)));
64
+ } else if (part.startsWith(":")) {
65
+ const paramName = part.slice(1);
66
+ const value = params[paramName];
67
+ if (value === void 0 || value === null) throw new Error(`[vinext] buildUrlFromParams: required param "${paramName}" is missing for pattern "${pattern}". Check that generateStaticParams (or getStaticPaths) returns an object with a "${paramName}" key.`);
68
+ result.push(encodeURIComponent(String(value)));
69
+ } else result.push(part);
70
+ return "/" + result.join("/");
71
+ }
72
+ /**
73
+ * Determine the HTML output file path for a URL.
74
+ * Respects trailingSlash config.
75
+ */
76
+ function getOutputPath(urlPath, trailingSlash) {
77
+ if (urlPath === "/") return "index.html";
78
+ const clean = urlPath.replace(/^\//, "");
79
+ if (trailingSlash) return `${clean}/index.html`;
80
+ return `${clean}.html`;
81
+ }
82
+ /**
83
+ * Resolve parent dynamic segment params for a route.
84
+ * Handles top-down generateStaticParams resolution for nested dynamic routes.
85
+ *
86
+ * Uses the `staticParamsMap` (pattern → generateStaticParams) exported from
87
+ * the production bundle.
88
+ */
89
+ async function resolveParentParams(childRoute, allRoutes, staticParamsMap) {
90
+ const patternParts = childRoute.pattern.split("/").filter(Boolean);
91
+ const parentSegments = [];
92
+ for (let i = 0; i < patternParts.length; i++) {
93
+ const part = patternParts[i];
94
+ if (!part.startsWith(":")) continue;
95
+ if (!patternParts.slice(i + 1).some((p) => p.startsWith(":"))) break;
96
+ const prefixPattern = "/" + patternParts.slice(0, i + 1).join("/");
97
+ if (allRoutes.find((r) => r.pattern === prefixPattern)?.pagePath) {
98
+ const fn = staticParamsMap[prefixPattern];
99
+ if (typeof fn === "function") {
100
+ const paramName = part.replace(/^:/, "").replace(/[+*]$/, "");
101
+ parentSegments.push({
102
+ params: [paramName],
103
+ generateStaticParams: fn
104
+ });
105
+ }
106
+ }
107
+ }
108
+ if (parentSegments.length === 0) return [];
109
+ let currentParams = [{}];
110
+ for (const segment of parentSegments) {
111
+ const nextParams = [];
112
+ for (const parentParams of currentParams) {
113
+ const results = await segment.generateStaticParams({ params: parentParams });
114
+ if (Array.isArray(results)) for (const result of results) nextParams.push({
115
+ ...parentParams,
116
+ ...result
117
+ });
118
+ }
119
+ currentParams = nextParams;
120
+ }
121
+ return currentParams;
122
+ }
123
+ /**
124
+ * Run the prerender phase for Pages Router.
125
+ *
126
+ * Rendering is done via HTTP through a locally-spawned production server.
127
+ * Works for both plain Node and Cloudflare Workers builds.
128
+ * Route classification uses static file analysis (classifyPagesRoute);
129
+ * getStaticPaths is fetched via a dedicated
130
+ * `/__vinext/prerender/pages-static-paths?pattern=…` endpoint on the server.
131
+ *
132
+ * Returns structured results for every route (rendered, skipped, or error).
133
+ * Writes HTML files to `outDir`. If `manifestDir` is set, writes
134
+ * `vinext-prerender.json` there; otherwise writes it to `outDir`.
135
+ */
136
+ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mode, ...options }) {
137
+ const pagesBundlePath = options.pagesBundlePath;
138
+ const manifestDir = options.manifestDir ?? outDir;
139
+ const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
140
+ const onProgress = options.onProgress;
141
+ const skipManifest = options.skipManifest ?? false;
142
+ const fileMatcher = createValidFileMatcher(config.pageExtensions);
143
+ const results = [];
144
+ if (!pagesBundlePath && !options._prodServer) throw new Error("[vinext] prerenderPages: either pagesBundlePath or _prodServer must be provided.");
145
+ fs.mkdirSync(outDir, { recursive: true });
146
+ for (const apiRoute of apiRoutes) results.push({
147
+ route: apiRoute.pattern,
148
+ status: "skipped",
149
+ reason: "api"
150
+ });
151
+ const previousHandler = getCacheHandler();
152
+ setCacheHandler(new NoOpCacheHandler());
153
+ process.env.VINEXT_PRERENDER = "1";
154
+ let ownedProdServerHandle = null;
155
+ try {
156
+ let prerenderSecret = options._prerenderSecret;
157
+ if (!prerenderSecret && pagesBundlePath) prerenderSecret = readPrerenderSecret(path.dirname(pagesBundlePath));
158
+ if (!prerenderSecret) console.warn("[vinext] Warning: prerender secret not found. /__vinext/prerender/* endpoints will return 403 and dynamic routes will produce no paths. Run `vinext build` to regenerate the secret.");
159
+ const baseUrl = `http://127.0.0.1:${(options._prodServer ? options._prodServer : await (async () => {
160
+ const srv = await startProdServer({
161
+ port: 0,
162
+ host: "127.0.0.1",
163
+ outDir: path.dirname(path.dirname(pagesBundlePath)),
164
+ noCompression: true
165
+ });
166
+ ownedProdServerHandle = srv;
167
+ return srv;
168
+ })()).port}`;
169
+ const secretHeaders = prerenderSecret ? { "x-vinext-prerender-secret": prerenderSecret } : {};
170
+ const renderPage = (urlPath) => fetch(`${baseUrl}${urlPath}`, {
171
+ headers: secretHeaders,
172
+ redirect: "manual"
173
+ });
174
+ const bundlePageRoutes = routes.map((r) => ({
175
+ pattern: r.pattern,
176
+ isDynamic: r.isDynamic ?? false,
177
+ params: {},
178
+ filePath: r.filePath,
179
+ module: { getStaticPaths: r.isDynamic ? async ({ locales, defaultLocale }) => {
180
+ const search = new URLSearchParams({ pattern: r.pattern });
181
+ if (locales.length > 0) search.set("locales", JSON.stringify(locales));
182
+ if (defaultLocale) search.set("defaultLocale", defaultLocale);
183
+ const res = await fetch(`${baseUrl}/__vinext/prerender/pages-static-paths?${search}`, { headers: secretHeaders });
184
+ const text = await res.text();
185
+ if (!res.ok) {
186
+ console.warn(`[vinext] Warning: /__vinext/prerender/pages-static-paths returned ${res.status} for ${r.pattern}. Dynamic paths will be skipped. This may indicate a stale or missing prerender secret.`);
187
+ return {
188
+ paths: [],
189
+ fallback: false
190
+ };
191
+ }
192
+ if (text === "null") return {
193
+ paths: [],
194
+ fallback: false
195
+ };
196
+ return JSON.parse(text);
197
+ } : void 0 }
198
+ }));
199
+ const pagesToRender = [];
200
+ for (const route of bundlePageRoutes) {
201
+ if (path.basename(route.filePath, path.extname(route.filePath)).startsWith("_")) continue;
202
+ if (!routes.find((r) => r.filePath === route.filePath || r.pattern === route.pattern)) continue;
203
+ const { type, revalidate: classifiedRevalidate } = classifyPagesRoute(route.filePath);
204
+ if (type === "ssr") {
205
+ if (mode === "export") results.push({
206
+ route: route.pattern,
207
+ status: "error",
208
+ error: `Page uses getServerSideProps which is not supported with output: 'export'. Use getStaticProps instead.`
209
+ });
210
+ else results.push({
211
+ route: route.pattern,
212
+ status: "skipped",
213
+ reason: "ssr"
214
+ });
215
+ continue;
216
+ }
217
+ const revalidate = mode === "export" ? false : typeof classifiedRevalidate === "number" ? classifiedRevalidate : false;
218
+ if (route.isDynamic) {
219
+ if (typeof route.module.getStaticPaths !== "function") {
220
+ if (mode === "export") results.push({
221
+ route: route.pattern,
222
+ status: "error",
223
+ error: `Dynamic route requires getStaticPaths with output: 'export'`
224
+ });
225
+ else results.push({
226
+ route: route.pattern,
227
+ status: "skipped",
228
+ reason: "no-static-params"
229
+ });
230
+ continue;
231
+ }
232
+ const pathsResult = await route.module.getStaticPaths({
233
+ locales: [],
234
+ defaultLocale: ""
235
+ });
236
+ const fallback = pathsResult?.fallback ?? false;
237
+ if (mode === "export" && fallback !== false) {
238
+ results.push({
239
+ route: route.pattern,
240
+ status: "error",
241
+ error: `getStaticPaths must return fallback: false with output: 'export' (got: ${JSON.stringify(fallback)})`
242
+ });
243
+ continue;
244
+ }
245
+ const paths = pathsResult?.paths ?? [];
246
+ for (const { params } of paths) {
247
+ const urlPath = buildUrlFromParams(route.pattern, params);
248
+ pagesToRender.push({
249
+ route,
250
+ urlPath,
251
+ params,
252
+ revalidate
253
+ });
254
+ }
255
+ } else pagesToRender.push({
256
+ route,
257
+ urlPath: route.pattern,
258
+ params: {},
259
+ revalidate
260
+ });
261
+ }
262
+ let completed = 0;
263
+ const pageResults = await runWithConcurrency(pagesToRender, concurrency, async ({ route, urlPath, revalidate }) => {
264
+ let result;
265
+ try {
266
+ const response = await renderPage(urlPath);
267
+ const outputFiles = [];
268
+ const htmlOutputPath = getOutputPath(urlPath, config.trailingSlash);
269
+ const htmlFullPath = path.join(outDir, htmlOutputPath);
270
+ if (response.status >= 300 && response.status < 400) {
271
+ const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=${(response.headers.get("location") ?? "/").replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}" /></head><body></body></html>`;
272
+ fs.mkdirSync(path.dirname(htmlFullPath), { recursive: true });
273
+ fs.writeFileSync(htmlFullPath, html, "utf-8");
274
+ outputFiles.push(htmlOutputPath);
275
+ } else {
276
+ if (!response.ok) throw new Error(`renderPage returned ${response.status} for ${urlPath}`);
277
+ const html = await response.text();
278
+ fs.mkdirSync(path.dirname(htmlFullPath), { recursive: true });
279
+ fs.writeFileSync(htmlFullPath, html, "utf-8");
280
+ outputFiles.push(htmlOutputPath);
281
+ }
282
+ result = {
283
+ route: route.pattern,
284
+ status: "rendered",
285
+ outputFiles,
286
+ revalidate,
287
+ ...urlPath !== route.pattern ? { path: urlPath } : {}
288
+ };
289
+ } catch (e) {
290
+ result = {
291
+ route: route.pattern,
292
+ status: "error",
293
+ error: e.message
294
+ };
295
+ }
296
+ onProgress?.({
297
+ completed: ++completed,
298
+ total: pagesToRender.length,
299
+ route: urlPath,
300
+ status: result.status
301
+ });
302
+ return result;
303
+ });
304
+ results.push(...pageResults);
305
+ if (findFileWithExtensions(path.join(pagesDir, "404"), fileMatcher) || findFileWithExtensions(path.join(pagesDir, "_error"), fileMatcher)) try {
306
+ const notFoundRes = await renderPage(NOT_FOUND_SENTINEL_PATH);
307
+ if ((notFoundRes.headers.get("content-type") ?? "").includes("text/html")) {
308
+ const html404 = await notFoundRes.text();
309
+ const fullPath = path.join(outDir, "404.html");
310
+ fs.writeFileSync(fullPath, html404, "utf-8");
311
+ results.push({
312
+ route: "/404",
313
+ status: "rendered",
314
+ outputFiles: ["404.html"],
315
+ revalidate: false
316
+ });
317
+ }
318
+ } catch {}
319
+ if (!skipManifest) writePrerenderIndex(results, manifestDir);
320
+ return { routes: results };
321
+ } finally {
322
+ setCacheHandler(previousHandler);
323
+ delete process.env.VINEXT_PRERENDER;
324
+ if (ownedProdServerHandle) await new Promise((resolve) => ownedProdServerHandle.server.close(() => resolve()));
325
+ }
326
+ }
327
+ /**
328
+ * Run the prerender phase for App Router.
329
+ *
330
+ * Starts a local production server and fetches every static/ISR route via HTTP.
331
+ * Works for both plain Node and Cloudflare Workers builds — the CF Workers bundle
332
+ * (`dist/server/index.js`) is a standard Node-compatible server entry, so no
333
+ * wrangler/miniflare is needed. Writes HTML files, `.rsc` files, and
334
+ * `vinext-prerender.json` to `outDir`.
335
+ *
336
+ * If the bundle does not exist, an error is thrown directing the user to run
337
+ * `vinext build` first.
338
+ *
339
+ * Speculative static rendering: routes classified as 'unknown' (no explicit
340
+ * config, non-dynamic URL) are attempted with an empty headers/cookies context.
341
+ * If they succeed, they are marked as rendered. If they throw a DynamicUsageError
342
+ * or fail, they are marked as skipped with reason 'dynamic'.
343
+ */
344
+ async function prerenderApp({ routes, outDir, config, mode, rscBundlePath, ...options }) {
345
+ const manifestDir = options.manifestDir ?? outDir;
346
+ const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
347
+ const onProgress = options.onProgress;
348
+ const skipManifest = options.skipManifest ?? false;
349
+ const results = [];
350
+ fs.mkdirSync(outDir, { recursive: true });
351
+ const previousHandler = getCacheHandler();
352
+ setCacheHandler(new NoOpCacheHandler());
353
+ process.env.VINEXT_PRERENDER = "1";
354
+ const serverDir = path.dirname(rscBundlePath);
355
+ let rscHandler;
356
+ let staticParamsMap = {};
357
+ let ownedProdServerHandle = null;
358
+ try {
359
+ const prerenderSecret = readPrerenderSecret(serverDir);
360
+ if (!prerenderSecret) console.warn("[vinext] Warning: prerender secret not found. /__vinext/prerender/* endpoints will return 403 and generateStaticParams will not be called. Run `vinext build` to regenerate the secret.");
361
+ const baseUrl = `http://127.0.0.1:${(options._prodServer ? options._prodServer : await (async () => {
362
+ const srv = await startProdServer({
363
+ port: 0,
364
+ host: "127.0.0.1",
365
+ outDir: path.dirname(serverDir),
366
+ noCompression: true
367
+ });
368
+ ownedProdServerHandle = srv;
369
+ return srv;
370
+ })()).port}`;
371
+ const secretHeaders = prerenderSecret ? { "x-vinext-prerender-secret": prerenderSecret } : {};
372
+ rscHandler = (req) => {
373
+ const parsed = new URL(req.url);
374
+ const url = `${baseUrl}${parsed.pathname}${parsed.search}`;
375
+ return fetch(url, {
376
+ method: req.method,
377
+ headers: {
378
+ ...secretHeaders,
379
+ ...Object.fromEntries(req.headers.entries())
380
+ },
381
+ body: req.method !== "GET" && req.method !== "HEAD" ? req.body : void 0
382
+ });
383
+ };
384
+ const staticParamsCache = /* @__PURE__ */ new Map();
385
+ staticParamsMap = new Proxy({}, {
386
+ get(_target, pattern) {
387
+ return async ({ params }) => {
388
+ const cacheKey = `${pattern}\0${JSON.stringify(params)}`;
389
+ const cached = staticParamsCache.get(cacheKey);
390
+ if (cached !== void 0) return cached;
391
+ const request = (async () => {
392
+ const search = new URLSearchParams({ pattern });
393
+ if (Object.keys(params).length > 0) search.set("parentParams", JSON.stringify(params));
394
+ const res = await fetch(`${baseUrl}/__vinext/prerender/static-params?${search}`, { headers: secretHeaders });
395
+ const text = await res.text();
396
+ if (!res.ok) {
397
+ console.warn(`[vinext] Warning: /__vinext/prerender/static-params returned ${res.status} for ${pattern}. Static params will be skipped. This may indicate a stale or missing prerender secret.`);
398
+ return null;
399
+ }
400
+ if (text === "null") return null;
401
+ return JSON.parse(text);
402
+ })();
403
+ request.catch(() => staticParamsCache.delete(cacheKey));
404
+ staticParamsCache.set(cacheKey, request);
405
+ return request;
406
+ };
407
+ },
408
+ has(_target, _pattern) {
409
+ return false;
410
+ }
411
+ });
412
+ const urlsToRender = [];
413
+ for (const route of routes) {
414
+ if (route.routePath && !route.pagePath) {
415
+ results.push({
416
+ route: route.pattern,
417
+ status: "skipped",
418
+ reason: "api"
419
+ });
420
+ continue;
421
+ }
422
+ if (!route.pagePath) continue;
423
+ const { type, revalidate: classifiedRevalidate } = classifyAppRoute(route.pagePath, route.routePath, route.isDynamic);
424
+ if (type === "api") {
425
+ results.push({
426
+ route: route.pattern,
427
+ status: "skipped",
428
+ reason: "api"
429
+ });
430
+ continue;
431
+ }
432
+ if (type === "ssr" && !route.isDynamic) {
433
+ if (mode === "export") results.push({
434
+ route: route.pattern,
435
+ status: "error",
436
+ error: `Route uses dynamic rendering (force-dynamic or revalidate=0) which is not supported with output: 'export'`
437
+ });
438
+ else results.push({
439
+ route: route.pattern,
440
+ status: "skipped",
441
+ reason: "dynamic"
442
+ });
443
+ continue;
444
+ }
445
+ const revalidate = mode === "export" ? false : typeof classifiedRevalidate === "number" ? classifiedRevalidate : false;
446
+ if (route.isDynamic) try {
447
+ const generateStaticParamsFn = staticParamsMap[route.pattern];
448
+ if (typeof generateStaticParamsFn !== "function") {
449
+ if (mode === "export") results.push({
450
+ route: route.pattern,
451
+ status: "error",
452
+ error: `Dynamic route requires generateStaticParams() with output: 'export'`
453
+ });
454
+ else results.push({
455
+ route: route.pattern,
456
+ status: "skipped",
457
+ reason: "no-static-params"
458
+ });
459
+ continue;
460
+ }
461
+ const parentParamSets = await resolveParentParams(route, routes, staticParamsMap);
462
+ let paramSets;
463
+ if (parentParamSets.length > 0) {
464
+ paramSets = [];
465
+ for (const parentParams of parentParamSets) {
466
+ const childResults = await generateStaticParamsFn({ params: parentParams });
467
+ if (childResults === null) {
468
+ paramSets = null;
469
+ break;
470
+ }
471
+ if (Array.isArray(childResults)) for (const childParams of childResults) paramSets.push({
472
+ ...parentParams,
473
+ ...childParams
474
+ });
475
+ }
476
+ } else paramSets = await generateStaticParamsFn({ params: {} });
477
+ if (paramSets === null) {
478
+ if (mode === "export") results.push({
479
+ route: route.pattern,
480
+ status: "error",
481
+ error: `Dynamic route requires generateStaticParams() with output: 'export'`
482
+ });
483
+ else results.push({
484
+ route: route.pattern,
485
+ status: "skipped",
486
+ reason: "no-static-params"
487
+ });
488
+ continue;
489
+ }
490
+ if (!Array.isArray(paramSets) || paramSets.length === 0) {
491
+ results.push({
492
+ route: route.pattern,
493
+ status: "skipped",
494
+ reason: "no-static-params"
495
+ });
496
+ continue;
497
+ }
498
+ for (const params of paramSets) {
499
+ const urlPath = buildUrlFromParams(route.pattern, params);
500
+ urlsToRender.push({
501
+ urlPath,
502
+ routePattern: route.pattern,
503
+ revalidate,
504
+ isSpeculative: false
505
+ });
506
+ }
507
+ } catch (e) {
508
+ results.push({
509
+ route: route.pattern,
510
+ status: "error",
511
+ error: `Failed to call generateStaticParams(): ${e.message}`
512
+ });
513
+ }
514
+ else if (type === "unknown") urlsToRender.push({
515
+ urlPath: route.pattern,
516
+ routePattern: route.pattern,
517
+ revalidate: false,
518
+ isSpeculative: true
519
+ });
520
+ else urlsToRender.push({
521
+ urlPath: route.pattern,
522
+ routePattern: route.pattern,
523
+ revalidate,
524
+ isSpeculative: false
525
+ });
526
+ }
527
+ /**
528
+ * Render a single URL and return its result.
529
+ * `onProgress` is intentionally not called here; the outer loop calls it
530
+ * exactly once per URL after this function returns, keeping the callback
531
+ * at a single, predictable call site.
532
+ */
533
+ async function renderUrl({ urlPath, routePattern, revalidate, isSpeculative }) {
534
+ try {
535
+ const htmlRequest = new Request(`http://localhost${urlPath}`);
536
+ const htmlRes = await runWithHeadersContext(headersContextFromRequest(htmlRequest), () => rscHandler(htmlRequest));
537
+ if (!htmlRes.ok) {
538
+ if (isSpeculative) return {
539
+ route: routePattern,
540
+ status: "skipped",
541
+ reason: "dynamic"
542
+ };
543
+ return {
544
+ route: routePattern,
545
+ status: "error",
546
+ error: `RSC handler returned ${htmlRes.status}`
547
+ };
548
+ }
549
+ if (isSpeculative) {
550
+ if ((htmlRes.headers.get("cache-control") ?? "").includes("no-store")) {
551
+ await htmlRes.body?.cancel();
552
+ return {
553
+ route: routePattern,
554
+ status: "skipped",
555
+ reason: "dynamic"
556
+ };
557
+ }
558
+ }
559
+ const html = await htmlRes.text();
560
+ const rscRequest = new Request(`http://localhost${urlPath}`, { headers: {
561
+ Accept: "text/x-component",
562
+ RSC: "1"
563
+ } });
564
+ const rscRes = await runWithHeadersContext(headersContextFromRequest(rscRequest), () => rscHandler(rscRequest));
565
+ const rscData = rscRes.ok ? await rscRes.text() : null;
566
+ const outputFiles = [];
567
+ const htmlOutputPath = getOutputPath(urlPath, config.trailingSlash);
568
+ const htmlFullPath = path.join(outDir, htmlOutputPath);
569
+ fs.mkdirSync(path.dirname(htmlFullPath), { recursive: true });
570
+ fs.writeFileSync(htmlFullPath, html, "utf-8");
571
+ outputFiles.push(htmlOutputPath);
572
+ if (rscData !== null) {
573
+ const rscOutputPath = getRscOutputPath(urlPath);
574
+ const rscFullPath = path.join(outDir, rscOutputPath);
575
+ fs.mkdirSync(path.dirname(rscFullPath), { recursive: true });
576
+ fs.writeFileSync(rscFullPath, rscData, "utf-8");
577
+ outputFiles.push(rscOutputPath);
578
+ }
579
+ return {
580
+ route: routePattern,
581
+ status: "rendered",
582
+ outputFiles,
583
+ revalidate,
584
+ ...urlPath !== routePattern ? { path: urlPath } : {}
585
+ };
586
+ } catch (e) {
587
+ if (isSpeculative) return {
588
+ route: routePattern,
589
+ status: "skipped",
590
+ reason: "dynamic"
591
+ };
592
+ const err = e;
593
+ return {
594
+ route: routePattern,
595
+ status: "error",
596
+ error: err.digest ? `${err.message} (digest: ${err.digest})` : err.message
597
+ };
598
+ }
599
+ }
600
+ let completedApp = 0;
601
+ const appResults = await runWithConcurrency(urlsToRender, concurrency, async (urlToRender) => {
602
+ const result = await renderUrl(urlToRender);
603
+ onProgress?.({
604
+ completed: ++completedApp,
605
+ total: urlsToRender.length,
606
+ route: urlToRender.urlPath,
607
+ status: result.status
608
+ });
609
+ return result;
610
+ });
611
+ results.push(...appResults);
612
+ try {
613
+ const notFoundRequest = new Request(`http://localhost${NOT_FOUND_SENTINEL_PATH}`);
614
+ const notFoundRes = await runWithHeadersContext(headersContextFromRequest(notFoundRequest), () => rscHandler(notFoundRequest));
615
+ if (notFoundRes.status === 404) {
616
+ const html404 = await notFoundRes.text();
617
+ const fullPath = path.join(outDir, "404.html");
618
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
619
+ fs.writeFileSync(fullPath, html404, "utf-8");
620
+ results.push({
621
+ route: "/404",
622
+ status: "rendered",
623
+ outputFiles: ["404.html"],
624
+ revalidate: false
625
+ });
626
+ }
627
+ } catch {}
628
+ if (!skipManifest) writePrerenderIndex(results, manifestDir);
629
+ return { routes: results };
630
+ } finally {
631
+ setCacheHandler(previousHandler);
632
+ delete process.env.VINEXT_PRERENDER;
633
+ if (ownedProdServerHandle) await new Promise((resolve) => ownedProdServerHandle.server.close(() => resolve()));
634
+ }
635
+ }
636
+ /**
637
+ * Determine the RSC output file path for a URL.
638
+ * "/blog/hello-world" → "blog/hello-world.rsc"
639
+ * "/" → "index.rsc"
640
+ */
641
+ function getRscOutputPath(urlPath) {
642
+ if (urlPath === "/") return "index.rsc";
643
+ return urlPath.replace(/^\//, "") + ".rsc";
644
+ }
645
+ /**
646
+ * Write `vinext-prerender.json` to `outDir`.
647
+ *
648
+ * This is a minimal flat list of route results used during testing and as a
649
+ * seed for future ISR cache population. Not consumed by the production server.
650
+ */
651
+ function writePrerenderIndex(routes, outDir) {
652
+ const index = { routes: routes.map((r) => {
653
+ if (r.status === "rendered") return {
654
+ route: r.route,
655
+ status: r.status,
656
+ revalidate: r.revalidate,
657
+ ...r.path ? { path: r.path } : {}
658
+ };
659
+ if (r.status === "skipped") return {
660
+ route: r.route,
661
+ status: r.status,
662
+ reason: r.reason
663
+ };
664
+ return {
665
+ route: r.route,
666
+ status: r.status,
667
+ error: r.error
668
+ };
669
+ }) };
670
+ fs.writeFileSync(path.join(outDir, "vinext-prerender.json"), JSON.stringify(index, null, 2), "utf-8");
671
+ }
672
+ //#endregion
673
+ export { buildUrlFromParams, getOutputPath, getRscOutputPath, prerenderApp, prerenderPages, readPrerenderSecret, writePrerenderIndex };
674
+
675
+ //# sourceMappingURL=prerender.js.map