Unverified Commit 97f42091 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move adapterPath from experimental to stable top-level config (#91535)

## Move `adapterPath` from experimental to stable

Graduates `adapterPath` from `experimental.adapterPath` to a top-level
`NextConfig` option, following the same pattern used for
`cacheHandlers`, `cacheComponents`, `typedRoutes`, and other options
that moved out of experimental.

### Changes

- **Type definition** (`config-shared.ts`): Added `adapterPath` to
`NextConfig` interface, marked `ExperimentalConfig.adapterPath` as
`@deprecated`, moved default value to top-level in `defaultConfig`,
updated `NextConfigRuntime` and `getNextConfigRuntime`
- **Zod schema** (`config-schema.ts`): Added `adapterPath` to top-level
`configSchema`
- **Backward compat** (`config.ts`): Added
`warnOptionHasBeenMovedOutOfExperimental` call so existing
`experimental.adapterPath` configs still work with a deprecation
warning, updated `applyModifyConfig` to read from `config.adapterPath`
- **Runtime references**: Updated `build/index.ts`, `app-page.ts`,
`app-route.ts`, `pages-handler.ts` to use `config.adapterPath` /
`nextConfig.adapterPath`
- **Tests**: Updated 4 test fixture `next.config` files
- **Docs**: Updated app router doc (removed `version: experimental`
frontmatter, top-level config example), pages router doc title, and v16
upgrade guide
parent 668f8e3a
...@@ -1040,7 +1040,7 @@ const nextConfig = { ...@@ -1040,7 +1040,7 @@ const nextConfig = {
module.exports = nextConfig module.exports = nextConfig
``` ```
Share your feedback in the [RFC discussion](https://github.com/vercel/next.js/discussions/77740). `adapterPath` was promoted to a stable, top-level option in 16.2.0. See [`adapterPath`](/docs/app/api-reference/config/next-config-js/adapterPath) for the current API reference.
## Modern Sass API ## Modern Sass API
......
--- ---
title: adapterPath title: adapterPath
description: Configure a custom adapter for Next.js to hook into the build process. description: Configure a custom adapter for Next.js to hook into the build process.
version: experimental
--- ---
Next.js provides a built-in adapters API. It allows deployment platforms or build systems to integrate with the Next.js build process. Next.js provides a built-in adapters API. It allows deployment platforms or build systems to integrate with the Next.js build process.
...@@ -10,14 +9,12 @@ For a full reference implementation, see the [`nextjs/adapter-vercel`](https://g ...@@ -10,14 +9,12 @@ For a full reference implementation, see the [`nextjs/adapter-vercel`](https://g
## Configuration ## Configuration
To use an adapter, specify the path to your adapter module in `experimental.adapterPath`: To use an adapter, specify the path to your adapter module in `adapterPath`:
```js filename="next.config.js" ```js filename="next.config.js"
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
experimental: { adapterPath: require.resolve('./my-adapter.js'),
adapterPath: require.resolve('./my-adapter.js'),
},
} }
module.exports = nextConfig module.exports = nextConfig
......
--- ---
title: experimental.adapterPath title: adapterPath
description: Configure a custom adapter for Next.js to hook into the build process with modifyConfig and buildComplete callbacks. description: Configure a custom adapter for Next.js to hook into the build process with modifyConfig and buildComplete callbacks.
source: app/api-reference/config/next-config-js/adapterPath source: app/api-reference/config/next-config-js/adapterPath
--- ---
......
...@@ -4122,7 +4122,7 @@ export default async function build( ...@@ -4122,7 +4122,7 @@ export default async function build(
// This should come after output: export handling but before // This should come after output: export handling but before
// output: standalone, in the future output: standalone might // output: standalone, in the future output: standalone might
// not be allowed if an adapter with onBuildComplete is configured // not be allowed if an adapter with onBuildComplete is configured
const adapterPath = config.experimental.adapterPath const adapterPath = config.adapterPath
if (adapterPath) { if (adapterPath) {
await nextBuildSpan await nextBuildSpan
.traceChild('adapter-handle-build-complete') .traceChild('adapter-handle-build-complete')
......
...@@ -1059,7 +1059,7 @@ export async function handler( ...@@ -1059,7 +1059,7 @@ export async function handler(
// When fallback isn't present, abort this render so we 404 // When fallback isn't present, abort this render so we 404
fallbackMode === FallbackMode.NOT_FOUND fallbackMode === FallbackMode.NOT_FOUND
) { ) {
if (nextConfig.experimental.adapterPath) { if (nextConfig.adapterPath) {
return await render404() return await render404()
} }
throw new NoFallbackError() throw new NoFallbackError()
......
...@@ -160,7 +160,7 @@ export async function handler( ...@@ -160,7 +160,7 @@ export async function handler(
if (prerenderInfo) { if (prerenderInfo) {
if (prerenderInfo.fallback === false && !isPrerendered) { if (prerenderInfo.fallback === false && !isPrerendered) {
if (nextConfig.experimental.adapterPath) { if (nextConfig.adapterPath) {
return await render404() return await render404()
} }
throw new NoFallbackError() throw new NoFallbackError()
......
...@@ -188,7 +188,6 @@ const zTurbopackConfig: zod.ZodType<TurbopackOptions> = z.strictObject({ ...@@ -188,7 +188,6 @@ const zTurbopackConfig: zod.ZodType<TurbopackOptions> = z.strictObject({
}) })
export const experimentalSchema = { export const experimentalSchema = {
adapterPath: z.string().optional(),
useSkewCookie: z.boolean().optional(), useSkewCookie: z.boolean().optional(),
after: z.boolean().optional(), after: z.boolean().optional(),
appNavFailHandling: z.boolean().optional(), appNavFailHandling: z.boolean().optional(),
...@@ -411,6 +410,7 @@ export const experimentalSchema = { ...@@ -411,6 +410,7 @@ export const experimentalSchema = {
export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
z.strictObject({ z.strictObject({
adapterPath: z.string().optional(),
allowedDevOrigins: z.array(z.string()).optional(), allowedDevOrigins: z.array(z.string()).optional(),
assetPrefix: z.string().optional(), assetPrefix: z.string().optional(),
basePath: z.string().optional(), basePath: z.string().optional(),
......
...@@ -393,7 +393,6 @@ export interface LightningCssFeatures { ...@@ -393,7 +393,6 @@ export interface LightningCssFeatures {
} }
export interface ExperimentalConfig { export interface ExperimentalConfig {
adapterPath?: string
appNewScrollHandler?: boolean appNewScrollHandler?: boolean
useSkewCookie?: boolean useSkewCookie?: boolean
/** @deprecated use top-level `cacheHandlers` instead */ /** @deprecated use top-level `cacheHandlers` instead */
...@@ -1258,6 +1257,12 @@ export interface NextConfig { ...@@ -1258,6 +1257,12 @@ export interface NextConfig {
*/ */
cacheHandler?: string | undefined cacheHandler?: string | undefined
/**
* Path to a custom adapter module for deployment platform integration.
* Can also be set via the `NEXT_ADAPTER_PATH` environment variable.
*/
adapterPath?: string
cacheHandlers?: { cacheHandlers?: {
default?: string default?: string
remote?: string remote?: string
...@@ -1707,8 +1712,8 @@ export const defaultConfig = Object.freeze({ ...@@ -1707,8 +1712,8 @@ export const defaultConfig = Object.freeze({
remote: process.env.NEXT_REMOTE_CACHE_HANDLER_PATH, remote: process.env.NEXT_REMOTE_CACHE_HANDLER_PATH,
static: process.env.NEXT_STATIC_CACHE_HANDLER_PATH, static: process.env.NEXT_STATIC_CACHE_HANDLER_PATH,
}, },
adapterPath: process.env.NEXT_ADAPTER_PATH || undefined,
experimental: { experimental: {
adapterPath: process.env.NEXT_ADAPTER_PATH || undefined,
appNewScrollHandler: false, appNewScrollHandler: false,
useSkewCookie: false, useSkewCookie: false,
cssChunking: true, cssChunking: true,
...@@ -1858,6 +1863,7 @@ export interface NextConfigRuntime { ...@@ -1858,6 +1863,7 @@ export interface NextConfigRuntime {
pageExtensions: NextConfigComplete['pageExtensions'] pageExtensions: NextConfigComplete['pageExtensions']
useFileSystemPublicRoutes: NextConfigComplete['useFileSystemPublicRoutes'] useFileSystemPublicRoutes: NextConfigComplete['useFileSystemPublicRoutes']
logging?: NextConfigComplete['logging'] logging?: NextConfigComplete['logging']
adapterPath?: NextConfigComplete['adapterPath']
experimental: Pick< experimental: Pick<
NextConfigComplete['experimental'], NextConfigComplete['experimental'],
...@@ -1872,7 +1878,6 @@ export interface NextConfigRuntime { ...@@ -1872,7 +1878,6 @@ export interface NextConfigRuntime {
| 'authInterrupts' | 'authInterrupts'
| 'clientTraceMetadata' | 'clientTraceMetadata'
| 'clientParamParsingOrigins' | 'clientParamParsingOrigins'
| 'adapterPath'
| 'allowedRevalidateHeaderKeys' | 'allowedRevalidateHeaderKeys'
| 'fetchCacheKeyPrefix' | 'fetchCacheKeyPrefix'
| 'isrFlushToDisk' | 'isrFlushToDisk'
...@@ -1938,10 +1943,6 @@ export function getNextConfigRuntime( ...@@ -1938,10 +1943,6 @@ export function getNextConfigRuntime(
authInterrupts: ex.authInterrupts, authInterrupts: ex.authInterrupts,
clientTraceMetadata: ex.clientTraceMetadata, clientTraceMetadata: ex.clientTraceMetadata,
clientParamParsingOrigins: ex.clientParamParsingOrigins, clientParamParsingOrigins: ex.clientParamParsingOrigins,
// The full adapterPath might be non-deterministic across builds and doesn't actually matter
// at runtime, as it's only used to determine whether the adapter was used or not, not to
// execute it again. So replace it with a placeholder if it's set.
adapterPath: ex.adapterPath ? '<ommited but set>' : undefined,
allowedRevalidateHeaderKeys: ex.allowedRevalidateHeaderKeys, allowedRevalidateHeaderKeys: ex.allowedRevalidateHeaderKeys,
fetchCacheKeyPrefix: ex.fetchCacheKeyPrefix, fetchCacheKeyPrefix: ex.fetchCacheKeyPrefix,
isrFlushToDisk: ex.isrFlushToDisk, isrFlushToDisk: ex.isrFlushToDisk,
...@@ -2002,6 +2003,9 @@ export function getNextConfigRuntime( ...@@ -2002,6 +2003,9 @@ export function getNextConfigRuntime(
poweredByHeader: config.poweredByHeader, poweredByHeader: config.poweredByHeader,
cacheHandler: config.cacheHandler, cacheHandler: config.cacheHandler,
cacheHandlers: config.cacheHandlers, cacheHandlers: config.cacheHandlers,
// The full adapterPath might be non-deterministic across builds and doesn't
// actually matter at runtime, so replace it with a placeholder if it's set.
adapterPath: config.adapterPath ? '<omitted but set>' : undefined,
cacheMaxMemorySize: config.cacheMaxMemorySize, cacheMaxMemorySize: config.cacheMaxMemorySize,
compress: config.compress, compress: config.compress,
i18n: config.i18n, i18n: config.i18n,
......
...@@ -798,6 +798,13 @@ function assignDefaultsAndValidate( ...@@ -798,6 +798,13 @@ function assignDefaultsAndValidate(
configFileName, configFileName,
silent silent
) )
warnOptionHasBeenMovedOutOfExperimental(
result,
'adapterPath',
'adapterPath',
configFileName,
silent
)
if ((result.experimental as any).outputStandalone) { if ((result.experimental as any).outputStandalone) {
if (!silent) { if (!silent) {
...@@ -1452,11 +1459,9 @@ async function applyModifyConfig( ...@@ -1452,11 +1459,9 @@ async function applyModifyConfig(
): Promise<NextConfigComplete> { ): Promise<NextConfigComplete> {
// we always call modify config and phase can be used to only // we always call modify config and phase can be used to only
// modify for specific times // modify for specific times
if (config.experimental?.adapterPath) { if (config.adapterPath) {
const adapterMod = interopDefault( const adapterMod = interopDefault(
await import( await import(pathToFileURL(require.resolve(config.adapterPath)).href)
pathToFileURL(require.resolve(config.experimental.adapterPath)).href
)
) as NextAdapter ) as NextAdapter
if (typeof adapterMod.modifyConfig === 'function') { if (typeof adapterMod.modifyConfig === 'function') {
......
...@@ -196,7 +196,7 @@ export const getHandler = ({ ...@@ -196,7 +196,7 @@ export const getHandler = ({
if (prerenderInfo) { if (prerenderInfo) {
if (prerenderInfo.fallback === false && !isPrerendered) { if (prerenderInfo.fallback === false && !isPrerendered) {
if (nextConfig.experimental.adapterPath) { if (nextConfig.adapterPath) {
return await render404() return await render404()
} }
throw new NoFallbackError() throw new NoFallbackError()
......
...@@ -3,10 +3,8 @@ ...@@ -3,10 +3,8 @@
*/ */
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { adapterPath:
adapterPath: process.env.NEXT_ADAPTER_PATH ?? require.resolve('./my-adapter.mjs'),
process.env.NEXT_ADAPTER_PATH ?? require.resolve('./my-adapter.mjs'),
},
} }
module.exports = nextConfig module.exports = nextConfig
...@@ -11,8 +11,6 @@ module.exports = { ...@@ -11,8 +11,6 @@ module.exports = {
}, },
] ]
}, },
experimental: { adapterPath:
adapterPath: process.env.NEXT_ADAPTER_PATH ?? require.resolve('./my-adapter.js'),
process.env.NEXT_ADAPTER_PATH ?? require.resolve('./my-adapter.js'),
},
} }
...@@ -3,9 +3,7 @@ const require = Module.createRequire(import.meta.url) ...@@ -3,9 +3,7 @@ const require = Module.createRequire(import.meta.url)
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
experimental: { adapterPath: require.resolve('./my-adapter.mjs'),
adapterPath: require.resolve('./my-adapter.mjs'),
},
cacheComponents: process.env.TEST_CACHE_COMPONENTS === '1', cacheComponents: process.env.TEST_CACHE_COMPONENTS === '1',
rewrites() { rewrites() {
return [ return [
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
*/ */
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
adapterPath: require.resolve('./my-adapter.mjs'),
experimental: { experimental: {
adapterPath: require.resolve('./my-adapter.mjs'),
partialFallbacks: true, partialFallbacks: true,
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment