From 0673248b1496ea6ebaaf14c6a3e56def2baf5739 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 16 Jul 2024 18:04:01 +0800 Subject: [PATCH 1/4] Allow `publishConfig.registry` to be npm default registry when using yarn berry --- source/cli-implementation.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index 73db73f6..62926078 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -127,7 +127,12 @@ async function getOptions() { const packageManager = getPackageManagerConfig(rootDirectory, package_); - if (packageManager.throwOnExternalRegistry && npm.isExternalRegistry(package_)) { + if ( + packageManager.throwOnExternalRegistry + && npm.isExternalRegistry(package_) + // NPM default registry https://github.com/npm/pneumatic-tubes/blob/1064fbb461464cc0fe18bd2790a176aa92bd63fd/index.js#L35 + && package_.publishConfig.registry !== 'https://registry.npmjs.org' + ) { throw new Error(`External registry is not yet supported with ${packageManager.id}.`); } From ff7f87e8490b73ca28b7a8c54994419e9f6a68a1 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 16 Jul 2024 18:45:47 +0800 Subject: [PATCH 2/4] Move to `isExternalRegistry` --- source/cli-implementation.js | 7 +------ source/npm/util.js | 7 ++++++- test/npm/util/is-external-registry.js | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index 62926078..73db73f6 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -127,12 +127,7 @@ async function getOptions() { const packageManager = getPackageManagerConfig(rootDirectory, package_); - if ( - packageManager.throwOnExternalRegistry - && npm.isExternalRegistry(package_) - // NPM default registry https://github.com/npm/pneumatic-tubes/blob/1064fbb461464cc0fe18bd2790a176aa92bd63fd/index.js#L35 - && package_.publishConfig.registry !== 'https://registry.npmjs.org' - ) { + if (packageManager.throwOnExternalRegistry && npm.isExternalRegistry(package_)) { throw new Error(`External registry is not yet supported with ${packageManager.id}.`); } diff --git a/source/npm/util.js b/source/npm/util.js index 02736fcb..34042572 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -43,7 +43,12 @@ export const username = async ({externalRegistry}) => { } }; -export const isExternalRegistry = package_ => typeof package_.publishConfig?.registry === 'string'; +// NPM default registry https://github.com/npm/pneumatic-tubes/blob/1064fbb461464cc0fe18bd2790a176aa92bd63fd/index.js#L35 +const NPM_DEFAULT_REGISTRY = 'https://registry.npmjs.org'; +export const isExternalRegistry = package_ => { + const registry = package_.publishConfig?.registry; + return typeof registry === 'string' && registry !== NPM_DEFAULT_REGISTRY; +}; export const collaborators = async package_ => { const packageName = package_.name; diff --git a/test/npm/util/is-external-registry.js b/test/npm/util/is-external-registry.js index c449cc66..e1162c00 100644 --- a/test/npm/util/is-external-registry.js +++ b/test/npm/util/is-external-registry.js @@ -7,4 +7,5 @@ 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'}})); }); From 6bbf3df4f3a04f64e78db34a502a753ab62cbcd4 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 16 Jul 2024 18:57:33 +0800 Subject: [PATCH 3/4] Allow both --- source/npm/util.js | 10 +++++++--- test/npm/util/is-external-registry.js | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 34042572..1b532559 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -43,11 +43,15 @@ export const username = async ({externalRegistry}) => { } }; -// NPM default registry https://github.com/npm/pneumatic-tubes/blob/1064fbb461464cc0fe18bd2790a176aa92bd63fd/index.js#L35 -const NPM_DEFAULT_REGISTRY = 'https://registry.npmjs.org'; +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' && registry !== NPM_DEFAULT_REGISTRY; + return typeof registry === 'string' && !NPM_DEFAULT_REGISTRIES.has(registry); }; export const collaborators = async package_ => { diff --git a/test/npm/util/is-external-registry.js b/test/npm/util/is-external-registry.js index e1162c00..6b7bcadb 100644 --- a/test/npm/util/is-external-registry.js +++ b/test/npm/util/is-external-registry.js @@ -8,4 +8,5 @@ test('main', t => { 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/'}})); }); From f32b8d416cb4924d660af8d0cf92cfc377616b65 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 16 Jul 2024 19:00:44 +0800 Subject: [PATCH 4/4] Linting --- source/npm/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/npm/util.js b/source/npm/util.js index 1b532559..4ea325e6 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -47,7 +47,7 @@ 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/' + 'https://registry.npmjs.org/', ]); export const isExternalRegistry = package_ => { const registry = package_.publishConfig?.registry;