Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attempt wasm-bindgen install if it exists in path. #81

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
use console::style;
use emoji;
use error::Error;
use std::process::Command;
use std::{env, fs, process::Command};
use PBAR;

#[cfg(target_family = "windows")]
static PATH_SEP: &str = ";";

#[cfg(not(target_family = "windows"))]
static PATH_SEP: &str = ":";

pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
if wasm_bindgen_installed()? {
return Ok(());
}
let step = format!(
"{} {}Installing WASM-bindgen...",
style("[6/7]").bold().dim(),
Expand Down Expand Up @@ -71,3 +80,14 @@ pub fn wasm_bindgen_build(
Ok(())
}
}

fn wasm_bindgen_installed() -> Result<bool, Error> {
let path = env::var("PATH")?;
let is_installed = path.split(PATH_SEP)
.map(|p: &str| -> bool {
let prog_str = format!("{}/wasm-bindgen", p);
fs::metadata(prog_str).is_ok()
})
.fold(false, |res, b| res || b);
Ok(is_installed)
}
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Code related to error handling for wasm-pack
use serde_json;
use std::borrow::Cow;
use std::env;
use std::io;
use toml;

Expand All @@ -13,6 +14,8 @@ pub enum Error {
SerdeJson(#[cause] serde_json::Error),
#[fail(display = "{}", _0)]
SerdeToml(#[cause] toml::de::Error),
#[fail(display = "{}", _0)]
VarError(#[cause] env::VarError),
#[fail(display = "{}. stderr:\n\n{}", message, stderr)]
Cli { message: String, stderr: String },
}
Expand All @@ -30,6 +33,7 @@ impl Error {
Error::Io(_) => "There was an I/O error. Details:\n\n",
Error::SerdeJson(_) => "There was an JSON error. Details:\n\n",
Error::SerdeToml(_) => "There was an TOML error. Details:\n\n",
Error::VarError(_) => "There was an error finding an environment variable. Details:\n\n",
Error::Cli {
message: _,
stderr: _,
Expand All @@ -55,3 +59,9 @@ impl From<toml::de::Error> for Error {
Error::SerdeToml(e)
}
}

impl From<env::VarError> for Error {
fn from(e: env::VarError) -> Self {
Error::VarError(e)
}
}