Skip to content

Commit 6fd46c3

Browse files
committed
refactor: optimize onCurrent function
1 parent b54c249 commit 6fd46c3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

actions.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@ async function onList() {
3434

3535
async function onCurrent({ showUrl }) {
3636
const currentRegistry = await getCurrentRegistry();
37-
let usingUnknownRegistry = true;
3837
const registries = await getRegistries();
39-
for (const name in registries) {
40-
const registry = registries[name];
41-
if (isLowerCaseEqual(registry[REGISTRY], currentRegistry)) {
42-
usingUnknownRegistry = false;
43-
printMessages([`You are using ${chalk.green(showUrl ? registry[REGISTRY] : name)} registry.`]);
44-
}
45-
}
46-
if (usingUnknownRegistry) {
38+
39+
const matchedRegistry = Object.entries(registries).find(([_name, registry]) =>
40+
isLowerCaseEqual(registry[REGISTRY], currentRegistry),
41+
);
42+
43+
// not find equal registry
44+
if (!matchedRegistry) {
4745
printMessages([
4846
`Your current registry(${currentRegistry}) is not included in the nrm registries.`,
4947
`Use the ${chalk.green('nrm add <registry> <url> [home]')} command to add your registry.`,
5048
]);
49+
return;
5150
}
51+
52+
printMessages([
53+
`You are using ${chalk.green(showUrl ? matchedRegistry.registry[REGISTRY] : matchedRegistry.name)} registry.`,
54+
]);
5255
}
5356

5457
async function onUse(name) {

0 commit comments

Comments
 (0)