-
-
Notifications
You must be signed in to change notification settings - Fork 757
feat: add requireAlias option to control require variable renaming
#12686
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 ready!
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 introduces a new experimental parser option requireRename for JavaScript modules, providing control over whether the require identifier can be renamed to other variables. The option defaults to true (allowing renaming), maintaining backward compatibility, while setting it to false preserves the require identifier in the output bundle.
Key changes:
- Added
requireRenameboolean option to JavascriptParserOptions with default value oftrue - Implemented parser logic to respect the option when determining if
requirecan be renamed - Added comprehensive test coverage for both enabled (default) and disabled renaming scenarios
Reviewed changes
Copilot reviewed 16 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/rspack/src/config/types.ts | Added requireRename type definition to JavascriptParserOptions |
| packages/rspack/src/config/defaults.ts | Set default value of requireRename to true |
| packages/rspack/src/config/adapter.ts | Added adapter mapping for requireRename option |
| packages/rspack/etc/core.api.md | Updated API documentation with new option |
| crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs | Implemented core logic to check require_rename option in can_rename method |
| crates/rspack_core/src/options/module.rs | Added require_rename field to JavascriptParserOptions struct |
| crates/rspack_binding_api/src/raw_options/raw_module/mod.rs | Added binding support for requireRename with experimental annotation |
| crates/rspack/src/builder/mod.rs | Set builder default value to true |
| crates/node_binding/napi-binding.d.ts | Added TypeScript bindings with experimental JSDoc annotation |
| crates/rspack/tests/snapshots/defaults__default_options.snap | Updated snapshot to include new option |
| tests/rspack-test/normalCases/parsing/renaming/index.js | Uncommented existing tests to verify default renaming behavior |
| tests/rspack-test/configCases/parsing/renaming-disabled/* | Added new test case to verify disabled renaming behavior |
| tests/rspack-test/defaultsCases/default/base.js | Updated snapshot to include requireRename: true |
| tests/rspack-test/defaultsCases/library/*.js | Fixed indentation in inline snapshots (formatting) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/rspack-test/configCases/parsing/renaming-disabled/index.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 7.00KB from 47.87MB to 47.88MB (⬆️0.01%) |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
requireAlias option to control require variable renaming
0a86fc3 to
44e0b46
Compare
…12686) * feat: add requireRename option to control require variable renaming * Update packages/rspack/src/config/types.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/rspack-test/configCases/parsing/renaming-disabled/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rename * rename --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…12686) * feat: add requireRename option to control require variable renaming * Update packages/rspack/src/config/types.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/rspack-test/configCases/parsing/renaming-disabled/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rename * rename --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…12686) * feat: add requireRename option to control require variable renaming * Update packages/rspack/src/config/types.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/rspack-test/configCases/parsing/renaming-disabled/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rename * rename --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
This PR introduces a new experimental parser option
requireAliasfor JavaScript modules, which controls whether therequireidentifier can be renamed to another variable.By default,
requireAliasis set totrue, allowing users to renamerequireto custom variables (e.g.,var cjsRequire = require). When set tofalse, therequireidentifier cannot be renamed, preserving its original behavior.This option provides more flexibility for users who want to control how CommonJS imports are handled in their builds, especially in scenarios where preventing
requirerenaming is necessary for compatibility or code generation purposes.Checklist