From 833900f2b9e72b94a837522281b0924cf2ac3486 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 3 Aug 2023 16:52:56 -0700 Subject: [PATCH] fix(nargo): Make dependencies section optional in TOML --- crates/nargo_cli/src/manifest.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/nargo_cli/src/manifest.rs b/crates/nargo_cli/src/manifest.rs index e1da57c0c2..7a4c67dfeb 100644 --- a/crates/nargo_cli/src/manifest.rs +++ b/crates/nargo_cli/src/manifest.rs @@ -15,7 +15,7 @@ use crate::{errors::ManifestError, git::clone_git_repo}; #[derive(Debug, Deserialize, Clone)] struct PackageConfig { package: PackageMetadata, - dependencies: BTreeMap, + dependencies: Option>, } impl PackageConfig { @@ -23,11 +23,13 @@ impl PackageConfig { let name = self.package.name.parse().map_err(|_| ManifestError::InvalidPackageName)?; let mut dependencies: BTreeMap = 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)?; @@ -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#"