Skip to content

Commit

Permalink
Merge pull request #18977 from storybookjs/shilman/fix-local-repro
Browse files Browse the repository at this point in the history
CLI: Fix local repro publishing
  • Loading branch information
shilman authored Aug 22, 2022
2 parents 4b9e2d3 + d6c968c commit de2fd05
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 45 deletions.
15 changes: 13 additions & 2 deletions code/lib/cli/src/js-package-manager/JsPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 0 additions & 13 deletions code/lib/cli/src/js-package-manager/NPMProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>) {
return {
overrides: {
Expand Down
4 changes: 2 additions & 2 deletions code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});
Expand Down
13 changes: 0 additions & 13 deletions code/lib/cli/src/js-package-manager/Yarn1Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>) {
return {
resolutions: {
Expand Down
4 changes: 2 additions & 2 deletions code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});
Expand Down
13 changes: 0 additions & 13 deletions code/lib/cli/src/js-package-manager/Yarn2Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>) {
return {
resolutions: {
Expand Down

0 comments on commit de2fd05

Please sign in to comment.