Skip to content

Commit

Permalink
Fix tree-shaking (#2339) (closes #2207)
Browse files Browse the repository at this point in the history
Fixed broken tree-shaking caused by missing links to corresponding ESM.
  • Loading branch information
fturmel committed Apr 13, 2021
1 parent 4dd34a2 commit 0eac335
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions scripts/build/packages.js
Expand Up @@ -18,18 +18,23 @@ const rootPath =

const extraModules = [
{ fullPath: './src/fp/index.js' },
{ fullPath: './src/locale/index.js' }
{ fullPath: './src/locale/index.js' },
]

const initialPackages = getInitialPackages()
writePackages()

listAll()
.then(modules =>
Promise.all(modules.map(module => writePackage(module.fullPath)))
async function writePackages() {
const initialPackages = await getInitialPackages()
const modules = await listAll()
await Promise.all(
modules.map(async (module) =>
writePackage(module.fullPath, initialPackages[module.fullPath])
)
)
.then('package.json files are generated')
console.log('package.json files are generated')
}

function writePackage(fullPath) {
function writePackage(fullPath, initialPackage) {
const dirPath = path.dirname(fullPath)
const typingsRelativePath = path.relative(dirPath, `./src/typings.d.ts`)
const packagePath = path.resolve(
Expand All @@ -40,8 +45,8 @@ function writePackage(fullPath) {
return writeFile(
packagePath,
JSON.stringify(
Object.assign({ sideEffects: false }, initialPackages[fullPath] || {}, {
typings: typingsRelativePath
Object.assign({ sideEffects: false }, initialPackage || {}, {
typings: typingsRelativePath,
}),
null,
2
Expand Down Expand Up @@ -79,7 +84,7 @@ async function listAll() {
.concat(extraModules)
.reduce((acc, module) => {
const esmModule = Object.assign({}, module, {
fullPath: module.fullPath.replace('./src/', './src/esm/')
fullPath: module.fullPath.replace('./src/', './src/esm/'),
})
return acc.concat([module, esmModule])
}, [])
Expand Down

0 comments on commit 0eac335

Please sign in to comment.