Skip to content

Commit

Permalink
feat: fallback to using the Azure CLI (#11)
Browse files Browse the repository at this point in the history
<!-- 👋 Hi, thanks for sending a PR to ado-npm-auth-lite! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [ ] Addresses an existing open issue: fixes #10
- [ ] That issue was marked as [`status: accepting
prs`](https://github.com/johnnyreilly/ado-npm-auth-lite/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [ ] Steps in
[CONTRIBUTING.md](https://github.com/johnnyreilly/ado-npm-auth-lite/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

<!-- Description of what is changed and how the code change does that.
-->
Falls back to using the AZ CLI with execa if the initial attempt fails. 

Output looks like this:

```sh
┌  📦🔑 Welcome to ado-npm-auth-lite 0.5.0! 📦🔑
│
│
●  options:
│  - pat: [NONE SUPPLIED - WILL ACQUIRE FROM AZURE API]
│  - config: ./ignore/.npmrc
│  - email: [NONE SUPPLIED - WILL USE DEFAULT]
│
│
●  Loading .npmrc at: /home/john/code/github/ado-npm-auth-lite/ignore/.npmrc
│
●  Parsed: 
│  - organisation: johnnyreilly
│  - urlWithoutRegistryAtStart: //pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/
│  - urlWithoutRegistryAtEnd: //pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/
◇  ✅ Passed parsing project .npmrc.
│
│
●  Creating Azure CLI Token
◓  Creating Personal Access Token..│
●  Creating Personal Access Token with API: {
│    "displayName": "made by ado-npm-auth-lite at: 2024-11-10T17:41:11.033Z",
│    "scope": "vso.packaging",
│    "validTo": "2024-12-10T17:41:11.033Z",
│    "allOrgs": false
│  }
◓  Creating Personal Access Token...│
■  Error creating Personal Access Token with API: HTTP error! status: 401 - {"$id":"1","innerException":null,"message":"TF401444: Please sign-in at least once as Windows Live ID\\johnny_reilly@hotmail.com in a web browser to enable access to the service.","typeName":"Microsoft.TeamFoundation.Framework.Server.UnauthorizedRequestException, Microsoft.TeamFoundation.Framework.Server","typeKey":"UnauthorizedRequestException","errorCode":0,"eventId":3000}
│
●  Will re-attempt with Azure CLI
│
●  Creating Personal Access Token with Azure CLI: {
│    "displayName": "made by ado-npm-auth-lite at: 2024-11-10T17:41:11.033Z",
│    "scope": "vso.packaging",
│    "validTo": "2024-12-10T17:41:11.033Z",
│    "allOrgs": false
│  }
◒  Creating Personal Access Token.│
●  Created Personal Access Token with Azure CLI
◇  ✅ Passed creating Personal Access Token.
│
◇  ✅ Passed constructing user .npmrc.
│
│
●  Writing users .npmrc to: /home/john/.npmrc
◇  ✅ Passed writing user .npmrc.
│
└  📦🔑 Thanks for using ado-npm-auth-lite 0.5.0! 📦🔑
```
  • Loading branch information
johnnyreilly authored Nov 10, 2024
1 parent 0a89880 commit 1e10db2
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 32 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@clack/prompts": "^0.7.0",
"chalk": "^5.3.0",
"ci-info": "^4.0.0",
"execa": "^9.5.1",
"zod": "^3.23.8",
"zod-validation-error": "^3.3.1"
},
Expand Down
103 changes: 103 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as prompts from "@clack/prompts";
import chalk from "chalk";
import ci from "ci-info";
import path from "node:path";
import { parseArgs } from "node:util";
import { fromZodError } from "zod-validation-error";

Expand Down Expand Up @@ -97,7 +98,9 @@ export async function bin(args: string[]) {
try {
const parsedProjectNpmrc = await withSpinner(`Parsing project .npmrc`, () =>
parseProjectNpmrc({
config,
npmrcPath: config
? path.resolve(config)
: path.resolve(process.cwd(), ".npmrc"),
logger,
}),
);
Expand Down
Loading

0 comments on commit 1e10db2

Please sign in to comment.