Support specifying sourcemap via HTTP headers
As noted in https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit, the URL for sourcemaps can be specified via a 'SourceMap' header. It was previously called 'X-SourceMap', so let's support that too.
This commit is contained in:
parent
7e9bcdcba0
commit
a9ceaf67c3
@ -53,17 +53,38 @@ function supportRelativeURL(file, url) {
|
|||||||
return protocol + path.resolve(dir.slice(protocol.length), url);
|
return protocol + path.resolve(dir.slice(protocol.length), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function retrieveSourceMapURL(source) {
|
||||||
|
var fileData;
|
||||||
|
|
||||||
|
if (isInBrowser()) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', source, false);
|
||||||
|
xhr.send(null);
|
||||||
|
fileData = xhr.readyState === 4 ? xhr.responseText : null;
|
||||||
|
|
||||||
|
// Support providing a sourceMappingURL via the SourceMap header
|
||||||
|
var sourceMapHeader = xhr.getResponseHeader("SourceMap") ||
|
||||||
|
xhr.getResponseHeader("X-SourceMap");
|
||||||
|
if (sourceMapHeader) {
|
||||||
|
return sourceMapHeader;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fileData = retrieveFile(source);
|
||||||
|
}
|
||||||
|
// Get the URL of the source map
|
||||||
|
var match = /\/\/[#@]\s*sourceMappingURL=(.*)\s*$/m.exec(fileData);
|
||||||
|
if (!match) return null;
|
||||||
|
return match[1];
|
||||||
|
};
|
||||||
|
|
||||||
// Can be overridden by the retrieveSourceMap option to install. Takes a
|
// Can be overridden by the retrieveSourceMap option to install. Takes a
|
||||||
// generated source filename; returns a {map, optional url} object, or null if
|
// generated source filename; returns a {map, optional url} object, or null if
|
||||||
// there is no source map. The map field may be either a string or the parsed
|
// there is no source map. The map field may be either a string or the parsed
|
||||||
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
|
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
|
||||||
// constructor).
|
// constructor).
|
||||||
function retrieveSourceMap(source) {
|
function retrieveSourceMap(source) {
|
||||||
// Get the URL of the source map
|
var sourceMappingURL = retrieveSourceMapURL(source);
|
||||||
var fileData = retrieveFile(source);
|
if (!sourceMappingURL) return null;
|
||||||
var match = /\/\/[#@]\s*sourceMappingURL=(.*)\s*$/m.exec(fileData);
|
|
||||||
if (!match) return null;
|
|
||||||
var sourceMappingURL = match[1];
|
|
||||||
|
|
||||||
// Read the contents of the source map
|
// Read the contents of the source map
|
||||||
var sourceMapData;
|
var sourceMapData;
|
||||||
|
Loading…
Reference in New Issue
Block a user