Skip to content
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

fix: the value of this.sourceMap in LoaderContext is incorrect when using SourceMapDevToolPlugin #7968

Merged
merged 1 commit into from
Oct 10, 2024
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
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ export interface JsModule {
factoryMeta?: JsFactoryMeta
type: string
layer?: string
useSourceMap?: boolean
}

export interface JsModuleDescriptor {
Expand Down
21 changes: 6 additions & 15 deletions crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub struct JsModule {
pub factory_meta: Option<JsFactoryMeta>,
pub r#type: String,
pub layer: Option<String>,
pub use_source_map: Option<bool>,
}

pub trait ToJsModule {
Expand Down Expand Up @@ -365,20 +366,17 @@ impl ToJsModule for dyn Module {
.map(|factory_meta| JsFactoryMeta {
side_effect_free: factory_meta.side_effect_free,
}),
..Default::default()
})
.or_else(|_| {
self.try_as_raw_module().map(|_| JsModule {
context: context(),
r#type: module_type(),
layer: module_layer(),
original_source: original_source(),
resource: None,
module_identifier: module_identifier(),
name_for_condition: name_for_condition(),
raw_request: None,
user_request: None,
request: None,
factory_meta: None,
..Default::default()
})
})
.or_else(|_| {
Expand All @@ -387,13 +385,9 @@ impl ToJsModule for dyn Module {
original_source: original_source(),
r#type: module_type(),
layer: module_layer(),
resource: None,
module_identifier: module_identifier(),
name_for_condition: name_for_condition(),
raw_request: None,
user_request: None,
request: None,
factory_meta: None,
..Default::default()
})
})
.or_else(|_| {
Expand All @@ -402,13 +396,9 @@ impl ToJsModule for dyn Module {
original_source: original_source(),
r#type: module_type(),
layer: module_layer(),
resource: None,
module_identifier: module_identifier(),
name_for_condition: name_for_condition(),
raw_request: None,
user_request: None,
request: None,
factory_meta: None,
..Default::default()
})
})
.or_else(|_| {
Expand Down Expand Up @@ -440,6 +430,7 @@ impl ToJsModule for CompilerModuleContext {
factory_meta: self.factory_meta.as_ref().map(|fm| JsFactoryMeta {
side_effect_free: fm.side_effect_free,
}),
use_source_map: Some(self.use_source_map),
};
Ok(module)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_core/src/loader/loader_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct CompilerModuleContext {
pub user_request: Option<String>,
pub raw_request: Option<String>,
pub factory_meta: Option<FactoryMeta>,
pub use_source_map: bool,
}

impl CompilerModuleContext {
Expand All @@ -40,6 +41,7 @@ impl CompilerModuleContext {
factory_meta: normal_module
.and_then(|normal_module| normal_module.factory_meta())
.map(|factory_meta| factory_meta.to_owned()),
use_source_map: module.get_source_map_kind().source_map(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("should include a.ts in SourceMap", function() {
expect(__SOURCEMAP__).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (content) {
return content.replace("__SOURCEMAP__", this.sourceMap);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
devtool: false,
plugins: [
compiler => {
new compiler.webpack.SourceMapDevToolPlugin({}).apply(compiler);
}
],
module: {
rules: [
{
loader: "./loader.js"
}
]
}
};
2 changes: 1 addition & 1 deletion packages/rspack/src/loader-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export async function runLoaders(
loaderContext.version = 2;
loaderContext.sourceMap = compiler.options.devtool
? isUseSourceMap(compiler.options.devtool)
: false;
: context._module.useSourceMap ?? false;
loaderContext.mode = compiler.options.mode;
Object.assign(loaderContext, compiler.options.loader);

Expand Down
Loading