Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Jan 9, 2026

Summary

This PR introduces a new experimental parser option requireAlias for JavaScript modules, which controls whether the require identifier can be renamed to another variable.

By default, requireAlias is set to true, allowing users to rename require to custom variables (e.g., var cjsRequire = require). When set to false, the require identifier 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 require renaming is necessary for compatibility or code generation purposes.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 9, 2026 05:35
@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: feature release: feature related release(mr only) labels Jan 9, 2026
@netlify
Copy link

netlify bot commented Jan 9, 2026

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 073cd41
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6960bfa624ec0f00086c80a8
😎 Deploy Preview https://deploy-preview-12686--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a 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 requireRename boolean option to JavascriptParserOptions with default value of true
  • Implemented parser logic to respect the option when determining if require can 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.

LingyuCoder and others added 2 commits January 9, 2026 13:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
rome 984.3 KB 0
react-5k 2.7 MB 0
ui-components 2.1 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

📦 Binary Size-limit

Comparing 073cd41 to feat: rspack_cacheable context expose project root (#12685) by jinrui

❌ Size increased by 7.00KB from 47.87MB to 47.88MB (⬆️0.01%)

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 9, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feat/require-rename-option (073cd41) with main (b81dfa2)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@LingyuCoder LingyuCoder changed the title feat: add requireRename option to control require variable renaming feat: add requireAlias option to control require variable renaming Jan 9, 2026
@LingyuCoder LingyuCoder force-pushed the feat/require-rename-option branch from 0a86fc3 to 44e0b46 Compare January 9, 2026 06:54
@LingyuCoder LingyuCoder enabled auto-merge (squash) January 9, 2026 08:29
@LingyuCoder LingyuCoder merged commit 6ee0d4b into main Jan 9, 2026
52 checks passed
@LingyuCoder LingyuCoder deleted the feat/require-rename-option branch January 9, 2026 09:10
LingyuCoder added a commit that referenced this pull request Jan 9, 2026
…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>
@github-actions github-actions bot mentioned this pull request Jan 9, 2026
2 tasks
LingyuCoder added a commit that referenced this pull request Jan 14, 2026
…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>
LingyuCoder added a commit that referenced this pull request Jan 15, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants