add setRegistryURL to jspackagemanager

This commit is contained in:
Yann Braga 2022-08-16 12:15:55 +02:00
parent e3a7dbfb97
commit a13f330517
7 changed files with 62 additions and 0 deletions

View File

@ -36,6 +36,8 @@ export abstract class JsPackageManager {
public abstract getRunCommand(command: string): string;
public abstract setRegistryURL(url: string): void;
/**
* Install dependencies listed in `package.json`
*/

View File

@ -21,6 +21,21 @@ describe('NPM Proxy', () => {
});
});
describe('setRegistryUrl', () => {
it('should run `npm config set registry https://foo.bar`', () => {
const executeCommandSpy = jest.spyOn(npmProxy, 'executeCommand').mockReturnValue('');
npmProxy.setRegistryURL('https://foo.bar');
expect(executeCommandSpy).toHaveBeenCalledWith('npm', [
'config',
'set',
'registry',
'https://foo.bar',
]);
});
});
describe('installDependencies', () => {
describe('npm6', () => {
it('should run `npm install`', () => {

View File

@ -61,6 +61,11 @@ export class NPMProxy extends JsPackageManager {
return this.uninstallArgs;
}
setRegistryURL(url: string) {
const args = ['config', 'set', 'registry', url];
this.executeCommand('npm', args);
}
protected getResolutions(packageJson: PackageJson, versions: Record<string, string>) {
return {
overrides: {

View File

@ -21,6 +21,21 @@ describe('Yarn 1 Proxy', () => {
});
});
describe('setRegistryUrl', () => {
it('should run `yarn config set npmRegistryServer https://foo.bar`', () => {
const executeCommandSpy = jest.spyOn(yarn1Proxy, 'executeCommand').mockReturnValue('');
yarn1Proxy.setRegistryURL('https://foo.bar');
expect(executeCommandSpy).toHaveBeenCalledWith('yarn', [
'config',
'set',
'npmRegistryServer',
'https://foo.bar',
]);
});
});
describe('installDependencies', () => {
it('should run `yarn`', () => {
const executeCommandSpy = jest.spyOn(yarn1Proxy, 'executeCommand').mockReturnValue('');

View File

@ -16,6 +16,11 @@ export class Yarn1Proxy extends JsPackageManager {
return `yarn ${command}`;
}
setRegistryURL(url: string) {
const args = ['config', 'set', 'npmRegistryServer', url];
this.executeCommand('yarn', args);
}
protected getResolutions(packageJson: PackageJson, versions: Record<string, string>) {
return {
resolutions: {

View File

@ -31,6 +31,21 @@ describe('Yarn 2 Proxy', () => {
});
});
describe('setRegistryUrl', () => {
it('should run `yarn config set npmRegistryServer https://foo.bar`', () => {
const executeCommandSpy = jest.spyOn(yarn2Proxy, 'executeCommand').mockReturnValue('');
yarn2Proxy.setRegistryURL('https://foo.bar');
expect(executeCommandSpy).toHaveBeenCalledWith('yarn', [
'config',
'set',
'npmRegistryServer',
'https://foo.bar',
]);
});
});
describe('addDependencies', () => {
it('with devDep it should run `yarn install -D @storybook/addons`', () => {
const executeCommandSpy = jest.spyOn(yarn2Proxy, 'executeCommand').mockReturnValue('');

View File

@ -16,6 +16,11 @@ export class Yarn2Proxy extends JsPackageManager {
return `yarn ${command}`;
}
setRegistryURL(url: string) {
const args = ['config', 'set', 'npmRegistryServer', url];
this.executeCommand('yarn', args);
}
protected getResolutions(packageJson: PackageJson, versions: Record<string, string>) {
return {
resolutions: {