Skip to content

Commit

Permalink
feat: support org scoped npmrc (#26)
Browse files Browse the repository at this point in the history
<!-- 👋 Hi, thanks for sending a PR to azdo-npm-auth! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [x] Addresses an existing open issue: fixes #25
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/johnnyreilly/azdo-npm-auth/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/johnnyreilly/azdo-npm-auth/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

<!-- Description of what is changed and how the code change does that.
-->
This PR adds support for org scoped registry entries as described in #25
  • Loading branch information
johnnyreilly authored Dec 10, 2024
1 parent a88fad9 commit 54ef22d
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 54ef22d

Please sign in to comment.