musicbrainz-api 0.20.2 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -473,27 +473,35 @@ async function getCoverArt(releaseGroupMbid, coverType = '') {
473
473
 
474
474
  ## CommonJS backward compatibility
475
475
 
476
- For legacy CommonJS projects needing to load the `music-metadata` ESM module, you can use the `loadMusicMetadata` function:
476
+ I recommend CommonJS projects to consider upgrading their project to ECMAScript Module (ESM).
477
+ Please continue reading how to use **musicbrainz-api** in a CommonJS project.
478
+
479
+ Using Node.js ≥ 22, which is support loading ESM module via require, you can use:
477
480
  ```js
478
- const { loadMusicBrainzApi } = require('musicbrainz-api');
481
+ const { MusicBrainzApi } = require('musicbrainz-api');
482
+ ```
479
483
 
480
- (async () => {
484
+ Other CommonJS projects have to use [dynamic import](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import) to load the **musicbrainz-api** pure ESM module:
485
+ ```js
486
+ async function run() {
487
+ // Dynamically loads the ESM module in a CommonJS project
488
+ const { MusicBrainzApi } = await import('musicbrainz-api');
489
+ };
481
490
 
482
- // Dynamically loads the ESM module in a CommonJS project
483
- const {MusicBrainzApi} = await loadMusicBrainzApi();
491
+ run();
492
+ ```
484
493
 
485
- const mbApi = new MusicBrainzApi({
486
- appName: 'my-app',
487
- appVersion: '0.1.0',
488
- appContactInfo: 'user@mail.org',
489
- });
494
+ This is known not to work in TypeScript CommonJS projects, as the TypeScript compiler, in my opinion,
495
+ incorrectly converts the [dynamic import](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import)
496
+ to `require()`. To perform the dynamic import in TypeScript, you can use [load-esm](https://github.com/Borewit/load-esm):
490
497
 
491
- const releaseList = await mbApi.search('release', {query: {barcode: 602537479870}});
492
- for(const release of releaseList.releases) {
493
- console.log(release.title);
494
- }
495
- })();
496
- ```
498
+ ```js
499
+ import {loadEsm} from 'load-esm';
497
500
 
498
- > [!NOTE]
499
- > The `loadMusicMetadata` function is experimental.
501
+ async function run() {
502
+ // Dynamically loads the ESM module in a TypeScript CommonJS project
503
+ const { MusicBrainzApi } = await loadEsm<typeof import('musicbrainz-api')>('musicbrainz-api');
504
+ };
505
+
506
+ run();
507
+ ```
@@ -1,6 +1,2 @@
1
1
  export * from './coverartarchive-api.js';
2
2
  export * from './musicbrainz-api.js';
3
- /**
4
- * CommonJS (only) function to load `musicbrainz-api` ESM module
5
- */
6
- export declare function loadMusicBrainzApi(): Promise<typeof import('musicbrainz-api')>;
package/package.json CHANGED
@@ -1,23 +1,21 @@
1
1
  {
2
2
  "name": "musicbrainz-api",
3
- "version": "0.20.2",
3
+ "version": "0.21.0",
4
4
  "description": "MusicBrainz API client for reading and submitting metadata",
5
5
  "exports": {
6
6
  "node": {
7
- "import": "./lib/entry-node.js",
8
- "require": "./lib/entry-node.cjs"
7
+ "types": "./lib/entry-node.d.ts",
8
+ "default": "./lib/entry-node.js"
9
9
  },
10
10
  "default": {
11
- "import": "./lib/entry-default.js",
12
- "require": "./lib/entry-default.cjs"
11
+ "types": "./lib/entry-default.d.ts",
12
+ "default": "./lib/entry-default.js"
13
13
  }
14
14
  },
15
- "types": "lib/index.d.ts",
15
+ "types": "lib/entry-default.d.ts",
16
16
  "files": [
17
17
  "lib/**/*.js",
18
- "lib/**/*.d.ts",
19
- "lib/entry-node.cjs",
20
- "lib/entry-default.cjs"
18
+ "lib/**/*.d.ts"
21
19
  ],
22
20
  "type": "module",
23
21
  "author": {
@@ -1,5 +0,0 @@
1
- // CommonJS entry point
2
- "use strict";
3
- module.exports = {
4
- loadMusicBrainzApi: () => import('./entry-default.js'),
5
- };
@@ -1,5 +0,0 @@
1
- // Node.js CommonJS entry point
2
- "use strict";
3
- module.exports = {
4
- loadMusicBrainzApi: () => import('./entry-node.js'),
5
- };