Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
137 lines
3.8 KiB
TypeScript
137 lines
3.8 KiB
TypeScript
// Used to deterministically stub out minified local names in stack traces.
|
|
const abc = 'abcdefghijklmnopqrstuvwxyz'
|
|
const hostElementsUsedInFixtures = ['html', 'body', 'main', 'div']
|
|
const ignoredLines = [
|
|
'Generating static pages',
|
|
'Inlining static env',
|
|
'Finalizing page optimization',
|
|
]
|
|
|
|
/**
|
|
* Converts a module function sequence expression, e.g.:
|
|
* - (0 , __TURBOPACK__imported__module__1836__.cookies)(...)
|
|
* - (0 , c.cookies)(...)
|
|
* - (0 , cookies.U)(...)
|
|
* - (0 , e.U)(...)
|
|
* to a deterministic, bundler-agnostic representation.
|
|
*/
|
|
export function convertModuleFunctionSequenceExpression(
|
|
output: string
|
|
): string {
|
|
return output.replace(/\(0 , \w+\.(\w+)\)\(\.\.\.\)/, '<module-function>()')
|
|
}
|
|
|
|
export function getDeterministicOutput(
|
|
cliOutput: string,
|
|
{
|
|
isMinified,
|
|
startingLineMatch,
|
|
}: { isMinified: boolean; startingLineMatch?: string }
|
|
): string {
|
|
const lines: string[] = []
|
|
|
|
// If no starting line match is provided, we start from the beginning.
|
|
let foundStartingLine = !startingLineMatch
|
|
let a = 0
|
|
let n = 0
|
|
|
|
const replaceNextDistStackFrame = (_m: string, name: string) =>
|
|
`at ${isMinified ? abc[a++ % abc.length] : name} (<next-dist-dir>)`
|
|
|
|
const isLikelyLibraryInternalStackFrame = (line: string) => {
|
|
return line.startsWith(' at InnerLayoutRouter (')
|
|
}
|
|
|
|
const replaceAnonymousStackFrame = (_m: string, name: string) => {
|
|
const deterministicName = hostElementsUsedInFixtures.includes(name)
|
|
? name
|
|
: abc[a++ % abc.length]
|
|
|
|
return `at ${deterministicName} (<anonymous>)`
|
|
}
|
|
|
|
const replaceMinifiedName = () => `at ${abc[a++ % abc.length]} (`
|
|
const replaceNumericModuleId = () => `at ${n++} (`
|
|
|
|
let isErrorWithStackTraceStartingInLibraryInternals = false
|
|
for (let line of cliOutput.split('\n')) {
|
|
if (
|
|
!isErrorWithStackTraceStartingInLibraryInternals &&
|
|
isLikelyLibraryInternalStackFrame(line)
|
|
) {
|
|
isErrorWithStackTraceStartingInLibraryInternals = true
|
|
lines.push(' at <FIXME-library-internal>')
|
|
continue
|
|
}
|
|
if (isErrorWithStackTraceStartingInLibraryInternals) {
|
|
if (
|
|
// stackframe
|
|
line.startsWith(' at ') ||
|
|
// codeframe
|
|
/^ {2}\d+ \|/.test(line) ||
|
|
// codeframe cursor for callsite
|
|
/^> \d+ \|/.test(line) ||
|
|
/^\s+\|/.test(line)
|
|
) {
|
|
// still an error with a stack trace starting in library internals
|
|
continue
|
|
} else {
|
|
isErrorWithStackTraceStartingInLibraryInternals = false
|
|
}
|
|
}
|
|
if (startingLineMatch && line.includes(startingLineMatch)) {
|
|
foundStartingLine = true
|
|
continue
|
|
}
|
|
|
|
if (line.includes('Next.js build worker exited')) {
|
|
break
|
|
}
|
|
|
|
if (line.includes('Route (app)')) {
|
|
break
|
|
}
|
|
|
|
if (
|
|
foundStartingLine &&
|
|
!ignoredLines.some((ignoredLine) => line.includes(ignoredLine))
|
|
) {
|
|
if (isMinified) {
|
|
line = line.replace(
|
|
/at (\S+) \(<anonymous>\)/,
|
|
replaceAnonymousStackFrame
|
|
)
|
|
} else {
|
|
line = line.replace(
|
|
/at (\S+) \((webpack:\/\/\/)src[^)]+\)/,
|
|
`at $1 ($2<next-src>)`
|
|
)
|
|
}
|
|
|
|
line = line
|
|
.replace(/at (.+?) \(.next[^)]+\)/, replaceNextDistStackFrame)
|
|
.replace(
|
|
// Single-letter lower-case names are likely minified.
|
|
/at [a-z] \((?!(<next-dist-dir>|<anonymous>))/,
|
|
replaceMinifiedName
|
|
)
|
|
.replace(/at \d+ \(/, replaceNumericModuleId)
|
|
.replace(/digest: '\d+(@E\d+)?'/, "digest: '<error-digest>'")
|
|
|
|
lines.push(convertModuleFunctionSequenceExpression(line))
|
|
}
|
|
}
|
|
|
|
return lines.join('\n').trim()
|
|
}
|
|
|
|
export function getPrerenderOutput(
|
|
cliOutput: string,
|
|
{ isMinified }: { isMinified: boolean }
|
|
): string {
|
|
return getDeterministicOutput(cliOutput, {
|
|
isMinified,
|
|
startingLineMatch: 'Collecting page data',
|
|
})
|
|
}
|