Skip to content

Commit

Permalink
fix: cjs exports (#10) (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongger authored Jul 4, 2022
1 parent e3757b7 commit dd90f50
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions scripts/postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ async function run() {
for (const file of files) {
// eslint-disable-next-line no-console
console.log(chalk.cyan.inverse(' POST '), `Fix ${basename(file)}`)
if (file === 'index.js') {
// fix cjs exports
let code = await fs.readFile(file, 'utf8')
code = code.replace('exports.default =', 'module.exports =')
code += 'exports.default = module.exports;'
await fs.writeFile(file, code)
}
// fix cjs exports
let code = await fs.readFile(file, 'utf8')
code += 'if (module.exports.default) module.exports = module.exports.default;'
await fs.writeFile(file, code)
// generate submodule .d.ts redirecting
const name = basename(file, '.js')
await fs.writeFile(`${name}.d.ts`, `export { default } from './dist/${name}'\n`)
Expand Down

0 comments on commit dd90f50

Please sign in to comment.