Skip to content

Commit a2151d4

Browse files
t3dotggclaude
andcommitted
fix(scripts): check:changed cache key covers what checks read, and nothing else
- Hash the raw bytes of changed files. .gitattributes normalizes line endings in the diff, so a CRLF-only change hit the cache while format failed. - Hash only the ignored files a check can read (.generated, .astro, .env*). Hashing every ignored file read 2.3 GB of iOS Pods and dist output in a main checkout, and a symlink to a directory crashed with EISDIR. - Hash only regular files, so untracked nested repositories and directory symlinks are skipped. - Run the key diff with --no-ext-diff --no-textconv, so a user diff tool cannot hide a change. - knip ignores scripts/.knip-test-*, the throwaway project knip-schemas.test.ts writes while knip runs beside it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ff4a4da commit a2151d4

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎knip.jsonc‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
],
3131
"ignoreDependencies": ["esbuild"],
3232
// The `t3` npm package's files: copied into the package, never imported.
33-
"ignore": ["npm-launcher/**"],
33+
// knip-schemas.test.ts writes a throwaway project to .knip-test-*, which a
34+
// knip run beside it in check:changed must not report.
35+
"ignore": ["npm-launcher/**", ".knip-test-*/**"],
3436
},
3537
"apps/server": {
3638
// Vite+ pack entries and the launcher used by installed background services.

‎scripts/check-changed.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,47 @@ if (files.length === 0) {
5050
console.log(`check:changed: ${files.length} files since ${base.slice(0, 12)}`);
5151

5252
// The checked tree is the merge base plus the diff plus the untracked files.
53-
// Ignored files outside node_modules (generated sources, .astro types) and the
54-
// install state can change results too, so they are part of the key.
55-
// tsbuildinfo files are excluded: typecheck rewrites them on every run.
53+
// Ignored generated sources, .astro types, env files, and the install state can
54+
// change results too, so they are part of the key. Other ignored folders (iOS
55+
// Pods, dist, the Electron runtime) are large and no check reads them.
5656
// Computed again after a passing run, so edits made during the run are never
5757
// cached as passing.
5858
const inputKey = () => {
5959
const hash = NodeCrypto.createHash("sha256");
6060
hash.update(`${process.version}\0${base}\0`);
6161
hash.update(
62-
NodeChildProcess.execFileSync("git", ["diff", "--binary", "--no-renames", base, "--"], {
63-
cwd: root,
64-
maxBuffer: 1024 * 1024 * 1024,
65-
}),
62+
NodeChildProcess.execFileSync(
63+
"git",
64+
["diff", "--binary", "--no-renames", "--no-ext-diff", "--no-textconv", base, "--"],
65+
{ cwd: root, maxBuffer: 1024 * 1024 * 1024 },
66+
),
6667
);
6768
const ignored = git(
6869
"ls-files",
6970
"--others",
7071
"--ignored",
7172
"--exclude-standard",
7273
"--",
73-
":!node_modules/**",
74+
":(glob)**/.generated/**",
75+
":(glob)**/.astro/**",
76+
":(glob)**/.env*",
7477
":!**/node_modules/**",
75-
":!.t3/**",
76-
":!**/*.tsbuildinfo",
7778
);
7879
for (const file of [
80+
// Raw bytes of changed files too: .gitattributes normalizes line endings in
81+
// the diff, but the formatter reads the file as it is on disk.
82+
...git("diff", "--name-only", "--no-renames", base, "--"),
7983
...git("ls-files", "--others", "--exclude-standard"),
8084
...ignored,
8185
"node_modules/.modules.yaml",
8286
"node_modules/.pnpm/lock.yaml",
8387
]) {
8488
hash.update(`\0${file}\0`);
8589
const path = NodePath.join(root, file);
86-
if (NodeFS.existsSync(path)) hash.update(NodeFS.readFileSync(path));
90+
// Untracked nested repositories are listed as directories.
91+
if (NodeFS.statSync(path, { throwIfNoEntry: false })?.isFile()) {
92+
hash.update(NodeFS.readFileSync(path));
93+
}
8794
}
8895
return hash.digest("hex");
8996
};

0 commit comments

Comments
 (0)