@rb-mwindh/setup-npm-auth
v1.2.7
Published
CLI to discover configured npm registries write authToken to user config
Readme
setup-npm-auth
A CLI and GitHub Action to discover configured npm registries and write authentication tokens to the npm user config. Supports default, publish, and scoped registries. Designed for use in CI/CD pipelines and local development.
Features
- Discovers all configured npm registries (default, publishConfig, and @scope registries)
- Writes authentication tokens to the correct npm config location
- Supports dry-run and verbose modes
- Usable as a CLI or as a declarative GitHub Action
Usage
CLI
Install globally or use via npx:
npx @rb-mwindh/setup-npm-auth --include default --include publish=PUBLISH_TOKEN --include @myscope=SCOPE_TOKENOptions
--include <scope>[=<ENV_VAR>]
Include a registry. Repeatable. Grammar:default,publish, or@scope[=ENV_VAR]. Defaults toNODE_AUTH_TOKENif ENV_VAR is omitted.-L, --location <global|project|user>
Specify npm config location. Defaults to user-level config.--dry-run
Show what would be configured, but do not write anything.-v, --verbose
Show detailed output.
Examples
# Set auth for the default registry using NODE_AUTH_TOKEN
NODE_AUTH_TOKEN=foo npx @rb-mwindh/setup-npm-auth
# Set auth for default and publishConfig.registry using the same token from NODE_AUTH_TOKEN
NODE_AUTH_TOKEN=foo PUBLISH_TOKEN=bar npx @rb-mwindh/setup-npm-auth --include default --include publish
# Set auth for default and publishConfig.registry using different env vars
NODE_AUTH_TOKEN=foo PUBLISH_TOKEN=bar npx @rb-mwindh/setup-npm-auth --include default --include publish=PUBLISH_TOKEN
# Set auth for a scoped registry
SCOPE_TOKEN=abc npx @rb-mwindh/setup-npm-auth --include @myscope=SCOPE_TOKEN
# Use a specific npm config location (e.g. user)
NODE_AUTH_TOKEN=foo npx @rb-mwindh/setup-npm-auth -L user
# Show what would be configured, but do not write anything
NODE_AUTH_TOKEN=foo npx @rb-mwindh/setup-npm-auth --dry-run
# Show planned configuration details before execution
NODE_AUTH_TOKEN=foo npx @rb-mwindh/setup-npm-auth --verboseGitHub Action
You can use this tool as a declarative GitHub Action in your workflows:
- uses: rb-mwindh/setup-npm-auth@main
with:
verbose: 'true'
includes: |
default
publish=PUBLISH_TOKEN
@myscope=SCOPE_TOKENAction Inputs
includes: Registries to include (e.g.default,publish,@scope=ENV)location: npm config location (user, global, project)dry-run: Show what would be done, but do not executeverbose: Show more output
Development
Building the Action
This action uses @vercel/ncc to bundle all runtime dependencies into a single file. The bundled output is committed to the repository in the dist/ directory because GitHub Actions require all code and dependencies to be present in the repository.
To build the action after making changes:
npm ci
npm run buildThe dist/ directory is intentionally committed to version control, as this is required for JavaScript GitHub Actions to work on self-hosted runners without requiring npm install.
License
MIT © Markus Windhager
