diff --git a/.changeset/itchy-shirts-join.md b/.changeset/itchy-shirts-join.md new file mode 100644 index 000000000..e819117c8 --- /dev/null +++ b/.changeset/itchy-shirts-join.md @@ -0,0 +1,5 @@ +--- +'@rock-js/platform-apple-helpers': patch +--- + +fix: run:ios with non-app targets ordered first diff --git a/packages/platform-apple-helpers/src/lib/commands/run/getBuildSettings.ts b/packages/platform-apple-helpers/src/lib/commands/run/getBuildSettings.ts index 76fe1e3cb..560b1d52d 100644 --- a/packages/platform-apple-helpers/src/lib/commands/run/getBuildSettings.ts +++ b/packages/platform-apple-helpers/src/lib/commands/run/getBuildSettings.ts @@ -39,7 +39,7 @@ export async function getBuildSettings({ ? getSimulatorPlatformSDK(platformName) : getDevicePlatformSDK(platformName); - const { stdout: buildSettings } = await spawn( + const { stdout: buildSettingsOutput } = await spawn( 'xcodebuild', [ xcodeProject.isWorkspace ? '-workspace' : '-project', @@ -64,13 +64,22 @@ export async function getBuildSettings({ action: string; buildSettings: BuildSettings; target: string; - }[] = JSON.parse(buildSettings).filter( - ({ target }: { target: string }) => - target !== 'React' && target !== 'React-Core', + }[] = JSON.parse(buildSettingsOutput).filter( + ({ + buildSettings: { WRAPPER_EXTENSION }, + }: { + buildSettings: BuildSettings; + }) => WRAPPER_EXTENSION === 'app' || WRAPPER_EXTENSION === 'framework', ); const targets = settings.map( ({ target: settingsTarget }: { target: string }) => settingsTarget, ); + if (settings.length === 0) { + throw new RockError( + `Failed to get build settings for your project. Looking for "app" or "framework" wrapper extensions but found none.`, + ); + } + let selectedTarget = targets[0]; if (target) { @@ -89,31 +98,21 @@ export async function getBuildSettings({ // Find app in all building settings - look for WRAPPER_EXTENSION: 'app', const targetIndex = targets.indexOf(selectedTarget); - const targetSettings = settings[targetIndex].buildSettings; - - const wrapperExtension = targetSettings.WRAPPER_EXTENSION; - - if (wrapperExtension === 'app' || wrapperExtension === 'framework') { - const buildSettings = settings[targetIndex].buildSettings; - - if (!buildSettings) { - throw new RockError('Failed to get build settings for your project'); - } - - const appPath = getBuildPath(buildSettings, platformName); - const infoPlistPath = buildSettings.INFOPLIST_PATH; - const targetBuildDir = buildSettings.TARGET_BUILD_DIR; + const buildSettings = settings[targetIndex].buildSettings; - return { - appPath, - infoPlistPath: path.join(targetBuildDir, infoPlistPath), - bundleIdentifier: buildSettings.PRODUCT_BUNDLE_IDENTIFIER, - }; + if (!buildSettings) { + throw new RockError('Failed to get build settings for your project'); } - throw new RockError( - `Failed to get build settings for your project. Looking for "app" or "framework" wrapper extension but found: ${wrapperExtension}`, - ); + const appPath = getBuildPath(buildSettings, platformName); + const infoPlistPath = buildSettings.INFOPLIST_PATH; + const targetBuildDir = buildSettings.TARGET_BUILD_DIR; + + return { + appPath, + infoPlistPath: path.join(targetBuildDir, infoPlistPath), + bundleIdentifier: buildSettings.PRODUCT_BUNDLE_IDENTIFIER, + }; } function getBuildPath( diff --git a/packages/platform-apple-helpers/src/lib/utils/pods.ts b/packages/platform-apple-helpers/src/lib/utils/pods.ts index 72697fa06..fa6c05d78 100644 --- a/packages/platform-apple-helpers/src/lib/utils/pods.ts +++ b/packages/platform-apple-helpers/src/lib/utils/pods.ts @@ -147,8 +147,16 @@ async function runPodInstall(options: { }); } catch (error) { loader.stop('Failed: Installing CocoaPods dependencies', 1); - const stderr = - (error as SubprocessError).stderr || (error as SubprocessError).output; + const stderr = (error as SubprocessError).stderr; + const fullOutput = (error as SubprocessError).output; + let errorMessage = stderr; + /** + * CocoaPods occasionally provides a markdown template with error message. + * We don't need the part above the Error secion. + */ + if (fullOutput.includes('### Error')) { + errorMessage = fullOutput.split('### Error')[1].trim(); + } /** * If CocoaPods failed due to repo being out of date, it will * include the update command in the error message. @@ -156,7 +164,7 @@ async function runPodInstall(options: { * `shouldHandleRepoUpdate` will be set to `false` to * prevent infinite loop (unlikely scenario) */ - if (stderr.includes('pod repo update') && shouldHandleRepoUpdate) { + if (fullOutput.includes('pod repo update') && shouldHandleRepoUpdate) { await runPodUpdate(options.sourceDir, options.useBundler); await runPodInstall({ shouldHandleRepoUpdate: false, @@ -170,7 +178,7 @@ async function runPodInstall(options: { throw new RockError( `CocoaPods installation failed. ${podErrorHelpMessage}`, - { cause: stderr }, + { cause: errorMessage }, ); } }