justfile(just)是一个用于保存和运行项目专用命令的命令运行器(command runner),不是构建系统,因此避免了 make 的不少复杂性与古怪行为。命令被称为 recipe,存放在名为 justfile 的文件中,语法受 make 启发。
【用途】 用 just 可以保存并运行项目相关命令,例如测试、构建、发布、代码行数统计等。运行时输入 just RECIPE 即可执行对应 recipe,例如 just test-all 会执行相应命令并输出结果。
【主要能力】
- 无 .PHONY recipe 需求,支持 Linux、macOS、Windows 等系统且无需额外依赖(若系统无 sh,需要另选 shell)。
- 错误具体且信息丰富,语法错误会附带源码上下文。
- recipe 可接受命令行参数。
- 尽可能静态解析错误:未知 recipe、循环依赖会在运行前报告。
- 可加载 .env 文件,便于填充环境变量。
- 可从命令行列出 recipe。
- 提供多数常见 shell 的命令行补全脚本。
- recipe 可用 Python、NodeJS 等任意语言编写。
- 可从任意子目录调用,不必位于 justfile 所在的目录。
- 支持别名、子模块、settings、属性(如 [no-cd]、[working-directory]、[positional-arguments]、[script])等。
【使用方式】 在项目根目录创建名为 justfile 的文件,例如: recipe-name: echo 'This is a recipe!'
this is a comment
another-recipe: @echo 'This is another recipe.'
运行 just 时会在当前目录及上层目录查找 justfile(大小写不敏感,也可命名为 .justfile)。无参数运行 just 会运行第一个 recipe;带一个或多个参数则指定要运行的 recipe。just 默认在运行前把每条命令打印到标准错误,以 @ 开头的行会抑制打印。recipe 中命令失败即停止;可定义依赖,依赖总会先运行。无依赖的 recipe 按命令行给定顺序运行。recipe 可依赖子模块中的 recipe。
【适用场景】 资料列举的场景包括:运行测试、构建、发布、统计行数、列出可用 recipe、从子目录调用、使用 .env 填充环境变量、用不同 shell(sh、bash、zsh、fish、Python 3、Windows shell、PowerShell)执行命令等。示例 recipe 见 examples 目录及 GitHub。
【限制与缺失事实】 资料未提供 just 的收费、价格、性能指标或具体使用效果等信息;未提供官方文档中未列出的功能与步骤。部分特性标注了版本号(如 script-interpreter 1.33.0、unstable 1.31.0、working-directory 属性 1.38.0、positional-arguments 属性 1.29.0)。