@qzsy/vinext 0.1.12 → 0.1.80

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 (225) hide show
  1. package/README.md +19 -5
  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/pages-client-assets-module.d.ts +11 -0
  5. package/dist/build/pages-client-assets-module.js +27 -0
  6. package/dist/build/prerender.d.ts +2 -1
  7. package/dist/build/prerender.js +11 -4
  8. package/dist/build/report.d.ts +2 -1
  9. package/dist/build/report.js +2 -1
  10. package/dist/build/run-prerender.d.ts +7 -0
  11. package/dist/build/run-prerender.js +9 -0
  12. package/dist/build/standalone.js +2 -0
  13. package/dist/check.d.ts +18 -0
  14. package/dist/check.js +77 -19
  15. package/dist/cli-dev-config.d.ts +12 -0
  16. package/dist/cli-dev-config.js +23 -0
  17. package/dist/cli.js +64 -28
  18. package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
  19. package/dist/{server → client}/dev-error-overlay-store.js +1 -1
  20. package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
  21. package/dist/{server → client}/dev-error-overlay.js +2 -2
  22. package/dist/cloudflare/deploy-config.d.ts +51 -0
  23. package/dist/cloudflare/deploy-config.js +153 -0
  24. package/dist/cloudflare/index.d.ts +1 -1
  25. package/dist/cloudflare/index.js +1 -1
  26. package/dist/cloudflare/project.d.ts +41 -0
  27. package/dist/cloudflare/project.js +243 -0
  28. package/dist/cloudflare/tpr.js +1 -1
  29. package/dist/config/config-matchers.js +14 -10
  30. package/dist/config/next-config.d.ts +6 -3
  31. package/dist/config/next-config.js +47 -1
  32. package/dist/config/server-external-packages.d.ts +4 -0
  33. package/dist/config/server-external-packages.js +91 -0
  34. package/dist/deploy.d.ts +2 -122
  35. package/dist/deploy.js +20 -793
  36. package/dist/entries/app-rsc-entry.d.ts +2 -1
  37. package/dist/entries/app-rsc-entry.js +70 -12
  38. package/dist/entries/app-rsc-manifest.js +8 -0
  39. package/dist/entries/pages-client-entry.d.ts +1 -0
  40. package/dist/entries/pages-client-entry.js +2 -1
  41. package/dist/entries/pages-server-entry.js +6 -2
  42. package/dist/image/image-adapters-virtual.d.ts +59 -0
  43. package/dist/image/image-adapters-virtual.js +50 -0
  44. package/dist/index.d.ts +12 -0
  45. package/dist/index.js +158 -109
  46. package/dist/init-cloudflare.d.ts +43 -0
  47. package/dist/init-cloudflare.js +1000 -0
  48. package/dist/init-platform.d.ts +38 -0
  49. package/dist/init-platform.js +150 -0
  50. package/dist/init.d.ts +14 -37
  51. package/dist/init.js +205 -95
  52. package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
  53. package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
  54. package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
  55. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
  56. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
  57. package/dist/plugins/ast-scope.d.ts +16 -0
  58. package/dist/plugins/ast-scope.js +62 -0
  59. package/dist/plugins/ast-utils.js +3 -0
  60. package/dist/plugins/css-module-imports.d.ts +14 -0
  61. package/dist/plugins/css-module-imports.js +59 -0
  62. package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
  63. package/dist/plugins/ignore-dynamic-requests.js +530 -0
  64. package/dist/plugins/middleware-server-only.d.ts +8 -6
  65. package/dist/plugins/middleware-server-only.js +8 -7
  66. package/dist/plugins/optimize-imports.js +1 -1
  67. package/dist/plugins/typeof-window.d.ts +1 -1
  68. package/dist/plugins/typeof-window.js +28 -56
  69. package/dist/routing/app-route-graph.d.ts +13 -2
  70. package/dist/routing/app-route-graph.js +116 -32
  71. package/dist/routing/app-router.d.ts +5 -0
  72. package/dist/routing/app-router.js +5 -0
  73. package/dist/routing/file-matcher.d.ts +8 -0
  74. package/dist/routing/file-matcher.js +10 -1
  75. package/dist/routing/pages-router.js +2 -2
  76. package/dist/server/app-browser-action-result.d.ts +2 -1
  77. package/dist/server/app-browser-action-result.js +5 -1
  78. package/dist/server/app-browser-entry.js +17 -12
  79. package/dist/server/app-browser-history-controller.d.ts +2 -1
  80. package/dist/server/app-browser-history-controller.js +6 -2
  81. package/dist/server/app-browser-interception-context.d.ts +1 -0
  82. package/dist/server/app-browser-interception-context.js +4 -2
  83. package/dist/server/app-browser-navigation-controller.js +1 -0
  84. package/dist/server/app-browser-server-action-client.js +2 -3
  85. package/dist/server/app-browser-state.d.ts +1 -0
  86. package/dist/server/app-browser-state.js +3 -2
  87. package/dist/server/app-fallback-renderer.d.ts +3 -2
  88. package/dist/server/app-fallback-renderer.js +12 -7
  89. package/dist/server/app-middleware.d.ts +2 -3
  90. package/dist/server/app-middleware.js +3 -2
  91. package/dist/server/app-optimistic-routing.js +1 -1
  92. package/dist/server/app-page-boundary-render.d.ts +1 -0
  93. package/dist/server/app-page-boundary-render.js +12 -3
  94. package/dist/server/app-page-cache-finalizer.d.ts +1 -0
  95. package/dist/server/app-page-cache-finalizer.js +10 -3
  96. package/dist/server/app-page-cache-render.d.ts +1 -0
  97. package/dist/server/app-page-cache-render.js +8 -4
  98. package/dist/server/app-page-cache.d.ts +1 -0
  99. package/dist/server/app-page-cache.js +4 -1
  100. package/dist/server/app-page-dispatch.d.ts +11 -3
  101. package/dist/server/app-page-dispatch.js +55 -15
  102. package/dist/server/app-page-element-builder.d.ts +5 -1
  103. package/dist/server/app-page-element-builder.js +57 -20
  104. package/dist/server/app-page-head.d.ts +12 -0
  105. package/dist/server/app-page-head.js +42 -19
  106. package/dist/server/app-page-params.d.ts +2 -1
  107. package/dist/server/app-page-params.js +8 -1
  108. package/dist/server/app-page-probe.d.ts +1 -0
  109. package/dist/server/app-page-probe.js +6 -1
  110. package/dist/server/app-page-render-identity.d.ts +1 -0
  111. package/dist/server/app-page-render-identity.js +1 -1
  112. package/dist/server/app-page-render.d.ts +4 -1
  113. package/dist/server/app-page-render.js +8 -3
  114. package/dist/server/app-page-request.d.ts +22 -1
  115. package/dist/server/app-page-request.js +89 -13
  116. package/dist/server/app-page-route-wiring.d.ts +6 -1
  117. package/dist/server/app-page-route-wiring.js +31 -15
  118. package/dist/server/app-page-search-params-observation.d.ts +4 -2
  119. package/dist/server/app-page-search-params-observation.js +11 -7
  120. package/dist/server/app-page-segment-state.js +2 -0
  121. package/dist/server/app-route-handler-dispatch.js +1 -0
  122. package/dist/server/app-route-handler-execution.js +7 -2
  123. package/dist/server/app-route-handler-response.js +1 -0
  124. package/dist/server/app-route-handler-runtime.js +1 -1
  125. package/dist/server/app-route-module-loader.d.ts +2 -0
  126. package/dist/server/app-route-module-loader.js +1 -0
  127. package/dist/server/app-router-entry.d.ts +12 -0
  128. package/dist/server/app-router-entry.js +22 -8
  129. package/dist/server/app-router-image-optimization.d.ts +37 -0
  130. package/dist/server/app-router-image-optimization.js +40 -0
  131. package/dist/server/app-rsc-errors.js +7 -1
  132. package/dist/server/app-rsc-handler.js +27 -14
  133. package/dist/server/app-rsc-route-matching.d.ts +7 -0
  134. package/dist/server/app-rsc-route-matching.js +36 -3
  135. package/dist/server/app-segment-config.d.ts +12 -0
  136. package/dist/server/app-segment-config.js +91 -5
  137. package/dist/server/app-server-action-execution.d.ts +5 -0
  138. package/dist/server/app-server-action-execution.js +94 -33
  139. package/dist/server/app-ssr-entry.js +12 -1
  140. package/dist/server/app-static-generation.d.ts +1 -0
  141. package/dist/server/app-static-generation.js +1 -0
  142. package/dist/server/client-trace-metadata.js +26 -0
  143. package/dist/server/default-global-not-found-module.d.ts +14 -0
  144. package/dist/server/default-global-not-found-module.js +14 -0
  145. package/dist/server/dev-server.js +8 -15
  146. package/dist/server/dev-stack-sourcemap.d.ts +1 -1
  147. package/dist/server/dev-stack-sourcemap.js +1 -1
  148. package/dist/server/headers.d.ts +5 -15
  149. package/dist/server/headers.js +4 -15
  150. package/dist/server/image-optimization.d.ts +51 -1
  151. package/dist/server/image-optimization.js +52 -2
  152. package/dist/server/isr-cache.d.ts +1 -1
  153. package/dist/server/isr-cache.js +2 -2
  154. package/dist/server/middleware-runtime.js +6 -1
  155. package/dist/server/navigation-planner.d.ts +1 -0
  156. package/dist/server/navigation-planner.js +14 -3
  157. package/dist/server/pages-asset-tags.d.ts +4 -6
  158. package/dist/server/pages-asset-tags.js +12 -12
  159. package/dist/server/pages-client-assets.d.ts +12 -0
  160. package/dist/server/pages-client-assets.js +10 -0
  161. package/dist/server/pages-page-data.d.ts +23 -1
  162. package/dist/server/pages-page-data.js +43 -24
  163. package/dist/server/pages-page-handler.d.ts +2 -1
  164. package/dist/server/pages-page-handler.js +10 -4
  165. package/dist/server/pages-request-pipeline.d.ts +2 -0
  166. package/dist/server/pages-request-pipeline.js +25 -1
  167. package/dist/server/prerender-manifest.d.ts +3 -1
  168. package/dist/server/prerender-route-params.js +1 -1
  169. package/dist/server/prod-server.d.ts +1 -1
  170. package/dist/server/prod-server.js +47 -25
  171. package/dist/server/request-pipeline.js +1 -0
  172. package/dist/server/seed-cache.js +4 -4
  173. package/dist/server/worker-utils.d.ts +2 -1
  174. package/dist/server/worker-utils.js +7 -1
  175. package/dist/shims/app-router-scroll-state.d.ts +1 -0
  176. package/dist/shims/app-router-scroll-state.js +1 -0
  177. package/dist/shims/app-router-scroll.js +2 -1
  178. package/dist/shims/cache.js +19 -15
  179. package/dist/shims/cdn-cache.js +1 -1
  180. package/dist/shims/dynamic-preload-chunks.js +2 -1
  181. package/dist/shims/error-boundary.d.ts +19 -1
  182. package/dist/shims/error-boundary.js +11 -1
  183. package/dist/shims/form.d.ts +3 -1
  184. package/dist/shims/form.js +37 -43
  185. package/dist/shims/headers.d.ts +9 -1
  186. package/dist/shims/headers.js +31 -6
  187. package/dist/shims/image-optimization-url.d.ts +4 -0
  188. package/dist/shims/image-optimization-url.js +33 -1
  189. package/dist/shims/image.js +46 -13
  190. package/dist/shims/internal/app-route-detection.d.ts +2 -17
  191. package/dist/shims/internal/app-route-detection.js +4 -17
  192. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
  193. package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
  194. package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -5
  195. package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
  196. package/dist/shims/internal/pages-router-components.d.ts +7 -0
  197. package/dist/shims/internal/pages-router-components.js +13 -0
  198. package/dist/shims/link.js +23 -16
  199. package/dist/shims/metadata.d.ts +3 -2
  200. package/dist/shims/metadata.js +8 -4
  201. package/dist/shims/navigation.js +4 -2
  202. package/dist/shims/root-params.d.ts +15 -1
  203. package/dist/shims/root-params.js +21 -1
  204. package/dist/shims/router.d.ts +2 -5
  205. package/dist/shims/router.js +41 -22
  206. package/dist/shims/server.js +3 -2
  207. package/dist/typegen.js +6 -5
  208. package/dist/utils/client-runtime-metadata.d.ts +2 -18
  209. package/dist/utils/client-runtime-metadata.js +31 -22
  210. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
  211. package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
  212. package/dist/utils/domain-locale.d.ts +6 -3
  213. package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
  214. package/dist/{server → utils}/middleware-request-headers.js +2 -2
  215. package/dist/utils/path.d.ts +2 -1
  216. package/dist/utils/path.js +1 -1
  217. package/dist/utils/project.d.ts +9 -1
  218. package/dist/utils/project.js +21 -4
  219. package/dist/utils/protocol-headers.d.ts +17 -0
  220. package/dist/utils/protocol-headers.js +17 -0
  221. package/dist/utils/react-version.d.ts +4 -0
  222. package/dist/utils/react-version.js +44 -0
  223. package/package.json +6 -1
  224. package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
  225. /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { detectPackageManager } from "./utils/project.js";
2
- import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
3
2
  import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
4
3
  import { escapeRegExp } from "./utils/regex.js";
4
+ import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
5
5
  import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
6
6
  import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
7
- import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
7
+ import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
8
+ import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
8
9
  import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
9
10
  import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
10
11
  import { isOpenRedirectShaped } from "./server/open-redirect.js";
@@ -16,6 +17,8 @@ import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from
16
17
  import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
17
18
  import { isUnknownRecord } from "./utils/record.js";
18
19
  import { logRequest, now } from "./server/request-log.js";
20
+ import { resolvePagesI18nRequest } from "./server/pages-i18n.js";
21
+ import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
19
22
  import { createSSRHandler } from "./server/dev-server.js";
20
23
  import { handleApiRoute } from "./server/api-handler.js";
21
24
  import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
@@ -27,6 +30,7 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
27
30
  import { generateRscEntry } from "./entries/app-rsc-entry.js";
28
31
  import { generateSsrEntry } from "./entries/app-ssr-entry.js";
29
32
  import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
33
+ import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
30
34
  import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
31
35
  import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
32
36
  import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
@@ -35,7 +39,7 @@ import { resolveAssetsDir } from "./utils/asset-prefix.js";
35
39
  import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
36
40
  import { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine } from "./utils/vite-version.js";
37
41
  import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
38
- import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
42
+ import { mergeServerExternalPackages } from "./config/server-external-packages.js";
39
43
  import { precompressAssets } from "./build/precompress.js";
40
44
  import { ensureAssetsIgnore } from "./build/assets-ignore.js";
41
45
  import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
@@ -48,6 +52,7 @@ import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
48
52
  import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
49
53
  import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
50
54
  import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
55
+ import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
51
56
  import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
52
57
  import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
53
58
  import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
@@ -60,9 +65,11 @@ import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins
60
65
  import { generateRouteTypes } from "./typegen.js";
61
66
  import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
62
67
  import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
68
+ import { hasWranglerConfig } from "./cloudflare/project.js";
69
+ import { formatMissingCloudflarePluginError } from "./cloudflare/deploy-config.js";
63
70
  import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
64
- import { buildRuntimeGlobalsScript, computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
65
- import { formatMissingCloudflarePluginError, hasWranglerConfig } from "./deploy.js";
71
+ import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
72
+ import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
66
73
  import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
67
74
  import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
68
75
  import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
@@ -76,6 +83,7 @@ import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
76
83
  import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeof-window.js";
77
84
  import { hasMdxFiles } from "./utils/mdx-scan.js";
78
85
  import { scanPublicFileRoutes } from "./utils/public-routes.js";
86
+ import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
79
87
  import { staticExportApp, staticExportPages } from "./build/static-export.js";
80
88
  import { createRequire } from "node:module";
81
89
  import fs from "node:fs";
@@ -301,6 +309,8 @@ const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
301
309
  const RESOLVED_SERVER_ENTRY = "\0virtual:vinext-server-entry";
302
310
  const VIRTUAL_CLIENT_ENTRY = "virtual:vinext-client-entry";
303
311
  const RESOLVED_CLIENT_ENTRY = "\0virtual:vinext-client-entry";
312
+ const VIRTUAL_PAGES_CLIENT_ASSETS = "virtual:vinext-pages-client-assets";
313
+ const RESOLVED_PAGES_CLIENT_ASSETS = "\0virtual:vinext-pages-client-assets";
304
314
  const VIRTUAL_RSC_ENTRY = "virtual:vinext-rsc-entry";
305
315
  const RESOLVED_RSC_ENTRY = "\0virtual:vinext-rsc-entry";
306
316
  const VIRTUAL_APP_SSR_ENTRY = "virtual:vinext-app-ssr-entry";
@@ -312,6 +322,8 @@ const RESOLVED_APP_CAPABILITIES = "\0virtual:vinext-app-capabilities";
312
322
  const RESOLVED_ROOT_PARAMS = "\0virtual:vinext-root-params";
313
323
  /** Virtual module that registers config-driven cache adapters (see VinextOptions.cache). */
314
324
  const RESOLVED_CACHE_ADAPTERS = "\0" + VIRTUAL_CACHE_ADAPTERS;
325
+ /** Virtual module that registers the config-driven image optimizer (see VinextOptions.images). */
326
+ const RESOLVED_IMAGE_ADAPTERS = "\0" + VIRTUAL_IMAGE_ADAPTERS;
315
327
  /** Virtual module for composed instrumentation-client bootstrap. */
316
328
  const VIRTUAL_INSTRUMENTATION_CLIENT = "private-next-instrumentation-client";
317
329
  const RESOLVED_INSTRUMENTATION_CLIENT = `${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs`;
@@ -337,9 +349,11 @@ function createStaticImageAsset(imagePath) {
337
349
  * the `id.startsWith(_shimsDir)` checks would never match.
338
350
  */
339
351
  const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
352
+ const _serverDir = normalizePathSeparators(path.resolve(__dirname, "server"));
340
353
  const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
341
- const _appBrowserServerActionClientPath = resolveShimModulePath(normalizePathSeparators(path.resolve(__dirname, "server")), "app-browser-server-action-client");
342
- const _appRscHandlerPath = resolveShimModulePath(normalizePathSeparators(path.resolve(__dirname, "server")), "app-rsc-handler");
354
+ const _appBrowserServerActionClientPath = resolveShimModulePath(_serverDir, "app-browser-server-action-client");
355
+ const _appRscHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-handler");
356
+ const _pagesClientAssetsPath = resolveShimModulePath(_serverDir, "pages-client-assets");
343
357
  const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js");
344
358
  const _defaultImageLoaderShimPath = resolveShimModulePath(_shimsDir, "default-image-loader");
345
359
  /** Absolute path to `images.loaderFile` when configured; set in vinext:config. */
@@ -472,6 +486,8 @@ function vinext(options = {}) {
472
486
  let hasCloudflarePlugin = false;
473
487
  let warnedInlineNextConfigOverride = false;
474
488
  let hasNitroPlugin = false;
489
+ const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
490
+ let pagesClientAssetsModule = null;
475
491
  let rscCompatibilityId;
476
492
  const draftModeSecret = randomUUID();
477
493
  const sassComposesLoader = createSassAwareFileSystemLoader();
@@ -517,7 +533,8 @@ function vinext(options = {}) {
517
533
  const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => isLinkPrefetchRoute(route) ? toLinkPrefetchRoute(route) : toDocumentOnlyAppRoute(route)) : [];
518
534
  return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
519
535
  appPrefetchRoutes,
520
- instrumentationClientPath
536
+ instrumentationClientPath,
537
+ reactPreamble: options.react !== false
521
538
  });
522
539
  }
523
540
  async function writeRouteTypes() {
@@ -608,6 +625,7 @@ function vinext(options = {}) {
608
625
  const plugins = [
609
626
  ...viteMajorVersion >= 8 ? [] : [loadVite7TsconfigPathsPlugin(earlyBaseDir)],
610
627
  reactPluginPromise,
628
+ createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
611
629
  commonjs(),
612
630
  ...viteMajorVersion >= 8 ? [{
613
631
  name: "vinext:jsx-in-js",
@@ -636,9 +654,14 @@ function vinext(options = {}) {
636
654
  createMiddlewareServerOnlyPlugin({
637
655
  getMiddlewarePath: () => middlewarePath,
638
656
  getCanonicalMiddlewarePath: () => middlewarePath ? tryRealpathSync(middlewarePath) ?? middlewarePath : null,
657
+ isNeutralServerModule: (id) => {
658
+ const canonicalId = canonicalizePageTransformPath(id);
659
+ return isWithinPagesDirectory(canonicalId) && isApiPage(canonicalId);
660
+ },
639
661
  serverOnlyShimPath: resolveShimModulePath(shimsDir, "server-only")
640
662
  }),
641
663
  dataUrlCssPlugin(),
664
+ createCssModuleImportCompatibilityPlugin(),
642
665
  {
643
666
  name: "vinext:image-loader-file",
644
667
  enforce: "pre",
@@ -758,6 +781,7 @@ function vinext(options = {}) {
758
781
  defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowSVG ?? false));
759
782
  defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
760
783
  defines["process.env.__VINEXT_IMAGE_LOADER_CONFIGURED"] = JSON.stringify(nextConfig.images?.loaderFile ? "true" : "false");
784
+ defines["process.env.__VINEXT_IMAGE_UNOPTIMIZED"] = JSON.stringify(String(nextConfig.images?.unoptimized === true));
761
785
  defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
762
786
  defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
763
787
  defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
@@ -824,7 +848,7 @@ function vinext(options = {}) {
824
848
  "vinext/cache": path.resolve(__dirname, "cache"),
825
849
  "vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
826
850
  "vinext/instrumentation-client": path.resolve(__dirname, "client", "instrumentation-client"),
827
- "vinext/dev-error-overlay": path.resolve(__dirname, "server", "dev-error-overlay"),
851
+ "vinext/dev-error-overlay": path.resolve(__dirname, "client", "dev-error-overlay"),
828
852
  "vinext/html": path.resolve(__dirname, "server", "html"),
829
853
  ...clientInjectModule === null ? { "private-next-instrumentation-client": instrumentationClientPath ?? INSTRUMENTATION_CLIENT_EMPTY_MODULE } : {}
830
854
  }).flatMap(([k, v]) => k.startsWith("next/") ? [[k, v], [`${k}.js`, v]] : [[k, v]]));
@@ -842,6 +866,8 @@ function vinext(options = {}) {
842
866
  hasUserMdxPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "@mdx-js/rollup" || p.name === "mdx"));
843
867
  if (!hasUserMdxPlugin && hasMdxFiles(root, hasAppDir ? appDir : null, hasPagesDir ? pagesDir : null)) await ensureMdxDelegate("detected");
844
868
  const isSSR = !!config.build?.ssr;
869
+ const serverTranspilePackages = [...nextConfig?.turbopackTranspilePackages ?? [], ...nextConfig?.optimizePackageImports ?? []];
870
+ const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages);
845
871
  const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
846
872
  const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
847
873
  const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
@@ -893,7 +919,9 @@ function vinext(options = {}) {
893
919
  "react",
894
920
  "react-dom",
895
921
  "react-dom/server",
896
- "ipaddr.js"
922
+ "ipaddr.js",
923
+ ...Array.isArray(config.ssr?.external) ? config.ssr.external : [],
924
+ ...nextServerExternal
897
925
  ],
898
926
  noExternal: true
899
927
  } },
@@ -901,7 +929,8 @@ function vinext(options = {}) {
901
929
  alias: {
902
930
  ...tsconfigPathAliases,
903
931
  ...nextConfig.aliases,
904
- ...nextShimMap
932
+ ...nextShimMap,
933
+ "vinext/server/pages-client-assets": _pagesClientAssetsPath
905
934
  },
906
935
  dedupe: [
907
936
  "react",
@@ -938,7 +967,6 @@ function vinext(options = {}) {
938
967
  ...cssModulesOverride
939
968
  }
940
969
  };
941
- const nextServerExternal = nextConfig?.serverExternalPackages ?? [];
942
970
  const userSsrExternal = Array.isArray(config.ssr?.external) ? [...config.ssr.external, ...nextServerExternal] : config.ssr?.external === true ? true : nextServerExternal;
943
971
  const externalizeSsrReactInDev = env.command === "serve" && !hasCloudflarePlugin && !hasNitroPlugin;
944
972
  const incomingExclude = config.optimizeDeps?.exclude ?? [];
@@ -1075,7 +1103,8 @@ function vinext(options = {}) {
1075
1103
  "react",
1076
1104
  "react-dom",
1077
1105
  "react-dom/server",
1078
- "ipaddr.js"
1106
+ "ipaddr.js",
1107
+ ...nextServerExternal
1079
1108
  ],
1080
1109
  noExternal: true
1081
1110
  },
@@ -1146,7 +1175,7 @@ function vinext(options = {}) {
1146
1175
  resolveId: {
1147
1176
  filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/app-rsc-handler)|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
1148
1177
  handler(id, importer) {
1149
- const cleanId = id.startsWith("\0") ? id.slice(1) : id;
1178
+ const cleanId = normalizePathSeparators(id.startsWith("\0") ? id.slice(1) : id);
1150
1179
  if (cleanId === "vinext/server/app-rsc-handler") {
1151
1180
  if (_canExternalizeAppRscHandler && this.environment?.name === "rsc" && this.environment.config?.command === "serve") return {
1152
1181
  id: _appRscHandlerPath,
@@ -1158,19 +1187,20 @@ function vinext(options = {}) {
1158
1187
  if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
1159
1188
  if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
1160
1189
  if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
1161
- if (cleanId.endsWith("/virtual:vinext-server-entry") || cleanId.endsWith("\\virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
1162
- if (cleanId.endsWith("/virtual:vinext-client-entry") || cleanId.endsWith("\\virtual:vinext-client-entry")) return RESOLVED_CLIENT_ENTRY;
1190
+ if (cleanId.endsWith("/virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
1191
+ if (cleanId.endsWith("/virtual:vinext-client-entry")) return RESOLVED_CLIENT_ENTRY;
1163
1192
  if (cleanId === VIRTUAL_RSC_ENTRY) return RESOLVED_RSC_ENTRY;
1164
1193
  if (cleanId === VIRTUAL_APP_SSR_ENTRY) return RESOLVED_APP_SSR_ENTRY;
1165
1194
  if (cleanId === VIRTUAL_APP_BROWSER_ENTRY) return RESOLVED_APP_BROWSER_ENTRY;
1166
1195
  if (cleanId === VIRTUAL_APP_CAPABILITIES) return RESOLVED_APP_CAPABILITIES;
1167
1196
  if (cleanId === "next/root-params" || cleanId === "next/root-params.js") return RESOLVED_ROOT_PARAMS;
1168
- if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters") || cleanId.endsWith("\\virtual:vinext-cache-adapters")) return RESOLVED_CACHE_ADAPTERS;
1197
+ if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters")) return RESOLVED_CACHE_ADAPTERS;
1198
+ if (cleanId === "virtual:vinext-image-adapters" || cleanId.endsWith("/virtual:vinext-image-adapters")) return RESOLVED_IMAGE_ADAPTERS;
1169
1199
  if (cleanId.startsWith("virtual:vinext-google-fonts?")) return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(VIRTUAL_GOOGLE_FONTS.length);
1170
- if (cleanId.endsWith("/virtual:vinext-rsc-entry") || cleanId.endsWith("\\virtual:vinext-rsc-entry")) return RESOLVED_RSC_ENTRY;
1171
- if (cleanId.endsWith("/virtual:vinext-app-ssr-entry") || cleanId.endsWith("\\virtual:vinext-app-ssr-entry")) return RESOLVED_APP_SSR_ENTRY;
1172
- if (cleanId.endsWith("/virtual:vinext-app-browser-entry") || cleanId.endsWith("\\virtual:vinext-app-browser-entry")) return RESOLVED_APP_BROWSER_ENTRY;
1173
- if (cleanId.includes("/virtual:vinext-google-fonts?") || cleanId.includes("\\virtual:vinext-google-fonts?")) {
1200
+ if (cleanId.endsWith("/virtual:vinext-rsc-entry")) return RESOLVED_RSC_ENTRY;
1201
+ if (cleanId.endsWith("/virtual:vinext-app-ssr-entry")) return RESOLVED_APP_SSR_ENTRY;
1202
+ if (cleanId.endsWith("/virtual:vinext-app-browser-entry")) return RESOLVED_APP_BROWSER_ENTRY;
1203
+ if (cleanId.includes("/virtual:vinext-google-fonts?")) {
1174
1204
  const queryIndex = cleanId.indexOf(VIRTUAL_GOOGLE_FONTS + "?");
1175
1205
  return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(queryIndex + VIRTUAL_GOOGLE_FONTS.length);
1176
1206
  }
@@ -1181,12 +1211,13 @@ function vinext(options = {}) {
1181
1211
  async load(id) {
1182
1212
  if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1();
1183
1213
  if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
1214
+ if (id === RESOLVED_PAGES_CLIENT_ASSETS) return "export default { clientEntry: '/@id/__x00__virtual:vinext-client-entry' };";
1184
1215
  if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
1185
1216
  const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
1186
1217
  const metaRoutes = scanMetadataFiles(appDir);
1187
1218
  const hasServerActions = await resolveHasServerActions(this.environment.config);
1188
1219
  const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
1189
- const globalNotFoundPath = findFileWithExts(appDir, "global-not-found", fileMatcher);
1220
+ const globalNotFoundPath = nextConfig?.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
1190
1221
  rscClassificationManifest = collectRouteClassificationManifest(routes);
1191
1222
  return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
1192
1223
  redirects: nextConfig?.redirects,
@@ -1203,13 +1234,18 @@ function vinext(options = {}) {
1203
1234
  reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
1204
1235
  cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
1205
1236
  inlineCss: nextConfig?.inlineCss,
1237
+ globalNotFound: nextConfig?.globalNotFound,
1206
1238
  cacheComponents: nextConfig?.cacheComponents,
1207
1239
  hasServerActions,
1208
1240
  i18n: nextConfig?.i18n,
1209
1241
  imageConfig: {
1210
1242
  deviceSizes: nextConfig?.images?.deviceSizes,
1211
1243
  imageSizes: nextConfig?.images?.imageSizes,
1212
- qualities: nextConfig?.images?.qualities
1244
+ qualities: nextConfig?.images?.qualities,
1245
+ dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
1246
+ dangerouslyAllowLocalIP: nextConfig?.images?.dangerouslyAllowLocalIP,
1247
+ contentDispositionType: nextConfig?.images?.contentDispositionType,
1248
+ contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
1213
1249
  },
1214
1250
  hasPagesDir,
1215
1251
  publicFiles: scanPublicFileRoutes(root),
@@ -1219,6 +1255,7 @@ function vinext(options = {}) {
1219
1255
  }
1220
1256
  if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
1221
1257
  if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
1258
+ if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
1222
1259
  if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
1223
1260
  if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
1224
1261
  const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
@@ -1278,6 +1315,28 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1278
1315
  }
1279
1316
  }
1280
1317
  },
1318
+ {
1319
+ name: "vinext:pages-client-assets-resolver",
1320
+ sharedDuringBuild: true,
1321
+ resolveId: {
1322
+ filter: { id: /virtual:vinext-pages-client-assets$/ },
1323
+ handler(id) {
1324
+ const cleanId = normalizePathSeparators(id.startsWith("\0") ? id.slice(1) : id);
1325
+ if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/virtual:vinext-pages-client-assets")) return;
1326
+ if (this.environment?.config.command !== "build") return RESOLVED_PAGES_CLIENT_ASSETS;
1327
+ const buildRoot = this.environment.config.root ?? process.cwd();
1328
+ const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
1329
+ const sidecarDir = !hasAppDir && this.environment.name === "ssr" ? path.dirname(environmentOutDir) : environmentOutDir;
1330
+ let externalId = normalizePathSeparators(path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE)));
1331
+ if (!externalId.startsWith(".")) externalId = `./${externalId}`;
1332
+ pagesClientAssetsOutputDirs.add(sidecarDir);
1333
+ return {
1334
+ id: externalId,
1335
+ external: true
1336
+ };
1337
+ }
1338
+ }
1339
+ },
1281
1340
  {
1282
1341
  name: "vinext:css-url-assets-mark",
1283
1342
  enforce: "pre",
@@ -1298,11 +1357,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1298
1357
  }
1299
1358
  },
1300
1359
  {
1301
- name: "vinext:client-css-url-assets-defaults",
1360
+ name: "vinext:css-url-assets-defaults",
1302
1361
  apply: "build",
1303
- configEnvironment(name) {
1304
- if (name !== "client") return null;
1305
- return { build: { assetsInlineLimit: clientAssetsInlineLimit } };
1362
+ configEnvironment(name, config) {
1363
+ if (name === "client") return { build: { assetsInlineLimit: clientAssetsInlineLimit } };
1364
+ if (!hasAppDir || name !== "rsc" && name !== "ssr") return null;
1365
+ const output = getBuildBundlerOptions(config.build)?.output;
1366
+ if (Array.isArray(output) || output?.assetFileNames !== void 0) return null;
1367
+ return { build: { ...withBuildBundlerOptions(viteMajorVersion, { output: { assetFileNames: createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? "")) } }) } };
1306
1368
  }
1307
1369
  },
1308
1370
  {
@@ -1385,6 +1447,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1385
1447
  }
1386
1448
  }
1387
1449
  },
1450
+ createCssModuleImportCompatibilityPlugin({ compiledMdx: true }),
1388
1451
  {
1389
1452
  name: "vinext:react-canary",
1390
1453
  enforce: "pre",
@@ -1844,11 +1907,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
1844
1907
  hadBasePath: true,
1845
1908
  isDataReq,
1846
1909
  isDataRequest,
1910
+ hasMiddleware: capturedMiddlewarePath !== null,
1847
1911
  rawSearch: url.includes("?") ? url.slice(url.indexOf("?")) : "",
1848
1912
  runMiddleware: devRunMiddlewareAdapter,
1849
- matchPageRoute: (resolvedPathname) => {
1850
- const m = matchRoute(resolvedPathname, devPageRoutes);
1851
- return m ? { route: { isDynamic: m.route.isDynamic } } : null;
1913
+ matchPageRoute: (resolvedPathname, request) => {
1914
+ const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, new URL(request.url).hostname, bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
1915
+ return m ? { route: {
1916
+ isDynamic: m.route.isDynamic,
1917
+ pattern: m.route.pattern
1918
+ } } : null;
1852
1919
  },
1853
1920
  proxyExternal: async (currentRequest, externalUrl) => {
1854
1921
  const externalMethod = req.method ?? "GET";
@@ -2035,7 +2102,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2035
2102
  handler(code, id) {
2036
2103
  const cacheDirPrefix = getCacheDirPrefix(this.environment.config.cacheDir);
2037
2104
  if (normalizePathSeparators(id).startsWith(cacheDirPrefix)) return null;
2038
- return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
2105
+ return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment), id);
2039
2106
  }
2040
2107
  }
2041
2108
  },
@@ -2289,29 +2356,6 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2289
2356
  createOgInlineFetchAssetsPlugin(),
2290
2357
  createOgAssetsPlugin(),
2291
2358
  createServerExternalsManifestPlugin(),
2292
- {
2293
- name: "vinext:image-config",
2294
- apply: "build",
2295
- enforce: "post",
2296
- writeBundle: {
2297
- sequential: true,
2298
- order: "post",
2299
- handler(options) {
2300
- if (this.environment?.name !== "rsc") return;
2301
- const outDir = options.dir;
2302
- if (!outDir) return;
2303
- const imageConfig = {
2304
- deviceSizes: nextConfig?.images?.deviceSizes,
2305
- imageSizes: nextConfig?.images?.imageSizes,
2306
- qualities: nextConfig?.images?.qualities,
2307
- dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
2308
- contentDispositionType: nextConfig?.images?.contentDispositionType,
2309
- contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
2310
- };
2311
- fs.writeFileSync(path.join(outDir, "image-config.json"), JSON.stringify(imageConfig));
2312
- }
2313
- }
2314
- },
2315
2359
  (() => {
2316
2360
  let buildIdWritten = false;
2317
2361
  return {
@@ -2484,6 +2528,65 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2484
2528
  }
2485
2529
  };
2486
2530
  })(),
2531
+ {
2532
+ name: "vinext:pages-client-assets",
2533
+ apply: "build",
2534
+ enforce: "post",
2535
+ sharedDuringBuild: true,
2536
+ closeBundle: {
2537
+ sequential: true,
2538
+ order: "post",
2539
+ handler() {
2540
+ const envConfig = this.environment.config;
2541
+ if (this.environment.name === "client") {
2542
+ const buildRoot = envConfig.root ?? process.cwd();
2543
+ const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
2544
+ const runtimeMetadata = computeClientRuntimeMetadata({
2545
+ clientDir,
2546
+ assetBase: envConfig.base ?? "/",
2547
+ assetPrefix: nextConfig.assetPrefix,
2548
+ includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
2549
+ });
2550
+ let ssrManifest;
2551
+ const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
2552
+ if (fs.existsSync(ssrManifestPath)) try {
2553
+ ssrManifest = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
2554
+ } catch {}
2555
+ pagesClientAssetsModule = buildPagesClientAssetsModule({
2556
+ clientEntry: runtimeMetadata.clientEntryFile ?? void 0,
2557
+ appBootstrapPreinitModules: runtimeMetadata.appBootstrapPreinitModules,
2558
+ ssrManifest,
2559
+ lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
2560
+ dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0
2561
+ });
2562
+ const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
2563
+ if (hasAppDir && hasPagesDir && buildSession) setPagesClientAssetsBuildMetadata(buildSession, pagesClientAssetsModule);
2564
+ }
2565
+ if (pagesClientAssetsModule === null) {
2566
+ if (pagesClientAssetsOutputDirs.size === 0) return;
2567
+ const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
2568
+ if (buildSession) pagesClientAssetsModule = takePagesClientAssetsBuildMetadata(buildSession);
2569
+ }
2570
+ if (pagesClientAssetsModule === null) {
2571
+ const emptyModule = buildPagesClientAssetsModule({});
2572
+ for (const outputDir of pagesClientAssetsOutputDirs) writePagesClientAssetsModuleIfMissing(outputDir, emptyModule);
2573
+ return;
2574
+ }
2575
+ for (const outputDir of pagesClientAssetsOutputDirs) {
2576
+ fs.mkdirSync(outputDir, { recursive: true });
2577
+ fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
2578
+ }
2579
+ }
2580
+ },
2581
+ buildApp() {
2582
+ if (pagesClientAssetsModule === null) return Promise.resolve();
2583
+ for (const outputDir of pagesClientAssetsOutputDirs) {
2584
+ fs.mkdirSync(outputDir, { recursive: true });
2585
+ fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
2586
+ }
2587
+ return Promise.resolve();
2588
+ }
2589
+ },
2487
2590
  {
2488
2591
  name: "vinext:inline-css-manifest",
2489
2592
  apply: "build",
@@ -2517,61 +2620,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
2517
2620
  const envConfig = this.environment?.config;
2518
2621
  if (!envConfig) return;
2519
2622
  const buildRoot = envConfig.root ?? process.cwd();
2520
- const distDir = path.resolve(buildRoot, "dist");
2521
- if (!fs.existsSync(distDir)) return;
2522
- const clientDir = path.resolve(buildRoot, "dist", "client");
2523
- const runtimeMetadata = computeClientRuntimeMetadata({
2524
- clientDir,
2525
- assetBase: envConfig.base ?? "/",
2526
- assetPrefix: nextConfig.assetPrefix,
2527
- includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
2528
- });
2529
- const lazyChunksData = runtimeMetadata.lazyChunks ?? null;
2530
- const dynamicPreloadsData = runtimeMetadata.dynamicPreloads ?? null;
2531
- let clientEntryFile = runtimeMetadata.clientEntryFile ?? null;
2532
- let ssrManifestData = null;
2533
- const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
2534
- if (fs.existsSync(ssrManifestPath)) try {
2535
- ssrManifestData = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
2536
- } catch {}
2537
- if (hasAppDir) {
2538
- const workerEntry = path.resolve(distDir, "server", "index.js");
2539
- if (fs.existsSync(workerEntry)) {
2540
- const script = buildRuntimeGlobalsScript({
2541
- clientEntryFile,
2542
- ssrManifest: ssrManifestData,
2543
- lazyChunks: lazyChunksData,
2544
- dynamicPreloads: dynamicPreloadsData
2545
- });
2546
- if (script) {
2547
- const code = fs.readFileSync(workerEntry, "utf-8");
2548
- fs.writeFileSync(workerEntry, script + "\n" + code);
2549
- }
2550
- }
2551
- } else {
2552
- let workerOutDir = null;
2553
- for (const entry of fs.readdirSync(distDir)) {
2554
- const candidate = path.join(distDir, entry);
2555
- if (entry === "client") continue;
2556
- if (fs.statSync(candidate).isDirectory() && fs.existsSync(path.join(candidate, "wrangler.json"))) {
2557
- workerOutDir = candidate;
2558
- break;
2559
- }
2560
- }
2561
- if (!workerOutDir) return;
2562
- const workerEntry = path.join(workerOutDir, "index.js");
2563
- if (!fs.existsSync(workerEntry)) return;
2564
- const script = buildRuntimeGlobalsScript({
2565
- clientEntryFile,
2566
- ssrManifest: ssrManifestData,
2567
- lazyChunks: lazyChunksData,
2568
- dynamicPreloads: dynamicPreloadsData
2569
- });
2570
- if (script) {
2571
- const code = fs.readFileSync(workerEntry, "utf-8");
2572
- fs.writeFileSync(workerEntry, script + "\n" + code);
2573
- }
2574
- }
2623
+ const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
2575
2624
  const headersPath = path.join(clientDir, "_headers");
2576
2625
  if (!fs.existsSync(headersPath)) {
2577
2626
  const headersContent = [
@@ -0,0 +1,43 @@
1
+ import { CloudflareInitOptions } from "./init-platform.js";
2
+
3
+ //#region src/init-cloudflare.d.ts
4
+ type CloudflareProjectInfo = {
5
+ root: string;
6
+ projectName: string;
7
+ isAppRouter: boolean;
8
+ hasISR: boolean;
9
+ hasMDX: boolean;
10
+ nativeModulesToStub: string[];
11
+ };
12
+ type CloudflarePlatformSetupContext = {
13
+ root: string;
14
+ isAppRouter: boolean;
15
+ existingViteConfigPath?: string;
16
+ today?: string;
17
+ };
18
+ type CloudflarePlatformSetupResult = {
19
+ generatedViteConfig: boolean;
20
+ skippedViteConfig: boolean;
21
+ generatedPlatformFiles: string[];
22
+ nextSteps: string[];
23
+ };
24
+ declare function validateCloudflarePlatformSetup(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): void;
25
+ declare function setupCloudflarePlatform(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): CloudflarePlatformSetupResult;
26
+ declare function generateWranglerConfig(info: CloudflareProjectInfo, options?: CloudflareInitOptions, today?: string): string;
27
+ declare function updateWranglerConfigForCloudflare(code: string, options: CloudflareInitOptions): string;
28
+ declare function getWranglerImagesBinding(code: string): string;
29
+ /** Generate worker/index.ts for Pages Router */
30
+ declare function generatePagesRouterWorkerEntry(): string;
31
+ /** Generate vite.config.ts for App Router */
32
+ declare function generateAppRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string): string;
33
+ /** Generate vite.config.ts for Pages Router */
34
+ declare function generatePagesRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string): string;
35
+ declare function updateViteConfigForCloudflare(filePath: string, code: string, options: {
36
+ isAppRouter: boolean;
37
+ nativeModulesToStub: string[];
38
+ cache?: CloudflareInitOptions;
39
+ imagesBinding?: string;
40
+ }): string;
41
+ declare function usesCommonJsViteConfig(filePath: string, code: string): boolean;
42
+ //#endregion
43
+ export { CloudflarePlatformSetupContext, CloudflarePlatformSetupResult, CloudflareProjectInfo, generateAppRouterViteConfig, generatePagesRouterViteConfig, generatePagesRouterWorkerEntry, generateWranglerConfig, getWranglerImagesBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };