vinext 1.0.0 → 1.1.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 +72 -1
- package/THIRD_PARTY_LICENSES.md +26 -0
- package/dist/build/app-page-static-eligibility.d.ts +15 -0
- package/dist/build/app-page-static-eligibility.js +82 -0
- package/dist/build/lifecycle.js +10 -10
- package/dist/build/pages-client-assets-module.js +6 -1
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender-paths.js +6 -85
- package/dist/build/prerender.d.ts +8 -1
- package/dist/build/prerender.js +167 -46
- package/dist/build/run-prerender.js +4 -3
- package/dist/build/server-entry.d.ts +2 -0
- package/dist/build/server-entry.js +7 -1
- package/dist/build/server-manifest.d.ts +7 -0
- package/dist/build/server-manifest.js +11 -1
- package/dist/cache/cache-adapters-virtual.d.ts +7 -1
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/client/browser-globals.d.ts +4 -0
- package/dist/client/browser-globals.js +5 -0
- package/dist/client/navigation-runtime.d.ts +11 -1
- package/dist/client/navigation-runtime.js +3 -3
- package/dist/config/config-matchers.js +3 -1
- package/dist/config/dotenv.js +14 -3
- package/dist/config/next-config.d.ts +7 -0
- package/dist/config/next-config.js +18 -3
- package/dist/entries/app-rsc-entry.d.ts +2 -0
- package/dist/entries/app-rsc-entry.js +67 -45
- package/dist/index.d.ts +4 -1
- package/dist/index.js +200 -100
- package/dist/init-cloudflare.d.ts +1 -1
- package/dist/init-cloudflare.js +6 -6
- package/dist/init-platform.js +1 -1
- package/dist/init.js +4 -2
- package/dist/plugins/cache-flight-codec.d.ts +19 -0
- package/dist/plugins/cache-flight-codec.js +68 -0
- package/dist/plugins/commonjs-esm-facade.d.ts +35 -0
- package/dist/plugins/commonjs-esm-facade.js +80 -0
- package/dist/plugins/commonjs-syntax.d.ts +16 -0
- package/dist/plugins/commonjs-syntax.js +22 -0
- package/dist/plugins/fonts.d.ts +8 -11
- package/dist/plugins/fonts.js +71 -34
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +54 -3
- package/dist/plugins/import-meta-url.js +6 -6
- package/dist/plugins/og-asset-ownership.d.ts +2 -0
- package/dist/plugins/og-asset-ownership.js +24 -13
- package/dist/plugins/og-assets.d.ts +18 -0
- package/dist/plugins/og-assets.js +50 -8
- package/dist/plugins/og-harfbuzz.js +38 -27
- package/dist/plugins/optimize-imports.js +2 -1
- package/dist/plugins/require-context.d.ts +1 -0
- package/dist/plugins/require-context.js +28 -1
- package/dist/plugins/scan-build-css.d.ts +12 -0
- package/dist/plugins/scan-build-css.js +39 -0
- package/dist/plugins/strip-server-exports.d.ts +2 -0
- package/dist/plugins/strip-server-exports.js +3 -1
- package/dist/plugins/transform-result.d.ts +18 -0
- package/dist/plugins/transform-result.js +23 -2
- package/dist/plugins/typeof-window.d.ts +10 -0
- package/dist/plugins/typeof-window.js +33 -9
- package/dist/routing/app-route-graph.d.ts +0 -1
- package/dist/routing/app-route-graph.js +2 -4
- package/dist/routing/app-route-ids.d.ts +3 -0
- package/dist/routing/app-route-ids.js +6 -0
- package/dist/routing/file-matcher.d.ts +1 -0
- package/dist/routing/file-matcher.js +1 -1
- package/dist/server/api-handler.js +17 -7
- package/dist/server/app-bfcache-id.d.ts +1 -0
- package/dist/server/app-bfcache-id.js +7 -1
- package/dist/server/app-bfcache-identity.js +1 -2
- package/dist/server/app-browser-entry.js +15 -9
- package/dist/server/app-browser-history-controller.d.ts +2 -0
- package/dist/server/app-browser-history-controller.js +8 -0
- package/dist/server/app-browser-hydration.d.ts +1 -1
- package/dist/server/app-browser-hydration.js +2 -2
- package/dist/server/app-browser-interception-context.js +26 -2
- package/dist/server/app-browser-navigation-controller.d.ts +7 -1
- package/dist/server/app-browser-navigation-controller.js +94 -11
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-stream.d.ts +1 -1
- package/dist/server/app-fallback-renderer.d.ts +2 -0
- package/dist/server/app-fallback-renderer.js +1 -0
- package/dist/server/app-history-state.d.ts +3 -1
- package/dist/server/app-history-state.js +9 -5
- package/dist/server/app-middleware.js +2 -1
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +5 -0
- package/dist/server/app-page-boundary-render.js +6 -4
- package/dist/server/app-page-cache-finalizer.d.ts +11 -0
- package/dist/server/app-page-cache-finalizer.js +41 -7
- package/dist/server/app-page-cache-render.d.ts +18 -0
- package/dist/server/app-page-cache-render.js +65 -44
- package/dist/server/app-page-cache.d.ts +5 -0
- package/dist/server/app-page-cache.js +27 -7
- package/dist/server/app-page-dispatch.d.ts +9 -1
- package/dist/server/app-page-dispatch.js +47 -30
- package/dist/server/app-page-element-builder.d.ts +7 -0
- package/dist/server/app-page-element-builder.js +27 -42
- package/dist/server/app-page-execution.d.ts +15 -12
- package/dist/server/app-page-execution.js +30 -40
- package/dist/server/app-page-head.d.ts +5 -0
- package/dist/server/app-page-head.js +9 -3
- package/dist/server/app-page-probe.d.ts +0 -109
- package/dist/server/app-page-probe.js +3 -136
- package/dist/server/app-page-render-identity.d.ts +0 -1
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render-observation.js +2 -2
- package/dist/server/app-page-render.d.ts +13 -5
- package/dist/server/app-page-render.js +219 -118
- package/dist/server/app-page-request.d.ts +0 -1
- package/dist/server/app-page-request.js +1 -2
- package/dist/server/app-page-response.d.ts +4 -3
- package/dist/server/app-page-response.js +4 -3
- package/dist/server/app-page-route-wiring.d.ts +17 -5
- package/dist/server/app-page-route-wiring.js +55 -33
- package/dist/server/app-page-rsc-render-status.d.ts +48 -0
- package/dist/server/app-page-rsc-render-status.js +54 -0
- package/dist/server/app-page-search-params-observation.js +1 -1
- package/dist/server/app-page-stream.d.ts +15 -8
- package/dist/server/app-page-stream.js +7 -1
- package/dist/server/app-page-tracing.js +2 -1
- package/dist/server/app-pages-bridge.js +3 -2
- package/dist/server/app-render-abort-error.d.ts +3 -0
- package/dist/server/app-render-abort-error.js +8 -0
- package/dist/server/app-request-stage-dispatch.js +1 -1
- package/dist/server/app-request-stage-independent-entry.js +8 -11
- package/dist/server/app-response-header-provenance.d.ts +2 -0
- package/dist/server/app-response-header-provenance.js +10 -4
- package/dist/server/app-route-handler-cache.d.ts +2 -1
- package/dist/server/app-route-handler-cache.js +11 -7
- package/dist/server/app-route-handler-dispatch.js +11 -4
- package/dist/server/app-route-handler-execution.d.ts +9 -1
- package/dist/server/app-route-handler-execution.js +28 -13
- package/dist/server/app-route-handler-policy.js +2 -2
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-handler-response.js +14 -5
- package/dist/server/app-router-entry.d.ts +2 -1
- package/dist/server/app-router-entry.js +8 -12
- package/dist/server/app-rsc-errors.d.ts +0 -1
- package/dist/server/app-rsc-errors.js +2 -6
- package/dist/server/app-rsc-handler.d.ts +5 -0
- package/dist/server/app-rsc-handler.js +229 -102
- package/dist/server/app-rsc-request-normalization.d.ts +4 -2
- package/dist/server/app-rsc-request-normalization.js +7 -4
- package/dist/server/app-rsc-response-finalizer.js +4 -1
- package/dist/server/app-rsc-response-stage.d.ts +1 -1
- package/dist/server/app-rsc-response-stage.js +6 -4
- package/dist/server/app-rsc-route-matching.d.ts +9 -1
- package/dist/server/app-rsc-route-matching.js +37 -20
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +1 -1
- package/dist/server/app-ssr-entry.d.ts +3 -2
- package/dist/server/app-ssr-entry.js +9 -7
- package/dist/server/app-ssr-search-params-gate.js +1 -1
- package/dist/server/app-ssr-stream.d.ts +6 -1
- package/dist/server/app-ssr-stream.js +35 -16
- package/dist/server/app-worker-stages.d.ts +2 -2
- package/dist/server/app-worker-stages.js +3 -3
- package/dist/server/cache-control.js +3 -11
- package/dist/server/cacheability-request.js +56 -52
- package/dist/server/config-headers.js +3 -1
- package/dist/server/dev-server.js +23 -5
- package/dist/server/headers.d.ts +16 -0
- package/dist/server/headers.js +19 -1
- package/dist/server/http-error-responses.js +1 -0
- package/dist/server/image-optimization.d.ts +16 -0
- package/dist/server/image-optimization.js +26 -6
- package/dist/server/isr-cache.d.ts +2 -0
- package/dist/server/isr-cache.js +8 -3
- package/dist/server/metadata-route-response.js +94 -37
- package/dist/server/middleware-matcher-pattern.js +8 -4
- package/dist/server/middleware-response-headers.js +2 -0
- package/dist/server/multi-stage.d.ts +8 -0
- package/dist/server/navigation-planner.js +1 -1
- package/dist/server/node-response-signal.d.ts +16 -0
- package/dist/server/node-response-signal.js +26 -0
- package/dist/server/open-redirect.d.ts +47 -0
- package/dist/server/open-redirect.js +74 -1
- package/dist/server/pages-api-route.js +8 -2
- package/dist/server/pages-asset-tags.d.ts +1 -0
- package/dist/server/pages-asset-tags.js +73 -22
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-page-data.d.ts +6 -1
- package/dist/server/pages-page-data.js +71 -65
- package/dist/server/pages-page-handler.js +50 -15
- package/dist/server/pages-page-response.js +3 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -1
- package/dist/server/pages-request-pipeline.js +20 -5
- package/dist/server/pages-request-stage-entry.js +14 -8
- package/dist/server/prerender-manifest.d.ts +6 -0
- package/dist/server/prerender-manifest.js +1 -1
- package/dist/server/prod-server.d.ts +8 -7
- package/dist/server/prod-server.js +152 -78
- package/dist/server/request-pipeline.d.ts +20 -8
- package/dist/server/request-pipeline.js +21 -7
- package/dist/server/response-compression.d.ts +43 -0
- package/dist/server/response-compression.js +111 -0
- package/dist/server/response-stage-cacheability.js +1 -1
- package/dist/server/seed-cache.js +10 -7
- package/dist/server/socket-error-backstop.d.ts +14 -0
- package/dist/server/socket-error-backstop.js +27 -4
- package/dist/server/worker-revalidation-context.d.ts +2 -1
- package/dist/server/worker-revalidation-context.js +1 -0
- package/dist/server/workers-tracing.d.ts +17 -0
- package/dist/server/workers-tracing.js +48 -8
- package/dist/shims/cache-adapter-instantiate.d.ts +50 -0
- package/dist/shims/cache-adapter-instantiate.js +118 -0
- package/dist/shims/cache-callable-runtime.d.ts +2 -40
- package/dist/shims/cache-callable-runtime.js +50 -168
- package/dist/shims/cache-flight-arguments.d.ts +22 -0
- package/dist/shims/cache-flight-arguments.js +56 -0
- package/dist/shims/cache-request-state.d.ts +18 -14
- package/dist/shims/cache-request-state.js +33 -21
- package/dist/shims/cache-runtime.d.ts +6 -19
- package/dist/shims/cache-runtime.js +168 -226
- package/dist/shims/cache.d.ts +3 -2
- package/dist/shims/cache.js +8 -5
- package/dist/shims/cacheability-classification.d.ts +8 -1
- package/dist/shims/cacheability-classification.js +2 -2
- package/dist/shims/cdn-cache.d.ts +10 -1
- package/dist/shims/cdn-cache.js +16 -9
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +19 -1
- package/dist/shims/error-boundary.d.ts +10 -10
- package/dist/shims/error-boundary.js +26 -7
- package/dist/shims/error.d.ts +4 -18
- package/dist/shims/error.js +17 -10
- package/dist/shims/error.react-server.d.ts +4 -6
- package/dist/shims/error.react-server.js +4 -1
- package/dist/shims/fetch-cache.d.ts +6 -0
- package/dist/shims/fetch-cache.js +23 -4
- package/dist/shims/form.js +1 -1
- package/dist/shims/headers.d.ts +19 -69
- package/dist/shims/headers.js +82 -183
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -2
- package/dist/shims/internal/app-page-props-cache-key.js +24 -15
- package/dist/shims/internal/cache-context-accessor.d.ts +16 -0
- package/dist/shims/internal/cache-context-accessor.js +15 -0
- package/dist/shims/internal/headers-state.d.ts +73 -0
- package/dist/shims/internal/headers-state.js +157 -0
- package/dist/shims/metadata.js +3 -3
- package/dist/shims/navigation-errors.d.ts +6 -0
- package/dist/shims/navigation-errors.js +11 -1
- package/dist/shims/navigation.d.ts +7 -0
- package/dist/shims/navigation.js +16 -6
- package/dist/shims/request-context.d.ts +9 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/root-params.js +1 -1
- package/dist/shims/server.js +52 -2
- package/dist/shims/thenable-params.d.ts +4 -0
- package/dist/shims/thenable-params.js +25 -3
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/utils/encode-cache-tag.d.ts +1 -0
- package/dist/utils/encode-cache-tag.js +11 -1
- package/dist/utils/mdx-scan.d.ts +5 -0
- package/dist/utils/mdx-scan.js +8 -1
- package/dist/utils/regex-safety.d.ts +10 -0
- package/dist/utils/regex-safety.js +70 -18
- package/dist/utils/vite-cli-invocation.js +8 -1
- package/package.json +8 -4
- package/dist/server/metadata-route-cache-policy.d.ts +0 -5
- package/dist/server/metadata-route-cache-policy.js +0 -6
package/dist/index.js
CHANGED
|
@@ -11,9 +11,10 @@ import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/consta
|
|
|
11
11
|
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
12
12
|
import { encodeMiddlewareRequestHeaders } from "./utils/middleware-request-headers.js";
|
|
13
13
|
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
14
|
-
import {
|
|
14
|
+
import { omitUnusedBuildSourcemap } from "./plugins/transform-result.js";
|
|
15
|
+
import { assetPrefixPathname, isNextStaticPath, resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
15
16
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
16
|
-
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
17
|
+
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, lightningCssFeatureNamesToMask, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
17
18
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
18
19
|
import { hasBasePath, stripBasePath } from "./utils/base-path.js";
|
|
19
20
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
@@ -23,8 +24,8 @@ import { resolveRuntimeEntryModule } from "./entries/runtime-entry-module.js";
|
|
|
23
24
|
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
24
25
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
25
26
|
import { validateMiddlewareMatcherPatterns } from "./server/middleware-matcher-pattern.js";
|
|
26
|
-
import { methodNotAllowedResponse } from "./server/http-error-responses.js";
|
|
27
|
-
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
27
|
+
import { methodNotAllowedResponse, notFoundStaticAssetResponse } from "./server/http-error-responses.js";
|
|
28
|
+
import { isOpenRedirectShaped, sendRepeatedSlashRedirect } from "./server/open-redirect.js";
|
|
28
29
|
import { canonicalizeRequestUrlPathname, filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
29
30
|
import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
|
|
30
31
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
@@ -32,16 +33,17 @@ import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middlew
|
|
|
32
33
|
import { extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, hasExportedName } from "./build/report.js";
|
|
33
34
|
import { generatePagesRequestEntry, generatePagesResponseEntry, generateServerEntry } from "./entries/pages-server-entry.js";
|
|
34
35
|
import { compileClientMiddlewareMatchers, generateClientEntry } from "./entries/pages-client-entry.js";
|
|
36
|
+
import { isPathInside, isPathInsideOrEqual, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
35
37
|
import { logRequest, now } from "./server/request-log.js";
|
|
36
38
|
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
37
39
|
import { getPagesPreviewModeId } from "./server/pages-preview.js";
|
|
38
40
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
41
|
+
import { signalFromNodeResponse } from "./server/node-response-signal.js";
|
|
39
42
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
40
43
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
41
44
|
import { CACHEABILITY_MANIFEST_MODULE, CACHEABILITY_REQUEST_PROJECTION_MODULE } from "./server/cacheability-manifest.js";
|
|
42
45
|
import { PREGENERATED_CONCRETE_PATHS_MODULE } from "./server/pregenerated-concrete-paths.js";
|
|
43
46
|
import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
|
|
44
|
-
import { isPathInside, isPathInsideOrEqual, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
45
47
|
import { invalidateMetadataFileCache, scanMetadataFiles } from "./server/metadata-routes.js";
|
|
46
48
|
import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
|
|
47
49
|
import { createDirectRunner } from "./server/dev-module-runner.js";
|
|
@@ -78,6 +80,7 @@ import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
|
|
|
78
80
|
import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
|
|
79
81
|
import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
|
|
80
82
|
import { createRscReferenceValidationNormalizerPlugin } from "./plugins/rsc-reference-validation-normalizer.js";
|
|
83
|
+
import { createScanBuildCssPlugin } from "./plugins/scan-build-css.js";
|
|
81
84
|
import { createInstrumentationClientTransformPlugin, createInstrumentationServerTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
82
85
|
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
83
86
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
@@ -88,9 +91,11 @@ import { validateMiddlewareModuleExports } from "./plugins/middleware-export-val
|
|
|
88
91
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
89
92
|
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
90
93
|
import { createDynamicPreloadMetadataPlugin } from "./plugins/dynamic-preload-metadata.js";
|
|
94
|
+
import { createTransformCache } from "./plugins/transform-cache.js";
|
|
91
95
|
import { createOgHarfbuzzPlugin } from "./plugins/og-harfbuzz.js";
|
|
92
96
|
import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins/og-assets.js";
|
|
93
97
|
import { createUseCacheCallablePlugin } from "./plugins/use-cache-callable.js";
|
|
98
|
+
import { cacheFlightCodecPlugin } from "./plugins/cache-flight-codec.js";
|
|
94
99
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
95
100
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
96
101
|
import { createTransitiveExternalsPlugin } from "./plugins/transitive-externals.js";
|
|
@@ -102,17 +107,18 @@ import { createModuleDependencyCache } from "./build/module-dependency-cache.js"
|
|
|
102
107
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
103
108
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter, createSassTsconfigPathImporters } from "./plugins/sass.js";
|
|
104
109
|
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createMultiStageChunkFileNames, createMultiStageCodeSplittingConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
105
|
-
import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
110
|
+
import { EXPORT_ALL_CANDIDATE_FILTER, hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
106
111
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
107
112
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
108
113
|
import { createWorkerImageImportsPlugin } from "./plugins/worker-image-imports.js";
|
|
109
114
|
import { createRequireContextPlugin } from "./plugins/require-context.js";
|
|
115
|
+
import { commonJsEsmFacadeOptimizeDepsPlugin, stripEsmCommonJsExportFacade } from "./plugins/commonjs-esm-facade.js";
|
|
116
|
+
import { COMMONJS_SYNTAX_CODE_FILTER } from "./plugins/commonjs-syntax.js";
|
|
110
117
|
import { createRequireConditionResolutionPlugin, isConditionalRequireScriptModuleId } from "./plugins/require-condition-resolution.js";
|
|
111
|
-
import { createTransformCache } from "./plugins/transform-cache.js";
|
|
112
118
|
import { createExtensionlessDynamicImportPlugin } from "./plugins/extensionless-dynamic-import.js";
|
|
113
119
|
import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
114
|
-
import { consumerEnvironmentConditionFilter, getTypeofWindowReplacement, replaceConsumerEnvironmentConditions } from "./plugins/typeof-window.js";
|
|
115
|
-
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
120
|
+
import { consumerEnvironmentConditionFilter, getTypeofWindowReplacement, mayFoldChangeScannedImports, replaceConsumerEnvironmentConditions } from "./plugins/typeof-window.js";
|
|
121
|
+
import { hasMdxFiles, loadMdxEsmReader, pageExtensionsIncludeMdx } from "./utils/mdx-scan.js";
|
|
116
122
|
import { publicFilePathVariants } from "./utils/public-file-path.js";
|
|
117
123
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
118
124
|
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
@@ -133,17 +139,23 @@ const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
|
133
139
|
"react-dom",
|
|
134
140
|
"react-dom/server.edge",
|
|
135
141
|
"react/jsx-runtime",
|
|
136
|
-
"react/jsx-dev-runtime"
|
|
137
|
-
|
|
142
|
+
"react/jsx-dev-runtime"
|
|
143
|
+
]);
|
|
144
|
+
const APP_CLIENT_OPTIONAL_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
145
|
+
"use-sync-external-store/shim",
|
|
146
|
+
"use-sync-external-store/shim/index.js",
|
|
147
|
+
"use-sync-external-store/shim/with-selector",
|
|
148
|
+
"use-sync-external-store/shim/with-selector.js",
|
|
149
|
+
"use-sync-external-store/with-selector",
|
|
150
|
+
"use-sync-external-store/with-selector.js"
|
|
138
151
|
]);
|
|
139
|
-
const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-sync-external-store\/with-selector.*present in .* 'optimizeDeps\.include'/;
|
|
140
|
-
const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
|
|
141
152
|
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
142
153
|
const RSC_ENVIRONMENTS = /* @__PURE__ */ new Set([
|
|
143
154
|
"rsc",
|
|
144
155
|
"ssr",
|
|
145
156
|
"client"
|
|
146
157
|
]);
|
|
158
|
+
const VINEXT_GENERATED_DIR_RE = /(?:^|[/\\])\.vinext(?:[/\\]|$)/;
|
|
147
159
|
function scopeRscPlugin(plugin) {
|
|
148
160
|
const applyToEnvironment = plugin.applyToEnvironment;
|
|
149
161
|
return {
|
|
@@ -544,15 +556,24 @@ function mergeStringArrayValues(value, additions) {
|
|
|
544
556
|
function stripAnsi(value) {
|
|
545
557
|
return value.replace(ANSI_ESCAPE_RE, "");
|
|
546
558
|
}
|
|
547
|
-
function
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
559
|
+
function createOptionalOptimizeDepsLogger(logger, warnings) {
|
|
560
|
+
if (warnings.size === 0) return logger;
|
|
561
|
+
return {
|
|
562
|
+
get hasWarned() {
|
|
563
|
+
return logger.hasWarned;
|
|
564
|
+
},
|
|
565
|
+
set hasWarned(value) {
|
|
566
|
+
logger.hasWarned = value;
|
|
567
|
+
},
|
|
568
|
+
info: logger.info.bind(logger),
|
|
569
|
+
warn(msg, options) {
|
|
570
|
+
if (!warnings.has(stripAnsi(msg))) logger.warn(msg, options);
|
|
571
|
+
},
|
|
572
|
+
warnOnce: logger.warnOnce.bind(logger),
|
|
573
|
+
error: logger.error.bind(logger),
|
|
574
|
+
clearScreen: logger.clearScreen.bind(logger),
|
|
575
|
+
hasErrorLogged: logger.hasErrorLogged.bind(logger)
|
|
554
576
|
};
|
|
555
|
-
marker[VINEXT_FILTERED_OPTIMIZE_DEPS_WARN] = true;
|
|
556
577
|
}
|
|
557
578
|
const _tsconfigAliasCache = /* @__PURE__ */ new Map();
|
|
558
579
|
/**
|
|
@@ -847,6 +868,7 @@ function vinext(options = {}) {
|
|
|
847
868
|
let nitroBuildDir;
|
|
848
869
|
let fileMatcher;
|
|
849
870
|
let middlewarePath = null;
|
|
871
|
+
let canonicalMiddlewarePath = null;
|
|
850
872
|
let instrumentationPath = null;
|
|
851
873
|
let instrumentationClientPath = null;
|
|
852
874
|
let clientInjectModule = null;
|
|
@@ -996,7 +1018,7 @@ function vinext(options = {}) {
|
|
|
996
1018
|
});
|
|
997
1019
|
const useServerIndex = plugins.findIndex((plugin) => plugin.name === "rsc:use-server");
|
|
998
1020
|
if (useServerIndex === -1) throw new Error("vinext: Failed to locate @vitejs/plugin-rsc use-server plugin.");
|
|
999
|
-
plugins.splice(useServerIndex, 0, useCachePlugin);
|
|
1021
|
+
plugins.splice(useServerIndex, 0, cacheFlightCodecPlugin(), useCachePlugin);
|
|
1000
1022
|
return plugins.map(scopeRscPlugin);
|
|
1001
1023
|
}).catch((cause) => {
|
|
1002
1024
|
throw new Error("vinext: Failed to load @vitejs/plugin-rsc.", { cause });
|
|
@@ -1115,33 +1137,53 @@ function vinext(options = {}) {
|
|
|
1115
1137
|
}
|
|
1116
1138
|
};
|
|
1117
1139
|
const cachedConsumerConditionTransform = createTransformCache();
|
|
1140
|
+
const cachedJsxInJsTransform = createTransformCache();
|
|
1118
1141
|
let transformProjectLocalCommonJs = false;
|
|
1119
1142
|
let transformBundledCommonJsDependencies = false;
|
|
1120
1143
|
const commonJsPlugin = commonjs({ filter(id) {
|
|
1144
|
+
if (isPathInside(__dirname, toSlash(stripViteModuleQuery(id)))) return false;
|
|
1121
1145
|
return commonjsTransformFilter(id, transformProjectLocalCommonJs, transformBundledCommonJsDependencies, importMetaUrlCapability.isBundledCommonJsDependencyId);
|
|
1122
1146
|
} });
|
|
1123
1147
|
const commonJsTransform = commonJsPlugin.transform;
|
|
1124
|
-
if (typeof commonJsTransform === "function")
|
|
1125
|
-
const
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1148
|
+
if (typeof commonJsTransform === "function") {
|
|
1149
|
+
const environmentAwareCommonJsTransform = function(code, id, ...args) {
|
|
1150
|
+
const normalizedId = toSlash(stripViteModuleQuery(id));
|
|
1151
|
+
const nitroServicePath = this.environment.name === "nitro" && nitroBuildDir && normalizedId.endsWith("/entry.js") ? path.relative(path.join(canonicalize(nitroBuildDir), "vite/services"), normalizedId) : "";
|
|
1152
|
+
if (/^[^/]+\/entry\.js$/.test(nitroServicePath)) return null;
|
|
1153
|
+
if (isPathInside(__dirname, toSlash(stripViteModuleQuery(id)))) return null;
|
|
1154
|
+
if (this.environment.mode === "dev" && this.environment.depsOptimizer?.isOptimizedDepFile(id)) return null;
|
|
1155
|
+
const isDev = this.environment.mode === "dev";
|
|
1156
|
+
const isServer = this.environment.config.consumer === "server";
|
|
1157
|
+
const bundledDependency = isDev && isServer && (code.includes("__filename") || code.includes("__dirname")) && importMetaUrlCapability.isBundledCommonJsDependencyId(id);
|
|
1158
|
+
const projectLocal = !bundledDependency && !id.includes("/node_modules/") && !id.includes("\\node_modules\\");
|
|
1159
|
+
const userCondition = commonjsTransformFilter(id, projectLocal && isDev, bundledDependency, importMetaUrlCapability.isBundledCommonJsDependencyId);
|
|
1160
|
+
if (userCondition === false) return null;
|
|
1161
|
+
if (userCondition !== true && id.includes("node_modules")) return null;
|
|
1162
|
+
const previousProjectLocal = transformProjectLocalCommonJs;
|
|
1163
|
+
const previous = transformBundledCommonJsDependencies;
|
|
1164
|
+
transformProjectLocalCommonJs = projectLocal && isDev;
|
|
1165
|
+
transformBundledCommonJsDependencies = bundledDependency;
|
|
1166
|
+
let result;
|
|
1167
|
+
try {
|
|
1168
|
+
result = commonJsTransform.call(this, code, id, ...args);
|
|
1169
|
+
} finally {
|
|
1170
|
+
transformProjectLocalCommonJs = previousProjectLocal;
|
|
1171
|
+
transformBundledCommonJsDependencies = previous;
|
|
1172
|
+
}
|
|
1173
|
+
return Promise.resolve(result).then((transformed) => {
|
|
1174
|
+
if (typeof transformed !== "object" || typeof transformed?.code !== "string") return transformed;
|
|
1175
|
+
const stripped = stripEsmCommonJsExportFacade(transformed.code);
|
|
1176
|
+
return stripped === void 0 ? transformed : {
|
|
1177
|
+
...transformed,
|
|
1178
|
+
code: stripped
|
|
1179
|
+
};
|
|
1180
|
+
});
|
|
1181
|
+
};
|
|
1182
|
+
commonJsPlugin.transform = {
|
|
1183
|
+
filter: { code: { include: COMMONJS_SYNTAX_CODE_FILTER } },
|
|
1184
|
+
handler: environmentAwareCommonJsTransform
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1145
1187
|
const buildLifecyclePlugins = createBuildLifecyclePlugins({
|
|
1146
1188
|
isEnabled: (builder) => buildLifecycleEnabled && builder.config.build.write !== false && !builder.config.build.lib && (buildLifecycleInvocation !== void 0 || !builder.config.build.watch && !builder.config.build.ssr && getBuildBundlerOptions(builder.config.build)?.input === void 0),
|
|
1147
1189
|
onComplete: () => buildLifecycleInvocation?.onComplete?.(),
|
|
@@ -1229,15 +1271,17 @@ function vinext(options = {}) {
|
|
|
1229
1271
|
if (!code.includes("use client") && !code.includes("use server")) return;
|
|
1230
1272
|
if (!hasReactDirective(code)) return;
|
|
1231
1273
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1274
|
+
return cachedJsxInJsTransform(id, code, void 0, async () => {
|
|
1275
|
+
const result = await transformWithOxc(code, id, {
|
|
1276
|
+
lang: "jsx",
|
|
1277
|
+
jsx: { runtime: "automatic" },
|
|
1278
|
+
sourcemap: true
|
|
1279
|
+
});
|
|
1280
|
+
return {
|
|
1281
|
+
code: result.code,
|
|
1282
|
+
map: result.map
|
|
1283
|
+
};
|
|
1236
1284
|
});
|
|
1237
|
-
return {
|
|
1238
|
-
code: result.code,
|
|
1239
|
-
map: result.map
|
|
1240
|
-
};
|
|
1241
1285
|
}
|
|
1242
1286
|
}
|
|
1243
1287
|
},
|
|
@@ -1366,6 +1410,8 @@ function vinext(options = {}) {
|
|
|
1366
1410
|
instrumentationClientPath = findInstrumentationClientFile(root, fileMatcher);
|
|
1367
1411
|
const middlewareConventionDir = canonicalize(baseDir) === canonicalize(path.join(root, "src")) ? path.join(root, "src") : root;
|
|
1368
1412
|
middlewarePath = findMiddlewareFile(root, fileMatcher, middlewareConventionDir);
|
|
1413
|
+
pageTransformCanonicalPaths.clear();
|
|
1414
|
+
canonicalMiddlewarePath = middlewarePath ? canonicalize(middlewarePath) : null;
|
|
1369
1415
|
if (middlewarePath) {
|
|
1370
1416
|
const staticMatcher = extractMiddlewareMatcherConfigValue(middlewarePath);
|
|
1371
1417
|
if (staticMatcher !== void 0) validateMiddlewareMatcherPatterns(staticMatcher);
|
|
@@ -1522,6 +1568,7 @@ function vinext(options = {}) {
|
|
|
1522
1568
|
const viteConfig = {
|
|
1523
1569
|
appType: "custom",
|
|
1524
1570
|
...devCliLifecycleEnabled ? { [VINEXT_DEV_CLI_LIFECYCLE]: true } : {},
|
|
1571
|
+
...hasAppDir && hasNitroPlugin ? { rsc: { serverHandler: false } } : {},
|
|
1525
1572
|
...!hasAppDir && hasCloudflarePlugin ? { builder: {
|
|
1526
1573
|
...config.builder,
|
|
1527
1574
|
sharedConfigBuild: true
|
|
@@ -1553,6 +1600,10 @@ function vinext(options = {}) {
|
|
|
1553
1600
|
},
|
|
1554
1601
|
worker: { plugins: () => [createWorkerImageImportsPlugin({ deploymentId: nextConfig.deploymentId })] },
|
|
1555
1602
|
server: {
|
|
1603
|
+
watch: config.server?.watch === null ? null : {
|
|
1604
|
+
ignored: [VINEXT_GENERATED_DIR_RE],
|
|
1605
|
+
exclude: [VINEXT_GENERATED_DIR_RE]
|
|
1606
|
+
},
|
|
1556
1607
|
cors: {
|
|
1557
1608
|
preflightContinue: true,
|
|
1558
1609
|
origin: /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/
|
|
@@ -1604,7 +1655,8 @@ function vinext(options = {}) {
|
|
|
1604
1655
|
transformer: "lightningcss",
|
|
1605
1656
|
lightningcss: {
|
|
1606
1657
|
...nextConfig.lightningCssFeatures.include ? { include: nextConfig.lightningCssFeatures.include } : {},
|
|
1607
|
-
...nextConfig.lightningCssFeatures.exclude ? { exclude: nextConfig.lightningCssFeatures.exclude } : {}
|
|
1658
|
+
...nextConfig.lightningCssFeatures.exclude ? { exclude: nextConfig.lightningCssFeatures.exclude } : {},
|
|
1659
|
+
...(nextConfig.lightningCssFeatures.include & ~nextConfig.lightningCssFeatures.exclude & lightningCssFeatureNamesToMask(["custom-media-queries"])) !== 0 ? { drafts: { customMedia: true } } : {}
|
|
1608
1660
|
}
|
|
1609
1661
|
} : {},
|
|
1610
1662
|
...postcssOverride ? { postcss: postcssOverride } : {},
|
|
@@ -1654,7 +1706,7 @@ function vinext(options = {}) {
|
|
|
1654
1706
|
...depOptimizeNodeEnvOptions,
|
|
1655
1707
|
rolldownOptions: {
|
|
1656
1708
|
...depOptimizeNodeEnvOptions.rolldownOptions,
|
|
1657
|
-
plugins: [depOptimizeAliasPlugin]
|
|
1709
|
+
plugins: [depOptimizeAliasPlugin, commonJsEsmFacadeOptimizeDepsPlugin]
|
|
1658
1710
|
}
|
|
1659
1711
|
};
|
|
1660
1712
|
pagesOptimizeEntries = !hasAppDir ? [...hasPagesDir ? [toRelativeFileEntry(root, pagesDir) + "/**/*.{tsx,ts,jsx,js}"] : [], ...[instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : [])] : [];
|
|
@@ -1714,8 +1766,10 @@ function vinext(options = {}) {
|
|
|
1714
1766
|
}
|
|
1715
1767
|
const appClientInput = { index: VIRTUAL_APP_BROWSER_ENTRY };
|
|
1716
1768
|
if (hasPagesDir) appClientInput["vinext-client-entry"] = VIRTUAL_CLIENT_ENTRY;
|
|
1769
|
+
const nitroDevEnvironmentResolve = hasNitroPlugin && env?.command === "serve" ? { resolve: { noExternal: ["next"] } } : {};
|
|
1717
1770
|
viteConfig.environments = {
|
|
1718
1771
|
rsc: {
|
|
1772
|
+
...nitroDevEnvironmentResolve,
|
|
1719
1773
|
...hasCloudflarePlugin || hasNitroPlugin ? {} : { resolve: {
|
|
1720
1774
|
external: userSsrExternal === true ? true : [
|
|
1721
1775
|
"satori",
|
|
@@ -1745,6 +1799,7 @@ function vinext(options = {}) {
|
|
|
1745
1799
|
}
|
|
1746
1800
|
},
|
|
1747
1801
|
ssr: {
|
|
1802
|
+
...nitroDevEnvironmentResolve,
|
|
1748
1803
|
...hasCloudflarePlugin || hasNitroPlugin ? {} : { resolve: {
|
|
1749
1804
|
external: userSsrExternal === true ? true : [
|
|
1750
1805
|
...userSsrExternal,
|
|
@@ -1895,7 +1950,19 @@ function vinext(options = {}) {
|
|
|
1895
1950
|
if (!config.server.middlewareMode) applyDevServerDefaults(config.server, {});
|
|
1896
1951
|
}
|
|
1897
1952
|
}
|
|
1898
|
-
if (isServeCommand && hasCloudflarePlugin && hasPagesDir
|
|
1953
|
+
if (isServeCommand && (hasAppDir || hasCloudflarePlugin && hasPagesDir)) {
|
|
1954
|
+
const optionalWarnings = /* @__PURE__ */ new Set();
|
|
1955
|
+
for (const [name, environment] of Object.entries(config.environments)) {
|
|
1956
|
+
const optimizer = environment.optimizeDeps;
|
|
1957
|
+
const optionalIncludes = hasAppDir ? name === "client" && !optimizer.noDiscovery ? APP_CLIENT_OPTIONAL_OPTIMIZE_DEPS_INCLUDE : [] : name !== "client" ? ["use-sync-external-store/with-selector"] : [];
|
|
1958
|
+
for (const id of optionalIncludes) {
|
|
1959
|
+
if (optimizer.include?.includes(id) || optimizer.exclude?.some((excluded) => id === excluded || id.startsWith(`${excluded}/`))) continue;
|
|
1960
|
+
(optimizer.include ??= []).push(id);
|
|
1961
|
+
optionalWarnings.add(`Failed to resolve dependency: ${id}, present in ${name} 'optimizeDeps.include'`);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
Object.assign(config, { logger: createOptionalOptimizeDepsLogger(config.logger, optionalWarnings) });
|
|
1965
|
+
}
|
|
1899
1966
|
if (config.worker?.rolldownOptions) {
|
|
1900
1967
|
const workerFileNames = `${resolveAssetsDir(nextConfig.assetPrefix ?? "")}/workers/[name]-[hash].js`;
|
|
1901
1968
|
const workerOutputs = config.worker.rolldownOptions.output;
|
|
@@ -2145,6 +2212,7 @@ function vinext(options = {}) {
|
|
|
2145
2212
|
inlineCss: nextConfig?.inlineCss,
|
|
2146
2213
|
globalNotFound: nextConfig?.globalNotFound,
|
|
2147
2214
|
cacheComponents: nextConfig?.cacheComponents,
|
|
2215
|
+
readMdxEsm: !nextConfig?.cacheComponents && pageExtensionsIncludeMdx(nextConfig?.pageExtensions ?? []) ? await loadMdxEsmReader(root) : null,
|
|
2148
2216
|
prefetchInlining: nextConfig?.prefetchInlining,
|
|
2149
2217
|
hasServerActions,
|
|
2150
2218
|
actionOwners: this.environment.config.command === "build" ? void 0 : null,
|
|
@@ -2530,21 +2598,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2530
2598
|
const devBuildId = nextConfig?.buildId ?? process.env.__VINEXT_BUILD_ID ?? "development";
|
|
2531
2599
|
server.middlewares.use((req, _res, next) => {
|
|
2532
2600
|
req.__vinextOriginalEncodedUrl ??= req.url;
|
|
2601
|
+
delete req.headers[VINEXT_MW_CTX_HEADER];
|
|
2533
2602
|
next();
|
|
2534
2603
|
});
|
|
2535
|
-
server.middlewares.use((req, _res, next) => {
|
|
2536
|
-
try {
|
|
2537
|
-
assertNoPublicNextRequestConflict({
|
|
2538
|
-
root: server.config.root,
|
|
2539
|
-
publicDir: server.config.publicDir === "" ? null : server.config.publicDir,
|
|
2540
|
-
basePath: nextConfig.basePath ?? "",
|
|
2541
|
-
requestUrl: req.url ?? "/"
|
|
2542
|
-
});
|
|
2543
|
-
next();
|
|
2544
|
-
} catch (error) {
|
|
2545
|
-
next(error);
|
|
2546
|
-
}
|
|
2547
|
-
});
|
|
2548
2604
|
const pageExtensions = fileMatcher.extensionRegex;
|
|
2549
2605
|
let pagesRunner = null;
|
|
2550
2606
|
const getTrustedDevRevalidateOrigin = () => {
|
|
@@ -2841,6 +2897,22 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2841
2897
|
}
|
|
2842
2898
|
next();
|
|
2843
2899
|
});
|
|
2900
|
+
server.middlewares.use((req, res, next) => {
|
|
2901
|
+
if (!sendRepeatedSlashRedirect(req.url ?? "/", res)) next();
|
|
2902
|
+
});
|
|
2903
|
+
server.middlewares.use((req, _res, next) => {
|
|
2904
|
+
try {
|
|
2905
|
+
assertNoPublicNextRequestConflict({
|
|
2906
|
+
root: server.config.root,
|
|
2907
|
+
publicDir: server.config.publicDir === "" ? null : server.config.publicDir,
|
|
2908
|
+
basePath: nextConfig.basePath ?? "",
|
|
2909
|
+
requestUrl: req.url ?? "/"
|
|
2910
|
+
});
|
|
2911
|
+
next();
|
|
2912
|
+
} catch (error) {
|
|
2913
|
+
next(error);
|
|
2914
|
+
}
|
|
2915
|
+
});
|
|
2844
2916
|
server.middlewares.use((req, res, next) => {
|
|
2845
2917
|
if (!hasPagesDir || !handlePagesMiddleware || !isUnsupportedDevPublicRequest(req)) return next();
|
|
2846
2918
|
handlePagesMiddleware(req, res, next).catch(next);
|
|
@@ -3116,7 +3188,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3116
3188
|
const apiRouteUrl = stripI18nLocaleForApiRoute(pathname, nextConfig?.i18n ?? null);
|
|
3117
3189
|
filePathMatchesPagesRoute = matchRoute(pageRouteUrl, pageRoutes) !== null || matchRoute(apiRouteUrl, apiRoutes) !== null;
|
|
3118
3190
|
}
|
|
3119
|
-
if (isFilePathRequest && !isDataReq && !filePathMatchesRewrite && !filePathMatchesPagesRoute && !isExistingPublicMutation) return next();
|
|
3191
|
+
if (isFilePathRequest && !isDataReq && !filePathMatchesRewrite && !filePathMatchesPagesRoute && !isNextStaticPath(pathname, "", assetPrefixPathname(nextConfig?.assetPrefix ?? "")) && !isExistingPublicMutation) return next();
|
|
3120
3192
|
const rawHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([k, v]) => v !== void 0 && !k.startsWith(":")).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
|
|
3121
3193
|
const isDataRequest = isDataReq;
|
|
3122
3194
|
const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
|
|
@@ -3126,7 +3198,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3126
3198
|
const method = req.method ?? "GET";
|
|
3127
3199
|
const webRequest = new Request(new URL(routeUrl, requestOrigin), {
|
|
3128
3200
|
method,
|
|
3129
|
-
headers: nodeRequestHeaders
|
|
3201
|
+
headers: nodeRequestHeaders,
|
|
3202
|
+
signal: signalFromNodeResponse(res)
|
|
3130
3203
|
});
|
|
3131
3204
|
const applyRequestHeadersToNodeRequest = (nextRequestHeaders) => {
|
|
3132
3205
|
for (const key of Object.keys(req.headers)) delete req.headers[key];
|
|
@@ -3137,7 +3210,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3137
3210
|
const mwOrigin = `${rawProto === "https" || rawProto === "http" ? rawProto : "http"}://${requestHost}`;
|
|
3138
3211
|
const middlewareRequest = new Request(new URL(middlewareUrl, mwOrigin), {
|
|
3139
3212
|
method: req.method,
|
|
3140
|
-
headers: nodeRequestHeaders
|
|
3213
|
+
headers: nodeRequestHeaders,
|
|
3214
|
+
signal: webRequest.signal
|
|
3141
3215
|
});
|
|
3142
3216
|
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest, pathname);
|
|
3143
3217
|
if (hasAppDir && result.continue) {
|
|
@@ -3161,6 +3235,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3161
3235
|
const getDevAppRoutes = () => devAppRoutesPromise ??= hasAppDir && appDir ? appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : Promise.resolve([]);
|
|
3162
3236
|
const classifyDevPageRoute = (route) => classifyDevPageFile(route.filePath);
|
|
3163
3237
|
const pipelineDeps = {
|
|
3238
|
+
assetPrefix: nextConfig?.assetPrefix,
|
|
3164
3239
|
basePath: bp,
|
|
3165
3240
|
trailingSlash: nextConfig?.trailingSlash ?? false,
|
|
3166
3241
|
i18nConfig: nextConfig?.i18n ?? null,
|
|
@@ -3200,7 +3275,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3200
3275
|
const hasBody = externalMethod !== "GET" && externalMethod !== "HEAD";
|
|
3201
3276
|
const externalInit = {
|
|
3202
3277
|
method: externalMethod,
|
|
3203
|
-
headers: currentRequest.headers
|
|
3278
|
+
headers: currentRequest.headers,
|
|
3279
|
+
signal: currentRequest.signal
|
|
3204
3280
|
};
|
|
3205
3281
|
if (hasBody) {
|
|
3206
3282
|
const { Readable } = await import("node:stream");
|
|
@@ -3294,6 +3370,12 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3294
3370
|
const appMatch = matchAppRoute(resolvedPathname, appRoutes);
|
|
3295
3371
|
if (appMatch && !pagesRouteHasPriorityOverAppRoute(renderMatch.route, appMatch.route)) return next();
|
|
3296
3372
|
}
|
|
3373
|
+
if (!renderMatch && isNextStaticPath(resolvedPathname, "", assetPrefixPathname(nextConfig?.assetPrefix ?? ""))) {
|
|
3374
|
+
const headers = new Headers();
|
|
3375
|
+
forEachStagedHeader((key, value) => headers.append(key, value));
|
|
3376
|
+
await writeWebResponseToNodeRes(res, notFoundStaticAssetResponse(headers));
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3297
3379
|
if (!cachedSSRHandler || cachedSSRHandler.routes !== routes) cachedSSRHandler = {
|
|
3298
3380
|
routes,
|
|
3299
3381
|
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true, nextConfig?.expireTime, nextConfig?.crossOrigin, devBuildId, middlewarePath ? compileClientMiddlewareMatchers(extractMiddlewareMatcherConfig(middlewarePath)) : void 0, classifyDevPageRoute)
|
|
@@ -3360,12 +3442,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3360
3442
|
{
|
|
3361
3443
|
name: "vinext:validate-middleware-exports",
|
|
3362
3444
|
enforce: "pre",
|
|
3363
|
-
transform
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3445
|
+
transform: {
|
|
3446
|
+
filter: { id: { exclude: VIRTUAL_MODULE_ID_RE } },
|
|
3447
|
+
handler(code, id) {
|
|
3448
|
+
if (!middlewarePath) return null;
|
|
3449
|
+
const modulePath = stripViteModuleQuery(id);
|
|
3450
|
+
if (canonicalizePageTransformPath(modulePath) !== canonicalMiddlewarePath) return null;
|
|
3451
|
+
validateMiddlewareModuleExports(code, modulePath, middlewarePath, isProxyFile(middlewarePath));
|
|
3452
|
+
return null;
|
|
3453
|
+
}
|
|
3369
3454
|
}
|
|
3370
3455
|
},
|
|
3371
3456
|
{
|
|
@@ -3373,7 +3458,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3373
3458
|
transform: {
|
|
3374
3459
|
filter: {
|
|
3375
3460
|
id: { exclude: VIRTUAL_MODULE_ID_RE },
|
|
3376
|
-
code:
|
|
3461
|
+
code: EXPORT_ALL_CANDIDATE_FILTER
|
|
3377
3462
|
},
|
|
3378
3463
|
handler(code, id) {
|
|
3379
3464
|
if (this.environment?.name !== "client") return null;
|
|
@@ -3470,6 +3555,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3470
3555
|
filter: { code: consumerEnvironmentConditionFilter },
|
|
3471
3556
|
handler(code, id) {
|
|
3472
3557
|
const scansImports = this.environment.config.build.write === false;
|
|
3558
|
+
const skipsUnobservableFold = scansImports && useNativeTypeofWindowFolding && this.environment.config.isBundled;
|
|
3559
|
+
if (skipsUnobservableFold && !mayFoldChangeScannedImports(code)) return null;
|
|
3473
3560
|
const replaceTypeofWindow = !useNativeTypeofWindowFolding || scansImports;
|
|
3474
3561
|
const replaceProcessBrowser = scansImports;
|
|
3475
3562
|
if (!replaceTypeofWindow && !replaceProcessBrowser) return null;
|
|
@@ -3477,12 +3564,13 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3477
3564
|
if (toSlash(id).startsWith(cacheDir)) return null;
|
|
3478
3565
|
const typeofWindow = getTypeofWindowReplacement(this.environment);
|
|
3479
3566
|
const processBrowser = this.environment.config.consumer === "client";
|
|
3480
|
-
const variant = `${replaceTypeofWindow ? typeofWindow : "-"}:${replaceProcessBrowser ? processBrowser : "-"}`;
|
|
3481
|
-
return cachedConsumerConditionTransform(id, code, variant, () => replaceConsumerEnvironmentConditions(code, {
|
|
3567
|
+
const variant = `${replaceTypeofWindow ? typeofWindow : "-"}:${replaceProcessBrowser ? processBrowser : "-"}:${skipsUnobservableFold ? "gated" : "full"}`;
|
|
3568
|
+
return omitUnusedBuildSourcemap(this.environment, cachedConsumerConditionTransform(id, code, variant, () => replaceConsumerEnvironmentConditions(code, {
|
|
3482
3569
|
...replaceTypeofWindow ? { typeofWindow } : {},
|
|
3483
3570
|
...replaceProcessBrowser ? { processBrowser } : {},
|
|
3484
|
-
pruneUnreachableImports: scansImports
|
|
3485
|
-
|
|
3571
|
+
pruneUnreachableImports: scansImports,
|
|
3572
|
+
onlyIfScannedImportsChange: skipsUnobservableFold
|
|
3573
|
+
}, id)));
|
|
3486
3574
|
}
|
|
3487
3575
|
}
|
|
3488
3576
|
},
|
|
@@ -3706,6 +3794,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3706
3794
|
}
|
|
3707
3795
|
const manifest = {
|
|
3708
3796
|
prerenderSecret,
|
|
3797
|
+
compress: nextConfig?.compress !== false,
|
|
3709
3798
|
...serverRuntimeOutputDirs.size === 0 ? {} : { runtimeOutputDirs: [...serverRuntimeOutputDirs].map((runtimeOutputDir) => path.relative(root, runtimeOutputDir) || ".").sort() }
|
|
3710
3799
|
};
|
|
3711
3800
|
const source = JSON.stringify(manifest);
|
|
@@ -4038,22 +4127,25 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
4038
4127
|
}
|
|
4039
4128
|
});
|
|
4040
4129
|
if (rscPluginPromise) plugins.push(rscPluginPromise);
|
|
4041
|
-
if (earlyAppDirExists)
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4130
|
+
if (earlyAppDirExists) {
|
|
4131
|
+
plugins.push(createActionOwnerManifestPlugin({
|
|
4132
|
+
canonicalizeModuleId: canonicalize,
|
|
4133
|
+
async getManager(config) {
|
|
4134
|
+
return (await rscPluginModulePromise)?.getPluginApi(config)?.manager;
|
|
4135
|
+
},
|
|
4136
|
+
getRoutes: () => rscActionOwnerRoutes ?? [],
|
|
4137
|
+
getSharedRoots: () => rscActionOwnerSharedRoots,
|
|
4138
|
+
onComplete() {
|
|
4139
|
+
rscActionOwnerRoutes = null;
|
|
4140
|
+
rscActionOwnerSharedRoots = [];
|
|
4141
|
+
}
|
|
4142
|
+
}));
|
|
4143
|
+
plugins.push(createScanBuildCssPlugin());
|
|
4144
|
+
}
|
|
4053
4145
|
if (rscPluginPromise) {
|
|
4054
4146
|
plugins.push(createRscReferenceValidationNormalizerPlugin());
|
|
4055
4147
|
plugins.push(createRscClientReferenceLoadersPlugin());
|
|
4056
|
-
} else if (manualUseCachePluginPromise) plugins.push(manualUseCachePluginPromise);
|
|
4148
|
+
} else if (manualUseCachePluginPromise) plugins.push(cacheFlightCodecPlugin(), manualUseCachePluginPromise);
|
|
4057
4149
|
plugins.push({
|
|
4058
4150
|
name: "vinext:plain-pages-build-config",
|
|
4059
4151
|
apply: "build",
|
|
@@ -4091,6 +4183,10 @@ function getNextPublicEnvDefines() {
|
|
|
4091
4183
|
* Handles multi-value headers (Set-Cookie) correctly.
|
|
4092
4184
|
*/
|
|
4093
4185
|
async function writeWebResponseToNodeRes(res, response) {
|
|
4186
|
+
if (res.destroyed) {
|
|
4187
|
+
response.body?.cancel().catch(() => {});
|
|
4188
|
+
return;
|
|
4189
|
+
}
|
|
4094
4190
|
const nodeHeaders = {};
|
|
4095
4191
|
response.headers.forEach((value, key) => {
|
|
4096
4192
|
if (key === "set-cookie") return;
|
|
@@ -4103,13 +4199,17 @@ async function writeWebResponseToNodeRes(res, response) {
|
|
|
4103
4199
|
if (response.statusText) res.writeHead(response.status, response.statusText, nodeHeaders);
|
|
4104
4200
|
else res.writeHead(response.status, nodeHeaders);
|
|
4105
4201
|
if (response.body) {
|
|
4106
|
-
const { Readable } = await import("node:stream");
|
|
4202
|
+
const { Readable, pipeline } = await import("node:stream");
|
|
4107
4203
|
const nodeStream = Readable.fromWeb(response.body);
|
|
4204
|
+
let clientDisconnected = false;
|
|
4205
|
+
res.once("close", () => {
|
|
4206
|
+
clientDisconnected = !res.writableFinished && !nodeStream.errored;
|
|
4207
|
+
});
|
|
4108
4208
|
await new Promise((resolve, reject) => {
|
|
4109
|
-
nodeStream
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4209
|
+
pipeline(nodeStream, res, (error) => {
|
|
4210
|
+
if (error && !(clientDisconnected && error.code === "ERR_STREAM_PREMATURE_CLOSE")) reject(error);
|
|
4211
|
+
else resolve();
|
|
4212
|
+
});
|
|
4113
4213
|
});
|
|
4114
4214
|
} else res.end();
|
|
4115
4215
|
}
|
|
@@ -37,7 +37,7 @@ export declare function cssModulesConfigSource(indent?: string): string;
|
|
|
37
37
|
/** Generate vite.config.ts for App Router */
|
|
38
38
|
export declare function generateAppRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, versionMetadataBinding?: string, serviceBinding?: boolean, assetsBinding?: string, assetsDirectory?: string, hasCssModules?: boolean): string;
|
|
39
39
|
/** Generate vite.config.ts for Pages Router */
|
|
40
|
-
export declare function generatePagesRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, versionMetadataBinding?: string, serviceBinding?: boolean, hasCssModules?: boolean): string;
|
|
40
|
+
export declare function generatePagesRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, versionMetadataBinding?: string, serviceBinding?: boolean, hasCssModules?: boolean, assetsBinding?: string, assetsDirectory?: string): string;
|
|
41
41
|
export declare function updateViteConfigForCssModules(filePath: string, code: string): {
|
|
42
42
|
code: string;
|
|
43
43
|
preservedExistingGenerateScopedName: boolean;
|