Unverified Commit 6169e786 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix required-server-files (#86875)

Fixes a regression in https://github.com/vercel/next.js/pull/86830

`config.distDir` was missing

<img width="1622" height="475" alt="Bildschirmfoto 2025-12-05 um 17 50 43" src="https://github.com/user-attachments/assets/6460801d-949e-441b-a7d3-6fb679f22d83" />
parent 7c969652
...@@ -1931,17 +1931,22 @@ export default async function build( ...@@ -1931,17 +1931,22 @@ export default async function build(
if (hasInstrumentationHook) { if (hasInstrumentationHook) {
serverFilesManifest.files.push( serverFilesManifest.files.push(
path.join(SERVER_DIRECTORY, `${INSTRUMENTATION_HOOK_FILENAME}.js`) path.join(
config.distDir,
SERVER_DIRECTORY,
`${INSTRUMENTATION_HOOK_FILENAME}.js`
)
) )
// If there are edge routes, append the edge instrumentation hook // If there are edge routes, append the edge instrumentation hook
// Turbopack generates this chunk with a hashed name and references it in middleware-manifest. // Turbopack generates this chunk with a hashed name and references it in middleware-manifest.
let edgeInstrumentationHook = path.join( let edgeInstrumentationHook = path.join(
config.distDir,
SERVER_DIRECTORY, SERVER_DIRECTORY,
`edge-${INSTRUMENTATION_HOOK_FILENAME}.js` `edge-${INSTRUMENTATION_HOOK_FILENAME}.js`
) )
if ( if (
bundler !== Bundler.Turbopack && bundler !== Bundler.Turbopack &&
existsSync(path.join(distDir, edgeInstrumentationHook)) existsSync(path.join(dir, edgeInstrumentationHook))
) { ) {
serverFilesManifest.files.push(edgeInstrumentationHook) serverFilesManifest.files.push(edgeInstrumentationHook)
} }
......
...@@ -217,7 +217,7 @@ export class NextStartInstance extends NextInstance { ...@@ -217,7 +217,7 @@ export class NextStartInstance extends NextInstance {
) )
} }
return new Promise<{ let result = await new Promise<{
exitCode: NodeJS.Signals | number | null exitCode: NodeJS.Signals | number | null
cliOutput: string cliOutput: string
}>((resolve) => { }>((resolve) => {
...@@ -238,6 +238,21 @@ export class NextStartInstance extends NextInstance { ...@@ -238,6 +238,21 @@ export class NextStartInstance extends NextInstance {
}) })
}) })
}) })
this._buildId = (
await fs
.readFile(
path.join(
this.testDir,
this.nextConfig?.distDir || '.next',
'BUILD_ID'
),
'utf8'
)
.catch(() => '')
).trim()
return result
} }
public async waitForMinPrerenderAge(minAgeMS: number): Promise<void> { public async waitForMinPrerenderAge(minAgeMS: number): Promise<void> {
......
...@@ -44,6 +44,9 @@ describe('required server files', () => { ...@@ -44,6 +44,9 @@ describe('required server files', () => {
: 'middleware.js' : 'middleware.js'
) )
), ),
'instrumentation.js': new FileRef(
join(__dirname, 'instrumentation.js')
),
'cache-handler.js': new FileRef(join(__dirname, 'cache-handler.js')), 'cache-handler.js': new FileRef(join(__dirname, 'cache-handler.js')),
'data.txt': new FileRef(join(__dirname, 'data.txt')), 'data.txt': new FileRef(join(__dirname, 'data.txt')),
'.env': new FileRef(join(__dirname, '.env')), '.env': new FileRef(join(__dirname, '.env')),
...@@ -84,8 +87,11 @@ describe('required server files', () => { ...@@ -84,8 +87,11 @@ describe('required server files', () => {
} }
}, },
}, },
skipStart: true,
}) })
await next.stop()
let { exitCode } = await next.build()
expect(exitCode).toBe(0)
requiredFilesManifest = JSON.parse( requiredFilesManifest = JSON.parse(
await next.readFile('.next/required-server-files.json') await next.readFile('.next/required-server-files.json')
...@@ -241,11 +247,11 @@ describe('required server files', () => { ...@@ -241,11 +247,11 @@ describe('required server files', () => {
redirect: 'manual', redirect: 'manual',
} }
) )
expect(dataRes.headers.get('cache-control')).toBe(cacheControl)
expect((await dataRes.json()).pageProps).toEqual({ expect((await dataRes.json()).pageProps).toEqual({
__N_REDIRECT: dest, __N_REDIRECT: dest,
__N_REDIRECT_STATUS: 307, __N_REDIRECT_STATUS: 307,
}) })
expect(dataRes.headers.get('cache-control')).toBe(cacheControl)
} }
) )
...@@ -415,6 +421,12 @@ describe('required server files', () => { ...@@ -415,6 +421,12 @@ describe('required server files', () => {
expect(typeof requiredFilesManifest.appDir).toBe('string') expect(typeof requiredFilesManifest.appDir).toBe('string')
// not in a monorepo so relative app dir is empty string // not in a monorepo so relative app dir is empty string
expect(requiredFilesManifest.relativeAppDir).toBe('') expect(requiredFilesManifest.relativeAppDir).toBe('')
expect(
requiredFilesManifest.files.filter(
(f) => !fs.pathExistsSync(join(next.testDir, 'standalone', f))
)
).toBeEmpty()
}) })
it('should de-dupe HTML/data requests', async () => { it('should de-dupe HTML/data requests', async () => {
......
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