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

curlconverter by default consider server root path for 'tree-sitter-bash.wasm' file #617

Open
eknathyadav opened this issue Jan 4, 2024 · 2 comments

Comments

@eknathyadav
Copy link

Dear Team,

Is there any way I could customize the path? Rather than considering the server root path (i.e http://127.0.0.1:8000/tree-sitter-bash.wasm) for 'tree-sitter-bash.wasm file, is there any possibility that I can specify my customized path? The thing is I don't want to serve that file from the server root path.

@verhovsky
Copy link
Member

There is no way currently, you would have to fork the repo and change these two lines

await Parser.init();
const Bash = await Parser.Language.load("/tree-sitter-bash.wasm");

to something like

await Parser.init({
  locateFile(scriptName: string, scriptDirectory: string) {
    return '/some/other/path/tree-sitter.wasm';
  },
});
const Bash = await Parser.Language.load("/some/other/path/tree-sitter-bash.wasm");

The reason a way to pass these file names hasn't been implemented is so the normal usecase is simpler, you can just do

import * as curlconverter from 'curlconverter';

curlconverter.toPython('curl example.com');

instead of having to do

import * as curlconverterInit from 'curlconverter';

const curlconverter = curlconverterInit();

curlconverter.toPython('curl example.com');

and there's as little distinction between the native version of the library and the WASM version of the library, the only difference is just this line in package.json

"browser": {
"./dist/src/shell/Parser.js": "./dist/src/shell/webParser.js"
}

@chris48s
Copy link

I'm bumping an old issue here, but the way this is at the moment, it works fine if your website lives at the root of your domain (e.g: https://curlconverter.com ) but if your website lives in a subdirectory (e.g: https://username.github.io/my-static-site ) the library tries to load tree-sitter-bash.wasm from

https://username.github.io/tree-sitter-bash.wasm instead of
https://username.github.io/my-static-site/tree-sitter-bash.wasm

This makes it impossible to use the library in a site that is deployed to a subdirectory.

The other thing I noticed trying to use this in a browser is that although the docs say tree-sitter.wasm is also loaded from the root, that one seems to actually be loaded relative to the js file that tries to load it. So if my js bundle is https://username.github.io/my-static-site/js/app.js then tree-sitter.wasm will be loaded from https://username.github.io/my-static-site/js/tree-sitter.wasm

It would be useful if those two worked the same way, but the inconsistency is less of an issue.

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

No branches or pull requests

3 participants