From 7fe6ab59278de8cf4c7cc4c8fb0903eb833e46f4 Mon Sep 17 00:00:00 2001 From: Dmitri Zagidulin Date: Sat, 3 Aug 2024 20:05:46 -0400 Subject: [PATCH] Fix cjs and esm dist export. --- .github/workflows/main.yml | 27 ++------------------------- README.md | 10 ++++++---- build-dist.sh | 13 +++++++++++++ package.json | 31 +++++++++++++++++++------------ rollup.config.js | 16 ++++------------ 5 files changed, 44 insertions(+), 53 deletions(-) create mode 100755 build-dist.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c10ce15..c699e4a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: timeout-minutes: 10 strategy: matrix: - node-version: [18.x, 20.x] + node-version: [20.x] steps: - uses: actions/checkout@v3 - name: Install with Node.js 20.x @@ -38,11 +38,9 @@ jobs: node-version: ${{ matrix.node-version }} - name: Run ESM test with Node.js ${{ matrix.node-version }} run: npm run test-node - - name: Run CJS test with Node.js ${{ matrix.node-version }} - run: npm run test-node-cjs test-karma: runs-on: ubuntu-latest - needs: [lint, test-node] + needs: [lint] timeout-minutes: 10 strategy: matrix: @@ -56,24 +54,3 @@ jobs: - run: npm install - name: Run karma tests run: npm run test-karma - coverage: - needs: [test-node, test-karma] - runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - node-version: [20.x] - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - name: Generate coverage report - run: npm run coverage-ci - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - file: ./coverage/lcov.info - fail_ci_if_error: true diff --git a/README.md b/README.md index d19a1b8..bb4b920 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,24 @@ # http-client -An opinionated, isomorphic HTTP client for Node.js, browsers, and React Native. +[![NPM Version](https://img.shields.io/npm/v/@digitalcredentials/http-client.svg)](https://npm.im/@digitalcredentials/http-client) + +> An opinionated, isomorphic HTTP client for Node.js, browsers, and React Native. ### Usage #### Import httpClient (Node.js) ```js import https from 'https'; -import {httpClient} from '@digitalbazaar/http-client'; +import {httpClient} from '@digitalcredentials/http-client'; ``` #### Import httpClient (browsers or React Native) ```js -import {httpClient} from '@digitalbazaar/http-client'; +import {httpClient} from '@digitalcredentials/http-client'; ``` #### Import and initialize a custom Bearer Token client ```js -import {httpClient} from '@digitalbazaar/http-client'; +import {httpClient} from '@digitalcredentials/http-client'; const httpsAgent = new https.Agent({rejectUnauthorized: false}); diff --git a/build-dist.sh b/build-dist.sh new file mode 100755 index 0000000..e295c5d --- /dev/null +++ b/build-dist.sh @@ -0,0 +1,13 @@ +mkdir ./dist/esm +cat >dist/esm/index.js <dist/esm/package.json <=18.0" }, diff --git a/rollup.config.js b/rollup.config.js index f08fbaa..0906eb7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,24 +1,16 @@ import pkg from './package.json' assert {type: 'json'}; -function preserveDynamicImportPlugin() { - return { - name: 'preserve-dynamic-import', - renderDynamicImport() { - return {left: 'import(', right: ')'}; - } - }; -} - export default [ { input: './lib/index.js', output: [ { - file: 'dist/cjs/index.cjs', - format: 'cjs' + dir: 'dist', + + format: 'cjs', + preserveModules: true } ], - plugins: [preserveDynamicImportPlugin()], external: Object.keys(pkg.dependencies).concat(['crypto', 'util']) } ];