diff --git a/change/change-e750e299-3f52-4757-8968-fb45d7ecf356.json b/change/change-e750e299-3f52-4757-8968-fb45d7ecf356.json new file mode 100644 index 00000000..98146bfc --- /dev/null +++ b/change/change-e750e299-3f52-4757-8968-fb45d7ecf356.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "type": "patch", + "comment": "Fix circular promise in fetchTokens", + "packageName": "@microsoft/yarn-plugin-ado-auth", + "email": "masplund@microsoft.com", + "dependentChangeType": "patch" + } + ] +} \ No newline at end of file diff --git a/packages/yarn-plugin-ado-auth/src/tokenCache.ts b/packages/yarn-plugin-ado-auth/src/tokenCache.ts index 2ed8e979..ff624dee 100644 --- a/packages/yarn-plugin-ado-auth/src/tokenCache.ts +++ b/packages/yarn-plugin-ado-auth/src/tokenCache.ts @@ -58,6 +58,8 @@ export class TokenCache { */ private async fetchToken(registry: string, ident?: Ident): Promise { const configuration = this.configuration; + let token: string | null = null; + await StreamReport.start( { configuration, stdout: process.stdout }, async (report) => { @@ -70,6 +72,7 @@ export class TokenCache { const authConfig = this.getAuthConfiguration(registry, ident); const tokenFromYarnrc = getConfigString(authConfig, "npmAuthToken"); if (tokenFromYarnrc) { + token = tokenFromYarnrc; this.cache[registry] = tokenFromYarnrc; report.reportInfo( null, @@ -91,6 +94,7 @@ export class TokenCache { false, this.azureAuthPath, ); + token = pat; this.cache[registry] = pat; report.reportInfo( null, @@ -99,11 +103,10 @@ export class TokenCache { }, ); - const pat = this.cache[registry]; - if (pat == null) { + if (token == null) { throw new Error(`Failed to authenticate to: ${registry}`); } - return pat; + return token; } /**