🧪
[Elixir]`mix local` の local ってどこ?
結論
~/.mix/archives
のことのようです。
詳細
$ mix help local
mix local
Lists local tasks.
Location: /usr/local/Cellar/elixir/1.13.4/lib/mix/ebin
mix local
コマンドはローカルのタスクを一覧表示してくれます。
ですが、ローカルとはどこを指すのでしょうか?
mix local
の実装はここになります。
Mix.Local.archives_tasks()
で返却されたタスクの情報を出力しているようです。
Mix.Local.archives_tasks()
の実装はここ。
Mix.Local.archives_ebins()
の実装はここ。
そしてiexでMix.path_for(:archives)
を実行すると、ホームディレクトリ下にあるarchiveディレクトリが出力されます。
$ iex(1)> Mix.path_for(:archives)
"/Users/XXXX/.mix/archives"
つまり、mix local
の"ローカル"とは、"ホーム"つまりユーザー環境の.mix/archives
のことを指しているようです。
mix localと件数を比較
$ mix local
mix hex # Prints Hex help information
mix hex.audit # Shows retired Hex deps for the current project
mix hex.build # Builds a new package version locally
mix hex.config # Reads, updates or deletes local Hex config
mix hex.docs # Fetches or opens documentation of a package
mix hex.info # Prints Hex information
mix hex.install # false
mix hex.organization # Manages Hex.pm organizations
mix hex.outdated # Shows outdated Hex deps for the current project
mix hex.owner # Manages Hex package ownership
mix hex.package # Fetches or diffs packages
mix hex.publish # Publishes a new package version
mix hex.registry # Manages local Hex registries
mix hex.repo # Manages Hex repositories
mix hex.retire # Retires a package version
mix hex.search # Searches for package names
mix hex.sponsor # Show Hex packages accepting sponsorships
mix hex.user # Manages your Hex user account
mix local.phx # Updates the Phoenix project generator locally
mix phx.new # Creates a new Phoenix v1.6.10 application
mix phx.new.ecto # Creates a new Ecto project within an umbrella project
mix phx.new.web # Creates a new Phoenix web project within an umbrella project
mix still.new # nil
$ mix local | wc -l
23
$ exa --no-user -T /Users/XXXX/.mix/archives | ag Tasks
.rw-r--r-- 2.6k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Audit.beam
.rw-r--r-- 15k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.beam
.rw-r--r-- 17k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Build.beam
.rw-r--r-- 6.9k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Config.beam
.rw-r--r-- 11k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Docs.beam
.rw-r--r-- 8.0k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Info.beam
.rw-r--r-- 4.6k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Install.beam
.rw-r--r-- 6.4k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Organization.beam
.rw-r--r-- 9.3k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Outdated.beam
.rw-r--r-- 5.2k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Owner.beam
.rw-r--r-- 9.7k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Package.beam
.rw-r--r-- 14k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Publish.beam
.rw-r--r-- 8.0k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Registry.beam
.rw-r--r-- 6.5k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Repo.beam
.rw-r--r-- 3.5k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Retire.beam
.rw-r--r-- 3.9k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Search.beam
.rw-r--r-- 2.6k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.Sponsor.beam
.rw-r--r-- 7.5k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Hex.User.beam
.rw-r--r-- 2.0k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Local.Phx.beam
.rw-r--r-- 16k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Phx.New.beam
.rw-r--r-- 3.1k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Phx.New.Ecto.beam
.rw-r--r-- 2.8k 7 Jun 16:36 │ ├── Elixir.Mix.Tasks.Phx.New.Web.beam
.rw-r--r-- 4.6k 8 Jun 18:15 │ ├── Elixir.Mix.Tasks.Still.New.beam
$ e --no-user -T /Users/XXXX/.mix/archives | ag Tasks | wc -l
23
おまけ
mix help archive.install
の冒頭にそれらしいことが書いてありました。
$ mix help archive.install
mix archive.install
Installs an archive locally.
If no argument is supplied but there is an archive in the project's root
directory (created with mix archive.build), then the archive will be installed
locally. For example:
mix do archive.build, archive.install
If an argument is provided, it should be a local path to a prebuilt archive, a
Git repository, a GitHub repository, or a Hex package.
mix archive.install archive.ez
mix archive.install path/to/archive.ez
mix archive.install git https://path/to/git/repo
mix archive.install git https://path/to/git/repo branch git_branch
mix archive.install git https://path/to/git/repo tag git_tag
mix archive.install git https://path/to/git/repo ref git_ref
mix archive.install github user/project
mix archive.install github user/project branch git_branch
mix archive.install github user/project tag git_tag
mix archive.install github user/project ref git_ref
mix archive.install hex hex_package
mix archive.install hex hex_package 1.2.3
After installation, the tasks in the archive are available locally:
mix some_task
Note that installing via Git, GitHub, or Hex fetches the source of the archive
and builds it, while using local path uses a pre-built archive.
## Command line options
• --sha512 - checks the archive matches the given SHA-512 checksum. Only
applies to installations via a local path
• --force - forces installation without a shell prompt; primarily
intended for automation in build systems like Make
• --submodules - fetches repository submodules before building archive
from Git or GitHub
• --app - specifies a custom app name to be used for building the archive
from Git, GitHub, or Hex
• --organization - set this for Hex private packages belonging to an
organization
• --repo - set this for self-hosted Hex instances, defaults to hexpm
Location: /usr/local/Cellar/elixir/1.13.4/lib/mix/ebin
Discussion