vinext 1.0.0-beta.11 → 1.0.0-beta.13

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 (170) hide show
  1. package/README.md +39 -12
  2. package/dist/build/action-owner-manifest.js +23 -5
  3. package/dist/build/lifecycle.d.ts +42 -0
  4. package/dist/build/lifecycle.js +246 -0
  5. package/dist/build/nitro-route-rules.js +1 -1
  6. package/dist/build/pages-client-assets-module.d.ts +0 -3
  7. package/dist/build/pages-client-assets-module.js +1 -13
  8. package/dist/build/precompress.js +1 -1
  9. package/dist/build/prerender-paths.d.ts +1 -1
  10. package/dist/build/prerender-paths.js +6 -6
  11. package/dist/build/prerender-server-pool.js +1 -1
  12. package/dist/build/prerender.d.ts +1 -1
  13. package/dist/build/prerender.js +5 -5
  14. package/dist/build/preview-credentials.d.ts +1 -1
  15. package/dist/build/preview-credentials.js +2 -2
  16. package/dist/build/report.js +1 -1
  17. package/dist/build/run-prerender.d.ts +2 -2
  18. package/dist/build/run-prerender.js +5 -5
  19. package/dist/build/standalone.js +2 -2
  20. package/dist/cli-args.d.ts +5 -13
  21. package/dist/cli-args.js +2 -45
  22. package/dist/cli-dev-config.d.ts +6 -2
  23. package/dist/cli-dev-config.js +160 -3
  24. package/dist/cli.js +104 -439
  25. package/dist/config/config-matchers.js +1 -1
  26. package/dist/config/next-config.d.ts +2 -2
  27. package/dist/config/next-config.js +5 -5
  28. package/dist/config/prerender.d.ts +3 -0
  29. package/dist/config/prerender.js +8 -2
  30. package/dist/entries/app-browser-entry.js +1 -1
  31. package/dist/entries/app-rsc-entry.d.ts +2 -0
  32. package/dist/entries/app-rsc-entry.js +25 -5
  33. package/dist/entries/pages-client-entry.d.ts +1 -0
  34. package/dist/entries/pages-client-entry.js +17 -2
  35. package/dist/index.d.ts +6 -8
  36. package/dist/index.js +282 -105
  37. package/dist/init-cloudflare.d.ts +3 -2
  38. package/dist/init-cloudflare.js +117 -5
  39. package/dist/init-platform.d.ts +2 -0
  40. package/dist/init-platform.js +9 -3
  41. package/dist/init.d.ts +7 -5
  42. package/dist/init.js +41 -22
  43. package/dist/plugins/dynamic-preload-metadata.js +1 -1
  44. package/dist/plugins/extensionless-dynamic-import.js +2 -2
  45. package/dist/plugins/fonts.js +1 -1
  46. package/dist/plugins/ignore-dynamic-requests.js +1 -1
  47. package/dist/plugins/import-meta-url.js +1 -1
  48. package/dist/plugins/instrumentation-client.js +1 -1
  49. package/dist/plugins/og-assets.js +32 -13
  50. package/dist/plugins/og-harfbuzz.d.ts +24 -0
  51. package/dist/plugins/og-harfbuzz.js +260 -0
  52. package/dist/plugins/optimize-imports.js +1 -1
  53. package/dist/plugins/require-condition-resolution.js +2 -2
  54. package/dist/plugins/require-context.js +2 -2
  55. package/dist/plugins/typeof-window.js +1 -1
  56. package/dist/plugins/use-cache-callable.d.ts +0 -2
  57. package/dist/plugins/use-cache-callable.js +40 -22
  58. package/dist/plugins/worker-image-imports.js +1 -1
  59. package/dist/routing/app-route-graph.js +1 -1
  60. package/dist/routing/app-router.js +1 -1
  61. package/dist/routing/pages-router.js +1 -1
  62. package/dist/server/app-action-forwarding.js +1 -1
  63. package/dist/server/app-browser-entry.js +1 -0
  64. package/dist/server/app-browser-error.js +1 -1
  65. package/dist/server/app-elements-wire.js +2 -2
  66. package/dist/server/app-middleware.js +1 -1
  67. package/dist/server/app-optimistic-routing.js +1 -1
  68. package/dist/server/app-page-cache-finalizer.d.ts +1 -0
  69. package/dist/server/app-page-cache-finalizer.js +14 -2
  70. package/dist/server/app-page-dispatch.js +1 -1
  71. package/dist/server/app-page-element-builder.js +3 -2
  72. package/dist/server/app-page-probe.js +3 -3
  73. package/dist/server/app-page-render.js +1 -0
  74. package/dist/server/app-page-request.d.ts +2 -0
  75. package/dist/server/app-page-request.js +16 -12
  76. package/dist/server/app-request-stage-dispatch.js +1 -1
  77. package/dist/server/app-request-stage-independent-entry.js +2 -2
  78. package/dist/server/app-route-handler-dispatch.d.ts +1 -0
  79. package/dist/server/app-route-handler-dispatch.js +3 -2
  80. package/dist/server/app-route-handler-execution.d.ts +1 -0
  81. package/dist/server/app-route-handler-execution.js +2 -2
  82. package/dist/server/app-route-handler-runtime.js +1 -1
  83. package/dist/server/app-router-entry.js +2 -2
  84. package/dist/server/app-rsc-handler.d.ts +9 -2
  85. package/dist/server/app-rsc-handler.js +30 -10
  86. package/dist/server/app-rsc-response-stage.js +6 -3
  87. package/dist/server/app-rsc-route-matching.js +1 -1
  88. package/dist/server/app-server-action-execution.js +35 -6
  89. package/dist/server/app-ssr-entry.js +7 -2
  90. package/dist/server/app-ssr-stream.js +25 -6
  91. package/dist/server/app-worker-stages.d.ts +4 -1
  92. package/dist/server/app-worker-stages.js +4 -4
  93. package/dist/server/artifact-compatibility.js +1 -1
  94. package/dist/server/client-reuse-manifest.js +1 -1
  95. package/dist/server/dev-lockfile.d.ts +1 -1
  96. package/dist/server/dev-lockfile.js +4 -1
  97. package/dist/server/dev-server.d.ts +1 -1
  98. package/dist/server/dev-server.js +28 -6
  99. package/dist/server/dev-stack-sourcemap.js +1 -1
  100. package/dist/server/html.d.ts +0 -20
  101. package/dist/server/html.js +16 -1
  102. package/dist/server/instrumentation.d.ts +4 -9
  103. package/dist/server/instrumentation.js +10 -15
  104. package/dist/server/isr-cache.js +3 -3
  105. package/dist/server/metadata-route-response.d.ts +1 -0
  106. package/dist/server/metadata-route-response.js +65 -0
  107. package/dist/server/middleware-runtime.js +3 -3
  108. package/dist/server/pages-asset-tags.d.ts +1 -0
  109. package/dist/server/pages-asset-tags.js +37 -2
  110. package/dist/server/pages-client-assets.d.ts +7 -0
  111. package/dist/server/pages-data-route.js +1 -1
  112. package/dist/server/pages-dev-hydration.d.ts +6 -0
  113. package/dist/server/pages-dev-hydration.js +19 -7
  114. package/dist/server/pages-document-initial-props.d.ts +1 -0
  115. package/dist/server/pages-document-initial-props.js +1 -1
  116. package/dist/server/pages-page-data.js +2 -2
  117. package/dist/server/pages-page-handler.js +5 -2
  118. package/dist/server/pages-page-response.d.ts +1 -0
  119. package/dist/server/pages-page-response.js +3 -2
  120. package/dist/server/pages-request-pipeline.js +3 -3
  121. package/dist/server/pages-request-stage-entry.js +3 -3
  122. package/dist/server/pages-revalidate.js +1 -1
  123. package/dist/server/prerender-route-params.js +1 -1
  124. package/dist/server/prod-server.js +19 -13
  125. package/dist/server/request-pipeline.js +2 -2
  126. package/dist/server/rsc-stream-hints.d.ts +12 -0
  127. package/dist/server/rsc-stream-hints.js +70 -35
  128. package/dist/server/seed-cache.js +3 -4
  129. package/dist/server/socket-error-backstop.js +1 -1
  130. package/dist/shims/cache-callable-runtime.d.ts +38 -0
  131. package/dist/shims/cache-callable-runtime.js +162 -11
  132. package/dist/shims/cache-runtime.d.ts +6 -8
  133. package/dist/shims/cache-runtime.js +89 -24
  134. package/dist/shims/constants.js +1 -1
  135. package/dist/shims/dynamic-preload-chunks.js +6 -2
  136. package/dist/shims/font-local.js +1 -1
  137. package/dist/shims/form.js +1 -1
  138. package/dist/shims/head.js +1 -1
  139. package/dist/shims/headers.js +2 -2
  140. package/dist/shims/image-config.js +2 -0
  141. package/dist/shims/internal/app-page-props-cache-key.d.ts +29 -0
  142. package/dist/shims/internal/app-page-props-cache-key.js +53 -1
  143. package/dist/shims/internal/format-url-object.d.ts +7 -0
  144. package/dist/shims/internal/format-url-object.js +53 -0
  145. package/dist/shims/internal/normalize-router-href.d.ts +15 -0
  146. package/dist/shims/internal/normalize-router-href.js +41 -0
  147. package/dist/shims/internal/pages-data-target.d.ts +4 -1
  148. package/dist/shims/internal/pages-data-target.js +28 -35
  149. package/dist/shims/internal/route-pattern-for-warning.d.ts +2 -2
  150. package/dist/shims/internal/route-pattern-for-warning.js +3 -3
  151. package/dist/shims/link.js +31 -92
  152. package/dist/shims/metadata.js +5 -4
  153. package/dist/shims/navigation.js +2 -2
  154. package/dist/shims/router-state.js +1 -1
  155. package/dist/shims/router.d.ts +8 -7
  156. package/dist/shims/router.js +312 -148
  157. package/dist/shims/script-nonce-context.d.ts +4 -1
  158. package/dist/shims/script-nonce-context.js +15 -6
  159. package/dist/shims/server.js +3 -3
  160. package/dist/utils/built-asset-url.js +1 -1
  161. package/dist/utils/client-runtime-metadata.d.ts +6 -0
  162. package/dist/utils/client-runtime-metadata.js +16 -0
  163. package/dist/utils/lazy-chunks.js +1 -1
  164. package/dist/utils/project.d.ts +1 -11
  165. package/dist/utils/project.js +20 -29
  166. package/dist/utils/react-version.d.ts +3 -1
  167. package/dist/utils/react-version.js +19 -1
  168. package/dist/utils/vite-cli-invocation.d.ts +21 -0
  169. package/dist/utils/vite-cli-invocation.js +144 -0
  170. package/package.json +10 -2
@@ -208,7 +208,7 @@ export type NextConfig = {
208
208
  cacheComponents?: boolean;
209
209
  /**
210
210
  * Enables source maps while generating static pages.
211
- * Helps with errors during the prerender phase in `vinext build`.
211
+ * Helps with errors during the prerender phase in `vite build`.
212
212
  * Defaults to `true`. Set to `false` to disable.
213
213
  */
214
214
  enablePrerenderSourceMaps?: boolean;
@@ -602,7 +602,7 @@ export declare function normalizeAssetPrefix(value: unknown): string;
602
602
  * across plugin instances); otherwise we mint a random UUID.
603
603
  *
604
604
  * NOTE: like `resolveBuildId`, this is non-deterministic in the no-deploymentId
605
- * case, so a single `vinext build` that instantiates the plugin more than once
605
+ * case, so a single `vite build` that instantiates the plugin more than once
606
606
  * (App Router `buildApp()` + the hybrid Pages Router `vite.build()`) must
607
607
  * resolve it once and share it — see `__VINEXT_SHARED_RSC_COMPATIBILITY_ID`.
608
608
  */
@@ -1,11 +1,11 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { normalizePageExtensions } from "../routing/file-matcher.js";
3
- import { isExternalUrl } from "../utils/external-url.js";
4
- import { applyLocaleToRoutes } from "./config-matchers.js";
5
2
  import { isUnknownRecord } from "../utils/record.js";
3
+ import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
4
+ import { normalizePageExtensions } from "../routing/file-matcher.js";
6
5
  import { getHtmlLimitedBotRegex } from "../utils/html-limited-bots.js";
7
6
  import { flattenPluginOptions } from "../utils/plugin-options.js";
8
- import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
7
+ import { isExternalUrl } from "../utils/external-url.js";
8
+ import { applyLocaleToRoutes } from "./config-matchers.js";
9
9
  import { loadTsconfigResolutionForRoot } from "./tsconfig-paths.js";
10
10
  import { loadCommonJsModule, shouldRetryAsCommonJs } from "../utils/commonjs-loader.js";
11
11
  import { Module, createRequire } from "node:module";
@@ -527,7 +527,7 @@ function resolveDeploymentId(configDeploymentId) {
527
527
  * across plugin instances); otherwise we mint a random UUID.
528
528
  *
529
529
  * NOTE: like `resolveBuildId`, this is non-deterministic in the no-deploymentId
530
- * case, so a single `vinext build` that instantiates the plugin more than once
530
+ * case, so a single `vite build` that instantiates the plugin more than once
531
531
  * (App Router `buildApp()` + the hybrid Pages Router `vite.build()`) must
532
532
  * resolve it once and share it — see `__VINEXT_SHARED_RSC_COMPATIBILITY_ID`.
533
533
  */
@@ -9,9 +9,12 @@ export type VinextPrerenderConfig = true | {
9
9
  * App Router and Pages Router route that vinext can statically render.
10
10
  */
11
11
  routes: "*";
12
+ /** Maximum number of routes to render concurrently. */
13
+ concurrency?: number;
12
14
  };
13
15
  export type ResolvedVinextPrerenderConfig = {
14
16
  routes: "*";
17
+ concurrency?: number;
15
18
  };
16
19
  export type VinextPrerenderDecisionReason = "flag" | "next-export" | "vinext-config";
17
20
  export type VinextPrerenderDecision = ResolvedVinextPrerenderConfig & {
@@ -8,7 +8,13 @@ function normalizeVinextPrerenderConfig(config) {
8
8
  if (config === void 0) return null;
9
9
  if (config === true) return { routes: "*" };
10
10
  if (!isUnknownRecord(config)) throw new Error("[vinext] Invalid `prerender` config. Use `true` or `{ routes: \"*\" }`.");
11
- if (config.routes === "*") return { routes: "*" };
11
+ if (config.routes === "*") {
12
+ if (config.concurrency !== void 0 && (!Number.isInteger(config.concurrency) || config.concurrency <= 0)) throw new Error("[vinext] `prerender.concurrency` must be a positive integer.");
13
+ return {
14
+ routes: "*",
15
+ ...config.concurrency === void 0 ? {} : { concurrency: config.concurrency }
16
+ };
17
+ }
12
18
  throw new Error("[vinext] Unsupported `prerender.routes` config. Currently only `routes: \"*\"` is supported.");
13
19
  }
14
20
  async function findVinextPrerenderConfigInPlugins(plugins) {
@@ -51,7 +57,7 @@ function resolveVinextPrerenderDecision(options) {
51
57
  reason: "next-export"
52
58
  };
53
59
  if (options.vinextPrerenderConfig?.routes === "*") return {
54
- routes: "*",
60
+ ...options.vinextPrerenderConfig,
55
61
  reason: "vinext-config"
56
62
  };
57
63
  return null;
@@ -1,6 +1,6 @@
1
+ import { patternsStructurallyEquivalent } from "../routing/app-route-graph.js";
1
2
  import { resolveClientRuntimeModule, resolveRuntimeEntryModule } from "./runtime-entry-module.js";
2
3
  import { toClientRewrites } from "../client/client-rewrites.js";
3
- import { patternsStructurallyEquivalent } from "../routing/app-route-graph.js";
4
4
  //#region src/entries/app-browser-entry.ts
5
5
  /**
6
6
  * Generate the virtual browser entry module.
@@ -43,6 +43,8 @@ type AppRouterConfig = {
43
43
  * @see https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix
44
44
  */
45
45
  assetPrefix?: string;
46
+ /** CORS mode for framework-managed assets from next.config. */
47
+ crossOrigin?: "anonymous" | "use-credentials";
46
48
  /** Route-level expire fallback in seconds for ISR entries with numeric revalidate. */
47
49
  expireTime?: number;
48
50
  /**
@@ -1,8 +1,8 @@
1
1
  import { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
+ import { appRouteHasMainTreeLoadingBoundary } from "../routing/app-router.js";
2
3
  import { resolveEntryPath } from "./runtime-entry-module.js";
3
4
  import { isProxyFile } from "../server/middleware.js";
4
5
  import { extractExportConstString } from "../build/report.js";
5
- import { appRouteHasMainTreeLoadingBoundary } from "../routing/app-router.js";
6
6
  import { routePatternParts } from "../routing/route-pattern.js";
7
7
  import { safeJsonStringify } from "../server/html.js";
8
8
  import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES } from "../server/image-optimization.js";
@@ -190,6 +190,7 @@ const __trailingSlash = ${JSON.stringify(ts)};
190
190
  const __draftModeSecret = ${JSON.stringify(config?.draftModeSecret ?? "")};
191
191
  export const __prerenderSecret = ${JSON.stringify(config?.prerenderSecret ?? "")};
192
192
  export const __assetPrefix = ${JSON.stringify(config?.assetPrefix ?? "")};
193
+ export const __crossOrigin = ${JSON.stringify(config?.crossOrigin ?? "")};
193
194
  export { __basePath };
194
195
  export const __imageAllowedWidths = ${JSON.stringify([...config?.imageConfig?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...config?.imageConfig?.imageSizes ?? DEFAULT_IMAGE_SIZES])};
195
196
  export const __imageConfig = ${JSON.stringify({
@@ -371,6 +372,7 @@ function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes, global
371
372
  const htmlLimitedBots = config?.htmlLimitedBots;
372
373
  const clientTraceMetadata = config?.clientTraceMetadata;
373
374
  const assetPrefix = config?.assetPrefix ?? "";
375
+ const crossOrigin = config?.crossOrigin ?? "";
374
376
  const expireTime = config?.expireTime ?? DEFAULT_EXPIRE_TIME;
375
377
  const reactMaxHeadersLength = config?.reactMaxHeadersLength ?? DEFAULT_REACT_MAX_HEADERS_LENGTH;
376
378
  const cacheMaxMemorySize = config?.cacheMaxMemorySize;
@@ -820,6 +822,7 @@ const __reactMaxHeadersLength = ${JSON.stringify(reactMaxHeadersLength)};
820
822
  // mirrors the embedded \`__basePath\` pattern (and Pages Router's
821
823
  // \`vinextConfig\` export). Empty string when unset.
822
824
  export const __assetPrefix = ${JSON.stringify(assetPrefix)};
825
+ export const __crossOrigin = ${JSON.stringify(crossOrigin)};
823
826
  export const __imageAllowedWidths = ${JSON.stringify(imageAllowedWidths)};
824
827
  export const __imageConfig = ${JSON.stringify(imageConfig)};
825
828
  export const __inlineCss = ${JSON.stringify(inlineCss)};
@@ -898,6 +901,7 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
898
901
  draftModeSecret: __draftModeSecret,
899
902
  dispatchMatchedPage({
900
903
  bypassInterceptionContextCache,
904
+ cachePathname,
901
905
  clientReuseManifest,
902
906
  cleanPathname,
903
907
  displayPathname,
@@ -1025,8 +1029,18 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
1025
1029
  isRscRequest,
1026
1030
  isrDebug: __isrDebug,
1027
1031
  isrGet: __isrGet,
1028
- isrHtmlKey: __isrHtmlKey,
1029
- isrRscKey: __isrRscKey,
1032
+ isrHtmlKey(pathname) {
1033
+ return __isrHtmlKey(pathname === cleanPathname ? cachePathname : pathname);
1034
+ },
1035
+ isrRscKey(pathname, mountedSlots, requestedRenderMode, requestedInterceptionContext, requestedInterceptionId) {
1036
+ return __isrRscKey(
1037
+ pathname === cleanPathname ? cachePathname : pathname,
1038
+ mountedSlots,
1039
+ requestedRenderMode,
1040
+ requestedInterceptionContext,
1041
+ requestedInterceptionId,
1042
+ );
1043
+ },
1030
1044
  isrSet: __isrSet,
1031
1045
  loadSsrHandler() {
1032
1046
  return import.meta.viteRsc.loadModule("ssr", "index");
@@ -1133,6 +1147,8 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
1133
1147
  });
1134
1148
  },
1135
1149
  async dispatchMatchedRouteHandler({
1150
+ bypassInterceptionContextCache,
1151
+ cachePathname,
1136
1152
  cleanPathname,
1137
1153
  middlewareContext,
1138
1154
  params,
@@ -1144,6 +1160,7 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
1144
1160
  await __loadAppRouteHandlerDispatch();
1145
1161
  return __dispatchAppRouteHandler({
1146
1162
  basePath: __basePath,
1163
+ bypassSharedCache: bypassInterceptionContextCache,
1147
1164
  cleanPathname,
1148
1165
  clearRequestContext() {
1149
1166
  __clearRequestContext();
@@ -1153,7 +1170,9 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
1153
1170
  trailingSlash: __trailingSlash,
1154
1171
  isrDebug: __isrDebug,
1155
1172
  isrGet: __isrGet,
1156
- isrRouteKey: __isrRouteKey,
1173
+ isrRouteKey(pathname) {
1174
+ return __isrRouteKey(pathname === cleanPathname ? cachePathname : pathname);
1175
+ },
1157
1176
  isrSet: __isrSet,
1158
1177
  middlewareContext,
1159
1178
  middlewareRequestHeaders: middlewareContext.requestHeaders,
@@ -1461,7 +1480,7 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
1461
1480
  await __loadMetadataRouteResponse();
1462
1481
  return __isMetadataRouteRequestPath(metadataRoutes, cleanPathname);
1463
1482
  },` : ""}
1464
- ${(metadataRoutes?.length ?? 0) > 0 ? `async handleMetadataRouteRequest(cleanPathname) {
1483
+ ${(metadataRoutes?.length ?? 0) > 0 ? `async handleMetadataRouteRequest(cleanPathname, routePathname) {
1465
1484
  const { handleMetadataRouteRequest: __handleMetadataRouteRequest } =
1466
1485
  await __loadMetadataRouteResponse();
1467
1486
  return __handleMetadataRouteRequest({
@@ -1471,6 +1490,7 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
1471
1490
  isrRouteKey: __isrRouteKey,
1472
1491
  isrSet: __isrSet,
1473
1492
  makeThenableParams,
1493
+ routePathname,
1474
1494
  scheduleBackgroundRegeneration: __triggerBackgroundRegeneration,
1475
1495
  });
1476
1496
  },` : ""}
@@ -3,6 +3,7 @@ import { ResolvedNextConfig } from "../config/next-config.js";
3
3
  import { StaticMiddlewareMatcher } from "../build/report.js";
4
4
  import { VinextLinkPrefetchRoute } from "../client/vinext-next-data.js";
5
5
  //#region src/entries/pages-client-entry.d.ts
6
+ export declare function compileClientMiddlewareMatchers(matcher: StaticMiddlewareMatcher | undefined): unknown[] | undefined;
6
7
  export declare function generateClientEntry(pagesDir: string, nextConfig: ResolvedNextConfig, fileMatcher: ReturnType<typeof createValidFileMatcher>, options?: {
7
8
  appPrefetchRoutes?: readonly VinextLinkPrefetchRoute[];
8
9
  instrumentationClientPath?: string | null;
@@ -3,6 +3,7 @@ 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
5
  import { resolveClientRuntimeModule } from "./runtime-entry-module.js";
6
+ import { compileMiddlewareMatcherPattern } from "../server/middleware-matcher-pattern.js";
6
7
  import { hasExportedName } from "../build/report.js";
7
8
  import { toClientRewrites } from "../client/client-rewrites.js";
8
9
  import { readFile } from "node:fs/promises";
@@ -18,6 +19,19 @@ import { readFile } from "node:fs/promises";
18
19
  *
19
20
  * Extracted from index.ts.
20
21
  */
22
+ function compileClientMiddlewareMatchers(matcher) {
23
+ if (matcher === void 0) return void 0;
24
+ return (typeof matcher === "string" ? [matcher] : matcher).map((entry) => {
25
+ const source = typeof entry === "string" ? entry : entry.source;
26
+ const compiled = compileMiddlewareMatcherPattern(source);
27
+ if (!compiled.regexp) return entry;
28
+ return {
29
+ ...typeof entry === "string" ? { source } : entry,
30
+ regexp: compiled.regexp.source,
31
+ flags: compiled.regexp.flags
32
+ };
33
+ });
34
+ }
21
35
  /**
22
36
  * Project a Pages `Route` down to the public `VinextPagesLinkPrefetchRoute`
23
37
  * shape used for client-side hybrid ownership decisions. Mirrors
@@ -54,6 +68,7 @@ async function generateClientEntry(pagesDir, nextConfig, fileMatcher, options =
54
68
  const pagesSspPatterns = (await Promise.all(pageRoutes.map(async (route) => await hasGetServerSidePropsExport(route.filePath) ? patternToNextFormat(route.pattern) : null))).filter((pattern) => pattern !== null);
55
69
  const instrumentationClientPath = options.instrumentationClientPath ?? null;
56
70
  const clientRewrites = toClientRewrites(nextConfig.rewrites);
71
+ const clientMiddlewareMatchers = compileClientMiddlewareMatchers(options.middlewareMatcher);
57
72
  const reactInstanceBootstrapPath = resolveClientRuntimeModule("react-instance-bootstrap");
58
73
  const loaderEntries = pageRoutes.map((r) => {
59
74
  const absPath = r.filePath;
@@ -103,7 +118,7 @@ window.__VINEXT_PAGE_PATTERNS__ = Object.keys(pageLoaders);
103
118
  window.__VINEXT_REACT_STRICT_MODE__ = ${JSON.stringify(reactStrictModeEnabled)};
104
119
  window.__VINEXT_PAGES_SSG_PATTERNS__ = ${JSON.stringify(pagesSsgPatterns)};
105
120
  window.__VINEXT_PAGES_SSP_PATTERNS__ = ${JSON.stringify(pagesSspPatterns)};
106
- window.__VINEXT_MIDDLEWARE_MATCHER__ = ${JSON.stringify(options.middlewareMatcher)};
121
+ window.__VINEXT_MIDDLEWARE_MATCHER__ = ${JSON.stringify(clientMiddlewareMatchers)};
107
122
  window.__VINEXT_APP_LOADER__ = appLoader;
108
123
  // Expose the App Router prefetch manifest so Pages Router \`<Link>\`s and
109
124
  // \`Router.prefetch\` can detect when a prefetch target is actually an App
@@ -237,4 +252,4 @@ hydrate();
237
252
  `;
238
253
  }
239
254
  //#endregion
240
- export { generateClientEntry };
255
+ export { compileClientMiddlewareMatchers, generateClientEntry };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { NextConfig, NextConfigInput } from "./config/next-config.js";
2
1
  import { VinextMultiStageOutput, VinextResponseStageDispatchOptions, VinextResponseStageTransport } from "./server/multi-stage.js";
3
2
  import { VinextCacheConfig } from "./cache/cache-adapters-virtual.js";
4
3
  import { VinextPrerenderConfig } from "./config/prerender.js";
4
+ import { NextConfig, NextConfigInput } from "./config/next-config.js";
5
5
  import { AppStaticExportOptions, StaticExportOptions, StaticExportResult, staticExportApp, staticExportPages } from "./build/static-export.js";
6
6
  import { VinextImageConfig } from "./image/image-adapters-virtual.js";
7
7
  import { PluginOption } from "vite";
@@ -78,22 +78,20 @@ export type VinextOptions = {
78
78
  * Disabled by default. Not useful when deploying to edge platforms
79
79
  * (Cloudflare Workers, Nitro) that handle compression at the CDN layer.
80
80
  *
81
- * Can also be enabled via the `--precompress` CLI flag or by setting the
82
- * `VINEXT_PRECOMPRESS=1` environment variable (useful for CI pipelines
83
- * that need to enable precompression without modifying vite.config.ts).
81
+ * Can also be enabled by setting the `VINEXT_PRECOMPRESS=1` environment
82
+ * variable (useful for CI pipelines that cannot modify vite.config.ts).
84
83
  * @default false
85
84
  */
86
85
  precompress?: boolean;
87
86
  /**
88
- * Pre-render routes after `vinext build` without passing
89
- * `--prerender-all`.
87
+ * Pre-render routes after `vite build`.
90
88
  *
91
89
  * Use `true` as shorthand for `{ routes: "*" }`. The object form is
92
90
  * available so future releases can support narrower route selections, but
93
91
  * currently only `"*"` is supported.
94
92
  *
95
- * The `vinext build --prerender-all` and `vinext deploy --prerender-all`
96
- * flags still work and take priority when present.
93
+ * The `vinext-cloudflare deploy --prerender-all` flag takes priority when
94
+ * present.
97
95
  *
98
96
  * @example
99
97
  * vinext({ prerender: true })