|
| 1 | +# Task Inputs Configuration |
| 2 | + |
| 3 | +The `inputs` field controls which files are tracked for cache invalidation. When any tracked input file changes, the task's cache is invalidated and the task will re-run. |
| 4 | + |
| 5 | +## Default Behavior |
| 6 | + |
| 7 | +When `inputs` is omitted, vite-task automatically tracks files that the command reads during execution using fspy (file system spy): |
| 8 | + |
| 9 | +```json |
| 10 | +{ |
| 11 | + "tasks": { |
| 12 | + "build": { |
| 13 | + "command": "tsc" |
| 14 | + } |
| 15 | + } |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +Files read by `tsc` are automatically tracked. **In most cases, you don't need to configure `inputs` at all.** |
| 20 | + |
| 21 | +## Input Types |
| 22 | + |
| 23 | +### Glob Patterns |
| 24 | + |
| 25 | +Specify files using glob patterns relative to the package directory: |
| 26 | + |
| 27 | +```json |
| 28 | +{ |
| 29 | + "inputs": ["src/**/*.ts", "package.json"] |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +Supported glob syntax: |
| 34 | + |
| 35 | +- `*` - matches any characters except `/` |
| 36 | +- `**` - matches any characters including `/` |
| 37 | +- `?` - matches a single character |
| 38 | +- `[abc]` - matches any character in the brackets |
| 39 | +- `[!abc]` - matches any character not in the brackets |
| 40 | + |
| 41 | +### Auto-Inference |
| 42 | + |
| 43 | +Enable automatic input detection using fspy (file system spy): |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "inputs": [{ "auto": true }] |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +When enabled, vite-task automatically tracks files that the command actually reads during execution. This is the default behavior when `inputs` is omitted. |
| 52 | + |
| 53 | +### Negative Patterns |
| 54 | + |
| 55 | +Exclude files from tracking using `!` prefix: |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "inputs": ["src/**", "!src/**/*.test.ts"] |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +Negative patterns filter out files that would otherwise be matched by positive patterns or auto-inference. |
| 64 | + |
| 65 | +## Configuration Examples |
| 66 | + |
| 67 | +### Explicit Globs Only |
| 68 | + |
| 69 | +Specify exact files to track, disabling auto-inference: |
| 70 | + |
| 71 | +```json |
| 72 | +{ |
| 73 | + "tasks": { |
| 74 | + "build": { |
| 75 | + "command": "tsc", |
| 76 | + "inputs": ["src/**/*.ts", "tsconfig.json"] |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +Only files matching the globs are tracked. Files read by the command but not matching the globs are ignored. |
| 83 | + |
| 84 | +### Auto-Inference with Exclusions |
| 85 | + |
| 86 | +Track inferred files but exclude certain patterns: |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "tasks": { |
| 91 | + "build": { |
| 92 | + "command": "tsc", |
| 93 | + "inputs": [{ "auto": true }, "!dist/**", "!node_modules/**"] |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +Files in `dist/` and `node_modules/` won't trigger cache invalidation even if the command reads them. |
| 100 | + |
| 101 | +### Mixed Mode |
| 102 | + |
| 103 | +Combine explicit globs with auto-inference: |
| 104 | + |
| 105 | +```json |
| 106 | +{ |
| 107 | + "tasks": { |
| 108 | + "build": { |
| 109 | + "command": "tsc", |
| 110 | + "inputs": ["package.json", { "auto": true }, "!**/*.test.ts"] |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +- `package.json` is always tracked (explicit) |
| 117 | +- Files read by the command are tracked (auto) |
| 118 | +- Test files are excluded from both (negative pattern) |
| 119 | + |
| 120 | +### No File Inputs |
| 121 | + |
| 122 | +Disable all file tracking (cache only on command/env changes): |
| 123 | + |
| 124 | +```json |
| 125 | +{ |
| 126 | + "tasks": { |
| 127 | + "echo": { |
| 128 | + "command": "echo hello", |
| 129 | + "inputs": [] |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +The cache will only invalidate when the command itself or environment variables change. |
| 136 | + |
| 137 | +## Behavior Summary |
| 138 | + |
| 139 | +| Configuration | Auto-Inference | File Tracking | |
| 140 | +| ---------------------------------------- | -------------- | ----------------------------- | |
| 141 | +| `inputs` omitted | Enabled | Inferred files | |
| 142 | +| `inputs: [{ "auto": true }]` | Enabled | Inferred files | |
| 143 | +| `inputs: ["src/**"]` | Disabled | Matched files only | |
| 144 | +| `inputs: [{ "auto": true }, "!dist/**"]` | Enabled | Inferred files except `dist/` | |
| 145 | +| `inputs: ["pkg.json", { "auto": true }]` | Enabled | `pkg.json` + inferred files | |
| 146 | +| `inputs: []` | Disabled | No files tracked | |
| 147 | + |
| 148 | +## Important Notes |
| 149 | + |
| 150 | +### Glob Base Directory |
| 151 | + |
| 152 | +Glob patterns are resolved relative to the **package directory** (where `package.json` is located), not the task's working directory (`cwd`). |
| 153 | + |
| 154 | +```json |
| 155 | +{ |
| 156 | + "tasks": { |
| 157 | + "build": { |
| 158 | + "command": "tsc", |
| 159 | + "cwd": "src", |
| 160 | + "inputs": ["src/**/*.ts"] // Still relative to package root |
| 161 | + } |
| 162 | + } |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +### Negative Patterns Apply to Both Modes |
| 167 | + |
| 168 | +When using mixed mode, negative patterns filter both explicit globs AND auto-inferred files: |
| 169 | + |
| 170 | +```json |
| 171 | +{ |
| 172 | + "inputs": ["src/**", { "auto": true }, "!**/*.generated.ts"] |
| 173 | +} |
| 174 | +``` |
| 175 | + |
| 176 | +Files matching `*.generated.ts` are excluded whether they come from the `src/**` glob or from auto-inference. |
| 177 | + |
| 178 | +### Auto-Inference Behavior |
| 179 | + |
| 180 | +The auto-inference (fspy) is intentionally **cautious** - it tracks all files that a command reads, even auxiliary files. This means **negative patterns are expected to be useful** for filtering out files you don't want to trigger cache invalidation. |
| 181 | + |
| 182 | +Common files you might want to exclude: |
| 183 | + |
| 184 | +```json |
| 185 | +{ |
| 186 | + "inputs": [ |
| 187 | + { "auto": true }, |
| 188 | + "!**/*.tsbuildinfo", // TypeScript incremental build info |
| 189 | + "!**/tsconfig.tsbuildinfo", |
| 190 | + "!dist/**" // Build outputs that get read during builds |
| 191 | + ] |
| 192 | +} |
| 193 | +``` |
| 194 | + |
| 195 | +**When to use positive patterns vs negative patterns:** |
| 196 | + |
| 197 | +- **Negative patterns (expected)**: Use these to exclude files that fspy correctly detected but you don't want tracked (like `.tsbuildinfo`, cache files, build outputs) |
| 198 | +- **Positive patterns (usually indicates a bug)**: If you find yourself adding explicit positive patterns because fspy missed files that your command actually reads, this likely indicates a bug in fspy |
| 199 | + |
| 200 | +If you encounter a case where fspy fails to detect a file read, please [report the issue](https://github.com/voidzero-dev/vite-task/issues) with: |
| 201 | + |
| 202 | +1. The command being run |
| 203 | +2. The file(s) that weren't detected |
| 204 | +3. Steps to reproduce |
| 205 | + |
| 206 | +### Cache Disabled |
| 207 | + |
| 208 | +The `inputs` field cannot be used with `cache: false`: |
| 209 | + |
| 210 | +```json |
| 211 | +// ERROR: inputs cannot be specified when cache is disabled |
| 212 | +{ |
| 213 | + "tasks": { |
| 214 | + "dev": { |
| 215 | + "command": "vite dev", |
| 216 | + "cache": false, |
| 217 | + "inputs": ["src/**"] // This will cause a parse error |
| 218 | + } |
| 219 | + } |
| 220 | +} |
| 221 | +``` |
0 commit comments