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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to pass locateFile fn on Parser.init #659

Open
agniokas opened this issue May 16, 2024 · 2 comments
Open

Is there a way to pass locateFile fn on Parser.init #659

agniokas opened this issue May 16, 2024 · 2 comments

Comments

@agniokas
Copy link

There is a problem, when trying to host curlconverter in nextjs project, which is aknowleged by tree-sitter. It also has a solution (see below), however, i am not able to use it, i assume because, when curl converter initializes Parser, it overrides locateFunction.
For the moment, i relocate tree-sitter.wasm files to each page in .next/static/chunk/pages, but i would like a nicer solution to this. Is there a way?

#For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as http://localhost:3000/_next/static/chunks/pages/index.js. The loader will therefore look for the wasm file at http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm. The solution is to pass a locateFile function in the moduleOptions argument to Parser.init():

await Parser.init({
  locateFile(scriptName: string, scriptDirectory: string) {
    return scriptName;
  },
});
@verhovsky
Copy link
Member

You'll have to make a personal fork of curlconverter, sorry. I want to keep the interface simple.

Not exactly what you're asking, I but I tried making it look for the wasm files in a relative directory #649 but that doesn't work for https://curlconverter.com/ because you can open it like https://curlconverter.com/go/ (for example), which requests the wasm from https://curlconverter.com/go/tree-sitter.wasm which wouldn't work, unless we copy the wasm to each directory but I don't want to duplicate it like that...

@verhovsky
Copy link
Member

Another alternative would be replacing tree-sitter with https://github.com/withfig/lezer-bash

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

No branches or pull requests

2 participants