Created
January 15, 2024 21:47
-
-
Save looskie/e53dc74366a45b8ce2bab4c1611b921c to your computer and use it in GitHub Desktop.
React Native: Check if any of your packages are not Gradle 8 compliant (no android.namespace)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const packages = fs.readdirSync('node_modules'); | |
for (const pkg of packages) { | |
const pkgPath = `node_modules/${pkg}`; | |
const hasAndroidDirectory = fs.existsSync(`${pkgPath}/android`); | |
let packageName = pkg; | |
let gradlePath = hasAndroidDirectory ? `${pkgPath}/android/build.gradle` : null; | |
if (!hasAndroidDirectory) { | |
if (!pkg.startsWith('@')) { | |
// we don't want any rando folder, this is just an edge case check for packages that start with an @ | |
continue; | |
} | |
try { | |
const subPackages = fs.readdirSync(pkgPath); | |
for (const subPkg of subPackages) { | |
const subPkgPath = `${pkgPath}/${subPkg}`; | |
const hasAndroidDirectory = fs.existsSync(`${subPkgPath}/android`); | |
if (!hasAndroidDirectory) continue; | |
gradlePath = `${subPkgPath}/android/build.gradle`; | |
packageName = `${pkg}/${subPkg}`; | |
} | |
} catch (e) { | |
continue; | |
} | |
} | |
if (!gradlePath || !fs.existsSync(gradlePath)) continue; | |
const buildGradle = fs.readFileSync(gradlePath, 'utf8'); | |
if (!buildGradle.includes('namespace')) { | |
console.log(`NO namespace on ${packageName}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment