login: Fix empty input prompt

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`.)
master
Dan Wilhelm 6 years ago
parent 8af40029a9
commit 0147dae9fe
  1. 16
      src/npm.rs

@ -62,12 +62,14 @@ pub fn npm_login(
args.push_str(&format!(" --auth_type={}", auth_type)); args.push_str(&format!(" --auth_type={}", auth_type));
} }
// Interactively ask user for npm login info.
// (child::run does not support interactive input)
let mut cmd = Command::new("npm"); let mut cmd = Command::new("npm");
cmd.arg("login") cmd.arg("login").arg(args);
.arg(args)
.stdin(Stdio::inherit()) info!(log, "Running {:?}", cmd);
.stdout(Stdio::inherit()); match cmd.status()?.success() {
child::run(log, cmd, "npm login") true => Ok(()),
.with_context(|_| format!("Login to registry {} failed", registry))?; false => bail!("Login to registry {} failed", registry),
Ok(()) }
} }

Loading…
Cancel
Save