Skip to content

Commit 85dfe9b

Browse files
authored
perf(noImportCycles): exclude node_modules from cycle detection (#9326)
1 parent d5ee469 commit 85dfe9b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

.changeset/some-badgers-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved performance for [`noImportCycles`](https://biomejs.dev/linter/rules/no-import-cycles/) by explicitly excluding node_modules from the cycle detection. The performance improvement is directly proportional to how big your dependency tree is.

crates/biome_js_analyze/src/lint/suspicious/no_import_cycles.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ impl Rule for NoImportCycles {
179179
}
180180

181181
let resolved_path = resolved_path.as_path()?;
182+
183+
// Don't check for cycles through node_modules imports.
184+
if is_node_modules_path(resolved_path) {
185+
return None;
186+
}
187+
182188
let imports = ctx.module_info_for_path(resolved_path)?;
183189

184190
find_cycle(ctx, resolved_path, imports)
@@ -252,6 +258,11 @@ fn find_cycle(
252258
continue;
253259
};
254260

261+
// Skip node_modules paths — we don't traverse into dependencies.
262+
if is_node_modules_path(path) {
263+
continue;
264+
}
265+
255266
if !seen.insert(resolved_path.clone()) {
256267
continue;
257268
}
@@ -295,3 +306,8 @@ fn find_cycle(
295306

296307
None
297308
}
309+
310+
/// Returns `true` if the given path is inside a `node_modules` directory.
311+
fn is_node_modules_path(path: &Utf8Path) -> bool {
312+
path.components().any(|c| c.as_str() == "node_modules")
313+
}

0 commit comments

Comments
 (0)