This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(index): correct loader sourcemaps usage (#67)
* fix: pass sourcemaps to istanbul
- Loading branch information
1 parent
d0cf823
commit 691b565
Showing
8 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { createInstrumenter } from 'istanbul-lib-instrument'; | ||
import loaderUtils from 'loader-utils'; | ||
import convert from 'convert-source-map'; | ||
|
||
export default function (source, sourceMap) { | ||
let srcMap = sourceMap; | ||
// use inline source map, if any | ||
if (!srcMap) { | ||
const inlineSourceMap = convert.fromSource(source); | ||
if (inlineSourceMap) { | ||
srcMap = inlineSourceMap.sourcemap; | ||
} | ||
} | ||
|
||
export default function (source) { | ||
const options = Object.assign({ produceSourceMap: true }, loaderUtils.getOptions(this)); | ||
const instrumenter = createInstrumenter(options); | ||
|
||
instrumenter.instrument(source, this.resourcePath, (error, instrumentedSource) => { | ||
this.callback(error, instrumentedSource, instrumenter.lastSourceMap()); | ||
}); | ||
}, srcMap); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,4 @@ module.exports = class Foo { | |
return !!this; | ||
} | ||
|
||
baz() { | ||
return !this.bar(); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import path from 'path'; | ||
import loader from '../../src/cjs'; | ||
|
||
module.exports = function (...args) { | ||
const normalize = str => str.split(path.sep).join('/'); | ||
|
||
module.exports = function (source, map, ...args) { | ||
// hack the resourcePath to be consistent across systems so that tests always work | ||
this.resourcePath = this.resourcePath | ||
.replace(path.resolve(__dirname, '..'), '') | ||
// make windows paths appear like unix | ||
.replace(/\\/g, '/'); | ||
return loader.call(this, ...args); | ||
this.resourcePath = normalize(this.resourcePath.replace(path.resolve(__dirname, '..'), '')); | ||
|
||
// do the same hack for sourcemaps so tests are consistent | ||
const sourceMap = map; | ||
if (sourceMap) { | ||
sourceMap.sourceRoot = ''; | ||
sourceMap.sources = sourceMap.sources.map(normalize); | ||
} | ||
|
||
return loader.call(this, source, sourceMap, ...args); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters