Expand description
Find circular imports between files and workspace packages in JavaScript and TypeScript projects.
jscycles is both a command-line tool and a library. To embed the whole
analysis, the same one the command runs, use Scan:
use jscycles::Scan;
let report = Scan::new("path/to/repo").run()?;
if report.has_cycles() {
std::io::Write::write_all(&mut std::io::stdout(), &report.to_human(false)?)?;
}See the scan module for the options and results. The lower-level
modules (discovery, imports, graph, cycles) are the parts a
scan is built from, for callers that supply their own import graph:
use jscycles::{CycleDetector, DependencyGraph, Import, ImportTarget};
use std::path::PathBuf;
let imports = vec![Import {
source: PathBuf::from("a.ts"),
target: ImportTarget::Resolved(PathBuf::from("a.ts")),
specifier: "./a".into(),
}];
let cycles = CycleDetector::detect(&DependencyGraph::from_imports(&imports));
assert_eq!(cycles.len(), 1);
assert_eq!(cycles[0].path, vec![PathBuf::from("a.ts"), PathBuf::from("a.ts")]);Re-exports§
pub use config::Config;pub use cycles::Cycle;pub use cycles::CycleDetector;pub use cycles::PackageCycle;pub use cycles::PackageCycleDetector;pub use cycles::PackageCycleEdge;pub use cycles::PackageCycleWithFiles;pub use discovery::Discovered;pub use discovery::Package;pub use discovery::PackageDiscovery;pub use graph::DependencyGraph;pub use graph::EdgeEvidence;pub use graph::PackageDependencyGraph;pub use imports::Import;pub use imports::ImportExtractor;pub use imports::ImportTarget;pub use output::CycleFilter;pub use output::HumanFormatter;pub use output::JsonFormatter;pub use output::OutputFormatter;pub use output::PackageResult;pub use output::Results;pub use output::UnifiedOutputFormatter;pub use output::UnifiedResults;pub use scan::Scan;pub use scan::ScanReport;pub use scan::TsConfigSource;pub use tsconfig::TsConfig;pub use tsconfig::TsConfigCache;pub use workspace::Workspace;pub use workspace::WorkspaceFormat;
Modules§
- budget
- Monotonic, shared admission budgets for one analysis operation.
- config
- Configuration file parsing for jscycles.
- cycles
- Cycle detection using Tarjan’s strongly connected components algorithm.
- discovery
- Package discovery for monorepo scanning.
- graph
- Dependency graph construction for cycle detection.
- imports
- Import extraction from JavaScript/TypeScript files using tree-sitter cursors.
- output
- Output formatting for cycle detection results.
- scan
- Run a complete scan from Rust: the same analysis the
jscyclescommand performs, returning the results instead of printing them. - tsconfig
- TypeScript configuration parsing for path alias resolution.
- workspace
- Workspace detection and parsing for monorepos.
Structs§
- Workspace
Yaml Error - Path and original cause of a YAML workspace parse failure.
Boxed by
WorkspaceError::Yamlto keep the common Result representation small.
Enums§
- Config
Error - Error type for configuration operations.
- Discovery
Error - Error type for package discovery operations.
- Extract
Error - Error type for import extraction operations.
- Jscycles
Error - Top-level error type for jscycles operations.
- TsConfig
Error - Error type for TypeScript config operations.
- Workspace
Error - Error type for workspace detection operations.
Constants§
- DEFAULT_
EXTENSIONS - Source extensions analyzed when neither the CLI nor the configuration selects others.