Skip to content

Commit 13200ca

Browse files
authored
fix: use NPM_CONFIG_USERCONFIG in get-registry to match auth (semantic-release#362)
Previously NPM_CONFIG_USERCONFIG was only used for getting the auth token and not used for actually getting the registry from .npmrc.
1 parent a8b1026 commit 13200ca

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ Both the [token](https://docs.npmjs.com/getting-started/working_with_tokens) and
4545

4646
### Environment variables
4747

48-
| Variable | Description |
49-
| -------------- | ----------------------------------------------------------------------------------------------------------------------------- |
50-
| `NPM_TOKEN` | Npm token created via [npm token create](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) |
51-
| `NPM_USERNAME` | Npm username created via [npm adduser](https://docs.npmjs.com/cli/adduser) or on [npmjs.com](https://www.npmjs.com) |
52-
| `NPM_PASSWORD` | Password of the npm user. |
53-
| `NPM_EMAIL` | Email address associated with the npm user |
48+
| Variable | Description |
49+
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
50+
| `NPM_TOKEN` | Npm token created via [npm token create](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) |
51+
| `NPM_USERNAME` | Npm username created via [npm adduser](https://docs.npmjs.com/cli/adduser) or on [npmjs.com](https://www.npmjs.com) |
52+
| `NPM_PASSWORD` | Password of the npm user. |
53+
| `NPM_EMAIL` | Email address associated with the npm user |
54+
| `NPM_CONFIG_USERCONFIG` | Path to non-default .npmrc file |
5455

5556
Use either `NPM_TOKEN` for token authentication or `NPM_USERNAME`, `NPM_PASSWORD` and `NPM_EMAIL` for legacy authentication
5657

lib/get-registry.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ module.exports = ({publishConfig: {registry} = {}, name}, {cwd, env}) =>
77
env.NPM_CONFIG_REGISTRY ||
88
getRegistryUrl(
99
name.split('/')[0],
10-
rc('npm', {registry: 'https://registry.npmjs.org/'}, {config: path.resolve(cwd, '.npmrc')})
10+
rc(
11+
'npm',
12+
{registry: 'https://registry.npmjs.org/'},
13+
{config: env.NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc')}
14+
)
1115
);

test/get-registry.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ test('Get the registry configured in ".npmrc" for scoped package', async (t) =>
4242

4343
t.is(getRegistry({name: '@scope/package-name'}, {cwd, env: {}}), 'https://custom3.registry.com/');
4444
});
45+
46+
test.serial('Get the registry configured via "NPM_CONFIG_USERCONFIG" for scoped package', async (t) => {
47+
const cwd = tempy.directory();
48+
await appendFile(path.resolve(cwd, '.custom-npmrc'), '@scope:registry = https://custom4.registry.com');
49+
50+
t.is(
51+
getRegistry(
52+
{
53+
name: '@scope/package-name',
54+
},
55+
{
56+
cwd,
57+
env: {NPM_CONFIG_USERCONFIG: path.resolve(cwd, '.custom-npmrc')},
58+
}
59+
),
60+
'https://custom4.registry.com/'
61+
);
62+
});

0 commit comments

Comments
 (0)