-
-
Notifications
You must be signed in to change notification settings - Fork 737
feat: Support import.meta.filename/dirname/resolve
#12317
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
Conversation
✅ Deploy Preview for rspack canceled.Built without sensitive environment variables
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive support for Node.js ESM features import.meta.filename, import.meta.dirname, and import.meta.resolve to align with modern Node.js module capabilities. The implementation handles various configuration modes (mock, warn-mock, eval-only, node-module, true, false) and supports both CommonJS and ESM output formats, with intelligent behavior based on target environment capabilities.
Key Changes:
- Extended
NodeStuffPluginto handleimport.meta.dirname/filenamealongside existing__dirname/__filenamesupport - Implemented
import.meta.resolve()functionality with new dependency types for module resolution - Added
importMetaDirnameAndFilenameenvironment configuration option to control native support detection - Changed
DestructuringAssignmentPropertiesfromFxHashSettoFxIndexSetto preserve property order
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs |
Core implementation for handling import.meta.dirname/filename with various node option modes, including member access, destructuring, and typeof operations |
crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs |
Added import.meta.resolve support with call handling and evaluation, plus special handling to skip dirname/filename evaluation (delegated to NodeStuffPlugin) |
crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs |
Updated parser plugin registration to support ESM-only NodeStuffPlugin instances; changed DestructuringAssignmentProperties to use FxIndexSet for order preservation |
crates/rspack_plugin_javascript/src/dependency/esm/import_meta_resolve_dependency.rs |
New dependency type for handling import.meta.resolve() module references |
crates/rspack_plugin_javascript/src/dependency/esm/import_meta_resolve_header_dependency.rs |
Header dependency for import.meta.resolve to replace callee with comment marker |
crates/rspack_core/src/options/output.rs |
Added import_meta_dirname_and_filename option to Environment config |
crates/rspack_core/src/dependency/dependency_type.rs |
Added ImportMetaResolve dependency type enum variant |
crates/rspack_binding_api/src/raw_options/raw_output.rs |
Exposed import_meta_dirname_and_filename option in binding API |
crates/node_binding/napi-binding.d.ts |
TypeScript definition for new importMetaDirnameAndFilename option |
crates/rspack_plugin_rslib/src/plugin.rs |
Updated to use new NodeStuffPlugin constructor with esm_only parameter |
tests/rspack-test/configCases/node/filename-and-dirname/* |
Comprehensive test suite covering all node option modes for both CJS and ESM formats |
crates/rspack/tests/snapshots/defaults__default_options.snap |
Updated snapshot reflecting new environment option |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs
Outdated
Show resolved
Hide resolved
crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs
Outdated
Show resolved
Hide resolved
crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs
Outdated
Show resolved
Hide resolved
17c8bf5 to
47562ad
Compare
CodSpeed Performance ReportMerging #12317 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 24 out of 25 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs
Outdated
Show resolved
Hide resolved
crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs
Outdated
Show resolved
Hide resolved
tests/rspack-test/configCases/node/filename-and-dirname/test.filter.js
Outdated
Show resolved
Hide resolved
aeeede2 to
8a4dce6
Compare
8a4dce6 to
6340d36
Compare
LingyuCoder
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
|
🎉 |
Summary
import.meta.resolve+ Node Specific Meta Values #8008Related links
import.meta.filename/dirname/resolve#10573Checklist