Skip to content

Commit

Permalink
Breaking: Remove .add options & always load maps
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 17, 2017
1 parent b26b013 commit 5f5a2b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ function add(file, options, callback) {
preExistingComment: null
};

if (options.loadMaps) {
helpers.loadInlineMaps(file, state);
}

helpers.addSourceMaps(file, state, options, callback);
helpers.addSourceMaps(file, state, callback);
}

function write(file, options, callback) {
Expand Down
31 changes: 12 additions & 19 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ function parse(data) {
}
}

function loadSourceMap(file, state, options, callback) {
function loadSourceMap(file, state, callback) {
// Try to read inline source map
state.map = convert.fromSource(state.content);

if (state.map) {
state.map = state.map.toObject();
// sources in map are relative to the source file
state.path = path.dirname(file.path);
state.content = convert.removeComments(state.content);
return callback();
}

Expand Down Expand Up @@ -59,7 +66,7 @@ function loadSourceMap(file, state, options, callback) {
}

// fix source paths and sourceContent for imported source map
function fixImportedSourceMap(file, state, options, callback) {
function fixImportedSourceMap(file, state, callback) {
if (!state.map) {
return callback();
}
Expand Down Expand Up @@ -120,7 +127,7 @@ function fixImportedSourceMap(file, state, options, callback) {
}
}

function mapsLoaded(file, state, options, callback) {
function mapsLoaded(file, state, callback) {

if (!state.map) {
state.map = {
Expand All @@ -143,27 +150,14 @@ function mapsLoaded(file, state, options, callback) {
callback();
}

function loadInlineMaps(file, state) {
// Try to read inline source map
state.map = convert.fromSource(state.content);

if (state.map) {
state.map = state.map.toObject();
// sources in map are relative to the source file
state.path = path.dirname(file.path);
state.content = convert.removeComments(state.content);
}
}

function addSourceMaps(file, state, options, callback) {

function addSourceMaps(file, state, callback) {
var tasks = [
loadSourceMap,
fixImportedSourceMap,
mapsLoaded,
];

async.applyEachSeries(tasks, file, state, options, done);
async.applyEachSeries(tasks, file, state, done);

function done(err) {
if (err) {
Expand Down Expand Up @@ -334,7 +328,6 @@ function writeSourceMaps(file, state, options, callback) {
}

module.exports = {
loadInlineMaps: loadInlineMaps,
addSourceMaps: addSourceMaps,
writeSourceMaps: writeSourceMaps,
unixStylePath: unixStylePath,
Expand Down

0 comments on commit 5f5a2b5

Please sign in to comment.