Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx: sourcemap combine debug utils #8307

Merged
merged 1 commit into from May 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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