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

fix(vite): fix 4964(Windows drive letter inconsistency) #4985

Merged
merged 5 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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