Skip to content

Commit

Permalink
fix: duplicate emit source map from child compiler (#7847)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind authored Sep 10, 2024
1 parent d782bf6 commit 5aa2f24
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/rspack_plugin_devtool/src/mapped_assets_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dashmap::DashMap;
use futures::Future;
use rspack_core::{CompilationAsset, CompilationAssets};
use rspack_core::CompilationAsset;
use rspack_error::{Error, Result};

use crate::MappedAsset;
Expand All @@ -15,7 +15,7 @@ impl MappedAssetsCache {

pub async fn use_cache<'a, F, R>(
&self,
assets: &'a CompilationAssets,
assets: Vec<(&'a String, &'a CompilationAsset)>,
map_assets: F,
) -> Result<Vec<MappedAsset>>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,14 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
}

let start = logger.time("collect source maps");
let raw_assets = compilation
.assets()
.iter()
.filter(|(_filename, asset)| asset.info.related.source_map.is_none())
.collect::<Vec<_>>();
let mapped_asstes = self
.mapped_assets_cache
.use_cache(compilation.assets(), |assets| {
.use_cache(raw_assets, |assets| {
self.map_assets(compilation, &file_to_chunk, assets)
})
.await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use rspack_core::{
AffectType, AsModuleDependency, Compilation, ContextDependency, ContextOptions,
ContextTypePrefix, Dependency, DependencyCategory, DependencyId, DependencyTemplate,
DependencyType, ErrorSpan, RealDependencyLocation, RuntimeSpec, TemplateContext,
TemplateReplaceSource,
DependencyType, RealDependencyLocation, RuntimeSpec, TemplateContext, TemplateReplaceSource,
};

use super::{context_dependency_template_as_id, create_resource_identifier_for_context_dependency};
Expand Down Expand Up @@ -42,8 +41,8 @@ impl Dependency for RequireResolveContextDependency {
&DependencyType::RequireContext
}

fn span(&self) -> Option<ErrorSpan> {
Some(ErrorSpan::new(self.range.start, self.range.end))
fn range(&self) -> Option<&RealDependencyLocation> {
Some(&self.range)
}

fn could_affect_referencing_module(&self) -> AffectType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it("should successfully compile and retrieve assets from the child compiler", function () {
const child = require('./child');
expect(child.foo).toBe(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const path = require("path");
const rspack = require("@rspack/core");

const CHILD_ID = "child";
const CHILD_FILENAME = "./child";

/**
* @type {import("@rspack/core").Configuration}
*/
module.exports = {
devtool: "source-map",
node: {
__dirname: false,
__filename: false
},
externals: {
CHILD_FILENAME: `commonjs ${CHILD_FILENAME}`
},
output: {
filename: "[name].js"
},
plugins: [
new rspack.DefinePlugin({
CONTEXT: JSON.stringify(__dirname)
}),
compiler => {
compiler.hooks.make.tapAsync('PLUGIN', (compilation, callback) => {
const outputOptions = {};
const childCompiler = compilation.createChildCompiler(CHILD_ID, outputOptions);
const SingleEntryPlugin = compiler.webpack.EntryPlugin;
new SingleEntryPlugin(compiler.context, path.join(__dirname, CHILD_FILENAME), CHILD_ID).apply(childCompiler);
childCompiler.runAsChild(err => callback(err));
});
}
]
};

2 comments on commit 5aa2f24

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-09-10 8134f86) Current Change
10000_development-mode + exec 2.2 s ± 26 ms 2.23 s ± 35 ms +1.27 %
10000_development-mode_hmr + exec 689 ms ± 14 ms 697 ms ± 6.7 ms +1.22 %
10000_production-mode + exec 2.86 s ± 43 ms 2.83 s ± 37 ms -0.94 %
arco-pro_development-mode + exec 1.88 s ± 74 ms 1.87 s ± 48 ms -0.42 %
arco-pro_development-mode_hmr + exec 434 ms ± 2.5 ms 434 ms ± 3.4 ms +0.08 %
arco-pro_production-mode + exec 3.24 s ± 123 ms 3.27 s ± 53 ms +0.78 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.31 s ± 86 ms 3.37 s ± 96 ms +1.76 %
threejs_development-mode_10x + exec 1.69 s ± 16 ms 1.69 s ± 19 ms -0.14 %
threejs_development-mode_10x_hmr + exec 808 ms ± 13 ms 807 ms ± 2.1 ms -0.10 %
threejs_production-mode_10x + exec 5.18 s ± 34 ms 5.19 s ± 33 ms +0.20 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success

Please sign in to comment.