scripts/owner.sh: npm asks for 2FA on the terminal, and a run with none stops first

Run through Claude Code's ! (no terminal), every npm step printed the 2FA
link and failed with EOTP at once: npm waits for the browser only when it
can ask on a terminal. npm now reads from /dev/tty, so piping the script
to sh still works, and a run with no terminal says so before any npm step.

Run: with no terminal, --dry-run lists the four packages and the real run
stops with the message, exit 1, nothing asked of npm. Not run on a terminal
(that takes the owner's 2FA).
This commit is contained in:
yetone
2026-10-15 18:13:30 +08:00
parent 80baa27570
commit c59ee33efe
+8 -2
View File
@@ -21,8 +21,10 @@ dry=""
repo=magpie-community/plugins
reg=https://registry.npmjs.org/
export npm_config_registry="$reg"
# npm trust needs npm 11.5 or later
npm11() { npx -y npm@11 "$@"; }
# npm trust needs npm 11.5 or later. Its 2FA waits for the browser only
# when it can ask on a terminal; without one it prints the link and fails
# with EOTP, so npm reads from the terminal even when this script is piped.
npm11() { npx -y npm@11 "$@" </dev/tty; }
root=$(git -C "$(dirname "$0")" rev-parse --show-toplevel)
git -C "$root" fetch -q https://github.com/$repo.git main
@@ -62,6 +64,10 @@ echo "$todo" | while read -r d name version state; do
esac
done
[ -n "$dry" ] && exit 0
if ! (: </dev/tty) 2>/dev/null; then
echo "npm's 2FA needs a terminal: run this in Terminal (not through a tool with no terminal, such as Claude Code's !)." >&2
exit 1
fi
if ! npm11 whoami >/dev/null 2>&1; then
echo "Signing in to npm (in the browser)..."