Skip to content

Commit d933b56

Browse files
committed
Add exports to package.json
Fixes apollographql#11569 apollographql#9925
1 parent 26fe4a5 commit d933b56

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.changeset/green-roses-flow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Added `exports` field to `package.json` for better ESM interop

config/entryPoints.js

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ exports.map = function map(callback, context) {
5151
return entryPoints.map(callback, context);
5252
};
5353

54+
exports.reduce = function (callback, context) {
55+
return entryPoints.reduce(callback, context);
56+
};
57+
5458
const path = require("path").posix;
5559

5660
exports.check = function (id, parentId) {

config/prepareDist.js

+21
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ delete packageJson.scripts;
3838
delete packageJson.bundlesize;
3939
delete packageJson.engines;
4040

41+
packageJson.exports = {
42+
".": {
43+
types: packageJson.types,
44+
import: packageJson.module,
45+
require: packageJson.main,
46+
},
47+
"./package.json": {
48+
default: "./package.json",
49+
},
50+
...entryPoints.reduce((acc, { dirs, bundleName = dirs[dirs.length - 1] }) => {
51+
if (!dirs.length) return acc;
52+
const path = `./${dirs.join("/")}`;
53+
acc[path] = {
54+
types: `${path}/index.d.ts`,
55+
import: `${path}/index.js`,
56+
require: `${path}/${bundleName}.cjs`,
57+
};
58+
return acc;
59+
}, {}),
60+
}
61+
4162
// The root package.json points to the CJS/ESM source in "dist", to support
4263
// on-going package development (e.g. running tests, supporting npm link, etc.).
4364
// When publishing from "dist" however, we need to update the package.json

0 commit comments

Comments
 (0)