Skip to content

Instantly share code, notes, and snippets.

@Looskie
Created January 15, 2024 21:47
Show Gist options
  • Save Looskie/e53dc74366a45b8ce2bab4c1611b921c to your computer and use it in GitHub Desktop.
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)
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