Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-stack-trace

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-stack-trace - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

dist/getStackTrace.js

81

dist/index.js

@@ -6,79 +6,12 @@ "use strict";

});
exports.getStackTrace = exports.getOriginalStackTrace = void 0;
Object.defineProperty(exports, "getStackTrace", {
enumerable: true,
get: function () {
return _getStackTrace.default;
}
});
var _fs = _interopRequireDefault(require("fs"));
var _getStackTrace = _interopRequireDefault(require("./getStackTrace"));
var _path = _interopRequireDefault(require("path"));
var _bluebird = _interopRequireDefault(require("bluebird"));
var _sourceMap = require("source-map");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getStackTrace = () => {
const oldStackTraceLimit = Error.stackTraceLimit;
const oldPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (error, structuredStackTrace) => {
return structuredStackTrace;
};
const honeypot = {};
Error.captureStackTrace(honeypot);
const callSites = honeypot.stack;
Error.stackTraceLimit = oldStackTraceLimit;
Error.prepareStackTrace = oldPrepareStackTrace;
return callSites;
};
exports.getStackTrace = getStackTrace;
const isReadableFile = filePath => {
try {
_fs.default.accessSync(filePath, _fs.default.constants.R_OK);
return true;
} catch (error) {
return false;
}
};
const getOriginalStackTrace = callSites => {
return _bluebird.default.resolve(callSites).map(async callSite => {
const columnNumber = callSite.getColumnNumber();
const fileName = callSite.getFileName();
const lineNumber = callSite.getLineNumber();
const maybeMapFilePath = callSite.getFileName() + '.map';
const reportedNormalisedCallSite = {
columnNumber,
fileName,
lineNumber
};
let originalNormalisedCallSite = null;
if (isReadableFile(maybeMapFilePath)) {
const rawSourceMap = JSON.parse(_fs.default.readFileSync(maybeMapFilePath, 'utf8'));
const consumer = await new _sourceMap.SourceMapConsumer(rawSourceMap);
const originalPosition = consumer.originalPositionFor({
column: columnNumber,
line: lineNumber
});
await consumer.destroy();
originalNormalisedCallSite = {
columnNumber: originalPosition.column,
fileName: originalPosition.source ? _path.default.resolve(_path.default.basename(fileName), originalPosition.source) : null,
lineNumber: originalPosition.line
};
}
return {
callSite,
originalNormalisedCallSite,
reportedNormalisedCallSite
};
});
};
exports.getOriginalStackTrace = getOriginalStackTrace;
//# sourceMappingURL=index.js.map

@@ -13,3 +13,3 @@ {

"dependencies": {
"bluebird": "^3.5.1",
"bluebird": "^3.5.2",
"source-map": "^0.7.3"

@@ -19,15 +19,18 @@ },

"devDependencies": {
"@babel/cli": "^7.0.0-rc.1",
"@babel/core": "^7.0.0-rc.1",
"@babel/node": "^7.0.0-rc.1",
"@babel/plugin-transform-flow-strip-types": "^7.0.0-rc.1",
"@babel/preset-env": "^7.0.0-rc.1",
"@babel/register": "^7.0.0-rc.1",
"ava": "^0.25.0",
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"ava": "^1.0.0-rc.1",
"babel-plugin-istanbul": "^5.1.0",
"babel-plugin-transform-export-default-name": "^2.0.4",
"eslint": "^5.3.0",
"eslint-config-canonical": "^12.0.0",
"flow-bin": "^0.78.0",
"coveralls": "^3.0.2",
"eslint": "^5.7.0",
"eslint-config-canonical": "^13.0.0",
"flow-bin": "^0.84.0",
"flow-copy-source": "^2.0.2",
"husky": "^1.0.0-rc.13"
"husky": "^1.1.2",
"nyc": "^13.1.0"
},

@@ -54,3 +57,3 @@ "engines": {

"reporter": [
"text-lcov"
"text-summary"
],

@@ -70,5 +73,5 @@ "require": [

"lint": "eslint ./src ./test && flow",
"test": "NODE_ENV=test ava --serial --verbose"
"test": "NODE_ENV=test nyc ava --verbose --serial --concurrency 1"
},
"version": "1.0.1"
"version": "2.0.0"
}

@@ -36,45 +36,2 @@ # get-stack-trace

## Types
```js
/**
* @see https://github.com/v8/v8/wiki/Stack-Trace-API#customizing-stack-traces
*/
type CallSiteType = {|
+getColumnNumber: () => number,
+getEvalOrigin: () => string,
// eslint-disable-next-line flowtype/no-weak-types
+getFileName: () => Function | void,
+getFunction: () => string | void,
+getFunctionName: () => string,
+getLineNumber: () => number,
+getMethodName: () => string,
// eslint-disable-next-line flowtype/no-weak-types
+getThis: () => Object | void,
+getTypeName: () => string,
+isConstructor: () => boolean,
+isEval: () => boolean,
+isNative: () => boolean,
+isToplevel: () => boolean
|};
type NormalisedCallSiteType = {|
+columnNumber: string,
+fileName: string,
+lineNumber: string
|};
type ResolvedCallSiteType = {|
+callSite: CallSiteType,
+originalNormalisedCallSite: NormalisedCallSiteType,
+reportedNormalisedCallSite: NormalisedCallSiteType
|};
declare function getStackTrace (): $ReadOnlyArray<CallSiteType>;
declare function getOriginalStackTrace (): Promise<$ReadOnlyArray<ResolvedCallSiteType>>;
```
## Usage

@@ -84,8 +41,7 @@

import {
getOriginalStackTrace,
getStackTrace
} from 'get-stack-trace';
const traces = await getOriginalStackTrace(getStackTrace());
const stackTrace = await getStackTrace();
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc