Skip to content

Upgrading to 0.5

0.5 changes only the Rust library; the command, its exit statuses and its JSON output are unchanged. The changes bring the library in line with the Google Rust style guide’s code organization and API design rules for library code.

The crate-root re-exports (jscycles::Scan, jscycles::Config, jscycles::DependencyGraph, …) are unchanged. Two things moved:

0.4 path 0.5 path
jscycles::imports::Import, ImportTarget jscycles::import::Import, ImportTarget
jscycles::imports::ImportExtractor, ExtractionMode jscycles::extract::ImportExtractor, ExtractionMode
jscycles::JscyclesError also jscycles::scan::JscyclesError
jscycles::ConfigError also jscycles::config::ConfigError
jscycles::DiscoveryError also jscycles::discovery::DiscoveryError
jscycles::ExtractError also jscycles::import::ExtractError
jscycles::TsConfigError also jscycles::tsconfig::TsConfigError
jscycles::WorkspaceError, WorkspaceYamlError also jscycles::workspace::WorkspaceError, WorkspaceYamlError

Each error type is now defined in the module that returns it; the root re-exports keep the 0.4 paths working.

New in the API: UnifiedResults::has_cycles_for(filter) (which ScanReport::has_cycles uses), ImportTarget::retained_bytes and PathAlias::resolve.

0.4 0.5
CycleDetector::detect(graph) jscycles::cycles::file_cycles(graph)
CycleDetector::try_detect(graph, budget) try_file_cycles(graph, budget)
CycleDetector::try_detect_imports(imports, budget) try_file_cycles_from_imports(imports, budget)
PackageCycleDetector::detect(graph) package_cycles(graph)
PackageCycleDetector::detect_with_files(graph) package_cycles_with_files(graph)
PackageCycleDetector::try_detect(graph, budget) try_package_cycles(graph, budget)
PackageCycleDetector::try_detect_imports(groups, budget) try_package_cycles_from_imports(groups, budget)
PackageCycleDetector::try_detect_imports_with_files(groups, budget) try_package_cycles_with_files_from_imports(groups, budget)
ScanReport::to_human(bool) ScanReport::to_human(ColorMode::Plain | ColorMode::Ansi)
HumanFormatter::new(bool) HumanFormatter::new(ColorMode); its use_color and verbose fields are private
HumanFormatter::with_verbose(v) HumanFormatter::verbose(v)
Workspace::get_package_path Workspace::package_path
Config::load_or_default (removed) Config::try_load_or_default, which reports unreadable or invalid files instead of silently using defaults
AnalysisBudget::new(limits) AnalysisBudget::try_new(limits)
PackageDiscovery::new(..), new_with_budget(..) PackageDiscovery::try_new(..), try_new_with_budget(..)
TsConfigCache::new().with_budget(budget) TsConfigCache::new_with_budget(budget)
TsConfigCache::rejected() → Vec<(PathBuf, String)> TsConfigCache::ignored() → Vec<IgnoredTsConfig> (path, reason)
ScanReport::ignored_tsconfigs() → &[(PathBuf, String)] &[IgnoredTsConfig]
EdgeEvidence::files(), PackageCycleEdge::files as (PathBuf, Option<String>) EvidenceFile (source, subpath)
Workspace::split_specifier → Option<(&str, Option<&str>)> Option<PackageSpecifier> (name, subpath)
PackageCycleEdge::with_evidence PackageCycleEdge::new_with_evidence
PackageCycleWithFiles::from_cycle PackageCycleWithFiles::new_from_cycle

The cycle functions are in jscycles::cycles. The detector structs held no state, so the functions take the same arguments. Names follow the Google style guide: fallible constructors are try_new, further constructors new_with_../new_from_.., and with_.. is kept for closure accessors.

ImportExtractor<'shared> borrows the data every package’s extractor shares, instead of holding Arcs, and its builder methods drop the with_ prefix:

0.4 0.5
ImportExtractor::new(extensions, Some(tsconfig)) ImportExtractor::new(extensions, Some(&tsconfig))
.with_workspace(Some(workspace)), .with_shared_workspace(Some(arc)) .workspace(Some(&workspace))
.with_shared_tsconfig(arc) pass arc.as_deref() to new
.with_owners(arc), .with_package_names(arc) .owners(&roots), .package_names(&names)
.with_budget, .with_mode, .with_ignore_patterns, .with_nested_packages, .with_skip_type_imports .budget, .mode, .ignore_patterns, .nested_packages, .skip_type_imports
  • TsConfig::discover returns Result<Option<TsConfig>, TsConfigError>. Ok(None) still means no tsconfig.json was found; a malformed or unreadable nearest config, which used to be None, is now an error. For the scan’s best-effort behavior, which skips unusable files and lists them, use TsConfigCache::discover and TsConfigCache::ignored.
  • Config::extensions_for_package returns &[String] and Config::ignore_for_package returns Option<&[String]> instead of cloned vectors. Call .to_vec() where an owned copy is needed.
  • Functions that only iterate their input take iterators: DependencyGraph::from_imports and cycles::try_file_cycles_from_imports take any IntoIterator of imports (owned or borrowed); PackageDependencyGraph::from_imports takes (name, imports) pairs, so a &HashMap<String, Vec<Import>> still works; PackageDiscovery’s discover_explicit* and discover_workspace_packages take any IntoIterator of paths.
  • OutputFormatter::format and UnifiedOutputFormatter::format_unified are generic over the writer (W: Write + ?Sized) instead of taking &mut dyn Write. Existing calls compile unchanged, including with a &mut dyn Write, but the traits can no longer be used as trait objects.
  • These builder methods and accessors are no longer const fn: Scan::skip_type_imports, filter and verbose; ScanReport::results and filter; ImportExtractor::mode, skip_type_imports, workspace, owners and package_names; HumanFormatter::new and verbose; UnifiedResults::has_package_cycles; DependencyGraph::nodes, PackageDependencyGraph::nodes and EdgeEvidence::file_count; BoundedReport::new. Public const fn is a permanent promise, and these may need non-const work later.
  • A poisoned lock in the tsconfig cache or the extractor now propagates the other thread’s panic instead of reading the possibly half-updated state.

These enums are #[non_exhaustive]; add a wildcard arm to matches outside the crate: Resource, ExtractionMode, ImportTarget, CycleFilter, WorkspaceFormat and the new ColorMode.

These structs are #[non_exhaustive]. Their fields stay public for reading and updating, but struct literals outside the crate no longer compile; use the constructors:

Type Constructor
Import Import::new(source, target, specifier)
Cycle, PackageCycle Cycle::new(path), PackageCycle::new(packages)
PackageCycleEdge PackageCycleEdge::new or new_with_evidence
PackageCycleWithFiles PackageCycleWithFiles::new(packages, edges) or new_from_cycle
EvidenceFile EvidenceFile::new(source, subpath)
PackageResult PackageResult::new(name, path, cycles)
Results, UnifiedResults new(), then set or push to the fields
Package Package::new(name, path, config)
Workspace Workspace::new(root, format, packages), then set aliases if needed
TsConfig TsConfig::new(base_url, paths)
PathAlias PathAlias::new_exact(name, replacements) or PathAlias::new_wildcard(prefix, replacements)

Config, ScanConfig and AnalysisLimits stay exhaustive so that Config { limits, ..Config::default() } keeps working; fields added later take their defaults in that form.

  • ColorMode, EvidenceFile, IgnoredTsConfig and PackageSpecifier.
  • impl FromStr for Config (the same as Config::parse) and impl FromIterator<Import> for DependencyGraph, for owned or borrowed imports.
  • Structural PartialEq/Eq for the result, configuration, discovery, workspace, tsconfig and graph types, and Hash for the small value types and enums, so they can be compared and used as keys.
  • Clone for the graphs, PackageDiscovery, HumanFormatter, JsonFormatter (also Copy) and BoundedReport; Default is derived for Results.
  • Debug for ImportExtractor (settings only) and BoundedReport.
  • #[must_use] on TsConfigCache::discover_shared and both graphs’ edge_count.
  • Runnable documentation examples for AnalysisBudget, PackageDiscovery, ImportExtractor, the cycle functions, Config, HumanFormatter, Workspace and TsConfig.