Open10

miseを試してみる

tf63tf63

miseについて

Like asdf (or nvm or pyenv but for any language) it manages dev tools like node, python, cmake, terraform, and hundreds more.
Like direnv it manages environment variables for different project directories.
Like make it manages tasks used to build and test projects.

https://mise.jdx.dev/

https://github.com/jdx/mise

tf63tf63

miseのセットアップ

mise activateをシェル起動時に仕込んでおく

echo 'eval "$(~/.local/bin/mise activate bash)"' >> ~/.bashrc # bash
echo 'eval "$(~/.local/bin/mise activate zsh)"' >> ~/.zshrc # zsh
echo '~/.local/bin/mise activate fish | source' >> ~/.config/fish/config.fish # fish
tf63tf63

シェル補完

mise completion bash > ~/.local/share/bash-completion/completions/mise # bash
mise completion zsh  > /usr/local/share/zsh/site-functions/_mise # zsh
mise completion fish > ~/.config/fish/completions/mise.fish # fish

追加でUsageというツールが必要らしい。miseでインストールできる

mise plugin install usage
mise use -g usage

シェル補完でインストールしたいパッケージのバージョンを確認できたりする

> mise use node@
node@0.1.14   node@0.8.23   node@4.7.3   node@9.4.0     node@13.9.0   node@18.9.1 
node@0.1.15   node@0.8.24   node@4.8.0   node@9.5.0     node@13.10.0  node@18.10.0
node@0.1.16   node@0.8.25   node@4.8.1   node@9.6.0     node@13.10.1  node@18.11.0
tf63tf63

mise.toml

mise.toml, mise/config.toml, mise.local.toml (バージョン管理から外す) などでプロジェクトごとの設定を作れる
https://mise.jdx.dev/configuration.html

[env]
NODE_ENV = 'production'

[tools]
terraform = '1.0.0'
erlang = '24.0'

[tasks.build]
run = 'echo "running build tasks"'
tf63tf63

パッケージのインストール

mise.tomlからインストール

mise install

インストール可能なパッケージを検索

mise registry

インストール可能なバージョンを検索

mise ls-remote <パッケージ>

パッケージのインストール

mise use <パッケージ>

パッケージのアンインストール

mise unuse <パッケージ>
tf63tf63

グローバルにインストール

~/.config/mise/config.tomlにグローバルインストールしたパッケージが記載される

mise use -g <パッケージ>
tf63tf63

ツールを一時的に実行

mise x <パッケージ>
mise x <パッケージ> -- <arg> # ツールにコマンドライン引数を渡して実行

mise x python -- python
tf63tf63

タスクを登録

Makefileみたいなことをmise.tomlで設定できる

https://mise.jdx.dev/tasks/toml-tasks.html

[tasks.clean]
depends = ['cleancache']
run = "cargo clean" # runs as a shell command

[tasks.build]
description = 'Build the CLI'
run = "cargo build"
alias = 'b' # `mise run b`

[tasks.test]
description = 'Run automated tests'
# multiple commands are run in series
run = [
    'cargo test',
    './scripts/test-e2e.sh',
]
dir = "{{cwd}}" # run in user's cwd, default is the project's base directory

[tasks.lint]
description = 'Lint with clippy'
env = { RUST_BACKTRACE = '1' } # env vars for the script
# you can specify a multiline script instead of individual commands
run = """
#!/usr/bin/env bash
cargo clippy
"""

[tasks.ci] # only dependencies to be run
description = 'Run CI tasks'
depends = ['build', 'lint', 'test']

タスクの実行

mise run build
tf63tf63

Hook

特定のイベントで自動実行するコマンドを登録できる
https://mise.jdx.dev/hooks.html

[hooks]
preinstall = "echo 'I am about to install tools'"
postinstall = "echo 'I just installed tools'"