[react-packager] kill non-standard RAW_SOURCE_MAP

This commit is contained in:
Amjad Masad 2015-03-24 17:32:03 -07:00
parent bef3d46cee
commit ec1b9ec735
3 changed files with 15 additions and 12 deletions

View File

@ -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;
};

View File

@ -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'));
});

View File

@ -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
),
};
}