:, in the format of scope:task.
Overview
Targets are the primary way to reference and run tasks in moon. They combine:- A scope - which project(s) to run in
- A task - which command to execute
Common Scopes
These scopes are available for both running targets and configuring them.By Project
The most common scope is the project scope, which requires the name of a project, as defined in.moon/workspace.yml. When paired with a task name, it will run a specific task from that project.
moon.yml
By Tag
Another way to target projects is with the tag scope, which requires the name of a tag prefixed with#, and will run a specific task in all projects with that tag.
packages/ui/moon.yml
Run Scopes
These scopes are only available on the command line when running tasks withmoon run or moon ci.
All Projects
For situations where you want to run a specific target in all projects, for examplelinting, you can utilize the all projects scope by omitting the project name from the target: :lint.
This is particularly useful for CI pipelines where you want to validate all code.
Closest Project ~
If you are within a project folder, or an arbitrarily nested folder, and want to run a task in the closest project (traversing upwards), the ~ scope can be used.
Config Scopes
These scopes are only available when configuring a task.Dependencies ^
When you want to include a reference for each project that’s depended on, you can utilize the ^ scope. This will be expanded to all depended on projects. If you do not want all projects, then you’ll need to explicitly define them.
moon.yml
This is extremely powerful for ensuring all dependencies are built before the current project.
apps/web/moon.yml
Owning Project ~
When referring to another task within the current project, you can utilize the ~ scope, or omit the ~: prefix altogether, which will be expanded to the current project’s name. This is useful for situations where the name is unknown, for example, when configuring .moon/tasks/**/*, or if you just want a shortcut!
.moon/tasks/all.yml
moon.yml
Target Patterns
Parallel Execution
Run multiple targets in parallel:Sequential with Dependencies
Tasks with deps run sequentially:moon.yml
Complex Dependency Graphs
apps/web/moon.yml
Real-World Examples
Monorepo CI Pipeline
Local Development
Complex Build Dependencies
apps/web/moon.yml
Special Characters Reference
| Character | Scope | Usage | Example |
|---|---|---|---|
: | Separator | Separates scope from task | app:build |
# | Tag | Run task in all projects with tag | #frontend:test |
^ | Dependencies | Run task in all project dependencies | ^:build |
~ | Self/Closest | Current or closest project | ~:typecheck |
| (none) | All projects | Run task in all projects | :lint |
Best Practices
Use dependency scope (^) for builds
Use dependency scope (^) for builds
Always use
^:build in build tasks to ensure all dependencies are built first. This is essential for proper dependency ordering.Leverage tags for grouping
Leverage tags for grouping
Prefer explicit targets over all projects
Prefer explicit targets over all projects
Instead of
:test (all projects), use #library:test or specific targets. This is faster and more intentional.Use self-scope (~) in global tasks
Use self-scope (~) in global tasks
When defining tasks in
.moon/tasks/, use ~: prefix to make tasks work regardless of project name.Related Concepts
- Tasks - The commands that targets execute
- Projects - The scope where targets run
- Action Graph - How targets are executed