From 45dba509024fa12d26daf2dc59cf3a14fe896b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 24 May 2022 21:40:36 +0900 Subject: [PATCH] dx: sourcemap combine debug utils (#8307) --- .../vite/src/node/server/pluginContainer.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 4d124759af0afa..1b7e2e421960ad 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -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 + }) // --------------------------------------------------------------------------- @@ -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) @@ -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) } }