Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Add fixWebpackSourcePath option
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbruegge committed Aug 4, 2017
1 parent df7a77d commit 25e8619
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ The loader supports all options supported by `istanbul-lib-instrument`
|**`coverageVariable`**|`{String}`|`__coverage__`|Name of global coverage variable|
|**`preserveComments`**|`{Boolean}`|`false`|Preserve comments in `output`|
|**`produceSourceMap`**|`{Boolean}`|`false`|Set to `true` to produce a source map for the instrumented code|
|**`fixWebpackSourcePaths`**|`{Boolean}`|`false`|Set to `true` to prevent filepath error in coverage|
|**`sourceMapUrlCallback`**|`{Function}`|`null`|A callback function that is called when a source map URL is found in the original code. This function is called with the source filename and the source map URL|

```js
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export default function (source, sourceMap) {
const instrumenter = createInstrumenter(options);

instrumenter.instrument(source, this.resourcePath, (error, instrumentedSource) => {
this.callback(error, instrumentedSource, instrumenter.lastSourceMap());
let src = instrumentedSource;
if (options.fixWebpackSourcePaths) {
src = src.replace(/sources:\[([^\]])*\]/g, (match) => {
const splits = match.split('!');
return `sources:['${splits[splits.length - 1]}`;
});
}
this.callback(error, src, instrumenter.lastSourceMap());
}, srcMap);
}
3 changes: 3 additions & 0 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
"produceSourceMap": {
"type": "boolean"
},
"fixWebpackSourcePaths": {
"type": "boolean"
}
},
"additionalProperties": true
Expand Down

0 comments on commit 25e8619

Please sign in to comment.