From 40552506914e50472474856509a9b6617406100c Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Fri, 14 Apr 2023 13:26:35 +0200 Subject: [PATCH] fix: str.replace not a function issue --- .../src/tools/getProjectInfo.ts | 17 +++++++++++------ packages/cli-tools/src/errors.ts | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/cli-platform-ios/src/tools/getProjectInfo.ts b/packages/cli-platform-ios/src/tools/getProjectInfo.ts index 0eb5eb532..23189713e 100644 --- a/packages/cli-platform-ios/src/tools/getProjectInfo.ts +++ b/packages/cli-platform-ios/src/tools/getProjectInfo.ts @@ -1,15 +1,20 @@ -import {CLIError} from '@react-native-community/cli-tools'; import execa from 'execa'; import {IosProjectInfo} from '../types'; export function getProjectInfo(): IosProjectInfo { try { - const {project} = JSON.parse( - execa.sync('xcodebuild', ['-list', '-json']).stdout, - ); - + const out = execa.sync('xcodebuild', ['-list', '-json']).stdout; + const {project} = JSON.parse(out); return project; } catch (error) { - throw new CLIError(error as any); + if ( + (error as Error)?.message && + (error as Error).message.includes('xcodebuild: error:') + ) { + const match = (error as Error).message.match(/xcodebuild: error: (.*)/); + const err = match ? match[0] : error; + throw new Error(err as any); + } + throw new Error(error as any); } } diff --git a/packages/cli-tools/src/errors.ts b/packages/cli-tools/src/errors.ts index d83b7e769..b37b848c8 100644 --- a/packages/cli-tools/src/errors.ts +++ b/packages/cli-tools/src/errors.ts @@ -24,5 +24,5 @@ export class CLIError extends Error { */ export class UnknownProjectError extends Error {} -export const inlineString = (str: string) => +export const inlineString = (str: string = '') => str.replace(/(\s{2,})/gm, ' ').trim();