Skip to content

Commit

Permalink
Breaking: Remove destPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 17, 2017
1 parent 571fbcf commit ec34ab1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 42 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function write(file, options, callback) {
sourceMapFile: null,
};

helpers.writeSourceMaps(file, state, opts, callback);
helpers.writeSourceMaps(file, state, callback);
}

module.exports = {
Expand Down
28 changes: 8 additions & 20 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function commentFormatter(extname, url) {
return convert.generateMapFileComment(url, opts);
}

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

state.sourceMap.sourcesContent = state.sourceMap.sourcesContent || [];

Expand All @@ -239,7 +239,7 @@ function includeContent(file, state, options, callback) {
async.eachOf(file.sourceMap.sources, loadSources, callback);
}

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

var comment;
if (state.destPath == undefined) {
Expand All @@ -252,22 +252,10 @@ function contentIncluded(file, state, options, callback) {

var sourceMapPath = path.join(file.base, mapFile);

// if explicit destination path is set
if (options.destPath) {
var destSourceMapPath = path.join(file.cwd, options.destPath, mapFile);
var destFilePath = path.join(file.cwd, options.destPath, file.relative);
state.sourceMap.file = normalizePath(path.relative(path.dirname(destSourceMapPath), destFilePath));
if (state.sourceMap.sourceRoot === undefined) {
state.sourceMap.sourceRoot = normalizePath(path.relative(path.dirname(destSourceMapPath), file.base));
} else if (state.sourceMap.sourceRoot === '' || (state.sourceMap.sourceRoot && state.sourceMap.sourceRoot[0] === '.')) {
state.sourceMap.sourceRoot = normalizePath(path.join(path.relative(path.dirname(destSourceMapPath), file.base), state.sourceMap.sourceRoot));
}
} else {
// best effort, can be incorrect if options.destPath not set
state.sourceMap.file = normalizePath(path.relative(path.dirname(sourceMapPath), file.path));
if (state.sourceMap.sourceRoot === '' || (state.sourceMap.sourceRoot && state.sourceMap.sourceRoot[0] === '.')) {
state.sourceMap.sourceRoot = normalizePath(path.join(path.relative(path.dirname(sourceMapPath), file.base), state.sourceMap.sourceRoot));
}
// best effort, can be incorrect if options.destPath not set
state.sourceMap.file = normalizePath(path.relative(path.dirname(sourceMapPath), file.path));
if (state.sourceMap.sourceRoot === '' || (state.sourceMap.sourceRoot && state.sourceMap.sourceRoot[0] === '.')) {
state.sourceMap.sourceRoot = normalizePath(path.join(path.relative(path.dirname(sourceMapPath), file.base), state.sourceMap.sourceRoot));
}

// add new source map file to state
Expand All @@ -293,13 +281,13 @@ function contentIncluded(file, state, options, callback) {
callback();
}

function writeSourceMaps(file, state, options, callback) {
function writeSourceMaps(file, state, callback) {
var tasks = [
includeContent,
contentIncluded
];

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

function done(err) {
if (err) {
Expand Down
22 changes: 1 addition & 21 deletions test/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('write', function() {
});
});

it('should write external map files', function(done) {
it.skip('should write external map files', function(done) {
var file = makeFile();
sourcemaps.write(file, { path: '../maps', destPath: 'dist' }, function(err, updatedFile, sourceMapFile) {
expect(updatedFile instanceof File).toExist();
Expand Down Expand Up @@ -285,16 +285,6 @@ describe('write', function() {
});
});

it('should automatically determine sourceRoot if destPath is set', function(done) {
var file = makeNestedFile();
sourcemaps.write(file, { path: '.', destPath: 'dist', includeContent: false }, function(err, updatedFile, sourceMapFile) {
expect(updatedFile.sourceMap.sourceRoot).toBe('../../../assets');
expect(updatedFile.sourceMap.file).toBe('helloworld.js');
expect(sourceMapFile.path).toBe(path.join(__dirname, 'assets/dir1/dir2/helloworld.js.map'));
done(err);
});
});

it('should interpret relative path in sourceRoot as relative to destination', function(done) {
var file = makeNestedFile();
sourcemaps.write(file, { path: '.', sourceRoot: '../src' }, function(err, updatedFile, sourceMapFile) {
Expand Down Expand Up @@ -325,16 +315,6 @@ describe('write', function() {
});
});

it('should interpret relative path in sourceRoot as relative to destination (part 4)', function(done) {
var file = makeNestedFile();
sourcemaps.write(file, { path: '../maps', sourceRoot: '../src', destPath: 'dist' }, function(err, updatedFile, sourceMapFile) {
expect(updatedFile.sourceMap.sourceRoot).toBe('../../../src');
expect(updatedFile.sourceMap.file).toBe('../../../dist/dir1/dir2/helloworld.js');
expect(sourceMapFile.path).toBe(path.join(__dirname, 'maps/dir1/dir2/helloworld.js.map'));
done(err);
});
});

it.skip('should output an error message if debug option is set and sourceContent is missing', function(done) {
var file = makeFile();
file.sourceMap.sources[0] += '.invalid';
Expand Down

0 comments on commit ec34ab1

Please sign in to comment.