Skip to content

Commit d7e6a89

Browse files
authored
ESM/CSJ build & dependency reduction (#42)
* chore: support ESM/CJS builds and bump deps * fix: swap jsonwebtoken with jose - support esm/cjs treeshakable without transient dependencies to support various envs * fix: read version from package file - tsup and extracts version as constant from the json file * chore: swap to pnpm and use directly lib for example * chore: migrate tests to vitest * fix: use env-agnostic std libraries * chore(deps): build updates - example as pnpm-managed workspace - update dependencies - drop EOL node.js 18
1 parent 6026c47 commit d7e6a89

33 files changed

Lines changed: 3717 additions & 7184 deletions

.eslintrc.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/nodejs-ci.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,32 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [18.x, 20.x]
16+
node-version: [20.x, 22.x]
1717

1818
steps:
1919
- name: Repository checkout
2020
uses: actions/checkout@v4
21+
22+
- name: Install pnpm
23+
uses: pnpm/action-setup@v3
24+
2125
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v3.8.1
26+
uses: actions/setup-node@v4
2327
with:
2428
node-version: ${{ matrix.node-version }}
25-
- name: Install latest npm
26-
run: npm install -g npm
29+
cache: pnpm
30+
2731
- name: Install dependencies
28-
run: npm ci
32+
run: pnpm install
33+
2934
- name: Run lint
30-
run: npm run lint
35+
run: pnpm lint
36+
3137
- name: Run build
32-
run: npm run build
38+
run: pnpm build
39+
3340
- name: Run tests
34-
run: npm run test:coverage
41+
run: pnpm test:coverage
42+
3543
- name: Code coverage
3644
uses: codecov/codecov-action@v1

.github/workflows/npm-publish.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13-
- uses: actions/setup-node@v3.8.1
13+
- uses: pnpm/action-setup@v3
14+
- uses: actions/setup-node@v4
1415
with:
1516
node-version: 20
16-
- run: npm install
17-
- run: npm run test
17+
- run: pnpm install
18+
- run: pnpm test
1819

1920
publish-npm:
2021
needs: build
2122
runs-on: ubuntu-latest
2223
steps:
2324
- uses: actions/checkout@v4
24-
- uses: actions/setup-node@v3.8.1
25+
- uses: pnpm/action-setup@v3
26+
- uses: actions/setup-node@v4
2527
with:
2628
node-version: 20
2729
registry-url: https://registry.npmjs.org/
28-
- run: npm install
29-
- run: npm publish --access public
30+
- run: pnpm install
31+
- run: pnpm publish --access public
3032
env:
3133
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-manager-strict=false

.prettierrc.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ Duo especially thanks [Lukas Hroch](https://github.com/lukashroch) for creating
1212

1313
## Getting Started
1414

15-
This library requires Node.js v14 or later.
15+
This library requires Node.js LTS (v20 or later).
1616

17-
To use this client in your existing developing environment, install it from NPM
17+
To use this client in your existing developing environment, install it with your package manager of choice.
1818

1919
```sh
2020
npm install @duosecurity/duo_universal
21+
22+
pnpm add @duosecurity/duo_universal
23+
24+
yarn add @duosecurity/duo_universal
2125
```
2226

2327
Once it's installed, see our developer documentation at https://duo.com/docs/duoweb and the `example` folder in this repo for guidance on integrating Duo 2FA into your web application.
@@ -68,7 +72,7 @@ const state = client.generateState();
6872
Creates authentication URL to redirect user to Duo Security Universal prompt. Provide user identifier and state generated in previous step.
6973

7074
```ts
71-
const authUrl = client.createAuthUrl('username', 'state');
75+
const authUrl = await client.createAuthUrl('username', 'state');
7276
```
7377

7478
### 6. Token & code exchange
@@ -92,19 +96,19 @@ Fork the repository
9296
Install dependencies
9397

9498
```sh
95-
npm install
99+
pnpm install
96100
```
97101

98102
Make your proposed changes. Add tests if applicable, lint the code. Submit a pull request.
99103

100104
## Tests
101105

102106
```sh
103-
npm run test
107+
pnpm run test
104108
```
105109

106110
## Lint
107111

108112
```sh
109-
npm run lint
113+
pnpm run lint
110114
```

eslint.config.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import eslint from '@eslint/js';
2+
import tseslint from 'typescript-eslint';
3+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4+
5+
export default tseslint.config(
6+
eslint.configs.recommended,
7+
...tseslint.configs.recommended,
8+
eslintPluginPrettierRecommended,
9+
{
10+
rules: {
11+
'@typescript-eslint/no-explicit-any': 'warn',
12+
'@typescript-eslint/no-unused-vars': ['warn', { ignoreRestSiblings: true }],
13+
},
14+
},
15+
);

example/.eslintrc.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

example/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@ Navigate to example folder
1414
cd duo_universal_nodejs/example
1515
```
1616

17-
Install dependencies
18-
```
19-
npm install
20-
```
21-
2217
## Run the application
2318

2419
1. Copy the Client ID, Client Secret, and API Hostname values for your Web SDK application into `src/config.js`
2520

2621
2. Start the application
2722
```
28-
npm run start
23+
pnpm start
2924
```
3025

3126
3. Navigate to http://localhost:3000

0 commit comments

Comments
 (0)