vinext 0.1.1 → 0.1.3
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 +2 -5
- package/dist/build/client-build-config.d.ts +7 -1
- package/dist/build/client-build-config.js +9 -1
- package/dist/build/prerender.d.ts +9 -1
- package/dist/build/prerender.js +41 -12
- package/dist/build/run-prerender.d.ts +10 -2
- package/dist/build/run-prerender.js +15 -1
- package/dist/check.js +4 -3
- package/dist/client/app-nav-failure-handler.d.ts +8 -0
- package/dist/client/app-nav-failure-handler.js +44 -0
- package/dist/client/navigation-runtime.d.ts +3 -2
- package/dist/client/vinext-next-data.d.ts +18 -1
- package/dist/client/window-next.d.ts +8 -5
- package/dist/client/window-next.js +12 -1
- package/dist/cloudflare/src/cache/cdn-adapter.runtime.js +6 -1
- package/dist/config/config-matchers.d.ts +11 -4
- package/dist/config/config-matchers.js +88 -16
- package/dist/config/next-config.d.ts +59 -4
- package/dist/config/next-config.js +149 -48
- package/dist/deploy.d.ts +30 -11
- package/dist/deploy.js +189 -101
- package/dist/entries/app-browser-entry.d.ts +9 -3
- package/dist/entries/app-browser-entry.js +21 -3
- package/dist/entries/app-rsc-entry.d.ts +2 -0
- package/dist/entries/app-rsc-entry.js +71 -6
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/app-ssr-entry.js +1 -1
- package/dist/entries/pages-client-entry.js +54 -9
- package/dist/entries/pages-server-entry.js +48 -11
- package/dist/index.d.ts +0 -2
- package/dist/index.js +285 -139
- package/dist/plugins/dynamic-preload-metadata.d.ts +13 -0
- package/dist/plugins/dynamic-preload-metadata.js +415 -0
- package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
- package/dist/plugins/extensionless-dynamic-import.js +152 -0
- package/dist/plugins/og-assets.js +2 -2
- package/dist/plugins/optimize-imports.d.ts +10 -5
- package/dist/plugins/optimize-imports.js +27 -21
- package/dist/plugins/postcss.js +7 -7
- package/dist/plugins/sass.d.ts +53 -24
- package/dist/plugins/sass.js +249 -1
- package/dist/plugins/typeof-window.d.ts +14 -0
- package/dist/plugins/typeof-window.js +150 -0
- package/dist/plugins/wasm-module-import.d.ts +15 -0
- package/dist/plugins/wasm-module-import.js +50 -0
- package/dist/routing/app-route-graph.d.ts +25 -2
- package/dist/routing/app-route-graph.js +91 -22
- package/dist/routing/file-matcher.d.ts +10 -1
- package/dist/routing/file-matcher.js +23 -2
- package/dist/routing/pages-router.js +3 -3
- package/dist/routing/utils.d.ts +35 -6
- package/dist/routing/utils.js +59 -7
- package/dist/server/api-handler.d.ts +6 -1
- package/dist/server/api-handler.js +21 -15
- package/dist/server/app-browser-action-result.d.ts +19 -6
- package/dist/server/app-browser-action-result.js +19 -10
- package/dist/server/app-browser-entry.js +269 -297
- package/dist/server/app-browser-error.d.ts +10 -3
- package/dist/server/app-browser-error.js +47 -6
- package/dist/server/app-browser-history-controller.d.ts +104 -0
- package/dist/server/app-browser-history-controller.js +210 -0
- package/dist/server/app-browser-hydration.d.ts +2 -0
- package/dist/server/app-browser-hydration.js +1 -0
- package/dist/server/app-browser-navigation-controller.d.ts +7 -4
- package/dist/server/app-browser-navigation-controller.js +33 -9
- package/dist/server/app-browser-rsc-redirect.d.ts +11 -2
- package/dist/server/app-browser-rsc-redirect.js +30 -8
- package/dist/server/app-browser-server-action-navigation.d.ts +6 -0
- package/dist/server/app-browser-server-action-navigation.js +9 -0
- package/dist/server/app-browser-state.js +4 -7
- package/dist/server/app-browser-stream.js +86 -43
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-elements-wire.d.ts +6 -1
- package/dist/server/app-elements-wire.js +14 -4
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +2 -2
- package/dist/server/app-fallback-renderer.d.ts +3 -1
- package/dist/server/app-fallback-renderer.js +6 -2
- package/dist/server/app-middleware.js +1 -0
- package/dist/server/app-optimistic-routing.js +24 -3
- package/dist/server/app-page-boundary-render.d.ts +3 -1
- package/dist/server/app-page-boundary-render.js +31 -16
- package/dist/server/app-page-cache-render.d.ts +53 -0
- package/dist/server/app-page-cache-render.js +91 -0
- package/dist/server/app-page-cache.d.ts +16 -2
- package/dist/server/app-page-cache.js +71 -8
- package/dist/server/app-page-dispatch.d.ts +34 -0
- package/dist/server/app-page-dispatch.js +167 -97
- package/dist/server/app-page-element-builder.d.ts +23 -2
- package/dist/server/app-page-element-builder.js +42 -10
- package/dist/server/app-page-execution.d.ts +7 -2
- package/dist/server/app-page-execution.js +53 -18
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +4 -0
- package/dist/server/app-page-render-observation.d.ts +3 -1
- package/dist/server/app-page-render-observation.js +17 -1
- package/dist/server/app-page-render.d.ts +13 -2
- package/dist/server/app-page-render.js +48 -17
- package/dist/server/app-page-request.d.ts +3 -0
- package/dist/server/app-page-request.js +5 -3
- package/dist/server/app-page-response.js +1 -1
- package/dist/server/app-page-route-wiring.d.ts +5 -1
- package/dist/server/app-page-route-wiring.js +21 -11
- package/dist/server/app-page-stream.d.ts +16 -9
- package/dist/server/app-page-stream.js +12 -9
- package/dist/server/app-pages-bridge.d.ts +18 -0
- package/dist/server/app-pages-bridge.js +22 -5
- package/dist/server/app-ppr-fallback-shell-render.d.ts +17 -0
- package/dist/server/app-ppr-fallback-shell-render.js +26 -0
- package/dist/server/app-ppr-fallback-shell.d.ts +13 -1
- package/dist/server/app-ppr-fallback-shell.js +8 -1
- package/dist/server/app-route-handler-dispatch.js +9 -2
- package/dist/server/app-route-handler-policy.d.ts +1 -0
- package/dist/server/app-route-handler-response.js +11 -10
- package/dist/server/app-route-handler-runtime.js +12 -1
- package/dist/server/app-router-entry.js +5 -0
- package/dist/server/app-rsc-cache-busting.js +2 -0
- package/dist/server/app-rsc-handler.d.ts +25 -0
- package/dist/server/app-rsc-handler.js +153 -53
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.d.ts +3 -0
- package/dist/server/app-rsc-route-matching.js +2 -0
- package/dist/server/app-segment-config.d.ts +9 -1
- package/dist/server/app-segment-config.js +12 -3
- package/dist/server/app-server-action-execution.d.ts +12 -0
- package/dist/server/app-server-action-execution.js +47 -15
- package/dist/server/app-ssr-entry.d.ts +2 -0
- package/dist/server/app-ssr-entry.js +81 -8
- package/dist/server/app-ssr-stream.js +9 -1
- package/dist/server/cache-control.js +4 -0
- package/dist/server/dev-lockfile.js +2 -1
- package/dist/server/dev-server.d.ts +2 -2
- package/dist/server/dev-server.js +287 -63
- package/dist/server/headers.d.ts +8 -1
- package/dist/server/headers.js +8 -1
- package/dist/server/hybrid-route-priority.d.ts +22 -0
- package/dist/server/hybrid-route-priority.js +33 -0
- package/dist/server/image-optimization.d.ts +18 -9
- package/dist/server/image-optimization.js +37 -23
- package/dist/server/implicit-tags.d.ts +2 -1
- package/dist/server/implicit-tags.js +4 -1
- package/dist/server/instrumentation-runtime.d.ts +6 -0
- package/dist/server/instrumentation-runtime.js +8 -0
- package/dist/server/isr-decision.d.ts +79 -0
- package/dist/server/isr-decision.js +70 -0
- package/dist/server/metadata-route-response.js +5 -3
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +11 -7
- package/dist/server/middleware.js +1 -0
- package/dist/server/navigation-planner.d.ts +186 -22
- package/dist/server/navigation-planner.js +302 -0
- package/dist/server/navigation-trace.d.ts +18 -1
- package/dist/server/navigation-trace.js +18 -1
- package/dist/server/normalize-path.d.ts +0 -8
- package/dist/server/normalize-path.js +3 -1
- package/dist/server/otel-tracer-extension.d.ts +45 -0
- package/dist/server/otel-tracer-extension.js +89 -0
- package/dist/server/pages-api-route.d.ts +20 -3
- package/dist/server/pages-api-route.js +19 -3
- package/dist/server/pages-asset-tags.d.ts +16 -4
- package/dist/server/pages-asset-tags.js +22 -12
- package/dist/server/pages-data-route.d.ts +8 -1
- package/dist/server/pages-data-route.js +16 -3
- package/dist/server/pages-get-initial-props.d.ts +54 -4
- package/dist/server/pages-get-initial-props.js +43 -1
- package/dist/server/pages-node-compat.d.ts +3 -11
- package/dist/server/pages-node-compat.js +175 -122
- package/dist/server/pages-page-data.d.ts +39 -2
- package/dist/server/pages-page-data.js +261 -46
- package/dist/server/pages-page-handler.d.ts +5 -2
- package/dist/server/pages-page-handler.js +78 -25
- package/dist/server/pages-page-response.d.ts +47 -2
- package/dist/server/pages-page-response.js +73 -9
- package/dist/server/pages-readiness.d.ts +1 -1
- package/dist/server/pages-request-pipeline.d.ts +16 -1
- package/dist/server/pages-request-pipeline.js +96 -38
- package/dist/server/pregenerated-concrete-paths.d.ts +1 -17
- package/dist/server/pregenerated-concrete-paths.js +2 -19
- package/dist/server/prerender-manifest.d.ts +33 -0
- package/dist/server/prerender-manifest.js +54 -0
- package/dist/server/prerender-route-params.d.ts +1 -2
- package/dist/server/prod-server.d.ts +39 -1
- package/dist/server/prod-server.js +107 -37
- package/dist/server/request-pipeline.d.ts +3 -15
- package/dist/server/request-pipeline.js +58 -47
- package/dist/server/rsc-stream-hints.d.ts +5 -1
- package/dist/server/rsc-stream-hints.js +6 -1
- package/dist/server/seed-cache.js +10 -18
- package/dist/shims/app-router-scroll-state.d.ts +3 -1
- package/dist/shims/app-router-scroll-state.js +14 -2
- package/dist/shims/app-router-scroll.d.ts +3 -0
- package/dist/shims/app-router-scroll.js +28 -18
- package/dist/shims/cache-runtime.js +12 -4
- package/dist/shims/cache.d.ts +1 -0
- package/dist/shims/cache.js +1 -1
- package/dist/shims/cdn-cache.d.ts +5 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +8 -0
- package/dist/shims/dynamic-preload-chunks.js +79 -0
- package/dist/shims/dynamic.d.ts +4 -0
- package/dist/shims/dynamic.js +4 -2
- package/dist/shims/error-boundary.d.ts +6 -4
- package/dist/shims/error-boundary.js +7 -0
- package/dist/shims/error.js +38 -11
- package/dist/shims/error.react-server.d.ts +9 -0
- package/dist/shims/error.react-server.js +6 -0
- package/dist/shims/fetch-cache.d.ts +11 -1
- package/dist/shims/fetch-cache.js +55 -20
- package/dist/shims/hash-scroll.js +6 -1
- package/dist/shims/head.js +6 -1
- package/dist/shims/headers.d.ts +16 -2
- package/dist/shims/headers.js +66 -5
- package/dist/shims/image-config.js +7 -1
- package/dist/shims/internal/als-registry.js +28 -1
- package/dist/shims/internal/app-route-detection.d.ts +6 -3
- package/dist/shims/internal/app-route-detection.js +18 -23
- package/dist/shims/internal/app-router-context.d.ts +5 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +31 -0
- package/dist/shims/internal/hybrid-client-route-owner.js +143 -0
- package/dist/shims/internal/navigation-untracked.d.ts +35 -0
- package/dist/shims/internal/navigation-untracked.js +55 -0
- package/dist/shims/internal/pages-data-target.d.ts +7 -2
- package/dist/shims/internal/pages-data-target.js +17 -8
- package/dist/shims/internal/pages-router-accessor.d.ts +19 -0
- package/dist/shims/internal/pages-router-accessor.js +13 -0
- package/dist/shims/internal/router-context.d.ts +2 -1
- package/dist/shims/internal/router-context.js +3 -1
- package/dist/shims/link.js +12 -5
- package/dist/shims/metadata.d.ts +6 -2
- package/dist/shims/metadata.js +32 -14
- package/dist/shims/navigation.d.ts +14 -17
- package/dist/shims/navigation.js +93 -46
- package/dist/shims/ppr-fallback-shell.d.ts +5 -1
- package/dist/shims/ppr-fallback-shell.js +28 -7
- package/dist/shims/router.d.ts +13 -2
- package/dist/shims/router.js +434 -116
- package/dist/shims/script-nonce-context.d.ts +1 -1
- package/dist/shims/script-nonce-context.js +11 -3
- package/dist/shims/server.d.ts +33 -2
- package/dist/shims/server.js +75 -18
- package/dist/shims/slot.js +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/typegen.js +1 -0
- package/dist/utils/built-asset-url.d.ts +4 -0
- package/dist/utils/built-asset-url.js +11 -0
- package/dist/utils/client-build-manifest.js +15 -5
- package/dist/utils/client-runtime-metadata.d.ts +45 -0
- package/dist/utils/client-runtime-metadata.js +63 -0
- package/dist/utils/commonjs-loader.d.ts +16 -0
- package/dist/utils/commonjs-loader.js +100 -0
- package/dist/utils/deployment-id.d.ts +8 -0
- package/dist/utils/deployment-id.js +22 -0
- package/dist/utils/hash.d.ts +17 -1
- package/dist/utils/hash.js +36 -1
- package/dist/utils/html-limited-bots.d.ts +18 -1
- package/dist/utils/html-limited-bots.js +23 -1
- package/dist/utils/lazy-chunks.d.ts +27 -1
- package/dist/utils/lazy-chunks.js +65 -1
- package/dist/utils/manifest-paths.d.ts +20 -2
- package/dist/utils/manifest-paths.js +38 -3
- package/dist/utils/parse-cookie.d.ts +13 -0
- package/dist/utils/parse-cookie.js +52 -0
- package/dist/utils/path.d.ts +8 -1
- package/dist/utils/path.js +13 -1
- package/package.json +2 -2
- package/dist/shims/internal/parse-cookie-header.d.ts +0 -14
- package/dist/shims/internal/parse-cookie-header.js +0 -30
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { detectPackageManager } from "./utils/project.js";
|
|
2
|
+
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
2
3
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
3
|
-
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts } from "./routing/file-matcher.js";
|
|
4
|
+
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
4
5
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
5
|
-
import {
|
|
6
|
-
import { INTERNAL_HEADERS, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
6
|
+
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
7
7
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
8
8
|
import { proxyExternalRequest } from "./config/config-matchers.js";
|
|
9
9
|
import { filterInternalHeaders, isOpenRedirectShaped, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
10
10
|
import { findMiddlewareFile, runMiddleware } from "./server/middleware.js";
|
|
11
11
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
12
12
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
13
|
-
import { appRouteGraph, appRouter, invalidateAppRouteCache } from "./routing/app-router.js";
|
|
13
|
+
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
14
14
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
15
15
|
import { isUnknownRecord } from "./utils/record.js";
|
|
16
16
|
import { logRequest, now } from "./server/request-log.js";
|
|
17
17
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
18
18
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
19
|
-
import { isImageOptimizationPath } from "./server/image-optimization.js";
|
|
19
|
+
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
20
20
|
import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
|
|
21
21
|
import { scanMetadataFiles } from "./server/metadata-routes.js";
|
|
22
22
|
import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
|
|
@@ -25,11 +25,11 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
|
25
25
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
26
26
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
27
27
|
import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
28
|
-
import { generateBrowserEntry, isLinkPrefetchRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
|
|
28
|
+
import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
|
|
29
29
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
30
30
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
31
31
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
32
|
-
import {
|
|
32
|
+
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
33
33
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
34
34
|
import { getViteMajorVersion } from "./utils/vite-version.js";
|
|
35
35
|
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
@@ -40,7 +40,8 @@ import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-mani
|
|
|
40
40
|
import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
|
|
41
41
|
import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
|
|
42
42
|
import { runPagesRequest } from "./server/pages-request-pipeline.js";
|
|
43
|
-
import {
|
|
43
|
+
import { pagesRouteHasPriorityOverAppRoute, validateHybridRouteConflicts } from "./server/hybrid-route-priority.js";
|
|
44
|
+
import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
|
|
44
45
|
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
|
|
45
46
|
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
|
|
46
47
|
import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
|
|
@@ -49,23 +50,26 @@ import { createInstrumentationClientTransformPlugin } from "./plugins/instrument
|
|
|
49
50
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
50
51
|
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
51
52
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
53
|
+
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
54
|
+
import { createDynamicPreloadMetadataPlugin } from "./plugins/dynamic-preload-metadata.js";
|
|
52
55
|
import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins/og-assets.js";
|
|
53
56
|
import { generateRouteTypes } from "./typegen.js";
|
|
54
57
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
55
58
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
58
|
-
import { VINEXT_CLIENT_ENTRY_MANIFEST, findClientEntryFileFromVinextManifest, findPagesClientEntryFileFromVinextManifest, readClientEntryManifest } from "./utils/client-entry-manifest.js";
|
|
59
|
+
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
60
|
+
import { buildRuntimeGlobalsScript, computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
59
61
|
import { formatMissingCloudflarePluginError, hasWranglerConfig } from "./deploy.js";
|
|
60
62
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
61
|
-
import { buildSassPreprocessorOptions } from "./plugins/sass.js";
|
|
62
|
-
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
63
|
+
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
|
|
64
|
+
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
63
65
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
64
|
-
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
65
66
|
import { stripServerExports } from "./plugins/strip-server-exports.js";
|
|
66
67
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
67
68
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
68
69
|
import { createRequireContextPlugin } from "./plugins/require-context.js";
|
|
70
|
+
import { createExtensionlessDynamicImportPlugin } from "./plugins/extensionless-dynamic-import.js";
|
|
71
|
+
import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
72
|
+
import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeof-window.js";
|
|
69
73
|
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
70
74
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
71
75
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
@@ -80,25 +84,10 @@ import MagicString from "magic-string";
|
|
|
80
84
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
81
85
|
//#region src/index.ts
|
|
82
86
|
installSocketErrorBackstop();
|
|
83
|
-
function stripViteModuleQuery(id) {
|
|
84
|
-
const queryIndex = id.search(/[?#]/);
|
|
85
|
-
return queryIndex === -1 ? id : id.slice(0, queryIndex);
|
|
86
|
-
}
|
|
87
87
|
function isInsideDirectory(dir, filePath) {
|
|
88
88
|
const relativePath = path.relative(dir, filePath);
|
|
89
89
|
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
90
90
|
}
|
|
91
|
-
function hasModuleLevelUseServerDirective(body) {
|
|
92
|
-
for (const node of body) {
|
|
93
|
-
if (node.type !== "ExpressionStatement") break;
|
|
94
|
-
const directive = node.directive;
|
|
95
|
-
const expression = node.expression;
|
|
96
|
-
const value = typeof directive === "string" ? directive : expression?.type === "Literal" ? expression.value : void 0;
|
|
97
|
-
if (value === "use server") return true;
|
|
98
|
-
if (typeof value !== "string") break;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
91
|
function hasServerOnlyMarkerImport(code) {
|
|
103
92
|
if (!code.includes("server-only")) return false;
|
|
104
93
|
let ast;
|
|
@@ -107,7 +96,6 @@ function hasServerOnlyMarkerImport(code) {
|
|
|
107
96
|
} catch {
|
|
108
97
|
return false;
|
|
109
98
|
}
|
|
110
|
-
if (hasModuleLevelUseServerDirective(ast.body)) return false;
|
|
111
99
|
function walk(node) {
|
|
112
100
|
if (!node) return false;
|
|
113
101
|
if (Array.isArray(node)) return node.some((child) => walk(child));
|
|
@@ -148,10 +136,10 @@ function resolveShimModulePath(shimsDir, moduleName) {
|
|
|
148
136
|
".tsx",
|
|
149
137
|
".js"
|
|
150
138
|
]) {
|
|
151
|
-
const candidate = path.join(shimsDir, `${moduleName}${ext}`);
|
|
139
|
+
const candidate = path.posix.join(shimsDir, `${moduleName}${ext}`);
|
|
152
140
|
if (fs.existsSync(candidate)) return candidate;
|
|
153
141
|
}
|
|
154
|
-
return path.join(shimsDir, `${moduleName}.js`);
|
|
142
|
+
return path.posix.join(shimsDir, `${moduleName}.js`);
|
|
155
143
|
}
|
|
156
144
|
function isVercelOgImport(id) {
|
|
157
145
|
return id === "@vercel/og" || id === "@vercel/og.js";
|
|
@@ -300,8 +288,14 @@ const RESOLVED_INSTRUMENTATION_CLIENT = `\0${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs
|
|
|
300
288
|
/** Image file extensions handled by the vinext:image-imports plugin.
|
|
301
289
|
* Shared between the Rolldown hook filter and the transform handler regex. */
|
|
302
290
|
const IMAGE_EXTS = "png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?";
|
|
303
|
-
/**
|
|
304
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Absolute path to vinext's shims directory, with a trailing slash. Normalized
|
|
293
|
+
* to forward slashes because it is prefix-matched against Vite module ids (which
|
|
294
|
+
* Vite always normalizes to forward slashes) in the font plugins and
|
|
295
|
+
* clientManualChunks — a raw path.resolve value has backslashes on Windows and
|
|
296
|
+
* the `id.startsWith(_shimsDir)` checks would never match.
|
|
297
|
+
*/
|
|
298
|
+
const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
|
|
305
299
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
306
300
|
function isValidExportIdentifier(name) {
|
|
307
301
|
return /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
@@ -312,49 +306,52 @@ function isVirtualEntryFacade(id, virtualId) {
|
|
|
312
306
|
return cleanId === virtualId || cleanId.endsWith("/" + virtualId) || cleanId.endsWith("\\" + virtualId);
|
|
313
307
|
}
|
|
314
308
|
/**
|
|
315
|
-
* Returns
|
|
316
|
-
*
|
|
309
|
+
* Returns the leading React `"use client"` or `"use server"` directive after
|
|
310
|
+
* stripping leading comments, hashbang, and whitespace.
|
|
317
311
|
*
|
|
318
312
|
* Used by `vinext:jsx-in-js` to opt `.js` files inside `node_modules` into the
|
|
319
313
|
* JSX transform. We mirror `@vitejs/plugin-rsc`'s detection by looking at the
|
|
320
314
|
* directive prologue rather than scanning the whole file — `code.includes`
|
|
321
315
|
* alone would match incidental occurrences in template literals or comments.
|
|
322
316
|
*/
|
|
323
|
-
function
|
|
317
|
+
function getLeadingReactDirective(code) {
|
|
324
318
|
let i = 0;
|
|
325
319
|
const len = code.length;
|
|
326
320
|
if (code.charCodeAt(0) === 65279) i = 1;
|
|
327
321
|
if (code[i] === "#" && code[i + 1] === "!") {
|
|
328
322
|
const nl = code.indexOf("\n", i);
|
|
329
|
-
if (nl === -1) return
|
|
323
|
+
if (nl === -1) return null;
|
|
330
324
|
i = nl + 1;
|
|
331
325
|
}
|
|
332
326
|
while (i < len) {
|
|
333
327
|
while (i < len && /\s/.test(code[i] ?? "")) i++;
|
|
334
|
-
if (i >= len) return
|
|
328
|
+
if (i >= len) return null;
|
|
335
329
|
if (code[i] === "/" && code[i + 1] === "/") {
|
|
336
330
|
const nl = code.indexOf("\n", i + 2);
|
|
337
|
-
if (nl === -1) return
|
|
331
|
+
if (nl === -1) return null;
|
|
338
332
|
i = nl + 1;
|
|
339
333
|
continue;
|
|
340
334
|
}
|
|
341
335
|
if (code[i] === "/" && code[i + 1] === "*") {
|
|
342
336
|
const end = code.indexOf("*/", i + 2);
|
|
343
|
-
if (end === -1) return
|
|
337
|
+
if (end === -1) return null;
|
|
344
338
|
i = end + 2;
|
|
345
339
|
continue;
|
|
346
340
|
}
|
|
347
341
|
const quote = code[i];
|
|
348
|
-
if (quote !== "\"" && quote !== "'") return
|
|
342
|
+
if (quote !== "\"" && quote !== "'") return null;
|
|
349
343
|
const closing = code.indexOf(quote, i + 1);
|
|
350
|
-
if (closing === -1) return
|
|
344
|
+
if (closing === -1) return null;
|
|
351
345
|
const directive = code.slice(i + 1, closing);
|
|
352
|
-
if (directive === "use client" || directive === "use server") return
|
|
346
|
+
if (directive === "use client" || directive === "use server") return directive;
|
|
353
347
|
i = closing + 1;
|
|
354
348
|
while (i < len && (code[i] === ";" || code[i] === " " || code[i] === " ")) i++;
|
|
355
349
|
if (code[i] === "\n") i++;
|
|
356
350
|
}
|
|
357
|
-
return
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
function hasReactDirective(code) {
|
|
354
|
+
return getLeadingReactDirective(code) !== null;
|
|
358
355
|
}
|
|
359
356
|
function generateRootParamsModule(rootParamNames) {
|
|
360
357
|
const names = Array.from(new Set(rootParamNames)).filter(isValidExportIdentifier).sort();
|
|
@@ -380,12 +377,15 @@ function generateRootParamsModule(rootParamNames) {
|
|
|
380
377
|
const _reactServerShims = new Map([
|
|
381
378
|
["next/navigation", "navigation"],
|
|
382
379
|
["next/navigation.js", "navigation"],
|
|
383
|
-
["next/dist/client/components/navigation", "navigation"]
|
|
380
|
+
["next/dist/client/components/navigation", "navigation"],
|
|
381
|
+
["next/error", "error"],
|
|
382
|
+
["next/error.js", "error"]
|
|
384
383
|
]);
|
|
385
384
|
const clientManualChunks = createClientManualChunks(_shimsDir);
|
|
386
385
|
const clientCodeSplittingConfig = createClientCodeSplittingConfig(clientManualChunks);
|
|
387
386
|
function getClientOutputConfigForVite(viteMajorVersion, assetsDir) {
|
|
388
387
|
return viteMajorVersion >= 8 ? {
|
|
388
|
+
...createClientFileNameConfig(assetsDir),
|
|
389
389
|
assetFileNames: createClientAssetFileNames(assetsDir),
|
|
390
390
|
codeSplitting: clientCodeSplittingConfig
|
|
391
391
|
} : createClientOutputConfig(clientManualChunks, assetsDir);
|
|
@@ -409,6 +409,7 @@ function vinext(options = {}) {
|
|
|
409
409
|
let hasNitroPlugin = false;
|
|
410
410
|
let rscCompatibilityId;
|
|
411
411
|
const draftModeSecret = randomUUID();
|
|
412
|
+
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
412
413
|
let rscClassificationManifest = null;
|
|
413
414
|
const shimsDir = path.resolve(__dirname, "shims");
|
|
414
415
|
const canonicalize = (p) => tryRealpathSync(p) ?? p;
|
|
@@ -434,7 +435,7 @@ function vinext(options = {}) {
|
|
|
434
435
|
* __NEXT_DATA__ to determine which page to hydrate.
|
|
435
436
|
*/
|
|
436
437
|
async function generateClientEntry$1() {
|
|
437
|
-
const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).
|
|
438
|
+
const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => isLinkPrefetchRoute(route) ? toLinkPrefetchRoute(route) : toDocumentOnlyAppRoute(route)) : [];
|
|
438
439
|
return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
|
|
439
440
|
appPrefetchRoutes,
|
|
440
441
|
instrumentationClientPath
|
|
@@ -547,7 +548,7 @@ function vinext(options = {}) {
|
|
|
547
548
|
name: "vinext:config",
|
|
548
549
|
enforce: "pre",
|
|
549
550
|
async config(config, env) {
|
|
550
|
-
root = config.root ?? process.cwd();
|
|
551
|
+
root = normalizePathSeparators(config.root ?? process.cwd());
|
|
551
552
|
const userResolve = config.resolve;
|
|
552
553
|
const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === void 0;
|
|
553
554
|
const tsconfigPathAliases = resolveTsconfigAliases(root);
|
|
@@ -556,22 +557,22 @@ function vinext(options = {}) {
|
|
|
556
557
|
for (const [key, value] of Object.entries(dotenvVars)) if (process.env[key] === void 0) process.env[key] = value;
|
|
557
558
|
let resolvedNodeEnv;
|
|
558
559
|
if (mode === "test") resolvedNodeEnv = "test";
|
|
559
|
-
else if (env?.command === "build") resolvedNodeEnv = "production";
|
|
560
|
+
else if (env?.command === "build" || env?.isPreview === true) resolvedNodeEnv = "production";
|
|
560
561
|
else resolvedNodeEnv = "development";
|
|
561
562
|
if (process.env.NODE_ENV !== resolvedNodeEnv) process.env.NODE_ENV = resolvedNodeEnv;
|
|
562
563
|
let baseDir;
|
|
563
|
-
if (options.appDir) baseDir = path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir);
|
|
564
|
+
if (options.appDir) baseDir = normalizePathSeparators(path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir));
|
|
564
565
|
else {
|
|
565
|
-
const hasRootApp = fs.existsSync(path.join(root, "app"));
|
|
566
|
-
const hasRootPages = fs.existsSync(path.join(root, "pages"));
|
|
567
|
-
const hasSrcApp = fs.existsSync(path.join(root, "src", "app"));
|
|
568
|
-
const hasSrcPages = fs.existsSync(path.join(root, "src", "pages"));
|
|
566
|
+
const hasRootApp = fs.existsSync(path.posix.join(root, "app"));
|
|
567
|
+
const hasRootPages = fs.existsSync(path.posix.join(root, "pages"));
|
|
568
|
+
const hasSrcApp = fs.existsSync(path.posix.join(root, "src", "app"));
|
|
569
|
+
const hasSrcPages = fs.existsSync(path.posix.join(root, "src", "pages"));
|
|
569
570
|
if (hasRootApp || hasRootPages) baseDir = root;
|
|
570
|
-
else if (hasSrcApp || hasSrcPages) baseDir = path.join(root, "src");
|
|
571
|
+
else if (hasSrcApp || hasSrcPages) baseDir = path.posix.join(root, "src");
|
|
571
572
|
else baseDir = root;
|
|
572
573
|
}
|
|
573
|
-
pagesDir = path.join(baseDir, "pages");
|
|
574
|
-
appDir = path.join(baseDir, "app");
|
|
574
|
+
pagesDir = path.posix.join(baseDir, "pages");
|
|
575
|
+
appDir = path.posix.join(baseDir, "app");
|
|
575
576
|
hasPagesDir = fs.existsSync(pagesDir);
|
|
576
577
|
hasAppDir = !options.disableAppRouter && fs.existsSync(appDir);
|
|
577
578
|
if (!nextConfig) {
|
|
@@ -585,7 +586,7 @@ function vinext(options = {}) {
|
|
|
585
586
|
}
|
|
586
587
|
rawConfig = await resolveNextConfigInput(options.nextConfig, phase);
|
|
587
588
|
} else rawConfig = await loadNextConfig(root, phase);
|
|
588
|
-
nextConfig = await resolveNextConfig(rawConfig, root);
|
|
589
|
+
nextConfig = await resolveNextConfig(rawConfig, root, { dev: env?.command === "serve" && env?.isPreview !== true });
|
|
589
590
|
const sharedBuildId = process.env.__VINEXT_SHARED_BUILD_ID;
|
|
590
591
|
if (sharedBuildId && sharedBuildId.length > 0) nextConfig = {
|
|
591
592
|
...nextConfig,
|
|
@@ -612,6 +613,9 @@ function vinext(options = {}) {
|
|
|
612
613
|
defines["process.env.__NEXT_ROUTER_BASEPATH"] = JSON.stringify(nextConfig.basePath);
|
|
613
614
|
defines["process.env.__NEXT_CLIENT_ROUTER_STATIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.static));
|
|
614
615
|
defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
|
|
616
|
+
defines["process.env.__NEXT_GESTURE_TRANSITION"] = JSON.stringify(nextConfig.gestureTransition);
|
|
617
|
+
defines["process.env.__NEXT_APP_NAV_FAIL_HANDLING"] = JSON.stringify(nextConfig.appNavFailHandling);
|
|
618
|
+
defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
|
|
615
619
|
defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
|
|
616
620
|
defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
|
|
617
621
|
defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
|
|
@@ -638,6 +642,7 @@ function vinext(options = {}) {
|
|
|
638
642
|
];
|
|
639
643
|
defines["process.env.__VINEXT_IMAGE_DEVICE_SIZES"] = JSON.stringify(JSON.stringify(deviceSizes));
|
|
640
644
|
defines["process.env.__VINEXT_IMAGE_SIZES"] = JSON.stringify(JSON.stringify(imageSizes));
|
|
645
|
+
defines["process.env.__VINEXT_IMAGE_QUALITIES"] = JSON.stringify(JSON.stringify(nextConfig.images?.qualities ?? null));
|
|
641
646
|
}
|
|
642
647
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowSVG ?? false));
|
|
643
648
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
|
|
@@ -645,9 +650,10 @@ function vinext(options = {}) {
|
|
|
645
650
|
defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
|
|
646
651
|
defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
|
|
647
652
|
defines["process.env.NEXT_DEPLOYMENT_ID"] = nextConfig.deploymentId ? JSON.stringify(nextConfig.deploymentId) : "false";
|
|
653
|
+
defines["process.env.NEXT_RUNTIME"] = "\"\"";
|
|
648
654
|
defines["process.env.__NEXT_VERSION"] = JSON.stringify(getVinextVersion());
|
|
649
655
|
defines["process.env.__NEXT_APP_SHELLS"] = JSON.stringify(nextConfig.appShells);
|
|
650
|
-
defines["process.env.__NEXT_CACHE_COMPONENTS"] = JSON.stringify(
|
|
656
|
+
defines["process.env.__NEXT_CACHE_COMPONENTS"] = JSON.stringify(nextConfig.cacheComponents ?? false);
|
|
651
657
|
for (const [key, value] of Object.entries(nextConfig.compilerDefine)) {
|
|
652
658
|
if (key in defines) throw new Error(`The \`compiler.define\` option is configured to replace the \`${key}\` variable. This variable is either part of a built-in or is already configured.`);
|
|
653
659
|
defines[key] = value;
|
|
@@ -675,7 +681,6 @@ function vinext(options = {}) {
|
|
|
675
681
|
"next/web-vitals": path.join(shimsDir, "web-vitals"),
|
|
676
682
|
"next/amp": path.join(shimsDir, "amp"),
|
|
677
683
|
"next/offline": path.join(shimsDir, "offline"),
|
|
678
|
-
"next/error": path.join(shimsDir, "error"),
|
|
679
684
|
"next/constants": path.join(shimsDir, "constants"),
|
|
680
685
|
"next/dist/shared/lib/app-router-context.shared-runtime": path.join(shimsDir, "internal", "app-router-context"),
|
|
681
686
|
"next/dist/shared/lib/app-router-context": path.join(shimsDir, "internal", "app-router-context"),
|
|
@@ -735,6 +740,7 @@ function vinext(options = {}) {
|
|
|
735
740
|
...typeof config.server?.hmr === "object" ? config.server.hmr : {},
|
|
736
741
|
overlay: false
|
|
737
742
|
};
|
|
743
|
+
const cssModulesOverride = config.css?.modules === false || typeof config.css?.modules === "object" && "Loader" in config.css.modules ? {} : { modules: { Loader: sassComposesLoader.Loader } };
|
|
738
744
|
const viteConfig = {
|
|
739
745
|
appType: "custom",
|
|
740
746
|
build: {
|
|
@@ -784,7 +790,6 @@ function vinext(options = {}) {
|
|
|
784
790
|
...nextConfig.aliases,
|
|
785
791
|
...nextShimMap
|
|
786
792
|
},
|
|
787
|
-
extensions: buildViteResolveExtensions(nextConfig.pageExtensions),
|
|
788
793
|
dedupe: [
|
|
789
794
|
"react",
|
|
790
795
|
"react-dom",
|
|
@@ -796,18 +801,29 @@ function vinext(options = {}) {
|
|
|
796
801
|
...viteMajorVersion >= 8 ? { oxc: { jsx: { runtime: "automatic" } } } : { esbuild: { jsx: "automatic" } },
|
|
797
802
|
define: defines,
|
|
798
803
|
...nextConfig.basePath ? { base: nextConfig.basePath + "/" } : {},
|
|
799
|
-
...nextConfig.assetPrefix ? { experimental: { renderBuiltUrl: (filename) => {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
804
|
+
...nextConfig.assetPrefix || nextConfig.deploymentId ? { experimental: { renderBuiltUrl: (filename, context) => renderVinextBuiltUrl(filename, nextConfig.assetPrefix, nextConfig.deploymentId, context.hostType) } } : {},
|
|
805
|
+
css: {
|
|
806
|
+
...nextConfig.useLightningcss ? {
|
|
807
|
+
transformer: "lightningcss",
|
|
808
|
+
lightningcss: {
|
|
809
|
+
...nextConfig.lightningCssFeatures.include ? { include: nextConfig.lightningCssFeatures.include } : {},
|
|
810
|
+
...nextConfig.lightningCssFeatures.exclude ? { exclude: nextConfig.lightningCssFeatures.exclude } : {}
|
|
811
|
+
}
|
|
812
|
+
} : {},
|
|
805
813
|
...postcssOverride ? { postcss: postcssOverride } : {},
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
814
|
+
preprocessorOptions: (() => {
|
|
815
|
+
const tildeImporter = createSassTildeImporter(root);
|
|
816
|
+
const baseOpts = {
|
|
817
|
+
...sassPreprocessorOptions,
|
|
818
|
+
importers: [tildeImporter, ...sassPreprocessorOptions?.importers ?? []]
|
|
819
|
+
};
|
|
820
|
+
return {
|
|
821
|
+
scss: baseOpts,
|
|
822
|
+
sass: baseOpts
|
|
823
|
+
};
|
|
824
|
+
})(),
|
|
825
|
+
...cssModulesOverride
|
|
826
|
+
}
|
|
811
827
|
};
|
|
812
828
|
const nextServerExternal = nextConfig?.serverExternalPackages ?? [];
|
|
813
829
|
const userSsrExternal = Array.isArray(config.ssr?.external) ? [...config.ssr.external, ...nextServerExternal] : config.ssr?.external === true ? true : nextServerExternal;
|
|
@@ -884,7 +900,7 @@ function vinext(options = {}) {
|
|
|
884
900
|
])]
|
|
885
901
|
},
|
|
886
902
|
build: {
|
|
887
|
-
|
|
903
|
+
manifest: true,
|
|
888
904
|
...hasPagesDir ? { ssrManifest: true } : {},
|
|
889
905
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
890
906
|
...withBuildBundlerOptions(viteMajorVersion, {
|
|
@@ -951,7 +967,29 @@ function vinext(options = {}) {
|
|
|
951
967
|
};
|
|
952
968
|
return viteConfig;
|
|
953
969
|
},
|
|
954
|
-
|
|
970
|
+
configEnvironment(name, config) {
|
|
971
|
+
const configuredExtensions = name === "client" ? nextConfig.resolveExtensions : nextConfig.serverResolveExtensions;
|
|
972
|
+
const extensions = configuredExtensions === null ? buildViteResolveExtensions(nextConfig.pageExtensions, config.resolve?.extensions) : normalizeViteResolveExtensions(configuredExtensions);
|
|
973
|
+
config.resolve ??= {};
|
|
974
|
+
config.resolve.extensions = extensions;
|
|
975
|
+
return null;
|
|
976
|
+
},
|
|
977
|
+
async configResolved(config) {
|
|
978
|
+
sassComposesLoader.setResolvedConfig(config);
|
|
979
|
+
if (config.command === "build" && hasAppDir && hasPagesDir) {
|
|
980
|
+
const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
|
|
981
|
+
appRouter(appDir, nextConfig?.pageExtensions, fileMatcher),
|
|
982
|
+
pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher),
|
|
983
|
+
apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)
|
|
984
|
+
]);
|
|
985
|
+
validateHybridRouteConflicts([...pageRoutes, ...apiRoutes].map((route) => ({
|
|
986
|
+
...route,
|
|
987
|
+
sourcePath: path.relative(root, route.filePath)
|
|
988
|
+
})), appRoutes.filter((route) => route.pagePath !== null || route.routePath !== null).map((route) => ({
|
|
989
|
+
...route,
|
|
990
|
+
sourcePath: path.relative(root, route.pagePath ?? route.routePath)
|
|
991
|
+
})));
|
|
992
|
+
}
|
|
955
993
|
if (hasAppDir) {
|
|
956
994
|
const ssrEnv = config.environments?.ssr;
|
|
957
995
|
if (ssrEnv?.resolve?.external === true && Array.isArray(ssrEnv.resolve.noExternal)) ssrEnv.resolve.noExternal = ssrEnv.resolve.noExternal.filter((entry) => typeof entry !== "string" || !SSR_EXTERNAL_REACT_ENTRIES.includes(entry));
|
|
@@ -973,10 +1011,11 @@ function vinext(options = {}) {
|
|
|
973
1011
|
}));
|
|
974
1012
|
},
|
|
975
1013
|
resolveId: {
|
|
976
|
-
filter: { id: /(?:next\/|virtual:vinext
|
|
1014
|
+
filter: { id: /(?:next\/|vinext\/shims\/|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
|
|
977
1015
|
handler(id, importer) {
|
|
978
1016
|
const cleanId = id.startsWith("\0") ? id.slice(1) : id;
|
|
979
1017
|
if (isVercelOgImport(cleanId) && !isVinextOgShimImporter(importer)) return resolveShimModulePath(_shimsDir, "og");
|
|
1018
|
+
if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
|
|
980
1019
|
if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
|
|
981
1020
|
if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
|
|
982
1021
|
if (cleanId.endsWith("/virtual:vinext-server-entry") || cleanId.endsWith("\\virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
|
|
@@ -1022,7 +1061,13 @@ function vinext(options = {}) {
|
|
|
1022
1061
|
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
1023
1062
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
1024
1063
|
inlineCss: nextConfig?.inlineCss,
|
|
1064
|
+
cacheComponents: nextConfig?.cacheComponents,
|
|
1025
1065
|
i18n: nextConfig?.i18n,
|
|
1066
|
+
imageConfig: {
|
|
1067
|
+
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
1068
|
+
imageSizes: nextConfig?.images?.imageSizes,
|
|
1069
|
+
qualities: nextConfig?.images?.qualities
|
|
1070
|
+
},
|
|
1026
1071
|
hasPagesDir,
|
|
1027
1072
|
publicFiles: scanPublicFileRoutes(root),
|
|
1028
1073
|
globalNotFoundPath,
|
|
@@ -1034,7 +1079,17 @@ function vinext(options = {}) {
|
|
|
1034
1079
|
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
|
|
1035
1080
|
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
|
|
1036
1081
|
const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1037
|
-
|
|
1082
|
+
const pagesPrefetchRoutes = hasPagesDir ? [...(await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
|
|
1083
|
+
canPrefetchLoadingShell: false,
|
|
1084
|
+
isDynamic: route.isDynamic,
|
|
1085
|
+
patternParts: [...route.patternParts]
|
|
1086
|
+
})), ...(await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
|
|
1087
|
+
canPrefetchLoadingShell: false,
|
|
1088
|
+
documentOnly: true,
|
|
1089
|
+
isDynamic: route.isDynamic,
|
|
1090
|
+
patternParts: [...route.patternParts]
|
|
1091
|
+
}))] : [];
|
|
1092
|
+
return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites);
|
|
1038
1093
|
}
|
|
1039
1094
|
if (id.startsWith("\0virtual:vinext-google-fonts?")) return generateGoogleFontsVirtualModule(id, _fontGoogleShimPath);
|
|
1040
1095
|
},
|
|
@@ -1241,11 +1296,65 @@ function vinext(options = {}) {
|
|
|
1241
1296
|
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1242
1297
|
}
|
|
1243
1298
|
}
|
|
1299
|
+
function invalidateHybridClientEntries() {
|
|
1300
|
+
if (!hasAppDir || !hasPagesDir) return;
|
|
1301
|
+
for (const env of Object.values(server.environments)) for (const id of [RESOLVED_CLIENT_ENTRY, RESOLVED_APP_BROWSER_ENTRY]) {
|
|
1302
|
+
const mod = env.moduleGraph.getModuleById(id);
|
|
1303
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1304
|
+
}
|
|
1305
|
+
server.ws.send({ type: "full-reload" });
|
|
1306
|
+
}
|
|
1307
|
+
function invalidatePagesServerEntry() {
|
|
1308
|
+
for (const env of Object.values(server.environments)) {
|
|
1309
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED_SERVER_ENTRY);
|
|
1310
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1311
|
+
}
|
|
1312
|
+
pagesRunner?.clearCache();
|
|
1313
|
+
}
|
|
1244
1314
|
function invalidateAppRoutingModules() {
|
|
1245
1315
|
invalidateAppRouteCache();
|
|
1246
1316
|
invalidateRscEntryModule();
|
|
1247
1317
|
invalidateRootParamsModule();
|
|
1248
1318
|
}
|
|
1319
|
+
let hybridRouteValidation = Promise.resolve();
|
|
1320
|
+
let hybridRouteValidationError = null;
|
|
1321
|
+
function sendHybridRouteValidationError(error) {
|
|
1322
|
+
server.ws.send({
|
|
1323
|
+
type: "error",
|
|
1324
|
+
err: {
|
|
1325
|
+
message: error.message,
|
|
1326
|
+
stack: error.stack ?? error.message
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
server.ws.on("connection", () => {
|
|
1331
|
+
if (hybridRouteValidationError) sendHybridRouteValidationError(hybridRouteValidationError);
|
|
1332
|
+
});
|
|
1333
|
+
function revalidateHybridRoutes() {
|
|
1334
|
+
if (!hasAppDir || !hasPagesDir) return;
|
|
1335
|
+
hybridRouteValidation = hybridRouteValidation.catch(() => {}).then(async () => {
|
|
1336
|
+
const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
|
|
1337
|
+
appRouter(appDir, nextConfig?.pageExtensions, fileMatcher),
|
|
1338
|
+
pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher),
|
|
1339
|
+
apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)
|
|
1340
|
+
]);
|
|
1341
|
+
validateHybridRouteConflicts([...pageRoutes, ...apiRoutes].map((route) => ({
|
|
1342
|
+
...route,
|
|
1343
|
+
sourcePath: path.relative(root, route.filePath)
|
|
1344
|
+
})), appRoutes.filter((route) => route.pagePath !== null || route.routePath !== null).map((route) => ({
|
|
1345
|
+
...route,
|
|
1346
|
+
sourcePath: path.relative(root, route.pagePath ?? route.routePath)
|
|
1347
|
+
})));
|
|
1348
|
+
if (hybridRouteValidationError) {
|
|
1349
|
+
hybridRouteValidationError = null;
|
|
1350
|
+
server.ws.send({ type: "full-reload" });
|
|
1351
|
+
}
|
|
1352
|
+
}).catch((error) => {
|
|
1353
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1354
|
+
hybridRouteValidationError = err;
|
|
1355
|
+
sendHybridRouteValidationError(err);
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1249
1358
|
let appRouteTypeGeneration = null;
|
|
1250
1359
|
let appRouteTypeGenerationPending = false;
|
|
1251
1360
|
function warnRouteTypeGenerationFailure(error) {
|
|
@@ -1270,21 +1379,42 @@ function vinext(options = {}) {
|
|
|
1270
1379
|
});
|
|
1271
1380
|
}
|
|
1272
1381
|
regenerateAppRouteTypes();
|
|
1382
|
+
revalidateHybridRoutes();
|
|
1273
1383
|
server.httpServer?.on("connection", (socket) => {
|
|
1274
1384
|
socket.on("error", () => {});
|
|
1275
1385
|
});
|
|
1276
1386
|
server.watcher.on("add", (filePath) => {
|
|
1277
|
-
|
|
1387
|
+
let routeChanged = false;
|
|
1388
|
+
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1389
|
+
invalidateRouteCache(pagesDir);
|
|
1390
|
+
routeChanged = true;
|
|
1391
|
+
}
|
|
1278
1392
|
if (hasAppDir && shouldInvalidateAppRouteFile(appDir, filePath, fileMatcher)) {
|
|
1279
1393
|
invalidateAppRoutingModules();
|
|
1280
1394
|
regenerateAppRouteTypes();
|
|
1395
|
+
routeChanged = true;
|
|
1396
|
+
}
|
|
1397
|
+
if (routeChanged) {
|
|
1398
|
+
invalidatePagesServerEntry();
|
|
1399
|
+
invalidateHybridClientEntries();
|
|
1400
|
+
revalidateHybridRoutes();
|
|
1281
1401
|
}
|
|
1282
1402
|
});
|
|
1283
1403
|
server.watcher.on("unlink", (filePath) => {
|
|
1284
|
-
|
|
1404
|
+
let routeChanged = false;
|
|
1405
|
+
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1406
|
+
invalidateRouteCache(pagesDir);
|
|
1407
|
+
routeChanged = true;
|
|
1408
|
+
}
|
|
1285
1409
|
if (hasAppDir && shouldInvalidateAppRouteFile(appDir, filePath, fileMatcher)) {
|
|
1286
1410
|
invalidateAppRoutingModules();
|
|
1287
1411
|
regenerateAppRouteTypes();
|
|
1412
|
+
routeChanged = true;
|
|
1413
|
+
}
|
|
1414
|
+
if (routeChanged) {
|
|
1415
|
+
invalidatePagesServerEntry();
|
|
1416
|
+
invalidateHybridClientEntries();
|
|
1417
|
+
revalidateHybridRoutes();
|
|
1288
1418
|
}
|
|
1289
1419
|
});
|
|
1290
1420
|
server.middlewares.use((req, res, next) => {
|
|
@@ -1361,6 +1491,7 @@ function vinext(options = {}) {
|
|
|
1361
1491
|
const handlePagesMiddleware = async (req, res, next) => {
|
|
1362
1492
|
try {
|
|
1363
1493
|
let url = req.url ?? "/";
|
|
1494
|
+
const originalRequestUrl = url;
|
|
1364
1495
|
if (!hasPagesDir) return next();
|
|
1365
1496
|
if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules")) return next();
|
|
1366
1497
|
if (url.split("?")[0].endsWith(".rsc")) return next();
|
|
@@ -1378,20 +1509,12 @@ function vinext(options = {}) {
|
|
|
1378
1509
|
return;
|
|
1379
1510
|
}
|
|
1380
1511
|
if (isImageOptimizationPath(url.split("?")[0])) {
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1383
|
-
if (!imgUrl || !imgUrl.startsWith("/") || imgUrl.startsWith("//") || imgUrl.startsWith("/@") || imgUrl.startsWith("/__vite") || imgUrl.startsWith("/node_modules")) {
|
|
1384
|
-
res.writeHead(400);
|
|
1385
|
-
res.end(!rawImgUrl ? "Missing url parameter" : "Only relative URLs allowed");
|
|
1386
|
-
return;
|
|
1387
|
-
}
|
|
1388
|
-
const resolvedImg = new URL(imgUrl, `http://${req.headers.host || "localhost"}`);
|
|
1389
|
-
if (resolvedImg.origin !== `http://${req.headers.host || "localhost"}`) {
|
|
1512
|
+
const encodedLocation = resolveDevImageRedirect(new URL(url, `http://${req.headers.host || "localhost"}`), [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES], nextConfig.images?.qualities);
|
|
1513
|
+
if (!encodedLocation) {
|
|
1390
1514
|
res.writeHead(400);
|
|
1391
|
-
res.end("
|
|
1515
|
+
res.end("Invalid image optimization parameters");
|
|
1392
1516
|
return;
|
|
1393
1517
|
}
|
|
1394
|
-
const encodedLocation = resolvedImg.pathname + resolvedImg.search;
|
|
1395
1518
|
res.writeHead(302, { Location: encodedLocation });
|
|
1396
1519
|
res.end();
|
|
1397
1520
|
return;
|
|
@@ -1444,14 +1567,17 @@ function vinext(options = {}) {
|
|
|
1444
1567
|
pathname = dataMatch.pagePathname;
|
|
1445
1568
|
req.url = url;
|
|
1446
1569
|
} else {
|
|
1447
|
-
|
|
1570
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
1571
|
+
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
1572
|
+
if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
1573
|
+
res.writeHead(404, notFoundHeaders);
|
|
1448
1574
|
res.end("{}");
|
|
1449
1575
|
return;
|
|
1450
1576
|
}
|
|
1451
1577
|
}
|
|
1452
1578
|
if (pathname.includes(".") && !pathname.endsWith(".html")) return next();
|
|
1453
1579
|
if (hasCloudflarePlugin) return next();
|
|
1454
|
-
const rawHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([, v]) => v !== void 0).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
|
|
1580
|
+
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)])));
|
|
1455
1581
|
const isDataRequest = rawHeaders.get("x-nextjs-data") === "1";
|
|
1456
1582
|
const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
|
|
1457
1583
|
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
@@ -1540,12 +1666,22 @@ function vinext(options = {}) {
|
|
|
1540
1666
|
};
|
|
1541
1667
|
if (pipelineResult.type === "api") {
|
|
1542
1668
|
const apiRoutes = await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1543
|
-
|
|
1669
|
+
const apiMatch = matchRoute(pipelineResult.apiUrl, apiRoutes);
|
|
1670
|
+
if (apiMatch && hasAppDir && appDir) {
|
|
1671
|
+
const appRoutes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1672
|
+
const appMatch = matchAppRoute(pipelineResult.apiUrl, appRoutes);
|
|
1673
|
+
if (appMatch && !pagesRouteHasPriorityOverAppRoute(apiMatch.route, appMatch.route)) return next();
|
|
1674
|
+
}
|
|
1675
|
+
if (apiMatch) {
|
|
1544
1676
|
flushStagedHeaders();
|
|
1545
1677
|
flushRequestHeaders();
|
|
1546
1678
|
if (pipelineResult.middlewareStatus !== void 0) req.__vinextMiddlewareStatus = pipelineResult.middlewareStatus;
|
|
1547
1679
|
}
|
|
1548
|
-
if (await handleApiRoute(getPagesRunner(), req, res, pipelineResult.apiUrl, apiRoutes
|
|
1680
|
+
if (await handleApiRoute(getPagesRunner(), req, res, pipelineResult.apiUrl, apiRoutes, {
|
|
1681
|
+
basePath: nextConfig?.basePath,
|
|
1682
|
+
i18n: nextConfig?.i18n,
|
|
1683
|
+
trailingSlash: nextConfig?.trailingSlash
|
|
1684
|
+
})) return;
|
|
1549
1685
|
if (hasAppDir) return next();
|
|
1550
1686
|
res.statusCode = 404;
|
|
1551
1687
|
res.end("404 - API route not found");
|
|
@@ -1553,13 +1689,19 @@ function vinext(options = {}) {
|
|
|
1553
1689
|
}
|
|
1554
1690
|
{
|
|
1555
1691
|
const routes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1556
|
-
|
|
1557
|
-
const
|
|
1692
|
+
const resolvedPathname = pipelineResult.resolvedUrl.split("#", 1)[0].split("?", 1)[0];
|
|
1693
|
+
const renderMatch = matchRoute(resolvedPathname, routes);
|
|
1694
|
+
if (hasAppDir && appDir) {
|
|
1695
|
+
if (!renderMatch) return next();
|
|
1696
|
+
const appMatch = matchAppRoute(resolvedPathname, await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher));
|
|
1697
|
+
if (appMatch && !pagesRouteHasPriorityOverAppRoute(renderMatch.route, appMatch.route)) return next();
|
|
1698
|
+
}
|
|
1699
|
+
const 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);
|
|
1558
1700
|
flushStagedHeaders();
|
|
1559
1701
|
flushRequestHeaders();
|
|
1560
1702
|
if (pipelineResult.middlewareStatus !== void 0) req.__vinextMiddlewareStatus = pipelineResult.middlewareStatus;
|
|
1561
1703
|
req.url = pipelineResult.resolvedUrl;
|
|
1562
|
-
await handler(req, res, pipelineResult.resolvedUrl, req.__vinextMiddlewareStatus, pipelineResult.isDataReq);
|
|
1704
|
+
await handler(req, res, pipelineResult.resolvedUrl, req.__vinextMiddlewareStatus, pipelineResult.isDataReq, originalRequestUrl);
|
|
1563
1705
|
}
|
|
1564
1706
|
} catch (e) {
|
|
1565
1707
|
next(e);
|
|
@@ -1581,6 +1723,7 @@ function vinext(options = {}) {
|
|
|
1581
1723
|
handler(code, id) {
|
|
1582
1724
|
if (this.environment?.name !== "client") return null;
|
|
1583
1725
|
if (id.startsWith("\0")) return null;
|
|
1726
|
+
if (getLeadingReactDirective(code) === "use server") return null;
|
|
1584
1727
|
if (!hasServerOnlyMarkerImport(code)) return null;
|
|
1585
1728
|
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.`);
|
|
1586
1729
|
}
|
|
@@ -1624,14 +1767,24 @@ function vinext(options = {}) {
|
|
|
1624
1767
|
}
|
|
1625
1768
|
}
|
|
1626
1769
|
},
|
|
1770
|
+
{
|
|
1771
|
+
name: "vinext:typeof-window",
|
|
1772
|
+
enforce: "post",
|
|
1773
|
+
transform: {
|
|
1774
|
+
filter: { code: /typeof\s+window/ },
|
|
1775
|
+
handler(code) {
|
|
1776
|
+
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
},
|
|
1627
1780
|
{
|
|
1628
1781
|
name: "vinext:compiler-define-server",
|
|
1629
1782
|
configEnvironment(name) {
|
|
1630
1783
|
if (name === "client") return null;
|
|
1631
1784
|
const serverDefines = { ...nextConfig.compilerDefineServer };
|
|
1785
|
+
serverDefines["process.env.NEXT_RUNTIME"] = JSON.stringify("nodejs");
|
|
1632
1786
|
const sharedRevalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
|
|
1633
1787
|
if (sharedRevalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(sharedRevalidateSecret);
|
|
1634
|
-
if (Object.keys(serverDefines).length === 0) return null;
|
|
1635
1788
|
return { define: serverDefines };
|
|
1636
1789
|
}
|
|
1637
1790
|
},
|
|
@@ -1721,6 +1874,7 @@ function vinext(options = {}) {
|
|
|
1721
1874
|
createGoogleFontsPlugin(_fontGoogleShimPath, _shimsDir),
|
|
1722
1875
|
createLocalFontsPlugin(_shimsDir),
|
|
1723
1876
|
createOptimizeImportsPlugin(() => nextConfig, () => root),
|
|
1877
|
+
createDynamicPreloadMetadataPlugin(),
|
|
1724
1878
|
{
|
|
1725
1879
|
name: "vinext:use-cache",
|
|
1726
1880
|
transform: {
|
|
@@ -1825,6 +1979,7 @@ function vinext(options = {}) {
|
|
|
1825
1979
|
}
|
|
1826
1980
|
},
|
|
1827
1981
|
createImportMetaUrlPlugin({ getRoot: () => root }),
|
|
1982
|
+
createExtensionlessDynamicImportPlugin(),
|
|
1828
1983
|
createRequireContextPlugin(),
|
|
1829
1984
|
createOgInlineFetchAssetsPlugin(),
|
|
1830
1985
|
createOgAssetsPlugin(),
|
|
@@ -1841,6 +1996,9 @@ function vinext(options = {}) {
|
|
|
1841
1996
|
const outDir = options.dir;
|
|
1842
1997
|
if (!outDir) return;
|
|
1843
1998
|
const imageConfig = {
|
|
1999
|
+
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
2000
|
+
imageSizes: nextConfig?.images?.imageSizes,
|
|
2001
|
+
qualities: nextConfig?.images?.qualities,
|
|
1844
2002
|
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
1845
2003
|
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
1846
2004
|
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
@@ -2057,22 +2215,15 @@ function vinext(options = {}) {
|
|
|
2057
2215
|
const distDir = path.resolve(buildRoot, "dist");
|
|
2058
2216
|
if (!fs.existsSync(distDir)) return;
|
|
2059
2217
|
const clientDir = path.resolve(buildRoot, "dist", "client");
|
|
2060
|
-
const
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
clientDir,
|
|
2070
|
-
assetsSubdir: resolveAssetsDir(nextConfig?.assetPrefix),
|
|
2071
|
-
assetBase: clientBase
|
|
2072
|
-
}) ?? null;
|
|
2073
|
-
const lazy = manifestFilesWithBase(computeLazyChunks(buildManifest), clientBase);
|
|
2074
|
-
if (lazy.length > 0) lazyChunksData = lazy;
|
|
2075
|
-
}
|
|
2218
|
+
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2219
|
+
clientDir,
|
|
2220
|
+
assetBase: envConfig.base ?? "/",
|
|
2221
|
+
assetPrefix: nextConfig.assetPrefix,
|
|
2222
|
+
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2223
|
+
});
|
|
2224
|
+
const lazyChunksData = runtimeMetadata.lazyChunks ?? null;
|
|
2225
|
+
const dynamicPreloadsData = runtimeMetadata.dynamicPreloads ?? null;
|
|
2226
|
+
let clientEntryFile = runtimeMetadata.clientEntryFile ?? null;
|
|
2076
2227
|
let ssrManifestData = null;
|
|
2077
2228
|
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2078
2229
|
if (fs.existsSync(ssrManifestPath)) try {
|
|
@@ -2080,19 +2231,17 @@ function vinext(options = {}) {
|
|
|
2080
2231
|
} catch {}
|
|
2081
2232
|
if (hasAppDir) {
|
|
2082
2233
|
const workerEntry = path.resolve(distDir, "server", "index.js");
|
|
2083
|
-
if (
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
code = globals.join("\n") + "\n" + code;
|
|
2095
|
-
fs.writeFileSync(workerEntry, code);
|
|
2234
|
+
if (fs.existsSync(workerEntry)) {
|
|
2235
|
+
const script = buildRuntimeGlobalsScript({
|
|
2236
|
+
clientEntryFile,
|
|
2237
|
+
ssrManifest: ssrManifestData,
|
|
2238
|
+
lazyChunks: lazyChunksData,
|
|
2239
|
+
dynamicPreloads: dynamicPreloadsData
|
|
2240
|
+
});
|
|
2241
|
+
if (script) {
|
|
2242
|
+
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2243
|
+
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2244
|
+
}
|
|
2096
2245
|
}
|
|
2097
2246
|
} else {
|
|
2098
2247
|
let workerOutDir = null;
|
|
@@ -2107,19 +2256,15 @@ function vinext(options = {}) {
|
|
|
2107
2256
|
if (!workerOutDir) return;
|
|
2108
2257
|
const workerEntry = path.join(workerOutDir, "index.js");
|
|
2109
2258
|
if (!fs.existsSync(workerEntry)) return;
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
const
|
|
2118
|
-
|
|
2119
|
-
if (ssrManifestData) globals.push(`globalThis.__VINEXT_SSR_MANIFEST__ = ${JSON.stringify(ssrManifestData)};`);
|
|
2120
|
-
if (lazyChunksData) globals.push(`globalThis.__VINEXT_LAZY_CHUNKS__ = ${JSON.stringify(lazyChunksData)};`);
|
|
2121
|
-
code = globals.join("\n") + "\n" + code;
|
|
2122
|
-
fs.writeFileSync(workerEntry, code);
|
|
2259
|
+
const script = buildRuntimeGlobalsScript({
|
|
2260
|
+
clientEntryFile,
|
|
2261
|
+
ssrManifest: ssrManifestData,
|
|
2262
|
+
lazyChunks: lazyChunksData,
|
|
2263
|
+
dynamicPreloads: dynamicPreloadsData
|
|
2264
|
+
});
|
|
2265
|
+
if (script) {
|
|
2266
|
+
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2267
|
+
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2123
2268
|
}
|
|
2124
2269
|
}
|
|
2125
2270
|
const headersPath = path.join(clientDir, "_headers");
|
|
@@ -2137,6 +2282,7 @@ function vinext(options = {}) {
|
|
|
2137
2282
|
}
|
|
2138
2283
|
}
|
|
2139
2284
|
},
|
|
2285
|
+
createWasmModuleImportPlugin(),
|
|
2140
2286
|
{
|
|
2141
2287
|
name: "vinext:og-font-patch",
|
|
2142
2288
|
enforce: "pre",
|