Skip to content

Commit 53acfd0

Browse files
committed
feat: improve dist type
1 parent c4ad1a4 commit 53acfd0

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

build.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import fs from 'node:fs/promises'
2+
import { glob } from 'tinyglobby'
13
import { defineBuildConfig } from 'unbuild'
24

35
export default defineBuildConfig({
@@ -9,4 +11,19 @@ export default defineBuildConfig({
911
rollup: {
1012
emitCJS: true,
1113
},
14+
hooks: {
15+
'build:done': async () => {
16+
for (const file of await glob('./dist/*.d.{cts,mts,ts}')) {
17+
const content = await fs.readFile(file, 'utf-8')
18+
// Override `options` type on dist dts only
19+
const newContent = content.replace(
20+
'class MarkdownItAsync extends MarkdownIt {',
21+
'class MarkdownItAsync extends MarkdownIt {\n options: MarkdownItAsyncOptions',
22+
)
23+
if (content === newContent)
24+
throw new Error(`Failed to replace for ${file}`)
25+
await fs.writeFile(file, newContent, 'utf-8')
26+
}
27+
},
28+
},
1229
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"pnpm": "^9.15.4",
6464
"shiki": "^1.27.2",
6565
"simple-git-hooks": "^2.11.1",
66+
"tinyglobby": "^0.2.10",
6667
"typescript": "^5.7.3",
6768
"unbuild": "^3.3.1",
6869
"vite": "^6.0.7",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('markdown-it-async', async () => {
4444
const mda = createMarkdownItAsync()
4545

4646
mda.use((md) => {
47-
// @ts-expect-error cast, not yet have a solution to override this type
47+
// @ts-expect-error cast, patched in dist
4848
md.options.highlight = async (str, lang) => {
4949
return await codeToHtml(str, {
5050
lang,

0 commit comments

Comments
 (0)