Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/utils/path.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};