Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue when module runned by deno or bun #50

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

andrew-grechkin
Copy link
Contributor

For some reason when deno or bun runtime environments are used new StackUtils().capture(2)[1].getFileName() construct returns file path as is on the system, not as file url

as it's visible on example below the call will just fail

$ echo "import Path from 'npm:@mojojs/path'; Path.currentFile();" > path.test.ts

$ deno run --allow-read path.test.ts
error: Uncaught (in promise) TypeError: Invalid URL: '/home/agrechkin/test/path.test.ts'
    at getSerialization (ext:deno_url/00_url.js:98:11)
    at new URL (ext:deno_url/00_url.js:405:27)
    at Object.fileURLToPath (node:url:1152:40)
    at Function.fromFileURL (file:///home/agrechkin/.cache/deno/npm/registry.npmjs.org/@mojojs/path/1.6.0/lib/path.js:186:29)
    at Function.currentFile (file:///home/agrechkin/.cache/deno/npm/registry.npmjs.org/@mojojs/path/1.6.0/lib/path.js:153:21)
    at file:///home/agrechkin/test/path.test.ts:1:43

the provided change will make sure Path.currentFile and Path.callerFile are working properly.

For some reason when deno or bun runtime environments are used
`new StackUtils().capture(2)[1].getFileName()` construct returns
file path as is on the system, not as file url

as it's visible on example below the call will just fail

```bash
$ echo "import Path from 'npm:@mojojs/path'; Path.currentFile();" > path.test.ts

$ deno run --allow-read path.test.ts
error: Uncaught (in promise) TypeError: Invalid URL: '/home/agrechkin/test/path.test.ts'
    at getSerialization (ext:deno_url/00_url.js:98:11)
    at new URL (ext:deno_url/00_url.js:405:27)
    at Object.fileURLToPath (node:url:1152:40)
    at Function.fromFileURL (file:///home/agrechkin/.cache/deno/npm/registry.npmjs.org/@mojojs/path/1.6.0/lib/path.js:186:29)
    at Function.currentFile (file:///home/agrechkin/.cache/deno/npm/registry.npmjs.org/@mojojs/path/1.6.0/lib/path.js:153:21)
    at file:///home/agrechkin/test/path.test.ts:1:43
```

the provided change will make sure `Path.currentFile` and `Path.callerFile` are working properly.
@kraih
Copy link
Member

kraih commented Sep 28, 2024

Unfortunate that callerFile() has no test. Must have been an oversight on my part.

@kraih kraih merged commit d1c0c48 into mojolicious:main Oct 12, 2024
6 of 7 checks passed
@kraih
Copy link
Member

kraih commented Oct 12, 2024

Thanks, merged. Lets see how it goes. I've also added tests for callerFile and currentFile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants