Skip to content

Commit

Permalink
Fix cjs and esm dist export.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrizagidulin committed Aug 4, 2024
1 parent b20c245 commit 7fe6ab5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 53 deletions.
27 changes: 2 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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});

Expand Down
13 changes: 13 additions & 0 deletions build-dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mkdir ./dist/esm
cat >dist/esm/index.js <<!EOF
import cjsModule from '../index.js';
export const DEFAULT_HEADERS = cjsModule.DEFAULT_HEADERS;
export const httpClient = cjsModule.httpClient;
export const kyPromise = cjsModule.kyPromise;
!EOF

cat >dist/esm/package.json <<!EOF
{
"type": "module"
}
!EOF
31 changes: 19 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "@digitalbazaar/http-client",
"name": "@digitalcredentials/http-client",
"version": "4.1.2-0",
"description": "An opinionated, isomorphic HTTP client.",
"license": "BSD-3-Clause",
"type": "module",
"main": "./dist/cjs/index.cjs",
"main": "dist/index.js",
"module": "dist/esm/index.js",
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./lib/index.js"
".": {
"require": "./dist/index.js",
"import": "./dist/esm/index.js"
},
"./package.json": "./package.json"
},
"browser": {
"./lib/agentCompatibility.js": "./lib/agentCompatibility-browser.js",
Expand All @@ -17,14 +21,13 @@
"./lib/agentCompatibility.js": "./lib/agentCompatibility-browser.js"
},
"scripts": {
"rollup": "rollup -c rollup.config.js",
"rollup": "rollup -c rollup.config.js && ./build-dist.sh",
"build": "npm run clear && npm run rollup",
"clear": "rimraf dist/ && mkdir dist",
"prepare": "npm run build",
"rebuild": "npm run clear && npm run build",
"test": "npm run test-node && npm run test-node-cjs",
"test": "npm run test-node && npm run test-karma",
"test-node": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.js tests/*.spec.js",
"test-node-cjs": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.cjs tests/*.spec.cjs",
"test-karma": "karma start karma.conf.cjs",
"test-watch": "cross-env NODE_ENV=test mocha --watch --parallel --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.js tests/*.spec.js",
"coverage": "cross-env NODE_ENV=test c8 npm run test-node",
Expand All @@ -34,7 +37,11 @@
},
"files": [
"lib/*",
"dist/*"
"dist/*",
"rollup.config.js",
"build-dist.sh",
"README.md",
"LICENSE"
],
"dependencies": {
"ky": "^1.0.1",
Expand All @@ -60,13 +67,13 @@
"karma-sourcemap-loader": "^0.4.0",
"karma-webpack": "^5.0.0",
"mocha": "^10.2.0",
"rimraf": "^5.0.0",
"rimraf": "^6.0.1",
"rollup": "^3.20.2",
"webpack": "^5.79.0"
},
"repository": {
"type": "git",
"url": "https://github.com/digitalbazaar/http-client"
"url": "https://github.com/digitalcredentials/http-client"
},
"keywords": [
"http",
Expand All @@ -79,9 +86,9 @@
"url": "https://digitalbazaar.com/"
},
"bugs": {
"url": "https://github.com/digitalbazaar/http-client/issues"
"url": "https://github.com/digitalcredentials/http-client/issues"
},
"homepage": "https://github.com/digitalbazaar/http-client",
"homepage": "https://github.com/digitalcredentials/http-client",
"engines": {
"node": ">=18.0"
},
Expand Down
16 changes: 4 additions & 12 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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'])
}
];

0 comments on commit 7fe6ab5

Please sign in to comment.