[go: nahoru, domu]

Skip to content

Commit

Permalink
fix: use NPM_CONFIG_USERCONFIG in get-registry to match auth (#362)
Browse files Browse the repository at this point in the history
Previously NPM_CONFIG_USERCONFIG was only used for getting the auth token and not used for actually getting the registry from .npmrc.
  • Loading branch information
jameshartig committed May 4, 2021
1 parent a8b1026 commit 13200ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ Both the [token](https://docs.npmjs.com/getting-started/working_with_tokens) and

### Environment variables

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

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

Expand Down
6 changes: 5 additions & 1 deletion lib/get-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ module.exports = ({publishConfig: {registry} = {}, name}, {cwd, env}) =>
env.NPM_CONFIG_REGISTRY ||
getRegistryUrl(
name.split('/')[0],
rc('npm', {registry: 'https://registry.npmjs.org/'}, {config: path.resolve(cwd, '.npmrc')})
rc(
'npm',
{registry: 'https://registry.npmjs.org/'},
{config: env.NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc')}
)
);
18 changes: 18 additions & 0 deletions test/get-registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ test('Get the registry configured in ".npmrc" for scoped package', async (t) =>

t.is(getRegistry({name: '@scope/package-name'}, {cwd, env: {}}), 'https://custom3.registry.com/');
});

test.serial('Get the registry configured via "NPM_CONFIG_USERCONFIG" for scoped package', async (t) => {
const cwd = tempy.directory();
await appendFile(path.resolve(cwd, '.custom-npmrc'), '@scope:registry = https://custom4.registry.com');

t.is(
getRegistry(
{
name: '@scope/package-name',
},
{
cwd,
env: {NPM_CONFIG_USERCONFIG: path.resolve(cwd, '.custom-npmrc')},
}
),
'https://custom4.registry.com/'
);
});

0 comments on commit 13200ca

Please sign in to comment.