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,50 +532,48 @@ export async function handleBuildComplete({ ...@@ -532,50 +532,48 @@ 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) {
const currentDependencies: string[] = [] const currentDependencies: string[] = []
const modulePath = require.resolve( const modulePath = require.resolve(
`next/dist/server/route-modules/${type}/module.compiled` `next/dist/server/route-modules/${type}/module.compiled`
) )
const contextDir = path.join( currentDependencies.push(modulePath)
path.dirname(modulePath),
'vendored',
'contexts'
)
for (const item of await fs.readdir(contextDir)) { const contextDir = path.join(
if (item.match(/\.(mjs|cjs|js)$/)) { path.dirname(modulePath),
currentDependencies.push(path.join(contextDir, item)) 'vendored',
} 'contexts'
)
for (const item of await fs.readdir(contextDir)) {
if (item.match(/\.(mjs|cjs|js)$/)) {
currentDependencies.push(path.join(contextDir, item))
} }
}
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, rootRelativeFilePath
rootRelativeFilePath )
) } else {
} else { appPagesSharedNodeAssets[rootRelativeFilePath] = path.join(
appPagesSharedNodeAssets[rootRelativeFilePath] = path.join( tracingRoot,
tracingRoot, rootRelativeFilePath
rootRelativeFilePath )
)
}
} }
} }
}
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