From dd90f5037d0bb86bace6ee74ad3d4a6aa9bc45b4 Mon Sep 17 00:00:00 2001 From: Rongger <934004841@qq.com> Date: Mon, 4 Jul 2022 19:51:17 +0800 Subject: [PATCH] fix: cjs exports (#10) (#11) --- scripts/postbuild.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/postbuild.ts b/scripts/postbuild.ts index 9f186065..3e295667 100644 --- a/scripts/postbuild.ts +++ b/scripts/postbuild.ts @@ -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`)