From 909e393f2632674ab647234bdf6f148b1750585c Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Tue, 24 Mar 2015 17:32:03 -0700 Subject: [PATCH] [react-packager] kill non-standard RAW_SOURCE_MAP --- packager/react-packager/src/Packager/Package.js | 10 +++++----- .../src/Packager/__tests__/Package-test.js | 8 +++----- packager/react-packager/src/Server/index.js | 9 +++++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packager/react-packager/src/Packager/Package.js b/packager/react-packager/src/Packager/Package.js index 99edbbe0a..0f55c8edc 100644 --- a/packager/react-packager/src/Packager/Package.js +++ b/packager/react-packager/src/Packager/Package.js @@ -68,10 +68,9 @@ Package.prototype._getSource = function() { Package.prototype._getInlineSourceMap = function() { if (this._inlineSourceMap == null) { var sourceMap = this.getSourceMap({excludeSource: true}); - this._inlineSourceMap = '\nRAW_SOURCE_MAP = ' + - JSON.stringify(sourceMap) + ';'; + var encoded = new Buffer(JSON.stringify(sourceMap)).toString('base64'); + this._inlineSourceMap = 'data:application/json;base64,' + encoded; } - return this._inlineSourceMap; }; @@ -85,13 +84,14 @@ Package.prototype.getSource = function(options) { } var source = this._getSource(); + source += '\n\/\/@ sourceMappingURL='; if (options.inlineSourceMap) { source += this._getInlineSourceMap(); + } else { + source += this._sourceMapUrl; } - source += '\n\/\/@ sourceMappingURL=' + this._sourceMapUrl; - return source; }; diff --git a/packager/react-packager/src/Packager/__tests__/Package-test.js b/packager/react-packager/src/Packager/__tests__/Package-test.js index ee94437d1..5a7438d27 100644 --- a/packager/react-packager/src/Packager/__tests__/Package-test.js +++ b/packager/react-packager/src/Packager/__tests__/Package-test.js @@ -29,11 +29,10 @@ describe('Package', function() { ppackage.addModule('transformed foo;', 'source foo', 'foo path'); ppackage.addModule('transformed bar;', 'source bar', 'bar path'); ppackage.finalize({}); - expect(ppackage.getSource({inlineSourceMap: true})).toBe([ + expect(ppackage.getSource()).toBe([ 'transformed foo;', 'transformed bar;', - 'RAW_SOURCE_MAP = "test-source-map";', - '\/\/@ sourceMappingURL=test_url', + '\/\/@ sourceMappingURL=test_url' ].join('\n')); }); @@ -42,11 +41,10 @@ describe('Package', function() { ppackage.addModule('transformed bar;', 'source bar', 'bar path'); ppackage.setMainModuleId('foo'); ppackage.finalize({runMainModule: true}); - expect(ppackage.getSource({inlineSourceMap: true})).toBe([ + expect(ppackage.getSource()).toBe([ 'transformed foo;', 'transformed bar;', ';require("foo");', - 'RAW_SOURCE_MAP = "test-source-map";', '\/\/@ sourceMappingURL=test_url', ].join('\n')); }); diff --git a/packager/react-packager/src/Server/index.js b/packager/react-packager/src/Server/index.js index 19ec00395..f40ebeeaf 100644 --- a/packager/react-packager/src/Server/index.js +++ b/packager/react-packager/src/Server/index.js @@ -98,7 +98,7 @@ Server.prototype._rebuildPackages = function() { packages[key] = buildPackage(options).then(function(p) { // Make a throwaway call to getSource to cache the source string. p.getSource({ - inlineSourceMap: options.dev, + inlineSourceMap: options.inlineSourceMap, minify: options.minify, }); return p; @@ -228,7 +228,7 @@ Server.prototype.processRequest = function(req, res, next) { function(p) { if (requestType === 'bundle') { res.end(p.getSource({ - inlineSourceMap: options.dev, + inlineSourceMap: options.inlineSourceMap, minify: options.minify, })); Activity.endEvent(startReqEventId); @@ -264,6 +264,11 @@ function getOptionsFromUrl(reqUrl) { dev: getBoolOptionFromQuery(urlObj.query, 'dev', true), minify: getBoolOptionFromQuery(urlObj.query, 'minify'), runModule: getBoolOptionFromQuery(urlObj.query, 'runModule', true), + inlineSourceMap: getBoolOptionFromQuery( + urlObj.query, + 'inlineSourceMap', + false + ), }; }