您现在的位置是:首页 > 文章详情

Bun v0.5.7 发布,Zig 编写的 JavaScript 运行时

日期:2023-02-26点击:285

Bun 是采用 Zig 语言编写的高性能 “全家桶” JavaScript 运行时,官方称其为 "all-in-one JavaScript runtime"。所谓 "all in one",是因为 Bun 提供了打包、转译、安装和运行 JavaScript & TypeScript 项目的功能,内置原生打包器 (native bundler)、转译器、task runner、npm 客户端,以及fetchWebSocket等 Web API。

Bun 最近发布了 0.5.7 版本,主要变化:

  • 支持FormData

FormData是标准的 Web API,用于处理分段上传中的表单字段和文件。

 const formData = new FormData(); formData.set("attachment-id", crypto.randomUUID()); formData.set("attachment", Bun.file("./package.json")); const response = await fetch("https://example.com/upload", { method: "POST", body: formData, });

测试显示,在 Bun 中,response.formData()运行:

  • 比 Node v19.6.0 快 25 倍
  • 比 Deno v1.30.3 快 4 倍

  • 引入git依赖

Bun 在package.json中现已支持git依赖,可接受多种 git 依赖格式,包括githubgitgit+ssh,git+https等。

 { "dependencies": { "zod": "github:colinhacks/zod", "lodash": "git@github.com:lodash/lodash.git#4.17.21" } }

此外还可以使用bun install添加git​​​​​​​依赖项。

  • AbortSignal添加fetch()

支持使用AbortSignal取消fetch()request。

 await fetch("https://example.com", { // Abort if the response is not received after 1 second signal: AbortSignal.timeout(1000), });

当从 HTTP Server 收到Request时,也可以使用AbortSignal

 export default { async fetch(request: Request): Promise<Response> { request.signal.addEventListener("abort", () => { console.log("Client aborted the request"); }); // ... return new Response(); }, };
  • 改进setTimeout()与 Node.js 的兼容性
  • bun wiptest变更为bun test,可更美观地打印差异信息
  • 改进对 AWS Lambda 和 GitHub Actions 的支持

详情查看发布公告

原文链接:https://www.oschina.net/news/230090/bun-v0-5-7-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章