From a06ce5337197f68117be65b11a54582bbf44fa3b Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Tue, 24 Jul 2018 19:51:11 -0400 Subject: [PATCH] fix(depcheck): check for simple and detailed dep reps --- src/manifest.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/manifest.rs b/src/manifest.rs index 36e69dfe3..411358198 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -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; @@ -15,7 +16,7 @@ use PBAR; #[derive(Deserialize)] struct CargoManifest { package: CargoPackage, - dependencies: Option, + dependencies: Option>, lib: Option, } @@ -29,10 +30,17 @@ struct CargoPackage { repository: Option, } -#[derive(Deserialize)] -struct CargoDependencies { - #[serde(rename = "wasm-bindgen")] - wasm_bindgen: Option, +#[derive(Deserialize, Debug)] +#[serde(untagged)] +enum CargoDependency { + Simple(String), + Detailed(DetailedCargoDependency), +} + +#[derive(Deserialize, Debug)] +struct DetailedCargoDependency { + version: String, + features: Option>, } #[derive(Deserialize)] @@ -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!(