{"id":15379663,"url":"https://github.com/yisar/labor","last_synced_at":"2025-08-22T22:03:13.842Z","repository":{"id":49377294,"uuid":"370288596","full_name":"yisar/labor","owner":"yisar","description":"Simple implementation of Web Container","archived":false,"fork":false,"pushed_at":"2021-05-27T05:34:06.000Z","size":4492,"stargazers_count":212,"open_issues_count":0,"forks_count":20,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-10T00:42:08.140Z","etag":null,"topics":["stackblitz","web-container"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yisar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-24T08:56:53.000Z","updated_at":"2024-11-14T16:56:30.000Z","dependencies_parsed_at":"2022-07-31T02:48:04.866Z","dependency_job_id":null,"html_url":"https://github.com/yisar/labor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisar%2Flabor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisar%2Flabor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisar%2Flabor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisar%2Flabor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yisar","download_url":"https://codeload.github.com/yisar/labor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230408171,"owners_count":18220974,"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":["stackblitz","web-container"],"created_at":"2024-10-01T14:19:36.430Z","updated_at":"2024-12-19T09:08:10.985Z","avatar_url":"https://github.com/yisar.png","language":"Go","readme":"# Labor\n\nImplementation of [Web Container](https://github.com/stackblitz/webcontainer-core)\n\n### Run\n\n```shell\n$ cd demo\n$ yarn build\n$ yarn dev\n```\n\n### Detail\n\n```js\ncode =\u003e js runtime =\u003e rust/go wasm API\n```\n\n举个例子\n\n```js\nconst res = await readFile('a.js')\n```\n这一句代码中的 `readFile` 最终是要执行到 rust/go 中的 API 的，但到底怎么将 go 的 API 注入进去的呢？\n\n此时就需要 go 注入到全局一个 API\n\n```go\njs.Global().Set(\"readFile\", js.FuncOf(func(this js.Value, args []js.Value) interface{} {\n    readFile(args[0].String()) // 相当于 eval\n    return nil\n}))\n```\n我们在 js 侧，只需要直接调用，不需要发接口\n\n```js\nnew Function('readFile', `const res = await readFile('a.js')`)(readFile)\n```\n大功告成，就是如此简单，在 wasm 端实现 API，然后在 js 侧注入到字符串里即可\n\n但还没完，那么问题来了，文件系统呢？http呢？\n\n这就得看 go 对 WASI 的支持程度了，亲测 `net/http` 包大部分支持良好，但不能启端口，`osutil` 包内存 API 是支持的\n\n\ndemo 只是打个比方，这个项目我会用 go 写，因为 docker 也是用 go 写的\n\n值得一提的是，为了获得更好的性能和大小，我们接下来会使用类似 [tinygo](https://github.com/tinygo-org/tinygo) 的编译器\n\n但是 trip worker 我还是会用 rust 实现，理由和 deno 一样，所以本质上，同一套标准库，我得写两遍了，呜呜呜\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisar%2Flabor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyisar%2Flabor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisar%2Flabor/lists"}