Skip to content

Commit

Permalink
dx: sourcemap combine debug utils (#8307)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed May 24, 2022
1 parent c18a5f3 commit 45dba50
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/vite/src/node/server/pluginContainer.ts
Expand Up @@ -147,6 +147,15 @@ export async function createPluginContainer(
const debugPluginTransform = createDebugger('vite:plugin-transform', {
onlyWhenFocused: 'vite:plugin'
})
const debugSourcemapCombineFlag = 'vite:sourcemap-combine'
const isDebugSourcemapCombineFocused = process.env.DEBUG?.includes(
debugSourcemapCombineFlag
)
const debugSourcemapCombineFilter =
process.env.DEBUG_VITE_SOURCEMAP_COMBINE_FILTER
const debugSourcemapCombine = createDebugger('vite:sourcemap-combine', {
onlyWhenFocused: true
})

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -424,6 +433,16 @@ export async function createPluginContainer(
}

_getCombinedSourcemap(createIfNull = false) {
if (
debugSourcemapCombineFilter &&
this.filename.includes(debugSourcemapCombineFilter)
) {
debugSourcemapCombine('----------', this.filename)
debugSourcemapCombine(this.combinedMap)
debugSourcemapCombine(this.sourcemapChain)
debugSourcemapCombine('----------')
}

let combinedMap = this.combinedMap
for (let m of this.sourcemapChain) {
if (typeof m === 'string') m = JSON.parse(m)
Expand Down Expand Up @@ -613,6 +632,10 @@ export async function createPluginContainer(
if (result.code !== undefined) {
code = result.code
if (result.map) {
if (isDebugSourcemapCombineFocused) {
// @ts-expect-error inject plugin name for debug purpose
result.map.name = plugin.name
}
ctx.sourcemapChain.push(result.map)
}
}
Expand Down

0 comments on commit 45dba50

Please sign in to comment.