vinext 0.0.38 → 0.0.40

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 (245) hide show
  1. package/README.md +33 -20
  2. package/dist/build/nitro-route-rules.d.ts +50 -0
  3. package/dist/build/nitro-route-rules.js +81 -0
  4. package/dist/build/nitro-route-rules.js.map +1 -0
  5. package/dist/build/precompress.d.ts +17 -0
  6. package/dist/build/precompress.js +102 -0
  7. package/dist/build/precompress.js.map +1 -0
  8. package/dist/build/prerender.d.ts +27 -22
  9. package/dist/build/prerender.js +17 -17
  10. package/dist/build/prerender.js.map +1 -1
  11. package/dist/build/report.d.ts +3 -4
  12. package/dist/build/report.js.map +1 -1
  13. package/dist/build/run-prerender.d.ts +3 -4
  14. package/dist/build/run-prerender.js.map +1 -1
  15. package/dist/build/standalone.d.ts +32 -0
  16. package/dist/build/standalone.js +206 -0
  17. package/dist/build/standalone.js.map +1 -0
  18. package/dist/build/static-export.d.ts +17 -29
  19. package/dist/build/static-export.js.map +1 -1
  20. package/dist/check.d.ts +4 -4
  21. package/dist/check.js +1 -1
  22. package/dist/check.js.map +1 -1
  23. package/dist/cli.js +31 -4
  24. package/dist/cli.js.map +1 -1
  25. package/dist/client/instrumentation-client.d.ts +2 -2
  26. package/dist/client/instrumentation-client.js.map +1 -1
  27. package/dist/client/vinext-next-data.d.ts +5 -8
  28. package/dist/cloudflare/index.js +1 -1
  29. package/dist/cloudflare/kv-cache-handler.d.ts +5 -3
  30. package/dist/cloudflare/kv-cache-handler.js +1 -1
  31. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  32. package/dist/cloudflare/tpr.d.ts +35 -27
  33. package/dist/cloudflare/tpr.js +36 -12
  34. package/dist/cloudflare/tpr.js.map +1 -1
  35. package/dist/config/config-matchers.d.ts +2 -2
  36. package/dist/config/config-matchers.js +1 -1
  37. package/dist/config/config-matchers.js.map +1 -1
  38. package/dist/config/dotenv.d.ts +4 -4
  39. package/dist/config/dotenv.js.map +1 -1
  40. package/dist/config/next-config.d.ts +40 -61
  41. package/dist/config/next-config.js +5 -4
  42. package/dist/config/next-config.js.map +1 -1
  43. package/dist/deploy.d.ts +25 -41
  44. package/dist/deploy.js +1 -1
  45. package/dist/deploy.js.map +1 -1
  46. package/dist/entries/app-rsc-entry.d.ts +8 -11
  47. package/dist/entries/app-rsc-entry.js +133 -249
  48. package/dist/entries/app-rsc-entry.js.map +1 -1
  49. package/dist/entries/pages-server-entry.js +1 -3
  50. package/dist/entries/pages-server-entry.js.map +1 -1
  51. package/dist/index.d.ts +49 -28
  52. package/dist/index.js +238 -83
  53. package/dist/index.js.map +1 -1
  54. package/dist/init.d.ts +14 -26
  55. package/dist/init.js +8 -2
  56. package/dist/init.js.map +1 -1
  57. package/dist/plugins/client-reference-dedup.js.map +1 -1
  58. package/dist/plugins/fix-use-server-closure-collision.js.map +1 -1
  59. package/dist/plugins/fonts.d.ts +18 -1
  60. package/dist/plugins/fonts.js +107 -8
  61. package/dist/plugins/fonts.js.map +1 -1
  62. package/dist/plugins/optimize-imports.d.ts +2 -2
  63. package/dist/plugins/optimize-imports.js +4 -4
  64. package/dist/plugins/optimize-imports.js.map +1 -1
  65. package/dist/plugins/server-externals-manifest.d.ts +37 -0
  66. package/dist/plugins/server-externals-manifest.js +83 -0
  67. package/dist/plugins/server-externals-manifest.js.map +1 -0
  68. package/dist/routing/app-router.d.ts +37 -55
  69. package/dist/routing/app-router.js +37 -22
  70. package/dist/routing/app-router.js.map +1 -1
  71. package/dist/routing/file-matcher.d.ts +2 -2
  72. package/dist/routing/file-matcher.js.map +1 -1
  73. package/dist/routing/pages-router.d.ts +6 -11
  74. package/dist/routing/pages-router.js.map +1 -1
  75. package/dist/routing/route-trie.d.ts +2 -2
  76. package/dist/routing/route-trie.js.map +1 -1
  77. package/dist/server/api-handler.js.map +1 -1
  78. package/dist/server/app-browser-entry.js +270 -39
  79. package/dist/server/app-browser-entry.js.map +1 -1
  80. package/dist/server/app-browser-stream.d.ts +6 -6
  81. package/dist/server/app-browser-stream.js.map +1 -1
  82. package/dist/server/app-page-boundary-render.d.ts +8 -8
  83. package/dist/server/app-page-boundary-render.js +2 -2
  84. package/dist/server/app-page-boundary-render.js.map +1 -1
  85. package/dist/server/app-page-boundary.d.ts +13 -11
  86. package/dist/server/app-page-boundary.js +1 -1
  87. package/dist/server/app-page-boundary.js.map +1 -1
  88. package/dist/server/app-page-cache.d.ts +10 -10
  89. package/dist/server/app-page-cache.js.map +1 -1
  90. package/dist/server/app-page-execution.d.ts +10 -10
  91. package/dist/server/app-page-execution.js.map +1 -1
  92. package/dist/server/app-page-probe.d.ts +2 -2
  93. package/dist/server/app-page-probe.js.map +1 -1
  94. package/dist/server/app-page-render.d.ts +4 -4
  95. package/dist/server/app-page-render.js.map +1 -1
  96. package/dist/server/app-page-request.d.ts +12 -12
  97. package/dist/server/app-page-request.js.map +1 -1
  98. package/dist/server/app-page-response.d.ts +30 -19
  99. package/dist/server/app-page-response.js +26 -7
  100. package/dist/server/app-page-response.js.map +1 -1
  101. package/dist/server/app-page-route-wiring.d.ts +79 -0
  102. package/dist/server/app-page-route-wiring.js +165 -0
  103. package/dist/server/app-page-route-wiring.js.map +1 -0
  104. package/dist/server/app-page-stream.d.ts +18 -18
  105. package/dist/server/app-page-stream.js +3 -0
  106. package/dist/server/app-page-stream.js.map +1 -1
  107. package/dist/server/app-route-handler-cache.d.ts +2 -2
  108. package/dist/server/app-route-handler-cache.js.map +1 -1
  109. package/dist/server/app-route-handler-execution.d.ts +6 -6
  110. package/dist/server/app-route-handler-execution.js.map +1 -1
  111. package/dist/server/app-route-handler-policy.d.ts +8 -8
  112. package/dist/server/app-route-handler-policy.js.map +1 -1
  113. package/dist/server/app-route-handler-response.d.ts +6 -6
  114. package/dist/server/app-route-handler-response.js +4 -1
  115. package/dist/server/app-route-handler-response.js.map +1 -1
  116. package/dist/server/app-route-handler-runtime.d.ts +4 -4
  117. package/dist/server/app-route-handler-runtime.js.map +1 -1
  118. package/dist/server/app-router-entry.d.ts +6 -1
  119. package/dist/server/app-router-entry.js +9 -2
  120. package/dist/server/app-router-entry.js.map +1 -1
  121. package/dist/server/app-ssr-entry.d.ts +4 -4
  122. package/dist/server/app-ssr-entry.js.map +1 -1
  123. package/dist/server/app-ssr-stream.d.ts +2 -2
  124. package/dist/server/app-ssr-stream.js +1 -3
  125. package/dist/server/app-ssr-stream.js.map +1 -1
  126. package/dist/server/dev-module-runner.d.ts +2 -2
  127. package/dist/server/dev-module-runner.js.map +1 -1
  128. package/dist/server/dev-server.js +5 -7
  129. package/dist/server/dev-server.js.map +1 -1
  130. package/dist/server/image-optimization.d.ts +7 -12
  131. package/dist/server/image-optimization.js.map +1 -1
  132. package/dist/server/instrumentation.d.ts +8 -12
  133. package/dist/server/instrumentation.js +1 -1
  134. package/dist/server/instrumentation.js.map +1 -1
  135. package/dist/server/isr-cache.d.ts +2 -2
  136. package/dist/server/isr-cache.js.map +1 -1
  137. package/dist/server/metadata-routes.d.ts +14 -19
  138. package/dist/server/metadata-routes.js.map +1 -1
  139. package/dist/server/middleware.d.ts +9 -17
  140. package/dist/server/middleware.js +1 -1
  141. package/dist/server/middleware.js.map +1 -1
  142. package/dist/server/pages-api-route.d.ts +6 -6
  143. package/dist/server/pages-api-route.js.map +1 -1
  144. package/dist/server/pages-i18n.d.ts +4 -4
  145. package/dist/server/pages-i18n.js.map +1 -1
  146. package/dist/server/pages-node-compat.d.ts +10 -10
  147. package/dist/server/pages-node-compat.js.map +1 -1
  148. package/dist/server/pages-page-data.d.ts +22 -22
  149. package/dist/server/pages-page-data.js.map +1 -1
  150. package/dist/server/pages-page-response.d.ts +8 -8
  151. package/dist/server/pages-page-response.js.map +1 -1
  152. package/dist/server/prod-server.d.ts +20 -15
  153. package/dist/server/prod-server.js +198 -55
  154. package/dist/server/prod-server.js.map +1 -1
  155. package/dist/server/seed-cache.js.map +1 -1
  156. package/dist/server/static-file-cache.d.ts +57 -0
  157. package/dist/server/static-file-cache.js +219 -0
  158. package/dist/server/static-file-cache.js.map +1 -0
  159. package/dist/server/worker-utils.d.ts +4 -1
  160. package/dist/server/worker-utils.js +31 -1
  161. package/dist/server/worker-utils.js.map +1 -1
  162. package/dist/shims/app.d.ts +2 -2
  163. package/dist/shims/cache-runtime.d.ts +6 -9
  164. package/dist/shims/cache-runtime.js.map +1 -1
  165. package/dist/shims/cache.d.ts +28 -31
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/config.d.ts +2 -2
  168. package/dist/shims/config.js.map +1 -1
  169. package/dist/shims/dynamic.d.ts +2 -2
  170. package/dist/shims/dynamic.js +5 -7
  171. package/dist/shims/dynamic.js.map +1 -1
  172. package/dist/shims/error-boundary.d.ts +19 -10
  173. package/dist/shims/error-boundary.js +23 -3
  174. package/dist/shims/error-boundary.js.map +1 -1
  175. package/dist/shims/error.d.ts +2 -2
  176. package/dist/shims/error.js.map +1 -1
  177. package/dist/shims/fetch-cache.d.ts +4 -4
  178. package/dist/shims/fetch-cache.js.map +1 -1
  179. package/dist/shims/font-google-base.d.ts +4 -4
  180. package/dist/shims/font-google-base.js.map +1 -1
  181. package/dist/shims/font-local.d.ts +6 -6
  182. package/dist/shims/font-local.js.map +1 -1
  183. package/dist/shims/form.d.ts +4 -8
  184. package/dist/shims/form.js +4 -6
  185. package/dist/shims/form.js.map +1 -1
  186. package/dist/shims/head-state.d.ts +2 -2
  187. package/dist/shims/head-state.js.map +1 -1
  188. package/dist/shims/head.d.ts +2 -2
  189. package/dist/shims/head.js +18 -20
  190. package/dist/shims/head.js.map +1 -1
  191. package/dist/shims/headers.d.ts +4 -4
  192. package/dist/shims/headers.js.map +1 -1
  193. package/dist/shims/i18n-context.d.ts +2 -2
  194. package/dist/shims/i18n-context.js.map +1 -1
  195. package/dist/shims/i18n-state.d.ts +2 -2
  196. package/dist/shims/i18n-state.js.map +1 -1
  197. package/dist/shims/image-config.d.ts +2 -2
  198. package/dist/shims/image-config.js.map +1 -1
  199. package/dist/shims/image.d.ts +5 -6
  200. package/dist/shims/image.js.map +1 -1
  201. package/dist/shims/internal/app-router-context.d.ts +6 -6
  202. package/dist/shims/internal/app-router-context.js.map +1 -1
  203. package/dist/shims/internal/utils.d.ts +2 -2
  204. package/dist/shims/internal/utils.js.map +1 -1
  205. package/dist/shims/layout-segment-context.d.ts +12 -5
  206. package/dist/shims/layout-segment-context.js +9 -4
  207. package/dist/shims/layout-segment-context.js.map +1 -1
  208. package/dist/shims/legacy-image.d.ts +5 -8
  209. package/dist/shims/legacy-image.js.map +1 -1
  210. package/dist/shims/link.d.ts +21 -31
  211. package/dist/shims/link.js +4 -58
  212. package/dist/shims/link.js.map +1 -1
  213. package/dist/shims/metadata.d.ts +23 -31
  214. package/dist/shims/metadata.js.map +1 -1
  215. package/dist/shims/navigation-state.d.ts +2 -2
  216. package/dist/shims/navigation-state.js.map +1 -1
  217. package/dist/shims/navigation.d.ts +118 -18
  218. package/dist/shims/navigation.js +377 -116
  219. package/dist/shims/navigation.js.map +1 -1
  220. package/dist/shims/request-context.d.ts +2 -2
  221. package/dist/shims/request-context.js.map +1 -1
  222. package/dist/shims/router-state.d.ts +4 -4
  223. package/dist/shims/router-state.js.map +1 -1
  224. package/dist/shims/router.d.ts +28 -47
  225. package/dist/shims/router.js +127 -38
  226. package/dist/shims/router.js.map +1 -1
  227. package/dist/shims/script.d.ts +16 -31
  228. package/dist/shims/script.js.map +1 -1
  229. package/dist/shims/server.d.ts +27 -14
  230. package/dist/shims/server.js +91 -73
  231. package/dist/shims/server.js.map +1 -1
  232. package/dist/shims/slot.d.ts +28 -0
  233. package/dist/shims/slot.js +49 -0
  234. package/dist/shims/slot.js.map +1 -0
  235. package/dist/shims/unified-request-context.d.ts +3 -5
  236. package/dist/shims/unified-request-context.js.map +1 -1
  237. package/dist/shims/web-vitals.d.ts +2 -2
  238. package/dist/shims/web-vitals.js.map +1 -1
  239. package/dist/utils/lazy-chunks.d.ts +34 -0
  240. package/dist/utils/lazy-chunks.js +50 -0
  241. package/dist/utils/lazy-chunks.js.map +1 -0
  242. package/dist/utils/vinext-root.d.ts +24 -0
  243. package/dist/utils/vinext-root.js +31 -0
  244. package/dist/utils/vinext-root.js.map +1 -0
  245. package/package.json +1 -2
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ import { generateSsrEntry } from "./entries/app-ssr-entry.js";
21
21
  import { generateBrowserEntry } from "./entries/app-browser-entry.js";
22
22
  import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
23
23
  import { findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
24
+ import { precompressAssets } from "./build/precompress.js";
24
25
  import { scanMetadataFiles } from "./server/metadata-routes.js";
25
26
  import { manifestFileWithBase, manifestFilesWithBase, normalizeManifestFile } from "./utils/manifest-paths.js";
26
27
  import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
@@ -29,7 +30,9 @@ import { createInstrumentationClientTransformPlugin } from "./plugins/instrument
29
30
  import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
30
31
  import { fixUseServerClosureCollisionPlugin } from "./plugins/fix-use-server-closure-collision.js";
31
32
  import { createOgInlineFetchAssetsPlugin, ogAssetsPlugin } from "./plugins/og-assets.js";
32
- import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
33
+ import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
34
+ import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, _findBalancedObject, _findCallEnd, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
35
+ import { computeLazyChunks } from "./utils/lazy-chunks.js";
33
36
  import { formatMissingCloudflarePluginError, hasWranglerConfig } from "./deploy.js";
34
37
  import { staticExportApp, staticExportPages } from "./build/static-export.js";
35
38
  import { createRequire } from "node:module";
@@ -116,7 +119,7 @@ function toViteAliasReplacement(absolutePath, projectRoot) {
116
119
  const realPath = tryRealpathSync(absolutePath);
117
120
  if (realPath) pathCandidates.add(realPath);
118
121
  for (const rootCandidate of rootCandidates) for (const pathCandidate of pathCandidates) {
119
- if (pathCandidate === rootCandidate) return "/";
122
+ if (pathCandidate === rootCandidate) return normalizedPath;
120
123
  const relativeId = relativeWithinRoot(rootCandidate, pathCandidate);
121
124
  if (relativeId) return "/" + relativeId;
122
125
  }
@@ -379,6 +382,9 @@ const clientCodeSplittingConfig = {
379
382
  * tryCatchDeoptimization: false, which can break specific libraries
380
383
  * that rely on property access side effects or try/catch for feature detection
381
384
  * - 'recommended' + 'no-external' gives most of the benefit with less risk
385
+ *
386
+ * @deprecated Use getClientTreeshakeConfigForVite(viteMajorVersion) instead
387
+ * for Vite version compatibility. Kept for backward compatibility.
382
388
  */
383
389
  const clientTreeshakeConfig = {
384
390
  preset: "recommended",
@@ -395,49 +401,31 @@ function getClientOutputConfigForVite(viteMajorVersion) {
395
401
  return viteMajorVersion >= 8 ? { codeSplitting: clientCodeSplittingConfig } : clientOutputConfig;
396
402
  }
397
403
  /**
398
- * Compute the set of chunk filenames that are ONLY reachable through dynamic
399
- * imports (i.e. behind React.lazy(), next/dynamic, or manual import()).
404
+ * Returns treeshake configuration appropriate for the Vite version.
400
405
  *
401
- * These chunks should NOT be modulepreloaded in the HTML — they will be
402
- * fetched on demand when the dynamic import executes.
406
+ * Rollup (Vite 7) supports presets like "recommended" which set multiple
407
+ * treeshake options at once. Rolldown (Vite 8+) doesn't support presets,
408
+ * so we only return moduleSideEffects for Vite 8+.
403
409
  *
404
- * Algorithm: Starting from all entry chunks in the build manifest, walk the
405
- * static `imports` tree (breadth-first). Any chunk file NOT reached by this
406
- * walk is only reachable through `dynamicImports` and is therefore "lazy".
410
+ * The Rollup "recommended" preset sets:
411
+ * - annotations: true (Rolldown default is also true)
412
+ * - manualPureFunctions: [] (Rolldown default is also [])
413
+ * - propertyReadSideEffects: true (Rolldown equivalent is 'always', the default)
414
+ * - unknownGlobalSideEffects: false (Rolldown default is true — this is a known acceptable
415
+ * divergence. Slightly less aggressive DCE on unknown globals, acceptable for client bundles)
416
+ * - correctVarValueBeforeDeclaration and tryCatchDeoptimization (Rolldown handles these differently)
407
417
  *
408
- * @param buildManifest - Vite's build manifest (manifest.json), which is a
409
- * Record<string, ManifestChunk> where each chunk has `file`, `imports`,
410
- * `dynamicImports`, `isEntry`, and `isDynamicEntry` fields.
411
- * @returns Array of chunk filenames (e.g. "assets/mermaid-NOHMQCX5.js") that
412
- * should be excluded from modulepreload hints.
418
+ * The key optimization is moduleSideEffects: "no-external", which is supported
419
+ * by both bundlers and provides the DCE benefits for barrel-exporting libraries.
420
+ * It treats node_modules as side-effect-free (enabling aggressive DCE) while
421
+ * preserving side effects in local code.
413
422
  */
414
- function computeLazyChunks(buildManifest) {
415
- const eagerFiles = /* @__PURE__ */ new Set();
416
- const visited = /* @__PURE__ */ new Set();
417
- const queue = [];
418
- for (const key of Object.keys(buildManifest)) if (buildManifest[key].isEntry) queue.push(key);
419
- while (queue.length > 0) {
420
- const key = queue.shift();
421
- if (visited.has(key)) continue;
422
- visited.add(key);
423
- const chunk = buildManifest[key];
424
- if (!chunk) continue;
425
- eagerFiles.add(chunk.file);
426
- if (chunk.css) for (const cssFile of chunk.css) eagerFiles.add(cssFile);
427
- if (chunk.imports) {
428
- for (const imp of chunk.imports) if (!visited.has(imp)) queue.push(imp);
429
- }
430
- }
431
- const lazyChunks = [];
432
- const allFiles = /* @__PURE__ */ new Set();
433
- for (const key of Object.keys(buildManifest)) {
434
- const chunk = buildManifest[key];
435
- if (chunk.file && !allFiles.has(chunk.file)) {
436
- allFiles.add(chunk.file);
437
- if (!eagerFiles.has(chunk.file) && chunk.file.endsWith(".js")) lazyChunks.push(chunk.file);
438
- }
439
- }
440
- return lazyChunks;
423
+ function getClientTreeshakeConfigForVite(viteMajorVersion) {
424
+ if (viteMajorVersion >= 8) return { moduleSideEffects: "no-external" };
425
+ return {
426
+ preset: "recommended",
427
+ moduleSideEffects: "no-external"
428
+ };
441
429
  }
442
430
  function tryRealpathSync(candidate) {
443
431
  try {
@@ -570,6 +558,37 @@ function vinext(options = {}) {
570
558
  }
571
559
  const imageImportDimCache = /* @__PURE__ */ new Map();
572
560
  let mdxDelegate = null;
561
+ let mdxDelegatePromise = null;
562
+ let hasUserMdxPlugin = false;
563
+ let warnedMissingMdxPlugin = false;
564
+ async function ensureMdxDelegate(reason) {
565
+ if (mdxDelegate || hasUserMdxPlugin) return mdxDelegate;
566
+ if (!mdxDelegatePromise) mdxDelegatePromise = (async () => {
567
+ try {
568
+ const mdxRollup = await import("@mdx-js/rollup");
569
+ const mdxFactory = mdxRollup.default ?? mdxRollup;
570
+ const mdxOpts = {};
571
+ if (nextConfig.mdx) {
572
+ if (nextConfig.mdx.remarkPlugins) mdxOpts.remarkPlugins = nextConfig.mdx.remarkPlugins;
573
+ if (nextConfig.mdx.rehypePlugins) mdxOpts.rehypePlugins = nextConfig.mdx.rehypePlugins;
574
+ if (nextConfig.mdx.recmaPlugins) mdxOpts.recmaPlugins = nextConfig.mdx.recmaPlugins;
575
+ }
576
+ const delegate = mdxFactory(mdxOpts);
577
+ mdxDelegate = delegate;
578
+ if (reason === "detected") if (nextConfig.mdx) console.log("[vinext] Auto-injected @mdx-js/rollup with remark/rehype plugins from next.config");
579
+ else console.log("[vinext] Auto-injected @mdx-js/rollup for MDX support");
580
+ else console.log("[vinext] Auto-injected @mdx-js/rollup for on-demand MDX support");
581
+ return delegate;
582
+ } catch {
583
+ if (reason === "detected" && !warnedMissingMdxPlugin) {
584
+ warnedMissingMdxPlugin = true;
585
+ console.warn("[vinext] MDX files detected but @mdx-js/rollup is not installed. Install it with: " + detectPackageManager(process.cwd()) + " @mdx-js/rollup");
586
+ }
587
+ return null;
588
+ }
589
+ })();
590
+ return mdxDelegatePromise;
591
+ }
573
592
  const plugins = [
574
593
  ...viteMajorVersion >= 8 ? [] : [tsconfigPaths()],
575
594
  reactPluginPromise,
@@ -606,17 +625,19 @@ function vinext(options = {}) {
606
625
  appDir = path.join(baseDir, "app");
607
626
  hasPagesDir = fs.existsSync(pagesDir);
608
627
  hasAppDir = !options.disableAppRouter && fs.existsSync(appDir);
609
- const phase = env?.command === "build" ? PHASE_PRODUCTION_BUILD : PHASE_DEVELOPMENT_SERVER;
610
- let rawConfig;
611
- if (options.nextConfig) {
612
- const diskConfigPath = findNextConfigPath(root);
613
- if (diskConfigPath && !warnedInlineNextConfigOverride) {
614
- warnedInlineNextConfigOverride = true;
615
- console.warn(`[vinext] vinext({ nextConfig }) overrides ${path.basename(diskConfigPath)}. Remove one of the config sources to avoid drift.`);
616
- }
617
- rawConfig = await resolveNextConfigInput(options.nextConfig, phase);
618
- } else rawConfig = await loadNextConfig(root, phase);
619
- nextConfig = await resolveNextConfig(rawConfig, root);
628
+ if (!nextConfig) {
629
+ const phase = env?.command === "build" ? PHASE_PRODUCTION_BUILD : PHASE_DEVELOPMENT_SERVER;
630
+ let rawConfig;
631
+ if (options.nextConfig) {
632
+ const diskConfigPath = findNextConfigPath(root);
633
+ if (diskConfigPath && !warnedInlineNextConfigOverride) {
634
+ warnedInlineNextConfigOverride = true;
635
+ console.warn(`[vinext] vinext({ nextConfig }) overrides ${path.basename(diskConfigPath)}. Remove one of the config sources to avoid drift.`);
636
+ }
637
+ rawConfig = await resolveNextConfigInput(options.nextConfig, phase);
638
+ } else rawConfig = await loadNextConfig(root, phase);
639
+ nextConfig = await resolveNextConfig(rawConfig, root);
640
+ }
620
641
  fileMatcher = createValidFileMatcher(nextConfig.pageExtensions);
621
642
  instrumentationPath = findInstrumentationFile(root, fileMatcher);
622
643
  instrumentationClientPath = findInstrumentationClientFile(root, fileMatcher);
@@ -719,25 +740,12 @@ function vinext(options = {}) {
719
740
  else if (p) pluginsFlat.push(p);
720
741
  }
721
742
  flattenPlugins(config.plugins ?? []);
722
- hasCloudflarePlugin = pluginsFlat.some((p) => p && typeof p === "object" && typeof p.name === "string" && (p.name === "vite-plugin-cloudflare" || p.name.startsWith("vite-plugin-cloudflare:")));
723
- hasNitroPlugin = pluginsFlat.some((p) => p && typeof p === "object" && typeof p.name === "string" && (p.name === "nitro" || p.name.startsWith("nitro:")));
743
+ hasCloudflarePlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "vite-plugin-cloudflare" || p.name.startsWith("vite-plugin-cloudflare:")));
744
+ hasNitroPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "nitro" || p.name.startsWith("nitro:")));
724
745
  let postcssOverride;
725
746
  if (!config.css?.postcss || typeof config.css.postcss === "string") postcssOverride = await resolvePostcssStringPlugins(root);
726
- if (!pluginsFlat.some((p) => p && typeof p === "object" && typeof p.name === "string" && (p.name === "@mdx-js/rollup" || p.name === "mdx")) && hasMdxFiles(root, hasAppDir ? appDir : null, hasPagesDir ? pagesDir : null)) try {
727
- const mdxRollup = await import("@mdx-js/rollup");
728
- const mdxFactory = mdxRollup.default ?? mdxRollup;
729
- const mdxOpts = {};
730
- if (nextConfig.mdx) {
731
- if (nextConfig.mdx.remarkPlugins) mdxOpts.remarkPlugins = nextConfig.mdx.remarkPlugins;
732
- if (nextConfig.mdx.rehypePlugins) mdxOpts.rehypePlugins = nextConfig.mdx.rehypePlugins;
733
- if (nextConfig.mdx.recmaPlugins) mdxOpts.recmaPlugins = nextConfig.mdx.recmaPlugins;
734
- }
735
- mdxDelegate = mdxFactory(mdxOpts);
736
- if (nextConfig.mdx) console.log("[vinext] Auto-injected @mdx-js/rollup with remark/rehype plugins from next.config");
737
- else console.log("[vinext] Auto-injected @mdx-js/rollup for MDX support");
738
- } catch {
739
- console.warn("[vinext] MDX files detected but @mdx-js/rollup is not installed. Install it with: " + detectPackageManager(process.cwd()) + " @mdx-js/rollup");
740
- }
747
+ hasUserMdxPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "@mdx-js/rollup" || p.name === "mdx"));
748
+ if (!hasUserMdxPlugin && hasMdxFiles(root, hasAppDir ? appDir : null, hasPagesDir ? pagesDir : null)) await ensureMdxDelegate("detected");
741
749
  const isSSR = !!config.build?.ssr;
742
750
  const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
743
751
  const viteConfig = {
@@ -752,7 +760,7 @@ function vinext(options = {}) {
752
760
  else defaultHandler(warning);
753
761
  };
754
762
  })(),
755
- ...!isSSR && !isMultiEnv ? { treeshake: clientTreeshakeConfig } : {},
763
+ ...!isSSR && !isMultiEnv ? { treeshake: getClientTreeshakeConfigForVite(viteMajorVersion) } : {},
756
764
  ...!isSSR && !isMultiEnv ? { output: getClientOutputConfigForVite(viteMajorVersion) } : {}
757
765
  }) },
758
766
  server: { cors: {
@@ -869,7 +877,7 @@ function vinext(options = {}) {
869
877
  ...withBuildBundlerOptions(viteMajorVersion, {
870
878
  input: { index: VIRTUAL_APP_BROWSER_ENTRY },
871
879
  output: getClientOutputConfigForVite(viteMajorVersion),
872
- treeshake: clientTreeshakeConfig
880
+ treeshake: getClientTreeshakeConfigForVite(viteMajorVersion)
873
881
  })
874
882
  }
875
883
  }
@@ -883,7 +891,7 @@ function vinext(options = {}) {
883
891
  ...withBuildBundlerOptions(viteMajorVersion, {
884
892
  input: { index: VIRTUAL_CLIENT_ENTRY },
885
893
  output: getClientOutputConfigForVite(viteMajorVersion),
886
- treeshake: clientTreeshakeConfig
894
+ treeshake: getClientTreeshakeConfigForVite(viteMajorVersion)
887
895
  })
888
896
  }
889
897
  } };
@@ -898,7 +906,7 @@ function vinext(options = {}) {
898
906
  ...withBuildBundlerOptions(viteMajorVersion, {
899
907
  input: { index: VIRTUAL_CLIENT_ENTRY },
900
908
  output: getClientOutputConfigForVite(viteMajorVersion),
901
- treeshake: clientTreeshakeConfig
909
+ treeshake: getClientTreeshakeConfigForVite(viteMajorVersion)
902
910
  })
903
911
  }
904
912
  },
@@ -929,14 +937,14 @@ function vinext(options = {}) {
929
937
  configResolved(config) {
930
938
  // @vitejs/plugin-react AND the user also registers it manually, the
931
939
  if (reactPluginPromise) {
932
- const reactRootPlugins = config.plugins.filter((p) => p && typeof p.name === "string" && p.name.startsWith("vite:react"));
940
+ const reactRootPlugins = config.plugins.filter((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && p.name.startsWith("vite:react"));
933
941
  const counts = /* @__PURE__ */ new Map();
934
942
  for (const plugin of reactRootPlugins) counts.set(plugin.name, (counts.get(plugin.name) ?? 0) + 1);
935
943
  if ([...counts.values()].some((count) => count > 1)) throw new Error("[vinext] Duplicate @vitejs/plugin-react detected.\n vinext auto-registers @vitejs/plugin-react by default.\n Your config also registers it manually, which duplicates React transforms.\n\n Fix: remove the explicit react() call from your plugins array.\n Or: pass react: false to vinext() if you want to configure react() yourself.");
936
944
  }
937
945
  // @vitejs/plugin-rsc AND the user also registers it manually, the
938
946
  if (rscPluginPromise) {
939
- if (config.plugins.filter((p) => p && p.name === "rsc").length > 1) throw new Error("[vinext] Duplicate @vitejs/plugin-rsc detected.\n vinext auto-registers @vitejs/plugin-rsc when app/ is detected.\n Your config also registers it manually, which doubles build time.\n\n Fix: remove the explicit rsc() call from your plugins array.\n Or: pass rsc: false to vinext() if you want to configure rsc() yourself.");
947
+ if (config.plugins.filter((p) => p && typeof p === "object" && "name" in p && p.name === "rsc").length > 1) throw new Error("[vinext] Duplicate @vitejs/plugin-rsc detected.\n vinext auto-registers @vitejs/plugin-rsc when app/ is detected.\n Your config also registers it manually, which doubles build time.\n\n Fix: remove the explicit rsc() call from your plugins array.\n Or: pass rsc: false to vinext() if you want to configure rsc() yourself.");
940
948
  }
941
949
  if (config.command === "build" && !hasCloudflarePlugin && !hasNitroPlugin && hasWranglerConfig(root) && !options.disableAppRouter) throw new Error(formatMissingCloudflarePluginError({
942
950
  isAppRouter: hasAppDir,
@@ -979,7 +987,8 @@ function vinext(options = {}) {
979
987
  allowedDevOrigins: nextConfig?.allowedDevOrigins,
980
988
  bodySizeLimit: nextConfig?.serverActionsBodySizeLimit,
981
989
  i18n: nextConfig?.i18n,
982
- hasPagesDir
990
+ hasPagesDir,
991
+ publicFiles: scanPublicFileRoutes(root)
983
992
  }, instrumentationPath);
984
993
  }
985
994
  if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
@@ -998,11 +1007,15 @@ function vinext(options = {}) {
998
1007
  const hook = mdxDelegate.config;
999
1008
  return (typeof hook === "function" ? hook : hook.handler).call(this, config, env);
1000
1009
  },
1001
- transform(code, id, options) {
1010
+ async transform(code, id, options) {
1002
1011
  if (id.includes("?")) return;
1003
- if (!mdxDelegate?.transform) return;
1004
- const hook = mdxDelegate.transform;
1005
- return (typeof hook === "function" ? hook : hook.handler).call(this, code, id, options);
1012
+ if (!id.toLowerCase().endsWith(".mdx")) return;
1013
+ const delegate = mdxDelegate ?? await ensureMdxDelegate("on-demand");
1014
+ if (delegate?.transform) {
1015
+ const hook = delegate.transform;
1016
+ return (typeof hook === "function" ? hook : hook.handler).call(this, code, id, options);
1017
+ }
1018
+ if (!hasUserMdxPlugin) throw new Error(`[vinext] Encountered MDX module ${id} but no MDX plugin is configured. Install @mdx-js/rollup or register an MDX plugin manually.`);
1006
1019
  }
1007
1020
  },
1008
1021
  {
@@ -1564,6 +1577,7 @@ function vinext(options = {}) {
1564
1577
  },
1565
1578
  createOgInlineFetchAssetsPlugin(),
1566
1579
  ogAssetsPlugin,
1580
+ createServerExternalsManifestPlugin(),
1567
1581
  {
1568
1582
  name: "vinext:image-config",
1569
1583
  apply: "build",
@@ -1584,6 +1598,25 @@ function vinext(options = {}) {
1584
1598
  }
1585
1599
  }
1586
1600
  },
1601
+ (() => {
1602
+ let buildIdWritten = false;
1603
+ return {
1604
+ name: "vinext:build-id",
1605
+ apply: "build",
1606
+ enforce: "post",
1607
+ closeBundle: {
1608
+ sequential: true,
1609
+ order: "post",
1610
+ handler() {
1611
+ if (buildIdWritten) return;
1612
+ buildIdWritten = true;
1613
+ const outDir = path.join(root, "dist", "server");
1614
+ fs.mkdirSync(outDir, { recursive: true });
1615
+ fs.writeFileSync(path.join(outDir, "BUILD_ID"), nextConfig.buildId);
1616
+ }
1617
+ }
1618
+ };
1619
+ })(),
1587
1620
  (() => {
1588
1621
  const prerenderSecret = randomBytes(32).toString("hex");
1589
1622
  return {
@@ -1604,6 +1637,24 @@ function vinext(options = {}) {
1604
1637
  }
1605
1638
  };
1606
1639
  })(),
1640
+ {
1641
+ name: "vinext:nitro-route-rules",
1642
+ nitro: { setup: async (nitro) => {
1643
+ if (nitro.options.dev) return;
1644
+ if (!nextConfig) return;
1645
+ if (!hasAppDir && !hasPagesDir) return;
1646
+ const { collectNitroRouteRules, mergeNitroRouteRules } = await import("./build/nitro-route-rules.js");
1647
+ const generatedRouteRules = await collectNitroRouteRules({
1648
+ appDir: hasAppDir ? appDir : null,
1649
+ pagesDir: hasPagesDir ? pagesDir : null,
1650
+ pageExtensions: nextConfig.pageExtensions
1651
+ });
1652
+ if (Object.keys(generatedRouteRules).length === 0) return;
1653
+ const { routeRules, skippedRoutes } = mergeNitroRouteRules(nitro.options.routeRules, generatedRouteRules);
1654
+ nitro.options.routeRules = routeRules;
1655
+ if (skippedRoutes.length > 0) (nitro.logger?.warn ?? console.warn)(`[vinext] Skipping generated Nitro routeRules for routes with existing exact cache config: ${skippedRoutes.join(", ")}`);
1656
+ } }
1657
+ },
1607
1658
  {
1608
1659
  name: "vinext:ssr-manifest-backfill",
1609
1660
  apply: "build",
@@ -1626,6 +1677,67 @@ function vinext(options = {}) {
1626
1677
  }
1627
1678
  }
1628
1679
  },
1680
+ (() => {
1681
+ let pendingPrecompress = null;
1682
+ let pendingPrecompressError = null;
1683
+ return {
1684
+ name: "vinext:precompress",
1685
+ apply: "build",
1686
+ enforce: "post",
1687
+ writeBundle: {
1688
+ sequential: true,
1689
+ order: "post",
1690
+ handler(outputOptions) {
1691
+ if (this.environment?.name !== "client") return;
1692
+ if (!options.precompress && process.env.VINEXT_PRECOMPRESS !== "1") return;
1693
+ const outDir = outputOptions.dir;
1694
+ if (!outDir) return;
1695
+ const assetsDir = path.join(outDir, "assets");
1696
+ if (!fs.existsSync(assetsDir)) return;
1697
+ const isTTY = process.stderr.isTTY;
1698
+ let lastLineLen = 0;
1699
+ pendingPrecompressError = null;
1700
+ pendingPrecompress = (async () => {
1701
+ const result = await precompressAssets(outDir, (completed, total, file) => {
1702
+ if (!isTTY) return;
1703
+ const pct = total > 0 ? Math.floor(completed / total * 100) : 0;
1704
+ const bar = `[${"█".repeat(Math.floor(pct / 5))}${" ".repeat(20 - Math.floor(pct / 5))}]`;
1705
+ const maxFile = 30;
1706
+ const fileLabel = file.length > maxFile ? "…" + file.slice(-(maxFile - 1)) : file;
1707
+ const line = `Compressing assets... ${bar} ${String(completed).padStart(String(total).length)}/${total} ${fileLabel}`;
1708
+ const padded = line.padEnd(lastLineLen);
1709
+ lastLineLen = line.length;
1710
+ process.stderr.write(`\r${padded}`);
1711
+ });
1712
+ if (isTTY) process.stderr.write(`\r${" ".repeat(lastLineLen)}\r`);
1713
+ if (result.filesCompressed > 0) {
1714
+ const ratio = ((1 - result.totalBrotliBytes / result.totalOriginalBytes) * 100).toFixed(1);
1715
+ console.log(` Precompressed ${result.filesCompressed} assets (${ratio}% smaller with brotli)`);
1716
+ }
1717
+ })().catch((error) => {
1718
+ pendingPrecompressError = error;
1719
+ console.error("[vinext] Precompression failed:", error);
1720
+ });
1721
+ }
1722
+ },
1723
+ closeBundle: {
1724
+ sequential: true,
1725
+ order: "post",
1726
+ async handler() {
1727
+ if (this.environment?.name !== "ssr") return;
1728
+ if (!pendingPrecompress) return;
1729
+ const task = pendingPrecompress;
1730
+ pendingPrecompress = null;
1731
+ await task;
1732
+ if (pendingPrecompressError) {
1733
+ const error = pendingPrecompressError;
1734
+ pendingPrecompressError = null;
1735
+ throw error;
1736
+ }
1737
+ }
1738
+ }
1739
+ };
1740
+ })(),
1629
1741
  {
1630
1742
  name: "vinext:cloudflare-build",
1631
1743
  apply: "build",
@@ -1805,7 +1917,7 @@ function stripServerExports(code) {
1805
1917
  if (node.type !== "ExportNamedDeclaration") continue;
1806
1918
  if (node.declaration) {
1807
1919
  const decl = node.declaration;
1808
- if (decl.type === "FunctionDeclaration" && SERVER_EXPORTS.has(decl.id?.name)) {
1920
+ if (decl.type === "FunctionDeclaration" && decl.id && SERVER_EXPORTS.has(decl.id.name)) {
1809
1921
  s.overwrite(node.start, node.end, `export function ${decl.id.name}() { return { props: {} }; }`);
1810
1922
  changed = true;
1811
1923
  } else if (decl.type === "VariableDeclaration") {
@@ -1956,12 +2068,55 @@ function scanDirForMdx(dir) {
1956
2068
  const full = path.join(dir, entry.name);
1957
2069
  if (entry.isDirectory()) {
1958
2070
  if (scanDirForMdx(full)) return true;
1959
- } else if (entry.isFile() && entry.name.endsWith(".mdx")) return true;
2071
+ } else if (entry.isFile() && entry.name.toLowerCase().endsWith(".mdx")) return true;
1960
2072
  }
1961
2073
  } catch {}
1962
2074
  return false;
1963
2075
  }
2076
+ function scanPublicFileRoutes(root) {
2077
+ const publicDir = path.join(root, "public");
2078
+ const routes = [];
2079
+ const visitedDirs = /* @__PURE__ */ new Set();
2080
+ function walk(dir) {
2081
+ let realDir;
2082
+ try {
2083
+ realDir = fs.realpathSync(dir);
2084
+ } catch {
2085
+ return;
2086
+ }
2087
+ if (visitedDirs.has(realDir)) return;
2088
+ visitedDirs.add(realDir);
2089
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
2090
+ for (const entry of entries) {
2091
+ const fullPath = path.join(dir, entry.name);
2092
+ if (entry.isDirectory()) {
2093
+ walk(fullPath);
2094
+ continue;
2095
+ }
2096
+ if (entry.isSymbolicLink()) {
2097
+ let stat;
2098
+ try {
2099
+ stat = fs.statSync(fullPath);
2100
+ } catch {
2101
+ continue;
2102
+ }
2103
+ if (stat.isDirectory()) {
2104
+ walk(fullPath);
2105
+ continue;
2106
+ }
2107
+ if (!stat.isFile()) continue;
2108
+ } else if (!entry.isFile()) continue;
2109
+ const relativePath = path.relative(publicDir, fullPath).split(path.sep).join("/");
2110
+ routes.push("/" + relativePath);
2111
+ }
2112
+ }
2113
+ if (fs.existsSync(publicDir)) try {
2114
+ walk(publicDir);
2115
+ } catch {}
2116
+ routes.sort();
2117
+ return routes;
2118
+ }
1964
2119
  //#endregion
1965
- export { asyncHooksStubPlugin as _asyncHooksStubPlugin, augmentSsrManifestFromBundle as _augmentSsrManifestFromBundle, hasMdxFiles as _hasMdxFiles, _mdxScanCache, parseStaticObjectLiteral as _parseStaticObjectLiteral, _postcssCache, resolvePostcssStringPlugins as _resolvePostcssStringPlugins, stripServerExports as _stripServerExports, clientManualChunks, clientOutputConfig, clientTreeshakeConfig, computeLazyChunks, vinext as default, getClientOutputConfigForVite, matchConfigPattern, staticExportApp, staticExportPages };
2120
+ export { asyncHooksStubPlugin as _asyncHooksStubPlugin, augmentSsrManifestFromBundle as _augmentSsrManifestFromBundle, _findBalancedObject, _findCallEnd, hasMdxFiles as _hasMdxFiles, _mdxScanCache, parseStaticObjectLiteral as _parseStaticObjectLiteral, _postcssCache, resolvePostcssStringPlugins as _resolvePostcssStringPlugins, scanPublicFileRoutes as _scanPublicFileRoutes, stripServerExports as _stripServerExports, clientManualChunks, clientOutputConfig, clientTreeshakeConfig, computeLazyChunks, vinext as default, getClientOutputConfigForVite, getClientTreeshakeConfigForVite, matchConfigPattern, staticExportApp, staticExportPages };
1966
2121
 
1967
2122
  //# sourceMappingURL=index.js.map