Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include proper instrumentation entry in required files manifest #68983

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,16 @@ export default async function build(

const { cacheHandler } = config

const instrumentationHookEntryFiles = hasInstrumentationHook
? [
path.join(SERVER_DIRECTORY, `${INSTRUMENTATION_HOOK_FILENAME}.js`),
path.join(
SERVER_DIRECTORY,
`edge-${INSTRUMENTATION_HOOK_FILENAME}.js`
),
].filter((filePath) => existsSync(path.join(distDir, filePath)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if we avoid .filter here we could avoid existsSync.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the manifest writing to later phase, and use the value that can determine if we already have edge routes. Then we don't need to do this fs check anymore!

: []

const requiredServerFilesManifest = nextBuildSpan
.traceChild('generate-required-server-files')
.traceFn(() => {
Expand Down Expand Up @@ -1312,18 +1322,7 @@ export default async function build(
BUILD_ID_FILE,
path.join(SERVER_DIRECTORY, NEXT_FONT_MANIFEST + '.js'),
path.join(SERVER_DIRECTORY, NEXT_FONT_MANIFEST + '.json'),
...(hasInstrumentationHook
? [
path.join(
SERVER_DIRECTORY,
`${INSTRUMENTATION_HOOK_FILENAME}.js`
),
path.join(
SERVER_DIRECTORY,
`edge-${INSTRUMENTATION_HOOK_FILENAME}.js`
),
]
: []),
...instrumentationHookEntryFiles,
]
.filter(nonNullable)
.map((file) => path.join(config.distDir, file)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function GET() {
return new Response('edge')
}

export const runtime = 'edge'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function register() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
instrumentationHook: true,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { nextTestSetup } from 'e2e-utils'

async function readRequiredFilesManifest(next: any) {
const manifest = JSON.parse(
await next.readFile('.next/required-server-files.json')
)
return manifest.files
}

describe('instrumentation - required-files-instrumentation-entry', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should not contain edge entry in required files manifest', async () => {
const requiredFiles = await readRequiredFilesManifest(next)
expect(requiredFiles).not.toContain('.next/server/edge-instrumentation.js')
})
})
Loading