Skip to content

Commit 4512234

Browse files
committed
fix: correct cjs types export
fixes #327
1 parent e391b18 commit 4512234

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/vite-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"url": "git+https://github.com/vuetifyjs/vuetify-loader.git"
1717
},
1818
"scripts": {
19-
"build": "unbuild && node ../../scripts/patchCJS.mjs",
19+
"build": "unbuild && node ../../scripts/patchCJS.mjs && node ../../scripts/patch.d.CJS.mjs",
2020
"dev": "unbuild --stub"
2121
},
2222
"author": "Kael Watts-Deuchar",

scripts/patch.d.CJS.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
3+
It converts
4+
5+
```ts
6+
export { vuePlugin as default };
7+
```
8+
9+
to
10+
11+
```ts
12+
export = vuePlugin;
13+
export { vuePlugin as default };
14+
```
15+
*/
16+
17+
import { readFileSync, writeFileSync } from 'node:fs'
18+
import colors from 'picocolors'
19+
20+
const files = ['dist/index.d.ts', 'dist/index.d.cts']
21+
22+
for (const indexPath of files) {
23+
let code = readFileSync(indexPath, 'utf-8')
24+
25+
const matchMixed = code.match(/\nexport \{ (\w+) as default };/)
26+
if (matchMixed) {
27+
const name = matchMixed[1]
28+
29+
code = code.slice(0, matchMixed.index) + `\nexport = ${name};` + code.slice(matchMixed.index)
30+
31+
writeFileSync(indexPath, code)
32+
33+
console.log(colors.bold(`${indexPath} d.CJS patched`))
34+
}
35+
}

0 commit comments

Comments
 (0)