Skip to content

Commit 45dba50

Browse files
authored
dx: sourcemap combine debug utils (#8307)
1 parent c18a5f3 commit 45dba50

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ export async function createPluginContainer(
147147
const debugPluginTransform = createDebugger('vite:plugin-transform', {
148148
onlyWhenFocused: 'vite:plugin'
149149
})
150+
const debugSourcemapCombineFlag = 'vite:sourcemap-combine'
151+
const isDebugSourcemapCombineFocused = process.env.DEBUG?.includes(
152+
debugSourcemapCombineFlag
153+
)
154+
const debugSourcemapCombineFilter =
155+
process.env.DEBUG_VITE_SOURCEMAP_COMBINE_FILTER
156+
const debugSourcemapCombine = createDebugger('vite:sourcemap-combine', {
157+
onlyWhenFocused: true
158+
})
150159

151160
// ---------------------------------------------------------------------------
152161

@@ -424,6 +433,16 @@ export async function createPluginContainer(
424433
}
425434

426435
_getCombinedSourcemap(createIfNull = false) {
436+
if (
437+
debugSourcemapCombineFilter &&
438+
this.filename.includes(debugSourcemapCombineFilter)
439+
) {
440+
debugSourcemapCombine('----------', this.filename)
441+
debugSourcemapCombine(this.combinedMap)
442+
debugSourcemapCombine(this.sourcemapChain)
443+
debugSourcemapCombine('----------')
444+
}
445+
427446
let combinedMap = this.combinedMap
428447
for (let m of this.sourcemapChain) {
429448
if (typeof m === 'string') m = JSON.parse(m)
@@ -613,6 +632,10 @@ export async function createPluginContainer(
613632
if (result.code !== undefined) {
614633
code = result.code
615634
if (result.map) {
635+
if (isDebugSourcemapCombineFocused) {
636+
// @ts-expect-error inject plugin name for debug purpose
637+
result.map.name = plugin.name
638+
}
616639
ctx.sourcemapChain.push(result.map)
617640
}
618641
}

0 commit comments

Comments
 (0)