istanbuljs / v8-to-istanbul

convert from v8 coverage format to istanbul's format
ISC License
114 stars 41 forks source link

Support webpack:// in the `sourceRoot` option #133

Open tomardern opened 3 years ago

tomardern commented 3 years ago

Hi,

I'm having an issue with resolving to the correct file paths when the sourceRoot is webpack://.

Here is my investigation notes:

Example Sourcemap:

{
    "version":3,
    "sources":["./src/app/helloworld.js"],
     ... 
    "sourceRoot":"webpack://"
}

Example:

let result = _resolveSource({
    sourcemap: {
   sourceRoot: "webpack://"
 }
}, "src/app/helloworld.js");

Should probably return src/app/helloworld.js but currently returns webpack:/src/app/helloworld.js

Maybe changing this line (https://github.com/istanbuljs/v8-to-istanbul/blob/master/lib/v8-to-istanbul.js#L87) from :

const sourceRoot = rawSourceMap.sourcemap.sourceRoot ? rawSourceMap.sourcemap.sourceRoot.replace('file://', '') : ''

to:

const sourceRoot = rawSourceMap.sourcemap.sourceRoot ? rawSourceMap.sourcemap.sourceRoot.replace(/(^file:\/\/)|(^webpack:\/\/)/, '') : ''

As a workaround, I can override the sourceRoot property to 'file://'.

Environment Information

  System:
    OS: macOS 10.15.1
    CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
    Memory: 281.22 MB / 8.00 GB
  Binaries:
    Node: 14.11.0 - ~/.nvm/versions/node/v14.11.0/bin/node
    npm: 6.14.8 - ~/.nvm/versions/node/v14.11.0/bin/npm
  npmPackages:
    nyc: ^15.1.0 => 15.1.0 
    typescript: ^4.1.3 => 4.1.3 
    v8-to-istanbul: ^7.1.0 => 7.1.0 

Thanks!

bcoe commented 3 years ago

@tomardern what's the expected behavior? should we just be dropping webpack:// in this case?

tomardern commented 3 years ago

@bcoe For my case, yes, I'm not an expert on sourcemaps, so I'm not totally sure.