History

Refactor mobile remote search and review state

- Move composer path search and source-control discovery into shared managed state - Persist review async/loading state in atoms and add coverage - Update mobile/web composers and review highlighter initialization

Julius Marminge committed 6 months ago

Commit e793c071 parent ab95f1137 files · +1366 −545Browse files

Showing the changes to scripts (4 of 37 files). Show all

Unified · Split

4 files
  1. scripts/mobile-native-static-check.ts +3 −13
  2. scripts/patch-expo-dev-launcher.mjs +0 −63
  3. scripts/patch-pierre-diffs-utils.mjs +0 −105
  4. scripts/patch-react-native-nitro-modules.mjs +0 −73
scripts/mobile-native-static-check.ts+3−13
@@ -40,8 +40,10 @@ const sourceExtensions = new Set([".swift", ".kt", ".kts"]); · 39 unmodified lines
40const excludedDirectories = new Set([40const excludedDirectories = new Set([
41 ".expo",41 ".expo",
42 ".git",42 ".git",
43 "android",
43 "build",44 "build",
44 "DerivedData",45 "DerivedData",
46 "ios",
45 "node_modules",47 "node_modules",
46 "Pods",48 "Pods",
47 "Vendor",49 "Vendor",
@@ -188,19 +190,7 @@ const runNativeStaticChecks = Effect.fn("runNativeStaticChecks")(function* () { · 140 unmodified lines
188 }190 }
189 }191 }
190 192
191 const androidProject = path.join(root, "android");193 yield* Console.log("Skipping generated native project folders: android/, ios/.");
192 const gradlew = path.join(
193 androidProject,
194 process.platform === "win32" ? "gradlew.bat" : "gradlew",
195 );
196 const fs = yield* FileSystem.FileSystem;
197
198 if (yield* fs.exists(gradlew)) {
199 const stat = yield* fs.stat(gradlew);
200 if (stat.type === "File") {
201 yield* runCommand(gradlew, ["lint"], androidProject);
202 }
203 }
204});194});
205 195
206export const mobileNativeStaticCheckCommand = Command.make("mobile-native-static-check", {}, () =>196export const mobileNativeStaticCheckCommand = Command.make("mobile-native-static-check", {}, () =>
scripts/patch-expo-dev-launcher.mjs+0−63
@@ -1,63 +0,0 @@
1import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2import { join } from "node:path";
3
4const root = process.cwd();
5
6const candidates = [join(root, "node_modules/expo-dev-launcher/ios/EXDevLauncherController.m")];
7
8const bunStorePath = join(root, "node_modules/.bun");
9
10if (existsSync(bunStorePath)) {
11 for (const entry of readdirSync(bunStorePath)) {
12 if (!entry.startsWith("expo-dev-launcher@")) {
13 continue;
14 }
15
16 candidates.push(
17 join(bunStorePath, entry, "node_modules/expo-dev-launcher/ios/EXDevLauncherController.m"),
18 );
19 }
20}
21
22const targetLine = "[manager updateCurrentBridge:self.appBridge];";
23const replacement = [
24 " // Expo SDK 55's dev launcher still references `self.appBridge`,",
25 " // but React Native 0.83 removed that property from the delegate base class.",
26 " // Newer Expo builds stop updating the dev menu bridge here.",
27].join("\n");
28
29let patchedCount = 0;
30let locatedCount = 0;
31
32for (const filePath of candidates) {
33 if (!existsSync(filePath)) {
34 continue;
35 }
36
37 locatedCount += 1;
38 const source = readFileSync(filePath, "utf8");
39
40 if (source.includes(replacement)) {
41 continue;
42 }
43
44 if (!source.includes(targetLine)) {
45 throw new Error(
46 `Found expo-dev-launcher source at ${filePath}, but the expected bridge line was missing.`,
47 );
48 }
49
50 const nextSource = source.replace(` ${targetLine}`, replacement);
51 writeFileSync(filePath, nextSource);
52 patchedCount += 1;
53}
54
55if (patchedCount > 0) {
56 console.log(
57 `[patch-expo-dev-launcher] patched ${patchedCount} expo-dev-launcher installation(s).`,
58 );
59} else if (locatedCount > 0) {
60 console.log("[patch-expo-dev-launcher] expo-dev-launcher already patched.");
61} else {
62 console.log("[patch-expo-dev-launcher] expo-dev-launcher not installed; skipping.");
63}
scripts/patch-pierre-diffs-utils.mjs+0−105
@@ -1,105 +0,0 @@
1import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2import { join } from "node:path";
3
4const root = process.cwd();
5const bunStorePath = join(root, "node_modules/.bun");
6
7const packageDirs = [];
8
9if (existsSync(join(root, "node_modules/@pierre/diffs"))) {
10 packageDirs.push(join(root, "node_modules/@pierre/diffs"));
11}
12
13if (existsSync(bunStorePath)) {
14 for (const entry of readdirSync(bunStorePath)) {
15 if (!entry.startsWith("@pierre+diffs@")) {
16 continue;
17 }
18
19 packageDirs.push(join(bunStorePath, entry, "node_modules/@pierre/diffs"));
20 }
21}
22
23const utilsIndexJs = [
24 'export { parsePatchFiles, processFile, processPatch } from "./parsePatchFiles.js";',
25 "export {",
26 " EXTENSION_TO_FILE_FORMAT,",
27 " getCustomExtensionsMap,",
28 " getCustomExtensionsVersion,",
29 " getFiletypeFromFileName,",
30 " replaceCustomExtensions,",
31 " setCustomExtension,",
32 '} from "./getFiletypeFromFileName.js";',
33 "",
34].join("\n");
35
36const utilsIndexDts = [
37 'export { parsePatchFiles, processFile, processPatch } from "./parsePatchFiles.js";',
38 "export {",
39 " EXTENSION_TO_FILE_FORMAT,",
40 " getCustomExtensionsMap,",
41 " getCustomExtensionsVersion,",
42 " getFiletypeFromFileName,",
43 " replaceCustomExtensions,",
44 " setCustomExtension,",
45 '} from "./getFiletypeFromFileName.js";',
46 'export type { ChangeTypes, FileDiffMetadata, ParsedPatch, SupportedLanguages } from "../types.js";',
47 "",
48].join("\n");
49
50let patchedCount = 0;
51let locatedCount = 0;
52
53for (const packageDir of packageDirs) {
54 if (!existsSync(packageDir)) {
55 continue;
56 }
57
58 locatedCount += 1;
59
60 const packageJsonPath = join(packageDir, "package.json");
61 const utilsIndexJsPath = join(packageDir, "dist/utils/index.js");
62 const utilsIndexDtsPath = join(packageDir, "dist/utils/index.d.ts");
63
64 const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
65 const currentUtilsExport = pkg.exports?.["./utils"];
66
67 const expectedUtilsExport = {
68 types: "./dist/utils/index.d.ts",
69 import: "./dist/utils/index.js",
70 };
71
72 const needsExportPatch =
73 currentUtilsExport?.types !== expectedUtilsExport.types ||
74 currentUtilsExport?.import !== expectedUtilsExport.import;
75
76 if (needsExportPatch) {
77 pkg.exports = {
78 ...pkg.exports,
79 "./utils": expectedUtilsExport,
80 };
81 writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
82 }
83
84 const currentJs = existsSync(utilsIndexJsPath) ? readFileSync(utilsIndexJsPath, "utf8") : null;
85 if (currentJs !== utilsIndexJs) {
86 writeFileSync(utilsIndexJsPath, utilsIndexJs);
87 }
88
89 const currentDts = existsSync(utilsIndexDtsPath) ? readFileSync(utilsIndexDtsPath, "utf8") : null;
90 if (currentDts !== utilsIndexDts) {
91 writeFileSync(utilsIndexDtsPath, utilsIndexDts);
92 }
93
94 if (needsExportPatch || currentJs !== utilsIndexJs || currentDts !== utilsIndexDts) {
95 patchedCount += 1;
96 }
97}
98
99if (patchedCount > 0) {
100 console.log(`[patch-pierre-diffs-utils] patched ${patchedCount} @pierre/diffs installation(s).`);
101} else if (locatedCount > 0) {
102 console.log("[patch-pierre-diffs-utils] @pierre/diffs already patched.");
103} else {
104 console.log("[patch-pierre-diffs-utils] @pierre/diffs not installed; skipping.");
105}
scripts/patch-react-native-nitro-modules.mjs+0−73
@@ -1,73 +0,0 @@
1import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2import { join } from "node:path";
3
4const root = process.cwd();
5
6const candidates = [join(root, "node_modules/react-native-nitro-modules/package.json")];
7
8const bunStorePath = join(root, "node_modules/.bun");
9
10if (existsSync(bunStorePath)) {
11 for (const entry of readdirSync(bunStorePath)) {
12 if (!entry.startsWith("react-native-nitro-modules@")) {
13 continue;
14 }
15
16 candidates.push(
17 join(bunStorePath, entry, "node_modules/react-native-nitro-modules/package.json"),
18 );
19 }
20}
21
22let patchedCount = 0;
23let locatedCount = 0;
24
25for (const filePath of candidates) {
26 if (!existsSync(filePath)) {
27 continue;
28 }
29
30 locatedCount += 1;
31
32 const source = readFileSync(filePath, "utf8");
33 const pkg = JSON.parse(source);
34
35 if (pkg.codegenConfig == null || typeof pkg.codegenConfig !== "object") {
36 throw new Error(
37 `Found react-native-nitro-modules package at ${filePath}, but codegenConfig was missing.`,
38 );
39 }
40
41 const iosConfig =
42 pkg.codegenConfig.ios != null && typeof pkg.codegenConfig.ios === "object"
43 ? pkg.codegenConfig.ios
44 : {};
45
46 const modulesProvider =
47 iosConfig.modulesProvider != null && typeof iosConfig.modulesProvider === "object"
48 ? iosConfig.modulesProvider
49 : {};
50
51 if (modulesProvider.NitroModules === "NativeNitroModules") {
52 continue;
53 }
54
55 modulesProvider.NitroModules = "NativeNitroModules";
56 iosConfig.modulesProvider = modulesProvider;
57 pkg.codegenConfig.ios = iosConfig;
58
59 writeFileSync(filePath, `${JSON.stringify(pkg, null, 2)}\n`);
60 patchedCount += 1;
61}
62
63if (patchedCount > 0) {
64 console.log(
65 `[patch-react-native-nitro-modules] patched ${patchedCount} react-native-nitro-modules installation(s).`,
66 );
67} else if (locatedCount > 0) {
68 console.log("[patch-react-native-nitro-modules] react-native-nitro-modules already patched.");
69} else {
70 console.log(
71 "[patch-react-native-nitro-modules] react-native-nitro-modules not installed; skipping.",
72 );
73}