From f835416bfdde6a3c088341bbeb7ad6d1cb71ab32 Mon Sep 17 00:00:00 2001 From: pagoru Date: Fri, 22 Aug 2025 19:25:19 +0200 Subject: [PATCH] fix: get module path retrieves incorrect temp folder - fix #117 --- src/utils/path.utils.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/utils/path.utils.ts b/src/utils/path.utils.ts index c5d4c30..88a122b 100644 --- a/src/utils/path.utils.ts +++ b/src/utils/path.utils.ts @@ -4,10 +4,15 @@ export const getExecPath = (): string => Deno.execPath(); export const getPath = (): string => path.dirname(getExecPath()); export const getModulePath = (filePath: string = ""): string => { - // If running uncompiled (`deno run main.ts`), use Deno.mainModule - const root = Deno.mainModule.startsWith("file:") - ? path.dirname(path.fromFileUrl(Deno.mainModule)) - : path.dirname(getExecPath()); + const execBase = path.basename(Deno.execPath()).toLowerCase(); + const isCompiled = execBase !== "deno" && execBase !== "deno.exe"; - return path.join(root, filePath); + // Use a stable root that never lives in tmp: + // - compiled -> directory of the compiled binary + // - uncompiled -> directory of the entry script + const root = isCompiled + ? path.dirname(Deno.execPath()) + : path.dirname(path.fromFileUrl(Deno.mainModule)); + + return path.isAbsolute(filePath) ? filePath : path.join(root, filePath); };