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); };