Skip to content

Commit

Permalink
feat: support org scoped npmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyreilly committed Dec 10, 2024
1 parent a88fad9 commit b6e9cca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/projectNpmrcParse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ describe("projectNpmrcParse", () => {
it("outputs the expected structure on successful parse", async () => {
mockReadFile.mockResolvedValue(`registry=https://pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/
always-auth=true`);
const result = await projectNpmrcParse({
npmrcPath: "/home/john/code/github/azdo-npm-auth/.npmrc",
});
expect(result).toEqual({
organization: "johnnyreilly",
urlWithoutRegistryAtEnd:
"//pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/",
urlWithoutRegistryAtStart:
"//pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/",
});
});

it("outputs the expected structure on successful parse with org scope", async () => {
mockReadFile.mockResolvedValue(`@myorg:registry=https://pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/
always-auth=true`);
const result = await projectNpmrcParse({
npmrcPath: "/home/john/code/github/azdo-npm-auth/.npmrc",
Expand Down
6 changes: 3 additions & 3 deletions src/projectNpmrcParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export async function projectNpmrcParse({
throw new Error(`No .npmrc found at: ${npmrcPath}`);
}

const regex = /^registry=.*$/gm;
const match = npmrcContents.match(regex);
const regex = /^(?:@[\w-]+:)?registry=(.*)$/m;
const match = regex.exec(npmrcContents);

if (!match || match.length === 0) {
throw new Error(`Unable to extract information from project .npmrc`);
}

const registry = match[0].replace("registry=", "").trim();
const registry = match[1].trim();

return makeFromRegistry({ registry, logger });
}

0 comments on commit b6e9cca

Please sign in to comment.