vinext 0.2.1 → 1.0.0-beta.1

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 (236) hide show
  1. package/README.md +67 -30
  2. package/dist/build/assets-ignore.js +1 -1
  3. package/dist/build/clean-output.js +1 -1
  4. package/dist/build/client-build-config.d.ts +13 -92
  5. package/dist/build/client-build-config.js +23 -99
  6. package/dist/build/css-url-assets.js +3 -3
  7. package/dist/build/google-fonts/fallback-metrics.js +1 -1
  8. package/dist/build/google-fonts/font-metadata.js +1 -1
  9. package/dist/build/inject-pregenerated-paths.js +1 -1
  10. package/dist/build/inline-css.js +2 -5
  11. package/dist/build/module-dependency-cache.d.ts +4 -0
  12. package/dist/build/module-dependency-cache.js +13 -0
  13. package/dist/build/next-client-runtime-manifests.js +1 -1
  14. package/dist/build/pages-client-assets-module.js +1 -1
  15. package/dist/build/precompress.js +7 -7
  16. package/dist/build/prerender-paths.d.ts +23 -0
  17. package/dist/build/prerender-paths.js +291 -0
  18. package/dist/build/prerender-server-pool.js +2 -2
  19. package/dist/build/prerender.d.ts +12 -1
  20. package/dist/build/prerender.js +2 -2
  21. package/dist/build/preview-credentials.d.ts +11 -0
  22. package/dist/build/preview-credentials.js +19 -0
  23. package/dist/build/report.d.ts +0 -3
  24. package/dist/build/report.js +2 -4
  25. package/dist/build/run-prerender.d.ts +2 -11
  26. package/dist/build/run-prerender.js +2 -10
  27. package/dist/build/server-manifest.js +1 -1
  28. package/dist/build/ssr-manifest.d.ts +4 -0
  29. package/dist/build/ssr-manifest.js +10 -6
  30. package/dist/build/standalone.js +37 -37
  31. package/dist/cache/cache-adapters-virtual.d.ts +7 -17
  32. package/dist/cache/cache-adapters-virtual.js +35 -2
  33. package/dist/check.d.ts +0 -16
  34. package/dist/check.js +17 -34
  35. package/dist/cli.js +86 -101
  36. package/dist/client/instrumentation-client-inject.js +1 -1
  37. package/dist/client/pages-router-link-navigation.js +1 -1
  38. package/dist/config/config-matchers.js +2 -2
  39. package/dist/config/dotenv.js +1 -1
  40. package/dist/config/next-config.d.ts +4 -1
  41. package/dist/config/next-config.js +82 -16
  42. package/dist/config/prerender.d.ts +12 -2
  43. package/dist/config/prerender.js +22 -12
  44. package/dist/config/server-external-packages.js +1 -1
  45. package/dist/config/tsconfig-paths.js +7 -3
  46. package/dist/{node_modules/.pnpm/am-i-vibing@0.5.0/node_modules → deps/.pnpm/am-i-vibing@0.5.0/deps}/am-i-vibing/dist/detector-1yx2Hoe0.js +2 -2
  47. package/dist/deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js +50 -0
  48. package/dist/entries/app-rsc-entry.js +12 -5
  49. package/dist/entries/app-rsc-manifest.js +4 -4
  50. package/dist/entries/pages-client-entry.js +6 -5
  51. package/dist/entries/pages-server-entry.js +15 -26
  52. package/dist/entries/runtime-entry-module.js +2 -2
  53. package/dist/image/image-adapters-virtual.js +1 -0
  54. package/dist/index.d.ts +1 -1
  55. package/dist/index.js +500 -338
  56. package/dist/init-cloudflare.js +13 -4
  57. package/dist/init-platform.d.ts +10 -1
  58. package/dist/init-platform.js +79 -13
  59. package/dist/init.d.ts +11 -3
  60. package/dist/init.js +133 -35
  61. package/dist/plugins/ast-utils.js +1 -1
  62. package/dist/plugins/dynamic-preload-metadata.js +7 -7
  63. package/dist/plugins/extensionless-dynamic-import.js +1 -1
  64. package/dist/plugins/fonts.js +3 -3
  65. package/dist/plugins/ignore-dynamic-requests.js +13 -8
  66. package/dist/plugins/import-meta-url.js +16 -17
  67. package/dist/plugins/middleware-export-validation.js +1 -1
  68. package/dist/plugins/middleware-server-only.js +2 -2
  69. package/dist/plugins/og-asset-ownership.js +7 -6
  70. package/dist/plugins/og-assets.js +4 -5
  71. package/dist/plugins/optimize-imports.js +12 -13
  72. package/dist/plugins/postcss.js +1 -1
  73. package/dist/plugins/remove-console.js +1 -1
  74. package/dist/plugins/require-context.js +1 -1
  75. package/dist/plugins/sass.js +2 -2
  76. package/dist/plugins/server-externals-manifest.js +1 -1
  77. package/dist/plugins/strip-server-exports.js +1 -1
  78. package/dist/plugins/styled-jsx.js +3 -2
  79. package/dist/plugins/typeof-window.js +1 -1
  80. package/dist/routing/app-route-graph.d.ts +3 -10
  81. package/dist/routing/app-route-graph.js +28 -76
  82. package/dist/routing/app-router.d.ts +0 -5
  83. package/dist/routing/app-router.js +0 -5
  84. package/dist/routing/file-matcher.d.ts +2 -6
  85. package/dist/routing/file-matcher.js +10 -11
  86. package/dist/routing/pages-router.js +3 -3
  87. package/dist/server/api-handler.js +41 -33
  88. package/dist/server/app-browser-entry.js +15 -11
  89. package/dist/server/app-browser-navigation-controller.js +9 -4
  90. package/dist/server/app-browser-server-action-client.js +1 -1
  91. package/dist/server/app-elements-wire.d.ts +2 -1
  92. package/dist/server/app-fallback-renderer.d.ts +8 -0
  93. package/dist/server/app-fallback-renderer.js +13 -1
  94. package/dist/server/app-layout-param-observation.d.ts +1 -1
  95. package/dist/server/app-page-boundary-render.d.ts +14 -1
  96. package/dist/server/app-page-boundary-render.js +107 -54
  97. package/dist/server/app-page-cache-render.d.ts +1 -1
  98. package/dist/server/app-page-dispatch.d.ts +2 -1
  99. package/dist/server/app-page-dispatch.js +29 -40
  100. package/dist/server/app-page-element-builder.d.ts +2 -1
  101. package/dist/server/app-page-element-builder.js +3 -3
  102. package/dist/server/app-page-execution.d.ts +3 -1
  103. package/dist/server/app-page-execution.js +31 -39
  104. package/dist/server/app-page-render.d.ts +1 -1
  105. package/dist/server/app-page-request.js +1 -1
  106. package/dist/server/app-page-route-wiring.js +4 -4
  107. package/dist/server/app-route-handler-execution.d.ts +1 -1
  108. package/dist/server/app-route-tree-prefetch.js +1 -1
  109. package/dist/server/app-rsc-cache-busting.js +1 -2
  110. package/dist/server/app-rsc-handler.js +2 -2
  111. package/dist/server/app-rsc-redirect-flight.d.ts +66 -0
  112. package/dist/server/app-rsc-redirect-flight.js +71 -0
  113. package/dist/server/app-rsc-render-mode.d.ts +2 -5
  114. package/dist/server/app-rsc-render-mode.js +2 -12
  115. package/dist/server/app-segment-config.js +2 -2
  116. package/dist/server/app-server-action-execution.js +3 -3
  117. package/dist/server/app-ssr-entry.js +4 -1
  118. package/dist/server/app-ssr-stream.d.ts +2 -1
  119. package/dist/server/app-ssr-stream.js +4 -1
  120. package/dist/server/cache-proof.js +1 -1
  121. package/dist/server/default-global-error-module.d.ts +3 -1
  122. package/dist/server/default-not-found-module.d.ts +3 -1
  123. package/dist/server/dev-lockfile.js +2 -3
  124. package/dist/server/dev-module-runner.js +1 -1
  125. package/dist/server/dev-origin-check.d.ts +2 -2
  126. package/dist/server/dev-origin-check.js +2 -2
  127. package/dist/server/dev-route-files.js +1 -1
  128. package/dist/server/dev-server.js +256 -164
  129. package/dist/server/dev-stack-sourcemap.js +4 -3
  130. package/dist/server/headers.d.ts +3 -1
  131. package/dist/server/headers.js +3 -1
  132. package/dist/server/image-optimization.d.ts +12 -1
  133. package/dist/server/image-optimization.js +15 -3
  134. package/dist/server/implicit-tags.js +2 -1
  135. package/dist/server/instrumentation.js +2 -2
  136. package/dist/server/isr-cache.d.ts +12 -4
  137. package/dist/server/isr-cache.js +3 -3
  138. package/dist/server/metadata-routes.js +4 -4
  139. package/dist/server/middleware-response-headers.js +1 -1
  140. package/dist/server/middleware-runtime.js +1 -1
  141. package/dist/server/middleware.d.ts +1 -0
  142. package/dist/server/middleware.js +1 -1
  143. package/dist/server/navigation-planner.d.ts +2 -0
  144. package/dist/server/navigation-planner.js +8 -2
  145. package/dist/server/next-error-digest.d.ts +9 -24
  146. package/dist/server/next-error-digest.js +23 -15
  147. package/dist/server/operation-token.js +1 -1
  148. package/dist/server/pages-body-parser-config.js +2 -1
  149. package/dist/server/pages-dev-hydration.d.ts +14 -0
  150. package/dist/server/pages-dev-hydration.js +83 -0
  151. package/dist/server/pages-dev-module-url.js +2 -2
  152. package/dist/server/pages-node-compat.d.ts +13 -6
  153. package/dist/server/pages-node-compat.js +44 -45
  154. package/dist/server/pages-page-data.d.ts +1 -1
  155. package/dist/server/pages-page-data.js +5 -4
  156. package/dist/server/pages-page-handler.js +61 -29
  157. package/dist/server/pages-page-response.d.ts +2 -2
  158. package/dist/server/pages-page-response.js +2 -2
  159. package/dist/server/pages-preview.d.ts +26 -0
  160. package/dist/server/pages-preview.js +165 -0
  161. package/dist/server/pages-readiness.d.ts +2 -1
  162. package/dist/server/pages-readiness.js +4 -2
  163. package/dist/server/pages-request-pipeline.js +1 -1
  164. package/dist/server/prerender-manifest.d.ts +15 -1
  165. package/dist/server/prerender-manifest.js +29 -1
  166. package/dist/server/prod-server.d.ts +6 -5
  167. package/dist/server/prod-server.js +15 -15
  168. package/dist/server/request-pipeline.js +1 -1
  169. package/dist/server/seed-cache.js +1 -1
  170. package/dist/server/socket-error-backstop.js +1 -1
  171. package/dist/server/static-file-cache.js +8 -9
  172. package/dist/server/worker-utils.js +1 -1
  173. package/dist/shims/cache.d.ts +1 -1
  174. package/dist/shims/cache.js +2 -1
  175. package/dist/shims/cdn-cache.d.ts +2 -7
  176. package/dist/shims/cdn-cache.js +2 -14
  177. package/dist/shims/constants.js +1 -1
  178. package/dist/shims/error-boundary.d.ts +4 -4
  179. package/dist/shims/error.d.ts +21 -5
  180. package/dist/shims/error.js +52 -14
  181. package/dist/shims/fetch-cache.js +1 -1
  182. package/dist/shims/font-utils.js +1 -1
  183. package/dist/shims/form.d.ts +1 -1
  184. package/dist/shims/head.js +3 -3
  185. package/dist/shims/headers.js +6 -4
  186. package/dist/shims/internal/pages-data-fetch-dedup.js +5 -3
  187. package/dist/shims/layout-segment-context.d.ts +1 -1
  188. package/dist/shims/link.d.ts +3 -1
  189. package/dist/shims/link.js +6 -3
  190. package/dist/shims/navigation-errors.d.ts +2 -1
  191. package/dist/shims/navigation-errors.js +9 -13
  192. package/dist/shims/navigation.d.ts +1 -1
  193. package/dist/shims/navigation.js +5 -5
  194. package/dist/shims/request-state-types.d.ts +2 -2
  195. package/dist/shims/router-state.d.ts +1 -0
  196. package/dist/shims/router.d.ts +2 -1
  197. package/dist/shims/router.js +18 -11
  198. package/dist/shims/script.js +1 -1
  199. package/dist/shims/server.js +2 -2
  200. package/dist/shims/slot.d.ts +1 -1
  201. package/dist/shims/thenable-params.js +1 -1
  202. package/dist/shims/unified-request-context.d.ts +1 -1
  203. package/dist/typegen.js +9 -11
  204. package/dist/utils/client-build-manifest.js +2 -2
  205. package/dist/utils/client-entry-manifest.js +1 -1
  206. package/dist/utils/client-runtime-metadata.js +1 -1
  207. package/dist/utils/commonjs-loader.js +3 -3
  208. package/dist/utils/mdx-scan.js +1 -1
  209. package/dist/utils/path.d.ts +1 -13
  210. package/dist/utils/path.js +1 -15
  211. package/dist/utils/plugin-options.d.ts +4 -0
  212. package/dist/utils/plugin-options.js +8 -0
  213. package/dist/utils/project.d.ts +1 -7
  214. package/dist/utils/project.js +2 -8
  215. package/dist/utils/public-routes.js +2 -2
  216. package/dist/utils/react-version.js +1 -1
  217. package/dist/utils/redirect-digest.d.ts +9 -0
  218. package/dist/utils/redirect-digest.js +25 -0
  219. package/dist/utils/vinext-root.js +1 -1
  220. package/dist/utils/vite-version.d.ts +6 -13
  221. package/dist/utils/vite-version.js +68 -34
  222. package/package.json +33 -14
  223. package/dist/cloudflare/index.d.ts +0 -3
  224. package/dist/cloudflare/index.js +0 -3
  225. package/dist/packages/cloudflare/src/cache/cdn-adapter.runtime.js +0 -102
  226. package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +0 -126
  227. package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.js +0 -442
  228. package/dist/packages/cloudflare/src/deploy-config.js +0 -150
  229. package/dist/packages/cloudflare/src/deploy-help.js +0 -55
  230. package/dist/packages/cloudflare/src/deploy.js +0 -272
  231. package/dist/packages/cloudflare/src/tpr.d.ts +0 -45
  232. package/dist/packages/cloudflare/src/tpr.js +0 -582
  233. package/dist/packages/cloudflare/src/utils/cache-control-metadata.js +0 -20
  234. /package/dist/build/google-fonts/{fallback-metrics-data.js → fallback-metrics-data.json.js} +0 -0
  235. /package/dist/build/google-fonts/{font-data.js → font-data.json.js} +0 -0
  236. /package/dist/{node_modules/.pnpm/process-ancestry@0.1.0/node_modules → deps/.pnpm/process-ancestry@0.1.0/deps}/process-ancestry/dist/index.js +0 -0
@@ -0,0 +1,8 @@
1
+ //#region src/utils/plugin-options.ts
2
+ async function flattenPluginOptions(value) {
3
+ if (value instanceof Promise) return flattenPluginOptions(await value);
4
+ if (Array.isArray(value)) return (await Promise.all(value.map((item) => flattenPluginOptions(item)))).flat();
5
+ return value ? [value] : [];
6
+ }
7
+ //#endregion
8
+ export { flattenPluginOptions };
@@ -110,17 +110,11 @@ _isResolvable?: (root: string, pkg: string) => boolean): MissingDep[];
110
110
  * Return the first candidate directory (resolved against `root`) that exists,
111
111
  * or null. Used to locate conventional `app`/`pages` directories that may live
112
112
  * at the root or under `src/`.
113
- *
114
- * `root` and `candidates` must be forward-slash, and the returned path is
115
- * forward-slash too: the candidate is joined with `path.posix.join`, which only
116
- * stays canonical when its inputs already are.
117
113
  */
118
114
  declare function findDir(root: string, ...candidates: string[]): string | null;
119
115
  /**
120
116
  * Check if the project uses App Router (has an app/ directory).
121
- *
122
- * `root` must be forward-slash — it is passed straight to `findDir`.
123
117
  */
124
118
  declare function hasAppDir(root: string): boolean;
125
119
  //#endregion
126
- export { ProjectInfo, detectPackageManager, detectPackageManagerName, detectProject, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, findViteConfigPath, formatMissingCloudflarePluginError, getMissingDeps, hasAppDir, hasViteConfig, hasWranglerConfig, isPackageResolvable, renameCJSConfigs };
120
+ export { PackageManagerName, ProjectInfo, detectPackageManager, detectPackageManagerName, detectProject, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, findViteConfigPath, formatMissingCloudflarePluginError, getMissingDeps, hasAppDir, hasViteConfig, hasWranglerConfig, isPackageResolvable, renameCJSConfigs };
@@ -1,6 +1,6 @@
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
1
2
  import { createRequire } from "node:module";
2
3
  import fs from "node:fs";
3
- import path from "node:path";
4
4
  //#region src/utils/project.ts
5
5
  /**
6
6
  * Shared project utilities used by `vinext init`, the vinext plugin, and
@@ -412,14 +412,10 @@ function getMissingDeps(info, _isResolvable = isPackageResolvable) {
412
412
  * Return the first candidate directory (resolved against `root`) that exists,
413
413
  * or null. Used to locate conventional `app`/`pages` directories that may live
414
414
  * at the root or under `src/`.
415
- *
416
- * `root` and `candidates` must be forward-slash, and the returned path is
417
- * forward-slash too: the candidate is joined with `path.posix.join`, which only
418
- * stays canonical when its inputs already are.
419
415
  */
420
416
  function findDir(root, ...candidates) {
421
417
  for (const candidate of candidates) {
422
- const full = path.posix.join(root, candidate);
418
+ const full = path.join(root, candidate);
423
419
  try {
424
420
  if (fs.statSync(full).isDirectory()) return full;
425
421
  } catch {}
@@ -428,8 +424,6 @@ function findDir(root, ...candidates) {
428
424
  }
429
425
  /**
430
426
  * Check if the project uses App Router (has an app/ directory).
431
- *
432
- * `root` must be forward-slash — it is passed straight to `findDir`.
433
427
  */
434
428
  function hasAppDir(root) {
435
429
  return findDir(root, "app", "src/app") !== null;
@@ -1,5 +1,5 @@
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
1
2
  import fs from "node:fs";
2
- import path from "node:path";
3
3
  //#region src/utils/public-routes.ts
4
4
  function scanPublicFileRoutes(root) {
5
5
  const publicDir = path.join(root, "public");
@@ -34,7 +34,7 @@ function scanPublicFileRoutes(root) {
34
34
  }
35
35
  if (!stat.isFile()) continue;
36
36
  } else if (!entry.isFile()) continue;
37
- const relativePath = path.relative(publicDir, fullPath).split(path.sep).join("/");
37
+ const relativePath = path.relative(publicDir, fullPath);
38
38
  routes.push("/" + relativePath);
39
39
  }
40
40
  }
@@ -1,6 +1,6 @@
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
1
2
  import { createRequire } from "node:module";
2
3
  import fs from "node:fs";
3
- import path from "node:path";
4
4
  //#region src/utils/react-version.ts
5
5
  function getDependencyUpgradeDeps(root, recommendations) {
6
6
  const req = createRequire(path.join(root, "package.json"));
@@ -0,0 +1,9 @@
1
+ //#region src/utils/redirect-digest.d.ts
2
+ type RedirectDigest = {
3
+ status: number;
4
+ type: string | null;
5
+ url: string;
6
+ };
7
+ declare function parseRedirectDigest(digest: string): RedirectDigest | null;
8
+ //#endregion
9
+ export { RedirectDigest, parseRedirectDigest };
@@ -0,0 +1,25 @@
1
+ //#region src/utils/redirect-digest.ts
2
+ const NEXT_REDIRECT_PREFIX = "NEXT_REDIRECT;";
3
+ function parseRedirectDigest(digest) {
4
+ if (!digest.startsWith(NEXT_REDIRECT_PREFIX)) return null;
5
+ const firstSemi = digest.indexOf(";", 14);
6
+ if (firstSemi === -1) return null;
7
+ const rest = digest.slice(firstSemi + 1);
8
+ const statusMatch = rest.match(/;(303|307|308);?$/);
9
+ const isCanonical = rest !== "" && digest.endsWith(";");
10
+ if (isCanonical && !statusMatch) return null;
11
+ const target = statusMatch ? rest.slice(0, -statusMatch[0].length) : rest;
12
+ let url = target;
13
+ if (!isCanonical) try {
14
+ url = decodeURIComponent(target);
15
+ } catch {
16
+ return null;
17
+ }
18
+ return {
19
+ status: statusMatch ? Number(statusMatch[1]) : 307,
20
+ type: digest.slice(14, firstSemi) || null,
21
+ url
22
+ };
23
+ }
24
+ //#endregion
25
+ export { parseRedirectDigest };
@@ -1,4 +1,4 @@
1
- import path from "node:path";
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
2
  import { fileURLToPath } from "node:url";
3
3
  //#region src/utils/vinext-root.ts
4
4
  /**
@@ -1,23 +1,16 @@
1
1
  //#region src/utils/vite-version.d.ts
2
2
  declare function serializeViteDefine(value: unknown): string;
3
- declare function getDepOptimizeNodeEnvOptions(viteMajorVersion: number, nodeEnvDefine: string): {
3
+ declare function getDepOptimizeNodeEnvOptions(nodeEnvDefine: string): {
4
4
  rolldownOptions?: {
5
5
  transform: {
6
6
  define: Record<string, string>;
7
7
  };
8
8
  moduleTypes?: Record<string, "jsx">;
9
9
  };
10
- esbuildOptions?: {
11
- define: Record<string, string>;
12
- loader?: Record<string, "jsx">;
13
- };
14
10
  };
15
- /**
16
- * Detect Vite major version at runtime by resolving from cwd.
17
- * The plugin may be installed in a workspace root with Vite 7 but used
18
- * by a project that has Vite 8 — so we resolve from cwd, not from
19
- * the plugin's own location.
20
- */
21
- declare function getViteMajorVersion(): number;
11
+ declare function supportsNativeTypeofWindowFolding(viteVersion: string, bundledRolldownVersion?: string): boolean;
12
+ declare function assertSupportedViteVersion(): {
13
+ supportsNativeTypeofWindowFolding: boolean;
14
+ };
22
15
  //#endregion
23
- export { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine };
16
+ export { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine, supportsNativeTypeofWindowFolding };
@@ -1,52 +1,86 @@
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
1
2
  import { createRequire } from "node:module";
2
- import path from "node:path";
3
3
  //#region src/utils/vite-version.ts
4
4
  /**
5
5
  * Vite major-version detection.
6
6
  *
7
- * Several vinext behaviors depend on whether the host project is running Vite 8
8
- * (Rolldown-based, with native `resolve.tsconfigPaths`, `oxc` transforms, and
9
- * `rolldownOptions`) or Vite 7 (Rollup/esbuild). This helper centralizes the
10
- * detection so the Vite-major gate is computed the same way everywhere.
7
+ * vinext requires Vite 8 or newer so it can rely on Rolldown-based build
8
+ * options, native `resolve.tsconfigPaths`, and OXC transforms.
11
9
  */
12
10
  function serializeViteDefine(value) {
13
11
  if (typeof value === "string") return value;
14
12
  return JSON.stringify(value) ?? "undefined";
15
13
  }
16
- function getDepOptimizeNodeEnvOptions(viteMajorVersion, nodeEnvDefine) {
17
- const define = { "process.env.NODE_ENV": nodeEnvDefine };
18
- const jsxModuleTypes = {
19
- ".js": "jsx",
20
- ".mjs": "jsx"
21
- };
22
- return viteMajorVersion >= 8 ? { rolldownOptions: {
23
- transform: { define },
24
- moduleTypes: jsxModuleTypes
25
- } } : { esbuildOptions: {
26
- define,
27
- loader: jsxModuleTypes
14
+ function getDepOptimizeNodeEnvOptions(nodeEnvDefine) {
15
+ return { rolldownOptions: {
16
+ transform: { define: { "process.env.NODE_ENV": nodeEnvDefine } },
17
+ moduleTypes: {
18
+ ".js": "jsx",
19
+ ".mjs": "jsx"
20
+ }
28
21
  } };
29
22
  }
30
- /**
31
- * Detect Vite major version at runtime by resolving from cwd.
32
- * The plugin may be installed in a workspace root with Vite 7 but used
33
- * by a project that has Vite 8 — so we resolve from cwd, not from
34
- * the plugin's own location.
35
- */
36
- function getViteMajorVersion() {
23
+ function getViteToolchainVersion() {
24
+ try {
25
+ return getViteToolchainVersionFromRequire(createRequire(path.join(process.cwd(), "package.json")));
26
+ } catch (error) {
27
+ if (!isModuleNotFoundError(error)) {
28
+ const message = error instanceof Error ? error.message : String(error);
29
+ throw new Error(`[vinext] Vite 8 or newer is required, but ${message}`);
30
+ }
31
+ }
37
32
  try {
38
- const vitePkg = createRequire(path.join(process.cwd(), "package.json"))("vite/package.json");
39
- const viteMajor = parseInt(vitePkg?.version, 10);
40
- if (vitePkg?.name === "vite" && Number.isFinite(viteMajor)) return viteMajor;
41
- const bundledViteMajor = parseInt(vitePkg?.bundledVersions?.vite, 10);
42
- if (Number.isFinite(bundledViteMajor)) return bundledViteMajor;
43
- console.warn(`[vinext] Could not determine Vite major version from ${vitePkg?.name ?? "vite/package.json"}; assuming Vite 7`);
44
- return 7;
33
+ return getViteToolchainVersionFromRequire(createRequire(import.meta.url));
45
34
  } catch (error) {
46
35
  const message = error instanceof Error ? error.message : String(error);
47
- console.warn(`[vinext] Failed to resolve vite/package.json (${message}); assuming Vite 7`);
48
- return 7;
36
+ throw new Error(`[vinext] Vite 8 or newer is required, but vinext could not resolve vite/package.json (${message})`);
37
+ }
38
+ }
39
+ function getViteToolchainVersionFromRequire(require) {
40
+ const vitePkg = require("vite/package.json");
41
+ if (vitePkg?.name === "vite" && parseViteVersion(vitePkg.version)) return { vite: vitePkg.version };
42
+ const bundledViteVersion = vitePkg?.bundledVersions?.vite;
43
+ if (parseViteVersion(bundledViteVersion)) {
44
+ const bundledRolldownVersion = vitePkg?.bundledVersions?.rolldown;
45
+ return {
46
+ vite: bundledViteVersion,
47
+ rolldown: parseViteVersion(bundledRolldownVersion) ? bundledRolldownVersion : void 0
48
+ };
49
49
  }
50
+ throw new Error(`could not determine Vite version from ${vitePkg?.name ?? "vite/package.json"}`);
51
+ }
52
+ function parseViteVersion(version) {
53
+ if (typeof version !== "string") return null;
54
+ const match = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.exec(version);
55
+ if (!match) return null;
56
+ return [
57
+ Number(match[1]),
58
+ Number(match[2]),
59
+ Number(match[3]),
60
+ !!match[4]
61
+ ];
62
+ }
63
+ function isModuleNotFoundError(error) {
64
+ return !!error && typeof error === "object" && "code" in error && error.code === "MODULE_NOT_FOUND";
65
+ }
66
+ function supportsNativeTypeofWindowFolding(viteVersion, bundledRolldownVersion) {
67
+ if (bundledRolldownVersion !== void 0) return isVersionAtLeast(bundledRolldownVersion, 1, 1, 4);
68
+ return isVersionAtLeast(viteVersion, 8, 1, 4);
69
+ }
70
+ function isVersionAtLeast(version, requiredMajor, requiredMinor, requiredPatch) {
71
+ const parsedVersion = parseViteVersion(version);
72
+ if (!parsedVersion) return false;
73
+ const [major, minor, patch, prerelease] = parsedVersion;
74
+ if (major !== requiredMajor) return major > requiredMajor;
75
+ if (minor !== requiredMinor) return minor > requiredMinor;
76
+ if (patch !== requiredPatch) return patch > requiredPatch;
77
+ return !prerelease;
78
+ }
79
+ function assertSupportedViteVersion() {
80
+ const toolchainVersion = getViteToolchainVersion();
81
+ const [major] = parseViteVersion(toolchainVersion.vite);
82
+ if (major < 8) throw new Error(`[vinext] Vite 8 or newer is required. Detected Vite ${major}.`);
83
+ return { supportsNativeTypeofWindowFolding: supportsNativeTypeofWindowFolding(toolchainVersion.vite, toolchainVersion.rolldown) };
50
84
  }
51
85
  //#endregion
52
- export { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine };
86
+ export { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine, supportsNativeTypeofWindowFolding };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vinext",
3
- "version": "0.2.1",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Run Next.js apps on Vite. Drop-in replacement for the next CLI.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -37,10 +37,6 @@
37
37
  "types": "./dist/server/pages-i18n.d.ts",
38
38
  "import": "./dist/server/pages-i18n.js"
39
39
  },
40
- "./cloudflare": {
41
- "types": "./dist/cloudflare/index.d.ts",
42
- "import": "./dist/cloudflare/index.js"
43
- },
44
40
  "./server/image-optimization": {
45
41
  "types": "./dist/server/image-optimization.d.ts",
46
42
  "import": "./dist/server/image-optimization.js"
@@ -81,10 +77,34 @@
81
77
  "types": "./dist/server/app-page-cache.d.ts",
82
78
  "import": "./dist/server/app-page-cache.js"
83
79
  },
80
+ "./internal/server/prerender-manifest": {
81
+ "types": "./dist/server/prerender-manifest.d.ts",
82
+ "import": "./dist/server/prerender-manifest.js"
83
+ },
84
+ "./internal/server/pregenerated-concrete-paths": {
85
+ "types": "./dist/server/pregenerated-concrete-paths.d.ts",
86
+ "import": "./dist/server/pregenerated-concrete-paths.js"
87
+ },
84
88
  "./internal/build/run-prerender": {
85
89
  "types": "./dist/build/run-prerender.d.ts",
86
90
  "import": "./dist/build/run-prerender.js"
87
91
  },
92
+ "./internal/build/prerender-paths": {
93
+ "types": "./dist/build/prerender-paths.d.ts",
94
+ "import": "./dist/build/prerender-paths.js"
95
+ },
96
+ "./internal/cache-adapters": {
97
+ "types": "./dist/cache/cache-adapters-virtual.d.ts",
98
+ "import": "./dist/cache/cache-adapters-virtual.js"
99
+ },
100
+ "./internal/init": {
101
+ "types": "./dist/init.d.ts",
102
+ "import": "./dist/init.js"
103
+ },
104
+ "./internal/init-platform": {
105
+ "types": "./dist/init-platform.d.ts",
106
+ "import": "./dist/init-platform.js"
107
+ },
88
108
  "./internal/config/dotenv": {
89
109
  "types": "./dist/config/dotenv.d.ts",
90
110
  "import": "./dist/config/dotenv.js"
@@ -128,6 +148,10 @@
128
148
  "./internal/utils/project": {
129
149
  "types": "./dist/utils/project.d.ts",
130
150
  "import": "./dist/utils/project.js"
151
+ },
152
+ "./internal/utils/prerender-output-paths": {
153
+ "types": "./dist/utils/prerender-output-paths.d.ts",
154
+ "import": "./dist/utils/prerender-output-paths.js"
131
155
  }
132
156
  },
133
157
  "dependencies": {
@@ -146,11 +170,10 @@
146
170
  "@vitejs/plugin-react": "^6.0.1",
147
171
  "@vitejs/plugin-rsc": "^0.5.27",
148
172
  "am-i-vibing": "^0.5.0",
173
+ "pathslash": "^0.1.0",
149
174
  "react-server-dom-webpack": "^19.2.7",
150
- "vite": "npm:@voidzero-dev/vite-plus-core@0.2.1",
151
- "vite-plus": "0.2.1",
152
- "vite-tsconfig-paths": "^6.1.1",
153
- "@vinext/cloudflare": "0.2.1"
175
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.2",
176
+ "vite-plus": "0.2.2"
154
177
  },
155
178
  "peerDependencies": {
156
179
  "@mdx-js/rollup": "^3.0.0",
@@ -159,8 +182,7 @@
159
182
  "react": "^19.2.6",
160
183
  "react-dom": "^19.2.6",
161
184
  "react-server-dom-webpack": "^19.2.6",
162
- "vite": "^7.0.0 || ^8.0.0",
163
- "vite-tsconfig-paths": "^6.1.1"
185
+ "vite": "^8.0.0"
164
186
  },
165
187
  "peerDependenciesMeta": {
166
188
  "@mdx-js/rollup": {
@@ -171,9 +193,6 @@
171
193
  },
172
194
  "react-server-dom-webpack": {
173
195
  "optional": true
174
- },
175
- "vite-tsconfig-paths": {
176
- "optional": true
177
196
  }
178
197
  },
179
198
  "engines": {
@@ -1,3 +0,0 @@
1
- import { KVCacheHandler } from "../packages/cloudflare/src/cache/kv-data-adapter.runtime.js";
2
- import { TPROptions, TPRResult, runTPR } from "../packages/cloudflare/src/tpr.js";
3
- export { KVCacheHandler, type TPROptions, type TPRResult, runTPR };
@@ -1,3 +0,0 @@
1
- import { KVCacheHandler } from "../packages/cloudflare/src/cache/kv-data-adapter.runtime.js";
2
- import { runTPR } from "../packages/cloudflare/src/tpr.js";
3
- export { KVCacheHandler, runTPR };
@@ -1,102 +0,0 @@
1
- import { getRequestExecutionContext } from "../../../../shims/request-context.js";
2
- //#region ../cloudflare/src/cache/cdn-adapter.runtime.ts
3
- function getWorkersCache() {
4
- const cache = getRequestExecutionContext()?.cache;
5
- if (cache && typeof cache.purge === "function") return cache;
6
- return null;
7
- }
8
- /** Non-cacheable responses: nobody (edge or browser) stores them. */
9
- const NO_STORE = "no-store";
10
- /**
11
- * Browser-facing policy for cacheable responses. `public` allows shared caches
12
- * to participate, but `max-age=0, must-revalidate` forces every reuse to
13
- * revalidate (against the edge) rather than serving a stored copy — so the user
14
- * always sees edge-fresh content while still permitting conditional 304s.
15
- */
16
- const BROWSER_REVALIDATE = "public, max-age=0, must-revalidate";
17
- /**
18
- * A concrete stale window (1 year) substituted for a value-less
19
- * `stale-while-revalidate`. The framework emits a bare `stale-while-revalidate`
20
- * (no `=seconds`) to mean an unbounded stale window — a Vercel CDN extension.
21
- * Cloudflare follows RFC 5861, which requires `stale-while-revalidate=<seconds>`,
22
- * and treats the value-less form as a zero-width window (no stale serving →
23
- * hard expiry at `max-age`, so the next request is a MISS instead of UPDATING).
24
- * Stamping a large finite value preserves the "serve stale ~indefinitely while
25
- * revalidating" intent in a form the edge honors.
26
- */
27
- const UNBOUNDED_SWR_SECONDS = 31536e3;
28
- /**
29
- * Convert the framework's shared-cache policy into a CDN-scoped one:
30
- * `s-maxage=…` → `max-age=…` (the edge honors `max-age` inside
31
- * `CDN-Cache-Control`), give a value-less `stale-while-revalidate` an explicit
32
- * seconds value (Cloudflare ignores the bare directive), and ensure a leading
33
- * `public`.
34
- */
35
- function toEdgeCacheControl(cacheControl) {
36
- const withMaxAge = cacheControl.replace(/\bs-maxage=/g, "max-age=").replace(/\bstale-while-revalidate\b(?!=)/g, `stale-while-revalidate=${UNBOUNDED_SWR_SECONDS}`);
37
- return /\bpublic\b/.test(withMaxAge) ? withMaxAge : `public, ${withMaxAge}`;
38
- }
39
- /**
40
- * Cloudflare's `Cache-Tag` header budget is 16 KB total with each tag capped at
41
- * 1024 bytes. Keep a conservative ceiling so a page with a large tag set never
42
- * produces an oversized (silently-dropped) header.
43
- */
44
- const MAX_CACHE_TAG_BYTES = 8 * 1024;
45
- const MAX_SINGLE_TAG_BYTES = 1024;
46
- /**
47
- * Build a `Cache-Tag` header value from canonicalised tags. Tags containing a
48
- * comma (the header separator) or exceeding the per-tag size are skipped, and
49
- * the whole value is bounded to stay within Cloudflare's limit.
50
- */
51
- function formatCacheTag(tags) {
52
- const parts = [];
53
- let total = 0;
54
- for (const tag of tags) {
55
- if (!tag || tag.includes(",") || tag.length > MAX_SINGLE_TAG_BYTES) continue;
56
- const next = total + tag.length + (parts.length > 0 ? 1 : 0);
57
- if (next > MAX_CACHE_TAG_BYTES) break;
58
- parts.push(tag);
59
- total = next;
60
- }
61
- return parts.length > 0 ? parts.join(",") : null;
62
- }
63
- var CloudflareCdnCacheAdapter = class {
64
- ownsBackgroundRevalidation = false;
65
- /**
66
- * The origin keeps no page store — return null so the request renders fresh.
67
- * The edge serves cached HIT/STALE responses without reaching the origin.
68
- */
69
- async get() {
70
- return null;
71
- }
72
- /** No-op: the platform caches the response via its headers, not an origin store. */
73
- async set(_key, _data, _ctx) {}
74
- buildResponseHeaders(input) {
75
- if (!input.cacheControl) return { "Cache-Control": NO_STORE };
76
- if (/\b(?:no-store|no-cache|private)\b/.test(input.cacheControl)) return {
77
- "Cache-Control": input.cacheControl,
78
- "CDN-Cache-Control": null,
79
- "Cloudflare-CDN-Cache-Control": null,
80
- "Cache-Tag": null
81
- };
82
- const headers = {
83
- "Cache-Control": BROWSER_REVALIDATE,
84
- "CDN-Cache-Control": toEdgeCacheControl(input.cacheControl)
85
- };
86
- if (input.tags && input.tags.length > 0) {
87
- const cacheTag = formatCacheTag(input.tags);
88
- if (cacheTag) headers["Cache-Tag"] = cacheTag;
89
- }
90
- return headers;
91
- }
92
- /** Purge edge-cached responses by tag via the request context's `cache.purge`. */
93
- async revalidateTag(tags, _durations) {
94
- const cache = getWorkersCache();
95
- if (!cache) return;
96
- const tagList = (Array.isArray(tags) ? tags : [tags]).filter((t) => typeof t === "string" && t.length > 0);
97
- if (tagList.length === 0) return;
98
- await cache.purge({ tags: tagList });
99
- }
100
- };
101
- //#endregion
102
- export { CloudflareCdnCacheAdapter };
@@ -1,126 +0,0 @@
1
- import { CacheHandler, CacheHandlerValue, IncrementalCacheValue } from "../../../../shims/cache-handler.js";
2
- import { ExecutionContextLike } from "../../../../shims/request-context.js";
3
-
4
- //#region ../cloudflare/src/cache/kv-data-adapter.runtime.d.ts
5
- type KVNamespace = {
6
- get(key: string, options?: {
7
- type?: string;
8
- }): Promise<string | null>;
9
- get(key: string, options: {
10
- type: "arrayBuffer";
11
- }): Promise<ArrayBuffer | null>;
12
- put(key: string, value: string | ArrayBuffer | ReadableStream, options?: {
13
- expirationTtl?: number;
14
- metadata?: Record<string, unknown>;
15
- }): Promise<void>;
16
- delete(key: string): Promise<void>;
17
- list(options?: {
18
- prefix?: string;
19
- limit?: number;
20
- cursor?: string;
21
- }): Promise<{
22
- keys: Array<{
23
- name: string;
24
- metadata?: Record<string, unknown>;
25
- }>;
26
- list_complete: boolean;
27
- cursor?: string;
28
- }>;
29
- };
30
- /** Key prefix for cache entries. */
31
- /**
32
- * Cloudflare KV data cache handler.
33
- *
34
- * @deprecated Consumers should not instantiate or register this handler by
35
- * hand. Configure it declaratively via the `cache.data` option on the
36
- * `vinext()` plugin, using the {@link kvDataAdapter} builder:
37
- *
38
- * ```ts
39
- * import { vinext } from "vinext";
40
- * import { kvDataAdapter } from "@vinext/cloudflare/cache/kv-data-adapter";
41
- *
42
- * export default defineConfig({
43
- * plugins: [vinext({ cache: { data: kvDataAdapter({ binding: "VINEXT_KV_CACHE" }) } })],
44
- * });
45
- * ```
46
- *
47
- * `kvDataAdapter()` is safe to call from `vite.config.ts` — it never touches
48
- * the Workers runtime — and the plugin defers instantiation of this handler to
49
- * the first request. This class stays exported for the runtime factory and for
50
- * backwards compatibility, but is not the recommended consumer API.
51
- */
52
- declare class KVCacheHandler implements CacheHandler {
53
- private kv;
54
- private prefix;
55
- private ctx;
56
- private ttlSeconds;
57
- /** Local in-memory cache for tag invalidation timestamps. Avoids redundant KV reads. */
58
- private _tagCache;
59
- /** TTL (ms) for local tag cache entries. After this, re-fetch from KV. */
60
- private _tagCacheTtl;
61
- constructor(kvNamespace: KVNamespace, options?: {
62
- appPrefix?: string;
63
- ctx?: ExecutionContextLike;
64
- ttlSeconds?: number; /** TTL in milliseconds for the local tag cache. Defaults to 5000ms. */
65
- tagCacheTtlMs?: number;
66
- });
67
- get(key: string, _ctx?: Record<string, unknown>): Promise<CacheHandlerValue | null>;
68
- /**
69
- * Check tag invalidation markers for stored tags or read-time soft tags.
70
- * Uses a local in-memory cache to avoid redundant KV reads for recently-seen tags.
71
- */
72
- private _hasRevalidatedTag;
73
- set(key: string, data: IncrementalCacheValue | null, ctx?: Record<string, unknown>): Promise<void>;
74
- revalidateTag(tags: string | string[], _durations?: {
75
- expire?: number;
76
- }): Promise<void>;
77
- /**
78
- * Invalidate all cache entries whose path tags fall under `pathPrefix`.
79
- *
80
- * Uses KV list metadata to discover tags without fetching entry values —
81
- * entries written by `set()` store their tags in KV metadata, so
82
- * `kv.list()` returns them inline with each key. This makes prefix
83
- * invalidation O(list_pages) instead of O(entries × get).
84
- *
85
- * Entries written before metadata was added (no metadata.tags) are
86
- * gracefully skipped — they'll be picked up on next `set()` which
87
- * writes metadata.
88
- *
89
- * When present, this method fully replaces the `revalidateTag` call
90
- * path in `revalidatePath()` — implementors own all path-based tag
91
- * handling.
92
- */
93
- revalidateByPathPrefix(pathPrefix: string): Promise<void>;
94
- /**
95
- * Clear the in-memory tag cache for this KVCacheHandler instance.
96
- *
97
- * Note: KVCacheHandler instances are typically reused across multiple
98
- * requests in a Cloudflare Worker. The `_tagCache` is intentionally
99
- * cross-request — it reduces redundant KV reads for recently-seen tags
100
- * across all requests hitting the same isolate, bounded by `tagCacheTtlMs`
101
- * (default 5s). vinext does NOT call this method per request.
102
- *
103
- * This is an opt-in escape hatch for callers that need stricter isolation
104
- * (e.g., tests, or environments with custom lifecycle management).
105
- * Callers that require per-request isolation should either construct a
106
- * fresh KVCacheHandler per request or invoke this method explicitly.
107
- */
108
- resetRequestCache(): void;
109
- /**
110
- * Fire a KV delete in the background.
111
- * Prefers the per-request ExecutionContext from ALS (set by
112
- * runWithExecutionContext in the worker entry) so that background KV
113
- * operations are registered with the correct request's waitUntil().
114
- * Falls back to the constructor-provided ctx for callers that set it
115
- * explicitly, and to fire-and-forget when neither is available (Node.js dev).
116
- */
117
- private _deleteInBackground;
118
- /**
119
- * Execute a KV put and return the promise so callers can await completion.
120
- * Also registers with ctx.waitUntil() so the Workers runtime keeps the
121
- * isolate alive even if the caller does not await the returned promise.
122
- */
123
- private _put;
124
- }
125
- //#endregion
126
- export { KVCacheHandler };