Skip to content

Commit

Permalink
fix: simplify getConfigPath
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Oct 27, 2024
1 parent 95b0ba1 commit e1ee873
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@ import { hotUrlRegistrys, registryKeys, registrys } from "./constant.ts";
async function getConfigPath(local?: boolean) {
const rc = ".npmrc";

if (local === true) {
return rc;
}

const hasLocalRc = await exists(rc, { isFile: true });

if (!hasLocalRc) {
if (local === undefined) {
if (await exists(rc, { isFile: true })) {
return rc;
}
return getHomeDirRc();
}

const hasLocalRcRegistry = await Deno.readTextFile(rc).then((text) => {
return text.includes("registry");
});

if (hasLocalRcRegistry) {
return rc;
}

return getHomeDirRc();
return local ? rc : getHomeDirRc();

function getHomeDirRc() {
return `${homedir().replaceAll("\\", "/")}/${rc}`;
Expand Down

0 comments on commit e1ee873

Please sign in to comment.