0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

実行バイナリ/スクリプトインストール用のメタパッケージマネージャーを作った

0
Posted at

概要

image.png


今現在最もよく使われている言語は便利なパッケージマネージャーも持っており、それを利用することで実行バイナリ/スクリプトを簡単にインストールすることができます。

  • Python -> uv
  • Typescript -> npm/bun
  • Rust -> cargo
  • Go -> 本体に内蔵

一方で複数のパッケージマネージャーがあるとそれぞれでインストールしたアプリの管理が面倒になります。それを解決するのが今回紹介するメタパッケージマネージャーのiです。iは複数のパッケージマネージャーに対して統一的なインターフェースを提供します。

i ができること

対応しているマネージャー

Manager Requirement Status Command used
cargo cargo-binstall cargo binstall
uv uv uv tool install
bun bun bun i -g
npm npm npm i -g
grd grd grd
go Go toolchain go install pkg@version

grdは特定の言語に依存しない自作のマネージャーでGitHubのReleaseページからユーザーの環境に合うビルド済みの実行ファイルをダウンロードすることに特化しています。

コマンド一覧

  • i add <pkg> --manager <mgr>: パッケージをインストール & 登録
  • i remove <pkg>: アンインストール & 登録解除
  • i list: 登録済みパッケージ一覧
  • i sync [--force]: 全登録パッケージを一括インストール
  • i upgrade [<pkg>]: 全パッケージ(または指定)をアップグレード
  • i self-upgrade: i 自身を最新版に更新
  • i version: バージョン表示

実行例

  • i add xh --manager cargo: xhcargo-binstallでインストール
  • i add ipython --manager uv --with polars: IPythonとPolars をuvでインストール
  • i add @colbymchenry/codegraph --alias codegraph --manager bun: codegraphをBunでインストール
  • i add anomalyco/opencode --manager grd --destination D:/bin/ --exclude desktop,baseline: OpenCodeをgrdD:/binにインストール (--excludeで使用しないreleaseページのassetを除外)
  • i sync: 後述する設定ファイルから登録済みのパッケージを一括インストール
  • i upgrade: 登録済みのパッケージを一括で最新版に更新

設定ファイル

~/.i/package.tomlファイルで管理

[index]
codegraph = "@colbymchenry/codegraph"

[packages."@colbymchenry/codegraph"]
manager = "bun"
version = "1.0.1"

[packages."anomalyco/opencode"]
manager = "grd"
version = "v1.17.7"
[packages."anomalyco/opencode".options]
destination = "D:/bin/"
exclude = "desktop,baseline"

[packages.ipython]
manager = "uv"
version = "9.14.1"
[packages.ipython.options]
with = ["polars"]

実装詳細

Goで実装しており、以下のDriverインターフェースを通して統一的に様々なパッケージマネージャーを利用できるようにしています。実際には各パッケージマネージャのシェルコマンドを組み立て、os/execを利用して実行します。

type Driver interface {
	Name() string

	Detect() bool

	Install(ctx context.Context, spec PackageSpec) error

	Upgrade(ctx context.Context, spec PackageSpec) error

	Remove(ctx context.Context, spec PackageSpec) error

	InstalledVersion(ctx context.Context, pkg string) (string, error)
}

開発方法

OpenCode + OpenCode ZenのDeepSeek v4 Flash (Free)で100% vide codingです。DeepSeek v4 Flash (Free)は実用上十分の精度で推論速度もとても早く、OSSの開発には最適です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?