vinext 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -30
- package/dist/build/css-url-assets.d.ts +3 -1
- package/dist/build/css-url-assets.js +18 -1
- package/dist/build/inject-pregenerated-paths.d.ts +7 -0
- package/dist/build/inject-pregenerated-paths.js +21 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender-server-entry.d.ts +1 -0
- package/dist/build/prerender-server-entry.js +49 -0
- package/dist/build/prerender-server-pool.d.ts +44 -0
- package/dist/build/prerender-server-pool.js +194 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +98 -27
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +12 -2
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +4 -6
- package/dist/check.js +48 -11
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +112 -96
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/vinext-next-data.d.ts +4 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/config/config-matchers.js +45 -19
- package/dist/config/next-config.d.ts +41 -9
- package/dist/config/next-config.js +60 -3
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-browser-entry.js +5 -1
- package/dist/entries/app-rsc-entry.d.ts +5 -3
- package/dist/entries/app-rsc-entry.js +44 -10
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +28 -3
- package/dist/entries/pages-server-entry.js +23 -6
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +482 -120
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +209 -99
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +9 -2
- package/dist/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +272 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +44 -20
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/og-assets.js +2 -1
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
- package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
- package/dist/plugins/sass.d.ts +17 -1
- package/dist/plugins/sass.js +74 -1
- package/dist/plugins/styled-jsx.d.ts +16 -0
- package/dist/plugins/styled-jsx.js +149 -0
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +23 -2
- package/dist/routing/app-route-graph.js +138 -38
- package/dist/routing/file-matcher.d.ts +11 -1
- package/dist/routing/file-matcher.js +18 -3
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +198 -57
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +1 -1
- package/dist/server/app-browser-server-action-client.js +8 -7
- package/dist/server/app-browser-state.d.ts +12 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +42 -24
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +2 -1
- package/dist/server/app-fallback-renderer.js +10 -6
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +5 -4
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +27 -7
- package/dist/server/app-page-dispatch.d.ts +1 -0
- package/dist/server/app-page-dispatch.js +26 -8
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +59 -4
- package/dist/server/app-page-execution.js +2 -1
- package/dist/server/app-page-probe.js +5 -0
- package/dist/server/app-page-render-identity.d.ts +2 -0
- package/dist/server/app-page-render-identity.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +85 -16
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -4
- package/dist/server/app-page-response.d.ts +7 -0
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-route-wiring.d.ts +8 -1
- package/dist/server/app-page-route-wiring.js +32 -18
- package/dist/server/app-page-segment-state.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +7 -1
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-route-handler-execution.js +5 -1
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-tree-prefetch.d.ts +43 -0
- package/dist/server/app-route-tree-prefetch.js +187 -0
- package/dist/server/app-router-entry.js +9 -2
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +9 -4
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +148 -39
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.d.ts +6 -6
- package/dist/server/app-rsc-request-normalization.js +10 -8
- package/dist/server/app-segment-config.d.ts +11 -0
- package/dist/server/app-segment-config.js +62 -6
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +61 -30
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +13 -5
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/cache-control.d.ts +3 -1
- package/dist/server/cache-control.js +13 -1
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-route-files.js +4 -0
- package/dist/server/dev-server.d.ts +11 -1
- package/dist/server/dev-server.js +94 -35
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +11 -18
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +3 -2
- package/dist/server/isr-cache.js +9 -5
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-api-route.js +2 -2
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-data-route.d.ts +4 -2
- package/dist/server/pages-data-route.js +18 -4
- package/dist/server/pages-dev-module-url.d.ts +2 -1
- package/dist/server/pages-dev-module-url.js +6 -3
- package/dist/server/pages-node-compat.d.ts +19 -1
- package/dist/server/pages-node-compat.js +81 -4
- package/dist/server/pages-page-data.d.ts +33 -1
- package/dist/server/pages-page-data.js +62 -33
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +38 -19
- package/dist/server/pages-page-response.d.ts +8 -0
- package/dist/server/pages-page-response.js +7 -3
- package/dist/server/pages-request-pipeline.d.ts +9 -5
- package/dist/server/pages-request-pipeline.js +55 -7
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +5 -3
- package/dist/server/prod-server.js +68 -39
- package/dist/server/request-pipeline.js +2 -1
- package/dist/server/seed-cache.js +4 -4
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache-handler.js +8 -1
- package/dist/shims/cache.js +22 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +77 -52
- package/dist/shims/form.d.ts +4 -2
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +7 -1
- package/dist/shims/headers.js +17 -3
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
- package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +40 -58
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +10 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +84 -14
- package/dist/shims/internal/pages-data-target.d.ts +18 -12
- package/dist/shims/internal/pages-data-target.js +97 -13
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.d.ts +1 -1
- package/dist/shims/link.js +224 -58
- package/dist/shims/navigation.d.ts +19 -3
- package/dist/shims/navigation.js +245 -47
- package/dist/shims/request-context.js +18 -0
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +387 -102
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/typegen.js +1 -1
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +3 -3
- package/dist/utils/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- package/dist/utils/protocol-headers.d.ts +23 -0
- package/dist/utils/protocol-headers.js +23 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/dist/utils/vite-version.d.ts +2 -0
- package/dist/utils/vite-version.js +11 -1
- package/package.json +47 -2
- package/dist/deploy.d.ts +0 -197
- package/dist/deploy.js +0 -1040
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
package/dist/index.js
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
import { detectPackageManager } from "./utils/project.js";
|
|
1
|
+
import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
|
|
2
|
+
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
2
3
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
3
4
|
import { escapeRegExp } from "./utils/regex.js";
|
|
4
|
-
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
5
5
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
6
6
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
7
|
-
import {
|
|
7
|
+
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
8
|
+
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
8
9
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
9
10
|
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
10
11
|
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
11
12
|
import { filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
12
13
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
14
|
+
import { extractMiddlewareMatcherConfig, hasExportedName } from "./build/report.js";
|
|
13
15
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
14
16
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
15
17
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
16
18
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
17
19
|
import { isUnknownRecord } from "./utils/record.js";
|
|
18
20
|
import { logRequest, now } from "./server/request-log.js";
|
|
21
|
+
import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
|
|
22
|
+
import { isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
23
|
+
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
19
24
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
20
25
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
21
26
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
22
27
|
import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
|
|
23
|
-
import { scanMetadataFiles } from "./server/metadata-routes.js";
|
|
28
|
+
import { invalidateMetadataFileCache, scanMetadataFiles } from "./server/metadata-routes.js";
|
|
24
29
|
import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
|
|
25
30
|
import { createDirectRunner } from "./server/dev-module-runner.js";
|
|
26
31
|
import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
27
32
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
28
33
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
29
34
|
import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
35
|
+
import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
|
|
30
36
|
import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
|
|
31
37
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
32
38
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
33
39
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
34
|
-
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
35
40
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
36
41
|
import { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine } from "./utils/vite-version.js";
|
|
37
42
|
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
38
43
|
import { mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
39
|
-
import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
40
44
|
import { precompressAssets } from "./build/precompress.js";
|
|
41
45
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
42
46
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
@@ -49,8 +53,11 @@ import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
|
|
|
49
53
|
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
|
|
50
54
|
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
|
|
51
55
|
import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
|
|
56
|
+
import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
|
|
52
57
|
import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
|
|
58
|
+
import { createRscReferenceValidationNormalizerPlugin } from "./plugins/rsc-reference-validation-normalizer.js";
|
|
53
59
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
60
|
+
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
54
61
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
55
62
|
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
56
63
|
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
@@ -62,12 +69,12 @@ import { generateRouteTypes } from "./typegen.js";
|
|
|
62
69
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
63
70
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
64
71
|
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
72
|
+
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
73
|
+
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
67
74
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
68
|
-
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
|
|
69
|
-
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
70
75
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
76
|
+
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter } from "./plugins/sass.js";
|
|
77
|
+
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
71
78
|
import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
72
79
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
73
80
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
@@ -77,6 +84,8 @@ import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
|
77
84
|
import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeof-window.js";
|
|
78
85
|
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
79
86
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
87
|
+
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
88
|
+
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
80
89
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
81
90
|
import { createRequire } from "node:module";
|
|
82
91
|
import fs from "node:fs";
|
|
@@ -87,6 +96,18 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
|
87
96
|
import commonjs from "vite-plugin-commonjs";
|
|
88
97
|
import MagicString from "magic-string";
|
|
89
98
|
//#region src/index.ts
|
|
99
|
+
const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE = Object.freeze(["vinext/server/fetch-handler", "vinext/server/pages-router-entry"]);
|
|
100
|
+
const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
101
|
+
"react",
|
|
102
|
+
"react-dom",
|
|
103
|
+
"react-dom/server.edge",
|
|
104
|
+
"react/jsx-runtime",
|
|
105
|
+
"react/jsx-dev-runtime",
|
|
106
|
+
"use-sync-external-store/with-selector"
|
|
107
|
+
]);
|
|
108
|
+
const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-sync-external-store\/with-selector.*present in .* 'optimizeDeps\.include'/;
|
|
109
|
+
const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
|
|
110
|
+
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
90
111
|
installSocketErrorBackstop();
|
|
91
112
|
function getCacheDirPrefix(cacheDir) {
|
|
92
113
|
const normalizedCacheDir = normalizePathSeparators(cacheDir);
|
|
@@ -165,6 +186,122 @@ function isVinextOgShimImporter(importer) {
|
|
|
165
186
|
function toRelativeFileEntry(root, absPath) {
|
|
166
187
|
return path.relative(root, absPath).split(path.sep).join("/");
|
|
167
188
|
}
|
|
189
|
+
const DEV_PAGES_CLIENT_ENTRY = "/@id/__x00__virtual:vinext-client-entry";
|
|
190
|
+
const STYLESHEET_IMPORT_RE = /\.(?:css|scss|sass)$/i;
|
|
191
|
+
const STYLESHEET_FILE_RE = /\.(?:css|scss|sass)$/i;
|
|
192
|
+
const SCRIPT_IMPORT_RE = /\.(?:[cm]?[jt]sx?)$/i;
|
|
193
|
+
const GLOBAL_NOT_FOUND_CSS_QUERY = "?vinext-global-not-found-css";
|
|
194
|
+
function toMagicStringTransformResult(output) {
|
|
195
|
+
return {
|
|
196
|
+
code: output.toString(),
|
|
197
|
+
map: output.generateMap({ hires: "boundary" })
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function parserLanguageForScript(id) {
|
|
201
|
+
const cleanId = stripViteModuleQuery(id).toLowerCase();
|
|
202
|
+
return cleanId.endsWith(".ts") || cleanId.endsWith(".mts") || cleanId.endsWith(".cts") ? "ts" : "tsx";
|
|
203
|
+
}
|
|
204
|
+
function isStylesheetSpecifier(specifier) {
|
|
205
|
+
if (specifier.includes("?") || specifier.includes("#")) return false;
|
|
206
|
+
return STYLESHEET_IMPORT_RE.test(specifier.toLowerCase());
|
|
207
|
+
}
|
|
208
|
+
function isMdxModuleId(id) {
|
|
209
|
+
return stripViteModuleQuery(id).toLowerCase().endsWith(".mdx");
|
|
210
|
+
}
|
|
211
|
+
function isolateMdxStylesheetImports(code) {
|
|
212
|
+
const importRe = /(^|[;\n])(\s*import\s*)(["'])([^"'\n;]+)(\3)/g;
|
|
213
|
+
let output = null;
|
|
214
|
+
for (const match of code.matchAll(importRe)) {
|
|
215
|
+
const specifier = match[4];
|
|
216
|
+
if (!isStylesheetSpecifier(specifier)) continue;
|
|
217
|
+
const specifierStart = match.index + match[1].length + match[2].length + match[3].length;
|
|
218
|
+
const specifierEnd = specifierStart + specifier.length;
|
|
219
|
+
output ??= new MagicString(code);
|
|
220
|
+
output.overwrite(specifierStart, specifierEnd, specifier + GLOBAL_NOT_FOUND_CSS_QUERY);
|
|
221
|
+
}
|
|
222
|
+
return output ? toMagicStringTransformResult(output) : null;
|
|
223
|
+
}
|
|
224
|
+
function isolateGlobalNotFoundStylesheetImports(code, id) {
|
|
225
|
+
if (isMdxModuleId(id)) return isolateMdxStylesheetImports(code);
|
|
226
|
+
let ast;
|
|
227
|
+
try {
|
|
228
|
+
ast = parseAst(code, { lang: parserLanguageForScript(id) });
|
|
229
|
+
} catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
let output = null;
|
|
233
|
+
for (const statement of ast.body) {
|
|
234
|
+
if (statement.type !== "ImportDeclaration" || statement.importKind === "type") continue;
|
|
235
|
+
if (statement.specifiers && statement.specifiers.length > 0) continue;
|
|
236
|
+
if (statement.attributes && statement.attributes.length > 0) continue;
|
|
237
|
+
const source = statement.source;
|
|
238
|
+
const specifier = source?.value;
|
|
239
|
+
if (typeof specifier !== "string" || !isStylesheetSpecifier(specifier)) continue;
|
|
240
|
+
const range = source;
|
|
241
|
+
if (typeof range.start !== "number" || typeof range.end !== "number") continue;
|
|
242
|
+
output ??= new MagicString(code);
|
|
243
|
+
output.overwrite(range.start, range.end, JSON.stringify(specifier + GLOBAL_NOT_FOUND_CSS_QUERY));
|
|
244
|
+
}
|
|
245
|
+
return output ? toMagicStringTransformResult(output) : null;
|
|
246
|
+
}
|
|
247
|
+
function isScriptModuleId(id) {
|
|
248
|
+
return SCRIPT_IMPORT_RE.test(stripViteModuleQuery(id).toLowerCase());
|
|
249
|
+
}
|
|
250
|
+
function skipCommonjsForLocalCjs(id) {
|
|
251
|
+
const cleanId = normalizePathSeparators(stripViteModuleQuery(id));
|
|
252
|
+
return /\.c[jt]s$/i.test(cleanId) && !cleanId.includes("node_modules") ? false : void 0;
|
|
253
|
+
}
|
|
254
|
+
function hasOnlyTypeSpecifiers(statement) {
|
|
255
|
+
return statement.specifiers !== void 0 && statement.specifiers.length > 0 && statement.specifiers.every((specifier) => specifier.importKind === "type" || specifier.exportKind === "type");
|
|
256
|
+
}
|
|
257
|
+
function resolvedStylesheetToDevManifestAsset(root, resolvedId) {
|
|
258
|
+
const cleanId = stripViteModuleQuery(resolvedId);
|
|
259
|
+
if (!path.isAbsolute(cleanId)) return null;
|
|
260
|
+
const rootForRelative = tryRealpathSync(root) ?? root;
|
|
261
|
+
const fileForRelative = tryRealpathSync(cleanId) ?? cleanId;
|
|
262
|
+
const relativePath = path.relative(rootForRelative, fileForRelative);
|
|
263
|
+
if (relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath)) return normalizePathSeparators(relativePath);
|
|
264
|
+
return `@fs/${normalizePathSeparators(cleanId).replace(/^\/+/, "")}`;
|
|
265
|
+
}
|
|
266
|
+
async function collectDevPagesAppStylesheetAssets(root, appFilePath, resolve) {
|
|
267
|
+
const stylesheetAssets = [];
|
|
268
|
+
const seenAssets = /* @__PURE__ */ new Set();
|
|
269
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
270
|
+
async function visitModule(modulePath) {
|
|
271
|
+
const cleanModulePath = stripViteModuleQuery(modulePath);
|
|
272
|
+
if (!path.isAbsolute(cleanModulePath) || !fs.existsSync(cleanModulePath)) return;
|
|
273
|
+
if (seenModules.has(cleanModulePath)) return;
|
|
274
|
+
seenModules.add(cleanModulePath);
|
|
275
|
+
let ast;
|
|
276
|
+
try {
|
|
277
|
+
ast = parseAst(fs.readFileSync(cleanModulePath, "utf-8"), { lang: parserLanguageForScript(cleanModulePath) });
|
|
278
|
+
} catch {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
for (const statement of ast.body) {
|
|
282
|
+
if (statement.type !== "ImportDeclaration" && statement.type !== "ExportNamedDeclaration" && statement.type !== "ExportAllDeclaration") continue;
|
|
283
|
+
if (statement.importKind === "type") continue;
|
|
284
|
+
if (statement.exportKind === "type") continue;
|
|
285
|
+
if (hasOnlyTypeSpecifiers(statement)) continue;
|
|
286
|
+
if (statement.attributes && statement.attributes.length > 0) continue;
|
|
287
|
+
const specifier = statement.source?.value;
|
|
288
|
+
if (typeof specifier !== "string") continue;
|
|
289
|
+
const resolved = await resolve(specifier, cleanModulePath, { skipSelf: true });
|
|
290
|
+
if (!resolved?.id) continue;
|
|
291
|
+
if (isStylesheetSpecifier(specifier)) {
|
|
292
|
+
const asset = resolvedStylesheetToDevManifestAsset(root, resolved.id);
|
|
293
|
+
if (!asset || seenAssets.has(asset)) continue;
|
|
294
|
+
seenAssets.add(asset);
|
|
295
|
+
stylesheetAssets.push(asset);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (specifier.includes("?") || specifier.includes("#")) continue;
|
|
299
|
+
if (isScriptModuleId(resolved.id)) await visitModule(resolved.id);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
await visitModule(appFilePath);
|
|
303
|
+
return stylesheetAssets;
|
|
304
|
+
}
|
|
168
305
|
const TSCONFIG_FILES = ["tsconfig.json", "jsconfig.json"];
|
|
169
306
|
function resolveTsconfigPathCandidate(candidate) {
|
|
170
307
|
const candidates = candidate.endsWith(".json") ? [candidate] : [
|
|
@@ -235,6 +372,20 @@ function toViteAliasReplacement(absolutePath, projectRoot) {
|
|
|
235
372
|
}
|
|
236
373
|
return normalizedPath;
|
|
237
374
|
}
|
|
375
|
+
function resolveSwcHelpersAlias(root) {
|
|
376
|
+
const rootRequire = createRequire(path.join(root, "package.json"));
|
|
377
|
+
const resolvers = [];
|
|
378
|
+
try {
|
|
379
|
+
const nextPackageJson = rootRequire.resolve("next/package.json");
|
|
380
|
+
const realNextPackageJson = tryRealpathSync(nextPackageJson) ?? nextPackageJson;
|
|
381
|
+
resolvers.push(createRequire(realNextPackageJson));
|
|
382
|
+
} catch {}
|
|
383
|
+
resolvers.push(rootRequire, createRequire(import.meta.url));
|
|
384
|
+
for (const resolver of resolvers) try {
|
|
385
|
+
const packageJsonPath = resolver.resolve("@swc/helpers/package.json");
|
|
386
|
+
return normalizePathSeparators(path.join(path.dirname(packageJsonPath), "_"));
|
|
387
|
+
} catch {}
|
|
388
|
+
}
|
|
238
389
|
function loadTsconfigPathAliases(configPath, projectRoot, seen = /* @__PURE__ */ new Set()) {
|
|
239
390
|
const normalizedPath = tryRealpathSync(configPath) ?? configPath;
|
|
240
391
|
if (seen.has(normalizedPath)) return {};
|
|
@@ -285,6 +436,22 @@ function getVinextVersion() {
|
|
|
285
436
|
}
|
|
286
437
|
return _vinextVersionCache;
|
|
287
438
|
}
|
|
439
|
+
function mergeStringArrayValues(value, additions) {
|
|
440
|
+
return [...new Set([...value === void 0 ? [] : Array.isArray(value) ? value : [value], ...additions])];
|
|
441
|
+
}
|
|
442
|
+
function stripAnsi(value) {
|
|
443
|
+
return value.replace(ANSI_ESCAPE_RE, "");
|
|
444
|
+
}
|
|
445
|
+
function suppressOptionalOptimizeDepsWarnings(logger) {
|
|
446
|
+
const marker = logger;
|
|
447
|
+
if (marker[VINEXT_FILTERED_OPTIMIZE_DEPS_WARN]) return;
|
|
448
|
+
const warn = logger.warn.bind(logger);
|
|
449
|
+
logger.warn = (msg, options) => {
|
|
450
|
+
if (OPTIONAL_OPTIMIZE_DEPS_WARNING_RE.test(stripAnsi(msg))) return;
|
|
451
|
+
warn(msg, options);
|
|
452
|
+
};
|
|
453
|
+
marker[VINEXT_FILTERED_OPTIMIZE_DEPS_WARN] = true;
|
|
454
|
+
}
|
|
288
455
|
const _tsconfigAliasCache = /* @__PURE__ */ new Map();
|
|
289
456
|
function resolveTsconfigAliases(projectRoot) {
|
|
290
457
|
if (_tsconfigAliasCache.has(projectRoot)) return _tsconfigAliasCache.get(projectRoot);
|
|
@@ -298,10 +465,14 @@ function resolveTsconfigAliases(projectRoot) {
|
|
|
298
465
|
_tsconfigAliasCache.set(projectRoot, aliases);
|
|
299
466
|
return aliases;
|
|
300
467
|
}
|
|
468
|
+
const VIRTUAL_WORKER_ENTRY = "virtual:vinext-worker-entry";
|
|
469
|
+
const RESOLVED_WORKER_ENTRY = "\0virtual:vinext-worker-entry";
|
|
301
470
|
const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
|
|
302
471
|
const RESOLVED_SERVER_ENTRY = "\0virtual:vinext-server-entry";
|
|
303
472
|
const VIRTUAL_CLIENT_ENTRY = "virtual:vinext-client-entry";
|
|
304
473
|
const RESOLVED_CLIENT_ENTRY = "\0virtual:vinext-client-entry";
|
|
474
|
+
const VIRTUAL_PAGES_CLIENT_ASSETS = "virtual:vinext-pages-client-assets";
|
|
475
|
+
const RESOLVED_PAGES_CLIENT_ASSETS = "\0virtual:vinext-pages-client-assets";
|
|
305
476
|
const VIRTUAL_RSC_ENTRY = "virtual:vinext-rsc-entry";
|
|
306
477
|
const RESOLVED_RSC_ENTRY = "\0virtual:vinext-rsc-entry";
|
|
307
478
|
const VIRTUAL_APP_SSR_ENTRY = "virtual:vinext-app-ssr-entry";
|
|
@@ -313,6 +484,8 @@ const RESOLVED_APP_CAPABILITIES = "\0virtual:vinext-app-capabilities";
|
|
|
313
484
|
const RESOLVED_ROOT_PARAMS = "\0virtual:vinext-root-params";
|
|
314
485
|
/** Virtual module that registers config-driven cache adapters (see VinextOptions.cache). */
|
|
315
486
|
const RESOLVED_CACHE_ADAPTERS = "\0" + VIRTUAL_CACHE_ADAPTERS;
|
|
487
|
+
/** Virtual module that registers the config-driven image optimizer (see VinextOptions.images). */
|
|
488
|
+
const RESOLVED_IMAGE_ADAPTERS = "\0" + VIRTUAL_IMAGE_ADAPTERS;
|
|
316
489
|
/** Virtual module for composed instrumentation-client bootstrap. */
|
|
317
490
|
const VIRTUAL_INSTRUMENTATION_CLIENT = "private-next-instrumentation-client";
|
|
318
491
|
const RESOLVED_INSTRUMENTATION_CLIENT = `${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs`;
|
|
@@ -338,9 +511,11 @@ function createStaticImageAsset(imagePath) {
|
|
|
338
511
|
* the `id.startsWith(_shimsDir)` checks would never match.
|
|
339
512
|
*/
|
|
340
513
|
const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
|
|
514
|
+
const _serverDir = normalizePathSeparators(path.resolve(__dirname, "server"));
|
|
341
515
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
342
|
-
const _appBrowserServerActionClientPath = resolveShimModulePath(
|
|
343
|
-
const _appRscHandlerPath = resolveShimModulePath(
|
|
516
|
+
const _appBrowserServerActionClientPath = resolveShimModulePath(_serverDir, "app-browser-server-action-client");
|
|
517
|
+
const _appRscHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-handler");
|
|
518
|
+
const _pagesClientAssetsPath = resolveShimModulePath(_serverDir, "pages-client-assets");
|
|
344
519
|
const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js");
|
|
345
520
|
function isValidExportIdentifier(name) {
|
|
346
521
|
return /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
@@ -440,6 +615,7 @@ function getClientOutputConfigForVite(viteMajorVersion, assetsDir, preserveAppRo
|
|
|
440
615
|
} : createClientOutputConfig(manualChunks, assetsDir);
|
|
441
616
|
}
|
|
442
617
|
function vinext(options = {}) {
|
|
618
|
+
const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
|
|
443
619
|
const viteMajorVersion = getViteMajorVersion();
|
|
444
620
|
let root;
|
|
445
621
|
let pagesDir;
|
|
@@ -453,10 +629,15 @@ function vinext(options = {}) {
|
|
|
453
629
|
let instrumentationPath = null;
|
|
454
630
|
let instrumentationClientPath = null;
|
|
455
631
|
let clientInjectModule = null;
|
|
632
|
+
let globalNotFoundCssIsolationPath = null;
|
|
456
633
|
let clientAssetsInlineLimit = 0;
|
|
457
634
|
let hasCloudflarePlugin = false;
|
|
458
635
|
let warnedInlineNextConfigOverride = false;
|
|
459
636
|
let hasNitroPlugin = false;
|
|
637
|
+
let isServeCommand = false;
|
|
638
|
+
let pagesOptimizeEntries = [];
|
|
639
|
+
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
640
|
+
let pagesClientAssetsModule = null;
|
|
460
641
|
let rscCompatibilityId;
|
|
461
642
|
const draftModeSecret = randomUUID();
|
|
462
643
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
@@ -502,7 +683,9 @@ function vinext(options = {}) {
|
|
|
502
683
|
const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => isLinkPrefetchRoute(route) ? toLinkPrefetchRoute(route) : toDocumentOnlyAppRoute(route)) : [];
|
|
503
684
|
return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
|
|
504
685
|
appPrefetchRoutes,
|
|
505
|
-
instrumentationClientPath
|
|
686
|
+
instrumentationClientPath,
|
|
687
|
+
middlewareMatcher: middlewarePath ? extractMiddlewareMatcherConfig(middlewarePath) : void 0,
|
|
688
|
+
reactPreamble: options.react !== false
|
|
506
689
|
});
|
|
507
690
|
}
|
|
508
691
|
async function writeRouteTypes() {
|
|
@@ -592,8 +775,26 @@ function vinext(options = {}) {
|
|
|
592
775
|
}
|
|
593
776
|
const plugins = [
|
|
594
777
|
...viteMajorVersion >= 8 ? [] : [loadVite7TsconfigPathsPlugin(earlyBaseDir)],
|
|
778
|
+
createStyledJsxPlugin(earlyBaseDir),
|
|
595
779
|
reactPluginPromise,
|
|
596
|
-
|
|
780
|
+
createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
781
|
+
commonjs({ filter: skipCommonjsForLocalCjs }),
|
|
782
|
+
{
|
|
783
|
+
name: "vinext:global-not-found-css-isolation",
|
|
784
|
+
apply: "build",
|
|
785
|
+
enforce: "pre",
|
|
786
|
+
transform: {
|
|
787
|
+
filter: {
|
|
788
|
+
id: /(?:^|[/\\])global-not-found(?:\.[^./?\\]+)+(?:\?.*)?$/,
|
|
789
|
+
code: /\.(?:css|scss|sass)['"]/
|
|
790
|
+
},
|
|
791
|
+
handler(code, id) {
|
|
792
|
+
const cleanId = normalizePathSeparators(stripViteModuleQuery(id));
|
|
793
|
+
if (!globalNotFoundCssIsolationPath || canonicalize(cleanId) !== canonicalize(globalNotFoundCssIsolationPath)) return null;
|
|
794
|
+
return isolateGlobalNotFoundStylesheetImports(code, cleanId);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
},
|
|
597
798
|
...viteMajorVersion >= 8 ? [{
|
|
598
799
|
name: "vinext:jsx-in-js",
|
|
599
800
|
enforce: "pre",
|
|
@@ -628,14 +829,18 @@ function vinext(options = {}) {
|
|
|
628
829
|
serverOnlyShimPath: resolveShimModulePath(shimsDir, "server-only")
|
|
629
830
|
}),
|
|
630
831
|
dataUrlCssPlugin(),
|
|
832
|
+
createCssModuleImportCompatibilityPlugin(),
|
|
631
833
|
{
|
|
632
834
|
name: "vinext:config",
|
|
633
835
|
enforce: "pre",
|
|
836
|
+
[VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY]: prerenderConfig,
|
|
634
837
|
async config(config, env) {
|
|
838
|
+
isServeCommand = env.command === "serve";
|
|
635
839
|
root = normalizePathSeparators(config.root ?? process.cwd());
|
|
636
840
|
const userResolve = config.resolve;
|
|
637
841
|
const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === void 0;
|
|
638
842
|
const tsconfigPathAliases = resolveTsconfigAliases(root);
|
|
843
|
+
const swcHelpersAlias = resolveSwcHelpersAlias(root);
|
|
639
844
|
const mode = env?.mode ?? "development";
|
|
640
845
|
const dotenvVars = loadEnv(mode, config.envDir ?? root, "");
|
|
641
846
|
for (const [key, value] of Object.entries(dotenvVars)) if (process.env[key] === void 0) process.env[key] = value;
|
|
@@ -683,6 +888,7 @@ function vinext(options = {}) {
|
|
|
683
888
|
rscCompatibilityId = sharedRscCompatibilityId && sharedRscCompatibilityId.length > 0 ? sharedRscCompatibilityId : createRscCompatibilityId(nextConfig);
|
|
684
889
|
}
|
|
685
890
|
fileMatcher = createValidFileMatcher(nextConfig.pageExtensions);
|
|
891
|
+
globalNotFoundCssIsolationPath = env?.command === "build" && nextConfig.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
686
892
|
instrumentationPath = findInstrumentationFile(root, fileMatcher);
|
|
687
893
|
instrumentationClientPath = findInstrumentationClientFile(root, fileMatcher);
|
|
688
894
|
const middlewareConventionDir = canonicalize(baseDir) === canonicalize(path.posix.join(root, "src")) ? path.posix.join(root, "src") : root;
|
|
@@ -701,6 +907,7 @@ function vinext(options = {}) {
|
|
|
701
907
|
}
|
|
702
908
|
defines["process.env.__NEXT_ROUTER_BASEPATH"] = JSON.stringify(nextConfig.basePath);
|
|
703
909
|
defines["process.env.__VINEXT_HAS_PAGES_ROUTER"] = JSON.stringify(String(hasPagesDir));
|
|
910
|
+
defines["process.env.__NEXT_CLIENT_ROUTER_DYNAMIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.dynamic));
|
|
704
911
|
defines["process.env.__NEXT_CLIENT_ROUTER_STATIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.static));
|
|
705
912
|
defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
|
|
706
913
|
defines["process.env.__NEXT_GESTURE_TRANSITION"] = JSON.stringify(nextConfig.gestureTransition);
|
|
@@ -736,6 +943,7 @@ function vinext(options = {}) {
|
|
|
736
943
|
}
|
|
737
944
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowSVG ?? false));
|
|
738
945
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
|
|
946
|
+
defines["process.env.__VINEXT_IMAGE_UNOPTIMIZED"] = JSON.stringify(String(nextConfig.images?.unoptimized === true));
|
|
739
947
|
defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
|
|
740
948
|
defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
|
|
741
949
|
defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
|
|
@@ -802,7 +1010,7 @@ function vinext(options = {}) {
|
|
|
802
1010
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
803
1011
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
804
1012
|
"vinext/instrumentation-client": path.resolve(__dirname, "client", "instrumentation-client"),
|
|
805
|
-
"vinext/dev-error-overlay": path.resolve(__dirname, "
|
|
1013
|
+
"vinext/dev-error-overlay": path.resolve(__dirname, "client", "dev-error-overlay"),
|
|
806
1014
|
"vinext/html": path.resolve(__dirname, "server", "html"),
|
|
807
1015
|
...clientInjectModule === null ? { "private-next-instrumentation-client": instrumentationClientPath ?? INSTRUMENTATION_CLIENT_EMPTY_MODULE } : {}
|
|
808
1016
|
}).flatMap(([k, v]) => k.startsWith("next/") ? [[k, v], [`${k}.js`, v]] : [[k, v]]));
|
|
@@ -820,7 +1028,8 @@ function vinext(options = {}) {
|
|
|
820
1028
|
hasUserMdxPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "@mdx-js/rollup" || p.name === "mdx"));
|
|
821
1029
|
if (!hasUserMdxPlugin && hasMdxFiles(root, hasAppDir ? appDir : null, hasPagesDir ? pagesDir : null)) await ensureMdxDelegate("detected");
|
|
822
1030
|
const isSSR = !!config.build?.ssr;
|
|
823
|
-
const
|
|
1031
|
+
const serverTranspilePackages = [...nextConfig?.turbopackTranspilePackages ?? [], ...nextConfig?.optimizePackageImports ?? []];
|
|
1032
|
+
const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages);
|
|
824
1033
|
const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
|
|
825
1034
|
const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
|
|
826
1035
|
const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
|
|
@@ -879,9 +1088,11 @@ function vinext(options = {}) {
|
|
|
879
1088
|
} },
|
|
880
1089
|
resolve: {
|
|
881
1090
|
alias: {
|
|
1091
|
+
...swcHelpersAlias ? { "@swc/helpers/_": swcHelpersAlias } : {},
|
|
882
1092
|
...tsconfigPathAliases,
|
|
883
1093
|
...nextConfig.aliases,
|
|
884
|
-
...nextShimMap
|
|
1094
|
+
...nextShimMap,
|
|
1095
|
+
"vinext/server/pages-client-assets": _pagesClientAssetsPath
|
|
885
1096
|
},
|
|
886
1097
|
dedupe: [
|
|
887
1098
|
"react",
|
|
@@ -891,7 +1102,13 @@ function vinext(options = {}) {
|
|
|
891
1102
|
],
|
|
892
1103
|
...shouldEnableNativeTsconfigPaths ? { tsconfigPaths: true } : {}
|
|
893
1104
|
},
|
|
894
|
-
...viteMajorVersion >= 8 ? { oxc: {
|
|
1105
|
+
...viteMajorVersion >= 8 ? { oxc: {
|
|
1106
|
+
jsx: { runtime: "automatic" },
|
|
1107
|
+
typescript: { onlyRemoveTypeImports: false }
|
|
1108
|
+
} } : { esbuild: {
|
|
1109
|
+
jsx: "automatic",
|
|
1110
|
+
tsconfigRaw: { compilerOptions: { verbatimModuleSyntax: false } }
|
|
1111
|
+
} },
|
|
895
1112
|
define: defines,
|
|
896
1113
|
...nextConfig.basePath ? { base: nextConfig.basePath + "/" } : {},
|
|
897
1114
|
...nextConfig.assetPrefix || nextConfig.deploymentId ? { experimental: { renderBuiltUrl: (filename, context) => renderVinextBuiltUrl(filename, nextConfig.assetPrefix, nextConfig.deploymentId, context.hostType) } } : {},
|
|
@@ -906,9 +1123,19 @@ function vinext(options = {}) {
|
|
|
906
1123
|
...postcssOverride ? { postcss: postcssOverride } : {},
|
|
907
1124
|
preprocessorOptions: (() => {
|
|
908
1125
|
const tildeImporter = createSassTildeImporter(root);
|
|
1126
|
+
const cssUrlAssetImporter = env.command === "build" ? createSassCssUrlAssetImporter() : null;
|
|
1127
|
+
const userAdditionalData = sassPreprocessorOptions?.additionalData;
|
|
909
1128
|
const baseOpts = {
|
|
910
1129
|
...sassPreprocessorOptions,
|
|
911
|
-
|
|
1130
|
+
...cssUrlAssetImporter ? { additionalData: async (source, filename) => {
|
|
1131
|
+
const withUserData = typeof userAdditionalData === "function" ? await userAdditionalData(source, filename) : typeof userAdditionalData === "string" ? `${userAdditionalData}${source}` : source;
|
|
1132
|
+
return cssUrlAssetImporter.rewriteImports(withUserData, filename);
|
|
1133
|
+
} } : {},
|
|
1134
|
+
importers: [
|
|
1135
|
+
tildeImporter,
|
|
1136
|
+
...cssUrlAssetImporter ? [cssUrlAssetImporter] : [],
|
|
1137
|
+
...sassPreprocessorOptions?.importers ?? []
|
|
1138
|
+
]
|
|
912
1139
|
};
|
|
913
1140
|
return {
|
|
914
1141
|
scss: baseOpts,
|
|
@@ -939,7 +1166,7 @@ function vinext(options = {}) {
|
|
|
939
1166
|
plugins: [depOptimizeAliasPlugin]
|
|
940
1167
|
}
|
|
941
1168
|
};
|
|
942
|
-
|
|
1169
|
+
pagesOptimizeEntries = !hasAppDir ? [...hasPagesDir ? [toRelativeFileEntry(root, pagesDir) + "/**/*.{tsx,ts,jsx,js}"] : [], ...[instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : [])] : [];
|
|
943
1170
|
if (hasAppDir) {
|
|
944
1171
|
const appEntries = [`${path.relative(root, appDir)}/**/*.{tsx,ts,jsx,js}`];
|
|
945
1172
|
const explicitInstrumentationEntries = [instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : []);
|
|
@@ -1003,7 +1230,8 @@ function vinext(options = {}) {
|
|
|
1003
1230
|
"react-dom/client",
|
|
1004
1231
|
"react/jsx-runtime",
|
|
1005
1232
|
"react/jsx-dev-runtime"
|
|
1006
|
-
])]
|
|
1233
|
+
])],
|
|
1234
|
+
...depOptimizeNodeEnvOptions
|
|
1007
1235
|
},
|
|
1008
1236
|
build: {
|
|
1009
1237
|
manifest: true,
|
|
@@ -1019,7 +1247,10 @@ function vinext(options = {}) {
|
|
|
1019
1247
|
};
|
|
1020
1248
|
} else if (hasCloudflarePlugin) viteConfig.environments = { client: {
|
|
1021
1249
|
consumer: "client",
|
|
1022
|
-
optimizeDeps:
|
|
1250
|
+
optimizeDeps: {
|
|
1251
|
+
...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
|
|
1252
|
+
...depOptimizeNodeEnvOptions
|
|
1253
|
+
},
|
|
1023
1254
|
build: {
|
|
1024
1255
|
manifest: true,
|
|
1025
1256
|
ssrManifest: true,
|
|
@@ -1034,7 +1265,10 @@ function vinext(options = {}) {
|
|
|
1034
1265
|
else if (shouldInjectPlainPagesEnvironments) viteConfig.environments = {
|
|
1035
1266
|
client: {
|
|
1036
1267
|
consumer: "client",
|
|
1037
|
-
optimizeDeps:
|
|
1268
|
+
optimizeDeps: {
|
|
1269
|
+
...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
|
|
1270
|
+
...depOptimizeNodeEnvOptions
|
|
1271
|
+
},
|
|
1038
1272
|
build: {
|
|
1039
1273
|
outDir: "dist/client",
|
|
1040
1274
|
manifest: true,
|
|
@@ -1078,6 +1312,12 @@ function vinext(options = {}) {
|
|
|
1078
1312
|
return viteConfig;
|
|
1079
1313
|
},
|
|
1080
1314
|
configEnvironment(name, config) {
|
|
1315
|
+
if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir && name !== "client") {
|
|
1316
|
+
config.optimizeDeps ??= {};
|
|
1317
|
+
config.optimizeDeps.entries = mergeStringArrayValues(config.optimizeDeps.entries, pagesOptimizeEntries);
|
|
1318
|
+
config.optimizeDeps.include = mergeStringArrayValues(config.optimizeDeps.include, PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE);
|
|
1319
|
+
config.optimizeDeps.exclude = mergeOptimizeDepsExclude(config.optimizeDeps.exclude ?? [], VINEXT_OPTIMIZE_DEPS_EXCLUDE, PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE);
|
|
1320
|
+
}
|
|
1081
1321
|
const configuredExtensions = name === "client" ? nextConfig.resolveExtensions : nextConfig.serverResolveExtensions;
|
|
1082
1322
|
const extensions = configuredExtensions === null ? buildViteResolveExtensions(nextConfig.pageExtensions, config.resolve?.extensions) : normalizeViteResolveExtensions(configuredExtensions);
|
|
1083
1323
|
config.resolve ??= {};
|
|
@@ -1087,6 +1327,7 @@ function vinext(options = {}) {
|
|
|
1087
1327
|
async configResolved(config) {
|
|
1088
1328
|
const cacheDirPrefix = getCacheDirPrefix(config.cacheDir);
|
|
1089
1329
|
typeofWindowIdFilter.exclude = new RegExp(`^${escapeRegExp(cacheDirPrefix)}`);
|
|
1330
|
+
if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir) suppressOptionalOptimizeDepsWarnings(config.logger);
|
|
1090
1331
|
sassComposesLoader.setResolvedConfig(config);
|
|
1091
1332
|
if (config.command === "build" && hasAppDir && hasPagesDir) {
|
|
1092
1333
|
const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
|
|
@@ -1135,6 +1376,8 @@ function vinext(options = {}) {
|
|
|
1135
1376
|
}
|
|
1136
1377
|
if (isVercelOgImport(cleanId) && !isVinextOgShimImporter(importer)) return resolveShimModulePath(_shimsDir, "og");
|
|
1137
1378
|
if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
|
|
1379
|
+
if (cleanId === VIRTUAL_WORKER_ENTRY) return RESOLVED_WORKER_ENTRY;
|
|
1380
|
+
if (cleanId.endsWith("/virtual:vinext-worker-entry")) return RESOLVED_WORKER_ENTRY;
|
|
1138
1381
|
if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
|
|
1139
1382
|
if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
|
|
1140
1383
|
if (cleanId.endsWith("/virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
|
|
@@ -1145,6 +1388,7 @@ function vinext(options = {}) {
|
|
|
1145
1388
|
if (cleanId === VIRTUAL_APP_CAPABILITIES) return RESOLVED_APP_CAPABILITIES;
|
|
1146
1389
|
if (cleanId === "next/root-params" || cleanId === "next/root-params.js") return RESOLVED_ROOT_PARAMS;
|
|
1147
1390
|
if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters")) return RESOLVED_CACHE_ADAPTERS;
|
|
1391
|
+
if (cleanId === "virtual:vinext-image-adapters" || cleanId.endsWith("/virtual:vinext-image-adapters")) return RESOLVED_IMAGE_ADAPTERS;
|
|
1148
1392
|
if (cleanId.startsWith("virtual:vinext-google-fonts?")) return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(VIRTUAL_GOOGLE_FONTS.length);
|
|
1149
1393
|
if (cleanId.endsWith("/virtual:vinext-rsc-entry")) return RESOLVED_RSC_ENTRY;
|
|
1150
1394
|
if (cleanId.endsWith("/virtual:vinext-app-ssr-entry")) return RESOLVED_APP_SSR_ENTRY;
|
|
@@ -1158,14 +1402,28 @@ function vinext(options = {}) {
|
|
|
1158
1402
|
}
|
|
1159
1403
|
},
|
|
1160
1404
|
async load(id) {
|
|
1405
|
+
if (id === RESOLVED_WORKER_ENTRY) return `export { default } from ${JSON.stringify(hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry")};`;
|
|
1161
1406
|
if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1();
|
|
1162
1407
|
if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
|
|
1408
|
+
if (id === RESOLVED_PAGES_CLIENT_ASSETS) {
|
|
1409
|
+
const metadata = { clientEntry: DEV_PAGES_CLIENT_ENTRY };
|
|
1410
|
+
const ssrManifest = {};
|
|
1411
|
+
const appFilePath = findFileWithExts(pagesDir, "_app", fileMatcher);
|
|
1412
|
+
const pagesRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1413
|
+
const moduleFilePaths = [...appFilePath ? [appFilePath] : [], ...pagesRoutes.map((route) => route.filePath)];
|
|
1414
|
+
for (const moduleFilePath of moduleFilePaths) {
|
|
1415
|
+
const stylesheetAssets = await collectDevPagesAppStylesheetAssets(root, moduleFilePath, this.resolve.bind(this));
|
|
1416
|
+
if (stylesheetAssets.length > 0) ssrManifest[normalizePathSeparators(moduleFilePath)] = stylesheetAssets;
|
|
1417
|
+
}
|
|
1418
|
+
if (Object.keys(ssrManifest).length > 0) metadata.ssrManifest = ssrManifest;
|
|
1419
|
+
return `export default ${JSON.stringify(metadata)};`;
|
|
1420
|
+
}
|
|
1163
1421
|
if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
|
|
1164
1422
|
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1165
1423
|
const metaRoutes = scanMetadataFiles(appDir);
|
|
1166
1424
|
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
1167
1425
|
const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
|
|
1168
|
-
const globalNotFoundPath = findFileWithExts(appDir, "global-not-found", fileMatcher);
|
|
1426
|
+
const globalNotFoundPath = nextConfig?.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
1169
1427
|
rscClassificationManifest = collectRouteClassificationManifest(routes);
|
|
1170
1428
|
return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
|
|
1171
1429
|
redirects: nextConfig?.redirects,
|
|
@@ -1182,13 +1440,19 @@ function vinext(options = {}) {
|
|
|
1182
1440
|
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
1183
1441
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
1184
1442
|
inlineCss: nextConfig?.inlineCss,
|
|
1443
|
+
globalNotFound: nextConfig?.globalNotFound,
|
|
1185
1444
|
cacheComponents: nextConfig?.cacheComponents,
|
|
1445
|
+
prefetchInlining: nextConfig?.prefetchInlining,
|
|
1186
1446
|
hasServerActions,
|
|
1187
1447
|
i18n: nextConfig?.i18n,
|
|
1188
1448
|
imageConfig: {
|
|
1189
1449
|
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
1190
1450
|
imageSizes: nextConfig?.images?.imageSizes,
|
|
1191
|
-
qualities: nextConfig?.images?.qualities
|
|
1451
|
+
qualities: nextConfig?.images?.qualities,
|
|
1452
|
+
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
1453
|
+
dangerouslyAllowLocalIP: nextConfig?.images?.dangerouslyAllowLocalIP,
|
|
1454
|
+
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
1455
|
+
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
1192
1456
|
},
|
|
1193
1457
|
hasPagesDir,
|
|
1194
1458
|
publicFiles: scanPublicFileRoutes(root),
|
|
@@ -1198,6 +1462,7 @@ function vinext(options = {}) {
|
|
|
1198
1462
|
}
|
|
1199
1463
|
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
1200
1464
|
if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
|
|
1465
|
+
if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
|
|
1201
1466
|
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
|
|
1202
1467
|
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
|
|
1203
1468
|
const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
@@ -1257,6 +1522,28 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1257
1522
|
}
|
|
1258
1523
|
}
|
|
1259
1524
|
},
|
|
1525
|
+
{
|
|
1526
|
+
name: "vinext:pages-client-assets-resolver",
|
|
1527
|
+
sharedDuringBuild: true,
|
|
1528
|
+
resolveId: {
|
|
1529
|
+
filter: { id: /virtual:vinext-pages-client-assets$/ },
|
|
1530
|
+
handler(id) {
|
|
1531
|
+
const cleanId = normalizePathSeparators(id.startsWith("\0") ? id.slice(1) : id);
|
|
1532
|
+
if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/virtual:vinext-pages-client-assets")) return;
|
|
1533
|
+
if (this.environment?.config.command !== "build") return RESOLVED_PAGES_CLIENT_ASSETS;
|
|
1534
|
+
const buildRoot = this.environment.config.root ?? process.cwd();
|
|
1535
|
+
const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
|
|
1536
|
+
const sidecarDir = !hasAppDir && this.environment.name === "ssr" ? path.dirname(environmentOutDir) : environmentOutDir;
|
|
1537
|
+
let externalId = normalizePathSeparators(path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE)));
|
|
1538
|
+
if (!externalId.startsWith(".")) externalId = `./${externalId}`;
|
|
1539
|
+
pagesClientAssetsOutputDirs.add(sidecarDir);
|
|
1540
|
+
return {
|
|
1541
|
+
id: externalId,
|
|
1542
|
+
external: true
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
},
|
|
1260
1547
|
{
|
|
1261
1548
|
name: "vinext:css-url-assets-mark",
|
|
1262
1549
|
enforce: "pre",
|
|
@@ -1277,11 +1564,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1277
1564
|
}
|
|
1278
1565
|
},
|
|
1279
1566
|
{
|
|
1280
|
-
name: "vinext:
|
|
1567
|
+
name: "vinext:css-url-assets-defaults",
|
|
1281
1568
|
apply: "build",
|
|
1282
|
-
configEnvironment(name) {
|
|
1283
|
-
if (name
|
|
1284
|
-
|
|
1569
|
+
configEnvironment(name, config) {
|
|
1570
|
+
if (name === "client") return { build: { assetsInlineLimit: clientAssetsInlineLimit } };
|
|
1571
|
+
if (!hasAppDir || name !== "rsc" && name !== "ssr") return null;
|
|
1572
|
+
const output = getBuildBundlerOptions(config.build)?.output;
|
|
1573
|
+
if (Array.isArray(output) || output?.assetFileNames !== void 0) return null;
|
|
1574
|
+
return { build: { ...withBuildBundlerOptions(viteMajorVersion, { output: { assetFileNames: createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? "")) } }) } };
|
|
1285
1575
|
}
|
|
1286
1576
|
},
|
|
1287
1577
|
{
|
|
@@ -1364,6 +1654,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1364
1654
|
}
|
|
1365
1655
|
}
|
|
1366
1656
|
},
|
|
1657
|
+
createCssModuleImportCompatibilityPlugin({ compiledMdx: true }),
|
|
1367
1658
|
{
|
|
1368
1659
|
name: "vinext:react-canary",
|
|
1369
1660
|
enforce: "pre",
|
|
@@ -1398,7 +1689,32 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1398
1689
|
{
|
|
1399
1690
|
name: "vinext:pages-router",
|
|
1400
1691
|
hotUpdate(options) {
|
|
1401
|
-
if (!hasPagesDir
|
|
1692
|
+
if (!hasPagesDir) return;
|
|
1693
|
+
const isPagesAppFile = (filePath) => {
|
|
1694
|
+
const relativePath = normalizePathSeparators(path.relative(pagesDir, filePath));
|
|
1695
|
+
return !relativePath.includes("/") && relativePath.startsWith("_app.") && fileMatcher.extensionRegex.test(filePath);
|
|
1696
|
+
};
|
|
1697
|
+
const isPotentialPagesAssetGraphScript = (filePath) => {
|
|
1698
|
+
const cleanPath = stripViteModuleQuery(filePath);
|
|
1699
|
+
if (!path.isAbsolute(cleanPath)) return false;
|
|
1700
|
+
if (!isScriptModuleId(cleanPath) || cleanPath.endsWith(".d.ts")) return false;
|
|
1701
|
+
const relativeRootPath = normalizePathSeparators(path.relative(root, cleanPath));
|
|
1702
|
+
if (relativeRootPath.startsWith("..") || path.isAbsolute(relativeRootPath)) return false;
|
|
1703
|
+
if (relativeRootPath.includes("/node_modules/") || relativeRootPath.startsWith("node_modules/")) return false;
|
|
1704
|
+
const relativeAppPath = normalizePathSeparators(path.relative(appDir, cleanPath));
|
|
1705
|
+
return relativeAppPath.startsWith("..") || path.isAbsolute(relativeAppPath);
|
|
1706
|
+
};
|
|
1707
|
+
const pagesAppChanged = isPagesAppFile(options.file);
|
|
1708
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(options.file);
|
|
1709
|
+
if (pagesAppChanged || STYLESHEET_FILE_RE.test(options.file) || pagesAssetGraphScriptChanged) for (const env of Object.values(options.server.environments)) {
|
|
1710
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED_PAGES_CLIENT_ASSETS);
|
|
1711
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1712
|
+
}
|
|
1713
|
+
if (pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged) {
|
|
1714
|
+
options.server.ws.send({ type: "full-reload" });
|
|
1715
|
+
return [];
|
|
1716
|
+
}
|
|
1717
|
+
if (hasAppDir) return;
|
|
1402
1718
|
if (options.file.startsWith(pagesDir) && fileMatcher.extensionRegex.test(options.file)) {
|
|
1403
1719
|
options.server.environments.client.hot.send({ type: "full-reload" });
|
|
1404
1720
|
return [];
|
|
@@ -1451,8 +1767,17 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1451
1767
|
}
|
|
1452
1768
|
pagesRunner?.clearCache();
|
|
1453
1769
|
}
|
|
1770
|
+
function invalidatePagesClientAssetsModule(reloadDocument = false) {
|
|
1771
|
+
for (const env of Object.values(server.environments)) {
|
|
1772
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED_PAGES_CLIENT_ASSETS);
|
|
1773
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1774
|
+
}
|
|
1775
|
+
pagesRunner?.clearCache();
|
|
1776
|
+
if (reloadDocument) server.ws.send({ type: "full-reload" });
|
|
1777
|
+
}
|
|
1454
1778
|
function invalidateAppRoutingModules() {
|
|
1455
1779
|
invalidateAppRouteCache();
|
|
1780
|
+
invalidateMetadataFileCache();
|
|
1456
1781
|
invalidateRscEntryModule();
|
|
1457
1782
|
invalidateRootParamsModule();
|
|
1458
1783
|
}
|
|
@@ -1497,6 +1822,20 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1497
1822
|
}
|
|
1498
1823
|
let appRouteTypeGeneration = null;
|
|
1499
1824
|
let appRouteTypeGenerationPending = false;
|
|
1825
|
+
function isPagesAppFile(filePath) {
|
|
1826
|
+
const relativePath = normalizePathSeparators(path.relative(pagesDir, filePath));
|
|
1827
|
+
return !relativePath.includes("/") && relativePath.startsWith("_app.") && fileMatcher.extensionRegex.test(filePath);
|
|
1828
|
+
}
|
|
1829
|
+
function isPotentialPagesAssetGraphScript(filePath) {
|
|
1830
|
+
const cleanPath = stripViteModuleQuery(filePath);
|
|
1831
|
+
if (!path.isAbsolute(cleanPath)) return false;
|
|
1832
|
+
if (!isScriptModuleId(cleanPath) || cleanPath.endsWith(".d.ts")) return false;
|
|
1833
|
+
const relativeRootPath = normalizePathSeparators(path.relative(root, cleanPath));
|
|
1834
|
+
if (relativeRootPath.startsWith("..") || path.isAbsolute(relativeRootPath)) return false;
|
|
1835
|
+
if (relativeRootPath.includes("/node_modules/") || relativeRootPath.startsWith("node_modules/")) return false;
|
|
1836
|
+
const relativeAppPath = normalizePathSeparators(path.relative(appDir, cleanPath));
|
|
1837
|
+
return relativeAppPath.startsWith("..") || path.isAbsolute(relativeAppPath);
|
|
1838
|
+
}
|
|
1500
1839
|
function warnRouteTypeGenerationFailure(error) {
|
|
1501
1840
|
server.config.logger.warn(`[vinext] Failed to regenerate route types: ${error instanceof Error ? error.message : String(error)}`);
|
|
1502
1841
|
}
|
|
@@ -1525,6 +1864,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1525
1864
|
});
|
|
1526
1865
|
server.watcher.on("add", (filePath) => {
|
|
1527
1866
|
let routeChanged = false;
|
|
1867
|
+
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1868
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1869
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged);
|
|
1528
1870
|
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1529
1871
|
invalidateRouteCache(pagesDir);
|
|
1530
1872
|
routeChanged = true;
|
|
@@ -1540,8 +1882,16 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1540
1882
|
revalidateHybridRoutes();
|
|
1541
1883
|
}
|
|
1542
1884
|
});
|
|
1885
|
+
server.watcher.on("change", (filePath) => {
|
|
1886
|
+
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1887
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1888
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged);
|
|
1889
|
+
});
|
|
1543
1890
|
server.watcher.on("unlink", (filePath) => {
|
|
1544
1891
|
let routeChanged = false;
|
|
1892
|
+
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1893
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1894
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged);
|
|
1545
1895
|
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1546
1896
|
invalidateRouteCache(pagesDir);
|
|
1547
1897
|
routeChanged = true;
|
|
@@ -1693,8 +2043,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1693
2043
|
res.end("Forbidden");
|
|
1694
2044
|
return;
|
|
1695
2045
|
}
|
|
2046
|
+
const requestHost = (Array.isArray(req.headers.host) ? req.headers.host[0] : req.headers.host) || "localhost";
|
|
2047
|
+
const requestOrigin = `http://${requestHost}`;
|
|
2048
|
+
const getUrlHostname = (requestUrl) => new URL(requestUrl).hostname;
|
|
1696
2049
|
if (isImageOptimizationPath(url.split("?")[0])) {
|
|
1697
|
-
const encodedLocation = resolveDevImageRedirect(new URL(url,
|
|
2050
|
+
const encodedLocation = resolveDevImageRedirect(new URL(url, requestOrigin), [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES], nextConfig.images?.qualities);
|
|
1698
2051
|
if (!encodedLocation) {
|
|
1699
2052
|
res.writeHead(400);
|
|
1700
2053
|
res.end("Invalid image optimization parameters");
|
|
@@ -1725,6 +2078,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1725
2078
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
1726
2079
|
url = pathname + qs;
|
|
1727
2080
|
}
|
|
2081
|
+
const capturedMiddlewarePath = middlewarePath;
|
|
1728
2082
|
const bp = nextConfig?.basePath ?? "";
|
|
1729
2083
|
if (bp && pathname.startsWith(bp)) {
|
|
1730
2084
|
const stripped = pathname.slice(bp.length) || "/";
|
|
@@ -1749,8 +2103,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1749
2103
|
if (dataMatch) {
|
|
1750
2104
|
isDataReq = true;
|
|
1751
2105
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
1752
|
-
|
|
1753
|
-
|
|
2106
|
+
const pagePathname = normalizeNextDataPagePathname(dataMatch.pagePathname, capturedMiddlewarePath !== null && nextConfig?.trailingSlash === true);
|
|
2107
|
+
url = pagePathname + qs;
|
|
2108
|
+
pathname = pagePathname;
|
|
1754
2109
|
req.url = url;
|
|
1755
2110
|
} else {
|
|
1756
2111
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
@@ -1769,13 +2124,21 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1769
2124
|
basePath: bp,
|
|
1770
2125
|
hadBasePath: true
|
|
1771
2126
|
}));
|
|
1772
|
-
|
|
2127
|
+
const isFilePathRequest = pathname.includes(".") && !pathname.endsWith(".html");
|
|
2128
|
+
let filePathMatchesPagesRoute = false;
|
|
2129
|
+
const requestHostname = getUrlHostname(requestOrigin);
|
|
2130
|
+
if (isFilePathRequest && !filePathMatchesRewrite) {
|
|
2131
|
+
const [pageRoutes, apiRoutes] = await Promise.all([pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher), apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)]);
|
|
2132
|
+
const pageRouteUrl = nextConfig?.i18n ? resolvePagesI18nRequest(pathname, nextConfig.i18n, req.headers, requestHostname, bp, nextConfig.trailingSlash ?? false).url : pathname;
|
|
2133
|
+
const apiRouteUrl = stripI18nLocaleForApiRoute(pathname, nextConfig?.i18n ?? null);
|
|
2134
|
+
filePathMatchesPagesRoute = matchRoute(pageRouteUrl, pageRoutes) !== null || matchRoute(apiRouteUrl, apiRoutes) !== null;
|
|
2135
|
+
}
|
|
2136
|
+
if (isFilePathRequest && !filePathMatchesRewrite && !filePathMatchesPagesRoute) return next();
|
|
1773
2137
|
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)])));
|
|
1774
2138
|
const isDataRequest = isDataReq;
|
|
1775
2139
|
const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
|
|
1776
2140
|
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
1777
2141
|
for (const header of VINEXT_INTERNAL_HEADERS) delete req.headers[header];
|
|
1778
|
-
const requestOrigin = `http://${req.headers.host || "localhost"}`;
|
|
1779
2142
|
const method = req.method ?? "GET";
|
|
1780
2143
|
const webRequest = new Request(new URL(url, requestOrigin), {
|
|
1781
2144
|
method,
|
|
@@ -1785,10 +2148,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1785
2148
|
for (const key of Object.keys(req.headers)) delete req.headers[key];
|
|
1786
2149
|
for (const [key, value] of nextRequestHeaders) req.headers[key] = value;
|
|
1787
2150
|
};
|
|
1788
|
-
const capturedMiddlewarePath = middlewarePath;
|
|
1789
2151
|
const devRunMiddlewareAdapter = capturedMiddlewarePath ? async (_request, _ctx, opts) => {
|
|
1790
2152
|
const rawProto = process.env.VINEXT_TRUST_PROXY === "1" || (process.env.VINEXT_TRUSTED_HOSTS ?? "").split(",").some((h) => h.trim()) ? String(req.headers["x-forwarded-proto"] || "").split(",")[0].trim() : "";
|
|
1791
|
-
const mwOrigin = `${rawProto === "https" || rawProto === "http" ? rawProto : "http"}://${
|
|
2153
|
+
const mwOrigin = `${rawProto === "https" || rawProto === "http" ? rawProto : "http"}://${requestHost}`;
|
|
1792
2154
|
const middlewareRequest = new Request(new URL(url, mwOrigin), {
|
|
1793
2155
|
method: req.method,
|
|
1794
2156
|
headers: nodeRequestHeaders
|
|
@@ -1809,6 +2171,18 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1809
2171
|
return result;
|
|
1810
2172
|
} : null;
|
|
1811
2173
|
const devPageRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
2174
|
+
const devPageRouteDataKinds = /* @__PURE__ */ new Map();
|
|
2175
|
+
const classifyDevPageRoute = (route) => {
|
|
2176
|
+
const cached = devPageRouteDataKinds.get(route.filePath);
|
|
2177
|
+
if (cached) return cached;
|
|
2178
|
+
let dataKind = "none";
|
|
2179
|
+
try {
|
|
2180
|
+
const source = fs.readFileSync(route.filePath, "utf8");
|
|
2181
|
+
dataKind = hasExportedName(source, "getStaticProps") ? "static" : hasExportedName(source, "getServerSideProps") ? "server" : "none";
|
|
2182
|
+
} catch {}
|
|
2183
|
+
devPageRouteDataKinds.set(route.filePath, dataKind);
|
|
2184
|
+
return dataKind;
|
|
2185
|
+
};
|
|
1812
2186
|
const pipelineResult = await runPagesRequest(webRequest, {
|
|
1813
2187
|
basePath: bp,
|
|
1814
2188
|
trailingSlash: nextConfig?.trailingSlash ?? false,
|
|
@@ -1823,11 +2197,16 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1823
2197
|
hadBasePath: true,
|
|
1824
2198
|
isDataReq,
|
|
1825
2199
|
isDataRequest,
|
|
2200
|
+
hasMiddleware: capturedMiddlewarePath !== null,
|
|
1826
2201
|
rawSearch: url.includes("?") ? url.slice(url.indexOf("?")) : "",
|
|
1827
2202
|
runMiddleware: devRunMiddlewareAdapter,
|
|
1828
|
-
matchPageRoute: (resolvedPathname) => {
|
|
1829
|
-
const m = matchRoute(resolvedPathname, devPageRoutes);
|
|
1830
|
-
return m ? { route: {
|
|
2203
|
+
matchPageRoute: (resolvedPathname, request) => {
|
|
2204
|
+
const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, getUrlHostname(request.url), bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
|
|
2205
|
+
return m ? { route: {
|
|
2206
|
+
dataKind: classifyDevPageRoute(m.route),
|
|
2207
|
+
isDynamic: m.route.isDynamic,
|
|
2208
|
+
pattern: m.route.pattern
|
|
2209
|
+
} } : null;
|
|
1831
2210
|
},
|
|
1832
2211
|
proxyExternal: async (currentRequest, externalUrl) => {
|
|
1833
2212
|
const externalMethod = req.method ?? "GET";
|
|
@@ -1895,7 +2274,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1895
2274
|
}
|
|
1896
2275
|
if (!cachedSSRHandler || cachedSSRHandler.routes !== routes) cachedSSRHandler = {
|
|
1897
2276
|
routes,
|
|
1898
|
-
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)
|
|
2277
|
+
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)
|
|
1899
2278
|
};
|
|
1900
2279
|
flushStagedHeaders();
|
|
1901
2280
|
flushRequestHeaders();
|
|
@@ -2014,7 +2393,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2014
2393
|
handler(code, id) {
|
|
2015
2394
|
const cacheDirPrefix = getCacheDirPrefix(this.environment.config.cacheDir);
|
|
2016
2395
|
if (normalizePathSeparators(id).startsWith(cacheDirPrefix)) return null;
|
|
2017
|
-
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
|
|
2396
|
+
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment), id);
|
|
2018
2397
|
}
|
|
2019
2398
|
}
|
|
2020
2399
|
},
|
|
@@ -2268,29 +2647,6 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2268
2647
|
createOgInlineFetchAssetsPlugin(),
|
|
2269
2648
|
createOgAssetsPlugin(),
|
|
2270
2649
|
createServerExternalsManifestPlugin(),
|
|
2271
|
-
{
|
|
2272
|
-
name: "vinext:image-config",
|
|
2273
|
-
apply: "build",
|
|
2274
|
-
enforce: "post",
|
|
2275
|
-
writeBundle: {
|
|
2276
|
-
sequential: true,
|
|
2277
|
-
order: "post",
|
|
2278
|
-
handler(options) {
|
|
2279
|
-
if (this.environment?.name !== "rsc") return;
|
|
2280
|
-
const outDir = options.dir;
|
|
2281
|
-
if (!outDir) return;
|
|
2282
|
-
const imageConfig = {
|
|
2283
|
-
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
2284
|
-
imageSizes: nextConfig?.images?.imageSizes,
|
|
2285
|
-
qualities: nextConfig?.images?.qualities,
|
|
2286
|
-
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
2287
|
-
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
2288
|
-
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
2289
|
-
};
|
|
2290
|
-
fs.writeFileSync(path.join(outDir, "image-config.json"), JSON.stringify(imageConfig));
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
},
|
|
2294
2650
|
(() => {
|
|
2295
2651
|
let buildIdWritten = false;
|
|
2296
2652
|
return {
|
|
@@ -2463,6 +2819,65 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2463
2819
|
}
|
|
2464
2820
|
};
|
|
2465
2821
|
})(),
|
|
2822
|
+
{
|
|
2823
|
+
name: "vinext:pages-client-assets",
|
|
2824
|
+
apply: "build",
|
|
2825
|
+
enforce: "post",
|
|
2826
|
+
sharedDuringBuild: true,
|
|
2827
|
+
closeBundle: {
|
|
2828
|
+
sequential: true,
|
|
2829
|
+
order: "post",
|
|
2830
|
+
handler() {
|
|
2831
|
+
const envConfig = this.environment.config;
|
|
2832
|
+
if (this.environment.name === "client") {
|
|
2833
|
+
const buildRoot = envConfig.root ?? process.cwd();
|
|
2834
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
2835
|
+
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2836
|
+
clientDir,
|
|
2837
|
+
assetBase: envConfig.base ?? "/",
|
|
2838
|
+
assetPrefix: nextConfig.assetPrefix,
|
|
2839
|
+
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2840
|
+
});
|
|
2841
|
+
let ssrManifest;
|
|
2842
|
+
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2843
|
+
if (fs.existsSync(ssrManifestPath)) try {
|
|
2844
|
+
ssrManifest = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
|
|
2845
|
+
} catch {}
|
|
2846
|
+
pagesClientAssetsModule = buildPagesClientAssetsModule({
|
|
2847
|
+
clientEntry: runtimeMetadata.clientEntryFile ?? void 0,
|
|
2848
|
+
appBootstrapPreinitModules: runtimeMetadata.appBootstrapPreinitModules,
|
|
2849
|
+
ssrManifest,
|
|
2850
|
+
lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
|
|
2851
|
+
dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0
|
|
2852
|
+
});
|
|
2853
|
+
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
2854
|
+
if (hasAppDir && hasPagesDir && buildSession) setPagesClientAssetsBuildMetadata(buildSession, pagesClientAssetsModule);
|
|
2855
|
+
}
|
|
2856
|
+
if (pagesClientAssetsModule === null) {
|
|
2857
|
+
if (pagesClientAssetsOutputDirs.size === 0) return;
|
|
2858
|
+
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
2859
|
+
if (buildSession) pagesClientAssetsModule = takePagesClientAssetsBuildMetadata(buildSession);
|
|
2860
|
+
}
|
|
2861
|
+
if (pagesClientAssetsModule === null) {
|
|
2862
|
+
const emptyModule = buildPagesClientAssetsModule({});
|
|
2863
|
+
for (const outputDir of pagesClientAssetsOutputDirs) writePagesClientAssetsModuleIfMissing(outputDir, emptyModule);
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2866
|
+
for (const outputDir of pagesClientAssetsOutputDirs) {
|
|
2867
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2868
|
+
fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
},
|
|
2872
|
+
buildApp() {
|
|
2873
|
+
if (pagesClientAssetsModule === null) return Promise.resolve();
|
|
2874
|
+
for (const outputDir of pagesClientAssetsOutputDirs) {
|
|
2875
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2876
|
+
fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
|
|
2877
|
+
}
|
|
2878
|
+
return Promise.resolve();
|
|
2879
|
+
}
|
|
2880
|
+
},
|
|
2466
2881
|
{
|
|
2467
2882
|
name: "vinext:inline-css-manifest",
|
|
2468
2883
|
apply: "build",
|
|
@@ -2496,61 +2911,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2496
2911
|
const envConfig = this.environment?.config;
|
|
2497
2912
|
if (!envConfig) return;
|
|
2498
2913
|
const buildRoot = envConfig.root ?? process.cwd();
|
|
2499
|
-
const
|
|
2500
|
-
if (!fs.existsSync(distDir)) return;
|
|
2501
|
-
const clientDir = path.resolve(buildRoot, "dist", "client");
|
|
2502
|
-
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2503
|
-
clientDir,
|
|
2504
|
-
assetBase: envConfig.base ?? "/",
|
|
2505
|
-
assetPrefix: nextConfig.assetPrefix,
|
|
2506
|
-
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2507
|
-
});
|
|
2508
|
-
const lazyChunksData = runtimeMetadata.lazyChunks ?? null;
|
|
2509
|
-
const dynamicPreloadsData = runtimeMetadata.dynamicPreloads ?? null;
|
|
2510
|
-
let clientEntryFile = runtimeMetadata.clientEntryFile ?? null;
|
|
2511
|
-
let ssrManifestData = null;
|
|
2512
|
-
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2513
|
-
if (fs.existsSync(ssrManifestPath)) try {
|
|
2514
|
-
ssrManifestData = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
|
|
2515
|
-
} catch {}
|
|
2516
|
-
if (hasAppDir) {
|
|
2517
|
-
const workerEntry = path.resolve(distDir, "server", "index.js");
|
|
2518
|
-
if (fs.existsSync(workerEntry)) {
|
|
2519
|
-
const script = buildRuntimeGlobalsScript({
|
|
2520
|
-
clientEntryFile,
|
|
2521
|
-
ssrManifest: ssrManifestData,
|
|
2522
|
-
lazyChunks: lazyChunksData,
|
|
2523
|
-
dynamicPreloads: dynamicPreloadsData
|
|
2524
|
-
});
|
|
2525
|
-
if (script) {
|
|
2526
|
-
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2527
|
-
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
} else {
|
|
2531
|
-
let workerOutDir = null;
|
|
2532
|
-
for (const entry of fs.readdirSync(distDir)) {
|
|
2533
|
-
const candidate = path.join(distDir, entry);
|
|
2534
|
-
if (entry === "client") continue;
|
|
2535
|
-
if (fs.statSync(candidate).isDirectory() && fs.existsSync(path.join(candidate, "wrangler.json"))) {
|
|
2536
|
-
workerOutDir = candidate;
|
|
2537
|
-
break;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
if (!workerOutDir) return;
|
|
2541
|
-
const workerEntry = path.join(workerOutDir, "index.js");
|
|
2542
|
-
if (!fs.existsSync(workerEntry)) return;
|
|
2543
|
-
const script = buildRuntimeGlobalsScript({
|
|
2544
|
-
clientEntryFile,
|
|
2545
|
-
ssrManifest: ssrManifestData,
|
|
2546
|
-
lazyChunks: lazyChunksData,
|
|
2547
|
-
dynamicPreloads: dynamicPreloadsData
|
|
2548
|
-
});
|
|
2549
|
-
if (script) {
|
|
2550
|
-
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2551
|
-
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2914
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
2554
2915
|
const headersPath = path.join(clientDir, "_headers");
|
|
2555
2916
|
if (!fs.existsSync(headersPath)) {
|
|
2556
2917
|
const headersContent = [
|
|
@@ -2625,6 +2986,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2625
2986
|
];
|
|
2626
2987
|
if (rscPluginPromise) {
|
|
2627
2988
|
plugins.push(rscPluginPromise);
|
|
2989
|
+
plugins.push(createRscReferenceValidationNormalizerPlugin());
|
|
2628
2990
|
plugins.push(createRscClientReferenceLoadersPlugin());
|
|
2629
2991
|
}
|
|
2630
2992
|
return plugins;
|