get-stack-trace
Advanced tools
Comparing version 3.0.3 to 3.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getStackTrace = void 0; | ||
const stacktrace_parser_1 = require("stacktrace-parser"); | ||
const getStackTrace = () => { | ||
const oldStackTraceLimit = Error.stackTraceLimit; | ||
const oldPrepareStackTrace = Error.prepareStackTrace; | ||
Error.prepareStackTrace = (error, structuredStackTrace) => { | ||
return structuredStackTrace; | ||
}; | ||
const honeypot = { | ||
stack: [], | ||
}; | ||
Error.captureStackTrace(honeypot); | ||
const callSites = honeypot.stack; | ||
Error.stackTraceLimit = oldStackTraceLimit; | ||
Error.prepareStackTrace = oldPrepareStackTrace; | ||
const trail = callSites.slice(1); | ||
return { | ||
callSites: trail.map((callSite) => { | ||
var _a; | ||
return { | ||
columnNumber: callSite.getColumnNumber(), | ||
fileName: (_a = callSite.getFileName()) !== null && _a !== void 0 ? _a : null, | ||
functionName: callSite.getFunctionName(), | ||
lineNumber: callSite.getLineNumber(), | ||
}; | ||
}), | ||
}; | ||
// The reason we are parsing the stack trace rather than | ||
// using captureStackTrace is because captureStackTrace | ||
// does not resolve source maps, i.e. the stack trace | ||
// will contain the compiled code references rather than | ||
// the original source code references. | ||
// | ||
// eslint-disable-next-line unicorn/error-message | ||
const stackTrace = new Error().stack; | ||
if (!stackTrace) { | ||
throw new Error('Could not get stack trace'); | ||
} | ||
return (0, stacktrace_parser_1.parse)(stackTrace) | ||
.map((stackFrame) => { | ||
return { | ||
arguments: stackFrame.arguments, | ||
columnNumber: stackFrame.column, | ||
fileName: stackFrame.file, | ||
functionName: stackFrame.methodName, | ||
lineNumber: stackFrame.lineNumber, | ||
}; | ||
}) | ||
.slice(1); | ||
}; | ||
exports.getStackTrace = getStackTrace; | ||
//# sourceMappingURL=getStackTrace.js.map |
@@ -7,4 +7,6 @@ "use strict"; | ||
const stackTrace = (0, getStackTrace_1.getStackTrace)(); | ||
(0, vitest_1.expect)(stackTrace.callSites[0].fileName).toMatch(/getStackTrace/u); | ||
(0, vitest_1.expect)(stackTrace[0].fileName).toMatch(/getStackTrace/u); | ||
(0, vitest_1.expect)(stackTrace[0].lineNumber).toBe(5); | ||
(0, vitest_1.expect)(stackTrace[0].columnNumber).toBe(22); | ||
}); | ||
//# sourceMappingURL=getStackTrace.test.js.map |
export { getStackTrace } from './getStackTrace'; | ||
export { serializeStackTrace } from './serializeStackTrace'; | ||
export { CallSite, StackTrace } from './types'; | ||
export { StackFrame, StackTrace } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
'\n' + | ||
stackTrace.callSites | ||
stackTrace | ||
.map((stackFrame) => { | ||
@@ -12,0 +12,0 @@ const { columnNumber, fileName, functionName, lineNumber } = stackFrame; |
@@ -1,2 +0,3 @@ | ||
export type CallSite = { | ||
export type StackFrame = { | ||
arguments: readonly string[]; | ||
columnNumber: number | null; | ||
@@ -7,5 +8,3 @@ fileName: string | null; | ||
}; | ||
export type StackTrace = { | ||
callSites: CallSite[]; | ||
}; | ||
export type StackTrace = StackFrame[]; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -7,2 +7,5 @@ { | ||
}, | ||
"dependencies": { | ||
"stacktrace-parser": "^0.1.10" | ||
}, | ||
"description": "V8 stack traces", | ||
@@ -38,3 +41,3 @@ "devDependencies": { | ||
"types": "./dist/index.d.ts", | ||
"version": "3.0.3" | ||
"version": "3.1.0" | ||
} |
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
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
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
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
11883
1
+ Addedstacktrace-parser@^0.1.10
+ Addedstacktrace-parser@0.1.10(transitive)
+ Addedtype-fest@0.7.1(transitive)