nx_task

One task in a native Nx 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 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#

AttributeTypeRequiredDefaultDescription
projectstringyesNx project name as it appears in the project graph
taskstringyesNx target name for the project, such as build, test, or lint
project_rootstringnoWorkspace-relative directory that holds the project's sources
outputslist<string>no[]Workspace-relative Nx output paths or patterns with {projectRoot}, {workspaceRoot}, and {projectName} expanded. Only existing matches are cached; absent outputs are valid
executorstringnoNx executor id, kept for provenance so cache keys segregate between executors
executor_graphstringnoResolver-owned canonical graph used by plugin executor actions
workspace_outputslist<string>no[]Resolver-owned output patterns excluded from workspace source hashing
project_typestringnoNx project type reported by the graph: app, lib, or e2e
runnableboolnofalseResolver-owned flag: true when commands or a plugin executor graph are available
commandslist<string>no[]Resolver-owned shell commands lowered from the Nx executor options
command_cwdstringnoResolver-owned working directory for the lowered command
command_envmap<string, string>no{}Resolver-owned environment variables from the executor's env option
nodestringnonodeNode.js executable used to identify the toolchain in the cache key
dependencieslist<string>no["node_modules/**/*"]Installed package files required at execution time
configlist<string>no["nx.json", "package.json", "pnpm-lock.yaml", "yarn.lock", "package-lock.json"]Workspace-level configuration inputs
envmap<string, string>no{}User-supplied environment variables applied after command_env
env_inheritlist<string>no[]Host environment variables inherited by name

Providers#

The target emits nx_task.

Capabilities#

CapabilityOutput groups
buildnone

Sources#

  • Nx executors describe the per-task contract Struo translates.
  • Nx run-commands defines the shell command executor that Struo runs natively.
  • Nx run-script defines the package.json script executor that Struo runs natively.