Handle npm tokens with environment variables#1211
Merged
ecraig12345 merged 4 commits intomainfrom Apr 22, 2026
Merged
Conversation
b44bb28 to
662fda2
Compare
dannyvv
reviewed
Apr 21, 2026
| const npmrcContent = fs | ||
| .readFileSync(npmrcPath, 'utf-8') | ||
| .split(/\r?\n/g) | ||
| .find(line => line.startsWith(registryUrl) && line.includes('_authToken')); |
Member
There was a problem hiding this comment.
nit: it could also be _password
Member
Author
There was a problem hiding this comment.
In these tests using npm login against a Verdaccio registry, it always seems to use _authToken, so this should be fine.
dannyvv
approved these changes
Apr 21, 2026
662fda2 to
0b6f9de
Compare
0b6f9de to
b68b28f
Compare
c393bf1 to
73bdda2
Compare
3 tasks
73bdda2 to
c262ed9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for reading the npm token from the
NPM_TOKENenvironment variable, and update docs to recommend that approach. Getting the token from the environment is handled ingetCliOptionsfor simplicity.Pass the token through to
npmusing an environment variable rather than a CLI option. It's not well-documented for the specific case of auth, but the environment variable naming format isnpm_config_//registry.npmjs.org/:_authToken(or other registry; trailing slash on registry is required).Workaround for token env issues
Special characters such as
/and/or:aren't valid in env var names for certain shells/platforms, which caused the token environment variable to be dropped when trying to pass it to thenpm publishsubprocess. Unclear whether the issue is specific to platform, shell, or the combo, but it definitely happened with Ubuntu+bash.First issue is that running
npm publishwithshell: truedrops the token var. Fixed by only settingshell: trueon Windows.The other issue is specific to if the parent command was run VIA
yarn... Best I can tell, this is because on everyyarn run ...command, yarn makes temp directories like/<temp>/yarn--1776822418161-0.7992675923334178with aliases fornodeandyarn. On Linux (and Mac), thenodealias looks something like:My best guess is this extra
execstep drops invalid environment variable names?? (This consistently reproed on Ubuntu+bash, but not Mac+zsh or bash. The clue was that the tests passed even on Linux when run via debugTests.js, but failed when run via yarn test.) Removing theyarn--segment from the PATH seems to consistently fix this issue.