@qzsy/vinext 0.1.12 → 0.1.81
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 +19 -5
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- 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.d.ts +2 -1
- package/dist/build/prerender.js +11 -4
- package/dist/build/report.d.ts +2 -1
- package/dist/build/report.js +2 -1
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +9 -0
- package/dist/build/standalone.js +2 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +64 -28
- 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/cloudflare/deploy-config.d.ts +51 -0
- package/dist/cloudflare/deploy-config.js +153 -0
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/cloudflare/project.d.ts +41 -0
- package/dist/cloudflare/project.js +243 -0
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/config/config-matchers.js +14 -10
- package/dist/config/next-config.d.ts +6 -3
- package/dist/config/next-config.js +47 -1
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/deploy.d.ts +2 -122
- package/dist/deploy.js +20 -793
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +70 -12
- package/dist/entries/app-rsc-manifest.js +8 -0
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +2 -1
- package/dist/entries/pages-server-entry.js +6 -2
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +50 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +160 -160
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +1000 -0
- package/dist/init-platform.d.ts +38 -0
- package/dist/init-platform.js +150 -0
- package/dist/init.d.ts +14 -37
- package/dist/init.js +205 -95
- 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 +1 -1
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.js +3 -0
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/middleware-server-only.d.ts +8 -6
- package/dist/plugins/middleware-server-only.js +8 -7
- package/dist/plugins/optimize-imports.js +1 -1
- 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 +13 -2
- package/dist/routing/app-route-graph.js +116 -32
- package/dist/routing/app-router.d.ts +5 -0
- package/dist/routing/app-router.js +5 -0
- package/dist/routing/file-matcher.d.ts +8 -0
- package/dist/routing/file-matcher.js +10 -1
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/app-browser-action-result.d.ts +2 -1
- package/dist/server/app-browser-action-result.js +5 -1
- package/dist/server/app-browser-entry.js +17 -12
- package/dist/server/app-browser-history-controller.d.ts +2 -1
- package/dist/server/app-browser-history-controller.js +6 -2
- 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.js +1 -0
- package/dist/server/app-browser-server-action-client.js +2 -3
- package/dist/server/app-browser-state.d.ts +1 -0
- package/dist/server/app-browser-state.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +3 -2
- package/dist/server/app-fallback-renderer.js +12 -7
- package/dist/server/app-middleware.d.ts +2 -3
- package/dist/server/app-middleware.js +3 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +12 -3
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +10 -3
- 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 +4 -1
- package/dist/server/app-page-dispatch.d.ts +11 -3
- package/dist/server/app-page-dispatch.js +55 -15
- package/dist/server/app-page-element-builder.d.ts +5 -1
- package/dist/server/app-page-element-builder.js +57 -20
- package/dist/server/app-page-head.d.ts +12 -0
- package/dist/server/app-page-head.js +42 -19
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +6 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.d.ts +4 -1
- package/dist/server/app-page-render.js +8 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +89 -13
- package/dist/server/app-page-route-wiring.d.ts +6 -1
- package/dist/server/app-page-route-wiring.js +31 -15
- package/dist/server/app-page-search-params-observation.d.ts +4 -2
- package/dist/server/app-page-search-params-observation.js +11 -7
- package/dist/server/app-page-segment-state.js +2 -0
- package/dist/server/app-route-handler-dispatch.js +1 -0
- package/dist/server/app-route-handler-execution.js +7 -2
- 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-module-loader.d.ts +2 -0
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-router-entry.d.ts +12 -0
- package/dist/server/app-router-entry.js +22 -8
- package/dist/server/app-router-image-optimization.d.ts +37 -0
- package/dist/server/app-router-image-optimization.js +40 -0
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.js +27 -14
- package/dist/server/app-rsc-route-matching.d.ts +7 -0
- package/dist/server/app-rsc-route-matching.js +36 -3
- package/dist/server/app-segment-config.d.ts +12 -0
- package/dist/server/app-segment-config.js +91 -5
- package/dist/server/app-server-action-execution.d.ts +5 -0
- package/dist/server/app-server-action-execution.js +106 -33
- package/dist/server/app-ssr-entry.js +12 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- 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-response-headers.d.ts +19 -0
- package/dist/server/dev-response-headers.js +78 -0
- package/dist/server/dev-server.js +8 -15
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +6 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -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-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-page-data.d.ts +23 -1
- package/dist/server/pages-page-data.js +43 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +10 -4
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- 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 +1 -1
- package/dist/server/prod-server.js +47 -25
- package/dist/server/request-log.d.ts +5 -14
- package/dist/server/request-log.js +7 -1
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/server/server-action-logger.d.ts +39 -0
- package/dist/server/server-action-logger.js +104 -0
- package/dist/server/worker-utils.d.ts +2 -1
- package/dist/server/worker-utils.js +7 -1
- 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.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/error-boundary.d.ts +19 -1
- package/dist/shims/error-boundary.js +11 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +9 -1
- package/dist/shims/headers.js +31 -6
- package/dist/shims/image-optimization-url.d.ts +4 -0
- package/dist/shims/image-optimization-url.js +33 -1
- package/dist/shims/image.js +46 -13
- 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 +2 -5
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/link.js +23 -16
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.js +4 -2
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +2 -5
- package/dist/shims/router.js +41 -22
- package/dist/shims/server.js +3 -2
- package/dist/typegen.js +6 -5
- 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 +2 -2
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/project.d.ts +9 -1
- package/dist/utils/project.js +21 -4
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +29 -23
- 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,10 +1,11 @@
|
|
|
1
1
|
import { detectPackageManager } from "./utils/project.js";
|
|
2
|
-
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
3
2
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
4
3
|
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 } 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";
|
|
@@ -15,7 +16,8 @@ import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
|
15
16
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
16
17
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
17
18
|
import { isUnknownRecord } from "./utils/record.js";
|
|
18
|
-
import {
|
|
19
|
+
import { resolvePagesI18nRequest } from "./server/pages-i18n.js";
|
|
20
|
+
import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
19
21
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
20
22
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
21
23
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
@@ -27,6 +29,7 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
|
27
29
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
28
30
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
29
31
|
import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
32
|
+
import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
|
|
30
33
|
import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
|
|
31
34
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
32
35
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
@@ -35,7 +38,8 @@ import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
|
35
38
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
36
39
|
import { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine } from "./utils/vite-version.js";
|
|
37
40
|
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
38
|
-
import {
|
|
41
|
+
import { mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
42
|
+
import { installAppRouterDevRequestLogging } from "./server/dev-response-headers.js";
|
|
39
43
|
import { precompressAssets } from "./build/precompress.js";
|
|
40
44
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
41
45
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
@@ -48,6 +52,7 @@ import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
|
|
|
48
52
|
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
|
|
49
53
|
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
|
|
50
54
|
import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
|
|
55
|
+
import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
|
|
51
56
|
import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
|
|
52
57
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
53
58
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
@@ -60,9 +65,11 @@ import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins
|
|
|
60
65
|
import { generateRouteTypes } from "./typegen.js";
|
|
61
66
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
62
67
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
68
|
+
import { hasWranglerConfig } from "./cloudflare/project.js";
|
|
69
|
+
import { formatMissingCloudflarePluginError } from "./cloudflare/deploy-config.js";
|
|
63
70
|
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
64
|
-
import {
|
|
65
|
-
import {
|
|
71
|
+
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
72
|
+
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
66
73
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
67
74
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
|
|
68
75
|
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
@@ -76,6 +83,7 @@ import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
|
76
83
|
import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeof-window.js";
|
|
77
84
|
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
78
85
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
86
|
+
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
79
87
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
80
88
|
import { createRequire } from "node:module";
|
|
81
89
|
import fs from "node:fs";
|
|
@@ -301,6 +309,8 @@ const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
|
|
|
301
309
|
const RESOLVED_SERVER_ENTRY = "\0virtual:vinext-server-entry";
|
|
302
310
|
const VIRTUAL_CLIENT_ENTRY = "virtual:vinext-client-entry";
|
|
303
311
|
const RESOLVED_CLIENT_ENTRY = "\0virtual:vinext-client-entry";
|
|
312
|
+
const VIRTUAL_PAGES_CLIENT_ASSETS = "virtual:vinext-pages-client-assets";
|
|
313
|
+
const RESOLVED_PAGES_CLIENT_ASSETS = "\0virtual:vinext-pages-client-assets";
|
|
304
314
|
const VIRTUAL_RSC_ENTRY = "virtual:vinext-rsc-entry";
|
|
305
315
|
const RESOLVED_RSC_ENTRY = "\0virtual:vinext-rsc-entry";
|
|
306
316
|
const VIRTUAL_APP_SSR_ENTRY = "virtual:vinext-app-ssr-entry";
|
|
@@ -312,6 +322,8 @@ const RESOLVED_APP_CAPABILITIES = "\0virtual:vinext-app-capabilities";
|
|
|
312
322
|
const RESOLVED_ROOT_PARAMS = "\0virtual:vinext-root-params";
|
|
313
323
|
/** Virtual module that registers config-driven cache adapters (see VinextOptions.cache). */
|
|
314
324
|
const RESOLVED_CACHE_ADAPTERS = "\0" + VIRTUAL_CACHE_ADAPTERS;
|
|
325
|
+
/** Virtual module that registers the config-driven image optimizer (see VinextOptions.images). */
|
|
326
|
+
const RESOLVED_IMAGE_ADAPTERS = "\0" + VIRTUAL_IMAGE_ADAPTERS;
|
|
315
327
|
/** Virtual module for composed instrumentation-client bootstrap. */
|
|
316
328
|
const VIRTUAL_INSTRUMENTATION_CLIENT = "private-next-instrumentation-client";
|
|
317
329
|
const RESOLVED_INSTRUMENTATION_CLIENT = `${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs`;
|
|
@@ -337,9 +349,11 @@ function createStaticImageAsset(imagePath) {
|
|
|
337
349
|
* the `id.startsWith(_shimsDir)` checks would never match.
|
|
338
350
|
*/
|
|
339
351
|
const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
|
|
352
|
+
const _serverDir = normalizePathSeparators(path.resolve(__dirname, "server"));
|
|
340
353
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
341
|
-
const _appBrowserServerActionClientPath = resolveShimModulePath(
|
|
342
|
-
const _appRscHandlerPath = resolveShimModulePath(
|
|
354
|
+
const _appBrowserServerActionClientPath = resolveShimModulePath(_serverDir, "app-browser-server-action-client");
|
|
355
|
+
const _appRscHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-handler");
|
|
356
|
+
const _pagesClientAssetsPath = resolveShimModulePath(_serverDir, "pages-client-assets");
|
|
343
357
|
const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js");
|
|
344
358
|
const _defaultImageLoaderShimPath = resolveShimModulePath(_shimsDir, "default-image-loader");
|
|
345
359
|
/** Absolute path to `images.loaderFile` when configured; set in vinext:config. */
|
|
@@ -472,6 +486,8 @@ function vinext(options = {}) {
|
|
|
472
486
|
let hasCloudflarePlugin = false;
|
|
473
487
|
let warnedInlineNextConfigOverride = false;
|
|
474
488
|
let hasNitroPlugin = false;
|
|
489
|
+
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
490
|
+
let pagesClientAssetsModule = null;
|
|
475
491
|
let rscCompatibilityId;
|
|
476
492
|
const draftModeSecret = randomUUID();
|
|
477
493
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
@@ -517,7 +533,8 @@ function vinext(options = {}) {
|
|
|
517
533
|
const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => isLinkPrefetchRoute(route) ? toLinkPrefetchRoute(route) : toDocumentOnlyAppRoute(route)) : [];
|
|
518
534
|
return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
|
|
519
535
|
appPrefetchRoutes,
|
|
520
|
-
instrumentationClientPath
|
|
536
|
+
instrumentationClientPath,
|
|
537
|
+
reactPreamble: options.react !== false
|
|
521
538
|
});
|
|
522
539
|
}
|
|
523
540
|
async function writeRouteTypes() {
|
|
@@ -608,6 +625,7 @@ function vinext(options = {}) {
|
|
|
608
625
|
const plugins = [
|
|
609
626
|
...viteMajorVersion >= 8 ? [] : [loadVite7TsconfigPathsPlugin(earlyBaseDir)],
|
|
610
627
|
reactPluginPromise,
|
|
628
|
+
createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
611
629
|
commonjs(),
|
|
612
630
|
...viteMajorVersion >= 8 ? [{
|
|
613
631
|
name: "vinext:jsx-in-js",
|
|
@@ -636,9 +654,14 @@ function vinext(options = {}) {
|
|
|
636
654
|
createMiddlewareServerOnlyPlugin({
|
|
637
655
|
getMiddlewarePath: () => middlewarePath,
|
|
638
656
|
getCanonicalMiddlewarePath: () => middlewarePath ? tryRealpathSync(middlewarePath) ?? middlewarePath : null,
|
|
657
|
+
isNeutralServerModule: (id) => {
|
|
658
|
+
const canonicalId = canonicalizePageTransformPath(id);
|
|
659
|
+
return isWithinPagesDirectory(canonicalId) && isApiPage(canonicalId);
|
|
660
|
+
},
|
|
639
661
|
serverOnlyShimPath: resolveShimModulePath(shimsDir, "server-only")
|
|
640
662
|
}),
|
|
641
663
|
dataUrlCssPlugin(),
|
|
664
|
+
createCssModuleImportCompatibilityPlugin(),
|
|
642
665
|
{
|
|
643
666
|
name: "vinext:image-loader-file",
|
|
644
667
|
enforce: "pre",
|
|
@@ -758,6 +781,7 @@ function vinext(options = {}) {
|
|
|
758
781
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowSVG ?? false));
|
|
759
782
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
|
|
760
783
|
defines["process.env.__VINEXT_IMAGE_LOADER_CONFIGURED"] = JSON.stringify(nextConfig.images?.loaderFile ? "true" : "false");
|
|
784
|
+
defines["process.env.__VINEXT_IMAGE_UNOPTIMIZED"] = JSON.stringify(String(nextConfig.images?.unoptimized === true));
|
|
761
785
|
defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
|
|
762
786
|
defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
|
|
763
787
|
defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
|
|
@@ -824,7 +848,7 @@ function vinext(options = {}) {
|
|
|
824
848
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
825
849
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
826
850
|
"vinext/instrumentation-client": path.resolve(__dirname, "client", "instrumentation-client"),
|
|
827
|
-
"vinext/dev-error-overlay": path.resolve(__dirname, "
|
|
851
|
+
"vinext/dev-error-overlay": path.resolve(__dirname, "client", "dev-error-overlay"),
|
|
828
852
|
"vinext/html": path.resolve(__dirname, "server", "html"),
|
|
829
853
|
...clientInjectModule === null ? { "private-next-instrumentation-client": instrumentationClientPath ?? INSTRUMENTATION_CLIENT_EMPTY_MODULE } : {}
|
|
830
854
|
}).flatMap(([k, v]) => k.startsWith("next/") ? [[k, v], [`${k}.js`, v]] : [[k, v]]));
|
|
@@ -842,6 +866,8 @@ function vinext(options = {}) {
|
|
|
842
866
|
hasUserMdxPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "@mdx-js/rollup" || p.name === "mdx"));
|
|
843
867
|
if (!hasUserMdxPlugin && hasMdxFiles(root, hasAppDir ? appDir : null, hasPagesDir ? pagesDir : null)) await ensureMdxDelegate("detected");
|
|
844
868
|
const isSSR = !!config.build?.ssr;
|
|
869
|
+
const serverTranspilePackages = [...nextConfig?.turbopackTranspilePackages ?? [], ...nextConfig?.optimizePackageImports ?? []];
|
|
870
|
+
const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages);
|
|
845
871
|
const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
|
|
846
872
|
const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
|
|
847
873
|
const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
|
|
@@ -893,7 +919,9 @@ function vinext(options = {}) {
|
|
|
893
919
|
"react",
|
|
894
920
|
"react-dom",
|
|
895
921
|
"react-dom/server",
|
|
896
|
-
"ipaddr.js"
|
|
922
|
+
"ipaddr.js",
|
|
923
|
+
...Array.isArray(config.ssr?.external) ? config.ssr.external : [],
|
|
924
|
+
...nextServerExternal
|
|
897
925
|
],
|
|
898
926
|
noExternal: true
|
|
899
927
|
} },
|
|
@@ -901,7 +929,8 @@ function vinext(options = {}) {
|
|
|
901
929
|
alias: {
|
|
902
930
|
...tsconfigPathAliases,
|
|
903
931
|
...nextConfig.aliases,
|
|
904
|
-
...nextShimMap
|
|
932
|
+
...nextShimMap,
|
|
933
|
+
"vinext/server/pages-client-assets": _pagesClientAssetsPath
|
|
905
934
|
},
|
|
906
935
|
dedupe: [
|
|
907
936
|
"react",
|
|
@@ -938,7 +967,6 @@ function vinext(options = {}) {
|
|
|
938
967
|
...cssModulesOverride
|
|
939
968
|
}
|
|
940
969
|
};
|
|
941
|
-
const nextServerExternal = nextConfig?.serverExternalPackages ?? [];
|
|
942
970
|
const userSsrExternal = Array.isArray(config.ssr?.external) ? [...config.ssr.external, ...nextServerExternal] : config.ssr?.external === true ? true : nextServerExternal;
|
|
943
971
|
const externalizeSsrReactInDev = env.command === "serve" && !hasCloudflarePlugin && !hasNitroPlugin;
|
|
944
972
|
const incomingExclude = config.optimizeDeps?.exclude ?? [];
|
|
@@ -1075,7 +1103,8 @@ function vinext(options = {}) {
|
|
|
1075
1103
|
"react",
|
|
1076
1104
|
"react-dom",
|
|
1077
1105
|
"react-dom/server",
|
|
1078
|
-
"ipaddr.js"
|
|
1106
|
+
"ipaddr.js",
|
|
1107
|
+
...nextServerExternal
|
|
1079
1108
|
],
|
|
1080
1109
|
noExternal: true
|
|
1081
1110
|
},
|
|
@@ -1146,7 +1175,7 @@ function vinext(options = {}) {
|
|
|
1146
1175
|
resolveId: {
|
|
1147
1176
|
filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/app-rsc-handler)|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
|
|
1148
1177
|
handler(id, importer) {
|
|
1149
|
-
const cleanId = id.startsWith("\0") ? id.slice(1) : id;
|
|
1178
|
+
const cleanId = normalizePathSeparators(id.startsWith("\0") ? id.slice(1) : id);
|
|
1150
1179
|
if (cleanId === "vinext/server/app-rsc-handler") {
|
|
1151
1180
|
if (_canExternalizeAppRscHandler && this.environment?.name === "rsc" && this.environment.config?.command === "serve") return {
|
|
1152
1181
|
id: _appRscHandlerPath,
|
|
@@ -1158,19 +1187,20 @@ function vinext(options = {}) {
|
|
|
1158
1187
|
if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
|
|
1159
1188
|
if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
|
|
1160
1189
|
if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
|
|
1161
|
-
if (cleanId.endsWith("/virtual:vinext-server-entry")
|
|
1162
|
-
if (cleanId.endsWith("/virtual:vinext-client-entry")
|
|
1190
|
+
if (cleanId.endsWith("/virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
|
|
1191
|
+
if (cleanId.endsWith("/virtual:vinext-client-entry")) return RESOLVED_CLIENT_ENTRY;
|
|
1163
1192
|
if (cleanId === VIRTUAL_RSC_ENTRY) return RESOLVED_RSC_ENTRY;
|
|
1164
1193
|
if (cleanId === VIRTUAL_APP_SSR_ENTRY) return RESOLVED_APP_SSR_ENTRY;
|
|
1165
1194
|
if (cleanId === VIRTUAL_APP_BROWSER_ENTRY) return RESOLVED_APP_BROWSER_ENTRY;
|
|
1166
1195
|
if (cleanId === VIRTUAL_APP_CAPABILITIES) return RESOLVED_APP_CAPABILITIES;
|
|
1167
1196
|
if (cleanId === "next/root-params" || cleanId === "next/root-params.js") return RESOLVED_ROOT_PARAMS;
|
|
1168
|
-
if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters")
|
|
1197
|
+
if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters")) return RESOLVED_CACHE_ADAPTERS;
|
|
1198
|
+
if (cleanId === "virtual:vinext-image-adapters" || cleanId.endsWith("/virtual:vinext-image-adapters")) return RESOLVED_IMAGE_ADAPTERS;
|
|
1169
1199
|
if (cleanId.startsWith("virtual:vinext-google-fonts?")) return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(VIRTUAL_GOOGLE_FONTS.length);
|
|
1170
|
-
if (cleanId.endsWith("/virtual:vinext-rsc-entry")
|
|
1171
|
-
if (cleanId.endsWith("/virtual:vinext-app-ssr-entry")
|
|
1172
|
-
if (cleanId.endsWith("/virtual:vinext-app-browser-entry")
|
|
1173
|
-
if (cleanId.includes("/virtual:vinext-google-fonts?")
|
|
1200
|
+
if (cleanId.endsWith("/virtual:vinext-rsc-entry")) return RESOLVED_RSC_ENTRY;
|
|
1201
|
+
if (cleanId.endsWith("/virtual:vinext-app-ssr-entry")) return RESOLVED_APP_SSR_ENTRY;
|
|
1202
|
+
if (cleanId.endsWith("/virtual:vinext-app-browser-entry")) return RESOLVED_APP_BROWSER_ENTRY;
|
|
1203
|
+
if (cleanId.includes("/virtual:vinext-google-fonts?")) {
|
|
1174
1204
|
const queryIndex = cleanId.indexOf(VIRTUAL_GOOGLE_FONTS + "?");
|
|
1175
1205
|
return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(queryIndex + VIRTUAL_GOOGLE_FONTS.length);
|
|
1176
1206
|
}
|
|
@@ -1181,12 +1211,13 @@ function vinext(options = {}) {
|
|
|
1181
1211
|
async load(id) {
|
|
1182
1212
|
if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1();
|
|
1183
1213
|
if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
|
|
1214
|
+
if (id === RESOLVED_PAGES_CLIENT_ASSETS) return "export default { clientEntry: '/@id/__x00__virtual:vinext-client-entry' };";
|
|
1184
1215
|
if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
|
|
1185
1216
|
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1186
1217
|
const metaRoutes = scanMetadataFiles(appDir);
|
|
1187
1218
|
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
1188
1219
|
const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
|
|
1189
|
-
const globalNotFoundPath = findFileWithExts(appDir, "global-not-found", fileMatcher);
|
|
1220
|
+
const globalNotFoundPath = nextConfig?.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
1190
1221
|
rscClassificationManifest = collectRouteClassificationManifest(routes);
|
|
1191
1222
|
return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
|
|
1192
1223
|
redirects: nextConfig?.redirects,
|
|
@@ -1203,13 +1234,18 @@ function vinext(options = {}) {
|
|
|
1203
1234
|
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
1204
1235
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
1205
1236
|
inlineCss: nextConfig?.inlineCss,
|
|
1237
|
+
globalNotFound: nextConfig?.globalNotFound,
|
|
1206
1238
|
cacheComponents: nextConfig?.cacheComponents,
|
|
1207
1239
|
hasServerActions,
|
|
1208
1240
|
i18n: nextConfig?.i18n,
|
|
1209
1241
|
imageConfig: {
|
|
1210
1242
|
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
1211
1243
|
imageSizes: nextConfig?.images?.imageSizes,
|
|
1212
|
-
qualities: nextConfig?.images?.qualities
|
|
1244
|
+
qualities: nextConfig?.images?.qualities,
|
|
1245
|
+
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
1246
|
+
dangerouslyAllowLocalIP: nextConfig?.images?.dangerouslyAllowLocalIP,
|
|
1247
|
+
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
1248
|
+
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
1213
1249
|
},
|
|
1214
1250
|
hasPagesDir,
|
|
1215
1251
|
publicFiles: scanPublicFileRoutes(root),
|
|
@@ -1219,6 +1255,7 @@ function vinext(options = {}) {
|
|
|
1219
1255
|
}
|
|
1220
1256
|
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
1221
1257
|
if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
|
|
1258
|
+
if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
|
|
1222
1259
|
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
|
|
1223
1260
|
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
|
|
1224
1261
|
const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
@@ -1278,6 +1315,28 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1278
1315
|
}
|
|
1279
1316
|
}
|
|
1280
1317
|
},
|
|
1318
|
+
{
|
|
1319
|
+
name: "vinext:pages-client-assets-resolver",
|
|
1320
|
+
sharedDuringBuild: true,
|
|
1321
|
+
resolveId: {
|
|
1322
|
+
filter: { id: /virtual:vinext-pages-client-assets$/ },
|
|
1323
|
+
handler(id) {
|
|
1324
|
+
const cleanId = normalizePathSeparators(id.startsWith("\0") ? id.slice(1) : id);
|
|
1325
|
+
if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/virtual:vinext-pages-client-assets")) return;
|
|
1326
|
+
if (this.environment?.config.command !== "build") return RESOLVED_PAGES_CLIENT_ASSETS;
|
|
1327
|
+
const buildRoot = this.environment.config.root ?? process.cwd();
|
|
1328
|
+
const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
|
|
1329
|
+
const sidecarDir = !hasAppDir && this.environment.name === "ssr" ? path.dirname(environmentOutDir) : environmentOutDir;
|
|
1330
|
+
let externalId = normalizePathSeparators(path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE)));
|
|
1331
|
+
if (!externalId.startsWith(".")) externalId = `./${externalId}`;
|
|
1332
|
+
pagesClientAssetsOutputDirs.add(sidecarDir);
|
|
1333
|
+
return {
|
|
1334
|
+
id: externalId,
|
|
1335
|
+
external: true
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1281
1340
|
{
|
|
1282
1341
|
name: "vinext:css-url-assets-mark",
|
|
1283
1342
|
enforce: "pre",
|
|
@@ -1298,11 +1357,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1298
1357
|
}
|
|
1299
1358
|
},
|
|
1300
1359
|
{
|
|
1301
|
-
name: "vinext:
|
|
1360
|
+
name: "vinext:css-url-assets-defaults",
|
|
1302
1361
|
apply: "build",
|
|
1303
|
-
configEnvironment(name) {
|
|
1304
|
-
if (name
|
|
1305
|
-
|
|
1362
|
+
configEnvironment(name, config) {
|
|
1363
|
+
if (name === "client") return { build: { assetsInlineLimit: clientAssetsInlineLimit } };
|
|
1364
|
+
if (!hasAppDir || name !== "rsc" && name !== "ssr") return null;
|
|
1365
|
+
const output = getBuildBundlerOptions(config.build)?.output;
|
|
1366
|
+
if (Array.isArray(output) || output?.assetFileNames !== void 0) return null;
|
|
1367
|
+
return { build: { ...withBuildBundlerOptions(viteMajorVersion, { output: { assetFileNames: createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? "")) } }) } };
|
|
1306
1368
|
}
|
|
1307
1369
|
},
|
|
1308
1370
|
{
|
|
@@ -1385,6 +1447,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1385
1447
|
}
|
|
1386
1448
|
}
|
|
1387
1449
|
},
|
|
1450
|
+
createCssModuleImportCompatibilityPlugin({ compiledMdx: true }),
|
|
1388
1451
|
{
|
|
1389
1452
|
name: "vinext:react-canary",
|
|
1390
1453
|
enforce: "pre",
|
|
@@ -1644,56 +1707,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1644
1707
|
if (instrumentationPath && !hasAppDir) runInstrumentation(getPagesRunner(), instrumentationPath).catch((err) => {
|
|
1645
1708
|
console.error("[vinext] Instrumentation error:", err);
|
|
1646
1709
|
});
|
|
1647
|
-
if (hasAppDir) server.middlewares
|
|
1648
|
-
const url = req.url ?? "/";
|
|
1649
|
-
const [pathname] = url.split("?");
|
|
1650
|
-
if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules") || url.includes(".") && !pathname.endsWith(".html") && !pathname.endsWith(".rsc")) return next();
|
|
1651
|
-
const _reqStart = now();
|
|
1652
|
-
let _compileMs;
|
|
1653
|
-
let _renderMs;
|
|
1654
|
-
function _parseTiming(raw) {
|
|
1655
|
-
const [handlerStart, inHandlerCompileMs, renderMs] = String(raw).split(",").map((v) => Number(v));
|
|
1656
|
-
if (!Number.isNaN(handlerStart) && !Number.isNaN(inHandlerCompileMs) && inHandlerCompileMs !== -1) _compileMs = Math.max(0, Math.round(handlerStart - _reqStart)) + inHandlerCompileMs;
|
|
1657
|
-
if (!Number.isNaN(renderMs) && renderMs !== -1) _renderMs = renderMs;
|
|
1658
|
-
}
|
|
1659
|
-
const _origSetHeader = res.setHeader.bind(res);
|
|
1660
|
-
res.setHeader = function(name, value) {
|
|
1661
|
-
if (name.toLowerCase() === "x-vinext-timing") {
|
|
1662
|
-
_parseTiming(value);
|
|
1663
|
-
return res;
|
|
1664
|
-
}
|
|
1665
|
-
return _origSetHeader(name, value);
|
|
1666
|
-
};
|
|
1667
|
-
const _origWriteHead = res.writeHead.bind(res);
|
|
1668
|
-
res.writeHead = function(statusCode, ...args) {
|
|
1669
|
-
let headers;
|
|
1670
|
-
const [reasonOrHeaders, maybeHeaders] = args;
|
|
1671
|
-
if (typeof reasonOrHeaders === "string") headers = maybeHeaders;
|
|
1672
|
-
else headers = reasonOrHeaders;
|
|
1673
|
-
if (headers && typeof headers === "object" && !Array.isArray(headers)) {
|
|
1674
|
-
const timingKey = Object.keys(headers).find((k) => k.toLowerCase() === VINEXT_TIMING_HEADER);
|
|
1675
|
-
if (timingKey) {
|
|
1676
|
-
_parseTiming(headers[timingKey]);
|
|
1677
|
-
delete headers[timingKey];
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
return _origWriteHead(statusCode, ...args);
|
|
1681
|
-
};
|
|
1682
|
-
res.on("finish", () => {
|
|
1683
|
-
const logUrl = url.replace(/\.rsc(\?|$)/, "$1");
|
|
1684
|
-
const totalMs = now() - _reqStart;
|
|
1685
|
-
const resolvedRenderMs = _renderMs !== void 0 ? _renderMs : _compileMs !== void 0 ? Math.max(0, Math.round(totalMs - _compileMs)) : void 0;
|
|
1686
|
-
logRequest({
|
|
1687
|
-
method: req.method ?? "GET",
|
|
1688
|
-
url: logUrl,
|
|
1689
|
-
status: res.statusCode,
|
|
1690
|
-
totalMs,
|
|
1691
|
-
compileMs: _compileMs,
|
|
1692
|
-
renderMs: resolvedRenderMs
|
|
1693
|
-
});
|
|
1694
|
-
});
|
|
1695
|
-
next();
|
|
1696
|
-
});
|
|
1710
|
+
if (hasAppDir) installAppRouterDevRequestLogging(server.middlewares);
|
|
1697
1711
|
const handlePagesMiddleware = async (req, res, next) => {
|
|
1698
1712
|
try {
|
|
1699
1713
|
let url = req.url ?? "/";
|
|
@@ -1844,11 +1858,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1844
1858
|
hadBasePath: true,
|
|
1845
1859
|
isDataReq,
|
|
1846
1860
|
isDataRequest,
|
|
1861
|
+
hasMiddleware: capturedMiddlewarePath !== null,
|
|
1847
1862
|
rawSearch: url.includes("?") ? url.slice(url.indexOf("?")) : "",
|
|
1848
1863
|
runMiddleware: devRunMiddlewareAdapter,
|
|
1849
|
-
matchPageRoute: (resolvedPathname) => {
|
|
1850
|
-
const m = matchRoute(resolvedPathname, devPageRoutes);
|
|
1851
|
-
return m ? { route: {
|
|
1864
|
+
matchPageRoute: (resolvedPathname, request) => {
|
|
1865
|
+
const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, new URL(request.url).hostname, bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
|
|
1866
|
+
return m ? { route: {
|
|
1867
|
+
isDynamic: m.route.isDynamic,
|
|
1868
|
+
pattern: m.route.pattern
|
|
1869
|
+
} } : null;
|
|
1852
1870
|
},
|
|
1853
1871
|
proxyExternal: async (currentRequest, externalUrl) => {
|
|
1854
1872
|
const externalMethod = req.method ?? "GET";
|
|
@@ -2035,7 +2053,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2035
2053
|
handler(code, id) {
|
|
2036
2054
|
const cacheDirPrefix = getCacheDirPrefix(this.environment.config.cacheDir);
|
|
2037
2055
|
if (normalizePathSeparators(id).startsWith(cacheDirPrefix)) return null;
|
|
2038
|
-
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
|
|
2056
|
+
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment), id);
|
|
2039
2057
|
}
|
|
2040
2058
|
}
|
|
2041
2059
|
},
|
|
@@ -2289,29 +2307,6 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2289
2307
|
createOgInlineFetchAssetsPlugin(),
|
|
2290
2308
|
createOgAssetsPlugin(),
|
|
2291
2309
|
createServerExternalsManifestPlugin(),
|
|
2292
|
-
{
|
|
2293
|
-
name: "vinext:image-config",
|
|
2294
|
-
apply: "build",
|
|
2295
|
-
enforce: "post",
|
|
2296
|
-
writeBundle: {
|
|
2297
|
-
sequential: true,
|
|
2298
|
-
order: "post",
|
|
2299
|
-
handler(options) {
|
|
2300
|
-
if (this.environment?.name !== "rsc") return;
|
|
2301
|
-
const outDir = options.dir;
|
|
2302
|
-
if (!outDir) return;
|
|
2303
|
-
const imageConfig = {
|
|
2304
|
-
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
2305
|
-
imageSizes: nextConfig?.images?.imageSizes,
|
|
2306
|
-
qualities: nextConfig?.images?.qualities,
|
|
2307
|
-
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
2308
|
-
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
2309
|
-
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
2310
|
-
};
|
|
2311
|
-
fs.writeFileSync(path.join(outDir, "image-config.json"), JSON.stringify(imageConfig));
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
},
|
|
2315
2310
|
(() => {
|
|
2316
2311
|
let buildIdWritten = false;
|
|
2317
2312
|
return {
|
|
@@ -2484,6 +2479,65 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2484
2479
|
}
|
|
2485
2480
|
};
|
|
2486
2481
|
})(),
|
|
2482
|
+
{
|
|
2483
|
+
name: "vinext:pages-client-assets",
|
|
2484
|
+
apply: "build",
|
|
2485
|
+
enforce: "post",
|
|
2486
|
+
sharedDuringBuild: true,
|
|
2487
|
+
closeBundle: {
|
|
2488
|
+
sequential: true,
|
|
2489
|
+
order: "post",
|
|
2490
|
+
handler() {
|
|
2491
|
+
const envConfig = this.environment.config;
|
|
2492
|
+
if (this.environment.name === "client") {
|
|
2493
|
+
const buildRoot = envConfig.root ?? process.cwd();
|
|
2494
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
2495
|
+
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2496
|
+
clientDir,
|
|
2497
|
+
assetBase: envConfig.base ?? "/",
|
|
2498
|
+
assetPrefix: nextConfig.assetPrefix,
|
|
2499
|
+
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2500
|
+
});
|
|
2501
|
+
let ssrManifest;
|
|
2502
|
+
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2503
|
+
if (fs.existsSync(ssrManifestPath)) try {
|
|
2504
|
+
ssrManifest = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
|
|
2505
|
+
} catch {}
|
|
2506
|
+
pagesClientAssetsModule = buildPagesClientAssetsModule({
|
|
2507
|
+
clientEntry: runtimeMetadata.clientEntryFile ?? void 0,
|
|
2508
|
+
appBootstrapPreinitModules: runtimeMetadata.appBootstrapPreinitModules,
|
|
2509
|
+
ssrManifest,
|
|
2510
|
+
lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
|
|
2511
|
+
dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0
|
|
2512
|
+
});
|
|
2513
|
+
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
2514
|
+
if (hasAppDir && hasPagesDir && buildSession) setPagesClientAssetsBuildMetadata(buildSession, pagesClientAssetsModule);
|
|
2515
|
+
}
|
|
2516
|
+
if (pagesClientAssetsModule === null) {
|
|
2517
|
+
if (pagesClientAssetsOutputDirs.size === 0) return;
|
|
2518
|
+
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
2519
|
+
if (buildSession) pagesClientAssetsModule = takePagesClientAssetsBuildMetadata(buildSession);
|
|
2520
|
+
}
|
|
2521
|
+
if (pagesClientAssetsModule === null) {
|
|
2522
|
+
const emptyModule = buildPagesClientAssetsModule({});
|
|
2523
|
+
for (const outputDir of pagesClientAssetsOutputDirs) writePagesClientAssetsModuleIfMissing(outputDir, emptyModule);
|
|
2524
|
+
return;
|
|
2525
|
+
}
|
|
2526
|
+
for (const outputDir of pagesClientAssetsOutputDirs) {
|
|
2527
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2528
|
+
fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
},
|
|
2532
|
+
buildApp() {
|
|
2533
|
+
if (pagesClientAssetsModule === null) return Promise.resolve();
|
|
2534
|
+
for (const outputDir of pagesClientAssetsOutputDirs) {
|
|
2535
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2536
|
+
fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
|
|
2537
|
+
}
|
|
2538
|
+
return Promise.resolve();
|
|
2539
|
+
}
|
|
2540
|
+
},
|
|
2487
2541
|
{
|
|
2488
2542
|
name: "vinext:inline-css-manifest",
|
|
2489
2543
|
apply: "build",
|
|
@@ -2517,61 +2571,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2517
2571
|
const envConfig = this.environment?.config;
|
|
2518
2572
|
if (!envConfig) return;
|
|
2519
2573
|
const buildRoot = envConfig.root ?? process.cwd();
|
|
2520
|
-
const
|
|
2521
|
-
if (!fs.existsSync(distDir)) return;
|
|
2522
|
-
const clientDir = path.resolve(buildRoot, "dist", "client");
|
|
2523
|
-
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2524
|
-
clientDir,
|
|
2525
|
-
assetBase: envConfig.base ?? "/",
|
|
2526
|
-
assetPrefix: nextConfig.assetPrefix,
|
|
2527
|
-
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2528
|
-
});
|
|
2529
|
-
const lazyChunksData = runtimeMetadata.lazyChunks ?? null;
|
|
2530
|
-
const dynamicPreloadsData = runtimeMetadata.dynamicPreloads ?? null;
|
|
2531
|
-
let clientEntryFile = runtimeMetadata.clientEntryFile ?? null;
|
|
2532
|
-
let ssrManifestData = null;
|
|
2533
|
-
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2534
|
-
if (fs.existsSync(ssrManifestPath)) try {
|
|
2535
|
-
ssrManifestData = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
|
|
2536
|
-
} catch {}
|
|
2537
|
-
if (hasAppDir) {
|
|
2538
|
-
const workerEntry = path.resolve(distDir, "server", "index.js");
|
|
2539
|
-
if (fs.existsSync(workerEntry)) {
|
|
2540
|
-
const script = buildRuntimeGlobalsScript({
|
|
2541
|
-
clientEntryFile,
|
|
2542
|
-
ssrManifest: ssrManifestData,
|
|
2543
|
-
lazyChunks: lazyChunksData,
|
|
2544
|
-
dynamicPreloads: dynamicPreloadsData
|
|
2545
|
-
});
|
|
2546
|
-
if (script) {
|
|
2547
|
-
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2548
|
-
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
} else {
|
|
2552
|
-
let workerOutDir = null;
|
|
2553
|
-
for (const entry of fs.readdirSync(distDir)) {
|
|
2554
|
-
const candidate = path.join(distDir, entry);
|
|
2555
|
-
if (entry === "client") continue;
|
|
2556
|
-
if (fs.statSync(candidate).isDirectory() && fs.existsSync(path.join(candidate, "wrangler.json"))) {
|
|
2557
|
-
workerOutDir = candidate;
|
|
2558
|
-
break;
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
if (!workerOutDir) return;
|
|
2562
|
-
const workerEntry = path.join(workerOutDir, "index.js");
|
|
2563
|
-
if (!fs.existsSync(workerEntry)) return;
|
|
2564
|
-
const script = buildRuntimeGlobalsScript({
|
|
2565
|
-
clientEntryFile,
|
|
2566
|
-
ssrManifest: ssrManifestData,
|
|
2567
|
-
lazyChunks: lazyChunksData,
|
|
2568
|
-
dynamicPreloads: dynamicPreloadsData
|
|
2569
|
-
});
|
|
2570
|
-
if (script) {
|
|
2571
|
-
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2572
|
-
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2573
|
-
}
|
|
2574
|
-
}
|
|
2574
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
2575
2575
|
const headersPath = path.join(clientDir, "_headers");
|
|
2576
2576
|
if (!fs.existsSync(headersPath)) {
|
|
2577
2577
|
const headersContent = [
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CloudflareInitOptions } from "./init-platform.js";
|
|
2
|
+
|
|
3
|
+
//#region src/init-cloudflare.d.ts
|
|
4
|
+
type CloudflareProjectInfo = {
|
|
5
|
+
root: string;
|
|
6
|
+
projectName: string;
|
|
7
|
+
isAppRouter: boolean;
|
|
8
|
+
hasISR: boolean;
|
|
9
|
+
hasMDX: boolean;
|
|
10
|
+
nativeModulesToStub: string[];
|
|
11
|
+
};
|
|
12
|
+
type CloudflarePlatformSetupContext = {
|
|
13
|
+
root: string;
|
|
14
|
+
isAppRouter: boolean;
|
|
15
|
+
existingViteConfigPath?: string;
|
|
16
|
+
today?: string;
|
|
17
|
+
};
|
|
18
|
+
type CloudflarePlatformSetupResult = {
|
|
19
|
+
generatedViteConfig: boolean;
|
|
20
|
+
skippedViteConfig: boolean;
|
|
21
|
+
generatedPlatformFiles: string[];
|
|
22
|
+
nextSteps: string[];
|
|
23
|
+
};
|
|
24
|
+
declare function validateCloudflarePlatformSetup(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): void;
|
|
25
|
+
declare function setupCloudflarePlatform(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): CloudflarePlatformSetupResult;
|
|
26
|
+
declare function generateWranglerConfig(info: CloudflareProjectInfo, options?: CloudflareInitOptions, today?: string): string;
|
|
27
|
+
declare function updateWranglerConfigForCloudflare(code: string, options: CloudflareInitOptions): string;
|
|
28
|
+
declare function getWranglerImagesBinding(code: string): string;
|
|
29
|
+
/** Generate worker/index.ts for Pages Router */
|
|
30
|
+
declare function generatePagesRouterWorkerEntry(): string;
|
|
31
|
+
/** Generate vite.config.ts for App Router */
|
|
32
|
+
declare function generateAppRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string): string;
|
|
33
|
+
/** Generate vite.config.ts for Pages Router */
|
|
34
|
+
declare function generatePagesRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string): string;
|
|
35
|
+
declare function updateViteConfigForCloudflare(filePath: string, code: string, options: {
|
|
36
|
+
isAppRouter: boolean;
|
|
37
|
+
nativeModulesToStub: string[];
|
|
38
|
+
cache?: CloudflareInitOptions;
|
|
39
|
+
imagesBinding?: string;
|
|
40
|
+
}): string;
|
|
41
|
+
declare function usesCommonJsViteConfig(filePath: string, code: string): boolean;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CloudflarePlatformSetupContext, CloudflarePlatformSetupResult, CloudflareProjectInfo, generateAppRouterViteConfig, generatePagesRouterViteConfig, generatePagesRouterWorkerEntry, generateWranglerConfig, getWranglerImagesBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|