Modules 1.19.0

A justfile can declare modules using mod statements. mod statements are currently unstable, so you’ll need to use the --unstable flag, or set the JUST_UNSTABLE environment variable to use them.

If you have the following justfile:

mod bar

a:
  @echo A

And the following text in bar.just:

b:
  @echo B

bar.just will be included in justfile as a submodule. Recipes, aliases, and variables defined in one submodule cannot be used in another, and each module uses its own settings.

Recipes in submodules can be invoked as subcommands:

$ just --unstable bar b
B

Or with path syntax:

$ just --unstable bar::b
B

If a module is named foo, just will search for the module file in foo.just, foo/mod.just, foo/justfile, and foo/.justfile. In the latter two cases, the module file may have any capitalization.

Module statements may be of the form:

mod foo 'PATH'

Which loads the module’s source file from PATH, instead of from the usual locations. A leading ~/ in PATH is replaced with the current user’s home directory.

Environment files are only loaded for the root justfile, and loaded environment variables are available in submodules. Settings in submodules that affect environment file loading are ignored.

Recipes in submodules without the [no-cd] attribute run with the working directory set to the directory containing the submodule source file.

justfile() and justfile_directory() always return the path to the root justfile and the directory that contains it, even when called from submodule recipes.

Modules may be made optional by putting a ? after the mod keyword:

mod? foo

Missing source files for optional modules do not produce an error.

Optional modules with no source file do not conflict, so you can have multiple mod statements with the same name, but with different source file paths, as long as at most one source file exists:

mod? foo 'bar.just'
mod? foo 'baz.just'

See the module stabilization tracking issue for more information.