Skip to content

Commit

Permalink
Add exports to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Feb 4, 2024
1 parent 26fe4a5 commit e9b6c46
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-roses-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Added `exports` field to `package.json` for better ESM interop
4 changes: 4 additions & 0 deletions config/entryPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ exports.map = function map(callback, context) {
return entryPoints.map(callback, context);
};

exports.reduce = function (callback, context) {
return entryPoints.reduce(callback, context);
};

const path = require("path").posix;

exports.check = function (id, parentId) {
Expand Down
21 changes: 21 additions & 0 deletions config/prepareDist.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ delete packageJson.scripts;
delete packageJson.bundlesize;
delete packageJson.engines;

packageJson.exports = {
".": {
types: packageJson.types,
import: packageJson.module,
require: packageJson.main,
},
"./package.json": {
default: "./package.json",
},
...entryPoints.reduce((acc, { dirs, bundleName = dirs[dirs.length - 1] }) => {
if (!dirs.length) return acc;
let path = `./${dirs.join("/")}`;
acc[path] = {
types: `${path}/index.d.ts`,
import: `${path}/index.js`,
require: `${path}/${bundleName}.cjs`,
};
return acc;
}, {}),
}

// The root package.json points to the CJS/ESM source in "dist", to support
// on-going package development (e.g. running tests, supporting npm link, etc.).
// When publishing from "dist" however, we need to update the package.json
Expand Down

0 comments on commit e9b6c46

Please sign in to comment.