GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs: explain rebuildable inputs in automatic data tracking (#3419) · voidzero-dev/vite-plus@12ce0fb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • config
      • run.md
    • guide
      • automatic-data-tracking.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/config/run.md‎

Copy file name to clipboardExpand all lines: docs/config/run.md
+8-7Lines changed: 8 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,12 @@ Vite Task automatically detects which files a command uses. See [Automatic Data
265265

266266
```ts [vite.config.ts]
267267
tasks: {
268-
build: {
269-
command: 'vp build',
268+
lint: {
269+
command: 'vp lint',
270270
cache: {
271271
// Use `{ auto: true }` to use automatic fingerprinting (default).
272-
input: [{ auto: true }, '!**/*.tsbuildinfo', '!dist/**'],
272+
// Keep the build task's `dist` folder from affecting this task.
273+
input: [{ auto: true }, '!dist/**'],
273274
},
274275
},
275276
}
@@ -348,14 +349,14 @@ tasks: {
348349

349350
Use `{ auto: true }` to keep automatic write tracking while adding explicit output globs.
350351

351-
This is useful when a task writes files that should not be restored from the cache. For example, exclude TypeScript `.tsbuildinfo` files:
352+
This is useful when a task writes files that should not be restored from the cache, such as a debug log:
352353

353354
```ts [vite.config.ts]
354355
tasks: {
355-
typecheck: {
356-
command: 'tsc --build',
356+
build: {
357+
command: 'node build.mjs',
357358
cache: {
358-
output: [{ auto: true }, '!*.tsbuildinfo'],
359+
output: [{ auto: true }, '!build.log'],
359360
},
360361
},
361362
}
Collapse file

‎docs/guide/automatic-data-tracking.md‎

Copy file name to clipboardExpand all lines: docs/guide/automatic-data-tracking.md
+138Lines changed: 138 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,144 @@ For this task, Vite Task records source files, config files, missing files the c
3939

4040
File system tracking also tracks outputs. If you omit [`cache.output`](/config/run#cache-output), Vite Task archives files the command writes after a successful run and restores them on a cache hit.
4141

42+
### Rebuildable Inputs
43+
44+
Some tools read files they also write:
45+
46+
- With [`exports`](https://tsdown.dev/options/package-exports) enabled, tsdown reads `package.json` and writes the generated `exports` field back into it.
47+
- Many build tools list `dist` to delete the old build before they write a new one there.
48+
- Tools with their own cache read it and write it back, as `tsc --incremental` does with `tsconfig.tsbuildinfo`.
49+
50+
This section explains how Vite Task handles files and folders that a task both reads and writes.
51+
52+
Vite Task calls these files and folders **rebuildable**: the task produces them itself, so they don't have to exist before it runs. A task can rebuild:
53+
54+
- Files it writes, such as `dist/index.mjs` or the `package.json` that tsdown updates.
55+
- Folders where the task wrote everything inside, such as `dist`.
56+
57+
::: warning
58+
Rebuildable inputs assume that a task doesn't keep changing its outputs when its inputs stay the same.
59+
60+
For example, a script that appends data to a file on every run breaks this assumption, and Vite Task can't detect it. Vite Task caches the file as the script left it, so the next run is a cache hit that restores the file without appending anything.
61+
:::
62+
63+
After the task finishes, Vite Task fingerprints its inputs as the task left them. On the next run:
64+
65+
- A rebuildable input may be missing, as on a fresh clone or after you delete it. The cache still hits and restores it with the task's outputs.
66+
- A rebuildable file that exists must match what the task left. If something else changed it, the cache misses.
67+
- Inputs that aren't rebuildable, such as your source files, are still checked strictly. Deleting or editing one causes a cache miss.
68+
69+
#### Example: A Task Rewriting Sources
70+
71+
```ts [vite.config.ts]
72+
tasks: {
73+
build: {
74+
// `--exports` makes tsdown write the generated `exports` field into package.json.
75+
command: 'tsdown --exports',
76+
},
77+
}
78+
```
79+
80+
```
81+
my-lib/
82+
├── src/
83+
│ └── index.ts # input: tsdown reads it
84+
└── package.json # rebuildable: tsdown reads it, then writes "exports" into it
85+
```
86+
87+
On the next run, Vite Task compares `package.json` with the file tsdown wrote, so the `exports` field that tsdown added doesn't cause a cache miss:
88+
89+
```bash
90+
$ vp run build # first run: tsdown adds "exports" to package.json
91+
$ vp run build # cache hit
92+
```
93+
94+
Editing `package.json` yourself still causes a cache miss, as it should, because tsdown has to run again with your changes:
95+
96+
```bash
97+
$ vp pm pkg set version=1.1.0
98+
$ vp run build # cache miss: 'package.json' modified
99+
```
100+
101+
#### Example: A Task Listing Its Output Folder For Deletion
102+
103+
```ts [vite.config.ts]
104+
tasks: {
105+
build: {
106+
// `--clean` deletes the old build in `dist` before tsdown writes a new one.
107+
command: 'tsdown --clean',
108+
},
109+
}
110+
```
111+
112+
```
113+
my-lib/
114+
├── src/
115+
│ └── index.ts # input
116+
├── package.json # input
117+
└── dist/ # rebuildable: the task wrote everything inside
118+
└── index.mjs # rebuildable: the task writes it
119+
```
120+
121+
Listing `dist` makes it an input. Since the task wrote everything inside `dist`, the whole folder is rebuildable:
122+
123+
```bash
124+
$ vp run build # first run: tsdown writes dist/
125+
$ rm -rf dist # as on a fresh clone
126+
$ vp run build # cache hit: dist/ is restored
127+
```
128+
129+
You don't need `'!dist/**'` in `cache.input` to keep `dist` out of the task's inputs, even though the task lists `dist` to delete the old build and then writes a new one.
130+
131+
#### Example: A Task Reading And Writing Its Own Cache
132+
133+
```ts [vite.config.ts]
134+
tasks: {
135+
typecheck: {
136+
command: 'tsc --incremental --noEmit',
137+
},
138+
}
139+
```
140+
141+
```
142+
my-app/
143+
├── src/
144+
│ └── main.ts # input: tsc reads it
145+
├── tsconfig.json # input: tsc reads it
146+
└── tsconfig.tsbuildinfo # rebuildable: tsc reads its cache from it, then writes it back
147+
```
148+
149+
Vite Task compares `tsconfig.tsbuildinfo` with the file tsc wrote, so tsc's updates to it don't cause a cache miss. If the file is missing, as on a fresh clone, a cache hit restores it:
150+
151+
```bash
152+
$ vp run typecheck # first run: tsc writes tsconfig.tsbuildinfo
153+
$ vp run typecheck # cache hit
154+
$ rm tsconfig.tsbuildinfo # as on a fresh clone
155+
$ vp run typecheck # cache hit: tsconfig.tsbuildinfo is restored
156+
```
157+
158+
#### Avoid Caching Tasks That Modify Files In Place
159+
160+
A task that rewrites your source files makes them rebuildable. If a cached `vp fmt` rewrites every file in `src/utils`, the whole folder becomes rebuildable:
161+
162+
```
163+
src/
164+
└── utils/ # rebuildable: vp fmt rewrote everything inside
165+
├── a.ts # rebuildable: vp fmt rewrote it
166+
└── b.ts # rebuildable: vp fmt rewrote it
167+
```
168+
169+
Deleting `src/utils` is then a cache hit that writes the folder back.
170+
171+
Turn off auto-fix in the lint and format tasks you cache:
172+
173+
```ts [vite.config.ts]
174+
tasks: {
175+
lint: 'vp lint', // instead of `vp lint --fix`
176+
format: 'vp fmt --check', // instead of `vp fmt`
177+
}
178+
```
179+
42180
### Limitations
43181

44182
Vite Task cannot track environment variable reads, and it cannot always tell which tracked paths are stable inputs, generated outputs, or tool-managed cache paths that should not become inputs or outputs.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.