Skip to content

Commit

Permalink
fix: build single commonjs output while keeping ability to use import…
Browse files Browse the repository at this point in the history
… or require (#320)

Signed-off-by: Francisco Javier Ribo Labrador <elribonazo@gmail.com>
Signed-off-by: Curtish <ch@curtish.me>
Co-authored-by: Curtis <curtis.harding@iohk.io>
Co-authored-by: Curtish <ch@curtish.me>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent fbd5358 commit 2cdbf1e
Show file tree
Hide file tree
Showing 10 changed files with 711 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ jobs:
- name: Run coverage test
run: npm run coverage

- name: Test integration node-cjs
working-directory: integration-tests/node/cjs
run: npm i && node test.cjs

- name: Test integration node-esm
working-directory: integration-tests/node/esm
run: npm i && node test.mjs

- name: Npm audit
uses: oke-py/npm-audit-action@v2.4.4
with:
Expand Down
20 changes: 6 additions & 14 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,22 @@ const generic = {
platform: 'neutral',
splitting: false,
resolveExtensions: ['.ts', '.js', '.wasm'],
inject: ['anoncreds-wasm', 'didcomm-wasm', 'jwe-wasm'],
mainFields: ['module', 'main'],
banner: {
js: bufferShim,
},
target: ['esnext'],
define: {
'global.Buffer': 'Buffer',
},
banner: {
js: bufferShim,
},
external: ['buffer']
};

(async () => {
await esbuild.build({
...generic,
outfile: "build/index.mjs",
target: ['esnext'],
format: 'esm',
plugins
})
await esbuild.build({
...generic,
entryPoints: ['./build/index.mjs'],
outfile: "build/index.cjs",
target: ['es6'],
outdir: "build",
inject: ['anoncreds-wasm', 'didcomm-wasm', 'jwe-wasm'],
format: 'cjs',
plugins
})
Expand Down
2 changes: 1 addition & 1 deletion index.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./build/index.cjs')
module.exports = require('./build/index.js')
2 changes: 1 addition & 1 deletion index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as SDK from './build/index.mjs';
import SDK from './build/index.js';

export default SDK
143 changes: 143 additions & 0 deletions integration-tests/node/cjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions integration-tests/node/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@identus-edge-agent-sdk/integration-tests-cjs",
"version": "0.0.0",
"private": true,
"devDependencies": {
"sdk": "file:../../../"
},
"engines": {
"node": ">=18"
}
}
Loading

2 comments on commit 2cdbf1e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 75%
76.07% (3632/4774) 66.49% (1665/2504) 80.29% (864/1076)

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 75%
76.14% (3635/4774) 66.53% (1666/2504) 80.29% (864/1076)

Please sign in to comment.