From ec34ab14b6a0c97d07f446c164a87a9599598a87 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 19 Apr 2017 16:56:37 -0500 Subject: [PATCH] Breaking: Remove destPath option --- index.js | 2 +- lib/helpers.js | 28 ++++++++-------------------- test/write.js | 22 +--------------------- 3 files changed, 10 insertions(+), 42 deletions(-) diff --git a/index.js b/index.js index 04ecb44..ef933c8 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ function write(file, options, callback) { sourceMapFile: null, }; - helpers.writeSourceMaps(file, state, opts, callback); + helpers.writeSourceMaps(file, state, callback); } module.exports = { diff --git a/lib/helpers.js b/lib/helpers.js index 700b18a..7b20286 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -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 || []; @@ -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) { @@ -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 @@ -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) { diff --git a/test/write.js b/test/write.js index 06762b9..e4dee0b 100644 --- a/test/write.js +++ b/test/write.js @@ -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(); @@ -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) { @@ -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';