Skip to content

Commit

Permalink
fix: extract_block_modules dependencies order (#5046)
Browse files Browse the repository at this point in the history
* chore: πŸ€– init

* chore: πŸ€– init

* chore: πŸ€– refactor

* chore: πŸ€– remove temp test dir
  • Loading branch information
IWANABETHATGUY authored Dec 19, 2023
1 parent e51ce7f commit 41011dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
15 changes: 12 additions & 3 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::dependencies_block::AsyncDependenciesToInitialChunkError;
use crate::{
get_entry_runtime, AsyncDependenciesBlockIdentifier, BoxDependency, ChunkGroup, ChunkGroupInfo,
ChunkGroupKind, ChunkGroupOptions, ChunkGroupUkey, ChunkLoading, ChunkUkey, Compilation,
DependenciesBlock, GroupOptions, Logger, ModuleGraphConnection, ModuleIdentifier, RuntimeSpec,
DependenciesBlock, Dependency, GroupOptions, Logger, ModuleGraphConnection, ModuleIdentifier,
RuntimeSpec,
};

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -793,7 +794,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
.module_graph
.module_graph_module_by_identifier(&module)
.unwrap_or_else(|| panic!("no module found: {:?}", &module));
mgm
let mut filtered_dep: Vec<&Box<dyn Dependency>> = mgm
.outgoing_connections_unordered(&self.compilation.module_graph)
.expect("should have outgoing connections")
.filter_map(|con: &ModuleGraphConnection| {
Expand All @@ -804,7 +805,14 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
}
})
.filter_map(|dep_id| self.compilation.module_graph.dependency_by_id(&dep_id))
.collect()
.collect();
// keep the dependency original order if it does not have span, or sort the dependency by
// the error span
filtered_dep.sort_by(|a, b| match (a.span(), b.span()) {
(Some(a), Some(b)) => a.cmp(&b),
_ => std::cmp::Ordering::Equal,
});
filtered_dep
} else {
self
.compilation
Expand All @@ -815,6 +823,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
.filter_map(|dep_id| self.compilation.module_graph.dependency_by_id(dep_id))
.collect()
};

for dep in dependencies {
if dep.as_module_dependency().is_none() && dep.as_context_dependency().is_none() {
continue;
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/normal_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl NormalModuleFactory {
/// Rspan aka `Rspack span`, just avoiding conflict with span in other crate
/// ## Warning
/// RSpan is zero based, `Span` of `swc` is 1 based. see https://swc-css.netlify.app/?code=eJzLzC3ILypRSFRIK8rPVVAvSS0u0csqVgcAZaoIKg
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, Default)]
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, Default, PartialOrd, Ord)]
pub struct ErrorSpan {
pub start: u32,
pub end: u32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Plugin {
});
}
}
/** @type {import('webpack').Configuration} */
/** @type {import('@rspack/cli').Configuration} */
module.exports = {
module: {
rules: [
Expand All @@ -36,6 +36,9 @@ module.exports = {
},
plugins: [new Plugin()],
experiments: {
css: true
css: true,
rspackFuture: {
newTreeshaking: true
}
}
};

0 comments on commit 41011dd

Please sign in to comment.