Skip to content

Commit 5998eb7

Browse files
Merge pull request #6 from Pouja/bugfix/io-exception
Supresses the IO Exception of convert-source-map
2 parents 8dc129e + 3ccab96 commit 5998eb7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ export default function(this: loader.LoaderContext, source: string, sourceMap?:
2020
options = Object.assign(defaultOptions, options);
2121
validateOptions(optionsSchema, options, "Coverage Istanbul Loader");
2222

23-
if (!sourceMap) {
24-
// Check for an inline source map
25-
const inlineSourceMap = convert.fromSource(source)
26-
|| convert.fromMapFileSource(source, path.dirname(this.resourcePath));
23+
try {
24+
if (!sourceMap) {
25+
// Check for an inline source map
26+
const inlineSourceMap = convert.fromSource(source)
27+
|| convert.fromMapFileSource(source, path.dirname(this.resourcePath));
2728

28-
if (inlineSourceMap) {
29-
// Use the inline source map
30-
sourceMap = inlineSourceMap.sourcemap as RawSourceMap;
29+
if (inlineSourceMap) {
30+
// Use the inline source map
31+
sourceMap = inlineSourceMap.sourcemap as RawSourceMap;
32+
}
33+
}
34+
} catch (e) {
35+
// Exception is thrown by fromMapFileSource when there is no source map file
36+
if (e instanceof Error && e.message.includes("An error occurred while trying to read the map file at")) {
37+
this.emitWarning(e);
38+
} else {
39+
throw e;
3140
}
3241
}
3342

0 commit comments

Comments
 (0)