Skip to content

Commit

Permalink
fix: correct cjs types export
Browse files Browse the repository at this point in the history
fixes #327
  • Loading branch information
KaelWD committed Feb 28, 2024
1 parent e391b18 commit 4512234
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "git+https://github.com/vuetifyjs/vuetify-loader.git"
},
"scripts": {
"build": "unbuild && node ../../scripts/patchCJS.mjs",
"build": "unbuild && node ../../scripts/patchCJS.mjs && node ../../scripts/patch.d.CJS.mjs",
"dev": "unbuild --stub"
},
"author": "Kael Watts-Deuchar",
Expand Down
35 changes: 35 additions & 0 deletions scripts/patch.d.CJS.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
It converts
```ts
export { vuePlugin as default };
```
to
```ts
export = vuePlugin;
export { vuePlugin as default };
```
*/

import { readFileSync, writeFileSync } from 'node:fs'
import colors from 'picocolors'

const files = ['dist/index.d.ts', 'dist/index.d.cts']

for (const indexPath of files) {
let code = readFileSync(indexPath, 'utf-8')

const matchMixed = code.match(/\nexport \{ (\w+) as default };/)
if (matchMixed) {
const name = matchMixed[1]

code = code.slice(0, matchMixed.index) + `\nexport = ${name};` + code.slice(matchMixed.index)

writeFileSync(indexPath, code)

console.log(colors.bold(`${indexPath} d.CJS patched`))
}
}

0 comments on commit 4512234

Please sign in to comment.