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

Fix tracing in require-hook (#53642)

This ensures the resolve calls for `styled-jsx` are done in the correct context so that tracing can include the correct symlinks/package.json files. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1691217652833079)
parent 7bf3d77b
...@@ -126,7 +126,7 @@ if (!process.env.NEXT_MANUAL_SIG_HANDLE && command !== 'dev') { ...@@ -126,7 +126,7 @@ if (!process.env.NEXT_MANUAL_SIG_HANDLE && command !== 'dev') {
commands[command]() commands[command]()
.then((exec) => exec(forwardedArgs)) .then((exec) => exec(forwardedArgs))
.then(() => { .then(() => {
if (command === 'build') { if (command === 'build' || command === 'experimental-compile') {
// ensure process exits after build completes so open handles/connections // ensure process exits after build completes so open handles/connections
// don't cause process to hang // don't cause process to hang
process.exit(0) process.exit(0)
......
...@@ -141,11 +141,7 @@ import { createValidFileMatcher } from '../server/lib/find-page-file' ...@@ -141,11 +141,7 @@ import { createValidFileMatcher } from '../server/lib/find-page-file'
import { startTypeChecking } from './type-check' import { startTypeChecking } from './type-check'
import { generateInterceptionRoutesRewrites } from '../lib/generate-interception-routes-rewrites' import { generateInterceptionRoutesRewrites } from '../lib/generate-interception-routes-rewrites'
import { buildDataRoute } from '../server/lib/router-utils/build-data-route' import { buildDataRoute } from '../server/lib/router-utils/build-data-route'
import { import { baseOverrides, experimentalOverrides } from '../server/require-hook'
baseOverrides,
defaultOverrides,
experimentalOverrides,
} from '../server/require-hook'
import { initialize } from '../server/lib/incremental-cache-server' import { initialize } from '../server/lib/incremental-cache-server'
import { nodeFs } from '../server/lib/node-fs-methods' import { nodeFs } from '../server/lib/node-fs-methods'
...@@ -2041,11 +2037,6 @@ export default async function build( ...@@ -2041,11 +2037,6 @@ export default async function build(
...Object.values(experimentalOverrides).map((override) => ...Object.values(experimentalOverrides).map((override) =>
require.resolve(override) require.resolve(override)
), ),
...(config.experimental.turbotrace
? []
: Object.values(defaultOverrides).map((value) =>
require.resolve(value)
)),
] ]
// ensure we trace any dependencies needed for custom // ensure we trace any dependencies needed for custom
......
...@@ -19,9 +19,10 @@ const resolve = process.env.NEXT_MINIMAL ...@@ -19,9 +19,10 @@ const resolve = process.env.NEXT_MINIMAL
const toResolveMap = (map: Record<string, string>): [string, string][] => const toResolveMap = (map: Record<string, string>): [string, string][] =>
Object.entries(map).map(([key, value]) => [key, resolve(value)]) Object.entries(map).map(([key, value]) => [key, resolve(value)])
// these must use require.resolve to be statically analyzable
export const defaultOverrides = { export const defaultOverrides = {
'styled-jsx': dirname(resolve('styled-jsx/package.json')), 'styled-jsx': dirname(require.resolve('styled-jsx/package.json')),
'styled-jsx/style': resolve('styled-jsx/style'), 'styled-jsx/style': require.resolve('styled-jsx/style'),
} }
export const baseOverrides = { export const baseOverrides = {
......
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