Skip to content

Commit

Permalink
fix(commonjs): fix broken commonjs import (#149)
Browse files Browse the repository at this point in the history
* Add integration test to ensure that the client can be instantiated in a commonjs environment
* Fix Readme on how to import the client in commonjs
* Publish nested package.json's for the browser and commonjs packages
* Inline node-fetch for the commonjs bundle (node-fetch@3 is ESM only)
  • Loading branch information
lionralfs authored Apr 30, 2023
1 parent 7f8a31f commit c363f82
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ jobs:
- run: npm run lint
- run: npm test
- run: npm run build
- run: cd test/commonjs && node index.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Here are some basic usage examples that connect with the public API. Error handl
import { DiscogsClient } from '@lionralfs/discogs-client';

// in commonjs environments
const DiscogsClient = require('@lionralfs/discogs-client/commonjs');
const { DiscogsClient } = require('@lionralfs/discogs-client/commonjs');

// in browser environments
import { DiscogsClient } from '@lionralfs/discogs-client/browser';
Expand Down
1 change: 0 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ build({
platform: 'node',
minify: false,
define: { 'process.env.VERSION_NUMBER': `'${PACKAGE.version}'` },
external: ['node-fetch'],
}).catch(err => console.error(err) || process.exit(1));
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
},
"files": [
"browser/index.js",
"browser/package.json",
"commonjs/index.js",
"commonjs/package.json",
"types",
"node-esm/index.js",
"lib/*",
Expand Down
7 changes: 7 additions & 0 deletions test/commonjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */
const { DiscogsClient } = require('../../commonjs');

let client = new DiscogsClient();
if (!(client instanceof DiscogsClient)) {
process.exit(1);
}
3 changes: 3 additions & 0 deletions test/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

0 comments on commit c363f82

Please sign in to comment.