Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cli/depcheck/src/consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ pub(crate) fn lock_pair<'a>(eco: Language, manifest: &'a Path, lock: &'a Path) -
}
}

/// Checks that `lock` resolves every dependency `manifest` declares.
///
/// # Errors
///
/// Returns a usage error when the manifest or lock is missing, and a failure when either does not
/// parse or they disagree.
pub fn cmd_consistency(
eco: Language,
manifest: &Path,
Expand Down Expand Up @@ -290,6 +296,12 @@ fn maven_lock(_eco: Language, lock: &Path) -> Result<LockVersions, DepcheckError
single(jvm::parse_jvm_lock(lock))
}

/// Checks every manifest and lock pair of the workspace and reports each one.
///
/// # Errors
///
/// Returns the error of the worst failing pair: usage when a file is missing, failure when a file
/// does not parse or a pair disagrees.
pub fn cmd_locks(
locks: &WorkspaceLocks,
stdout: &mut dyn std::fmt::Write,
Expand Down
8 changes: 8 additions & 0 deletions cli/depcheck/src/ecosystem/ansible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ fn manifest_error(message: String) -> DepcheckError {
}

/// Reads the `collections` of an ansible manifest: each entry's `name` and `version`.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_ansible_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let root: yaml_serde::Value = yaml_serde::from_str(&text)
Expand Down Expand Up @@ -60,6 +64,10 @@ pub fn parse_ansible_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>,
}

/// Maps every collection in an ansible lock to its version.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_ansible_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
Ok(super::lock_packages(path)?
.into_iter()
Expand Down
14 changes: 14 additions & 0 deletions cli/depcheck/src/ecosystem/beam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ fn mix_deps_block(text: &str) -> Option<String> {
Some(block)
}

/// Reads the `deps` of a Mix manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_elixir_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let entry_re =
Expand Down Expand Up @@ -74,6 +79,10 @@ pub fn parse_elixir_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, D
}

/// Hex lock packages as `name -> version`.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_hex_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let data: serde_json::Value = serde_json::from_str(&text).map_err(DepcheckError::LockJson)?;
Expand Down Expand Up @@ -143,6 +152,11 @@ fn split_elements(body: &str) -> Vec<&str> {
.collect()
}

/// Reads the `deps` of a `rebar.config` manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_erlang_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let raw = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let text: String = raw
Expand Down
10 changes: 10 additions & 0 deletions cli/depcheck/src/ecosystem/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use crate::{DepInfo, DepcheckError};

use super::normalize_snake;

/// Reads the dependencies of a cc manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read, does not parse, or has an entry without a name.
pub fn parse_cc_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let data: toml::Value = toml::from_str(&text).map_err(DepcheckError::ManifestToml)?;
Expand Down Expand Up @@ -65,6 +70,11 @@ pub fn parse_cc_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, Depch
Ok(deps)
}

/// Maps every package of a cc lock to its version.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_cc_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let data: serde_json::Value = serde_json::from_str(&text).map_err(DepcheckError::LockJson)?;
Expand Down
16 changes: 16 additions & 0 deletions cli/depcheck/src/ecosystem/dart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ fn constraint(value: &yaml_serde::Value) -> String {
}

/// `dependencies` and `dev_dependencies` of a pubspec manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_dart_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
manifest_deps(path, true)
}

/// `dependencies` and `dev_dependencies` of a pubspec manifest without the `sdk:` ones.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_dart_manifest_packages(
path: &Path,
) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
Expand Down Expand Up @@ -110,6 +118,10 @@ fn lock_entries(path: &Path) -> Result<Vec<(String, String, String)>, DepcheckEr
}

/// `packages.<name>.version` of a pub lock, SDK packages included.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_dart_lock(path: &Path) -> Result<LockVersions, DepcheckError> {
let mut pkgs = LockVersions::new();
for (name, version, _) in lock_entries(path)? {
Expand All @@ -119,6 +131,10 @@ pub fn parse_dart_lock(path: &Path) -> Result<LockVersions, DepcheckError> {
}

/// Locked packages a source can import without the manifest naming them: hosted and git ones.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn dart_lock_candidates(path: &Path) -> Result<Vec<String>, DepcheckError> {
Ok(lock_entries(path)?
.into_iter()
Expand Down
8 changes: 8 additions & 0 deletions cli/depcheck/src/ecosystem/dlang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use super::{normalize_lower, put};

/// Reads the `dependencies` of a manifest, JSON or SDL chosen by the file extension.
/// A sub-package dependency (`vibe-d:http`) counts as its base package.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_d_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let mut deps = BTreeMap::new();
Expand Down Expand Up @@ -88,6 +92,10 @@ fn d_spec(version: &str) -> String {
}

/// Reads a selections file: package name to selected version. A path selection has none.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_d_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let data: serde_json::Value = serde_json::from_str(&text).map_err(DepcheckError::LockJson)?;
Expand Down
5 changes: 5 additions & 0 deletions cli/depcheck/src/ecosystem/dotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use crate::{DepInfo, DepcheckError};

use super::normalize_lower;

/// Reads the `nuget` lines of a Paket manifest, with their groups.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_dotnet_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let mut deps = BTreeMap::new();
Expand Down
8 changes: 8 additions & 0 deletions cli/depcheck/src/ecosystem/fortran.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use crate::{DepInfo, DepcheckError};
use super::{normalize_lower, put};

/// Reads `[dependencies]` and `[dev-dependencies]` of an fpm manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_fortran_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let data = crate::toml_util::parse_toml_file(path)?;
let mut deps = BTreeMap::new();
Expand Down Expand Up @@ -39,6 +43,10 @@ pub fn parse_fortran_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>,
}

/// Reads an fpm lock: the `name` and `version` of each locked package.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_fortran_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
Ok(super::lock_packages(path)?
.into_iter()
Expand Down
10 changes: 10 additions & 0 deletions cli/depcheck/src/ecosystem/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use crate::{DepInfo, DepcheckError};

use super::normalize_lower;

/// Reads the `require` lines of a Go module manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_go_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let file = dx_gomod::parse_mod(&text).map_err(DepcheckError::ManifestParse)?;
Expand Down Expand Up @@ -32,6 +37,11 @@ pub fn parse_go_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, Depch
Ok(deps)
}

/// Maps every module in a Go checksum lock to its version.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_go_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let mut pkgs = BTreeMap::new();
Expand Down
8 changes: 8 additions & 0 deletions cli/depcheck/src/ecosystem/haskell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use super::put;

/// Reads the `build-depends` of every component in a `.cabal` file. Test suites and
/// benchmarks are `dev`; `base` and the package's own library are not dependencies to check.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_haskell_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let mut package = String::new();
Expand Down Expand Up @@ -113,6 +117,10 @@ fn haskell_spec(range: &str) -> String {

/// Reads the pinned packages of the cabal freeze file (`any.text ==2.0.2`) or
/// `stack.yaml.lock` (`hackage: text-2.0.2@sha256:...`).
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_haskell_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let freeze = regex::Regex::new(
Expand Down
18 changes: 18 additions & 0 deletions cli/depcheck/src/ecosystem/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ fn manifest_spec(
.ok_or_else(|| DepcheckError::ManifestParse(format!("{field}.{name} must be a string")))
}

/// Reads the dependency sections of an npm package manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_js_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let data: serde_json::Value =
Expand Down Expand Up @@ -155,6 +160,10 @@ fn dir_of(path: &Path) -> std::path::PathBuf {
}

/// Names the lock importer that belongs to a manifest.
///
/// # Errors
///
/// Returns an error when either directory cannot be resolved or the manifest is outside the lock's workspace.
pub fn pnpm_importer_key(manifest: &Path, lock: &Path) -> Result<String, DepcheckError> {
let manifest_dir =
std::fs::canonicalize(dir_of(manifest)).map_err(DepcheckError::ManifestIo)?;
Expand Down Expand Up @@ -274,6 +283,11 @@ fn collect_packages(
Ok(())
}

/// Reads the importers and packages of a pnpm lock.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_pnpm_lock(path: &Path) -> Result<PnpmLock, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let value: yaml_serde::Value =
Expand Down Expand Up @@ -337,6 +351,10 @@ fn split_alias(text: &str) -> Option<(&str, &str)> {
}

/// Compares each manifest declaration with the importer's resolution.
///
/// # Errors
///
/// Returns an error when a declaration uses an unsupported `catalog:` specifier.
pub fn pnpm_failures(
deps: &BTreeMap<String, DepInfo>,
importer: &BTreeMap<String, PnpmEntry>,
Expand Down
8 changes: 8 additions & 0 deletions cli/depcheck/src/ecosystem/julia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use super::put;

/// Reads `[deps]`, `[weakdeps]` and `[extras]` of a Julia project manifest. Extras are test-only and
/// weak dependencies are optional.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_julia_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let data = parse_toml_file(path)?;
let mut deps = BTreeMap::new();
Expand Down Expand Up @@ -44,6 +48,10 @@ pub fn parse_julia_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, De

/// Maps every package in a Julia lock manifest (format 1 or 2) to its version. Standard libraries
/// carry no version and map to `stdlib`.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_julia_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let data = parse_toml_file(path)?;
let mut locked = BTreeMap::new();
Expand Down
15 changes: 15 additions & 0 deletions cli/depcheck/src/ecosystem/jvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use crate::{DepInfo, DepcheckError};

use super::normalize_lower;

/// Reads the dependencies of a JVM manifest.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read, does not parse, or has a malformed entry.
pub fn parse_jvm_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let data: toml::Value = toml::from_str(&text).map_err(DepcheckError::ManifestToml)?;
Expand Down Expand Up @@ -68,6 +73,11 @@ pub fn parse_jvm_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, Depc
Ok(deps)
}

/// Maps every artifact of a Maven lock to its version.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_jvm_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let data: serde_json::Value = serde_json::from_str(&text).map_err(DepcheckError::LockJson)?;
Expand Down Expand Up @@ -169,6 +179,11 @@ fn catalog_coords(text: &str) -> Result<Vec<String>, DepcheckError> {
Ok(coords)
}

/// Reads the Maven coordinates of a `maven.install` artifacts list or a version catalog.
///
/// # Errors
///
/// Returns an error when the list cannot be read or names no Maven coordinates.
pub fn parse_maven_artifacts_list(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let coords = if path.extension().is_some_and(|ext| ext == "toml") {
Expand Down
8 changes: 8 additions & 0 deletions cli/depcheck/src/ecosystem/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use super::put;

/// Reads the `dependencies`, `build_dependencies` and `test_dependencies` tables of a
/// `*.rockspec`. The `lua` entry only pins the interpreter and is skipped.
///
/// # Errors
///
/// Returns an error when the manifest cannot be read or does not parse.
pub fn parse_lua_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::ManifestIo)?;
let text = strip_comments(&text);
Expand Down Expand Up @@ -51,6 +55,10 @@ pub fn parse_lua_manifest(path: &Path) -> Result<BTreeMap<String, DepInfo>, Depc
}

/// Reads a lock: the name and version of each package. The rock revision is dropped.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_lua_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
Ok(super::lock_packages(path)?
.into_iter()
Expand Down
4 changes: 4 additions & 0 deletions cli/depcheck/src/ecosystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ pub fn normalize_snake(name: &str) -> String {

/// Parses a paren-style lock (a paket or bundler lock): every 4-space
/// indented `name (version)` line, keyed by `normalize_lower`.
///
/// # Errors
///
/// Returns an error when the lock cannot be read or does not parse.
pub fn parse_paren_lock(path: &Path) -> Result<BTreeMap<String, String>, DepcheckError> {
let text = std::fs::read_to_string(path).map_err(DepcheckError::LockIo)?;
let re = regex::Regex::new(r"^ ([A-Za-z0-9_.\-]+) \(([^)]+)\)")
Expand Down
Loading
Loading