Skip to content

[SCRIPT] Check Library Buildability script#163

Draft
radoslawrolka wants to merge 2 commits intomainfrom
rolkrado/check-script
Draft

[SCRIPT] Check Library Buildability script#163
radoslawrolka wants to merge 2 commits intomainfrom
rolkrado/check-script

Conversation

@radoslawrolka
Copy link
Collaborator

@radoslawrolka radoslawrolka commented Dec 9, 2025

📝 Description

Script that checks:

  • Presence of native code
  • Compatibility with New Architecture
  • Custom gradle plugins
  • Custom scripts
  • C++ code
  • externalNativeBuild settings
  • Dependencies on other libraries

🎯 Type of Change

Please delete options that are not relevant:

  • ✨ New feature (non-breaking change which adds functionality)

🧪 Testing

Please describe the tests you ran to verify your changes. Provide instructions so we can reproduce.

➜  builder git:(rolkrado/check-script) ✗ rm -rf TEMPORARY_LIBRARY_CHECKER_DIR && bun run check-library react-native-worklets 0.6.0
$ bun run library-checker.ts react-native-worklets "0.6.0"
Created temporary working directory at TEMPORARY_LIBRARY_CHECKER_DIR.
Installing package [email protected] in TEMPORARY_LIBRARY_CHECKER_DIR...
Package [email protected] installed.
Checking build.gradle dependencies in TEMPORARY_LIBRARY_CHECKER_DIR/node_modules/react-native-worklets/android/build.gradle...

📚 Library Buildability Check: [email protected]
Package Path: TEMPORARY_LIBRARY_CHECKER_DIR
═══════════════════════════════════════════════════
📋 Structural Analysis:
  - ✓ Android Implementation
  - ✓ iOS Implementation
  - ✓ Native Code Detected
  - ✓ C++ Code Detected
  - ✗ Custom Gradle Plugins
  - ✗ Custom Scripts
  - ✓ External Native Build (Android)
  - ✓ New Architecture Support

🔗 Native Dependencies (9):
  • react-native
  • @react-native-community/cli
  • @react-native/eslint-config
  • react-native-builder-bob
  • com.facebook.yoga:proguard-annotations:1.19.0
  • androidx.transition:transition:1.1.0
  • androidx.core:core:1.6.0
  • com.facebook.react:react-android
  • com.facebook.react:hermes-android

⚠️  Warnings (1):
  • C++ code detected (CMakeLists.txt)

Checks:
- Presence of native code
- Compatibility with New Architecture
- Custom react.native.config.js settings
- Custom gradle plugins
- Custom scripts
- C++ code
- `externalNativeBuild` settings
- Dependencies on other libraries
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new library checker script that analyzes React Native libraries for buildability by examining their structural requirements. The script creates a temporary working directory, installs the specified library, and performs static analysis on the package structure, native code, Gradle configuration, and dependencies to determine if the library can be built successfully.

Key changes:

  • Adds library-checker.ts script with comprehensive structural analysis capabilities
  • Updates package.json to include the check-library npm script
  • Adds documentation to README.md explaining the checker's purpose and usage
  • Updates ESLint config to ignore caught errors prefixed with underscore

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
packages/builder/library-checker.ts New script that performs static analysis on React Native libraries to check buildability, including native code detection, Gradle plugin analysis, C++ code detection, and dependency checking
packages/builder/package.json Adds check-library script command for running the library checker
packages/builder/README.md Documents the new library checker feature, its purpose, usage, and parameters
eslint.config.ts Extends unused variable ignore pattern to include caught errors, supporting the underscore prefix convention used in the new script

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Presence of native code
- Compatibility with New Architecture
- Custom gradle plugins
- Custom scripts
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md documentation mentions checking for "Custom scripts" but the script doesn't actually implement this check. Either remove this item from the documentation or implement the check in the script.

Suggested change
- Custom scripts

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +126
.filter((line) => line.includes('id '));
for (const line of pluginLines) {
if (
!knownPlugins.some((plugin) =>
line.includes(plugin)
)
) {
result.hasCustomGradlePlugins = true;
result.warnings.push(
`Custom gradle plugin detected: ${line.trim()}`
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkGradlePlugins function checks for plugins with id but this will also match lines that contain "id" in other contexts (like variable names, comments, or string values). Consider using a more precise regex pattern like /id\s+['"]([^'"]+)['"]/ to match only plugin declarations.

Suggested change
.filter((line) => line.includes('id '));
for (const line of pluginLines) {
if (
!knownPlugins.some((plugin) =>
line.includes(plugin)
)
) {
result.hasCustomGradlePlugins = true;
result.warnings.push(
`Custom gradle plugin detected: ${line.trim()}`
.map((line) => {
const match = line.match(/id\s+['"]([^'"]+)['"]/);
return match ? match[1] : null;
})
.filter((pluginName) => pluginName);
for (const pluginName of pluginLines) {
if (!knownPlugins.includes(pluginName)) {
result.hasCustomGradlePlugins = true;
result.warnings.push(
`Custom gradle plugin detected: ${pluginName}`

Copilot uses AI. Check for mistakes.
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));

// Check for native dependencies
const allDeps = {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkPackageJsonDependencies function only checks peerDependencies but not dependencies or devDependencies. This means native dependencies listed in the main dependencies field will be missed. Consider checking all dependency fields or clearly document why only peer dependencies are checked.

Suggested change
const allDeps = {
const allDeps = {
...packageJson.dependencies,
...packageJson.devDependencies,

Copilot uses AI. Check for mistakes.
return join(packageDir, 'apple');
}
return join(packageDir, 'ios');
}
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline before the function declaration. According to TypeScript style conventions, there should be a blank line between function declarations for better readability and consistency with the rest of the file (see lines 52, 68, 86, 99, etc.).

Suggested change
}
}

Copilot uses AI. Check for mistakes.
];

for (const dep of Object.keys(allDeps || {})) {
if (!knownDependencies.some((knownDep) => dep.includes(knownDep))) {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency filtering uses .includes() which can produce false positives. For example, a package named my-testing-library would be filtered out because it contains @testing in the knownDependencies array, even though it's not actually a testing library. Consider using more precise matching like checking if the dependency starts with the pattern (e.g., dep.startsWith(knownDep)) or exact matches for non-prefixed patterns.

Suggested change
if (!knownDependencies.some((knownDep) => dep.includes(knownDep))) {
if (
!knownDependencies.some((knownDep) => {
if (knownDep.endsWith('/') || knownDep.startsWith('@')) {
return dep.startsWith(knownDep);
} else {
return dep === knownDep;
}
})
) {

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +11
4. Building the library into an AAR artifact
5. Publishing to Maven Local repository
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numbered list skips step 3. The sequence goes from step 2 directly to step 4. Consider adding the missing step 3 (likely "Configuring the build environment" or similar) or renumbering the steps to maintain proper sequence.

Suggested change
4. Building the library into an AAR artifact
5. Publishing to Maven Local repository
3. Building the library into an AAR artifact
4. Publishing to Maven Local repository

Copilot uses AI. Check for mistakes.
if (existsSync(buildGradleFile)) {
try {
const content = readFileSync(buildGradleFile, 'utf-8');
if (content.includes('com.facebook.react')) {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkAndroidNewArchitectureSupport function only checks if the gradle file contains 'com.facebook.react' string, which is a very broad check. This could produce false positives since this string might appear in comments, dependency declarations, or other non-architecture-related contexts. Consider checking for more specific indicators of New Architecture support such as the presence of reactNativeArchitectures() function, newArchEnabled property, or React Native Codegen-related configurations.

Suggested change
if (content.includes('com.facebook.react')) {
// Look for more specific indicators of New Architecture support
const hasReactNativeArchitectures = /reactNativeArchitectures\s*\(/.test(content);
const hasNewArchEnabled = /newArchEnabled\s*[:=]\s*(true|['"]true['"])/.test(content);
const hasCodegen = /react-native-codegen/.test(content);
if (hasReactNativeArchitectures || hasNewArchEnabled || hasCodegen) {

Copilot uses AI. Check for mistakes.
* - Custom gradle plugins
* - C++ code
* - externalNativeBuild settings
* - Dependencies on other libraries
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script description says it checks for "Custom scripts" but there is no implementation that actually checks for custom scripts in package.json (like custom prebuild, postinstall, or other lifecycle scripts). Either remove this item from the description or implement the check.

Copilot uses AI. Check for mistakes.
@radoslawrolka radoslawrolka marked this pull request as draft December 16, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants