Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support org scoped npmrc #26

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
}
Loading