Skip to content

Commit 31d99df

Browse files
authored
fix(react-native): implement projectConfig and dependencyConfig (#2231)
1 parent 8ea9b6a commit 31d99df

File tree

5 files changed

+48
-68
lines changed

5 files changed

+48
-68
lines changed

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// @ts-check
12
/**
23
* Copyright (c) Microsoft Corporation. All rights reserved.
34
* Licensed under the MIT License.
45
* @format
5-
* @ts-check
66
*/
77
'use strict';
88

@@ -20,14 +20,22 @@
2020
*
2121
* @typedef {{
2222
* name: string;
23+
* path: string;
2324
* isWorkspace: boolean;
2425
* }} XcodeProject
26+
*
27+
* @typedef {{
28+
* project?: {
29+
* macos?: {
30+
* sourceDir: string;
31+
* xcodeProject: XcodeProject;
32+
* }
33+
* }
34+
* }} ProjectConfig
2535
*/
2636

27-
const findXcodeProject = require('./findXcodeProject');
2837
const chalk = require('chalk');
2938
const child_process = require('child_process');
30-
const fs = require('fs');
3139
const path = require('path');
3240
const {logger, CLIError, getDefaultUserTerminal} = (() => {
3341
const cli = require.resolve('@react-native-community/cli/package.json');
@@ -37,16 +45,11 @@ const {logger, CLIError, getDefaultUserTerminal} = (() => {
3745
})();
3846

3947
/**
48+
* @param {ProjectConfig} ctx
4049
* @param {Options} args
41-
* @returns {{ xcodeProject: XcodeProject, scheme: string }}
50+
* @returns {{ sourceDir: string, xcodeProject: XcodeProject, scheme: string }}
4251
*/
43-
function parseArgs(args) {
44-
if (!fs.existsSync(args.projectPath)) {
45-
throw new CLIError(
46-
'macOS project folder not found. Are you sure this is a React Native project?',
47-
);
48-
}
49-
52+
function parseArgs(ctx, args) {
5053
if (args.configuration) {
5154
logger.warn(
5255
'Argument --configuration has been deprecated and will be removed in a future release, please use --mode instead.',
@@ -57,15 +60,20 @@ function parseArgs(args) {
5760
}
5861
}
5962

60-
process.chdir(args.projectPath);
63+
const {sourceDir, xcodeProject} = ctx.project?.macos ?? {};
64+
if (!sourceDir) {
65+
throw new CLIError(
66+
'macOS project folder not found. Are you sure this is a React Native project?',
67+
);
68+
}
6169

62-
const xcodeProject = findXcodeProject(fs.readdirSync('.'));
6370
if (!xcodeProject) {
6471
throw new CLIError(
65-
`Could not find Xcode project files in "${args.projectPath}" folder`,
72+
'Xcode project for macOS not found. Did you forget to run `pod install`?',
6673
);
6774
}
6875

76+
// TODO: Find schemes using https://github.com/microsoft/rnx-kit/blob/2b4c569cda9e3755ba7afce42d846601bcc7c4e3/packages/tools-apple/src/scheme.ts#L5
6977
const inferredSchemeName =
7078
path.basename(xcodeProject.name, path.extname(xcodeProject.name)) +
7179
'-macOS';
@@ -77,36 +85,37 @@ function parseArgs(args) {
7785
} "${chalk.bold(xcodeProject.name)}"`,
7886
);
7987

80-
return {xcodeProject, scheme};
88+
return {sourceDir, xcodeProject, scheme};
8189
}
8290

8391
/**
8492
* @param {string[]} _
85-
* @param {Record<string, unknown>} _ctx
93+
* @param {ProjectConfig} ctx
8694
* @param {Options} args
8795
*/
88-
function buildMacOS(_, _ctx, args) {
89-
const {xcodeProject, scheme} = parseArgs(args);
90-
return buildProject(xcodeProject, scheme, {...args, packager: false});
96+
function buildMacOS(_, ctx, args) {
97+
const {sourceDir, xcodeProject, scheme} = parseArgs(ctx, args);
98+
return buildProject(sourceDir, xcodeProject, scheme, {...args, packager: false});
9199
}
92100

93101
/**
94102
* @param {string[]} _
95-
* @param {Record<string, unknown>} _ctx
103+
* @param {ProjectConfig} ctx
96104
* @param {Options} args
97105
*/
98-
function runMacOS(_, _ctx, args) {
99-
const {xcodeProject, scheme} = parseArgs(args);
100-
return run(xcodeProject, scheme, args);
106+
function runMacOS(_, ctx, args) {
107+
const {sourceDir, xcodeProject, scheme} = parseArgs(ctx, args);
108+
return run(sourceDir, xcodeProject, scheme, args);
101109
}
102110

103111
/**
112+
* @param {string} sourceDir
104113
* @param {XcodeProject} xcodeProject
105114
* @param {string} scheme
106115
* @param {Options} args
107116
*/
108-
async function run(xcodeProject, scheme, args) {
109-
await buildProject(xcodeProject, scheme, args);
117+
async function run(sourceDir, xcodeProject, scheme, args) {
118+
await buildProject(sourceDir, xcodeProject, scheme, args);
110119

111120
const buildSettings = getBuildSettings(xcodeProject, args.mode, scheme);
112121
const appPath = path.join(
@@ -143,15 +152,17 @@ async function run(xcodeProject, scheme, args) {
143152
}
144153

145154
/**
155+
* @param {string} sourceDir
146156
* @param {XcodeProject} xcodeProject
147157
* @param {string} scheme
148158
* @param {Options} args
159+
* @returns {Promise<void>}
149160
*/
150-
function buildProject(xcodeProject, scheme, args) {
161+
function buildProject(sourceDir, xcodeProject, scheme, args) {
151162
return new Promise((resolve, reject) => {
152163
const xcodebuildArgs = [
153164
xcodeProject.isWorkspace ? '-workspace' : '-project',
154-
xcodeProject.name,
165+
path.join(sourceDir, xcodeProject.path, xcodeProject.name),
155166
'-configuration',
156167
args.mode,
157168
'-scheme',

packages/react-native/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"@jest/create-cache-key-function": "^29.6.3",
114114
"@react-native-community/cli": "14.0.0-alpha.2",
115115
"@react-native-community/cli-platform-android": "14.0.0-alpha.2",
116+
"@react-native-community/cli-platform-apple": "14.0.0-alpha.2",
116117
"@react-native-community/cli-platform-ios": "14.0.0-alpha.2",
117118
"@react-native-mac/virtualized-lists": "0.75.0-main",
118119
"@react-native/assets-registry": "0.75.0-main",

packages/react-native/react-native.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ try {
4343
}
4444

4545
const macosCommands = require('./local-cli/runMacOS/runMacOS'); // [macOS]
46+
const {
47+
getDependencyConfig,
48+
getProjectConfig,
49+
} = require('@react-native-community/cli-platform-apple'); // [macOS]
4650
const {
4751
bundleCommand,
4852
startCommand,
@@ -128,8 +132,8 @@ config.platforms.macos = {
128132
) => {},
129133
};
130134
},
131-
projectConfig: () => null,
132-
dependencyConfig: () => null,
135+
projectConfig: getProjectConfig({platformName: 'macos'}),
136+
dependencyConfig: getDependencyConfig({platformName: 'macos'}),
133137
npmPackageName: 'react-native-macos',
134138
};
135139
// macOS]

yarn.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12937,6 +12937,7 @@ __metadata:
1293712937
"@jest/create-cache-key-function": "npm:^29.6.3"
1293812938
"@react-native-community/cli": "npm:14.0.0-alpha.2"
1293912939
"@react-native-community/cli-platform-android": "npm:14.0.0-alpha.2"
12940+
"@react-native-community/cli-platform-apple": "npm:14.0.0-alpha.2"
1294012941
"@react-native-community/cli-platform-ios": "npm:14.0.0-alpha.2"
1294112942
"@react-native-mac/virtualized-lists": "npm:0.75.0-main"
1294212943
"@react-native/assets-registry": "npm:0.75.0-main"
@@ -14651,11 +14652,11 @@ __metadata:
1465114652

1465214653
"typescript@patch:typescript@npm%3A^5.6.3#optional!builtin<compat/typescript>":
1465314654
version: 5.6.3
14654-
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=379a07"
14655+
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=8c6c40"
1465514656
bin:
1465614657
tsc: bin/tsc
1465714658
tsserver: bin/tsserver
14658-
checksum: 10c0/ac8307bb06bbfd08ae7137da740769b7d8c3ee5943188743bb622c621f8ad61d244767480f90fbd840277fbf152d8932aa20c33f867dea1bb5e79b187ca1a92f
14659+
checksum: 10c0/7c9d2e07c81226d60435939618c91ec2ff0b75fbfa106eec3430f0fcf93a584bc6c73176676f532d78c3594fe28a54b36eb40b3d75593071a7ec91301533ace7
1465914660
languageName: node
1466014661
linkType: hard
1466114662

0 commit comments

Comments
 (0)