# `nx_task`

One task in a native [Nx](https://nx.dev) workspace.

## Description

`nx_task` represents a single project and task pair from Nx's project
graph. Struo hashes its declared inputs, schedules it against the resolved
graph, and runs the task's underlying command directly.

Resolved command executors run directly:

- `nx:run-commands` and its aliases (`@nx/run-commands:run-commands`,
  `@nrwl/run-commands:run-commands`, `@nx/workspace:run-commands`,
  `@nrwl/workspace:run-commands`). The resolver lowers `options.command`
  or `options.commands` into a shell command executed via a POSIX shell
  on Linux and macOS, or `cmd.exe` on Windows.
- `nx:run-script`. The resolver reads `metadata.runCommand`, which Nx
  pre-resolves to the package-manager invocation for the requested
  script, and runs it from the project directory.

For `run-commands`, the resolver forwards `options.args` unless the task or
individual command sets `forwardAllArgs` to false.

Other executors run through the installed Nx `runExecutor` API with the
resolved project graph and default configuration. Struo still owns scheduling,
hashing, caching, and output restoration; Nx's task runner is not invoked.

Most attributes on this target are filled in by the `nx_workspace`
resolver. Declaring an `nx_task` by hand is only necessary when the
workspace is not fully covered by the `nx` native project.

Commands can invoke installed tools such as `tsc` and `vitest` by name.
The command's `PATH` holds the `node_modules/.bin` directories from its
working directory through the workspace root, with the nearest package taking
precedence, then the directories of Node.js and of the workspace's package
manager, then the system directories. It does not include your shell's
`PATH`, so changing it does not invalidate cached tasks. A task whose Nx
`inputs` include `{"env": "PATH"}` inherits your shell's value instead, as part
of its cache key. `HOME` is only passed when the inputs declare
`{"env": "HOME"}` in the same way.

Source hashing conservatively includes workspace sources and installed
dependencies, excluding declared outputs and runtime caches. Dependency output
snapshots are explicit action inputs, including transitive snapshots, so generated
content changes invalidate consumers even when workspace sources are unchanged. Default
configuration options resolve output tokens, including nested tokens such as
`{options.outputPath.base}`.

Tasks named `test` are emitted as [`nx_test`](/docs/reference/prelude/nx_test)
targets with the same attributes and both build and test capabilities, so test
prerequisites also execute during builds. Each project produces one normalized,
cacheable suite batch.

Nx output declarations are cache patterns, not required products. Struo stores
a required snapshot and a manifest of existing matches, then restores those
matches to their original workspace paths. An absent coverage directory is
valid when coverage was not requested. Output patterns use the installed
Nx version's native matcher. Ordinary Struo action outputs remain required.
Generated Vite caches under `node_modules/.vite` are not source inputs.

## Attributes

| Attribute | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `project` | string | yes |  | Nx project name as it appears in the project graph |
| `task` | string | yes |  | Nx target name for the project, such as `build`, `test`, or `lint` |
| `project_root` | string | no |  | Workspace-relative directory that holds the project's sources |
| `outputs` | list&lt;string&gt; | no | `[]` | Workspace-relative Nx output paths or patterns with `{projectRoot}`, `{workspaceRoot}`, and `{projectName}` expanded. Only existing matches are cached; absent outputs are valid |
| `executor` | string | no |  | Nx executor id, kept for provenance so cache keys segregate between executors |
| `executor_graph` | string | no |  | Resolver-owned canonical graph used by plugin executor actions |
| `workspace_outputs` | list&lt;string&gt; | no | `[]` | Resolver-owned output patterns excluded from workspace source hashing |
| `project_type` | string | no |  | Nx project type reported by the graph: `app`, `lib`, or `e2e` |
| `runnable` | bool | no | `false` | Resolver-owned flag: true when commands or a plugin executor graph are available |
| `commands` | list&lt;string&gt; | no | `[]` | Resolver-owned shell commands lowered from the Nx executor options |
| `command_cwd` | string | no |  | Resolver-owned working directory for the lowered command |
| `command_env` | map&lt;string, string&gt; | no | `{}` | Resolver-owned environment variables from the executor's `env` option |
| `node` | string | no | `node` | Node.js executable used to identify the toolchain in the cache key |
| `dependencies` | list&lt;string&gt; | no | `["node_modules/**/*"]` | Installed package files required at execution time |
| `config` | list&lt;string&gt; | no | `["nx.json", "package.json", "pnpm-lock.yaml", "yarn.lock", "package-lock.json"]` | Workspace-level configuration inputs |
| `env` | map&lt;string, string&gt; | no | `{}` | User-supplied environment variables applied after `command_env` |
| `env_inherit` | list&lt;string&gt; | no | `[]` | Host environment variables inherited by name |

## Providers

The target emits `nx_task`.

## Capabilities

| Capability | Output groups |
| --- | --- |
| `build` | none |

## Sources

- [Nx executors](https://nx.dev/concepts/executors-and-configurations)
  describe the per-task contract Struo translates.
- [Nx run-commands](https://nx.dev/nx-api/nx/executors/run-commands)
  defines the shell command executor that Struo runs natively.
- [Nx run-script](https://nx.dev/nx-api/nx/executors/run-script) defines
  the package.json script executor that Struo runs natively.
