fix bug in detecting recursive dependencies

This commit is contained in:
damirka 2021-07-23 14:14:48 +03:00
parent 1ebd4fb741
commit 77192723d0
5 changed files with 14 additions and 9 deletions

1
Cargo.lock generated
View File

@ -1326,6 +1326,7 @@ version = "1.5.2"
name = "leo-package"
version = "1.5.2"
dependencies = [
"indexmap",
"lazy_static",
"serde",
"thiserror",

View File

@ -25,8 +25,7 @@ use leo_package::root::{
};
use anyhow::{anyhow, Result};
use indexmap::set::IndexSet;
use std::collections::HashMap;
use indexmap::{set::IndexSet, IndexMap};
use structopt::StructOpt;
use tracing::span::Span;
@ -85,7 +84,7 @@ impl Fetch {
context: Context,
mut tree: IndexSet<String>,
lock_file: &mut LockFile,
dependencies: HashMap<String, Dependency>,
dependencies: IndexMap<String, Dependency>,
) -> Result<()> {
// Go through each dependency in Leo.toml and add it to the imports.
// While adding, pull dependencies of this package as well and check for recursion.

View File

@ -17,6 +17,9 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ]
license = "GPL-3.0"
edition = "2018"
[dependencies.indexmap]
version = "1.7"
[dependencies.serde]
version = "1.0"
features = [ "derive" ]

View File

@ -16,6 +16,7 @@
use crate::{errors::LockFileError, root::Dependency};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
@ -43,8 +44,8 @@ pub struct Package {
pub version: String,
pub author: String,
pub import_name: Option<String>,
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
pub dependencies: HashMap<String, String>,
#[serde(skip_serializing_if = "IndexMap::is_empty", default)]
pub dependencies: IndexMap<String, String>,
}
impl LockFile {
@ -125,7 +126,7 @@ impl TryFrom<&Path> for LockFile {
impl Package {
/// Fill dependencies from Leo Manifest data.
pub fn add_dependencies(&mut self, dependencies: &HashMap<String, Dependency>) {
pub fn add_dependencies(&mut self, dependencies: &IndexMap<String, Dependency>) {
for (import_name, dependency) in dependencies.iter() {
self.dependencies
.insert(import_name.clone(), Package::from(dependency).to_string());

View File

@ -16,6 +16,7 @@
use crate::{errors::ManifestError, package::Package};
use indexmap::IndexMap;
use serde::Deserialize;
use std::{
borrow::Cow,
@ -45,7 +46,7 @@ pub struct Dependency {
pub struct Manifest {
pub project: Package,
pub remote: Option<Remote>,
pub dependencies: Option<HashMap<String, Dependency>>,
pub dependencies: Option<IndexMap<String, Dependency>>,
}
impl Manifest {
@ -53,7 +54,7 @@ impl Manifest {
Ok(Self {
project: Package::new(package_name)?,
remote: author.map(|author| Remote { author }),
dependencies: Some(HashMap::<String, Dependency>::new()),
dependencies: Some(IndexMap::<String, Dependency>::new()),
})
}
@ -81,7 +82,7 @@ impl Manifest {
self.project.description.clone()
}
pub fn get_package_dependencies(&self) -> Option<HashMap<String, Dependency>> {
pub fn get_package_dependencies(&self) -> Option<IndexMap<String, Dependency>> {
self.dependencies.clone()
}