Skip to content

Commit 77322a0

Browse files
authored
docs: add Task Runner user documentation (#763)
## Summary - Add 5 new documentation pages for the task runner under `/vite/guide/task/`: - **Getting Started** — overview, running scripts, caching intro, task definitions, dependencies, monorepo usage - **Running Tasks** — package selection, compound commands, nested `vp run`, execution summary - **Caching** — how caching works, when it's enabled, automatic file tracking, environment variables, cache sharing - **CLI Reference** — `vp run` usage, options, filter patterns, `vp cache clean` - **Config Reference** — `run.cache`, `run.tasks`, and all per-task options - Update VitePress sidebar and nav configuration ## Test plan - [ ] Verify deploy preview renders all 5 pages correctly - [ ] Check all cross-page links resolve - [ ] Verify ASCII diagrams render properly in code blocks 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 1333406 commit 77322a0

6 files changed

Lines changed: 757 additions & 29 deletions

File tree

docs/.vitepress/config.mts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default extendConfig(
7171
{ text: 'Test', link: '/config/test' },
7272
{ text: 'Lint', link: '/config/lint' },
7373
{ text: 'Format', link: '/config/format' },
74-
{ text: 'Task Runner', link: '/config/task' },
74+
{ text: 'Task Runner', link: '/vite/guide/task/config' },
7575
{ text: 'Package Manager', link: '/config/package-manager' },
7676
],
7777
},
@@ -327,40 +327,20 @@ export default extendConfig(
327327
link: 'task/getting-started',
328328
},
329329
{
330-
text: 'Features',
331-
link: '/guide/task/features',
332-
},
333-
{
334-
text: 'CLI',
335-
link: '/guide/task/cli',
336-
},
337-
{
338-
text: 'Migration from Turborepo',
339-
link: '/guide/format/migration-from-turborepo',
340-
},
341-
{
342-
text: 'Migration from Nx',
343-
link: '/guide/format/migration-from-nx',
344-
},
345-
{
346-
text: 'Migration from Lerna',
347-
link: '/guide/format/migration-from-lerna',
330+
text: 'Running Tasks',
331+
link: 'task/running-tasks',
348332
},
349333
{
350-
text: 'Migration from pnpm',
351-
link: '/guide/format/migration-from-pnpm',
334+
text: 'Caching',
335+
link: 'task/caching',
352336
},
353337
{
354-
text: 'Migration from yarn',
355-
link: '/guide/format/migration-from-yarn',
356-
},
357-
{
358-
text: 'Migration from npm',
359-
link: '/guide/format/migration-from-npm',
338+
text: 'CLI',
339+
link: 'task/cli',
360340
},
361341
{
362-
text: 'Migration from bun',
363-
link: '/guide/format/migration-from-bun',
342+
text: 'Config',
343+
link: 'task/config',
364344
},
365345
],
366346
},
@@ -604,6 +584,15 @@ export default extendConfig(
604584
},
605585
],
606586
},
587+
{
588+
text: 'Task Runner',
589+
items: [
590+
{
591+
text: 'Configuring Task Runner',
592+
link: '/vite/guide/task/config',
593+
},
594+
],
595+
},
607596
],
608597
'/apis/': [
609598
{

docs/vite/guide/task/caching.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Caching
2+
3+
## How It Works {#how-caching-works}
4+
5+
When a task runs successfully (exit code 0), its terminal output (stdout/stderr) is saved. On the next run, the task runner checks if anything changed:
6+
7+
1. **Arguments** — did the [additional arguments](./cli#additional-arguments) passed to the task change?
8+
2. **Environment variables** — did any [fingerprinted env vars](./config#envs) change?
9+
3. **Input files** — did any file that the command reads change?
10+
11+
If everything matches, the cached output is replayed instantly — the command never actually runs.
12+
13+
::: info
14+
Currently, only terminal output is cached and replayed. Output files (e.g., `dist/`) are not cached — if you delete them, use `--no-cache` to force a re-run. Output file caching is planned for a future release.
15+
:::
16+
17+
When a cache miss occurs, the task runner tells you exactly why:
18+
19+
```
20+
$ vp lint ✗ cache miss: 'src/utils.ts' modified, executing
21+
$ vp build ✗ cache miss: envs changed, executing
22+
$ vp test ✗ cache miss: args changed, executing
23+
```
24+
25+
## When Is Caching Enabled? {#when-is-caching-enabled}
26+
27+
A command run by `vp run` is either a **task** (has an entry in `vite.config.ts`) or a **script** (only exists in `package.json` with no corresponding task entry). By default, **tasks are cached and scripts are not.** Three layers control whether caching is on:
28+
29+
### 1. Per-task `cache: false` (highest priority, tasks only)
30+
31+
A task can set [`cache: false`](./config#cache) to opt out. This cannot be overridden by `--cache` or `run.cache` — if a task says no caching, it means no caching.
32+
33+
### 2. CLI flags
34+
35+
`--no-cache` disables caching for everything. `--cache` enables caching for both tasks and scripts — equivalent to setting [`run.cache: true`](./config#run-cache) for that invocation.
36+
37+
### 3. Workspace config
38+
39+
The [`run.cache`](./config#run-cache) option in your root `vite.config.ts` controls the default for each category:
40+
41+
| Setting | Default | Effect |
42+
| --------------- | ------- | ------------------------------------- |
43+
| `cache.tasks` | `true` | Cache commands that have a task entry |
44+
| `cache.scripts` | `false` | Cache plain `package.json` scripts |
45+
46+
Use `--cache` to quickly enable script caching, or set `run.cache.scripts: true` in config to enable it permanently.
47+
48+
## Automatic File Tracking {#automatic-file-tracking}
49+
50+
By default, the task runner tracks which files each command reads during execution. When `vp build` runs, it records which files the process opens — your `.ts` source files, `vite.config.ts`, `package.json`, etc. — and records their content hashes. On the next run, it re-checks those hashes to determine if anything changed.
51+
52+
This means caching works out of the box for most commands without any configuration. The tracker also records:
53+
54+
- **File non-existence** — if a command probes for a file that doesn't exist (e.g., `utils.ts` during module resolution), creating that file later correctly invalidates the cache.
55+
- **Directory listings** — if a command scans a directory (e.g., a test runner looking for `*.test.ts`), adding or removing files in that directory invalidates the cache.
56+
57+
### Over-fingerprinting {#over-fingerprinting}
58+
59+
Automatic tracking can sometimes include more files than necessary, causing unnecessary cache misses:
60+
61+
- **Tool cache files** — some tools maintain their own cache (e.g., TypeScript's `.tsbuildinfo`, Cargo's `target/`). These files may change between runs even when your source code hasn't, causing unnecessary cache invalidation.
62+
- **Directory listings** — when a command scans a directory (e.g., globbing for `**/*.js`), the task runner sees the directory read but not the glob pattern. Any file added or removed in that directory — even unrelated ones — invalidates the cache.
63+
64+
Use the [`inputs`](./config#inputs) option to exclude noisy files or replace automatic tracking with explicit file patterns:
65+
66+
```ts
67+
tasks: {
68+
build: {
69+
command: 'tsc',
70+
inputs: [{ auto: true }, '!**/*.tsbuildinfo'],
71+
},
72+
}
73+
```
74+
75+
## Environment Variables {#environment-variables}
76+
77+
By default, tasks run in a clean environment — only a small set of common variables (like `PATH`, `HOME`, `CI`) are passed through. Other environment variables are neither visible to the task nor included in the cache fingerprint.
78+
79+
To make a variable affect caching, add it to [`envs`](./config#envs). Changing its value invalidates the cache:
80+
81+
```ts
82+
tasks: {
83+
build: {
84+
command: 'webpack --mode production',
85+
envs: ['NODE_ENV'],
86+
},
87+
}
88+
```
89+
90+
To pass a variable to the task **without** affecting the cache, use [`passThroughEnvs`](./config#pass-through-envs). This is useful for variables like `CI` or `GITHUB_ACTIONS` that should be available but shouldn't trigger a rebuild when they change.
91+
92+
See the [config reference](./config#envs) for details on wildcard patterns and the full list of automatically passed-through variables.
93+
94+
## Cache Sharing {#cache-sharing}
95+
96+
The cache is content-based — if two tasks run the same command with the same inputs, they share the cache entry. This happens naturally when multiple tasks include a common step, either as standalone tasks or as parts of [compound commands](./running-tasks#compound-commands):
97+
98+
```json [package.json]
99+
{
100+
"scripts": {
101+
"check": "vp lint && vp build",
102+
"release": "vp lint && deploy-script"
103+
}
104+
}
105+
```
106+
107+
With caching enabled (e.g. `--cache` or [`run.cache.scripts: true`](./config#run-cache)), running `check` first means the `vp lint` step in `release` is an instant cache hit, since both run the same command against the same files.
108+
109+
## Clearing the Cache {#clearing-the-cache}
110+
111+
```bash
112+
vp cache clean
113+
```
114+
115+
This deletes the entire cache directory. Tasks will run fresh on the next invocation.

docs/vite/guide/task/cli.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# CLI Reference
2+
3+
## `vp run` {#vp-run}
4+
5+
Run tasks defined in `vite.config.ts` or `package.json` scripts.
6+
7+
```bash
8+
vp run [options] [task] [additional-args]
9+
```
10+
11+
If `task` is omitted, an interactive selector is shown:
12+
13+
```
14+
Select a task (↑/↓, Enter to run, Esc to clear):
15+
16+
› build: vp build
17+
lint: vp lint
18+
```
19+
20+
### Task Argument {#task-argument}
21+
22+
The `[task]` argument can be:
23+
24+
- `build` — runs the `build` task in the current package
25+
- `@my/app#build` — runs the `build` task in a specific package
26+
27+
### Options {#options}
28+
29+
| Flag | Short | Description |
30+
| --------------------- | ----- | ---------------------------------------------------------- |
31+
| `--recursive` | `-r` | Run in all workspace packages, in topological order |
32+
| `--transitive` | `-t` | Run in the current package and its transitive dependencies |
33+
| `--workspace-root` | `-w` | Run in the workspace root package |
34+
| `--filter <pattern>` | `-F` | Select packages by name, directory, or glob (repeatable) |
35+
| `--cache` || Enable caching for all tasks and scripts |
36+
| `--no-cache` || Disable caching entirely |
37+
| `--ignore-depends-on` || Skip explicit `dependsOn` dependencies |
38+
| `--verbose` | `-v` | Show detailed execution summary |
39+
| `--last-details` || Display the summary from the last run |
40+
41+
### Additional Arguments {#additional-arguments}
42+
43+
Arguments after the task name are passed through to the task command:
44+
45+
```bash
46+
vp run test --reporter verbose
47+
```
48+
49+
### Filter Patterns {#filter-patterns}
50+
51+
| Pattern | Description |
52+
| ------------------ | ------------------------------------------ |
53+
| `@my/app` | Exact package name |
54+
| `@my/*` | Glob matching |
55+
| `./packages/app` | By directory |
56+
| `{./packages/app}` | By directory (braced form) |
57+
| `@my/app...` | Package and its dependencies |
58+
| `...@my/core` | Package and its dependents |
59+
| `@my/app^...` | Dependencies only (exclude package itself) |
60+
| `...^@my/core` | Dependents only (exclude package itself) |
61+
| `!@my/utils` | Exclude a package |
62+
63+
Multiple `--filter` flags are combined as a union. Exclusion filters (`!`) are applied after all inclusions.
64+
65+
## `vp cache clean` {#vp-cache-clean}
66+
67+
Delete all cached task results:
68+
69+
```bash
70+
vp cache clean
71+
```
72+
73+
Tasks will run fresh on the next invocation.

0 commit comments

Comments
 (0)