Monorepo Management
Manage complex monorepo projects with imports, namespacing, and parallel builds.
Project Structure
Section titled “Project Structure”monorepo/├── Jakefile # Root orchestrator├── jake/│ ├── common.jake # Shared utilities│ ├── web.jake # Web app tasks│ ├── api.jake # API tasks│ ├── mobile.jake # Mobile app tasks│ └── infra.jake # Infrastructure tasks├── packages/│ ├── web/│ ├── api/│ ├── mobile/│ └── shared/└── infrastructure/Root Jakefile
Section titled “Root Jakefile”# Monorepo Jakefile# =================
@import "jake/common.jake"@import "jake/web.jake" as web@import "jake/api.jake" as api@import "jake/mobile.jake" as mobile@import "jake/infra.jake" as infra
@dotenv@export MONOREPO_ROOT={{absolute_path(.)}}
@pre echo "=== Monorepo Build System ==="
# === Full Builds ===
@default@description "Build all packages"task all: [web.build, api.build, mobile.build] echo "All packages built!"
@description "Build all packages in parallel"task all-parallel: jake -j4 web.build api.build mobile.build echo "Parallel build complete!"
# === Development ===
@description "Start all dev servers"task dev: @pre echo "Starting development environment..." jake web.dev & jake api.dev & wait echo "All dev servers running"
@description "Start web dev server only"task dev-web: [web.dev]
@description "Start API dev server only"task dev-api: [api.dev]
# === Testing ===
@description "Run all tests"task test: [web.test, api.test, mobile.test] echo "All tests passed!"
@description "Test only affected packages"task test-affected: @pre echo "Determining affected packages..." @if exists(packages/web) git diff --name-only HEAD~1 | grep -q "^packages/web" && jake web.test || true @end @if exists(packages/api) git diff --name-only HEAD~1 | grep -q "^packages/api" && jake api.test || true @end echo "Affected tests complete"
# === Linting & Formatting ===
@description "Lint all packages"task lint: [web.lint, api.lint, mobile.lint] echo "All packages linted!"
@description "Format all packages"task format: [web.format, api.format, mobile.format] echo "All packages formatted!"
# === Deployment ===
@description "Deploy all to staging"task deploy-staging: [web.deploy-staging, api.deploy-staging] echo "Deployed to staging!"
@description "Deploy all to production"task deploy-production: [web.deploy-production, api.deploy-production] @confirm "Deploy ALL packages to production?" echo "Deployed to production!"
# === Infrastructure ===
@description "Plan infrastructure changes"task infra-plan: [infra.plan]
@description "Apply infrastructure changes"task infra-apply: [infra.apply]
# === Utilities ===
@description "Clean all packages"task clean: [web.clean, api.clean, mobile.clean] echo "All packages cleaned!"
@description "Install all dependencies"task install: @needs npm npm install @each packages/web packages/api packages/mobile packages/shared @cd {{item}} npm install @end echo "All dependencies installed!"
@description "Update dependencies in all packages"task deps-update: @needs npx npx ncu -u @each packages/web packages/api packages/mobile packages/shared @cd {{item}} npx ncu -u @end echo "Run 'jake install' to install updated deps"
# === CI/CD ===
@description "Full CI pipeline"task ci: [install, lint, test, all] echo "CI passed!"
@description "CI for affected packages only"task ci-affected: jake install jake test-affected echo "Affected CI passed!"Package Jakefiles
Section titled “Package Jakefiles”jake/web.jake
Section titled “jake/web.jake”# Web Package Tasks
root = "packages/web"
@description "Build web app"task build: @cd {{root}} npm run build echo "Web app built"
@description "Start web dev server"task dev: @cd {{root}} npm run dev
@description "Run web tests"task test: @cd {{root}} npm test
@description "Lint web code"task lint: @cd {{root}} npm run lint
@description "Format web code"task format: @cd {{root}} npm run format
task clean: rm -rf {{root}}/dist rm -rf {{root}}/.next echo "Web cleaned"
task deploy-staging: @cd {{root}} npm run deploy:staging echo "Web deployed to staging"
task deploy-production: @confirm "Deploy web to production?" @cd {{root}} npm run deploy:production echo "Web deployed to production"jake/api.jake
Section titled “jake/api.jake”# API Package Tasks
root = "packages/api"
@description "Build API"task build: @cd {{root}} npm run build echo "API built"
@description "Start API dev server"task dev: @cd {{root}} npm run dev
@description "Run API tests"task test: @cd {{root}} npm test
@description "Lint API code"task lint: @cd {{root}} npm run lint
@description "Format API code"task format: @cd {{root}} npm run format
task clean: rm -rf {{root}}/dist echo "API cleaned"
@description "Run API migrations"task migrate: @cd {{root}} npm run migrate
task deploy-staging: @cd {{root}} npm run deploy:staging echo "API deployed to staging"
task deploy-production: @confirm "Deploy API to production?" @cd {{root}} npm run deploy:production echo "API deployed to production"jake # Build all packagesjake -j4 all # Build all in paralleljake dev # Start all dev serversjake web.build # Build just webjake api.test # Test just APIjake test-affected # Test only changed packagesjake deploy-production # Deploy everythingKey Features
Section titled “Key Features”Namespaced Imports
Section titled “Namespaced Imports”Access package tasks with prefixes:
@import "jake/web.jake" as web@import "jake/api.jake" as api
task all: [web.build, api.build]Parallel Builds
Section titled “Parallel Builds”Run independent builds simultaneously:
jake -j4 all # 4 parallel workersOr explicitly in the Jakefile:
task all-parallel: jake -j4 web.build api.build mobile.buildAffected Package Detection
Section titled “Affected Package Detection”Only test/build changed packages:
task test-affected: git diff --name-only HEAD~1 | grep -q "^packages/web" && jake web.testShared Configuration
Section titled “Shared Configuration”Use @export to share variables:
@export MONOREPO_ROOT={{absolute_path(.)}}Per-Package Working Directory
Section titled “Per-Package Working Directory”Execute commands in package directories:
task build: @cd packages/web npm run buildCustomization
Section titled “Customization”Adding a New Package
Section titled “Adding a New Package”- Create
jake/newpackage.jake - Import it in root Jakefile:
@import "jake/newpackage.jake" as newpackage
- Add to composite tasks:
task all: [web.build, api.build, newpackage.build]
Workspace Tools
Section titled “Workspace Tools”Integrate with package managers:
# pnpm workspacestask install: pnpm install
# Turborepo integrationtask build: npx turbo run buildSee Also
Section titled “See Also”- Imports - Import syntax and namespacing
- Parallel Execution -
-jflag details