This commit replaces the `slog` family of crates used by `wasm-pack`
with the `log` crate plus `env_logger`. This also means that by default
`wasm-pack` also won't create a `wasm-pack.log` file in the current
directory. Enabling logging will now be done through
`RUST_LOG=wasm_pack` instead of `-v` flags.
Closes#425
Issue #277 - Affects running login, pack, and publish on Windows.
`Command::new("npm")` launched `npm` with quotes, `"npm"`, causing a
run-time error on Windows. Now, `Command::new` is wrapped by
`child::new_command(program: &str)`. This prepends `cmd /c` to the
program name if `cfg!(windows)`.
See rustc: #42436, #42791, #44542
`child::run` overrides the stdout config, so is misleading to to set it
differently beforehand. `child::run` uses `spawn()`, which inherits
stdin by default. So, no need to set stdin to default beforehand,
particularly when the spawned program is non-interactive.
All arguments were passed to `arg` inside one string when building a
`Command`. However, using the `arg` function, "only one argument can be
passed per use." This caused all arguments accidentally to be appended
to the registry URL. For example: After a successful login with a
provided `--auth_type`, the success message incorrectly displayed:
"Logged in as asf on https://registry.npmjs.org/%20--auth_type=Basic."
The space (%20 in hex) was caused by adding a fixed space before each
additional argument.
This commit pushes all arguments onto a `Vec<String>`. Then, the `args`
function adds the arguments separately to the command. This removes the
need to prepend spaces to each argument. Alternatively, `arg` could have
been used throughout to build the command argument-by-argument. However,
using `args` partitions the code more neatly into two distinct sections.
Issue #484.
PR392 inadvertantly replaced the `login` interactive process spawner
with
`child::run`, which is hard-coded to buffer stdout/stderr. This caused
`login` to become essentially unusable; the user could no longer see
interactive input prompts or error messages displayed by `npm adduser`.
The code was not directly reverted because the previous version:
1. Returned Error instead of failure::Error. (Updated to use
`bail!`, which is consistent with `publish`.)
2. Displayed all stderr only upon exit, rather than interactively
displaying it. This led to repeated interactive prompts without
informing the user why. (Updated to use `status()` which inherits
stdin/stdout/stderr by default.)
3. Did not provide logging. (Now duplicates the logging in
`child::run`.)
This does two big things:
- We add custom error messages and conversions from other error types
into our own error type. This means we can create or modify more
fine grained errors rather than using whatever `failure::Error` gives
us. The first one we have is a `Cli` error, whereby calls to things
like wasm-bindgen or npm failed.
- We also make it so that `PBAR.error()` is called only on exit. We grab
a reference to whatever error gets passed up the chain, have it
generate a message to be printed as an error to PBAR, close up PBAR
like normal, and then print our actual error message to stderr!
The main benefits of this is that as long as we return an error, PBAR
will print and close itself up and we don't need to call it every time
or forget that we would need to call it, and we put error details
specifically into our error!
Closes#12
This commit does quite a few things in order to get this to work:
1. We move all of the code dealing with knowing which command to run
into it's own function. This wrapper command allows us to always
close out PBAR before dumping error output. This fixes a problem
where stderr and stdout were borked and not printing out error
messages correctly.
2. We then refactor the code that has a panic to return early with that
error message.
3. If the command we ran errored, we print out with PBAR that there was
an error with the program we ran (not wasm-pack itself) then dump the
stderr from the command to the actual stderr
This means we can abort early on without continuing any of the other
parts of wasm-pack and let the user know what the error was rather than
just saying "There's an error"