vinext 0.1.1 → 0.1.3

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 (266) hide show
  1. package/README.md +2 -5
  2. package/dist/build/client-build-config.d.ts +7 -1
  3. package/dist/build/client-build-config.js +9 -1
  4. package/dist/build/prerender.d.ts +9 -1
  5. package/dist/build/prerender.js +41 -12
  6. package/dist/build/run-prerender.d.ts +10 -2
  7. package/dist/build/run-prerender.js +15 -1
  8. package/dist/check.js +4 -3
  9. package/dist/client/app-nav-failure-handler.d.ts +8 -0
  10. package/dist/client/app-nav-failure-handler.js +44 -0
  11. package/dist/client/navigation-runtime.d.ts +3 -2
  12. package/dist/client/vinext-next-data.d.ts +18 -1
  13. package/dist/client/window-next.d.ts +8 -5
  14. package/dist/client/window-next.js +12 -1
  15. package/dist/cloudflare/src/cache/cdn-adapter.runtime.js +6 -1
  16. package/dist/config/config-matchers.d.ts +11 -4
  17. package/dist/config/config-matchers.js +88 -16
  18. package/dist/config/next-config.d.ts +59 -4
  19. package/dist/config/next-config.js +149 -48
  20. package/dist/deploy.d.ts +30 -11
  21. package/dist/deploy.js +189 -101
  22. package/dist/entries/app-browser-entry.d.ts +9 -3
  23. package/dist/entries/app-browser-entry.js +21 -3
  24. package/dist/entries/app-rsc-entry.d.ts +2 -0
  25. package/dist/entries/app-rsc-entry.js +71 -6
  26. package/dist/entries/app-rsc-manifest.js +2 -0
  27. package/dist/entries/app-ssr-entry.js +1 -1
  28. package/dist/entries/pages-client-entry.js +54 -9
  29. package/dist/entries/pages-server-entry.js +48 -11
  30. package/dist/index.d.ts +0 -2
  31. package/dist/index.js +285 -139
  32. package/dist/plugins/dynamic-preload-metadata.d.ts +13 -0
  33. package/dist/plugins/dynamic-preload-metadata.js +415 -0
  34. package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
  35. package/dist/plugins/extensionless-dynamic-import.js +152 -0
  36. package/dist/plugins/og-assets.js +2 -2
  37. package/dist/plugins/optimize-imports.d.ts +10 -5
  38. package/dist/plugins/optimize-imports.js +27 -21
  39. package/dist/plugins/postcss.js +7 -7
  40. package/dist/plugins/sass.d.ts +53 -24
  41. package/dist/plugins/sass.js +249 -1
  42. package/dist/plugins/typeof-window.d.ts +14 -0
  43. package/dist/plugins/typeof-window.js +150 -0
  44. package/dist/plugins/wasm-module-import.d.ts +15 -0
  45. package/dist/plugins/wasm-module-import.js +50 -0
  46. package/dist/routing/app-route-graph.d.ts +25 -2
  47. package/dist/routing/app-route-graph.js +91 -22
  48. package/dist/routing/file-matcher.d.ts +10 -1
  49. package/dist/routing/file-matcher.js +23 -2
  50. package/dist/routing/pages-router.js +3 -3
  51. package/dist/routing/utils.d.ts +35 -6
  52. package/dist/routing/utils.js +59 -7
  53. package/dist/server/api-handler.d.ts +6 -1
  54. package/dist/server/api-handler.js +21 -15
  55. package/dist/server/app-browser-action-result.d.ts +19 -6
  56. package/dist/server/app-browser-action-result.js +19 -10
  57. package/dist/server/app-browser-entry.js +269 -297
  58. package/dist/server/app-browser-error.d.ts +10 -3
  59. package/dist/server/app-browser-error.js +47 -6
  60. package/dist/server/app-browser-history-controller.d.ts +104 -0
  61. package/dist/server/app-browser-history-controller.js +210 -0
  62. package/dist/server/app-browser-hydration.d.ts +2 -0
  63. package/dist/server/app-browser-hydration.js +1 -0
  64. package/dist/server/app-browser-navigation-controller.d.ts +7 -4
  65. package/dist/server/app-browser-navigation-controller.js +33 -9
  66. package/dist/server/app-browser-rsc-redirect.d.ts +11 -2
  67. package/dist/server/app-browser-rsc-redirect.js +30 -8
  68. package/dist/server/app-browser-server-action-navigation.d.ts +6 -0
  69. package/dist/server/app-browser-server-action-navigation.js +9 -0
  70. package/dist/server/app-browser-state.js +4 -7
  71. package/dist/server/app-browser-stream.js +86 -43
  72. package/dist/server/app-browser-visible-commit.js +1 -1
  73. package/dist/server/app-elements-wire.d.ts +6 -1
  74. package/dist/server/app-elements-wire.js +14 -4
  75. package/dist/server/app-elements.d.ts +2 -2
  76. package/dist/server/app-elements.js +2 -2
  77. package/dist/server/app-fallback-renderer.d.ts +3 -1
  78. package/dist/server/app-fallback-renderer.js +6 -2
  79. package/dist/server/app-middleware.js +1 -0
  80. package/dist/server/app-optimistic-routing.js +24 -3
  81. package/dist/server/app-page-boundary-render.d.ts +3 -1
  82. package/dist/server/app-page-boundary-render.js +31 -16
  83. package/dist/server/app-page-cache-render.d.ts +53 -0
  84. package/dist/server/app-page-cache-render.js +91 -0
  85. package/dist/server/app-page-cache.d.ts +16 -2
  86. package/dist/server/app-page-cache.js +71 -8
  87. package/dist/server/app-page-dispatch.d.ts +34 -0
  88. package/dist/server/app-page-dispatch.js +167 -97
  89. package/dist/server/app-page-element-builder.d.ts +23 -2
  90. package/dist/server/app-page-element-builder.js +42 -10
  91. package/dist/server/app-page-execution.d.ts +7 -2
  92. package/dist/server/app-page-execution.js +53 -18
  93. package/dist/server/app-page-probe.d.ts +1 -0
  94. package/dist/server/app-page-probe.js +4 -0
  95. package/dist/server/app-page-render-observation.d.ts +3 -1
  96. package/dist/server/app-page-render-observation.js +17 -1
  97. package/dist/server/app-page-render.d.ts +13 -2
  98. package/dist/server/app-page-render.js +48 -17
  99. package/dist/server/app-page-request.d.ts +3 -0
  100. package/dist/server/app-page-request.js +5 -3
  101. package/dist/server/app-page-response.js +1 -1
  102. package/dist/server/app-page-route-wiring.d.ts +5 -1
  103. package/dist/server/app-page-route-wiring.js +21 -11
  104. package/dist/server/app-page-stream.d.ts +16 -9
  105. package/dist/server/app-page-stream.js +12 -9
  106. package/dist/server/app-pages-bridge.d.ts +18 -0
  107. package/dist/server/app-pages-bridge.js +22 -5
  108. package/dist/server/app-ppr-fallback-shell-render.d.ts +17 -0
  109. package/dist/server/app-ppr-fallback-shell-render.js +26 -0
  110. package/dist/server/app-ppr-fallback-shell.d.ts +13 -1
  111. package/dist/server/app-ppr-fallback-shell.js +8 -1
  112. package/dist/server/app-route-handler-dispatch.js +9 -2
  113. package/dist/server/app-route-handler-policy.d.ts +1 -0
  114. package/dist/server/app-route-handler-response.js +11 -10
  115. package/dist/server/app-route-handler-runtime.js +12 -1
  116. package/dist/server/app-router-entry.js +5 -0
  117. package/dist/server/app-rsc-cache-busting.js +2 -0
  118. package/dist/server/app-rsc-handler.d.ts +25 -0
  119. package/dist/server/app-rsc-handler.js +153 -53
  120. package/dist/server/app-rsc-response-finalizer.js +1 -1
  121. package/dist/server/app-rsc-route-matching.d.ts +3 -0
  122. package/dist/server/app-rsc-route-matching.js +2 -0
  123. package/dist/server/app-segment-config.d.ts +9 -1
  124. package/dist/server/app-segment-config.js +12 -3
  125. package/dist/server/app-server-action-execution.d.ts +12 -0
  126. package/dist/server/app-server-action-execution.js +47 -15
  127. package/dist/server/app-ssr-entry.d.ts +2 -0
  128. package/dist/server/app-ssr-entry.js +81 -8
  129. package/dist/server/app-ssr-stream.js +9 -1
  130. package/dist/server/cache-control.js +4 -0
  131. package/dist/server/dev-lockfile.js +2 -1
  132. package/dist/server/dev-server.d.ts +2 -2
  133. package/dist/server/dev-server.js +287 -63
  134. package/dist/server/headers.d.ts +8 -1
  135. package/dist/server/headers.js +8 -1
  136. package/dist/server/hybrid-route-priority.d.ts +22 -0
  137. package/dist/server/hybrid-route-priority.js +33 -0
  138. package/dist/server/image-optimization.d.ts +18 -9
  139. package/dist/server/image-optimization.js +37 -23
  140. package/dist/server/implicit-tags.d.ts +2 -1
  141. package/dist/server/implicit-tags.js +4 -1
  142. package/dist/server/instrumentation-runtime.d.ts +6 -0
  143. package/dist/server/instrumentation-runtime.js +8 -0
  144. package/dist/server/isr-decision.d.ts +79 -0
  145. package/dist/server/isr-decision.js +70 -0
  146. package/dist/server/metadata-route-response.js +5 -3
  147. package/dist/server/middleware-runtime.d.ts +13 -0
  148. package/dist/server/middleware-runtime.js +11 -7
  149. package/dist/server/middleware.js +1 -0
  150. package/dist/server/navigation-planner.d.ts +186 -22
  151. package/dist/server/navigation-planner.js +302 -0
  152. package/dist/server/navigation-trace.d.ts +18 -1
  153. package/dist/server/navigation-trace.js +18 -1
  154. package/dist/server/normalize-path.d.ts +0 -8
  155. package/dist/server/normalize-path.js +3 -1
  156. package/dist/server/otel-tracer-extension.d.ts +45 -0
  157. package/dist/server/otel-tracer-extension.js +89 -0
  158. package/dist/server/pages-api-route.d.ts +20 -3
  159. package/dist/server/pages-api-route.js +19 -3
  160. package/dist/server/pages-asset-tags.d.ts +16 -4
  161. package/dist/server/pages-asset-tags.js +22 -12
  162. package/dist/server/pages-data-route.d.ts +8 -1
  163. package/dist/server/pages-data-route.js +16 -3
  164. package/dist/server/pages-get-initial-props.d.ts +54 -4
  165. package/dist/server/pages-get-initial-props.js +43 -1
  166. package/dist/server/pages-node-compat.d.ts +3 -11
  167. package/dist/server/pages-node-compat.js +175 -122
  168. package/dist/server/pages-page-data.d.ts +39 -2
  169. package/dist/server/pages-page-data.js +261 -46
  170. package/dist/server/pages-page-handler.d.ts +5 -2
  171. package/dist/server/pages-page-handler.js +78 -25
  172. package/dist/server/pages-page-response.d.ts +47 -2
  173. package/dist/server/pages-page-response.js +73 -9
  174. package/dist/server/pages-readiness.d.ts +1 -1
  175. package/dist/server/pages-request-pipeline.d.ts +16 -1
  176. package/dist/server/pages-request-pipeline.js +96 -38
  177. package/dist/server/pregenerated-concrete-paths.d.ts +1 -17
  178. package/dist/server/pregenerated-concrete-paths.js +2 -19
  179. package/dist/server/prerender-manifest.d.ts +33 -0
  180. package/dist/server/prerender-manifest.js +54 -0
  181. package/dist/server/prerender-route-params.d.ts +1 -2
  182. package/dist/server/prod-server.d.ts +39 -1
  183. package/dist/server/prod-server.js +107 -37
  184. package/dist/server/request-pipeline.d.ts +3 -15
  185. package/dist/server/request-pipeline.js +58 -47
  186. package/dist/server/rsc-stream-hints.d.ts +5 -1
  187. package/dist/server/rsc-stream-hints.js +6 -1
  188. package/dist/server/seed-cache.js +10 -18
  189. package/dist/shims/app-router-scroll-state.d.ts +3 -1
  190. package/dist/shims/app-router-scroll-state.js +14 -2
  191. package/dist/shims/app-router-scroll.d.ts +3 -0
  192. package/dist/shims/app-router-scroll.js +28 -18
  193. package/dist/shims/cache-runtime.js +12 -4
  194. package/dist/shims/cache.d.ts +1 -0
  195. package/dist/shims/cache.js +1 -1
  196. package/dist/shims/cdn-cache.d.ts +5 -5
  197. package/dist/shims/dynamic-preload-chunks.d.ts +8 -0
  198. package/dist/shims/dynamic-preload-chunks.js +79 -0
  199. package/dist/shims/dynamic.d.ts +4 -0
  200. package/dist/shims/dynamic.js +4 -2
  201. package/dist/shims/error-boundary.d.ts +6 -4
  202. package/dist/shims/error-boundary.js +7 -0
  203. package/dist/shims/error.js +38 -11
  204. package/dist/shims/error.react-server.d.ts +9 -0
  205. package/dist/shims/error.react-server.js +6 -0
  206. package/dist/shims/fetch-cache.d.ts +11 -1
  207. package/dist/shims/fetch-cache.js +55 -20
  208. package/dist/shims/hash-scroll.js +6 -1
  209. package/dist/shims/head.js +6 -1
  210. package/dist/shims/headers.d.ts +16 -2
  211. package/dist/shims/headers.js +66 -5
  212. package/dist/shims/image-config.js +7 -1
  213. package/dist/shims/internal/als-registry.js +28 -1
  214. package/dist/shims/internal/app-route-detection.d.ts +6 -3
  215. package/dist/shims/internal/app-route-detection.js +18 -23
  216. package/dist/shims/internal/app-router-context.d.ts +5 -0
  217. package/dist/shims/internal/hybrid-client-route-owner.d.ts +31 -0
  218. package/dist/shims/internal/hybrid-client-route-owner.js +143 -0
  219. package/dist/shims/internal/navigation-untracked.d.ts +35 -0
  220. package/dist/shims/internal/navigation-untracked.js +55 -0
  221. package/dist/shims/internal/pages-data-target.d.ts +7 -2
  222. package/dist/shims/internal/pages-data-target.js +17 -8
  223. package/dist/shims/internal/pages-router-accessor.d.ts +19 -0
  224. package/dist/shims/internal/pages-router-accessor.js +13 -0
  225. package/dist/shims/internal/router-context.d.ts +2 -1
  226. package/dist/shims/internal/router-context.js +3 -1
  227. package/dist/shims/link.js +12 -5
  228. package/dist/shims/metadata.d.ts +6 -2
  229. package/dist/shims/metadata.js +32 -14
  230. package/dist/shims/navigation.d.ts +14 -17
  231. package/dist/shims/navigation.js +93 -46
  232. package/dist/shims/ppr-fallback-shell.d.ts +5 -1
  233. package/dist/shims/ppr-fallback-shell.js +28 -7
  234. package/dist/shims/router.d.ts +13 -2
  235. package/dist/shims/router.js +434 -116
  236. package/dist/shims/script-nonce-context.d.ts +1 -1
  237. package/dist/shims/script-nonce-context.js +11 -3
  238. package/dist/shims/server.d.ts +33 -2
  239. package/dist/shims/server.js +75 -18
  240. package/dist/shims/slot.js +1 -1
  241. package/dist/shims/unified-request-context.js +2 -0
  242. package/dist/typegen.js +1 -0
  243. package/dist/utils/built-asset-url.d.ts +4 -0
  244. package/dist/utils/built-asset-url.js +11 -0
  245. package/dist/utils/client-build-manifest.js +15 -5
  246. package/dist/utils/client-runtime-metadata.d.ts +45 -0
  247. package/dist/utils/client-runtime-metadata.js +63 -0
  248. package/dist/utils/commonjs-loader.d.ts +16 -0
  249. package/dist/utils/commonjs-loader.js +100 -0
  250. package/dist/utils/deployment-id.d.ts +8 -0
  251. package/dist/utils/deployment-id.js +22 -0
  252. package/dist/utils/hash.d.ts +17 -1
  253. package/dist/utils/hash.js +36 -1
  254. package/dist/utils/html-limited-bots.d.ts +18 -1
  255. package/dist/utils/html-limited-bots.js +23 -1
  256. package/dist/utils/lazy-chunks.d.ts +27 -1
  257. package/dist/utils/lazy-chunks.js +65 -1
  258. package/dist/utils/manifest-paths.d.ts +20 -2
  259. package/dist/utils/manifest-paths.js +38 -3
  260. package/dist/utils/parse-cookie.d.ts +13 -0
  261. package/dist/utils/parse-cookie.js +52 -0
  262. package/dist/utils/path.d.ts +8 -1
  263. package/dist/utils/path.js +13 -1
  264. package/package.json +2 -2
  265. package/dist/shims/internal/parse-cookie-header.d.ts +0 -14
  266. package/dist/shims/internal/parse-cookie-header.js +0 -30
@@ -1,5 +1,6 @@
1
1
  import { VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER } from "../server/headers.js";
2
2
  import { buildRequestHeadersFromMiddlewareResponse } from "../server/middleware-request-headers.js";
3
+ import { parseCookieHeader } from "../utils/parse-cookie.js";
3
4
  //#region src/config/config-matchers.ts
4
5
  /**
5
6
  * Cache for compiled regex patterns in matchConfigPattern.
@@ -343,26 +344,30 @@ function shouldEvaluateRule(ruleBasePath, state) {
343
344
  * Parse a Cookie header string into a key-value record.
344
345
  */
345
346
  function parseCookies(cookieHeader) {
346
- if (!cookieHeader) return {};
347
- const cookies = {};
348
- for (const part of cookieHeader.split(";")) {
349
- const eq = part.indexOf("=");
350
- if (eq === -1) continue;
351
- const key = part.slice(0, eq).trim();
352
- const value = part.slice(eq + 1).trim();
353
- if (key) cookies[key] = value;
354
- }
355
- return cookies;
347
+ return parseCookieHeader(cookieHeader);
356
348
  }
357
349
  /**
358
350
  * Build a RequestContext from a Web Request object.
351
+ *
352
+ * `cookies` and `query` are lazy memoized getters: they are consumed only by
353
+ * `has`/`missing` condition evaluation (`checkHasConditions` /
354
+ * `matchesRuleConditions`), and most apps configure no such conditions. The
355
+ * cookie split and `searchParams` access are therefore deferred until first
356
+ * read and computed at most once. Mirrors `headersContextFromRequest` in
357
+ * `shims/headers.ts`.
359
358
  */
360
359
  function requestContextFromRequest(request) {
361
360
  const url = new URL(request.url);
361
+ let cookies;
362
+ let query;
362
363
  return {
363
364
  headers: request.headers,
364
- cookies: parseCookies(request.headers.get("cookie")),
365
- query: url.searchParams,
365
+ get cookies() {
366
+ return cookies ??= parseCookies(request.headers.get("cookie"));
367
+ },
368
+ get query() {
369
+ return query ??= url.searchParams;
370
+ },
366
371
  host: normalizeHost(request.headers.get("host"), url.hostname)
367
372
  };
368
373
  }
@@ -429,8 +434,8 @@ function matchSingleCondition(condition, ctx) {
429
434
  return _matchConditionValue(headerValue, condition.value);
430
435
  }
431
436
  case "cookie": {
437
+ if (!Object.hasOwn(ctx.cookies, condition.key)) return null;
432
438
  const cookieValue = ctx.cookies[condition.key];
433
- if (cookieValue === void 0) return null;
434
439
  return _matchConditionValue(cookieValue, condition.value);
435
440
  }
436
441
  case "query": {
@@ -528,7 +533,7 @@ function matchConfigPattern(pathname, pattern) {
528
533
  pathname = stripTrailingSlashForConfigMatch(pathname);
529
534
  const catchAllAnchor = /:[\w-]+[*+]/.test(pattern);
530
535
  const namedParamCount = (pattern.match(/:[\w-]+/g) || []).length;
531
- if (pattern.includes("(") || pattern.includes("\\") || /:[\w-]+[*+][^/]/.test(pattern) || /:[\w-]+\./.test(pattern) || catchAllAnchor && namedParamCount > 1) try {
536
+ if (pattern.includes("(") || pattern.includes("\\") || /:[\w-]+[*+][^/]/.test(pattern) || /:[\w-]+\./.test(pattern) || /[^/]:[\w-]+/.test(pattern) || catchAllAnchor && namedParamCount > 1) try {
532
537
  const compiled = getCachedRegex(_compiledPatternCache, pattern, () => {
533
538
  const paramNames = [];
534
539
  let regexStr = "";
@@ -703,10 +708,11 @@ function matchRewrite(pathname, rewrites, ctx, basePathState = _BASEPATH_DEFAULT
703
708
  if (params) {
704
709
  const conditionParams = rewrite.has || rewrite.missing ? collectConditionParams(rewrite.has, rewrite.missing, ctx) : _emptyParams();
705
710
  if (!conditionParams) continue;
706
- return substituteAndSanitizeDestination(rewrite.destination, {
711
+ const rewriteParams = {
707
712
  ...params,
708
713
  ...conditionParams
709
- });
714
+ };
715
+ return substituteAndSanitizeRewriteDestination(rewrite.destination, rewriteParams);
710
716
  }
711
717
  }
712
718
  return null;
@@ -740,6 +746,72 @@ function substituteAndSanitizeDestination(destination, params) {
740
746
  return sanitizeDestination(substituteDestinationParams(destination, params));
741
747
  }
742
748
  /**
749
+ * Match Next.js's rewrite-specific prepareDestination behavior: source params
750
+ * that are not consumed by the destination path/host are exposed to the target
751
+ * page through query.
752
+ *
753
+ * https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/router/utils/prepare-destination.ts
754
+ */
755
+ function substituteAndSanitizeRewriteDestination(destination, params) {
756
+ const rewritten = substituteAndSanitizeDestination(destination, params);
757
+ if (!shouldAppendRewriteParamsToQuery(destination, params)) return rewritten;
758
+ const existingQueryKeys = getDestinationQueryKeys(destination);
759
+ const paramsToAppend = [];
760
+ for (const [key, value] of Object.entries(params)) {
761
+ if (key === "nextInternalLocale" || existingQueryKeys.has(key)) continue;
762
+ paramsToAppend.push([key, value]);
763
+ }
764
+ if (paramsToAppend.length === 0) return rewritten;
765
+ return appendQueryParams(rewritten, paramsToAppend);
766
+ }
767
+ function shouldAppendRewriteParamsToQuery(destination, params) {
768
+ const keys = Object.keys(params).filter((key) => key !== "nextInternalLocale");
769
+ if (keys.length === 0) return false;
770
+ return !destinationPathOrHostUsesParam(destination, keys);
771
+ }
772
+ function destinationPathOrHostUsesParam(destination, keys) {
773
+ const pathAndHost = getDestinationPathAndHost(destination);
774
+ if (!pathAndHost) return false;
775
+ for (const key of keys) {
776
+ const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
777
+ if (new RegExp(`:${escapedKey}([+*])?(?![A-Za-z0-9_])`).test(pathAndHost)) return true;
778
+ }
779
+ return false;
780
+ }
781
+ function getDestinationPathAndHost(destination) {
782
+ const hashIndex = destination.indexOf("#");
783
+ const beforeHash = hashIndex === -1 ? destination : destination.slice(0, hashIndex);
784
+ const hash = hashIndex === -1 ? "" : destination.slice(hashIndex);
785
+ const queryIndex = beforeHash.indexOf("?");
786
+ const beforeQuery = queryIndex === -1 ? beforeHash : beforeHash.slice(0, queryIndex);
787
+ const schemeMatch = /^[a-z][a-z0-9+.-]*:\/\//i.exec(beforeQuery);
788
+ if (!schemeMatch) return `${beforeQuery}${hash}`;
789
+ const withoutScheme = beforeQuery.slice(schemeMatch[0].length);
790
+ const slashIndex = withoutScheme.indexOf("/");
791
+ if (slashIndex === -1) return `${withoutScheme}${hash}`;
792
+ return `${withoutScheme.slice(0, slashIndex)}${withoutScheme.slice(slashIndex)}${hash}`;
793
+ }
794
+ function getDestinationQueryKeys(destination) {
795
+ const hashIndex = destination.indexOf("#");
796
+ const beforeHash = hashIndex === -1 ? destination : destination.slice(0, hashIndex);
797
+ const queryIndex = beforeHash.indexOf("?");
798
+ if (queryIndex === -1) return /* @__PURE__ */ new Set();
799
+ const query = beforeHash.slice(queryIndex + 1);
800
+ return new Set(new URLSearchParams(query).keys());
801
+ }
802
+ function appendQueryParams(url, params) {
803
+ const hashIndex = url.indexOf("#");
804
+ const beforeHash = hashIndex === -1 ? url : url.slice(0, hashIndex);
805
+ const hash = hashIndex === -1 ? "" : url.slice(hashIndex);
806
+ const queryIndex = beforeHash.indexOf("?");
807
+ const base = queryIndex === -1 ? beforeHash : beforeHash.slice(0, queryIndex);
808
+ const query = queryIndex === -1 ? "" : beforeHash.slice(queryIndex + 1);
809
+ const merged = new URLSearchParams(query);
810
+ for (const [key, value] of params) merged.append(key, value);
811
+ const search = merged.toString();
812
+ return `${base}${search ? `?${search}` : ""}${hash}`;
813
+ }
814
+ /**
743
815
  * Sanitize a redirect/rewrite destination to collapse protocol-relative URLs.
744
816
  *
745
817
  * After parameter substitution, a destination like `/:path*` can become
@@ -117,14 +117,20 @@ type NextConfig = {
117
117
  domains?: string[];
118
118
  unoptimized?: boolean; /** Allowed device widths for image optimization. Defaults to Next.js defaults: [640, 750, 828, 1080, 1200, 1920, 2048, 3840] */
119
119
  deviceSizes?: number[]; /** Allowed image sizes for fixed-width images. Defaults to Next.js defaults: [16, 32, 48, 64, 96, 128, 256, 384] */
120
- imageSizes?: number[]; /** Allow SVG images through the image optimization endpoint. SVG can contain scripts, so only enable if you trust all image sources. */
120
+ imageSizes?: number[]; /** Allowed image qualities. When unset, any quality from 1-100 is permitted (matches Next.js). */
121
+ qualities?: number[]; /** Allow SVG images through the image optimization endpoint. SVG can contain scripts, so only enable if you trust all image sources. */
121
122
  dangerouslyAllowSVG?: boolean; /** Allow image optimization for hostnames that resolve to private IP addresses. This is a security risk (SSRF) — only enable for private networks when you understand the risk. */
122
123
  dangerouslyAllowLocalIP?: boolean; /** Content-Disposition header for image responses. Defaults to "inline". */
123
124
  contentDispositionType?: "inline" | "attachment"; /** Content-Security-Policy header for image responses. Defaults to "script-src 'none'; frame-src 'none'; sandbox;" */
124
125
  contentSecurityPolicy?: string;
125
126
  }; /** Build output mode: 'export' for full static export, 'standalone' for single server */
126
127
  output?: "export" | "standalone"; /** File extensions treated as routable pages/routes (Next.js pageExtensions) */
127
- pageExtensions?: string[];
128
+ pageExtensions?: string[]; /** Turbopack-compatible module resolution options. */
129
+ turbopack?: {
130
+ resolveAlias?: Record<string, unknown>;
131
+ resolveExtensions?: string[];
132
+ [key: string]: unknown;
133
+ };
128
134
  /**
129
135
  * Module specifiers that are required for side effects on the client before
130
136
  * hydration, in array order, ahead of the user's `instrumentation-client.{ts,js}`.
@@ -181,6 +187,15 @@ type NextConfig = {
181
187
  */
182
188
  defineServer?: Record<string, string | number | boolean>;
183
189
  };
190
+ experimental?: {
191
+ /** Enables hard-navigation recovery when App Router navigation rendering fails. */appNavFailHandling?: boolean;
192
+ /**
193
+ * Enables the experimental App Router gesture transition API:
194
+ * `useRouter().experimental_gesturePush()`.
195
+ */
196
+ gestureTransition?: boolean;
197
+ [key: string]: unknown;
198
+ };
184
199
  /**
185
200
  * Path to a custom cache handler module (e.g., KV, Redis, DynamoDB).
186
201
  * Accepts relative paths, absolute paths, or file:// URLs from import.meta.resolve().
@@ -228,8 +243,16 @@ type ResolvedNextConfig = {
228
243
  trailingSlash: boolean;
229
244
  output: "" | "export" | "standalone";
230
245
  pageExtensions: string[];
246
+ resolveExtensions: string[] | null;
247
+ serverResolveExtensions: string[] | null;
231
248
  instrumentationClientInject: string[];
232
249
  cacheComponents: boolean;
250
+ appNavFailHandling: boolean;
251
+ /**
252
+ * Enables the experimental App Router gesture transition API:
253
+ * `useRouter().experimental_gesturePush()`.
254
+ */
255
+ gestureTransition: boolean;
233
256
  /**
234
257
  * Whether `experimental.prefetchInlining` is configured. Next.js uses this
235
258
  * with the Segment Cache to fetch the route tree before the bundled inlined
@@ -324,6 +347,13 @@ type ResolvedNextConfig = {
324
347
  * `test/e2e/optimized-loading` test fixture.
325
348
  */
326
349
  disableOptimizedLoading: boolean;
350
+ /**
351
+ * Mirrors Next.js `experimental.scrollRestoration`. When true, the Pages
352
+ * Router client takes ownership of browser history scroll restoration by
353
+ * setting `window.history.scrollRestoration = "manual"` and snapshotting
354
+ * scroll positions per history entry.
355
+ */
356
+ scrollRestoration: boolean;
327
357
  /**
328
358
  * Build-time constant replacement map applied to BOTH client and server
329
359
  * bundles. Sourced from `compiler.define` in next.config. Values are
@@ -365,6 +395,28 @@ type ResolvedNextConfig = {
365
395
  dynamic: number;
366
396
  static: number;
367
397
  };
398
+ /**
399
+ * Mirrors Next.js `experimental.useLightningcss`. When `true`, switch
400
+ * Vite's CSS pipeline from PostCSS to lightningcss for both transforms
401
+ * and minification, so the user's `lightningCssFeatures` config takes
402
+ * effect (without this flag set, Next.js's own
403
+ * `lightningCssFeatures` option is also a no-op).
404
+ *
405
+ * @see https://nextjs.org/docs/app/api-reference/config/next-config-js/useLightningcss
406
+ */
407
+ useLightningcss: boolean;
408
+ /**
409
+ * Resolved `experimental.lightningCssFeatures` from next.config, converted
410
+ * from dash-case feature names into the numeric bitmask form expected by
411
+ * the lightningcss `transform()` API (`include` / `exclude` options). When
412
+ * the user did not supply the option, both masks are `0` (a no-op).
413
+ *
414
+ * @see https://nextjs.org/docs/app/api-reference/config/next-config-js/lightningCssFeatures
415
+ */
416
+ lightningCssFeatures: {
417
+ include: number;
418
+ exclude: number;
419
+ };
368
420
  };
369
421
  /**
370
422
  * Whole-word substring check for any of the CJS-style globals that the
@@ -444,11 +496,14 @@ declare function normalizeAssetPrefix(value: unknown): string;
444
496
  * resolve it once and share it — see `__VINEXT_SHARED_RSC_COMPATIBILITY_ID`.
445
497
  */
446
498
  declare function createRscCompatibilityId(nextConfig: Pick<ResolvedNextConfig, "deploymentId">): string;
499
+ declare function lightningCssFeatureNamesToMask(names: readonly string[]): number;
447
500
  /**
448
501
  * Resolve a NextConfig into a fully-resolved ResolvedNextConfig.
449
502
  * Awaits async functions for redirects/rewrites/headers.
450
503
  */
451
- declare function resolveNextConfig(config: NextConfig | null, root?: string): Promise<ResolvedNextConfig>;
504
+ declare function resolveNextConfig(config: NextConfig | null, root?: string, options?: {
505
+ dev?: boolean;
506
+ }): Promise<ResolvedNextConfig>;
452
507
  /**
453
508
  * Extract MDX compilation options (remark/rehype/recma plugins) from
454
509
  * a Next.js config that uses @next/mdx.
@@ -476,4 +531,4 @@ declare function extractMdxOptions(config: NextConfig, root?: string): Promise<M
476
531
  */
477
532
  declare function detectNextIntlConfig(root: string, resolved: ResolvedNextConfig): void;
478
533
  //#endregion
479
- export { HasCondition, MdxOptions, NextConfig, NextConfigInput, NextHeader, NextI18nConfig, NextRedirect, NextRewrite, PHASE_PRODUCTION_BUILD, ResolvedNextConfig, createRscCompatibilityId, detectNextIntlConfig, extractMdxOptions, findNextConfigPath, loadNextConfig, normalizeAssetPrefix, parseBodySizeLimit, reassignsModuleExports, referencesCjsGlobals, resolveNextConfig, resolveNextConfigInput };
534
+ export { HasCondition, MdxOptions, NextConfig, NextConfigInput, NextHeader, NextI18nConfig, NextRedirect, NextRewrite, PHASE_PRODUCTION_BUILD, ResolvedNextConfig, createRscCompatibilityId, detectNextIntlConfig, extractMdxOptions, findNextConfigPath, lightningCssFeatureNamesToMask, loadNextConfig, normalizeAssetPrefix, parseBodySizeLimit, reassignsModuleExports, referencesCjsGlobals, resolveNextConfig, resolveNextConfigInput };
@@ -1,10 +1,11 @@
1
1
  import { normalizePageExtensions } from "../routing/file-matcher.js";
2
2
  import { applyLocaleToRoutes, isExternalUrl } from "./config-matchers.js";
3
3
  import { isUnknownRecord } from "../utils/record.js";
4
- import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
5
4
  import { getHtmlLimitedBotRegex } from "../utils/html-limited-bots.js";
5
+ import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
6
6
  import { loadTsconfigResolutionForRoot } from "./tsconfig-paths.js";
7
7
  import { getViteMajorVersion } from "../utils/vite-version.js";
8
+ import { loadCommonJsModule, shouldRetryAsCommonJs } from "../utils/commonjs-loader.js";
8
9
  import { createRequire } from "node:module";
9
10
  import fs from "node:fs";
10
11
  import path from "node:path";
@@ -259,31 +260,16 @@ async function resolveNextConfigInput(config, phase = PHASE_DEVELOPMENT_SERVER)
259
260
  *
260
261
  * For `.cjs` (or `.js` in a non-type-module package) Node's loader picks the
261
262
  * right format automatically and `require()` just works. For `.js` in a
262
- * `"type": "module"` package, Node infers ESM from package.json and the file
263
- * fails with `require is not defined`. In that case we copy the source to a
264
- * sibling temp `.cjs` (where the explicit extension forces CJS regardless of
265
- * the parent type field) and require *that*. Relative imports inside the
266
- * config still resolve against the original directory.
263
+ * `"type": "module"` package, retry through the shared in-memory CommonJS
264
+ * loader so nested local `.js` dependencies retain CommonJS semantics too.
267
265
  */
268
266
  async function loadConfigViaRequire(configPath, root, phase) {
269
267
  const require = createRequire(path.join(root, "package.json"));
270
268
  try {
271
269
  return await unwrapConfig(require(configPath), phase);
272
270
  } catch (e) {
273
- if (!isCjsError(e) || !configPath.endsWith(".js")) throw e;
274
- return await loadConfigViaCjsTempCopy(configPath, root, phase);
275
- }
276
- }
277
- async function loadConfigViaCjsTempCopy(configPath, root, phase) {
278
- const dir = path.dirname(configPath);
279
- const tmpPath = path.join(dir, `.vinext-next-config.${process.pid}.${Date.now()}.cjs`);
280
- fs.copyFileSync(configPath, tmpPath);
281
- try {
282
- return await unwrapConfig(createRequire(path.join(root, "package.json"))(tmpPath), phase);
283
- } finally {
284
- try {
285
- fs.unlinkSync(tmpPath);
286
- } catch {}
271
+ if (!shouldRetryAsCommonJs(e, configPath)) throw e;
272
+ return await unwrapConfig(loadCommonJsModule(configPath), phase);
287
273
  }
288
274
  }
289
275
  /**
@@ -454,6 +440,58 @@ function readStringArray(value) {
454
440
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
455
441
  }
456
442
  /**
443
+ * Convert lightningcss feature names from `experimental.lightningCssFeatures`
444
+ * into a numeric bitmask consumable by the `lightningcss` `transform()` /
445
+ * `bundle()` API (the `include` / `exclude` options).
446
+ *
447
+ * The mapping mirrors Next.js exactly so the same dash-case feature names
448
+ * accepted by `next.config` produce the same bits on both sides. See:
449
+ * - `.nextjs-ref/packages/next/src/server/config-shared.ts` (`LIGHTNINGCSS_FEATURE_NAMES`)
450
+ * - `.nextjs-ref/crates/next-core/src/next_config.rs` (`lightningcss_feature_names_to_mask`)
451
+ * - `lightningcss/node/targets.d.ts` (`Features` enum bits)
452
+ *
453
+ * Unknown names emit a warning (matching the Next.js Rust path, which errors;
454
+ * we warn instead so a stray name doesn't break the whole build).
455
+ */
456
+ const LIGHTNINGCSS_FEATURE_BITS = {
457
+ nesting: 1,
458
+ "not-selector-list": 2,
459
+ "dir-selector": 4,
460
+ "lang-selector-list": 8,
461
+ "is-selector": 16,
462
+ "text-decoration-thickness-percent": 32,
463
+ "media-interval-syntax": 64,
464
+ "media-range-syntax": 128,
465
+ "custom-media-queries": 256,
466
+ "clamp-function": 512,
467
+ "color-function": 1024,
468
+ "oklab-colors": 2048,
469
+ "lab-colors": 4096,
470
+ "p3-colors": 8192,
471
+ "hex-alpha-colors": 16384,
472
+ "space-separated-color-notation": 32768,
473
+ "font-family-system-ui": 65536,
474
+ "double-position-gradients": 131072,
475
+ "vendor-prefixes": 262144,
476
+ "logical-properties": 524288,
477
+ "light-dark": 1048576,
478
+ selectors: 31,
479
+ "media-queries": 448,
480
+ colors: 1113088
481
+ };
482
+ function lightningCssFeatureNamesToMask(names) {
483
+ let mask = 0;
484
+ for (const name of names) {
485
+ const bit = LIGHTNINGCSS_FEATURE_BITS[name];
486
+ if (bit === void 0) {
487
+ console.warn(`[vinext] Unknown lightningcss feature name "${name}" in experimental.lightningCssFeatures — ignoring.`);
488
+ continue;
489
+ }
490
+ mask |= bit;
491
+ }
492
+ return mask;
493
+ }
494
+ /**
457
495
  * Serialize a `compiler.define` / `compiler.defineServer` map into the
458
496
  * Vite-friendly `Record<string, string>` shape where each value is already
459
497
  * a JSON-encoded literal of source code. Entries whose values are not a
@@ -500,7 +538,7 @@ function resolveStaleTimes(experimental) {
500
538
  * Resolve a NextConfig into a fully-resolved ResolvedNextConfig.
501
539
  * Awaits async functions for redirects/rewrites/headers.
502
540
  */
503
- async function resolveNextConfig(config, root = process.cwd()) {
541
+ async function resolveNextConfig(config, root = process.cwd(), options = {}) {
504
542
  if (!config) {
505
543
  const buildId = await resolveBuildId(void 0);
506
544
  const deploymentId = resolveDeploymentId(void 0);
@@ -511,7 +549,11 @@ async function resolveNextConfig(config, root = process.cwd()) {
511
549
  trailingSlash: false,
512
550
  output: "",
513
551
  pageExtensions: normalizePageExtensions(),
552
+ resolveExtensions: null,
553
+ serverResolveExtensions: null,
514
554
  cacheComponents: false,
555
+ appNavFailHandling: false,
556
+ gestureTransition: false,
515
557
  prefetchInlining: false,
516
558
  redirects: [],
517
559
  rewrites: {
@@ -544,11 +586,17 @@ async function resolveNextConfig(config, root = process.cwd()) {
544
586
  sassOptions: null,
545
587
  removeConsole: false,
546
588
  disableOptimizedLoading: false,
589
+ scrollRestoration: false,
547
590
  compilerDefine: {},
548
591
  compilerDefineServer: {},
549
592
  instrumentationClientInject: [],
550
593
  clientTraceMetadata: void 0,
551
- staleTimes: { ...DEFAULT_STALE_TIMES }
594
+ staleTimes: { ...DEFAULT_STALE_TIMES },
595
+ useLightningcss: false,
596
+ lightningCssFeatures: {
597
+ include: 0,
598
+ exclude: 0
599
+ }
552
600
  };
553
601
  detectNextIntlConfig(root, resolved);
554
602
  return resolved;
@@ -586,7 +634,7 @@ async function resolveNextConfig(config, root = process.cwd()) {
586
634
  }
587
635
  let headers = [];
588
636
  if (config.headers) headers = await config.headers();
589
- const webpackProbe = await probeWebpackConfig(config, root);
637
+ const webpackProbe = await probeWebpackConfig(config, root, options.dev ?? false);
590
638
  const mdx = webpackProbe.mdx;
591
639
  const aliases = {
592
640
  ...extractTurboAliases(config, root),
@@ -620,12 +668,22 @@ async function resolveNextConfig(config, root = process.cwd()) {
620
668
  const serverExternalPackages = topLevelServerExternalPackages ?? legacyServerComponentsExternal;
621
669
  if (experimental?.swcEnvOptions !== void 0) console.warn("[vinext] next.config option \"experimental.swcEnvOptions\" is not applicable and will be ignored (vinext uses Vite, not SWC). A Vite-compatible polyfill solution may be explored in the future.");
622
670
  if (experimental?.rootParams !== void 0) console.warn("[vinext] `experimental.rootParams` is no longer needed, because `next/root-params` is available by default. You can remove it from next.config.(js|mjs|ts).");
671
+ const useLightningcss = experimental?.useLightningcss === true;
672
+ const rawLightningCssFeatures = readOptionalRecord(experimental?.lightningCssFeatures);
673
+ const lightningCssFeatures = {
674
+ include: lightningCssFeatureNamesToMask(readStringArray(rawLightningCssFeatures?.include)),
675
+ exclude: lightningCssFeatureNamesToMask(readStringArray(rawLightningCssFeatures?.exclude))
676
+ };
677
+ if (rawLightningCssFeatures && !useLightningcss) console.warn("[vinext] experimental.lightningCssFeatures is set but experimental.useLightningcss is not enabled. The lightningCssFeatures option has no effect without useLightningcss.");
623
678
  if (experimental?.cachedNavigations === true && !config.cacheComponents) console.warn("[vinext] `experimental.cachedNavigations` requires `cacheComponents: true` to have any effect. Set `cacheComponents: true` in your next.config, or remove `experimental.cachedNavigations`.");
624
- if (config.webpack !== void 0) if (mdx || Object.keys(webpackProbe.aliases).length > 0) console.warn("[vinext] next.config option \"webpack\" is only partially supported. vinext preserves resolve.alias entries and MDX loader settings, but other webpack customization is ignored");
679
+ if (config.webpack !== void 0) if (mdx || Object.keys(webpackProbe.aliases).length > 0 || webpackProbe.resolveExtensionsCustomized) console.warn("[vinext] next.config option \"webpack\" is only partially supported. vinext preserves resolve.alias, resolve.extensions, and MDX loader settings, but other webpack customization is ignored");
625
680
  else console.warn("[vinext] next.config option \"webpack\" is not yet supported and will be ignored");
626
681
  const output = readOptionalString(config.output) ?? "";
627
682
  if (output && output !== "export" && output !== "standalone") console.warn(`[vinext] Unknown output mode "${output}", ignoring`);
628
683
  const pageExtensions = normalizePageExtensions(config.pageExtensions);
684
+ const experimentalTurbo = readOptionalRecord(experimental?.turbo);
685
+ const turbopack = readOptionalRecord(config.turbopack);
686
+ const resolveExtensions = Array.isArray(turbopack?.resolveExtensions) ? readStringArray(turbopack.resolveExtensions) : Array.isArray(experimentalTurbo?.resolveExtensions) ? readStringArray(experimentalTurbo.resolveExtensions) : null;
629
687
  let i18n = null;
630
688
  if (config.i18n) i18n = {
631
689
  locales: config.i18n.locales,
@@ -653,8 +711,12 @@ async function resolveNextConfig(config, root = process.cwd()) {
653
711
  trailingSlash: config.trailingSlash ?? false,
654
712
  output: output === "export" || output === "standalone" ? output : "",
655
713
  pageExtensions,
714
+ resolveExtensions: resolveExtensions ?? webpackProbe.resolveExtensions,
715
+ serverResolveExtensions: resolveExtensions ?? webpackProbe.serverResolveExtensions,
656
716
  instrumentationClientInject: Array.isArray(config.instrumentationClientInject) ? config.instrumentationClientInject.filter((x) => typeof x === "string") : [],
657
717
  cacheComponents: config.cacheComponents ?? false,
718
+ appNavFailHandling: experimental?.appNavFailHandling === true,
719
+ gestureTransition: experimental?.gestureTransition === true,
658
720
  prefetchInlining,
659
721
  redirects,
660
722
  rewrites,
@@ -683,10 +745,13 @@ async function resolveNextConfig(config, root = process.cwd()) {
683
745
  sassOptions: readOptionalRecord(config.sassOptions) ?? null,
684
746
  removeConsole: config.compiler?.removeConsole === true ? true : isUnknownRecord(config.compiler?.removeConsole) ? { exclude: readStringArray(config.compiler.removeConsole.exclude) } : false,
685
747
  disableOptimizedLoading: experimental?.disableOptimizedLoading === true,
748
+ scrollRestoration: experimental?.scrollRestoration === true,
686
749
  compilerDefine: serializeCompilerDefine(config.compiler?.define),
687
750
  compilerDefineServer: serializeCompilerDefine(config.compiler?.defineServer),
688
751
  clientTraceMetadata: Array.isArray(experimental?.clientTraceMetadata) ? experimental.clientTraceMetadata.filter((value) => typeof value === "string") : void 0,
689
- staleTimes: resolveStaleTimes(experimental)
752
+ staleTimes: resolveStaleTimes(experimental),
753
+ useLightningcss,
754
+ lightningCssFeatures
690
755
  };
691
756
  detectNextIntlConfig(root, resolved);
692
757
  if (resolved.basePath !== "" && resolved.basePath !== "/" && resolved.assetPrefix === "") resolved.assetPrefix = resolved.basePath;
@@ -725,39 +790,75 @@ function extractTurboAliases(config, root) {
725
790
  ...normalizeAliasEntries(readOptionalRecord(topLevelTurbopack?.resolveAlias), root)
726
791
  };
727
792
  }
728
- async function probeWebpackConfig(config, root) {
793
+ async function probeWebpackConfig(config, root, dev) {
729
794
  if (typeof config.webpack !== "function") return {
730
795
  aliases: {},
731
- mdx: null
732
- };
733
- const mockModuleRules = [];
734
- const mockConfig = {
735
- context: root,
736
- resolve: { alias: {} },
737
- module: { rules: mockModuleRules },
738
- plugins: []
739
- };
740
- const mockOptions = {
741
- defaultLoaders: { babel: { loader: "next-babel-loader" } },
742
- isServer: false,
743
- dev: false,
744
- dir: root
796
+ mdx: null,
797
+ resolveExtensions: null,
798
+ serverResolveExtensions: null,
799
+ resolveExtensionsCustomized: false
745
800
  };
746
801
  try {
747
- const finalConfig = await config.webpack(mockConfig, mockOptions) ?? mockConfig;
748
- const rules = finalConfig.module?.rules ?? mockModuleRules;
749
- invokeLoaderSideEffects(rules, root);
802
+ const clientProbe = await runWebpackConfigProbe(config, root, {
803
+ dev,
804
+ isServer: false
805
+ });
806
+ const serverProbe = await runWebpackConfigProbe(config, root, {
807
+ dev,
808
+ isServer: true,
809
+ nextRuntime: "nodejs"
810
+ });
811
+ invokeLoaderSideEffects(clientProbe.rules, root);
750
812
  return {
751
- aliases: normalizeAliasEntries(finalConfig.resolve?.alias, root),
752
- mdx: extractMdxOptionsFromRules(rules)
813
+ aliases: normalizeAliasEntries(clientProbe.config.resolve?.alias, root),
814
+ mdx: extractMdxOptionsFromRules(clientProbe.rules),
815
+ resolveExtensions: clientProbe.resolveExtensions,
816
+ serverResolveExtensions: serverProbe.resolveExtensions,
817
+ resolveExtensionsCustomized: clientProbe.resolveExtensions !== null || serverProbe.resolveExtensions !== null
753
818
  };
754
819
  } catch {
755
820
  return {
756
821
  aliases: {},
757
- mdx: null
822
+ mdx: null,
823
+ resolveExtensions: null,
824
+ serverResolveExtensions: null,
825
+ resolveExtensionsCustomized: false
758
826
  };
759
827
  }
760
828
  }
829
+ const DEFAULT_WEBPACK_RESOLVE_EXTENSIONS = [
830
+ ".js",
831
+ ".mjs",
832
+ ".tsx",
833
+ ".ts",
834
+ ".jsx",
835
+ ".json",
836
+ ".wasm"
837
+ ];
838
+ async function runWebpackConfigProbe(config, root, options) {
839
+ const rules = [];
840
+ const mockConfig = {
841
+ context: root,
842
+ resolve: {
843
+ alias: {},
844
+ extensions: [...DEFAULT_WEBPACK_RESOLVE_EXTENSIONS]
845
+ },
846
+ module: { rules },
847
+ plugins: []
848
+ };
849
+ const finalConfig = await config.webpack(mockConfig, {
850
+ defaultLoaders: { babel: { loader: "next-babel-loader" } },
851
+ ...options,
852
+ dir: root
853
+ }) ?? mockConfig;
854
+ const finalRules = finalConfig.module?.rules ?? rules;
855
+ const extensions = Array.isArray(finalConfig.resolve?.extensions) ? readStringArray(finalConfig.resolve.extensions) : null;
856
+ return {
857
+ config: finalConfig,
858
+ rules: finalRules,
859
+ resolveExtensions: extensions !== null && (extensions.length !== DEFAULT_WEBPACK_RESOLVE_EXTENSIONS.length || extensions.some((extension, index) => extension !== DEFAULT_WEBPACK_RESOLVE_EXTENSIONS[index])) ? extensions : null
860
+ };
861
+ }
761
862
  /**
762
863
  * Walk webpack module rules and invoke each referenced loader once with a
763
864
  * dummy source string. Loaders that mutate `process.env` at compile time (a
@@ -837,7 +938,7 @@ function invokeLoaderSideEffects(rules, root) {
837
938
  * We probe the webpack function with a mock config to extract them.
838
939
  */
839
940
  async function extractMdxOptions(config, root = process.cwd()) {
840
- return (await probeWebpackConfig(config, root)).mdx;
941
+ return (await probeWebpackConfig(config, root, false)).mdx;
841
942
  }
842
943
  /**
843
944
  * Probe file candidates relative to root. Returns the first one that exists,
@@ -930,4 +1031,4 @@ function extractPluginsFromOptions(opts) {
930
1031
  return null;
931
1032
  }
932
1033
  //#endregion
933
- export { PHASE_PRODUCTION_BUILD, createRscCompatibilityId, detectNextIntlConfig, extractMdxOptions, findNextConfigPath, loadNextConfig, normalizeAssetPrefix, parseBodySizeLimit, reassignsModuleExports, referencesCjsGlobals, resolveNextConfig, resolveNextConfigInput };
1034
+ export { PHASE_PRODUCTION_BUILD, createRscCompatibilityId, detectNextIntlConfig, extractMdxOptions, findNextConfigPath, lightningCssFeatureNamesToMask, loadNextConfig, normalizeAssetPrefix, parseBodySizeLimit, reassignsModuleExports, referencesCjsGlobals, resolveNextConfig, resolveNextConfigInput };
package/dist/deploy.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ensureESModule as ensureESModule$1, renameCJSConfigs as renameCJSConfigs$1 } from "./utils/project.js";
2
+ import { execFileSync } from "node:child_process";
2
3
 
3
4
  //#region src/deploy.d.ts
4
5
  type DeployOptions = {
@@ -151,21 +152,39 @@ type WranglerDeployArgs = {
151
152
  args: string[];
152
153
  env: string | undefined;
153
154
  };
155
+ declare function validateWranglerEnvName(env: string): string;
154
156
  declare function buildWranglerDeployArgs(options: Pick<DeployOptions, "preview" | "env">): WranglerDeployArgs;
155
157
  /**
156
- * Resolve the wrangler executable in node_modules.
158
+ * Resolve Wrangler's JavaScript CLI entrypoint in node_modules.
157
159
  *
158
- * Walks up ancestor directories so the binary is found even when node_modules
159
- * is hoisted to the workspace root in a monorepo.
160
+ * Invoking the JavaScript file through `process.execPath` avoids the `.cmd`
161
+ * shim and command shell that package managers create on Windows.
162
+ */
163
+ declare function resolveWranglerBin(root: string, resolvePackageJson?: (root: string) => string | null): string;
164
+ declare function buildNodeCliInvocation(scriptPath: string, args: string[], nodeExecutable?: string): {
165
+ file: string;
166
+ args: string[];
167
+ };
168
+ declare function buildWranglerInvocation(root: string, options: Pick<DeployOptions, "preview" | "env">, nodeExecutable?: string): {
169
+ file: string;
170
+ args: string[];
171
+ env: string | undefined;
172
+ };
173
+ declare function runWranglerDeploy(root: string, options: Pick<DeployOptions, "preview" | "env">, execute?: typeof execFileSync): string;
174
+ /**
175
+ * Read the prerender manifest and inject pregenerated concrete paths into the
176
+ * App Router Worker bundle so the PPR fallback-shell guard is populated at
177
+ * module init time without calling `seedMemoryCacheFromPrerender`.
178
+ *
179
+ * The paths are injected as `globalThis.__VINEXT_PREGENERATED_CONCRETE_PATHS`
180
+ * wrapped in replaceable marker comments, and consumed by
181
+ * `initPregeneratedPathsFromGlobals` in the generated RSC entry.
160
182
  *
161
- * On Windows, `node_modules/.bin/` contains both a Unix shebang script (no
162
- * extension) and a `.CMD` shim. Node's `execFileSync` uses CreateProcess(),
163
- * which only resolves PATHEXT extensions (`.cmd`, `.exe`, ...) spawning the
164
- * bare-name shebang file fails with ENOENT even though the file exists. So on
165
- * Windows we prefer the `.CMD` shim and only fall back to the bare name for a
166
- * clearer error message if neither is present.
183
+ * Idempotent: repeated calls strip the previous injection before writing the
184
+ * new one. If the manifest is missing, corrupt, or empty, any prior injection
185
+ * is stripped and nothing new is writtenfailing closed to empty.
167
186
  */
168
- declare function resolveWranglerBin(root: string, platform?: NodeJS.Platform): string;
187
+ declare function injectPregeneratedConcretePaths(root: string): void;
169
188
  declare function deploy(options: DeployOptions): Promise<void>;
170
189
  //#endregion
171
- export { buildWranglerDeployArgs, deploy, detectProject, ensureESModule, formatMissingCacheAdapterError, formatMissingCloudflarePluginError, generateAppRouterViteConfig, generateAppRouterWorkerEntry, generatePagesRouterViteConfig, generatePagesRouterWorkerEntry, generateWranglerConfig, getFilesToGenerate, getMissingDeps, hasWranglerConfig, isPackageResolvable, parseDeployArgs, renameCJSConfigs, resolveWranglerBin, viteConfigHasCacheAdapter, viteConfigHasCloudflarePlugin, withCloudflareEnv, workerEntryHasCacheHandler };
190
+ export { buildNodeCliInvocation, buildWranglerDeployArgs, buildWranglerInvocation, deploy, detectProject, ensureESModule, formatMissingCacheAdapterError, formatMissingCloudflarePluginError, generateAppRouterViteConfig, generateAppRouterWorkerEntry, generatePagesRouterViteConfig, generatePagesRouterWorkerEntry, generateWranglerConfig, getFilesToGenerate, getMissingDeps, hasWranglerConfig, injectPregeneratedConcretePaths, isPackageResolvable, parseDeployArgs, renameCJSConfigs, resolveWranglerBin, runWranglerDeploy, validateWranglerEnvName, viteConfigHasCacheAdapter, viteConfigHasCloudflarePlugin, withCloudflareEnv, workerEntryHasCacheHandler };