Socket
Socket
Sign inDemoInstall

source-map-support

Package Overview
Dependencies
2
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

.npmignore

2

package.json
{
"name": "source-map-support",
"description": "Fixes stack traces for files with source maps",
"version": "0.2.0",
"version": "0.2.1",
"main": "./source-map-support.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -7,2 +7,4 @@ # Source Map Support

#### Node support
npm install source-map-support

@@ -17,2 +19,10 @@

#### Browser support
This library also works in Chrome. While the DevTools console already supports source maps, the V8 engine doesn't and `Error.prototype.stack` will be incorrect without this library. Everything will just work if you deploy your source files using [browserify](http://browserify.org/). Just make sure to pass the `--debug` flag to the browserify command so your source maps are included in the bundled code.
This library also works if you use another build process or just include the source files directly. In this case, include the file `source-map-support.browser.js` in your page. It contains the whole library already bundled for the browser using browserify.
<script src="source-map-support.browser.js"></script>
## Options

@@ -42,3 +52,3 @@

### Basic Demo
#### Basic Demo

@@ -82,3 +92,3 @@ original.js:

### TypeScript Demo
#### TypeScript Demo

@@ -115,3 +125,3 @@ demo.ts:

### CoffeeScript Demo
#### CoffeeScript Demo

@@ -118,0 +128,0 @@ demo.coffee:

@@ -5,2 +5,11 @@ var SourceMapConsumer = require('source-map').SourceMapConsumer;

// If true, the caches are reset before a stack trace formatting operation
var emptyCacheBetweenOperations = false;
// Maps a file path to a string containing the file contents
var fileContentsCache = {};
// Maps a file path to a source map for that file
var sourceMapCache = {};
function isInBrowser() {

@@ -11,16 +20,24 @@ return typeof window !== 'undefined';

function retrieveFile(path) {
// Use SJAX if we are in the browser
if (isInBrowser()) {
var xhr = new XMLHttpRequest();
xhr.open('GET', path, false);
xhr.send(null);
return xhr.readyState === 4 ? xhr.responseText : null;
if (path in fileContentsCache) {
return fileContentsCache[path];
}
// Otherwise, use the filesystem
try {
return fs.readFileSync(path, 'utf8');
// Use SJAX if we are in the browser
if (isInBrowser()) {
var xhr = new XMLHttpRequest();
xhr.open('GET', path, false);
xhr.send(null);
var contents = xhr.readyState === 4 ? xhr.responseText : null;
}
// Otherwise, use the filesystem
else {
var contents = fs.readFileSync(path, 'utf8');
}
} catch (e) {
return null;
var contents = null;
}
return fileContentsCache[path] = contents;
}

@@ -71,4 +88,4 @@

var mapSourcePosition = exports.mapSourcePosition = function(cache, position) {
var sourceMap = cache[position.source];
var mapSourcePosition = exports.mapSourcePosition = function(position) {
var sourceMap = sourceMapCache[position.source];
if (!sourceMap) {

@@ -78,3 +95,3 @@ // Call the (overrideable) retrieveSourceMap function to get the source map.

if (urlAndMap) {
sourceMap = cache[position.source] = {
sourceMap = sourceMapCache[position.source] = {
url: urlAndMap.url,

@@ -109,7 +126,7 @@ map: new SourceMapConsumer(urlAndMap.map)

// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
function mapEvalOrigin(cache, origin) {
function mapEvalOrigin(origin) {
// Most eval() calls are in this format
var match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
if (match) {
var position = mapSourcePosition(cache, {
var position = mapSourcePosition({
source: match[2],

@@ -126,3 +143,3 @@ line: match[3],

if (match) {
return 'eval at ' + match[1] + ' (' + mapEvalOrigin(cache, match[2]) + ')';
return 'eval at ' + match[1] + ' (' + mapEvalOrigin(match[2]) + ')';
}

@@ -134,3 +151,3 @@

function wrapCallSite(cache, frame) {
function wrapCallSite(frame) {
// Most call sites will return the source file from getFileName(), but code

@@ -141,3 +158,3 @@ // passed to eval() ending in "//# sourceURL=..." will return the source file

if (source) {
var position = mapSourcePosition(cache, {
var position = mapSourcePosition({
source: source,

@@ -159,3 +176,3 @@ line: frame.getLineNumber(),

if (origin) {
origin = mapEvalOrigin(cache, origin);
origin = mapEvalOrigin(origin);
return {

@@ -174,8 +191,8 @@ __proto__: frame,

function prepareStackTrace(error, stack) {
// Store source maps in a cache so we don't load them more than once when
// formatting a single stack trace (don't cache them forever though in case
// the files change on disk and the user wants to see the updated mapping)
var cache = {};
if (emptyCacheBetweenOperations) {
fileContentsCache = {};
sourceMapCache = {};
}
return error + stack.map(function(frame) {
return '\n at ' + wrapCallSite(cache, frame);
return '\n at ' + wrapCallSite(frame);
}).join('');

@@ -192,4 +209,3 @@ }

if (match) {
var cache = {};
var position = mapSourcePosition(cache, {
var position = mapSourcePosition({
source: match[1],

@@ -220,2 +236,4 @@ line: match[2],

options.handleUncaughtExceptions : true;
emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
options.emptyCacheBetweenOperations : false;

@@ -222,0 +240,0 @@ // Allow source maps to be found by methods other than reading the files

@@ -1,2 +0,4 @@

require('./source-map-support').install();
require('./source-map-support').install({
emptyCacheBetweenOperations: true // Needed to be able to test for failure
});

@@ -3,0 +5,0 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc