Skip to content

Commit

Permalink
fix(react-native): fix run-macos failing to find Xcode project (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Oct 25, 2024
1 parent 9ffd3da commit 104bb76
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/react-native/local-cli/runMacOS/runMacOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const {logger, CLIError, getDefaultUserTerminal} = (() => {
return require(tools);
})();

/**
* @param {string} sourceDir
* @param {XcodeProject} xcodeProject
*/
function getXcodeProjectPath(sourceDir, xcodeProject) {
return path.join(sourceDir, xcodeProject.path || '.', xcodeProject.name);
}

/**
* @param {ProjectConfig} ctx
* @param {Options} args
Expand Down Expand Up @@ -117,7 +125,7 @@ function runMacOS(_, ctx, args) {
async function run(sourceDir, xcodeProject, scheme, args) {
await buildProject(sourceDir, xcodeProject, scheme, args);

const buildSettings = getBuildSettings(xcodeProject, args.mode, scheme);
const buildSettings = getBuildSettings(sourceDir, xcodeProject, args.mode, scheme);
const appPath = path.join(
buildSettings.TARGET_BUILD_DIR,
buildSettings.FULL_PRODUCT_NAME,
Expand Down Expand Up @@ -162,7 +170,7 @@ function buildProject(sourceDir, xcodeProject, scheme, args) {
return new Promise((resolve, reject) => {
const xcodebuildArgs = [
xcodeProject.isWorkspace ? '-workspace' : '-project',
path.join(sourceDir, xcodeProject.path || '.', xcodeProject.name),
getXcodeProjectPath(sourceDir, xcodeProject),
'-configuration',
args.mode,
'-scheme',
Expand Down Expand Up @@ -231,18 +239,19 @@ function buildProject(sourceDir, xcodeProject, scheme, args) {
}

/**
* @param {string} sourceDir
* @param {XcodeProject} xcodeProject
* @param {string} configuration
* @param {string} scheme
* @returns {{ FULL_PRODUCT_NAME: string, INFOPLIST_PATH: string, TARGET_BUILD_DIR: string }}
*/
function getBuildSettings(xcodeProject, configuration, scheme) {
function getBuildSettings(sourceDir, xcodeProject, configuration, scheme) {
const settings = JSON.parse(
child_process.execFileSync(
'xcodebuild',
[
xcodeProject.isWorkspace ? '-workspace' : '-project',
xcodeProject.name,
getXcodeProjectPath(sourceDir, xcodeProject),
'-scheme',
scheme,
'-sdk',
Expand Down Expand Up @@ -363,7 +372,7 @@ module.exports = [
{
name: '--port [number]',
default: process.env.RCT_METRO_PORT || 8081,
parse: val => Number(val),
parse: (/** @type {string} */ val) => Number(val),
},
{
name: '--terminal [string]',
Expand Down

0 comments on commit 104bb76

Please sign in to comment.