justfile can declare modules using
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
And the following text in
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
Or with path syntax:
$ just --unstable bar::b
If a module is named
foo, just will search for the module file in
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
PATH is replaced with the current user’s home
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_directory() always return the path to the root
justfile and the directory that contains it, even when called from submodule
Modules may be made optional by putting a
? after the
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.