diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 2c659b3814b..3ac0f01bc9e 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -219,6 +219,7 @@ export declare class JsExportsInfo { } export declare class JsModule { + get constructorName(): string get context(): string | undefined get originalSource(): JsCompatSource | undefined get resource(): string | undefined diff --git a/crates/rspack_binding_values/src/module.rs b/crates/rspack_binding_values/src/module.rs index a7d1f42eeed..fcef799e574 100644 --- a/crates/rspack_binding_values/src/module.rs +++ b/crates/rspack_binding_values/src/module.rs @@ -68,6 +68,13 @@ impl JsModule { #[napi] impl JsModule { + #[napi(getter)] + pub fn constructor_name(&mut self) -> napi::Result { + let module = self.as_ref()?; + + Ok(module.constructor_name().to_string()) + } + #[napi(getter)] pub fn context(&mut self) -> napi::Result> { let module = self.as_ref()?; diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 4b87057d969..08ca0624f44 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -472,6 +472,10 @@ impl DependenciesBlock for ConcatenatedModule { #[cacheable_dyn] #[async_trait::async_trait] impl Module for ConcatenatedModule { + fn constructor_name(&self) -> &'static str { + "ConcatenatedModule" + } + fn module_type(&self) -> &ModuleType { // https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/optimize/ConcatenatedModule.js#L688 &ModuleType::JsEsm diff --git a/crates/rspack_core/src/module.rs b/crates/rspack_core/src/module.rs index df3d2ee7b5f..25af2e15398 100644 --- a/crates/rspack_core/src/module.rs +++ b/crates/rspack_core/src/module.rs @@ -210,6 +210,10 @@ pub trait Module: + Diagnosable + ModuleSourceMapConfig { + fn constructor_name(&self) -> &'static str { + "Module" + } + /// Defines what kind of module this is. fn module_type(&self) -> &ModuleType; diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index 5c80563658b..b53fce73ab0 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -261,6 +261,12 @@ export class Module { } Object.defineProperties(this, { + constructorName: { + enumerable: true, + get(): string { + return module.constructorName; + } + }, type: { enumerable: true, get(): string | null {