@devries-cameron20 / t3code Mirror · read-only / commits / 97edb7ad42
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 11:00 UTC

perf(scripts): check:changed on Windows no longer spends minutes walking node_modules (2,500 s → 5.0 s) (#32023)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Pyseph committed Nov 15, 2026 at 06:45 UTC 97edb7ad42a0f2d3386d290cf77717ed09eca51e
2 files changed +84 -14
scripts/check-changed.test.ts
+42 -2
@@ -20,6 +20,7 @@ import {
20 defaultConcurrency,
21 docReaderTests,
22 gitLines,
23 + ignoredCheckInputs,
24 runSteps,
25 splitTests,
26 type Step,
@@ -297,16 +298,17 @@ function fixture(remotes: Record<string, "A" | "B">) {
298 };
299 }
300
300 -const compare = (root: string, ref: Option.Option<string>) =>
301 +const inFixture = <A, E>(effect: Effect.Effect<A, E, ChildProcessSpawner.ChildProcessSpawner>) =>
302 Effect.gen(function* () {
303 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
303 - return yield* comparisonBase(root, ref).pipe(
304 + return yield* effect.pipe(
305 Effect.provideService(
306 ChildProcessSpawner.ChildProcessSpawner,
307 ChildProcessSpawner.make((command) => spawner.spawn(ChildProcess.setEnv(command, env))),
308 ),
309 );
310 }).pipe(Effect.provide(NodeServices.layer), Effect.runPromise);
311 +const compare = (root: string, ref: Option.Option<string>) => inFixture(comparisonBase(root, ref));
312
313 it.each(["upstream", "team/upstream"])(
314 "compares against %s/main when the fork's origin/main lags it",
@@ -325,6 +327,44 @@ it("compares against an explicit ref instead of the closest remote main", async
327 assert.strictEqual(result.ref, "origin/main");
328 });
329
330 +it("lists the ignored inputs that main's pathspecs list, without entering node_modules", async () => {
331 + using project = fixture({});
332 + const git = (...args: Array<string>) =>
333 + NodeChildProcess.execFileSync("git", args, { cwd: project.root, encoding: "utf8", env });
334 + const write = (file: string, content = "") => {
335 + NodeFS.mkdirSync(NodePath.dirname(NodePath.join(project.root, file)), { recursive: true });
336 + NodeFS.writeFileSync(NodePath.join(project.root, file), content);
337 + };
338 + write(".gitignore", "node_modules/\ndist/\n.generated/\n.env*\n*.gen.d.ts\nreplaced/\nskipped/");
339 + for (const file of ["replaced", "skipped"]) write(file);
340 + git("add", ".");
341 + git("commit", "-m", "files that directories replace");
342 + git("update-index", "--skip-worktree", "skipped");
343 + for (const file of ["replaced", "skipped"]) NodeFS.rmSync(NodePath.join(project.root, file));
344 + for (const file of [
345 + ".env.local",
346 + "src/types.gen.d.ts",
347 + "src/.generated/routes.ts",
348 + "dist/index.d.ts",
349 + "dist/node_modules/pkg/index.d.ts",
350 + "node_modules/pkg/index.d.ts",
351 + // A package folder left behind by a branch switch.
352 + "old/dist/a.d.ts",
353 + "old/node_modules/pkg/index.d.ts",
354 + "replaced/sub/a.d.ts",
355 + "skipped/a.d.ts",
356 + ])
357 + write(file);
358 + const command =
359 + "ls-files -o -i --exclude-standard -- :(glob)**/.generated/** :(glob)**/.astro/** :(glob)**/*.d.ts :(glob)**/.env* :(exclude,glob)**/node_modules/**";
360 + const old = git(...command.split(" "))
361 + .split("\n")
362 + .filter(Boolean)
363 + .sort();
364 + assert.includeMembers(old, ["old/dist/a.d.ts", "replaced/sub/a.d.ts", "skipped/a.d.ts"]);
365 + assert.deepStrictEqual(await inFixture(ignoredCheckInputs(project.root)), old);
366 +});
367 +
368 function launcherFixture() {
369 const root = NodeFS.realpathSync(
370 NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3 checks & (fixture) ")),
scripts/check-changed.ts
+42 -12
@@ -150,6 +150,47 @@ export const git = Effect.fn("checkChanged.git")(function* (
150 export const gitLines = (cwd: string, args: ReadonlyArray<string>) =>
151 git(cwd, args).pipe(Effect.map((stdout) => stdout.toString().split("\n").filter(Boolean)));
152
153 +// Ignored files that checks read: generated sources, declarations, and env files.
154 +const checkInput = /(^|\/)\.(generated|astro)\/|\.d\.ts$|(^|\/)\.env[^/]*$/;
155 +const inNodeModules = /(^|\/)node_modules\//;
156 +
157 +// Pathspecs don't stop git from walking an ignored directory, and on Windows it follows pnpm's
158 +// junctions in node_modules until MAX_PATH. `--directory` lists one without entering it.
159 +export const ignoredCheckInputs = Effect.fn("checkChanged.ignoredCheckInputs")(function* (
160 + root: string,
161 +) {
162 + const list = (args: ReadonlyArray<string>) =>
163 + git(root, ["ls-files", "-z", ...args]).pipe(
164 + Effect.map((stdout) => stdout.toString().split("\0").filter(Boolean)),
165 + );
166 + const ignored = ["--others", "--ignored", "--exclude-standard"];
167 + // `--directory` hides a directory where the index has a file; `-k` lists those.
168 + const [listed, replaced] = yield* Effect.all(
169 + [list([...ignored, "--directory"]), list(["-k", "--directory"])],
170 + { concurrency: 2 },
171 + );
172 + const entries = [...new Set([...listed, ...replaced])].sort();
173 + // git lists an untracked directory whose contents are all ignored together with them;
174 + // listing it again would walk its node_modules.
175 + const directories = entries.filter(
176 + (entry, index) =>
177 + entry.endsWith("/") && !inNodeModules.test(entry) && !entries[index + 1]?.startsWith(entry),
178 + );
179 + const files = entries.filter((entry) => !entry.endsWith("/"));
180 + // Calls fit Windows' 32,767-character command line: 16 covers `:(literal)`, quotes, a space.
181 + // `.git/` matches nothing; it stops git starting its walk inside a nested repository.
182 + const longest = directories.reduce((max, dir) => Math.max(max, dir.length), 0);
183 + const size = Math.max(1, Math.floor(30_000 / (longest + 16)));
184 + for (let start = 0; start < directories.length; start += size) {
185 + const batch = directories.slice(start, start + size).map((dir) => `:(literal)${dir}`);
186 + files.push(...(yield* list([...ignored, "--", ":(literal).git/", ...batch])));
187 + }
188 + // A nested repository is listed by its directory, as the old pathspecs listed it.
189 + return files
190 + .filter((file) => !inNodeModules.test(file) && (file.endsWith("/") || checkInput.test(file)))
191 + .sort();
192 +});
193 +
194 export const comparisonBase = Effect.fn("checkChanged.comparisonBase")(function* (
195 root: string,
196 explicitRef: Option.Option<string>,
@@ -274,18 +315,7 @@ const checkChanged = Effect.fn("checkChanged")(function* (input: {
315 "--",
316 ]),
317 );
277 - const ignored = yield* lines(
278 - "ls-files",
279 - "--others",
280 - "--ignored",
281 - "--exclude-standard",
282 - "--",
283 - ":(glob)**/.generated/**",
284 - ":(glob)**/.astro/**",
285 - ":(glob)**/*.d.ts",
286 - ":(glob)**/.env*",
287 - ":(exclude,glob)**/node_modules/**",
288 - );
318 + const ignored = yield* ignoredCheckInputs(root);
319 for (const file of [
320 // Raw bytes of changed files too: .gitattributes normalizes line endings in
321 // the diff, but the formatter reads the file as it is on disk.