diff --git a/src/bindgen.rs b/src/bindgen.rs index 68e9b606..296e4ab3 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -1,6 +1,7 @@ //! Functionality related to installing and running `wasm-bindgen`. use binaries::{self, bin_path, install_binaries_from_targz_at_url}; +use cargo_metadata; use child; use emoji; use error::Error; @@ -127,10 +128,17 @@ pub fn wasm_bindgen_build( let out_dir = out_dir.to_str().unwrap(); if let Some(wasm_bindgen_path) = wasm_bindgen_path(log, path) { - let wasm_path = format!( - "target/wasm32-unknown-unknown/{}/{}.wasm", - release_or_debug, binary_name - ); + let manifest = path.join("Cargo.toml"); + let target_path = cargo_metadata::metadata(Some(&manifest)) + .unwrap() + .target_directory; + let mut wasm_path = PathBuf::from(&target_path) + .join("wasm32-unknown-unknown") + .join(release_or_debug) + .join(binary_name); + wasm_path.set_extension("wasm"); + let wasm_path = wasm_path.display().to_string(); + let dts_arg = if disable_dts { "--no-typescript" } else { diff --git a/tests/all/build.rs b/tests/all/build.rs index 69a9bab9..240a1a2f 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -20,3 +20,18 @@ fn build_in_non_crate_directory_doesnt_panic() { let err_msg = result.unwrap_err().to_string(); assert!(err_msg.contains("missing a `Cargo.toml`")); } + +#[test] +fn it_should_build_js_hello_world_example() { + let fixture = utils::fixture::js_hello_world(); + fixture.install_local_wasm_bindgen(); + let cli = Cli::from_iter_safe(vec![ + "wasm-pack", + "build", + &fixture.path.display().to_string(), + ]) + .unwrap(); + let logger = logger::new(&cli.cmd, cli.verbosity).unwrap(); + command::run_wasm_pack(cli.cmd, &logger) + .expect("running wasm-pack in a js-hello-world directory should succeed."); +}