Skip to content

Commit

Permalink
Allow publishConfig.registry to be npm default registry when using …
Browse files Browse the repository at this point in the history
…Yarn berry (#750)
  • Loading branch information
fisker authored Jul 16, 2024
1 parent a9e8fc7 commit 6c5eee3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion source/npm/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ export const username = async ({externalRegistry}) => {
}
};

export const isExternalRegistry = package_ => typeof package_.publishConfig?.registry === 'string';
const NPM_DEFAULT_REGISTRIES = new Set([
// https://docs.npmjs.com/cli/v10/using-npm/registry
'https://registry.npmjs.org',
// https://docs.npmjs.com/cli/v10/commands/npm-profile#registry
'https://registry.npmjs.org/',
]);
export const isExternalRegistry = package_ => {
const registry = package_.publishConfig?.registry;
return typeof registry === 'string' && !NPM_DEFAULT_REGISTRIES.has(registry);
};

export const collaborators = async package_ => {
const packageName = package_.name;
Expand Down
2 changes: 2 additions & 0 deletions test/npm/util/is-external-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ test('main', t => {
t.false(npm.isExternalRegistry({name: 'foo'}));
t.false(npm.isExternalRegistry({publishConfig: {registry: true}}));
t.false(npm.isExternalRegistry({publishConfig: 'not an object'}));
t.false(npm.isExternalRegistry({publishConfig: {registry: 'https://registry.npmjs.org'}}));
t.false(npm.isExternalRegistry({publishConfig: {registry: 'https://registry.npmjs.org/'}}));
});

0 comments on commit 6c5eee3

Please sign in to comment.