aboutsummaryrefslogtreecommitdiff
path: root/node_modules/source-map-support/source-map-support.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/source-map-support/source-map-support.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/source-map-support/source-map-support.js')
-rw-r--r--node_modules/source-map-support/source-map-support.js67
1 files changed, 50 insertions, 17 deletions
diff --git a/node_modules/source-map-support/source-map-support.js b/node_modules/source-map-support/source-map-support.js
index abd888604..06ac0f9ba 100644
--- a/node_modules/source-map-support/source-map-support.js
+++ b/node_modules/source-map-support/source-map-support.js
@@ -12,6 +12,8 @@ try {
/* nop */
}
+var bufferFrom = require('buffer-from');
+
// Only install once if called multiple times
var errorFormatterInstalled = false;
var uncaughtShimInstalled = false;
@@ -64,39 +66,52 @@ var retrieveFile = handlerExec(retrieveFileHandlers);
retrieveFileHandlers.push(function(path) {
// Trim the path to make sure there is no extra whitespace.
path = path.trim();
+ if (/^file:/.test(path)) {
+ // existsSync/readFileSync can't handle file protocol, but once stripped, it works
+ path = path.replace(/file:\/\/\/(\w:)?/, function(protocol, drive) {
+ return drive ?
+ '' : // file:///C:/dir/file -> C:/dir/file
+ '/'; // file:///root-dir/file -> /root-dir/file
+ });
+ }
if (path in fileContentsCache) {
return fileContentsCache[path];
}
- var contents = null;
- if (!fs) {
- // Use SJAX if we are in the browser
- var xhr = new XMLHttpRequest();
- xhr.open('GET', path, false);
- xhr.send(null);
- var contents = null
- if (xhr.readyState === 4 && xhr.status === 200) {
- contents = xhr.responseText
- }
- } else if (fs.existsSync(path)) {
- // Otherwise, use the filesystem
- try {
+ var contents = '';
+ try {
+ if (!fs) {
+ // Use SJAX if we are in the browser
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', path, /** async */ false);
+ xhr.send(null);
+ if (xhr.readyState === 4 && xhr.status === 200) {
+ contents = xhr.responseText;
+ }
+ } else if (fs.existsSync(path)) {
+ // Otherwise, use the filesystem
contents = fs.readFileSync(path, 'utf8');
- } catch (er) {
- contents = '';
}
+ } catch (er) {
+ /* ignore any errors */
}
return fileContentsCache[path] = contents;
});
// Support URLs relative to a directory, but be careful about a protocol prefix
-// in case we are in the browser (i.e. directories may start with "http://")
+// in case we are in the browser (i.e. directories may start with "http://" or "file:///")
function supportRelativeURL(file, url) {
if (!file) return url;
var dir = path.dirname(file);
var match = /^\w+:\/\/[^\/]*/.exec(dir);
var protocol = match ? match[0] : '';
+ var startPath = dir.slice(protocol.length);
+ if (protocol && /^\/\w\:/.test(startPath)) {
+ // handle file:///C:/ paths
+ protocol += '/';
+ return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, '/');
+ }
return protocol + path.resolve(dir.slice(protocol.length), url);
}
@@ -146,7 +161,7 @@ retrieveMapHandlers.push(function(source) {
if (reSourceMap.test(sourceMappingURL)) {
// Support source map URL as a data url
var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
- sourceMapData = new Buffer(rawData, "base64").toString();
+ sourceMapData = bufferFrom(rawData, "base64").toString();
sourceMappingURL = source;
} else {
// Support source map URLs relative to the source URL
@@ -346,6 +361,8 @@ function wrapCallSite(frame) {
column: column
});
frame = cloneCallSite(frame);
+ var originalFunctionName = frame.getFunctionName;
+ frame.getFunctionName = function() { return position.name || originalFunctionName(); };
frame.getFileName = function() { return position.source; };
frame.getLineNumber = function() { return position.line; };
frame.getColumnNumber = function() { return position.column + 1; };
@@ -414,6 +431,11 @@ function getErrorSource(error) {
function printErrorAndExit (error) {
var source = getErrorSource(error);
+ // Ensure error is printed synchronously and not truncated
+ if (process.stderr._handle && process.stderr._handle.setBlocking) {
+ process.stderr._handle.setBlocking(true);
+ }
+
if (source) {
console.error();
console.error(source);
@@ -440,6 +462,9 @@ function shimEmitUncaughtException () {
};
}
+var originalRetrieveFileHandlers = retrieveFileHandlers.slice(0);
+var originalRetrieveMapHandlers = retrieveMapHandlers.slice(0);
+
exports.wrapCallSite = wrapCallSite;
exports.getErrorSource = getErrorSource;
exports.mapSourcePosition = mapSourcePosition;
@@ -525,3 +550,11 @@ exports.install = function(options) {
}
}
};
+
+exports.resetRetrieveHandlers = function() {
+ retrieveFileHandlers.length = 0;
+ retrieveMapHandlers.length = 0;
+
+ retrieveFileHandlers = originalRetrieveFileHandlers.slice(0);
+ retrieveMapHandlers = originalRetrieveMapHandlers.slice(0);
+}