-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.config.ts
33 lines (32 loc) · 1.04 KB
/
build.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from 'node:fs/promises'
import { glob } from 'tinyglobby'
import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
entries: [
'src/index',
],
declaration: true,
clean: true,
hooks: {
'build:done': async () => {
for (const file of await glob('./dist/*.d.{cts,mts,ts}')) {
let content = await fs.readFile(file, 'utf-8')
// Override `options` type on dist dts only
let newContent = content.replace(
'class MarkdownItAsync extends MarkdownIt {',
'class MarkdownItAsync extends MarkdownIt {\n // @ts-ignore\n options: MarkdownItAsyncOptions',
)
if (content === newContent)
throw new Error(`Failed to replace for ${file}`)
content = newContent
newContent = content.replace(
'import MarkdownIt',
'import type MarkdownIt',
)
if (content === newContent)
throw new Error(`Failed to replace for ${file}`)
await fs.writeFile(file, newContent, 'utf-8')
}
},
},
})