Skip to content

Commit

Permalink
Advise library authors on how best to depend on child dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 18, 2024
1 parent 73fed09 commit 30b0c50
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/elixir/pages/references/library-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ Keep in mind your library's [lockfile](`Mix.Project#module-configuration`) (usua
On the other hand, contributors of your library, need a deterministic build, which implies the presence of `mix.lock` in your Version Control System (VCS), such as `git`.

If you want to validate both scenarios, you should check the `mix.lock` into version control and run two different Continuous Integration (CI) workflows: one that relies on the `mix.lock` for deterministic builds, and another one, that starts with `mix deps.unlock --all` and always compiles your library and runs tests against latest versions of dependencies. The latter one might be even run nightly or otherwise recurrently to stay notified about any possible issue in regard to dependencies updates.

### Dependency Version Requirements

When depending on other libraries, the dependency version requirements are ultimately up to you. However, you should consider the effects that an overly strict dependency requirement can have on users of your library. Most dependencies adopt semver, and therefore provide reasonable guarantees about what each release contains. For instance, if you use `{:some_dep, "== 0.2.3"}`, this prevents users from using other version but the one that you specified, which means that they cannot receive bug fix upgrades to that package. When in doubt, use a dependency in the format of `"~> x.y"`. This prevents the user from using a higher major version of the library, but allows them to upgrade to newer minor and patch versions, which should only include bug fixes and non-breaking improvements.

A common mistake is to use a dependency in the format of `"~> x.y.z"`. For example, if you are depending on version `1.2`, and the dependency publishes a fix in version `1.2.1` that you need for the next version of your library. If you use `"~> 1.2.1"` to express that dependency, you are preventing users from upgrading to `"1.3.0"` or higher! Instead of `"~> 1.2.1"`, you should use `"~> 1.2 and >= 1.2.1"` as the version requirement. This allows users to use any version less thatn `2.0`, and greater than `1.2.1`.

0 comments on commit 30b0c50

Please sign in to comment.