Skip to content

Commit

Permalink
perf: simplify registry acquisition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Jun 20, 2023
1 parent e803774 commit 0d3b129
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,14 @@ export async function ensureGetConfigPath(local = false) {

export const registryReg = /(?<=registry=).*/;

function parseRegistry(text: string) {
const [registry] = registryReg.exec(text) || [];
return registry ?? "npm";
}

export function getConfigRegistry(configText: string) {
const registry = parseRegistry(configText);
return registryKeys.find((k) => {
if (k === registry) {
return registry;
}
return registrys[k] === registry;
}) ?? registry;
const [url] = registryReg.exec(configText) || [];
return registryKeys.find((k) => registrys[k] === url);
}

export async function getConfig(local?: boolean) {
const configPath = await ensureGetConfigPath(local);
const configText = await Deno.readTextFile(configPath);
const configRegistry = getConfigRegistry(configText);
const configRegistry = getConfigRegistry(configText) ?? "npm";
return { configPath, configRegistry, configText };
}

0 comments on commit 0d3b129

Please sign in to comment.