Skip to content

Commit

Permalink
feat: preserve path separators when stripping projectRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Apr 10, 2024
1 parent 3d53bba commit cae77d3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/transformers/StripProjectRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ export default async function stripProjectRoot (sourceMapPath: string, sourceMap

function strip (sourceMapPath: string, map: UnsafeSourceMap, projectRoot: string): void {
if (!map.sources) return
map.sources = map.sources.map(s => {
map.sources = map.sources.map(sourcePath => {
// leave sources for virtual webpack files untouched
if (/^webpack:\/\/(.*)\/webpack/.test(s)) return s
if (/^webpack:\/\/(.*)\/webpack/.test(sourcePath)) return sourcePath

// detect if s uses windows file separators
const isWindowsPath = sourcePath.includes('\\')
const separator = isWindowsPath ? '\\' : '/'

const absoluteSourcePath = path.resolve(
path.dirname(sourceMapPath),
s.replace(/webpack:\/\/.*\/\.\//, `${projectRoot}/`)
sourcePath.replace(/webpack:\/\/.*\/\.\//, `${projectRoot}${separator}`)
)
return absoluteSourcePath.replace(projectRoot, '').replace(/^(\/|\\)/, '')
const strippedSourcePath = absoluteSourcePath.replace(projectRoot, '').replace(/^(\/|\\)/, '')
const normalizedSourcePath = isWindowsPath ? strippedSourcePath.replace(/\//g, '\\') : strippedSourcePath.replace(/\\/g, '/')
return normalizedSourcePath
})
}

0 comments on commit cae77d3

Please sign in to comment.