Skip to content

Commit 30b0c50

Browse files
committed
Advise library authors on how best to depend on child dependencies
1 parent 73fed09 commit 30b0c50

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/elixir/pages/references/library-guidelines.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ Keep in mind your library's [lockfile](`Mix.Project#module-configuration`) (usua
4242
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`.
4343

4444
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.
45+
46+
### Dependency Version Requirements
47+
48+
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.
49+
50+
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 commit comments

Comments
 (0)