Bun v1.0.31 发布,支持 Unix 套接字发送 HTTP 请求

Bun 是一款非常快速的 JavaScript 运行时、捆绑器、转译器和包管理器的一体化工具。

Bun v1.0.31 修复了 54 个错误(解决了 113 个 👍 问题),引入了 bun --print<stdin> | bun run -bun add --trust,使用 Unix 套接字的 fetch(),修复了 macOS 二进制文件大小问题,在旧版 Linux 上修复 spawn() 中的高 CPU 使用率 bug,添加了 util.styleText,Node.js 兼容性改进,修复了 bun install bug 和 bunx bug。

Bun v1.0.31 发布,支持 Unix 套接字发送 HTTP 请求

安装 Bun

# curl
curl -fsSL https://bun.sh/install | bash

# npm
npm install -g bun

# brew
brew tap oven-sh/bun
brew install bun

# docker
docker pull oven/bun
docker run --rm --init --ulimit memlock=-1:-1 oven/bun

# 更新 Bun
bun upgrade

bun –print

您现在可以使用 bun --print 来评估提供的代码并使用 console.log 打印结果。它与 node --print 相同,不过 Bun 支持顶层 await、ESM、CommonJS、TypeScript 和 JSX。

Bun v1.0.31 发布,支持 Unix 套接字发送 HTTP 请求

Bun 也会等待未完成的 Promise,因此您不需要将 await 添加到您的代码中。

Bun 实施这一举措是因为许多 npm 包具有 postinstall 脚本调用 node –print,并且当您没有安装 Node.js 时,Bun 不希望 bun install 出现任何问题。

从标准输入运行代码

您现在可以使用 bun run – 将 stdin 管道传输到 Bun 中,这对于从文件或脚本运行代码非常有用。

Bun v1.0.31 发布,支持 Unix 套接字发送 HTTP 请求

与 Bun 的其他功能一样,此功能支持顶层 await、ESM、CommonJS、TypeScript 和 JSX。

bun add –trust package

Bun 已经改进了处理 package.json 中 trustedDependencies 的方式。默认情况下,Bun 不会运行未受信任的包的 postinstall 脚本。这是一个安全功能,可以防止恶意代码在您的计算机上运行。

当您第一次添加一个包时,Bun 会告诉您该包是否有一个未运行的 postinstall 脚本。

bun add v1.0.31
 Saved lockfile

 installed @biomejs/biome@1.6.1 with binaries:
  - biome

 1 package installed [55.00ms]

 Blocked 1 postinstall. Run `bun pm untrusted` for details.

bun pm untrusted

如果您想查看被阻止的脚本,请运行 bun pm untrusted。

bun pm untrusted v1.0.31

./node_modules/@biomejs/biome @1.6.1
 » [postinstall]: node scripts/postinstall.js

These dependencies had their lifecycle scripts blocked during install.

If you trust them and wish to run their scripts, use `bun pm trust`.

bun pm trust

如果您信任软件包,您可以运行 bun pm trust package。如果您想信任每个软件包,您也可以运行 bun pm trust –all。

bun pm trust v1.0.31

./node_modules/@biomejs/biome @1.6.1
 ✓ [postinstall]: node scripts/postinstall.js

 1 script ran across 1 package [71.00ms]

最受欢迎的软件包已经默认受信任。您可以通过运行 bun pm default-trusted 来查看受信任软件包的列表。

如果您已经知道要信任一个依赖项,可以使用 bun add –trust package 添加它。这将把该软件包及其传递性依赖项添加到您的 trustedDependencies 列表中,因此您无需为该软件包运行 bun pm trust。

Unix 套接字的 fetch()

Bun 现在支持通过 Unix 套接字发送 HTTP 请求。

const response = await fetch("http://localhost/info", {
  // a file path to a Unix socket
  unix: "/var/run/docker.sock",
});

const { ID } = await response.json();
console.log("Docker ID:", ID);

这意味着您可以向使用 Unix 套接字通信但讲述 HTTP 的服务发送 fetch() 请求,比如 Docker 守护程序。此功能适用于 fetch 和 node:http

通常,Unix 套接字的文件路径限制约为 108 个字符,但在 Linux 上,我们添加了一种解决方案以支持更长的路径。

Windows 支持即将到来

Bun 即将发布支持 Windows 的 Bun v1.1 版本。一旦 Windows 版 Bun 通过了 95% 的测试套件,Bun 将宣布发布日期。

Bun v1.0.31 发布,支持 Unix 套接字发送 HTTP 请求

给TA打赏
共{{data.count}}人
人已打赏
技术教程

全新 Astro 主题管理平台,Astro 开发者门户上线

2024-4-16 10:49:34

软件应用

安卓剪辑videoleap视频编辑器

2019-7-24 16:34:18

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索