mod analysis;
mod input;
mod module_syntax;
mod syntax;
mod terminal;
pub mod budget;
pub mod config;
pub mod cycles;
pub mod discovery;
pub mod graph;
pub mod imports;
pub mod output;
pub mod scan;
pub mod tsconfig;
pub mod workspace;
use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum JscyclesError {
#[error(transparent)]
Limit(#[from] budget::LimitError),
#[error("Config error: {0}")]
Config(#[from] ConfigError),
#[error("Discovery error: {0}")]
Discovery(#[from] DiscoveryError),
#[error("Import extraction error: {0}")]
Import(#[from] ExtractError),
#[error("TSConfig error: {0}")]
TsConfig(#[from] TsConfigError),
#[error("Workspace error: {0}")]
Workspace(#[from] WorkspaceError),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ConfigError {
#[error("Invalid configuration: {0}")]
Invalid(String),
#[error("Failed to read config file: {0}")]
Read(#[source] std::io::Error),
#[error("Failed to parse config YAML: {}", first_line(&.0.to_string()))]
Parse(#[source] serde_saphyr::Error),
}
fn first_line(message: &str) -> &str {
message.lines().next().unwrap_or_default()
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum DiscoveryError {
#[error(
"duplicate package name {name:?} at {first} and {second}; exclude copies such as nested worktrees or fixtures with scan.exclude, or pass the intended directories explicitly"
)]
DuplicatePackage {
name: String,
first: PathBuf,
second: PathBuf,
},
#[error(transparent)]
Limit(#[from] budget::LimitError),
#[error("Invalid glob pattern '{pattern}': {source}")]
InvalidPattern {
pattern: String,
#[source]
source: glob::PatternError,
},
#[error("Failed to read directory {path}: {source}")]
ReadDir {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("Failed to parse package.json at {path}: {source}")]
ParsePackageJson {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error("Missing 'name' field in package.json at {0}")]
MissingPackageName(PathBuf),
#[error("no packages to check: {}", if *.filtered {
"no package name matches --only/--exclude"
} else {
"no package.json with a `name` field was found; run from the repository root, pass package directories, or check scan.include"
})]
NoPackages {
filtered: bool,
},
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ExtractError {
#[error(transparent)]
Limit(#[from] budget::LimitError),
#[error("Failed to parse {path}: {message}")]
ParseError {
path: PathBuf,
message: String,
},
#[error("IO error reading {path}: {source}")]
IoError {
path: PathBuf,
#[source]
source: std::io::Error,
},
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TsConfigError {
#[error("TSConfig at {path}: {source}")]
AtPath {
path: PathBuf,
#[source]
source: Box<Self>,
},
#[error(transparent)]
Limit(#[from] budget::LimitError),
#[error("Failed to read tsconfig.json: {0}")]
Read(#[source] std::io::Error),
#[error("Failed to parse tsconfig.json: {0}")]
Parse(#[source] serde_json::Error),
#[error("Invalid path in tsconfig: {0}")]
InvalidPath(String),
#[error("Extended tsconfig not found: {0}")]
ExtendsNotFound(String),
#[error("Extends chain too deep (max 10), possible circular reference")]
ExtendsDepth,
}
impl TsConfigError {
pub(crate) fn at_path(self, path: &std::path::Path) -> Self {
match self {
Self::AtPath { .. } | Self::Limit(_) => self,
Self::Read(_)
| Self::Parse(_)
| Self::InvalidPath(_)
| Self::ExtendsNotFound(_)
| Self::ExtendsDepth => Self::AtPath {
path: path.to_path_buf(),
source: Box::new(self),
},
}
}
}
#[derive(Debug, Error)]
#[error("Failed to parse {path}: {source}")]
pub struct WorkspaceYamlError {
pub path: PathBuf,
#[source]
pub source: serde_saphyr::Error,
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum WorkspaceError {
#[error("Failed to parse {path}: {source}")]
Json {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error(transparent)]
Yaml(Box<WorkspaceYamlError>),
#[error(transparent)]
Limit(#[from] budget::LimitError),
#[error("Failed to read {path}: {source}")]
Read {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("Failed to parse {path}: {message}")]
Parse {
path: PathBuf,
message: String,
},
#[error("Invalid glob pattern '{pattern}': {source}")]
InvalidPattern {
pattern: String,
#[source]
source: glob::PatternError,
},
}
pub const DEFAULT_EXTENSIONS: [&str; 8] = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];
pub use config::Config;
pub use cycles::{
Cycle, CycleDetector, PackageCycle, PackageCycleDetector, PackageCycleEdge,
PackageCycleWithFiles,
};
pub use discovery::{Discovered, Package, PackageDiscovery};
pub use graph::{DependencyGraph, EdgeEvidence, PackageDependencyGraph};
pub use imports::{Import, ImportExtractor, ImportTarget};
pub use output::{
CycleFilter, HumanFormatter, JsonFormatter, OutputFormatter, PackageResult, Results,
UnifiedOutputFormatter, UnifiedResults,
};
pub use scan::{Scan, ScanReport, TsConfigSource};
pub use tsconfig::{TsConfig, TsConfigCache};
pub use workspace::{Workspace, WorkspaceFormat};