Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/'
);
});