A fast and accurate circular dependency detector for JavaScript and TypeScript projects, built in Rust.
- π Accurate Detection: Uses regex patterns to extract imports from JS/TS files
- πΊοΈ Path Resolution: Integrates with
oxc-resolverto resolve aliased and relative imports - π Dependency Graph: Builds a complete dependency graph using strongly connected components
- π― Multiple Import Styles: Supports ES6 imports, CommonJS require, dynamic imports, and re-exports
- β‘ Fast: Written in Rust for optimal performance
- π Detailed Output: Shows exact circular paths and line numbers with verbose mode
.js- JavaScript files.jsx- JavaScript React components.ts- TypeScript files.tsx- TypeScript React components.mjs- ES Module JavaScript files.cjs- CommonJS files
The tool detects the following import patterns:
// ES6 imports
import { func } from './module.js';
import * as mod from './module.js';
import defaultExport from './module.js';
// CommonJS require
const { func } = require('./module.js');
// Dynamic imports
import('./module.js');
// Re-exports
export { func } from './module.js';
export * from './module.js';Clone this repository and build:
git clone <repository-url>
cd rustyring
cargo build --releaseThe binary will be available at target/release/rustyring.
To use rustyring from anywhere:
# Option 1: Copy to a directory in your PATH
cp target/release/rustyring /usr/local/bin/
# Option 2: Create a symlink
ln -s $(pwd)/target/release/rustyring /usr/local/bin/rustyring
# Option 3: Install with cargo (if published to crates.io)
cargo install rustyringAnalyze a single entry file:
rustyring src/main.jsAnalyze multiple entry files:
rustyring src/main.js src/app.js src/utils.jsGet detailed information about dependencies and line numbers:
rustyring src/main.js --verboseSet a custom project root directory:
rustyring src/main.js --root /path/to/projectRustyRing supports multiple output formats:
rustyring src/main.js --output text --verboserustyring src/main.js --output json --output-file results.jsonrustyring src/main.js --output dot --output-file deps.dotThe GraphViz output shows only files involved in circular dependencies for clean, focused visualization:
- Files in circular dependencies are highlighted in red
- Each circular dependency is grouped in a dashed box
- Clean "No Circular Dependencies Found" message when project is clean
Then visualize with:
# Generate SVG (requires graphviz: brew install graphviz)
dot -Tsvg deps.dot -o deps.svg
# Or use online tools:
# - https://viz-js.com/
# - https://dreampuf.github.io/GraphvizOnline/π Analyzing dependencies...
π Processed 10 files
π Found 25 imports
β
No circular dependencies found!
β±οΈ Analysis completed in 45ms
π Analyzing dependencies...
π Processed 4 files
π Found 5 imports
π΄ Found 2 circular dependencies:
Circular Dependency #1:
ββ src/utils.js β src/helpers.js
ββ src/helpers.js β src/utils.js (completes circle)
Circular Dependency #2:
ββ src/components/Button.jsx β src/components/Modal.jsx
ββ src/components/Modal.jsx β src/components/Button.jsx (completes circle)
β±οΈ Analysis completed in 32ms
rustyring src/main.js --verboseπ Analyzing dependencies...
π Processed 4 files
π Found 5 imports
π΄ Found 1 circular dependencies:
Circular Dependency #1:
ββ src/a.js β src/b.js
ββ src/b.js β src/a.js (completes circle)
Dependencies involved:
From src/a.js:
- Line 1: ./b.js β src/b.js
From src/b.js:
- Line 1: ./a.js β src/a.js
β±οΈ Analysis completed in 25ms
0: No circular dependencies found1: Circular dependencies detected or error occurred
The tool uses the following approach:
- Import Extraction: Uses regex patterns to extract import statements from source files
- Path Resolution: Leverages
oxc-resolverto resolve relative and aliased import paths - Graph Building: Constructs a directed graph where nodes are files and edges are dependencies
- Cycle Detection: Uses Tarjan's strongly connected components algorithm to find circular dependencies
- Result Formatting: Presents circular dependencies in a clear, actionable format
The tool uses oxc-resolver which automatically handles:
- TypeScript path mapping (via
tsconfig.json) - Package.json main field resolution
- Node.js module resolution
- File extensions resolution (.js, .ts, .jsx, .tsx, etc.)
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License.