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.
Module paths
Section titled “Module paths”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.
API changes
Section titled “API changes”Renamed and replaced
Section titled “Renamed and replaced”| 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.
The import extractor borrows
Section titled “The import extractor borrows”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 |
Changed signatures
Section titled “Changed signatures”TsConfig::discoverreturnsResult<Option<TsConfig>, TsConfigError>.Ok(None)still means notsconfig.jsonwas found; a malformed or unreadable nearest config, which used to beNone, is now an error. For the scan’s best-effort behavior, which skips unusable files and lists them, useTsConfigCache::discoverandTsConfigCache::ignored.Config::extensions_for_packagereturns&[String]andConfig::ignore_for_packagereturnsOption<&[String]>instead of cloned vectors. Call.to_vec()where an owned copy is needed.- Functions that only iterate their input take iterators:
DependencyGraph::from_importsandcycles::try_file_cycles_from_importstake anyIntoIteratorof imports (owned or borrowed);PackageDependencyGraph::from_importstakes(name, imports)pairs, so a&HashMap<String, Vec<Import>>still works;PackageDiscovery’sdiscover_explicit*anddiscover_workspace_packagestake anyIntoIteratorof paths. OutputFormatter::formatandUnifiedOutputFormatter::format_unifiedare 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,filterandverbose;ScanReport::resultsandfilter;ImportExtractor::mode,skip_type_imports,workspace,ownersandpackage_names;HumanFormatter::newandverbose;UnifiedResults::has_package_cycles;DependencyGraph::nodes,PackageDependencyGraph::nodesandEdgeEvidence::file_count;BoundedReport::new. Publicconst fnis 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.
Non-exhaustive types
Section titled “Non-exhaustive types”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.
Additions
Section titled “Additions”ColorMode,EvidenceFile,IgnoredTsConfigandPackageSpecifier.impl FromStr for Config(the same asConfig::parse) andimpl FromIterator<Import> for DependencyGraph, for owned or borrowed imports.- Structural
PartialEq/Eqfor the result, configuration, discovery, workspace, tsconfig and graph types, andHashfor the small value types and enums, so they can be compared and used as keys. Clonefor the graphs,PackageDiscovery,HumanFormatter,JsonFormatter(alsoCopy) andBoundedReport;Defaultis derived forResults.DebugforImportExtractor(settings only) andBoundedReport.#[must_use]onTsConfigCache::discover_sharedand both graphs’edge_count.- Runnable documentation examples for
AnalysisBudget,PackageDiscovery,ImportExtractor, the cycle functions,Config,HumanFormatter,WorkspaceandTsConfig.