fix(api): correctly merge pkg exports in after-build.js script (#1609)

This commit is contained in:
Amr Bashir
2021-04-24 14:43:29 +02:00
committed by GitHub
parent 10e5996bfa
commit ba208b7e9b

View File

@@ -13,25 +13,29 @@ const modules = readdirSync('src').map((mod) => mod.replace('.ts', ''))
if (!pkg.exports) {
pkg.exports = {}
}
const outputPkg = Object.assign(
pkg.exports,
...modules.map((mod) => {
let temp = {}
let key = `./${mod}`
if (mod === 'index') {
key = '.'
}
temp[key] = {
import: `./${mod}.js`,
require: `./${mod}.cjs`
}
return temp
}),
// if for some reason in the future we manually add something in the `exports` field
// this will ensure it doesn't get overwritten by the logic above
{ ...pkg.exports }
)
const outputPkg = {
...pkg,
exports: Object.assign(
{},
...modules.map((mod) => {
let temp = {}
let key = `./${mod}`
if (mod === 'index') {
key = '.'
}
temp[key] = {
import: `./${mod}.js`,
require: `./${mod}.cjs`
}
return temp
}),
// if for some reason in the future we manually add something in the `exports` field
// this will ensure it doesn't get overwritten by the logic above
{ ...pkg.exports }
)
}
writeFileSync('dist/package.json', JSON.stringify(outputPkg, undefined, 2))
/**