async function addExportsToPackageJson() {
  const packageJsonPath = path.join(root, 'package.json')
  const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))

  for (const destination of EXPORTS) {
    packageJson.exports ??= {}
    packageJson.exports[`./${destination}`] = {
      import: {
        types: `./lib.esm/${destination}.d.ts`,
        default: `./lib.esm/${destination}.js`,
      },
      require: {
        types: `./lib.cjs/${destination}.d.ts`,
        default: `./lib.cjs/${destination}.js`,
      },
    }
  }

  await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
}
addExportsToPackageJson adds all entries from EXPORTS to the exports field of package.json,
so loaders and bundlers supporting the exports field can resolve them properly to either ESM or CommonJS.