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
5 changes: 3 additions & 2 deletions crates/kodoc/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ fn resolve_manifest_deps(project_dir: &std::path::Path) -> Vec<std::path::PathBu

let manifest = match crate::manifest::read_manifest(project_dir) {
Ok(m) => m,
Err(e) => {
eprintln!("warning: {e}");
Err(_) => {
// kodo.toml exists but may be a trust-only config (no module/version/deps).
// Silently skip dependency loading in that case.
return Vec::new();
}
};
Expand Down
21 changes: 20 additions & 1 deletion crates/kodoc/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,33 @@ pub(crate) enum Dependency {
},
}

/// Minimal manifest used only for trust config extraction.
///
/// Unlike [`Manifest`], this struct does not require `module` or `version`,
/// allowing a `kodo.toml` that contains only a `[trust]` section to parse
/// successfully.
#[derive(Debug, Deserialize, Default)]
struct TrustOnlyManifest {
#[serde(default)]
trust: Option<TrustSection>,
}

/// Loads trust configuration for a source file by looking for `kodo.toml`.
///
/// Searches only the immediate parent directory of `source_file`. Returns
/// `TrustConfig::default()` (no validation) if no `kodo.toml` exists or
/// if it has no `[trust]` section.
///
/// Accepts both a full project manifest (with `module`/`version`) and a
/// minimal manifest containing only `[trust]`.
pub(crate) fn load_trust_config(source_file: &Path) -> kodo_types::TrustConfig {
let dir = source_file.parent().unwrap_or(Path::new("."));
read_manifest(dir)
let manifest_path = dir.join("kodo.toml");
let content = match std::fs::read_to_string(&manifest_path) {
Ok(c) => c,
Err(_) => return kodo_types::TrustConfig::default(),
};
toml::from_str::<TrustOnlyManifest>(&content)
.ok()
.and_then(|m| m.trust)
.map(TrustSection::into_trust_config)
Expand Down
Loading