npmauth
Run vsts-npm-auth -config .npmrc in all directories containing a .npmrc file. Forces new credentials for the first .npmrc found (useful when multiple directories share the same npm registries), then authenticates the remaining directories without forcing. This is helpful in monorepo setups where multiple packages authenticate against the same Azure Artifacts npm registries.
Written with the help of Claude.
Usage:
git npmauth
CLI Command
git config --global alias.npmauth "!f() { root=$(git rev-parse --show-toplevel); first=1; git ls-files "*/.npmrc" | sed "s|/[^/]*$||" | sort -u | while IFS= read -r dir; do echo "Running vsts-npm-auth in $dir" && cd "$root/$dir" && if [ "$first" = "1" ]; then vsts-npm-auth -F -config .npmrc; first=0; else vsts-npm-auth -config .npmrc; fi; done; }; f"
.gitconfig Snippet
[alias]
npmauth = !f() { root=$(git rev-parse --show-toplevel); first=1; git ls-files "*/.npmrc" | sed "s|/[^/]*$||" | sort -u | while IFS= read -r dir; do echo "Running vsts-npm-auth in $dir" && cd "$root/$dir" && if [ "$first" = "1" ]; then vsts-npm-auth -F -config .npmrc; first=0; else vsts-npm-auth -config .npmrc; fi; done; }; f