fix: include Cordova plugin files in Android cloud-build upload bundle#577
Conversation
The Capgo CLI's extractNativeDependencies only parsed capacitor.settings.gradle, which lists Capacitor plugins. Cordova plugins are wired by `cap sync` into android/capacitor-cordova-android-plugins/build.gradle via `apply from: "../../node_modules/<plugin>/<file>.gradle"` lines and were never detected, so their files were stripped from the upload zip. Cloud builds then failed with errors like: Could not read script '.../node_modules/onesignal-cordova-plugin/ build-extras-onesignal.gradle' as it does not exist. This change parses that file for `apply from` references, tracks Cordova plugins in a new cordovaPackages set on NativeDependencies, and includes the entire package contents in the bundle (Cordova plugins do not follow Capacitor's <pkg>/android/ convention — gradle scripts live at the root, native sources under src/android/, etc.). A regression test reproducing the onesignal-cordova-plugin scenario is added to test/test-build-zip-filter.mjs.
📝 WalkthroughWalkthroughAdded Cordova plugin detection to Android native dependency extraction: parse Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/build/request.ts`:
- Around line 809-820: The cordova package match currently includes nested
node_modules (node_modules/<plugin>/node_modules/...), causing bundled deps to
be pulled into build.zip; modify the check in the android cordovaPackages loop
(using variables cordovaPrefix and normalizedPath and related to
addDirectoryToZip) to reject paths that are inside the plugin's nested
node_modules directory—i.e., after verifying normalizedPath
startsWith(cordovaPrefix), compute the remaining subpath and ensure it does NOT
start with "node_modules/" (or equal "node_modules"), only then return true so
only the plugin's own files (not its bundled dependencies) are included.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 586dd9d7-473a-4106-9bfd-4ffd0cb82115
📒 Files selected for processing (2)
src/build/request.tstest/test-build-zip-filter.mjs
The previous Cordova plugin inclusion in shouldIncludeFile matched anything under node_modules/<plugin>/, which would also pull the plugin's bundled transitive dependencies (node_modules/<plugin>/ node_modules/...) into the upload zip. Reject those subpaths so only the plugin's own files are bundled. Extended the Cordova regression test to also create a bundled transitive dep and assert it is not in the produced zip.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/build/request.ts (1)
764-764: Consider moving the regex to module scope to avoid recompilation.The
apply fromregex is compiled on every call toextractNativeDependencies. Moving it to module scope would avoid repeated compilation, though the performance impact is minimal since this function is called infrequently.♻️ Optional refactor to module scope
+// Regex for parsing Cordova plugin apply-from references (module-level for reuse) +const CORDOVA_APPLY_FROM_REGEX = /apply\s+from\s*:\s*["'](?:\.\.\/)+node_modules\/([^"']+)["']/g + async function extractNativeDependencies(Then at line 764:
- const applyFromMatches = cordovaContent.matchAll(/apply\s+from\s*:\s*["'](?:\.\.\/)+node_modules\/([^"']+)["']/g) + const applyFromMatches = cordovaContent.matchAll(CORDOVA_APPLY_FROM_REGEX)Note: Since
matchAllwith a global regex returns an iterator and doesn't mutate the regex, this is safe for reuse.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/build/request.ts` at line 764, Move the inline regex in extractNativeDependencies to module scope to avoid recompiling it on each call: create a top-level constant (e.g., APPLY_FROM_REGEX) with the pattern /apply\s+from\s*:\s*["'](?:\.\.\/)+node_modules\/([^"']+)["']/g and replace the inline regex usage in extractNativeDependencies (the cordovaContent.matchAll(...) call) with cordovaContent.matchAll(APPLY_FROM_REGEX); it’s safe to reuse because matchAll with a global regex returns an iterator and does not mutate the regex.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/build/request.ts`:
- Line 764: Move the inline regex in extractNativeDependencies to module scope
to avoid recompiling it on each call: create a top-level constant (e.g.,
APPLY_FROM_REGEX) with the pattern
/apply\s+from\s*:\s*["'](?:\.\.\/)+node_modules\/([^"']+)["']/g and replace the
inline regex usage in extractNativeDependencies (the
cordovaContent.matchAll(...) call) with
cordovaContent.matchAll(APPLY_FROM_REGEX); it’s safe to reuse because matchAll
with a global regex returns an iterator and does not mutate the regex.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 13087ede-51da-4336-9c4f-a8f1b6056566
📒 Files selected for processing (2)
src/build/request.tstest/test-build-zip-filter.mjs


Summary
onesignal-cordova-plugin) with errors likeCould not read script '.../node_modules/<plugin>/...gradle' as it does not exist.extractNativeDependenciesinsrc/build/request.tsonly parsedcapacitor.settings.gradle, which lists Capacitor plugins. Cordova plugins are wired bycap syncintoandroid/capacitor-cordova-android-plugins/build.gradleviaapply from: "../../node_modules/<plugin>/<file>.gradle"and were never detected, so their files were stripped from the upload zip.capacitor-cordova-android-plugins/build.gradleforapply fromreferences, track them on a newcordovaPackagesset inNativeDependencies, and include the entire package contents in the bundle. Cordova plugins don't follow Capacitor's<pkg>/android/convention — supporting gradle scripts live at the package root, native sources undersrc/android/, etc., so the simplest correct behavior is to ship the whole package.addDirectoryToZipis updated to walk into directories leading to either Capacitor or Cordova packages.Test plan
test:build-zip-filtercases still pass.test/test-build-zip-filter.mjsreproduces the onesignal-cordova-plugin scenario:capacitor.settings.gradleonly contains@capacitor/androidcapacitor-cordova-android-plugins/build.gradlereferences the Cordova plugin viaapply frombuild-extras-onesignal.gradle,plugin.xml,src/android/OneSignal.java,package.json, and the generatedcapacitor-cordova-android-plugins/build.gradleitself.Summary by CodeRabbit