Skip to content

Commit d1c0c48

Browse files
authored
Merge pull request #50 from andrew-grechkin/agrechkin/fix-current-file
fix: issue when module runned by deno or bun
2 parents 94f07cf + f1ec66e commit d1c0c48

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/path.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ export default class Path {
103103
* Create a new `Path` object for the caller source file.
104104
*/
105105
static callerFile(): Path {
106-
return Path.fromFileURL(new StackUtils().capture(3)[2].getFileName() ?? '');
106+
const fileName = new StackUtils().capture(3)[2].getFileName() ?? '';
107+
return fileName.startsWith('file://') ? Path.fromFileURL(fileName) : new Path(fileName);
107108
}
108109

109110
/**
@@ -199,7 +200,8 @@ export default class Path {
199200
* Create a new `Path` object for the current source file.
200201
*/
201202
static currentFile(): Path {
202-
return Path.fromFileURL(new StackUtils().capture(2)[1].getFileName() ?? '');
203+
const fileName = new StackUtils().capture(2)[1].getFileName() ?? '';
204+
return fileName.startsWith('file://') ? Path.fromFileURL(fileName) : new Path(fileName);
203205
}
204206

205207
/**

0 commit comments

Comments
 (0)