mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
chore: reorganize manifest module
This commit is contained in:
parent
f0cd53a2c9
commit
b10e7667f0
14 changed files with 201 additions and 166 deletions
|
@ -4,8 +4,7 @@ use clap::Args;
|
|||
use colored::Colorize;
|
||||
use inquire::validator::Validation;
|
||||
use pesde::{
|
||||
errors::ManifestReadError, manifest::ScriptName, names::PackageName, Project,
|
||||
DEFAULT_INDEX_NAME,
|
||||
errors::ManifestReadError, names::PackageName, scripts::ScriptName, Project, DEFAULT_INDEX_NAME,
|
||||
};
|
||||
use std::{path::Path, str::FromStr};
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::cli::{reqwest_client, IsUpToDate};
|
|||
use anyhow::Context;
|
||||
use clap::Args;
|
||||
use indicatif::MultiProgress;
|
||||
use pesde::{lockfile::Lockfile, manifest::TargetKind, Project};
|
||||
use pesde::{lockfile::Lockfile, manifest::target::TargetKind, Project};
|
||||
use std::{collections::HashSet, sync::Arc, time::Duration};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use anyhow::Context;
|
||||
use clap::Args;
|
||||
use colored::Colorize;
|
||||
use pesde::{manifest::Target, Project, MANIFEST_FILE_NAME, MAX_ARCHIVE_SIZE};
|
||||
use pesde::{manifest::target::Target, Project, MANIFEST_FILE_NAME, MAX_ARCHIVE_SIZE};
|
||||
use std::path::Component;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::path::{Component, Path};
|
|||
|
||||
use full_moon::{ast::luau::ExportedTypeDeclaration, visitors::Visitor};
|
||||
|
||||
use crate::manifest::Target;
|
||||
use crate::manifest::target::Target;
|
||||
|
||||
struct TypeVisitor {
|
||||
types: Vec<String>,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{
|
||||
linking::generator::get_file_types,
|
||||
lockfile::DownloadedGraph,
|
||||
manifest::{ScriptName, Target},
|
||||
manifest::target::Target,
|
||||
names::PackageNames,
|
||||
scripts::execute_script,
|
||||
scripts::{execute_script, ScriptName},
|
||||
source::{PackageRef, VersionId},
|
||||
Project, PACKAGES_CONTAINER_NAME,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
use crate::{
|
||||
manifest::{DependencyType, OverrideKey, Target, TargetKind},
|
||||
manifest::{
|
||||
overrides::OverrideKey,
|
||||
target::{Target, TargetKind},
|
||||
DependencyType,
|
||||
},
|
||||
names::{PackageName, PackageNames},
|
||||
source::{DependencySpecifiers, PackageRef, PackageRefs, VersionId},
|
||||
};
|
||||
|
|
96
src/manifest/mod.rs
Normal file
96
src/manifest/mod.rs
Normal file
|
@ -0,0 +1,96 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use relative_path::RelativePathBuf;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
manifest::{overrides::OverrideKey, target::Target},
|
||||
names::{PackageName, PackageNames},
|
||||
source::{DependencySpecifiers, VersionId},
|
||||
};
|
||||
|
||||
pub mod overrides;
|
||||
pub mod target;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Manifest {
|
||||
pub name: PackageName,
|
||||
pub version: Version,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub license: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub authors: Option<Vec<String>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub repository: Option<String>,
|
||||
pub target: Target,
|
||||
#[serde(default)]
|
||||
pub private: bool,
|
||||
#[serde(default, skip_serializing)]
|
||||
pub scripts: BTreeMap<String, RelativePathBuf>,
|
||||
#[serde(default)]
|
||||
pub indices: BTreeMap<String, url::Url>,
|
||||
#[cfg(feature = "wally-compat")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub wally_indices: BTreeMap<String, url::Url>,
|
||||
#[serde(default, skip_serializing)]
|
||||
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
|
||||
#[serde(default)]
|
||||
pub includes: BTreeSet<String>,
|
||||
#[cfg(feature = "patches")]
|
||||
#[serde(default, skip_serializing)]
|
||||
pub patches: BTreeMap<PackageNames, BTreeMap<VersionId, RelativePathBuf>>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub dependencies: BTreeMap<String, DependencySpecifiers>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub peer_dependencies: BTreeMap<String, DependencySpecifiers>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub dev_dependencies: BTreeMap<String, DependencySpecifiers>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DependencyType {
|
||||
Standard,
|
||||
Dev,
|
||||
Peer,
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
pub fn all_dependencies(
|
||||
&self,
|
||||
) -> Result<
|
||||
BTreeMap<String, (DependencySpecifiers, DependencyType)>,
|
||||
errors::AllDependenciesError,
|
||||
> {
|
||||
let mut all_deps = BTreeMap::new();
|
||||
|
||||
for (deps, ty) in [
|
||||
(&self.dependencies, DependencyType::Standard),
|
||||
(&self.peer_dependencies, DependencyType::Peer),
|
||||
(&self.dev_dependencies, DependencyType::Dev),
|
||||
] {
|
||||
for (alias, spec) in deps {
|
||||
if all_deps.insert(alias.clone(), (spec.clone(), ty)).is_some() {
|
||||
return Err(errors::AllDependenciesError::AliasConflict(alias.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(all_deps)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod errors {
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum AllDependenciesError {
|
||||
#[error("another specifier is already using the alias {0}")]
|
||||
AliasConflict(String),
|
||||
}
|
||||
}
|
58
src/manifest/overrides.rs
Normal file
58
src/manifest/overrides.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use serde_with::{DeserializeFromStr, SerializeDisplay};
|
||||
use std::{
|
||||
fmt::{Display, Formatter},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, DeserializeFromStr, SerializeDisplay, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
pub struct OverrideKey(pub Vec<Vec<String>>);
|
||||
|
||||
impl FromStr for OverrideKey {
|
||||
type Err = errors::OverrideKeyFromStr;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let overrides = s
|
||||
.split(',')
|
||||
.map(|overrides| overrides.split('>').map(|s| s.to_string()).collect())
|
||||
.collect::<Vec<Vec<String>>>();
|
||||
|
||||
if overrides.is_empty() {
|
||||
return Err(errors::OverrideKeyFromStr::Empty);
|
||||
}
|
||||
|
||||
Ok(Self(overrides))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for OverrideKey {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
self.0
|
||||
.iter()
|
||||
.map(|overrides| {
|
||||
overrides
|
||||
.iter()
|
||||
.map(|o| o.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.join(">")
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod errors {
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum OverrideKeyFromStr {
|
||||
#[error("empty override key")]
|
||||
Empty,
|
||||
}
|
||||
}
|
|
@ -1,13 +1,7 @@
|
|||
use crate::{
|
||||
names::{PackageName, PackageNames},
|
||||
source::{DependencySpecifiers, VersionId},
|
||||
};
|
||||
use relative_path::RelativePathBuf;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::{DeserializeFromStr, SerializeDisplay};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
collections::BTreeSet,
|
||||
fmt::{Display, Formatter},
|
||||
str::FromStr,
|
||||
};
|
||||
|
@ -176,155 +170,9 @@ impl Display for Target {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, DeserializeFromStr, SerializeDisplay, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
pub struct OverrideKey(pub Vec<Vec<String>>);
|
||||
|
||||
impl FromStr for OverrideKey {
|
||||
type Err = errors::OverrideKeyFromStr;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let overrides = s
|
||||
.split(',')
|
||||
.map(|overrides| overrides.split('>').map(|s| s.to_string()).collect())
|
||||
.collect::<Vec<Vec<String>>>();
|
||||
|
||||
if overrides.is_empty() {
|
||||
return Err(errors::OverrideKeyFromStr::Empty);
|
||||
}
|
||||
|
||||
Ok(Self(overrides))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for OverrideKey {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
self.0
|
||||
.iter()
|
||||
.map(|overrides| {
|
||||
overrides
|
||||
.iter()
|
||||
.map(|o| o.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.join(">")
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum ScriptName {
|
||||
#[cfg(feature = "roblox")]
|
||||
RobloxSyncConfigGenerator,
|
||||
#[cfg(feature = "wally-compat")]
|
||||
SourcemapGenerator,
|
||||
}
|
||||
|
||||
impl Display for ScriptName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
#[cfg(feature = "roblox")]
|
||||
ScriptName::RobloxSyncConfigGenerator => write!(f, "roblox_sync_config_generator"),
|
||||
#[cfg(feature = "wally-compat")]
|
||||
ScriptName::SourcemapGenerator => write!(f, "sourcemap_generator"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Manifest {
|
||||
pub name: PackageName,
|
||||
pub version: Version,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub license: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub authors: Option<Vec<String>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub repository: Option<String>,
|
||||
pub target: Target,
|
||||
#[serde(default)]
|
||||
pub private: bool,
|
||||
#[serde(default, skip_serializing)]
|
||||
pub scripts: BTreeMap<String, RelativePathBuf>,
|
||||
#[serde(default)]
|
||||
pub indices: BTreeMap<String, url::Url>,
|
||||
#[cfg(feature = "wally-compat")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub wally_indices: BTreeMap<String, url::Url>,
|
||||
#[serde(default, skip_serializing)]
|
||||
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
|
||||
#[serde(default)]
|
||||
pub includes: BTreeSet<String>,
|
||||
#[cfg(feature = "patches")]
|
||||
#[serde(default, skip_serializing)]
|
||||
pub patches: BTreeMap<PackageNames, BTreeMap<VersionId, RelativePathBuf>>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub dependencies: BTreeMap<String, DependencySpecifiers>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub peer_dependencies: BTreeMap<String, DependencySpecifiers>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub dev_dependencies: BTreeMap<String, DependencySpecifiers>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DependencyType {
|
||||
Standard,
|
||||
Dev,
|
||||
Peer,
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
pub fn all_dependencies(
|
||||
&self,
|
||||
) -> Result<
|
||||
BTreeMap<String, (DependencySpecifiers, DependencyType)>,
|
||||
errors::AllDependenciesError,
|
||||
> {
|
||||
let mut all_deps = BTreeMap::new();
|
||||
|
||||
for (deps, ty) in [
|
||||
(&self.dependencies, DependencyType::Standard),
|
||||
(&self.peer_dependencies, DependencyType::Peer),
|
||||
(&self.dev_dependencies, DependencyType::Dev),
|
||||
] {
|
||||
for (alias, spec) in deps {
|
||||
if all_deps.insert(alias.clone(), (spec.clone(), ty)).is_some() {
|
||||
return Err(errors::AllDependenciesError::AliasConflict(alias.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(all_deps)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod errors {
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum OverrideKeyFromStr {
|
||||
#[error("empty override key")]
|
||||
Empty,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum AllDependenciesError {
|
||||
#[error("another specifier is already using the alias {0}")]
|
||||
AliasConflict(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum TargetValidatePublishError {
|
|
@ -6,6 +6,27 @@ use std::{
|
|||
thread::spawn,
|
||||
};
|
||||
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum ScriptName {
|
||||
#[cfg(feature = "roblox")]
|
||||
RobloxSyncConfigGenerator,
|
||||
#[cfg(feature = "wally-compat")]
|
||||
SourcemapGenerator,
|
||||
}
|
||||
|
||||
impl Display for ScriptName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
#[cfg(feature = "roblox")]
|
||||
ScriptName::RobloxSyncConfigGenerator => write!(f, "roblox_sync_config_generator"),
|
||||
#[cfg(feature = "wally-compat")]
|
||||
ScriptName::SourcemapGenerator => write!(f, "sourcemap_generator"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute_script<A: IntoIterator<Item = S>, S: AsRef<OsStr>, P: AsRef<Path>>(
|
||||
script_name: Option<&str>,
|
||||
script_path: &Path,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use crate::{
|
||||
manifest::{DependencyType, Target, TargetKind},
|
||||
manifest::{
|
||||
target::{Target, TargetKind},
|
||||
DependencyType,
|
||||
},
|
||||
names::PackageNames,
|
||||
Project,
|
||||
};
|
||||
|
@ -246,6 +249,6 @@ pub mod errors {
|
|||
Version(#[from] semver::Error),
|
||||
|
||||
#[error("malformed target")]
|
||||
Target(#[from] crate::manifest::errors::TargetKindFromStr),
|
||||
Target(#[from] crate::manifest::target::errors::TargetKindFromStr),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ use pkg_ref::PesdePackageRef;
|
|||
use specifier::PesdeDependencySpecifier;
|
||||
|
||||
use crate::{
|
||||
manifest::{DependencyType, Target, TargetKind},
|
||||
manifest::{
|
||||
target::{Target, TargetKind},
|
||||
DependencyType,
|
||||
},
|
||||
names::{PackageName, PackageNames},
|
||||
source::{hash, DependencySpecifiers, PackageSource, ResolveResult, VersionId},
|
||||
util::authenticate_conn,
|
||||
|
|
|
@ -4,7 +4,10 @@ use semver::Version;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
manifest::{DependencyType, Target, TargetKind},
|
||||
manifest::{
|
||||
target::{Target, TargetKind},
|
||||
DependencyType,
|
||||
},
|
||||
names::PackageName,
|
||||
source::{pesde::PesdePackageSource, DependencySpecifiers, PackageRef, PackageSources},
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{manifest::TargetKind, names::PackageName, source::DependencySpecifier};
|
||||
use crate::{manifest::target::TargetKind, names::PackageName, source::DependencySpecifier};
|
||||
use semver::VersionReq;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
|
|
Loading…
Reference in a new issue