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

Commit 75e88bd

Browse files
committed
Add fixWebpackSourcePath option
1 parent df7a77d commit 75e88bd

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ The loader supports all options supported by `istanbul-lib-instrument`
123123
|**`coverageVariable`**|`{String}`|`__coverage__`|Name of global coverage variable|
124124
|**`preserveComments`**|`{Boolean}`|`false`|Preserve comments in `output`|
125125
|**`produceSourceMap`**|`{Boolean}`|`false`|Set to `true` to produce a source map for the instrumented code|
126+
|**`fixWebpackSourcePaths`**|`{Boolean}`|`false`|Set to `true` to prevent filepath error in coverage|
126127
|**`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|
127128

128129
```js

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default function (source, sourceMap) {
2222
const instrumenter = createInstrumenter(options);
2323

2424
instrumenter.instrument(source, this.resourcePath, (error, instrumentedSource) => {
25+
if(options.fixWebpackSourcePaths) {
26+
instrumentedSource = instrumentedSource.replace(/sources:\[([^\]])*\]/g, function(match) {
27+
const splits = match.split('!');
28+
return 'sources:[\'' + splits[splits.length - 1];
29+
});
30+
}
2531
this.callback(error, instrumentedSource, instrumenter.lastSourceMap());
2632
}, srcMap);
2733
}

src/options.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
},
2222
"produceSourceMap": {
2323
"type": "boolean"
24+
},
25+
"fixWebpackSourcePaths": {
26+
"type": "boolean"
2427
}
2528
},
2629
"additionalProperties": true

0 commit comments

Comments
 (0)