Skip to content

Commit d86362e

Browse files
committed
Reset commit
1 parent 34c4536 commit d86362e

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"type": "minor",
5+
"comment": "Add custom user config file",
6+
"packageName": "ado-npm-auth",
7+
"email": "[email protected]",
8+
"dependentChangeType": "patch"
9+
}
10+
]
11+
}

packages/ado-npm-auth/src/args.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface Args {
55
doValidCheck: boolean;
66
skipAuth: boolean;
77
configFile?: string;
8+
userConfigFile?: string;
89
}
910

1011
export function parseArgs(args: string[]): Args {
@@ -21,8 +22,13 @@ export function parseArgs(args: string[]): Args {
2122
configFile: {
2223
alias: "c",
2324
type: "string",
24-
description: "Skip checking the validity of the feeds",
25+
description: "Custom workspace config file path",
2526
},
27+
userConfigFile: {
28+
alias: "u",
29+
type: "string",
30+
description: "Custom user config file path",
31+
}
2632
})
2733
.help()
2834
.parseSync();
@@ -31,5 +37,6 @@ export function parseArgs(args: string[]): Args {
3137
skipAuth: argv.skipAuth || false,
3238
doValidCheck: !argv.skipCheck,
3339
configFile: argv.configFile,
40+
userConfigFile: argv.userConfigFile
3441
};
3542
}

packages/ado-npm-auth/src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { YarnRcFileProvider } from "./yarnrc/yarnrcFileProvider.js";
1111

1212
export const run = async (args: Args): Promise<null | boolean> => {
1313
const fileProviders = [
14-
new NpmrcFileProvider(args.configFile),
15-
new YarnRcFileProvider(args.configFile),
14+
new NpmrcFileProvider(args.configFile, args.userConfigFile),
15+
new YarnRcFileProvider(args.configFile, args.userConfigFile),
1616
];
1717

1818
const validatedFeeds: ValidatedFeed[] = [];

packages/ado-npm-auth/src/fileProvider.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export abstract class FileProvider {
4040
public id: string,
4141
public workspaceFileName: string,
4242
configFile?: string,
43+
userConfigFile?: string,
4344
) {
4445
let workspaceFilePath = undefined;
4546
if (configFile && path.basename(configFile) === this.workspaceFileName) {
@@ -50,9 +51,13 @@ export abstract class FileProvider {
5051
}
5152
this.workspaceFilePath = workspaceFilePath;
5253

53-
const userHome =
54-
process.env["HOME"] || process.env["USERPROFILE"] || homedir() || "";
55-
this.userFilePath = join(userHome, workspaceFileName);
54+
if (userConfigFile && path.basename(userConfigFile) === this.workspaceFileName) {
55+
this.userFilePath = userConfigFile;
56+
} else {
57+
const userHome =
58+
process.env["HOME"] || process.env["USERPROFILE"] || homedir() || "";
59+
this.userFilePath = join(userHome, workspaceFileName);
60+
}
5661
this.feeds = new Map<string, Feed>();
5762
}
5863

packages/ado-npm-auth/src/npmrc/npmrcFileProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { fromBase64, toBase64 } from "../utils/encoding.js";
1313
import path from "node:path";
1414

1515
export class NpmrcFileProvider extends FileProvider {
16-
constructor(configFile?: string) {
17-
super("NpmRc", ".npmrc", configFile);
16+
constructor(configFile?: string, userConfigFile?: string) {
17+
super("NpmRc", ".npmrc", configFile, userConfigFile);
1818
}
1919

2020
override async prepUserFile(): Promise<void> {

packages/ado-npm-auth/src/yarnrc/yarnrcFileProvider.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import { getOrganizationFromFeedUrl } from "../utils/get-organization-from-feed-
66
import { getFeedWithoutProtocol } from "../utils/get-feed-without-protocol.js";
77

88
export class YarnRcFileProvider extends FileProvider {
9-
constructor(configFile?: string) {
10-
super("YarnRc", ".yarnrc.yml", configFile);
9+
constructor(configFile?: string, userConfigFile?: string) {
10+
super("YarnRc", ".yarnrc.yml", configFile, userConfigFile);
1111
}
1212

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

1722
override async getUserFeeds(): Promise<Map<string, Feed>> {

packages/node-azureauth/scripts/azureauth.cjs

100644100755
File mode changed.

0 commit comments

Comments
 (0)