Unverified Commit f46db1c4 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Pass projectDir to adapter modifyConfig (#93916)

Adapters implementing `modifyConfig` may need to know the absolute
project directory to perform path resolution or apply directory-specific
configuration logic. Without this value, adapters had no reliable way to
determine where the application lives on disk.

onBuildComplete already received the directory as a parameter.
parent 2ca0d5df
...@@ -42,6 +42,7 @@ export interface NextAdapter { ...@@ -42,6 +42,7 @@ export interface NextAdapter {
ctx: { ctx: {
phase: PHASE_TYPE phase: PHASE_TYPE
nextVersion: string nextVersion: string
projectDir: string
} }
) => Promise<NextConfigComplete> | NextConfigComplete ) => Promise<NextConfigComplete> | NextConfigComplete
onBuildComplete?: (ctx: { onBuildComplete?: (ctx: {
......
...@@ -12,6 +12,7 @@ Called for any CLI command that loads the `next.config.js` file to allow modific ...@@ -12,6 +12,7 @@ Called for any CLI command that loads the `next.config.js` file to allow modific
- `config`: The complete Next.js configuration object - `config`: The complete Next.js configuration object
- `context.phase`: The current build phase (see [phases](/docs/app/api-reference/config/next-config-js#phase)) - `context.phase`: The current build phase (see [phases](/docs/app/api-reference/config/next-config-js#phase))
- `context.nextVersion`: Version of Next.js being used - `context.nextVersion`: Version of Next.js being used
- `context.projectDir`: Absolute path to the Next.js project directory
**Returns:** The modified configuration object (can be async) **Returns:** The modified configuration object (can be async)
......
...@@ -379,6 +379,10 @@ export interface NextAdapter { ...@@ -379,6 +379,10 @@ export interface NextAdapter {
* nextVersion is the current version of Next.js being used * nextVersion is the current version of Next.js being used
*/ */
nextVersion: string nextVersion: string
/**
* projectDir is the absolute directory the Next.js application is in
*/
projectDir: string
} }
) => Promise<NextConfigComplete> | NextConfigComplete ) => Promise<NextConfigComplete> | NextConfigComplete
onBuildComplete?: (ctx: { onBuildComplete?: (ctx: {
......
...@@ -1590,7 +1590,8 @@ function finalizeConfig(config: NextConfigComplete): NextConfigComplete { ...@@ -1590,7 +1590,8 @@ function finalizeConfig(config: NextConfigComplete): NextConfigComplete {
async function applyModifyConfig( async function applyModifyConfig(
config: NextConfigComplete, config: NextConfigComplete,
phase: PHASE_TYPE, phase: PHASE_TYPE,
silent: boolean silent: boolean,
dir: string
): 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
...@@ -1607,6 +1608,7 @@ async function applyModifyConfig( ...@@ -1607,6 +1608,7 @@ async function applyModifyConfig(
config = await adapterMod.modifyConfig(config, { config = await adapterMod.modifyConfig(config, {
phase, phase,
nextVersion: process.env.__NEXT_VERSION as string, nextVersion: process.env.__NEXT_VERSION as string,
projectDir: dir,
}) })
} }
} }
...@@ -1779,7 +1781,8 @@ export default async function loadConfig( ...@@ -1779,7 +1781,8 @@ export default async function loadConfig(
phase phase
), ),
phase, phase,
silent silent,
dir
) )
) )
...@@ -1977,7 +1980,7 @@ export default async function loadConfig( ...@@ -1977,7 +1980,7 @@ export default async function loadConfig(
) )
const finalConfig = finalizeConfig( const finalConfig = finalizeConfig(
await applyModifyConfig(completeConfig, phase, silent) await applyModifyConfig(completeConfig, phase, silent, dir)
) )
// Cache the final result // Cache the final result
...@@ -2036,7 +2039,7 @@ export default async function loadConfig( ...@@ -2036,7 +2039,7 @@ export default async function loadConfig(
setHttpClientAndAgentOptions(completeConfig) setHttpClientAndAgentOptions(completeConfig)
const finalConfig = finalizeConfig( const finalConfig = finalizeConfig(
await applyModifyConfig(completeConfig, phase, silent) await applyModifyConfig(completeConfig, phase, silent, dir)
) )
// Cache the default config result // Cache the default config result
......
...@@ -55,6 +55,7 @@ describe('adapter-config export', () => { ...@@ -55,6 +55,7 @@ describe('adapter-config export', () => {
} }
expect(ctx.nextVersion).toBe(nextVersion) expect(ctx.nextVersion).toBe(nextVersion)
expect(ctx.projectDir).toBe(next.testDir)
expect(config?.basePath).toBe('/docs') expect(config?.basePath).toBe('/docs')
const combinedRouteOutputs = [ const combinedRouteOutputs = [
......
...@@ -43,6 +43,7 @@ describe('adapter-config', () => { ...@@ -43,6 +43,7 @@ describe('adapter-config', () => {
} }
expect(ctx.nextVersion).toBe(nextVersion) expect(ctx.nextVersion).toBe(nextVersion)
expect(ctx.projectDir).toBe(next.testDir)
expect(config?.basePath).toBe('/docs') expect(config?.basePath).toBe('/docs')
const combinedRouteOutputs = [ const combinedRouteOutputs = [
......
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