Skip to content

Commit fcf1ee5

Browse files
committed
feat: add support for @expo/config-plugins
1 parent f9ea902 commit fcf1ee5

File tree

6 files changed

+64
-6
lines changed

6 files changed

+64
-6
lines changed

ios/test_app.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ def app_config(project_root)
2525
[manifest['name'], manifest['displayName'], manifest['version'], manifest['singleApp']]
2626
end
2727

28+
def apply_config_plugins(project_root)
29+
resolve_module('@rnx-kit/react-native-test-app-config-plugins')
30+
`node "#{File.join(__dir__, '..', 'scripts', 'apply-config-plugins.mjs')}" "#{project_root}"`
31+
rescue StandardError
32+
# Skip if `@rnx-kit/react-native-test-app-config-plugins` cannot be found
33+
end
34+
2835
def autolink_script_path
2936
package_path = resolve_module('@react-native-community/cli-platform-ios')
3037
File.join(package_path, 'native_modules')
@@ -451,6 +458,8 @@ def use_test_app_internal!(target_platform, options)
451458
end
452459
end
453460

461+
apply_config_plugins(project_root)
462+
454463
Pod::UI.notice(
455464
"`#{xcodeproj}` was sourced from `react-native-test-app`. " \
456465
'All modifications will be overwritten next time you run `pod install`.'

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"/macos",
3636
"/schema.json",
3737
"/scripts/*.js",
38+
"/scripts/apply-config-plugins.mjs",
3839
"/windows/*.{js,props,sln}",
3940
"/windows/ReactTestApp"
4041
],
@@ -78,6 +79,7 @@
7879
"@react-native-community/cli": ">=4.10.0",
7980
"@react-native-community/cli-platform-android": ">=4.10.0",
8081
"@react-native-community/cli-platform-ios": ">=4.10.0",
82+
"@rnx-kit/react-native-test-app-config-plugins": "*",
8183
"mustache": "^4.0.0",
8284
"react": "~16.11.0 || ~16.13.1 || ~17.0.1 || ~17.0.2 || ~18.0.0",
8385
"react-native": "^0.0.0-0 || 0.62 - 0.69 || 1000.0.0",
@@ -94,6 +96,9 @@
9496
"@react-native-community/cli-platform-ios": {
9597
"optional": true
9698
},
99+
"@rnx-kit/react-native-test-app-config-plugins": {
100+
"optional": true
101+
},
97102
"mustache": {
98103
"optional": true
99104
},

scripts/apply-config-plugins.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
// @ts-check
3+
4+
import * as fs from "fs/promises";
5+
import * as path from "path";
6+
import { findFile } from "./validate-manifest.js";
7+
8+
async function main(projectRoot = process.cwd()) {
9+
const packageJsonPath = findFile("package.json", projectRoot);
10+
if (!packageJsonPath) {
11+
throw new Error("Failed to find `package.json`");
12+
}
13+
14+
const content = await fs.readFile(packageJsonPath, { encoding: "utf-8" });
15+
if (!content.includes('"@rnx-kit/react-native-test-app-config-plugins"')) {
16+
return;
17+
}
18+
19+
const appJsonPath = findFile("app.json", projectRoot);
20+
if (!appJsonPath) {
21+
return;
22+
}
23+
24+
const { applyConfigPlugins } = await import(
25+
"@rnx-kit/react-native-test-app-config-plugins"
26+
);
27+
28+
return applyConfigPlugins({
29+
projectRoot: path.dirname(appJsonPath),
30+
packageJsonPath,
31+
appJsonPath,
32+
});
33+
}
34+
35+
const { [2]: projectRoot } = process.argv;
36+
main(projectRoot);

scripts/validate-manifest.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const BUILD_PROPS = [
1414
"ios",
1515
"macos",
1616
"windows",
17+
"plugins",
1718
"resources",
1819
];
1920

@@ -146,8 +147,3 @@ function validate(outputMode = "stdout", projectRoot = process.cwd()) {
146147
exports.findFile = findFile;
147148
exports.validate = validate;
148149
exports.validateManifest = validateManifest;
149-
150-
if (require.main === module) {
151-
// istanbul ignore next
152-
validate();
153-
}

test-app.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@ import org.gradle.initialization.DefaultSettings
44

55
import java.nio.file.Paths
66

7+
private static void applyConfigPlugins(String testAppDir, File rootDir) {
8+
String[] patch = ["node", "${testAppDir}/scripts/apply-config-plugins.mjs"]
9+
Runtime.runtime.exec(patch, null, rootDir).waitFor()
10+
}
11+
712
// TODO: Remove when `@react-native-community/cli` 6.0+ is required. See also
813
// https://github.com/react-native-community/cli/commit/fa0d09b2c9be144bbdff526bb14f171d7ddca88e
914
private static void patchArgumentTypeMismatchError(String testAppDir, File rootDir) {
1015
// We need to delegate this to a separate script to avoid running out of
1116
// Java heap space.
1217
String[] patch = ["node", "${testAppDir}/scripts/patch-cli-platform-android.js"]
13-
Runtime.getRuntime().exec(patch, null, rootDir).waitFor()
18+
Runtime.runtime.exec(patch, null, rootDir).waitFor()
1419
}
1520

1621
def testAppDir = buildscript.sourceFile.getParent()
1722
apply(from: "${testAppDir}/android/test-app-util.gradle")
1823

1924
patchArgumentTypeMismatchError(testAppDir, rootDir)
2025

26+
if (findNodeModulesPath("@rnx-kit/react-native-test-app-config-plugins", rootDir)) {
27+
applyConfigPlugins(testAppDir, rootDir)
28+
}
29+
2130
def cliAndroidDir = findNodeModulesPath("@react-native-community/cli-platform-android", rootDir)
2231
apply(from: "${cliAndroidDir}/native_modules.gradle")
2332

yarn.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10754,6 +10754,7 @@ fsevents@^2.3.2:
1075410754
"@react-native-community/cli": ">=4.10.0"
1075510755
"@react-native-community/cli-platform-android": ">=4.10.0"
1075610756
"@react-native-community/cli-platform-ios": ">=4.10.0"
10757+
"@rnx-kit/react-native-test-app-config-plugins": "*"
1075710758
mustache: ^4.0.0
1075810759
react: ~16.11.0 || ~16.13.1 || ~17.0.1 || ~17.0.2 || ~18.0.0
1075910760
react-native: ^0.0.0-0 || 0.62 - 0.69 || 1000.0.0
@@ -10766,6 +10767,8 @@ fsevents@^2.3.2:
1076610767
optional: true
1076710768
"@react-native-community/cli-platform-ios":
1076810769
optional: true
10770+
"@rnx-kit/react-native-test-app-config-plugins":
10771+
optional: true
1076910772
mustache:
1077010773
optional: true
1077110774
react-native-macos:

0 commit comments

Comments
 (0)