The .moon/tasks/**/* files configure file groups and tasks that are inherited by every matching project in the workspace based on inheritance conditions.
File Location
- Path:
.moon/tasks/**/*.yml or .moon/tasks/**/*.json
- Format: YAML or JSON
- Required: No
Overview
Task inheritance allows you to define common tasks once and have them automatically available in all matching projects. This reduces boilerplate and ensures consistency across your workspace.
Example structure:
.moon/
tasks/
all.yml # Tasks for all projects
node.yml # Tasks for Node.js projects
typescript.yml # Tasks for TypeScript projects
Configuration Options
extends
Defines one or many external .moon/tasks/**/*’s to extend and inherit settings from.
extends: 'https://raw.githubusercontent.com/organization/repository/master/.moon/tasks/all.yml'
For map-based settings (fileGroups and tasks), entries from both configurations are merged into a new map, with local values taking precedence. Map values are not deep merged!
inheritedBy
A map of conditions that must be met for the configuration to be inherited by a project. When not defined or empty, the configuration is inherited by all projects.
inheritedBy:
# Project belongs to either javascript or typescript toolchain, but not ruby
toolchains:
or: ['javascript', 'typescript']
not: ['ruby']
# And project is either frontend or backend stack
stacks: ['frontend', 'backend']
# And project is either library or tool layer
layers: ['library', 'tool']
Available conditions:
toolchains - Match by toolchain
stacks - Match by project stack
layers - Match by project layer
tags - Match by project tags
languages - Match by project language
fileGroups
Defines file groups that will be inherited by projects.
fileGroups:
configs:
- '*.config.{js,cjs,mjs}'
- '*.json'
sources:
- 'src/**/*'
- 'types/**/*'
tests:
- 'tests/**/*'
- '**/__tests__/**/*'
assets:
- 'assets/**/*'
- 'images/**/*'
- 'static/**/*'
- '**/*.{scss,css}'
File paths and globs used within a file group are relative from the inherited project’s root, not the workspace root.
tasks
Defines tasks that are inherited by many projects within the workspace.
tasks:
format:
command: 'prettier --check .'
lint:
command: 'eslint --no-error-on-unmatched-pattern .'
test:
command: 'jest --passWithNoTests'
typecheck:
command: 'tsc --build'
Relative file paths and globs used within a task are relative from the inherited project’s root, not the workspace root or the location of the .moon/tasks/* file.
taskOptions
Defines task options that will be inherited by all tasks within the configured file.
taskOptions:
# Never cache builds
cache: false
# Always re-run flaky tests
retryCount: 2
tasks:
build:
# ...
options:
# Override the default cache setting
cache: true
implicitDeps
Defines task dependencies that are implicitly inserted into all inherited tasks within a project.
implicitDeps:
- '^:build'
Implicit dependencies are always inherited, regardless of the mergeDeps option.
Defines task inputs that are implicitly inserted into all inherited tasks within a project.
implicitInputs:
- 'package.json'
Implicit inputs are always inherited, regardless of the mergeInputs option.
Examples
All Projects
Define common tasks for all projects:
fileGroups:
sources:
- 'src/**/*'
tests:
- 'tests/**/*'
- '**/__tests__/**/*'
tasks:
format:
command: 'prettier'
args: '--check .'
inputs:
- '@group(sources)'
- '@group(tests)'
format-write:
extends: 'format'
args: '--write .'
preset: 'utility'
Node.js Projects
Define tasks specific to Node.js projects:
inheritedBy:
toolchains: ['node']
implicitInputs:
- 'package.json'
- '/package.json'
fileGroups:
configs:
- '*.config.{js,cjs,mjs}'
- 'tsconfig.json'
tasks:
lint:
command: 'eslint'
args: '--no-error-on-unmatched-pattern .'
inputs:
- '@group(sources)'
- '@group(configs)'
test:
command: 'jest'
args: '--passWithNoTests'
inputs:
- '@group(sources)'
- '@group(tests)'
options:
retryCount: 2
TypeScript Projects
Define tasks specific to TypeScript projects:
.moon/tasks/typescript.yml
inheritedBy:
toolchains: ['typescript']
languages: ['typescript']
implicitInputs:
- 'tsconfig.json'
- '/tsconfig.json'
tasks:
typecheck:
command: 'tsc'
args: '--noEmit'
inputs:
- '@group(sources)'
- 'tsconfig.json'
options:
runFromWorkspaceRoot: true
Frontend Projects
Define tasks for frontend applications:
inheritedBy:
stacks: ['frontend']
layers: ['application']
tasks:
dev:
command: 'vite dev'
preset: 'server'
build:
command: 'vite build'
inputs:
- '@group(sources)'
- '@group(configs)'
outputs:
- 'dist/'
deps:
- '^:build'
preview:
command: 'vite preview'
preset: 'server'
deps:
- '~:build'
Library Projects
Define tasks for library projects:
inheritedBy:
layers: ['library']
implicitDeps:
- '^:build'
tasks:
build:
command: 'tsc'
args: '--build'
inputs:
- '@group(sources)'
- 'tsconfig.json'
outputs:
- 'dist/'
- 'build/'
Complete Example
# Extend from a shared configuration
extends: 'https://raw.githubusercontent.com/org/configs/main/.moon/tasks/base.yml'
# Define file groups
fileGroups:
sources:
- 'src/**/*'
- 'lib/**/*'
tests:
- 'tests/**/*'
- '**/__tests__/**/*'
- '**/*.test.*'
configs:
- '*.config.*'
- '*.json'
# Implicit inputs for all tasks
implicitInputs:
- '.env'
# Task options for all tasks
taskOptions:
cache: true
retryCount: 1
# Define tasks
tasks:
clean:
command: 'rm'
args: '-rf dist build .cache'
options:
cache: false
format:
command: 'prettier'
args: '--check .'
inputs:
- '@group(sources)'
- '@group(tests)'
format-write:
extends: 'format'
args: '--write .'
preset: 'utility'
lint:
command: 'eslint'
args: '.'
inputs:
- '@group(sources)'
- '@group(configs)'
test:
command: 'jest'
inputs:
- '@group(sources)'
- '@group(tests)'
options:
retryCount: 2
outputStyle: 'stream'