Skip to content

Commit

Permalink
Reset commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brwai committed Oct 3, 2024
1 parent 34c4536 commit d86362e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
11 changes: 11 additions & 0 deletions change/change-56e39eed-6d9b-4763-8660-c2230bd7c0f1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "minor",
"comment": "Add custom user config file",
"packageName": "ado-npm-auth",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
9 changes: 8 additions & 1 deletion 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;
userConfigFile?: string;
}

export function parseArgs(args: string[]): Args {
Expand All @@ -21,8 +22,13 @@ export function parseArgs(args: string[]): Args {
configFile: {
alias: "c",
type: "string",
description: "Skip checking the validity of the feeds",
description: "Custom workspace config file path",
},
userConfigFile: {
alias: "u",
type: "string",
description: "Custom user config file path",
}
})
.help()
.parseSync();
Expand All @@ -31,5 +37,6 @@ export function parseArgs(args: string[]): Args {
skipAuth: argv.skipAuth || false,
doValidCheck: !argv.skipCheck,
configFile: argv.configFile,
userConfigFile: argv.userConfigFile
};
}
4 changes: 2 additions & 2 deletions packages/ado-npm-auth/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { YarnRcFileProvider } from "./yarnrc/yarnrcFileProvider.js";

export const run = async (args: Args): Promise<null | boolean> => {
const fileProviders = [
new NpmrcFileProvider(args.configFile),
new YarnRcFileProvider(args.configFile),
new NpmrcFileProvider(args.configFile, args.userConfigFile),
new YarnRcFileProvider(args.configFile, args.userConfigFile),
];

const validatedFeeds: ValidatedFeed[] = [];
Expand Down
11 changes: 8 additions & 3 deletions packages/ado-npm-auth/src/fileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export abstract class FileProvider {
public id: string,
public workspaceFileName: string,
configFile?: string,
userConfigFile?: string,
) {
let workspaceFilePath = undefined;
if (configFile && path.basename(configFile) === this.workspaceFileName) {
Expand All @@ -50,9 +51,13 @@ export abstract class FileProvider {
}
this.workspaceFilePath = workspaceFilePath;

const userHome =
process.env["HOME"] || process.env["USERPROFILE"] || homedir() || "";
this.userFilePath = join(userHome, workspaceFileName);
if (userConfigFile && path.basename(userConfigFile) === this.workspaceFileName) {
this.userFilePath = userConfigFile;
} else {
const userHome =
process.env["HOME"] || process.env["USERPROFILE"] || homedir() || "";
this.userFilePath = join(userHome, workspaceFileName);
}
this.feeds = new Map<string, Feed>();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ado-npm-auth/src/npmrc/npmrcFileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { fromBase64, toBase64 } from "../utils/encoding.js";
import path from "node:path";

export class NpmrcFileProvider extends FileProvider {
constructor(configFile?: string) {
super("NpmRc", ".npmrc", configFile);
constructor(configFile?: string, userConfigFile?: string) {
super("NpmRc", ".npmrc", configFile, userConfigFile);
}

override async prepUserFile(): Promise<void> {
Expand Down
11 changes: 8 additions & 3 deletions packages/ado-npm-auth/src/yarnrc/yarnrcFileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { getOrganizationFromFeedUrl } from "../utils/get-organization-from-feed-
import { getFeedWithoutProtocol } from "../utils/get-feed-without-protocol.js";

export class YarnRcFileProvider extends FileProvider {
constructor(configFile?: string) {
super("YarnRc", ".yarnrc.yml", configFile);
constructor(configFile?: string, userConfigFile?: string) {
super("YarnRc", ".yarnrc.yml", configFile, userConfigFile);
}

override async prepUserFile(): Promise<void> {
// no need to do anything
try {
await fs.readFile(this.userFilePath, "utf-8");
} catch (error) {
// user yarnrc does not exist so make an empty one
await fs.writeFile(this.userFilePath, "");
}
}

override async getUserFeeds(): Promise<Map<string, Feed>> {
Expand Down
Empty file modified packages/node-azureauth/scripts/azureauth.cjs
100644 → 100755
Empty file.

0 comments on commit d86362e

Please sign in to comment.