Skip to content

Commit

Permalink
feat: Initial implementation
Browse files Browse the repository at this point in the history
Initial implementation. When run it does this:

<img width="637" alt="screenshot of output"
src="https://github.com/user-attachments/assets/d0f20c72-2c2e-4685-ab36-48a76d64b0ac">
  • Loading branch information
johnnyreilly authored Nov 7, 2024
1 parent 5a155fc commit 51a8a29
Show file tree
Hide file tree
Showing 41 changed files with 1,637 additions and 105 deletions.
15 changes: 0 additions & 15 deletions .all-contributorsrc

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
- uses: ./.github/actions/prepare
- run: pnpm build
- run: node ./lib/index.js

lint:
name: Lint
runs-on: ubuntu-latest
Expand All @@ -15,13 +16,15 @@ jobs:
- uses: ./.github/actions/prepare
- run: pnpm build
- run: pnpm lint

prettier:
name: Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm format --list-different

test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -30,6 +33,7 @@ jobs:
- uses: ./.github/actions/prepare
- run: pnpm run test --coverage
- uses: codecov/codecov-action@v3

type_check:
name: Type Check
runs-on: ubuntu-latest
Expand All @@ -38,6 +42,15 @@ jobs:
- uses: ./.github/actions/prepare
- run: pnpm tsc

are_the_types_wrong:
name: Are the types wrong?
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm build
- run: npx --yes @arethetypeswrong/cli --pack . --ignore-rules cjs-resolves-to-esm

name: CI

on:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
lib/
node_modules/
ignore/
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" },
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.rulers": [80],
"eslint.probe": [
"javascript",
"javascriptreact",
Expand Down
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,60 @@
<p align="center">Set up local authentication to Azure DevOps npm feeds</p>

<p align="center">
<a href="https://github.com/johnnyreilly/ado-npm-auth-lite/actions/workflows/release.yml" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://github.com/johnnyreilly/ado-npm-auth-lite/actions/workflows/release.yml/badge.svg" /></a>
<a href="https://github.com/johnnyreilly/ado-npm-auth-lite/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
<a href="https://codecov.io/gh/johnnyreilly/ado-npm-auth-lite" target="_blank"><img alt="🧪 Coverage" src="https://img.shields.io/codecov/c/github/johnnyreilly/ado-npm-auth-lite?label=%F0%9F%A7%AA%20coverage" /></a>
<a href="https://github.com/johnnyreilly/ado-npm-auth-lite/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg"></a>
<a href="http://npmjs.com/package/ado-npm-auth-lite"><img alt="📦 npm version" src="https://img.shields.io/npm/v/ado-npm-auth-lite?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
<img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
</p>

## Usage

To use `ado-npm-auth-lite` do this:

```shell
npm i ado-npm-auth-lite
az login
npx --yes ado-npm-auth-lite --config .npmrc
```

```ts
import { greet } from "ado-npm-auth-lite";
Typically `ado-npm-auth-lite` will be used as part of a `preinstall` script in your `package.json`:

greet("Hello, world! 💖");
```json
"scripts": {
"preinstall": "az login && npx --yes ado-npm-auth-lite"
},
```

This will ensure that the necessary authentication is set up before any `npm install` commands are run.

The `az login` command will prompt you to log in to Azure, so that a token may be acquired. It is not necessary to run this command if you are already logged in. The `config` is optional, and if not supplied will default to the `.npmrc` in the project directory. Crucially, `ado-npm-auth-lite` requires the project `.npmrc` in order to operate.

## Why Azure DevOps npm auth-lite?

Azure DevOps provides a mechanism for publishing npm packages for private use. This package sets up the necessary authentication to access those packages; particularly for non Windows users.

Consider the onboarding process for a Windows user:

![screenshot of the onboarding process for Windows users](screenshot-onboarding-with-windows.png)

Now consider the onboarding process for a non Windows user:

![screenshot of the onboarding process for non Windows users](screenshot-onboarding-with-other.png)

This is a significant difference in the onboarding experience. `ado-npm-auth-lite` aims to make the onboarding experience for non Windows users as simple as it is for Windows users.

There is an official package named [`ado-npm-auth`](https://github.com/microsoft/ado-npm-auth). However, due to issues experienced in using that package, this was created.

## Options

`-c` | `--config` (`string`): The location of the .npmrc file. Defaults to current directory

`-e` | `--email` (`string`): Allows users to supply an explicit email - if not supplied, will be inferred from git user.config

`-h` | `--help`: Show help

`-v` | `--version`: Show version

<!-- You can remove this notice if you don't want it 🙂 no worries! -->

> 💙 This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app).
4 changes: 4 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
import { bin } from "../lib/bin/index.js";

process.exitCode = await bin(process.argv.slice(2));
47 changes: 31 additions & 16 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,51 @@ export default tseslint.config(
},
},
rules: {
// These on-by-default rules work well for this repo if configured
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
// These on-by-default rules don't work well for this repo and we like them off.
"jsdoc/lines-before-block": "off",

// These off-by-default rules work well for this repo and we like them on.
"logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
],
"operator-assignment": "error",

// These on-by-default rules don't work well for this repo and we like them off.
"jsdoc/lines-before-block": "off",
"no-constant-condition": "off",

// These on-by-default rules work well for this repo if configured
"@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }],
"n/no-unsupported-features/node-builtins": [
"error",
{ allowExperimental: true },
],
"perfectionist/sort-objects": [
"error",
{
order: "asc",
partitionByComment: true,
type: "natural",
},
],

"no-constant-condition": "off",
// Stylistic concerns that don't interfere with Prettier
"no-useless-rename": "error",
"object-shorthand": "error",
// "perfectionist/sort-objects": [
// "error",
// {
// order: "asc",
// partitionByComment: true,
// type: "natural",
// },
// ],

"operator-assignment": "error",
"perfectionist/sort-objects": ["off"],
"perfectionist/sort-object-types": ["off"],

"jsdoc/match-description": "off",
},
}),
{
Expand Down
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ado-npm-auth-lite",
"version": "0.0.0",
"version": "0.1.0",
"description": "Set up local authentication to Azure DevOps npm feeds",
"repository": {
"type": "git",
Expand All @@ -12,10 +12,17 @@
"email": "johnny_reilly@hotmail.com"
},
"type": "module",
"main": "./lib/index.js",
"bin": "bin",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
}
},
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"bin": "./bin/index.js",
"files": [
"bin",
"bin/index.js",
"lib/",
"package.json",
"LICENSE.md",
Expand All @@ -26,12 +33,20 @@
"format": "prettier .",
"lint": "eslint . --max-warnings 0",
"prepare": "husky",
"start": "pnpm run build && node ./bin/index.js",
"test": "vitest",
"tsc": "tsc"
},
"lint-staged": {
"*": "prettier --ignore-unknown --write"
},
"dependencies": {
"@azure/identity": "^4.5.0",
"@clack/prompts": "^0.7.0",
"chalk": "^5.3.0",
"zod": "^3.23.8",
"zod-validation-error": "^3.3.1"
},
"devDependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
"@eslint/js": "^9.14.0",
Expand Down
Loading

0 comments on commit 51a8a29

Please sign in to comment.