Skip to content

Commit f21efd1

Browse files
authored
fix: support require (libp2p#3449)
Add the `module-sync` field to the exports map for each module to support synchronous loading from CJS environments using `require`. This allows use by older projects that cannot or do not want to upgrade to ESM.
1 parent b30baa9 commit f21efd1

47 files changed

Lines changed: 135 additions & 71 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/config/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"exports": {
2727
".": {
2828
"types": "./dist/src/index.d.ts",
29-
"import": "./dist/src/index.js"
29+
"import": "./dist/src/index.js",
30+
"module-sync": "./dist/src/index.js"
3031
}
3132
},
3233
"scripts": {

packages/connection-encrypter-plaintext/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"exports": {
2727
".": {
2828
"types": "./dist/src/index.d.ts",
29-
"import": "./dist/src/index.js"
29+
"import": "./dist/src/index.js",
30+
"module-sync": "./dist/src/index.js"
3031
}
3132
},
3233
"scripts": {

packages/connection-encrypter-tls/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"exports": {
2727
".": {
2828
"types": "./dist/src/index.d.ts",
29-
"import": "./dist/src/index.js"
29+
"import": "./dist/src/index.js",
30+
"module-sync": "./dist/src/index.js"
3031
}
3132
},
3233
"scripts": {

packages/crypto/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,28 @@
4949
"exports": {
5050
".": {
5151
"types": "./dist/src/index.d.ts",
52-
"import": "./dist/src/index.js"
52+
"import": "./dist/src/index.js",
53+
"module-sync": "./dist/src/index.js"
5354
},
5455
"./ciphers": {
5556
"types": "./dist/src/ciphers/index.d.ts",
56-
"import": "./dist/src/ciphers/index.js"
57+
"import": "./dist/src/ciphers/index.js",
58+
"module-sync": "./dist/src/ciphers/index.js"
5759
},
5860
"./hmac": {
5961
"types": "./dist/src/hmac/index.d.ts",
60-
"import": "./dist/src/hmac/index.js"
62+
"import": "./dist/src/hmac/index.js",
63+
"module-sync": "./dist/src/hmac/index.js"
6164
},
6265
"./keys": {
6366
"types": "./dist/src/keys/index.d.ts",
64-
"import": "./dist/src/keys/index.js"
67+
"import": "./dist/src/keys/index.js",
68+
"module-sync": "./dist/src/keys/index.js"
6569
},
6670
"./webcrypto": {
6771
"types": "./dist/src/webcrypto/index.d.ts",
68-
"import": "./dist/src/webcrypto/index.js"
72+
"import": "./dist/src/webcrypto/index.js",
73+
"module-sync": "./dist/src/webcrypto/index.js"
6974
}
7075
},
7176
"scripts": {

packages/floodsub/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"exports": {
3535
".": {
3636
"types": "./dist/src/index.d.ts",
37-
"import": "./dist/src/index.js"
37+
"import": "./dist/src/index.js",
38+
"module-sync": "./dist/src/index.js"
3839
}
3940
},
4041
"scripts": {

packages/gossipsub/package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,28 @@
1313
"exports": {
1414
".": {
1515
"types": "./dist/src/index.d.ts",
16-
"import": "./dist/src/index.js"
17-
},
18-
"./metrics": {
19-
"types": "./dist/src/metrics.d.ts",
20-
"import": "./dist/src/metrics.js"
16+
"import": "./dist/src/index.js",
17+
"module-sync": "./dist/src/index.js"
2118
},
2219
"./message": {
2320
"types": "./dist/src/message/index.d.ts",
24-
"import": "./dist/src/message/index.js"
21+
"import": "./dist/src/message/index.js",
22+
"module-sync": "./dist/src/message/index.js"
23+
},
24+
"./metrics": {
25+
"types": "./dist/src/metrics.d.ts",
26+
"import": "./dist/src/metrics.js",
27+
"module-sync": "./dist/src/metrics.js"
2528
},
2629
"./score": {
2730
"types": "./dist/src/score/index.d.ts",
28-
"import": "./dist/src/score/index.js"
31+
"import": "./dist/src/score/index.js",
32+
"module-sync": "./dist/src/score/index.js"
2933
},
3034
"./types": {
3135
"types": "./dist/src/types.d.ts",
32-
"import": "./dist/src/types.js"
36+
"import": "./dist/src/types.js",
37+
"module-sync": "./dist/src/types.js"
3338
}
3439
},
3540
"typesVersions": {

packages/interface-compliance-tests/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,28 @@
4646
"exports": {
4747
".": {
4848
"types": "./dist/src/index.d.ts",
49-
"import": "./dist/src/index.js"
49+
"import": "./dist/src/index.js",
50+
"module-sync": "./dist/src/index.js"
5051
},
5152
"./connection-encryption": {
5253
"types": "./dist/src/connection-encryption/index.d.ts",
53-
"import": "./dist/src/connection-encryption/index.js"
54+
"import": "./dist/src/connection-encryption/index.js",
55+
"module-sync": "./dist/src/connection-encryption/index.js"
5456
},
5557
"./peer-discovery": {
5658
"types": "./dist/src/peer-discovery/index.d.ts",
57-
"import": "./dist/src/peer-discovery/index.js"
59+
"import": "./dist/src/peer-discovery/index.js",
60+
"module-sync": "./dist/src/peer-discovery/index.js"
5861
},
5962
"./stream-muxer": {
6063
"types": "./dist/src/stream-muxer/index.d.ts",
61-
"import": "./dist/src/stream-muxer/index.js"
64+
"import": "./dist/src/stream-muxer/index.js",
65+
"module-sync": "./dist/src/stream-muxer/index.js"
6266
},
6367
"./transport": {
6468
"types": "./dist/src/transport/index.d.ts",
65-
"import": "./dist/src/transport/index.js"
69+
"import": "./dist/src/transport/index.js",
70+
"module-sync": "./dist/src/transport/index.js"
6671
}
6772
},
6873
"scripts": {

packages/interface-internal/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"exports": {
3131
".": {
3232
"types": "./dist/src/index.d.ts",
33-
"import": "./dist/src/index.js"
33+
"import": "./dist/src/index.js",
34+
"module-sync": "./dist/src/index.js"
3435
}
3536
},
3637
"scripts": {

packages/interface/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"exports": {
3131
".": {
3232
"types": "./dist/src/index.d.ts",
33-
"import": "./dist/src/index.js"
33+
"import": "./dist/src/index.js",
34+
"module-sync": "./dist/src/index.js"
3435
}
3536
},
3637
"scripts": {

packages/interop/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"exports": {
3030
".": {
3131
"types": "./src/index.d.ts",
32-
"import": "./dist/src/index.js"
32+
"import": "./dist/src/index.js",
33+
"module-sync": "./dist/src/index.js"
3334
}
3435
},
3536
"scripts": {

0 commit comments

Comments
 (0)