|
| 1 | +# Output Restoration |
| 2 | + |
| 3 | +When a cached task is replayed, vp doesn't just replay the terminal output — it also restores any files the task produced. So if your `build` task writes to `dist/`, a cache hit will put those files right back where they belong. |
| 4 | + |
| 5 | +## How It Works |
| 6 | + |
| 7 | +By default, vp watches which files a task writes during execution. On the next run, if the cache hits, those files are extracted back into the workspace automatically. You don't need to configure anything. |
| 8 | + |
| 9 | +```json |
| 10 | +{ |
| 11 | + "tasks": { |
| 12 | + "build": { |
| 13 | + "command": "tsc --outDir dist" |
| 14 | + } |
| 15 | + } |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +After `vp run build` runs once, the compiled files in `dist/` are archived. On subsequent runs that hit the cache, `dist/` is restored from that archive instead of recompiling. |
| 20 | + |
| 21 | +## The `output` Field |
| 22 | + |
| 23 | +The `output` field lets you control which files get archived and restored. It works exactly like `input` — same glob patterns, same `auto` directive, same negative patterns. |
| 24 | + |
| 25 | +### Default (omitted) |
| 26 | + |
| 27 | +Auto-detects written files. This is usually all you need: |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "tasks": { |
| 32 | + "build": { |
| 33 | + "command": "tsc --outDir dist" |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +### Explicit Globs |
| 40 | + |
| 41 | +If you only want specific files restored: |
| 42 | + |
| 43 | +```json |
| 44 | +{ |
| 45 | + "tasks": { |
| 46 | + "build": { |
| 47 | + "command": "tsc --outDir dist", |
| 48 | + "output": ["dist/**"] |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +This ignores any other files the task might write (temp files, logs, etc.) and only archives what's under `dist/`. |
| 55 | + |
| 56 | +### Negative Patterns |
| 57 | + |
| 58 | +Exclude certain output files from being cached: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "tasks": { |
| 63 | + "build": { |
| 64 | + "command": "webpack", |
| 65 | + "output": [{ "auto": true }, "!dist/cache/**"] |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +Here, everything the task writes is archived _except_ files under `dist/cache/`. |
| 72 | + |
| 73 | +### Disable Output Restoration |
| 74 | + |
| 75 | +If you don't want any files restored on cache hit — only terminal output replayed — pass an empty array: |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "tasks": { |
| 80 | + "test": { |
| 81 | + "command": "vitest run", |
| 82 | + "output": [] |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +## `output` and `input` Are Independent |
| 89 | + |
| 90 | +The `output` field has its own auto-detection, separate from `input`. You can disable auto-inference for inputs while keeping it for outputs: |
| 91 | + |
| 92 | +```json |
| 93 | +{ |
| 94 | + "tasks": { |
| 95 | + "build": { |
| 96 | + "command": "tsc --outDir dist", |
| 97 | + "input": ["src/**/*.ts", "tsconfig.json"], |
| 98 | + "output": [{ "auto": true }] |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +This tracks inputs via explicit globs only (no file-read inference), but still auto-detects which files the task writes for output restoration. |
| 105 | + |
| 106 | +## Configuration Summary |
| 107 | + |
| 108 | +| Configuration | Behavior | |
| 109 | +| ------------------------------------- | ----------------------------------- | |
| 110 | +| `output` omitted | Auto-detect written files (default) | |
| 111 | +| `output: [{ "auto": true }]` | Same as omitted | |
| 112 | +| `output: ["dist/**"]` | Only restore files under `dist/` | |
| 113 | +| `output: [{ "auto": true }, "!tmp/"]` | Auto-detect, but skip `tmp/` | |
| 114 | +| `output: []` | Don't restore any files | |
| 115 | + |
| 116 | +## Notes |
| 117 | + |
| 118 | +- Changing the `output` configuration invalidates the cache — if you switch from `["dist/**"]` to `["build/**"]`, the next run will be a cache miss. |
| 119 | +- Output archives are stored alongside the cache database. Running `vp cache clean` removes them. |
| 120 | +- The `output` field can't be used with `cache: false`, same as `input`. |
0 commit comments