use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct IncompletePackage {
pub name: String,
pub dir: PathBuf,
pub reasons: Vec<IncompleteEntries>,
}
impl IncompletePackage {
#[must_use]
pub const fn new(name: String, dir: PathBuf, reasons: Vec<IncompleteEntries>) -> Self {
Self { name, dir, reasons }
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub struct IncompleteEntries {
pub cause: IncompleteCause,
#[serde(skip_serializing_if = "Option::is_none")]
pub plugin: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum IncompleteCause {
UnparsableConfig,
UnknownConfig,
UnknownSpread,
ComputedEntries,
UnmappedPublished,
Unspecified,
}
impl IncompleteCause {
#[must_use]
pub const fn describe(self) -> &'static str {
match self {
Self::UnparsableConfig => "the configuration does not parse",
Self::UnknownConfig => "the configuration evaluates to a value that is not known statically",
Self::UnknownSpread => {
"the configuration spreads or merges in a value that is not known statically (an imported base config)"
}
Self::ComputedEntries => "the keys the tool reads entry files from are computed",
Self::UnmappedPublished => {
"package.json publishes build output or bin files none of which maps back to a source file"
}
Self::Unspecified => "an input source reported its entries incomplete",
}
}
}