Unverified Commit 2c9e7c10 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

test: accept index source maps in server chunk source map test

Per-item minification leaves production JS chunk maps indexed (sections), as unminified output already is; whole-chunk minification used to flatten them. Collect sources from sections recursively instead of only the top-level sources array.

<!-- NEXT_JS_LLM -->
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent bfc69dd9
...@@ -68,6 +68,19 @@ function scriptURLToFileURL(scriptURL: string): string { ...@@ -68,6 +68,19 @@ function scriptURLToFileURL(scriptURL: string): string {
: url.pathToFileURL(scriptURL).href : url.pathToFileURL(scriptURL).href
} }
/**
* The `sources` of a source map. Index maps list theirs in `sections`, and the
* top-level `sources` of an index map isn't meaningful.
*/
function sourceMapSources(sourceMap: any): string[] {
if (Array.isArray(sourceMap.sections)) {
return sourceMap.sections.flatMap((section: any) =>
sourceMapSources(section.map)
)
}
return sourceMap.sources ?? []
}
/** /**
* Debugger frontends cannot be assumed to fetch arbitrary http(s) URLs * Debugger frontends cannot be assumed to fetch arbitrary http(s) URLs
* themselves (the dedicated Chrome DevTools frontend for Node.js targets * themselves (the dedicated Chrome DevTools frontend for Node.js targets
...@@ -425,7 +438,7 @@ describe('app-dir - server source maps - fake frame source maps', () => { ...@@ -425,7 +438,7 @@ describe('app-dir - server source maps - fake frame source maps', () => {
script.sourceMapURL, script.sourceMapURL,
scriptURLToFileURL(script.url) scriptURLToFileURL(script.url)
) )
for (const source of sourceMap.sources as string[]) { for (const source of sourceMapSources(sourceMap)) {
const resolved = new URL(source, mapURL).href const resolved = new URL(source, mapURL).href
expectWellFormedSource(resolved) expectWellFormedSource(resolved)
resolvedSources.add(resolved) resolvedSources.add(resolved)
......
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