Skip to content

Commit 5f5a2b5

Browse files
committed
Breaking: Remove .add options & always load maps
1 parent b26b013 commit 5f5a2b5

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ function add(file, options, callback) {
4141
preExistingComment: null
4242
};
4343

44-
if (options.loadMaps) {
45-
helpers.loadInlineMaps(file, state);
46-
}
47-
48-
helpers.addSourceMaps(file, state, options, callback);
44+
helpers.addSourceMaps(file, state, callback);
4945
}
5046

5147
function write(file, options, callback) {

lib/helpers.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ function parse(data) {
2727
}
2828
}
2929

30-
function loadSourceMap(file, state, options, callback) {
30+
function loadSourceMap(file, state, callback) {
31+
// Try to read inline source map
32+
state.map = convert.fromSource(state.content);
33+
3134
if (state.map) {
35+
state.map = state.map.toObject();
36+
// sources in map are relative to the source file
37+
state.path = path.dirname(file.path);
38+
state.content = convert.removeComments(state.content);
3239
return callback();
3340
}
3441

@@ -59,7 +66,7 @@ function loadSourceMap(file, state, options, callback) {
5966
}
6067

6168
// fix source paths and sourceContent for imported source map
62-
function fixImportedSourceMap(file, state, options, callback) {
69+
function fixImportedSourceMap(file, state, callback) {
6370
if (!state.map) {
6471
return callback();
6572
}
@@ -120,7 +127,7 @@ function fixImportedSourceMap(file, state, options, callback) {
120127
}
121128
}
122129

123-
function mapsLoaded(file, state, options, callback) {
130+
function mapsLoaded(file, state, callback) {
124131

125132
if (!state.map) {
126133
state.map = {
@@ -143,27 +150,14 @@ function mapsLoaded(file, state, options, callback) {
143150
callback();
144151
}
145152

146-
function loadInlineMaps(file, state) {
147-
// Try to read inline source map
148-
state.map = convert.fromSource(state.content);
149-
150-
if (state.map) {
151-
state.map = state.map.toObject();
152-
// sources in map are relative to the source file
153-
state.path = path.dirname(file.path);
154-
state.content = convert.removeComments(state.content);
155-
}
156-
}
157-
158-
function addSourceMaps(file, state, options, callback) {
159-
153+
function addSourceMaps(file, state, callback) {
160154
var tasks = [
161155
loadSourceMap,
162156
fixImportedSourceMap,
163157
mapsLoaded,
164158
];
165159

166-
async.applyEachSeries(tasks, file, state, options, done);
160+
async.applyEachSeries(tasks, file, state, done);
167161

168162
function done(err) {
169163
if (err) {
@@ -334,7 +328,6 @@ function writeSourceMaps(file, state, options, callback) {
334328
}
335329

336330
module.exports = {
337-
loadInlineMaps: loadInlineMaps,
338331
addSourceMaps: addSourceMaps,
339332
writeSourceMaps: writeSourceMaps,
340333
unixStylePath: unixStylePath,

0 commit comments

Comments
 (0)