Skip to content

Commit 3ba188a

Browse files
authored
fix(react-native): fix run-macos failing to find Xcode project (#2247)
1 parent 96c0605 commit 3ba188a

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/react-native/local-cli/runMacOS/runMacOS.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const {logger, CLIError, getDefaultUserTerminal} = (() => {
4444
return require(tools);
4545
})();
4646

47+
/**
48+
* @param {string} sourceDir
49+
* @param {XcodeProject} xcodeProject
50+
*/
51+
function getXcodeProjectPath(sourceDir, xcodeProject) {
52+
return path.join(sourceDir, xcodeProject.path || '.', xcodeProject.name);
53+
}
54+
4755
/**
4856
* @param {ProjectConfig} ctx
4957
* @param {Options} args
@@ -117,7 +125,7 @@ function runMacOS(_, ctx, args) {
117125
async function run(sourceDir, xcodeProject, scheme, args) {
118126
await buildProject(sourceDir, xcodeProject, scheme, args);
119127

120-
const buildSettings = getBuildSettings(xcodeProject, args.mode, scheme);
128+
const buildSettings = getBuildSettings(sourceDir, xcodeProject, args.mode, scheme);
121129
const appPath = path.join(
122130
buildSettings.TARGET_BUILD_DIR,
123131
buildSettings.FULL_PRODUCT_NAME,
@@ -162,7 +170,7 @@ function buildProject(sourceDir, xcodeProject, scheme, args) {
162170
return new Promise((resolve, reject) => {
163171
const xcodebuildArgs = [
164172
xcodeProject.isWorkspace ? '-workspace' : '-project',
165-
path.join(sourceDir, xcodeProject.path || '.', xcodeProject.name),
173+
getXcodeProjectPath(sourceDir, xcodeProject),
166174
'-configuration',
167175
args.mode,
168176
'-scheme',
@@ -231,18 +239,19 @@ function buildProject(sourceDir, xcodeProject, scheme, args) {
231239
}
232240

233241
/**
242+
* @param {string} sourceDir
234243
* @param {XcodeProject} xcodeProject
235244
* @param {string} configuration
236245
* @param {string} scheme
237246
* @returns {{ FULL_PRODUCT_NAME: string, INFOPLIST_PATH: string, TARGET_BUILD_DIR: string }}
238247
*/
239-
function getBuildSettings(xcodeProject, configuration, scheme) {
248+
function getBuildSettings(sourceDir, xcodeProject, configuration, scheme) {
240249
const settings = JSON.parse(
241250
child_process.execFileSync(
242251
'xcodebuild',
243252
[
244253
xcodeProject.isWorkspace ? '-workspace' : '-project',
245-
xcodeProject.name,
254+
getXcodeProjectPath(sourceDir, xcodeProject),
246255
'-scheme',
247256
scheme,
248257
'-sdk',
@@ -363,7 +372,7 @@ module.exports = [
363372
{
364373
name: '--port [number]',
365374
default: process.env.RCT_METRO_PORT || 8081,
366-
parse: val => Number(val),
375+
parse: (/** @type {string} */ val) => Number(val),
367376
},
368377
{
369378
name: '--terminal [string]',

0 commit comments

Comments
 (0)