Skip to content

Commit

Permalink
fix: Honor NPM_CONFIG_USERCONFIG setting
Browse files Browse the repository at this point in the history
This bug cost me weeks 馃槄

`npm` honors the `NPM_CONFIG_USERCONFIG` setting, which our CI relies on to inject shared credentials at runtime. `npm publish` succeeds if we're not using Semantic Release. However, `@semantic-release/npm` has reimplemented a credentials check in a manner not compatible with the way `npm` handles the user config environment variable. This PR checks the location specified in `NPM_CONFIG_USERCONFIG` before using `rc` to crawl up the file hierarchy.

It should be noted that `rc` does not fully implement the `.npmrc` resolution algorithm, skipping the ability to specify config files from an env var. That's why we're facing this problem.

I've tested this locally, and this small fix would allow us to use Semantic Release 馃帀
  • Loading branch information
ryaninvents authored and pvdlg committed Aug 21, 2019
1 parent bf603e5 commit 932ea5e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/set-npmrc-auth.js
Expand Up @@ -6,9 +6,12 @@ const nerfDart = require('nerf-dart');
const AggregateError = require('aggregate-error');
const getError = require('./get-error');

module.exports = async (registry, {cwd, env: {NPM_TOKEN, NPM_USERNAME, NPM_PASSWORD, NPM_EMAIL}, logger}) => {
module.exports = async (
registry,
{cwd, env: {NPM_TOKEN, NPM_CONFIG_USERCONFIG, NPM_USERNAME, NPM_PASSWORD, NPM_EMAIL}, logger}
) => {
logger.log('Verify authentication for registry %s', registry);
const config = path.resolve(cwd, '.npmrc');
const config = NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc');
if (getAuthToken(registry, {npmrc: rc('npm', {registry: 'https://registry.npmjs.org/'}, {config})})) {
return;
}
Expand Down

0 comments on commit 932ea5e

Please sign in to comment.