From 20b33f6e31be0639d111a1a2f5c58daf301224d1 Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Thu, 15 Jan 2026 15:37:32 +0800 Subject: [PATCH] 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 --- scripts/build-native.sh | 9 +++++++++ .../daily-notification-test/package.json | 2 +- .../scripts/fix-capacitor-plugins.js | 20 ++++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/build-native.sh b/scripts/build-native.sh index f5fc743..ab7c5c4 100755 --- a/scripts/build-native.sh +++ b/scripts/build-native.sh @@ -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 diff --git a/test-apps/daily-notification-test/package.json b/test-apps/daily-notification-test/package.json index 70ac1b8..0f3bcc3 100644 --- a/test-apps/daily-notification-test/package.json +++ b/test-apps/daily-notification-test/package.json @@ -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", diff --git a/test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js b/test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js index 28ffe17..956e0e4 100755 --- a/test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js +++ b/test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js @@ -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