feat(bindgen): check wasm-bindgen cli version when running target web

master
Ashley Williams 6 years ago
parent 22a63ea86f
commit 032c9f4cbd
  1. 1
      Cargo.lock
  2. 1
      Cargo.toml
  3. 27
      src/bindgen.rs
  4. 1
      src/lib.rs
  5. 12
      tests/all/build.rs

1
Cargo.lock generated

@ -1987,6 +1987,7 @@ dependencies = [
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",

@ -24,6 +24,7 @@ log = "0.4.6"
openssl = { version = '0.10.11', optional = true }
parking_lot = "0.6"
reqwest = "0.9.14"
semver = "0.9.0"
serde = "1.0.74"
serde_derive = "1.0.74"
serde_ignored = "0.0.4"

@ -2,11 +2,11 @@
use binary_install::Download;
use child;
use crate::install;
use command::build::{BuildProfile, Target};
use failure::{self, ResultExt};
use install::Tool;
use install;
use manifest::CrateData;
use semver;
use std::path::{Path, PathBuf};
use std::process::Command;
@ -40,13 +40,20 @@ pub fn wasm_bindgen_build(
} else {
"--typescript"
};
let bindgen_path = bindgen.binary("wasm-bindgen")?;
let target_arg = match target {
Target::Nodejs => "--nodejs",
Target::NoModules => "--no-modules",
Target::Web => "--web",
Target::Web => {
if supports_web_target(&bindgen_path)? {
"--web"
} else {
bail!("Your current version of wasm-bindgen does not support the 'web' target. Please update your project to wasm-bindgen version >= 0.2.39.")
}
}
Target::Bundler => "--browser",
};
let bindgen_path = bindgen.binary("wasm-bindgen")?;
let mut cmd = Command::new(&bindgen_path);
cmd.arg(&wasm_path)
.arg("--out-dir")
@ -69,14 +76,16 @@ pub fn wasm_bindgen_build(
cmd.arg("--keep-debug");
}
let versions_match = install::check_version(&Tool::WasmBindgen, &bindgen_path, "0.2.37")?;
assert!(versions_match, "Something went wrong! wasm-bindgen CLI and dependency version don't match. This is likely not your fault! You should file an issue: https://github.com/rustwasm/wasm-pack/issues/new?template=bug_report.md.");
child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
Ok(())
}
/// Check if the `wasm-bindgen` dependency is locally satisfied.
fn supports_web_target(cli_path: &PathBuf, dep_version: &str) -> Result<bool, failure::Error> {
unimplemented!();
fn supports_web_target(cli_path: &PathBuf) -> Result<bool, failure::Error> {
let cli_version = semver::Version::parse(&install::get_cli_version(
&install::Tool::WasmBindgen,
cli_path,
)?)?;
let expected_version = semver::Version::parse("0.2.39")?;
Ok(cli_version >= expected_version)
}

@ -9,6 +9,7 @@ extern crate strsim;
extern crate failure;
extern crate glob;
extern crate parking_lot;
extern crate semver;
extern crate serde;
extern crate which;
#[macro_use]

@ -136,14 +136,20 @@ fn dash_dash_web_target_has_error_on_old_bindgen() {
"#,
)
.install_local_wasm_bindgen();
fixture
let cmd = fixture
.wasm_pack()
.arg("build")
.arg("--target")
.arg("web")
.assert()
.success()
.stdout("");
.failure();
let output = String::from_utf8(cmd.get_output().stderr.clone()).unwrap();
assert!(
output.contains("0.2.39"),
"Output did not contain '0.2.39', output was {}",
output
);
}
#[test]

Loading…
Cancel
Save