Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
stack-mapper
Advanced tools
Initialize it with a source map, then feed it error stacks to have the trace locations mapped to the original files.
Readme
Initialize it with a source map, then feed it error stacks to have the trace locations mapped to the original files.
var stackMapper = require('stack-mapper');
// it is up to you to create stack-mapper compatible frame objects
// this will depend on your environment
var inframes = [{
filename: '/full/path/to/bundle.js',
line: 5,
column: 10
}, {
filename: '/full/path/to/bundle.js',
line: 9,
column: 10
}, {
filename: '/full/path/to/bundle.js',
line: 20,
column: 12
}, {
filename: '/full/path/to/bundle.js',
line: 22,
column: 10,
}, {
filename: '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles.js',
line: 18,
column: 21
}];
var map = { version: 3,
file: 'generated.js',
sources:
[ '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/barbar.js',
'/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/main.js' ],
names: [],
mappings: ';AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA',
sourcesContent:
[ '\'use strict\';\n\nfunction foobar() {\n return new Error();\n}\n\nvar go = module.exports = function () {\n return foobar(); \n};\n',
'\'use strict\';\n\nvar barbar = require(\'./barbar\');\n\nmodule.exports = function main() {\n var a = 1;\n function bar() {\n return barbar();\n }\n return bar();\n}\n' ] }
var sm = stackMapper(map);
var frames = sm.map(inframes);
console.log(frames);
[{
filename: '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/barbar.js',
line: 4,
column: 10
}, {
filename: '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/barbar.js',
line: 8,
column: 10
}, {
...
}]
You need to pass the source map as an object as shown in the example. If your source map happens to be in a different format, please use the convert-source-map module in order to convert it.
browserify attaches source maps to the bottom of the bundle if the --debug
flag is set, here is an example how to
obtain and convert it to use with stack-mapper
.
var browserify = require('browserify')
, convert = require('convert-source-map')
browserify()
.require(entry)
.bundle({ debug: true }, function (err, src) {
if (err) return cb(err);
var map = convert.fromSource(src).toObject();
});
npm install stack-mapper
/**
* Returns a Stackmapper that will use the given source map to map error trace locations.
*
* @name stackMapper
* @function
* @param {Object} sourcemap source map for the generated file
* @return {StackMapper} stack mapper for the particular source map
*/
/**
* Maps the trace statements of the given error stack and replaces locations
* referencing code in the generated file with the locations inside the original files.
*
* @name map
* @function
* @param {Array} array of callsite objects (see readme for details about Callsite object)
* @param {boolean} includeSource if set to true, the source code at the first traced location is included
* @return {Array.<Object>} info about the error stack with adapted locations, each with the following properties
* - filename: original filename
* - line: origial line in that filename of the trace
* - column: origial column on that line of the trace
*/
The frames array passed to stackMapper.map should contain at least the following items
MIT
FAQs
Initialize it with a source map, then feed it error stacks to have the trace locations mapped to the original files.
The npm package stack-mapper receives a total of 801 weekly downloads. As such, stack-mapper popularity was classified as not popular.
We found that stack-mapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.