-
-
Notifications
You must be signed in to change notification settings - Fork 738
fix(javascript): prevent import.meta.url replacement in web target #12266
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for rspack ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
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 fixes an issue where import.meta.url was incorrectly replaced with a file:// URL during the build process for web targets. The fix ensures that when targeting web environments (where document is supported), import.meta.url is preserved in the output, allowing the browser to resolve it to the actual script URL at runtime.
Key Changes:
- Modified
ImportMetaPluginto check target environment capabilities before replacingimport.meta.url - Added test case to verify
import.meta.urlpreservation in web targets
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs |
Updated evaluate_identifier and member methods to conditionally preserve import.meta.url based on whether the target supports document |
tests/rspack-test/configCases/parsing/import-meta-url-web/rspack.config.js |
Test configuration targeting web environment |
tests/rspack-test/configCases/parsing/import-meta-url-web/index.js |
Test assertion verifying import.meta.url is not a file path in web builds |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| start, | ||
| end, | ||
| )) | ||
| if parser.compiler_options.output.environment.supports_document() { |
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.
The script must be an ES module to use import.meta.url. We could not use supports_document() to determine this.
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.
Pushed an update
The script must be an ES module to use import.meta.url. We cannot use supports_document() to determine this. This change adds a check for parser.is_esm before handling import.meta.url in both evaluate_identifier and member methods.
CodSpeed Performance ReportMerging #12266 will not alter performanceComparing Summary
Footnotes |
Description
This PR fixes an issue where
import.meta.urlwas unconditionally replaced by the local file path during the build, causingfile:///URLs to appear in web builds.Fix
Modified
ImportMetaPluginto check if the target environment supportsdocument. If it does (web target),import.meta.urlis preserved in the output.Verification
Added a new test case
tests/rspack-test/configCases/parsing/import-meta-url-webwhich asserts thatimport.meta.urlis not replaced by afile://URL when targeting web.