-
Notifications
You must be signed in to change notification settings - Fork 44
Feature: NodeJS contextual pathing use cases #121
Comments
What are the alternatives? We could either accept Another thing to consider is exposing a helper function for the conversion. |
For reference re the rejections of getting file:// URL string support in Node core directly to support eg |
@benjamingr I don't believe locking |
Could we perhaps only allow URLs that include a particular symbol on the proto? We can then auto add that to import.meta.url... likely reduces the security concern since it is opt in |
I think it would be good to try and explore carefully how __filename and __dirname are used in web-workflows so we can consider exactly what the universal use cases are here. If anyone knows of good examples of libraries using __filename and __dirname on that web that would be a huge help. As far as I recall, both __filename and __dirname are built into absolute URLs in the standard browserify workflow to support things like |
Oh definitely. I was under the impression I'm personally fine with things like
This is an interesting idea, we'd have to very carefully check that it doesn't violate user expectations though since Is there any reason why |
On the web, |
I realize that this is the situation - but wouldn't making it a URL make our lives much easier? I recall @iarna and @isaacs making a compelling argument |
Do we have a comparison for the cases that are outside of what the Right now you can do some things like: import fs from 'fs';
const files = fs.readdirSync(new URL('./', import.meta.url));
console.log(files); Which don't actually require getting a raw path. I suspect most of the time this will affect child processes, but think that allowing |
the only way to really make |
Maybe this is a little late, but Is there a problem with including the At the same time, I think a very good performance metric to introduce would be the time spent in the |
I wonder if as cross env solution this would work too: const {
pathname,
filename = decodeURI(pathname.replace(/^\/([^:/]+:\/)/, '$1')),
dirname = filename.replace(/\/[^/]*$/, '')
} = new URL(import.meta.url); |
There are a number of workflows in NodeJS today that use
__filename
and__dirname
to handle contextual paths relative to the current module itself.Currently we are looking at exposing a
import.meta.url
which will be a file URL of the current module.To use this contextual URL in NodeJS APIs requires a rather unwieldy conversion process along the lines of:
It would be great if we could allow a much more polished workflow here for users.
The text was updated successfully, but these errors were encountered: