vinext 0.1.7 → 0.2.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 (279) hide show
  1. package/README.md +51 -30
  2. package/dist/build/inject-pregenerated-paths.d.ts +4 -0
  3. package/dist/build/inject-pregenerated-paths.js +18 -0
  4. package/dist/build/layout-classification.js +1 -1
  5. package/dist/build/nitro-route-rules.js +1 -1
  6. package/dist/build/pages-client-assets-module.d.ts +11 -0
  7. package/dist/build/pages-client-assets-module.js +27 -0
  8. package/dist/build/prerender.d.ts +2 -1
  9. package/dist/build/prerender.js +13 -6
  10. package/dist/build/report.d.ts +13 -2
  11. package/dist/build/report.js +99 -2
  12. package/dist/build/run-prerender.d.ts +7 -0
  13. package/dist/build/run-prerender.js +10 -1
  14. package/dist/build/standalone.js +2 -0
  15. package/dist/cache/cache-adapters-virtual.js +3 -3
  16. package/dist/check.d.ts +18 -0
  17. package/dist/check.js +77 -19
  18. package/dist/cli-args.d.ts +1 -2
  19. package/dist/cli-args.js +1 -1
  20. package/dist/cli-dev-config.d.ts +12 -0
  21. package/dist/cli-dev-config.js +23 -0
  22. package/dist/cli.js +113 -97
  23. package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
  24. package/dist/{server → client}/dev-error-overlay-store.js +1 -1
  25. package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
  26. package/dist/{server → client}/dev-error-overlay.js +2 -2
  27. package/dist/client/navigation-runtime.d.ts +2 -0
  28. package/dist/client/navigation-runtime.js +3 -1
  29. package/dist/client/window-next.d.ts +2 -1
  30. package/dist/cloudflare/index.d.ts +2 -2
  31. package/dist/cloudflare/index.js +2 -2
  32. package/dist/config/config-matchers.js +14 -10
  33. package/dist/config/next-config.d.ts +6 -3
  34. package/dist/config/next-config.js +47 -1
  35. package/dist/config/prerender.d.ts +34 -0
  36. package/dist/config/prerender.js +55 -0
  37. package/dist/config/server-external-packages.d.ts +4 -0
  38. package/dist/config/server-external-packages.js +91 -0
  39. package/dist/entries/app-rsc-entry.d.ts +2 -1
  40. package/dist/entries/app-rsc-entry.js +89 -15
  41. package/dist/entries/app-rsc-manifest.js +10 -0
  42. package/dist/entries/pages-client-entry.d.ts +3 -0
  43. package/dist/entries/pages-client-entry.js +16 -1
  44. package/dist/entries/pages-server-entry.js +6 -2
  45. package/dist/image/image-adapters-virtual.d.ts +59 -0
  46. package/dist/image/image-adapters-virtual.js +59 -0
  47. package/dist/index.d.ts +33 -0
  48. package/dist/index.js +211 -118
  49. package/dist/init-cloudflare.d.ts +43 -0
  50. package/dist/init-cloudflare.js +839 -0
  51. package/dist/init-platform.d.ts +40 -0
  52. package/dist/init-platform.js +195 -0
  53. package/dist/init.d.ts +16 -38
  54. package/dist/init.js +208 -97
  55. package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
  56. package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
  57. package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
  58. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
  59. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
  60. package/dist/packages/cloudflare/src/deploy-config.js +150 -0
  61. package/dist/packages/cloudflare/src/deploy-help.js +55 -0
  62. package/dist/packages/cloudflare/src/deploy.js +276 -0
  63. package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
  64. package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +18 -15
  65. package/dist/plugins/ast-scope.d.ts +16 -0
  66. package/dist/plugins/ast-scope.js +62 -0
  67. package/dist/plugins/ast-utils.d.ts +27 -1
  68. package/dist/plugins/ast-utils.js +32 -1
  69. package/dist/plugins/css-module-imports.d.ts +14 -0
  70. package/dist/plugins/css-module-imports.js +59 -0
  71. package/dist/plugins/extensionless-dynamic-import.js +2 -2
  72. package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
  73. package/dist/plugins/ignore-dynamic-requests.js +530 -0
  74. package/dist/plugins/middleware-server-only.d.ts +8 -6
  75. package/dist/plugins/middleware-server-only.js +8 -7
  76. package/dist/plugins/optimize-imports.js +1 -1
  77. package/dist/plugins/typeof-window.d.ts +1 -1
  78. package/dist/plugins/typeof-window.js +28 -56
  79. package/dist/routing/app-route-graph.d.ts +29 -4
  80. package/dist/routing/app-route-graph.js +182 -40
  81. package/dist/routing/app-router.d.ts +5 -0
  82. package/dist/routing/app-router.js +5 -0
  83. package/dist/routing/file-matcher.d.ts +8 -0
  84. package/dist/routing/file-matcher.js +10 -1
  85. package/dist/routing/pages-router.js +2 -2
  86. package/dist/server/api-handler.js +9 -14
  87. package/dist/server/app-browser-action-result.d.ts +4 -1
  88. package/dist/server/app-browser-action-result.js +8 -1
  89. package/dist/server/app-browser-entry.js +194 -190
  90. package/dist/server/app-browser-history-controller.d.ts +2 -1
  91. package/dist/server/app-browser-history-controller.js +6 -2
  92. package/dist/server/app-browser-interception-context.d.ts +1 -0
  93. package/dist/server/app-browser-interception-context.js +4 -2
  94. package/dist/server/app-browser-navigation-controller.d.ts +2 -0
  95. package/dist/server/app-browser-navigation-controller.js +60 -31
  96. package/dist/server/app-browser-server-action-client.d.ts +32 -0
  97. package/dist/server/app-browser-server-action-client.js +127 -0
  98. package/dist/server/app-browser-state.d.ts +11 -1
  99. package/dist/server/app-browser-state.js +25 -8
  100. package/dist/server/app-browser-visible-commit.d.ts +6 -1
  101. package/dist/server/app-browser-visible-commit.js +43 -25
  102. package/dist/server/app-elements-wire.d.ts +9 -2
  103. package/dist/server/app-elements-wire.js +8 -1
  104. package/dist/server/app-elements.d.ts +2 -2
  105. package/dist/server/app-elements.js +4 -3
  106. package/dist/server/app-fallback-renderer.d.ts +5 -2
  107. package/dist/server/app-fallback-renderer.js +15 -7
  108. package/dist/server/app-hydration-cache-publication.d.ts +11 -0
  109. package/dist/server/app-hydration-cache-publication.js +43 -0
  110. package/dist/server/app-middleware.d.ts +4 -3
  111. package/dist/server/app-middleware.js +8 -3
  112. package/dist/server/app-optimistic-routing.js +11 -4
  113. package/dist/server/app-page-boundary-render.d.ts +3 -0
  114. package/dist/server/app-page-boundary-render.js +14 -3
  115. package/dist/server/app-page-cache-finalizer.d.ts +1 -0
  116. package/dist/server/app-page-cache-finalizer.js +10 -3
  117. package/dist/server/app-page-cache-render.d.ts +1 -0
  118. package/dist/server/app-page-cache-render.js +8 -4
  119. package/dist/server/app-page-cache.d.ts +1 -0
  120. package/dist/server/app-page-cache.js +5 -2
  121. package/dist/server/app-page-dispatch.d.ts +33 -4
  122. package/dist/server/app-page-dispatch.js +63 -90
  123. package/dist/server/app-page-element-builder.d.ts +9 -2
  124. package/dist/server/app-page-element-builder.js +114 -23
  125. package/dist/server/app-page-head.d.ts +16 -1
  126. package/dist/server/app-page-head.js +44 -22
  127. package/dist/server/app-page-params.d.ts +2 -1
  128. package/dist/server/app-page-params.js +8 -1
  129. package/dist/server/app-page-ppr-runtime.d.ts +7 -0
  130. package/dist/server/app-page-ppr-runtime.js +70 -0
  131. package/dist/server/app-page-probe.d.ts +1 -0
  132. package/dist/server/app-page-probe.js +6 -1
  133. package/dist/server/app-page-render-identity.d.ts +1 -0
  134. package/dist/server/app-page-render-identity.js +1 -1
  135. package/dist/server/app-page-render.d.ts +4 -1
  136. package/dist/server/app-page-render.js +26 -3
  137. package/dist/server/app-page-request.d.ts +22 -1
  138. package/dist/server/app-page-request.js +92 -15
  139. package/dist/server/app-page-route-wiring.d.ts +14 -2
  140. package/dist/server/app-page-route-wiring.js +61 -25
  141. package/dist/server/app-page-search-params-observation.d.ts +4 -2
  142. package/dist/server/app-page-search-params-observation.js +11 -7
  143. package/dist/server/app-page-segment-state.d.ts +2 -1
  144. package/dist/server/app-page-segment-state.js +3 -1
  145. package/dist/server/app-page-stream.d.ts +5 -0
  146. package/dist/server/app-page-stream.js +3 -1
  147. package/dist/server/app-ppr-fallback-shell-render.d.ts +4 -3
  148. package/dist/server/app-route-handler-dispatch.js +1 -0
  149. package/dist/server/app-route-handler-execution.js +7 -2
  150. package/dist/server/app-route-handler-response.js +1 -0
  151. package/dist/server/app-route-handler-runtime.js +1 -1
  152. package/dist/server/app-route-module-loader.d.ts +2 -0
  153. package/dist/server/app-route-module-loader.js +1 -0
  154. package/dist/server/app-router-entry.js +16 -8
  155. package/dist/server/app-rsc-errors.js +7 -1
  156. package/dist/server/app-rsc-handler.d.ts +3 -1
  157. package/dist/server/app-rsc-handler.js +67 -39
  158. package/dist/server/app-rsc-request-normalization.d.ts +3 -2
  159. package/dist/server/app-rsc-request-normalization.js +6 -3
  160. package/dist/server/app-rsc-route-matching.d.ts +7 -0
  161. package/dist/server/app-rsc-route-matching.js +36 -3
  162. package/dist/server/app-segment-config.d.ts +12 -0
  163. package/dist/server/app-segment-config.js +91 -5
  164. package/dist/server/app-server-action-execution.d.ts +5 -0
  165. package/dist/server/app-server-action-execution.js +94 -33
  166. package/dist/server/app-ssr-entry.d.ts +3 -0
  167. package/dist/server/app-ssr-entry.js +19 -8
  168. package/dist/server/app-ssr-stream.d.ts +7 -3
  169. package/dist/server/app-ssr-stream.js +10 -6
  170. package/dist/server/app-static-generation.d.ts +1 -0
  171. package/dist/server/app-static-generation.js +1 -0
  172. package/dist/server/app-visited-response-cache.d.ts +6 -0
  173. package/dist/server/app-visited-response-cache.js +3 -1
  174. package/dist/server/client-trace-metadata.js +26 -0
  175. package/dist/server/default-global-not-found-module.d.ts +14 -0
  176. package/dist/server/default-global-not-found-module.js +14 -0
  177. package/dist/server/dev-route-files.js +4 -0
  178. package/dist/server/dev-server.js +19 -18
  179. package/dist/server/dev-stack-sourcemap.d.ts +1 -1
  180. package/dist/server/dev-stack-sourcemap.js +1 -1
  181. package/dist/server/fetch-handler.d.ts +2 -0
  182. package/dist/server/fetch-handler.js +18 -0
  183. package/dist/server/headers.d.ts +5 -15
  184. package/dist/server/headers.js +4 -15
  185. package/dist/server/image-optimization.d.ts +51 -1
  186. package/dist/server/image-optimization.js +52 -2
  187. package/dist/server/implicit-tags.js +1 -1
  188. package/dist/server/isr-cache.d.ts +1 -1
  189. package/dist/server/isr-cache.js +2 -2
  190. package/dist/server/metadata-routes.d.ts +3 -1
  191. package/dist/server/metadata-routes.js +12 -2
  192. package/dist/server/middleware-runtime.js +6 -1
  193. package/dist/server/navigation-planner.d.ts +1 -0
  194. package/dist/server/navigation-planner.js +14 -3
  195. package/dist/server/pages-api-route.js +2 -2
  196. package/dist/server/pages-asset-tags.d.ts +4 -6
  197. package/dist/server/pages-asset-tags.js +12 -12
  198. package/dist/server/pages-client-assets.d.ts +12 -0
  199. package/dist/server/pages-client-assets.js +10 -0
  200. package/dist/server/pages-node-compat.d.ts +8 -1
  201. package/dist/server/pages-node-compat.js +32 -4
  202. package/dist/server/pages-page-data.d.ts +24 -1
  203. package/dist/server/pages-page-data.js +45 -24
  204. package/dist/server/pages-page-handler.d.ts +2 -1
  205. package/dist/server/pages-page-handler.js +19 -12
  206. package/dist/server/pages-page-response.d.ts +7 -0
  207. package/dist/server/pages-page-response.js +4 -1
  208. package/dist/server/pages-request-pipeline.d.ts +2 -0
  209. package/dist/server/pages-request-pipeline.js +25 -1
  210. package/dist/server/pages-router-entry.d.ts +30 -0
  211. package/dist/server/pages-router-entry.js +108 -0
  212. package/dist/server/prerender-manifest.d.ts +3 -1
  213. package/dist/server/prerender-route-params.js +1 -1
  214. package/dist/server/prod-server.d.ts +1 -1
  215. package/dist/server/prod-server.js +48 -26
  216. package/dist/server/request-pipeline.js +1 -0
  217. package/dist/server/seed-cache.js +4 -4
  218. package/dist/server/worker-utils.d.ts +2 -1
  219. package/dist/server/worker-utils.js +7 -1
  220. package/dist/shims/app-router-scroll-state.d.ts +1 -0
  221. package/dist/shims/app-router-scroll-state.js +1 -0
  222. package/dist/shims/app-router-scroll.js +2 -1
  223. package/dist/shims/cache.js +19 -15
  224. package/dist/shims/cdn-cache.js +1 -1
  225. package/dist/shims/dynamic-preload-chunks.js +2 -1
  226. package/dist/shims/error-boundary.d.ts +19 -1
  227. package/dist/shims/error-boundary.js +11 -1
  228. package/dist/shims/form.d.ts +3 -1
  229. package/dist/shims/form.js +37 -43
  230. package/dist/shims/headers.d.ts +9 -1
  231. package/dist/shims/headers.js +31 -6
  232. package/dist/shims/image.js +75 -14
  233. package/dist/shims/internal/app-route-detection.d.ts +2 -17
  234. package/dist/shims/internal/app-route-detection.js +4 -17
  235. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
  236. package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
  237. package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -15
  238. package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
  239. package/dist/shims/internal/pages-data-fetch-dedup.d.ts +9 -5
  240. package/dist/shims/internal/pages-data-fetch-dedup.js +73 -14
  241. package/dist/shims/internal/pages-data-target.d.ts +10 -9
  242. package/dist/shims/internal/pages-data-target.js +91 -12
  243. package/dist/shims/internal/pages-router-components.d.ts +7 -0
  244. package/dist/shims/internal/pages-router-components.js +13 -0
  245. package/dist/shims/layout-segment-context.d.ts +4 -1
  246. package/dist/shims/layout-segment-context.js +18 -4
  247. package/dist/shims/link.js +70 -37
  248. package/dist/shims/metadata.d.ts +3 -2
  249. package/dist/shims/metadata.js +8 -4
  250. package/dist/shims/navigation.d.ts +5 -1
  251. package/dist/shims/navigation.js +45 -10
  252. package/dist/shims/navigation.react-server.js +1 -1
  253. package/dist/shims/root-params.d.ts +15 -1
  254. package/dist/shims/root-params.js +21 -1
  255. package/dist/shims/router.d.ts +5 -7
  256. package/dist/shims/router.js +374 -94
  257. package/dist/shims/server.js +3 -2
  258. package/dist/shims/slot.js +3 -6
  259. package/dist/typegen.js +6 -5
  260. package/dist/utils/client-runtime-metadata.d.ts +2 -18
  261. package/dist/utils/client-runtime-metadata.js +31 -22
  262. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
  263. package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
  264. package/dist/utils/domain-locale.d.ts +6 -3
  265. package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
  266. package/dist/{server → utils}/middleware-request-headers.js +2 -2
  267. package/dist/utils/path.d.ts +2 -1
  268. package/dist/utils/path.js +1 -1
  269. package/dist/utils/project.d.ts +52 -2
  270. package/dist/utils/project.js +230 -5
  271. package/dist/utils/protocol-headers.d.ts +17 -0
  272. package/dist/utils/protocol-headers.js +17 -0
  273. package/dist/utils/react-version.d.ts +4 -0
  274. package/dist/utils/react-version.js +44 -0
  275. package/package.json +53 -4
  276. package/dist/deploy.d.ts +0 -190
  277. package/dist/deploy.js +0 -1033
  278. package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
  279. /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
@@ -74,6 +74,7 @@ function registerRouteModules(routes, imports) {
74
74
  if (slot.pagePath) imports.getLazyLoaderVar(slot.pagePath);
75
75
  if (slot.defaultPath) imports.getLazyLoaderVar(slot.defaultPath);
76
76
  if (slot.layoutPath) imports.getLazyLoaderVar(slot.layoutPath);
77
+ for (const layoutPath of slot.configLayoutPaths ?? []) imports.getLazyLoaderVar(layoutPath);
77
78
  if (slot.loadingPath) imports.getLazyLoaderVar(slot.loadingPath);
78
79
  if (slot.errorPath) imports.getLazyLoaderVar(slot.errorPath);
79
80
  for (const ir of slot.interceptingRoutes) {
@@ -112,6 +113,8 @@ function buildRouteEntries(routes, imports) {
112
113
  slotId: ${JSON.stringify(ir.slotId ?? null)},
113
114
  interceptLayouts: ${moduleArray(ir.layoutPaths.length)},
114
115
  __loadInterceptLayouts: ${lazyLoaderArray(ir.layoutPaths, imports)},
116
+ interceptLayoutSegments: ${JSON.stringify(ir.layoutSegments ?? [])},
117
+ interceptBranchSegments: ${JSON.stringify(ir.branchSegments ?? [])},
115
118
  page: null,
116
119
  __pageLoader: ${imports.getLazyLoaderVar(ir.pagePath)},
117
120
  params: ${JSON.stringify(ir.params)},
@@ -124,6 +127,8 @@ function buildRouteEntries(routes, imports) {
124
127
  sourcePageSegments: ${JSON.stringify(ir.sourcePageSegments)},
125
128
  interceptLayouts: ${moduleArray(ir.layoutPaths.length)},
126
129
  __loadInterceptLayouts: ${lazyLoaderArray(ir.layoutPaths, imports)},
130
+ interceptLayoutSegments: ${JSON.stringify(ir.layoutSegments ?? [])},
131
+ interceptBranchSegments: ${JSON.stringify(ir.branchSegments ?? [])},
127
132
  page: null,
128
133
  __pageLoader: ${imports.getLazyLoaderVar(ir.pagePath)},
129
134
  params: ${JSON.stringify(ir.params)},
@@ -137,6 +142,9 @@ function buildRouteEntries(routes, imports) {
137
142
  __loadDefault: ${slot.defaultPath ? imports.getLazyLoaderVar(slot.defaultPath) : "null"},
138
143
  layout: null,
139
144
  __loadLayout: ${slot.layoutPath ? imports.getLazyLoaderVar(slot.layoutPath) : "null"},
145
+ configLayouts: ${moduleArray(slot.configLayoutPaths?.length ?? 0)},
146
+ __loadConfigLayouts: ${lazyLoaderArray(slot.configLayoutPaths ?? [], imports)},
147
+ configLayoutTreePositions: ${JSON.stringify(slot.configLayoutTreePositions ?? [])},
140
148
  loading: null,
141
149
  __loadLoading: ${slot.loadingPath ? imports.getLazyLoaderVar(slot.loadingPath) : "null"},
142
150
  error: null,
@@ -173,6 +181,7 @@ ${interceptEntries.join(",\n")}
173
181
  layouts: ${moduleArray(route.layouts.length)},
174
182
  __loadLayouts: ${layoutLoaders},
175
183
  routeSegments: ${JSON.stringify(route.routeSegments)},
184
+ childrenRouteSegments: ${JSON.stringify(route.childrenRouteSegments ?? null)},
176
185
  templateTreePositions: ${JSON.stringify(route.templateTreePositions)},
177
186
  layoutTreePositions: ${JSON.stringify(route.layoutTreePositions)},
178
187
  templates: ${moduleArray(route.templates.length)},
@@ -185,6 +194,7 @@ ${interceptEntries.join(",\n")}
185
194
  slots: {
186
195
  ${slotEntries.join(",\n")}
187
196
  },
197
+ childrenSlot: ${JSON.stringify(route.childrenSlot ?? null)},
188
198
  siblingIntercepts: [
189
199
  ${siblingInterceptEntries.join(",\n")}
190
200
  ],
@@ -1,11 +1,14 @@
1
1
  import { ResolvedNextConfig } from "../config/next-config.js";
2
2
  import { createValidFileMatcher } from "../routing/file-matcher.js";
3
+ import { StaticMiddlewareMatcher } from "../build/report.js";
3
4
  import { VinextLinkPrefetchRoute } from "../client/vinext-next-data.js";
4
5
 
5
6
  //#region src/entries/pages-client-entry.d.ts
6
7
  declare function generateClientEntry(pagesDir: string, nextConfig: ResolvedNextConfig, fileMatcher: ReturnType<typeof createValidFileMatcher>, options?: {
7
8
  appPrefetchRoutes?: readonly VinextLinkPrefetchRoute[];
8
9
  instrumentationClientPath?: string | null;
10
+ middlewareMatcher?: StaticMiddlewareMatcher | undefined;
11
+ reactPreamble?: boolean;
9
12
  }): Promise<string>;
10
13
  //#endregion
11
14
  export { generateClientEntry };
@@ -2,6 +2,9 @@ import { normalizePathSeparators } from "../utils/path.js";
2
2
  import { findFileWithExts } from "../routing/file-matcher.js";
3
3
  import { patternToNextFormat } from "../routing/route-validation.js";
4
4
  import { apiRouter, pagesRouter } from "../routing/pages-router.js";
5
+ import "./pages-entry-helpers.js";
6
+ import { hasExportedName } from "../build/report.js";
7
+ import { readFile } from "node:fs/promises";
5
8
  //#region src/entries/pages-client-entry.ts
6
9
  /**
7
10
  * Pages Router client hydration entry generator.
@@ -29,6 +32,12 @@ function toPagesLinkPrefetchRoute(route) {
29
32
  patternParts: [...route.patternParts]
30
33
  };
31
34
  }
35
+ async function hasGetStaticPropsExport(filePath) {
36
+ return hasExportedName(await readFile(filePath, "utf8"), "getStaticProps");
37
+ }
38
+ async function hasGetServerSidePropsExport(filePath) {
39
+ return hasExportedName(await readFile(filePath, "utf8"), "getServerSideProps");
40
+ }
32
41
  async function generateClientEntry(pagesDir, nextConfig, fileMatcher, options = {}) {
33
42
  const pageRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
34
43
  const apiRoutes = await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
@@ -39,6 +48,8 @@ async function generateClientEntry(pagesDir, nextConfig, fileMatcher, options =
39
48
  ...toPagesLinkPrefetchRoute(route),
40
49
  documentOnly: true
41
50
  }))];
51
+ const pagesSsgPatterns = (await Promise.all(pageRoutes.map(async (route) => await hasGetStaticPropsExport(route.filePath) ? patternToNextFormat(route.pattern) : null))).filter((pattern) => pattern !== null);
52
+ const pagesSspPatterns = (await Promise.all(pageRoutes.map(async (route) => await hasGetServerSidePropsExport(route.filePath) ? patternToNextFormat(route.pattern) : null))).filter((pattern) => pattern !== null);
42
53
  const instrumentationClientPath = options.instrumentationClientPath ?? null;
43
54
  const loaderEntries = pageRoutes.map((r) => {
44
55
  const absPath = normalizePathSeparators(r.filePath);
@@ -46,7 +57,7 @@ async function generateClientEntry(pagesDir, nextConfig, fileMatcher, options =
46
57
  return ` ${JSON.stringify(nextFormatPattern)}: () => import(${JSON.stringify(absPath)})`;
47
58
  });
48
59
  const appFileBase = appFilePath ? normalizePathSeparators(appFilePath) : void 0;
49
- return `${instrumentationClientPath ? `import ${JSON.stringify(normalizePathSeparators(instrumentationClientPath))};\n` : ""}
60
+ return `${instrumentationClientPath ? `import ${JSON.stringify(normalizePathSeparators(instrumentationClientPath))};\n` : ""}${options.reactPreamble === false ? "" : "import \"@vitejs/plugin-react/preamble\";\n"}
50
61
  import "vinext/instrumentation-client";
51
62
  import React from "react";
52
63
  import { hydrateRoot } from "react-dom/client";
@@ -78,6 +89,9 @@ const appLoader = undefined;
78
89
  // can iterate in order and trust the first match.
79
90
  window.__VINEXT_PAGE_LOADERS__ = pageLoaders;
80
91
  window.__VINEXT_PAGE_PATTERNS__ = Object.keys(pageLoaders);
92
+ window.__VINEXT_PAGES_SSG_PATTERNS__ = ${JSON.stringify(pagesSsgPatterns)};
93
+ window.__VINEXT_PAGES_SSP_PATTERNS__ = ${JSON.stringify(pagesSspPatterns)};
94
+ window.__VINEXT_MIDDLEWARE_MATCHER__ = ${JSON.stringify(options.middlewareMatcher)};
81
95
  window.__VINEXT_APP_LOADER__ = appLoader;
82
96
  // Expose the App Router prefetch manifest so Pages Router \`<Link>\`s and
83
97
  // \`Router.prefetch\` can detect when a prefetch target is actually an App
@@ -99,6 +113,7 @@ window.__VINEXT_LINK_PREFETCH_ROUTES__ = ${JSON.stringify(appPrefetchRoutes)};
99
113
  // instead of issuing an RSC request). Set here AND in app-browser-entry.ts
100
114
  // so whichever entry runs first emits the Pages manifest.
101
115
  window.__VINEXT_PAGES_LINK_PREFETCH_ROUTES__ = ${JSON.stringify(pagesPrefetchRoutes)};
116
+ window.__VINEXT_CLIENT_REDIRECTS__ = ${JSON.stringify(nextConfig.redirects)};
102
117
  window.__VINEXT_CLIENT_REWRITES__ = ${JSON.stringify(nextConfig.rewrites)};
103
118
 
104
119
  const nextDataElement = document.getElementById("__NEXT_DATA__");
@@ -3,6 +3,7 @@ import { findFileWithExts } from "../routing/file-matcher.js";
3
3
  import { apiRouter, pagesRouter } from "../routing/pages-router.js";
4
4
  import { resolveEntryPath } from "./runtime-entry-module.js";
5
5
  import { isProxyFile } from "../server/middleware.js";
6
+ import "./pages-entry-helpers.js";
6
7
  //#region src/entries/pages-server-entry.ts
7
8
  /**
8
9
  * Pages Router server entry generator.
@@ -127,6 +128,8 @@ import Router, { setSSRContext, wrapWithRouterContext, getPagesNavigationIsReady
127
128
  import { _runWithCacheState } from "vinext/shims/cache-request-state";
128
129
  import { configureMemoryCacheHandler as __configureMemoryCacheHandler } from "vinext/shims/cache-handler";
129
130
  import { registerConfiguredCacheAdapters as __registerConfiguredCacheAdapters } from "virtual:vinext-cache-adapters";
131
+ import __pagesClientAssets from "virtual:vinext-pages-client-assets";
132
+ import { setPagesClientAssets as __setPagesClientAssets } from "vinext/server/pages-client-assets";
130
133
  import { runWithPrivateCache } from "vinext/cache-runtime";
131
134
  import { ensureFetchPatch, runWithFetchCache } from "vinext/fetch-cache";
132
135
  import "vinext/router-state";
@@ -163,7 +166,7 @@ export const buildId = ${buildIdJson};
163
166
  export function normalizeDataRequest(request) {
164
167
  return __normalizePagesDataRequest(request, buildId);
165
168
  }
166
- const __hasMiddleware = ${JSON.stringify(Boolean(middlewarePath))};
169
+ export const hasMiddleware = ${JSON.stringify(Boolean(middlewarePath))};
167
170
 
168
171
  // Full resolved config for production server (embedded at build time)
169
172
  export const vinextConfig = ${vinextConfigJson};
@@ -270,6 +273,7 @@ export function matchApiRoute(url, request) {
270
273
  // All next/*-derived values are passed as closures so the handler module
271
274
  // stays importable in test environments (the root vite.config.ts only
272
275
  // aliases vinext/shims/*, not next/*).
276
+ __setPagesClientAssets(__pagesClientAssets);
273
277
  const _renderPage = __createPagesPageHandler({
274
278
  pageRoutes,
275
279
  errorPageRoute: _errorPageRoute,
@@ -285,7 +289,7 @@ const _renderPage = __createPagesPageHandler({
285
289
  disableOptimizedLoading: vinextConfig.disableOptimizedLoading,
286
290
  },
287
291
  buildId,
288
- hasMiddleware: __hasMiddleware,
292
+ hasMiddleware,
289
293
  appAssetPath: _appAssetPath,
290
294
  hasRewrites:
291
295
  vinextConfig.rewrites.beforeFiles.length > 0 ||
@@ -0,0 +1,59 @@
1
+ //#region src/image/image-adapters-virtual.d.ts
2
+ /**
3
+ * Code generation for the `virtual:vinext-image-adapters` module, resolved by
4
+ * the vinext vite plugin from the user's `images` config ({@link VinextImageConfig}).
5
+ *
6
+ * The generated module exports `registerConfiguredImageOptimizer(env)`, which the
7
+ * server entries call on each request. It self-guards (the optimizer instantiates
8
+ * once per isolate) and is a no-op when nothing is configured. Registration is
9
+ * resilient: a factory that throws (e.g. a Cloudflare Images adapter on the
10
+ * Node.js server, where the `IMAGES` binding can't exist) is logged and skipped
11
+ * rather than failing every request, so the same config can be registered from
12
+ * every runtime/router entry. When no optimizer is registered, image requests
13
+ * fall back to serving the original asset unoptimized.
14
+ *
15
+ * Descriptor `options` are inlined into the generated module and forwarded to the
16
+ * factory at runtime, so a config-time builder like `imagesOptimizer({ binding })`
17
+ * never touches the Workers runtime — instantiation is deferred to the first
18
+ * request.
19
+ *
20
+ * This mirrors the cache-adapter pattern in `cache/cache-adapters-virtual.ts`.
21
+ */
22
+ /**
23
+ * A serializable pointer to an image optimizer adapter module — the shape of the
24
+ * `images.optimizer` slot in the vinext() plugin config. Produced by an adapter
25
+ * builder (e.g. `imagesOptimizer(...)` from `@vinext/cloudflare/images/images-optimizer`)
26
+ * or written by hand. `options` must be JSON-serializable: it is inlined into the
27
+ * generated registration module and forwarded to the adapter factory at runtime.
28
+ */
29
+ type ImageAdapterDescriptor<O extends Record<string, unknown> = Record<string, unknown>> = {
30
+ /**
31
+ * Module specifier (or absolute path, e.g. from `require.resolve(...)`) whose
32
+ * default export is an image optimizer factory.
33
+ */
34
+ adapter: string; /** JSON-serializable options forwarded to the factory at runtime. */
35
+ options?: O;
36
+ };
37
+ /**
38
+ * The `images` option of the vinext() plugin: declaratively register the
39
+ * server-side image optimizer (transform backend) instead of wiring `env.IMAGES`
40
+ * into a custom worker entry.
41
+ *
42
+ * This is complementary to the `images` field in `next.config.js`, which
43
+ * configures the standard Next.js image options (`remotePatterns`, `deviceSizes`,
44
+ * `dangerouslyAllowSVG`, etc.). Those continue to be read from next.config; this
45
+ * option only selects the runtime transform backend, which can't be expressed as
46
+ * serializable next.config data.
47
+ */
48
+ type VinextImageConfig = {
49
+ /** Server-side image optimizer adapter (the `/_next/image` transform backend). */optimizer?: ImageAdapterDescriptor;
50
+ };
51
+ /** Public virtual module id imported by the server entries. */
52
+ declare const VIRTUAL_IMAGE_ADAPTERS = "virtual:vinext-image-adapters";
53
+ /**
54
+ * Generate the source of the `virtual:vinext-image-adapters` module for the
55
+ * given config. Always exports `registerConfiguredImageOptimizer(env)`.
56
+ */
57
+ declare function generateImageAdaptersModule(images?: VinextImageConfig): string;
58
+ //#endregion
59
+ export { VIRTUAL_IMAGE_ADAPTERS, VinextImageConfig, generateImageAdaptersModule };
@@ -0,0 +1,59 @@
1
+ //#region src/image/image-adapters-virtual.ts
2
+ /** Public virtual module id imported by the server entries. */
3
+ const VIRTUAL_IMAGE_ADAPTERS = "virtual:vinext-image-adapters";
4
+ /**
5
+ * Serialize descriptor options into a JS expression for inlining. Plain JSON is
6
+ * a valid JS literal; `undefined` when there are no options. Throws a clear
7
+ * config-time error (not a runtime one) if options are not serializable.
8
+ */
9
+ function inlineOptions(adapter, options) {
10
+ if (options === void 0) return "undefined";
11
+ try {
12
+ return JSON.stringify(options);
13
+ } catch (cause) {
14
+ throw new Error(`[vinext] image adapter "${adapter}" options must be JSON-serializable.`, { cause });
15
+ }
16
+ }
17
+ /**
18
+ * Generate the source of the `virtual:vinext-image-adapters` module for the
19
+ * given config. Always exports `registerConfiguredImageOptimizer(env)`.
20
+ */
21
+ function generateImageAdaptersModule(images) {
22
+ const optimizer = images?.optimizer;
23
+ if (!optimizer?.adapter) return [
24
+ "// vinext: no images.optimizer adapter configured — registration is a no-op.",
25
+ "export function registerConfiguredImageOptimizer() {}",
26
+ ""
27
+ ].join("\n");
28
+ return [
29
+ "// vinext: generated from the `images` option in your vinext() plugin config.",
30
+ `import __vinextImageOptimizerFactory from ${JSON.stringify(optimizer.adapter)};`,
31
+ `import { setImageOptimizer } from "vinext/server/image-optimization";`,
32
+ "",
33
+ "// A factory that throws (e.g. a missing binding on an incompatible runtime)",
34
+ "// is logged and skipped so images fall back to unoptimized passthrough.",
35
+ "function __vinextFormatAdapterError(error) {",
36
+ " if (error instanceof Error && error.message) return error.message;",
37
+ " try {",
38
+ " return String(error);",
39
+ " } catch {",
40
+ " return '<unknown error>';",
41
+ " }",
42
+ "}",
43
+ "",
44
+ "let __vinextImageOptimizerRegistered = false;",
45
+ "",
46
+ "export function registerConfiguredImageOptimizer(env) {",
47
+ " if (__vinextImageOptimizerRegistered) return;",
48
+ " __vinextImageOptimizerRegistered = true;",
49
+ " try {",
50
+ ` setImageOptimizer(__vinextImageOptimizerFactory({ env, options: ${inlineOptions(optimizer.adapter, optimizer.options)} }));`,
51
+ " } catch (error) {",
52
+ " console.warn(\"[vinext] failed to initialize the configured image optimizer; serving images unoptimized.\\n\" + __vinextFormatAdapterError(error));",
53
+ " }",
54
+ "}",
55
+ ""
56
+ ].join("\n");
57
+ }
58
+ //#endregion
59
+ export { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { NextConfig, NextConfigInput } from "./config/next-config.js";
2
2
  import { AppStaticExportOptions, StaticExportOptions, StaticExportResult, staticExportApp, staticExportPages } from "./build/static-export.js";
3
3
  import { VinextCacheConfig } from "./cache/cache-adapters-virtual.js";
4
+ import { VinextPrerenderConfig } from "./config/prerender.js";
5
+ import { VinextImageConfig } from "./image/image-adapters-virtual.js";
4
6
  import { PluginOption } from "vite";
5
7
  import { Options } from "@vitejs/plugin-react";
6
8
 
@@ -79,6 +81,26 @@ type VinextOptions = {
79
81
  * @default false
80
82
  */
81
83
  precompress?: boolean;
84
+ /**
85
+ * Pre-render routes after `vinext build` without passing
86
+ * `--prerender-all`.
87
+ *
88
+ * Use `true` as shorthand for `{ routes: "*" }`. The object form is
89
+ * available so future releases can support narrower route selections, but
90
+ * currently only `"*"` is supported.
91
+ *
92
+ * The `vinext build --prerender-all` and `vinext deploy --prerender-all`
93
+ * flags still work and take priority when present.
94
+ *
95
+ * @example
96
+ * vinext({ prerender: true })
97
+ *
98
+ * @example
99
+ * vinext({ prerender: { routes: "*" } })
100
+ *
101
+ * @default undefined
102
+ */
103
+ prerender?: VinextPrerenderConfig;
82
104
  /**
83
105
  * Configure cache handlers declaratively, so you don't need a custom worker
84
106
  * entry that calls `setDataCacheHandler()` / `setCdnCacheAdapter()`. Each slot
@@ -97,6 +119,17 @@ type VinextOptions = {
97
119
  * })
98
120
  */
99
121
  cache?: VinextCacheConfig;
122
+ /**
123
+ * Configure the server-side image optimizer declaratively. The adapter factory
124
+ * receives the host `env`, allowing bindings such as Cloudflare Images to be
125
+ * used by both built-in and custom worker entrypoints that forward `env`.
126
+ *
127
+ * @example
128
+ * import { imagesOptimizer } from "@vinext/cloudflare/images/images-optimizer";
129
+ *
130
+ * vinext({ images: { optimizer: imagesOptimizer() } })
131
+ */
132
+ images?: VinextImageConfig;
100
133
  /**
101
134
  * Experimental vinext-only feature flags.
102
135
  */