feat(import.meta): add dirname and filename#19990
feat(import.meta): add dirname and filename#19990avivkeller wants to merge 1 commit intowebpack:mainfrom
Conversation
There was a problem hiding this comment.
It should not work like here, import.meta.dirname and import.meta.filename arenot supported by browsers (and maybe other envs), we should do the same as for __dirname and __filename, look at NdeStuffPlugin.js and we should do the same
Developer can use fs.readFileSync(import.meta.filename) and after bundling the path will be broken
CodSpeed Performance ReportMerging #19990 will not alter performanceComparing Summary
|
You mean like a variable response depending on the value of |
|
@avivkeller Yeah, we should duplicate logic, but for such things, and improve Feel free to split these steps into multiple commits/PRs |
1394761 to
c9364e1
Compare
3d3ec97 to
06dcb6c
Compare
|
Bump @alexander-akait |
|
@avivkeller Yeah, in my roadmap to review (will be part of the next minor release) |
| if (!parser.state.module) return; | ||
| const resource = parseResource(parser.state.module.resource); | ||
| return evaluateToString(resource.path)(expr); | ||
| if (isCJS) { |
There was a problem hiding this comment.
global supported in ES modules and CommonJS, so we should always handle this
| valueGetter(parser.state.module), | ||
| /** @type {Range} */ (expr.range), | ||
| [RuntimeGlobals.global] | ||
| /** @type {EXPECTED_ANY} */ (prop) |
There was a problem hiding this comment.
Don't use EXPECTED_ANY, we have types here
alexander-akait
left a comment
There was a problem hiding this comment.
Can you avoid refactoring here and implement only import.meta.__dirname and import.meta.__filename support and then we will do refactor in separate PR, hard to review and a lot of not related to the issue changes
|
The slight refactor makes it easier to keep the code DRY, since logic has to be repeated for ESM and CJS implementations. |
Summary
Fixes #18320 by adding the requested
import.metaproperties.What kind of change does this PR introduce?
This PR adds support for
import.meta.{dirname,filename}, having them return the identical data that__dirnameand__filenamereturn.Did you add tests for your changes?
Yes. I verified that
import.meta.dirname + [filename] === import.meta.filename === an existing file.Does this PR introduce a breaking change?
No, this is a semver-minor change.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Once merged, the additional properties must be documented accordingly.