Skip to content
Open
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
9 changes: 6 additions & 3 deletions lib/get-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import path from "path";
import rc from "rc";
import getRegistryUrl from "registry-auth-token/registry-url.js";

export default function ({ publishConfig: { registry } = {}, name }, { cwd, env }) {
export default function ({ publishConfig = {}, name }, { cwd, env }) {
const scope = name.split("/")[0];
const publishRegistry = publishConfig[`${scope}:registry`] ?? publishConfig.registry;

return (
registry ||
publishRegistry ||
env.NPM_CONFIG_REGISTRY ||
getRegistryUrl(
name.split("/")[0],
scope,
rc(
"npm",
{ registry: "https://registry.npmjs.org/" },
Expand Down
20 changes: 20 additions & 0 deletions test/get-registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ test('Get the registry configured in "NPM_CONFIG_REGISTRY"', (t) => {
);
});

test('Get the registry configured in "publishConfig" for scoped package', async (t) => {
const cwd = temporaryDirectory();
await fs.appendFile(path.resolve(cwd, ".npmrc"), "@scope:registry = https://custom3.registry.com");
await fs.appendFile(path.resolve(cwd, ".npmrc"), "registry = https://custom4.registry.com");

t.is(
getRegistry(
{
name: "@scope/package-name",
publishConfig: {
registry: "https://custom6.registry.com",
"@scope:registry": "https://custom5.registry.com",
},
},
{ cwd, env: { NPM_CONFIG_REGISTRY: "https://custom1.registry.com/" } }
),
"https://custom5.registry.com"
);
});

test('Get the registry configured in ".npmrc" for scoped package', async (t) => {
const cwd = temporaryDirectory();
await fs.appendFile(path.resolve(cwd, ".npmrc"), "@scope:registry = https://custom3.registry.com");
Expand Down