Repository: semantic-release/npm (js)

Issue:
get-registry.js doesn't take into account NPM_CONFIG_USERCONFIG
When `get-registry.js` looks for the registry it just looks at `./.npmrc` instead of taking into account `NPM_CONFIG_USERCONFIG`. This ends up requiring that you specify `NPM_CONFIG_REGISTRY` when you shouldn't have to because it's already in the alternative rc file specified by `NPM_CONFIG_USERCONFIG`.

Pull request description:
fix: use `NPM_CONFIG_USERCONFIG` in get-registry to match auth
Previously NPM_CONFIG_USERCONFIG was only used for getting the auth token and not used for actually getting the registry from .npmrc.

Fixes #349

Patch:
diff --git a/README.md b/README.md
index 968ea08..4758b24 100644
--- a/README.md
+++ b/README.md
@@ -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
 
diff --git a/lib/get-registry.js b/lib/get-registry.js
index d3e7e2b..b6f8b49 100644
--- a/lib/get-registry.js
+++ b/lib/get-registry.js
@@ -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')}
+    )
   );


Test patch:
diff --git a/test/get-registry.test.js b/test/get-registry.test.js
index 8f11237..f64a218 100644
--- a/test/get-registry.test.js
+++ b/test/get-registry.test.js
@@ -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/'
+  );
+});