vinext 1.0.0-beta.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (813) hide show
  1. package/README.md +158 -84
  2. package/THIRD_PARTY_LICENSES.md +25 -0
  3. package/dist/_virtual/_rolldown/runtime.js +25 -0
  4. package/dist/build/action-owner-manifest.d.ts +8 -9
  5. package/dist/build/action-owner-manifest.js +23 -5
  6. package/dist/build/assets-ignore.d.ts +3 -4
  7. package/dist/build/clean-output.d.ts +2 -3
  8. package/dist/build/client-build-config.d.ts +40 -12
  9. package/dist/build/client-build-config.js +76 -6
  10. package/dist/build/css-url-assets.d.ts +4 -5
  11. package/dist/build/css-url-assets.js +5 -2
  12. package/dist/build/google-fonts/build-url.d.ts +3 -4
  13. package/dist/build/google-fonts/fallback-metrics.d.ts +3 -4
  14. package/dist/build/google-fonts/find-font-files-in-css.d.ts +2 -3
  15. package/dist/build/google-fonts/font-metadata.d.ts +2 -3
  16. package/dist/build/google-fonts/get-axes.d.ts +2 -3
  17. package/dist/build/google-fonts/sort-variants.d.ts +2 -3
  18. package/dist/build/google-fonts/validate.d.ts +2 -3
  19. package/dist/build/google-fonts/validate.js +8 -4
  20. package/dist/build/inject-pregenerated-paths.d.ts +2 -3
  21. package/dist/build/inject-pregenerated-paths.js +16 -14
  22. package/dist/build/inline-css.d.ts +3 -4
  23. package/dist/build/layout-classification-types.d.ts +4 -5
  24. package/dist/build/layout-classification.d.ts +7 -8
  25. package/dist/build/lifecycle.d.ts +42 -0
  26. package/dist/build/lifecycle.js +253 -0
  27. package/dist/build/module-dependency-cache.d.ts +2 -3
  28. package/dist/build/next-client-runtime-manifests.d.ts +4 -5
  29. package/dist/build/nitro-route-rules.d.ts +6 -7
  30. package/dist/build/nitro-route-rules.js +1 -1
  31. package/dist/build/pages-client-assets-module.d.ts +4 -8
  32. package/dist/build/pages-client-assets-module.js +1 -13
  33. package/dist/build/precompress.d.ts +2 -3
  34. package/dist/build/prerender-cloudflare-loader.d.ts +4 -0
  35. package/dist/build/prerender-cloudflare-loader.js +49 -0
  36. package/dist/build/prerender-paths.d.ts +82 -8
  37. package/dist/build/prerender-paths.js +814 -99
  38. package/dist/build/prerender-phase.d.ts +2 -3
  39. package/dist/build/prerender-server-entry.js +11 -3
  40. package/dist/build/prerender-server-pool.d.ts +9 -6
  41. package/dist/build/prerender-server-pool.js +8 -5
  42. package/dist/build/prerender.d.ts +67 -15
  43. package/dist/build/prerender.js +177 -64
  44. package/dist/build/preview-credentials.d.ts +5 -6
  45. package/dist/build/preview-credentials.js +2 -2
  46. package/dist/build/public-dir-conflict.d.ts +5 -6
  47. package/dist/build/public-dir-conflict.js +2 -1
  48. package/dist/build/report.d.ts +38 -19
  49. package/dist/build/report.js +73 -4
  50. package/dist/build/route-classification-injector.d.ts +2 -3
  51. package/dist/build/route-classification-manifest.d.ts +5 -6
  52. package/dist/build/run-prerender.d.ts +11 -9
  53. package/dist/build/run-prerender.js +25 -16
  54. package/dist/build/server-entry.d.ts +4 -0
  55. package/dist/build/server-entry.js +28 -0
  56. package/dist/build/server-manifest.d.ts +8 -3
  57. package/dist/build/server-manifest.js +14 -2
  58. package/dist/build/ssr-manifest.d.ts +5 -6
  59. package/dist/build/standalone.d.ts +2 -3
  60. package/dist/build/standalone.js +2 -2
  61. package/dist/build/static-export.d.ts +7 -8
  62. package/dist/cache/cache-adapters-virtual.d.ts +95 -9
  63. package/dist/cache/cache-adapters-virtual.js +58 -6
  64. package/dist/check.d.ts +11 -10
  65. package/dist/check.js +467 -176
  66. package/dist/cli-args.d.ts +7 -16
  67. package/dist/cli-args.js +2 -45
  68. package/dist/cli-dev-config.d.ts +10 -7
  69. package/dist/cli-dev-config.js +160 -3
  70. package/dist/cli.js +124 -435
  71. package/dist/client/app-nav-failure-handler.d.ts +6 -7
  72. package/dist/client/client-rewrite-matcher.d.ts +2 -3
  73. package/dist/client/client-rewrites.d.ts +4 -5
  74. package/dist/client/dev-error-overlay-store.d.ts +13 -14
  75. package/dist/client/dev-error-overlay.d.ts +15 -15
  76. package/dist/client/dev-error-overlay.js +8 -5
  77. package/dist/client/instrumentation-client-inject.d.ts +3 -4
  78. package/dist/client/instrumentation-client-state.d.ts +5 -6
  79. package/dist/client/instrumentation-client.d.ts +3 -4
  80. package/dist/client/navigation-runtime.d.ts +21 -17
  81. package/dist/client/navigation-runtime.js +2 -1
  82. package/dist/client/pages-router-link-navigation.d.ts +4 -5
  83. package/dist/client/react-instance.d.ts +2 -3
  84. package/dist/client/validate-module-path.d.ts +2 -3
  85. package/dist/client/vinext-next-data.d.ts +7 -8
  86. package/dist/client/window-next.d.ts +4 -5
  87. package/dist/config/config-matchers.d.ts +16 -16
  88. package/dist/config/config-matchers.js +10 -7
  89. package/dist/config/dotenv.d.ts +3 -4
  90. package/dist/config/dotenv.js +2 -1
  91. package/dist/config/next-config.d.ts +31 -27
  92. package/dist/config/next-config.js +163 -16
  93. package/dist/config/prerender.d.ts +20 -16
  94. package/dist/config/prerender.js +10 -4
  95. package/dist/config/request-context.d.ts +5 -6
  96. package/dist/config/server-external-packages.d.ts +14 -3
  97. package/dist/config/server-external-packages.js +37 -3
  98. package/dist/config/tsconfig-paths.d.ts +3 -4
  99. package/dist/deps/.pnpm/ignore@5.3.2/deps/ignore/index.js +189 -0
  100. package/dist/deps/.pnpm/ua-parser-js@1.0.35/deps/ua-parser-js/src/ua-parser.js +1057 -0
  101. package/dist/entries/app-browser-entry.d.ts +5 -6
  102. package/dist/entries/app-browser-entry.js +3 -2
  103. package/dist/entries/app-rsc-entry.d.ts +12 -3
  104. package/dist/entries/app-rsc-entry.js +530 -55
  105. package/dist/entries/app-rsc-manifest.d.ts +4 -3
  106. package/dist/entries/app-rsc-manifest.js +27 -8
  107. package/dist/entries/app-ssr-entry.d.ts +2 -3
  108. package/dist/entries/app-ssr-entry.js +8 -1
  109. package/dist/entries/pages-client-entry.d.ts +3 -3
  110. package/dist/entries/pages-client-entry.js +17 -2
  111. package/dist/entries/pages-server-entry.d.ts +13 -3
  112. package/dist/entries/pages-server-entry.js +237 -33
  113. package/dist/entries/runtime-entry-module.d.ts +4 -5
  114. package/dist/image/image-adapters-virtual.d.ts +4 -5
  115. package/dist/index.d.ts +10 -11
  116. package/dist/index.js +832 -199
  117. package/dist/init-cloudflare.d.ts +27 -16
  118. package/dist/init-cloudflare.js +754 -113
  119. package/dist/init-platform.d.ts +26 -22
  120. package/dist/init-platform.js +85 -29
  121. package/dist/init.d.ts +19 -13
  122. package/dist/init.js +123 -41
  123. package/dist/plugins/action-owner-manifest.d.ts +3 -4
  124. package/dist/plugins/action-owner-manifest.js +10 -3
  125. package/dist/plugins/ast-scope.d.ts +10 -11
  126. package/dist/plugins/ast-scope.js +10 -22
  127. package/dist/plugins/ast-utils.d.ts +16 -29
  128. package/dist/plugins/ast-utils.js +27 -71
  129. package/dist/plugins/async-hooks-stub.d.ts +2 -3
  130. package/dist/plugins/client-reference-dedup.d.ts +4 -5
  131. package/dist/plugins/css-data-url.d.ts +2 -3
  132. package/dist/plugins/css-module-imports.d.ts +3 -4
  133. package/dist/plugins/css-module-imports.js +1 -1
  134. package/dist/plugins/dynamic-preload-metadata.d.ts +3 -4
  135. package/dist/plugins/dynamic-preload-metadata.js +55 -154
  136. package/dist/plugins/environment.d.ts +2 -3
  137. package/dist/plugins/extensionless-dynamic-import.d.ts +2 -3
  138. package/dist/plugins/extensionless-dynamic-import.js +6 -10
  139. package/dist/plugins/fonts.d.ts +10 -11
  140. package/dist/plugins/fonts.js +4 -3
  141. package/dist/plugins/ignore-dynamic-requests.d.ts +3 -4
  142. package/dist/plugins/ignore-dynamic-requests.js +60 -89
  143. package/dist/plugins/import-meta-url.d.ts +6 -7
  144. package/dist/plugins/import-meta-url.js +31 -43
  145. package/dist/plugins/instrumentation-client.d.ts +3 -3
  146. package/dist/plugins/instrumentation-client.js +46 -10
  147. package/dist/plugins/middleware-export-validation.d.ts +3 -4
  148. package/dist/plugins/middleware-export-validation.js +3 -3
  149. package/dist/plugins/middleware-server-only.d.ts +2 -3
  150. package/dist/plugins/og-asset-ownership.d.ts +3 -4
  151. package/dist/plugins/og-assets.d.ts +4 -5
  152. package/dist/plugins/og-assets.js +32 -13
  153. package/dist/plugins/og-harfbuzz.d.ts +24 -0
  154. package/dist/plugins/og-harfbuzz.js +260 -0
  155. package/dist/plugins/optimize-imports.d.ts +7 -7
  156. package/dist/plugins/optimize-imports.js +32 -44
  157. package/dist/plugins/pages-node-externals.d.ts +2 -3
  158. package/dist/plugins/pages-node-externals.js +6 -11
  159. package/dist/plugins/postcss.d.ts +8 -4
  160. package/dist/plugins/postcss.js +1 -1
  161. package/dist/plugins/remove-console.d.ts +2 -3
  162. package/dist/plugins/remove-console.js +0 -1
  163. package/dist/plugins/require-condition-resolution.d.ts +3 -4
  164. package/dist/plugins/require-condition-resolution.js +17 -18
  165. package/dist/plugins/require-context.d.ts +2 -3
  166. package/dist/plugins/require-context.js +13 -21
  167. package/dist/plugins/rsc-client-reference-loaders.d.ts +2 -3
  168. package/dist/plugins/rsc-client-shim-excludes.d.ts +4 -5
  169. package/dist/plugins/rsc-client-shim-excludes.js +1 -0
  170. package/dist/plugins/rsc-reference-validation-normalizer.d.ts +2 -3
  171. package/dist/plugins/sass.d.ts +7 -8
  172. package/dist/plugins/sass.js +7 -4
  173. package/dist/plugins/server-externals-manifest.d.ts +2 -3
  174. package/dist/plugins/strip-server-exports.d.ts +5 -6
  175. package/dist/plugins/strip-server-exports.js +1 -1
  176. package/dist/plugins/styled-jsx.d.ts +2 -3
  177. package/dist/plugins/styled-jsx.js +7 -7
  178. package/dist/plugins/transform-cache.d.ts +2 -3
  179. package/dist/plugins/transform-result.d.ts +3 -4
  180. package/dist/plugins/transitive-externals.d.ts +2 -3
  181. package/dist/plugins/typeof-window.d.ts +6 -7
  182. package/dist/plugins/typeof-window.js +30 -31
  183. package/dist/plugins/use-cache-callable.d.ts +2 -5
  184. package/dist/plugins/use-cache-callable.js +43 -22
  185. package/dist/plugins/wasm-module-import.d.ts +2 -3
  186. package/dist/plugins/worker-image-imports.d.ts +2 -3
  187. package/dist/plugins/worker-image-imports.js +6 -8
  188. package/dist/routing/app-route-graph.d.ts +19 -19
  189. package/dist/routing/app-route-graph.js +3 -2
  190. package/dist/routing/app-router.d.ts +20 -5
  191. package/dist/routing/app-router.js +28 -2
  192. package/dist/routing/file-matcher.d.ts +9 -10
  193. package/dist/routing/pages-router.d.ts +6 -6
  194. package/dist/routing/pages-router.js +1 -1
  195. package/dist/routing/route-matching.d.ts +4 -5
  196. package/dist/routing/route-matching.js +4 -2
  197. package/dist/routing/route-pattern.d.ts +13 -14
  198. package/dist/routing/route-trie.d.ts +5 -6
  199. package/dist/routing/route-validation.d.ts +3 -4
  200. package/dist/routing/route-validation.js +12 -11
  201. package/dist/routing/utils.d.ts +13 -14
  202. package/dist/server/accept-encoding.d.ts +9 -10
  203. package/dist/server/api-handler.d.ts +2 -3
  204. package/dist/server/api-handler.js +9 -6
  205. package/dist/server/app-action-forwarding.d.ts +3 -4
  206. package/dist/server/app-action-forwarding.js +1 -1
  207. package/dist/server/app-action-request.d.ts +2 -3
  208. package/dist/server/app-bfcache-id.d.ts +3 -4
  209. package/dist/server/app-bfcache-identity.d.ts +8 -9
  210. package/dist/server/app-browser-action-result.d.ts +15 -16
  211. package/dist/server/app-browser-client-reuse-manifest.d.ts +2 -3
  212. package/dist/server/app-browser-entry.js +121 -40
  213. package/dist/server/app-browser-error.d.ts +5 -6
  214. package/dist/server/app-browser-error.js +9 -3
  215. package/dist/server/app-browser-history-controller.d.ts +4 -5
  216. package/dist/server/app-browser-hydration.d.ts +16 -6
  217. package/dist/server/app-browser-hydration.js +14 -1
  218. package/dist/server/app-browser-interception-context.d.ts +3 -4
  219. package/dist/server/app-browser-mpa-navigation.d.ts +4 -5
  220. package/dist/server/app-browser-navigation-abort.d.ts +3 -4
  221. package/dist/server/app-browser-navigation-controller.d.ts +8 -8
  222. package/dist/server/app-browser-navigation-controller.js +9 -5
  223. package/dist/server/app-browser-navigation-response.d.ts +2 -3
  224. package/dist/server/app-browser-popstate.d.ts +4 -5
  225. package/dist/server/app-browser-prefetch-response.d.ts +5 -6
  226. package/dist/server/app-browser-rsc-redirect.d.ts +4 -5
  227. package/dist/server/app-browser-server-action-client.d.ts +7 -6
  228. package/dist/server/app-browser-server-action-client.js +9 -5
  229. package/dist/server/app-browser-server-action-navigation.d.ts +2 -3
  230. package/dist/server/app-browser-state.d.ts +17 -17
  231. package/dist/server/app-browser-state.js +7 -3
  232. package/dist/server/app-browser-stream.d.ts +4 -5
  233. package/dist/server/app-browser-stream.js +8 -6
  234. package/dist/server/app-browser-supplemental-refresh.d.ts +11 -12
  235. package/dist/server/app-browser-visible-commit.d.ts +6 -7
  236. package/dist/server/app-browser-visible-commit.js +1 -1
  237. package/dist/server/app-client-reference-preloader.d.ts +2 -3
  238. package/dist/server/app-elements-wire-key.d.ts +25 -0
  239. package/dist/server/app-elements-wire-key.js +69 -0
  240. package/dist/server/app-elements-wire.d.ts +34 -53
  241. package/dist/server/app-elements-wire.js +4 -75
  242. package/dist/server/app-elements.d.ts +5 -5
  243. package/dist/server/app-elements.js +1 -1
  244. package/dist/server/app-fallback-renderer.d.ts +4 -4
  245. package/dist/server/app-fallback-renderer.js +6 -6
  246. package/dist/server/app-fetch-tracing.d.ts +15 -0
  247. package/dist/server/app-fetch-tracing.js +38 -0
  248. package/dist/server/app-history-state.d.ts +26 -27
  249. package/dist/server/app-history-state.js +19 -11
  250. package/dist/server/app-hook-warning-suppression.d.ts +2 -3
  251. package/dist/server/app-hydration-cache-publication.d.ts +3 -4
  252. package/dist/server/app-inline-css-client.d.ts +3 -4
  253. package/dist/server/app-interception-context-header.d.ts +2 -3
  254. package/dist/server/app-layout-param-observation.d.ts +7 -8
  255. package/dist/server/app-metadata-tracing.d.ts +12 -0
  256. package/dist/server/app-metadata-tracing.js +17 -0
  257. package/dist/server/app-middleware.d.ts +15 -7
  258. package/dist/server/app-middleware.js +30 -5
  259. package/dist/server/app-mounted-slots-header.d.ts +2 -3
  260. package/dist/server/app-mounted-slots-header.js +2 -2
  261. package/dist/server/app-optimistic-routing.d.ts +14 -10
  262. package/dist/server/app-optimistic-routing.js +16 -3
  263. package/dist/server/app-page-boundary-render.d.ts +6 -6
  264. package/dist/server/app-page-boundary-render.js +10 -4
  265. package/dist/server/app-page-boundary.d.ts +9 -10
  266. package/dist/server/app-page-boundary.js +2 -1
  267. package/dist/server/app-page-cache-finalizer.d.ts +32 -8
  268. package/dist/server/app-page-cache-finalizer.js +118 -14
  269. package/dist/server/app-page-cache-render.d.ts +8 -5
  270. package/dist/server/app-page-cache-render.js +22 -5
  271. package/dist/server/app-page-cache.d.ts +28 -9
  272. package/dist/server/app-page-cache.js +96 -25
  273. package/dist/server/app-page-dispatch.d.ts +36 -12
  274. package/dist/server/app-page-dispatch.js +188 -63
  275. package/dist/server/app-page-element-builder.d.ts +13 -11
  276. package/dist/server/app-page-element-builder.js +104 -61
  277. package/dist/server/app-page-execution.d.ts +14 -14
  278. package/dist/server/app-page-execution.js +12 -8
  279. package/dist/server/app-page-head.d.ts +19 -16
  280. package/dist/server/app-page-head.js +25 -25
  281. package/dist/server/app-page-http-access-fallback-metadata.d.ts +6 -5
  282. package/dist/server/app-page-http-access-fallback-metadata.js +9 -2
  283. package/dist/server/app-page-method.d.ts +5 -11
  284. package/dist/server/app-page-method.js +2 -9
  285. package/dist/server/app-page-params.d.ts +5 -6
  286. package/dist/server/app-page-ppr-runtime.d.ts +2 -2
  287. package/dist/server/app-page-probe.d.ts +5 -6
  288. package/dist/server/app-page-probe.js +5 -4
  289. package/dist/server/app-page-render-identity.d.ts +4 -5
  290. package/dist/server/app-page-render-observation.d.ts +8 -9
  291. package/dist/server/app-page-render-observation.js +1 -1
  292. package/dist/server/app-page-render.d.ts +42 -6
  293. package/dist/server/app-page-render.js +192 -28
  294. package/dist/server/app-page-request.d.ts +10 -9
  295. package/dist/server/app-page-request.js +16 -12
  296. package/dist/server/app-page-response.d.ts +20 -9
  297. package/dist/server/app-page-response.js +31 -13
  298. package/dist/server/app-page-route-wiring.d.ts +15 -15
  299. package/dist/server/app-page-route-wiring.js +31 -24
  300. package/dist/server/app-page-search-params-observation.d.ts +26 -5
  301. package/dist/server/app-page-search-params-observation.js +42 -6
  302. package/dist/server/app-page-segment-plan.d.ts +2 -3
  303. package/dist/server/app-page-segment-state.d.ts +11 -12
  304. package/dist/server/app-page-stream.d.ts +27 -11
  305. package/dist/server/app-page-stream.js +35 -6
  306. package/dist/server/app-page-tracing.d.ts +33 -0
  307. package/dist/server/app-page-tracing.js +49 -0
  308. package/dist/server/app-pages-bridge.d.ts +6 -6
  309. package/dist/server/app-pages-bridge.js +19 -4
  310. package/dist/server/app-post-middleware-context.d.ts +2 -3
  311. package/dist/server/app-ppr-fallback-shell-render.d.ts +3 -4
  312. package/dist/server/app-ppr-fallback-shell-render.js +3 -2
  313. package/dist/server/app-ppr-fallback-shell.d.ts +6 -7
  314. package/dist/server/app-prerender-endpoints.d.ts +5 -5
  315. package/dist/server/app-prerender-endpoints.js +26 -12
  316. package/dist/server/app-prerender-static-params.d.ts +15 -7
  317. package/dist/server/app-prerender-static-params.js +33 -11
  318. package/dist/server/app-render-dependency.d.ts +14 -13
  319. package/dist/server/app-render-dependency.js +5 -1
  320. package/dist/server/app-request-context.d.ts +3 -4
  321. package/dist/server/app-request-stage-context.d.ts +5 -0
  322. package/dist/server/app-request-stage-context.js +11 -0
  323. package/dist/server/app-request-stage-dispatch.d.ts +25 -0
  324. package/dist/server/app-request-stage-dispatch.js +54 -0
  325. package/dist/server/app-request-stage-independent-entry.d.ts +8 -0
  326. package/dist/server/app-request-stage-independent-entry.js +115 -0
  327. package/dist/server/app-response-header-provenance.d.ts +13 -7
  328. package/dist/server/app-response-header-provenance.js +34 -1
  329. package/dist/server/app-response-stage-entry.d.ts +9 -0
  330. package/dist/server/app-response-stage-entry.js +87 -0
  331. package/dist/server/app-route-handler-cache.d.ts +2 -3
  332. package/dist/server/app-route-handler-cache.js +46 -34
  333. package/dist/server/app-route-handler-dispatch.d.ts +3 -3
  334. package/dist/server/app-route-handler-dispatch.js +75 -57
  335. package/dist/server/app-route-handler-execution.d.ts +18 -13
  336. package/dist/server/app-route-handler-execution.js +189 -25
  337. package/dist/server/app-route-handler-middleware-context.d.ts +8 -0
  338. package/dist/server/app-route-handler-middleware-context.js +15 -0
  339. package/dist/server/app-route-handler-policy.d.ts +22 -10
  340. package/dist/server/app-route-handler-policy.js +19 -4
  341. package/dist/server/app-route-handler-response.d.ts +9 -10
  342. package/dist/server/app-route-handler-response.js +2 -0
  343. package/dist/server/app-route-handler-runtime.d.ts +9 -10
  344. package/dist/server/app-route-handler-runtime.js +20 -16
  345. package/dist/server/app-route-module-loader.d.ts +6 -7
  346. package/dist/server/app-route-request-built-ins.d.ts +3 -4
  347. package/dist/server/app-route-tree-prefetch.d.ts +6 -7
  348. package/dist/server/app-route-tree-prefetch.js +2 -1
  349. package/dist/server/app-router-entry.d.ts +2 -0
  350. package/dist/server/app-router-entry.js +76 -12
  351. package/dist/server/app-rsc-cache-busting.d.ts +47 -22
  352. package/dist/server/app-rsc-cache-busting.js +80 -18
  353. package/dist/server/app-rsc-combined-handler.d.ts +9 -0
  354. package/dist/server/app-rsc-combined-handler.js +11 -0
  355. package/dist/server/app-rsc-embedded-chunks.d.ts +6 -7
  356. package/dist/server/app-rsc-error-handler.d.ts +12 -6
  357. package/dist/server/app-rsc-error-handler.js +15 -6
  358. package/dist/server/app-rsc-errors.d.ts +12 -9
  359. package/dist/server/app-rsc-errors.js +15 -13
  360. package/dist/server/app-rsc-handler.d.ts +33 -6
  361. package/dist/server/app-rsc-handler.js +498 -83
  362. package/dist/server/app-rsc-redirect-flight.d.ts +4 -5
  363. package/dist/server/app-rsc-render-mode.d.ts +8 -9
  364. package/dist/server/app-rsc-request-normalization.d.ts +3 -3
  365. package/dist/server/app-rsc-request-normalization.js +2 -1
  366. package/dist/server/app-rsc-response-finalizer.d.ts +8 -5
  367. package/dist/server/app-rsc-response-finalizer.js +24 -7
  368. package/dist/server/app-rsc-response-stage.d.ts +6 -0
  369. package/dist/server/app-rsc-response-stage.js +251 -0
  370. package/dist/server/app-rsc-route-matching.d.ts +4 -4
  371. package/dist/server/app-rsc-route-matching.js +4 -2
  372. package/dist/server/app-rsc-state-fingerprint.d.ts +3 -4
  373. package/dist/server/app-rsc-vary.d.ts +16 -0
  374. package/dist/server/app-rsc-vary.js +31 -0
  375. package/dist/server/app-segment-config.d.ts +120 -6
  376. package/dist/server/app-segment-config.js +264 -12
  377. package/dist/server/app-server-action-execution.d.ts +16 -12
  378. package/dist/server/app-server-action-execution.js +88 -35
  379. package/dist/server/app-ssr-entry.d.ts +14 -4
  380. package/dist/server/app-ssr-entry.js +64 -17
  381. package/dist/server/app-ssr-error-meta.d.ts +3 -4
  382. package/dist/server/app-ssr-error-meta.js +2 -1
  383. package/dist/server/app-ssr-router-instance.d.ts +2 -3
  384. package/dist/server/app-ssr-search-params-gate.d.ts +20 -0
  385. package/dist/server/app-ssr-search-params-gate.js +54 -0
  386. package/dist/server/app-ssr-stream.d.ts +13 -9
  387. package/dist/server/app-ssr-stream.js +33 -7
  388. package/dist/server/app-static-generation.d.ts +4 -5
  389. package/dist/server/app-visited-response-cache.d.ts +11 -12
  390. package/dist/server/app-visited-response-cache.js +2 -2
  391. package/dist/server/app-worker-stages.d.ts +112 -0
  392. package/dist/server/app-worker-stages.js +105 -0
  393. package/dist/server/artifact-compatibility.d.ts +11 -12
  394. package/dist/server/before-interactive-head.d.ts +2 -3
  395. package/dist/server/bfcache-identity.d.ts +7 -8
  396. package/dist/server/cache-control.d.ts +39 -11
  397. package/dist/server/cache-control.js +104 -7
  398. package/dist/server/cache-headers.d.ts +3 -4
  399. package/dist/server/cache-proof.d.ts +75 -70
  400. package/dist/server/cache-proof.js +9 -1
  401. package/dist/server/cacheability-limits.d.ts +8 -0
  402. package/dist/server/cacheability-limits.js +9 -0
  403. package/dist/server/cacheability-manifest.d.ts +68 -0
  404. package/dist/server/cacheability-manifest.js +241 -0
  405. package/dist/server/cacheability-request.d.ts +49 -0
  406. package/dist/server/cacheability-request.js +559 -0
  407. package/dist/server/client-reuse-manifest.d.ts +17 -18
  408. package/dist/server/client-reuse-manifest.js +2 -2
  409. package/dist/server/client-trace-metadata.d.ts +9 -6
  410. package/dist/server/client-trace-metadata.js +27 -15
  411. package/dist/server/cloudflare-workers-tracing.d.ts +1 -0
  412. package/dist/server/cloudflare-workers-tracing.js +8 -0
  413. package/dist/server/config-headers.d.ts +19 -5
  414. package/dist/server/config-headers.js +39 -5
  415. package/dist/server/cookie-utils.d.ts +2 -3
  416. package/dist/server/csp.d.ts +5 -6
  417. package/dist/server/default-global-error-module.d.ts +2 -3
  418. package/dist/server/default-global-not-found-module.d.ts +2 -3
  419. package/dist/server/default-not-found-module.d.ts +2 -3
  420. package/dist/server/defer-until-stream-consumed.d.ts +2 -3
  421. package/dist/server/defer-until-stream-consumed.js +2 -1
  422. package/dist/server/dev-initial-server-error.d.ts +3 -4
  423. package/dist/server/dev-initial-server-error.js +2 -1
  424. package/dist/server/dev-lockfile.d.ts +7 -8
  425. package/dist/server/dev-lockfile.js +4 -1
  426. package/dist/server/dev-module-runner.d.ts +2 -3
  427. package/dist/server/dev-origin-check.d.ts +5 -6
  428. package/dist/server/dev-route-files.d.ts +2 -3
  429. package/dist/server/dev-server.d.ts +4 -5
  430. package/dist/server/dev-server.js +130 -61
  431. package/dist/server/dev-stack-sourcemap.d.ts +7 -7
  432. package/dist/server/dev-stack-sourcemap.js +1 -1
  433. package/dist/server/document-initial-head.d.ts +3 -4
  434. package/dist/server/edge-api-runtime.d.ts +4 -5
  435. package/dist/server/fetch-handler.d.ts +3 -2
  436. package/dist/server/fetch-handler.js +3 -18
  437. package/dist/server/file-based-metadata.d.ts +2 -3
  438. package/dist/server/framework-tracer.d.ts +46 -0
  439. package/dist/server/framework-tracer.js +125 -0
  440. package/dist/server/fully-buffered-response.d.ts +11 -0
  441. package/dist/server/fully-buffered-response.js +19 -0
  442. package/dist/server/headers.d.ts +62 -56
  443. package/dist/server/headers.js +33 -20
  444. package/dist/server/html.d.ts +6 -27
  445. package/dist/server/html.js +16 -1
  446. package/dist/server/http-conditional.d.ts +5 -6
  447. package/dist/server/http-date.d.ts +2 -3
  448. package/dist/server/http-error-responses.d.ts +9 -10
  449. package/dist/server/http-range.d.ts +4 -5
  450. package/dist/server/hybrid-route-priority.d.ts +4 -5
  451. package/dist/server/image-optimization.d.ts +20 -21
  452. package/dist/server/implicit-tags.d.ts +3 -4
  453. package/dist/server/instrumentation-runtime.d.ts +17 -21
  454. package/dist/server/instrumentation-runtime.js +26 -8
  455. package/dist/server/instrumentation.d.ts +26 -30
  456. package/dist/server/instrumentation.js +18 -23
  457. package/dist/server/isr-cache.d.ts +28 -27
  458. package/dist/server/isr-cache.js +18 -70
  459. package/dist/server/isr-decision.d.ts +4 -4
  460. package/dist/server/metadata-route-build-data.d.ts +4 -5
  461. package/dist/server/metadata-route-cache-policy.d.ts +2 -3
  462. package/dist/server/metadata-route-response.d.ts +7 -7
  463. package/dist/server/metadata-route-response.js +68 -2
  464. package/dist/server/metadata-routes.d.ts +18 -19
  465. package/dist/server/middleware-matcher-pattern.d.ts +6 -7
  466. package/dist/server/middleware-matcher.d.ts +13 -6
  467. package/dist/server/middleware-matcher.js +22 -1
  468. package/dist/server/middleware-path-to-regexp.d.ts +6 -7
  469. package/dist/server/middleware-path-to-regexp.js +11 -9
  470. package/dist/server/middleware-response-headers.d.ts +3 -4
  471. package/dist/server/middleware-runtime.d.ts +13 -8
  472. package/dist/server/middleware-runtime.js +54 -10
  473. package/dist/server/middleware.d.ts +5 -5
  474. package/dist/server/multi-stage.d.ts +141 -0
  475. package/dist/server/multi-stage.js +8 -0
  476. package/dist/server/navigation-planner.d.ts +26 -26
  477. package/dist/server/navigation-trace.d.ts +11 -12
  478. package/dist/server/next-error-digest.d.ts +4 -5
  479. package/dist/server/normalize-path.d.ts +5 -6
  480. package/dist/server/normalize-path.js +1 -1
  481. package/dist/server/open-redirect.d.ts +2 -3
  482. package/dist/server/opentelemetry-api.d.ts +59 -0
  483. package/dist/server/opentelemetry-api.js +53 -0
  484. package/dist/server/opentelemetry-tracing.d.ts +5 -0
  485. package/dist/server/opentelemetry-tracing.js +83 -0
  486. package/dist/server/operation-token.d.ts +11 -12
  487. package/dist/server/otel-tracer-extension.d.ts +7 -9
  488. package/dist/server/otel-tracer-extension.js +37 -36
  489. package/dist/server/pages-api-route.d.ts +5 -4
  490. package/dist/server/pages-api-route.js +21 -8
  491. package/dist/server/pages-asset-tags.d.ts +6 -6
  492. package/dist/server/pages-asset-tags.js +37 -2
  493. package/dist/server/pages-body-parser-config.d.ts +4 -5
  494. package/dist/server/pages-body-parser-config.js +4 -4
  495. package/dist/server/pages-client-assets.d.ts +11 -5
  496. package/dist/server/pages-data-route.d.ts +11 -12
  497. package/dist/server/pages-data-route.js +1 -1
  498. package/dist/server/pages-default-404.d.ts +3 -4
  499. package/dist/server/pages-dev-hydration.d.ts +9 -4
  500. package/dist/server/pages-dev-hydration.js +19 -7
  501. package/dist/server/pages-dev-module-url.d.ts +3 -4
  502. package/dist/server/pages-dev-stylesheets.d.ts +5 -6
  503. package/dist/server/pages-document-asset-props.d.ts +6 -7
  504. package/dist/server/pages-document-initial-props.d.ts +5 -5
  505. package/dist/server/pages-document-initial-props.js +4 -2
  506. package/dist/server/pages-execution-tracing.d.ts +40 -0
  507. package/dist/server/pages-execution-tracing.js +80 -0
  508. package/dist/server/pages-get-initial-props.d.ts +9 -10
  509. package/dist/server/pages-i18n.d.ts +8 -8
  510. package/dist/server/pages-i18n.js +3 -2
  511. package/dist/server/pages-media-type.d.ts +4 -5
  512. package/dist/server/pages-node-compat.d.ts +11 -10
  513. package/dist/server/pages-node-compat.js +12 -4
  514. package/dist/server/pages-page-data.d.ts +18 -19
  515. package/dist/server/pages-page-data.js +11 -10
  516. package/dist/server/pages-page-handler.d.ts +7 -6
  517. package/dist/server/pages-page-handler.js +98 -47
  518. package/dist/server/pages-page-method.d.ts +2 -3
  519. package/dist/server/pages-page-response.d.ts +14 -10
  520. package/dist/server/pages-page-response.js +49 -31
  521. package/dist/server/pages-preview.d.ts +10 -11
  522. package/dist/server/pages-readiness.d.ts +2 -3
  523. package/dist/server/pages-request-pipeline.d.ts +16 -12
  524. package/dist/server/pages-request-pipeline.js +69 -28
  525. package/dist/server/pages-request-stage-entry.d.ts +23 -0
  526. package/dist/server/pages-request-stage-entry.js +314 -0
  527. package/dist/server/pages-response-stage-entry.d.ts +11 -0
  528. package/dist/server/pages-response-stage-entry.js +106 -0
  529. package/dist/server/pages-response-stage.d.ts +31 -0
  530. package/dist/server/pages-response-stage.js +49 -0
  531. package/dist/server/pages-revalidate.d.ts +3 -4
  532. package/dist/server/pages-revalidate.js +9 -4
  533. package/dist/server/pages-route-data-kind.d.ts +18 -0
  534. package/dist/server/pages-route-data-kind.js +11 -0
  535. package/dist/server/pages-router-entry.d.ts +1 -25
  536. package/dist/server/pages-router-entry.js +48 -114
  537. package/dist/server/pages-serializable-props.d.ts +3 -4
  538. package/dist/server/pregenerated-concrete-paths.d.ts +9 -7
  539. package/dist/server/pregenerated-concrete-paths.js +12 -6
  540. package/dist/server/prerender-cache-life-header.d.ts +3 -4
  541. package/dist/server/prerender-manifest.d.ts +11 -11
  542. package/dist/server/prerender-manifest.js +6 -3
  543. package/dist/server/prerender-route-params.d.ts +16 -9
  544. package/dist/server/prerender-route-params.js +18 -2
  545. package/dist/server/prerender-work-unit-setup.d.ts +4 -4
  546. package/dist/server/prerender-work-unit-setup.js +37 -14
  547. package/dist/server/prod-server.d.ts +12 -9
  548. package/dist/server/prod-server.js +129 -36
  549. package/dist/server/proxy-trust.d.ts +5 -6
  550. package/dist/server/request-log.d.ts +3 -4
  551. package/dist/server/request-pipeline.d.ts +17 -21
  552. package/dist/server/request-pipeline.js +8 -10
  553. package/dist/server/request-stage.d.ts +5 -0
  554. package/dist/server/request-stage.js +7 -0
  555. package/dist/server/request-tracing.d.ts +22 -0
  556. package/dist/server/request-tracing.js +180 -0
  557. package/dist/server/response-stage-cacheability.d.ts +37 -0
  558. package/dist/server/response-stage-cacheability.js +55 -0
  559. package/dist/server/response-stage-policy.d.ts +23 -0
  560. package/dist/server/response-stage-policy.js +89 -0
  561. package/dist/server/response-stage.d.ts +5 -0
  562. package/dist/server/response-stage.js +7 -0
  563. package/dist/server/response-start-tracing.d.ts +14 -0
  564. package/dist/server/response-start-tracing.js +80 -0
  565. package/dist/server/revalidation-host.d.ts +2 -3
  566. package/dist/server/revalidation-host.js +2 -1
  567. package/dist/server/revalidation-request.d.ts +8 -0
  568. package/dist/server/revalidation-request.js +37 -0
  569. package/dist/server/rsc-completion-metadata.d.ts +6 -7
  570. package/dist/server/rsc-stream-hints.d.ts +18 -7
  571. package/dist/server/rsc-stream-hints.js +70 -35
  572. package/dist/server/seed-cache.d.ts +2 -3
  573. package/dist/server/seed-cache.js +8 -7
  574. package/dist/server/server-action-not-found.d.ts +5 -6
  575. package/dist/server/server-globals.d.ts +2 -3
  576. package/dist/server/server-globals.js +13 -0
  577. package/dist/server/skip-cache-proof.d.ts +4 -4
  578. package/dist/server/socket-error-backstop.d.ts +5 -6
  579. package/dist/server/socket-error-backstop.js +1 -1
  580. package/dist/server/static-file-cache.d.ts +5 -6
  581. package/dist/server/static-file-cache.js +9 -7
  582. package/dist/server/static-file-signal.d.ts +16 -0
  583. package/dist/server/static-file-signal.js +82 -0
  584. package/dist/server/static-layout-client-reuse-proof.d.ts +4 -5
  585. package/dist/server/streaming-metadata.d.ts +2 -3
  586. package/dist/server/tracer.d.ts +5 -0
  587. package/dist/server/tracer.js +13 -0
  588. package/dist/server/worker-prerender-discovery.d.ts +18 -0
  589. package/dist/server/worker-prerender-discovery.js +55 -0
  590. package/dist/server/worker-revalidation-context.d.ts +2 -3
  591. package/dist/server/worker-revalidation-context.js +5 -5
  592. package/dist/server/worker-stages.d.ts +43 -0
  593. package/dist/server/worker-stages.js +25 -0
  594. package/dist/server/worker-utils.d.ts +5 -6
  595. package/dist/server/worker-utils.js +4 -4
  596. package/dist/server/workers-tracing.d.ts +17 -0
  597. package/dist/server/workers-tracing.js +27 -0
  598. package/dist/shims/amp.d.ts +3 -4
  599. package/dist/shims/app-router-scroll-state.d.ts +9 -10
  600. package/dist/shims/app-router-scroll.d.ts +4 -5
  601. package/dist/shims/app-router-scroll.js +2 -1
  602. package/dist/shims/app.d.ts +5 -6
  603. package/dist/shims/before-interactive-context.d.ts +5 -6
  604. package/dist/shims/cache-callable-runtime.d.ts +44 -4
  605. package/dist/shims/cache-callable-runtime.js +168 -8
  606. package/dist/shims/cache-for-request.d.ts +2 -3
  607. package/dist/shims/cache-handler.d.ts +33 -20
  608. package/dist/shims/cache-handler.js +61 -2
  609. package/dist/shims/cache-request-state.d.ts +28 -29
  610. package/dist/shims/cache-runtime.d.ts +23 -21
  611. package/dist/shims/cache-runtime.js +239 -121
  612. package/dist/shims/cache.d.ts +15 -15
  613. package/dist/shims/cache.js +25 -13
  614. package/dist/shims/cacheability-classification.d.ts +106 -0
  615. package/dist/shims/cacheability-classification.js +161 -0
  616. package/dist/shims/cdn-cache-state.d.ts +13 -0
  617. package/dist/shims/cdn-cache-state.js +23 -0
  618. package/dist/shims/cdn-cache.d.ts +76 -18
  619. package/dist/shims/cdn-cache.js +40 -39
  620. package/dist/shims/client-hook-error.d.ts +3 -4
  621. package/dist/shims/client-locale.d.ts +2 -3
  622. package/dist/shims/client-page-root.d.ts +24 -0
  623. package/dist/shims/client-page-root.js +121 -0
  624. package/dist/shims/compat-router.d.ts +2 -3
  625. package/dist/shims/config.d.ts +3 -4
  626. package/dist/shims/constants.d.ts +73 -74
  627. package/dist/shims/constants.js +1 -1
  628. package/dist/shims/default-not-found.d.ts +2 -3
  629. package/dist/shims/document.d.ts +9 -9
  630. package/dist/shims/dynamic-preload-chunks.d.ts +2 -3
  631. package/dist/shims/dynamic-preload-chunks.js +17 -13
  632. package/dist/shims/dynamic.d.ts +3 -3
  633. package/dist/shims/error-boundary-navigation.d.ts +3 -4
  634. package/dist/shims/error-boundary.d.ts +17 -18
  635. package/dist/shims/error-boundary.js +17 -11
  636. package/dist/shims/error.d.ts +4 -4
  637. package/dist/shims/error.js +1 -1
  638. package/dist/shims/error.react-server.d.ts +3 -4
  639. package/dist/shims/fetch-cache.d.ts +22 -22
  640. package/dist/shims/fetch-cache.js +50 -20
  641. package/dist/shims/font-google-base.d.ts +9 -9
  642. package/dist/shims/font-google-base.js +2 -1
  643. package/dist/shims/font-local.d.ts +3 -3
  644. package/dist/shims/font-local.js +1 -1
  645. package/dist/shims/font-utils.d.ts +14 -15
  646. package/dist/shims/form.d.ts +2 -2
  647. package/dist/shims/form.js +10 -7
  648. package/dist/shims/hash-scroll.d.ts +5 -6
  649. package/dist/shims/head-state.d.ts +4 -5
  650. package/dist/shims/head.d.ts +16 -16
  651. package/dist/shims/head.js +5 -4
  652. package/dist/shims/headers.d.ts +68 -32
  653. package/dist/shims/headers.js +101 -10
  654. package/dist/shims/i18n-context.d.ts +5 -6
  655. package/dist/shims/i18n-state.d.ts +4 -5
  656. package/dist/shims/image-config.d.ts +5 -6
  657. package/dist/shims/image-config.js +2 -0
  658. package/dist/shims/image.d.ts +5 -5
  659. package/dist/shims/image.js +12 -8
  660. package/dist/shims/internal/als-registry.d.ts +4 -5
  661. package/dist/shims/internal/api-utils.d.ts +3 -4
  662. package/dist/shims/internal/app-page-props-cache-key.d.ts +32 -4
  663. package/dist/shims/internal/app-page-props-cache-key.js +53 -1
  664. package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +5 -6
  665. package/dist/shims/internal/app-prefetch-rsc-request.d.ts +13 -0
  666. package/dist/shims/internal/app-prefetch-rsc-request.js +12 -0
  667. package/dist/shims/internal/app-route-detection.d.ts +2 -2
  668. package/dist/shims/internal/app-route-prefetch-policy.d.ts +5 -6
  669. package/dist/shims/internal/app-route-prefetch-policy.js +1 -0
  670. package/dist/shims/internal/app-router-context.d.ts +9 -10
  671. package/dist/shims/internal/cookie-serialize.d.ts +4 -5
  672. package/dist/shims/internal/format-url-object.d.ts +7 -0
  673. package/dist/shims/internal/format-url-object.js +53 -0
  674. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +6 -7
  675. package/dist/shims/internal/hybrid-client-route-owner-direct.js +29 -11
  676. package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -3
  677. package/dist/shims/internal/hybrid-client-route-owner.js +5 -4
  678. package/dist/shims/internal/interpolate-as.d.ts +5 -6
  679. package/dist/shims/internal/interpolate-as.js +4 -2
  680. package/dist/shims/internal/link-status-registry.d.ts +5 -6
  681. package/dist/shims/internal/make-hanging-promise.d.ts +8 -3
  682. package/dist/shims/internal/make-hanging-promise.js +13 -2
  683. package/dist/shims/internal/navigation-untracked.d.ts +2 -3
  684. package/dist/shims/internal/normalize-router-href.d.ts +15 -0
  685. package/dist/shims/internal/normalize-router-href.js +41 -0
  686. package/dist/shims/internal/pages-data-fetch-dedup.d.ts +8 -9
  687. package/dist/shims/internal/pages-data-target.d.ts +8 -6
  688. package/dist/shims/internal/pages-data-target.js +32 -36
  689. package/dist/shims/internal/pages-data-url.d.ts +4 -5
  690. package/dist/shims/internal/pages-data-url.js +2 -1
  691. package/dist/shims/internal/pages-router-accessor.d.ts +3 -4
  692. package/dist/shims/internal/pages-router-components.d.ts +3 -4
  693. package/dist/shims/internal/route-pattern-for-warning.d.ts +5 -6
  694. package/dist/shims/internal/route-pattern-for-warning.js +3 -3
  695. package/dist/shims/internal/router-context.d.ts +2 -3
  696. package/dist/shims/internal/thenable-well-known-properties.d.ts +10 -0
  697. package/dist/shims/internal/thenable-well-known-properties.js +33 -0
  698. package/dist/shims/internal/utils.d.ts +7 -8
  699. package/dist/shims/internal/work-unit-async-storage.d.ts +12 -11
  700. package/dist/shims/layout-segment-context.d.ts +3 -4
  701. package/dist/shims/link-prefetch.d.ts +9 -10
  702. package/dist/shims/link.d.ts +4 -4
  703. package/dist/shims/link.js +67 -116
  704. package/dist/shims/metadata.d.ts +15 -16
  705. package/dist/shims/metadata.js +40 -36
  706. package/dist/shims/navigation-context-accessors.d.ts +9 -0
  707. package/dist/shims/navigation-context-accessors.js +19 -0
  708. package/dist/shims/navigation-context-state.d.ts +27 -18
  709. package/dist/shims/navigation-errors.d.ts +18 -19
  710. package/dist/shims/navigation-state.d.ts +6 -7
  711. package/dist/shims/navigation.d.ts +80 -68
  712. package/dist/shims/navigation.js +45 -17
  713. package/dist/shims/navigation.react-server.d.ts +9 -9
  714. package/dist/shims/navigation.react-server.js +1 -1
  715. package/dist/shims/offline.d.ts +2 -3
  716. package/dist/shims/og.d.ts +2 -2
  717. package/dist/shims/pages-router-runtime.d.ts +4 -5
  718. package/dist/shims/ppr-fallback-shell.d.ts +13 -14
  719. package/dist/shims/readonly-url-search-params.d.ts +2 -3
  720. package/dist/shims/request-context.d.ts +7 -6
  721. package/dist/shims/root-params.d.ts +14 -15
  722. package/dist/shims/router-state.d.ts +5 -6
  723. package/dist/shims/router-state.js +1 -1
  724. package/dist/shims/router.d.ts +22 -21
  725. package/dist/shims/router.js +339 -164
  726. package/dist/shims/script-nonce-context.d.ts +8 -6
  727. package/dist/shims/script-nonce-context.js +15 -6
  728. package/dist/shims/script.d.ts +4 -4
  729. package/dist/shims/script.js +9 -7
  730. package/dist/shims/search-params-gate.d.ts +35 -0
  731. package/dist/shims/search-params-gate.js +32 -0
  732. package/dist/shims/server.d.ts +19 -51
  733. package/dist/shims/server.js +14 -28
  734. package/dist/shims/slot.d.ts +33 -15
  735. package/dist/shims/slot.js +41 -9
  736. package/dist/shims/streamed-icons.d.ts +3 -4
  737. package/dist/shims/thenable-params.d.ts +5 -7
  738. package/dist/shims/thenable-params.js +3 -24
  739. package/dist/shims/unified-request-context.d.ts +34 -31
  740. package/dist/shims/unified-request-context.js +34 -24
  741. package/dist/shims/unrecognized-action-error.d.ts +3 -4
  742. package/dist/shims/url-safety.d.ts +5 -6
  743. package/dist/shims/url-utils.d.ts +18 -12
  744. package/dist/shims/url-utils.js +10 -1
  745. package/dist/shims/use-merged-ref.d.ts +2 -3
  746. package/dist/shims/user-agent.d.ts +31 -0
  747. package/dist/shims/user-agent.js +16 -0
  748. package/dist/shims/web-vitals.d.ts +2 -2
  749. package/dist/typegen.d.ts +3 -4
  750. package/dist/utils/asset-prefix.d.ts +7 -8
  751. package/dist/utils/base-path.d.ts +5 -6
  752. package/dist/utils/built-asset-url.d.ts +2 -3
  753. package/dist/utils/built-asset-url.js +1 -1
  754. package/dist/utils/cache-control-metadata.d.ts +4 -5
  755. package/dist/utils/client-build-manifest.d.ts +6 -7
  756. package/dist/utils/client-build-manifest.js +2 -1
  757. package/dist/utils/client-entry-manifest.d.ts +6 -7
  758. package/dist/utils/client-runtime-metadata.d.ts +8 -3
  759. package/dist/utils/client-runtime-metadata.js +18 -1
  760. package/dist/utils/commonjs-loader.d.ts +4 -5
  761. package/dist/utils/compare.d.ts +2 -3
  762. package/dist/utils/deployment-id.d.ts +6 -7
  763. package/dist/utils/dev-error-recovery-event.d.ts +2 -3
  764. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +2 -3
  765. package/dist/utils/domain-locale.d.ts +7 -8
  766. package/dist/utils/encode-cache-tag.d.ts +3 -4
  767. package/dist/utils/error-cause.d.ts +2 -3
  768. package/dist/utils/external-url.d.ts +2 -3
  769. package/dist/utils/has-trailing-comma.d.ts +3 -4
  770. package/dist/utils/hash.d.ts +3 -4
  771. package/dist/utils/html-limited-bots.d.ts +3 -4
  772. package/dist/utils/lazy-chunks.d.ts +8 -9
  773. package/dist/utils/lazy-chunks.js +4 -4
  774. package/dist/utils/manifest-paths.d.ts +5 -6
  775. package/dist/utils/mdx-scan.d.ts +11 -4
  776. package/dist/utils/mdx-scan.js +27 -1
  777. package/dist/utils/middleware-request-headers.d.ts +7 -6
  778. package/dist/utils/middleware-request-headers.js +6 -1
  779. package/dist/utils/navigation-signal.d.ts +3 -3
  780. package/dist/utils/navigation-signal.js +16 -1
  781. package/dist/utils/number.d.ts +2 -3
  782. package/dist/utils/package-name.d.ts +3 -4
  783. package/dist/utils/parse-cookie.d.ts +4 -5
  784. package/dist/utils/path.d.ts +8 -9
  785. package/dist/utils/plugin-options.d.ts +2 -3
  786. package/dist/utils/precompressed-variant.d.ts +3 -4
  787. package/dist/utils/prerender-output-paths.d.ts +9 -10
  788. package/dist/utils/prerender-output-paths.js +16 -9
  789. package/dist/utils/project.d.ts +19 -30
  790. package/dist/utils/project.js +20 -29
  791. package/dist/utils/promise.d.ts +2 -3
  792. package/dist/utils/protocol-headers.d.ts +14 -15
  793. package/dist/utils/public-file-path.d.ts +2 -3
  794. package/dist/utils/public-routes.d.ts +2 -3
  795. package/dist/utils/query.d.ts +14 -9
  796. package/dist/utils/query.js +22 -1
  797. package/dist/utils/react-compiler-support.d.ts +6 -7
  798. package/dist/utils/react-version.d.ts +4 -3
  799. package/dist/utils/react-version.js +19 -1
  800. package/dist/utils/record.d.ts +2 -3
  801. package/dist/utils/redirect-digest.d.ts +3 -4
  802. package/dist/utils/regex-safety.d.ts +4 -5
  803. package/dist/utils/regex.d.ts +2 -3
  804. package/dist/utils/safe-json-file.d.ts +2 -3
  805. package/dist/utils/sorted-array.d.ts +2 -3
  806. package/dist/utils/text-stream.d.ts +3 -4
  807. package/dist/utils/vinext-root.d.ts +2 -3
  808. package/dist/utils/virtual-module.d.ts +3 -4
  809. package/dist/utils/vite-cli-invocation.d.ts +21 -0
  810. package/dist/utils/vite-cli-invocation.js +144 -0
  811. package/dist/utils/vite-version.d.ts +5 -6
  812. package/next-package.json +4 -0
  813. package/package.json +55 -6
package/dist/index.js CHANGED
@@ -1,33 +1,45 @@
1
1
  import path, { toSlash } from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
2
  import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
3
- import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
4
3
  import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
4
+ import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
5
+ import { claimViteCliBuildInvocation, getViteCliInvocation, isViteCliConfigFile } from "./utils/vite-cli-invocation.js";
6
+ import { VINEXT_DEV_CLI_LIFECYCLE, applyDevServerDefaults, claimViteCliDevInvocation, createDevServerLifecyclePlugin, reserveViteCliDevInvocation } from "./cli-dev-config.js";
7
+ import { isUnknownRecord } from "./utils/record.js";
8
+ import { getReactUpgradeDeps } from "./utils/react-version.js";
9
+ import { loadDotenv } from "./config/dotenv.js";
10
+ import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
11
+ import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
12
+ import { encodeMiddlewareRequestHeaders } from "./utils/middleware-request-headers.js";
13
+ import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
14
+ import { resolveAssetsDir } from "./utils/asset-prefix.js";
15
+ import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
16
+ import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
17
+ import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
5
18
  import { hasBasePath, stripBasePath } from "./utils/base-path.js";
19
+ import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
20
+ import { generateRouteTypes } from "./typegen.js";
6
21
  import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
7
- import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
22
+ import { resolveRuntimeEntryModule } from "./entries/runtime-entry-module.js";
8
23
  import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
9
- import { encodeMiddlewareRequestHeaders } from "./utils/middleware-request-headers.js";
10
24
  import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
11
- import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
12
25
  import { validateMiddlewareMatcherPatterns } from "./server/middleware-matcher-pattern.js";
13
26
  import { methodNotAllowedResponse } from "./server/http-error-responses.js";
14
27
  import { isOpenRedirectShaped } from "./server/open-redirect.js";
15
28
  import { canonicalizeRequestUrlPathname, filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
16
29
  import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
30
+ import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
17
31
  import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
18
32
  import { extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, hasExportedName } from "./build/report.js";
19
- import { generateServerEntry } from "./entries/pages-server-entry.js";
20
- import { generateClientEntry } from "./entries/pages-client-entry.js";
21
- import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
22
- import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
23
- import { isUnknownRecord } from "./utils/record.js";
33
+ import { generatePagesRequestEntry, generatePagesResponseEntry, generateServerEntry } from "./entries/pages-server-entry.js";
34
+ import { compileClientMiddlewareMatchers, generateClientEntry } from "./entries/pages-client-entry.js";
24
35
  import { logRequest, now } from "./server/request-log.js";
25
36
  import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
26
- import { resolveAssetsDir } from "./utils/asset-prefix.js";
27
37
  import { getPagesPreviewModeId } from "./server/pages-preview.js";
28
38
  import { createSSRHandler } from "./server/dev-server.js";
29
39
  import { handleApiRoute } from "./server/api-handler.js";
30
40
  import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
41
+ import { CACHEABILITY_MANIFEST_MODULE, CACHEABILITY_REQUEST_PROJECTION_MODULE } from "./server/cacheability-manifest.js";
42
+ import { PREGENERATED_CONCRETE_PATHS_MODULE } from "./server/pregenerated-concrete-paths.js";
31
43
  import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
32
44
  import { isPathInside, isPathInsideOrEqual, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
33
45
  import { invalidateMetadataFileCache, scanMetadataFiles } from "./server/metadata-routes.js";
@@ -35,24 +47,25 @@ import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
35
47
  import { createDirectRunner } from "./server/dev-module-runner.js";
36
48
  import { validateDevRequest } from "./server/dev-origin-check.js";
37
49
  import { createActionOwnerManifestPlugin } from "./plugins/action-owner-manifest.js";
38
- import { generateRscEntry } from "./entries/app-rsc-entry.js";
50
+ import { generateAppRequestRscEntry, generateAppResponseRscEntry, generateRscEntry } from "./entries/app-rsc-entry.js";
39
51
  import { generateSsrEntry } from "./entries/app-ssr-entry.js";
40
- import { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
52
+ import { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, VIRTUAL_CDN_CACHE_ADAPTER, generateCacheAdaptersModule, generateCdnCacheAdapterModule } from "./cache/cache-adapters-virtual.js";
41
53
  import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
42
54
  import { generateBrowserEntry, toLinkPrefetchRoutes } from "./entries/app-browser-entry.js";
43
55
  import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
44
56
  import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
45
- import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
46
- import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
47
- import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
48
- import { loadDotenv } from "./config/dotenv.js";
49
- import { mergeServerExternalPackages } from "./config/server-external-packages.js";
57
+ import { findOpenTelemetryPackages, mergeServerExternalPackages } from "./config/server-external-packages.js";
50
58
  import { precompressAssets } from "./build/precompress.js";
59
+ import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
60
+ import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
61
+ import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
62
+ import { VINEXT_BUILD_LIFECYCLE_CONFIG, createBuildLifecyclePlugins } from "./build/lifecycle.js";
51
63
  import { ensureAssetsIgnore } from "./build/assets-ignore.js";
52
64
  import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
53
65
  import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
54
66
  import { readTrustedRevalidationHostname } from "./server/revalidation-host.js";
55
67
  import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
68
+ import { traceFrameworkRequest } from "./server/request-tracing.js";
56
69
  import { runPagesRequest } from "./server/pages-request-pipeline.js";
57
70
  import { pagesRouteHasPriorityOverAppRoute, validateHybridRouteConflicts } from "./server/hybrid-route-priority.js";
58
71
  import { hasReactCompilerPlugin, isReactCompilerPlugin, isReactCompilerRequested, reactCompilerUnsupportedMessage } from "./utils/react-compiler-support.js";
@@ -65,31 +78,30 @@ import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
65
78
  import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
66
79
  import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
67
80
  import { createRscReferenceValidationNormalizerPlugin } from "./plugins/rsc-reference-validation-normalizer.js";
68
- import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
81
+ import { createInstrumentationClientTransformPlugin, createInstrumentationServerTransformPlugin } from "./plugins/instrumentation-client.js";
69
82
  import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
70
83
  import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
71
84
  import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
85
+ import { isServerEnvironment } from "./plugins/environment.js";
72
86
  import { createPagesNodeExternalsPlugin } from "./plugins/pages-node-externals.js";
73
87
  import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
74
88
  import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
75
89
  import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
76
90
  import { createDynamicPreloadMetadataPlugin } from "./plugins/dynamic-preload-metadata.js";
91
+ import { createOgHarfbuzzPlugin } from "./plugins/og-harfbuzz.js";
77
92
  import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins/og-assets.js";
78
93
  import { createUseCacheCallablePlugin } from "./plugins/use-cache-callable.js";
79
- import { generateRouteTypes } from "./typegen.js";
80
94
  import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
81
95
  import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
82
96
  import { createTransitiveExternalsPlugin } from "./plugins/transitive-externals.js";
83
97
  import public_shim_map_default from "./shims/public-shim-map.json.js";
84
98
  import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
85
99
  import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
86
- import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
87
- import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
100
+ import { readPrerenderSecret, readServerRuntimeOutputDirs } from "./build/server-manifest.js";
88
101
  import { createModuleDependencyCache } from "./build/module-dependency-cache.js";
89
- import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
90
102
  import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
91
103
  import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter, createSassTsconfigPathImporters } from "./plugins/sass.js";
92
- import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
104
+ import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createMultiStageChunkFileNames, createMultiStageCodeSplittingConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
93
105
  import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
94
106
  import { removeConsoleCalls } from "./plugins/remove-console.js";
95
107
  import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
@@ -105,15 +117,15 @@ import { publicFilePathVariants } from "./utils/public-file-path.js";
105
117
  import { scanPublicFileRoutes } from "./utils/public-routes.js";
106
118
  import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
107
119
  import { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine } from "./utils/vite-version.js";
108
- import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
109
120
  import { staticExportApp, staticExportPages } from "./build/static-export.js";
110
121
  import { createRequire } from "node:module";
111
122
  import fs from "node:fs";
112
- import { createIdResolver, createLogger, parseAst, transformWithOxc } from "vite";
113
123
  import { pathToFileURL } from "node:url";
124
+ import { createIdResolver, createLogger, isRunnableDevEnvironment, parseAst, transformWithOxc } from "vite";
125
+ import { execFileSync } from "node:child_process";
114
126
  import { createHash, randomBytes } from "node:crypto";
115
- import commonjs from "vite-plugin-commonjs";
116
127
  import MagicString from "magic-string";
128
+ import commonjs from "vite-plugin-commonjs";
117
129
  //#region src/index.ts
118
130
  const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE = Object.freeze(["vinext/server/fetch-handler", "vinext/server/pages-router-entry"]);
119
131
  const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
@@ -127,6 +139,30 @@ const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
127
139
  const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-sync-external-store\/with-selector.*present in .* 'optimizeDeps\.include'/;
128
140
  const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
129
141
  const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
142
+ const RSC_ENVIRONMENTS = /* @__PURE__ */ new Set([
143
+ "rsc",
144
+ "ssr",
145
+ "client"
146
+ ]);
147
+ function scopeRscPlugin(plugin) {
148
+ const applyToEnvironment = plugin.applyToEnvironment;
149
+ return {
150
+ ...plugin,
151
+ applyToEnvironment(environment) {
152
+ if (!RSC_ENVIRONMENTS.has(environment.name)) return false;
153
+ return applyToEnvironment?.(environment) ?? true;
154
+ }
155
+ };
156
+ }
157
+ const earlyViteCliInvocation = getViteCliInvocation();
158
+ const viteCliBuildConfigNodeEnv = earlyViteCliInvocation?.command === "build" && process.env.NODE_ENV === "test" ? "test" : void 0;
159
+ if (earlyViteCliInvocation) {
160
+ if (!process.env.NODE_ENV) Reflect.set(process.env, "NODE_ENV", earlyViteCliInvocation.command === "build" ? viteCliBuildConfigNodeEnv ?? "production" : earlyViteCliInvocation.mode === "test" ? "test" : "development");
161
+ loadDotenv({
162
+ root: earlyViteCliInvocation.root,
163
+ mode: earlyViteCliInvocation.mode
164
+ });
165
+ }
130
166
  installSocketErrorBackstop();
131
167
  function hasServerOnlyMarkerImport(code) {
132
168
  if (!code.includes("server-only")) return false;
@@ -181,6 +217,7 @@ function resolveShimModulePath(shimsDir, moduleName) {
181
217
  }
182
218
  return path.join(shimsDir, `${moduleName}.js`);
183
219
  }
220
+ const PATCHED_SERVER_PACKAGES = ["@vercel/og"];
184
221
  function isVercelOgImport(id) {
185
222
  return id === "@vercel/og" || id === "@vercel/og.js";
186
223
  }
@@ -310,7 +347,7 @@ function createDevPagesModuleDependencyReader(root, resolve) {
310
347
  if (typeof specifier !== "string") continue;
311
348
  const resolved = await resolve(specifier, cleanModulePath, { skipSelf: true });
312
349
  if (!resolved?.id) continue;
313
- if (isStylesheetSpecifier(specifier)) {
350
+ if (isStylesheetSpecifier(specifier) || isStylesheetSpecifier(resolved.id)) {
314
351
  const asset = resolvedStylesheetToDevManifestAsset(root, resolved.id);
315
352
  if (asset) dependencies.push({
316
353
  type: "stylesheet",
@@ -595,8 +632,8 @@ const tsconfigAliasCustomResolver = async function(updatedId, importer, options)
595
632
  * stylesheet-scoping resolver to entries that came from tsconfig `paths`.
596
633
  * Array order preserves the map's first-match ordering.
597
634
  */
598
- function buildResolveAliasEntries(aliasMap, tsconfigPathAliases) {
599
- return Object.entries(aliasMap).map(([find, replacement]) => tsconfigPathAliases[find] === replacement ? {
635
+ function buildResolveAliasEntries(aliasMap, tsconfigPathAliases, explicitAliases) {
636
+ return Object.entries(aliasMap).map(([find, replacement]) => Object.hasOwn(tsconfigPathAliases, find) && !Object.hasOwn(explicitAliases, find) ? {
600
637
  find,
601
638
  replacement,
602
639
  customResolver: tsconfigAliasCustomResolver
@@ -619,24 +656,49 @@ function suppressAliasCustomResolverDeprecationWarning(logger) {
619
656
  return logger;
620
657
  }
621
658
  const VIRTUAL_WORKER_ENTRY = "virtual:vinext-worker-entry";
622
- const RESOLVED_WORKER_ENTRY = "\0virtual:vinext-worker-entry";
659
+ const RESOLVED_WORKER_ENTRY = "\0" + VIRTUAL_WORKER_ENTRY;
660
+ const VIRTUAL_REQUEST_STAGE = "virtual:vinext-request-stage";
661
+ const RESOLVED_REQUEST_STAGE = "\0" + VIRTUAL_REQUEST_STAGE;
662
+ const VIRTUAL_RESPONSE_STAGE = "virtual:vinext-response-stage";
663
+ const RESOLVED_RESPONSE_STAGE = "\0" + VIRTUAL_RESPONSE_STAGE;
623
664
  const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
624
- const RESOLVED_SERVER_ENTRY = "\0virtual:vinext-server-entry";
665
+ const RESOLVED_SERVER_ENTRY = "\0" + VIRTUAL_SERVER_ENTRY;
666
+ const VIRTUAL_PAGES_REQUEST_ENTRY = "virtual:vinext-pages-request-entry";
667
+ const RESOLVED_PAGES_REQUEST_ENTRY = "\0" + VIRTUAL_PAGES_REQUEST_ENTRY;
668
+ const VIRTUAL_PAGES_RESPONSE_ENTRY = "virtual:vinext-pages-response-entry";
669
+ const RESOLVED_PAGES_RESPONSE_ENTRY = "\0" + VIRTUAL_PAGES_RESPONSE_ENTRY;
625
670
  const VIRTUAL_CLIENT_ENTRY = "virtual:vinext-client-entry";
626
- const RESOLVED_CLIENT_ENTRY = "\0virtual:vinext-client-entry";
671
+ const RESOLVED_CLIENT_ENTRY = "\0" + VIRTUAL_CLIENT_ENTRY;
627
672
  const VIRTUAL_PAGES_CLIENT_ASSETS = "virtual:vinext-pages-client-assets";
628
- const RESOLVED_PAGES_CLIENT_ASSETS = "\0virtual:vinext-pages-client-assets";
673
+ const RESOLVED_PAGES_CLIENT_ASSETS = "\0" + VIRTUAL_PAGES_CLIENT_ASSETS;
629
674
  const VIRTUAL_RSC_ENTRY = "virtual:vinext-rsc-entry";
630
- const RESOLVED_RSC_ENTRY = "\0virtual:vinext-rsc-entry";
675
+ const RESOLVED_RSC_ENTRY = "\0" + VIRTUAL_RSC_ENTRY;
676
+ const VIRTUAL_CACHEABILITY_MANIFEST = "virtual:vinext-cacheability-manifest";
677
+ const RESOLVED_CACHEABILITY_MANIFEST = "\0" + VIRTUAL_CACHEABILITY_MANIFEST;
678
+ const VIRTUAL_CACHEABILITY_REQUEST_PROJECTION = "virtual:vinext-cacheability-request-projection";
679
+ const RESOLVED_CACHEABILITY_REQUEST_PROJECTION = "\0" + VIRTUAL_CACHEABILITY_REQUEST_PROJECTION;
680
+ const VIRTUAL_PREGENERATED_CONCRETE_PATHS = "virtual:vinext-pregenerated-concrete-paths";
681
+ const RESOLVED_PREGENERATED_CONCRETE_PATHS = "\0" + VIRTUAL_PREGENERATED_CONCRETE_PATHS;
682
+ const VIRTUAL_APP_REQUEST_ENTRY = "virtual:vinext-app-request-entry";
683
+ const RESOLVED_APP_REQUEST_ENTRY = "\0" + VIRTUAL_APP_REQUEST_ENTRY;
684
+ const VIRTUAL_APP_RESPONSE_ENTRY = "virtual:vinext-app-response-entry";
685
+ const RESOLVED_APP_RESPONSE_ENTRY = "\0" + VIRTUAL_APP_RESPONSE_ENTRY;
631
686
  const VIRTUAL_APP_SSR_ENTRY = "virtual:vinext-app-ssr-entry";
632
- const RESOLVED_APP_SSR_ENTRY = "\0virtual:vinext-app-ssr-entry";
687
+ const RESOLVED_APP_SSR_ENTRY = "\0" + VIRTUAL_APP_SSR_ENTRY;
633
688
  const VIRTUAL_APP_BROWSER_ENTRY = "virtual:vinext-app-browser-entry";
634
- const RESOLVED_APP_BROWSER_ENTRY = "\0virtual:vinext-app-browser-entry";
689
+ const RESOLVED_APP_BROWSER_ENTRY = "\0" + VIRTUAL_APP_BROWSER_ENTRY;
635
690
  const VIRTUAL_APP_CAPABILITIES = "virtual:vinext-app-capabilities";
636
- const RESOLVED_APP_CAPABILITIES = "\0virtual:vinext-app-capabilities";
691
+ const RESOLVED_APP_CAPABILITIES = "\0" + VIRTUAL_APP_CAPABILITIES;
637
692
  const RESOLVED_ROOT_PARAMS = "\0virtual:vinext-root-params";
693
+ const APP_REQUEST_STAGE_ENTRY = resolveRuntimeEntryModule("app-request-stage-independent-entry");
694
+ const APP_RESPONSE_STAGE_ENTRY = resolveRuntimeEntryModule("app-response-stage-entry");
695
+ const PAGES_REQUEST_STAGE_ENTRY = resolveRuntimeEntryModule("pages-request-stage-entry");
696
+ const PAGES_RESPONSE_STAGE_ENTRY = resolveRuntimeEntryModule("pages-response-stage-entry");
697
+ const WORKER_ROUTER_ENTRIES = /* @__PURE__ */ new Set([resolveRuntimeEntryModule("app-router-entry"), resolveRuntimeEntryModule("pages-router-entry")]);
638
698
  /** Virtual module that registers config-driven cache adapters (see VinextOptions.cache). */
639
699
  const RESOLVED_CACHE_ADAPTERS = "\0" + VIRTUAL_CACHE_ADAPTERS;
700
+ /** CDN-only registrar kept out of the data-cache response graph. */
701
+ const RESOLVED_CDN_CACHE_ADAPTER = "\0" + VIRTUAL_CDN_CACHE_ADAPTER;
640
702
  /** Virtual module that registers the config-driven image optimizer (see VinextOptions.images). */
641
703
  const RESOLVED_IMAGE_ADAPTERS = "\0" + VIRTUAL_IMAGE_ADAPTERS;
642
704
  /** Virtual module for composed instrumentation-client bootstrap. */
@@ -667,9 +729,10 @@ const _shimsDir = path.resolve(__dirname, "shims") + "/";
667
729
  const _serverDir = path.resolve(__dirname, "server");
668
730
  const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
669
731
  const _appBrowserServerActionClientPath = resolveShimModulePath(_serverDir, "app-browser-server-action-client");
732
+ const _appRscCombinedHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-combined-handler");
670
733
  const _appRscHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-handler");
671
734
  const _pagesClientAssetsPath = resolveShimModulePath(_serverDir, "pages-client-assets");
672
- const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js");
735
+ const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js") && _appRscCombinedHandlerPath.endsWith(".js");
673
736
  function isValidExportIdentifier(name) {
674
737
  return /^[$A-Z_a-z][$\w]*$/.test(name);
675
738
  }
@@ -741,8 +804,10 @@ for (const [specifier, definition] of Object.entries(_publicNextShimMap)) {
741
804
  _reactServerShims.set(`${specifier}.js`, definition.shim);
742
805
  }
743
806
  _reactServerShims.set("next/dist/client/components/navigation", "navigation");
744
- const clientCodeSplittingConfig = createClientCodeSplittingConfig(createClientManualChunks(_shimsDir));
745
- const appClientCodeSplittingConfig = createClientCodeSplittingConfig(createClientManualChunks(_shimsDir, true));
807
+ const clientManualChunks = createClientManualChunks(_shimsDir);
808
+ const clientCodeSplittingConfig = createClientCodeSplittingConfig(clientManualChunks);
809
+ const appClientManualChunks = createClientManualChunks(_shimsDir, true);
810
+ const appClientCodeSplittingConfig = createClientCodeSplittingConfig(appClientManualChunks);
746
811
  function getClientOutputConfig(assetsDir, preserveAppRouteBoundaries = false) {
747
812
  const codeSplitting = preserveAppRouteBoundaries ? appClientCodeSplittingConfig : clientCodeSplittingConfig;
748
813
  return {
@@ -767,8 +832,11 @@ function createServerEnvironmentFileNameResolver(config, outputRoot) {
767
832
  };
768
833
  }
769
834
  function vinext(options = {}) {
835
+ const internalOptions = options;
770
836
  const { supportsNativeTypeofWindowFolding: useNativeTypeofWindowFolding } = assertSupportedViteVersion();
837
+ const reservedDevCliInvocation = reserveViteCliDevInvocation();
771
838
  const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
839
+ const cacheAdapterBuildOutputs = [options.cache?.data?.output, options.cache?.cdn?.output].filter((output) => output !== void 0);
772
840
  let root;
773
841
  let pagesDir;
774
842
  let canonicalPagesDir;
@@ -776,6 +844,7 @@ function vinext(options = {}) {
776
844
  let hasAppDir = false;
777
845
  let hasPagesDir = false;
778
846
  let nextConfig;
847
+ let nitroBuildDir;
779
848
  let fileMatcher;
780
849
  let middlewarePath = null;
781
850
  let instrumentationPath = null;
@@ -784,12 +853,23 @@ function vinext(options = {}) {
784
853
  let globalNotFoundCssIsolationPath = null;
785
854
  let clientAssetsInlineLimit = 0;
786
855
  let hasCloudflarePlugin = false;
856
+ let matchedMultiStageOutput;
857
+ let selectedMultiStageOutput;
858
+ const isMultiStageServerEnvironment = (environment) => isServerEnvironment(environment) && (!hasAppDir || environment.name === "rsc");
787
859
  let warnedInlineNextConfigOverride = false;
788
860
  let hasNitroPlugin = false;
861
+ let nitroHostRuntime = "node";
789
862
  let resolvedServerExternalPackages = [];
863
+ let registerNodeOpenTelemetryLoader = false;
790
864
  let pagesTsconfigAliases = {};
791
865
  let pagesBundledPackages = /* @__PURE__ */ new Set();
792
866
  let isServeCommand = false;
867
+ let buildEmptyOutDir;
868
+ let buildLifecycleEnabled = false;
869
+ let hasPlainPagesBuildEnvironments = false;
870
+ let originalPlainPagesEnvironments;
871
+ let buildLifecycleInvocation;
872
+ let reactUpgradeChecked = false;
793
873
  let pagesOptimizeEntries = [];
794
874
  const importMetaUrlCapability = createImportMetaUrlPlugin({
795
875
  getRoot: () => root,
@@ -799,16 +879,32 @@ function vinext(options = {}) {
799
879
  }
800
880
  });
801
881
  const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
802
- let pagesClientAssetsModule = null;
882
+ const resolvePagesClientAssetsOutputDir = (environmentName, outputDir) => !selectedMultiStageOutput && !hasAppDir && !hasCloudflarePlugin && environmentName === "ssr" ? path.dirname(outputDir) : outputDir;
883
+ let pagesClientAssetsModule = internalOptions.__pagesClientAssetsModule ?? null;
803
884
  let devPublicFileRoutes = null;
804
885
  let publicDirConflictOptions = null;
886
+ let copyPublicDirIntoStaticExportBasePath = false;
887
+ let rscBuildIdentity;
805
888
  let rscCompatibilityId;
806
889
  let draftModeSecret = getPagesPreviewModeId();
890
+ const prerenderSecret = process.env.__VINEXT_SHARED_PRERENDER_SECRET ?? randomBytes(32).toString("hex");
891
+ let revalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
807
892
  let previewBuildCredentials;
808
893
  const sassComposesLoader = createSassAwareFileSystemLoader();
809
- let rscClassificationManifest = null;
894
+ const rscClassificationManifests = /* @__PURE__ */ new Map();
810
895
  let rscActionOwnerRoutes = null;
811
896
  let rscActionOwnerSharedRoots = [];
897
+ const serverEntryKindsByEnvironment = /* @__PURE__ */ new Map();
898
+ const serverRuntimeOutputDirs = /* @__PURE__ */ new Set();
899
+ function recordServerEntryLoad(environmentName, id) {
900
+ if (!environmentName) return;
901
+ let entries = serverEntryKindsByEnvironment.get(environmentName);
902
+ if (!entries) {
903
+ entries = /* @__PURE__ */ new Set();
904
+ serverEntryKindsByEnvironment.set(environmentName, entries);
905
+ }
906
+ entries.add(id);
907
+ }
812
908
  const shimsDir = path.resolve(__dirname, "shims");
813
909
  const canonicalize = (p) => toSlash(tryRealpathSync(p) ?? p);
814
910
  const pageTransformCanonicalPaths = /* @__PURE__ */ new Map();
@@ -836,7 +932,17 @@ function vinext(options = {}) {
836
932
  */
837
933
  async function generateServerEntry$1(configuredPublicDir) {
838
934
  const publicFiles = isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, configuredPublicDir === "" ? false : configuredPublicDir);
839
- return generateServerEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles);
935
+ return generateServerEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles, {
936
+ nodeOpenTelemetryLoader: registerNodeOpenTelemetryLoader,
937
+ prerenderSecret
938
+ });
939
+ }
940
+ async function generatePagesRequestEntry$1(configuredPublicDir) {
941
+ const publicFiles = isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, configuredPublicDir === "" ? false : configuredPublicDir);
942
+ return generatePagesRequestEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles, prerenderSecret);
943
+ }
944
+ function generatePagesResponseEntry$1() {
945
+ return generatePagesResponseEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, prerenderSecret);
840
946
  }
841
947
  /**
842
948
  * Generate the virtual client hydration entry module.
@@ -863,7 +969,8 @@ function vinext(options = {}) {
863
969
  });
864
970
  }
865
971
  const autoRsc = options.rsc !== false;
866
- const earlyBaseDir = options.appDir ?? process.cwd();
972
+ const earlyRoot = earlyViteCliInvocation?.root ?? process.cwd();
973
+ const earlyBaseDir = path.resolve(earlyRoot, options.appDir ?? ".");
867
974
  const earlyAppDirExists = !options.disableAppRouter && (fs.existsSync(path.join(earlyBaseDir, "app")) || fs.existsSync(path.join(earlyBaseDir, "src", "app")));
868
975
  let resolvedReactPath = null;
869
976
  let resolvedRscPath = null;
@@ -885,14 +992,12 @@ function vinext(options = {}) {
885
992
  } });
886
993
  const useCachePlugin = await createUseCacheCallablePlugin({
887
994
  projectRoot: earlyBaseDir,
888
- cacheRuntime: pathToFileURL(resolveShimModulePath(shimsDir, "cache-callable-runtime")).href,
889
- getAppDir: () => appDir,
890
- matchesPageExtension: (fileName) => fileMatcher.extensionRegex.test(fileName)
995
+ cacheRuntime: pathToFileURL(resolveShimModulePath(shimsDir, "cache-callable-runtime")).href
891
996
  });
892
997
  const useServerIndex = plugins.findIndex((plugin) => plugin.name === "rsc:use-server");
893
998
  if (useServerIndex === -1) throw new Error("vinext: Failed to locate @vitejs/plugin-rsc use-server plugin.");
894
999
  plugins.splice(useServerIndex, 0, useCachePlugin);
895
- return plugins;
1000
+ return plugins.map(scopeRscPlugin);
896
1001
  }).catch((cause) => {
897
1002
  throw new Error("vinext: Failed to load @vitejs/plugin-rsc.", { cause });
898
1003
  });
@@ -901,8 +1006,6 @@ function vinext(options = {}) {
901
1006
  manualUseCachePluginPromise = createUseCacheCallablePlugin({
902
1007
  projectRoot: earlyBaseDir,
903
1008
  cacheRuntime: pathToFileURL(resolveShimModulePath(shimsDir, "cache-callable-runtime")).href,
904
- getAppDir: () => appDir,
905
- matchesPageExtension: (fileName) => fileMatcher.extensionRegex.test(fileName),
906
1009
  allowMissingRsc: true
907
1010
  });
908
1011
  }
@@ -969,9 +1072,10 @@ function vinext(options = {}) {
969
1072
  }
970
1073
  const delegate = mdxFactory(mdxOpts);
971
1074
  mdxDelegate = delegate;
972
- if (reason === "detected") if (nextConfig.mdx) console.log("[vinext] Auto-injected @mdx-js/rollup with remark/rehype plugins from next.config");
973
- else console.log("[vinext] Auto-injected @mdx-js/rollup for MDX support");
974
- else console.log("[vinext] Auto-injected @mdx-js/rollup for on-demand MDX support");
1075
+ if (reason === "detected") {
1076
+ if (nextConfig.mdx) console.log("[vinext] Auto-injected @mdx-js/rollup with remark/rehype plugins from next.config");
1077
+ else console.log("[vinext] Auto-injected @mdx-js/rollup for MDX support");
1078
+ } else console.log("[vinext] Auto-injected @mdx-js/rollup for on-demand MDX support");
975
1079
  return delegate;
976
1080
  } catch {
977
1081
  if (reason === "detected" && !warnedMissingMdxPlugin) {
@@ -1018,6 +1122,10 @@ function vinext(options = {}) {
1018
1122
  } });
1019
1123
  const commonJsTransform = commonJsPlugin.transform;
1020
1124
  if (typeof commonJsTransform === "function") commonJsPlugin.transform = function environmentAwareCommonJsTransform(code, id, ...args) {
1125
+ const normalizedId = toSlash(stripViteModuleQuery(id));
1126
+ const nitroServicePath = this.environment.name === "nitro" && nitroBuildDir && normalizedId.endsWith("/entry.js") ? path.relative(path.join(canonicalize(nitroBuildDir), "vite/services"), normalizedId) : "";
1127
+ if (/^[^/]+\/entry\.js$/.test(nitroServicePath)) return null;
1128
+ if (isPathInside(__dirname, toSlash(stripViteModuleQuery(id)))) return null;
1021
1129
  if (this.environment.mode === "dev" && this.environment.depsOptimizer?.isOptimizedDepFile(id)) return null;
1022
1130
  const isDev = this.environment.mode === "dev";
1023
1131
  const isServer = this.environment.config.consumer === "server";
@@ -1034,7 +1142,59 @@ function vinext(options = {}) {
1034
1142
  transformBundledCommonJsDependencies = previous;
1035
1143
  }
1036
1144
  };
1145
+ const buildLifecyclePlugins = createBuildLifecyclePlugins({
1146
+ isEnabled: (builder) => buildLifecycleEnabled && builder.config.build.write !== false && !builder.config.build.lib && (buildLifecycleInvocation !== void 0 || !builder.config.build.watch && !builder.config.build.ssr && getBuildBundlerOptions(builder.config.build)?.input === void 0),
1147
+ onComplete: () => buildLifecycleInvocation?.onComplete?.(),
1148
+ shouldDeferPostBuild: () => buildLifecycleInvocation !== void 0,
1149
+ shouldPrepare: (config) => buildLifecycleEnabled && config.build?.write !== false && !config.build?.lib && (buildLifecycleInvocation !== void 0 || !config.build?.watch && !config.build?.ssr && getBuildBundlerOptions(config.build)?.input === void 0),
1150
+ onPrepare: () => {
1151
+ if (!hasAppDir || reactUpgradeChecked) return;
1152
+ reactUpgradeChecked = true;
1153
+ const reactUpgrade = getReactUpgradeDeps(root);
1154
+ if (reactUpgrade.length === 0) return;
1155
+ const [packageManager, ...packageManagerArgs] = detectPackageManager(root).replace(/ -D$/, "").split(" ");
1156
+ console.log(" Upgrading React for RSC compatibility...");
1157
+ execFileSync(packageManager, [...packageManagerArgs, ...reactUpgrade], {
1158
+ cwd: root,
1159
+ stdio: "inherit",
1160
+ shell: process.platform === "win32"
1161
+ });
1162
+ },
1163
+ shouldBuildPlainPages: () => !hasAppDir && !hasCloudflarePlugin && !hasNitroPlugin,
1164
+ createContext: () => ({
1165
+ cacheConfig: options.cache ?? null,
1166
+ configNodeEnv: viteCliBuildConfigNodeEnv,
1167
+ createPagesOnlyPlugins: (pagesClientAssetsModule) => vinext({
1168
+ ...options,
1169
+ disableAppRouter: true,
1170
+ precompress: false,
1171
+ prerender: void 0,
1172
+ __skipBuildLifecycle: true,
1173
+ __pagesClientAssetsModule: pagesClientAssetsModule
1174
+ }),
1175
+ emptyOutDir: buildEmptyOutDir,
1176
+ hasAppDir,
1177
+ hasPagesDir,
1178
+ nextConfig,
1179
+ prerenderConfig,
1180
+ prerenderConcurrency: prerenderConfig?.concurrency,
1181
+ prerenderSecret,
1182
+ previewBuildCredentials,
1183
+ revalidateSecret,
1184
+ root,
1185
+ routeRootConfig: {
1186
+ appDir: options.appDir,
1187
+ disableAppRouter: options.disableAppRouter,
1188
+ rscOutDir: options.rscOutDir,
1189
+ ssrOutDir: options.ssrOutDir
1190
+ },
1191
+ rscBuildIdentity,
1192
+ rscCompatibilityId,
1193
+ skipHybridPagesBundle: hasCloudflarePlugin
1194
+ })
1195
+ });
1037
1196
  const plugins = [
1197
+ buildLifecyclePlugins[0],
1038
1198
  createStyledJsxPlugin(earlyBaseDir),
1039
1199
  mdxProxyPlugin,
1040
1200
  reactPluginPromise,
@@ -1101,6 +1261,7 @@ function vinext(options = {}) {
1101
1261
  }),
1102
1262
  dataUrlCssPlugin(),
1103
1263
  createCssModuleImportCompatibilityPlugin(),
1264
+ createDevServerLifecyclePlugin({}, (config) => config[VINEXT_DEV_CLI_LIFECYCLE] === true),
1104
1265
  {
1105
1266
  name: "vinext:config",
1106
1267
  enforce: "pre",
@@ -1108,33 +1269,48 @@ function vinext(options = {}) {
1108
1269
  [VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY]: options.nextConfig ?? null,
1109
1270
  [VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY]: {
1110
1271
  appDir: options.appDir,
1272
+ clientOutDir: options.clientOutDir,
1111
1273
  disableAppRouter: options.disableAppRouter,
1112
1274
  rscOutDir: options.rscOutDir,
1113
1275
  ssrOutDir: options.ssrOutDir
1114
1276
  },
1115
1277
  [VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY]: options.cache ?? null,
1116
1278
  async config(config, env) {
1279
+ hasPlainPagesBuildEnvironments = false;
1280
+ originalPlainPagesEnvironments = void 0;
1281
+ buildEmptyOutDir = typeof config.build?.emptyOutDir === "boolean" ? config.build.emptyOutDir : void 0;
1117
1282
  isServeCommand = env.command === "serve";
1118
- root = toSlash(config.root ?? process.cwd());
1283
+ root = path.resolve(toSlash(process.cwd()), config.root ?? ".");
1284
+ const devCliLifecycleEnabled = env.command === "serve" && env.isPreview !== true && claimViteCliDevInvocation(root, config["__vinextDevRestart"] === true, reservedDevCliInvocation && config.configFile === false);
1285
+ buildLifecycleInvocation = config[VINEXT_BUILD_LIFECYCLE_CONFIG];
1286
+ buildLifecycleEnabled = env.command === "build" && !internalOptions.__skipBuildLifecycle && (buildLifecycleInvocation !== void 0 || claimViteCliBuildInvocation());
1119
1287
  const userResolve = config.resolve;
1120
1288
  let tsconfigPathAliases = {};
1121
1289
  let sassTsconfigPathAliases = [];
1122
1290
  const swcHelpersAlias = resolveSwcHelpersAlias(root);
1123
1291
  const mode = env?.mode ?? "development";
1124
- if (config.envDir !== false) loadDotenv({
1125
- root: config.envDir ?? root,
1126
- mode
1127
- });
1292
+ if (config.envDir !== false) {
1293
+ const envDir = config.envDir ?? root;
1294
+ loadDotenv({
1295
+ root: envDir,
1296
+ mode
1297
+ });
1298
+ }
1128
1299
  let resolvedNodeEnv;
1129
1300
  if (env?.command === "build" || env?.isPreview === true) resolvedNodeEnv = "production";
1130
1301
  else if (mode === "test") resolvedNodeEnv = "test";
1131
1302
  else resolvedNodeEnv = "development";
1132
- if (process.env.NODE_ENV !== resolvedNodeEnv) Reflect.set(process.env, "NODE_ENV", resolvedNodeEnv);
1133
- if (env?.command === "build") previewBuildCredentials = getPreviewBuildCredentials() ?? createPreviewBuildCredentials();
1303
+ if (!(process.env.NODE_ENV === "test" && viteCliBuildConfigNodeEnv === "test") && process.env.NODE_ENV !== resolvedNodeEnv) Reflect.set(process.env, "NODE_ENV", resolvedNodeEnv);
1304
+ if (env?.command === "build") {
1305
+ previewBuildCredentials = getPreviewBuildCredentials() ?? createPreviewBuildCredentials();
1306
+ if (buildLifecycleEnabled) revalidateSecret ??= randomBytes(32).toString("hex");
1307
+ }
1134
1308
  draftModeSecret = previewBuildCredentials?.id ?? getPagesPreviewModeId();
1135
1309
  let baseDir;
1136
- if (options.appDir) baseDir = toSlash(path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir));
1137
- else {
1310
+ if (options.appDir) {
1311
+ const dir = path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir);
1312
+ baseDir = toSlash(dir);
1313
+ } else {
1138
1314
  const hasRootApp = fs.existsSync(path.join(root, "app"));
1139
1315
  const hasRootPages = fs.existsSync(path.join(root, "pages"));
1140
1316
  const hasSrcApp = fs.existsSync(path.join(root, "src", "app"));
@@ -1168,6 +1344,7 @@ function vinext(options = {}) {
1168
1344
  buildId: sharedBuildId
1169
1345
  };
1170
1346
  }
1347
+ if (env?.command === "build" && earlyViteCliInvocation?.command === "build") Reflect.set(process.env, "NODE_ENV", "production");
1171
1348
  const configuredTsconfigPath = isUnknownRecord(nextConfig.typescript) ? typeof nextConfig.typescript.tsconfigPath === "string" ? nextConfig.typescript.tsconfigPath : void 0 : void 0;
1172
1349
  const resolvedTsconfigAliases = resolveTsconfigAliases(root, configuredTsconfigPath);
1173
1350
  tsconfigPathAliases = resolvedTsconfigAliases.vite;
@@ -1179,6 +1356,10 @@ function vinext(options = {}) {
1179
1356
  const sharedRscCompatibilityId = process.env.__VINEXT_SHARED_RSC_COMPATIBILITY_ID;
1180
1357
  rscCompatibilityId = sharedRscCompatibilityId && sharedRscCompatibilityId.length > 0 ? sharedRscCompatibilityId : createRscCompatibilityId(nextConfig);
1181
1358
  }
1359
+ if (env?.command === "build" && rscBuildIdentity === void 0) {
1360
+ const sharedRscBuildIdentity = process.env.__VINEXT_SHARED_RSC_BUILD_IDENTITY;
1361
+ rscBuildIdentity = sharedRscBuildIdentity && sharedRscBuildIdentity.length > 0 ? sharedRscBuildIdentity : randomBytes(16).toString("hex");
1362
+ }
1182
1363
  fileMatcher = createValidFileMatcher(nextConfig.pageExtensions);
1183
1364
  globalNotFoundCssIsolationPath = env?.command === "build" && nextConfig.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
1184
1365
  instrumentationPath = findInstrumentationFile(root, fileMatcher);
@@ -1215,6 +1396,7 @@ function vinext(options = {}) {
1215
1396
  defines["process.env.__NEXT_TEST_MODE"] = JSON.stringify(process.env.__NEXT_TEST_MODE ?? false);
1216
1397
  defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
1217
1398
  defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
1399
+ defines["process.env.__NEXT_CONFIG_OUTPUT"] = JSON.stringify(nextConfig.output ?? "");
1218
1400
  defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
1219
1401
  defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
1220
1402
  {
@@ -1238,6 +1420,7 @@ function vinext(options = {}) {
1238
1420
  defines["process.env.__VINEXT_IMAGE_UNOPTIMIZED"] = JSON.stringify(String(nextConfig.images?.unoptimized === true));
1239
1421
  defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
1240
1422
  defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
1423
+ defines["process.env.__VINEXT_RSC_BUILD_IDENTITY"] = JSON.stringify(rscBuildIdentity ?? "");
1241
1424
  defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
1242
1425
  defines["process.env.NEXT_DEPLOYMENT_ID"] = nextConfig.deploymentId ? JSON.stringify(nextConfig.deploymentId) : "false";
1243
1426
  defines["process.env.NEXT_RUNTIME"] = "\"\"";
@@ -1293,6 +1476,9 @@ function vinext(options = {}) {
1293
1476
  }
1294
1477
  flattenPlugins(config.plugins ?? []);
1295
1478
  hasCloudflarePlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "vite-plugin-cloudflare" || p.name.startsWith("vite-plugin-cloudflare:")));
1479
+ const configuredMultiStageOutput = options.cache?.cdn?.output;
1480
+ matchedMultiStageOutput = configuredMultiStageOutput?.type === "multi-stage" && (configuredMultiStageOutput.matchesBuild?.({ plugins: pluginsFlat }) ?? true) ? configuredMultiStageOutput : void 0;
1481
+ selectedMultiStageOutput = isServeCommand ? void 0 : matchedMultiStageOutput;
1296
1482
  hasNitroPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "nitro" || p.name.startsWith("nitro:")));
1297
1483
  let postcssOverride;
1298
1484
  if (!config.css?.postcss || typeof config.css.postcss === "string") postcssOverride = await resolvePostcssStringPlugins(root);
@@ -1302,11 +1488,20 @@ function vinext(options = {}) {
1302
1488
  const isSSR = !!config.build?.ssr;
1303
1489
  const serverTranspilePackages = [...nextConfig?.turbopackTranspilePackages ?? [], ...nextConfig?.optimizePackageImports ?? []];
1304
1490
  pagesBundledPackages = new Set(serverTranspilePackages);
1305
- const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages);
1491
+ const openTelemetryPackages = findOpenTelemetryPackages(root);
1492
+ registerNodeOpenTelemetryLoader = env.command === "build" && !hasCloudflarePlugin && !hasNitroPlugin && instrumentationPath !== null && openTelemetryPackages.includes("@opentelemetry/instrumentation") && !serverTranspilePackages.includes("@opentelemetry/instrumentation") && (() => {
1493
+ try {
1494
+ createRequire(path.join(root, "package.json")).resolve("@opentelemetry/instrumentation/hook.mjs");
1495
+ return true;
1496
+ } catch {
1497
+ return false;
1498
+ }
1499
+ })();
1500
+ const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages, openTelemetryPackages);
1306
1501
  resolvedServerExternalPackages = nextServerExternal;
1307
1502
  const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
1308
1503
  const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
1309
- const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
1504
+ const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput && !config.build?.lib;
1310
1505
  const hasClientBuildEnvironment = hasAppDir || hasCloudflarePlugin || hasNitroPlugin || shouldInjectPlainPagesEnvironments;
1311
1506
  const clientAssetsDir = resolveAssetsDir(nextConfig.assetPrefix ?? "");
1312
1507
  clientAssetsInlineLimit = config.build?.assetsInlineLimit ?? 0;
@@ -1315,8 +1510,22 @@ function vinext(options = {}) {
1315
1510
  overlay: false
1316
1511
  };
1317
1512
  const cssModulesOverride = config.css?.modules === false || typeof config.css?.modules === "object" && "Loader" in config.css.modules ? {} : { modules: { Loader: sassComposesLoader.Loader } };
1513
+ const explicitViteAliases = config.resolve?.alias;
1514
+ const userAliasEntries = Array.isArray(explicitViteAliases) ? explicitViteAliases : Object.entries(explicitViteAliases ?? {}).map(([find, replacement]) => ({
1515
+ find,
1516
+ replacement
1517
+ }));
1518
+ if (config.resolve) {
1519
+ config.resolve = { ...config.resolve };
1520
+ delete config.resolve.alias;
1521
+ }
1318
1522
  const viteConfig = {
1319
1523
  appType: "custom",
1524
+ ...devCliLifecycleEnabled ? { [VINEXT_DEV_CLI_LIFECYCLE]: true } : {},
1525
+ ...!hasAppDir && hasCloudflarePlugin ? { builder: {
1526
+ ...config.builder,
1527
+ sharedConfigBuild: true
1528
+ } } : {},
1320
1529
  build: {
1321
1530
  ssrEmitAssets: true,
1322
1531
  cssTarget: [
@@ -1350,7 +1559,10 @@ function vinext(options = {}) {
1350
1559
  },
1351
1560
  hmr: devHmrConfig
1352
1561
  },
1353
- ...hasCloudflarePlugin || hasNitroPlugin ? {} : config.ssr?.external === true ? { ssr: { external: true } } : { ssr: {
1562
+ ...hasCloudflarePlugin || hasNitroPlugin ? {} : config.ssr?.external === true ? { ssr: {
1563
+ external: true,
1564
+ noExternal: [...PATCHED_SERVER_PACKAGES]
1565
+ } } : { ssr: {
1354
1566
  external: [
1355
1567
  "react",
1356
1568
  "react-dom",
@@ -1362,13 +1574,16 @@ function vinext(options = {}) {
1362
1574
  noExternal: true
1363
1575
  } },
1364
1576
  resolve: {
1365
- alias: buildResolveAliasEntries({
1577
+ alias: [...userAliasEntries, ...buildResolveAliasEntries({
1366
1578
  ...swcHelpersAlias ? { "@swc/helpers/_": swcHelpersAlias } : {},
1367
1579
  ...tsconfigPathAliases,
1368
1580
  ...nextConfig.aliases,
1369
1581
  ...nextShimMap,
1370
1582
  "vinext/server/pages-client-assets": _pagesClientAssetsPath
1371
- }, tsconfigPathAliases),
1583
+ }, tsconfigPathAliases, {
1584
+ ...nextConfig.aliases,
1585
+ ...nextShimMap
1586
+ })],
1372
1587
  dedupe: [
1373
1588
  "react",
1374
1589
  "react-dom",
@@ -1443,10 +1658,60 @@ function vinext(options = {}) {
1443
1658
  }
1444
1659
  };
1445
1660
  pagesOptimizeEntries = !hasAppDir ? [...hasPagesDir ? [toRelativeFileEntry(root, pagesDir) + "/**/*.{tsx,ts,jsx,js}"] : [], ...[instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : [])] : [];
1661
+ if (env.command === "serve" && !hasAppDir && !hasCloudflarePlugin && !shouldInjectPlainPagesEnvironments) viteConfig.optimizeDeps.include = [.../* @__PURE__ */ new Set([...incomingInclude, "react-dom/client"])];
1446
1662
  if (hasAppDir) {
1447
1663
  const appEntries = [`${path.relative(root, appDir)}/**/*.{tsx,ts,jsx,js}`];
1448
1664
  const explicitInstrumentationEntries = [instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : []);
1449
1665
  const optimizeEntries = [.../* @__PURE__ */ new Set([...appEntries, ...explicitInstrumentationEntries])];
1666
+ const additionalRscOptimizeIncludes = [];
1667
+ if (env.command === "serve" && hasCloudflarePlugin && nextConfig?.aliases["next-intl/config"] && !(config.environments?.rsc?.optimizeDeps?.noDiscovery ?? config.optimizeDeps?.noDiscovery)) {
1668
+ const projectRequire = createRequire(path.join(root, "package.json"));
1669
+ const excluded = [...incomingExclude, ...config.environments?.rsc?.optimizeDeps?.exclude ?? []];
1670
+ for (const id of [
1671
+ "@formatjs/intl-localematcher",
1672
+ "negotiator",
1673
+ "@formatjs/fast-memoize",
1674
+ "intl-messageformat"
1675
+ ]) {
1676
+ if (excluded.includes(id)) continue;
1677
+ try {
1678
+ projectRequire.resolve(id);
1679
+ additionalRscOptimizeIncludes.push(id);
1680
+ } catch {}
1681
+ }
1682
+ }
1683
+ const additionalClientOptimizeIncludes = [];
1684
+ let hasNextIntl = Boolean(nextConfig?.aliases["next-intl/config"]);
1685
+ if (env.command === "serve" && !hasNextIntl) try {
1686
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
1687
+ hasNextIntl = [
1688
+ "dependencies",
1689
+ "devDependencies",
1690
+ "optionalDependencies",
1691
+ "peerDependencies"
1692
+ ].some((field) => Object.hasOwn(pkg[field] ?? {}, "next-intl"));
1693
+ } catch {}
1694
+ if (env.command === "serve" && hasNextIntl && !(config.environments?.client?.optimizeDeps?.noDiscovery ?? config.optimizeDeps?.noDiscovery)) {
1695
+ const excluded = [...incomingExclude, ...config.environments?.client?.optimizeDeps?.exclude ?? []];
1696
+ try {
1697
+ const projectRequire = createRequire(path.join(root, "package.json"));
1698
+ const packageRequire = createRequire(projectRequire.resolve("next-intl"));
1699
+ for (const id of [
1700
+ "use-intl",
1701
+ "use-intl/react",
1702
+ "use-intl/_IntlProvider",
1703
+ "use-intl/_useLocale"
1704
+ ]) {
1705
+ const include = `next-intl > ${id}`;
1706
+ if (excluded.includes("use-intl") || excluded.includes(id) || excluded.includes(include)) continue;
1707
+ try {
1708
+ packageRequire.resolve(id);
1709
+ additionalClientOptimizeIncludes.push(include);
1710
+ } catch {}
1711
+ }
1712
+ if (!excluded.includes("next") && !excluded.includes("next/link")) additionalClientOptimizeIncludes.push("next/link");
1713
+ } catch {}
1714
+ }
1450
1715
  const appClientInput = { index: VIRTUAL_APP_BROWSER_ENTRY };
1451
1716
  if (hasPagesDir) appClientInput["vinext-client-entry"] = VIRTUAL_CLIENT_ENTRY;
1452
1717
  viteConfig.environments = {
@@ -1456,15 +1721,19 @@ function vinext(options = {}) {
1456
1721
  "satori",
1457
1722
  "@resvg/resvg-js",
1458
1723
  "yoga-wasm-web",
1459
- ...env?.command === "serve" && _canExternalizeAppRscHandler ? ["vinext/server/app-rsc-handler"] : [],
1724
+ ...env?.command === "serve" && _canExternalizeAppRscHandler ? ["vinext/server/app-rsc-combined-handler", "vinext/server/app-rsc-handler"] : [],
1460
1725
  ...userSsrExternal
1461
1726
  ],
1462
- ...userSsrExternal === true ? {} : { noExternal: true }
1727
+ noExternal: userSsrExternal === true ? [...PATCHED_SERVER_PACKAGES] : true
1463
1728
  } },
1464
1729
  optimizeDeps: {
1465
1730
  exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE),
1466
1731
  entries: optimizeEntries,
1467
- include: [.../* @__PURE__ */ new Set([...incomingInclude, "react-server-dom-webpack/static.edge"])],
1732
+ include: [.../* @__PURE__ */ new Set([
1733
+ ...incomingInclude,
1734
+ ...additionalRscOptimizeIncludes,
1735
+ "react-server-dom-webpack/static.edge"
1736
+ ])],
1468
1737
  ...depOptimizeNodeEnvOptions
1469
1738
  },
1470
1739
  build: {
@@ -1482,7 +1751,7 @@ function vinext(options = {}) {
1482
1751
  "ipaddr.js",
1483
1752
  ...externalizeSsrReactInDev ? SSR_EXTERNAL_REACT_ENTRIES : []
1484
1753
  ],
1485
- ...userSsrExternal === true ? {} : { noExternal: true }
1754
+ noExternal: userSsrExternal === true ? [...PATCHED_SERVER_PACKAGES] : true
1486
1755
  } },
1487
1756
  optimizeDeps: {
1488
1757
  exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["ipaddr.js"], userSsrExternal === true || externalizeSsrReactInDev ? SSR_EXTERNAL_REACT_ENTRIES : []),
@@ -1501,6 +1770,7 @@ function vinext(options = {}) {
1501
1770
  entries: optimizeEntries,
1502
1771
  include: [.../* @__PURE__ */ new Set([
1503
1772
  ...incomingInclude,
1773
+ ...additionalClientOptimizeIncludes,
1504
1774
  "react",
1505
1775
  "react-dom",
1506
1776
  "react-dom/client",
@@ -1524,6 +1794,7 @@ function vinext(options = {}) {
1524
1794
  } else if (hasCloudflarePlugin) viteConfig.environments = { client: {
1525
1795
  consumer: "client",
1526
1796
  optimizeDeps: {
1797
+ include: ["react-dom/client"],
1527
1798
  ...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
1528
1799
  ...depOptimizeNodeEnvOptions
1529
1800
  },
@@ -1538,49 +1809,55 @@ function vinext(options = {}) {
1538
1809
  })
1539
1810
  }
1540
1811
  } };
1541
- else if (shouldInjectPlainPagesEnvironments) viteConfig.environments = {
1542
- client: {
1543
- consumer: "client",
1544
- optimizeDeps: {
1545
- ...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
1546
- ...depOptimizeNodeEnvOptions
1547
- },
1548
- build: {
1549
- outDir: "dist/client",
1550
- manifest: true,
1551
- ssrManifest: true,
1552
- assetsInlineLimit: clientAssetsInlineLimit,
1553
- ...withBuildBundlerOptions({
1554
- input: { index: VIRTUAL_CLIENT_ENTRY },
1555
- output: getClientOutputConfig(clientAssetsDir),
1556
- treeshake: getClientTreeshakeConfig()
1557
- })
1558
- }
1559
- },
1560
- ssr: {
1561
- resolve: {
1562
- external: [
1563
- "react",
1564
- "react-dom",
1565
- "react-dom/server",
1566
- "ipaddr.js",
1567
- ...nextServerExternal
1568
- ],
1569
- noExternal: true
1570
- },
1571
- optimizeDeps: {
1572
- exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["ipaddr.js"], Object.keys(nextShimMap)),
1573
- ...depOptimizeNodeEnvOptions
1812
+ else if (shouldInjectPlainPagesEnvironments) {
1813
+ const plainPagesEnvironments = {
1814
+ client: {
1815
+ consumer: "client",
1816
+ optimizeDeps: {
1817
+ include: ["react-dom/client"],
1818
+ ...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
1819
+ ...depOptimizeNodeEnvOptions
1820
+ },
1821
+ build: {
1822
+ outDir: "dist/client",
1823
+ manifest: true,
1824
+ ssrManifest: true,
1825
+ assetsInlineLimit: clientAssetsInlineLimit,
1826
+ ...withBuildBundlerOptions({
1827
+ input: { index: VIRTUAL_CLIENT_ENTRY },
1828
+ output: getClientOutputConfig(clientAssetsDir),
1829
+ treeshake: getClientTreeshakeConfig()
1830
+ })
1831
+ }
1574
1832
  },
1575
- build: {
1576
- outDir: "dist/server",
1577
- ...withBuildBundlerOptions({
1578
- input: { index: VIRTUAL_SERVER_ENTRY },
1579
- output: { entryFileNames: "entry.js" }
1580
- })
1833
+ ssr: {
1834
+ resolve: {
1835
+ external: [
1836
+ "react",
1837
+ "react-dom",
1838
+ "react-dom/server",
1839
+ "ipaddr.js",
1840
+ ...nextServerExternal
1841
+ ],
1842
+ noExternal: true
1843
+ },
1844
+ optimizeDeps: {
1845
+ exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["ipaddr.js"], Object.keys(nextShimMap)),
1846
+ ...depOptimizeNodeEnvOptions
1847
+ },
1848
+ build: {
1849
+ outDir: "dist/server",
1850
+ ...withBuildBundlerOptions({
1851
+ input: { index: hasNitroPlugin ? VIRTUAL_WORKER_ENTRY : VIRTUAL_SERVER_ENTRY },
1852
+ output: { entryFileNames: "entry.js" }
1853
+ })
1854
+ }
1581
1855
  }
1582
- }
1583
- };
1856
+ };
1857
+ originalPlainPagesEnvironments = config.environments;
1858
+ viteConfig.environments = plainPagesEnvironments;
1859
+ hasPlainPagesBuildEnvironments = env.command === "build";
1860
+ }
1584
1861
  if (pagesOptimizeEntries.length > 0 && !hasCloudflarePlugin) viteConfig.optimizeDeps = {
1585
1862
  ...viteConfig.optimizeDeps,
1586
1863
  entries: pagesOptimizeEntries
@@ -1588,6 +1865,11 @@ function vinext(options = {}) {
1588
1865
  return viteConfig;
1589
1866
  },
1590
1867
  configEnvironment(name, config) {
1868
+ if (name === "client" && nextConfig.output === "export" && nextConfig.basePath) {
1869
+ config.build ??= {};
1870
+ copyPublicDirIntoStaticExportBasePath = config.build.copyPublicDir !== false;
1871
+ config.build.copyPublicDir = false;
1872
+ }
1591
1873
  if (name !== "client" && config.consumer !== "client") {
1592
1874
  config.optimizeDeps ??= {};
1593
1875
  config.optimizeDeps.rolldownOptions ??= {};
@@ -1607,6 +1889,12 @@ function vinext(options = {}) {
1607
1889
  return null;
1608
1890
  },
1609
1891
  async configResolved(config) {
1892
+ if (isServeCommand && !config["__vinextDevCliLifecycle"] && config.configFile && isViteCliConfigFile(config.configFile, config.inlineConfig)) {
1893
+ if (claimViteCliDevInvocation(config.root, false, true)) {
1894
+ config[VINEXT_DEV_CLI_LIFECYCLE] = true;
1895
+ if (!config.server.middlewareMode) applyDevServerDefaults(config.server, {});
1896
+ }
1897
+ }
1610
1898
  if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir) suppressOptionalOptimizeDepsWarnings(config.logger);
1611
1899
  if (config.worker?.rolldownOptions) {
1612
1900
  const workerFileNames = `${resolveAssetsDir(nextConfig.assetPrefix ?? "")}/workers/[name]-[hash].js`;
@@ -1671,10 +1959,37 @@ function vinext(options = {}) {
1671
1959
  assertNoPublicDirAssetConflict(publicDirConflictOptions);
1672
1960
  }
1673
1961
  },
1962
+ writeBundle: {
1963
+ sequential: true,
1964
+ order: "post",
1965
+ handler(outputOptions) {
1966
+ if (this.environment?.name !== "client" || nextConfig.output !== "export" || !nextConfig.basePath || !copyPublicDirIntoStaticExportBasePath) return;
1967
+ const envConfig = this.environment.config;
1968
+ const publicDir = envConfig.publicDir;
1969
+ if (!publicDir || !fs.existsSync(publicDir)) return;
1970
+ if (publicDirConflictOptions) assertNoPublicDirAssetConflict(publicDirConflictOptions);
1971
+ const buildRoot = envConfig.root ?? process.cwd();
1972
+ const clientOutDir = outputOptions.dir ? path.resolve(buildRoot, outputOptions.dir) : path.resolve(buildRoot, envConfig.build.outDir);
1973
+ const basePathDir = path.join(clientOutDir, nextConfig.basePath.slice(1));
1974
+ fs.mkdirSync(basePathDir, { recursive: true });
1975
+ fs.cpSync(publicDir, basePathDir, {
1976
+ recursive: true,
1977
+ dereference: true,
1978
+ force: true
1979
+ });
1980
+ }
1981
+ },
1674
1982
  resolveId: {
1675
- filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/app-rsc-handler)|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
1983
+ filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/(?:app-rsc-(?:combined-)?handler|app-router-entry|pages-router-entry))|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
1676
1984
  handler(id, importer) {
1677
1985
  const cleanId = toSlash(id.startsWith("\0") ? id.slice(1) : id);
1986
+ if (cleanId === "vinext/server/app-rsc-combined-handler") {
1987
+ if (_canExternalizeAppRscHandler && this.environment?.name === "rsc" && this.environment.config?.command === "serve") return {
1988
+ id: _appRscCombinedHandlerPath,
1989
+ external: true
1990
+ };
1991
+ return _appRscCombinedHandlerPath;
1992
+ }
1678
1993
  if (cleanId === "vinext/server/app-rsc-handler") {
1679
1994
  if (_canExternalizeAppRscHandler && this.environment?.name === "rsc" && this.environment.config?.command === "serve") return {
1680
1995
  id: _appRscHandlerPath,
@@ -1685,22 +2000,57 @@ function vinext(options = {}) {
1685
2000
  if (isVercelOgImport(cleanId) && !isVinextOgShimImporter(importer)) return resolveShimModulePath(_shimsDir, "og");
1686
2001
  if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
1687
2002
  if (cleanId === VIRTUAL_WORKER_ENTRY) return RESOLVED_WORKER_ENTRY;
1688
- if (cleanId.endsWith("/virtual:vinext-worker-entry")) return RESOLVED_WORKER_ENTRY;
2003
+ if (selectedMultiStageOutput && (cleanId === "vinext/server/app-router-entry" || cleanId === "vinext/server/pages-router-entry")) return RESOLVED_WORKER_ENTRY;
2004
+ if (cleanId.endsWith("/" + VIRTUAL_WORKER_ENTRY)) return RESOLVED_WORKER_ENTRY;
2005
+ if (cleanId === VIRTUAL_REQUEST_STAGE) return RESOLVED_REQUEST_STAGE;
2006
+ if (cleanId.endsWith("/" + VIRTUAL_REQUEST_STAGE)) return RESOLVED_REQUEST_STAGE;
2007
+ if (cleanId === VIRTUAL_RESPONSE_STAGE) return RESOLVED_RESPONSE_STAGE;
2008
+ if (cleanId.endsWith("/" + VIRTUAL_RESPONSE_STAGE)) return RESOLVED_RESPONSE_STAGE;
1689
2009
  if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
2010
+ if (cleanId === VIRTUAL_PAGES_REQUEST_ENTRY) return RESOLVED_PAGES_REQUEST_ENTRY;
2011
+ if (cleanId === VIRTUAL_PAGES_RESPONSE_ENTRY) return RESOLVED_PAGES_RESPONSE_ENTRY;
1690
2012
  if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
1691
- if (cleanId.endsWith("/virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
1692
- if (cleanId.endsWith("/virtual:vinext-client-entry")) return RESOLVED_CLIENT_ENTRY;
2013
+ if (cleanId.endsWith("/" + VIRTUAL_SERVER_ENTRY)) return RESOLVED_SERVER_ENTRY;
2014
+ if (cleanId.endsWith("/" + VIRTUAL_PAGES_REQUEST_ENTRY)) return RESOLVED_PAGES_REQUEST_ENTRY;
2015
+ if (cleanId.endsWith("/" + VIRTUAL_PAGES_RESPONSE_ENTRY)) return RESOLVED_PAGES_RESPONSE_ENTRY;
2016
+ if (cleanId.endsWith("/" + VIRTUAL_CLIENT_ENTRY)) return RESOLVED_CLIENT_ENTRY;
1693
2017
  if (cleanId === VIRTUAL_RSC_ENTRY) return RESOLVED_RSC_ENTRY;
2018
+ if (cleanId === VIRTUAL_CACHEABILITY_MANIFEST) {
2019
+ if ((hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment)) && this.environment.config?.command === "build") return {
2020
+ id: `./${CACHEABILITY_MANIFEST_MODULE}`,
2021
+ external: true
2022
+ };
2023
+ return RESOLVED_CACHEABILITY_MANIFEST;
2024
+ }
2025
+ if (cleanId === VIRTUAL_CACHEABILITY_REQUEST_PROJECTION) {
2026
+ if (hasAppDir && this.environment?.name === "rsc" && this.environment.config?.command === "build") return {
2027
+ id: `./${CACHEABILITY_REQUEST_PROJECTION_MODULE}`,
2028
+ external: true
2029
+ };
2030
+ return RESOLVED_CACHEABILITY_REQUEST_PROJECTION;
2031
+ }
2032
+ if (cleanId === VIRTUAL_PREGENERATED_CONCRETE_PATHS) {
2033
+ if ((hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment)) && this.environment.config?.command === "build") return {
2034
+ id: `./${PREGENERATED_CONCRETE_PATHS_MODULE}`,
2035
+ external: true
2036
+ };
2037
+ return RESOLVED_PREGENERATED_CONCRETE_PATHS;
2038
+ }
2039
+ if (cleanId === VIRTUAL_APP_REQUEST_ENTRY) return RESOLVED_APP_REQUEST_ENTRY;
2040
+ if (cleanId === VIRTUAL_APP_RESPONSE_ENTRY) return RESOLVED_APP_RESPONSE_ENTRY;
1694
2041
  if (cleanId === VIRTUAL_APP_SSR_ENTRY) return RESOLVED_APP_SSR_ENTRY;
1695
2042
  if (cleanId === VIRTUAL_APP_BROWSER_ENTRY) return RESOLVED_APP_BROWSER_ENTRY;
1696
2043
  if (cleanId === VIRTUAL_APP_CAPABILITIES) return RESOLVED_APP_CAPABILITIES;
1697
2044
  if (cleanId === "next/root-params" || cleanId === "next/root-params.js") return RESOLVED_ROOT_PARAMS;
1698
2045
  if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters")) return RESOLVED_CACHE_ADAPTERS;
2046
+ if (cleanId === "virtual:vinext-cdn-cache-adapter" || cleanId.endsWith("/virtual:vinext-cdn-cache-adapter")) return RESOLVED_CDN_CACHE_ADAPTER;
1699
2047
  if (cleanId === "virtual:vinext-image-adapters" || cleanId.endsWith("/virtual:vinext-image-adapters")) return RESOLVED_IMAGE_ADAPTERS;
1700
2048
  if (cleanId.startsWith("virtual:vinext-google-fonts?")) return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(VIRTUAL_GOOGLE_FONTS.length);
1701
- if (cleanId.endsWith("/virtual:vinext-rsc-entry")) return RESOLVED_RSC_ENTRY;
1702
- if (cleanId.endsWith("/virtual:vinext-app-ssr-entry")) return RESOLVED_APP_SSR_ENTRY;
1703
- if (cleanId.endsWith("/virtual:vinext-app-browser-entry")) return RESOLVED_APP_BROWSER_ENTRY;
2049
+ if (cleanId.endsWith("/" + VIRTUAL_RSC_ENTRY)) return RESOLVED_RSC_ENTRY;
2050
+ if (cleanId.endsWith("/" + VIRTUAL_APP_REQUEST_ENTRY)) return RESOLVED_APP_REQUEST_ENTRY;
2051
+ if (cleanId.endsWith("/" + VIRTUAL_APP_RESPONSE_ENTRY)) return RESOLVED_APP_RESPONSE_ENTRY;
2052
+ if (cleanId.endsWith("/" + VIRTUAL_APP_SSR_ENTRY)) return RESOLVED_APP_SSR_ENTRY;
2053
+ if (cleanId.endsWith("/" + VIRTUAL_APP_BROWSER_ENTRY)) return RESOLVED_APP_BROWSER_ENTRY;
1704
2054
  if (cleanId.includes("/virtual:vinext-google-fonts?")) {
1705
2055
  const queryIndex = cleanId.indexOf(VIRTUAL_GOOGLE_FONTS + "?");
1706
2056
  return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(queryIndex + VIRTUAL_GOOGLE_FONTS.length);
@@ -1715,11 +2065,41 @@ function vinext(options = {}) {
1715
2065
  load: {
1716
2066
  filter: { id: /virtual:vinext-/ },
1717
2067
  async handler(id) {
1718
- if (id === RESOLVED_WORKER_ENTRY) return `export { default } from ${JSON.stringify(hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry")};`;
1719
- if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1(this.environment.config.publicDir === "" ? false : this.environment.config.publicDir);
2068
+ if (id === RESOLVED_WORKER_ENTRY) {
2069
+ if (selectedMultiStageOutput?.type === "multi-stage") return [
2070
+ `export { default } from ${JSON.stringify(selectedMultiStageOutput.entry)};`,
2071
+ `export * from ${JSON.stringify(selectedMultiStageOutput.entry)};`,
2072
+ ""
2073
+ ].join("\n");
2074
+ const entry = hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry";
2075
+ if (!hasAppDir && hasNitroPlugin) return [
2076
+ `import worker from ${JSON.stringify(entry)};`,
2077
+ "export default { fetch(request, env, ctx) {",
2078
+ ` return worker.fetch(request, env, { ...ctx, hostRuntime: ${JSON.stringify(nitroHostRuntime)} });`,
2079
+ "} };"
2080
+ ].join("\n");
2081
+ return `export { default } from ${JSON.stringify(entry)};`;
2082
+ }
2083
+ if (id === RESOLVED_REQUEST_STAGE) return `export { handleRequestStage } from ${JSON.stringify(hasAppDir ? APP_REQUEST_STAGE_ENTRY : PAGES_REQUEST_STAGE_ENTRY)};\n`;
2084
+ if (id === RESOLVED_RESPONSE_STAGE) return `export * from ${JSON.stringify(hasAppDir ? APP_RESPONSE_STAGE_ENTRY : PAGES_RESPONSE_STAGE_ENTRY)};\n`;
2085
+ if (id === RESOLVED_SERVER_ENTRY) {
2086
+ recordServerEntryLoad(this.environment?.name, id);
2087
+ return await generateServerEntry$1(this.environment.config.publicDir === "" ? false : this.environment.config.publicDir);
2088
+ }
2089
+ if (id === RESOLVED_PAGES_REQUEST_ENTRY) {
2090
+ recordServerEntryLoad(this.environment?.name, id);
2091
+ return await generatePagesRequestEntry$1(this.environment.config.publicDir === "" ? false : this.environment.config.publicDir);
2092
+ }
2093
+ if (id === RESOLVED_PAGES_RESPONSE_ENTRY) {
2094
+ recordServerEntryLoad(this.environment?.name, id);
2095
+ return await generatePagesResponseEntry$1();
2096
+ }
1720
2097
  if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
1721
2098
  if (id === RESOLVED_PAGES_CLIENT_ASSETS) {
1722
- const metadata = { clientEntry: DEV_PAGES_CLIENT_ENTRY };
2099
+ const metadata = {
2100
+ clientEntry: DEV_PAGES_CLIENT_ENTRY,
2101
+ crossOrigin: nextConfig?.crossOrigin ?? ""
2102
+ };
1723
2103
  const ssrManifest = {};
1724
2104
  const appFilePath = findFileWithExts(pagesDir, "_app", fileMatcher);
1725
2105
  const pagesRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
@@ -1732,16 +2112,21 @@ function vinext(options = {}) {
1732
2112
  if (Object.keys(ssrManifest).length > 0) metadata.ssrManifest = ssrManifest;
1733
2113
  return `export default ${JSON.stringify(metadata)};`;
1734
2114
  }
1735
- if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
2115
+ if (id === RESOLVED_CACHEABILITY_MANIFEST || id === RESOLVED_CACHEABILITY_REQUEST_PROJECTION) return "export default null;";
2116
+ if (id === RESOLVED_PREGENERATED_CONCRETE_PATHS) return "export {};";
2117
+ if ((id === RESOLVED_RSC_ENTRY || id === RESOLVED_APP_REQUEST_ENTRY || id === RESOLVED_APP_RESPONSE_ENTRY) && hasAppDir) {
2118
+ recordServerEntryLoad(this.environment?.name, id);
1736
2119
  const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
1737
2120
  const metaRoutes = scanMetadataFiles(appDir);
1738
2121
  const hasServerActions = await resolveHasServerActions(this.environment.config);
1739
2122
  const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
1740
2123
  const globalNotFoundPath = nextConfig?.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
1741
- rscClassificationManifest = collectRouteClassificationManifest(routes);
1742
- rscActionOwnerRoutes = this.environment.config.command === "build" && hasServerActions ? routes : null;
1743
- rscActionOwnerSharedRoots = [globalErrorPath, globalNotFoundPath].filter((path) => path !== null);
1744
- return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
2124
+ if (id !== RESOLVED_APP_REQUEST_ENTRY) {
2125
+ rscClassificationManifests.set(id, collectRouteClassificationManifest(routes));
2126
+ rscActionOwnerRoutes = this.environment.config.command === "build" && hasServerActions ? routes : null;
2127
+ rscActionOwnerSharedRoots = [globalErrorPath, globalNotFoundPath].filter((path) => path !== null);
2128
+ }
2129
+ return (id === RESOLVED_APP_REQUEST_ENTRY ? generateAppRequestRscEntry : id === RESOLVED_APP_RESPONSE_ENTRY ? generateAppResponseRscEntry : generateRscEntry)(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
1745
2130
  redirects: nextConfig?.redirects,
1746
2131
  rewrites: nextConfig?.rewrites,
1747
2132
  headers: nextConfig?.headers,
@@ -1751,7 +2136,9 @@ function vinext(options = {}) {
1751
2136
  bodySizeLimitLabel: nextConfig?.serverActionsBodySizeLimitLabel,
1752
2137
  htmlLimitedBots: nextConfig?.htmlLimitedBots,
1753
2138
  clientTraceMetadata: nextConfig?.clientTraceMetadata,
2139
+ nodeOpenTelemetryLoader: registerNodeOpenTelemetryLoader,
1754
2140
  assetPrefix: nextConfig?.assetPrefix,
2141
+ crossOrigin: nextConfig?.crossOrigin,
1755
2142
  expireTime: nextConfig?.expireTime,
1756
2143
  reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
1757
2144
  cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
@@ -1774,13 +2161,18 @@ function vinext(options = {}) {
1774
2161
  hasPagesDir,
1775
2162
  publicFiles: isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, this.environment.config.publicDir === "" ? false : this.environment.config.publicDir),
1776
2163
  globalNotFoundPath,
1777
- draftModeSecret
2164
+ draftModeSecret,
2165
+ prerenderSecret
1778
2166
  }, instrumentationPath);
1779
2167
  }
1780
2168
  if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
1781
2169
  if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
2170
+ if (id === RESOLVED_CDN_CACHE_ADAPTER) return generateCdnCacheAdapterModule(options.cache);
1782
2171
  if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
1783
- if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
2172
+ if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) {
2173
+ recordServerEntryLoad(this.environment?.name, id);
2174
+ return generateSsrEntry(hasPagesDir);
2175
+ }
1784
2176
  if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
1785
2177
  const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
1786
2178
  const pagesPrefetchRoutes = hasPagesDir ? [...(await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
@@ -1793,7 +2185,7 @@ function vinext(options = {}) {
1793
2185
  isDynamic: route.isDynamic,
1794
2186
  patternParts: [...route.patternParts]
1795
2187
  }))] : [];
1796
- return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites);
2188
+ return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites, nextConfig.i18n?.locales);
1797
2189
  }
1798
2190
  if (id === RESOLVED_APP_CAPABILITIES && hasAppDir) {
1799
2191
  const hasServerActions = await resolveHasServerActions(this.environment.config);
@@ -1810,9 +2202,12 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1810
2202
  order: "pre",
1811
2203
  handler(code, chunk) {
1812
2204
  if (this.environment?.name !== "rsc") return null;
1813
- if (!rscClassificationManifest) return null;
1814
2205
  const hasClassificationStub = code.includes("__VINEXT_CLASS");
1815
2206
  if (!hasClassificationStub) return null;
2207
+ const rscEntryId = [RESOLVED_RSC_ENTRY, RESOLVED_APP_RESPONSE_ENTRY].find((id) => chunk.moduleIds.includes(id));
2208
+ if (!rscEntryId) return null;
2209
+ const rscClassificationManifest = rscClassificationManifests.get(rscEntryId);
2210
+ if (!rscClassificationManifest) return null;
1816
2211
  const enableClassificationDebug = Boolean(process.env.VINEXT_DEBUG_CLASSIFICATION);
1817
2212
  const patchPlan = hasClassificationStub && rscClassificationManifest ? planRouteClassificationInjection({
1818
2213
  canonicalizeLayoutPath: canonicalize,
@@ -1834,7 +2229,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1834
2229
  }) : { kind: "skip" };
1835
2230
  const nextCode = patchPlan.kind === "skip" ? code : patchPlan.code;
1836
2231
  if (patchPlan.kind === "skip") return null;
1837
- rscClassificationManifest = null;
2232
+ rscClassificationManifests.delete(rscEntryId);
1838
2233
  return {
1839
2234
  code: nextCode,
1840
2235
  map: null
@@ -1842,6 +2237,21 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1842
2237
  }
1843
2238
  }
1844
2239
  },
2240
+ {
2241
+ name: "vinext:cloudflare-framework-tracing",
2242
+ transform: {
2243
+ filter: { id: /(?:app|pages)-router-entry\.[cm]?[jt]s(?:\?|$)/ },
2244
+ handler(code, id) {
2245
+ if (!hasCloudflarePlugin) return null;
2246
+ const cleanId = toSlash(stripViteModuleQuery(id));
2247
+ if (!WORKER_ROUTER_ENTRIES.has(cleanId)) return null;
2248
+ return {
2249
+ code: `import "vinext/internal/server/cloudflare-workers-tracing";\n${code}`,
2250
+ map: null
2251
+ };
2252
+ }
2253
+ }
2254
+ },
1845
2255
  {
1846
2256
  name: "vinext:pages-client-assets-resolver",
1847
2257
  sharedDuringBuild: true,
@@ -1849,11 +2259,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1849
2259
  filter: { id: /virtual:vinext-pages-client-assets$/ },
1850
2260
  handler(id) {
1851
2261
  const cleanId = toSlash(id.startsWith("\0") ? id.slice(1) : id);
1852
- if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/virtual:vinext-pages-client-assets")) return;
2262
+ if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/" + VIRTUAL_PAGES_CLIENT_ASSETS)) return;
1853
2263
  if (this.environment?.config.command !== "build") return RESOLVED_PAGES_CLIENT_ASSETS;
1854
2264
  const buildRoot = this.environment.config.root ?? process.cwd();
1855
2265
  const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
1856
- const sidecarDir = !hasAppDir && this.environment.name === "ssr" ? path.dirname(environmentOutDir) : environmentOutDir;
2266
+ const sidecarDir = resolvePagesClientAssetsOutputDir(this.environment.name, environmentOutDir);
1857
2267
  let externalId = path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE));
1858
2268
  if (!externalId.startsWith(".")) externalId = `./${externalId}`;
1859
2269
  pagesClientAssetsOutputDirs.add(sidecarDir);
@@ -1862,6 +2272,13 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1862
2272
  external: true
1863
2273
  };
1864
2274
  }
2275
+ },
2276
+ outputOptions(output) {
2277
+ const environment = this.environment;
2278
+ if (!selectedMultiStageOutput || !environment || !isMultiStageServerEnvironment(environment)) return;
2279
+ const buildRoot = environment.config.root ?? process.cwd();
2280
+ const outputDir = path.resolve(buildRoot, output.dir ?? environment.config.build.outDir);
2281
+ pagesClientAssetsOutputDirs.add(resolvePagesClientAssetsOutputDir(environment.name, outputDir));
1865
2282
  }
1866
2283
  },
1867
2284
  {
@@ -1883,6 +2300,49 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1883
2300
  }
1884
2301
  }
1885
2302
  },
2303
+ {
2304
+ name: "vinext:multi-stage-host-entry",
2305
+ transform: {
2306
+ filter: { id: /virtual:|\.[cm]?[jt]sx?(?:\?|$)/ },
2307
+ handler(code, id) {
2308
+ const environment = this.environment;
2309
+ if (!isServeCommand && (!environment || !isMultiStageServerEnvironment(environment))) return null;
2310
+ const transformed = matchedMultiStageOutput?.transformHostEntry?.({
2311
+ code,
2312
+ id
2313
+ });
2314
+ return transformed == null ? null : {
2315
+ code: transformed,
2316
+ map: null
2317
+ };
2318
+ }
2319
+ }
2320
+ },
2321
+ {
2322
+ name: "vinext:multi-stage-server-output",
2323
+ apply: "build",
2324
+ buildStart() {
2325
+ const entries = selectedMultiStageOutput?.entries;
2326
+ const environment = this.environment;
2327
+ if (!entries || !environment || !isMultiStageServerEnvironment(environment)) return;
2328
+ for (const [name, id] of [["vinext-request-stage", entries.request], ["vinext-response-stage", entries.response]]) this.emitFile({
2329
+ id,
2330
+ name,
2331
+ preserveSignature: "strict",
2332
+ type: "chunk"
2333
+ });
2334
+ },
2335
+ outputOptions(output) {
2336
+ const environment = this.environment;
2337
+ if (!selectedMultiStageOutput || !environment || !isMultiStageServerEnvironment(environment)) return;
2338
+ if (output.format !== void 0 && output.format !== "es" && output.format !== "esm" && output.format !== "module") throw new Error(`[vinext] Multi-stage output requires an ES module format; ${JSON.stringify(output.format)} cannot represent independently deployable request and response entries.`);
2339
+ return {
2340
+ ...output,
2341
+ chunkFileNames: createMultiStageChunkFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? ""), output.chunkFileNames),
2342
+ codeSplitting: createMultiStageCodeSplittingConfig(output.codeSplitting)
2343
+ };
2344
+ }
2345
+ },
1886
2346
  {
1887
2347
  name: "vinext:css-url-assets-defaults",
1888
2348
  apply: "build",
@@ -1891,7 +2351,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1891
2351
  if (!hasAppDir || name !== "rsc" && name !== "ssr") return null;
1892
2352
  const output = getBuildBundlerOptions(config.build)?.output;
1893
2353
  if (Array.isArray(output) || output?.assetFileNames !== void 0) return null;
1894
- return { build: { ...withBuildBundlerOptions({ output: { assetFileNames: createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? "")) } }) } };
2354
+ const assetFileNames = createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? ""));
2355
+ return { build: { ...withBuildBundlerOptions({ output: { assetFileNames } }) } };
1895
2356
  }
1896
2357
  },
1897
2358
  {
@@ -1914,6 +2375,30 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1914
2375
  return null;
1915
2376
  }
1916
2377
  },
2378
+ {
2379
+ name: "vinext:cacheability-manifest-asset",
2380
+ apply: "build",
2381
+ generateBundle() {
2382
+ if (!(hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment))) return;
2383
+ this.emitFile({
2384
+ type: "asset",
2385
+ fileName: CACHEABILITY_MANIFEST_MODULE,
2386
+ source: "export default null;\n"
2387
+ });
2388
+ if (hasAppDir) {
2389
+ this.emitFile({
2390
+ type: "asset",
2391
+ fileName: CACHEABILITY_REQUEST_PROJECTION_MODULE,
2392
+ source: "export default null;\n"
2393
+ });
2394
+ this.emitFile({
2395
+ type: "asset",
2396
+ fileName: PREGENERATED_CONCRETE_PATHS_MODULE,
2397
+ source: "delete globalThis.__VINEXT_PREGENERATED_CONCRETE_PATHS;\n"
2398
+ });
2399
+ }
2400
+ }
2401
+ },
1917
2402
  {
1918
2403
  name: "vinext:css-url-assets-restore",
1919
2404
  enforce: "post",
@@ -1948,7 +2433,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1948
2433
  }
1949
2434
  },
1950
2435
  asyncHooksStubPlugin,
1951
- createInstrumentationClientTransformPlugin(() => instrumentationClientPath),
2436
+ createInstrumentationClientTransformPlugin(() => instrumentationClientPath, () => nextConfig.instrumentationClientRouteManifest),
2437
+ createInstrumentationServerTransformPlugin(() => instrumentationPath, () => nextConfig.instrumentationServerValueInjections),
1952
2438
  {
1953
2439
  name: "vinext:instrumentation-client-inject",
1954
2440
  enforce: "pre",
@@ -2070,8 +2556,23 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2070
2556
  return `http://localhost:${typeof address === "object" && address ? address.port : server.config.server.port ?? 3e3}`;
2071
2557
  };
2072
2558
  let cachedSSRHandler = null;
2559
+ const devPageRouteDataKinds = /* @__PURE__ */ new Map();
2560
+ function classifyDevPageFile(filePath) {
2561
+ const cached = devPageRouteDataKinds.get(filePath);
2562
+ if (cached) return cached;
2563
+ let dataKind = "none";
2564
+ try {
2565
+ const source = fs.readFileSync(filePath, "utf8");
2566
+ dataKind = hasExportedName(source, "getStaticProps") ? "static" : hasExportedName(source, "getServerSideProps") ? "server" : "none";
2567
+ } catch {}
2568
+ devPageRouteDataKinds.set(filePath, dataKind);
2569
+ return dataKind;
2570
+ }
2073
2571
  function getPagesRunner() {
2074
- if (!pagesRunner) pagesRunner = createDirectRunner(server.environments["ssr"] ?? Object.values(server.environments).find((e) => e !== server.environments["rsc"]) ?? Object.values(server.environments)[0]);
2572
+ if (!pagesRunner) {
2573
+ const env = server.environments["ssr"] ?? Object.values(server.environments).find((e) => e !== server.environments["rsc"]) ?? Object.values(server.environments)[0];
2574
+ pagesRunner = createDirectRunner(env);
2575
+ }
2075
2576
  return pagesRunner;
2076
2577
  }
2077
2578
  /**
@@ -2120,6 +2621,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2120
2621
  }
2121
2622
  pagesRunner?.clearCache();
2122
2623
  }
2624
+ function invalidatePagesHydrationProxies() {
2625
+ const graph = server.environments.client?.moduleGraph;
2626
+ if (!graph) return;
2627
+ for (const mod of graph.idToModuleMap.values()) if (mod.id?.includes("?html-proxy&index=")) graph.invalidateModule(mod);
2628
+ }
2123
2629
  function invalidateAppRoutingModules() {
2124
2630
  invalidateAppRouteCache();
2125
2631
  invalidateMetadataFileCache();
@@ -2231,13 +2737,20 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2231
2737
  if (hasAppDir) invalidateRscEntryModule();
2232
2738
  if (hasCloudflarePlugin && hasPagesDir && !hasAppDir) invalidatePagesServerEntry();
2233
2739
  };
2740
+ function invalidatePagesMiddlewareMatcher(filePath) {
2741
+ if (!hasPagesDir || !middlewarePath || toSlash(filePath) !== middlewarePath) return;
2742
+ cachedSSRHandler = null;
2743
+ server.ws.send({ type: "full-reload" });
2744
+ }
2234
2745
  server.watcher.on("add", (filePath) => {
2746
+ invalidatePagesMiddlewareMatcher(filePath);
2235
2747
  updatePublicFileRoute(filePath, true);
2236
2748
  let routeChanged = false;
2237
2749
  const pagesAppChanged = isPagesAppFile(filePath);
2238
2750
  const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
2239
2751
  if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
2240
2752
  if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
2753
+ devPageRouteDataKinds.delete(toSlash(filePath));
2241
2754
  invalidateRouteCache(pagesDir);
2242
2755
  routeChanged = true;
2243
2756
  }
@@ -2248,23 +2761,37 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2248
2761
  }
2249
2762
  if (routeChanged) {
2250
2763
  invalidatePagesServerEntry();
2764
+ if (hasPagesDir) invalidatePagesHydrationProxies();
2251
2765
  if (!hasAppDir) server.ws.send({ type: "full-reload" });
2252
2766
  invalidateHybridClientEntries();
2253
2767
  revalidateHybridRoutes();
2254
2768
  }
2255
2769
  });
2256
2770
  server.watcher.on("change", (filePath) => {
2771
+ invalidatePagesMiddlewareMatcher(filePath);
2772
+ if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
2773
+ const pageFile = toSlash(filePath);
2774
+ const previousKind = devPageRouteDataKinds.get(pageFile);
2775
+ devPageRouteDataKinds.delete(pageFile);
2776
+ if (previousKind !== void 0 && previousKind !== classifyDevPageFile(pageFile)) {
2777
+ cachedSSRHandler = null;
2778
+ invalidatePagesHydrationProxies();
2779
+ server.ws.send({ type: "full-reload" });
2780
+ }
2781
+ }
2257
2782
  const pagesAppChanged = isPagesAppFile(filePath);
2258
2783
  const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
2259
2784
  if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
2260
2785
  });
2261
2786
  server.watcher.on("unlink", (filePath) => {
2787
+ invalidatePagesMiddlewareMatcher(filePath);
2262
2788
  updatePublicFileRoute(filePath, false);
2263
2789
  let routeChanged = false;
2264
2790
  const pagesAppChanged = isPagesAppFile(filePath);
2265
2791
  const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
2266
2792
  if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
2267
2793
  if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
2794
+ devPageRouteDataKinds.delete(toSlash(filePath));
2268
2795
  invalidateRouteCache(pagesDir);
2269
2796
  routeChanged = true;
2270
2797
  }
@@ -2275,6 +2802,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2275
2802
  }
2276
2803
  if (routeChanged) {
2277
2804
  invalidatePagesServerEntry();
2805
+ if (hasPagesDir) invalidatePagesHydrationProxies();
2278
2806
  if (!hasAppDir) server.ws.send({ type: "full-reload" });
2279
2807
  invalidateHybridClientEntries();
2280
2808
  revalidateHybridRoutes();
@@ -2315,7 +2843,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2315
2843
  });
2316
2844
  server.middlewares.use((req, res, next) => {
2317
2845
  if (!hasPagesDir || !handlePagesMiddleware || !isUnsupportedDevPublicRequest(req)) return next();
2318
- handlePagesMiddleware(req, res, next);
2846
+ handlePagesMiddleware(req, res, next).catch(next);
2319
2847
  });
2320
2848
  installDevStackSourcemapMiddleware(server);
2321
2849
  return () => {
@@ -2375,9 +2903,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2375
2903
  restore();
2376
2904
  return false;
2377
2905
  };
2378
- if (instrumentationPath && !hasAppDir) runInstrumentation(getPagesRunner(), instrumentationPath).catch((err) => {
2379
- console.error("[vinext] Instrumentation error:", err);
2380
- });
2906
+ const pagesInstrumentationReady = (async () => {
2907
+ if (!instrumentationPath || hasAppDir && hasCloudflarePlugin) return;
2908
+ if (hasAppDir) {
2909
+ const environment = server.environments["rsc"];
2910
+ if (!isRunnableDevEnvironment(environment)) return;
2911
+ return runInstrumentation(environment.runner, instrumentationPath);
2912
+ } else return runInstrumentation(getPagesRunner(), instrumentationPath);
2913
+ })();
2914
+ pagesInstrumentationReady.catch(() => {});
2381
2915
  if (hasAppDir) server.middlewares.use((req, res, next) => {
2382
2916
  const url = req.url ?? "/";
2383
2917
  const [pathname] = url.split("?");
@@ -2428,13 +2962,10 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2428
2962
  });
2429
2963
  next();
2430
2964
  });
2431
- handlePagesMiddleware = async (req, res, next) => {
2965
+ const handlePagesRequest = async (req, res, next) => {
2432
2966
  try {
2433
2967
  let url = req.url ?? "/";
2434
2968
  const originalRequestUrl = url;
2435
- if (!hasPagesDir) return next();
2436
- if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules")) return next();
2437
- if (url.split("?")[0].endsWith(".rsc")) return next();
2438
2969
  const blockReason = validateDevRequest({
2439
2970
  origin: req.headers.origin,
2440
2971
  host: req.headers.host,
@@ -2628,19 +3159,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2628
3159
  const getDevApiRoutes = () => devApiRoutesPromise ??= apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
2629
3160
  let devAppRoutesPromise = null;
2630
3161
  const getDevAppRoutes = () => devAppRoutesPromise ??= hasAppDir && appDir ? appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : Promise.resolve([]);
2631
- const devPageRouteDataKinds = /* @__PURE__ */ new Map();
2632
- const classifyDevPageRoute = (route) => {
2633
- const cached = devPageRouteDataKinds.get(route.filePath);
2634
- if (cached) return cached;
2635
- let dataKind = "none";
2636
- try {
2637
- const source = fs.readFileSync(route.filePath, "utf8");
2638
- dataKind = hasExportedName(source, "getStaticProps") ? "static" : hasExportedName(source, "getServerSideProps") ? "server" : "none";
2639
- } catch {}
2640
- devPageRouteDataKinds.set(route.filePath, dataKind);
2641
- return dataKind;
2642
- };
2643
- const pipelineResult = await runPagesRequest(webRequest, {
3162
+ const classifyDevPageRoute = (route) => classifyDevPageFile(route.filePath);
3163
+ const pipelineDeps = {
2644
3164
  basePath: bp,
2645
3165
  trailingSlash: nextConfig?.trailingSlash ?? false,
2646
3166
  i18nConfig: nextConfig?.i18n ?? null,
@@ -2660,12 +3180,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2660
3180
  configMatchPathname,
2661
3181
  runMiddleware: devRunMiddlewareAdapter,
2662
3182
  matchApiRoute: async (apiUrl) => {
2663
- const pagesMatch = matchRoute(apiUrl, await getDevApiRoutes());
3183
+ const devApiRoutes = await getDevApiRoutes();
3184
+ const pagesMatch = matchRoute(apiUrl, devApiRoutes);
2664
3185
  if (pagesMatch) return pagesMatch;
2665
- return matchAppRoute(apiUrl, await getDevAppRoutes());
3186
+ const devAppRoutes = await getDevAppRoutes();
3187
+ return matchAppRoute(apiUrl, devAppRoutes);
2666
3188
  },
2667
3189
  matchPageRoute: (resolvedPathname, request) => {
2668
- const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, getUrlHostname(request.url), bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
3190
+ const routeUrl = nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, getUrlHostname(request.url), bp, nextConfig.trailingSlash ?? false).url : resolvedPathname;
3191
+ const m = matchRoute(routeUrl, devPageRoutes);
2669
3192
  return m ? { route: {
2670
3193
  dataKind: classifyDevPageRoute(m.route),
2671
3194
  isDynamic: m.route.isDynamic,
@@ -2684,11 +3207,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2684
3207
  externalInit.body = Readable.toWeb(req);
2685
3208
  externalInit.duplex = "half";
2686
3209
  }
2687
- return proxyExternalRequest(new Request(new URL(url, requestOrigin), externalInit), externalUrl);
3210
+ const reqWithBody = new Request(new URL(url, requestOrigin), externalInit);
3211
+ return proxyExternalRequest(reqWithBody, externalUrl);
2688
3212
  },
2689
3213
  serveFilesystemRoute: async (requestPathname, stagedHeaders, phase, resolvedUrl) => {
2690
3214
  if (isImageOptimizationPath(requestPathname)) {
2691
- const encodedLocation = resolveDevImageRedirect(new URL(resolvedUrl, requestOrigin), [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES], nextConfig.images?.qualities);
3215
+ const imageRequestUrl = new URL(resolvedUrl, requestOrigin);
3216
+ const allowedWidths = [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES];
3217
+ const encodedLocation = resolveDevImageRedirect(imageRequestUrl, allowedWidths, nextConfig.images?.qualities);
2692
3218
  return encodedLocation ? new Response(null, {
2693
3219
  status: 302,
2694
3220
  headers: { Location: encodedLocation }
@@ -2699,7 +3225,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2699
3225
  if (!isRetrievalMethod) return isExistingDevPublicFile(requestPathname) ? methodNotAllowedResponse("GET, HEAD") : false;
2700
3226
  return serveRewrittenViteFilesystemRoute(req, res, requestPathname, stagedHeaders);
2701
3227
  }
2702
- });
3228
+ };
3229
+ const pipelineResult = await runPagesRequest(webRequest, pipelineDeps);
2703
3230
  if (pipelineResult.type === "response") {
2704
3231
  await writeWebResponseToNodeRes(res, pipelineResult.response);
2705
3232
  return;
@@ -2763,12 +3290,13 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2763
3290
  const renderMatch = matchRoute(resolvedPathname, routes);
2764
3291
  if (hasAppDir && appDir) {
2765
3292
  if (!renderMatch) return next();
2766
- const appMatch = matchAppRoute(resolvedPathname, await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher));
3293
+ const appRoutes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
3294
+ const appMatch = matchAppRoute(resolvedPathname, appRoutes);
2767
3295
  if (appMatch && !pagesRouteHasPriorityOverAppRoute(renderMatch.route, appMatch.route)) return next();
2768
3296
  }
2769
3297
  if (!cachedSSRHandler || cachedSSRHandler.routes !== routes) cachedSSRHandler = {
2770
3298
  routes,
2771
- handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true, nextConfig?.expireTime, nextConfig?.crossOrigin, devBuildId)
3299
+ handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true, nextConfig?.expireTime, nextConfig?.crossOrigin, devBuildId, middlewarePath ? compileClientMiddlewareMatchers(extractMiddlewareMatcherConfig(middlewarePath)) : void 0, classifyDevPageRoute)
2772
3300
  };
2773
3301
  flushStagedHeaders();
2774
3302
  flushRequestHeaders();
@@ -2777,11 +3305,54 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2777
3305
  await cachedSSRHandler.handler(req, res, pipelineResult.resolvedUrl, req.__vinextMiddlewareStatus, pipelineResult.isDataReq, originalRequestUrl);
2778
3306
  }
2779
3307
  } catch (e) {
2780
- next(e);
3308
+ return next(e);
3309
+ }
3310
+ };
3311
+ handlePagesMiddleware = async (req, res, next) => {
3312
+ const url = req.url ?? "/";
3313
+ if (!hasPagesDir) return next();
3314
+ if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules")) return next();
3315
+ if (url.split("?")[0].endsWith(".rsc")) return next();
3316
+ if (hasCloudflarePlugin) return next();
3317
+ await pagesInstrumentationReady;
3318
+ const traceHeaders = new Headers();
3319
+ for (const [name, value] of Object.entries(req.headers)) {
3320
+ if (value === void 0 || name.startsWith(":")) continue;
3321
+ traceHeaders.set(name, Array.isArray(value) ? value.join(", ") : value);
2781
3322
  }
3323
+ const continueRequest = (error) => new Promise((resolve, reject) => {
3324
+ const finish = () => {
3325
+ res.off("finish", finish);
3326
+ res.off("close", finish);
3327
+ res.off("error", fail);
3328
+ resolve();
3329
+ };
3330
+ const fail = (responseError) => {
3331
+ res.off("finish", finish);
3332
+ res.off("close", finish);
3333
+ res.off("error", fail);
3334
+ reject(responseError);
3335
+ };
3336
+ res.once("finish", finish);
3337
+ res.once("close", finish);
3338
+ res.once("error", fail);
3339
+ try {
3340
+ next(error);
3341
+ if (res.writableFinished || res.destroyed) finish();
3342
+ } catch (nextError) {
3343
+ fail(nextError);
3344
+ }
3345
+ });
3346
+ return traceFrameworkRequest({
3347
+ callback: () => handlePagesRequest(req, res, continueRequest),
3348
+ getStatus: () => res.statusCode,
3349
+ headers: traceHeaders,
3350
+ method: req.method ?? "GET",
3351
+ target: url
3352
+ });
2782
3353
  };
2783
3354
  server.middlewares.use((req, res, next) => {
2784
- handlePagesMiddleware(req, res, next);
3355
+ handlePagesMiddleware(req, res, next).catch(next);
2785
3356
  });
2786
3357
  };
2787
3358
  }
@@ -2921,8 +3492,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2921
3492
  if (name === "client") return null;
2922
3493
  const serverDefines = { ...nextConfig.compilerDefineServer };
2923
3494
  serverDefines["process.env.NEXT_RUNTIME"] = JSON.stringify("nodejs");
2924
- const sharedRevalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
2925
- if (sharedRevalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(sharedRevalidateSecret);
3495
+ serverDefines["process.env.NEXT_PHASE"] = "globalThis.__VINEXT_NEXT_PHASE";
3496
+ if (revalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(revalidateSecret);
2926
3497
  if (previewBuildCredentials) {
2927
3498
  serverDefines["process.env.__VINEXT_PREVIEW_MODE_ID"] = JSON.stringify(previewBuildCredentials.id);
2928
3499
  serverDefines["process.env.__VINEXT_PREVIEW_MODE_SIGNING_KEY"] = JSON.stringify(previewBuildCredentials.signingKey);
@@ -3097,11 +3668,12 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3097
3668
  sequential: true,
3098
3669
  order: "post",
3099
3670
  handler() {
3100
- if (buildIdWritten) return;
3671
+ if (buildIdWritten || !isServerEnvironment(this.environment)) return;
3101
3672
  buildIdWritten = true;
3102
3673
  const outDir = path.join(root, "dist", "server");
3103
3674
  fs.mkdirSync(outDir, { recursive: true });
3104
3675
  fs.writeFileSync(path.join(outDir, "BUILD_ID"), nextConfig.buildId);
3676
+ if (rscBuildIdentity) fs.writeFileSync(path.join(outDir, "RSC_BUILD_ID"), rscBuildIdentity);
3105
3677
  }
3106
3678
  }
3107
3679
  };
@@ -3115,29 +3687,41 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3115
3687
  if (salt) return salt;
3116
3688
  }
3117
3689
  },
3118
- (() => {
3119
- const prerenderSecret = randomBytes(32).toString("hex");
3120
- return {
3121
- name: "vinext:server-manifest",
3122
- apply: "build",
3123
- enforce: "post",
3124
- writeBundle: {
3125
- sequential: true,
3126
- order: "post",
3127
- handler(options) {
3128
- const envName = this.environment?.name;
3129
- if (envName !== "rsc" && envName !== "ssr") return;
3130
- const outDir = options.dir;
3131
- if (!outDir) return;
3132
- const manifest = { prerenderSecret };
3133
- fs.writeFileSync(path.join(outDir, "vinext-server.json"), JSON.stringify(manifest));
3690
+ {
3691
+ name: "vinext:server-manifest",
3692
+ apply: "build",
3693
+ enforce: "post",
3694
+ writeBundle: {
3695
+ sequential: true,
3696
+ order: "post",
3697
+ handler(options) {
3698
+ const environment = this.environment;
3699
+ if (!environment || (hasAppDir ? environment.name !== "rsc" : !isServerEnvironment(environment))) return;
3700
+ const outDir = options.dir;
3701
+ if (!outDir) return;
3702
+ const canonicalServerDir = path.join(root, "dist", "server");
3703
+ if (selectedMultiStageOutput) {
3704
+ if (readPrerenderSecret(canonicalServerDir) === prerenderSecret) for (const runtimeOutputDir of readServerRuntimeOutputDirs(canonicalServerDir, root)) serverRuntimeOutputDirs.add(runtimeOutputDir);
3705
+ serverRuntimeOutputDirs.add(path.resolve(outDir));
3706
+ }
3707
+ const manifest = {
3708
+ prerenderSecret,
3709
+ ...serverRuntimeOutputDirs.size === 0 ? {} : { runtimeOutputDirs: [...serverRuntimeOutputDirs].map((runtimeOutputDir) => path.relative(root, runtimeOutputDir) || ".").sort() }
3710
+ };
3711
+ const source = JSON.stringify(manifest);
3712
+ fs.writeFileSync(path.join(outDir, "vinext-server.json"), source);
3713
+ if (path.resolve(outDir) !== canonicalServerDir) {
3714
+ fs.mkdirSync(canonicalServerDir, { recursive: true });
3715
+ fs.writeFileSync(path.join(canonicalServerDir, "vinext-server.json"), source);
3134
3716
  }
3135
3717
  }
3136
- };
3137
- })(),
3718
+ }
3719
+ },
3138
3720
  {
3139
3721
  name: "vinext:nitro-route-rules",
3140
3722
  nitro: { setup: async (nitro) => {
3723
+ nitroBuildDir = nitro.options.buildDir ? path.resolve(root, nitro.options.buildDir) : void 0;
3724
+ nitroHostRuntime = nitro.options.exportConditions?.includes("workerd") ? "worker" : "node";
3141
3725
  if (!nextConfig) return;
3142
3726
  if (!hasAppDir && !hasPagesDir) return;
3143
3727
  if (resolvedServerExternalPackages.length > 0) nitro.options.traceDeps = [.../* @__PURE__ */ new Set([...nitro.options.traceDeps ?? [], ...resolvedServerExternalPackages])];
@@ -3168,7 +3752,10 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3168
3752
  const ssrManifestPath = path.join(viteDir, "ssr-manifest.json");
3169
3753
  if (!fs.existsSync(ssrManifestPath)) return;
3170
3754
  try {
3171
- const augmentedManifest = augmentSsrManifestFromBundle(JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8")), bundle, this.environment?.config.root ?? process.cwd(), this.environment?.config.base ?? "/");
3755
+ const ssrManifest = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
3756
+ const buildRoot = this.environment?.config.root ?? process.cwd();
3757
+ const buildBase = this.environment?.config.base ?? "/";
3758
+ const augmentedManifest = augmentSsrManifestFromBundle(ssrManifest, bundle, buildRoot, buildBase);
3172
3759
  fs.writeFileSync(ssrManifestPath, JSON.stringify(augmentedManifest, null, 2));
3173
3760
  } catch (err) {
3174
3761
  console.warn("[vinext] Failed to augment SSR manifest:", err);
@@ -3288,17 +3875,13 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3288
3875
  clientEntry: runtimeMetadata.clientEntryFile ?? void 0,
3289
3876
  appBootstrapPreinitModules: runtimeMetadata.appBootstrapPreinitModules,
3290
3877
  ssrManifest,
3878
+ cssGraph: runtimeMetadata.cssGraph,
3291
3879
  lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
3292
- dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0
3880
+ dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0,
3881
+ crossOrigin: nextConfig.crossOrigin ?? ""
3293
3882
  });
3294
- const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
3295
- if (hasAppDir && hasPagesDir && buildSession) setPagesClientAssetsBuildMetadata(buildSession, pagesClientAssetsModule);
3296
- }
3297
- if (pagesClientAssetsModule === null) {
3298
- if (pagesClientAssetsOutputDirs.size === 0) return;
3299
- const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
3300
- if (buildSession) pagesClientAssetsModule = takePagesClientAssetsBuildMetadata(buildSession);
3301
3883
  }
3884
+ if (pagesClientAssetsModule === null && pagesClientAssetsOutputDirs.size === 0) return;
3302
3885
  if (pagesClientAssetsModule === null) {
3303
3886
  const emptyModule = buildPagesClientAssetsModule({});
3304
3887
  for (const outputDir of pagesClientAssetsOutputDirs) writePagesClientAssetsModuleIfMissing(outputDir, emptyModule);
@@ -3332,7 +3915,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3332
3915
  const envConfig = this.environment?.config;
3333
3916
  if (!envConfig) return;
3334
3917
  const buildRoot = envConfig.root ?? process.cwd();
3335
- const manifest = collectInlineCssManifest(path.resolve(buildRoot, "dist", "client"), nextConfig.assetPrefix);
3918
+ const clientDir = path.resolve(buildRoot, "dist", "client");
3919
+ const manifest = collectInlineCssManifest(clientDir, nextConfig.assetPrefix);
3336
3920
  const rscOutDir = path.resolve(buildRoot, options.rscOutDir ?? path.join("dist", "server"));
3337
3921
  for (const entryFile of ["index.js", "index.mjs"]) if (injectInlineCssManifestGlobal(path.join(rscOutDir, entryFile), manifest)) break;
3338
3922
  }
@@ -3369,6 +3953,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3369
3953
  }
3370
3954
  },
3371
3955
  createWasmModuleImportPlugin(),
3956
+ createOgHarfbuzzPlugin(),
3372
3957
  {
3373
3958
  name: "vinext:og-font-patch",
3374
3959
  enforce: "pre",
@@ -3425,6 +4010,33 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3425
4010
  }
3426
4011
  }
3427
4012
  ];
4013
+ if (cacheAdapterBuildOutputs.length > 0) plugins.push({
4014
+ name: "vinext:cache-adapter-build-output",
4015
+ apply: "build",
4016
+ enforce: "post",
4017
+ writeBundle: {
4018
+ sequential: true,
4019
+ order: "post",
4020
+ async handler(outputOptions) {
4021
+ if (!outputOptions.dir) return;
4022
+ const config = this.environment?.config;
4023
+ if (!config) return;
4024
+ const build = { plugins: config.plugins };
4025
+ const buildRoot = config.root ?? process.cwd();
4026
+ const outDir = path.resolve(buildRoot, outputOptions.dir);
4027
+ const loadedEntries = serverEntryKindsByEnvironment.get(this.environment?.name ?? "");
4028
+ const isPrimaryServerOutput = Boolean(loadedEntries?.has(RESOLVED_RSC_ENTRY) || loadedEntries?.has(RESOLVED_APP_REQUEST_ENTRY) || loadedEntries?.has(RESOLVED_APP_RESPONSE_ENTRY) || loadedEntries?.has(RESOLVED_PAGES_REQUEST_ENTRY) || loadedEntries?.has(RESOLVED_PAGES_RESPONSE_ENTRY) || loadedEntries?.has(RESOLVED_SERVER_ENTRY) && !loadedEntries.has(RESOLVED_APP_SSR_ENTRY));
4029
+ for (const output of cacheAdapterBuildOutputs) {
4030
+ if (output.matchesBuild && !output.matchesBuild(build)) continue;
4031
+ await output.finalizeBuildOutput?.({
4032
+ root: buildRoot,
4033
+ outDir,
4034
+ isPrimaryServerOutput
4035
+ });
4036
+ }
4037
+ }
4038
+ }
4039
+ });
3428
4040
  if (rscPluginPromise) plugins.push(rscPluginPromise);
3429
4041
  if (earlyAppDirExists) plugins.push(createActionOwnerManifestPlugin({
3430
4042
  canonicalizeModuleId: canonicalize,
@@ -3442,6 +4054,27 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
3442
4054
  plugins.push(createRscReferenceValidationNormalizerPlugin());
3443
4055
  plugins.push(createRscClientReferenceLoadersPlugin());
3444
4056
  } else if (manualUseCachePluginPromise) plugins.push(manualUseCachePluginPromise);
4057
+ plugins.push({
4058
+ name: "vinext:plain-pages-build-config",
4059
+ apply: "build",
4060
+ enforce: "post",
4061
+ config: {
4062
+ order: "post",
4063
+ handler(config) {
4064
+ if (!hasPlainPagesBuildEnvironments) return;
4065
+ if (config.build?.watch || config.build?.ssr || config.build?.lib || getBuildBundlerOptions(config.build)?.input !== void 0) {
4066
+ for (const name of ["client", "ssr"]) if (originalPlainPagesEnvironments?.[name]) config.environments[name] = originalPlainPagesEnvironments[name];
4067
+ else delete config.environments?.[name];
4068
+ return;
4069
+ }
4070
+ return { builder: {
4071
+ ...config.builder,
4072
+ sharedConfigBuild: true
4073
+ } };
4074
+ }
4075
+ }
4076
+ });
4077
+ plugins.push(buildLifecyclePlugins[1]);
3445
4078
  return plugins;
3446
4079
  }
3447
4080
  /**