From 7ea7a6cbb191adeacb0aaf3511b95d53241f52ca Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 15 Feb 2013 00:23:03 -0800 Subject: [PATCH] Automatically set a source map's "sources" key based on the build performed. Former-commit-id: c02c88dfd1db097a3f98113ee57c3da850da5abb --- build.js | 3 ++- test/test-build.js | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/build.js b/build.js index e38a3f1aa..cd1cfe9a0 100755 --- a/build.js +++ b/build.js @@ -2414,9 +2414,10 @@ } else if (!isStdOut) { outputUsed = true; + filePath = outputPath || path.join(cwd, basename + '.js'); callback({ 'source': debugSource, - 'outputPath': outputPath || path.join(cwd, basename + '.js') + 'outputPath': filePath }); } } diff --git a/test/test-build.js b/test/test-build.js index e7ece6995..64a4dba3d 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -643,33 +643,38 @@ QUnit.module('source maps'); (function() { - var commands = [ + var mapCommands = [ '-p', '--source-map' ]; - var outputPaths = [ + var outputCommands = [ '', - '-o foo.js' + '-o foo.js', + '-m -o bar.js' ]; - commands.forEach(function(command) { - outputPaths.forEach(function(outputPath) { - asyncTest('`lodash ' + command + (outputPath ? ' ' + outputPath : '') + '`', function() { - var start = _.once(QUnit.start); - outputPath = outputPath ? outputPath.split(' ') : []; - - build(['-s', '-m', command].concat(outputPath), function(data) { + mapCommands.forEach(function(mapCommand) { + outputCommands.forEach(function(outputCommand) { + asyncTest('`lodash ' + mapCommand + (outputCommand ? ' ' + outputCommand : '') + '`', function() { + var callback = _.once(function(data) { var basename = path.basename(data.outputPath, '.js'), comment = (/(\s*\/\/.*\s*|\s*\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/\s*)$/.exec(data.source) || [])[0], + sources = /foo.js/.test(outputCommand) ? ['foo.js'] : ['lodash' + (outputCommand.length ? '' : '.custom') + '.js'], sourceMap = JSON.parse(data.sourceMap); ok(RegExp('/\\*\\n//@ sourceMappingURL=' + basename + '.map\\n\\*/').test(comment), basename); equal(sourceMap.file, basename + '.js', basename); - deepEqual(sourceMap.sources, ['lodash.js'], basename); + deepEqual(sourceMap.sources, sources, basename); - start(); + QUnit.start(); }); + + outputCommand = outputCommand ? outputCommand.split(' ') : []; + if (outputCommand.indexOf('-m') < 0) { + callback = _.after(2, callback); + } + build(['-s', mapCommand].concat(outputCommand), callback); }); }); });