## 経緯 [[Bun]]の1.0.24がリリースされた。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://bun.sh/logo.svg" /> <span class="link-card-v2-site-name">bun.sh</span> </div> <div class="link-card-v2-title"> Bun v1.0.24 | Bun Blog </div> <div class="link-card-v2-content"> Fixes 9 bugs and adds Bun Shell, a fast cross-platform shell with seamless JavaScript interop. Fixes a socket ti ... </div> <img class="link-card-v2-image" src="https://bun.com/og/blog/bun-v1.0.24.png" /> <a href="https://bun.sh/blog/bun-v1.0.24"></a> </div> 新機能として[[Bun Shell]]が追加され、[[zx]]のようにシェルが書けるようになったので試してみる。以前に[[Bun]]で[[zx]]を使おうと試したときは、[[zx]]だけでは動かなくて今後のメンテが不安だったのでやめたことがある。 > [[📜Bunでzxをいじってみる]] ## いじってみる [リリースノート](https://bun.sh/blog/bun-v1.0.24#bun-shell)の記載を参考に。品質はα版らしいのでお試しという感じ。 > Alpha-quality software: Bun Shell is an unstable API still under development. If you have feature requests or run into bugs, please open an issue. There may be breaking changes in the future. `index.ts`を書いてみる。 ```ts import { $ } from "bun"; const stdout = await
pwd`.text(); console.log(stdout); ``` 動作はする。 ```console $ bun . /home/tadashi-aikawa/tmp/bun-shell-use ``` だが、実はこのコード、1行目がエラーになる。 ## $をimportできない `import { $ } from "bun"` に対して以下のエラーが発生する。 ```error Module '"bun"' has no exported member ' (tsserver 2305). (tsserver 2305) ``` [[GitHub]]にissuesもあがってそう。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://github.githubassets.com/favicons/favicon.svg" /> <span class="link-card-v2-site-name">GitHub</span> </div> <div class="link-card-v2-title"> "Module 'bun' has no exported member '". (Outdated `@types/bun`) · Issue #8301 · oven-sh/bun </div> <div class="link-card-v2-content"> What version of Bun is running? 1.0.24+6fa35839c What platform is your computer? Darwin 23.2.0 arm64 arm What st ... </div> <img class="link-card-v2-image" src="https://opengraph.githubassets.com/5e2d2420f9d246cbfb9042dd529cbdaa15b86ff20f1e25513201999b95ac8b62/oven-sh/bun/issues/8301" /> <a href="https://github.com/oven-sh/bun/issues/8301"></a> </div> ## JavaScriptで書いてみる [[JavaScript]]だと型エラーは出ない... けど当然型がないものとして扱われる。あまりメリットがない。 ```js import { $ } from "bun"; const stdout = await
ls`.lines(); for await (const x of stdout) { console.log(x); } ``` ```console $ bun . tsconfig.json biome.json index.js~ bun.lockb node_modules package.json README.md index.js ``` `for wait`の`await`を書いていなくてしばらくハマってしまった。。