Skip to content

Commit

Permalink
Merge pull request #50 from andrew-grechkin/agrechkin/fix-current-file
Browse files Browse the repository at this point in the history
fix: issue when module runned by deno or bun
  • Loading branch information
kraih authored Oct 12, 2024
2 parents 94f07cf + f1ec66e commit d1c0c48
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export default class Path {
* Create a new `Path` object for the caller source file.
*/
static callerFile(): Path {
return Path.fromFileURL(new StackUtils().capture(3)[2].getFileName() ?? '');
const fileName = new StackUtils().capture(3)[2].getFileName() ?? '';
return fileName.startsWith('file://') ? Path.fromFileURL(fileName) : new Path(fileName);
}

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

/**
Expand Down

0 comments on commit d1c0c48

Please sign in to comment.