axle watch
axle watch <task>... [options] [-- <arguments>]Runs the tasks once, the way axle run does, then waits. When you save a file, Axle works out which tasks the change affects and runs only those, and the tasks that depend on them:
Running build in 3 packages with pnpm, up to 16 tasks at once.
@acme/core#build built@acme/ui#build built@acme/web#build built
3 tasks passed in 4.2s
Waiting for changes. Press Ctrl+C to stop.
Changed packages/ui/src/button.tsx@acme/ui#build built@acme/web#build built
2 tasks passed in 2.1sCtrl+C stops every task and ends watching, and Axle exits with 0.
What runs again
Section titled “What runs again”After each change, Axle reads the repository and hashes every task again, exactly as axle run does, and runs a task when:
- its hash differs from the one it had when it last passed, because its own files, a dependency, an environment variable or the lockfile changed;
- it has
^outputsamong its inputs and a task it waits for runs again; - it failed, or was stopped, the last time it ran.
Everything else is up to date and isn’t shown. Since a task’s hash covers the tasks it waits for, a change reaches every task downstream. Files a task writes aren’t among its inputs, so a build writing dist never starts another run. Tasks still come from the cache when they can: undo an edit, and the next run replays the earlier result.
Changes are collected until the files have been quiet for a tenth of a second, so a formatter saving twenty files, or switching branches, starts one run. A change that comes while a run is going stops that run and starts the next with everything that changed since the last one that finished.
Changing an axle.toml, a package.json or a lockfile is picked up by the next run, so a new package or task needs no restart. A mistake in one is shown, and watching goes on until it’s fixed.
Which files count
Section titled “Which files count”Files Git ignores never start a run, nor do .git, .axle and node_modules. [watch] in the root axle.toml ignores more:
[watch]ignore = ["**/*.log", "docs/**"]A change to a file no task reads runs nothing, and Axle says so. Changes to [watch] itself take effect the next time you start axle watch.
Test files
Section titled “Test files”A task whose arguments hold {testFiles} or {changedFiles} runs every test the first time, then gets the files of each change: save packages/ui/src/button.ts, and @acme/web#test runs the tests that import it. The files it’s given are part of its hash, so a task given the same files as last time, with nothing else changed, doesn’t run again. A change to a lockfile runs every test.
Persistent tasks
Section titled “Persistent tasks”A persistent task, such as a dev server, starts in the first run and keeps running; changes wait until the first run’s other tasks have finished. Most dev servers reload on their own. One that doesn’t can say restart = true in axle.toml, and axle watch restarts it, and says so, after a run when a file in its package changed or a task it waits for ran again:
[tasks.start]persistent = truerestart = trueOptions
Section titled “Options”axle watch takes these options of axle run, which mean the same: --filter, --only, --variant, --concurrency, --continue, --log-order, --output-logs, --json, --log-file, --force, --cache, --env-mode and -- <arguments>. It always prints labelled lines, as --ui stream does, and has no --affected, --dry, --profile, --summarize or --check-inputs. [run] settings and AXLE_* variables apply too, and [hooks] commands run once before watching starts and once after it ends.
A log file is created once when watching starts, and gets the output and the summary of every run until it ends. To run any command again on changes, rather than scripts, use axle exec --watch.
JSON events
Section titled “JSON events”--json prints the events of axle run. Each run has its own run number, starting at 1, and every run after the first begins with the files that started it:
{ "run": 2, "event": "watch-change", "files": ["packages/ui/src/button.tsx"] }{ "run": 2, "event": "run-started", "protocol": 1, "tasks": 2, "concurrency": 16 }files is empty when the system lost track of what changed, such as after a very large checkout; every task is checked then. Persistent tasks belong to run 1, so their events keep that number while later runs come and go, including the task-restarted of one with restart = true.