@devries-cameron20 / t3code Mirror · read-only / commits / 6a9f588309
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 23, 04:15 UTC

perf(mobile): clean Android builds keep their Gradle and native caches (#20069)

Co-authored-by: Aaron Queen <bompus@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 18, 2026 at 12:20 UTC 6a9f588309132f223a92caeb6970669ea289a79e
3 files changed +108 -2
.gitignore
+1
@@ -33,6 +33,7 @@ dist-electron/
33 .showcase/
34 apps/mobile/.showcase/
35 apps/mobile/.generated/
36 +apps/mobile/.android-cache/
37 /.generated/
38 artifacts/app-store/screenshots/
39 .github/pr-assets/
scripts/mobile-native-client.test.ts new
+65
@@ -0,0 +1,65 @@
1 +import * as NodeServices from "@effect/platform-node/NodeServices";
2 +import { assert, it } from "@effect/vitest";
3 +import * as Effect from "effect/Effect";
4 +import * as FileSystem from "effect/FileSystem";
5 +import * as Path from "effect/Path";
6 +
7 +import { NativeClientError, prebuildAndroid } from "./mobile-native-client.ts";
8 +
9 +const caches = [".gradle/history", "app/.cxx/object"];
10 +
11 +// A generated Android project with Gradle and native outputs, and a stand-in for
12 +// `expo prebuild --clean`, which deletes the directory and writes fresh sources.
13 +const fixture = Effect.gen(function* () {
14 + const fs = yield* FileSystem.FileSystem;
15 + const path = yield* Path.Path;
16 + const mobile = yield* fs.makeTempDirectoryScoped({ prefix: "mobile-native-client-" });
17 + const android = path.join(mobile, "android");
18 + for (const cache of caches) {
19 + yield* fs.makeDirectory(path.dirname(path.join(android, cache)), { recursive: true });
20 + yield* fs.writeFileString(path.join(android, cache), cache);
21 + }
22 + const cleanPrebuild = Effect.gen(function* () {
23 + yield* fs.remove(android, { recursive: true });
24 + yield* fs.makeDirectory(path.join(android, "app"), { recursive: true });
25 + yield* fs.writeFileString(path.join(android, "app/build.gradle"), "regenerated");
26 + });
27 + const assertCachesRestored = Effect.gen(function* () {
28 + for (const cache of caches) {
29 + assert.strictEqual(yield* fs.readFileString(path.join(android, cache)), cache);
30 + }
31 + assert.deepStrictEqual(yield* fs.readDirectory(mobile), ["android"]);
32 + });
33 + return { fs, path, mobile, android, cleanPrebuild, assertCachesRestored };
34 +});
35 +
36 +it.layer(NodeServices.layer)("prebuildAndroid", (it) => {
37 + it.effect("keeps Gradle and native caches through a clean prebuild", () =>
38 + Effect.gen(function* () {
39 + const { fs, path, mobile, android, cleanPrebuild, assertCachesRestored } = yield* fixture;
40 +
41 + yield* prebuildAndroid(mobile, cleanPrebuild);
42 +
43 + assert.strictEqual(
44 + yield* fs.readFileString(path.join(android, "app/build.gradle")),
45 + "regenerated",
46 + );
47 + yield* assertCachesRestored;
48 + }),
49 + );
50 +
51 + it.effect("restores the caches and returns the error when prebuild fails", () =>
52 + Effect.gen(function* () {
53 + const { mobile, cleanPrebuild, assertCachesRestored } = yield* fixture;
54 + const failure = new NativeClientError({ message: "prebuild failed" });
55 +
56 + const error = yield* prebuildAndroid(
57 + mobile,
58 + cleanPrebuild.pipe(Effect.andThen(Effect.fail(failure))),
59 + ).pipe(Effect.flip);
60 +
61 + assert.strictEqual(error, failure);
62 + yield* assertCachesRestored;
63 + }),
64 + );
65 +});
scripts/mobile-native-client.ts
+42 -2
@@ -284,6 +284,45 @@ export const installedBinary = Effect.fn("installedBinary")(function* (
284 return yield* digest(hashes.sort().join("\n"));
285 });
286
287 +/**
288 + * Run `expo prebuild --clean` without losing `android/.gradle` (task history) and
289 + * `android/app/.cxx` (native compile outputs). Both invalidate by input, so a clean
290 + * rebuild only redoes changed work. `app/build` stays out: its autolinking and JS
291 + * bundle tasks do not declare every input. Each step is best-effort, because a lost
292 + * cache costs one slower build and must never cost the build.
293 + */
294 +export const prebuildAndroid = Effect.fn("nativeClient.prebuildAndroid")(function* <E, R>(
295 + mobile: string,
296 + prebuild: Effect.Effect<void, E, R>,
297 +) {
298 + const fs = yield* FileSystem.FileSystem;
299 + const path = yield* Path.Path;
300 + const android = path.join(mobile, "android");
301 + // A sibling of android/ keeps the renames on one filesystem. It is gitignored, and a
302 + // run killed mid-prebuild leaves it for the next run to clear.
303 + const saved = path.join(mobile, ".android-cache");
304 + const caches = [".gradle", "app/.cxx"];
305 + const clear = fs.remove(saved, { recursive: true, force: true }).pipe(Effect.ignore);
306 + const move = (from: string, to: string) =>
307 + Effect.forEach(
308 + caches,
309 + (cache) =>
310 + Effect.gen(function* () {
311 + const source = path.join(from, cache);
312 + const target = path.join(to, cache);
313 + if (!(yield* fs.exists(source)) || (yield* fs.exists(target))) return;
314 + yield* fs.makeDirectory(path.dirname(target), { recursive: true });
315 + yield* fs.rename(source, target);
316 + }).pipe(Effect.ignore),
317 + { discard: true },
318 + );
319 + yield* Effect.acquireUseRelease(
320 + clear.pipe(Effect.andThen(move(android, saved))),
321 + () => prebuild,
322 + () => move(saved, android).pipe(Effect.andThen(clear)),
323 + );
324 +});
325 +
326 const main = Command.make(
327 "mobile-native-client",
328 {
@@ -333,11 +372,12 @@ const main = Command.make(
372 message:
373 "Native directory contains tracked files; clean prebuild would overwrite them.",
374 });
336 - yield* command(
375 + const prebuild = command(
376 "vp",
377 ["exec", "expo", "prebuild", "--clean", "--platform", platform, "--no-install"],
378 true,
340 - );
379 + ).pipe(Effect.asVoid);
380 + yield* platform === "android" ? prebuildAndroid((yield* roots).mobile, prebuild) : prebuild;
381 if (platform === "ios") {
382 const output = yield* fs.makeTempDirectoryScoped({ prefix: "t3-native-client-" });
383 const { mobile } = yield* roots;