Repository: drager/wasm-pack (Rust)

Issue:
don't rename the js file
Hello! I was following the tutorial for wasm-pack and got to this step: https://rust-lang-nursery.github.io/rust-wasm/wasm-pack/package-code.html

Compiling took a while and then printed this:

```
wasm-pack -v init --scope thallada
  [1/7] Adding WASM target...
  [2/7] Compiling to WASM...
  [3/7] Creating a pkg directory...
  [4/7] Writing a package.json...
| [5/7] Copying over your README...
| :-) [WARN]: origin crate has no README
  [6/7] Installing WASM-bindgen...
  [7/7] Running WASM-bindgen...
:-) Done in 1 minute
:-) Your WASM pkg is ready to publish at ./pkg
```

But, if I look at the `./pkg` directory, there's only a `package.json` file:

```
$ ls pkg/
package.json
```

Do you know what might have gone wrong?

```
$ npm --version
v9.11.1

$ npm --version
5.6.0

$ rustup show
Default host: x86_64-unknown-linux-gnu

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

asmjs-unknown-emscripten
wasm32-unknown-emscripten
wasm32-unknown-unknown
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.27.0-nightly (ac3c2288f 2018-04-18)
```


Discussion:
Same here, both Linux and Windows.
I installed  `wasm-bindgen` globally and then it worked. It seems that this step is missing in the tutorial: `cargo install wasm-bindgen-cli`.
Looking into the code it seems that `wasm-pack` should install `wasm-bindgen` and, indeed, it does but for some reason there's a mismatch in the versions (I guess [next version will fix this](https://github.com/ashleygwilliams/wasm-pack/pull/95/files#diff-71a1bad0102c7715b6b5e3b58595c7e2R17)).

It seems that this is a known issue: 

![image](https://user-images.githubusercontent.com/696981/39097169-285ed51a-4659-11e8-82b0-5e2c431e948f.png)

So just follow the previous instructions 😉 

@ashleygwilliams, I'm thinking that maybe it would be nice to leverage the `verbose` flag so we could get the `stdout` from the `wasm-bindgen` process.  I guess we could add this option [here](https://github.com/ashleygwilliams/wasm-pack/blob/master/src/bindgen.rs#L49) and we could also make this option explicit to the user at the end of any process so she can have a tool to directly use in case things didn't work as expected (as for instance happened to @thallada and myself).

EDIT: I can see that this is already planned in issue #50 
@robertohuertasm thanks for the tip. `cargo install -f wasm-bindgen-cli` fixed it for me.

I did use `wasm-pack`'s `-v` verbose flag, but that didn't print the error. So I think getting that to show the errors from `wasm-bindgen` would be really helpful.
hey all! sorry you ran into this trouble. so we have an 0.2.0 coming out, likely today that should fix this issue. we were definitely irresponsibly eating up stderr but that should be fixed! if you'd like to test it out before we release, you can run `cargo install --git https://github.com/ashleygwilliams/wasm-pack.git` to install this tool from master. we additionally plan on having some much nicer logs but what is currently on master should ideally solve this for you! do let me know and thanks for filing!
@ashleygwilliams , I did try a clean install directly from the github repo and it works as expected. 

Unfortunately, I think I've found another issue with the resulting `js` file being renamed to `index.js`. Whenever I try to test it I get this error:

![image](https://user-images.githubusercontent.com/696981/39146462-22199fc6-4737-11e8-8695-44a4c45f8671.png)

If I change the name of `index.js` to `wasm-test` and change the `main` entry in `package.json` accordingly then it all works flawlessly. 

I've not had time to look carefully into it but it seems that the associated `.wasm` file refers to the `js`file by its old name. Does it make any sense?

I'll take a look again later to see what I can find.
oh iiiiiiinteresting. thank you so much for trying this out @robertohuertasm and for providing such a good detailed report. i don't think that the wasm should be referring to the js at all but i'm gonna dive into that now and see what's up!
@robertohuertasm ok, i misspoke, the wasm aboslutely refers to the js and i cannot and should not rename it. i'll need to revert that! thanks for noting it!
@ashleygwilliams you're very welcome! I'm really glad to help. :wink: 
@robertohuertasm #105 should have fixed the issue for ya! :) hoping to cut a 0.2.0 release today! thanks again for all your help! let me know if you are interested in contributing at any point! we'd love to have you
@ashleygwilliams, it's awesome hearing about the 0.2.0 release! :grinning: 

I've taken a look at #105. I feel a little bit curious about this "circular" reference between the `js` and the `wasm` file. I had the intention to study a little bit the `wasm-bindgen` repo to gain some insight on this matter but maybe you can point me out to the proper resource. :wink: 

On the other hand, regarding my interest in contributing, I'd be really happy to provide my help or assistance. I really :hearts: what you guys are doing and I'm really interested in learning more about `rust` and `wasm`.





Patch:
diff --git a/src/bindgen.rs b/src/bindgen.rs
index 3b587b1d..a640c0e3 100644
--- a/src/bindgen.rs
+++ b/src/bindgen.rs
@@ -1,7 +1,6 @@
 use console::style;
 use emoji;
 use failure::Error;
-use std::fs;
 use std::process::Command;
 use PBAR;
 
@@ -51,9 +50,6 @@ pub fn wasm_bindgen_build(path: &str, name: &str) -> Result<(), Error> {
         PBAR.error("wasm-bindgen failed to execute properly");
         bail!(format!("Details:\n{}", s));
     } else {
-        let js_file = format!("{}/pkg/{}.js", path, binary_name);
-        let index_file = format!("{}/pkg/index.js", path);
-        fs::rename(&js_file, &index_file)?;
         Ok(())
     }
 }
diff --git a/src/manifest.rs b/src/manifest.rs
index 9f604350..9ea770fa 100644
--- a/src/manifest.rs
+++ b/src/manifest.rs
@@ -55,6 +55,7 @@ impl CargoManifest {
     fn into_npm(mut self, scope: Option<String>) -> NpmPackage {
         let filename = self.package.name.replace("-", "_");
         let wasm_file = format!("{}_bg.wasm", filename);
+        let js_file = format!("{}.js", filename);
         if let Some(s) = scope {
             self.package.name = format!("@{}/{}", s, self.package.name);
         }
@@ -69,7 +70,7 @@ impl CargoManifest {
                 url: repo_url,
             }),
             files: vec![wasm_file],
-            main: "index.js".to_string(),
+            main: js_file,
         }
     }
 }


Test patch:
diff --git a/tests/manifest/main.rs b/tests/manifest/main.rs
index 6b4ca9e3..813087d6 100644
--- a/tests/manifest/main.rs
+++ b/tests/manifest/main.rs
@@ -41,7 +41,7 @@ fn it_creates_a_package_json_default_path() {
         "https://github.com/ashleygwilliams/wasm-pack.git"
     );
     assert_eq!(pkg.files, ["wasm_pack_bg.wasm"]);
-    assert_eq!(pkg.main, "index.js");
+    assert_eq!(pkg.main, "wasm_pack.js");
 }
 
 #[test]