diff --git a/packages/core/utils/src/common/get-caller-file-path.ts b/packages/core/utils/src/common/get-caller-file-path.ts index c4f1dd25bc..1fd38aded6 100644 --- a/packages/core/utils/src/common/get-caller-file-path.ts +++ b/packages/core/utils/src/common/get-caller-file-path.ts @@ -4,24 +4,26 @@ */ export function getCallerFilePath(position = 2) { 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 + - "`" - ) + return null } const oldPrepareStackTrace = Error.prepareStackTrace - Error.prepareStackTrace = (_, stack) => stack - const stack = new Error().stack + + let result!: string + + Error.prepareStackTrace = (_, stack) => { + 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, in most cases, otherwise we need to get higher + result = stack[position] + ? (stack[position] as any).getFileName() + : undefined + } + return stack + } + new Error().stack 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 result } diff --git a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts index 87075d0a66..ee7b7f1275 100644 --- a/packages/core/utils/src/modules-sdk/joiner-config-builder.ts +++ b/packages/core/utils/src/modules-sdk/joiner-config-builder.ts @@ -69,7 +69,6 @@ export function defineJoinerConfig( loadedModels = [] let index = 1 - const maxSearchIndex = 6 while (true) { ++index @@ -101,7 +100,7 @@ export function defineJoinerConfig( loadedModels = loadModels(basePath) - if (index === maxSearchIndex || loadedModels.length) { + if (loadedModels.length) { break } }