Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 7e56c8e

Browse files
authored
fix: when scope is provided use proper separator (#457)
1 parent b59840d commit 7e56c8e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/utils/cli-utils.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SyntheticEvent } from 'react';
22

3-
import { copyToClipBoardUtility } from './cli-utils';
3+
import { copyToClipBoardUtility, getCLISetConfigRegistry } from './cli-utils';
44

55
describe('copyToClipBoardUtility', () => {
66
let originalGetSelection;
@@ -47,3 +47,18 @@ describe('copyToClipBoardUtility', () => {
4747
expect(spys.removeChild).toHaveBeenCalledWith(expectedDiv);
4848
});
4949
});
50+
51+
describe('getCLISetRegistry', () => {
52+
const command = 'npm set';
53+
const scope = '@testscope';
54+
const blankScope = '';
55+
const url = 'https://test.local';
56+
57+
test('should return ":" separated string when scope is set', () => {
58+
expect(getCLISetConfigRegistry(command, scope, url)).toEqual(`${command} ${scope}:registry ${url}`);
59+
});
60+
61+
test('should not output scope when scope is not set', () => {
62+
expect(getCLISetConfigRegistry(command, blankScope, url)).toEqual(`${command} registry ${url}`);
63+
});
64+
});

src/utils/cli-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const copyToClipBoardUtility = (str: string): ((e: SyntheticEvent<HTMLEle
2121
};
2222

2323
export function getCLISetConfigRegistry(command: string, scope: string, registryUrl: string): string {
24-
return `${command} ${scope}registry ${registryUrl}`;
24+
// if there is a scope defined there needs to be a ":" separator between the scope and the registry
25+
return `${command} ${scope}${scope !== '' ? ':' : ''}registry ${registryUrl}`;
2526
}
2627

2728
export function getCLISetRegistry(command: string, registryUrl: string): string {

0 commit comments

Comments
 (0)