# @e11community/token-exporter

> Find NPM auth tokens in HOME/.npmrc and export them as environment variables

Latest version **3.2.1** (published 2021-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @e11community/token-exporter
pnpm add @e11community/token-exporter
yarn add @e11community/token-exporter
bun add @e11community/token-exporter
```

Provides the commands `npmrc-export`, `npmrc-write-cwd`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2021-08-09 |
| First published | 2021-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Engineering 11 |
| Maintainers | todd-trimmer, dave.smith |
| Keywords | auth, token |

## Links

- npm: https://www.npmjs.com/package/@e11community/token-exporter
- Repository: https://github.com/e11community/token-exporter
- Homepage: https://github.com/e11community/token-exporter#readme
- Issues: https://github.com/e11community/token-exporter/issues
- npm.io page: https://npm.io/package/@e11community/token-exporter

## Dependencies (2)

- [typescript](https://npm.io/package/typescript.md) ^4.3.5
- [@types/node](https://npm.io/package/@types/node.md) ^16.4.10

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 3.2.1 (latest) — 2021-08-09

## README

# Overview

Find NPM auth tokens in **HOME/.npmrc** and export them as environment variables

# Installation

## Package

`npm install -g @e11community/token-exporter`

## Shell setup

In **HOME/.bashrc**, you have two options, and you *may do both*:

1. Use the node package to dynamically generate a bash script to source
2. Use your **personal access token** everywhere

```
# OPTION 1: dynamically generated tokens
if which npmrc-export 2>&1 >/dev/null; then
  . <(npmrc-export)
fi

# OPTION 2: personal access token
export NPM_AUTH_TOKEN=YourPersonalAccessTokenHere
```

# Project Usage

In **PROJECT_ROOT/.yarnrc.yml**, use environment variables instead of hard-coded tokens. It first tries to use the scope-specific token. If not found, it falls back to the personal access token. If neither is found, **yarn** throws an error.

```
npmScopes:
  e11community:
    npmAuthToken: ${E11COMMUNITY_NPM_AUTH_TOKEN:-$NPM_AUTH_TOKEN}
    npmPublishRegistry: "https://npm.pkg.github.com/e11community/"
    npmRegistryServer: "https://npm.pkg.github.com/e11community/"
  engineering11:
    npmAuthToken: ${ENGINEERING11_NPM_AUTH_TOKEN:-$NPM_AUTH_TOKEN}
    npmPublishRegistry: "https://npm.pkg.github.com/engineering11/"
    npmRegistryServer: "https://npm.pkg.github.com/engineering11/"
```

# Example

## Config

Given a **HOME/.npmrc** with redacted tokens:
```
@engineering11:registry=https://npm.pkg.github.com/engineering11/
//npm.pkg.github.com/engineering11/:_authToken=SecretForE11

@e11community:registry=https://npm.pkg.github.com/e11community/
//npm.pkg.github.com/e11community/:_authToken=SecretForCommunity

@bit:registry=https://node.bit.dev/
//node.bitsrc.io/:_authToken=SecretForBitProd
//node.bit.dev/:_authToken=SecretForBitDev

//npm.pkg.github.com/:_authToken=SecretForAllOfGitHub

registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=SecretForMainRegistry
```

## Expected Output

The **npmrc-export | sort** command *should* produce this script:

```
export BIT_NPM_AUTH_TOKEN='SecretForBitDev'
export E11COMMUNITY_NPM_AUTH_TOKEN='SecretForCommunity'
export ENGINEERING11_NPM_AUTH_TOKEN='SecretForE11'
```

# Write Local .npmrc

## Workflow for AppEngine Deploys
```
cd BACKEND_REPO/microservices/service-FOO/microservice/

cat template.yaml | envsubst > app.yaml

npmrc-write-cwd

gcloud app deploy app.yaml --project=PROJECT_ID
```

In **firebase.json**, in the **predeploy** array, put `npmrc-write-cwd`

## Notes

* **DO** put **.npmrc** in **.gitignore**
* Do **NOT** put **.npmrc** in **.gcloudignore**

---
_Source: https://npm.io/package/@e11community/token-exporter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
