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: should not panic when passing test option to SourceMapDevToolPlugin #8136

Merged
merged 1 commit into from
Oct 16, 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
7 changes: 4 additions & 3 deletions crates/rspack_binding_options/src/options/raw_devtool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rspack_plugin_devtool::{
Append, EvalDevToolModulePluginOptions, ModuleFilenameTemplate, ModuleFilenameTemplateFnCtx,
SourceMapDevToolPluginOptions, TestFn,
};
use tokio::runtime::Handle;

type RawAppend = Either3<String, bool, ThreadsafeFunction<RawPathData, String>>;

Expand Down Expand Up @@ -95,8 +94,10 @@ fn normalize_raw_module_filename_template(
}

fn normalize_raw_test(raw: ThreadsafeFunction<String, bool>) -> TestFn {
let handle = Handle::current();
Box::new(move |ctx| handle.block_on(raw.call(ctx)))
Box::new(move |ctx| {
let raw = raw.clone();
Box::pin(async move { raw.call(ctx).await })
})
}

#[napi(object, object_to_js = false)]
Expand Down
14 changes: 10 additions & 4 deletions crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum Append {
Disabled,
}

pub type TestFn = Box<dyn Fn(String) -> Result<bool> + Sync + Send>;
pub type TestFn = Box<dyn Fn(String) -> BoxFuture<'static, Result<bool>> + Sync + Send>;

#[derive(Derivative)]
#[derivative(Debug)]
Expand Down Expand Up @@ -173,11 +173,11 @@ impl SourceMapDevToolPlugin {
let output_options = &compilation.options.output;
let map_options = MapOptions::new(self.columns);

let mut mapped_sources = raw_assets
let futures = raw_assets
.into_par_iter()
.filter_map(|(file, asset)| {
.map(|(file, asset)| async {
let is_match = match &self.test {
Some(test) => match test(file.to_owned()) {
Some(test) => match test(file.to_owned()).await {
Ok(val) => val,
Err(e) => return Some(Err(e)),
},
Expand All @@ -193,6 +193,12 @@ impl SourceMapDevToolPlugin {
};
source.map(Ok)
})
.collect::<Vec<_>>();

let mut mapped_sources = join_all(futures)
.await
.into_iter()
.flatten()
.collect::<Result<Vec<_>>>()?;

let source_map_modules = mapped_sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
},
plugins: [
new rspack.SourceMapDevToolPlugin({
test: /\.js/,
filename: "[file].map",
sourceRoot: path.join(__dirname, "folder") + "/"
}),
Expand Down
Loading