# axle list

List every package and project in the monorepo, its scripts and what it depends on.

```sh
axle list [--filter <selector>]... [--affected] [--base <ref>] [--head <ref>] [--tasks [<task>...]] [--json]
```

Run it anywhere inside a repository. Axle finds the [root](https://axlers.dev/docs/crafting-your-repository/structuring-a-repository.md#the-root) and lists every package and [project](https://axlers.dev/docs/reference/configuration.md#projects) with its folder, its scripts, what in the monorepo it depends on and its tags:

```text
Axle found 2 packages and 1 project in /home/me/acme.
The monorepo is managed with pnpm.

@acme/web
  Folder:      apps/web
  Scripts:     build, test
  Depends on:  @acme/ui

@acme/ui
  Folder:      packages/ui
  Scripts:     build
  Depends on:  no other package here

worker (project)
  Folder:      services/worker
  Scripts:     build
  Depends on:  @acme/ui
  Tags:        backend, go

Scripts are the commands in a package's package.json that you can run, like build or test.
Depends on lists the packages in this repository that a package uses, so they have to be built before it.
Projects are folders listed under projects in axle.toml, in any language. Their tasks are the commands in their own axle.toml.
```

In a terminal the output is coloured, with a ✗, ⚠ or → in front of errors, warnings and hints. See [system environment variables](https://axlers.dev/docs/reference/system-environment-variables.md) to turn colours off or on.

## Choosing what to list

`--filter` and `--affected` choose packages exactly as they do for [axle run](https://axlers.dev/docs/reference/run.md#choosing-packages), so `axle list --filter "...@acme/ui"` shows where a `--filter` would run before running anything. `--base` and `--head` say what `--affected` compares.

`--tasks` lists tasks instead of packages, each with its command and, under it, its [description](https://axlers.dev/docs/reference/configuration.md#tasks), and with names, such as `axle list --tasks build test`, only those:

```text
$ axle list --tasks build --filter "./apps/*"
@acme/admin#build  vite build
@acme/web#build    vite build
                   Builds the site for production
```

With `--json`, `--tasks` prints `{ "formatVersion": 1, "tasks": [...] }`, where each task has `task`, `package` and the fields each task has under `tasks` below.

## JSON output

`--json` prints the same list for tools and editors. It is never coloured.

```json
{
    "formatVersion": 1,
    "packageManager": "pnpm",
    "packages": [
        {
            "name": "@acme/web",
            "path": "apps/web",
            "kind": "package",
            "scripts": ["build", "test"],
            "dependencies": ["@acme/ui"],
            "tags": [],
            "tasks": [
                {
                    "name": "build",
                    "command": "vite build",
                    "description": "Builds the site for production",
                    "persistent": false,
                    "interactive": false,
                    "cache": true,
                    "definedAt": { "file": "apps/web/package.json", "line": 5 }
                },
                {
                    "name": "test",
                    "command": "vitest run",
                    "description": null,
                    "persistent": false,
                    "interactive": false,
                    "cache": true,
                    "definedAt": { "file": "apps/web/package.json", "line": 6 }
                }
            ]
        },
        {
            "name": "worker",
            "path": "services/worker",
            "kind": "project",
            "scripts": ["build"],
            "dependencies": ["@acme/ui"],
            "tags": ["backend", "go"],
            "tasks": [
                {
                    "name": "build",
                    "command": "go build ./...",
                    "description": null,
                    "persistent": false,
                    "interactive": false,
                    "cache": true,
                    "definedAt": { "file": "services/worker/axle.toml", "line": 6 }
                }
            ]
        }
    ]
}
```

`formatVersion` is 1, and goes up only when a change would break a tool that reads the output. `kind` is `package` for a workspace package, `project` for a folder listed under `projects` in `axle.toml`, and `plugin` for a project a [plugin](https://axlers.dev/docs/reference/plugins.md) found. `path` uses `/` on every system. `tasks` describes each script and command: what it runs, its `description` from `axle.toml` or `null` without one, whether it is [persistent](https://axlers.dev/docs/reference/configuration.md#tasks), interactive or cached, and `definedAt`, the file and line its command comes from, either the `package.json` script or the `command` in an `axle.toml`, and `null` when a plugin gave the command. On an error, `--json` prints `{ "formatVersion": 1, "error": { "file", "line", "column", "code", "message" } }` instead, where `code` names the error's page under [messages](https://axlers.dev/docs/messages.md), with `line` and `column` set to `null` when the error has no position, and `file` set to `null` when the error isn't about a file, such as an unknown option.

## Errors and warnings

If something is wrong, Axle says which file, at which line and column, and what to do about it, then exits with code 1:

```text
error: packages/bad/package.json has a mistake at line 5, column 1: the file ends too early, so a closing } or ] is probably missing
hint: Fix the mistake at that spot, then run axle again.
```

Every error and warning has its own page under [messages](https://axlers.dev/docs/messages.md). Warnings go to standard error, so `--json` output keeps the same shape.
