Get the FREE Ultimate OpenClaw Setup Guide →

nx-run-tasks

Scanned
npx machina-cli add skill tech-leads-club/agent-skills/nx-run-tasks --openclaw
Files (1)
SKILL.md
2.6 KB

You can run tasks with Nx in the following way.

Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.

For more details on any command, run it with --help (e.g. nx run-many --help, nx affected --help).

Understand which tasks can be run

You can check those via nx show project <projectname> --json, for example nx show project myapp --json. It contains a targets section which has information about targets that can be run. You can also just look at the package.json scripts or project.json targets, but you might miss out on inferred tasks by Nx plugins.

Run a single task

nx run <project>:<task>

where project is the project name defined in package.json or project.json (if present).

Run multiple tasks

nx run-many -t build test lint typecheck

You can pass a -p flag to filter to specific projects, otherwise it runs on all projects. You can also use --exclude to exclude projects, and --parallel to control the number of parallel processes (default is 3).

Examples:

  • nx run-many -t test -p proj1 proj2 — test specific projects
  • nx run-many -t test --projects=*-app --exclude=excluded-app — test projects matching a pattern
  • nx run-many -t test --projects=tag:api-* — test projects by tag

Run tasks for affected projects

Use nx affected to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.

nx affected -t build test lint

By default it compares against the base branch. You can customize this:

  • nx affected -t test --base=main --head=HEAD — compare against a specific base and head
  • nx affected -t test --files=libs/mylib/src/index.ts — specify changed files directly

Useful flags

These flags work with run, run-many, and affected:

  • --skipNxCache — rerun tasks even when results are cached
  • --verbose — print additional information such as stack traces
  • --nxBail — stop execution after the first failed task
  • --configuration=<name> — use a specific configuration (e.g. production)

Source

git clone https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(tooling)/nx-run-tasks/SKILL.mdView on GitHub

Overview

This skill executes Nx targets like build, test, lint, and serve across a workspace using single runs, run-many, and affected. It maps user intents such as 'run tests', 'build my app', or 'serve the project' to the appropriate Nx commands, and notes when not to use code generation or workspace configuration tasks.

How This Skill Works

Identify the project and target from the workspace (e.g., via nx show project <name> --json or by inspecting project.json). Run a single task with nx run <project>:<task>, or use nx run-many -t <tasks> to apply to multiple projects with optional -p/--projects filters. For changes-based runs, use nx affected -t <tasks>, and tailor behavior with flags like --skipNxCache, --verbose, --nxBail, and --configuration; prefix commands with npx/pnpx/yarn if nx isn’t installed globally.

When to Use It

  • You want to run a single task on one project, e.g., nx run my-app:build.
  • You need to run the same task across multiple projects, e.g., nx run-many -t test -p proj1 proj2.
  • You want to run tasks only for changed projects, e.g., nx affected -t build lint.
  • You want to serve a project with a specific configuration, e.g., nx run my-app:serve --configuration=production.
  • You want to explore all available tasks for a project, e.g., nx show project my-app --json.

Quick Start

  1. Step 1: Identify the task and project using nx show project <name> --json or inspect project.json.
  2. Step 2: Run the task, e.g. nx run <project>:<task> or nx run-many -t <task(s)> with optional -p/--projects filters.
  3. Step 3: If nx isn’t installed globally, prefix with npx/pnpx/yarn and apply useful flags like --parallel or --nxBail.

Best Practices

  • Always confirm available targets with nx show project <name> --json or inspect project.json.
  • Prefer nx run-many when applying the same task to multiple projects to avoid repetition.
  • Use nx affected for CI to limit work to changed and dependent projects.
  • Leverage flags like --parallel, --nxBail, --skipNxCache, and --configuration to tailor runs.
  • Remember this skill is for running tasks; avoid code generation or workspace configuration—use nx generate and nx-workspace respectively.

Example Use Cases

  • nx run my-app:build
  • nx run-many -t test -p my-app another-app
  • nx run-many -t test --projects=*-api --parallel=2
  • nx affected -t build lint
  • nx affected -t test --base=main --head=HEAD

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers