Skip to content

Commit 1395b18

Browse files
ryaninventsgr2m
authored andcommitted
fix: Honor NPM_CONFIG_USERCONFIG setting
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 🎉
1 parent 8288c24 commit 1395b18

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/set-npmrc-auth.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ const nerfDart = require('nerf-dart');
66
const AggregateError = require('aggregate-error');
77
const getError = require('./get-error');
88

9-
module.exports = async (registry, {cwd, env: {NPM_TOKEN, NPM_USERNAME, NPM_PASSWORD, NPM_EMAIL}, logger}) => {
9+
module.exports = async (
10+
registry,
11+
{cwd, env: {NPM_TOKEN, NPM_CONFIG_USERCONFIG, NPM_USERNAME, NPM_PASSWORD, NPM_EMAIL}, logger}
12+
) => {
1013
logger.log('Verify authentication for registry %s', registry);
11-
const config = path.resolve(cwd, '.npmrc');
14+
const config = NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc');
1215
if (getAuthToken(registry, {npmrc: rc('npm', {registry: 'https://registry.npmjs.org/'}, {config})})) {
1316
return;
1417
}

0 commit comments

Comments
 (0)