From 041952cdfe1338bc8c4c29cf038eb7f148fc6400 Mon Sep 17 00:00:00 2001 From: pagoru Date: Fri, 22 Aug 2025 18:45:46 +0200 Subject: [PATCH] fix: module path for compiled --- src/modules/updater.ts | 3 +-- src/utils/path.utils.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/updater.ts b/src/modules/updater.ts index d0e2f36..df78693 100644 --- a/src/modules/updater.ts +++ b/src/modules/updater.ts @@ -2,7 +2,6 @@ import { getModulePath, getOS, getOSName, - getPath, getTemporalUpdateFilePathname, } from "../utils/main.ts"; import { OS } from "../enums/main.ts"; @@ -106,7 +105,7 @@ export const update = async ({ log(`[${label}] Update files downloaded!`); const dirPath = getModulePath(""); - const updateFilePath = getModulePath(getTemporalUpdateFilePathname()); + const updateFilePath = getTemporalUpdateFilePathname(); const updateFile = path.join(dirPath, `update_${osAsset.name}`); const updatedFile = path.join(dirPath, osAsset.name); diff --git a/src/utils/path.utils.ts b/src/utils/path.utils.ts index 823b942..c5d4c30 100644 --- a/src/utils/path.utils.ts +++ b/src/utils/path.utils.ts @@ -3,5 +3,11 @@ import * as path from "@std/path"; export const getExecPath = (): string => Deno.execPath(); export const getPath = (): string => path.dirname(getExecPath()); -export const getModulePath = (filePath: string = ""): string => - path.join(path.dirname(path.fromFileUrl(Deno.mainModule)), filePath); +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()); + + return path.join(root, filePath); +};