Skip to content
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
2 changes: 1 addition & 1 deletion crates/mako/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Compiler {
Arc::new(plugins::async_runtime::AsyncRuntimePlugin {}),
Arc::new(plugins::emotion::EmotionPlugin {}),
Arc::new(plugins::tree_shaking::FarmTreeShake {}),
Arc::new(plugins::loop_detector::LoopDetector {}),
Arc::new(plugins::detect_circular_dependence::LoopDetector {}),
];
plugins.extend(builtin_plugins);

Expand Down
10 changes: 5 additions & 5 deletions crates/mako/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ create_deserialize_fn!(deserialize_inline_css, InlineCssConfig);
create_deserialize_fn!(deserialize_rsc_client, RscClientConfig);
create_deserialize_fn!(deserialize_rsc_server, RscServerConfig);
create_deserialize_fn!(deserialize_stats, StatsConfig);
create_deserialize_fn!(deserialize_detect_loop, DetectLoop);
create_deserialize_fn!(deserialize_detect_loop, DetectCircularDependence);

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -428,8 +428,8 @@ pub struct RscClientConfig {

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct DetectLoop {
pub ignore_node_modules: bool,
pub struct DetectCircularDependence {
pub ignores: Vec<String>,
pub graphviz: bool,
}

Expand All @@ -439,7 +439,7 @@ pub struct ExperimentalConfig {
pub webpack_syntax_validate: Vec<String>,
pub require_context: bool,
#[serde(deserialize_with = "deserialize_detect_loop")]
pub detect_loop: Option<DetectLoop>,
pub detect_circular_dependence: Option<DetectCircularDependence>,
}

#[derive(Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -715,7 +715,7 @@ const DEFAULT_CONFIG: &str = r#"
"experimental": {
"webpackSyntaxValidate": [],
"requireContext": true,
"detectLoop": { "ignoreNodeModules": true, "graphviz": false }
"detectCircularDependence": { "ignores": ["node_modules"], "graphviz": false }
},
"useDefineForClassFields": true,
"emitDecoratorMetadata": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,32 @@ pub struct LoopDetector {}

impl Plugin for LoopDetector {
fn name(&self) -> &str {
"loop_detector"
"loop_circular_dependence"
}

fn generate_begin(&self, context: &Arc<Context>) -> Result<()> {
if let Some(detect_loop) = &context.config.experimental.detect_loop
if let Some(detect_loop) = &context.config.experimental.detect_circular_dependence
&& !context.args.watch
{
let module_graph = context.module_graph.read().unwrap();
let (_, loops) = module_graph.toposort();

let ignore_regexes = detect_loop
.ignores
.iter()
.map(|s| {
regex::Regex::new(s).map_err(|e| {
anyhow::anyhow!("Invalid regex: {} in detectCircularDependence#ignore", e)
})
})
.collect::<Result<Vec<_>>>()?;

let loop_lines = loops
.iter()
.filter(|ids| {
if detect_loop.ignore_node_modules {
!ids.iter().any(|id| id.id.contains("node_modules"))
if !ignore_regexes.is_empty() {
!ids.iter()
.any(|id| ignore_regexes.iter().any(|r| r.is_match(&id.id)))
} else {
true
}
Expand All @@ -52,7 +63,7 @@ impl Plugin for LoopDetector {

if !loop_lines.is_empty() {
for l in &loop_lines {
println!("{} Found a Dependency Loop: {}", "Warning".yellow(), l);
println!("{} Circular Dependencies: {}", "Warning".yellow(), l);
}

if detect_loop.graphviz {
Expand All @@ -61,10 +72,7 @@ impl Plugin for LoopDetector {
std::fs::write(context.root.join("_mako_loop_detector.dot"), dot)?;
}
}

Ok(())
} else {
Ok(())
}
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/mako/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ pub mod async_runtime;
pub mod bundless_compiler;
pub mod context_module;
pub mod copy;
pub mod detect_circular_dependence;
pub mod emotion;
pub mod graphviz;
pub mod hmr_runtime;
pub mod ignore;
pub mod import;
pub mod invalid_webpack_syntax;
pub mod loop_detector;
pub mod manifest;
pub mod minifish;
pub mod require_context;
Expand Down
8 changes: 8 additions & 0 deletions packages/bundler-mako/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,14 @@ async function getMakoConfig(opts) {
plugins: opts.config.lessLoader?.plugins,
},
analyze: analyze || process.env.ANALYZE ? {} : undefined,
experimental: {
webpackSyntaxValidate: [],
requireContext: true,
detectCircularDependence: {
ignores: ['node_modules', '\\.umi'],
graphviz: false,
},
},
...mako,
};

Expand Down