Merge branch 'master' into non-rustup-env

master
ashley williams 6 years ago committed by GitHub
commit 6a666fa295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 71
      Cargo.lock
  2. 3
      Cargo.toml
  3. 2
      README.md
  4. 4
      docs/src/SUMMARY.md
  5. 1
      docs/src/command/pack-and-publish.md
  6. 21
      docs/src/prerequisites/index.md
  7. 35
      docs/src/prerequisites/rust.md
  8. 10
      src/bindgen.rs
  9. 8
      src/build.rs
  10. 174
      src/child.rs
  11. 52
      src/command/build.rs
  12. 2
      src/command/login.rs
  13. 2
      src/command/pack.rs
  14. 2
      src/command/publish/mod.rs
  15. 52
      src/command/test.rs
  16. 19
      src/command/utils.rs
  17. 11
      src/lib.rs
  18. 9
      src/license.rs
  19. 10
      src/manifest/mod.rs
  20. 118
      src/progressbar.rs
  21. 12
      src/readme.rs
  22. 32
      src/test/webdriver.rs
  23. 15
      tests/all/license.rs
  24. 78
      tests/all/manifest.rs
  25. 6
      tests/all/readme.rs
  26. 6
      tests/all/test.rs

71
Cargo.lock generated

@ -89,7 +89,7 @@ name = "binary-install"
version = "0.0.1"
dependencies = [
"curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -194,7 +194,7 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -214,7 +214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"clicolors-control 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -231,7 +231,7 @@ dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -296,7 +296,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -307,11 +307,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dirs"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -457,17 +457,6 @@ dependencies = [
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "indicatif"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "is_executable"
version = "0.1.2"
@ -497,7 +486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.2.0"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -599,7 +588,7 @@ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -896,27 +885,15 @@ dependencies = [
[[package]]
name = "redox_users"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.1.0"
@ -929,14 +906,6 @@ dependencies = [
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.5"
@ -984,7 +953,7 @@ name = "schannel"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1217,7 +1186,7 @@ name = "thread_local"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1308,13 +1277,12 @@ dependencies = [
"console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
"dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.10.18 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1448,7 +1416,7 @@ dependencies = [
"checksum curl-sys 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ca79238a79fb294be6173b4057c95b22a718c94c4e38475d5faa82b8383f3502"
"checksum dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad1c29a0368928e78c551354dbff79f103a962ad820519724ef0d74f1c62fa9"
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
"checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a"
"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd"
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
@ -1466,12 +1434,11 @@ dependencies = [
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
"checksum human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21638c5955a6daf3ecc42cae702335fc37a72a4abcc6959ce457b31a7d43bbdd"
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
"checksum indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a29b2fa6f00010c268bface64c18bb0310aaa70d46a195d5382d288c477fb016"
"checksum is_executable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e"
"checksum libflate 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "54d1ddf9c52870243c5689d7638d888331c1116aa5b398f3ba1acfa7d8758ca1"
"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe"
@ -1518,10 +1485,8 @@ dependencies = [
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "214a97e49be64fd2c86f568dd0cb2c757d2cc53de95b273b6ad0a1c908482f26"
"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384"
"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828"
"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f"
"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7"
"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"

@ -20,8 +20,6 @@ env_logger = { version = "0.5.13", default-features = false }
failure = "0.1.2"
human-panic = "1.0.1"
glob = "0.2"
indicatif = "0.9.0"
lazy_static = "1.1.0"
log = "0.4.6"
openssl = { version = '0.10.11', optional = true }
parking_lot = "0.6"
@ -39,6 +37,7 @@ walkdir = "2"
[dev-dependencies]
assert_cmd = "0.10.2"
lazy_static = "1.1.0"
predicates = "1.0.0"
tempfile = "3"

@ -32,8 +32,8 @@ This project requires Rust 1.30.0 or later.
## 🎙 Commands
- [`init` (⚠ DEPRECATED)](https://rustwasm.github.io/wasm-pack/book/commands/init.html): This command has been deprecated since release `0.5.0`, in favor of `build`. `0.4.2` and previous use this command.
- [`build`](https://rustwasm.github.io/wasm-pack/book/commands/build.html): Generate an npm wasm pkg from a rustwasm crate
- [`test`](https://rustwasm.github.io/wasm-pack/book/commands/test.html): Run browser tests
- [`pack` and `publish`](https://rustwasm.github.io/wasm-pack/book/commands/pack-and-publish.html): Create a tarball of your rustwasm pkg and/or publish to a registry
## 📝 Logging

@ -1,14 +1,14 @@
# Summary
- [Prerequisites](./prerequisites/index.md)
- [Rust](./prerequisites/rust.md)
- [npm](./prerequisites/npm.md)
- [npm (optional)](./prerequisites/npm.md)
- [Project Setup](./project-setup/index.md)
- [Using a Template](./project-setup/using-a-template.md)
- [Manual Setup](./project-setup/manual-setup.md)
- [Commands](./commands/index.md)
- [`init` (DEPRECATED)](./commands/init.md)
- [`build`](./commands/build.md)
- [`test`](./commands/test.md)
- [`pack` and `publish`](./commands/pack-and-publish.md)
- [Tutorial](./tutorial/index.md)
- [Getting Started](./tutorial/getting-started.md)

@ -1,10 +1,19 @@
# Prerequisites
To run `wasm-pack` you'll need to have both Rust and npm installed and configured.
First you'll want to [install the `wasm-pack` CLI][wasm-pack], and `wasm-pack
-V` should print the version that you just installed.
- [Rust](/wasm-pack/book/prerequisites/rust.html)
- [npm](/wasm-pack/book/prerequisites/npm.html)
[wasm-pack]: https://rustwasm.github.io/wasm-pack/installer/
In the future, we intend to rewrite the npm registry client bits so that the need
for a Node runtime is eliminated. If you're excited about that work- you should
reach out to the maintainers and get involved!
Next, since `wasm-pack` is a build tool, you'll want to make sure you have
[Rust][rust] installed. Make sure `rustc -V` prints out at least 1.30.0.
[rust]: https://www.rust-lang.org/tools/install
Finally, if you're using `wasm-pack` to install to publish to NPM, you'll want
to [install and configure `npm`][npm]. In the future, we intend to rewrite the
npm registry client bits so that the need for a Node runtime is eliminated. If
you're excited about that work- you should reach out to the maintainers and get
involved!
[npm]: npm.html

@ -1,35 +0,0 @@
# Rust
`wasm-pack` is a Command Line Interface tool written in Rust, and distributed with `cargo`.
As a result, you'll need Rust and `cargo` to use `wasm-pack`.
### Installing Rust and Cargo
To install Rust, visit this [page](https://www.rust-lang.org/en-US/install.html), which will
walk you through installing Rust and `cargo` on your machine using a tool called `rustup`.
To confirm you have Rust and `cargo` installed, run:
```
rustc --version
cargo --version
```
### Rust Versions
`wasm-pack` depends on a library called `wasm-bindgen`. `wasm-bindgen` requires that you use
Rust 1.30.0 or higher. This version is currently only available on the `nightly` or `beta`
channels.
To get the correct version of Rust, you'll use `rustup` a Rust version manager that comes
bundled with Rust. Run this command to install the latest Rust on the `beta` channel:
```
rustup install beta
```
You can set your project directory to always use this version of Rust by running:
```
rustup override set beta
```

@ -8,7 +8,6 @@ use failure::{self, ResultExt};
use log::debug;
use log::{info, warn};
use manifest::CrateData;
use progressbar::Step;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
@ -27,7 +26,6 @@ pub fn install_wasm_bindgen(
cache: &Cache,
version: &str,
install_permitted: bool,
step: &Step,
) -> Result<Download, failure::Error> {
// If `wasm-bindgen` is installed globally and it has the right version, use
// that. Assume that other tools are installed next to it.
@ -42,7 +40,7 @@ pub fn install_wasm_bindgen(
}
let msg = format!("{}Installing wasm-bindgen...", emoji::DOWN_ARROW);
PBAR.step(step, &msg);
PBAR.info(&msg);
let dl = download_prebuilt_wasm_bindgen(&cache, version, install_permitted);
match dl {
@ -178,11 +176,7 @@ pub fn wasm_bindgen_build(
disable_dts: bool,
target: &Target,
profile: BuildProfile,
step: &Step,
) -> Result<(), failure::Error> {
let msg = format!("{}Running wasm-bindgen...", emoji::RUNNER);
PBAR.step(step, &msg);
let release_or_debug = match profile {
BuildProfile::Release | BuildProfile::Profiling => "release",
BuildProfile::Dev => "debug",
@ -235,7 +229,7 @@ pub fn wasm_bindgen_build(
fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool {
let mut cmd = Command::new(bindgen_path);
cmd.arg("--version");
child::run(cmd, "wasm-bindgen")
child::run_capture_stdout(cmd, "wasm-bindgen")
.map(|stdout| {
stdout
.trim()

@ -5,16 +5,13 @@ use command::build::BuildProfile;
use emoji;
use failure::{Error, ResultExt};
use log::info;
use progressbar::Step;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;
use PBAR;
/// Ensure that `rustc` is present and that it is >= 1.30.0
pub fn check_rustc_version(step: &Step) -> Result<String, Error> {
let msg = format!("{}Checking `rustc` version...", emoji::CRAB);
PBAR.step(step, &msg);
pub fn check_rustc_version() -> Result<String, Error> {
let local_minor_version = rustc_minor_version();
match local_minor_version {
Some(mv) => {
@ -128,11 +125,10 @@ pub fn check_for_wasm32_target(step: &Step) -> Result<(), Error> {
pub fn cargo_build_wasm(
path: &Path,
profile: BuildProfile,
step: &Step,
extra_options: &Vec<String>,
) -> Result<(), Error> {
let msg = format!("{}Compiling to Wasm...", emoji::CYCLONE);
PBAR.step(step, &msg);
PBAR.info(&msg);
let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build").arg("--lib");
match profile {

@ -5,21 +5,7 @@
use failure::Error;
use log::info;
use std::{
io::{self, Read},
mem,
process::{Command, Stdio},
string,
sync::mpsc,
thread,
};
use PBAR;
#[derive(Debug)]
enum OutputFragment {
Stdout(Vec<u8>),
Stderr(Vec<u8>),
}
use std::process::{Command, Stdio};
/// Return a new Command object
pub fn new_command(program: &str) -> Command {
@ -37,151 +23,39 @@ pub fn new_command(program: &str) -> Command {
}
}
/// Read data from the give reader and send it as an `OutputFragment` over the
/// given sender.
fn read_and_send<R, F>(
mut reader: R,
sender: &mpsc::Sender<OutputFragment>,
mut map: F,
) -> io::Result<()>
where
R: Read,
F: FnMut(Vec<u8>) -> OutputFragment,
{
let mut buf = vec![0; 1024];
loop {
match reader.read(&mut buf) {
Err(e) => {
if e.kind() == io::ErrorKind::Interrupted {
continue;
} else {
return Err(e);
}
}
Ok(0) => return Ok(()),
Ok(n) => {
buf.truncate(n);
let buf = mem::replace(&mut buf, vec![0; 1024]);
sender.send(map(buf)).unwrap();
}
}
}
}
/// Accumulates output from a stream of output fragments and calls a callback on
/// each complete line as it is accumulating.
struct OutputAccumulator<F> {
result: String,
in_progress: Vec<u8>,
on_each_line: F,
}
impl<F> OutputAccumulator<F>
where
F: FnMut(&str),
{
/// Construct a new output accumulator with the given `on_each_line`
/// callback.
fn new(on_each_line: F) -> OutputAccumulator<F> {
OutputAccumulator {
result: String::new(),
in_progress: Vec::new(),
on_each_line,
}
}
/// Add another fragment of output to the accumulation, calling the
/// `on_each_line` callback for any complete lines we accumulate.
fn push(&mut self, fragment: Vec<u8>) -> Result<(), string::FromUtf8Error> {
debug_assert!(!fragment.is_empty());
self.in_progress.extend(fragment);
/// Run the given command and return its stdout.
pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> {
info!("Running {:?}", command);
if let Some((last_newline, _)) = self
.in_progress
.iter()
.cloned()
.enumerate()
.rev()
.find(|(_, ch)| *ch == b'\n')
{
let next_in_progress: Vec<u8> = self.in_progress[last_newline + 1..].to_vec();
let mut these_lines = mem::replace(&mut self.in_progress, next_in_progress);
these_lines.truncate(last_newline + 1);
let these_lines = String::from_utf8(these_lines)?;
for line in these_lines.lines() {
(self.on_each_line)(line);
}
self.result.push_str(&these_lines);
}
let status = command.status()?;
if status.success() {
Ok(())
}
/// Finish accumulation, run the `on_each_line` callback on the final line
/// (if any), and return the accumulated output.
fn finish(mut self) -> Result<String, string::FromUtf8Error> {
if !self.in_progress.is_empty() {
let last_line = String::from_utf8(self.in_progress)?;
(self.on_each_line)(&last_line);
self.result.push_str(&last_line);
}
Ok(self.result)
} else {
bail!(
"failed to execute `{}`: exited with {}",
command_name,
status
)
}
}
/// Run the given command and return its stdout.
pub fn run(mut command: Command, command_name: &str) -> Result<String, Error> {
pub fn run_capture_stdout(mut command: Command, command_name: &str) -> Result<String, Error> {
info!("Running {:?}", command);
let mut child = command
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
let stdout = child.stdout.take().unwrap();
let stderr = child.stderr.take().unwrap();
let (send, recv) = mpsc::channel();
let stdout_send = send.clone();
let stderr_send = send;
// Because pipes have a fixed-size buffer, we need to keep reading stdout
// and stderr on a separate thread to avoid potential dead locks with
// waiting on the child process.
let stdout_handle =
thread::spawn(move || read_and_send(stdout, &stdout_send, OutputFragment::Stdout));
let stderr_handle =
thread::spawn(move || read_and_send(stderr, &stderr_send, OutputFragment::Stderr));
let mut stdout = OutputAccumulator::new(|line| {
info!("{} (stdout): {}", command_name, line);
PBAR.message(line)
});
let mut stderr = OutputAccumulator::new(|line| {
info!("{} (stderr): {}", command_name, line);
PBAR.message(line)
});
for output in recv {
match output {
OutputFragment::Stdout(line) => stdout.push(line)?,
OutputFragment::Stderr(line) => stderr.push(line)?,
};
}
let stdout = stdout.finish()?;
let stderr = stderr.finish()?;
// Join the threads reading the child's output to make sure the finish OK.
stdout_handle.join().unwrap()?;
stderr_handle.join().unwrap()?;
let output = command
.stderr(Stdio::inherit())
.stdin(Stdio::inherit())
.output()?;
let exit = child.wait()?;
if exit.success() {
Ok(stdout)
if output.status.success() {
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
} else {
drop((stdout, stderr));
bail!("failed to execute `{}`: exited with {}", command_name, exit)
bail!(
"failed to execute `{}`: exited with {}",
command_name,
output.status
)
}
}

@ -7,12 +7,10 @@ use cache;
use command::utils::{create_pkg_dir, set_crate_path};
use emoji;
use failure::Error;
use indicatif::HumanDuration;
use license;
use lockfile::Lockfile;
use log::info;
use manifest;
use progressbar::Step;
use readme;
use std::path::PathBuf;
use std::str::FromStr;
@ -184,7 +182,7 @@ impl Default for BuildOptions {
}
}
type BuildStep = fn(&mut Build, &Step) -> Result<(), Error>;
type BuildStep = fn(&mut Build) -> Result<(), Error>;
impl Build {
/// Construct a build command from the given options.
@ -227,25 +225,22 @@ impl Build {
pub fn run(&mut self) -> Result<(), Error> {
let process_steps = Build::get_process_steps(self.mode);
let mut step_counter = Step::new(process_steps.len());
let started = Instant::now();
for (_, process_step) in process_steps {
process_step(self, &step_counter)?;
step_counter.inc();
process_step(self)?;
}
let duration = HumanDuration(started.elapsed());
let duration = crate::command::utils::elapsed(started.elapsed());
info!("Done in {}.", &duration);
info!(
"Your wasm pkg is ready to publish at {}.",
self.out_dir.display()
);
PBAR.message(&format!("{} Done in {}", emoji::SPARKLE, &duration));
PBAR.info(&format!("{} Done in {}", emoji::SPARKLE, &duration));
PBAR.message(&format!(
PBAR.info(&format!(
"{} Your wasm pkg is ready to publish at {}.",
emoji::PACKAGE,
self.out_dir.display()
@ -298,31 +293,31 @@ impl Build {
}
}
fn step_check_rustc_version(&mut self, step: &Step) -> Result<(), Error> {
fn step_check_rustc_version(&mut self) -> Result<(), Error> {
info!("Checking rustc version...");
let version = build::check_rustc_version(step)?;
let version = build::check_rustc_version()?;
let msg = format!("rustc version is {}.", version);
info!("{}", &msg);
Ok(())
}
fn step_check_crate_config(&mut self, step: &Step) -> Result<(), Error> {
fn step_check_crate_config(&mut self) -> Result<(), Error> {
info!("Checking crate configuration...");
self.crate_data.check_crate_config(step)?;
self.crate_data.check_crate_config()?;
info!("Crate is correctly configured.");
Ok(())
}
fn step_check_for_wasm_target(&mut self, step: &Step) -> Result<(), Error> {
fn step_check_for_wasm_target(&mut self) -> Result<(), Error> {
info!("Checking for wasm-target...");
build::check_for_wasm32_target(step)?;
info!("Checking for wasm-target was successful.");
Ok(())
}
fn step_build_wasm(&mut self, step: &Step) -> Result<(), Error> {
fn step_build_wasm(&mut self) -> Result<(), Error> {
info!("Building wasm...");
build::cargo_build_wasm(&self.crate_path, self.profile, step, &self.extra_options)?;
build::cargo_build_wasm(&self.crate_path, self.profile, &self.extra_options)?;
info!(
"wasm built at {:#?}.",
@ -335,21 +330,19 @@ impl Build {
Ok(())
}
fn step_create_dir(&mut self, step: &Step) -> Result<(), Error> {
fn step_create_dir(&mut self) -> Result<(), Error> {
info!("Creating a pkg directory...");
create_pkg_dir(&self.out_dir, step)?;
create_pkg_dir(&self.out_dir)?;
info!("Created a pkg directory at {:#?}.", &self.crate_path);
Ok(())
}
fn step_create_json(&mut self, step: &Step) -> Result<(), Error> {
info!("Writing a package.json...");
fn step_create_json(&mut self) -> Result<(), Error> {
self.crate_data.write_package_json(
&self.out_dir,
&self.scope,
self.disable_dts,
&self.target,
step,
)?;
info!(
"Wrote a package.json at {:#?}.",
@ -358,21 +351,21 @@ impl Build {
Ok(())
}
fn step_copy_readme(&mut self, step: &Step) -> Result<(), Error> {
fn step_copy_readme(&mut self) -> Result<(), Error> {
info!("Copying readme from crate...");
readme::copy_from_crate(&self.crate_path, &self.out_dir, step)?;
readme::copy_from_crate(&self.crate_path, &self.out_dir)?;
info!("Copied readme from crate to {:#?}.", &self.out_dir);
Ok(())
}
fn step_copy_license(&mut self, step: &Step) -> Result<(), failure::Error> {
fn step_copy_license(&mut self) -> Result<(), failure::Error> {
info!("Copying license from crate...");
license::copy_from_crate(&self.crate_data, &self.crate_path, &self.out_dir, step)?;
license::copy_from_crate(&self.crate_data, &self.crate_path, &self.out_dir)?;
info!("Copied license from crate to {:#?}.", &self.out_dir);
Ok(())
}
fn step_install_wasm_bindgen(&mut self, step: &Step) -> Result<(), failure::Error> {
fn step_install_wasm_bindgen(&mut self) -> Result<(), failure::Error> {
info!("Identifying wasm-bindgen dependency...");
let lockfile = Lockfile::new(&self.crate_data)?;
let bindgen_version = lockfile.require_wasm_bindgen()?;
@ -383,13 +376,13 @@ impl Build {
BuildMode::Noinstall => false,
};
let bindgen =
bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted, step)?;
bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted)?;
self.bindgen = Some(bindgen);
info!("Installing wasm-bindgen-cli was successful.");
Ok(())
}
fn step_run_wasm_bindgen(&mut self, step: &Step) -> Result<(), Error> {
fn step_run_wasm_bindgen(&mut self) -> Result<(), Error> {
info!("Building the wasm bindings...");
bindgen::wasm_bindgen_build(
&self.crate_data,
@ -398,7 +391,6 @@ impl Build {
self.disable_dts,
&self.target,
self.profile,
step,
)?;
info!("wasm bindings were built at {:#?}.", &self.out_dir);
Ok(())

@ -20,6 +20,6 @@ pub fn login(
npm::npm_login(&registry, &scope, always_auth, &auth_type)?;
info!("Logged you in!");
PBAR.message(&"👋 logged you in!".to_string());
PBAR.info(&"👋 logged you in!".to_string());
Ok(())
}

@ -22,6 +22,6 @@ pub fn pack(path: Option<PathBuf>) -> result::Result<(), Error> {
npm::npm_pack(&pkg_directory.to_string_lossy())?;
info!("Your package is located at {:#?}", crate_path.join("pkg"));
PBAR.message("🎒 packed up your package!");
PBAR.info("🎒 packed up your package!");
Ok(())
}

@ -77,6 +77,6 @@ pub fn publish(
npm::npm_publish(&pkg_directory.to_string_lossy(), access)?;
info!("Published your package!");
PBAR.message("💥 published your package!");
PBAR.info("💥 published your package!");
Ok(())
}

@ -7,17 +7,13 @@ use build;
use cache;
use command::utils::set_crate_path;
use console::style;
use emoji;
use failure::Error;
use indicatif::HumanDuration;
use lockfile::Lockfile;
use log::info;
use manifest;
use progressbar::Step;
use std::path::PathBuf;
use std::time::Instant;
use test::{self, webdriver};
use PBAR;
#[derive(Debug, Default, StructOpt)]
/// Everything required to configure the `wasm-pack test` command.
@ -103,7 +99,7 @@ pub struct Test {
extra_options: Vec<String>,
}
type TestStep = fn(&mut Test, &Step) -> Result<(), Error>;
type TestStep = fn(&mut Test) -> Result<(), Error>;
impl Test {
/// Construct a test command from the given options.
@ -165,14 +161,12 @@ impl Test {
/// Execute this test command.
pub fn run(mut self) -> Result<(), Error> {
let process_steps = self.get_process_steps();
let mut step_counter = Step::new(process_steps.len());
let started = Instant::now();
for (_, process_step) in process_steps {
process_step(&mut self, &step_counter)?;
step_counter.inc();
process_step(&mut self)?;
}
let duration = HumanDuration(started.elapsed());
let duration = crate::command::utils::elapsed(started.elapsed());
info!("Done in {}.", &duration);
Ok(())
@ -233,33 +227,30 @@ impl Test {
}
}
fn step_check_rustc_version(&mut self, step: &Step) -> Result<(), Error> {
fn step_check_rustc_version(&mut self) -> Result<(), Error> {
info!("Checking rustc version...");
let _ = build::check_rustc_version(step)?;
let _ = build::check_rustc_version()?;
info!("Rustc version is correct.");
Ok(())
}
fn step_check_for_wasm_target(&mut self, step: &Step) -> Result<(), Error> {
fn step_check_for_wasm_target(&mut self) -> Result<(), Error> {
info!("Adding wasm-target...");
build::check_for_wasm32_target(step)?;
info!("Adding wasm-target was successful.");
Ok(())
}
fn step_build_tests(&mut self, step: &Step) -> Result<(), Error> {
fn step_build_tests(&mut self) -> Result<(), Error> {
info!("Compiling tests to wasm...");
let msg = format!("{}Compiling tests to Wasm...", emoji::CYCLONE);
PBAR.step(step, &msg);
build::cargo_build_wasm_tests(&self.crate_path, !self.release)?;
info!("Finished compiling tests to wasm.");
Ok(())
}
fn step_install_wasm_bindgen(&mut self, step: &Step) -> Result<(), Error> {
fn step_install_wasm_bindgen(&mut self) -> Result<(), Error> {
info!("Identifying wasm-bindgen dependency...");
let lockfile = Lockfile::new(&self.crate_data)?;
let bindgen_version = lockfile.require_wasm_bindgen()?;
@ -293,8 +284,7 @@ impl Test {
}
};
let dl =
bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted, step)?;
let dl = bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted)?;
self.test_runner_path = Some(dl.binary("wasm-bindgen-test-runner")?);
@ -302,10 +292,9 @@ impl Test {
Ok(())
}
fn step_test_node(&mut self, step: &Step) -> Result<(), Error> {
fn step_test_node(&mut self) -> Result<(), Error> {
assert!(self.node);
info!("Running tests in node...");
PBAR.step(step, "Running tests in node...");
test::cargo_test_wasm(
&self.crate_path,
self.release,
@ -319,8 +308,7 @@ impl Test {
Ok(())
}
fn step_get_chromedriver(&mut self, step: &Step) -> Result<(), Error> {
PBAR.step(step, "Getting chromedriver...");
fn step_get_chromedriver(&mut self) -> Result<(), Error> {
assert!(self.chrome && self.chromedriver.is_none());
self.chromedriver = Some(webdriver::get_or_install_chromedriver(
@ -330,9 +318,7 @@ impl Test {
Ok(())
}
fn step_test_chrome(&mut self, step: &Step) -> Result<(), Error> {
PBAR.step(step, "Running tests in Chrome...");
fn step_test_chrome(&mut self) -> Result<(), Error> {
let chromedriver = self.chromedriver.as_ref().unwrap().display().to_string();
let chromedriver = chromedriver.as_str();
info!(
@ -361,8 +347,7 @@ impl Test {
Ok(())
}
fn step_get_geckodriver(&mut self, step: &Step) -> Result<(), Error> {
PBAR.step(step, "Getting geckodriver...");
fn step_get_geckodriver(&mut self) -> Result<(), Error> {
assert!(self.firefox && self.geckodriver.is_none());
self.geckodriver = Some(webdriver::get_or_install_geckodriver(
@ -372,9 +357,7 @@ impl Test {
Ok(())
}
fn step_test_firefox(&mut self, step: &Step) -> Result<(), Error> {
PBAR.step(step, "Running tests in Firefox...");
fn step_test_firefox(&mut self) -> Result<(), Error> {
let geckodriver = self.geckodriver.as_ref().unwrap().display().to_string();
let geckodriver = geckodriver.as_str();
info!(
@ -403,17 +386,14 @@ impl Test {
Ok(())
}
fn step_get_safaridriver(&mut self, step: &Step) -> Result<(), Error> {
PBAR.step(step, "Getting safaridriver...");
fn step_get_safaridriver(&mut self) -> Result<(), Error> {
assert!(self.safari && self.safaridriver.is_none());
self.safaridriver = Some(webdriver::get_safaridriver()?);
Ok(())
}
fn step_test_safari(&mut self, step: &Step) -> Result<(), Error> {
PBAR.step(step, "Running tests in Safari...");
fn step_test_safari(&mut self) -> Result<(), Error> {
let safaridriver = self.safaridriver.as_ref().unwrap().display().to_string();
let safaridriver = safaridriver.as_str();
info!(

@ -1,12 +1,10 @@
//! Utility functions for commands.
use emoji;
use failure;
use progressbar::Step;
use std::fs;
use std::path::{Path, PathBuf};
use std::time::Duration;
use walkdir::WalkDir;
use PBAR;
/// If an explicit path is given, then use it, otherwise assume the current
/// directory is the crate path.
@ -15,9 +13,7 @@ pub fn set_crate_path(path: Option<PathBuf>) -> Result<PathBuf, failure::Error>
}
/// Construct our `pkg` directory in the crate.
pub fn create_pkg_dir(out_dir: &Path, step: &Step) -> Result<(), failure::Error> {
let msg = format!("{}Creating a pkg directory...", emoji::FOLDER);
PBAR.step(step, &msg);
pub fn create_pkg_dir(out_dir: &Path) -> Result<(), failure::Error> {
fs::create_dir_all(&out_dir)?;
fs::write(out_dir.join(".gitignore"), "*")?;
Ok(())
@ -39,3 +35,14 @@ pub fn find_pkg_directory(path: &Path) -> Option<PathBuf> {
fn is_pkg_directory(path: &Path) -> bool {
path.exists() && path.is_dir() && path.ends_with("pkg")
}
/// Render a `Duration` to a form suitable for display on a console
pub fn elapsed(duration: Duration) -> String {
let secs = duration.as_secs();
if secs >= 60 {
format!("{}m {:02}s", secs / 60, secs % 60)
} else {
format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000)
}
}

@ -8,12 +8,9 @@ extern crate strsim;
#[macro_use]
extern crate failure;
extern crate glob;
extern crate indicatif;
extern crate which;
#[macro_use]
extern crate lazy_static;
extern crate parking_lot;
extern crate serde;
extern crate which;
#[macro_use]
extern crate serde_derive;
extern crate serde_ignored;
@ -43,10 +40,8 @@ pub mod test;
use progressbar::ProgressOutput;
lazy_static! {
/// The global progress bar and user-facing message output.
pub static ref PBAR: ProgressOutput = { ProgressOutput::new() };
}
/// The global progress bar and user-facing message output.
pub static PBAR: ProgressOutput = ProgressOutput;
/// 📦 ✨ pack and publish your wasm!
#[derive(Debug, StructOpt)]

@ -4,10 +4,8 @@ use failure;
use std::fs;
use std::path::Path;
use emoji;
use glob::glob;
use manifest::CrateData;
use progressbar::Step;
use PBAR;
fn glob_license_files(path: &Path) -> Result<Vec<String>, failure::Error> {
@ -45,7 +43,6 @@ pub fn copy_from_crate(
crate_data: &CrateData,
path: &Path,
out_dir: &Path,
step: &Step,
) -> Result<(), failure::Error> {
assert!(
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
@ -59,8 +56,6 @@ pub fn copy_from_crate(
match (crate_data.crate_license(), crate_data.crate_license_file()) {
(Some(_), _) => {
let msg = format!("{}Copying over your LICENSE...", emoji::DANCERS);
PBAR.step(step, &msg);
let license_files = glob_license_files(path);
match license_files {
@ -87,9 +82,7 @@ pub fn copy_from_crate(
PBAR.info("origin crate has no LICENSE");
}
}
(None, None) => {
PBAR.step(step, "No LICENSE found in Cargo.toml, skipping...");
}
(None, None) => {}
};
Ok(())

@ -12,9 +12,7 @@ use self::npm::{
};
use cargo_metadata::Metadata;
use command::build::{BuildProfile, Target};
use emoji;
use failure::{Error, ResultExt};
use progressbar::Step;
use serde::{self, Deserialize};
use serde_json;
use std::collections::BTreeSet;
@ -312,9 +310,7 @@ impl CrateData {
}
/// Check that the crate the given path is properly configured.
pub fn check_crate_config(&self, step: &Step) -> Result<(), Error> {
let msg = format!("{}Checking crate configuration...", emoji::WRENCH);
PBAR.step(&step, &msg);
pub fn check_crate_config(&self) -> Result<(), Error> {
self.check_crate_type()?;
Ok(())
}
@ -378,11 +374,7 @@ impl CrateData {
scope: &Option<String>,
disable_dts: bool,
target: &Target,
step: &Step,
) -> Result<(), Error> {
let msg = format!("{}Writing a package.json...", emoji::MEMO);
PBAR.step(step, &msg);
let pkg_file_path = out_dir.join("package.json");
let npm_data = match target {
Target::Nodejs => self.to_commonjs(scope, disable_dts, out_dir),

@ -2,72 +2,20 @@
use console::style;
use emoji;
use indicatif::{ProgressBar, ProgressStyle};
use parking_lot::RwLock;
use std::fmt;
/// Synchronized progress bar and status message printing.
pub struct ProgressOutput {
spinner: RwLock<ProgressBar>,
messages: RwLock<String>,
}
pub struct ProgressOutput;
impl ProgressOutput {
/// Construct a new `ProgressOutput`.
pub fn new() -> Self {
Self {
spinner: RwLock::new(ProgressBar::new_spinner()),
messages: RwLock::new(String::from("")),
}
}
/// Inform the user that the given `step` is being executed, with details in
/// `message`.
pub fn step(&self, step: &Step, message: &str) {
let msg = format!("{} {}", style(step).bold().dim(), message);
self.message(&msg)
}
fn finish(&self) {
let spinner = self.spinner.read();
spinner.finish();
let mut message = self.messages.write();
print!("{}", *message);
message.clear();
}
/// Print the given message.
pub fn message(&self, message: &str) {
self.finish();
let mut spinner = self.spinner.write();
*spinner = Self::progressbar(message);
if !atty::is(atty::Stream::Stderr) {
// `indicatif` won't print any output if `stderr` is not a tty, so
// to ensure that our output is still emitted, we print it manually
// here.
eprintln!("{}", message)
}
}
fn add_message(&self, msg: &str) {
let mut message = self.messages.write();
message.push_str(" ");
message.push_str(msg);
message.push('\n');
fn message(&self, message: &str) {
eprintln!("{}", message);
}
/// Add an informational message.
pub fn info(&self, message: &str) {
let info = format!(
"{} {}: {}",
emoji::INFO,
style("[INFO]").bold().dim(),
message
);
self.add_message(&info);
let info = format!("{}: {}", style("[INFO]").bold().dim(), message,);
self.message(&info);
}
/// Add a warning message.
@ -78,7 +26,7 @@ impl ProgressOutput {
style("[WARN]").bold().dim(),
message
);
self.add_message(&warn);
self.message(&warn);
}
/// Add an error message.
@ -89,62 +37,12 @@ impl ProgressOutput {
style("[ERR]").bold().dim(),
message
);
self.add_message(&err);
}
fn progressbar(msg: &str) -> ProgressBar {
let pb = ProgressBar::new_spinner();
pb.enable_steady_tick(200);
pb.set_style(
ProgressStyle::default_spinner()
.tick_chars("/|\\- ")
.template("{spinner:.dim.bold} {wide_msg}"),
);
pb.set_message(&msg);
pb
}
/// After having built up a series of messages, print all of them out.
pub fn done(&self) {
self.finish();
}
}
/// For processes that can be broken down into N fractional steps, with messages
/// added for each step along the way like
///
/// > [2/5] Doing the second step out of five.
pub struct Step {
current: usize,
total: usize,
}
impl Step {
/// Construct a `Step` where there are `total` number of steps.
pub fn new(total: usize) -> Step {
Step { current: 1, total }
}
/// Increment the current step.
pub fn inc(&mut self) {
self.current += 1;
}
}
impl fmt::Display for Step {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}/{}]", self.current, self.total)
}
}
impl Drop for ProgressOutput {
fn drop(&mut self) {
self.done();
self.message(&err);
}
}
impl Default for ProgressOutput {
fn default() -> Self {
Self::new()
ProgressOutput
}
}

@ -1,15 +1,13 @@
//! Generating `README` files for the packaged wasm.
use failure;
use failure::{self, ResultExt};
use std::fs;
use std::path::Path;
use emoji;
use progressbar::Step;
use PBAR;
/// Copy the crate's README into the `pkg` directory.
pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), failure::Error> {
pub fn copy_from_crate(path: &Path, out_dir: &Path) -> Result<(), failure::Error> {
assert!(
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
"crate directory should exist"
@ -19,11 +17,11 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), f
"crate's pkg directory should exist"
);
let msg = format!("{}Copying over your README...", emoji::DANCERS);
PBAR.step(step, &msg);
let crate_readme_path = path.join("README.md");
let new_readme_path = out_dir.join("README.md");
if fs::copy(&crate_readme_path, &new_readme_path).is_err() {
if crate_readme_path.exists() {
fs::copy(&crate_readme_path, &new_readme_path).context("failed to copy README")?;
} else {
PBAR.warn("origin crate has no README");
}
Ok(())

@ -5,6 +5,25 @@ use command::build::BuildMode;
use failure;
use std::path::PathBuf;
use target;
use PBAR;
fn get_and_notify(
cache: &Cache,
installation_allowed: bool,
name: &str,
url: &str,
) -> Result<Option<PathBuf>, failure::Error> {
if let Some(dl) = cache.download(false, name, &[name], &url)? {
return Ok(Some(dl.binary(name)?));
}
if installation_allowed {
PBAR.info(&format!("Getting {}...", name));
}
match cache.download(installation_allowed, name, &[name], &url)? {
Some(dl) => Ok(Some(dl.binary(name)?)),
None => Ok(None),
}
}
/// Get the path to an existing `chromedriver`, or install it if no existing
/// binary is found.
@ -41,13 +60,8 @@ pub fn install_chromedriver(
"https://chromedriver.storage.googleapis.com/2.46/chromedriver_{}.zip",
target
);
match cache.download(
installation_allowed,
"chromedriver",
&["chromedriver"],
&url,
)? {
Some(dl) => Ok(dl.binary("chromedriver")?),
match get_and_notify(cache, installation_allowed, "chromedriver", &url)? {
Some(path) => Ok(path),
None => bail!(
"No cached `chromedriver` binary found, and could not find a global \
`chromedriver` on the `$PATH`. Not installing `chromedriver` because of noinstall \
@ -96,8 +110,8 @@ pub fn install_geckodriver(
target,
ext,
);
match cache.download(installation_allowed, "geckodriver", &["geckodriver"], &url)? {
Some(dl) => Ok(dl.binary("geckodriver")?),
match get_and_notify(cache, installation_allowed, "geckodriver", &url)? {
Some(path) => Ok(path),
None => bail!(
"No cached `geckodriver` binary found, and could not find a global `geckodriver` \
on the `$PATH`. Not installing `geckodriver` because of noinstall mode."

@ -14,8 +14,7 @@ fn it_copies_a_license_default_path() {
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path);
let step = wasm_pack::progressbar::Step::new(1);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok());
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE");
let pkg_license_path = out_dir.join("LICENSE");
@ -40,8 +39,7 @@ fn it_copies_a_license_provided_path() {
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path);
let step = wasm_pack::progressbar::Step::new(1);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok());
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE");
let pkg_license_path = out_dir.join("LICENSE");
println!(
@ -64,8 +62,7 @@ fn it_copies_all_licenses_default_path() {
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path);
let step = wasm_pack::progressbar::Step::new(1);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok());
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE-WTFPL");
let pkg_license_path = out_dir.join("LICENSE-WTFPL");
@ -100,8 +97,7 @@ fn it_copies_all_licenses_provided_path() {
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path);
let step = wasm_pack::progressbar::Step::new(1);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok());
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join("LICENSE-WTFPL");
let pkg_license_path = out_dir.join("LICENSE-WTFPL");
@ -137,8 +133,7 @@ fn it_copies_a_non_standard_license_provided_path() {
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path);
let step = wasm_pack::progressbar::Step::new(1);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok());
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok());
let crate_license_path = fixture.path.join(license_file);
let pkg_license_path = out_dir.join(license_file);

@ -27,8 +27,7 @@ fn it_checks_has_cdylib_default_path() {
// Ensure that there is a `Cargo.lock`.
fixture.cargo_check();
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
assert!(crate_data.check_crate_config(&step).is_err());
assert!(crate_data.check_crate_config().is_err());
}
#[test]
@ -37,16 +36,14 @@ fn it_checks_has_cdylib_provided_path() {
// Ensure that there is a `Cargo.lock`.
fixture.cargo_check();
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
crate_data.check_crate_config(&step).unwrap();
crate_data.check_crate_config().unwrap();
}
#[test]
fn it_checks_has_cdylib_wrong_crate_type() {
let fixture = fixture::bad_cargo_toml();
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
assert!(crate_data.check_crate_config(&step).is_err());
assert!(crate_data.check_crate_config().is_err());
}
#[test]
@ -55,8 +52,7 @@ fn it_recognizes_a_map_during_depcheck() {
// Ensure that there is a `Cargo.lock`.
fixture.cargo_check();
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
crate_data.check_crate_config(&step).unwrap();
crate_data.check_crate_config().unwrap();
}
#[test]
@ -64,10 +60,9 @@ fn it_creates_a_package_json_default_path() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, false, &Target::Bundler)
.is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
@ -100,10 +95,9 @@ fn it_creates_a_package_json_provided_path() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, false, &Target::Bundler)
.is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
@ -129,16 +123,9 @@ fn it_creates_a_package_json_provided_path_with_scope() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(
&out_dir,
&Some("test".to_string()),
false,
&Target::Bundler,
&step
)
.write_package_json(&out_dir, &Some("test".to_string()), false, &Target::Bundler,)
.is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
@ -164,10 +151,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, &Target::Nodejs, &step)
.write_package_json(&out_dir, &None, false, &Target::Nodejs)
.is_ok());
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
@ -200,10 +186,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, &Target::NoModules, &step)
.write_package_json(&out_dir, &None, false, &Target::NoModules)
.is_ok());
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
@ -235,10 +220,9 @@ fn it_creates_a_pkg_json_in_out_dir() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("./custom/out");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, false, &Target::Bundler)
.is_ok());
let package_json_path = &fixture.path.join(&out_dir).join("package.json");
@ -251,10 +235,9 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, true, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, true, &Target::Bundler)
.is_ok());
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
@ -280,8 +263,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
fn it_errors_when_wasm_bindgen_is_not_declared() {
let fixture = fixture::bad_cargo_toml();
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
assert!(crate_data.check_crate_config(&step).is_err());
assert!(crate_data.check_crate_config().is_err());
}
#[test]
@ -314,10 +296,9 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(2);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, true, &Target::Bundler)
.unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -331,10 +312,9 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(2);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, true, &Target::Bundler)
.unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
@ -347,8 +327,7 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() {
// Ensure that there is a `Cargo.lock`.
fixture.cargo_check();
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(1);
crate_data.check_crate_config(&step).unwrap();
crate_data.check_crate_config().unwrap();
}
#[test]
@ -420,7 +399,7 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() {
.arg("build")
.assert()
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
"[WARN]: \"package.metadata.wasm-pack.profile.production\" is an unknown key and will \
be ignored. Please check your Cargo.toml.",
));
@ -433,11 +412,10 @@ fn it_lists_license_files_in_files_field_of_package_json() {
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(3);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
license::copy_from_crate(&crate_data, &fixture.path, &out_dir, &step).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
license::copy_from_crate(&crate_data, &fixture.path, &out_dir).unwrap();
crate_data
.write_package_json(&out_dir, &None, false, &Target::Bundler, &step)
.write_package_json(&out_dir, &None, false, &Target::Bundler)
.unwrap();
let package_json_path = &fixture.path.join("pkg").join("package.json");

@ -12,8 +12,7 @@ fn it_copies_a_readme_default_path() {
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let step = wasm_pack::progressbar::Step::new(1);
assert!(readme::copy_from_crate(&fixture.path, &out_dir, &step).is_ok());
assert!(readme::copy_from_crate(&fixture.path, &out_dir).is_ok());
let crate_readme_path = fixture.path.join("README.md");
let pkg_readme_path = out_dir.join("README.md");
@ -37,8 +36,7 @@ fn it_copies_a_readme_provided_path() {
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let step = wasm_pack::progressbar::Step::new(1);
assert!(readme::copy_from_crate(&fixture.path, &out_dir, &step).is_ok());
assert!(readme::copy_from_crate(&fixture.path, &out_dir).is_ok());
let crate_readme_path = fixture.path.join("README.md");
let pkg_readme_path = out_dir.join("README.md");
println!(

@ -331,9 +331,9 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() {
.arg("--node")
.assert()
.failure()
.stderr(predicate::function(|err: &str| {
// but the err string will capture both stdout and failures,
.stdout(predicate::function(|out: &str| {
// but the out string will capture both stdout and failures,
// so we will get a log that count twice
err.matches("YABBA DABBA DOO").count() == log_cnt * 2
out.matches("YABBA DABBA DOO").count() == log_cnt * 2
}));
}

Loading…
Cancel
Save