refactor: render runtime globals by runtime template#12272
Conversation
✅ Deploy Preview for rspack canceled.
|
📦 Binary Size-limit
❌ Size increased by 23.00KB from 47.63MB to 47.65MB (⬆️0.05%) |
CodSpeed Performance ReportMerging #12272 will not alter performanceComparing Summary
|
|
⏳ Triggered benchmark: Open |
12c83f9 to
bbc3ad7
Compare
|
📝 Benchmark detail: Open
|
There was a problem hiding this comment.
Pull request overview
This refactoring introduces a centralized way to render runtime globals through the RuntimeTemplate, replacing direct .name() and .to_string() calls on RuntimeGlobals. This enables future customization of the runtime scope name (e.g., replacing __webpack_require__ with __rspack_require__).
Key changes:
- Removed
Displaytrait and.name()method fromRuntimeGlobals - Created
runtime_globals_to_string()function that usesCompilerOptionsfor rendering - Added
render_runtime_globals()method toRuntimeTemplate - Threaded
RuntimeTemplatethrough parsers viaTaskContextandParseContext
Reviewed changes
Copilot reviewed 87 out of 87 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_core/src/runtime_globals.rs |
Removed Display impl and .name() method, added runtime_globals_to_string() function |
crates/rspack_core/src/runtime_template.rs |
Refactored to accept CompilerOptions, added render_runtime_globals() method, made dojang optional via clone_without_dojang() |
crates/rspack_core/src/parser_and_generator.rs |
Added runtime_template field to ParseContext |
crates/rspack_core/src/module.rs |
Added runtime_template field to BuildContext |
crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs |
Added runtime_template field to JavascriptParser |
crates/rspack_plugin_javascript/src/parser_plugin/*.rs |
Updated all parser plugins to use parser.runtime_template.render_runtime_globals() |
crates/rspack_plugin_javascript/src/dependency/**/*.rs |
Updated dependency templates to use compilation.runtime_template.render_runtime_globals() |
crates/rspack_plugin_runtime/src/**/*.rs |
Updated runtime modules to use compilation.runtime_template.render_runtime_globals() |
| All other plugin files | Consistently replaced runtime global rendering with the new API |
Comments suppressed due to low confidence (2)
crates/rspack_plugin_javascript/src/plugin/mod.rs:1
- [nitpick] The formatting pattern for
render_runtime_globals()calls is inconsistent. In some places, it's on a single line within a string interpolation, while in others (like line 491), it's assigned to a variable or called directly. For maintainability, consider establishing a consistent pattern, especially when the result is used multiple times in the same expression.
crates/rspack_core/src/runtime_template.rs:1 - This TODO comment is critical to the purpose of this refactoring. It should be expanded to clarify what configuration option will be used, or better yet, create a tracking issue and reference it here (e.g., 'TODO(#1234): use compiler_options.output.runtime_scope_name').
use std::{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This refactoring is aimed at smoothly replacing
__webpack_require__in the bundled assets with__rspack_require__or some else in the future.In the runtime template, runtime globals are rendered according to the compiler options, and its
fmttrait andname()method are removed.However, since some parsers also use runtime globals for
for_namematching, the runtime template without the dojang template engine is added to theTaskContextand sent to parser.Related links
Checklist