Skip to content

Commit

Permalink
fix: sourcemaps windows drive letter inconsistency, fix 4964 (vitejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CGQAQ authored and aleclarson committed Nov 8, 2021
1 parent e2f0aff commit da42f5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
cleanUrl,
createDebugger,
ensureWatchedFile,
generateCodeFrame
generateCodeFrame,
toUpperCaseDriveLetter
} from '../utils'
import { RawSourceMap } from '@ampproject/remapping/dist/types/types'
import { SourceMap } from 'rollup'
Expand Down Expand Up @@ -126,23 +127,25 @@ export async function transformWithEsbuild(

try {
const result = await transform(code, resolvedOptions)
let map: SourceMap
if (inMap && resolvedOptions.sourcemap) {
const nextMap = JSON.parse(result.map)
nextMap.sourcesContent = []
return {
...result,
map: combineSourcemaps(filename, [
nextMap as RawSourceMap,
inMap as RawSourceMap
]) as SourceMap
}
map = combineSourcemaps(filename, [
nextMap as RawSourceMap,
inMap as RawSourceMap
]) as SourceMap
} else {
return {
...result,
map: resolvedOptions.sourcemap
? JSON.parse(result.map)
: { mappings: '' }
}
map = resolvedOptions.sourcemap
? JSON.parse(result.map)
: { mappings: '' }
}
if (Array.isArray(map.sources)) {
map.sources = map.sources.map((it) => toUpperCaseDriveLetter(it))
}
return {
...result,
map
}
} catch (e) {
debug(`esbuild error with options used: `, resolvedOptions)
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,5 +561,9 @@ export function arraify<T>(target: T | T[]): T[] {
return Array.isArray(target) ? target : [target]
}

export function toUpperCaseDriveLetter(pathName: string): string {
return pathName.replace(/^\w:/, letter => letter.toUpperCase())
}

export const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm
export const singlelineCommentsRE = /\/\/.*/g

0 comments on commit da42f5e

Please sign in to comment.