Skip to content

Commit

Permalink
fix: fix auto detect local rc
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Oct 4, 2024
1 parent eecd813 commit 9cb4fa1
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,42 @@ import { hotUrlRegistrys, registryKeys, registrys } from "./constant.ts";

async function getConfigPath(local?: boolean) {
const rc = ".npmrc";
const detectLocal = local === undefined &&
(await exists(rc, { isFile: true }));
if (local || detectLocal) {

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

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

if (!hasLocalRc) {
return getHomeDirRc();
}

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

if (hasLocalRcRegistry) {
return rc;
}
return `${homedir().replaceAll("\\", "/")}/${rc}`;

return getHomeDirRc();

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

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

const hotUrlRegistry = hotUrlRegistrys[url];

if (hotUrlRegistry) {
return hotUrlRegistry;
}

return registryKeys.find((k) => registrys[k] === url);
}

export async function getConfig(local?: boolean) {
Expand Down

0 comments on commit 9cb4fa1

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy