Skip to content

Commit c2796d4

Browse files
committed
fix: Publish in custom artifactory #424 with auth or authToken
1 parent 8669687 commit c2796d4

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

.changeset/sharp-lies-shop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/action": patch
3+
---
4+
5+
fix: Publish in custom artifactory #424 with `auth` or `authToken`

src/utils.test.ts

+40-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("extractAuthTokenLine", () => {
107107
it("should correctly find the auth token line for multiple registries", () => {
108108
const testCases = [
109109
{
110-
name: "Custom private registry",
110+
name: "Custom private registry with _authToken",
111111
npmrc: `
112112
registry=https://custom.private-registry.com/api/npm/npm/
113113
//custom.private-registry.com/api/npm/npm/:_authToken=abcd1234
@@ -116,15 +116,32 @@ describe("extractAuthTokenLine", () => {
116116
expected: "//custom.private-registry.com/api/npm/npm/:_authToken=abcd1234",
117117
},
118118
{
119-
name: "NPM default registry",
119+
name: "Custom private registry with _auth",
120+
npmrc: `
121+
registry=https://custom.private-registry.com/api/npm/npm/
122+
//custom.private-registry.com/api/npm/npm/:_auth=abcd1234
123+
always-auth=true
124+
`,
125+
expected: "//custom.private-registry.com/api/npm/npm/:_auth=abcd1234",
126+
},
127+
{
128+
name: "NPM default registry with _authToken",
120129
npmrc: `
121130
registry=https://registry.npmjs.org/
122131
//registry.npmjs.org/:_authToken=efgh5678
123132
`,
124133
expected: "//registry.npmjs.org/:_authToken=efgh5678",
125134
},
126135
{
127-
name: "AWS CodeArtifact registry",
136+
name: "NPM default registry with _auth",
137+
npmrc: `
138+
registry=https://registry.npmjs.org/
139+
//registry.npmjs.org/:_auth=efgh5678
140+
`,
141+
expected: "//registry.npmjs.org/:_auth=efgh5678",
142+
},
143+
{
144+
name: "AWS CodeArtifact registry with _authToken",
128145
npmrc: `
129146
registry=https://mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/
130147
//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_authToken=ijkl9012
@@ -133,14 +150,32 @@ describe("extractAuthTokenLine", () => {
133150
"//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_authToken=ijkl9012",
134151
},
135152
{
136-
name: "Azure DevOps registry",
153+
name: "AWS CodeArtifact registry with _auth",
154+
npmrc: `
155+
registry=https://mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/
156+
//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_auth=ijkl9012
157+
`,
158+
expected:
159+
"//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_auth=ijkl9012",
160+
},
161+
{
162+
name: "Azure DevOps registry with _authToken",
137163
npmrc: `
138164
registry=https://pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/
139165
//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_authToken=mnop3456
140166
`,
141167
expected:
142168
"//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_authToken=mnop3456",
143169
},
170+
{
171+
name: "Azure DevOps registry with _auth",
172+
npmrc: `
173+
registry=https://pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/
174+
//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_auth=mnop3456
175+
`,
176+
expected:
177+
"//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_auth=mnop3456",
178+
},
144179
];
145180

146181
testCases.forEach(({ name, npmrc, expected }) => {
@@ -157,4 +192,4 @@ describe("extractAuthTokenLine", () => {
157192
const result = extractAuthTokenLine(npmrcContent);
158193
expect(result).toBeUndefined();
159194
});
160-
});
195+
});

src/utils.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ export function sortTheThings(
105105
* @param {string} npmrcContent - The content of the .npmrc file as a string.
106106
* @returns {string | undefined} - The line containing the auth token or undefined if not found.
107107
*/
108-
export function extractAuthTokenLine(npmrcContent:string) {
108+
export function extractAuthTokenLine(npmrcContent: string) {
109109
/**
110110
* @see https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
111-
* Also dynamically adapt to any registry by looking for :_authToken= pattern
111+
* This regex dynamically adapts to any registry by looking for the :_auth or :_authToken= pattern.
112112
*/
113-
const line = npmrcContent.split("\n").find((line) => {
114-
return /^\s*\/\/.*\/:[_-]authToken=/i.test(line);
113+
const line = npmrcContent.split("\n").find((line) => {
114+
return /^\s*\/\/.*\/:(_auth|_authToken)=/i.test(line); // Match both _auth and _authToken
115115
});
116-
return line ? line.trim() : undefined;
116+
return line ? line.trim() : undefined;
117117
};

0 commit comments

Comments
 (0)