Skip to content

Add npm package using napi-rs #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open

Add npm package using napi-rs #182

wants to merge 60 commits into from

Conversation

remorses
Copy link

@remorses remorses commented Jun 19, 2025

Fix #6

The npm package is currently published as @xmorse/markdown-rs

This npm package will also support WASM. Most of the CI has been ported from the oxc-resolver package.

Still a WIP, the exported functions need to be thought out better, for now I am experimenting.

Things to do before merge:

  • re-enable windows builds
  • rename from @xmorse/markdown-rs to markdown-rs (or other available name)
  • fix benchmark, which now does not work because of a Vitest bench bug, all benchmarks take 0ms

@wooorm
Copy link
Owner

wooorm commented Jun 20, 2025

Wow, cool work! It’s a lot, will take some time to review. And, also I am sure you can find stuff if you self-review.
Do you have any questions for me? Anything you want me to look at?

@remorses
Copy link
Author

Here is the benchmark result on the Zod v3 mdx documentation

clk: ~3.25 GHz
cpu: Apple M2 Pro
runtime: node 24.2.0 (arm64-darwin)

benchmark                           avg (min … max) p75 / p99    (min … top 1%)
--------------------------------------------------- -------------------------------
markdown-rs parse                     16.33 ms/iter  16.57 ms             █▄
                              (15.29 ms … 17.08 ms)  17.04 ms        ▅ ▅ ▅██ ▅  ▅
                            (  1.21 mb …   1.22 mb)   1.21 mb ▅▁▁▁▅█▅█▅█▁█████▅▅█▁█

remark parse                          42.02 ms/iter  43.75 ms ██
                              (39.96 ms … 46.92 ms)  46.26 ms ██
                            ( 10.46 mb …  44.35 mb)  15.31 mb ███▁██▁▁▁▁▁▁█▁▁▁▁█▁▁█

summary
  markdown-rs parse
   2.57x faster than remark parse

--------------------------------------------------- -------------------------------
markdown-rs parse without parsing js  16.14 ms/iter  16.31 ms          █
                              (15.63 ms … 16.81 ms)  16.64 ms      ▅ ▅▅█ ▅  ▅ ▅
                            (  1.21 mb …   1.21 mb)   1.21 mb ▅▅█▅▁█▅████████▁█▅▁▅▅

remark parse                          41.73 ms/iter  41.63 ms    █
                              (39.68 ms … 47.57 ms)  45.96 ms █ ██
                            (841.99 kb …  14.55 mb)  11.21 mb █▁█████▁▁▁▁█▁▁▁▁▁▁▁▁█

summary
  markdown-rs parse without parsing js
   2.59x faster than remark parse

--------------------------------------------------- -------------------------------
markdown-rs html                       7.86 ms/iter   8.03 ms         ▃ █▃
                                (7.34 ms … 8.29 ms)   8.29 ms     ▃█▆▃█▃███ ▃▃ ▃ ▃▃
                            (186.48 kb … 186.64 kb) 186.51 kb ▄▆▄▁█████████████████

remark html                           41.38 ms/iter  42.53 ms     █
                              (39.16 ms … 46.77 ms)  43.76 ms ▅▅▅▅█ ▅ ▅  ▅   ▅ ▅  ▅
                            (  6.65 mb …  14.85 mb)  12.03 mb █████▁█▁█▁▁█▁▁▁█▁█▁▁█

summary
  markdown-rs html
   5.27x faster than remark html

@remorses
Copy link
Author

Notice that the bigger files like index.js and browser.js are generated by NAPI-RS

The important parts live in the lib.rs file. That is the interface exported to the npm package. You can also take a look at the tests, which mostly consist of inline snapshots.

@remorses remorses marked this pull request as ready for review June 20, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

napi bindings? wasm?
2 participants