|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | +const { argv } = require('process'); |
| 6 | + |
| 7 | +const parseArgs = require('minimist'); |
| 8 | +const { debug } = require('@sentry/core'); |
| 9 | +debug.enable(); |
| 10 | + |
| 11 | +const args = parseArgs(argv.slice(2)); |
| 12 | +if (!args['app-dir']) { |
| 13 | + throw new Error('Missing --app-dir'); |
| 14 | +} |
| 15 | + |
| 16 | +// Sonatype's legacy OSSRH host (oss.sonatype.org) reached end-of-life on |
| 17 | +// 2025-06-30 and is now unreliable — it intermittently answers with a |
| 18 | +// `504 Gateway Time-out` instead of a clean `404`. The React Native Gradle |
| 19 | +// plugin bundled with older RN versions (e.g. 0.71) hardcodes this host as a |
| 20 | +// snapshots repository and injects it into every project's repository list. |
| 21 | +// Gradle treats a 5xx from any declared repo as fatal (unlike a 404, which it |
| 22 | +// skips), so a single 504 breaks resolution of ANY dependency (react-android, |
| 23 | +// AGP lint, ...) even though those artifacts live on Maven Central / google(). |
| 24 | +// |
| 25 | +// We pin a stable RN release, so the snapshots repo is only ever used for |
| 26 | +// nightly (0.0.0-*) builds and serves no purpose here — remove it entirely so |
| 27 | +// nothing in the resolution path depends on a Sonatype snapshots host. |
| 28 | +const SNAPSHOT_REPO_LINE = /^[^\n]*mavenRepoFromUrl\("https:\/\/oss\.sonatype\.org\/content\/repositories\/snapshots\/"\)[^\n]*\n/m; |
| 29 | + |
| 30 | +const dependencyUtilsPath = path.join( |
| 31 | + args['app-dir'], |
| 32 | + 'node_modules', |
| 33 | + 'react-native-gradle-plugin', |
| 34 | + 'src', |
| 35 | + 'main', |
| 36 | + 'kotlin', |
| 37 | + 'com', |
| 38 | + 'facebook', |
| 39 | + 'react', |
| 40 | + 'utils', |
| 41 | + 'DependencyUtils.kt' |
| 42 | +); |
| 43 | + |
| 44 | +debug.log('Removing dead OSSRH snapshots repo from React Native Gradle plugin', dependencyUtilsPath); |
| 45 | + |
| 46 | +if (!fs.existsSync(dependencyUtilsPath)) { |
| 47 | + debug.log('DependencyUtils.kt not found, skipping patch (plugin likely already uses a live repo)'); |
| 48 | +} else { |
| 49 | + const source = fs.readFileSync(dependencyUtilsPath, 'utf8'); |
| 50 | + |
| 51 | + if (!SNAPSHOT_REPO_LINE.test(source)) { |
| 52 | + debug.log('DependencyUtils.kt does not reference the dead OSSRH host, nothing to patch'); |
| 53 | + } else { |
| 54 | + const patched = source.replace(SNAPSHOT_REPO_LINE, ''); |
| 55 | + fs.writeFileSync(dependencyUtilsPath, patched); |
| 56 | + debug.log('Removed dead OSSRH snapshots repo successfully!'); |
| 57 | + } |
| 58 | +} |
0 commit comments