fix: Improve get caller file path util (#7974)
* fix: Improve get caller file path util * improve compatibility * update comment --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
1 parent
de0a9c14ab
commit
1393f51046
2 files changed
+15
-14
No files matched your search
@@ -4,24 +4,26 @@
|
|||||||
*/
|
*/
|
||||||
export function getCallerFilePath(position = 2) {
|
export function getCallerFilePath(position = 2) {
|
||||||
if (position >= Error.stackTraceLimit) {
|
if (position >= Error.stackTraceLimit) {
|
||||||
throw new TypeError(
|
return null
|
||||||
"getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `" +
|
|
||||||
position +
|
|
||||||
"` and Error.stackTraceLimit was: `" +
|
|
||||||
Error.stackTraceLimit +
|
|
||||||
"`"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldPrepareStackTrace = Error.prepareStackTrace
|
const oldPrepareStackTrace = Error.prepareStackTrace
|
||||||
Error.prepareStackTrace = (_, stack) => stack
|
|
||||||
const stack = new Error().stack
|
|
||||||
Error.prepareStackTrace = oldPrepareStackTrace
|
|
||||||
|
|
||||||
|
let result!: string
|
||||||
|
|
||||||
|
Error.prepareStackTrace = (_, stack) => {
|
||||||
if (stack !== null && typeof stack === "object") {
|
if (stack !== null && typeof stack === "object") {
|
||||||
// stack[0] holds this file
|
// stack[0] holds this file
|
||||||
// stack[1] holds where this function was called
|
// stack[1] holds where this function was called
|
||||||
// stack[2] holds the file we're interested in
|
// stack[2] holds the file we're interested in, in most cases, otherwise we need to get higher
|
||||||
return stack[position] ? (stack[position] as any).getFileName() : undefined
|
result = stack[position]
|
||||||
|
? (stack[position] as any).getFileName()
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
|
return stack
|
||||||
|
}
|
||||||
|
new Error().stack
|
||||||
|
Error.prepareStackTrace = oldPrepareStackTrace
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,6 @@ export function defineJoinerConfig(
|
|||||||
loadedModels = []
|
loadedModels = []
|
||||||
|
|
||||||
let index = 1
|
let index = 1
|
||||||
const maxSearchIndex = 6
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
++index
|
++index
|
||||||
@@ -101,7 +100,7 @@ export function defineJoinerConfig(
|
|||||||
|
|
||||||
loadedModels = loadModels(basePath)
|
loadedModels = loadModels(basePath)
|
||||||
|
|
||||||
if (index === maxSearchIndex || loadedModels.length) {
|
if (loadedModels.length) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user