{"id":16495169,"url":"https://github.com/bellisario/v-bun","last_synced_at":"2025-10-12T21:07:18.969Z","repository":{"id":182834927,"uuid":"669102497","full_name":"Bellisario/v-bun","owner":"Bellisario","description":"Easily run V code with Bun","archived":false,"fork":false,"pushed_at":"2023-07-21T13:42:15.000Z","size":9,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-01T18:09:25.962Z","etag":null,"topics":["bun","ffi","plugin","proof-of-concept","template","typescript","v","vlang"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bellisario.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"Bellisario"}},"created_at":"2023-07-21T10:48:45.000Z","updated_at":"2024-02-21T13:35:40.000Z","dependencies_parsed_at":"2023-07-21T17:48:29.869Z","dependency_job_id":null,"html_url":"https://github.com/Bellisario/v-bun","commit_stats":null,"previous_names":["bellisario/v-bun"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bellisario%2Fv-bun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bellisario%2Fv-bun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bellisario%2Fv-bun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bellisario%2Fv-bun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bellisario","download_url":"https://codeload.github.com/Bellisario/v-bun/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219860658,"owners_count":16556016,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","ffi","plugin","proof-of-concept","template","typescript","v","vlang"],"created_at":"2024-10-11T14:28:13.663Z","updated_at":"2025-10-12T21:07:13.934Z","avatar_url":"https://github.com/Bellisario.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Bellisario"],"categories":[],"sub_categories":[],"readme":"# v-bun\n\n\u003e Easily run [V](https://vlang.io) code with [Bun](https://bun.sh)\n\n\u003e **If you want to use this project as template:**\n\u003e ```bash\n\u003e bunx degit Bellisario/v-bun \u003cfolder\u003e\n\u003e ```\n\n## Getting started\n\nInstall dependencies:\n\n```bash\nbun install\n```\n\nWatch V code for changes:\n\n```bash\nbun watch\n```\n\nYou can now make TS code changes inside the `src` folder and V code changes inside the `src/v` folder.\n\n\u003e **Warning**\\\n\u003e This folder also contains all the type definitions for TS and all the built V shared libraries, but you should not worry about them: the running watcher will know the right action to perform and you can continue to work normally (ex. edit, rename, delete, etc.).\n\nWhen you're ready to run the code:\n\n```bash\nbun start\n```\n\n## Technical details\n\n### Bun Plugin\n\nThis project is possible thanks to [Bun support for Plugins](https://bun.sh/docs/bundler/plugins), which simplify a lot the process of making a custom handler for files not supported natively.\n\n### The hard part: automating Bun FFI handling\n\nThe hard part is telling Bun to open a shared library with all the symbols ([Bun FFI](https://bun.sh/docs/api/ffi)) (function names, arguments, arguments types, returns and returns types), without manually writing all the symbols map.\n\nTo solve this issue, I \"simply\" parsed the imported V file and extracted the function names, arguments types and return types, all through RegEx. To convert all the extracted types to valid Bun FFI types (to use it as a symbols map), I then used a switch statement.\n\nAfter successfully opening the shared library (with the given symbols map), the `symbols` object returned by Bun can be directly exported (always through the plugin system) and used in the TS code.\n\n### TypeScript problems\n\nThe last (but not least) issue was that TypeScript didn't even know what type of file we were importing, so the solution was to create a `d.ts` file with the same name of the V file, put it on the same directory and export the same functions names extracted from the V file (if you know a better implementation, let me know, I wanted to put all V types on a different folder but I didn't find a way to do it).\n\nThe current implementation exports the functions with generic arguments and return types, just to make TypeScript happy and provide a minimal auto-completion support.\\\nBetter types could be added in the future from the same parsing process used to extract the symbols (if you want to work on this, feel free to open an issue or a pull request).\n\n## FAQ\n\n### Is this project ready for production?\n\nYes and no.\\\nThe current implementation works as expected, but because we're parsing all through RegEx, it's not guaranteed that it will work with all the V code. To use this, you should also be able to check what's wrong in the parsing process and fix it (or change your own V code implementation to fix that specific parser bug).\n\n### Why didn't you release this as a Bun Plugin?\n\nThis project is kind of a proof of concept and a template for other projects.\\\nThe current implementation requires a `bunfig.toml` file to make the plugin run automatically when needed inside the TS code ([see here](https://bun.sh/docs/bundler/plugins#preload)), a watcher to provide TS type definitions for V code on every change and adds type definitions and builds shared libraries directly inside the V folder, which is not admissible for a plugin released as a package.\\\nAlso, as said before, because the parsing process is not perfect and errors are expected, you should be able to edit the plugin code on the fly instead of expecting a new release to fix your specific issue (anyway this doesn't mean that I won't release fixes in this repo).\n\n## Contributing\n\nWe :heart: contributions!\\\nFeel free to open an [issue](https://github.com/Bellisario/v-bun/issues) or a [pull request](https://github.com/Bellisario/v-bun/pulls) but follow [Contributing Guidelines](https://github.com/Bellisario/v-bun/blob/main/CONTRIBUTING.md).\n\n\u003e **Tip:** if you don't know where to start, check out the [help wanted issues](https://github.com/Bellisario/v-bun/labels/help%20wanted)!\n\n## License\n\nMIT License [here](https://github.com/Bellisario/v-bun/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellisario%2Fv-bun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbellisario%2Fv-bun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellisario%2Fv-bun/lists"}