GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — modules: add import.meta.__dirname and import.meta.__filename by jasnell · Pull Request #39147 · nodejs/node Conversation
Member
To help ease the transition from existing CommonJS code to This may or may not be a good idea, but I've run into this const { __filename, __dirname, } = import.meta; They are only available when
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
To help ease the transition from existing CommonJS code to ESM, adds convenience properties to `import.meta` that are explicitly marked "Legacy" in the documentation. Signed-off-by: James M Snell <[email protected]>
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unused primordial.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
bmeck
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the check in the impl only uses
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
bmeck
reviewed
Comment on lines
+135
to
+136
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be done with getters / lazily?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately not, there's a test that checks that
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems fine
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
As an alternative or in parallel, I think we should also improve the documentation at https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#esm_no_filename_or_dirname or https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#esm_import_meta_url, by giving examples of how common use cases can be done with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I was hoping that one day we will get rid of CJS legacy aka |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Do we have a clear problem with including these? It won't cause a static unrecoverable error if these values are used. My main concern is this just adds 1 more code migration, though it is incremental. Adding them to import.meta still requires that code be updated so that they can be used. It also still means that examples are not shared between CJS and ESM: // __dirname is a ReferenceError here fs.readFile(import.meta.__dirname); // import.meta is a SyntaxError here fs.readFile(__dirname); I think an approach that allows both CJS and ESM to share the code would be somewhat preferable to this, but I don't have any major concerns w/ these being added except that they would be wasted compute for any module not using them and using import.meta.url (and vice versa). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
given the controversy here and given that I'm not 100% bought in to this idea either, I'm going to go ahead and close this :-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.