vinext 1.1.0 → 1.2.0
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 +21 -9
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/pages-client-assets-module.d.ts +8 -0
- package/dist/build/pages-client-assets-module.js +21 -1
- package/dist/build/prerender-paths.js +5 -3
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/ssr-manifest.d.ts +2 -0
- package/dist/build/ssr-manifest.js +6 -2
- package/dist/check.js +7 -6
- package/dist/cli.js +2 -1
- package/dist/client/client-redirect-matcher.d.ts +14 -0
- package/dist/client/client-redirect-matcher.js +37 -0
- package/dist/client/client-redirects.d.ts +27 -0
- package/dist/client/client-redirects.js +28 -0
- package/dist/client/client-rewrites.d.ts +2 -1
- package/dist/client/client-rewrites.js +1 -1
- package/dist/config/config-matchers.d.ts +26 -11
- package/dist/config/config-matchers.js +78 -81
- package/dist/config/destination-params.d.ts +47 -0
- package/dist/config/destination-params.js +116 -0
- package/dist/config/next-config.d.ts +7 -0
- package/dist/config/next-config.js +3 -0
- package/dist/entries/app-rsc-entry.d.ts +4 -0
- package/dist/entries/app-rsc-entry.js +20 -6
- package/dist/entries/pages-client-entry.js +3 -1
- package/dist/entries/pages-server-entry.js +13 -37
- package/dist/index.d.ts +3 -1
- package/dist/index.js +134 -43
- package/dist/init-cloudflare.d.ts +9 -0
- package/dist/init-cloudflare.js +107 -31
- package/dist/init-platform.d.ts +4 -0
- package/dist/init-platform.js +27 -2
- package/dist/init.d.ts +1 -0
- package/dist/init.js +67 -3
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/cache-flight-codec.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +9 -8
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +3 -4
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/pages-node-externals.js +1 -1
- package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
- package/dist/plugins/rsc-scan-glob-imports.js +50 -0
- package/dist/plugins/strip-server-exports.js +262 -98
- package/dist/plugins/transform-result.d.ts +9 -5
- package/dist/plugins/transitive-externals.js +1 -1
- package/dist/plugins/typeof-window.d.ts +2 -2
- package/dist/plugins/use-cache-callable.js +8 -2
- package/dist/plugins/worker-server-only-imports.d.ts +20 -0
- package/dist/plugins/worker-server-only-imports.js +31 -0
- package/dist/plugins/worker-use-server.d.ts +25 -0
- package/dist/plugins/worker-use-server.js +129 -0
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +2 -1
- package/dist/server/app-browser-action-result.d.ts +1 -1
- package/dist/server/app-browser-action-result.js +9 -2
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +17 -2
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js +1 -1
- package/dist/server/app-page-dispatch.d.ts +3 -1
- package/dist/server/app-page-dispatch.js +4 -3
- package/dist/server/app-page-ppr-runtime.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-request.js +53 -15
- package/dist/server/app-page-route-wiring.js +2 -2
- package/dist/server/app-pages-bridge.d.ts +1 -1
- package/dist/server/app-pages-bridge.js +2 -3
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-request-stage-dispatch.js +6 -2
- package/dist/server/app-request-stage-independent-entry.js +25 -5
- package/dist/server/app-response-stage-entry.js +10 -2
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +1 -0
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +5 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +45 -24
- package/dist/server/app-router-entry.js +24 -5
- package/dist/server/app-rsc-cache-busting.js +1 -1
- package/dist/server/app-rsc-errors.js +20 -16
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +85 -35
- package/dist/server/app-rsc-response-stage.js +4 -2
- package/dist/server/app-segment-config.d.ts +2 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +61 -22
- package/dist/server/app-ssr-entry.js +2 -1
- package/dist/server/app-worker-stages.d.ts +5 -0
- package/dist/server/app-worker-stages.js +1 -1
- package/dist/server/cacheability-request.js +2 -2
- package/dist/server/client-build-files.d.ts +16 -0
- package/dist/server/client-build-files.js +36 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/dev-server.js +38 -27
- package/dist/server/dev-stack-sourcemap.js +18 -23
- package/dist/server/document-initial-head.d.ts +0 -11
- package/dist/server/document-initial-head.js +1 -1
- package/dist/server/forwarded-middleware-context.d.ts +5 -0
- package/dist/server/forwarded-middleware-context.js +22 -0
- package/dist/server/headers.d.ts +4 -1
- package/dist/server/headers.js +4 -1
- package/dist/server/http-conditional.d.ts +11 -0
- package/dist/server/http-conditional.js +10 -1
- package/dist/server/http-error-responses.d.ts +1 -1
- package/dist/server/image-optimization.d.ts +38 -0
- package/dist/server/image-optimization.js +93 -4
- package/dist/server/isr-cache.d.ts +10 -0
- package/dist/server/isr-cache.js +41 -6
- package/dist/server/metadata-route-response.js +9 -8
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +33 -20
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +3 -1
- package/dist/server/multi-stage.d.ts +11 -0
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +4 -3
- package/dist/server/pages-cache-tag.d.ts +12 -0
- package/dist/server/pages-cache-tag.js +19 -0
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-data-route.d.ts +10 -0
- package/dist/server/pages-data-route.js +19 -2
- package/dist/server/pages-document-asset-props.d.ts +5 -1
- package/dist/server/pages-document-asset-props.js +13 -5
- package/dist/server/pages-document-splice.d.ts +19 -0
- package/dist/server/pages-document-splice.js +55 -0
- package/dist/server/pages-i18n.d.ts +12 -1
- package/dist/server/pages-i18n.js +18 -4
- package/dist/server/pages-node-compat.d.ts +16 -5
- package/dist/server/pages-node-compat.js +20 -12
- package/dist/server/pages-page-data.d.ts +32 -24
- package/dist/server/pages-page-data.js +50 -120
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +188 -126
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +41 -34
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +37 -18
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +71 -12
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/pages-router-entry.js +4 -3
- package/dist/server/prerender-manifest.d.ts +3 -3
- package/dist/server/prerender-manifest.js +4 -3
- package/dist/server/prerender-work-unit-setup.js +4 -0
- package/dist/server/prod-server.d.ts +12 -0
- package/dist/server/prod-server.js +199 -69
- package/dist/server/proper-error.d.ts +4 -0
- package/dist/server/proper-error.js +31 -0
- package/dist/server/request-pipeline.d.ts +4 -1
- package/dist/server/request-pipeline.js +3 -2
- package/dist/server/revalidation-request.d.ts +1 -0
- package/dist/server/revalidation-request.js +1 -1
- package/dist/server/rsc-stream-hints.js +31 -2
- package/dist/server/seed-cache.d.ts +1 -0
- package/dist/server/seed-cache.js +5 -4
- package/dist/server/server-reference-loader.d.ts +4 -0
- package/dist/server/server-reference-loader.js +29 -0
- package/dist/server/socket-error-backstop.d.ts +9 -1
- package/dist/server/socket-error-backstop.js +46 -17
- package/dist/server/static-file-signal.d.ts +15 -4
- package/dist/server/static-file-signal.js +46 -12
- package/dist/server/worker-image-optimization.d.ts +34 -0
- package/dist/server/worker-image-optimization.js +86 -0
- package/dist/server/worker-stages.d.ts +1 -1
- package/dist/server/worker-stages.js +2 -2
- package/dist/server/worker-utils.d.ts +8 -3
- package/dist/server/worker-utils.js +12 -7
- package/dist/shims/app-router-scroll.js +4 -1
- package/dist/shims/app-router-tree-context.d.ts +5 -0
- package/dist/shims/app-router-tree-context.js +27 -0
- package/dist/shims/cache-callable-runtime.d.ts +4 -2
- package/dist/shims/cache-callable-runtime.js +21 -12
- package/dist/shims/cache-handler.js +1 -9
- package/dist/shims/cache-runtime.d.ts +6 -1
- package/dist/shims/cache-runtime.js +2 -1
- package/dist/shims/cache.d.ts +2 -2
- package/dist/shims/cache.js +40 -13
- package/dist/shims/cdn-cache.d.ts +8 -0
- package/dist/shims/cdn-cache.js +17 -1
- package/dist/shims/disable-smooth-scroll.d.ts +3 -0
- package/dist/shims/disable-smooth-scroll.js +36 -0
- package/dist/shims/document-placeholders.d.ts +19 -0
- package/dist/shims/document-placeholders.js +45 -0
- package/dist/shims/document.js +21 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
- package/dist/shims/dynamic-preload-chunks.js +13 -9
- package/dist/shims/dynamic.d.ts +1 -1
- package/dist/shims/dynamic.js +60 -8
- package/dist/shims/fetch-cache-state.d.ts +66 -0
- package/dist/shims/fetch-cache-state.js +92 -0
- package/dist/shims/fetch-cache.d.ts +3 -67
- package/dist/shims/fetch-cache.js +160 -125
- package/dist/shims/head.d.ts +10 -6
- package/dist/shims/head.js +15 -13
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/navigation.js +31 -5
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +12 -20
- package/dist/shims/server.d.ts +16 -0
- package/dist/shims/server.js +24 -4
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-utils.d.ts +2 -0
- package/dist/shims/url-utils.js +3 -1
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +11 -1
- package/dist/utils/package-name.d.ts +6 -0
- package/dist/utils/package-name.js +12 -1
- package/dist/utils/plugin-rsc-version.d.ts +4 -0
- package/dist/utils/plugin-rsc-version.js +15 -0
- package/dist/utils/prerender-output-paths.js +15 -4
- package/dist/utils/public-file-path.d.ts +10 -2
- package/dist/utils/public-file-path.js +13 -9
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.d.ts +3 -0
- package/dist/utils/react-version.js +1 -1
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { omitUnusedBuildSourcemap } from "./plugins/transform-result.js";
|
|
|
15
15
|
import { assetPrefixPathname, isNextStaticPath, resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
16
16
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
17
17
|
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, lightningCssFeatureNamesToMask, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
18
|
-
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
18
|
+
import { normalizePathnameForRouteMatch, normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
19
19
|
import { hasBasePath, stripBasePath } from "./utils/base-path.js";
|
|
20
20
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
21
21
|
import { generateRouteTypes } from "./typegen.js";
|
|
@@ -28,6 +28,7 @@ import { methodNotAllowedResponse, notFoundStaticAssetResponse } from "./server/
|
|
|
28
28
|
import { isOpenRedirectShaped, sendRepeatedSlashRedirect } from "./server/open-redirect.js";
|
|
29
29
|
import { canonicalizeRequestUrlPathname, filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
30
30
|
import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
|
|
31
|
+
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
31
32
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
32
33
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
33
34
|
import { extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, hasExportedName } from "./build/report.js";
|
|
@@ -35,7 +36,6 @@ import { generatePagesRequestEntry, generatePagesResponseEntry, generateServerEn
|
|
|
35
36
|
import { compileClientMiddlewareMatchers, generateClientEntry } from "./entries/pages-client-entry.js";
|
|
36
37
|
import { isPathInside, isPathInsideOrEqual, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
37
38
|
import { logRequest, now } from "./server/request-log.js";
|
|
38
|
-
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
39
39
|
import { getPagesPreviewModeId } from "./server/pages-preview.js";
|
|
40
40
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
41
41
|
import { signalFromNodeResponse } from "./server/node-response-signal.js";
|
|
@@ -56,16 +56,19 @@ import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/ima
|
|
|
56
56
|
import { generateBrowserEntry, toLinkPrefetchRoutes } from "./entries/app-browser-entry.js";
|
|
57
57
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
58
58
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
59
|
+
import { createRscScanGlobImportsPlugin, isRscScanGlobImportsAffected } from "./plugins/rsc-scan-glob-imports.js";
|
|
59
60
|
import { findOpenTelemetryPackages, mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
60
61
|
import { precompressAssets } from "./build/precompress.js";
|
|
61
62
|
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
62
|
-
import {
|
|
63
|
+
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
64
|
+
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, collectClientBuildFiles, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
63
65
|
import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
|
|
64
66
|
import { VINEXT_BUILD_LIFECYCLE_CONFIG, createBuildLifecyclePlugins } from "./build/lifecycle.js";
|
|
65
67
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
66
68
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
67
69
|
import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
|
|
68
70
|
import { readTrustedRevalidationHostname } from "./server/revalidation-host.js";
|
|
71
|
+
import { sealForwardedMiddlewareContext } from "./server/forwarded-middleware-context.js";
|
|
69
72
|
import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
|
|
70
73
|
import { traceFrameworkRequest } from "./server/request-tracing.js";
|
|
71
74
|
import { runPagesRequest } from "./server/pages-request-pipeline.js";
|
|
@@ -84,8 +87,8 @@ import { createScanBuildCssPlugin } from "./plugins/scan-build-css.js";
|
|
|
84
87
|
import { createInstrumentationClientTransformPlugin, createInstrumentationServerTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
85
88
|
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
86
89
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
87
|
-
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
88
90
|
import { isServerEnvironment } from "./plugins/environment.js";
|
|
91
|
+
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
89
92
|
import { createPagesNodeExternalsPlugin } from "./plugins/pages-node-externals.js";
|
|
90
93
|
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
91
94
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
@@ -100,17 +103,18 @@ import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimize
|
|
|
100
103
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
101
104
|
import { createTransitiveExternalsPlugin } from "./plugins/transitive-externals.js";
|
|
102
105
|
import public_shim_map_default from "./shims/public-shim-map.json.js";
|
|
103
|
-
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
104
106
|
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
105
107
|
import { readPrerenderSecret, readServerRuntimeOutputDirs } from "./build/server-manifest.js";
|
|
106
108
|
import { createModuleDependencyCache } from "./build/module-dependency-cache.js";
|
|
107
109
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
108
110
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter, createSassTsconfigPathImporters } from "./plugins/sass.js";
|
|
109
|
-
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createMultiStageChunkFileNames, createMultiStageCodeSplittingConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
111
|
+
import { assertClientOutDirIsSeparate, createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createMultiStageChunkFileNames, createMultiStageCodeSplittingConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
110
112
|
import { EXPORT_ALL_CANDIDATE_FILTER, hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
111
113
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
112
114
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
113
115
|
import { createWorkerImageImportsPlugin } from "./plugins/worker-image-imports.js";
|
|
116
|
+
import { SERVER_ONLY_SPECIFIER_RE, createWorkerServerOnlyImportsPlugin } from "./plugins/worker-server-only-imports.js";
|
|
117
|
+
import { createWorkerUseServerPlugins } from "./plugins/worker-use-server.js";
|
|
114
118
|
import { createRequireContextPlugin } from "./plugins/require-context.js";
|
|
115
119
|
import { commonJsEsmFacadeOptimizeDepsPlugin, stripEsmCommonJsExportFacade } from "./plugins/commonjs-esm-facade.js";
|
|
116
120
|
import { COMMONJS_SYNTAX_CODE_FILTER } from "./plugins/commonjs-syntax.js";
|
|
@@ -119,9 +123,10 @@ import { createExtensionlessDynamicImportPlugin } from "./plugins/extensionless-
|
|
|
119
123
|
import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
120
124
|
import { consumerEnvironmentConditionFilter, getTypeofWindowReplacement, mayFoldChangeScannedImports, replaceConsumerEnvironmentConditions } from "./plugins/typeof-window.js";
|
|
121
125
|
import { hasMdxFiles, loadMdxEsmReader, pageExtensionsIncludeMdx } from "./utils/mdx-scan.js";
|
|
122
|
-
import {
|
|
126
|
+
import { publicFileRouteKey } from "./utils/public-file-path.js";
|
|
123
127
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
124
128
|
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
129
|
+
import { assertPluginRscVersion } from "./utils/plugin-rsc-version.js";
|
|
125
130
|
import { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine } from "./utils/vite-version.js";
|
|
126
131
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
127
132
|
import { createRequire } from "node:module";
|
|
@@ -156,6 +161,17 @@ const RSC_ENVIRONMENTS = /* @__PURE__ */ new Set([
|
|
|
156
161
|
"client"
|
|
157
162
|
]);
|
|
158
163
|
const VINEXT_GENERATED_DIR_RE = /(?:^|[/\\])\.vinext(?:[/\\]|$)/;
|
|
164
|
+
function removeForwardedMiddlewareContext(req) {
|
|
165
|
+
delete req.headers[VINEXT_MW_CTX_HEADER];
|
|
166
|
+
const rawHeaders = req.rawHeaders;
|
|
167
|
+
for (let i = rawHeaders.length - 2; i >= 0; i -= 2) if (rawHeaders[i].toLowerCase() === "x-vinext-mw-ctx") rawHeaders.splice(i, 2);
|
|
168
|
+
}
|
|
169
|
+
function setForwardedMiddlewareContext(req, key, context) {
|
|
170
|
+
removeForwardedMiddlewareContext(req);
|
|
171
|
+
const value = sealForwardedMiddlewareContext(key, context);
|
|
172
|
+
req.headers[VINEXT_MW_CTX_HEADER] = value;
|
|
173
|
+
req.rawHeaders.push(VINEXT_MW_CTX_HEADER, value);
|
|
174
|
+
}
|
|
159
175
|
function scopeRscPlugin(plugin) {
|
|
160
176
|
const applyToEnvironment = plugin.applyToEnvironment;
|
|
161
177
|
return {
|
|
@@ -176,6 +192,11 @@ if (earlyViteCliInvocation) {
|
|
|
176
192
|
});
|
|
177
193
|
}
|
|
178
194
|
installSocketErrorBackstop();
|
|
195
|
+
const INVALID_SERVER_ONLY_ID_PREFIX = "\0vinext:invalid-server-only:";
|
|
196
|
+
const INVALID_SERVER_ONLY_ID_RE = /^\0vinext:invalid-server-only:/;
|
|
197
|
+
function createServerOnlyClientImportError(importer) {
|
|
198
|
+
return /* @__PURE__ */ new Error(`You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but ${importer || "this module"} is reachable from a client bundle.`);
|
|
199
|
+
}
|
|
179
200
|
function hasServerOnlyMarkerImport(code) {
|
|
180
201
|
if (!code.includes("server-only")) return false;
|
|
181
202
|
let ast;
|
|
@@ -903,6 +924,7 @@ function vinext(options = {}) {
|
|
|
903
924
|
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
904
925
|
const resolvePagesClientAssetsOutputDir = (environmentName, outputDir) => !selectedMultiStageOutput && !hasAppDir && !hasCloudflarePlugin && environmentName === "ssr" ? path.dirname(outputDir) : outputDir;
|
|
905
926
|
let pagesClientAssetsModule = internalOptions.__pagesClientAssetsModule ?? null;
|
|
927
|
+
let clientBuildFiles = [];
|
|
906
928
|
let devPublicFileRoutes = null;
|
|
907
929
|
let publicDirConflictOptions = null;
|
|
908
930
|
let copyPublicDirIntoStaticExportBasePath = false;
|
|
@@ -911,6 +933,7 @@ function vinext(options = {}) {
|
|
|
911
933
|
let draftModeSecret = getPagesPreviewModeId();
|
|
912
934
|
const prerenderSecret = process.env.__VINEXT_SHARED_PRERENDER_SECRET ?? randomBytes(32).toString("hex");
|
|
913
935
|
let revalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
|
|
936
|
+
const devForwardedMiddlewareContextKey = randomBytes(32).toString("hex");
|
|
914
937
|
let previewBuildCredentials;
|
|
915
938
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
916
939
|
const rscClassificationManifests = /* @__PURE__ */ new Map();
|
|
@@ -999,6 +1022,7 @@ function vinext(options = {}) {
|
|
|
999
1022
|
let rscPluginModulePromise = null;
|
|
1000
1023
|
resolvedReactPath = resolveOptionalDependency(earlyBaseDir, "@vitejs/plugin-react");
|
|
1001
1024
|
resolvedRscPath = resolveOptionalDependency(earlyBaseDir, "@vitejs/plugin-rsc");
|
|
1025
|
+
const rscVersion = earlyAppDirExists && resolvedRscPath ? assertPluginRscVersion(resolvedRscPath) : null;
|
|
1002
1026
|
let rscPluginPromise = null;
|
|
1003
1027
|
let manualUseCachePluginPromise = null;
|
|
1004
1028
|
if (earlyAppDirExists && autoRsc) {
|
|
@@ -1325,6 +1349,7 @@ function vinext(options = {}) {
|
|
|
1325
1349
|
buildEmptyOutDir = typeof config.build?.emptyOutDir === "boolean" ? config.build.emptyOutDir : void 0;
|
|
1326
1350
|
isServeCommand = env.command === "serve";
|
|
1327
1351
|
root = path.resolve(toSlash(process.cwd()), config.root ?? ".");
|
|
1352
|
+
if (env.command === "build") assertClientOutDirIsSeparate(root, options);
|
|
1328
1353
|
const devCliLifecycleEnabled = env.command === "serve" && env.isPreview !== true && claimViteCliDevInvocation(root, config["__vinextDevRestart"] === true, reservedDevCliInvocation && config.configFile === false);
|
|
1329
1354
|
buildLifecycleInvocation = config[VINEXT_BUILD_LIFECYCLE_CONFIG];
|
|
1330
1355
|
buildLifecycleEnabled = env.command === "build" && !internalOptions.__skipBuildLifecycle && (buildLifecycleInvocation !== void 0 || claimViteCliBuildInvocation());
|
|
@@ -1442,6 +1467,7 @@ function vinext(options = {}) {
|
|
|
1442
1467
|
defines["process.env.__NEXT_TEST_MODE"] = JSON.stringify(process.env.__NEXT_TEST_MODE ?? false);
|
|
1443
1468
|
defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
|
|
1444
1469
|
defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
|
|
1470
|
+
defines["process.env.__VINEXT_MANUAL_TRAILING_SLASH"] = JSON.stringify(nextConfig.skipTrailingSlashRedirect ? "true" : "false");
|
|
1445
1471
|
defines["process.env.__NEXT_CONFIG_OUTPUT"] = JSON.stringify(nextConfig.output ?? "");
|
|
1446
1472
|
defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
|
|
1447
1473
|
defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
|
|
@@ -1507,6 +1533,7 @@ function vinext(options = {}) {
|
|
|
1507
1533
|
"vinext/head-state": path.join(shimsDir, "head-state"),
|
|
1508
1534
|
"vinext/i18n-state": path.join(shimsDir, "i18n-state"),
|
|
1509
1535
|
"vinext/i18n-context": path.join(shimsDir, "i18n-context"),
|
|
1536
|
+
"vinext/document-placeholders": path.join(shimsDir, "document-placeholders"),
|
|
1510
1537
|
"vinext/client": path.resolve(__dirname, "client", "index"),
|
|
1511
1538
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
1512
1539
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
@@ -1598,7 +1625,14 @@ function vinext(options = {}) {
|
|
|
1598
1625
|
...!isSSR && !isMultiEnv ? { output: getClientOutputConfig(clientAssetsDir) } : {}
|
|
1599
1626
|
})
|
|
1600
1627
|
},
|
|
1601
|
-
worker: { plugins: () => [
|
|
1628
|
+
worker: { plugins: () => [
|
|
1629
|
+
createWorkerImageImportsPlugin({ deploymentId: nextConfig.deploymentId }),
|
|
1630
|
+
createWorkerServerOnlyImportsPlugin(),
|
|
1631
|
+
...rscPluginModulePromise && resolvedRscPath ? [createWorkerUseServerPlugins({
|
|
1632
|
+
rscPluginModule: rscPluginModulePromise,
|
|
1633
|
+
rscPluginPath: resolvedRscPath
|
|
1634
|
+
})] : []
|
|
1635
|
+
] },
|
|
1602
1636
|
server: {
|
|
1603
1637
|
watch: config.server?.watch === null ? null : {
|
|
1604
1638
|
ignored: [VINEXT_GENERATED_DIR_RE],
|
|
@@ -1835,6 +1869,7 @@ function vinext(options = {}) {
|
|
|
1835
1869
|
...depOptimizeNodeEnvOptions
|
|
1836
1870
|
},
|
|
1837
1871
|
build: {
|
|
1872
|
+
...options.clientOutDir ? { outDir: options.clientOutDir } : {},
|
|
1838
1873
|
manifest: true,
|
|
1839
1874
|
...hasPagesDir ? { ssrManifest: true } : {},
|
|
1840
1875
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
@@ -1854,6 +1889,7 @@ function vinext(options = {}) {
|
|
|
1854
1889
|
...depOptimizeNodeEnvOptions
|
|
1855
1890
|
},
|
|
1856
1891
|
build: {
|
|
1892
|
+
...options.clientOutDir ? { outDir: options.clientOutDir } : {},
|
|
1857
1893
|
manifest: true,
|
|
1858
1894
|
ssrManifest: true,
|
|
1859
1895
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
@@ -1874,7 +1910,7 @@ function vinext(options = {}) {
|
|
|
1874
1910
|
...depOptimizeNodeEnvOptions
|
|
1875
1911
|
},
|
|
1876
1912
|
build: {
|
|
1877
|
-
outDir: "dist/client",
|
|
1913
|
+
outDir: options.clientOutDir ?? "dist/client",
|
|
1878
1914
|
manifest: true,
|
|
1879
1915
|
ssrManifest: true,
|
|
1880
1916
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
@@ -2206,6 +2242,7 @@ function vinext(options = {}) {
|
|
|
2206
2242
|
nodeOpenTelemetryLoader: registerNodeOpenTelemetryLoader,
|
|
2207
2243
|
assetPrefix: nextConfig?.assetPrefix,
|
|
2208
2244
|
crossOrigin: nextConfig?.crossOrigin,
|
|
2245
|
+
skipTrailingSlashRedirect: nextConfig?.skipTrailingSlashRedirect,
|
|
2209
2246
|
expireTime: nextConfig?.expireTime,
|
|
2210
2247
|
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
2211
2248
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
@@ -2230,7 +2267,8 @@ function vinext(options = {}) {
|
|
|
2230
2267
|
publicFiles: isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, this.environment.config.publicDir === "" ? false : this.environment.config.publicDir),
|
|
2231
2268
|
globalNotFoundPath,
|
|
2232
2269
|
draftModeSecret,
|
|
2233
|
-
prerenderSecret
|
|
2270
|
+
prerenderSecret,
|
|
2271
|
+
devForwardedMiddlewareContextKey: isServeCommand && this.environment.config.consumer === "server" ? devForwardedMiddlewareContextKey : void 0
|
|
2234
2272
|
}, instrumentationPath);
|
|
2235
2273
|
}
|
|
2236
2274
|
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
@@ -2595,10 +2633,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2595
2633
|
}
|
|
2596
2634
|
},
|
|
2597
2635
|
configureServer(server) {
|
|
2636
|
+
installSocketErrorBackstop({ runningServer: true });
|
|
2598
2637
|
const devBuildId = nextConfig?.buildId ?? process.env.__VINEXT_BUILD_ID ?? "development";
|
|
2599
2638
|
server.middlewares.use((req, _res, next) => {
|
|
2600
2639
|
req.__vinextOriginalEncodedUrl ??= req.url;
|
|
2601
|
-
|
|
2640
|
+
removeForwardedMiddlewareContext(req);
|
|
2602
2641
|
next();
|
|
2603
2642
|
});
|
|
2604
2643
|
const pageExtensions = fileMatcher.extensionRegex;
|
|
@@ -2777,7 +2816,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2777
2816
|
const cleanPath = toSlash(stripViteModuleQuery(filePath));
|
|
2778
2817
|
const relativePath = path.relative(devPublicDir, cleanPath);
|
|
2779
2818
|
if (relativePath === "" || relativePath.startsWith("../") || path.isAbsolute(relativePath)) return null;
|
|
2780
|
-
return
|
|
2819
|
+
return [publicFileRouteKey(`/${relativePath}`)];
|
|
2781
2820
|
};
|
|
2782
2821
|
const updatePublicFileRoute = (filePath, present) => {
|
|
2783
2822
|
const routes = publicRoutesForFile(filePath);
|
|
@@ -3072,16 +3111,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3072
3111
|
}
|
|
3073
3112
|
const canonicalOriginalUrl = canonicalizeRequestUrlPathname(originalEncodedUrl);
|
|
3074
3113
|
url = canonicalizeRequestUrlPathname(url);
|
|
3075
|
-
const rawPathname = url.split("?")[0];
|
|
3076
|
-
if (rawPathname.endsWith("/index.html")) url = url.replace("/index.html", "/");
|
|
3077
|
-
else if (rawPathname.endsWith(".html")) url = url.replace(/\.html(?=\?|$)/, "");
|
|
3078
3114
|
let middlewareUrl = canonicalOriginalUrl;
|
|
3079
3115
|
let routeUrl = middlewareUrl;
|
|
3080
|
-
{
|
|
3081
|
-
const routePathname = routeUrl.split("?")[0];
|
|
3082
|
-
if (routePathname.endsWith("/index.html")) routeUrl = routeUrl.replace("/index.html", "/");
|
|
3083
|
-
else if (routePathname.endsWith(".html")) routeUrl = routeUrl.replace(/\.html(?=\?|$)/, "");
|
|
3084
|
-
}
|
|
3085
3116
|
let pathname = url.split("?")[0];
|
|
3086
3117
|
if (isOpenRedirectShaped(pathname)) {
|
|
3087
3118
|
res.writeHead(404);
|
|
@@ -3129,7 +3160,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3129
3160
|
}
|
|
3130
3161
|
}
|
|
3131
3162
|
let configMatchPathname = stripBasePath(middlewareUrl.split("?")[0], routingBasePath);
|
|
3132
|
-
if (nextConfig) {
|
|
3163
|
+
if (nextConfig && !nextConfig.skipTrailingSlashRedirect) {
|
|
3133
3164
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
3134
3165
|
const trailingSlashRedirect = normalizeTrailingSlash(routeUrl.split("?")[0], bp, nextConfig.trailingSlash, qs);
|
|
3135
3166
|
if (trailingSlashRedirect) {
|
|
@@ -3142,18 +3173,22 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3142
3173
|
if (hasCloudflarePlugin) return next();
|
|
3143
3174
|
let isDataReq = false;
|
|
3144
3175
|
let dataNotFoundResponse = null;
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3176
|
+
const rawRoutePathname = routeUrl.split("?")[0];
|
|
3177
|
+
if (isNextDataPathname(rawRoutePathname)) {
|
|
3178
|
+
const rawDataMatch = parseNextDataPathname(rawRoutePathname, devBuildId);
|
|
3179
|
+
const dataMatch = rawDataMatch ? parseNextDataPathname(pathname, devBuildId) : null;
|
|
3180
|
+
if (dataMatch && rawDataMatch) {
|
|
3148
3181
|
isDataReq = true;
|
|
3149
3182
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
3150
|
-
const
|
|
3183
|
+
const addTrailingSlash = shouldAddTrailingSlashToPagesDataPath(capturedMiddlewarePath !== null, nextConfig?.trailingSlash === true, nextConfig?.skipProxyUrlNormalize === true);
|
|
3184
|
+
const pagePathname = normalizeNextDataPagePathname(dataMatch.pagePathname, addTrailingSlash);
|
|
3185
|
+
const rawPagePathname = normalizeNextDataPagePathname(rawDataMatch.pagePathname, addTrailingSlash);
|
|
3151
3186
|
url = pagePathname + qs;
|
|
3152
|
-
|
|
3153
|
-
|
|
3187
|
+
routeUrl = rawPagePathname + qs;
|
|
3188
|
+
if (!nextConfig?.skipProxyUrlNormalize) middlewareUrl = routeUrl;
|
|
3154
3189
|
pathname = pagePathname;
|
|
3155
|
-
configMatchPathname =
|
|
3156
|
-
req.url =
|
|
3190
|
+
configMatchPathname = rawPagePathname;
|
|
3191
|
+
req.url = routeUrl;
|
|
3157
3192
|
} else {
|
|
3158
3193
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
3159
3194
|
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
@@ -3202,6 +3237,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3202
3237
|
signal: signalFromNodeResponse(res)
|
|
3203
3238
|
});
|
|
3204
3239
|
const applyRequestHeadersToNodeRequest = (nextRequestHeaders) => {
|
|
3240
|
+
removeForwardedMiddlewareContext(req);
|
|
3205
3241
|
for (const key of Object.keys(req.headers)) delete req.headers[key];
|
|
3206
3242
|
for (const [key, value] of nextRequestHeaders) req.headers[key] = value;
|
|
3207
3243
|
};
|
|
@@ -3213,18 +3249,19 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3213
3249
|
headers: nodeRequestHeaders,
|
|
3214
3250
|
signal: webRequest.signal
|
|
3215
3251
|
});
|
|
3216
|
-
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest, pathname);
|
|
3252
|
+
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest, pathname, opts.isStaleDataRequest, nextConfig?.skipTrailingSlashRedirect);
|
|
3217
3253
|
if (hasAppDir && result.continue) {
|
|
3218
3254
|
const mwCtxEntries = [];
|
|
3219
3255
|
if (result.responseHeaders) {
|
|
3220
3256
|
for (const [key, value] of result.responseHeaders) if (key !== "x-middleware-next" && key !== "x-middleware-rewrite") mwCtxEntries.push([key, value]);
|
|
3221
3257
|
}
|
|
3222
3258
|
const mwStatus = result.status ?? result.rewriteStatus;
|
|
3223
|
-
req
|
|
3259
|
+
setForwardedMiddlewareContext(req, devForwardedMiddlewareContextKey, JSON.stringify({
|
|
3224
3260
|
h: mwCtxEntries,
|
|
3225
3261
|
s: mwStatus ?? null,
|
|
3226
|
-
r: result.rewriteUrl ?? null
|
|
3227
|
-
|
|
3262
|
+
r: result.rewriteUrl ?? null,
|
|
3263
|
+
b: result.rewriteHadBasePath ?? null
|
|
3264
|
+
}));
|
|
3228
3265
|
}
|
|
3229
3266
|
return result;
|
|
3230
3267
|
} : null;
|
|
@@ -3238,6 +3275,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3238
3275
|
assetPrefix: nextConfig?.assetPrefix,
|
|
3239
3276
|
basePath: bp,
|
|
3240
3277
|
trailingSlash: nextConfig?.trailingSlash ?? false,
|
|
3278
|
+
skipTrailingSlashRedirect: nextConfig?.skipTrailingSlashRedirect ?? false,
|
|
3241
3279
|
i18nConfig: nextConfig?.i18n ?? null,
|
|
3242
3280
|
configRedirects: nextConfig?.redirects ?? [],
|
|
3243
3281
|
configRewrites: nextConfig?.rewrites ?? {
|
|
@@ -3286,8 +3324,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3286
3324
|
const reqWithBody = new Request(new URL(url, requestOrigin), externalInit);
|
|
3287
3325
|
return proxyExternalRequest(reqWithBody, externalUrl);
|
|
3288
3326
|
},
|
|
3289
|
-
serveFilesystemRoute: async (requestPathname, stagedHeaders, phase, resolvedUrl) => {
|
|
3290
|
-
if (isImageOptimizationPath(requestPathname)) {
|
|
3327
|
+
serveFilesystemRoute: async (requestPathname, stagedHeaders, phase, resolvedUrl, _request, resolvedPathnameHasBasePath) => {
|
|
3328
|
+
if (resolvedPathnameHasBasePath && isImageOptimizationPath(requestPathname)) {
|
|
3291
3329
|
const imageRequestUrl = new URL(resolvedUrl, requestOrigin);
|
|
3292
3330
|
const allowedWidths = [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES];
|
|
3293
3331
|
const encodedLocation = resolveDevImageRedirect(imageRequestUrl, allowedWidths, nextConfig.images?.qualities);
|
|
@@ -3298,7 +3336,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3298
3336
|
}
|
|
3299
3337
|
const isRetrievalMethod = req.method === "GET" || req.method === "HEAD";
|
|
3300
3338
|
if (phase === "direct" && isRetrievalMethod || requestPathname === "/" || requestPathname === "/api" || requestPathname.startsWith("/api/")) return false;
|
|
3301
|
-
if (!isRetrievalMethod) return isExistingDevPublicFile(requestPathname) ? methodNotAllowedResponse("GET, HEAD") : false;
|
|
3339
|
+
if (!isRetrievalMethod) return isExistingDevPublicFile(normalizePathnameForRouteMatch(requestPathname)) ? methodNotAllowedResponse("GET, HEAD") : false;
|
|
3302
3340
|
return serveRewrittenViteFilesystemRoute(req, res, requestPathname, stagedHeaders);
|
|
3303
3341
|
}
|
|
3304
3342
|
};
|
|
@@ -3325,12 +3363,12 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3325
3363
|
const requestHeaders = new Headers();
|
|
3326
3364
|
encodeMiddlewareRequestHeaders(requestHeaders, pipelineResult.requestHeaders);
|
|
3327
3365
|
flushRequestHeaders();
|
|
3328
|
-
req
|
|
3366
|
+
setForwardedMiddlewareContext(req, devForwardedMiddlewareContextKey, JSON.stringify({
|
|
3329
3367
|
h: responseHeaders,
|
|
3330
3368
|
q: [...requestHeaders],
|
|
3331
3369
|
s: pipelineResult.middlewareStatus ?? null,
|
|
3332
3370
|
r: apiUrl
|
|
3333
|
-
});
|
|
3371
|
+
}));
|
|
3334
3372
|
};
|
|
3335
3373
|
if (pipelineResult.type === "api") {
|
|
3336
3374
|
const devApiRoutes = await getDevApiRoutes();
|
|
@@ -3350,7 +3388,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3350
3388
|
i18n: nextConfig?.i18n,
|
|
3351
3389
|
trustedRevalidateOrigin: getTrustedDevRevalidateOrigin(),
|
|
3352
3390
|
allowedRevalidateHeaderKeys: nextConfig?.allowedRevalidateHeaderKeys,
|
|
3353
|
-
trailingSlash: nextConfig?.trailingSlash
|
|
3391
|
+
trailingSlash: nextConfig?.trailingSlash,
|
|
3392
|
+
skipTrailingSlashRedirect: nextConfig?.skipTrailingSlashRedirect
|
|
3354
3393
|
})) return;
|
|
3355
3394
|
if (hasAppDir) {
|
|
3356
3395
|
if (pipelineResult.configRewriteFired) forwardInternalApiRewriteToApp(pipelineResult.apiUrl);
|
|
@@ -3498,6 +3537,25 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3498
3537
|
},
|
|
3499
3538
|
{
|
|
3500
3539
|
name: "vinext:validate-server-only-client-imports",
|
|
3540
|
+
resolveId: {
|
|
3541
|
+
order: "pre",
|
|
3542
|
+
filter: { id: SERVER_ONLY_SPECIFIER_RE },
|
|
3543
|
+
handler(_source, importer) {
|
|
3544
|
+
const environment = this.environment;
|
|
3545
|
+
if (environment?.name !== "client" || hasAppDir) return null;
|
|
3546
|
+
if (environment.mode === "dev" && !(importer && environment.moduleGraph.getModuleById(importer))) return {
|
|
3547
|
+
id: INVALID_SERVER_ONLY_ID_PREFIX + (importer ?? ""),
|
|
3548
|
+
moduleSideEffects: true
|
|
3549
|
+
};
|
|
3550
|
+
throw createServerOnlyClientImportError(importer);
|
|
3551
|
+
}
|
|
3552
|
+
},
|
|
3553
|
+
load: {
|
|
3554
|
+
filter: { id: INVALID_SERVER_ONLY_ID_RE },
|
|
3555
|
+
handler(id) {
|
|
3556
|
+
throw createServerOnlyClientImportError(id.slice(28));
|
|
3557
|
+
}
|
|
3558
|
+
},
|
|
3501
3559
|
transform: {
|
|
3502
3560
|
filter: {
|
|
3503
3561
|
id: {
|
|
@@ -3507,7 +3565,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3507
3565
|
code: "server-only"
|
|
3508
3566
|
},
|
|
3509
3567
|
handler(code) {
|
|
3510
|
-
if (this.environment?.name !== "client") return null;
|
|
3568
|
+
if (this.environment?.name !== "client" || !hasAppDir) return null;
|
|
3569
|
+
// @vitejs/plugin-rsc replaces a "use server" module in the client
|
|
3511
3570
|
if (getLeadingReactDirective(code) === "use server") return null;
|
|
3512
3571
|
if (!hasServerOnlyMarkerImport(code)) return null;
|
|
3513
3572
|
throw new Error(`You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but this module is reachable from a client bundle.`);
|
|
@@ -3735,7 +3794,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3735
3794
|
createGoogleFontsPlugin(_fontGoogleShimPath, _shimsDir),
|
|
3736
3795
|
createLocalFontsPlugin(_shimsDir),
|
|
3737
3796
|
createOptimizeImportsPlugin(() => nextConfig, () => root),
|
|
3738
|
-
createDynamicPreloadMetadataPlugin(),
|
|
3797
|
+
createDynamicPreloadMetadataPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
3739
3798
|
importMetaUrlCapability.vitePlugin,
|
|
3740
3799
|
createExtensionlessDynamicImportPlugin(),
|
|
3741
3800
|
createRequireContextPlugin(),
|
|
@@ -3941,6 +4000,10 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3941
4000
|
apply: "build",
|
|
3942
4001
|
enforce: "post",
|
|
3943
4002
|
sharedDuringBuild: true,
|
|
4003
|
+
writeBundle(_options, bundle) {
|
|
4004
|
+
if (this.environment.name !== "client") return;
|
|
4005
|
+
clientBuildFiles = collectClientBuildFiles(Object.keys(bundle));
|
|
4006
|
+
},
|
|
3944
4007
|
closeBundle: {
|
|
3945
4008
|
sequential: true,
|
|
3946
4009
|
order: "post",
|
|
@@ -3967,7 +4030,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3967
4030
|
cssGraph: runtimeMetadata.cssGraph,
|
|
3968
4031
|
lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
|
|
3969
4032
|
dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0,
|
|
3970
|
-
crossOrigin: nextConfig.crossOrigin ?? ""
|
|
4033
|
+
crossOrigin: nextConfig.crossOrigin ?? "",
|
|
4034
|
+
clientBuildFiles: clientBuildFiles.length > 0 ? clientBuildFiles : void 0
|
|
3971
4035
|
});
|
|
3972
4036
|
}
|
|
3973
4037
|
if (pagesClientAssetsModule === null && pagesClientAssetsOutputDirs.size === 0) return;
|
|
@@ -4004,13 +4068,37 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4004
4068
|
const envConfig = this.environment?.config;
|
|
4005
4069
|
if (!envConfig) return;
|
|
4006
4070
|
const buildRoot = envConfig.root ?? process.cwd();
|
|
4007
|
-
const clientDir = path.resolve(buildRoot,
|
|
4071
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
4008
4072
|
const manifest = collectInlineCssManifest(clientDir, nextConfig.assetPrefix);
|
|
4009
4073
|
const rscOutDir = path.resolve(buildRoot, options.rscOutDir ?? path.join("dist", "server"));
|
|
4010
4074
|
for (const entryFile of ["index.js", "index.mjs"]) if (injectInlineCssManifestGlobal(path.join(rscOutDir, entryFile), manifest)) break;
|
|
4011
4075
|
}
|
|
4012
4076
|
}
|
|
4013
4077
|
},
|
|
4078
|
+
(
|
|
4079
|
+
// @vitejs/plugin-rsc's preview handler, and Cloudflare and Nitro builds
|
|
4080
|
+
{
|
|
4081
|
+
name: "vinext:preview-server",
|
|
4082
|
+
async configurePreviewServer(server) {
|
|
4083
|
+
if (hasAppDir || hasCloudflarePlugin || hasNitroPlugin) return;
|
|
4084
|
+
if (nextConfig?.output === "export") return;
|
|
4085
|
+
const { createPagesPreviewHandler } = await import("./server/prod-server.js");
|
|
4086
|
+
const { environments, preview, root } = server.config;
|
|
4087
|
+
const handler = await createPagesPreviewHandler({
|
|
4088
|
+
clientDir: path.resolve(root, environments.client?.build.outDir ?? "dist/client"),
|
|
4089
|
+
serverDir: path.resolve(root, environments.ssr?.build.outDir ?? "dist/server"),
|
|
4090
|
+
host: typeof preview.host === "string" ? preview.host : "localhost",
|
|
4091
|
+
port: preview.port ?? 4173
|
|
4092
|
+
});
|
|
4093
|
+
if (!handler) return;
|
|
4094
|
+
return () => {
|
|
4095
|
+
server.middlewares.use((req, res) => {
|
|
4096
|
+
if (nextConfig?.basePath) req.url = nextConfig.basePath + (req.url ?? "/");
|
|
4097
|
+
handler(req, res);
|
|
4098
|
+
});
|
|
4099
|
+
};
|
|
4100
|
+
}
|
|
4101
|
+
}),
|
|
4014
4102
|
{
|
|
4015
4103
|
name: "vinext:cloudflare-build",
|
|
4016
4104
|
apply: "build",
|
|
@@ -4127,6 +4215,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4127
4215
|
}
|
|
4128
4216
|
});
|
|
4129
4217
|
if (rscPluginPromise) plugins.push(rscPluginPromise);
|
|
4218
|
+
if (rscVersion && isRscScanGlobImportsAffected(rscVersion)) plugins.push(createRscScanGlobImportsPlugin({ async getManager(config) {
|
|
4219
|
+
return (await rscPluginModulePromise)?.getPluginApi(config)?.manager;
|
|
4220
|
+
} }));
|
|
4130
4221
|
if (earlyAppDirExists) {
|
|
4131
4222
|
plugins.push(createActionOwnerManifestPlugin({
|
|
4132
4223
|
canonicalizeModuleId: canonicalize,
|
|
@@ -6,6 +6,8 @@ export type CloudflareProjectInfo = {
|
|
|
6
6
|
isAppRouter: boolean;
|
|
7
7
|
hasISR: boolean;
|
|
8
8
|
hasMDX: boolean;
|
|
9
|
+
/** The effective Next.js config sets `output: "export"`. */
|
|
10
|
+
isStaticExport?: boolean;
|
|
9
11
|
nativeModulesToStub: string[];
|
|
10
12
|
};
|
|
11
13
|
export type CloudflarePlatformSetupContext = {
|
|
@@ -13,6 +15,7 @@ export type CloudflarePlatformSetupContext = {
|
|
|
13
15
|
isAppRouter: boolean;
|
|
14
16
|
existingViteConfigPath?: string;
|
|
15
17
|
hasCssModules?: boolean;
|
|
18
|
+
isStaticExport?: boolean;
|
|
16
19
|
packageManager?: string;
|
|
17
20
|
today?: string;
|
|
18
21
|
};
|
|
@@ -25,11 +28,17 @@ export type CloudflarePlatformSetupResult = {
|
|
|
25
28
|
};
|
|
26
29
|
export declare function validateCloudflarePlatformSetup(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): void;
|
|
27
30
|
export declare function setupCloudflarePlatform(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): CloudflarePlatformSetupResult;
|
|
31
|
+
/**
|
|
32
|
+
* The existing config that keeps its own Worker name, if `--name` was given.
|
|
33
|
+
* Init doesn't rename the Worker in an existing config, so callers warn instead.
|
|
34
|
+
*/
|
|
35
|
+
export declare function findConfigKeepingWorkerName(root: string, cloudflare: CloudflareInitOptions): string | undefined;
|
|
28
36
|
export declare function generateWranglerConfig(info: CloudflareProjectInfo, options?: CloudflareInitOptions, today?: string): string;
|
|
29
37
|
export declare function compactResourceName(name: string, suffix: string, maxLength: number): string;
|
|
30
38
|
export declare function generateResponseStoreWranglerConfig(appWranglerCode: string, root: string): string;
|
|
31
39
|
export declare function updateWranglerConfigForCloudflare(code: string, options: CloudflareInitOptions, context?: {
|
|
32
40
|
root?: string;
|
|
41
|
+
isStaticExport?: boolean;
|
|
33
42
|
}): string;
|
|
34
43
|
export declare function getWranglerImagesBinding(code: string): string;
|
|
35
44
|
export declare function getWranglerVersionMetadataBinding(code: string): string;
|