get-stack-trace
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25870
24
145
16
46
2
1
Updatedbluebird@^3.5.2