Skip to content

Commit

Permalink
fix: 🔒 don't write the auth token in npmrc (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghusse authored Dec 31, 2021
1 parent 1da5ea7 commit 7669fce
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/authentifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("Authentifier", () => {
npm.authenticate(
{
registry: npmConfig.registry,
token: "token",
},
instance(context)
)
Expand Down
5 changes: 1 addition & 4 deletions src/authentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export class Authentifier {
throw new Error("NPM TOKEN needs to be set");
}

await this.npm.authenticate(
{ registry: npmConfig.registry, token: env.NPM_TOKEN },
context
);
await this.npm.authenticate({ registry: npmConfig.registry }, context);

logger.log("npm token set");
}
Expand Down
4 changes: 2 additions & 2 deletions src/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("npm", () => {
"config",
"set",
"//registry.npmjs.org/:_authToken",
"token",
"${NPM_TOKEN}",
"--json",
],
{
Expand All @@ -47,7 +47,7 @@ describe("npm", () => {
).thenResolve(undefined as any);

await npm.authenticate(
{ registry: "https://registry.npmjs.org", token: "token" },
{ registry: "https://registry.npmjs.org/" },
instance(context)
);

Expand Down
6 changes: 3 additions & 3 deletions src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export class Npm {
constructor(private readonly execa: Execa) {}

public async authenticate(
{ registry, token }: { registry: string; token: string },
{ registry }: { registry: string },
context: Context & Config
): Promise<void> {
const registryUrl = registry.replace(/^https?:/, "");
const registryUrl = registry.replace(/^https?:/, "").replace(/\/$/, "");
await this.runJsonNpm(
["config", "set", `${registryUrl}/:_authToken`, token],
["config", "set", `${registryUrl}/:_authToken`, "${NPM_TOKEN}"],
context
);
}
Expand Down

0 comments on commit 7669fce

Please sign in to comment.