updated from upstream

master
daubaris 7 years ago
parent 33c602cf82
commit f7c534ffe5
  1. 9
      src/build.rs
  2. 6
      src/command/build.rs
  3. 12
      src/command/mod.rs
  4. 22
      src/manifest/mod.rs
  5. 8
      tests/all/bindgen.rs
  6. 7
      tests/all/build.rs
  7. 86
      tests/all/manifest.rs

@ -3,8 +3,6 @@
use child;
use emoji;
use failure::{Error, ResultExt};
use error::Error;
use failure::ResultExt;
use manifest::Crate;
use progressbar::Step;
use slog::Logger;
@ -38,7 +36,7 @@ pub fn check_wasm_pack_version(step: &Step) -> Result<(), failure::Error> {
let msg = format!("{}Checking `wasm-pack` version...", emoji::PACKAGE);
PBAR.step(step, &msg);
let wasm_pack_local_version = wasm_pack_local_version();
let wasm_pack_latest_version = Crate::return_wasm_pack_latest_version();
let wasm_pack_latest_version = Crate::return_wasm_pack_latest_version()?;
match wasm_pack_local_version {
Some(lv) => {
if !(lv == wasm_pack_latest_version) {
@ -47,9 +45,8 @@ pub fn check_wasm_pack_version(step: &Step) -> Result<(), failure::Error> {
Ok(())
}
},
None => Err(Error::WasmPackMissing {
message: "We can't figure out what your wasm-pack version is, make sure the installation path is correct.".to_string(),
}.into()),
None => bail!("We can't figure out what your wasm-pack version is, make sure the installation path is correct."),
}
}

@ -213,11 +213,7 @@ impl Build {
Ok(())
}
fn step_check_wasm_pack_version(
&mut self,
step: &Step,
log: &Logger,
) -> Result<(), failure::Error> {
fn step_check_wasm_pack_version(&mut self, step: &Step, log: &Logger) -> Result<(), Error> {
info!(&log, "Checking wasm-pack version...");
let version = build::check_wasm_pack_version(step)?;
let msg = format!("wasm-pack version is: {:?}.", version);

@ -13,10 +13,12 @@ use self::login::login;
use self::pack::pack;
use self::publish::{access::Access, publish};
use self::test::{Test, TestOptions};
use std::sync::mpsc;
use failure::Error;
use slog::Logger;
use std::path::PathBuf;
use std::result;
use std::thread;
/// The various kinds of commands that `wasm-pack` can execute.
#[derive(Debug, StructOpt)]
@ -82,6 +84,15 @@ pub enum Command {
Test(TestOptions),
}
/// Spawn a thread for wasm-pack version
fn background_check_for_updates() -> mpsc::Receiver<(String, String)> {
let (sender, receiver) = mpsc::channel();
let _detached_thread = thread::spawn(move || {
});
}
/// Run a command with the given logger!
pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error> {
// Run the correct command based off input and store the result of it so that we can clear
@ -89,6 +100,7 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error
let status = match command {
Command::Build(build_opts) => {
info!(&log, "Running build command...");
// Add the background_check_for_updates() here
Build::try_from_opts(build_opts).and_then(|mut b| b.run(&log))
}
Command::Pack { path } => {

@ -4,7 +4,6 @@ mod npm;
use std::fs;
use std::path::Path;
use std::collections::HashMap;
use self::npm::{
repository::Repository, CommonJSPackage, ESModulesPackage, NoModulesPackage, NpmPackage,
@ -41,7 +40,7 @@ struct CargoManifest {
package: CargoPackage,
}
#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
struct CargoPackage {
name: String,
description: Option<String>,
@ -70,22 +69,21 @@ struct CrateInformation {
impl Crate {
/// Call to the crates.io api and return the latest version of `wasm-pack`
pub fn return_wasm_pack_latest_version() -> String {
let crt = Crate::check_wasm_pack_latest_version();
crt.crt.max_version
pub fn return_wasm_pack_latest_version() -> Result<String, Error> {
let crt = Crate::check_wasm_pack_latest_version()?;
Ok(crt.crt.max_version)
}
fn check_wasm_pack_latest_version() -> Crate {
fn check_wasm_pack_latest_version() -> Result<Crate, Error> {
let mut easy = easy::Easy2::new(Collector(Vec::new()));
easy.get(true).unwrap();
easy.url("https://crates.io/api/v1/crates/wasm-pack")
.unwrap();
easy.perform().unwrap();
easy.get(true)?;
easy.url("https://crates.io/api/v1/crates/wasm-pack")?;
easy.perform()?;
let contents = easy.get_ref();
let result = String::from_utf8_lossy(&contents.0);
serde_json::from_str(result.into_owned().as_str()).unwrap()
Ok(serde_json::from_str(result.into_owned().as_str())?)
}
}
@ -134,8 +132,6 @@ impl CrateData {
}
}
/// Check that the crate the given path is properly configured.
pub fn check_crate_config(&self, step: &Step) -> Result<(), Error> {
let msg = format!("{}Checking crate configuration...", emoji::WRENCH);

@ -31,7 +31,9 @@ fn downloading_prebuilt_wasm_bindgen_handles_http_errors() {
let error = result.err().unwrap();
assert!(error.iter_chain().any(|e| e.to_string().contains("404")));
assert!(error
.iter_chain()
.any(|e| e.to_string().contains(bad_version)));
assert!(
error
.iter_chain()
.any(|e| e.to_string().contains(bad_version))
);
}

@ -18,9 +18,10 @@ fn build_in_non_crate_directory_doesnt_panic() {
"running wasm-pack in a non-crate directory should fail, but it should not panic"
);
let err = result.unwrap_err();
assert!(err
.iter_chain()
.any(|e| e.to_string().contains("missing a `Cargo.toml`")));
assert!(
err.iter_chain()
.any(|e| e.to_string().contains("missing a `Cargo.toml`"))
);
}
#[test]

@ -65,9 +65,11 @@ fn it_creates_a_package_json_default_path() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.is_ok()
);
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -88,9 +90,9 @@ fn it_creates_a_package_json_default_path() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}
@ -101,9 +103,11 @@ fn it_creates_a_package_json_provided_path() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.is_ok()
);
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -117,9 +121,9 @@ fn it_creates_a_package_json_provided_path() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}
@ -130,9 +134,11 @@ fn it_creates_a_package_json_provided_path_with_scope() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &Some("test".to_string()), false, "", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &Some("test".to_string()), false, "", &step)
.is_ok()
);
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -146,9 +152,9 @@ fn it_creates_a_package_json_provided_path_with_scope() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}
@ -159,9 +165,11 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, "nodejs", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &None, false, "nodejs", &step)
.is_ok()
);
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -182,9 +190,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}
@ -195,9 +203,11 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, "no-modules", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &None, false, "no-modules", &step)
.is_ok()
);
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -217,9 +227,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
"js_hello_world.js",
"js_hello_world.d.ts",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}
@ -230,9 +240,11 @@ fn it_creates_a_pkg_json_in_out_dir() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.is_ok()
);
let package_json_path = &fixture.path.join(&out_dir).join("package.json");
fs::metadata(package_json_path).unwrap();
@ -246,9 +258,11 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, true, "", &step)
.is_ok());
assert!(
crate_data
.write_package_json(&out_dir, &None, true, "", &step)
.is_ok()
);
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();

Loading…
Cancel
Save