From 857e692c08f2f3cb1b3facb39f247c09e6a3a402 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Mon, 22 Aug 2022 11:21:54 +0800 Subject: [PATCH 1/2] CLI: Fix local repro publishing --- .../src/js-package-manager/JsPackageManager.ts | 15 +++++++++++++-- code/lib/cli/src/js-package-manager/NPMProxy.ts | 13 ------------- code/lib/cli/src/js-package-manager/Yarn1Proxy.ts | 13 ------------- code/lib/cli/src/js-package-manager/Yarn2Proxy.ts | 13 ------------- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/code/lib/cli/src/js-package-manager/JsPackageManager.ts b/code/lib/cli/src/js-package-manager/JsPackageManager.ts index 4f7e553a5dea..46414f43b483 100644 --- a/code/lib/cli/src/js-package-manager/JsPackageManager.ts +++ b/code/lib/cli/src/js-package-manager/JsPackageManager.ts @@ -39,9 +39,20 @@ export abstract class JsPackageManager { public abstract getRunCommand(command: string): string; - public abstract setRegistryURL(url: string): void; + // NOTE: for some reason yarn prefers the npm registry in + // local development, so always use npm + setRegistryURL(url: string) { + if (url) { + this.executeCommand('npm', ['config', 'set', 'registry', url]); + } else { + this.executeCommand('npm', ['config', 'delete', 'registry']); + } + } - public abstract getRegistryURL(): string; + getRegistryURL() { + const url = this.executeCommand('npm', ['config', 'get', 'registry']).trim(); + return url === 'undefined' ? undefined : url; + } public readonly cwd?: string; diff --git a/code/lib/cli/src/js-package-manager/NPMProxy.ts b/code/lib/cli/src/js-package-manager/NPMProxy.ts index 64edffa7a6b7..d89726f9d7dc 100644 --- a/code/lib/cli/src/js-package-manager/NPMProxy.ts +++ b/code/lib/cli/src/js-package-manager/NPMProxy.ts @@ -61,19 +61,6 @@ export class NPMProxy extends JsPackageManager { return this.uninstallArgs; } - setRegistryURL(url: string) { - if (url) { - this.executeCommand('npm', ['config', 'set', 'registry', url]); - } else { - this.executeCommand('npm', ['config', 'delete', 'registry']); - } - } - - getRegistryURL() { - const url = this.executeCommand('npm', ['config', 'get', 'registry']).trim(); - return url === 'undefined' ? undefined : url; - } - protected getResolutions(packageJson: PackageJson, versions: Record) { return { overrides: { diff --git a/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts b/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts index bcb0c01ae213..789499084c85 100644 --- a/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts +++ b/code/lib/cli/src/js-package-manager/Yarn1Proxy.ts @@ -16,19 +16,6 @@ export class Yarn1Proxy extends JsPackageManager { return `yarn ${command}`; } - setRegistryURL(url: string) { - if (url) { - this.executeCommand('yarn', ['config', 'set', 'npmRegistryServer', url]); - } else { - this.executeCommand('yarn', ['config', 'delete', 'npmRegistryServer']); - } - } - - getRegistryURL() { - const url = this.executeCommand('yarn', ['config', 'get', 'npmRegistryServer']).trim(); - return url === 'undefined' ? undefined : url; - } - protected getResolutions(packageJson: PackageJson, versions: Record) { return { resolutions: { diff --git a/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts b/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts index 4ab59b903d4b..63736283424f 100644 --- a/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts +++ b/code/lib/cli/src/js-package-manager/Yarn2Proxy.ts @@ -16,19 +16,6 @@ export class Yarn2Proxy extends JsPackageManager { return `yarn ${command}`; } - setRegistryURL(url: string) { - if (url) { - this.executeCommand('yarn', ['config', 'set', 'npmRegistryServer', url]); - } else { - this.executeCommand('yarn', ['config', 'delete', 'npmRegistryServer']); - } - } - - getRegistryURL() { - const url = this.executeCommand('yarn', ['config', 'get', 'npmRegistryServer']).trim(); - return url === 'undefined' ? undefined : url; - } - protected getResolutions(packageJson: PackageJson, versions: Record) { return { resolutions: { From d6c968c42cb13318480f479cd0c1653ff2eb316a Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Mon, 22 Aug 2022 17:14:40 +0800 Subject: [PATCH 2/2] Fix unit tests --- code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts | 4 ++-- code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts b/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts index 90a7df8b9b8c..c9087095df63 100644 --- a/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts +++ b/code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts @@ -27,10 +27,10 @@ describe('Yarn 1 Proxy', () => { yarn1Proxy.setRegistryURL('https://foo.bar'); - expect(executeCommandSpy).toHaveBeenCalledWith('yarn', [ + expect(executeCommandSpy).toHaveBeenCalledWith('npm', [ 'config', 'set', - 'npmRegistryServer', + 'registry', 'https://foo.bar', ]); }); diff --git a/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts b/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts index 93faad9aa82e..561c957257da 100644 --- a/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts +++ b/code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts @@ -37,10 +37,10 @@ describe('Yarn 2 Proxy', () => { yarn2Proxy.setRegistryURL('https://foo.bar'); - expect(executeCommandSpy).toHaveBeenCalledWith('yarn', [ + expect(executeCommandSpy).toHaveBeenCalledWith('npm', [ 'config', 'set', - 'npmRegistryServer', + 'registry', 'https://foo.bar', ]); });