vinext 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -10
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/output-root-externals.d.ts +21 -0
- package/dist/build/output-root-externals.js +40 -0
- 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 +6 -4
- package/dist/build/prerender.js +1 -1
- 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 +12 -12
- package/dist/cli-dev-config.js +3 -3
- package/dist/cli.js +3 -2
- 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 +90 -88
- 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 +246 -136
- 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 +2 -1
- package/dist/init.js +153 -9
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/ast-utils.d.ts +53 -2
- package/dist/plugins/ast-utils.js +90 -2
- package/dist/plugins/cloudflare-dev-module-urls.d.ts +41 -0
- package/dist/plugins/cloudflare-dev-module-urls.js +271 -0
- package/dist/plugins/commonjs-esm-facade.js +2 -2
- package/dist/plugins/css-module-imports.js +13 -20
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +11 -11
- package/dist/plugins/extensionless-dynamic-import.js +2 -3
- package/dist/plugins/fonts.d.ts +1 -1
- package/dist/plugins/fonts.js +3 -3
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +5 -7
- package/dist/plugins/import-meta-url.js +3 -4
- package/dist/plugins/instrumentation-client.js +3 -2
- package/dist/plugins/middleware-export-validation.js +2 -3
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/og-harfbuzz.js +2 -3
- package/dist/plugins/optimize-imports.js +3 -4
- package/dist/plugins/pages-node-externals.js +3 -4
- package/dist/plugins/remove-console.js +2 -18
- package/dist/plugins/require-condition-resolution.js +3 -3
- package/dist/plugins/require-context.js +2 -3
- 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 +265 -102
- package/dist/plugins/styled-jsx.js +2 -3
- 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.d.ts +21 -2
- package/dist/plugins/use-cache-callable.js +84 -35
- package/dist/plugins/worker-image-imports.js +30 -33
- 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 +153 -0
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +3 -2
- package/dist/server/app-action-forwarding.js +2 -2
- 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-entry.js +3 -3
- package/dist/server/app-browser-interception-context.js +1 -1
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-prefetch-response.js +2 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-supplemental-refresh.js +1 -1
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +17 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- 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 +5 -4
- 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-render.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 +3 -4
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-render-abort-error.d.ts +19 -0
- package/dist/server/app-render-abort-error.js +31 -1
- package/dist/server/app-request-stage-dispatch.js +6 -2
- package/dist/server/app-request-stage-independent-entry.js +29 -9
- package/dist/server/app-response-stage-entry.js +11 -3
- 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 +46 -25
- package/dist/server/app-router-entry.js +29 -10
- package/dist/server/app-rsc-cache-busting.d.ts +16 -0
- package/dist/server/app-rsc-cache-busting.js +30 -13
- 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 +89 -39
- package/dist/server/app-rsc-request-normalization.js +3 -3
- package/dist/server/app-rsc-response-stage.js +5 -3
- 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 +62 -23
- package/dist/server/app-ssr-entry.js +7 -5
- package/dist/server/app-visited-response-cache.js +2 -2
- 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/config-headers.js +1 -1
- package/dist/server/defer-until-stream-consumed.d.ts +2 -1
- package/dist/server/defer-until-stream-consumed.js +3 -1
- package/dist/server/dev-server.js +39 -28
- 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 +94 -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 +11 -10
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-path-to-regexp.js +1 -1
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +38 -25
- 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/navigation-planner.js +1 -1
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/open-redirect.d.ts +11 -4
- package/dist/server/open-redirect.js +11 -4
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +6 -5
- 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 +21 -3
- 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 +51 -121
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +189 -127
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +42 -35
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +41 -22
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +75 -16
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +3 -3
- package/dist/server/pages-router-entry.js +5 -4
- 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 +204 -74
- 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.d.ts +1 -1
- package/dist/server/rsc-stream-hints.js +52 -5
- 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 +99 -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 +16 -14
- package/dist/shims/headers.js +2 -2
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +1 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +1 -0
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/link-prefetch.js +5 -4
- package/dist/shims/link.js +2 -2
- package/dist/shims/navigation.js +34 -9
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +21 -32
- package/dist/shims/server.d.ts +27 -4
- package/dist/shims/server.js +65 -9
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-utils.d.ts +9 -0
- package/dist/shims/url-utils.js +15 -4
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/domain-locale.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 +6 -0
- package/dist/utils/plugin-rsc-version.js +41 -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 +10 -0
- package/dist/utils/react-version.js +39 -16
- package/package.json +11 -7
- package/dist/build/nitro-route-rules.d.ts +0 -47
- package/dist/build/nitro-route-rules.js +0 -79
- package/dist/plugins/cache-flight-codec.d.ts +0 -19
- package/dist/plugins/cache-flight-codec.js +0 -68
package/dist/index.js
CHANGED
|
@@ -2,32 +2,34 @@ import path, { toSlash } from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/
|
|
|
2
2
|
import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
|
|
3
3
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
4
4
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
5
|
+
import { TRIVIA_PATTERN, hasImportAttributes, isTypeOnlyImport, parseModuleRecord, parseProgram } from "./plugins/ast-utils.js";
|
|
5
6
|
import { claimViteCliBuildInvocation, getViteCliInvocation, isViteCliConfigFile } from "./utils/vite-cli-invocation.js";
|
|
6
7
|
import { VINEXT_DEV_CLI_LIFECYCLE, applyDevServerDefaults, claimViteCliDevInvocation, createDevServerLifecyclePlugin, reserveViteCliDevInvocation } from "./cli-dev-config.js";
|
|
7
8
|
import { isUnknownRecord } from "./utils/record.js";
|
|
8
|
-
import { getReactUpgradeDeps } from "./utils/react-version.js";
|
|
9
|
+
import { getReactUpgradeDeps, reactUpgradeRequiredMessage } from "./utils/react-version.js";
|
|
9
10
|
import { loadDotenv } from "./config/dotenv.js";
|
|
10
11
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
11
12
|
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
12
13
|
import { encodeMiddlewareRequestHeaders } from "./utils/middleware-request-headers.js";
|
|
14
|
+
import { hasBasePath, stripBasePath } from "./utils/base-path.js";
|
|
15
|
+
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
16
|
+
import { methodNotAllowedResponse, notFoundStaticAssetResponse } from "./server/http-error-responses.js";
|
|
17
|
+
import { isOpenRedirectShaped, sendRepeatedSlashRedirect } from "./server/open-redirect.js";
|
|
18
|
+
import { canonicalizeRequestUrlPathname, filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
13
19
|
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
14
20
|
import { omitUnusedBuildSourcemap } from "./plugins/transform-result.js";
|
|
15
21
|
import { assetPrefixPathname, isNextStaticPath, resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
16
22
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
17
23
|
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, lightningCssFeatureNamesToMask, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
18
|
-
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
19
|
-
import { hasBasePath, stripBasePath } from "./utils/base-path.js";
|
|
24
|
+
import { normalizePathnameForRouteMatch, normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
20
25
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
21
26
|
import { generateRouteTypes } from "./typegen.js";
|
|
22
27
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
23
28
|
import { resolveRuntimeEntryModule } from "./entries/runtime-entry-module.js";
|
|
24
|
-
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
25
29
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
26
30
|
import { validateMiddlewareMatcherPatterns } from "./server/middleware-matcher-pattern.js";
|
|
27
|
-
import { methodNotAllowedResponse, notFoundStaticAssetResponse } from "./server/http-error-responses.js";
|
|
28
|
-
import { isOpenRedirectShaped, sendRepeatedSlashRedirect } from "./server/open-redirect.js";
|
|
29
|
-
import { canonicalizeRequestUrlPathname, filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
30
31
|
import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
|
|
32
|
+
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
31
33
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
32
34
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
33
35
|
import { extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, hasExportedName } from "./build/report.js";
|
|
@@ -35,7 +37,6 @@ import { generatePagesRequestEntry, generatePagesResponseEntry, generateServerEn
|
|
|
35
37
|
import { compileClientMiddlewareMatchers, generateClientEntry } from "./entries/pages-client-entry.js";
|
|
36
38
|
import { isPathInside, isPathInsideOrEqual, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
37
39
|
import { logRequest, now } from "./server/request-log.js";
|
|
38
|
-
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
39
40
|
import { getPagesPreviewModeId } from "./server/pages-preview.js";
|
|
40
41
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
41
42
|
import { signalFromNodeResponse } from "./server/node-response-signal.js";
|
|
@@ -43,6 +44,7 @@ import { handleApiRoute } from "./server/api-handler.js";
|
|
|
43
44
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
44
45
|
import { CACHEABILITY_MANIFEST_MODULE, CACHEABILITY_REQUEST_PROJECTION_MODULE } from "./server/cacheability-manifest.js";
|
|
45
46
|
import { PREGENERATED_CONCRETE_PATHS_MODULE } from "./server/pregenerated-concrete-paths.js";
|
|
47
|
+
import { rewriteOutputRootExternals } from "./build/output-root-externals.js";
|
|
46
48
|
import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
|
|
47
49
|
import { invalidateMetadataFileCache, scanMetadataFiles } from "./server/metadata-routes.js";
|
|
48
50
|
import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
|
|
@@ -56,16 +58,19 @@ import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/ima
|
|
|
56
58
|
import { generateBrowserEntry, toLinkPrefetchRoutes } from "./entries/app-browser-entry.js";
|
|
57
59
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
58
60
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
61
|
+
import { createRscScanGlobImportsPlugin, isRscScanGlobImportsAffected } from "./plugins/rsc-scan-glob-imports.js";
|
|
59
62
|
import { findOpenTelemetryPackages, mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
60
63
|
import { precompressAssets } from "./build/precompress.js";
|
|
61
64
|
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
62
|
-
import {
|
|
65
|
+
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
66
|
+
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, collectClientBuildFiles, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
63
67
|
import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
|
|
64
68
|
import { VINEXT_BUILD_LIFECYCLE_CONFIG, createBuildLifecyclePlugins } from "./build/lifecycle.js";
|
|
65
69
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
66
70
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
67
71
|
import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
|
|
68
72
|
import { readTrustedRevalidationHostname } from "./server/revalidation-host.js";
|
|
73
|
+
import { sealForwardedMiddlewareContext } from "./server/forwarded-middleware-context.js";
|
|
69
74
|
import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
|
|
70
75
|
import { traceFrameworkRequest } from "./server/request-tracing.js";
|
|
71
76
|
import { runPagesRequest } from "./server/pages-request-pipeline.js";
|
|
@@ -84,9 +89,10 @@ import { createScanBuildCssPlugin } from "./plugins/scan-build-css.js";
|
|
|
84
89
|
import { createInstrumentationClientTransformPlugin, createInstrumentationServerTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
85
90
|
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
86
91
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
87
|
-
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
88
92
|
import { isServerEnvironment } from "./plugins/environment.js";
|
|
93
|
+
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
89
94
|
import { createPagesNodeExternalsPlugin } from "./plugins/pages-node-externals.js";
|
|
95
|
+
import { createCloudflareDevModuleUrlsPlugin } from "./plugins/cloudflare-dev-module-urls.js";
|
|
90
96
|
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
91
97
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
92
98
|
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
@@ -95,22 +101,22 @@ import { createTransformCache } from "./plugins/transform-cache.js";
|
|
|
95
101
|
import { createOgHarfbuzzPlugin } from "./plugins/og-harfbuzz.js";
|
|
96
102
|
import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins/og-assets.js";
|
|
97
103
|
import { createUseCacheCallablePlugin } from "./plugins/use-cache-callable.js";
|
|
98
|
-
import { cacheFlightCodecPlugin } from "./plugins/cache-flight-codec.js";
|
|
99
104
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
100
105
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
101
106
|
import { createTransitiveExternalsPlugin } from "./plugins/transitive-externals.js";
|
|
102
107
|
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
108
|
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
105
109
|
import { readPrerenderSecret, readServerRuntimeOutputDirs } from "./build/server-manifest.js";
|
|
106
110
|
import { createModuleDependencyCache } from "./build/module-dependency-cache.js";
|
|
107
111
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
108
112
|
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";
|
|
113
|
+
import { assertClientOutDirIsSeparate, createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createMultiStageChunkFileNames, createMultiStageCodeSplittingConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
110
114
|
import { EXPORT_ALL_CANDIDATE_FILTER, hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
111
115
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
112
116
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
113
117
|
import { createWorkerImageImportsPlugin } from "./plugins/worker-image-imports.js";
|
|
118
|
+
import { SERVER_ONLY_SPECIFIER_RE, createWorkerServerOnlyImportsPlugin } from "./plugins/worker-server-only-imports.js";
|
|
119
|
+
import { createWorkerUseServerPlugins } from "./plugins/worker-use-server.js";
|
|
114
120
|
import { createRequireContextPlugin } from "./plugins/require-context.js";
|
|
115
121
|
import { commonJsEsmFacadeOptimizeDepsPlugin, stripEsmCommonJsExportFacade } from "./plugins/commonjs-esm-facade.js";
|
|
116
122
|
import { COMMONJS_SYNTAX_CODE_FILTER } from "./plugins/commonjs-syntax.js";
|
|
@@ -119,16 +125,16 @@ import { createExtensionlessDynamicImportPlugin } from "./plugins/extensionless-
|
|
|
119
125
|
import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
120
126
|
import { consumerEnvironmentConditionFilter, getTypeofWindowReplacement, mayFoldChangeScannedImports, replaceConsumerEnvironmentConditions } from "./plugins/typeof-window.js";
|
|
121
127
|
import { hasMdxFiles, loadMdxEsmReader, pageExtensionsIncludeMdx } from "./utils/mdx-scan.js";
|
|
122
|
-
import {
|
|
128
|
+
import { publicFileRouteKey } from "./utils/public-file-path.js";
|
|
123
129
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
124
130
|
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
131
|
+
import { assertPluginRscVersion, needsAppReactServerDom } from "./utils/plugin-rsc-version.js";
|
|
125
132
|
import { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine } from "./utils/vite-version.js";
|
|
126
133
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
127
134
|
import { createRequire } from "node:module";
|
|
128
135
|
import fs from "node:fs";
|
|
129
136
|
import { pathToFileURL } from "node:url";
|
|
130
|
-
import { createIdResolver, createLogger, isRunnableDevEnvironment,
|
|
131
|
-
import { execFileSync } from "node:child_process";
|
|
137
|
+
import { createIdResolver, createLogger, isRunnableDevEnvironment, transformWithOxc } from "vite";
|
|
132
138
|
import { createHash, randomBytes } from "node:crypto";
|
|
133
139
|
import MagicString from "magic-string";
|
|
134
140
|
import commonjs from "vite-plugin-commonjs";
|
|
@@ -141,6 +147,7 @@ const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
|
141
147
|
"react/jsx-runtime",
|
|
142
148
|
"react/jsx-dev-runtime"
|
|
143
149
|
]);
|
|
150
|
+
const PAGES_CLOUDFLARE_WORKER_OPTIONAL_OPTIMIZE_DEPS_INCLUDE = Object.freeze(["use-sync-external-store/with-selector", "vinext > @vitejs/plugin-rsc/react/rsc"]);
|
|
144
151
|
const APP_CLIENT_OPTIONAL_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
145
152
|
"use-sync-external-store/shim",
|
|
146
153
|
"use-sync-external-store/shim/index.js",
|
|
@@ -156,6 +163,17 @@ const RSC_ENVIRONMENTS = /* @__PURE__ */ new Set([
|
|
|
156
163
|
"client"
|
|
157
164
|
]);
|
|
158
165
|
const VINEXT_GENERATED_DIR_RE = /(?:^|[/\\])\.vinext(?:[/\\]|$)/;
|
|
166
|
+
function removeForwardedMiddlewareContext(req) {
|
|
167
|
+
delete req.headers[VINEXT_MW_CTX_HEADER];
|
|
168
|
+
const rawHeaders = req.rawHeaders;
|
|
169
|
+
for (let i = rawHeaders.length - 2; i >= 0; i -= 2) if (rawHeaders[i].toLowerCase() === "x-vinext-mw-ctx") rawHeaders.splice(i, 2);
|
|
170
|
+
}
|
|
171
|
+
function setForwardedMiddlewareContext(req, key, context) {
|
|
172
|
+
removeForwardedMiddlewareContext(req);
|
|
173
|
+
const value = sealForwardedMiddlewareContext(key, context);
|
|
174
|
+
req.headers[VINEXT_MW_CTX_HEADER] = value;
|
|
175
|
+
req.rawHeaders.push(VINEXT_MW_CTX_HEADER, value);
|
|
176
|
+
}
|
|
159
177
|
function scopeRscPlugin(plugin) {
|
|
160
178
|
const applyToEnvironment = plugin.applyToEnvironment;
|
|
161
179
|
return {
|
|
@@ -176,11 +194,20 @@ if (earlyViteCliInvocation) {
|
|
|
176
194
|
});
|
|
177
195
|
}
|
|
178
196
|
installSocketErrorBackstop();
|
|
197
|
+
const INVALID_SERVER_ONLY_ID_PREFIX = "\0vinext:invalid-server-only:";
|
|
198
|
+
const INVALID_SERVER_ONLY_ID_RE = /^\0vinext:invalid-server-only:/;
|
|
199
|
+
function createServerOnlyClientImportError(importer) {
|
|
200
|
+
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.`);
|
|
201
|
+
}
|
|
179
202
|
function hasServerOnlyMarkerImport(code) {
|
|
180
203
|
if (!code.includes("server-only")) return false;
|
|
204
|
+
const record = parseModuleRecord(code, "js");
|
|
205
|
+
if (!record) return false;
|
|
206
|
+
if (record.staticImports.some((statement) => statement.moduleRequest.value === "server-only")) return true;
|
|
207
|
+
if (!code.includes("require")) return false;
|
|
181
208
|
let ast;
|
|
182
209
|
try {
|
|
183
|
-
ast =
|
|
210
|
+
ast = parseProgram(code);
|
|
184
211
|
} catch {
|
|
185
212
|
return false;
|
|
186
213
|
}
|
|
@@ -188,9 +215,6 @@ function hasServerOnlyMarkerImport(code) {
|
|
|
188
215
|
if (!node) return false;
|
|
189
216
|
if (Array.isArray(node)) return node.some((child) => walk(child));
|
|
190
217
|
if (typeof node !== "object") return false;
|
|
191
|
-
if (node.type === "ImportDeclaration") {
|
|
192
|
-
if (node.source?.value === "server-only") return true;
|
|
193
|
-
}
|
|
194
218
|
if (node.type === "CallExpression") {
|
|
195
219
|
const call = node;
|
|
196
220
|
if (call.callee?.type === "Identifier" && call.callee.name === "require" && call.arguments?.[0]?.type === "Literal" && call.arguments[0].value === "server-only") return true;
|
|
@@ -279,24 +303,16 @@ function isolateMdxStylesheetImports(code) {
|
|
|
279
303
|
}
|
|
280
304
|
function isolateGlobalNotFoundStylesheetImports(code, id) {
|
|
281
305
|
if (isMdxModuleId(id)) return isolateMdxStylesheetImports(code);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
ast = parseAst(code, { lang: parserLanguageForScript(id) });
|
|
285
|
-
} catch {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
306
|
+
const record = parseModuleRecord(code, parserLanguageForScript(id));
|
|
307
|
+
if (!record) return null;
|
|
288
308
|
let output = null;
|
|
289
|
-
for (const statement of
|
|
290
|
-
if (statement.
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
const specifier = source?.value;
|
|
295
|
-
if (typeof specifier !== "string" || !isStylesheetSpecifier(specifier)) continue;
|
|
296
|
-
const range = source;
|
|
297
|
-
if (typeof range.start !== "number" || typeof range.end !== "number") continue;
|
|
309
|
+
for (const statement of record.staticImports) {
|
|
310
|
+
if (statement.entries.length > 0 || isTypeOnlyImport(code, statement)) continue;
|
|
311
|
+
const source = statement.moduleRequest;
|
|
312
|
+
if (hasImportAttributes(code, source.end, statement.end)) continue;
|
|
313
|
+
if (!isStylesheetSpecifier(source.value)) continue;
|
|
298
314
|
output ??= new MagicString(code);
|
|
299
|
-
output.overwrite(
|
|
315
|
+
output.overwrite(source.start, source.end, JSON.stringify(source.value + GLOBAL_NOT_FOUND_CSS_QUERY));
|
|
300
316
|
}
|
|
301
317
|
return output ? toMagicStringTransformResult(output) : null;
|
|
302
318
|
}
|
|
@@ -309,8 +325,46 @@ function commonjsTransformFilter(id, transformProjectLocalCommonJs = false, tran
|
|
|
309
325
|
if (transformBundledDependencies && isBundledCommonJsDependency(cleanId)) return true;
|
|
310
326
|
if (/\.c[jt]s$/i.test(cleanId) && !cleanId.includes("node_modules")) return transformProjectLocalCommonJs;
|
|
311
327
|
}
|
|
312
|
-
|
|
313
|
-
|
|
328
|
+
const EMPTY_EXPORT_PRESCAN = new RegExp(String.raw`\bexport${TRIVIA_PATTERN}*\{${TRIVIA_PATTERN}*\}`);
|
|
329
|
+
/**
|
|
330
|
+
* Sources of a module's static imports and re-exports, in source order.
|
|
331
|
+
* Type-only declarations and declarations with import attributes are skipped.
|
|
332
|
+
*/
|
|
333
|
+
function runtimeStaticDependencySpecifiers(code, record, lang) {
|
|
334
|
+
const dependencies = [];
|
|
335
|
+
for (const statement of record.staticImports) {
|
|
336
|
+
if (isTypeOnlyImport(code, statement)) continue;
|
|
337
|
+
if (hasImportAttributes(code, statement.moduleRequest.end, statement.end)) continue;
|
|
338
|
+
dependencies.push({
|
|
339
|
+
start: statement.start,
|
|
340
|
+
specifier: statement.moduleRequest.value
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
for (const statement of record.staticExports) {
|
|
344
|
+
const source = statement.entries[0]?.moduleRequest;
|
|
345
|
+
if (!source || statement.entries.every((entry) => entry.isType)) continue;
|
|
346
|
+
if (hasImportAttributes(code, source.end, statement.end)) continue;
|
|
347
|
+
dependencies.push({
|
|
348
|
+
start: statement.start,
|
|
349
|
+
specifier: source.value
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (EMPTY_EXPORT_PRESCAN.test(code)) {
|
|
353
|
+
let program = null;
|
|
354
|
+
try {
|
|
355
|
+
program = parseProgram(code, { lang });
|
|
356
|
+
} catch {}
|
|
357
|
+
for (const statement of program?.body ?? []) {
|
|
358
|
+
if (statement.type !== "ExportNamedDeclaration" || !statement.source) continue;
|
|
359
|
+
if (statement.specifiers.length > 0 || statement.exportKind === "type") continue;
|
|
360
|
+
if (statement.attributes.length > 0) continue;
|
|
361
|
+
dependencies.push({
|
|
362
|
+
start: statement.start,
|
|
363
|
+
specifier: statement.source.value
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return dependencies.sort((a, b) => a.start - b.start).map(({ specifier }) => specifier);
|
|
314
368
|
}
|
|
315
369
|
function resolvedStylesheetToDevManifestAsset(root, resolvedId) {
|
|
316
370
|
const cleanId = stripViteModuleQuery(resolvedId);
|
|
@@ -342,22 +396,17 @@ function createDevPagesModuleDependencyReader(root, resolve) {
|
|
|
342
396
|
async function collectModuleDependencies(modulePath) {
|
|
343
397
|
const cleanModulePath = stripViteModuleQuery(modulePath);
|
|
344
398
|
if (!path.isAbsolute(cleanModulePath) || !fs.existsSync(cleanModulePath)) return [];
|
|
345
|
-
let
|
|
399
|
+
let code;
|
|
346
400
|
try {
|
|
347
|
-
|
|
401
|
+
code = fs.readFileSync(cleanModulePath, "utf-8");
|
|
348
402
|
} catch {
|
|
349
403
|
return [];
|
|
350
404
|
}
|
|
405
|
+
const record = parseModuleRecord(code, parserLanguageForScript(cleanModulePath));
|
|
406
|
+
if (!record) return [];
|
|
351
407
|
const dependencies = [];
|
|
352
|
-
for (const
|
|
353
|
-
|
|
354
|
-
if (statement.importKind === "type") continue;
|
|
355
|
-
if (statement.exportKind === "type") continue;
|
|
356
|
-
if (hasOnlyTypeSpecifiers(statement)) continue;
|
|
357
|
-
if (statement.attributes && statement.attributes.length > 0) continue;
|
|
358
|
-
const specifier = statement.source?.value;
|
|
359
|
-
if (typeof specifier !== "string") continue;
|
|
360
|
-
const resolved = await resolve(specifier, cleanModulePath, { skipSelf: true });
|
|
408
|
+
for (const specifier of runtimeStaticDependencySpecifiers(code, record, parserLanguageForScript(cleanModulePath))) {
|
|
409
|
+
const resolved = await resolve(specifier, cleanModulePath, { skipSelf: false });
|
|
361
410
|
if (!resolved?.id) continue;
|
|
362
411
|
if (isStylesheetSpecifier(specifier) || isStylesheetSpecifier(resolved.id)) {
|
|
363
412
|
const asset = resolvedStylesheetToDevManifestAsset(root, resolved.id);
|
|
@@ -700,6 +749,11 @@ const VIRTUAL_CACHEABILITY_REQUEST_PROJECTION = "virtual:vinext-cacheability-req
|
|
|
700
749
|
const RESOLVED_CACHEABILITY_REQUEST_PROJECTION = "\0" + VIRTUAL_CACHEABILITY_REQUEST_PROJECTION;
|
|
701
750
|
const VIRTUAL_PREGENERATED_CONCRETE_PATHS = "virtual:vinext-pregenerated-concrete-paths";
|
|
702
751
|
const RESOLVED_PREGENERATED_CONCRETE_PATHS = "\0" + VIRTUAL_PREGENERATED_CONCRETE_PATHS;
|
|
752
|
+
const OUTPUT_ROOT_SERVER_EXTERNALS = /* @__PURE__ */ new Map([
|
|
753
|
+
[VIRTUAL_CACHEABILITY_MANIFEST, CACHEABILITY_MANIFEST_MODULE],
|
|
754
|
+
[VIRTUAL_CACHEABILITY_REQUEST_PROJECTION, CACHEABILITY_REQUEST_PROJECTION_MODULE],
|
|
755
|
+
[VIRTUAL_PREGENERATED_CONCRETE_PATHS, PREGENERATED_CONCRETE_PATHS_MODULE]
|
|
756
|
+
]);
|
|
703
757
|
const VIRTUAL_APP_REQUEST_ENTRY = "virtual:vinext-app-request-entry";
|
|
704
758
|
const RESOLVED_APP_REQUEST_ENTRY = "\0" + VIRTUAL_APP_REQUEST_ENTRY;
|
|
705
759
|
const VIRTUAL_APP_RESPONSE_ENTRY = "virtual:vinext-app-response-entry";
|
|
@@ -891,7 +945,7 @@ function vinext(options = {}) {
|
|
|
891
945
|
let hasPlainPagesBuildEnvironments = false;
|
|
892
946
|
let originalPlainPagesEnvironments;
|
|
893
947
|
let buildLifecycleInvocation;
|
|
894
|
-
let
|
|
948
|
+
let reactVersionChecked = false;
|
|
895
949
|
let pagesOptimizeEntries = [];
|
|
896
950
|
const importMetaUrlCapability = createImportMetaUrlPlugin({
|
|
897
951
|
getRoot: () => root,
|
|
@@ -901,8 +955,10 @@ function vinext(options = {}) {
|
|
|
901
955
|
}
|
|
902
956
|
});
|
|
903
957
|
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
958
|
+
const pagesClientAssetsExternalTargets = /* @__PURE__ */ new Map();
|
|
904
959
|
const resolvePagesClientAssetsOutputDir = (environmentName, outputDir) => !selectedMultiStageOutput && !hasAppDir && !hasCloudflarePlugin && environmentName === "ssr" ? path.dirname(outputDir) : outputDir;
|
|
905
960
|
let pagesClientAssetsModule = internalOptions.__pagesClientAssetsModule ?? null;
|
|
961
|
+
let clientBuildFiles = [];
|
|
906
962
|
let devPublicFileRoutes = null;
|
|
907
963
|
let publicDirConflictOptions = null;
|
|
908
964
|
let copyPublicDirIntoStaticExportBasePath = false;
|
|
@@ -911,6 +967,7 @@ function vinext(options = {}) {
|
|
|
911
967
|
let draftModeSecret = getPagesPreviewModeId();
|
|
912
968
|
const prerenderSecret = process.env.__VINEXT_SHARED_PRERENDER_SECRET ?? randomBytes(32).toString("hex");
|
|
913
969
|
let revalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
|
|
970
|
+
const devForwardedMiddlewareContextKey = randomBytes(32).toString("hex");
|
|
914
971
|
let previewBuildCredentials;
|
|
915
972
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
916
973
|
const rscClassificationManifests = /* @__PURE__ */ new Map();
|
|
@@ -999,6 +1056,7 @@ function vinext(options = {}) {
|
|
|
999
1056
|
let rscPluginModulePromise = null;
|
|
1000
1057
|
resolvedReactPath = resolveOptionalDependency(earlyBaseDir, "@vitejs/plugin-react");
|
|
1001
1058
|
resolvedRscPath = resolveOptionalDependency(earlyBaseDir, "@vitejs/plugin-rsc");
|
|
1059
|
+
const rscVersion = earlyAppDirExists && resolvedRscPath ? assertPluginRscVersion(resolvedRscPath) : null;
|
|
1002
1060
|
let rscPluginPromise = null;
|
|
1003
1061
|
let manualUseCachePluginPromise = null;
|
|
1004
1062
|
if (earlyAppDirExists && autoRsc) {
|
|
@@ -1018,7 +1076,7 @@ function vinext(options = {}) {
|
|
|
1018
1076
|
});
|
|
1019
1077
|
const useServerIndex = plugins.findIndex((plugin) => plugin.name === "rsc:use-server");
|
|
1020
1078
|
if (useServerIndex === -1) throw new Error("vinext: Failed to locate @vitejs/plugin-rsc use-server plugin.");
|
|
1021
|
-
plugins.splice(useServerIndex, 0,
|
|
1079
|
+
plugins.splice(useServerIndex, 0, useCachePlugin);
|
|
1022
1080
|
return plugins.map(scopeRscPlugin);
|
|
1023
1081
|
}).catch((cause) => {
|
|
1024
1082
|
throw new Error("vinext: Failed to load @vitejs/plugin-rsc.", { cause });
|
|
@@ -1190,17 +1248,13 @@ function vinext(options = {}) {
|
|
|
1190
1248
|
shouldDeferPostBuild: () => buildLifecycleInvocation !== void 0,
|
|
1191
1249
|
shouldPrepare: (config) => buildLifecycleEnabled && config.build?.write !== false && !config.build?.lib && (buildLifecycleInvocation !== void 0 || !config.build?.watch && !config.build?.ssr && getBuildBundlerOptions(config.build)?.input === void 0),
|
|
1192
1250
|
onPrepare: () => {
|
|
1193
|
-
if (!hasAppDir ||
|
|
1194
|
-
|
|
1251
|
+
if (!hasAppDir || reactVersionChecked) return;
|
|
1252
|
+
reactVersionChecked = true;
|
|
1195
1253
|
const reactUpgrade = getReactUpgradeDeps(root);
|
|
1254
|
+
const needsAppRsdw = rscVersion !== null && needsAppReactServerDom(process.cwd(), rscVersion);
|
|
1255
|
+
if (needsAppRsdw && !reactUpgrade.includes("react-server-dom-webpack@latest")) reactUpgrade.push("react-server-dom-webpack@latest");
|
|
1196
1256
|
if (reactUpgrade.length === 0) return;
|
|
1197
|
-
|
|
1198
|
-
console.log(" Upgrading React for RSC compatibility...");
|
|
1199
|
-
execFileSync(packageManager, [...packageManagerArgs, ...reactUpgrade], {
|
|
1200
|
-
cwd: root,
|
|
1201
|
-
stdio: "inherit",
|
|
1202
|
-
shell: process.platform === "win32"
|
|
1203
|
-
});
|
|
1257
|
+
throw new Error(reactUpgradeRequiredMessage(detectPackageManager(root).replace(/ -D$/, ""), reactUpgrade, needsAppRsdw ? rscVersion : void 0));
|
|
1204
1258
|
},
|
|
1205
1259
|
shouldBuildPlainPages: () => !hasAppDir && !hasCloudflarePlugin && !hasNitroPlugin,
|
|
1206
1260
|
createContext: () => ({
|
|
@@ -1325,6 +1379,7 @@ function vinext(options = {}) {
|
|
|
1325
1379
|
buildEmptyOutDir = typeof config.build?.emptyOutDir === "boolean" ? config.build.emptyOutDir : void 0;
|
|
1326
1380
|
isServeCommand = env.command === "serve";
|
|
1327
1381
|
root = path.resolve(toSlash(process.cwd()), config.root ?? ".");
|
|
1382
|
+
if (env.command === "build") assertClientOutDirIsSeparate(root, options);
|
|
1328
1383
|
const devCliLifecycleEnabled = env.command === "serve" && env.isPreview !== true && claimViteCliDevInvocation(root, config["__vinextDevRestart"] === true, reservedDevCliInvocation && config.configFile === false);
|
|
1329
1384
|
buildLifecycleInvocation = config[VINEXT_BUILD_LIFECYCLE_CONFIG];
|
|
1330
1385
|
buildLifecycleEnabled = env.command === "build" && !internalOptions.__skipBuildLifecycle && (buildLifecycleInvocation !== void 0 || claimViteCliBuildInvocation());
|
|
@@ -1442,6 +1497,7 @@ function vinext(options = {}) {
|
|
|
1442
1497
|
defines["process.env.__NEXT_TEST_MODE"] = JSON.stringify(process.env.__NEXT_TEST_MODE ?? false);
|
|
1443
1498
|
defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
|
|
1444
1499
|
defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
|
|
1500
|
+
defines["process.env.__VINEXT_MANUAL_TRAILING_SLASH"] = JSON.stringify(nextConfig.skipTrailingSlashRedirect ? "true" : "false");
|
|
1445
1501
|
defines["process.env.__NEXT_CONFIG_OUTPUT"] = JSON.stringify(nextConfig.output ?? "");
|
|
1446
1502
|
defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
|
|
1447
1503
|
defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
|
|
@@ -1507,6 +1563,7 @@ function vinext(options = {}) {
|
|
|
1507
1563
|
"vinext/head-state": path.join(shimsDir, "head-state"),
|
|
1508
1564
|
"vinext/i18n-state": path.join(shimsDir, "i18n-state"),
|
|
1509
1565
|
"vinext/i18n-context": path.join(shimsDir, "i18n-context"),
|
|
1566
|
+
"vinext/document-placeholders": path.join(shimsDir, "document-placeholders"),
|
|
1510
1567
|
"vinext/client": path.resolve(__dirname, "client", "index"),
|
|
1511
1568
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
1512
1569
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
@@ -1598,7 +1655,14 @@ function vinext(options = {}) {
|
|
|
1598
1655
|
...!isSSR && !isMultiEnv ? { output: getClientOutputConfig(clientAssetsDir) } : {}
|
|
1599
1656
|
})
|
|
1600
1657
|
},
|
|
1601
|
-
worker: { plugins: () => [
|
|
1658
|
+
worker: { plugins: () => [
|
|
1659
|
+
createWorkerImageImportsPlugin({ deploymentId: nextConfig.deploymentId }),
|
|
1660
|
+
createWorkerServerOnlyImportsPlugin(),
|
|
1661
|
+
...rscPluginModulePromise && resolvedRscPath ? [createWorkerUseServerPlugins({
|
|
1662
|
+
rscPluginModule: rscPluginModulePromise,
|
|
1663
|
+
rscPluginPath: resolvedRscPath
|
|
1664
|
+
})] : []
|
|
1665
|
+
] },
|
|
1602
1666
|
server: {
|
|
1603
1667
|
watch: config.server?.watch === null ? null : {
|
|
1604
1668
|
ignored: [VINEXT_GENERATED_DIR_RE],
|
|
@@ -1835,6 +1899,7 @@ function vinext(options = {}) {
|
|
|
1835
1899
|
...depOptimizeNodeEnvOptions
|
|
1836
1900
|
},
|
|
1837
1901
|
build: {
|
|
1902
|
+
...options.clientOutDir ? { outDir: options.clientOutDir } : {},
|
|
1838
1903
|
manifest: true,
|
|
1839
1904
|
...hasPagesDir ? { ssrManifest: true } : {},
|
|
1840
1905
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
@@ -1854,6 +1919,7 @@ function vinext(options = {}) {
|
|
|
1854
1919
|
...depOptimizeNodeEnvOptions
|
|
1855
1920
|
},
|
|
1856
1921
|
build: {
|
|
1922
|
+
...options.clientOutDir ? { outDir: options.clientOutDir } : {},
|
|
1857
1923
|
manifest: true,
|
|
1858
1924
|
ssrManifest: true,
|
|
1859
1925
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
@@ -1874,7 +1940,7 @@ function vinext(options = {}) {
|
|
|
1874
1940
|
...depOptimizeNodeEnvOptions
|
|
1875
1941
|
},
|
|
1876
1942
|
build: {
|
|
1877
|
-
outDir: "dist/client",
|
|
1943
|
+
outDir: options.clientOutDir ?? "dist/client",
|
|
1878
1944
|
manifest: true,
|
|
1879
1945
|
ssrManifest: true,
|
|
1880
1946
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
@@ -1954,9 +2020,10 @@ function vinext(options = {}) {
|
|
|
1954
2020
|
const optionalWarnings = /* @__PURE__ */ new Set();
|
|
1955
2021
|
for (const [name, environment] of Object.entries(config.environments)) {
|
|
1956
2022
|
const optimizer = environment.optimizeDeps;
|
|
1957
|
-
const optionalIncludes = hasAppDir ? name === "client" && !optimizer.noDiscovery ? APP_CLIENT_OPTIONAL_OPTIMIZE_DEPS_INCLUDE : [] : name !== "client" ?
|
|
2023
|
+
const optionalIncludes = hasAppDir ? name === "client" && !optimizer.noDiscovery ? APP_CLIENT_OPTIONAL_OPTIMIZE_DEPS_INCLUDE : [] : name !== "client" ? PAGES_CLOUDFLARE_WORKER_OPTIONAL_OPTIMIZE_DEPS_INCLUDE : [];
|
|
1958
2024
|
for (const id of optionalIncludes) {
|
|
1959
|
-
|
|
2025
|
+
const depId = id.slice(id.lastIndexOf(">") + 1).trim();
|
|
2026
|
+
if (optimizer.include?.includes(id) || optimizer.include?.includes(depId) || optimizer.exclude?.some((excluded) => depId === excluded || depId.startsWith(`${excluded}/`))) continue;
|
|
1960
2027
|
(optimizer.include ??= []).push(id);
|
|
1961
2028
|
optionalWarnings.add(`Failed to resolve dependency: ${id}, present in ${name} 'optimizeDeps.include'`);
|
|
1962
2029
|
}
|
|
@@ -2084,21 +2151,21 @@ function vinext(options = {}) {
|
|
|
2084
2151
|
if (cleanId === VIRTUAL_RSC_ENTRY) return RESOLVED_RSC_ENTRY;
|
|
2085
2152
|
if (cleanId === VIRTUAL_CACHEABILITY_MANIFEST) {
|
|
2086
2153
|
if ((hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment)) && this.environment.config?.command === "build") return {
|
|
2087
|
-
id:
|
|
2154
|
+
id: VIRTUAL_CACHEABILITY_MANIFEST,
|
|
2088
2155
|
external: true
|
|
2089
2156
|
};
|
|
2090
2157
|
return RESOLVED_CACHEABILITY_MANIFEST;
|
|
2091
2158
|
}
|
|
2092
2159
|
if (cleanId === VIRTUAL_CACHEABILITY_REQUEST_PROJECTION) {
|
|
2093
2160
|
if (hasAppDir && this.environment?.name === "rsc" && this.environment.config?.command === "build") return {
|
|
2094
|
-
id:
|
|
2161
|
+
id: VIRTUAL_CACHEABILITY_REQUEST_PROJECTION,
|
|
2095
2162
|
external: true
|
|
2096
2163
|
};
|
|
2097
2164
|
return RESOLVED_CACHEABILITY_REQUEST_PROJECTION;
|
|
2098
2165
|
}
|
|
2099
2166
|
if (cleanId === VIRTUAL_PREGENERATED_CONCRETE_PATHS) {
|
|
2100
2167
|
if ((hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment)) && this.environment.config?.command === "build") return {
|
|
2101
|
-
id:
|
|
2168
|
+
id: VIRTUAL_PREGENERATED_CONCRETE_PATHS,
|
|
2102
2169
|
external: true
|
|
2103
2170
|
};
|
|
2104
2171
|
return RESOLVED_PREGENERATED_CONCRETE_PATHS;
|
|
@@ -2206,6 +2273,7 @@ function vinext(options = {}) {
|
|
|
2206
2273
|
nodeOpenTelemetryLoader: registerNodeOpenTelemetryLoader,
|
|
2207
2274
|
assetPrefix: nextConfig?.assetPrefix,
|
|
2208
2275
|
crossOrigin: nextConfig?.crossOrigin,
|
|
2276
|
+
skipTrailingSlashRedirect: nextConfig?.skipTrailingSlashRedirect,
|
|
2209
2277
|
expireTime: nextConfig?.expireTime,
|
|
2210
2278
|
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
2211
2279
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
@@ -2230,7 +2298,8 @@ function vinext(options = {}) {
|
|
|
2230
2298
|
publicFiles: isServeCommand && devPublicFileRoutes ? [...devPublicFileRoutes].sort() : scanPublicFileRoutes(root, this.environment.config.publicDir === "" ? false : this.environment.config.publicDir),
|
|
2231
2299
|
globalNotFoundPath,
|
|
2232
2300
|
draftModeSecret,
|
|
2233
|
-
prerenderSecret
|
|
2301
|
+
prerenderSecret,
|
|
2302
|
+
devForwardedMiddlewareContextKey: isServeCommand && this.environment.config.consumer === "server" ? devForwardedMiddlewareContextKey : void 0
|
|
2234
2303
|
}, instrumentationPath);
|
|
2235
2304
|
}
|
|
2236
2305
|
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
@@ -2332,15 +2401,19 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2332
2401
|
const buildRoot = this.environment.config.root ?? process.cwd();
|
|
2333
2402
|
const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
|
|
2334
2403
|
const sidecarDir = resolvePagesClientAssetsOutputDir(this.environment.name, environmentOutDir);
|
|
2335
|
-
|
|
2336
|
-
if (!externalId.startsWith(".")) externalId = `./${externalId}`;
|
|
2404
|
+
pagesClientAssetsExternalTargets.set(this.environment.name, /* @__PURE__ */ new Map([[VIRTUAL_PAGES_CLIENT_ASSETS, path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE))]]));
|
|
2337
2405
|
pagesClientAssetsOutputDirs.add(sidecarDir);
|
|
2338
2406
|
return {
|
|
2339
|
-
id:
|
|
2407
|
+
id: VIRTUAL_PAGES_CLIENT_ASSETS,
|
|
2340
2408
|
external: true
|
|
2341
2409
|
};
|
|
2342
2410
|
}
|
|
2343
2411
|
},
|
|
2412
|
+
renderChunk(code, chunk) {
|
|
2413
|
+
const targets = pagesClientAssetsExternalTargets.get(this.environment.name);
|
|
2414
|
+
if (!targets) return null;
|
|
2415
|
+
return rewriteOutputRootExternals(code, chunk.fileName, targets);
|
|
2416
|
+
},
|
|
2344
2417
|
outputOptions(output) {
|
|
2345
2418
|
const environment = this.environment;
|
|
2346
2419
|
if (!selectedMultiStageOutput || !environment || !isMultiStageServerEnvironment(environment)) return;
|
|
@@ -2446,6 +2519,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2446
2519
|
{
|
|
2447
2520
|
name: "vinext:cacheability-manifest-asset",
|
|
2448
2521
|
apply: "build",
|
|
2522
|
+
renderChunk(code, chunk) {
|
|
2523
|
+
return rewriteOutputRootExternals(code, chunk.fileName, OUTPUT_ROOT_SERVER_EXTERNALS);
|
|
2524
|
+
},
|
|
2449
2525
|
generateBundle() {
|
|
2450
2526
|
if (!(hasAppDir ? this.environment?.name === "rsc" : this.environment !== void 0 && isServerEnvironment(this.environment))) return;
|
|
2451
2527
|
this.emitFile({
|
|
@@ -2595,10 +2671,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2595
2671
|
}
|
|
2596
2672
|
},
|
|
2597
2673
|
configureServer(server) {
|
|
2674
|
+
installSocketErrorBackstop({ runningServer: true });
|
|
2598
2675
|
const devBuildId = nextConfig?.buildId ?? process.env.__VINEXT_BUILD_ID ?? "development";
|
|
2599
2676
|
server.middlewares.use((req, _res, next) => {
|
|
2600
2677
|
req.__vinextOriginalEncodedUrl ??= req.url;
|
|
2601
|
-
|
|
2678
|
+
removeForwardedMiddlewareContext(req);
|
|
2602
2679
|
next();
|
|
2603
2680
|
});
|
|
2604
2681
|
const pageExtensions = fileMatcher.extensionRegex;
|
|
@@ -2609,7 +2686,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2609
2686
|
return new URL(resolved).origin;
|
|
2610
2687
|
} catch {}
|
|
2611
2688
|
const address = server.httpServer?.address();
|
|
2612
|
-
return `http://localhost:${typeof address === "object" && address ? address.port : server.config.server.port
|
|
2689
|
+
return `http://localhost:${typeof address === "object" && address ? address.port : server.config.server.port}`;
|
|
2613
2690
|
};
|
|
2614
2691
|
let cachedSSRHandler = null;
|
|
2615
2692
|
const devPageRouteDataKinds = /* @__PURE__ */ new Map();
|
|
@@ -2777,7 +2854,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2777
2854
|
const cleanPath = toSlash(stripViteModuleQuery(filePath));
|
|
2778
2855
|
const relativePath = path.relative(devPublicDir, cleanPath);
|
|
2779
2856
|
if (relativePath === "" || relativePath.startsWith("../") || path.isAbsolute(relativePath)) return null;
|
|
2780
|
-
return
|
|
2857
|
+
return [publicFileRouteKey(`/${relativePath}`)];
|
|
2781
2858
|
};
|
|
2782
2859
|
const updatePublicFileRoute = (filePath, present) => {
|
|
2783
2860
|
const routes = publicRoutesForFile(filePath);
|
|
@@ -3072,16 +3149,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3072
3149
|
}
|
|
3073
3150
|
const canonicalOriginalUrl = canonicalizeRequestUrlPathname(originalEncodedUrl);
|
|
3074
3151
|
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
3152
|
let middlewareUrl = canonicalOriginalUrl;
|
|
3079
3153
|
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
3154
|
let pathname = url.split("?")[0];
|
|
3086
3155
|
if (isOpenRedirectShaped(pathname)) {
|
|
3087
3156
|
res.writeHead(404);
|
|
@@ -3129,7 +3198,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3129
3198
|
}
|
|
3130
3199
|
}
|
|
3131
3200
|
let configMatchPathname = stripBasePath(middlewareUrl.split("?")[0], routingBasePath);
|
|
3132
|
-
if (nextConfig) {
|
|
3201
|
+
if (nextConfig && !nextConfig.skipTrailingSlashRedirect) {
|
|
3133
3202
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
3134
3203
|
const trailingSlashRedirect = normalizeTrailingSlash(routeUrl.split("?")[0], bp, nextConfig.trailingSlash, qs);
|
|
3135
3204
|
if (trailingSlashRedirect) {
|
|
@@ -3142,18 +3211,22 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3142
3211
|
if (hasCloudflarePlugin) return next();
|
|
3143
3212
|
let isDataReq = false;
|
|
3144
3213
|
let dataNotFoundResponse = null;
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3214
|
+
const rawRoutePathname = routeUrl.split("?")[0];
|
|
3215
|
+
if (isNextDataPathname(rawRoutePathname)) {
|
|
3216
|
+
const rawDataMatch = parseNextDataPathname(rawRoutePathname, devBuildId);
|
|
3217
|
+
const dataMatch = rawDataMatch ? parseNextDataPathname(pathname, devBuildId) : null;
|
|
3218
|
+
if (dataMatch && rawDataMatch) {
|
|
3148
3219
|
isDataReq = true;
|
|
3149
3220
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
3150
|
-
const
|
|
3221
|
+
const addTrailingSlash = shouldAddTrailingSlashToPagesDataPath(capturedMiddlewarePath !== null, nextConfig?.trailingSlash === true, nextConfig?.skipProxyUrlNormalize === true);
|
|
3222
|
+
const pagePathname = normalizeNextDataPagePathname(dataMatch.pagePathname, addTrailingSlash);
|
|
3223
|
+
const rawPagePathname = normalizeNextDataPagePathname(rawDataMatch.pagePathname, addTrailingSlash);
|
|
3151
3224
|
url = pagePathname + qs;
|
|
3152
|
-
|
|
3153
|
-
|
|
3225
|
+
routeUrl = rawPagePathname + qs;
|
|
3226
|
+
if (!nextConfig?.skipProxyUrlNormalize) middlewareUrl = routeUrl;
|
|
3154
3227
|
pathname = pagePathname;
|
|
3155
|
-
configMatchPathname =
|
|
3156
|
-
req.url =
|
|
3228
|
+
configMatchPathname = rawPagePathname;
|
|
3229
|
+
req.url = routeUrl;
|
|
3157
3230
|
} else {
|
|
3158
3231
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
3159
3232
|
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
@@ -3202,6 +3275,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3202
3275
|
signal: signalFromNodeResponse(res)
|
|
3203
3276
|
});
|
|
3204
3277
|
const applyRequestHeadersToNodeRequest = (nextRequestHeaders) => {
|
|
3278
|
+
removeForwardedMiddlewareContext(req);
|
|
3205
3279
|
for (const key of Object.keys(req.headers)) delete req.headers[key];
|
|
3206
3280
|
for (const [key, value] of nextRequestHeaders) req.headers[key] = value;
|
|
3207
3281
|
};
|
|
@@ -3213,18 +3287,19 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3213
3287
|
headers: nodeRequestHeaders,
|
|
3214
3288
|
signal: webRequest.signal
|
|
3215
3289
|
});
|
|
3216
|
-
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest, pathname);
|
|
3290
|
+
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest, pathname, opts.isStaleDataRequest, nextConfig?.skipTrailingSlashRedirect);
|
|
3217
3291
|
if (hasAppDir && result.continue) {
|
|
3218
3292
|
const mwCtxEntries = [];
|
|
3219
3293
|
if (result.responseHeaders) {
|
|
3220
3294
|
for (const [key, value] of result.responseHeaders) if (key !== "x-middleware-next" && key !== "x-middleware-rewrite") mwCtxEntries.push([key, value]);
|
|
3221
3295
|
}
|
|
3222
3296
|
const mwStatus = result.status ?? result.rewriteStatus;
|
|
3223
|
-
req
|
|
3297
|
+
setForwardedMiddlewareContext(req, devForwardedMiddlewareContextKey, JSON.stringify({
|
|
3224
3298
|
h: mwCtxEntries,
|
|
3225
3299
|
s: mwStatus ?? null,
|
|
3226
|
-
r: result.rewriteUrl ?? null
|
|
3227
|
-
|
|
3300
|
+
r: result.rewriteUrl ?? null,
|
|
3301
|
+
b: result.rewriteHadBasePath ?? null
|
|
3302
|
+
}));
|
|
3228
3303
|
}
|
|
3229
3304
|
return result;
|
|
3230
3305
|
} : null;
|
|
@@ -3238,6 +3313,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3238
3313
|
assetPrefix: nextConfig?.assetPrefix,
|
|
3239
3314
|
basePath: bp,
|
|
3240
3315
|
trailingSlash: nextConfig?.trailingSlash ?? false,
|
|
3316
|
+
skipTrailingSlashRedirect: nextConfig?.skipTrailingSlashRedirect ?? false,
|
|
3241
3317
|
i18nConfig: nextConfig?.i18n ?? null,
|
|
3242
3318
|
configRedirects: nextConfig?.redirects ?? [],
|
|
3243
3319
|
configRewrites: nextConfig?.rewrites ?? {
|
|
@@ -3286,8 +3362,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3286
3362
|
const reqWithBody = new Request(new URL(url, requestOrigin), externalInit);
|
|
3287
3363
|
return proxyExternalRequest(reqWithBody, externalUrl);
|
|
3288
3364
|
},
|
|
3289
|
-
serveFilesystemRoute: async (requestPathname, stagedHeaders, phase, resolvedUrl) => {
|
|
3290
|
-
if (isImageOptimizationPath(requestPathname)) {
|
|
3365
|
+
serveFilesystemRoute: async (requestPathname, stagedHeaders, phase, resolvedUrl, _request, resolvedPathnameHasBasePath) => {
|
|
3366
|
+
if (resolvedPathnameHasBasePath && isImageOptimizationPath(requestPathname)) {
|
|
3291
3367
|
const imageRequestUrl = new URL(resolvedUrl, requestOrigin);
|
|
3292
3368
|
const allowedWidths = [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES];
|
|
3293
3369
|
const encodedLocation = resolveDevImageRedirect(imageRequestUrl, allowedWidths, nextConfig.images?.qualities);
|
|
@@ -3298,7 +3374,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3298
3374
|
}
|
|
3299
3375
|
const isRetrievalMethod = req.method === "GET" || req.method === "HEAD";
|
|
3300
3376
|
if (phase === "direct" && isRetrievalMethod || requestPathname === "/" || requestPathname === "/api" || requestPathname.startsWith("/api/")) return false;
|
|
3301
|
-
if (!isRetrievalMethod) return isExistingDevPublicFile(requestPathname) ? methodNotAllowedResponse("GET, HEAD") : false;
|
|
3377
|
+
if (!isRetrievalMethod) return isExistingDevPublicFile(normalizePathnameForRouteMatch(requestPathname)) ? methodNotAllowedResponse("GET, HEAD") : false;
|
|
3302
3378
|
return serveRewrittenViteFilesystemRoute(req, res, requestPathname, stagedHeaders);
|
|
3303
3379
|
}
|
|
3304
3380
|
};
|
|
@@ -3325,12 +3401,12 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3325
3401
|
const requestHeaders = new Headers();
|
|
3326
3402
|
encodeMiddlewareRequestHeaders(requestHeaders, pipelineResult.requestHeaders);
|
|
3327
3403
|
flushRequestHeaders();
|
|
3328
|
-
req
|
|
3404
|
+
setForwardedMiddlewareContext(req, devForwardedMiddlewareContextKey, JSON.stringify({
|
|
3329
3405
|
h: responseHeaders,
|
|
3330
3406
|
q: [...requestHeaders],
|
|
3331
3407
|
s: pipelineResult.middlewareStatus ?? null,
|
|
3332
3408
|
r: apiUrl
|
|
3333
|
-
});
|
|
3409
|
+
}));
|
|
3334
3410
|
};
|
|
3335
3411
|
if (pipelineResult.type === "api") {
|
|
3336
3412
|
const devApiRoutes = await getDevApiRoutes();
|
|
@@ -3350,7 +3426,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3350
3426
|
i18n: nextConfig?.i18n,
|
|
3351
3427
|
trustedRevalidateOrigin: getTrustedDevRevalidateOrigin(),
|
|
3352
3428
|
allowedRevalidateHeaderKeys: nextConfig?.allowedRevalidateHeaderKeys,
|
|
3353
|
-
trailingSlash: nextConfig?.trailingSlash
|
|
3429
|
+
trailingSlash: nextConfig?.trailingSlash,
|
|
3430
|
+
skipTrailingSlashRedirect: nextConfig?.skipTrailingSlashRedirect
|
|
3354
3431
|
})) return;
|
|
3355
3432
|
if (hasAppDir) {
|
|
3356
3433
|
if (pipelineResult.configRewriteFired) forwardInternalApiRewriteToApp(pipelineResult.apiUrl);
|
|
@@ -3498,6 +3575,25 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3498
3575
|
},
|
|
3499
3576
|
{
|
|
3500
3577
|
name: "vinext:validate-server-only-client-imports",
|
|
3578
|
+
resolveId: {
|
|
3579
|
+
order: "pre",
|
|
3580
|
+
filter: { id: SERVER_ONLY_SPECIFIER_RE },
|
|
3581
|
+
handler(_source, importer) {
|
|
3582
|
+
const environment = this.environment;
|
|
3583
|
+
if (environment?.name !== "client" || hasAppDir) return null;
|
|
3584
|
+
if (environment.mode === "dev" && !(importer && environment.moduleGraph.getModuleById(importer))) return {
|
|
3585
|
+
id: INVALID_SERVER_ONLY_ID_PREFIX + (importer ?? ""),
|
|
3586
|
+
moduleSideEffects: true
|
|
3587
|
+
};
|
|
3588
|
+
throw createServerOnlyClientImportError(importer);
|
|
3589
|
+
}
|
|
3590
|
+
},
|
|
3591
|
+
load: {
|
|
3592
|
+
filter: { id: INVALID_SERVER_ONLY_ID_RE },
|
|
3593
|
+
handler(id) {
|
|
3594
|
+
throw createServerOnlyClientImportError(id.slice(28));
|
|
3595
|
+
}
|
|
3596
|
+
},
|
|
3501
3597
|
transform: {
|
|
3502
3598
|
filter: {
|
|
3503
3599
|
id: {
|
|
@@ -3507,7 +3603,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3507
3603
|
code: "server-only"
|
|
3508
3604
|
},
|
|
3509
3605
|
handler(code) {
|
|
3510
|
-
if (this.environment?.name !== "client") return null;
|
|
3606
|
+
if (this.environment?.name !== "client" || !hasAppDir) return null;
|
|
3607
|
+
// @vitejs/plugin-rsc replaces a "use server" module in the client
|
|
3511
3608
|
if (getLeadingReactDirective(code) === "use server") return null;
|
|
3512
3609
|
if (!hasServerOnlyMarkerImport(code)) return null;
|
|
3513
3610
|
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.`);
|
|
@@ -3665,27 +3762,18 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3665
3762
|
},
|
|
3666
3763
|
async handler(code, id) {
|
|
3667
3764
|
const lang = id.endsWith(".ts") ? "ts" : "tsx";
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
ast = parseAst(code, { lang });
|
|
3671
|
-
} catch {
|
|
3672
|
-
return null;
|
|
3673
|
-
}
|
|
3765
|
+
const record = parseModuleRecord(code, lang);
|
|
3766
|
+
if (!record) return null;
|
|
3674
3767
|
const s = new MagicString(code);
|
|
3675
3768
|
let hasChanges = false;
|
|
3676
3769
|
const imageImports = /* @__PURE__ */ new Set();
|
|
3677
|
-
for (const
|
|
3678
|
-
|
|
3679
|
-
const importNode = node;
|
|
3680
|
-
const importPath = importNode.source?.value;
|
|
3681
|
-
if (typeof importPath !== "string") continue;
|
|
3770
|
+
for (const importNode of record.staticImports) {
|
|
3771
|
+
const importPath = importNode.moduleRequest.value;
|
|
3682
3772
|
if (!IMAGE_EXT_RE.test(importPath)) continue;
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
const varName = specifier.local?.name;
|
|
3688
|
-
if (!varName) continue;
|
|
3773
|
+
if (importNode.entries.length !== 1) continue;
|
|
3774
|
+
const [entry] = importNode.entries;
|
|
3775
|
+
if (entry.importName.kind !== "Default") continue;
|
|
3776
|
+
const varName = entry.localName.value;
|
|
3689
3777
|
const dir = path.dirname(id);
|
|
3690
3778
|
const resolvedImage = importPath.startsWith(".") ? path.resolve(dir, importPath) : (await this.resolve(importPath, id, { skipSelf: true }))?.id;
|
|
3691
3779
|
if (!resolvedImage) continue;
|
|
@@ -3735,7 +3823,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3735
3823
|
createGoogleFontsPlugin(_fontGoogleShimPath, _shimsDir),
|
|
3736
3824
|
createLocalFontsPlugin(_shimsDir),
|
|
3737
3825
|
createOptimizeImportsPlugin(() => nextConfig, () => root),
|
|
3738
|
-
createDynamicPreloadMetadataPlugin(),
|
|
3826
|
+
createDynamicPreloadMetadataPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
3739
3827
|
importMetaUrlCapability.vitePlugin,
|
|
3740
3828
|
createExtensionlessDynamicImportPlugin(),
|
|
3741
3829
|
createRequireContextPlugin(),
|
|
@@ -3807,24 +3895,13 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3807
3895
|
}
|
|
3808
3896
|
},
|
|
3809
3897
|
{
|
|
3810
|
-
name: "vinext:nitro-
|
|
3811
|
-
nitro: { setup:
|
|
3898
|
+
name: "vinext:nitro-setup",
|
|
3899
|
+
nitro: { setup: (nitro) => {
|
|
3812
3900
|
nitroBuildDir = nitro.options.buildDir ? path.resolve(root, nitro.options.buildDir) : void 0;
|
|
3813
3901
|
nitroHostRuntime = nitro.options.exportConditions?.includes("workerd") ? "worker" : "node";
|
|
3814
3902
|
if (!nextConfig) return;
|
|
3815
3903
|
if (!hasAppDir && !hasPagesDir) return;
|
|
3816
3904
|
if (resolvedServerExternalPackages.length > 0) nitro.options.traceDeps = [.../* @__PURE__ */ new Set([...nitro.options.traceDeps ?? [], ...resolvedServerExternalPackages])];
|
|
3817
|
-
if (nitro.options.dev) return;
|
|
3818
|
-
const { collectNitroRouteRules, mergeNitroRouteRules } = await import("./build/nitro-route-rules.js");
|
|
3819
|
-
const generatedRouteRules = await collectNitroRouteRules({
|
|
3820
|
-
appDir: hasAppDir ? appDir : null,
|
|
3821
|
-
pagesDir: hasPagesDir ? pagesDir : null,
|
|
3822
|
-
pageExtensions: nextConfig.pageExtensions
|
|
3823
|
-
});
|
|
3824
|
-
if (Object.keys(generatedRouteRules).length === 0) return;
|
|
3825
|
-
const { routeRules, skippedRoutes } = mergeNitroRouteRules(nitro.options.routeRules, generatedRouteRules);
|
|
3826
|
-
nitro.options.routeRules = routeRules;
|
|
3827
|
-
if (skippedRoutes.length > 0) (nitro.logger?.warn ?? console.warn)(`[vinext] Skipping generated Nitro routeRules for routes with existing exact cache config: ${skippedRoutes.join(", ")}`);
|
|
3828
3905
|
} }
|
|
3829
3906
|
},
|
|
3830
3907
|
{
|
|
@@ -3941,6 +4018,10 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3941
4018
|
apply: "build",
|
|
3942
4019
|
enforce: "post",
|
|
3943
4020
|
sharedDuringBuild: true,
|
|
4021
|
+
writeBundle(_options, bundle) {
|
|
4022
|
+
if (this.environment.name !== "client") return;
|
|
4023
|
+
clientBuildFiles = collectClientBuildFiles(Object.keys(bundle));
|
|
4024
|
+
},
|
|
3944
4025
|
closeBundle: {
|
|
3945
4026
|
sequential: true,
|
|
3946
4027
|
order: "post",
|
|
@@ -3967,7 +4048,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3967
4048
|
cssGraph: runtimeMetadata.cssGraph,
|
|
3968
4049
|
lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
|
|
3969
4050
|
dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0,
|
|
3970
|
-
crossOrigin: nextConfig.crossOrigin ?? ""
|
|
4051
|
+
crossOrigin: nextConfig.crossOrigin ?? "",
|
|
4052
|
+
clientBuildFiles: clientBuildFiles.length > 0 ? clientBuildFiles : void 0
|
|
3971
4053
|
});
|
|
3972
4054
|
}
|
|
3973
4055
|
if (pagesClientAssetsModule === null && pagesClientAssetsOutputDirs.size === 0) return;
|
|
@@ -4004,13 +4086,37 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4004
4086
|
const envConfig = this.environment?.config;
|
|
4005
4087
|
if (!envConfig) return;
|
|
4006
4088
|
const buildRoot = envConfig.root ?? process.cwd();
|
|
4007
|
-
const clientDir = path.resolve(buildRoot,
|
|
4089
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
4008
4090
|
const manifest = collectInlineCssManifest(clientDir, nextConfig.assetPrefix);
|
|
4009
4091
|
const rscOutDir = path.resolve(buildRoot, options.rscOutDir ?? path.join("dist", "server"));
|
|
4010
4092
|
for (const entryFile of ["index.js", "index.mjs"]) if (injectInlineCssManifestGlobal(path.join(rscOutDir, entryFile), manifest)) break;
|
|
4011
4093
|
}
|
|
4012
4094
|
}
|
|
4013
4095
|
},
|
|
4096
|
+
(
|
|
4097
|
+
// @vitejs/plugin-rsc's preview handler, and Cloudflare and Nitro builds
|
|
4098
|
+
{
|
|
4099
|
+
name: "vinext:preview-server",
|
|
4100
|
+
async configurePreviewServer(server) {
|
|
4101
|
+
if (hasAppDir || hasCloudflarePlugin || hasNitroPlugin) return;
|
|
4102
|
+
if (nextConfig?.output === "export") return;
|
|
4103
|
+
const { createPagesPreviewHandler } = await import("./server/prod-server.js");
|
|
4104
|
+
const { environments, preview, root } = server.config;
|
|
4105
|
+
const handler = await createPagesPreviewHandler({
|
|
4106
|
+
clientDir: path.resolve(root, environments.client?.build.outDir ?? "dist/client"),
|
|
4107
|
+
serverDir: path.resolve(root, environments.ssr?.build.outDir ?? "dist/server"),
|
|
4108
|
+
host: typeof preview.host === "string" ? preview.host : "localhost",
|
|
4109
|
+
port: preview.port ?? 4173
|
|
4110
|
+
});
|
|
4111
|
+
if (!handler) return;
|
|
4112
|
+
return () => {
|
|
4113
|
+
server.middlewares.use((req, res) => {
|
|
4114
|
+
if (nextConfig?.basePath) req.url = nextConfig.basePath + (req.url ?? "/");
|
|
4115
|
+
handler(req, res);
|
|
4116
|
+
});
|
|
4117
|
+
};
|
|
4118
|
+
}
|
|
4119
|
+
}),
|
|
4014
4120
|
{
|
|
4015
4121
|
name: "vinext:cloudflare-build",
|
|
4016
4122
|
apply: "build",
|
|
@@ -4127,6 +4233,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4127
4233
|
}
|
|
4128
4234
|
});
|
|
4129
4235
|
if (rscPluginPromise) plugins.push(rscPluginPromise);
|
|
4236
|
+
if (rscVersion && isRscScanGlobImportsAffected(rscVersion)) plugins.push(createRscScanGlobImportsPlugin({ async getManager(config) {
|
|
4237
|
+
return (await rscPluginModulePromise)?.getPluginApi(config)?.manager;
|
|
4238
|
+
} }));
|
|
4130
4239
|
if (earlyAppDirExists) {
|
|
4131
4240
|
plugins.push(createActionOwnerManifestPlugin({
|
|
4132
4241
|
canonicalizeModuleId: canonicalize,
|
|
@@ -4145,7 +4254,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4145
4254
|
if (rscPluginPromise) {
|
|
4146
4255
|
plugins.push(createRscReferenceValidationNormalizerPlugin());
|
|
4147
4256
|
plugins.push(createRscClientReferenceLoadersPlugin());
|
|
4148
|
-
} else if (manualUseCachePluginPromise) plugins.push(
|
|
4257
|
+
} else if (manualUseCachePluginPromise) plugins.push(manualUseCachePluginPromise);
|
|
4149
4258
|
plugins.push({
|
|
4150
4259
|
name: "vinext:plain-pages-build-config",
|
|
4151
4260
|
apply: "build",
|
|
@@ -4166,6 +4275,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4166
4275
|
}
|
|
4167
4276
|
}
|
|
4168
4277
|
});
|
|
4278
|
+
plugins.push(createCloudflareDevModuleUrlsPlugin({ isEnabled: () => hasCloudflarePlugin }));
|
|
4169
4279
|
plugins.push(buildLifecyclePlugins[1]);
|
|
4170
4280
|
return plugins;
|
|
4171
4281
|
}
|