Skip to content

Commit 6ed7750

Browse files
committed
Added logic to the bindgen::cargo_install_wasm_bindgen function to check if 'wasm-bindgen' already exists in the path.
1 parent 0f01272 commit 6ed7750

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

src/bindgen.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
use PBAR;
21
use console::style;
32
use emoji;
4-
use std::process::Command;
3+
use std::{env, fs, process::Command};
4+
use PBAR;
5+
6+
#[cfg(target_family = "windows")]
7+
static PATH_SEP: &str = ";";
8+
9+
#[cfg(not(target_family = "windows"))]
10+
static PATH_SEP: &str = ":";
511

612
pub fn cargo_install_wasm_bindgen() {
13+
if wasm_bindgen_installed() {
14+
return;
15+
}
716
let step = format!(
817
"{} {}Installing WASM-bindgen...",
918
style("[6/7]").bold().dim(),
@@ -36,3 +45,16 @@ pub fn wasm_bindgen_build(path: &str, name: &str) {
3645
.unwrap_or_else(|e| panic!("{} failed to execute process: {}", emoji::ERROR, e));
3746
pb.finish();
3847
}
48+
49+
fn wasm_bindgen_installed() -> bool {
50+
if let Ok(path) = env::var("PATH") {
51+
path.split(PATH_SEP)
52+
.map(|p: &str| -> bool {
53+
let prog_str = format!("{}/wasm-bindgen", p);
54+
fs::metadata(prog_str).is_ok()
55+
})
56+
.fold(false, |res, b| res || b)
57+
} else {
58+
false
59+
}
60+
}

src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use PBAR;
21
use console::style;
32
use emoji;
43
use std::process::Command;
4+
use PBAR;
55

66
pub fn rustup_add_wasm_target() {
77
let step = format!(

src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use PBAR;
21
use bindgen;
32
use build;
43
use console::style;
@@ -12,6 +11,7 @@ use readme;
1211
use std::fs;
1312
use std::result;
1413
use std::time::Instant;
14+
use PBAR;
1515

1616
#[derive(Debug, StructOpt)]
1717
pub enum Command {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ extern crate indicatif;
55
extern crate quicli;
66

77
use quicli::prelude::*;
8-
use wasm_pack::Cli;
98
use wasm_pack::command::{init_command, pack_command, publish_command, Command};
9+
use wasm_pack::Cli;
1010

1111
main!(|args: Cli, log_level: verbosity| match args.cmd {
1212
Command::Init { path, scope } => {

src/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::fs::File;
22
use std::io::prelude::*;
33

4-
use PBAR;
54
use console::style;
65
use emoji;
76
use failure::Error;
87
use serde_json;
98
use toml;
9+
use PBAR;
1010

1111
#[derive(Deserialize)]
1212
struct CargoManifest {

src/readme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use console::style;
22
use failure::Error;
33
use std::fs;
44

5-
use PBAR;
65
use emoji;
6+
use PBAR;
77

88
pub fn copy_from_crate(path: &str) -> Result<(), Error> {
99
let step = format!(

0 commit comments

Comments
 (0)