Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

feat: adding sourcemap support #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
'use strict';

var SourceMapConsumer = require('source-map').SourceMapConsumer;
var isparta = require('isparta');

module.exports = function(source) {
module.exports = function(source, map) {
var config = this.options.isparta || {
embedSource: true,
noAutoWrap: true,
babel: this.options.babel
};

if(this.sourceMap){
config.codeGenerationOptions = config.codeGenerationOptions || {};
config.codeGenerationOptions.sourceMap = this.resourcePath;
config.codeGenerationOptions.sourceMapWithCode = true;
}

var instrumenter = new isparta.Instrumenter(config);

if (this.cacheable) {
this.cacheable();
}

return instrumenter.instrumentSync(source, this.resourcePath);
var instrumented = instrumenter.instrumentSync(source, this.resourcePath);

if(this.sourceMap){
var outMap = instrumenter.lastSourceMap();

if(outMap){
outMap.applySourceMap(new SourceMapConsumer(map), this.resourcePath);

map = outMap.toJSON();
}
}

this.callback(null, instrumented, map);
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"main": "index.js",
"files": [ "index.js" ],
"dependencies": {
"isparta": "4.x.x"
"isparta": "4.x.x",
"source-map": "^0.5.6"
},
"engines": {
"node": ">=0.10.0"
Expand Down