Skip to content

Commit

Permalink
fix(depcheck): check for simple and detailed dep reps
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed Jul 25, 2018
1 parent ceaabf1 commit a06ce53
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Reading and writing Cargo.toml and package.json manifests.

use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
Expand All @@ -15,7 +16,7 @@ use PBAR;
#[derive(Deserialize)]
struct CargoManifest {
package: CargoPackage,
dependencies: Option<CargoDependencies>,
dependencies: Option<HashMap<String, CargoDependency>>,
lib: Option<CargoLib>,
}

Expand All @@ -29,10 +30,17 @@ struct CargoPackage {
repository: Option<String>,
}

#[derive(Deserialize)]
struct CargoDependencies {
#[serde(rename = "wasm-bindgen")]
wasm_bindgen: Option<String>,
#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum CargoDependency {
Simple(String),
Detailed(DetailedCargoDependency),
}

#[derive(Deserialize, Debug)]
struct DetailedCargoDependency {
version: String,
features: Option<Vec<String>>,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -177,9 +185,11 @@ pub fn check_crate_config(path: &Path, step: &Step) -> Result<(), Error> {
}

fn check_wasm_bindgen(path: &Path) -> Result<(), Error> {
if read_cargo_toml(path)?.dependencies.map_or(false, |x| {
!x.wasm_bindgen.unwrap_or("".to_string()).is_empty()
}) {
let cargo_toml = read_cargo_toml(path)?;
if cargo_toml
.dependencies
.map_or(false, |deps| deps.contains_key("wasm-bindgen"))
{
return Ok(());
}
Error::crate_config(&format!(
Expand Down

0 comments on commit a06ce53

Please sign in to comment.