Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/rspack_binding_api/src/plugins/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,12 +1481,19 @@ impl CompilationRuntimeModule for CompilationRuntimeModuleTap {
let Some(module) = runtime_modules.get(m) else {
return Ok(());
};
let runtime_template = compilation.runtime_template.create_runtime_code_template();
let runtime_template = compilation
.runtime_template
.create_runtime_module_code_template();
let context = RuntimeModuleGenerateContext {
compilation,
runtime_template: &runtime_template,
};
let source_string = module.generate(&context).await?;
let runtime_module_prefix = if compilation.runtime_template.render_mode().is_legacy() {
"webpack/runtime/"
} else {
"rspack/runtime/"
};
Comment thread
LingyuCoder marked this conversation as resolved.
let arg = JsRuntimeModuleArg {
module: JsRuntimeModule {
source: Some(JsSourceToJs::from(source_string)),
Expand All @@ -1495,7 +1502,7 @@ impl CompilationRuntimeModule for CompilationRuntimeModuleTap {
name: module
.name()
.as_str()
.cow_replace(compilation.runtime_template.runtime_module_prefix(), "")
.cow_replace(runtime_module_prefix, "")
Comment thread
LingyuCoder marked this conversation as resolved.
.into_owned(),
stage: module.stage().into(),
isolate: module.should_isolate(compilation.options.experiments.runtime_mode),
Expand Down
6 changes: 0 additions & 6 deletions crates/rspack_core/src/options/experiments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ pub mod runtime_mode {
}
}
}

impl RuntimeMode {
pub fn uses_runtime_context(&self) -> bool {
matches!(self, RuntimeMode::Rspack)
}
}
}

use runtime_mode::RuntimeMode;
Expand Down
12 changes: 0 additions & 12 deletions crates/rspack_core/src/runtime_globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use heck::ToLowerCamelCase;
use rspack_hash::{RspackHash, RspackHasher};
use rustc_hash::FxHashMap;

use crate::{CompilerOptions, runtime_mode::RuntimeMode};

#[rspack_cacheable::cacheable]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct RuntimeGlobals(u128);
Expand Down Expand Up @@ -498,16 +496,6 @@ pub enum RuntimeVariable {
StartupExec,
}

pub fn runtime_variable_to_string(
runtime_variable: &RuntimeVariable,
compiler_options: &CompilerOptions,
) -> String {
match compiler_options.experiments.runtime_mode {
RuntimeMode::Webpack => runtime_variable_name(runtime_variable).to_string(),
RuntimeMode::Rspack => rspack_runtime_variable_name(runtime_variable).to_string(),
}
}

pub fn rspack_runtime_variable_name(runtime_variable: &RuntimeVariable) -> &'static str {
match *runtime_variable {
RuntimeVariable::Require => "__rspack_require",
Expand Down
10 changes: 7 additions & 3 deletions crates/rspack_core/src/runtime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{

pub struct RuntimeModuleGenerateContext<'a> {
pub compilation: &'a Compilation,
pub runtime_template: &'a RuntimeCodeTemplate<'a>,
pub runtime_template: &'a RuntimeCodeTemplate,
}

pub fn runtime_module_owned_define_fields(
Expand Down Expand Up @@ -168,7 +168,9 @@ pub async fn runtime_module_get_generated_code(
let result: Result<&BoxSource> = common
.cached_generated_code
.get_or_try_init(|| async {
let runtime_template = compilation.runtime_template.create_runtime_code_template();
let runtime_template = compilation
.runtime_template
.create_runtime_module_code_template();
let context = RuntimeModuleGenerateContext {
compilation,
runtime_template: &runtime_template,
Expand Down Expand Up @@ -207,7 +209,9 @@ pub async fn runtime_module_get_runtime_hash(
module.name().hash(&mut hasher);
module.stage().hash(&mut hasher);
if module.full_hash() || module.dependent_hash() {
let runtime_template = compilation.runtime_template.create_runtime_code_template();
let runtime_template = compilation
.runtime_template
.create_runtime_module_code_template();
let context = RuntimeModuleGenerateContext {
compilation,
runtime_template: &runtime_template,
Expand Down
Loading
Loading