Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eba1828

Browse files
blakeffacebook-github-bot
authored andcommittedJun 5, 2024
directly call community-cli-plugin in react-native-xcode.sh (facebook#44721)
Summary: Pull Request resolved: facebook#44721 For iOS builds of `react-native`, the [react-native-xcode.sh](https://www.internalfb.com/code/fbsource/[7ad79aae3e8bf565d53f087ac7f7b7622b19acec]/xplat/js/react-native-github/packages/react-native/scripts/react-native-xcode.sh) script is executed as one of the build phases. This phase bundles the JS application (dev or production). I've updated this to use the new `bundle.js` script instead of calling the `react-native/cli.js`. This is identical except with how the config is captured: {F1669960016} This is similar to our approach with the Gradle plugin, giving Framework authors more control. **Other:** formatting changes for the Privacy Manifest that Xcode keeps updating. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D57915368 fbshipit-source-id: f52ea4b3cb94212ac97a3d7edeb68747418fe0a9
1 parent 7ae0e46 commit eba1828

File tree

8 files changed

+151
-67
lines changed

8 files changed

+151
-67
lines changed
 

‎.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
**/staticBundle.js
33
docs/generatedComponentApiDocs.js
44
packages/react-native/flow/
5+
packages/react-native/sdks/
6+
packages/react-native/ReactAndroid/hermes-engine/build/
57
packages/react-native/Libraries/Renderer/*
68
packages/react-native/Libraries/vendor/**/*
79
node_modules/
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"platforms": {
3+
"ios": {},
4+
"android": {}
5+
},
6+
"project": {
7+
"ios": {
8+
"sourceDir": "HELLOWORLD_PATH/ios",
9+
"xcodeProject": {
10+
"name": "HelloWorld.xcworkspace",
11+
"isWorkspace": true
12+
}
13+
},
14+
"android": {
15+
"sourceDir": "HELLOWORLD_PATH/android",
16+
"appName": "app",
17+
"packageName": "com.helloworld",
18+
"applicationId": "com.helloworld",
19+
"mainActivity": ".MainActivity"
20+
}
21+
}
22+
}

‎packages/helloworld/ios/HelloWorld.xcodeproj/project.pbxproj

+12-31
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
1313
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1414
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
15+
6EA01F72FAC10D00AECACF94 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 0EC7AB76F90EED035707BA4E /* PrivacyInfo.xcprivacy */; };
1516
7699B88040F8A987B510C191 /* libPods-HelloWorld-HelloWorldTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-HelloWorld-HelloWorldTests.a */; };
1617
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
1718
/* End PBXBuildFile section */
@@ -30,6 +31,7 @@
3031
00E356EE1AD99517003FC87E /* HelloWorldTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HelloWorldTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3132
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3233
00E356F21AD99517003FC87E /* HelloWorldTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HelloWorldTests.m; sourceTree = "<group>"; };
34+
0EC7AB76F90EED035707BA4E /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = HelloWorld/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3335
13B07F961A680F5B00A75B9A /* HelloWorld.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloWorld.app; sourceTree = BUILT_PRODUCTS_DIR; };
3436
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = HelloWorld/AppDelegate.h; sourceTree = "<group>"; };
3537
13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = HelloWorld/AppDelegate.mm; sourceTree = "<group>"; };
@@ -94,6 +96,7 @@
9496
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
9597
13B07FB71A68108700A75B9A /* main.m */,
9698
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
99+
0EC7AB76F90EED035707BA4E /* PrivacyInfo.xcprivacy */,
97100
);
98101
name = HelloWorld;
99102
sourceTree = "<group>";
@@ -183,7 +186,6 @@
183186
13B07F8C1A680F5B00A75B9A /* Frameworks */,
184187
13B07F8E1A680F5B00A75B9A /* Resources */,
185188
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
186-
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */,
187189
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
188190
);
189191
buildRules = (
@@ -245,6 +247,7 @@
245247
files = (
246248
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
247249
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
250+
6EA01F72FAC10D00AECACF94 /* PrivacyInfo.xcprivacy in Resources */,
248251
);
249252
runOnlyForDeploymentPostprocessing = 0;
250253
};
@@ -259,13 +262,14 @@
259262
inputPaths = (
260263
"$(SRCROOT)/.xcode.env.local",
261264
"$(SRCROOT)/.xcode.env",
265+
"$(SRCROOT)/../.react-native.config",
262266
);
263267
name = "Bundle React Native code and images";
264268
outputPaths = (
265269
);
266270
runOnlyForDeploymentPostprocessing = 0;
267271
shellPath = /bin/sh;
268-
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
272+
shellScript = "set -e\n\nexport CONFIG_JSON=$(sed -e \"s|HELLOWORLD_PATH|$(realpath \"${SRCROOT}/../\")|g\" \"${SRCROOT}/../.react-native.config\")\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
269273
};
270274
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
271275
isa = PBXShellScriptBuildPhase;
@@ -328,23 +332,6 @@
328332
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
329333
showEnvVarsInLog = 0;
330334
};
331-
C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */ = {
332-
isa = PBXShellScriptBuildPhase;
333-
buildActionMask = 2147483647;
334-
files = (
335-
);
336-
inputFileListPaths = (
337-
"${PODS_ROOT}/Target Support Files/Pods-HelloWorld-HelloWorldTests/Pods-HelloWorld-HelloWorldTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
338-
);
339-
name = "[CP] Embed Pods Frameworks";
340-
outputFileListPaths = (
341-
"${PODS_ROOT}/Target Support Files/Pods-HelloWorld-HelloWorldTests/Pods-HelloWorld-HelloWorldTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
342-
);
343-
runOnlyForDeploymentPostprocessing = 0;
344-
shellPath = /bin/sh;
345-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-HelloWorld-HelloWorldTests/Pods-HelloWorld-HelloWorldTests-frameworks.sh\"\n";
346-
showEnvVarsInLog = 0;
347-
};
348335
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = {
349336
isa = PBXShellScriptBuildPhase;
350337
buildActionMask = 2147483647;
@@ -433,6 +420,7 @@
433420
);
434421
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
435422
PRODUCT_NAME = "$(TARGET_NAME)";
423+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../react-native";
436424
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HelloWorld.app/HelloWorld";
437425
};
438426
name = Debug;
@@ -457,6 +445,7 @@
457445
);
458446
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
459447
PRODUCT_NAME = "$(TARGET_NAME)";
448+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../react-native";
460449
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HelloWorld.app/HelloWorld";
461450
};
462451
name = Release;
@@ -482,6 +471,7 @@
482471
);
483472
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
484473
PRODUCT_NAME = HelloWorld;
474+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../react-native";
485475
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
486476
SWIFT_VERSION = 5.0;
487477
VERSIONING_SYSTEM = "apple-generic";
@@ -508,6 +498,7 @@
508498
);
509499
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
510500
PRODUCT_NAME = HelloWorld;
501+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../react-native";
511502
SWIFT_VERSION = 5.0;
512503
VERSIONING_SYSTEM = "apple-generic";
513504
};
@@ -582,13 +573,8 @@
582573
"-DFOLLY_CFG_NO_COROUTINES=1",
583574
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
584575
);
585-
OTHER_LDFLAGS = (
586-
"$(inherited)",
587-
" ",
588-
);
589-
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../react-native";
576+
OTHER_LDFLAGS = "$(inherited) ";
590577
SDKROOT = iphoneos;
591-
USE_HERMES = true;
592578
};
593579
name = Debug;
594580
};
@@ -653,13 +639,8 @@
653639
"-DFOLLY_CFG_NO_COROUTINES=1",
654640
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
655641
);
656-
OTHER_LDFLAGS = (
657-
"$(inherited)",
658-
" ",
659-
);
660-
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../react-native";
642+
OTHER_LDFLAGS = "$(inherited) ";
661643
SDKROOT = iphoneos;
662-
USE_HERMES = true;
663644
VALIDATE_PRODUCT = YES;
664645
};
665646
name = Release;

‎packages/helloworld/ios/HelloWorld/PrivacyInfo.xcprivacy

+31-32
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,36 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>NSPrivacyCollectedDataTypes</key>
6-
<array>
7-
</array>
8-
<key>NSPrivacyAccessedAPITypes</key>
9-
<array>
10-
<dict>
11-
<key>NSPrivacyAccessedAPIType</key>
12-
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
13-
<key>NSPrivacyAccessedAPITypeReasons</key>
14-
<array>
15-
<string>C617.1</string>
16-
</array>
17-
</dict>
18-
<dict>
19-
<key>NSPrivacyAccessedAPIType</key>
20-
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
21-
<key>NSPrivacyAccessedAPITypeReasons</key>
22-
<array>
23-
<string>CA92.1</string>
24-
</array>
25-
</dict>
26-
<dict>
27-
<key>NSPrivacyAccessedAPIType</key>
28-
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
29-
<key>NSPrivacyAccessedAPITypeReasons</key>
30-
<array>
31-
<string>35F9.1</string>
32-
</array>
33-
</dict>
34-
</array>
35-
<key>NSPrivacyTracking</key>
36-
<false/>
5+
<key>NSPrivacyAccessedAPITypes</key>
6+
<array>
7+
<dict>
8+
<key>NSPrivacyAccessedAPIType</key>
9+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
10+
<key>NSPrivacyAccessedAPITypeReasons</key>
11+
<array>
12+
<string>C617.1</string>
13+
</array>
14+
</dict>
15+
<dict>
16+
<key>NSPrivacyAccessedAPIType</key>
17+
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
18+
<key>NSPrivacyAccessedAPITypeReasons</key>
19+
<array>
20+
<string>CA92.1</string>
21+
</array>
22+
</dict>
23+
<dict>
24+
<key>NSPrivacyAccessedAPIType</key>
25+
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
26+
<key>NSPrivacyAccessedAPITypeReasons</key>
27+
<array>
28+
<string>35F9.1</string>
29+
</array>
30+
</dict>
31+
</array>
32+
<key>NSPrivacyCollectedDataTypes</key>
33+
<array/>
34+
<key>NSPrivacyTracking</key>
35+
<false/>
3736
</dict>
3837
</plist>

‎packages/helloworld/ios/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ target 'HelloWorld' do
1313
config = use_native_modules!
1414

1515
use_react_native!(
16-
:path => config[:reactNativePath],
16+
:path => "../../react-native",
1717
# An absolute path to your application root.
1818
:app_path => "#{Pod::Config.instance.installation_root}/.."
1919
)

‎packages/react-native/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"rn-get-polyfills.js",
5757
"scripts/compose-source-maps.js",
5858
"scripts/find-node-for-xcode.sh",
59+
"scripts/bundle.js",
5960
"scripts/generate-codegen-artifacts.js",
6061
"scripts/generate-provider-cli.js",
6162
"scripts/generate-specs-cli.js",
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @oncall react_native
9+
*/
10+
11+
'use strict';
12+
13+
const {bundleCommand: bc} = require('@react-native/community-cli-plugin');
14+
const {execSync} = require('child_process');
15+
const program = require('commander');
16+
const {existsSync, readFileSync} = require('fs');
17+
const path = require('path');
18+
19+
program.version(
20+
JSON.parse(
21+
readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf8'),
22+
).version,
23+
);
24+
25+
program
26+
.name(bc.name)
27+
.description(bc.description ?? '')
28+
.option(
29+
'--config-cmd <string>',
30+
'Command to generate a JSON project config',
31+
'npx react-native config',
32+
)
33+
.option('--load-config <string>', 'JSON project config')
34+
.action(async function handleAction(options, ...args) {
35+
let config = null;
36+
37+
if (options.loadConfig != null) {
38+
const rawText = existsSync(options.loadConfig)
39+
? readFileSync(options.loadConfig, 'utf8')
40+
: options.loadConfig;
41+
config = JSON.parse(rawText);
42+
} else if (options.configCmd != null) {
43+
config = JSON.parse(
44+
execSync(options.configCmd.trim(), {encoding: 'utf8'}),
45+
);
46+
}
47+
48+
if (config == null) {
49+
throw new Error('No config provided');
50+
}
51+
52+
await bc.func(args, config, options);
53+
});
54+
55+
if (bc.options != null) {
56+
for (const o of bc.options) {
57+
program.option(
58+
o.name,
59+
o.description ?? '',
60+
o.parse ?? (value => value),
61+
o.default,
62+
);
63+
}
64+
}
65+
66+
if (require.main === module) {
67+
program.parse(process.argv);
68+
}
69+
70+
module.exports = program;

‎packages/react-native/scripts/react-native-xcode.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ fi
9090

9191
[ -z "$NODE_ARGS" ] && export NODE_ARGS=""
9292

93-
[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/cli.js"
94-
9593
[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"
9694

9795
[ -z "$COMPOSE_SOURCEMAP_PATH" ] && COMPOSE_SOURCEMAP_PATH="$REACT_NATIVE_DIR/scripts/compose-source-maps.js"
@@ -139,8 +137,19 @@ if [[ $USE_HERMES != false && $DEV == false ]]; then
139137
EXTRA_ARGS+=("--minify" "false")
140138
fi
141139

142-
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
140+
# Allow opting out of using npx react-native config
141+
if [[ -n "$CONFIG_JSON" ]]; then
142+
EXTRA_ARGS+=("--load-config" "$CONFIG_JSON")
143+
elif [[ -n "$CONFIG_CMD" ]]; then
144+
EXTRA_ARGS+=("--config-cmd" "$CONFIG_APP")
145+
else
146+
EXTRA_ARGS+=("--config-cmd" "$NODE_BINARY $NODE_ARGS $REACT_NATIVE_DIR/cli.js config")
147+
fi
148+
149+
# shellcheck disable=SC2086
150+
"$NODE_BINARY" $NODE_ARGS "$REACT_NATIVE_DIR/scripts/bundle.js" \
143151
$CONFIG_ARG \
152+
--config-cmd "$CONFIG" \
144153
--entry-file "$ENTRY_FILE" \
145154
--platform "$BUNDLE_PLATFORM" \
146155
--dev $DEV \

0 commit comments

Comments
 (0)
Please sign in to comment.