Skip to content

Commit 077d3af

Browse files
branchseerclaude
andauthored
fix: deterministic TypeScript type generation for run-config.ts (#194)
## Summary The `typescript_generation` test in CI was flaky due to non-deterministic ordering of type declarations in `run-config.ts`. ### Root cause `ts_rs::visit_dependencies` traverses type dependencies using a `HashMap` internally, so the visitation order of sibling types (e.g. `UserGlobalCacheConfig` vs `Task`) varies between runs. This caused `generate_ts_definition()` to emit declarations in a random order, making the test pass or fail depending on whether the output happened to match the checked-in file. ### Fix - Sort the collected type declarations alphabetically before emitting them, ensuring deterministic output regardless of `HashMap` iteration order - Regenerate `run-config.ts` with the now-stable ordering Verified stable across 20 consecutive regenerations. https://claude.ai/code/session_014eMPQ1Mw6EQpPkjkk1onsQ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9ce14cf commit 077d3af

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

crates/vite_task_graph/run-config.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
export type UserGlobalCacheConfig =
2-
| boolean
3-
| {
4-
/**
5-
* Enable caching for package.json scripts not defined in the `tasks` map.
6-
*
7-
* When `false`, package.json scripts will not be cached.
8-
* When `true`, package.json scripts will be cached with default settings.
9-
*
10-
* Default: `false`
11-
*/
12-
scripts?: boolean;
13-
/**
14-
* Global cache kill switch for task entries.
15-
*
16-
* When `false`, overrides all tasks to disable caching, even tasks with `cache: true`.
17-
* When `true`, respects each task's individual `cache` setting
18-
* (each task's `cache` defaults to `true` if omitted).
19-
*
20-
* Default: `true`
21-
*/
22-
tasks?: boolean;
23-
};
24-
251
export type Task = {
262
/**
273
* The command to run for the task.
@@ -60,6 +36,30 @@ export type Task = {
6036
}
6137
);
6238

39+
export type UserGlobalCacheConfig =
40+
| boolean
41+
| {
42+
/**
43+
* Enable caching for package.json scripts not defined in the `tasks` map.
44+
*
45+
* When `false`, package.json scripts will not be cached.
46+
* When `true`, package.json scripts will be cached with default settings.
47+
*
48+
* Default: `false`
49+
*/
50+
scripts?: boolean;
51+
/**
52+
* Global cache kill switch for task entries.
53+
*
54+
* When `false`, overrides all tasks to disable caching, even tasks with `cache: true`.
55+
* When `true`, respects each task's individual `cache` setting
56+
* (each task's `cache` defaults to `true` if omitted).
57+
*
58+
* Default: `true`
59+
*/
60+
tasks?: boolean;
61+
};
62+
6363
export type RunConfig = {
6464
/**
6565
* Root-level cache configuration.

crates/vite_task_graph/src/config/user.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ impl UserRunConfig {
225225
let mut collector = DeclCollector(Vec::new());
226226
Self::visit_dependencies(&mut collector);
227227

228+
// Sort declarations for deterministic output order
229+
collector.0.sort();
230+
228231
// Export all types
229232
let mut types: String = collector
230233
.0

0 commit comments

Comments
 (0)