From 59039e41181a47dccdf1fbb5c5e151f04492a7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 12 Nov 2018 21:45:36 +0100 Subject: [PATCH 01/15] feat: Catch types in Cargo.toml and warn about them --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/lib.rs | 1 + src/manifest/mod.rs | 22 ++++++++++++++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2279393c..d07284f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,6 +756,14 @@ dependencies = [ "syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde_ignored" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde_json" version = "1.0.32" @@ -1056,6 +1064,7 @@ dependencies = [ "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1226,6 +1235,7 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef" "checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c" +"checksum serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "190e9765dcedb56be63b6e0993a006c7e3b071a016a304736e4a315dc01fb142" "checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1a2eec401952cd7b12a84ea120e2d57281329940c3f93c2bf04f462539508e" diff --git a/Cargo.toml b/Cargo.toml index b486071b..0c7a45bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ openssl = { version = '0.10.11', optional = true } parking_lot = "0.6" serde = "1.0.74" serde_derive = "1.0.74" +serde_ignored = "0.0.4" serde_json = "1.0.26" siphasher = "0.2.3" slog = "2.3" diff --git a/src/lib.rs b/src/lib.rs index 2cec7a83..0000c4ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ extern crate parking_lot; extern crate serde; #[macro_use] extern crate serde_derive; +extern crate serde_ignored; extern crate serde_json; extern crate siphasher; #[macro_use] diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 8c3e3902..7b809366 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -15,6 +15,7 @@ use failure::{Error, ResultExt}; use progressbar::Step; use serde::{self, Deserialize}; use serde_json; +use std::collections::BTreeSet; use toml; use PBAR; @@ -210,8 +211,25 @@ impl CrateData { } let manifest = fs::read_to_string(&manifest_path) .with_context(|_| format!("failed to read: {}", manifest_path.display()))?; - let manifest: CargoManifest = toml::from_str(&manifest) - .with_context(|_| format!("failed to parse manifest: {}", manifest_path.display()))?; + let manifest = &mut toml::Deserializer::new(&manifest); + + let mut unused_keys = BTreeSet::new(); + + let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { + let path_string = path.to_string(); + + if path_string.contains("metadata") { + unused_keys.insert(path_string); + } + }) + .with_context(|_| format!("failed to parse manifest: {}", manifest_path.display()))?; + + unused_keys.iter().for_each(|path| { + PBAR.warn(&format!( + "\"{}\" is misspelled and will be ignored. Please check your Cargo.toml.", + path + )); + }); let data = cargo_metadata::metadata(Some(&manifest_path)).map_err(error_chain_to_failure)?; From 2ed3d01541f114cc3374c6c6b295b6495c60fa8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 13 Nov 2018 20:31:51 +0100 Subject: [PATCH 02/15] refactor: Move parsing and warning code into two new functions --- src/manifest/mod.rs | 76 ++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 7b809366..b8c5f01f 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -26,8 +26,9 @@ pub struct CrateData { manifest: CargoManifest, } +#[doc(hidden)] #[derive(Deserialize)] -struct CargoManifest { +pub struct CargoManifest { package: CargoPackage, } @@ -197,6 +198,12 @@ struct NpmData { main: String, } +#[doc(hidden)] +pub struct ManifestAndUnsedKeys { + pub manifest: CargoManifest, + pub unused_keys: BTreeSet, +} + impl CrateData { /// Reads all metadata for the crate whose manifest is inside the directory /// specified by `path`. @@ -209,31 +216,16 @@ impl CrateData { crate_path.display() ) } - let manifest = fs::read_to_string(&manifest_path) - .with_context(|_| format!("failed to read: {}", manifest_path.display()))?; - let manifest = &mut toml::Deserializer::new(&manifest); - - let mut unused_keys = BTreeSet::new(); - - let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { - let path_string = path.to_string(); - - if path_string.contains("metadata") { - unused_keys.insert(path_string); - } - }) - .with_context(|_| format!("failed to parse manifest: {}", manifest_path.display()))?; - - unused_keys.iter().for_each(|path| { - PBAR.warn(&format!( - "\"{}\" is misspelled and will be ignored. Please check your Cargo.toml.", - path - )); - }); let data = cargo_metadata::metadata(Some(&manifest_path)).map_err(error_chain_to_failure)?; + let ManifestAndUnsedKeys { + manifest, + unused_keys, + } = CrateData::parse_crate_data(&manifest_path)?; + CrateData::warn_for_unused_keys(&unused_keys); + let current_idx = data .packages .iter() @@ -259,6 +251,46 @@ impl CrateData { } } + /// Read the `manifest_path` file and deserializes it using the toml Deserializer. + /// Returns a Result containing `ManifestAndUnsedKeys` which contains `CargoManifest` + /// and a `BTreeSet` containing the unused keys from the parsed file. + /// + /// # Errors + /// Will return Err if the file (manifest_path) couldn't be read or + /// if deserializion of to `CargoManifest` fails. + pub fn parse_crate_data(manifest_path: &Path) -> Result { + let manifest = fs::read_to_string(&manifest_path) + .with_context(|_| format!("failed to read: {}", manifest_path.display()))?; + let manifest = &mut toml::Deserializer::new(&manifest); + + let mut unused_keys = BTreeSet::new(); + + let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { + let path_string = path.to_string(); + + if path_string.contains("metadata") { + unused_keys.insert(path_string); + } + }) + .with_context(|_| format!("failed to parse manifest: {}", manifest_path.display()))?; + + Ok(ManifestAndUnsedKeys { + manifest, + unused_keys, + }) + } + + /// Iterating through all the passed `unused_keys` and output + /// a warning for each unknown key. + pub fn warn_for_unused_keys(unused_keys: &BTreeSet) { + unused_keys.iter().for_each(|path| { + PBAR.warn(&format!( + "\"{}\" is a unknown key and will be ignored. Please check your Cargo.toml.", + path + )); + }); + } + /// Get the configured profile. pub fn configured_profile(&self, profile: BuildProfile) -> &CargoWasmPackProfile { match profile { From 6894e631107cc9c8d462633b6562a5885bbf2e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 13 Nov 2018 20:34:38 +0100 Subject: [PATCH 03/15] chore: Fix typo --- src/manifest/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index b8c5f01f..9211303e 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -257,7 +257,7 @@ impl CrateData { /// /// # Errors /// Will return Err if the file (manifest_path) couldn't be read or - /// if deserializion of to `CargoManifest` fails. + /// if deserialize to `CargoManifest` fails. pub fn parse_crate_data(manifest_path: &Path) -> Result { let manifest = fs::read_to_string(&manifest_path) .with_context(|_| format!("failed to read: {}", manifest_path.display()))?; From 203cf6996cdd76048daf05ce755d77420946003a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 13 Nov 2018 20:53:57 +0100 Subject: [PATCH 04/15] test: Add test case for `parse_crate_data` --- tests/all/manifest.rs | 48 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 6bc9df8c..dce984fb 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -292,11 +292,9 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { #[test] fn configure_wasm_bindgen_debug_incorrectly_is_error() { let fixture = utils::fixture::Fixture::new(); - fixture - .readme() - .file( - "Cargo.toml", - r#" + fixture.readme().hello_world_src_lib().file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -314,8 +312,7 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { [package.metadata.wasm-pack.profile.dev.wasm-bindgen] debug-js-glue = "not a boolean" "#, - ) - .hello_world_src_lib(); + ); let cli = Cli::from_iter_safe(vec![ "wasm-pack", @@ -333,3 +330,40 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { .to_string() .contains("package.metadata.wasm-pack.profile.dev.wasm-bindgen.debug"))); } + +#[test] +fn parse_crate_data_returns_unused_keys_in_cargo_toml() { + let fixture = utils::fixture::Fixture::new(); + fixture + .readme() + .file( + "Cargo.toml", + r#" + [package] + authors = ["The wasm-pack developers"] + description = "so awesome rust+wasm package" + license = "WTFPL" + name = "whatever" + repository = "https://github.com/rustwasm/wasm-pack.git" + version = "0.1.0" + + [lib] + crate-type = ["cdylib"] + + [dependencies] + wasm-bindgen = "0.2" + + [package.metadata.wasmpack.profile.dev.wasm-bindgen] + debug-js-glue = true + "#, + ) + .hello_world_src_lib(); + + let result = manifest::CrateData::parse_crate_data(&fixture.path.join("Cargo.toml")); + + assert!(result.is_ok()); + + let manifest::ManifestAndUnsedKeys { unused_keys, .. } = result.unwrap(); + + assert!(unused_keys.contains("package.metadata.wasmpack")); +} From c39410c81e8f69c2449e0a1465544ff744664f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 13 Nov 2018 22:42:59 +0100 Subject: [PATCH 05/15] feat: Use levenshtein function to warn about wasm-pack typos --- Cargo.lock | 7 +++++++ Cargo.toml | 22 +++++++++++++--------- src/lib.rs | 1 + src/manifest/mod.rs | 31 +++++++++++++++++++++++-------- tests/all/manifest.rs | 5 +++-- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d07284f1..d2eaa239 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -835,6 +835,11 @@ name = "strsim" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "structopt" version = "0.2.13" @@ -1070,6 +1075,7 @@ dependencies = [ "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1245,6 +1251,7 @@ dependencies = [ "checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum structopt 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "41c4a2479a078509940d82773d90ff824a8c89533ab3b59cd3ce8b0c0e369c02" "checksum structopt-derive 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "5352090cfae7a2c85e1a31146268b53396106c88ca5d6ccee2e3fae83b6e35c2" "checksum syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430" diff --git a/Cargo.toml b/Cargo.toml index 0c7a45bb..b39ba120 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "wasm-pack" -description = "pack up the wasm and publish it to npm!" -version = "0.5.1" authors = ["Ashley Williams "] -repository = "https://github.com/ashleygwilliams/wasm-pack.git" -license = "MIT/Apache-2.0" -readme = "README.md" categories = ["wasm"] +description = "pack up the wasm and publish it to npm!" documentation = "https://rustwasm.github.io/wasm-pack/" +license = "MIT/Apache-2.0" +name = "wasm-pack" +readme = "README.md" +repository = "https://github.com/ashleygwilliams/wasm-pack.git" +version = "0.5.1" [dependencies] atty = "0.2.11" @@ -21,7 +21,6 @@ hex = "0.3" human-panic = "1.0.1" indicatif = "0.9.0" lazy_static = "1.1.0" -openssl = { version = '0.10.11', optional = true } parking_lot = "0.6" serde = "1.0.74" serde_derive = "1.0.74" @@ -29,16 +28,21 @@ serde_ignored = "0.0.4" serde_json = "1.0.26" siphasher = "0.2.3" slog = "2.3" -slog-term = "2.4" slog-async = "2.3" +slog-term = "2.4" +strsim = "0.8.0" structopt = "0.2" tar = "0.4.16" toml = "0.4" which = "2.0.0" zip = "0.4.2" +[dependencies.openssl] +optional = true +version = "0.10.11" + [dev-dependencies] tempfile = "3" [features] -vendored-openssl = ['openssl/vendored'] +vendored-openssl = ["openssl/vendored"] diff --git a/src/lib.rs b/src/lib.rs index 0000c4ad..7ced3bb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ extern crate cargo_metadata; extern crate console; extern crate curl; extern crate dirs; +extern crate strsim; #[macro_use] extern crate failure; extern crate flate2; diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 9211303e..6efe1a1c 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -16,9 +16,12 @@ use progressbar::Step; use serde::{self, Deserialize}; use serde_json; use std::collections::BTreeSet; +use strsim::levenshtein; use toml; use PBAR; +const WASM_PACK_METADATA_KEY: &'static str = "package.metadata.wasm-pack"; + /// Store for metadata learned about a crate pub struct CrateData { data: Metadata, @@ -202,6 +205,7 @@ struct NpmData { pub struct ManifestAndUnsedKeys { pub manifest: CargoManifest, pub unused_keys: BTreeSet, + pub has_possible_typo: bool, } impl CrateData { @@ -220,12 +224,10 @@ impl CrateData { let data = cargo_metadata::metadata(Some(&manifest_path)).map_err(error_chain_to_failure)?; - let ManifestAndUnsedKeys { - manifest, - unused_keys, - } = CrateData::parse_crate_data(&manifest_path)?; - CrateData::warn_for_unused_keys(&unused_keys); + let manifest_and_keys = CrateData::parse_crate_data(&manifest_path)?; + CrateData::warn_for_unused_keys(&manifest_and_keys); + let manifest = manifest_and_keys.manifest; let current_idx = data .packages .iter() @@ -264,11 +266,17 @@ impl CrateData { let manifest = &mut toml::Deserializer::new(&manifest); let mut unused_keys = BTreeSet::new(); + let mut has_possible_typo = false; + let levenshtein_threshold = 1; let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { let path_string = path.to_string(); - if path_string.contains("metadata") { + if levenshtein(WASM_PACK_METADATA_KEY, &path_string) == levenshtein_threshold { + has_possible_typo = true; + } + + if path_string.contains(WASM_PACK_METADATA_KEY) { unused_keys.insert(path_string); } }) @@ -277,13 +285,20 @@ impl CrateData { Ok(ManifestAndUnsedKeys { manifest, unused_keys, + has_possible_typo, }) } /// Iterating through all the passed `unused_keys` and output /// a warning for each unknown key. - pub fn warn_for_unused_keys(unused_keys: &BTreeSet) { - unused_keys.iter().for_each(|path| { + pub fn warn_for_unused_keys(manifest_and_keys: &ManifestAndUnsedKeys) { + if manifest_and_keys.has_possible_typo { + PBAR.warn(&format!( + "It's possible that you misspelled the \"{}\" setting in your Cargo.toml.", + WASM_PACK_METADATA_KEY + )); + } + manifest_and_keys.unused_keys.iter().for_each(|path| { PBAR.warn(&format!( "\"{}\" is a unknown key and will be ignored. Please check your Cargo.toml.", path diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index dce984fb..1d631c84 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -353,7 +353,8 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { [dependencies] wasm-bindgen = "0.2" - [package.metadata.wasmpack.profile.dev.wasm-bindgen] + # Note: production is not valid. + [package.metadata.wasm-pack.profile.production.wasm-bindgen] debug-js-glue = true "#, ) @@ -365,5 +366,5 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { let manifest::ManifestAndUnsedKeys { unused_keys, .. } = result.unwrap(); - assert!(unused_keys.contains("package.metadata.wasmpack")); + assert!(unused_keys.contains("package.metadata.wasm-pack.profile.production")); } From 8dd6fe4453c07e5f8f116b3d12da8ac39916f82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Wed, 14 Nov 2018 18:29:04 +0100 Subject: [PATCH 06/15] chore: Restore unwanted reordering --- Cargo.toml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b39ba120..60aa2bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -authors = ["Ashley Williams "] -categories = ["wasm"] +name = "wasm-pack" description = "pack up the wasm and publish it to npm!" -documentation = "https://rustwasm.github.io/wasm-pack/" +version = "0.5.1" +authors = ["Ashley Williams "] +repository = "https://github.com/ashleygwilliams/wasm-pack.git" license = "MIT/Apache-2.0" -name = "wasm-pack" readme = "README.md" -repository = "https://github.com/ashleygwilliams/wasm-pack.git" -version = "0.5.1" +categories = ["wasm"] +documentation = "https://rustwasm.github.io/wasm-pack/" [dependencies] atty = "0.2.11" @@ -21,6 +21,7 @@ hex = "0.3" human-panic = "1.0.1" indicatif = "0.9.0" lazy_static = "1.1.0" +openssl = { version = '0.10.11', optional = true } parking_lot = "0.6" serde = "1.0.74" serde_derive = "1.0.74" @@ -28,8 +29,8 @@ serde_ignored = "0.0.4" serde_json = "1.0.26" siphasher = "0.2.3" slog = "2.3" -slog-async = "2.3" slog-term = "2.4" +slog-async = "2.3" strsim = "0.8.0" structopt = "0.2" tar = "0.4.16" @@ -37,12 +38,8 @@ toml = "0.4" which = "2.0.0" zip = "0.4.2" -[dependencies.openssl] -optional = true -version = "0.10.11" - [dev-dependencies] tempfile = "3" [features] -vendored-openssl = ["openssl/vendored"] +vendored-openssl = ['openssl/vendored'] From 07d813f6063bce9e8525a99c4ed7134a25f9a1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Wed, 14 Nov 2018 21:59:25 +0100 Subject: [PATCH 07/15] fix: Print the possible misspelled key so the user doesnt have to guess --- src/manifest/mod.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 6efe1a1c..5d44d393 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -205,7 +205,6 @@ struct NpmData { pub struct ManifestAndUnsedKeys { pub manifest: CargoManifest, pub unused_keys: BTreeSet, - pub has_possible_typo: bool, } impl CrateData { @@ -266,17 +265,15 @@ impl CrateData { let manifest = &mut toml::Deserializer::new(&manifest); let mut unused_keys = BTreeSet::new(); - let mut has_possible_typo = false; let levenshtein_threshold = 1; let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { let path_string = path.to_string(); - if levenshtein(WASM_PACK_METADATA_KEY, &path_string) == levenshtein_threshold { - has_possible_typo = true; - } - - if path_string.contains(WASM_PACK_METADATA_KEY) { + if path_string.starts_with("package.metadata") + && (path_string.contains("wasm-pack") + || levenshtein(WASM_PACK_METADATA_KEY, &path_string) <= levenshtein_threshold) + { unused_keys.insert(path_string); } }) @@ -285,19 +282,12 @@ impl CrateData { Ok(ManifestAndUnsedKeys { manifest, unused_keys, - has_possible_typo, }) } /// Iterating through all the passed `unused_keys` and output /// a warning for each unknown key. pub fn warn_for_unused_keys(manifest_and_keys: &ManifestAndUnsedKeys) { - if manifest_and_keys.has_possible_typo { - PBAR.warn(&format!( - "It's possible that you misspelled the \"{}\" setting in your Cargo.toml.", - WASM_PACK_METADATA_KEY - )); - } manifest_and_keys.unused_keys.iter().for_each(|path| { PBAR.warn(&format!( "\"{}\" is a unknown key and will be ignored. Please check your Cargo.toml.", From 2d837f795c2448d0d14724c1bb047021342f7a48 Mon Sep 17 00:00:00 2001 From: Mason Stallmo Date: Sun, 14 Oct 2018 09:37:19 -0500 Subject: [PATCH 08/15] Copy license file(s) to out directory Check the Cagro.toml for a license and if one is found glob for LICENSE* files to copy to the out directory --- Cargo.lock | 7 +++ Cargo.toml | 1 + src/command/build.rs | 17 ++++- src/lib.rs | 3 + src/license.rs | 76 ++++++++++++++++++++++ tests/all/license.rs | 125 +++++++++++++++++++++++++++++++++++++ tests/all/main.rs | 1 + tests/all/utils/fixture.rs | 59 +++++++++++++++++ 8 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 src/license.rs create mode 100644 tests/all/license.rs diff --git a/Cargo.lock b/Cargo.lock index 2279393c..d0133d5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -317,6 +317,11 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "glob" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "heck" version = "0.3.0" @@ -1048,6 +1053,7 @@ dependencies = [ "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1172,6 +1178,7 @@ dependencies = [ "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21638c5955a6daf3ecc42cae702335fc37a72a4abcc6959ce457b31a7d43bbdd" diff --git a/Cargo.toml b/Cargo.toml index b486071b..e2563caa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ failure = "0.1.2" flate2 = "1.0.2" hex = "0.3" human-panic = "1.0.1" +glob = "0.2" indicatif = "0.9.0" lazy_static = "1.1.0" openssl = { version = '0.10.11', optional = true } diff --git a/src/command/build.rs b/src/command/build.rs index d3dc15f0..2779851f 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -7,6 +7,7 @@ use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use failure::Error; use indicatif::HumanDuration; +use license; use lockfile::Lockfile; use manifest; use progressbar::Step; @@ -209,6 +210,7 @@ impl Build { step_create_dir, step_create_json, step_copy_readme, + step_copy_license, step_install_wasm_bindgen, step_run_wasm_bindgen, ], @@ -219,6 +221,7 @@ impl Build { step_create_dir, step_create_json, step_copy_readme, + step_copy_license, step_run_wasm_bindgen ], BuildMode::Force => steps![ @@ -226,6 +229,7 @@ impl Build { step_create_dir, step_create_json, step_copy_readme, + step_copy_license, step_run_wasm_bindgen ], } @@ -300,7 +304,18 @@ impl Build { Ok(()) } - fn step_install_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + fn step_copy_license(&mut self, step: &Step, log: &Logger) -> Result<(), failure::Error> { + info!(&log, "Copying license from crate..."); + license::copy_from_crate(&self.crate_path, &self.out_dir, step)?; + info!(&log, "Copied license from crate to {:#?}.", &self.out_dir); + Ok(()) + } + + fn step_install_wasm_bindgen( + &mut self, + step: &Step, + log: &Logger, + ) -> Result<(), failure::Error> { info!(&log, "Identifying wasm-bindgen dependency..."); let lockfile = Lockfile::new(&self.crate_data)?; let bindgen_version = lockfile.require_wasm_bindgen()?; diff --git a/src/lib.rs b/src/lib.rs index 2cec7a83..bebdb2a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ extern crate dirs; extern crate failure; extern crate flate2; extern crate hex; +extern crate glob; extern crate indicatif; #[macro_use] extern crate lazy_static; @@ -36,6 +37,8 @@ pub mod build; pub mod child; pub mod command; pub mod emoji; +pub mod error; +pub mod license; pub mod lockfile; pub mod logger; pub mod manifest; diff --git a/src/license.rs b/src/license.rs new file mode 100644 index 00000000..4e7a41b8 --- /dev/null +++ b/src/license.rs @@ -0,0 +1,76 @@ +//! Copy `LICENSE` file(s) for the packaged wasm. + +use failure; +use std::fs; +use std::path::Path; + +use emoji; +use glob::glob; +use manifest; +use progressbar::Step; +use PBAR; + +fn get_license(path: &Path) -> Option { + match manifest::get_crate_license(path) { + Ok(license) => license, + Err(_) => None, + } +} + +fn glob_license_files(path: &Path) -> Result, failure::Error> { + let mut license_files: Vec = Vec::new(); + for entry in glob(path.join("LICENSE*").to_str().unwrap())? { + match entry { + Ok(globed_path) => { + license_files.push(String::from( + globed_path.file_name().unwrap().to_str().unwrap(), + )); + } + Err(e) => println!("{:?}", e), + } + } + Ok(license_files) +} + +/// Copy the crate's license into the `pkg` directory. +pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), failure::Error> { + assert!( + fs::metadata(path).ok().map_or(false, |m| m.is_dir()), + "crate directory should exist" + ); + + assert!( + fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()), + "crate's pkg directory should exist" + ); + + match get_license(path) { + Some(_) => { + let msg = format!("{}Copying over your LICENSE...", emoji::DANCERS); + PBAR.step(step, &msg); + let license_files = glob_license_files(path); + + match license_files { + Ok(files) => { + if files.len() == 0 { + PBAR.info("License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory"); + return Ok(()); + } + for license_file in files { + let crate_license_path = path.join(&license_file); + let new_license_path = out_dir.join(&license_file); + if let Err(_) = fs::copy(&crate_license_path, &new_license_path) { + PBAR.info("origin crate has no LICENSE"); + } + } + } + Err(_) => PBAR.info("origin crate has no LICENSE"), + } + } + None => { + PBAR.step(step, "No LICENSE found in Cargo.toml skipping..."); + } + }; + + Ok(()) +} diff --git a/tests/all/license.rs b/tests/all/license.rs new file mode 100644 index 00000000..376bd4d6 --- /dev/null +++ b/tests/all/license.rs @@ -0,0 +1,125 @@ +extern crate failure; +extern crate wasm_pack; + +use std::fs; + +use utils::{self, fixture}; +use wasm_pack::license; + +#[test] +fn it_copies_a_license_default_path() { + let fixture = fixture::single_license(); + let out_dir = fixture.path.join("pkg"); + fs::create_dir(&out_dir).expect("should create pkg directory OK"); + + let step = wasm_pack::progressbar::Step::new(1); + assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + + let crate_license_path = fixture.path.join("LICENSE-WTFPL"); + let pkg_license_path = out_dir.join("LICENSE-WTFPL"); + println!( + "wasm-pack: should have copied LICENSE from '{}' to '{}'", + crate_license_path.display(), + pkg_license_path.display() + ); + assert!(fs::metadata(&crate_license_path).is_ok()); + + assert!(fs::metadata(&pkg_license_path).is_ok()); + + let crate_license = utils::file::read_file(&crate_license_path).unwrap(); + let pkg_license = utils::file::read_file(&pkg_license_path).unwrap(); + assert_eq!(crate_license, pkg_license); +} + +#[test] +fn it_copies_a_license_provied_path() { + let fixture = fixture::single_license(); + let out_dir = fixture.path.join("pkg"); + fs::create_dir(&out_dir).expect("should create pkg directory OK"); + + let step = wasm_pack::progressbar::Step::new(1); + assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + let crate_license_path = fixture.path.join("LICENSE-WTFPL"); + let pkg_license_path = out_dir.join("LICENSE-WTFPL"); + println!( + "wasm-pack: should have copied LICENSE-WTFPL from '{}' to '{}'", + crate_license_path.display(), + pkg_license_path.display() + ); + assert!(fs::metadata(&crate_license_path).is_ok()); + assert!(fs::metadata(&pkg_license_path).is_ok()); + + let crate_license = utils::file::read_file(&crate_license_path).unwrap(); + let pkg_license = utils::file::read_file(&pkg_license_path).unwrap(); + assert_eq!(crate_license, pkg_license); +} + +#[test] +fn it_copies_all_licenses_default_path() { + let fixture = fixture::dual_license(); + let out_dir = fixture.path.join("pkg"); + fs::create_dir(&out_dir).expect("should create pkg directory OK"); + + let step = wasm_pack::progressbar::Step::new(1); + assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + + let crate_license_path = fixture.path.join("LICENSE-WTFPL"); + let pkg_license_path = out_dir.join("LICENSE-WTFPL"); + + let crate_license_path_2 = fixture.path.join("LICENSE-MIT"); + let pkg_license_path_2 = out_dir.join("LICENSE-MIT"); + + println!( + "wasm-pack: should have copied LICENSE from '{}' to '{}'", + crate_license_path.display(), + pkg_license_path.display() + ); + assert!(fs::metadata(&crate_license_path).is_ok()); + assert!(fs::metadata(&pkg_license_path).is_ok()); + + assert!(fs::metadata(&crate_license_path_2).is_ok()); + assert!(fs::metadata(&pkg_license_path_2).is_ok()); + + let crate_license = utils::file::read_file(&crate_license_path).unwrap(); + let pkg_license = utils::file::read_file(&pkg_license_path).unwrap(); + assert_eq!(crate_license, pkg_license); + + let crate_license_2 = utils::file::read_file(&crate_license_path_2).unwrap(); + let pkg_license_2 = utils::file::read_file(&pkg_license_path_2).unwrap(); + assert_eq!(crate_license_2, pkg_license_2); +} + +#[test] +fn it_copies_all_licenses_provided_path() { + let fixture = fixture::dual_license(); + let out_dir = fixture.path.join("pkg"); + fs::create_dir(&out_dir).expect("should create pkg directory OK"); + + let step = wasm_pack::progressbar::Step::new(1); + assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + + let crate_license_path = fixture.path.join("LICENSE-WTFPL"); + let pkg_license_path = out_dir.join("LICENSE-WTFPL"); + + let crate_license_path_2 = fixture.path.join("LICENSE-MIT"); + let pkg_license_path_2 = out_dir.join("LICENSE-MIT"); + + println!( + "wasm-pack: should have copied LICENSE from '{}' to '{}'", + crate_license_path.display(), + pkg_license_path.display() + ); + assert!(fs::metadata(&crate_license_path).is_ok()); + assert!(fs::metadata(&pkg_license_path).is_ok()); + + assert!(fs::metadata(&crate_license_path_2).is_ok()); + assert!(fs::metadata(&pkg_license_path_2).is_ok()); + + let crate_license = utils::file::read_file(&crate_license_path).unwrap(); + let pkg_license = utils::file::read_file(&pkg_license_path).unwrap(); + assert_eq!(crate_license, pkg_license); + + let crate_license_2 = utils::file::read_file(&crate_license_path_2).unwrap(); + let pkg_license_2 = utils::file::read_file(&pkg_license_path_2).unwrap(); + assert_eq!(crate_license_2, pkg_license_2); +} diff --git a/tests/all/main.rs b/tests/all/main.rs index 3fa272f3..563424d3 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -12,6 +12,7 @@ extern crate wasm_pack; mod bindgen; mod build; +mod license; mod lockfile; mod manifest; mod readme; diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 9a9a58cd..17ca3653 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -68,6 +68,44 @@ impl Fixture { ) } + /// Add `WTFPL LICENSE` file to the fixture. + pub fn wtfpl_license(&self) -> &Self { + self.file( + "LICENSE-WTFPL", + r#" + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + "#, + ) + } + + /// Add `MIT LICENSE` file to the fixture. + pub fn mit_license(&self) -> &Self { + self.file( + "LICENSE-MIT", + r#" + Copyright + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + "#, + ) + } + /// Add a `Cargo.toml` with a correctly configured `wasm-bindgen` /// dependency, `wasm-bindgen-test` dev-dependency, and `crate-type = /// ["cdylib"]`. @@ -590,3 +628,24 @@ pub fn transitive_dependencies() -> Fixture { project_main_fixture(&mut fixture); fixture } + +pub fn single_license() -> Fixture { + let fixture = Fixture::new(); + fixture + .readme() + .cargo_toml("single_license") + .wtfpl_license() + .hello_world_src_lib(); + fixture +} + +pub fn dual_license() -> Fixture { + let fixture = Fixture::new(); + fixture + .readme() + .cargo_toml("dual_license") + .wtfpl_license() + .mit_license() + .hello_world_src_lib(); + fixture +} From 1c704b7b7ccce54e9d290735fdc5e88146f00106 Mon Sep 17 00:00:00 2001 From: Mason Stallmo Date: Wed, 31 Oct 2018 08:54:42 -0500 Subject: [PATCH 09/15] Reword WTFPL and add punctuation to license not found message. --- src/license.rs | 2 +- tests/all/utils/fixture.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/license.rs b/src/license.rs index 4e7a41b8..44391e71 100644 --- a/src/license.rs +++ b/src/license.rs @@ -68,7 +68,7 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), f } } None => { - PBAR.step(step, "No LICENSE found in Cargo.toml skipping..."); + PBAR.step(step, "No LICENSE found in Cargo.toml, skipping..."); } }; diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 17ca3653..51331b66 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -73,7 +73,7 @@ impl Fixture { self.file( "LICENSE-WTFPL", r#" - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + DO WHATEVER YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar @@ -82,10 +82,10 @@ impl Fixture { copies of this license document, and changing it is allowed as long as the name is changed. - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + DO WHATEVER YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - 0. You just DO WHAT THE FUCK YOU WANT TO. + 0. You just DO WHATEVER YOU WANT TO. "#, ) } From 272ef97befcca09cccd667181c786b1664d57c99 Mon Sep 17 00:00:00 2001 From: Mason Stallmo Date: Sat, 17 Nov 2018 10:53:44 -0600 Subject: [PATCH 10/15] Refactor: make `crate_license` a method of CrateData. --- src/command/build.rs | 2 +- src/lib.rs | 3 +-- src/license.rs | 18 ++++++++---------- src/manifest/mod.rs | 5 +++++ tests/all/license.rs | 13 +++++++++---- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 2779851f..c495cdc2 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -306,7 +306,7 @@ impl Build { fn step_copy_license(&mut self, step: &Step, log: &Logger) -> Result<(), failure::Error> { info!(&log, "Copying license from crate..."); - license::copy_from_crate(&self.crate_path, &self.out_dir, step)?; + license::copy_from_crate(&self.crate_data, &self.crate_path, &self.out_dir, step)?; info!(&log, "Copied license from crate to {:#?}.", &self.out_dir); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index bebdb2a4..03cd4368 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,8 @@ extern crate dirs; #[macro_use] extern crate failure; extern crate flate2; -extern crate hex; extern crate glob; +extern crate hex; extern crate indicatif; #[macro_use] extern crate lazy_static; @@ -37,7 +37,6 @@ pub mod build; pub mod child; pub mod command; pub mod emoji; -pub mod error; pub mod license; pub mod lockfile; pub mod logger; diff --git a/src/license.rs b/src/license.rs index 44391e71..0b91e78e 100644 --- a/src/license.rs +++ b/src/license.rs @@ -6,17 +6,10 @@ use std::path::Path; use emoji; use glob::glob; -use manifest; +use manifest::CrateData; use progressbar::Step; use PBAR; -fn get_license(path: &Path) -> Option { - match manifest::get_crate_license(path) { - Ok(license) => license, - Err(_) => None, - } -} - fn glob_license_files(path: &Path) -> Result, failure::Error> { let mut license_files: Vec = Vec::new(); for entry in glob(path.join("LICENSE*").to_str().unwrap())? { @@ -33,7 +26,12 @@ fn glob_license_files(path: &Path) -> Result, failure::Error> { } /// Copy the crate's license into the `pkg` directory. -pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), failure::Error> { +pub fn copy_from_crate( + crate_data: &CrateData, + path: &Path, + out_dir: &Path, + step: &Step, +) -> Result<(), failure::Error> { assert!( fs::metadata(path).ok().map_or(false, |m| m.is_dir()), "crate directory should exist" @@ -44,7 +42,7 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), f "crate's pkg directory should exist" ); - match get_license(path) { + match crate_data.crate_license() { Some(_) => { let msg = format!("{}Copying over your LICENSE...", emoji::DANCERS); PBAR.step(step, &msg); diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 8c3e3902..0be6c283 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -289,6 +289,11 @@ impl CrateData { } } + /// Get the license for the crate at the given path. + pub fn crate_license(&self) -> &Option { + &self.manifest.package.license + } + /// Returns the path to this project's target directory where artifacts are /// located after a cargo build. pub fn target_directory(&self) -> &Path { diff --git a/tests/all/license.rs b/tests/all/license.rs index 376bd4d6..ac7d3776 100644 --- a/tests/all/license.rs +++ b/tests/all/license.rs @@ -5,15 +5,17 @@ use std::fs; use utils::{self, fixture}; use wasm_pack::license; +use wasm_pack::manifest::CrateData; #[test] fn it_copies_a_license_default_path() { let fixture = fixture::single_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); + let crate_data = CrateData::new(&fixture.path); let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); let crate_license_path = fixture.path.join("LICENSE-WTFPL"); let pkg_license_path = out_dir.join("LICENSE-WTFPL"); @@ -36,9 +38,10 @@ fn it_copies_a_license_provied_path() { let fixture = fixture::single_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); + let crate_data = CrateData::new(&fixture.path); let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); let crate_license_path = fixture.path.join("LICENSE-WTFPL"); let pkg_license_path = out_dir.join("LICENSE-WTFPL"); println!( @@ -59,9 +62,10 @@ fn it_copies_all_licenses_default_path() { let fixture = fixture::dual_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); + let crate_data = CrateData::new(&fixture.path); let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); let crate_license_path = fixture.path.join("LICENSE-WTFPL"); let pkg_license_path = out_dir.join("LICENSE-WTFPL"); @@ -94,9 +98,10 @@ fn it_copies_all_licenses_provided_path() { let fixture = fixture::dual_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); + let crate_data = CrateData::new(&fixture.path); let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); let crate_license_path = fixture.path.join("LICENSE-WTFPL"); let pkg_license_path = out_dir.join("LICENSE-WTFPL"); From b567fc0f8894b45c156e066d7411f791cb447796 Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Mon, 19 Nov 2018 08:41:07 +1100 Subject: [PATCH 11/15] update zip to 0.5.0 --- Cargo.lock | 40 +++++++++++++++++++++++++--------------- Cargo.toml | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2279393c..3bb6ba85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,6 +203,14 @@ dependencies = [ "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crc32fast" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "curl" version = "0.4.19" @@ -397,6 +405,16 @@ name = "libc" version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libflate" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libz-sys" version = "1.0.25" @@ -455,15 +473,6 @@ dependencies = [ "miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "msdos_time" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "nodrop" version = "0.1.12" @@ -1066,7 +1075,7 @@ dependencies = [ "tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zip 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1125,12 +1134,12 @@ dependencies = [ [[package]] name = "zip" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crc32fast 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libflate 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1160,6 +1169,7 @@ dependencies = [ "checksum console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd48adf136733979b49e15bc3b4c43cc0d3c85ece7bd08e6daa414c6fcb13e6" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum crc32fast 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a8795e4883c14e32604fe28607ae96c921f3377d2a80c46f06a9e6e734c364f4" "checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16" "checksum curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "721c204978be2143fab0a84b708c49d79d1f6100b8785610f456043a90708870" "checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a" @@ -1182,13 +1192,13 @@ dependencies = [ "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum libflate 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "21138fc6669f438ed7ae3559d5789a5f0ba32f28c1f0608d1e452b0bb06ee936" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a" "checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" "checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649" "checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" "checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" -"checksum msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aad9dfe950c057b1bfe9c1f2aa51583a8468ef2a5baba2ebbe06d775efeb7729" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" @@ -1270,4 +1280,4 @@ dependencies = [ "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767" "checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" -"checksum zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "36b9e08fb518a65cf7e08a1e482573eb87a2f4f8c6619316612a3c1f162fe822" +"checksum zip 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00acf1fafb786ff450b6726e5be41ef029142597b47a40ce80f952f1471730a0" diff --git a/Cargo.toml b/Cargo.toml index b486071b..2869362d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ structopt = "0.2" tar = "0.4.16" toml = "0.4" which = "2.0.0" -zip = "0.4.2" +zip = "0.5.0" [dev-dependencies] tempfile = "3" From d788b805831416251ab0043f40aa1309bebe6091 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Thu, 29 Nov 2018 17:04:11 +0000 Subject: [PATCH 12/15] Generate self-.gitignore as part of pkg folder --- src/command/utils.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/utils.rs b/src/command/utils.rs index fee4d4f3..59279829 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -18,6 +18,7 @@ pub fn create_pkg_dir(out_dir: &Path, step: &Step) -> Result<(), failure::Error> let msg = format!("{}Creating a pkg directory...", emoji::FOLDER); PBAR.step(step, &msg); fs::create_dir_all(&out_dir)?; + fs::write(out_dir.join(".gitignore"), "*")?; Ok(()) } From 87b4c5c7b1655f8032a7cb5de7a0426d1895b850 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Thu, 29 Nov 2018 17:09:44 +0000 Subject: [PATCH 13/15] Add rust-toolchain file set to nightly This allows new contributors to avoid manually running `rustup override set nightly`. --- .github/PULL_REQUEST_TEMPLATE.md | 6 ++---- rust-toolchain | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 rust-toolchain diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e07bd504..43c3cb78 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,12 +1,10 @@ Make sure these boxes are checked! 📦✅ -- [ ] You have the latest version of `rustfmt` installed and have your - cloned directory set to nightly +- [ ] You have the latest version of `rustfmt` installed ```bash -$ rustup override set nightly $ rustup component add rustfmt-preview --toolchain nightly ``` -- [ ] You ran `rustfmt` on the code base before submitting +- [ ] You ran `cargo fmt` on the code base before submitting - [ ] You reference which issue is being closed in the PR text ✨✨ 😄 Thanks so much for contributing to wasm-pack! 😄 ✨✨ diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 00000000..bf867e0a --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly From 2b30ca8e13365494b339151969bd08e548285f31 Mon Sep 17 00:00:00 2001 From: Selwyn Date: Fri, 21 Dec 2018 15:57:23 +0100 Subject: [PATCH 14/15] Fix link to manual setup instructions from getting started --- docs/src/tutorial/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/tutorial/getting-started.md b/docs/src/tutorial/getting-started.md index 8eee61fc..a011e996 100644 --- a/docs/src/tutorial/getting-started.md +++ b/docs/src/tutorial/getting-started.md @@ -25,4 +25,4 @@ further in this guide. ⚠️ If you'd rather not use a template, or are having trouble with the template, you can do a manual setup by following [these instructions]. -[these instructions]: ../project-setup/manual-setup/index.html +[these instructions]: ../project-setup/manual-setup.html From 99ccb75105561d3b4198dfb1e53f0b32d467f49d Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Thu, 27 Dec 2018 20:44:36 +0000 Subject: [PATCH 15/15] Delete rust-toolchain --- rust-toolchain | 1 - 1 file changed, 1 deletion(-) delete mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index bf867e0a..00000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly