fix(core): simplify cloudflare wasm loading#670
Conversation
✅ Deploy Preview for shiki-matsu ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for shiki-next ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [shiki](https://github.com/shikijs/shiki) ([source](https://github.com/shikijs/shiki/tree/HEAD/packages/shiki)) | [`1.3.0` -> `1.5.1`](https://renovatebot.com/diffs/npm/shiki/1.3.0/1.5.1) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>shikijs/shiki (shiki)</summary> ### [`v1.5.1`](https://github.com/shikijs/shiki/releases/tag/v1.5.1) [Compare Source](https://github.com/shikijs/shiki/compare/v1.5.0...v1.5.1) ##### 🐞 Bug Fixes - **core**: Simplify cloudflare wasm loading - by [@​hi-ogawa](https://github.com/hi-ogawa) in [https://github.com/shikijs/shiki/issues/670](https://github.com/shikijs/shiki/issues/670) [<samp>(cd239)</samp>](https://github.com/shikijs/shiki/commit/cd239324) ##### [View changes on GitHub](https://github.com/shikijs/shiki/compare/v1.5.0...v1.5.1) ### [`v1.5.0`](https://github.com/shikijs/shiki/releases/tag/v1.5.0) [Compare Source](https://github.com/shikijs/shiki/compare/v1.4.0...v1.5.0) ##### 🚀 Features - Upgrade deps, new langs - by [@​antfu](https://github.com/antfu) [<samp>(d5b04)</samp>](https://github.com/shikijs/shiki/commit/d5b04703) ##### [View changes on GitHub](https://github.com/shikijs/shiki/compare/v1.4.0...v1.5.0) ### [`v1.4.0`](https://github.com/shikijs/shiki/releases/tag/v1.4.0) [Compare Source](https://github.com/shikijs/shiki/compare/v1.3.0...v1.4.0) ##### 🚀 Features - Upgrade deps, new langs and themes - by [@​antfu](https://github.com/antfu) [<samp>(26f37)</samp>](https://github.com/shikijs/shiki/commit/26f37f08) ##### 🐞 Bug Fixes - **core**: Check existance of `Buffer.isBuffer`, fix [#​664](https://github.com/shikijs/shiki/issues/664) - by [@​NullVoxPopuli](https://github.com/NullVoxPopuli) in [https://github.com/shikijs/shiki/issues/666](https://github.com/shikijs/shiki/issues/666) and [https://github.com/shikijs/shiki/issues/664](https://github.com/shikijs/shiki/issues/664) [<samp>(86d52)</samp>](https://github.com/shikijs/shiki/commit/86d5271e) - **monaco**: Options for tokenize limit - by [@​hddhyq](https://github.com/hddhyq), [@​antfu](https://github.com/antfu) and **Anthony Fu** in [https://github.com/shikijs/shiki/issues/657](https://github.com/shikijs/shiki/issues/657) [<samp>(a606d)</samp>](https://github.com/shikijs/shiki/commit/a606d449) - **transformers**: Allow SQL comment syntax in notation transformer, fix [#​654](https://github.com/shikijs/shiki/issues/654) - by [@​senicko](https://github.com/senicko) in [https://github.com/shikijs/shiki/issues/655](https://github.com/shikijs/shiki/issues/655) and [https://github.com/shikijs/shiki/issues/654](https://github.com/shikijs/shiki/issues/654) [<samp>(cc135)</samp>](https://github.com/shikijs/shiki/commit/cc13539e) ##### [View changes on GitHub](https://github.com/shikijs/shiki/compare/v1.3.0...v1.4.0) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ariakit/ariakit). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjM0MC4xMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
|
Tried all sorts of different ways but unable to get this working on Cloudflare with 1.5.2. Is there a Cloudflare example to plug & play deploy? results in
|
|
@wouterds Did you follow https://shiki.style/guide/install#cloudflare-workers? Note that As written in the description, there is https://github.com/shikijs/shiki/blob/main/packages/shiki/test/cf.ts to test it out locally. |
|
Sorry I should have clarified that I'm using Remix with Cloudflare Pages. Eventually I got it working in a similar fashion wouterds/wouterds.com@fedec70 locally. However, my deploy to Cloudflare "succeeds" ( I would assume it's some size limitation on the free plan, but even that seems weird as the total size of the build folder is around 3 MB and the biggest file 300 KB, which is well below Cloudflare stated limits. Edit: hopefully this gives some more insights once merged cloudflare/workers-sdk#5819 Edit 2: turns out it indeed the bundle was too large Edit 3: managed to work around it by loading shiki from esm.sh wouterds/wouterds.com@aba12a2 Edit 4: wrote about it https://wouterds.be/blog/code-highlighting-with-shiki-keeping-your-cloudflare-worker-bundle-small |

Description
It looks like the exact usage of
loadWasm(import('shiki/onig.wasm'))shown in the documentation doesn't work currently https://shiki.style/guide/install#cloudflare-workers.There is actually a different way to load wasm directly
WebAssembly.instantiateas demonstrated inpackages/shiki/test/cf.tsand it works. However, this usage seems a little more convoluted, so I'm suggesting to improveloadWasmutility to supportloadWasm(import('shiki/onig.wasm')usage like in the documentation.shiki/packages/shiki/test/cf.ts
Line 11 in 044181d
I tested locally with
pnpm -C packages/shiki test:cf, but It looks like this is not checked on CI.Please let me know if it's desired to have some integration test for cloudflare usage.
Linked Issues
#604
Additional context
I was experimenting with shiki on Vite SSR demo https://github.com/hi-ogawa/reproductions/tree/main/shiki-604-cloudflare and currently my
loadWasmlooks like a following since I need to switch toimport("shiki/onig.wasm")only on cloudflare build:With this PR's patch, I would be able to always write
await loadWasm(import("shiki/wasm"))then setupaliasor custom resolution to switch to"shiki/onig.wasmhi-ogawa/reproductions#7.