vinext 1.0.0-beta.12 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +39 -12
  2. package/dist/build/action-owner-manifest.js +23 -5
  3. package/dist/build/lifecycle.d.ts +42 -0
  4. package/dist/build/lifecycle.js +246 -0
  5. package/dist/build/nitro-route-rules.js +1 -1
  6. package/dist/build/pages-client-assets-module.d.ts +0 -3
  7. package/dist/build/pages-client-assets-module.js +1 -13
  8. package/dist/build/precompress.js +1 -1
  9. package/dist/build/prerender-paths.d.ts +1 -1
  10. package/dist/build/prerender-paths.js +6 -6
  11. package/dist/build/prerender-server-pool.js +1 -1
  12. package/dist/build/prerender.d.ts +1 -1
  13. package/dist/build/prerender.js +5 -5
  14. package/dist/build/preview-credentials.d.ts +1 -1
  15. package/dist/build/preview-credentials.js +2 -2
  16. package/dist/build/report.js +1 -1
  17. package/dist/build/run-prerender.d.ts +2 -2
  18. package/dist/build/run-prerender.js +5 -5
  19. package/dist/build/standalone.js +2 -2
  20. package/dist/cli-args.d.ts +5 -13
  21. package/dist/cli-args.js +2 -45
  22. package/dist/cli-dev-config.d.ts +6 -2
  23. package/dist/cli-dev-config.js +160 -3
  24. package/dist/cli.js +104 -439
  25. package/dist/config/config-matchers.js +1 -1
  26. package/dist/config/next-config.d.ts +2 -2
  27. package/dist/config/next-config.js +5 -5
  28. package/dist/config/prerender.d.ts +3 -0
  29. package/dist/config/prerender.js +8 -2
  30. package/dist/entries/app-browser-entry.js +1 -1
  31. package/dist/entries/app-rsc-entry.js +1 -1
  32. package/dist/entries/pages-client-entry.d.ts +1 -0
  33. package/dist/entries/pages-client-entry.js +17 -2
  34. package/dist/index.d.ts +6 -8
  35. package/dist/index.js +262 -101
  36. package/dist/init-cloudflare.d.ts +3 -2
  37. package/dist/init-cloudflare.js +117 -5
  38. package/dist/init-platform.d.ts +2 -0
  39. package/dist/init-platform.js +9 -3
  40. package/dist/init.d.ts +7 -5
  41. package/dist/init.js +41 -22
  42. package/dist/plugins/dynamic-preload-metadata.js +1 -1
  43. package/dist/plugins/extensionless-dynamic-import.js +2 -2
  44. package/dist/plugins/fonts.js +1 -1
  45. package/dist/plugins/ignore-dynamic-requests.js +1 -1
  46. package/dist/plugins/import-meta-url.js +1 -1
  47. package/dist/plugins/instrumentation-client.js +1 -1
  48. package/dist/plugins/og-assets.js +32 -13
  49. package/dist/plugins/og-harfbuzz.d.ts +24 -0
  50. package/dist/plugins/og-harfbuzz.js +260 -0
  51. package/dist/plugins/optimize-imports.js +1 -1
  52. package/dist/plugins/require-condition-resolution.js +2 -2
  53. package/dist/plugins/require-context.js +2 -2
  54. package/dist/plugins/typeof-window.js +1 -1
  55. package/dist/plugins/use-cache-callable.d.ts +0 -2
  56. package/dist/plugins/use-cache-callable.js +8 -16
  57. package/dist/plugins/worker-image-imports.js +1 -1
  58. package/dist/routing/app-route-graph.js +1 -1
  59. package/dist/routing/app-router.js +1 -1
  60. package/dist/routing/pages-router.js +1 -1
  61. package/dist/server/app-action-forwarding.js +1 -1
  62. package/dist/server/app-browser-error.js +1 -1
  63. package/dist/server/app-elements-wire.js +2 -2
  64. package/dist/server/app-middleware.js +1 -1
  65. package/dist/server/app-optimistic-routing.js +1 -1
  66. package/dist/server/app-page-dispatch.js +1 -1
  67. package/dist/server/app-page-element-builder.js +3 -2
  68. package/dist/server/app-page-probe.js +3 -3
  69. package/dist/server/app-request-stage-independent-entry.js +2 -2
  70. package/dist/server/app-route-handler-dispatch.js +1 -1
  71. package/dist/server/app-route-handler-runtime.js +1 -1
  72. package/dist/server/app-router-entry.js +2 -2
  73. package/dist/server/app-rsc-handler.d.ts +1 -1
  74. package/dist/server/app-rsc-handler.js +4 -4
  75. package/dist/server/app-rsc-response-stage.js +1 -1
  76. package/dist/server/app-rsc-route-matching.js +1 -1
  77. package/dist/server/app-server-action-execution.js +4 -4
  78. package/dist/server/artifact-compatibility.js +1 -1
  79. package/dist/server/client-reuse-manifest.js +1 -1
  80. package/dist/server/dev-lockfile.d.ts +1 -1
  81. package/dist/server/dev-lockfile.js +4 -1
  82. package/dist/server/dev-server.d.ts +1 -1
  83. package/dist/server/dev-server.js +28 -6
  84. package/dist/server/dev-stack-sourcemap.js +1 -1
  85. package/dist/server/isr-cache.js +1 -1
  86. package/dist/server/metadata-route-response.js +8 -0
  87. package/dist/server/middleware-runtime.js +3 -3
  88. package/dist/server/pages-data-route.js +1 -1
  89. package/dist/server/pages-dev-hydration.d.ts +6 -0
  90. package/dist/server/pages-dev-hydration.js +19 -7
  91. package/dist/server/pages-page-data.js +2 -2
  92. package/dist/server/pages-page-handler.js +1 -1
  93. package/dist/server/pages-page-response.js +1 -1
  94. package/dist/server/pages-request-pipeline.js +3 -3
  95. package/dist/server/pages-request-stage-entry.js +3 -3
  96. package/dist/server/pages-revalidate.js +1 -1
  97. package/dist/server/prerender-route-params.js +1 -1
  98. package/dist/server/prod-server.js +7 -7
  99. package/dist/server/request-pipeline.js +2 -2
  100. package/dist/server/socket-error-backstop.js +1 -1
  101. package/dist/shims/cache-callable-runtime.d.ts +38 -0
  102. package/dist/shims/cache-callable-runtime.js +162 -11
  103. package/dist/shims/cache-runtime.d.ts +6 -8
  104. package/dist/shims/cache-runtime.js +82 -22
  105. package/dist/shims/font-local.js +1 -1
  106. package/dist/shims/form.js +1 -1
  107. package/dist/shims/headers.js +2 -2
  108. package/dist/shims/internal/app-page-props-cache-key.d.ts +29 -0
  109. package/dist/shims/internal/app-page-props-cache-key.js +53 -1
  110. package/dist/shims/internal/format-url-object.d.ts +7 -0
  111. package/dist/shims/internal/format-url-object.js +53 -0
  112. package/dist/shims/internal/normalize-router-href.d.ts +15 -0
  113. package/dist/shims/internal/normalize-router-href.js +41 -0
  114. package/dist/shims/internal/pages-data-target.d.ts +4 -1
  115. package/dist/shims/internal/pages-data-target.js +28 -35
  116. package/dist/shims/internal/route-pattern-for-warning.d.ts +2 -2
  117. package/dist/shims/internal/route-pattern-for-warning.js +3 -3
  118. package/dist/shims/link.js +31 -92
  119. package/dist/shims/metadata.js +5 -4
  120. package/dist/shims/navigation.js +2 -2
  121. package/dist/shims/router-state.js +1 -1
  122. package/dist/shims/router.d.ts +8 -7
  123. package/dist/shims/router.js +312 -148
  124. package/dist/shims/server.js +3 -3
  125. package/dist/utils/built-asset-url.js +1 -1
  126. package/dist/utils/project.d.ts +1 -11
  127. package/dist/utils/project.js +19 -28
  128. package/dist/utils/react-version.d.ts +3 -1
  129. package/dist/utils/react-version.js +19 -1
  130. package/dist/utils/vite-cli-invocation.d.ts +21 -0
  131. package/dist/utils/vite-cli-invocation.js +144 -0
  132. package/package.json +10 -2
@@ -208,7 +208,7 @@ export type NextConfig = {
208
208
  cacheComponents?: boolean;
209
209
  /**
210
210
  * Enables source maps while generating static pages.
211
- * Helps with errors during the prerender phase in `vinext build`.
211
+ * Helps with errors during the prerender phase in `vite build`.
212
212
  * Defaults to `true`. Set to `false` to disable.
213
213
  */
214
214
  enablePrerenderSourceMaps?: boolean;
@@ -602,7 +602,7 @@ export declare function normalizeAssetPrefix(value: unknown): string;
602
602
  * across plugin instances); otherwise we mint a random UUID.
603
603
  *
604
604
  * NOTE: like `resolveBuildId`, this is non-deterministic in the no-deploymentId
605
- * case, so a single `vinext build` that instantiates the plugin more than once
605
+ * case, so a single `vite build` that instantiates the plugin more than once
606
606
  * (App Router `buildApp()` + the hybrid Pages Router `vite.build()`) must
607
607
  * resolve it once and share it — see `__VINEXT_SHARED_RSC_COMPATIBILITY_ID`.
608
608
  */
@@ -1,11 +1,11 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { normalizePageExtensions } from "../routing/file-matcher.js";
3
- import { isExternalUrl } from "../utils/external-url.js";
4
- import { applyLocaleToRoutes } from "./config-matchers.js";
5
2
  import { isUnknownRecord } from "../utils/record.js";
3
+ import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
4
+ import { normalizePageExtensions } from "../routing/file-matcher.js";
6
5
  import { getHtmlLimitedBotRegex } from "../utils/html-limited-bots.js";
7
6
  import { flattenPluginOptions } from "../utils/plugin-options.js";
8
- import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "../shims/constants.js";
7
+ import { isExternalUrl } from "../utils/external-url.js";
8
+ import { applyLocaleToRoutes } from "./config-matchers.js";
9
9
  import { loadTsconfigResolutionForRoot } from "./tsconfig-paths.js";
10
10
  import { loadCommonJsModule, shouldRetryAsCommonJs } from "../utils/commonjs-loader.js";
11
11
  import { Module, createRequire } from "node:module";
@@ -527,7 +527,7 @@ function resolveDeploymentId(configDeploymentId) {
527
527
  * across plugin instances); otherwise we mint a random UUID.
528
528
  *
529
529
  * NOTE: like `resolveBuildId`, this is non-deterministic in the no-deploymentId
530
- * case, so a single `vinext build` that instantiates the plugin more than once
530
+ * case, so a single `vite build` that instantiates the plugin more than once
531
531
  * (App Router `buildApp()` + the hybrid Pages Router `vite.build()`) must
532
532
  * resolve it once and share it — see `__VINEXT_SHARED_RSC_COMPATIBILITY_ID`.
533
533
  */
@@ -9,9 +9,12 @@ export type VinextPrerenderConfig = true | {
9
9
  * App Router and Pages Router route that vinext can statically render.
10
10
  */
11
11
  routes: "*";
12
+ /** Maximum number of routes to render concurrently. */
13
+ concurrency?: number;
12
14
  };
13
15
  export type ResolvedVinextPrerenderConfig = {
14
16
  routes: "*";
17
+ concurrency?: number;
15
18
  };
16
19
  export type VinextPrerenderDecisionReason = "flag" | "next-export" | "vinext-config";
17
20
  export type VinextPrerenderDecision = ResolvedVinextPrerenderConfig & {
@@ -8,7 +8,13 @@ function normalizeVinextPrerenderConfig(config) {
8
8
  if (config === void 0) return null;
9
9
  if (config === true) return { routes: "*" };
10
10
  if (!isUnknownRecord(config)) throw new Error("[vinext] Invalid `prerender` config. Use `true` or `{ routes: \"*\" }`.");
11
- if (config.routes === "*") return { routes: "*" };
11
+ if (config.routes === "*") {
12
+ if (config.concurrency !== void 0 && (!Number.isInteger(config.concurrency) || config.concurrency <= 0)) throw new Error("[vinext] `prerender.concurrency` must be a positive integer.");
13
+ return {
14
+ routes: "*",
15
+ ...config.concurrency === void 0 ? {} : { concurrency: config.concurrency }
16
+ };
17
+ }
12
18
  throw new Error("[vinext] Unsupported `prerender.routes` config. Currently only `routes: \"*\"` is supported.");
13
19
  }
14
20
  async function findVinextPrerenderConfigInPlugins(plugins) {
@@ -51,7 +57,7 @@ function resolveVinextPrerenderDecision(options) {
51
57
  reason: "next-export"
52
58
  };
53
59
  if (options.vinextPrerenderConfig?.routes === "*") return {
54
- routes: "*",
60
+ ...options.vinextPrerenderConfig,
55
61
  reason: "vinext-config"
56
62
  };
57
63
  return null;
@@ -1,6 +1,6 @@
1
+ import { patternsStructurallyEquivalent } from "../routing/app-route-graph.js";
1
2
  import { resolveClientRuntimeModule, resolveRuntimeEntryModule } from "./runtime-entry-module.js";
2
3
  import { toClientRewrites } from "../client/client-rewrites.js";
3
- import { patternsStructurallyEquivalent } from "../routing/app-route-graph.js";
4
4
  //#region src/entries/app-browser-entry.ts
5
5
  /**
6
6
  * Generate the virtual browser entry module.
@@ -1,8 +1,8 @@
1
1
  import { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
+ import { appRouteHasMainTreeLoadingBoundary } from "../routing/app-router.js";
2
3
  import { resolveEntryPath } from "./runtime-entry-module.js";
3
4
  import { isProxyFile } from "../server/middleware.js";
4
5
  import { extractExportConstString } from "../build/report.js";
5
- import { appRouteHasMainTreeLoadingBoundary } from "../routing/app-router.js";
6
6
  import { routePatternParts } from "../routing/route-pattern.js";
7
7
  import { safeJsonStringify } from "../server/html.js";
8
8
  import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES } from "../server/image-optimization.js";
@@ -3,6 +3,7 @@ import { ResolvedNextConfig } from "../config/next-config.js";
3
3
  import { StaticMiddlewareMatcher } from "../build/report.js";
4
4
  import { VinextLinkPrefetchRoute } from "../client/vinext-next-data.js";
5
5
  //#region src/entries/pages-client-entry.d.ts
6
+ export declare function compileClientMiddlewareMatchers(matcher: StaticMiddlewareMatcher | undefined): unknown[] | undefined;
6
7
  export declare function generateClientEntry(pagesDir: string, nextConfig: ResolvedNextConfig, fileMatcher: ReturnType<typeof createValidFileMatcher>, options?: {
7
8
  appPrefetchRoutes?: readonly VinextLinkPrefetchRoute[];
8
9
  instrumentationClientPath?: string | null;
@@ -3,6 +3,7 @@ import { findFileWithExts } from "../routing/file-matcher.js";
3
3
  import { patternToNextFormat } from "../routing/route-validation.js";
4
4
  import { apiRouter, pagesRouter } from "../routing/pages-router.js";
5
5
  import { resolveClientRuntimeModule } from "./runtime-entry-module.js";
6
+ import { compileMiddlewareMatcherPattern } from "../server/middleware-matcher-pattern.js";
6
7
  import { hasExportedName } from "../build/report.js";
7
8
  import { toClientRewrites } from "../client/client-rewrites.js";
8
9
  import { readFile } from "node:fs/promises";
@@ -18,6 +19,19 @@ import { readFile } from "node:fs/promises";
18
19
  *
19
20
  * Extracted from index.ts.
20
21
  */
22
+ function compileClientMiddlewareMatchers(matcher) {
23
+ if (matcher === void 0) return void 0;
24
+ return (typeof matcher === "string" ? [matcher] : matcher).map((entry) => {
25
+ const source = typeof entry === "string" ? entry : entry.source;
26
+ const compiled = compileMiddlewareMatcherPattern(source);
27
+ if (!compiled.regexp) return entry;
28
+ return {
29
+ ...typeof entry === "string" ? { source } : entry,
30
+ regexp: compiled.regexp.source,
31
+ flags: compiled.regexp.flags
32
+ };
33
+ });
34
+ }
21
35
  /**
22
36
  * Project a Pages `Route` down to the public `VinextPagesLinkPrefetchRoute`
23
37
  * shape used for client-side hybrid ownership decisions. Mirrors
@@ -54,6 +68,7 @@ async function generateClientEntry(pagesDir, nextConfig, fileMatcher, options =
54
68
  const pagesSspPatterns = (await Promise.all(pageRoutes.map(async (route) => await hasGetServerSidePropsExport(route.filePath) ? patternToNextFormat(route.pattern) : null))).filter((pattern) => pattern !== null);
55
69
  const instrumentationClientPath = options.instrumentationClientPath ?? null;
56
70
  const clientRewrites = toClientRewrites(nextConfig.rewrites);
71
+ const clientMiddlewareMatchers = compileClientMiddlewareMatchers(options.middlewareMatcher);
57
72
  const reactInstanceBootstrapPath = resolveClientRuntimeModule("react-instance-bootstrap");
58
73
  const loaderEntries = pageRoutes.map((r) => {
59
74
  const absPath = r.filePath;
@@ -103,7 +118,7 @@ window.__VINEXT_PAGE_PATTERNS__ = Object.keys(pageLoaders);
103
118
  window.__VINEXT_REACT_STRICT_MODE__ = ${JSON.stringify(reactStrictModeEnabled)};
104
119
  window.__VINEXT_PAGES_SSG_PATTERNS__ = ${JSON.stringify(pagesSsgPatterns)};
105
120
  window.__VINEXT_PAGES_SSP_PATTERNS__ = ${JSON.stringify(pagesSspPatterns)};
106
- window.__VINEXT_MIDDLEWARE_MATCHER__ = ${JSON.stringify(options.middlewareMatcher)};
121
+ window.__VINEXT_MIDDLEWARE_MATCHER__ = ${JSON.stringify(clientMiddlewareMatchers)};
107
122
  window.__VINEXT_APP_LOADER__ = appLoader;
108
123
  // Expose the App Router prefetch manifest so Pages Router \`<Link>\`s and
109
124
  // \`Router.prefetch\` can detect when a prefetch target is actually an App
@@ -237,4 +252,4 @@ hydrate();
237
252
  `;
238
253
  }
239
254
  //#endregion
240
- export { generateClientEntry };
255
+ export { compileClientMiddlewareMatchers, generateClientEntry };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { NextConfig, NextConfigInput } from "./config/next-config.js";
2
1
  import { VinextMultiStageOutput, VinextResponseStageDispatchOptions, VinextResponseStageTransport } from "./server/multi-stage.js";
3
2
  import { VinextCacheConfig } from "./cache/cache-adapters-virtual.js";
4
3
  import { VinextPrerenderConfig } from "./config/prerender.js";
4
+ import { NextConfig, NextConfigInput } from "./config/next-config.js";
5
5
  import { AppStaticExportOptions, StaticExportOptions, StaticExportResult, staticExportApp, staticExportPages } from "./build/static-export.js";
6
6
  import { VinextImageConfig } from "./image/image-adapters-virtual.js";
7
7
  import { PluginOption } from "vite";
@@ -78,22 +78,20 @@ export type VinextOptions = {
78
78
  * Disabled by default. Not useful when deploying to edge platforms
79
79
  * (Cloudflare Workers, Nitro) that handle compression at the CDN layer.
80
80
  *
81
- * Can also be enabled via the `--precompress` CLI flag or by setting the
82
- * `VINEXT_PRECOMPRESS=1` environment variable (useful for CI pipelines
83
- * that need to enable precompression without modifying vite.config.ts).
81
+ * Can also be enabled by setting the `VINEXT_PRECOMPRESS=1` environment
82
+ * variable (useful for CI pipelines that cannot modify vite.config.ts).
84
83
  * @default false
85
84
  */
86
85
  precompress?: boolean;
87
86
  /**
88
- * Pre-render routes after `vinext build` without passing
89
- * `--prerender-all`.
87
+ * Pre-render routes after `vite build`.
90
88
  *
91
89
  * Use `true` as shorthand for `{ routes: "*" }`. The object form is
92
90
  * available so future releases can support narrower route selections, but
93
91
  * currently only `"*"` is supported.
94
92
  *
95
- * The `vinext build --prerender-all` and `vinext deploy --prerender-all`
96
- * flags still work and take priority when present.
93
+ * The `vinext-cloudflare deploy --prerender-all` flag takes priority when
94
+ * present.
97
95
  *
98
96
  * @example
99
97
  * vinext({ prerender: true })