fix(build): handle missing dependencies and Capacitor files during iOS build

Fixed build failures when test app dependencies aren't installed and when
Capacitor files don't exist during initial install.

Changes:
- Use `npx run-p` in test app build script to work without local install
- Add dependency check in build-native.sh before building Vue app
- Make fix-capacitor-plugins.js resilient to missing files during postinstall
  - Gracefully handles missing capacitor.plugins.json on first install
  - Provides clear messaging about when fixes will be applied
  - No longer exits with error when Capacitor hasn't been synced yet

This allows the build to complete successfully even when:
- npm dependencies aren't installed in test app
- Capacitor files don't exist yet (will be created during cap:sync:ios)

Files modified:
- scripts/build-native.sh
- test-apps/daily-notification-test/package.json
- test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js
This commit is contained in:
Jose Olarte III
2026-01-15 15:37:32 +08:00
parent 630fd3de81
commit 20b33f6e31
3 changed files with 23 additions and 8 deletions

View File

@@ -171,6 +171,15 @@ build_plugin_for_test_app_ios() {
# Navigate to test app directory
cd test-apps/daily-notification-test || exit 1
# Install dependencies if node_modules doesn't exist or is missing key packages
if [ ! -d "node_modules" ] || [ ! -f "node_modules/.bin/run-p" ]; then
log_info "Installing test app dependencies..."
if ! npm install; then
log_error "Failed to install test app dependencies"
exit 1
fi
fi
# Build Vue app
log_info "Building Vue app..."
if ! npm run build; then

View File

@@ -8,7 +8,7 @@
},
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"build": "npx run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build",

View File

@@ -35,13 +35,17 @@ const PLUGIN_ENTRY = {
function fixCapacitorPlugins() {
console.log('🔧 Fixing capacitor.plugins.json...');
// Check if the file exists - if not, it means Capacitor hasn't been synced yet
if (!fs.existsSync(PLUGINS_JSON_PATH)) {
console.log(' capacitor.plugins.json not found (Capacitor not synced yet - will be fixed after cap sync)');
return;
}
try {
// Read current content
let plugins = [];
if (fs.existsSync(PLUGINS_JSON_PATH)) {
const content = fs.readFileSync(PLUGINS_JSON_PATH, 'utf8');
plugins = JSON.parse(content);
}
const content = fs.readFileSync(PLUGINS_JSON_PATH, 'utf8');
plugins = JSON.parse(content);
// Check if our plugin is already there
const hasPlugin = plugins.some(p => p.name === PLUGIN_ENTRY.name);
@@ -56,7 +60,8 @@ function fixCapacitorPlugins() {
} catch (error) {
console.error('❌ Error fixing capacitor.plugins.json:', error.message);
process.exit(1);
// Don't exit - this might be a first-time install
console.log(' This is normal on first install. Run "npm run cap:sync" to generate Capacitor files.');
}
}
@@ -207,8 +212,9 @@ function fixAll() {
fixCapacitorSettingsGradle();
fixPodfile();
console.log('\n✅ All fixes applied successfully!');
console.log('💡 These fixes will persist until the next "npx cap sync"');
console.log('\n✅ Fix script completed!');
console.log('💡 Note: Some fixes may be skipped if Capacitor files don\'t exist yet.');
console.log('💡 Run "npm run cap:sync" to generate Capacitor files, then this script will apply fixes.');
}
// Run if called directly