vinext 1.0.0-beta.12 → 1.0.0-beta.13
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 +39 -12
- package/dist/build/action-owner-manifest.js +23 -5
- package/dist/build/lifecycle.d.ts +42 -0
- package/dist/build/lifecycle.js +246 -0
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +0 -3
- package/dist/build/pages-client-assets-module.js +1 -13
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender-paths.d.ts +1 -1
- package/dist/build/prerender-paths.js +6 -6
- package/dist/build/prerender-server-pool.js +1 -1
- package/dist/build/prerender.d.ts +1 -1
- package/dist/build/prerender.js +5 -5
- package/dist/build/preview-credentials.d.ts +1 -1
- package/dist/build/preview-credentials.js +2 -2
- package/dist/build/report.js +1 -1
- package/dist/build/run-prerender.d.ts +2 -2
- package/dist/build/run-prerender.js +5 -5
- package/dist/build/standalone.js +2 -2
- package/dist/cli-args.d.ts +5 -13
- package/dist/cli-args.js +2 -45
- package/dist/cli-dev-config.d.ts +6 -2
- package/dist/cli-dev-config.js +160 -3
- package/dist/cli.js +104 -439
- package/dist/config/config-matchers.js +1 -1
- package/dist/config/next-config.d.ts +2 -2
- package/dist/config/next-config.js +5 -5
- package/dist/config/prerender.d.ts +3 -0
- package/dist/config/prerender.js +8 -2
- package/dist/entries/app-browser-entry.js +1 -1
- package/dist/entries/app-rsc-entry.js +1 -1
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +17 -2
- package/dist/index.d.ts +6 -8
- package/dist/index.js +262 -101
- package/dist/init-cloudflare.d.ts +3 -2
- package/dist/init-cloudflare.js +117 -5
- package/dist/init-platform.d.ts +2 -0
- package/dist/init-platform.js +9 -3
- package/dist/init.d.ts +7 -5
- package/dist/init.js +41 -22
- package/dist/plugins/dynamic-preload-metadata.js +1 -1
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +1 -1
- package/dist/plugins/import-meta-url.js +1 -1
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/og-assets.js +32 -13
- package/dist/plugins/og-harfbuzz.d.ts +24 -0
- package/dist/plugins/og-harfbuzz.js +260 -0
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/require-condition-resolution.js +2 -2
- package/dist/plugins/require-context.js +2 -2
- package/dist/plugins/typeof-window.js +1 -1
- package/dist/plugins/use-cache-callable.d.ts +0 -2
- package/dist/plugins/use-cache-callable.js +8 -16
- package/dist/plugins/worker-image-imports.js +1 -1
- package/dist/routing/app-route-graph.js +1 -1
- package/dist/routing/app-router.js +1 -1
- package/dist/routing/pages-router.js +1 -1
- package/dist/server/app-action-forwarding.js +1 -1
- package/dist/server/app-browser-error.js +1 -1
- package/dist/server/app-elements-wire.js +2 -2
- package/dist/server/app-middleware.js +1 -1
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-dispatch.js +1 -1
- package/dist/server/app-page-element-builder.js +3 -2
- package/dist/server/app-page-probe.js +3 -3
- package/dist/server/app-request-stage-independent-entry.js +2 -2
- package/dist/server/app-route-handler-dispatch.js +1 -1
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-router-entry.js +2 -2
- package/dist/server/app-rsc-handler.d.ts +1 -1
- package/dist/server/app-rsc-handler.js +4 -4
- package/dist/server/app-rsc-response-stage.js +1 -1
- package/dist/server/app-rsc-route-matching.js +1 -1
- package/dist/server/app-server-action-execution.js +4 -4
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/dev-lockfile.d.ts +1 -1
- package/dist/server/dev-lockfile.js +4 -1
- package/dist/server/dev-server.d.ts +1 -1
- package/dist/server/dev-server.js +28 -6
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/metadata-route-response.js +8 -0
- package/dist/server/middleware-runtime.js +3 -3
- package/dist/server/pages-data-route.js +1 -1
- package/dist/server/pages-dev-hydration.d.ts +6 -0
- package/dist/server/pages-dev-hydration.js +19 -7
- package/dist/server/pages-page-data.js +2 -2
- package/dist/server/pages-page-handler.js +1 -1
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/pages-request-pipeline.js +3 -3
- package/dist/server/pages-request-stage-entry.js +3 -3
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.js +7 -7
- package/dist/server/request-pipeline.js +2 -2
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/shims/cache-callable-runtime.d.ts +38 -0
- package/dist/shims/cache-callable-runtime.js +162 -11
- package/dist/shims/cache-runtime.d.ts +6 -8
- package/dist/shims/cache-runtime.js +82 -22
- package/dist/shims/font-local.js +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/headers.js +2 -2
- package/dist/shims/internal/app-page-props-cache-key.d.ts +29 -0
- package/dist/shims/internal/app-page-props-cache-key.js +53 -1
- package/dist/shims/internal/format-url-object.d.ts +7 -0
- package/dist/shims/internal/format-url-object.js +53 -0
- package/dist/shims/internal/normalize-router-href.d.ts +15 -0
- package/dist/shims/internal/normalize-router-href.js +41 -0
- package/dist/shims/internal/pages-data-target.d.ts +4 -1
- package/dist/shims/internal/pages-data-target.js +28 -35
- package/dist/shims/internal/route-pattern-for-warning.d.ts +2 -2
- package/dist/shims/internal/route-pattern-for-warning.js +3 -3
- package/dist/shims/link.js +31 -92
- package/dist/shims/metadata.js +5 -4
- package/dist/shims/navigation.js +2 -2
- package/dist/shims/router-state.js +1 -1
- package/dist/shims/router.d.ts +8 -7
- package/dist/shims/router.js +312 -148
- package/dist/shims/server.js +3 -3
- package/dist/utils/built-asset-url.js +1 -1
- package/dist/utils/project.d.ts +1 -11
- package/dist/utils/project.js +19 -28
- package/dist/utils/react-version.d.ts +3 -1
- package/dist/utils/react-version.js +19 -1
- package/dist/utils/vite-cli-invocation.d.ts +21 -0
- package/dist/utils/vite-cli-invocation.js +144 -0
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import path, { toSlash } from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
|
|
3
|
-
import {
|
|
3
|
+
import { claimViteCliBuildInvocation, getViteCliInvocation, isViteCliConfigFile } from "./utils/vite-cli-invocation.js";
|
|
4
|
+
import { VINEXT_DEV_CLI_LIFECYCLE, applyDevServerDefaults, claimViteCliDevInvocation, createDevServerLifecyclePlugin, reserveViteCliDevInvocation } from "./cli-dev-config.js";
|
|
5
|
+
import { isUnknownRecord } from "./utils/record.js";
|
|
6
|
+
import { getReactUpgradeDeps } from "./utils/react-version.js";
|
|
7
|
+
import { loadDotenv } from "./config/dotenv.js";
|
|
8
|
+
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
4
9
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
10
|
+
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
11
|
+
import { encodeMiddlewareRequestHeaders } from "./utils/middleware-request-headers.js";
|
|
12
|
+
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
13
|
+
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
14
|
+
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
15
|
+
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
16
|
+
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
5
17
|
import { hasBasePath, stripBasePath } from "./utils/base-path.js";
|
|
18
|
+
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
19
|
+
import { generateRouteTypes } from "./typegen.js";
|
|
6
20
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
7
21
|
import { resolveRuntimeEntryModule } from "./entries/runtime-entry-module.js";
|
|
8
|
-
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
9
22
|
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
10
|
-
import { encodeMiddlewareRequestHeaders } from "./utils/middleware-request-headers.js";
|
|
11
23
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
12
|
-
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
13
24
|
import { validateMiddlewareMatcherPatterns } from "./server/middleware-matcher-pattern.js";
|
|
14
25
|
import { methodNotAllowedResponse } from "./server/http-error-responses.js";
|
|
15
26
|
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
@@ -19,12 +30,9 @@ import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentat
|
|
|
19
30
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
20
31
|
import { extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, hasExportedName } from "./build/report.js";
|
|
21
32
|
import { generatePagesRequestEntry, generatePagesResponseEntry, generateServerEntry } from "./entries/pages-server-entry.js";
|
|
22
|
-
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
23
|
-
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
24
|
-
import { isUnknownRecord } from "./utils/record.js";
|
|
33
|
+
import { compileClientMiddlewareMatchers, generateClientEntry } from "./entries/pages-client-entry.js";
|
|
25
34
|
import { logRequest, now } from "./server/request-log.js";
|
|
26
35
|
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
27
|
-
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
28
36
|
import { getPagesPreviewModeId } from "./server/pages-preview.js";
|
|
29
37
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
30
38
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
@@ -45,12 +53,12 @@ import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/ima
|
|
|
45
53
|
import { generateBrowserEntry, toLinkPrefetchRoutes } from "./entries/app-browser-entry.js";
|
|
46
54
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
47
55
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
48
|
-
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
49
|
-
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
50
|
-
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
51
|
-
import { loadDotenv } from "./config/dotenv.js";
|
|
52
56
|
import { findOpenTelemetryPackages, mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
53
57
|
import { precompressAssets } from "./build/precompress.js";
|
|
58
|
+
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
59
|
+
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
60
|
+
import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
|
|
61
|
+
import { VINEXT_BUILD_LIFECYCLE_CONFIG, createBuildLifecyclePlugins } from "./build/lifecycle.js";
|
|
54
62
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
55
63
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
56
64
|
import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
|
|
@@ -79,18 +87,16 @@ import { validateMiddlewareModuleExports } from "./plugins/middleware-export-val
|
|
|
79
87
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
80
88
|
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
81
89
|
import { createDynamicPreloadMetadataPlugin } from "./plugins/dynamic-preload-metadata.js";
|
|
90
|
+
import { createOgHarfbuzzPlugin } from "./plugins/og-harfbuzz.js";
|
|
82
91
|
import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins/og-assets.js";
|
|
83
92
|
import { createUseCacheCallablePlugin } from "./plugins/use-cache-callable.js";
|
|
84
|
-
import { generateRouteTypes } from "./typegen.js";
|
|
85
93
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
86
94
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
87
95
|
import { createTransitiveExternalsPlugin } from "./plugins/transitive-externals.js";
|
|
88
96
|
import public_shim_map_default from "./shims/public-shim-map.json.js";
|
|
89
97
|
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
90
98
|
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
91
|
-
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
92
99
|
import { readPrerenderSecret, readServerRuntimeOutputDirs } from "./build/server-manifest.js";
|
|
93
|
-
import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
|
|
94
100
|
import { createModuleDependencyCache } from "./build/module-dependency-cache.js";
|
|
95
101
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
96
102
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
@@ -111,15 +117,15 @@ import { publicFilePathVariants } from "./utils/public-file-path.js";
|
|
|
111
117
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
112
118
|
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
113
119
|
import { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine } from "./utils/vite-version.js";
|
|
114
|
-
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
115
120
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
116
121
|
import { createRequire } from "node:module";
|
|
117
122
|
import fs from "node:fs";
|
|
118
123
|
import { createIdResolver, createLogger, isRunnableDevEnvironment, parseAst, transformWithOxc } from "vite";
|
|
119
124
|
import { pathToFileURL } from "node:url";
|
|
125
|
+
import { execFileSync } from "node:child_process";
|
|
120
126
|
import { createHash, randomBytes } from "node:crypto";
|
|
121
|
-
import commonjs from "vite-plugin-commonjs";
|
|
122
127
|
import MagicString from "magic-string";
|
|
128
|
+
import commonjs from "vite-plugin-commonjs";
|
|
123
129
|
//#region src/index.ts
|
|
124
130
|
const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE = Object.freeze(["vinext/server/fetch-handler", "vinext/server/pages-router-entry"]);
|
|
125
131
|
const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
@@ -133,6 +139,30 @@ const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
|
133
139
|
const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-sync-external-store\/with-selector.*present in .* 'optimizeDeps\.include'/;
|
|
134
140
|
const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
|
|
135
141
|
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
142
|
+
const RSC_ENVIRONMENTS = /* @__PURE__ */ new Set([
|
|
143
|
+
"rsc",
|
|
144
|
+
"ssr",
|
|
145
|
+
"client"
|
|
146
|
+
]);
|
|
147
|
+
function scopeRscPlugin(plugin) {
|
|
148
|
+
const applyToEnvironment = plugin.applyToEnvironment;
|
|
149
|
+
return {
|
|
150
|
+
...plugin,
|
|
151
|
+
applyToEnvironment(environment) {
|
|
152
|
+
if (!RSC_ENVIRONMENTS.has(environment.name)) return false;
|
|
153
|
+
return applyToEnvironment?.(environment) ?? true;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const earlyViteCliInvocation = getViteCliInvocation();
|
|
158
|
+
const viteCliBuildConfigNodeEnv = earlyViteCliInvocation?.command === "build" && process.env.NODE_ENV === "test" ? "test" : void 0;
|
|
159
|
+
if (earlyViteCliInvocation) {
|
|
160
|
+
if (!process.env.NODE_ENV) Reflect.set(process.env, "NODE_ENV", earlyViteCliInvocation.command === "build" ? viteCliBuildConfigNodeEnv ?? "production" : earlyViteCliInvocation.mode === "test" ? "test" : "development");
|
|
161
|
+
loadDotenv({
|
|
162
|
+
root: earlyViteCliInvocation.root,
|
|
163
|
+
mode: earlyViteCliInvocation.mode
|
|
164
|
+
});
|
|
165
|
+
}
|
|
136
166
|
installSocketErrorBackstop();
|
|
137
167
|
function hasServerOnlyMarkerImport(code) {
|
|
138
168
|
if (!code.includes("server-only")) return false;
|
|
@@ -187,6 +217,7 @@ function resolveShimModulePath(shimsDir, moduleName) {
|
|
|
187
217
|
}
|
|
188
218
|
return path.join(shimsDir, `${moduleName}.js`);
|
|
189
219
|
}
|
|
220
|
+
const PATCHED_SERVER_PACKAGES = ["@vercel/og"];
|
|
190
221
|
function isVercelOgImport(id) {
|
|
191
222
|
return id === "@vercel/og" || id === "@vercel/og.js";
|
|
192
223
|
}
|
|
@@ -799,7 +830,9 @@ function createServerEnvironmentFileNameResolver(config, outputRoot) {
|
|
|
799
830
|
};
|
|
800
831
|
}
|
|
801
832
|
function vinext(options = {}) {
|
|
833
|
+
const internalOptions = options;
|
|
802
834
|
const { supportsNativeTypeofWindowFolding: useNativeTypeofWindowFolding } = assertSupportedViteVersion();
|
|
835
|
+
const reservedDevCliInvocation = reserveViteCliDevInvocation();
|
|
803
836
|
const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
|
|
804
837
|
const cacheAdapterBuildOutputs = [options.cache?.data?.output, options.cache?.cdn?.output].filter((output) => output !== void 0);
|
|
805
838
|
let root;
|
|
@@ -820,10 +853,7 @@ function vinext(options = {}) {
|
|
|
820
853
|
let hasCloudflarePlugin = false;
|
|
821
854
|
let matchedMultiStageOutput;
|
|
822
855
|
let selectedMultiStageOutput;
|
|
823
|
-
const isMultiStageServerEnvironment = (environment) =>
|
|
824
|
-
if (environment.name === "client") return Boolean(environment.config.build.ssr);
|
|
825
|
-
return isServerEnvironment(environment) && (!hasAppDir || environment.name !== "ssr");
|
|
826
|
-
};
|
|
856
|
+
const isMultiStageServerEnvironment = (environment) => isServerEnvironment(environment) && (!hasAppDir || environment.name === "rsc");
|
|
827
857
|
let warnedInlineNextConfigOverride = false;
|
|
828
858
|
let hasNitroPlugin = false;
|
|
829
859
|
let nitroHostRuntime = "node";
|
|
@@ -832,6 +862,12 @@ function vinext(options = {}) {
|
|
|
832
862
|
let pagesTsconfigAliases = {};
|
|
833
863
|
let pagesBundledPackages = /* @__PURE__ */ new Set();
|
|
834
864
|
let isServeCommand = false;
|
|
865
|
+
let buildEmptyOutDir;
|
|
866
|
+
let buildLifecycleEnabled = false;
|
|
867
|
+
let hasPlainPagesBuildEnvironments = false;
|
|
868
|
+
let originalPlainPagesEnvironments;
|
|
869
|
+
let buildLifecycleInvocation;
|
|
870
|
+
let reactUpgradeChecked = false;
|
|
835
871
|
let pagesOptimizeEntries = [];
|
|
836
872
|
const importMetaUrlCapability = createImportMetaUrlPlugin({
|
|
837
873
|
getRoot: () => root,
|
|
@@ -842,7 +878,7 @@ function vinext(options = {}) {
|
|
|
842
878
|
});
|
|
843
879
|
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
844
880
|
const resolvePagesClientAssetsOutputDir = (environmentName, outputDir) => !selectedMultiStageOutput && !hasAppDir && environmentName === "ssr" ? path.dirname(outputDir) : outputDir;
|
|
845
|
-
let pagesClientAssetsModule = null;
|
|
881
|
+
let pagesClientAssetsModule = internalOptions.__pagesClientAssetsModule ?? null;
|
|
846
882
|
let devPublicFileRoutes = null;
|
|
847
883
|
let publicDirConflictOptions = null;
|
|
848
884
|
let copyPublicDirIntoStaticExportBasePath = false;
|
|
@@ -850,6 +886,7 @@ function vinext(options = {}) {
|
|
|
850
886
|
let rscCompatibilityId;
|
|
851
887
|
let draftModeSecret = getPagesPreviewModeId();
|
|
852
888
|
const prerenderSecret = process.env.__VINEXT_SHARED_PRERENDER_SECRET ?? randomBytes(32).toString("hex");
|
|
889
|
+
let revalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
|
|
853
890
|
let previewBuildCredentials;
|
|
854
891
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
855
892
|
const rscClassificationManifests = /* @__PURE__ */ new Map();
|
|
@@ -930,7 +967,8 @@ function vinext(options = {}) {
|
|
|
930
967
|
});
|
|
931
968
|
}
|
|
932
969
|
const autoRsc = options.rsc !== false;
|
|
933
|
-
const
|
|
970
|
+
const earlyRoot = earlyViteCliInvocation?.root ?? process.cwd();
|
|
971
|
+
const earlyBaseDir = path.resolve(earlyRoot, options.appDir ?? ".");
|
|
934
972
|
const earlyAppDirExists = !options.disableAppRouter && (fs.existsSync(path.join(earlyBaseDir, "app")) || fs.existsSync(path.join(earlyBaseDir, "src", "app")));
|
|
935
973
|
let resolvedReactPath = null;
|
|
936
974
|
let resolvedRscPath = null;
|
|
@@ -952,14 +990,12 @@ function vinext(options = {}) {
|
|
|
952
990
|
} });
|
|
953
991
|
const useCachePlugin = await createUseCacheCallablePlugin({
|
|
954
992
|
projectRoot: earlyBaseDir,
|
|
955
|
-
cacheRuntime: pathToFileURL(resolveShimModulePath(shimsDir, "cache-callable-runtime")).href
|
|
956
|
-
getAppDir: () => appDir,
|
|
957
|
-
matchesPageExtension: (fileName) => fileMatcher.extensionRegex.test(fileName)
|
|
993
|
+
cacheRuntime: pathToFileURL(resolveShimModulePath(shimsDir, "cache-callable-runtime")).href
|
|
958
994
|
});
|
|
959
995
|
const useServerIndex = plugins.findIndex((plugin) => plugin.name === "rsc:use-server");
|
|
960
996
|
if (useServerIndex === -1) throw new Error("vinext: Failed to locate @vitejs/plugin-rsc use-server plugin.");
|
|
961
997
|
plugins.splice(useServerIndex, 0, useCachePlugin);
|
|
962
|
-
return plugins;
|
|
998
|
+
return plugins.map(scopeRscPlugin);
|
|
963
999
|
}).catch((cause) => {
|
|
964
1000
|
throw new Error("vinext: Failed to load @vitejs/plugin-rsc.", { cause });
|
|
965
1001
|
});
|
|
@@ -968,8 +1004,6 @@ function vinext(options = {}) {
|
|
|
968
1004
|
manualUseCachePluginPromise = createUseCacheCallablePlugin({
|
|
969
1005
|
projectRoot: earlyBaseDir,
|
|
970
1006
|
cacheRuntime: pathToFileURL(resolveShimModulePath(shimsDir, "cache-callable-runtime")).href,
|
|
971
|
-
getAppDir: () => appDir,
|
|
972
|
-
matchesPageExtension: (fileName) => fileMatcher.extensionRegex.test(fileName),
|
|
973
1007
|
allowMissingRsc: true
|
|
974
1008
|
});
|
|
975
1009
|
}
|
|
@@ -1106,7 +1140,59 @@ function vinext(options = {}) {
|
|
|
1106
1140
|
transformBundledCommonJsDependencies = previous;
|
|
1107
1141
|
}
|
|
1108
1142
|
};
|
|
1143
|
+
const buildLifecyclePlugins = createBuildLifecyclePlugins({
|
|
1144
|
+
isEnabled: (builder) => buildLifecycleEnabled && builder.config.build.write !== false && !builder.config.build.lib && (buildLifecycleInvocation !== void 0 || !builder.config.build.watch && !builder.config.build.ssr && getBuildBundlerOptions(builder.config.build)?.input === void 0),
|
|
1145
|
+
onComplete: () => buildLifecycleInvocation?.onComplete?.(),
|
|
1146
|
+
shouldDeferPostBuild: () => buildLifecycleInvocation !== void 0,
|
|
1147
|
+
shouldPrepare: (config) => buildLifecycleEnabled && config.build?.write !== false && !config.build?.lib && (buildLifecycleInvocation !== void 0 || !config.build?.watch && !config.build?.ssr && getBuildBundlerOptions(config.build)?.input === void 0),
|
|
1148
|
+
onPrepare: () => {
|
|
1149
|
+
if (!hasAppDir || reactUpgradeChecked) return;
|
|
1150
|
+
reactUpgradeChecked = true;
|
|
1151
|
+
const reactUpgrade = getReactUpgradeDeps(root);
|
|
1152
|
+
if (reactUpgrade.length === 0) return;
|
|
1153
|
+
const [packageManager, ...packageManagerArgs] = detectPackageManager(root).replace(/ -D$/, "").split(" ");
|
|
1154
|
+
console.log(" Upgrading React for RSC compatibility...");
|
|
1155
|
+
execFileSync(packageManager, [...packageManagerArgs, ...reactUpgrade], {
|
|
1156
|
+
cwd: root,
|
|
1157
|
+
stdio: "inherit",
|
|
1158
|
+
shell: process.platform === "win32"
|
|
1159
|
+
});
|
|
1160
|
+
},
|
|
1161
|
+
shouldBuildPlainPages: () => !hasAppDir && !hasCloudflarePlugin && !hasNitroPlugin,
|
|
1162
|
+
createContext: () => ({
|
|
1163
|
+
cacheConfig: options.cache ?? null,
|
|
1164
|
+
configNodeEnv: viteCliBuildConfigNodeEnv,
|
|
1165
|
+
createPagesOnlyPlugins: (pagesClientAssetsModule) => vinext({
|
|
1166
|
+
...options,
|
|
1167
|
+
disableAppRouter: true,
|
|
1168
|
+
precompress: false,
|
|
1169
|
+
prerender: void 0,
|
|
1170
|
+
__skipBuildLifecycle: true,
|
|
1171
|
+
__pagesClientAssetsModule: pagesClientAssetsModule
|
|
1172
|
+
}),
|
|
1173
|
+
emptyOutDir: buildEmptyOutDir,
|
|
1174
|
+
hasAppDir,
|
|
1175
|
+
hasPagesDir,
|
|
1176
|
+
nextConfig,
|
|
1177
|
+
prerenderConfig,
|
|
1178
|
+
prerenderConcurrency: prerenderConfig?.concurrency,
|
|
1179
|
+
prerenderSecret,
|
|
1180
|
+
previewBuildCredentials,
|
|
1181
|
+
revalidateSecret,
|
|
1182
|
+
root,
|
|
1183
|
+
routeRootConfig: {
|
|
1184
|
+
appDir: options.appDir,
|
|
1185
|
+
disableAppRouter: options.disableAppRouter,
|
|
1186
|
+
rscOutDir: options.rscOutDir,
|
|
1187
|
+
ssrOutDir: options.ssrOutDir
|
|
1188
|
+
},
|
|
1189
|
+
rscBuildIdentity,
|
|
1190
|
+
rscCompatibilityId,
|
|
1191
|
+
skipHybridPagesBundle: hasCloudflarePlugin
|
|
1192
|
+
})
|
|
1193
|
+
});
|
|
1109
1194
|
const plugins = [
|
|
1195
|
+
buildLifecyclePlugins[0],
|
|
1110
1196
|
createStyledJsxPlugin(earlyBaseDir),
|
|
1111
1197
|
mdxProxyPlugin,
|
|
1112
1198
|
reactPluginPromise,
|
|
@@ -1173,6 +1259,7 @@ function vinext(options = {}) {
|
|
|
1173
1259
|
}),
|
|
1174
1260
|
dataUrlCssPlugin(),
|
|
1175
1261
|
createCssModuleImportCompatibilityPlugin(),
|
|
1262
|
+
createDevServerLifecyclePlugin({}, (config) => config[VINEXT_DEV_CLI_LIFECYCLE] === true),
|
|
1176
1263
|
{
|
|
1177
1264
|
name: "vinext:config",
|
|
1178
1265
|
enforce: "pre",
|
|
@@ -1186,8 +1273,14 @@ function vinext(options = {}) {
|
|
|
1186
1273
|
},
|
|
1187
1274
|
[VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY]: options.cache ?? null,
|
|
1188
1275
|
async config(config, env) {
|
|
1276
|
+
hasPlainPagesBuildEnvironments = false;
|
|
1277
|
+
originalPlainPagesEnvironments = void 0;
|
|
1278
|
+
buildEmptyOutDir = typeof config.build?.emptyOutDir === "boolean" ? config.build.emptyOutDir : void 0;
|
|
1189
1279
|
isServeCommand = env.command === "serve";
|
|
1190
|
-
root = toSlash(config.root ??
|
|
1280
|
+
root = path.resolve(toSlash(process.cwd()), config.root ?? ".");
|
|
1281
|
+
const devCliLifecycleEnabled = env.command === "serve" && env.isPreview !== true && claimViteCliDevInvocation(root, config["__vinextDevRestart"] === true, reservedDevCliInvocation && config.configFile === false);
|
|
1282
|
+
buildLifecycleInvocation = config[VINEXT_BUILD_LIFECYCLE_CONFIG];
|
|
1283
|
+
buildLifecycleEnabled = env.command === "build" && !internalOptions.__skipBuildLifecycle && (buildLifecycleInvocation !== void 0 || claimViteCliBuildInvocation());
|
|
1191
1284
|
const userResolve = config.resolve;
|
|
1192
1285
|
let tsconfigPathAliases = {};
|
|
1193
1286
|
let sassTsconfigPathAliases = [];
|
|
@@ -1204,8 +1297,11 @@ function vinext(options = {}) {
|
|
|
1204
1297
|
if (env?.command === "build" || env?.isPreview === true) resolvedNodeEnv = "production";
|
|
1205
1298
|
else if (mode === "test") resolvedNodeEnv = "test";
|
|
1206
1299
|
else resolvedNodeEnv = "development";
|
|
1207
|
-
if (process.env.NODE_ENV !== resolvedNodeEnv) Reflect.set(process.env, "NODE_ENV", resolvedNodeEnv);
|
|
1208
|
-
if (env?.command === "build")
|
|
1300
|
+
if (!(process.env.NODE_ENV === "test" && viteCliBuildConfigNodeEnv === "test") && process.env.NODE_ENV !== resolvedNodeEnv) Reflect.set(process.env, "NODE_ENV", resolvedNodeEnv);
|
|
1301
|
+
if (env?.command === "build") {
|
|
1302
|
+
previewBuildCredentials = getPreviewBuildCredentials() ?? createPreviewBuildCredentials();
|
|
1303
|
+
if (buildLifecycleEnabled) revalidateSecret ??= randomBytes(32).toString("hex");
|
|
1304
|
+
}
|
|
1209
1305
|
draftModeSecret = previewBuildCredentials?.id ?? getPagesPreviewModeId();
|
|
1210
1306
|
let baseDir;
|
|
1211
1307
|
if (options.appDir) {
|
|
@@ -1245,6 +1341,7 @@ function vinext(options = {}) {
|
|
|
1245
1341
|
buildId: sharedBuildId
|
|
1246
1342
|
};
|
|
1247
1343
|
}
|
|
1344
|
+
if (env?.command === "build" && earlyViteCliInvocation?.command === "build") Reflect.set(process.env, "NODE_ENV", "production");
|
|
1248
1345
|
const configuredTsconfigPath = isUnknownRecord(nextConfig.typescript) ? typeof nextConfig.typescript.tsconfigPath === "string" ? nextConfig.typescript.tsconfigPath : void 0 : void 0;
|
|
1249
1346
|
const resolvedTsconfigAliases = resolveTsconfigAliases(root, configuredTsconfigPath);
|
|
1250
1347
|
tsconfigPathAliases = resolvedTsconfigAliases.vite;
|
|
@@ -1401,7 +1498,7 @@ function vinext(options = {}) {
|
|
|
1401
1498
|
resolvedServerExternalPackages = nextServerExternal;
|
|
1402
1499
|
const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
|
|
1403
1500
|
const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
|
|
1404
|
-
const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
|
|
1501
|
+
const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput && !config.build?.lib;
|
|
1405
1502
|
const hasClientBuildEnvironment = hasAppDir || hasCloudflarePlugin || hasNitroPlugin || shouldInjectPlainPagesEnvironments;
|
|
1406
1503
|
const clientAssetsDir = resolveAssetsDir(nextConfig.assetPrefix ?? "");
|
|
1407
1504
|
clientAssetsInlineLimit = config.build?.assetsInlineLimit ?? 0;
|
|
@@ -1421,6 +1518,11 @@ function vinext(options = {}) {
|
|
|
1421
1518
|
}
|
|
1422
1519
|
const viteConfig = {
|
|
1423
1520
|
appType: "custom",
|
|
1521
|
+
...devCliLifecycleEnabled ? { [VINEXT_DEV_CLI_LIFECYCLE]: true } : {},
|
|
1522
|
+
...!hasAppDir && hasCloudflarePlugin ? { builder: {
|
|
1523
|
+
...config.builder,
|
|
1524
|
+
sharedConfigBuild: true
|
|
1525
|
+
} } : {},
|
|
1424
1526
|
build: {
|
|
1425
1527
|
ssrEmitAssets: true,
|
|
1426
1528
|
cssTarget: [
|
|
@@ -1454,7 +1556,10 @@ function vinext(options = {}) {
|
|
|
1454
1556
|
},
|
|
1455
1557
|
hmr: devHmrConfig
|
|
1456
1558
|
},
|
|
1457
|
-
...hasCloudflarePlugin || hasNitroPlugin ? {} : config.ssr?.external === true ? { ssr: {
|
|
1559
|
+
...hasCloudflarePlugin || hasNitroPlugin ? {} : config.ssr?.external === true ? { ssr: {
|
|
1560
|
+
external: true,
|
|
1561
|
+
noExternal: [...PATCHED_SERVER_PACKAGES]
|
|
1562
|
+
} } : { ssr: {
|
|
1458
1563
|
external: [
|
|
1459
1564
|
"react",
|
|
1460
1565
|
"react-dom",
|
|
@@ -1567,7 +1672,7 @@ function vinext(options = {}) {
|
|
|
1567
1672
|
...env?.command === "serve" && _canExternalizeAppRscHandler ? ["vinext/server/app-rsc-combined-handler", "vinext/server/app-rsc-handler"] : [],
|
|
1568
1673
|
...userSsrExternal
|
|
1569
1674
|
],
|
|
1570
|
-
|
|
1675
|
+
noExternal: userSsrExternal === true ? [...PATCHED_SERVER_PACKAGES] : true
|
|
1571
1676
|
} },
|
|
1572
1677
|
optimizeDeps: {
|
|
1573
1678
|
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE),
|
|
@@ -1590,7 +1695,7 @@ function vinext(options = {}) {
|
|
|
1590
1695
|
"ipaddr.js",
|
|
1591
1696
|
...externalizeSsrReactInDev ? SSR_EXTERNAL_REACT_ENTRIES : []
|
|
1592
1697
|
],
|
|
1593
|
-
|
|
1698
|
+
noExternal: userSsrExternal === true ? [...PATCHED_SERVER_PACKAGES] : true
|
|
1594
1699
|
} },
|
|
1595
1700
|
optimizeDeps: {
|
|
1596
1701
|
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["ipaddr.js"], userSsrExternal === true || externalizeSsrReactInDev ? SSR_EXTERNAL_REACT_ENTRIES : []),
|
|
@@ -1647,50 +1752,55 @@ function vinext(options = {}) {
|
|
|
1647
1752
|
})
|
|
1648
1753
|
}
|
|
1649
1754
|
} };
|
|
1650
|
-
else if (shouldInjectPlainPagesEnvironments)
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
ssr: {
|
|
1671
|
-
resolve: {
|
|
1672
|
-
external: [
|
|
1673
|
-
"react",
|
|
1674
|
-
"react-dom",
|
|
1675
|
-
"react-dom/server",
|
|
1676
|
-
"ipaddr.js",
|
|
1677
|
-
...nextServerExternal
|
|
1678
|
-
],
|
|
1679
|
-
noExternal: true
|
|
1680
|
-
},
|
|
1681
|
-
optimizeDeps: {
|
|
1682
|
-
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["ipaddr.js"], Object.keys(nextShimMap)),
|
|
1683
|
-
...depOptimizeNodeEnvOptions
|
|
1755
|
+
else if (shouldInjectPlainPagesEnvironments) {
|
|
1756
|
+
const plainPagesEnvironments = {
|
|
1757
|
+
client: {
|
|
1758
|
+
consumer: "client",
|
|
1759
|
+
optimizeDeps: {
|
|
1760
|
+
include: ["react-dom/client"],
|
|
1761
|
+
...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
|
|
1762
|
+
...depOptimizeNodeEnvOptions
|
|
1763
|
+
},
|
|
1764
|
+
build: {
|
|
1765
|
+
outDir: "dist/client",
|
|
1766
|
+
manifest: true,
|
|
1767
|
+
ssrManifest: true,
|
|
1768
|
+
assetsInlineLimit: clientAssetsInlineLimit,
|
|
1769
|
+
...withBuildBundlerOptions({
|
|
1770
|
+
input: { index: VIRTUAL_CLIENT_ENTRY },
|
|
1771
|
+
output: getClientOutputConfig(clientAssetsDir),
|
|
1772
|
+
treeshake: getClientTreeshakeConfig()
|
|
1773
|
+
})
|
|
1774
|
+
}
|
|
1684
1775
|
},
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1776
|
+
ssr: {
|
|
1777
|
+
resolve: {
|
|
1778
|
+
external: [
|
|
1779
|
+
"react",
|
|
1780
|
+
"react-dom",
|
|
1781
|
+
"react-dom/server",
|
|
1782
|
+
"ipaddr.js",
|
|
1783
|
+
...nextServerExternal
|
|
1784
|
+
],
|
|
1785
|
+
noExternal: true
|
|
1786
|
+
},
|
|
1787
|
+
optimizeDeps: {
|
|
1788
|
+
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["ipaddr.js"], Object.keys(nextShimMap)),
|
|
1789
|
+
...depOptimizeNodeEnvOptions
|
|
1790
|
+
},
|
|
1791
|
+
build: {
|
|
1792
|
+
outDir: "dist/server",
|
|
1793
|
+
...withBuildBundlerOptions({
|
|
1794
|
+
input: { index: hasNitroPlugin ? VIRTUAL_WORKER_ENTRY : VIRTUAL_SERVER_ENTRY },
|
|
1795
|
+
output: { entryFileNames: "entry.js" }
|
|
1796
|
+
})
|
|
1797
|
+
}
|
|
1691
1798
|
}
|
|
1692
|
-
}
|
|
1693
|
-
|
|
1799
|
+
};
|
|
1800
|
+
originalPlainPagesEnvironments = config.environments;
|
|
1801
|
+
viteConfig.environments = plainPagesEnvironments;
|
|
1802
|
+
hasPlainPagesBuildEnvironments = env.command === "build";
|
|
1803
|
+
}
|
|
1694
1804
|
if (pagesOptimizeEntries.length > 0 && !hasCloudflarePlugin) viteConfig.optimizeDeps = {
|
|
1695
1805
|
...viteConfig.optimizeDeps,
|
|
1696
1806
|
entries: pagesOptimizeEntries
|
|
@@ -1722,6 +1832,12 @@ function vinext(options = {}) {
|
|
|
1722
1832
|
return null;
|
|
1723
1833
|
},
|
|
1724
1834
|
async configResolved(config) {
|
|
1835
|
+
if (isServeCommand && !config["__vinextDevCliLifecycle"] && config.configFile && isViteCliConfigFile(config.configFile, config.inlineConfig)) {
|
|
1836
|
+
if (claimViteCliDevInvocation(config.root, false, true)) {
|
|
1837
|
+
config[VINEXT_DEV_CLI_LIFECYCLE] = true;
|
|
1838
|
+
if (!config.server.middlewareMode) applyDevServerDefaults(config.server, {});
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1725
1841
|
if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir) suppressOptionalOptimizeDepsWarnings(config.logger);
|
|
1726
1842
|
if (config.worker?.rolldownOptions) {
|
|
1727
1843
|
const workerFileNames = `${resolveAssetsDir(nextConfig.assetPrefix ?? "")}/workers/[name]-[hash].js`;
|
|
@@ -2125,6 +2241,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2125
2241
|
transform: {
|
|
2126
2242
|
filter: { id: /virtual:|\.[cm]?[jt]sx?(?:\?|$)/ },
|
|
2127
2243
|
handler(code, id) {
|
|
2244
|
+
const environment = this.environment;
|
|
2245
|
+
if (!isServeCommand && (!environment || !isMultiStageServerEnvironment(environment))) return null;
|
|
2128
2246
|
const transformed = matchedMultiStageOutput?.transformHostEntry?.({
|
|
2129
2247
|
code,
|
|
2130
2248
|
id
|
|
@@ -2367,6 +2485,18 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2367
2485
|
return `http://localhost:${typeof address === "object" && address ? address.port : server.config.server.port ?? 3e3}`;
|
|
2368
2486
|
};
|
|
2369
2487
|
let cachedSSRHandler = null;
|
|
2488
|
+
const devPageRouteDataKinds = /* @__PURE__ */ new Map();
|
|
2489
|
+
function classifyDevPageFile(filePath) {
|
|
2490
|
+
const cached = devPageRouteDataKinds.get(filePath);
|
|
2491
|
+
if (cached) return cached;
|
|
2492
|
+
let dataKind = "none";
|
|
2493
|
+
try {
|
|
2494
|
+
const source = fs.readFileSync(filePath, "utf8");
|
|
2495
|
+
dataKind = hasExportedName(source, "getStaticProps") ? "static" : hasExportedName(source, "getServerSideProps") ? "server" : "none";
|
|
2496
|
+
} catch {}
|
|
2497
|
+
devPageRouteDataKinds.set(filePath, dataKind);
|
|
2498
|
+
return dataKind;
|
|
2499
|
+
}
|
|
2370
2500
|
function getPagesRunner() {
|
|
2371
2501
|
if (!pagesRunner) {
|
|
2372
2502
|
const env = server.environments["ssr"] ?? Object.values(server.environments).find((e) => e !== server.environments["rsc"]) ?? Object.values(server.environments)[0];
|
|
@@ -2420,6 +2550,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2420
2550
|
}
|
|
2421
2551
|
pagesRunner?.clearCache();
|
|
2422
2552
|
}
|
|
2553
|
+
function invalidatePagesHydrationProxies() {
|
|
2554
|
+
const graph = server.environments.client?.moduleGraph;
|
|
2555
|
+
if (!graph) return;
|
|
2556
|
+
for (const mod of graph.idToModuleMap.values()) if (mod.id?.includes("?html-proxy&index=")) graph.invalidateModule(mod);
|
|
2557
|
+
}
|
|
2423
2558
|
function invalidateAppRoutingModules() {
|
|
2424
2559
|
invalidateAppRouteCache();
|
|
2425
2560
|
invalidateMetadataFileCache();
|
|
@@ -2531,13 +2666,20 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2531
2666
|
if (hasAppDir) invalidateRscEntryModule();
|
|
2532
2667
|
if (hasCloudflarePlugin && hasPagesDir && !hasAppDir) invalidatePagesServerEntry();
|
|
2533
2668
|
};
|
|
2669
|
+
function invalidatePagesMiddlewareMatcher(filePath) {
|
|
2670
|
+
if (!hasPagesDir || !middlewarePath || toSlash(filePath) !== middlewarePath) return;
|
|
2671
|
+
cachedSSRHandler = null;
|
|
2672
|
+
server.ws.send({ type: "full-reload" });
|
|
2673
|
+
}
|
|
2534
2674
|
server.watcher.on("add", (filePath) => {
|
|
2675
|
+
invalidatePagesMiddlewareMatcher(filePath);
|
|
2535
2676
|
updatePublicFileRoute(filePath, true);
|
|
2536
2677
|
let routeChanged = false;
|
|
2537
2678
|
const pagesAppChanged = isPagesAppFile(filePath);
|
|
2538
2679
|
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
2539
2680
|
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
|
|
2540
2681
|
if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
2682
|
+
devPageRouteDataKinds.delete(toSlash(filePath));
|
|
2541
2683
|
invalidateRouteCache(pagesDir);
|
|
2542
2684
|
routeChanged = true;
|
|
2543
2685
|
}
|
|
@@ -2548,23 +2690,37 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2548
2690
|
}
|
|
2549
2691
|
if (routeChanged) {
|
|
2550
2692
|
invalidatePagesServerEntry();
|
|
2693
|
+
if (hasPagesDir) invalidatePagesHydrationProxies();
|
|
2551
2694
|
if (!hasAppDir) server.ws.send({ type: "full-reload" });
|
|
2552
2695
|
invalidateHybridClientEntries();
|
|
2553
2696
|
revalidateHybridRoutes();
|
|
2554
2697
|
}
|
|
2555
2698
|
});
|
|
2556
2699
|
server.watcher.on("change", (filePath) => {
|
|
2700
|
+
invalidatePagesMiddlewareMatcher(filePath);
|
|
2701
|
+
if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
2702
|
+
const pageFile = toSlash(filePath);
|
|
2703
|
+
const previousKind = devPageRouteDataKinds.get(pageFile);
|
|
2704
|
+
devPageRouteDataKinds.delete(pageFile);
|
|
2705
|
+
if (previousKind !== void 0 && previousKind !== classifyDevPageFile(pageFile)) {
|
|
2706
|
+
cachedSSRHandler = null;
|
|
2707
|
+
invalidatePagesHydrationProxies();
|
|
2708
|
+
server.ws.send({ type: "full-reload" });
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2557
2711
|
const pagesAppChanged = isPagesAppFile(filePath);
|
|
2558
2712
|
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
2559
2713
|
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
|
|
2560
2714
|
});
|
|
2561
2715
|
server.watcher.on("unlink", (filePath) => {
|
|
2716
|
+
invalidatePagesMiddlewareMatcher(filePath);
|
|
2562
2717
|
updatePublicFileRoute(filePath, false);
|
|
2563
2718
|
let routeChanged = false;
|
|
2564
2719
|
const pagesAppChanged = isPagesAppFile(filePath);
|
|
2565
2720
|
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
2566
2721
|
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
|
|
2567
2722
|
if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
2723
|
+
devPageRouteDataKinds.delete(toSlash(filePath));
|
|
2568
2724
|
invalidateRouteCache(pagesDir);
|
|
2569
2725
|
routeChanged = true;
|
|
2570
2726
|
}
|
|
@@ -2575,6 +2731,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2575
2731
|
}
|
|
2576
2732
|
if (routeChanged) {
|
|
2577
2733
|
invalidatePagesServerEntry();
|
|
2734
|
+
if (hasPagesDir) invalidatePagesHydrationProxies();
|
|
2578
2735
|
if (!hasAppDir) server.ws.send({ type: "full-reload" });
|
|
2579
2736
|
invalidateHybridClientEntries();
|
|
2580
2737
|
revalidateHybridRoutes();
|
|
@@ -2931,18 +3088,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2931
3088
|
const getDevApiRoutes = () => devApiRoutesPromise ??= apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
2932
3089
|
let devAppRoutesPromise = null;
|
|
2933
3090
|
const getDevAppRoutes = () => devAppRoutesPromise ??= hasAppDir && appDir ? appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : Promise.resolve([]);
|
|
2934
|
-
const
|
|
2935
|
-
const classifyDevPageRoute = (route) => {
|
|
2936
|
-
const cached = devPageRouteDataKinds.get(route.filePath);
|
|
2937
|
-
if (cached) return cached;
|
|
2938
|
-
let dataKind = "none";
|
|
2939
|
-
try {
|
|
2940
|
-
const source = fs.readFileSync(route.filePath, "utf8");
|
|
2941
|
-
dataKind = hasExportedName(source, "getStaticProps") ? "static" : hasExportedName(source, "getServerSideProps") ? "server" : "none";
|
|
2942
|
-
} catch {}
|
|
2943
|
-
devPageRouteDataKinds.set(route.filePath, dataKind);
|
|
2944
|
-
return dataKind;
|
|
2945
|
-
};
|
|
3091
|
+
const classifyDevPageRoute = (route) => classifyDevPageFile(route.filePath);
|
|
2946
3092
|
const pipelineDeps = {
|
|
2947
3093
|
basePath: bp,
|
|
2948
3094
|
trailingSlash: nextConfig?.trailingSlash ?? false,
|
|
@@ -3079,7 +3225,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3079
3225
|
}
|
|
3080
3226
|
if (!cachedSSRHandler || cachedSSRHandler.routes !== routes) cachedSSRHandler = {
|
|
3081
3227
|
routes,
|
|
3082
|
-
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true, nextConfig?.expireTime, nextConfig?.crossOrigin, devBuildId)
|
|
3228
|
+
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true, nextConfig?.expireTime, nextConfig?.crossOrigin, devBuildId, middlewarePath ? compileClientMiddlewareMatchers(extractMiddlewareMatcherConfig(middlewarePath)) : void 0, classifyDevPageRoute)
|
|
3083
3229
|
};
|
|
3084
3230
|
flushStagedHeaders();
|
|
3085
3231
|
flushRequestHeaders();
|
|
@@ -3276,8 +3422,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3276
3422
|
const serverDefines = { ...nextConfig.compilerDefineServer };
|
|
3277
3423
|
serverDefines["process.env.NEXT_RUNTIME"] = JSON.stringify("nodejs");
|
|
3278
3424
|
serverDefines["process.env.NEXT_PHASE"] = "globalThis.__VINEXT_NEXT_PHASE";
|
|
3279
|
-
|
|
3280
|
-
if (sharedRevalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(sharedRevalidateSecret);
|
|
3425
|
+
if (revalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(revalidateSecret);
|
|
3281
3426
|
if (previewBuildCredentials) {
|
|
3282
3427
|
serverDefines["process.env.__VINEXT_PREVIEW_MODE_ID"] = JSON.stringify(previewBuildCredentials.id);
|
|
3283
3428
|
serverDefines["process.env.__VINEXT_PREVIEW_MODE_SIGNING_KEY"] = JSON.stringify(previewBuildCredentials.signingKey);
|
|
@@ -3452,7 +3597,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3452
3597
|
sequential: true,
|
|
3453
3598
|
order: "post",
|
|
3454
3599
|
handler() {
|
|
3455
|
-
if (buildIdWritten) return;
|
|
3600
|
+
if (buildIdWritten || !isServerEnvironment(this.environment)) return;
|
|
3456
3601
|
buildIdWritten = true;
|
|
3457
3602
|
const outDir = path.join(root, "dist", "server");
|
|
3458
3603
|
fs.mkdirSync(outDir, { recursive: true });
|
|
@@ -3664,14 +3809,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3664
3809
|
dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0,
|
|
3665
3810
|
crossOrigin: nextConfig.crossOrigin ?? ""
|
|
3666
3811
|
});
|
|
3667
|
-
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
3668
|
-
if (hasAppDir && hasPagesDir && buildSession) setPagesClientAssetsBuildMetadata(buildSession, pagesClientAssetsModule);
|
|
3669
|
-
}
|
|
3670
|
-
if (pagesClientAssetsModule === null) {
|
|
3671
|
-
if (pagesClientAssetsOutputDirs.size === 0) return;
|
|
3672
|
-
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
3673
|
-
if (buildSession) pagesClientAssetsModule = takePagesClientAssetsBuildMetadata(buildSession);
|
|
3674
3812
|
}
|
|
3813
|
+
if (pagesClientAssetsModule === null && pagesClientAssetsOutputDirs.size === 0) return;
|
|
3675
3814
|
if (pagesClientAssetsModule === null) {
|
|
3676
3815
|
const emptyModule = buildPagesClientAssetsModule({});
|
|
3677
3816
|
for (const outputDir of pagesClientAssetsOutputDirs) writePagesClientAssetsModuleIfMissing(outputDir, emptyModule);
|
|
@@ -3743,6 +3882,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3743
3882
|
}
|
|
3744
3883
|
},
|
|
3745
3884
|
createWasmModuleImportPlugin(),
|
|
3885
|
+
createOgHarfbuzzPlugin(),
|
|
3746
3886
|
{
|
|
3747
3887
|
name: "vinext:og-font-patch",
|
|
3748
3888
|
enforce: "pre",
|
|
@@ -3843,6 +3983,27 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3843
3983
|
plugins.push(createRscReferenceValidationNormalizerPlugin());
|
|
3844
3984
|
plugins.push(createRscClientReferenceLoadersPlugin());
|
|
3845
3985
|
} else if (manualUseCachePluginPromise) plugins.push(manualUseCachePluginPromise);
|
|
3986
|
+
plugins.push({
|
|
3987
|
+
name: "vinext:plain-pages-build-config",
|
|
3988
|
+
apply: "build",
|
|
3989
|
+
enforce: "post",
|
|
3990
|
+
config: {
|
|
3991
|
+
order: "post",
|
|
3992
|
+
handler(config) {
|
|
3993
|
+
if (!hasPlainPagesBuildEnvironments) return;
|
|
3994
|
+
if (config.build?.watch || config.build?.ssr || config.build?.lib || getBuildBundlerOptions(config.build)?.input !== void 0) {
|
|
3995
|
+
for (const name of ["client", "ssr"]) if (originalPlainPagesEnvironments?.[name]) config.environments[name] = originalPlainPagesEnvironments[name];
|
|
3996
|
+
else delete config.environments?.[name];
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
return { builder: {
|
|
4000
|
+
...config.builder,
|
|
4001
|
+
sharedConfigBuild: true
|
|
4002
|
+
} };
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
});
|
|
4006
|
+
plugins.push(buildLifecyclePlugins[1]);
|
|
3846
4007
|
return plugins;
|
|
3847
4008
|
}
|
|
3848
4009
|
/**
|