Skip to content

Commit

Permalink
Merge branch 'main' into pr/Fix52
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvv authored Dec 27, 2024
2 parents 72c82a4 + baad56c commit cb3ef86
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
11 changes: 11 additions & 0 deletions change/change-9e2cbc00-db38-4fa4-8649-6ce6980de155.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "Add support to pass an override for azureAuthLocation on the commandline",
"packageName": "ado-npm-auth",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
11 changes: 11 additions & 0 deletions change/change-a91d72df-b1f7-4fb5-8632-3f0e3e68c110.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "Allow non azure devops feeds to be present in the configuration.",
"packageName": "ado-npm-auth",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
15 changes: 15 additions & 0 deletions packages/ado-npm-auth/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{
"name": "ado-npm-auth",
"entries": [
{
"date": "Fri, 27 Dec 2024 20:26:44 GMT",
"version": "0.3.1",
"tag": "ado-npm-auth_v0.3.1",
"comments": {
"none": [
{
"author": "[email protected]",
"package": "ado-npm-auth",
"commit": "760870e1f16885663cbc202e64db4ca3114db3ca",
"comment": "fix formatting of accidentally merged pr"
}
]
}
},
{
"date": "Wed, 30 Oct 2024 20:31:48 GMT",
"version": "0.3.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/ado-npm-auth/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Args {
doValidCheck: boolean;
skipAuth: boolean;
configFile?: string;
azureAuthLocation?: string;
}

export function parseArgs(args: string[]): Args {
Expand All @@ -23,6 +24,10 @@ export function parseArgs(args: string[]): Args {
type: "string",
description: "Skip checking the validity of the feeds",
},
azureAuthLocation: {
type: "string",
description: "Allow specifying alternate location to azureauth"
}
})
.help()
.parseSync();
Expand All @@ -31,5 +36,6 @@ export function parseArgs(args: string[]): Args {
skipAuth: argv.skipAuth || false,
doValidCheck: !argv.skipCheck,
configFile: argv.configFile,
azureAuthLocation: argv.azureAuthLocation,
};
}
6 changes: 4 additions & 2 deletions packages/ado-npm-auth/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const run = async (args: Args): Promise<null | boolean> => {
}
}

const invalidFeeds = validatedFeeds.filter((feed) => !feed.isValid);
// Filter to feeds to only feeds that were not authenticated and are actually
// azure devops feeds by checking if we discovered the adoOrganization for it.
const invalidFeeds = validatedFeeds.filter((feed) => !feed.isValid && feed.feed.adoOrganization);
const invalidFeedCount = invalidFeeds.length;

if (args.doValidCheck && invalidFeedCount == 0) {
Expand Down Expand Up @@ -57,7 +59,7 @@ export const run = async (args: Args): Promise<null | boolean> => {
// get a token for each feed
const organizationPatMap: Record<string, string> = {};
for (const adoOrg of adoOrgs) {
organizationPatMap[adoOrg] = await generateNpmrcPat(adoOrg, false);
organizationPatMap[adoOrg] = await generateNpmrcPat(adoOrg, false, args.azureAuthLocation);
}

// Update the pat in the invalid feeds.
Expand Down
19 changes: 17 additions & 2 deletions packages/ado-npm-auth/src/yarnrc/yarnrcFileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ export class YarnRcFileProvider extends FileProvider {
}

override async prepUserFile(): Promise<void> {
// no need to do anything
try {
const yarnrc = await this.paseYarnRc(this.userFilePath);

// remove the entry for registries in the user-level .npmrc
if (yarnrc && yarnrc.npmRegistryServer) {
delete yarnrc.npmRegistryServer;
await this.writeYarnRc(this.userFilePath, yarnrc);
}
} catch (error) {
// user .yarnrc file does not exist so make an empty one
await fs.writeFile(this.userFilePath, "");
}
}

override async getUserFeeds(): Promise<Map<string, Feed>> {
Expand Down Expand Up @@ -86,8 +97,12 @@ export class YarnRcFileProvider extends FileProvider {
yarnrc.npmRegistries[yarnRcYamlKey] = entry;
}

await this.writeYarnRc(this.userFilePath, yarnrc);
}

async writeYarnRc(filePath: string, yarnrc: YarnRc) {
const yarnrcContent = yaml.dump(yarnrc);
await fs.writeFile(this.userFilePath, yarnrcContent);
await fs.writeFile(filePath, yarnrcContent, "utf8");
}

async paseYarnRc(filePath: string): Promise<YarnRc> {
Expand Down

0 comments on commit cb3ef86

Please sign in to comment.