Rebuild PR #2013 on top of current origin/main without the duplicated commit lineage.
Showing the changes to scripts/patch-react-native-nitro-modules.mjs (1 of 189 files). Show all
Unified · Split
| @@ -0,0 +1,73 @@ | |||
| 1 | import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; | ||
| 2 | import { join } from "node:path"; | ||
| 3 | |||
| 4 | const root = process.cwd(); | ||
| 5 | |||
| 6 | const candidates = [join(root, "node_modules/react-native-nitro-modules/package.json")]; | ||
| 7 | |||
| 8 | const bunStorePath = join(root, "node_modules/.bun"); | ||
| 9 | |||
| 10 | if (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 | |||
| 22 | let patchedCount = 0; | ||
| 23 | let locatedCount = 0; | ||
| 24 | |||
| 25 | for (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 | |||
| 63 | if (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 | } | ||