vinext 1.0.0-beta.7 → 1.0.0-beta.9
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.
- package/README.md +43 -0
- package/dist/build/prerender-paths.d.ts +50 -1
- package/dist/build/prerender-paths.js +627 -88
- package/dist/build/prerender.d.ts +4 -2
- package/dist/build/prerender.js +40 -23
- package/dist/build/report.d.ts +16 -1
- package/dist/build/report.js +64 -3
- package/dist/build/static-export.d.ts +1 -1
- package/dist/cache/cache-adapters-virtual.d.ts +47 -1
- package/dist/cache/cache-adapters-virtual.js +10 -1
- package/dist/cli.js +7 -0
- package/dist/client/vinext-next-data.d.ts +2 -0
- package/dist/config/config-matchers.d.ts +3 -3
- package/dist/config/config-matchers.js +8 -3
- package/dist/config/prerender.d.ts +2 -2
- package/dist/config/prerender.js +2 -2
- package/dist/entries/app-browser-entry.d.ts +1 -1
- package/dist/entries/app-browser-entry.js +4 -1
- package/dist/entries/app-rsc-entry.d.ts +2 -0
- package/dist/entries/app-rsc-entry.js +28 -4
- package/dist/entries/app-rsc-manifest.js +1 -0
- package/dist/entries/pages-server-entry.d.ts +1 -1
- package/dist/entries/pages-server-entry.js +4 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +146 -28
- package/dist/init-cloudflare.d.ts +5 -3
- package/dist/init-cloudflare.js +58 -25
- package/dist/plugins/import-meta-url.js +7 -6
- package/dist/routing/app-router.d.ts +3 -1
- package/dist/routing/app-router.js +5 -1
- package/dist/server/app-browser-entry.js +41 -13
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-middleware.d.ts +8 -0
- package/dist/server/app-middleware.js +28 -2
- package/dist/server/app-optimistic-routing.d.ts +6 -1
- package/dist/server/app-optimistic-routing.js +13 -1
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +16 -1
- package/dist/server/app-page-cache-finalizer.js +73 -4
- package/dist/server/app-page-cache.js +2 -2
- package/dist/server/app-page-dispatch.d.ts +2 -0
- package/dist/server/app-page-dispatch.js +12 -4
- package/dist/server/app-page-execution.js +1 -1
- package/dist/server/app-page-render.d.ts +1 -0
- package/dist/server/app-page-render.js +27 -9
- package/dist/server/app-page-response.js +2 -2
- package/dist/server/app-page-stream.js +2 -1
- package/dist/server/app-pages-bridge.js +2 -0
- package/dist/server/app-prerender-endpoints.js +23 -11
- package/dist/server/app-prerender-static-params.js +12 -5
- package/dist/server/app-route-handler-dispatch.js +13 -9
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +127 -14
- package/dist/server/app-route-handler-policy.d.ts +15 -3
- package/dist/server/app-route-handler-policy.js +19 -4
- package/dist/server/app-route-tree-prefetch.js +2 -2
- package/dist/server/app-router-entry.js +52 -8
- package/dist/server/app-rsc-cache-busting.d.ts +22 -4
- package/dist/server/app-rsc-cache-busting.js +68 -18
- package/dist/server/app-rsc-handler.d.ts +2 -0
- package/dist/server/app-rsc-handler.js +95 -30
- package/dist/server/app-rsc-response-finalizer.js +24 -7
- package/dist/server/app-rsc-route-matching.d.ts +1 -0
- package/dist/server/app-rsc-route-matching.js +1 -0
- package/dist/server/app-segment-config.d.ts +3 -1
- package/dist/server/app-segment-config.js +23 -11
- package/dist/server/app-server-action-execution.js +4 -4
- package/dist/server/app-ssr-entry.js +4 -4
- package/dist/server/cache-control.d.ts +8 -2
- package/dist/server/cache-control.js +35 -4
- package/dist/server/cacheability-limits.d.ts +9 -0
- package/dist/server/cacheability-limits.js +9 -0
- package/dist/server/cacheability-manifest.d.ts +42 -0
- package/dist/server/cacheability-manifest.js +191 -0
- package/dist/server/cacheability-request.d.ts +20 -0
- package/dist/server/cacheability-request.js +457 -0
- package/dist/server/config-headers.js +23 -3
- package/dist/server/headers.d.ts +16 -3
- package/dist/server/headers.js +29 -3
- package/dist/server/middleware-matcher.d.ts +9 -1
- package/dist/server/middleware-matcher.js +22 -1
- package/dist/server/middleware-runtime.d.ts +6 -0
- package/dist/server/middleware-runtime.js +18 -3
- package/dist/server/normalize-path.js +1 -1
- package/dist/server/pages-api-route.js +1 -1
- package/dist/server/pages-i18n.js +3 -2
- package/dist/server/pages-page-handler.js +22 -9
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +17 -6
- package/dist/server/pages-router-entry.js +56 -9
- package/dist/server/prerender-route-params.js +1 -0
- package/dist/server/prerender-work-unit-setup.d.ts +3 -2
- package/dist/server/prerender-work-unit-setup.js +34 -11
- package/dist/server/prod-server.js +5 -5
- package/dist/server/request-pipeline.d.ts +1 -5
- package/dist/server/request-pipeline.js +2 -9
- package/dist/server/revalidation-host.js +1 -0
- package/dist/server/server-globals.js +13 -0
- package/dist/server/static-file-signal.d.ts +13 -0
- package/dist/server/static-file-signal.js +33 -0
- package/dist/server/worker-prerender-discovery.d.ts +19 -0
- package/dist/server/worker-prerender-discovery.js +55 -0
- package/dist/server/worker-utils.js +2 -3
- package/dist/shims/cache-runtime.js +140 -102
- package/dist/shims/cache.js +11 -1
- package/dist/shims/cacheability-classification.d.ts +85 -0
- package/dist/shims/cacheability-classification.js +146 -0
- package/dist/shims/cdn-cache.d.ts +30 -1
- package/dist/shims/cdn-cache.js +25 -1
- package/dist/shims/error.js +1 -1
- package/dist/shims/fetch-cache.js +8 -3
- package/dist/shims/headers.d.ts +3 -1
- package/dist/shims/headers.js +9 -5
- package/dist/shims/internal/app-prefetch-rsc-request.d.ts +25 -0
- package/dist/shims/internal/app-prefetch-rsc-request.js +21 -0
- package/dist/shims/internal/app-route-prefetch-policy.d.ts +2 -0
- package/dist/shims/internal/app-route-prefetch-policy.js +2 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +2 -2
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +29 -11
- package/dist/shims/internal/hybrid-client-route-owner.js +2 -2
- package/dist/shims/internal/make-hanging-promise.d.ts +7 -1
- package/dist/shims/internal/make-hanging-promise.js +13 -2
- package/dist/shims/internal/work-unit-async-storage.d.ts +2 -0
- package/dist/shims/link.js +25 -14
- package/dist/shims/navigation.js +31 -11
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/server.js +1 -1
- package/dist/shims/url-utils.d.ts +8 -1
- package/dist/shims/url-utils.js +10 -1
- package/dist/utils/prerender-output-paths.d.ts +7 -7
- package/dist/utils/prerender-output-paths.js +16 -9
- package/dist/utils/react-compiler-support.d.ts +20 -0
- package/dist/utils/react-compiler-support.js +29 -0
- package/package.json +10 -2
|
@@ -85,6 +85,8 @@ type AppRouterConfig = {
|
|
|
85
85
|
publicFiles?: string[];
|
|
86
86
|
/** Server-only token used to validate the draft-mode bypass cookie. */
|
|
87
87
|
draftModeSecret?: string;
|
|
88
|
+
/** Server-only token used to authorize build-time prerender endpoints. */
|
|
89
|
+
prerenderSecret?: string;
|
|
88
90
|
};
|
|
89
91
|
/**
|
|
90
92
|
* Generate the virtual RSC entry module.
|
|
@@ -90,6 +90,7 @@ function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes, global
|
|
|
90
90
|
const hasPagesDir = config?.hasPagesDir ?? false;
|
|
91
91
|
const publicFiles = config?.publicFiles ?? [];
|
|
92
92
|
const draftModeSecret = config?.draftModeSecret ?? randomUUID();
|
|
93
|
+
const prerenderSecret = config?.prerenderSecret ?? randomUUID();
|
|
93
94
|
const imageAllowedWidths = [...config?.imageConfig?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...config?.imageConfig?.imageSizes ?? DEFAULT_IMAGE_SIZES];
|
|
94
95
|
const imageConfig = {
|
|
95
96
|
qualities: config?.imageConfig?.qualities,
|
|
@@ -115,6 +116,8 @@ ${hasAppRouteHandlers ? `// Capture the canonical Request surface before any use
|
|
|
115
116
|
// The global-backed snapshot remains available to the lazy dispatch chunk.
|
|
116
117
|
import ${JSON.stringify(appRouteRequestBuiltInsPath)};` : ""}
|
|
117
118
|
import ${JSON.stringify(serverGlobalsPath)};
|
|
119
|
+
import __cacheabilityManifest from "virtual:vinext-cacheability-manifest";
|
|
120
|
+
export { __cacheabilityManifest };
|
|
118
121
|
import {
|
|
119
122
|
renderToReadableStream as _renderToReadableStream,
|
|
120
123
|
${hasServerActions ? `decodeAction,
|
|
@@ -352,6 +355,9 @@ ${metaRouteEntries.join(",\n")}
|
|
|
352
355
|
// Re-exported so the Cloudflare worker entry can strip basePath before
|
|
353
356
|
// recognising /_next/static/* paths (parity with __assetPrefix below).
|
|
354
357
|
export const __basePath = ${JSON.stringify(bp)};
|
|
358
|
+
// Per-build capability used by Worker entries to authorize remote path
|
|
359
|
+
// discovery. It is never included in responses or exposed to user modules.
|
|
360
|
+
export const __prerenderSecret = ${JSON.stringify(prerenderSecret)};
|
|
355
361
|
|
|
356
362
|
// Hoisted alongside __basePath so __fallbackRenderer / buildPageElements can
|
|
357
363
|
// thread the configured trailingSlash flag through canonical URL rendering.
|
|
@@ -557,6 +563,7 @@ const __appRscHandler = createAppRscHandler({
|
|
|
557
563
|
isDev: process.env.NODE_ENV !== "production",
|
|
558
564
|
draftModeSecret: __draftModeSecret,
|
|
559
565
|
dispatchMatchedPage({
|
|
566
|
+
bypassInterceptionContextCache,
|
|
560
567
|
clientReuseManifest,
|
|
561
568
|
cleanPathname,
|
|
562
569
|
displayPathname,
|
|
@@ -619,6 +626,7 @@ const __appRscHandler = createAppRscHandler({
|
|
|
619
626
|
const _asyncRouteParams = makeThenableParams(params);
|
|
620
627
|
return __dispatchAppPage({
|
|
621
628
|
basePath: __basePath,
|
|
629
|
+
bypassInterceptionContextCache,
|
|
622
630
|
ensureRouteLoaded: __ensureRouteLoaded,
|
|
623
631
|
clientTraceMetadata: __clientTraceMetadata,
|
|
624
632
|
reactMaxHeadersLength: __reactMaxHeadersLength,
|
|
@@ -709,7 +717,11 @@ const __appRscHandler = createAppRscHandler({
|
|
|
709
717
|
});
|
|
710
718
|
},
|
|
711
719
|
async probePage(probeSearchParams = searchParams) {
|
|
712
|
-
const __probeIntercept = findIntercept(
|
|
720
|
+
const __probeIntercept = findIntercept(
|
|
721
|
+
interceptionPathname,
|
|
722
|
+
interceptionContext,
|
|
723
|
+
interceptionId,
|
|
724
|
+
);
|
|
713
725
|
// The intercepting-route page module is lazy (page: null + __pageLoader).
|
|
714
726
|
// Resolve it before probing so buildAppPageProbes inspects the real page
|
|
715
727
|
// component for dynamic bailout — matching the render path, which also
|
|
@@ -730,7 +742,11 @@ const __appRscHandler = createAppRscHandler({
|
|
|
730
742
|
}));
|
|
731
743
|
},
|
|
732
744
|
renderErrorBoundaryPage(renderErr, errorOrigin) {
|
|
733
|
-
const __activeIntercept = findIntercept(
|
|
745
|
+
const __activeIntercept = findIntercept(
|
|
746
|
+
interceptionPathname,
|
|
747
|
+
interceptionContext,
|
|
748
|
+
interceptionId,
|
|
749
|
+
);
|
|
734
750
|
return __fallbackRenderer.renderErrorBoundary(route, renderErr, isRscRequest, request, params, scriptNonce, middlewareContext, {
|
|
735
751
|
isEdgeRuntime: __isEdgeRuntime(__segmentConfig.runtime),
|
|
736
752
|
sourcePageSegments: __activeIntercept?.slotKey === __SIBLING_PAGE_INTERCEPT_SLOT_KEY
|
|
@@ -739,7 +755,11 @@ const __appRscHandler = createAppRscHandler({
|
|
|
739
755
|
}, errorOrigin);
|
|
740
756
|
},
|
|
741
757
|
renderHttpAccessFallbackPage(statusCode, opts, currentMiddlewareContext) {
|
|
742
|
-
const __activeIntercept = findIntercept(
|
|
758
|
+
const __activeIntercept = findIntercept(
|
|
759
|
+
interceptionPathname,
|
|
760
|
+
interceptionContext,
|
|
761
|
+
interceptionId,
|
|
762
|
+
);
|
|
743
763
|
return __fallbackRenderer.renderHttpAccessFallback(route, statusCode, isRscRequest, request, opts, scriptNonce, currentMiddlewareContext, {
|
|
744
764
|
isEdgeRuntime: __isEdgeRuntime(__segmentConfig.runtime),
|
|
745
765
|
routePathname: cleanPathname,
|
|
@@ -1133,7 +1153,11 @@ const __appRscHandler = createAppRscHandler({
|
|
|
1133
1153
|
params[name] = intercept.sourceMatchedParams[name];
|
|
1134
1154
|
}
|
|
1135
1155
|
}
|
|
1136
|
-
return {
|
|
1156
|
+
return {
|
|
1157
|
+
interceptionSourceIsConcrete: intercept.sourceRouteIsConcrete,
|
|
1158
|
+
route,
|
|
1159
|
+
params,
|
|
1160
|
+
};
|
|
1137
1161
|
},
|
|
1138
1162
|
${middlewarePath ? `runMiddleware({ cleanPathname, context, externalRewriteRequest, hadBasePath, isDataRequest, middlewareRequest, request, validateExternalRewriteRequest }) {
|
|
1139
1163
|
return __applyAppMiddleware({
|
|
@@ -296,6 +296,7 @@ function buildGenerateStaticParamsEntries(routes, imports, namesByPattern) {
|
|
|
296
296
|
if (!route.isDynamic) continue;
|
|
297
297
|
for (const [index, layoutPath] of route.layouts.entries()) appendStaticParamSource(sourcesByPattern, createRoutePatternPrefix(route.routeSegments, route.layoutTreePositions[index] ?? 0)?.pattern ?? null, `{ load: ${imports.getLazyLoaderVar(layoutPath)} }`);
|
|
298
298
|
if (route.pagePath) appendStaticParamSource(sourcesByPattern, route.pattern, `{ load: ${imports.getLazyLoaderVar(route.pagePath)} }`);
|
|
299
|
+
if (!route.pagePath && route.routePath) appendStaticParamSource(sourcesByPattern, route.pattern, `{ load: ${imports.getLazyLoaderVar(route.routePath)} }`);
|
|
299
300
|
}
|
|
300
301
|
return Array.from(sourcesByPattern.entries()).map(([pattern, sources]) => {
|
|
301
302
|
const rootParamNames = namesByPattern.get(pattern) ?? [];
|
|
@@ -5,6 +5,6 @@ import { ResolvedNextConfig } from "../config/next-config.js";
|
|
|
5
5
|
* Generate the virtual SSR server entry module.
|
|
6
6
|
* This is the entry point for `vite build --ssr`.
|
|
7
7
|
*/
|
|
8
|
-
declare function generateServerEntry(pagesDir: string, nextConfig: ResolvedNextConfig, fileMatcher: ReturnType<typeof createValidFileMatcher>, middlewarePath: string | null, instrumentationPath: string | null, publicFiles?: string[]): Promise<string>;
|
|
8
|
+
declare function generateServerEntry(pagesDir: string, nextConfig: ResolvedNextConfig, fileMatcher: ReturnType<typeof createValidFileMatcher>, middlewarePath: string | null, instrumentationPath: string | null, publicFiles?: string[], prerenderSecret?: string): Promise<string>;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { generateServerEntry };
|
|
@@ -35,7 +35,7 @@ async function getPagesDataKind(filePath) {
|
|
|
35
35
|
* Generate the virtual SSR server entry module.
|
|
36
36
|
* This is the entry point for `vite build --ssr`.
|
|
37
37
|
*/
|
|
38
|
-
async function generateServerEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles = []) {
|
|
38
|
+
async function generateServerEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles = [], prerenderSecret) {
|
|
39
39
|
const pageRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
40
40
|
const apiRoutes = await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
41
41
|
const pageImports = pageRoutes.map((r, i) => `import * as page_${i} from ${JSON.stringify(r.filePath)};`);
|
|
@@ -173,6 +173,9 @@ const i18nConfig = ${i18nConfigJson};
|
|
|
173
173
|
// match _next/data requests against the embedded buildId without needing
|
|
174
174
|
// to load next.config.js at runtime.
|
|
175
175
|
export const buildId = ${buildIdJson};
|
|
176
|
+
// Per-build capability used by Worker entries to authorize remote path
|
|
177
|
+
// discovery. It is never included in responses or exposed to user modules.
|
|
178
|
+
export const prerenderSecret = ${JSON.stringify(prerenderSecret ?? null)};
|
|
176
179
|
export function normalizeDataRequest(request) {
|
|
177
180
|
return __normalizePagesDataRequest(
|
|
178
181
|
request,
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,9 @@ type VinextOptions = {
|
|
|
61
61
|
* Enabled by default. Set to `false` to disable (e.g. if you configure
|
|
62
62
|
* @vitejs/plugin-react manually in your vite.config.ts), or pass an options
|
|
63
63
|
* object to customize the Babel transform.
|
|
64
|
+
*
|
|
65
|
+
* Pass `{ compiler: true }` to enable the React Compiler. That requires
|
|
66
|
+
* @vitejs/plugin-react 6.1+ and the optional `oxc-transform-react` package.
|
|
64
67
|
* @default true
|
|
65
68
|
*/
|
|
66
69
|
react?: Options | boolean;
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ import { getPagesPreviewModeId } from "./server/pages-preview.js";
|
|
|
28
28
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
29
29
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
30
30
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
31
|
+
import { CACHEABILITY_MANIFEST_MODULE } from "./server/cacheability-manifest.js";
|
|
31
32
|
import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
|
|
32
33
|
import { isPathInside, isPathInsideOrEqual, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
33
34
|
import { invalidateMetadataFileCache, scanMetadataFiles } from "./server/metadata-routes.js";
|
|
@@ -37,7 +38,7 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
|
37
38
|
import { createActionOwnerManifestPlugin } from "./plugins/action-owner-manifest.js";
|
|
38
39
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
39
40
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
40
|
-
import { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
41
|
+
import { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule, hasVerbatimResponseVary } from "./cache/cache-adapters-virtual.js";
|
|
41
42
|
import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
|
|
42
43
|
import { generateBrowserEntry, toLinkPrefetchRoutes } from "./entries/app-browser-entry.js";
|
|
43
44
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
@@ -55,6 +56,7 @@ import { readTrustedRevalidationHostname } from "./server/revalidation-host.js";
|
|
|
55
56
|
import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
|
|
56
57
|
import { runPagesRequest } from "./server/pages-request-pipeline.js";
|
|
57
58
|
import { pagesRouteHasPriorityOverAppRoute, validateHybridRouteConflicts } from "./server/hybrid-route-priority.js";
|
|
59
|
+
import { hasReactCompilerPlugin, isReactCompilerPlugin, isReactCompilerRequested, reactCompilerUnsupportedMessage } from "./utils/react-compiler-support.js";
|
|
58
60
|
import { VIRTUAL_MODULE_ID_RE } from "./utils/virtual-module.js";
|
|
59
61
|
import { assertNoPublicDirAssetConflict, assertNoPublicNextRequestConflict } from "./build/public-dir-conflict.js";
|
|
60
62
|
import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
|
|
@@ -68,6 +70,7 @@ import { createInstrumentationClientTransformPlugin } from "./plugins/instrument
|
|
|
68
70
|
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
69
71
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
70
72
|
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
73
|
+
import { isServerEnvironment } from "./plugins/environment.js";
|
|
71
74
|
import { createPagesNodeExternalsPlugin } from "./plugins/pages-node-externals.js";
|
|
72
75
|
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
73
76
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
@@ -627,6 +630,8 @@ const VIRTUAL_PAGES_CLIENT_ASSETS = "virtual:vinext-pages-client-assets";
|
|
|
627
630
|
const RESOLVED_PAGES_CLIENT_ASSETS = "\0virtual:vinext-pages-client-assets";
|
|
628
631
|
const VIRTUAL_RSC_ENTRY = "virtual:vinext-rsc-entry";
|
|
629
632
|
const RESOLVED_RSC_ENTRY = "\0virtual:vinext-rsc-entry";
|
|
633
|
+
const VIRTUAL_CACHEABILITY_MANIFEST = "virtual:vinext-cacheability-manifest";
|
|
634
|
+
const RESOLVED_CACHEABILITY_MANIFEST = "\0virtual:vinext-cacheability-manifest";
|
|
630
635
|
const VIRTUAL_APP_SSR_ENTRY = "virtual:vinext-app-ssr-entry";
|
|
631
636
|
const RESOLVED_APP_SSR_ENTRY = "\0virtual:vinext-app-ssr-entry";
|
|
632
637
|
const VIRTUAL_APP_BROWSER_ENTRY = "virtual:vinext-app-browser-entry";
|
|
@@ -768,6 +773,7 @@ function createServerEnvironmentFileNameResolver(config, outputRoot) {
|
|
|
768
773
|
function vinext(options = {}) {
|
|
769
774
|
const { supportsNativeTypeofWindowFolding: useNativeTypeofWindowFolding } = assertSupportedViteVersion();
|
|
770
775
|
const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
|
|
776
|
+
const cacheAdapterBuildOutputs = [options.cache?.data?.output, options.cache?.cdn?.output].filter((output) => output !== void 0);
|
|
771
777
|
let root;
|
|
772
778
|
let pagesDir;
|
|
773
779
|
let canonicalPagesDir;
|
|
@@ -801,13 +807,26 @@ function vinext(options = {}) {
|
|
|
801
807
|
let pagesClientAssetsModule = null;
|
|
802
808
|
let devPublicFileRoutes = null;
|
|
803
809
|
let publicDirConflictOptions = null;
|
|
810
|
+
let copyPublicDirIntoStaticExportBasePath = false;
|
|
811
|
+
let rscBuildIdentity;
|
|
804
812
|
let rscCompatibilityId;
|
|
805
813
|
let draftModeSecret = getPagesPreviewModeId();
|
|
814
|
+
const prerenderSecret = process.env.__VINEXT_SHARED_PRERENDER_SECRET ?? randomBytes(32).toString("hex");
|
|
806
815
|
let previewBuildCredentials;
|
|
807
816
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
808
817
|
let rscClassificationManifest = null;
|
|
809
818
|
let rscActionOwnerRoutes = null;
|
|
810
819
|
let rscActionOwnerSharedRoots = [];
|
|
820
|
+
const serverEntryKindsByEnvironment = /* @__PURE__ */ new Map();
|
|
821
|
+
function recordServerEntryLoad(environmentName, id) {
|
|
822
|
+
if (!environmentName) return;
|
|
823
|
+
let entries = serverEntryKindsByEnvironment.get(environmentName);
|
|
824
|
+
if (!entries) {
|
|
825
|
+
entries = /* @__PURE__ */ new Set();
|
|
826
|
+
serverEntryKindsByEnvironment.set(environmentName, entries);
|
|
827
|
+
}
|
|
828
|
+
entries.add(id);
|
|
829
|
+
}
|
|
811
830
|
const shimsDir = path.resolve(__dirname, "shims");
|
|
812
831
|
const canonicalize = (p) => toSlash(tryRealpathSync(p) ?? p);
|
|
813
832
|
const pageTransformCanonicalPaths = /* @__PURE__ */ new Map();
|
|
@@ -835,7 +854,7 @@ function vinext(options = {}) {
|
|
|
835
854
|
*/
|
|
836
855
|
async function generateServerEntry$1(configuredPublicDir) {
|
|
837
856
|
const publicFiles = isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, configuredPublicDir === "" ? false : configuredPublicDir);
|
|
838
|
-
return generateServerEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles);
|
|
857
|
+
return generateServerEntry(pagesDir, nextConfig, fileMatcher, middlewarePath, instrumentationPath, publicFiles, prerenderSecret);
|
|
839
858
|
}
|
|
840
859
|
/**
|
|
841
860
|
* Generate the virtual client hydration entry module.
|
|
@@ -915,9 +934,12 @@ function vinext(options = {}) {
|
|
|
915
934
|
const configuredReactOptions = options.react && options.react !== true ? options.react : void 0;
|
|
916
935
|
const reactOptions = configuredReactOptions;
|
|
917
936
|
let reactPluginPromise = null;
|
|
937
|
+
let reactCompilerPluginPromise = null;
|
|
918
938
|
if (options.react !== false) {
|
|
919
939
|
if (!resolvedReactPath) throw new Error("vinext: @vitejs/plugin-react is not installed.\nRun: " + detectPackageManager(process.cwd()) + " @vitejs/plugin-react");
|
|
920
|
-
|
|
940
|
+
const allReactPlugins = import(pathToFileURL(resolvedReactPath).href).catch((cause) => {
|
|
941
|
+
throw new Error("vinext: Failed to load @vitejs/plugin-react.", { cause });
|
|
942
|
+
}).then((mod) => {
|
|
921
943
|
const react = mod.default;
|
|
922
944
|
const limitToCommand = (plugin, command) => {
|
|
923
945
|
const originalApply = plugin.apply;
|
|
@@ -931,15 +953,17 @@ function vinext(options = {}) {
|
|
|
931
953
|
}
|
|
932
954
|
};
|
|
933
955
|
};
|
|
934
|
-
const
|
|
956
|
+
const resolvedBuildPlugins = react(reactOptions);
|
|
957
|
+
if (isReactCompilerRequested(configuredReactOptions) && !hasReactCompilerPlugin(resolvedBuildPlugins)) throw new Error(reactCompilerUnsupportedMessage(detectPackageManager(process.cwd())));
|
|
958
|
+
const buildPlugins = resolvedBuildPlugins.map((plugin) => limitToCommand(plugin, "build"));
|
|
935
959
|
const servePlugins = react(configuredReactOptions !== void 0 && Object.prototype.hasOwnProperty.call(configuredReactOptions, "include") ? reactOptions : {
|
|
936
960
|
...reactOptions,
|
|
937
961
|
include: /\.(?:[tj]sx?|mdx)$/i
|
|
938
962
|
}).map((plugin) => limitToCommand(plugin, "serve"));
|
|
939
963
|
return [...buildPlugins, ...servePlugins];
|
|
940
|
-
}).catch((cause) => {
|
|
941
|
-
throw new Error("vinext: Failed to load @vitejs/plugin-react.", { cause });
|
|
942
964
|
});
|
|
965
|
+
reactPluginPromise = allReactPlugins.then((plugins) => plugins.filter((plugin) => !isReactCompilerPlugin(plugin)));
|
|
966
|
+
reactCompilerPluginPromise = allReactPlugins.then((plugins) => plugins.filter(isReactCompilerPlugin));
|
|
943
967
|
}
|
|
944
968
|
const imageImportDimCache = /* @__PURE__ */ new Map();
|
|
945
969
|
const staticImageAssets = /* @__PURE__ */ new Map();
|
|
@@ -1075,6 +1099,7 @@ function vinext(options = {}) {
|
|
|
1075
1099
|
}
|
|
1076
1100
|
}
|
|
1077
1101
|
},
|
|
1102
|
+
reactCompilerPluginPromise,
|
|
1078
1103
|
createMiddlewareServerOnlyPlugin({
|
|
1079
1104
|
getMiddlewarePath: () => middlewarePath,
|
|
1080
1105
|
getCanonicalMiddlewarePath: () => middlewarePath ? tryRealpathSync(middlewarePath) ?? middlewarePath : null,
|
|
@@ -1172,6 +1197,10 @@ function vinext(options = {}) {
|
|
|
1172
1197
|
const sharedRscCompatibilityId = process.env.__VINEXT_SHARED_RSC_COMPATIBILITY_ID;
|
|
1173
1198
|
rscCompatibilityId = sharedRscCompatibilityId && sharedRscCompatibilityId.length > 0 ? sharedRscCompatibilityId : createRscCompatibilityId(nextConfig);
|
|
1174
1199
|
}
|
|
1200
|
+
if (env?.command === "build" && rscBuildIdentity === void 0) {
|
|
1201
|
+
const sharedRscBuildIdentity = process.env.__VINEXT_SHARED_RSC_BUILD_IDENTITY;
|
|
1202
|
+
rscBuildIdentity = sharedRscBuildIdentity && sharedRscBuildIdentity.length > 0 ? sharedRscBuildIdentity : randomBytes(16).toString("hex");
|
|
1203
|
+
}
|
|
1175
1204
|
fileMatcher = createValidFileMatcher(nextConfig.pageExtensions);
|
|
1176
1205
|
globalNotFoundCssIsolationPath = env?.command === "build" && nextConfig.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
1177
1206
|
instrumentationPath = findInstrumentationFile(root, fileMatcher);
|
|
@@ -1208,6 +1237,7 @@ function vinext(options = {}) {
|
|
|
1208
1237
|
defines["process.env.__NEXT_TEST_MODE"] = JSON.stringify(process.env.__NEXT_TEST_MODE ?? false);
|
|
1209
1238
|
defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
|
|
1210
1239
|
defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
|
|
1240
|
+
defines["process.env.__NEXT_CONFIG_OUTPUT"] = JSON.stringify(nextConfig.output ?? "");
|
|
1211
1241
|
defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
|
|
1212
1242
|
defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
|
|
1213
1243
|
{
|
|
@@ -1230,7 +1260,9 @@ function vinext(options = {}) {
|
|
|
1230
1260
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
|
|
1231
1261
|
defines["process.env.__VINEXT_IMAGE_UNOPTIMIZED"] = JSON.stringify(String(nextConfig.images?.unoptimized === true));
|
|
1232
1262
|
defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
|
|
1263
|
+
defines["process.env.__VINEXT_CANONICAL_RSC_REQUESTS"] = JSON.stringify(env?.command === "build" && hasVerbatimResponseVary(options.cache) ? "1" : "");
|
|
1233
1264
|
defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
|
|
1265
|
+
defines["process.env.__VINEXT_RSC_BUILD_IDENTITY"] = JSON.stringify(rscBuildIdentity ?? "");
|
|
1234
1266
|
defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
|
|
1235
1267
|
defines["process.env.NEXT_DEPLOYMENT_ID"] = nextConfig.deploymentId ? JSON.stringify(nextConfig.deploymentId) : "false";
|
|
1236
1268
|
defines["process.env.NEXT_RUNTIME"] = "\"\"";
|
|
@@ -1581,6 +1613,11 @@ function vinext(options = {}) {
|
|
|
1581
1613
|
return viteConfig;
|
|
1582
1614
|
},
|
|
1583
1615
|
configEnvironment(name, config) {
|
|
1616
|
+
if (name === "client" && nextConfig.output === "export" && nextConfig.basePath) {
|
|
1617
|
+
config.build ??= {};
|
|
1618
|
+
copyPublicDirIntoStaticExportBasePath = config.build.copyPublicDir !== false;
|
|
1619
|
+
config.build.copyPublicDir = false;
|
|
1620
|
+
}
|
|
1584
1621
|
if (name !== "client" && config.consumer !== "client") {
|
|
1585
1622
|
config.optimizeDeps ??= {};
|
|
1586
1623
|
config.optimizeDeps.rolldownOptions ??= {};
|
|
@@ -1664,6 +1701,26 @@ function vinext(options = {}) {
|
|
|
1664
1701
|
assertNoPublicDirAssetConflict(publicDirConflictOptions);
|
|
1665
1702
|
}
|
|
1666
1703
|
},
|
|
1704
|
+
writeBundle: {
|
|
1705
|
+
sequential: true,
|
|
1706
|
+
order: "post",
|
|
1707
|
+
handler(outputOptions) {
|
|
1708
|
+
if (this.environment?.name !== "client" || nextConfig.output !== "export" || !nextConfig.basePath || !copyPublicDirIntoStaticExportBasePath) return;
|
|
1709
|
+
const envConfig = this.environment.config;
|
|
1710
|
+
const publicDir = envConfig.publicDir;
|
|
1711
|
+
if (!publicDir || !fs.existsSync(publicDir)) return;
|
|
1712
|
+
if (publicDirConflictOptions) assertNoPublicDirAssetConflict(publicDirConflictOptions);
|
|
1713
|
+
const buildRoot = envConfig.root ?? process.cwd();
|
|
1714
|
+
const clientOutDir = outputOptions.dir ? path.resolve(buildRoot, outputOptions.dir) : path.resolve(buildRoot, envConfig.build.outDir);
|
|
1715
|
+
const basePathDir = path.join(clientOutDir, nextConfig.basePath.slice(1));
|
|
1716
|
+
fs.mkdirSync(basePathDir, { recursive: true });
|
|
1717
|
+
fs.cpSync(publicDir, basePathDir, {
|
|
1718
|
+
recursive: true,
|
|
1719
|
+
dereference: true,
|
|
1720
|
+
force: true
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
},
|
|
1667
1724
|
resolveId: {
|
|
1668
1725
|
filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/app-rsc-handler)|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
|
|
1669
1726
|
handler(id, importer) {
|
|
@@ -1684,6 +1741,13 @@ function vinext(options = {}) {
|
|
|
1684
1741
|
if (cleanId.endsWith("/virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
|
|
1685
1742
|
if (cleanId.endsWith("/virtual:vinext-client-entry")) return RESOLVED_CLIENT_ENTRY;
|
|
1686
1743
|
if (cleanId === VIRTUAL_RSC_ENTRY) return RESOLVED_RSC_ENTRY;
|
|
1744
|
+
if (cleanId === VIRTUAL_CACHEABILITY_MANIFEST) {
|
|
1745
|
+
if ((hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment)) && this.environment.config?.command === "build") return {
|
|
1746
|
+
id: `./${CACHEABILITY_MANIFEST_MODULE}`,
|
|
1747
|
+
external: true
|
|
1748
|
+
};
|
|
1749
|
+
return RESOLVED_CACHEABILITY_MANIFEST;
|
|
1750
|
+
}
|
|
1687
1751
|
if (cleanId === VIRTUAL_APP_SSR_ENTRY) return RESOLVED_APP_SSR_ENTRY;
|
|
1688
1752
|
if (cleanId === VIRTUAL_APP_BROWSER_ENTRY) return RESOLVED_APP_BROWSER_ENTRY;
|
|
1689
1753
|
if (cleanId === VIRTUAL_APP_CAPABILITIES) return RESOLVED_APP_CAPABILITIES;
|
|
@@ -1709,7 +1773,10 @@ function vinext(options = {}) {
|
|
|
1709
1773
|
filter: { id: /virtual:vinext-/ },
|
|
1710
1774
|
async handler(id) {
|
|
1711
1775
|
if (id === RESOLVED_WORKER_ENTRY) return `export { default } from ${JSON.stringify(hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry")};`;
|
|
1712
|
-
if (id === RESOLVED_SERVER_ENTRY)
|
|
1776
|
+
if (id === RESOLVED_SERVER_ENTRY) {
|
|
1777
|
+
recordServerEntryLoad(this.environment?.name, id);
|
|
1778
|
+
return await generateServerEntry$1(this.environment.config.publicDir === "" ? false : this.environment.config.publicDir);
|
|
1779
|
+
}
|
|
1713
1780
|
if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
|
|
1714
1781
|
if (id === RESOLVED_PAGES_CLIENT_ASSETS) {
|
|
1715
1782
|
const metadata = { clientEntry: DEV_PAGES_CLIENT_ENTRY };
|
|
@@ -1725,7 +1792,9 @@ function vinext(options = {}) {
|
|
|
1725
1792
|
if (Object.keys(ssrManifest).length > 0) metadata.ssrManifest = ssrManifest;
|
|
1726
1793
|
return `export default ${JSON.stringify(metadata)};`;
|
|
1727
1794
|
}
|
|
1795
|
+
if (id === RESOLVED_CACHEABILITY_MANIFEST) return "export default null;";
|
|
1728
1796
|
if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
|
|
1797
|
+
recordServerEntryLoad(this.environment?.name, id);
|
|
1729
1798
|
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1730
1799
|
const metaRoutes = scanMetadataFiles(appDir);
|
|
1731
1800
|
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
@@ -1767,13 +1836,17 @@ function vinext(options = {}) {
|
|
|
1767
1836
|
hasPagesDir,
|
|
1768
1837
|
publicFiles: isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, this.environment.config.publicDir === "" ? false : this.environment.config.publicDir),
|
|
1769
1838
|
globalNotFoundPath,
|
|
1770
|
-
draftModeSecret
|
|
1839
|
+
draftModeSecret,
|
|
1840
|
+
prerenderSecret
|
|
1771
1841
|
}, instrumentationPath);
|
|
1772
1842
|
}
|
|
1773
1843
|
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
1774
1844
|
if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
|
|
1775
1845
|
if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
|
|
1776
|
-
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir)
|
|
1846
|
+
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) {
|
|
1847
|
+
recordServerEntryLoad(this.environment?.name, id);
|
|
1848
|
+
return generateSsrEntry(hasPagesDir);
|
|
1849
|
+
}
|
|
1777
1850
|
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
|
|
1778
1851
|
const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1779
1852
|
const pagesPrefetchRoutes = hasPagesDir ? [...(await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
|
|
@@ -1786,7 +1859,7 @@ function vinext(options = {}) {
|
|
|
1786
1859
|
isDynamic: route.isDynamic,
|
|
1787
1860
|
patternParts: [...route.patternParts]
|
|
1788
1861
|
}))] : [];
|
|
1789
|
-
return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites);
|
|
1862
|
+
return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites, nextConfig.i18n?.locales);
|
|
1790
1863
|
}
|
|
1791
1864
|
if (id === RESOLVED_APP_CAPABILITIES && hasAppDir) {
|
|
1792
1865
|
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
@@ -1907,6 +1980,18 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1907
1980
|
return null;
|
|
1908
1981
|
}
|
|
1909
1982
|
},
|
|
1983
|
+
{
|
|
1984
|
+
name: "vinext:cacheability-manifest-asset",
|
|
1985
|
+
apply: "build",
|
|
1986
|
+
generateBundle() {
|
|
1987
|
+
if (!(hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment))) return;
|
|
1988
|
+
this.emitFile({
|
|
1989
|
+
type: "asset",
|
|
1990
|
+
fileName: CACHEABILITY_MANIFEST_MODULE,
|
|
1991
|
+
source: "export default null;\n"
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
},
|
|
1910
1995
|
{
|
|
1911
1996
|
name: "vinext:css-url-assets-restore",
|
|
1912
1997
|
enforce: "post",
|
|
@@ -2914,6 +2999,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2914
2999
|
if (name === "client") return null;
|
|
2915
3000
|
const serverDefines = { ...nextConfig.compilerDefineServer };
|
|
2916
3001
|
serverDefines["process.env.NEXT_RUNTIME"] = JSON.stringify("nodejs");
|
|
3002
|
+
serverDefines["process.env.NEXT_PHASE"] = "globalThis.__VINEXT_NEXT_PHASE";
|
|
2917
3003
|
const sharedRevalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
|
|
2918
3004
|
if (sharedRevalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(sharedRevalidateSecret);
|
|
2919
3005
|
if (previewBuildCredentials) {
|
|
@@ -3095,6 +3181,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3095
3181
|
const outDir = path.join(root, "dist", "server");
|
|
3096
3182
|
fs.mkdirSync(outDir, { recursive: true });
|
|
3097
3183
|
fs.writeFileSync(path.join(outDir, "BUILD_ID"), nextConfig.buildId);
|
|
3184
|
+
if (rscBuildIdentity) fs.writeFileSync(path.join(outDir, "RSC_BUILD_ID"), rscBuildIdentity);
|
|
3098
3185
|
}
|
|
3099
3186
|
}
|
|
3100
3187
|
};
|
|
@@ -3108,26 +3195,30 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3108
3195
|
if (salt) return salt;
|
|
3109
3196
|
}
|
|
3110
3197
|
},
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3198
|
+
{
|
|
3199
|
+
name: "vinext:server-manifest",
|
|
3200
|
+
apply: "build",
|
|
3201
|
+
enforce: "post",
|
|
3202
|
+
writeBundle: {
|
|
3203
|
+
sequential: true,
|
|
3204
|
+
order: "post",
|
|
3205
|
+
handler(options) {
|
|
3206
|
+
const environment = this.environment;
|
|
3207
|
+
if (!environment || (hasAppDir ? environment.name !== "rsc" : !isServerEnvironment(environment))) return;
|
|
3208
|
+
const outDir = options.dir;
|
|
3209
|
+
if (!outDir) return;
|
|
3210
|
+
const source = JSON.stringify({ prerenderSecret });
|
|
3211
|
+
fs.writeFileSync(path.join(outDir, "vinext-server.json"), source);
|
|
3212
|
+
if (!hasAppDir) {
|
|
3213
|
+
const canonicalServerDir = path.join(root, "dist", "server");
|
|
3214
|
+
if (path.resolve(outDir) !== canonicalServerDir) {
|
|
3215
|
+
fs.mkdirSync(canonicalServerDir, { recursive: true });
|
|
3216
|
+
fs.writeFileSync(path.join(canonicalServerDir, "vinext-server.json"), source);
|
|
3217
|
+
}
|
|
3127
3218
|
}
|
|
3128
3219
|
}
|
|
3129
|
-
}
|
|
3130
|
-
}
|
|
3220
|
+
}
|
|
3221
|
+
},
|
|
3131
3222
|
{
|
|
3132
3223
|
name: "vinext:nitro-route-rules",
|
|
3133
3224
|
nitro: { setup: async (nitro) => {
|
|
@@ -3418,6 +3509,33 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3418
3509
|
}
|
|
3419
3510
|
}
|
|
3420
3511
|
];
|
|
3512
|
+
if (cacheAdapterBuildOutputs.length > 0) plugins.push({
|
|
3513
|
+
name: "vinext:cache-adapter-build-output",
|
|
3514
|
+
apply: "build",
|
|
3515
|
+
enforce: "post",
|
|
3516
|
+
writeBundle: {
|
|
3517
|
+
sequential: true,
|
|
3518
|
+
order: "post",
|
|
3519
|
+
async handler(outputOptions) {
|
|
3520
|
+
if (!outputOptions.dir) return;
|
|
3521
|
+
const config = this.environment?.config;
|
|
3522
|
+
if (!config) return;
|
|
3523
|
+
const build = { plugins: config.plugins };
|
|
3524
|
+
const buildRoot = config.root ?? process.cwd();
|
|
3525
|
+
const outDir = path.resolve(buildRoot, outputOptions.dir);
|
|
3526
|
+
const loadedEntries = serverEntryKindsByEnvironment.get(this.environment?.name ?? "");
|
|
3527
|
+
const isPrimaryServerOutput = Boolean(loadedEntries?.has(RESOLVED_RSC_ENTRY) || loadedEntries?.has(RESOLVED_SERVER_ENTRY) && !loadedEntries.has(RESOLVED_APP_SSR_ENTRY));
|
|
3528
|
+
for (const output of cacheAdapterBuildOutputs) {
|
|
3529
|
+
if (output.matchesBuild && !output.matchesBuild(build)) continue;
|
|
3530
|
+
await output.finalizeBuildOutput?.({
|
|
3531
|
+
root: buildRoot,
|
|
3532
|
+
outDir,
|
|
3533
|
+
isPrimaryServerOutput
|
|
3534
|
+
});
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
});
|
|
3421
3539
|
if (rscPluginPromise) plugins.push(rscPluginPromise);
|
|
3422
3540
|
if (earlyAppDirExists) plugins.push(createActionOwnerManifestPlugin({
|
|
3423
3541
|
canonicalizeModuleId: canonicalize,
|
|
@@ -28,17 +28,19 @@ declare function updateWranglerConfigForCloudflare(code: string, options: Cloudf
|
|
|
28
28
|
root?: string;
|
|
29
29
|
}): string;
|
|
30
30
|
declare function getWranglerImagesBinding(code: string): string;
|
|
31
|
+
declare function getWranglerVersionMetadataBinding(code: string): string;
|
|
31
32
|
/** Generate vite.config.ts for App Router */
|
|
32
|
-
declare function generateAppRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, prerender?: boolean): string;
|
|
33
|
+
declare function generateAppRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, prerender?: boolean, versionMetadataBinding?: string): string;
|
|
33
34
|
/** Generate vite.config.ts for Pages Router */
|
|
34
|
-
declare function generatePagesRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, prerender?: boolean): string;
|
|
35
|
+
declare function generatePagesRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, prerender?: boolean, versionMetadataBinding?: string): string;
|
|
35
36
|
declare function updateViteConfigForCloudflare(filePath: string, code: string, options: {
|
|
36
37
|
isAppRouter: boolean;
|
|
37
38
|
nativeModulesToStub: string[];
|
|
38
39
|
cache?: CloudflareInitOptions;
|
|
39
40
|
imagesBinding?: string;
|
|
41
|
+
versionMetadataBinding?: string;
|
|
40
42
|
prerender?: boolean;
|
|
41
43
|
}): string;
|
|
42
44
|
declare function usesCommonJsViteConfig(filePath: string, code: string): boolean;
|
|
43
45
|
//#endregion
|
|
44
|
-
export { CloudflarePlatformSetupContext, CloudflarePlatformSetupResult, CloudflareProjectInfo, generateAppRouterViteConfig, generatePagesRouterViteConfig, generateWranglerConfig, getWranglerImagesBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|
|
46
|
+
export { CloudflarePlatformSetupContext, CloudflarePlatformSetupResult, CloudflareProjectInfo, generateAppRouterViteConfig, generatePagesRouterViteConfig, generateWranglerConfig, getWranglerImagesBinding, getWranglerVersionMetadataBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|