Skip to content

Commit

Permalink
fix: default CJS exports (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Dec 1, 2023
1 parent 73cd738 commit f8d302c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
Expand All @@ -31,7 +31,7 @@
},
"./nuxt": {
"import": {
"types": "./dist/nuxt.d.ts",
"types": "./dist/nuxt.d.mts",
"default": "./dist/nuxt.mjs"
},
"require": {
Expand Down
14 changes: 3 additions & 11 deletions scripts/postbuild.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
import { readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'

function patchCjs(cjsModulePath: string, name: string) {
const cjsModule = readFileSync(cjsModulePath, 'utf-8')
writeFileSync(
cjsModulePath,
cjsModule.replace(`module.exports = ${name};`, `exports.default = ${name};`),
cjsModule.replace(`module.exports = ${name};`, `exports.default = ${name};\nexports.__esModule = true;`),
// cjsModule.replace(`module.exports = ${cjsName};`, `module.exports = ${cjsName};\nexports.default = ${cjsName};`),
{ encoding: 'utf-8' },
)
}

rmSync(resolve('./dist/index.d.mts'))
rmSync(resolve('./dist/nuxt.d.mts'))

readdirSync('./dist/shared')
.filter(file => file.endsWith('.d.mts'))
.forEach((file) => {
rmSync(resolve('./dist/shared', file))
})

patchCjs(resolve('./dist/index.cjs'), 'PluginInspect')
patchCjs(resolve('./dist/nuxt.cjs'), 'nuxt')

0 comments on commit f8d302c

Please sign in to comment.