-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use different appraoch to find definition file
- Loading branch information
Showing
5 changed files
with
35 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function getCallerFilePath(position = 2): string | undefined { | ||
if (position >= Error.stackTraceLimit) { | ||
throw new TypeError( | ||
`getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: \`${position}\` and Error.stackTraceLimit was: \`${Error.stackTraceLimit}\`` | ||
); | ||
} | ||
|
||
const oldPrepareStackTrace = Error.prepareStackTrace; | ||
Error.prepareStackTrace = (_, stack) => stack; | ||
// eslint-disable-next-line unicorn/error-message | ||
const { stack } = new Error(); | ||
Error.prepareStackTrace = oldPrepareStackTrace; | ||
|
||
if (stack !== null && typeof stack === 'object') { | ||
// stack[0] holds this file | ||
// stack[1] holds where this function was called | ||
// stack[2] holds the file we're interested in | ||
return stack[position] ? (stack[position] as any).getFileName() : undefined; | ||
} | ||
return undefined; | ||
} |