Skip to content

Commit 723cd63

Browse files
authoredSep 20, 2021
fix: sourcemaps windows drive letter inconsistency, fix 4964 (#4985)
1 parent 06eb57e commit 723cd63

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed
 

‎packages/vite/src/node/plugins/esbuild.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
cleanUrl,
1313
createDebugger,
1414
ensureWatchedFile,
15-
generateCodeFrame
15+
generateCodeFrame,
16+
toUpperCaseDriveLetter
1617
} from '../utils'
1718
import { RawSourceMap } from '@ampproject/remapping/dist/types/types'
1819
import { SourceMap } from 'rollup'
@@ -126,23 +127,25 @@ export async function transformWithEsbuild(
126127

127128
try {
128129
const result = await transform(code, resolvedOptions)
130+
let map: SourceMap
129131
if (inMap && resolvedOptions.sourcemap) {
130132
const nextMap = JSON.parse(result.map)
131133
nextMap.sourcesContent = []
132-
return {
133-
...result,
134-
map: combineSourcemaps(filename, [
135-
nextMap as RawSourceMap,
136-
inMap as RawSourceMap
137-
]) as SourceMap
138-
}
134+
map = combineSourcemaps(filename, [
135+
nextMap as RawSourceMap,
136+
inMap as RawSourceMap
137+
]) as SourceMap
139138
} else {
140-
return {
141-
...result,
142-
map: resolvedOptions.sourcemap
143-
? JSON.parse(result.map)
144-
: { mappings: '' }
145-
}
139+
map = resolvedOptions.sourcemap
140+
? JSON.parse(result.map)
141+
: { mappings: '' }
142+
}
143+
if (Array.isArray(map.sources)) {
144+
map.sources = map.sources.map((it) => toUpperCaseDriveLetter(it))
145+
}
146+
return {
147+
...result,
148+
map
146149
}
147150
} catch (e) {
148151
debug(`esbuild error with options used: `, resolvedOptions)

‎packages/vite/src/node/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -561,5 +561,9 @@ export function arraify<T>(target: T | T[]): T[] {
561561
return Array.isArray(target) ? target : [target]
562562
}
563563

564+
export function toUpperCaseDriveLetter(pathName: string): string {
565+
return pathName.replace(/^\w:/, letter => letter.toUpperCase())
566+
}
567+
564568
export const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm
565569
export const singlelineCommentsRE = /\/\/.*/g

0 commit comments

Comments
 (0)
Please sign in to comment.