Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudFlare workers support #247

Closed
Tahul opened this issue Oct 26, 2021 · 7 comments 路 Fixed by #557
Closed

CloudFlare workers support #247

Tahul opened this issue Oct 26, 2021 · 7 comments 路 Fixed by #557

Comments

@Tahul
Copy link

Tahul commented Oct 26, 2021

Hello @octref 馃槃

Thanks for this amazing project!

We are trying to use it as a syntax highlighter on the Docus project at NuxtLabs, which will most likely be ported as @nuxt/content v2 at some point.

We are using latest updates from Nuxt (Nuxt 3 beta and Nuxt Bridge) in that project, as this is made to be deployed on a CloudFlare worker environment.

While using Shiki, we encountered an issue in which it fallbacks to Node loader as it does not detect CloudFlare environment.

Here is the line that seem to be in cause:
https://github.com/shikijs/shiki/blob/main/packages/shiki/src/loader.ts#L49

Is CloudFlare Workers support planned for Shiki?

If so, maybe we could help on a PR supporting that use case!

cc: @farnabaz

@farnabaz
Copy link

farnabaz commented Nov 1, 2021

I manage to patch both shiki and onigasm and create rollup plugin for Nitro. But still there is an issue with WebAssembly memory.

Everything works fine with miniflare in simulated environment. But raise memory error in CF environment 馃
You can test it here: https://github.com/farnabaz/nuxt-shiki/tree/feat/cf-worker-detection

  • Clone the branch
  • Run yarn build
  • Run yarn start
  • Go to http://localhost:8787/api/test

Here is some info about patches:

  • I used WebSocketPair class to detect whether code is running in CF environment or not
  • Cloudflare does not support utf-16l text encoding

@WalrusSoup
Copy link

@farnabaz any progress since you started?

I recompiled the WASM with -s TEXTDECODER=0 \ but basically ran into a brick wall after that.

@octref octref added the question Further information is requested label Dec 24, 2021
@octref
Copy link
Collaborator

octref commented Dec 24, 2021

Hi @Tahul and @farnabaz, I take a quick look of CF workers, but I'm not super familiar with them.
Can you explain in more details how does your app with CF workers and shiki work? Also, how do you detect if a script is running in CF worker environment?

@Menci
Copy link

Menci commented Jan 11, 2022

I think we could add a method for the user to load WebAssembly module manually. Then CF Worker users could upload WASM file and load the module by new WebAssembly.Instance(UPLOADED_WASM_MODULE, {})

@octref octref added feature-request and removed question Further information is requested labels Jan 26, 2023
@antfu
Copy link
Member

antfu commented Aug 13, 2023

Made a fork rewrite https://github.com/antfu/shikiji that enables the CF support. Also opened proposal #510 to have them back to Shiki. Feedback appreciated ;)

@adamdehaven
Copy link

@antfu now that things are merged back to Shiki, is there any extra steps (e.g. creating a CF worker) needed to utilize Shiki highlighting via @nuxtjs/mdc when deploying to Cloudflare pages?

Everything works fine for me locally, but Shiki doesn't init for me when the page is deployed.

@adamdehaven
Copy link

Here's the open issue and linked reproduction: nuxt-modules/mdc#159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants