shikijs / shiki

A beautiful yet powerful syntax highlighter
http://shiki.style/
MIT License
9.91k stars 361 forks source link

Optimization suggestions for the 'hast' type in Shiki.js #713

Closed NWYLZW closed 2 months ago

NWYLZW commented 3 months ago

Validations

Describe the bug

While using Shiki, I encountered some issues that prevented me from correctly introducing certain type information into Shiki derivatives. Firstly, when I attempted to pass the correct type to the transformer, I found that Shiki/Core does not export the relevant types (related to 'hast'). The types I needed were bundled into the output instead of being an external dependency, although this behavior differs in other secondary applications. Here, I briefly investigated the package dependencies and potential issues involved.

These cases can be categorized as follows:

I would like to see if there is a better way to handle this or if there are any other suggestions. If possible, I would like to fix this issue myself.

Reproduction

undefined

Contributes

antfu commented 3 months ago

I would love to see a minimal reproduction repo where you encounter the error to further discuss the potential solutions.

@shikijs/core does not deps on hast in any form in the final bundle, as @types/hast get inlined into our bundle.

@shikijs/rehype does dep on hast, which we have the @types/hast in the dependencies already.

From high level I see the current behavior makes sense

NWYLZW commented 2 months ago

Hi, antfu. Thank you very much for your work on this issue. This fix has resolved my problem.

However, I found that twoslash also has this problem. I had written the code a couple of days ago and was ready to provide a fix for the hast type issue today. But I discovered that you have already solved it, hahaha. I will provide a fix for twoslash to shiki later.