.moon folder.
Overview
The workspace is the foundation of your moon setup. It serves as the central hub where:- All projects are discovered and managed
- Global configuration is defined
- Toolchain versions are specified
- Shared tasks are configured
- Cache and build artifacts are stored
By default, moon has been designed for monorepos, but can also be used for polyrepos.
Directory Structure
When you initialize a moon workspace, the following structure is created:Configuration
Workspace configuration is defined in.moon/workspace.yml. This file controls workspace-wide settings that affect all projects.
Basic Configuration
.moon/workspace.yml
Project Discovery
Moon supports two ways to define projects:- Explicit sources - Manually define each project with its path
- Glob patterns - Automatically discover projects using glob patterns
.moon/workspace.yml
Glob patterns are evaluated relative to the workspace root. Use
! prefix to exclude specific paths.Monorepo vs Polyrepo
Monorepo (Recommended)
In a monorepo setup, all projects live within a single workspace:- Shared toolchain versions across all projects
- Unified task inheritance
- Efficient caching and dependency management
- Simplified CI/CD pipelines
Polyrepo
For polyrepo setups, each repository can have its own moon workspace:Workspace Features
VCS Integration
Moon integrates with your version control system to enable features like affected detection:.moon/workspace.yml
Remote Caching
Configure remote caching to share build artifacts across machines and CI environments:.moon/workspace.yml
Pipeline Configuration
Control how tasks are executed in the pipeline:.moon/workspace.yml
Generator Templates
Define paths to code generation templates:.moon/workspace.yml
Environment Variables
Moon provides several environment variables that are automatically available in the workspace:MOON_VERSION- The version of moon being usedMOON_WORKSPACE_ROOT- Absolute path to the workspace rootMOON_CACHE_DIR- Path to the cache directory
Best Practices
Organize projects by purpose
Organize projects by purpose
Group related projects together using a consistent directory structure. Common patterns include:
apps/for applicationspackages/for librariestools/for internal tooling
Use project globs for scalability
Use project globs for scalability
Instead of manually listing every project, use glob patterns for automatic discovery. This makes it easier to add new projects without updating workspace config.
Version control your .moon directory
Version control your .moon directory
Commit
.moon/workspace.yml, .moon/toolchains.yml, and .moon/tasks/ to version control. Add .moon/cache/ to .gitignore.Leverage global task inheritance
Leverage global task inheritance
Define common tasks once in
.moon/tasks/ and inherit them across projects. This reduces duplication and ensures consistency.Related Concepts
- Projects - Individual projects within the workspace
- Toolchain - Version management for tools and languages
- Tasks - Commands that run in projects
- Cache - Build caching and artifact management