Skip to content

Commit

Permalink
fix(nargo): Make dependencies section optional in TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Aug 3, 2023
1 parent 2232a38 commit 833900f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions crates/nargo_cli/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ use crate::{errors::ManifestError, git::clone_git_repo};
#[derive(Debug, Deserialize, Clone)]
struct PackageConfig {
package: PackageMetadata,
dependencies: BTreeMap<String, DependencyConfig>,
dependencies: Option<BTreeMap<String, DependencyConfig>>,
}

impl PackageConfig {
fn resolve_to_package(&self, root_dir: &Path) -> Result<Package, ManifestError> {
let name = self.package.name.parse().map_err(|_| ManifestError::InvalidPackageName)?;

let mut dependencies: BTreeMap<CrateName, Dependency> = BTreeMap::new();
for (name, dep_config) in self.dependencies.iter() {
let name = name.parse().map_err(|_| ManifestError::InvalidPackageName)?;
let resolved_dep = dep_config.resolve_to_dependency(root_dir)?;
if let Some(dep_config) = &self.dependencies {
for (name, dep_config) in dep_config.iter() {
let name = name.parse().map_err(|_| ManifestError::InvalidPackageName)?;
let resolved_dep = dep_config.resolve_to_dependency(root_dir)?;

dependencies.insert(name, resolved_dep);
dependencies.insert(name, resolved_dep);
}
}

let (entry_path, crate_type) = crate::lib_or_bin(root_dir)?;
Expand Down Expand Up @@ -260,6 +262,19 @@ fn parse_standard_toml() {
assert!(Config::try_from(src).is_ok());
}

#[test]
fn parse_package_toml_no_deps() {
let src = r#"
[package]
name = "test"
authors = ["kev", "foo"]
compiler_version = "0.1"
"#;

assert!(Config::try_from(String::from(src)).is_ok());
assert!(Config::try_from(src).is_ok());
}

#[test]
fn parse_workspace_toml() {
let src = r#"
Expand Down

0 comments on commit 833900f

Please sign in to comment.