Unverified Commit f8179386 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure module contexts are always included in adapter traces (#89508)

parent ab8e7865
...@@ -532,7 +532,6 @@ export async function handleBuildComplete({ ...@@ -532,7 +532,6 @@ export async function handleBuildComplete({
sharedNodeAssets[path.relative(tracingRoot, setupNodeStubPath)] = sharedNodeAssets[path.relative(tracingRoot, setupNodeStubPath)] =
require.resolve('next/dist/build/adapter/setup-node-env.external') require.resolve('next/dist/build/adapter/setup-node-env.external')
if (bundler !== Bundler.Turbopack) {
const moduleTypes = ['app-page', 'pages'] as const const moduleTypes = ['app-page', 'pages'] as const
for (const type of moduleTypes) { for (const type of moduleTypes) {
...@@ -540,6 +539,8 @@ export async function handleBuildComplete({ ...@@ -540,6 +539,8 @@ export async function handleBuildComplete({
const modulePath = require.resolve( const modulePath = require.resolve(
`next/dist/server/route-modules/${type}/module.compiled` `next/dist/server/route-modules/${type}/module.compiled`
) )
currentDependencies.push(modulePath)
const contextDir = path.join( const contextDir = path.join(
path.dirname(modulePath), path.dirname(modulePath),
'vendored', 'vendored',
...@@ -552,16 +553,12 @@ export async function handleBuildComplete({ ...@@ -552,16 +553,12 @@ export async function handleBuildComplete({
} }
} }
const { fileList, esmFileList } = await nodeFileTrace( for (const dependencyPath of currentDependencies) {
currentDependencies, const rootRelativeFilePath = path.relative(
{ tracingRoot,
base: tracingRoot, dependencyPath
ignore: sharedIgnoreFn,
}
) )
esmFileList.forEach((item) => fileList.add(item))
for (const rootRelativeFilePath of fileList) {
if (type === 'pages') { if (type === 'pages') {
pagesSharedNodeAssets[rootRelativeFilePath] = path.join( pagesSharedNodeAssets[rootRelativeFilePath] = path.join(
tracingRoot, tracingRoot,
...@@ -576,6 +573,7 @@ export async function handleBuildComplete({ ...@@ -576,6 +573,7 @@ export async function handleBuildComplete({
} }
} }
if (bundler !== Bundler.Turbopack) {
// These are modules that are necessary for bootstrapping node env // These are modules that are necessary for bootstrapping node env
const necessaryNodeDependencies = [ const necessaryNodeDependencies = [
require.resolve('next/dist/server/node-environment'), require.resolve('next/dist/server/node-environment'),
......
...@@ -173,6 +173,35 @@ describe('adapter-config', () => { ...@@ -173,6 +173,35 @@ describe('adapter-config', () => {
} }
} }
// Verify vendored context files are traced in assets for app-page and pages outputs
const appPageOutput = outputs.appPages.find(
(output) =>
output.pathname === '/docs/node-app' && output.runtime === 'nodejs'
)
const pagesOutput = outputs.pages.find(
(output) =>
output.pathname === '/docs/node-pages' && output.runtime === 'nodejs'
)
expect(appPageOutput).toBeDefined()
expect(pagesOutput).toBeDefined()
// Check that vendored context files are included in assets
const appPageAssets = Object.values(appPageOutput!.assets)
const pagesAssets = Object.values(pagesOutput!.assets)
const appPageVendoredContexts = appPageAssets.filter((asset) =>
asset.includes('vendored/contexts/')
)
const pagesVendoredContexts = pagesAssets.filter((asset) =>
asset.includes('vendored/contexts/')
)
// app-page should have vendored context files traced
expect(appPageVendoredContexts.length).toBeGreaterThan(0)
// pages should have vendored context files traced
expect(pagesVendoredContexts.length).toBeGreaterThan(0)
for (const route of edgeOutputs) { for (const route of edgeOutputs) {
try { try {
expect(route.id).toBeString() expect(route.id).toBeString()
......
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