Skip to content

Commit 0c91e79

Browse files
committed
fix(expo): harden config plugin import and validate it in CI
1 parent cdad391 commit 0c91e79

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ jobs:
102102
fs.writeFileSync(path, JSON.stringify(app, null, 2) + '\n');
103103
NODE
104104
105+
CI=1 npx expo config --json > "$EXPO_WORK_DIR/expo-config.json"
106+
node -e "JSON.parse(require(\"node:fs\").readFileSync(process.argv[1], \"utf8\"))" "$EXPO_WORK_DIR/expo-config.json"
107+
105108
CI=1 npx expo prebuild --platform all --clean --no-install 2>&1 | tee "$EXPO_WORK_DIR/prebuild.log"
106109
107110
grep -q "^react_native_file_hash_engine=${ZFH_ENGINE}$" android/gradle.properties
@@ -120,6 +123,14 @@ jobs:
120123
fi
121124
echo "::endgroup::"
122125
126+
echo "::group::expo config"
127+
if [[ -f "$EXPO_WORK_DIR/expo-config.json" ]]; then
128+
cat "$EXPO_WORK_DIR/expo-config.json"
129+
else
130+
echo "Missing: $EXPO_WORK_DIR/expo-config.json"
131+
fi
132+
echo "::endgroup::"
133+
123134
echo "::group::android/gradle.properties"
124135
if [[ -f "$EXPO_WORK_DIR/app/android/gradle.properties" ]]; then
125136
cat "$EXPO_WORK_DIR/app/android/gradle.properties"
@@ -145,6 +156,7 @@ jobs:
145156
path: |
146157
${{ env.EXPO_WORK_DIR }}/prebuild.log
147158
${{ env.EXPO_WORK_DIR }}/app/app.json
159+
${{ env.EXPO_WORK_DIR }}/expo-config.json
148160
${{ env.EXPO_WORK_DIR }}/app/android/gradle.properties
149161
${{ env.EXPO_WORK_DIR }}/app/ios/Podfile
150162

app.plugin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ let configPlugins;
33
try {
44
configPlugins = require('@expo/config-plugins');
55
} catch (error) {
6-
if (error?.code !== 'MODULE_NOT_FOUND') {
6+
const errorCode = error && error.code;
7+
if (errorCode !== 'MODULE_NOT_FOUND') {
78
throw error;
89
}
910
configPlugins = require('expo/config-plugins');
1011
}
1112
const { createRunOncePlugin, withPodfile } = configPlugins;
1213
const withAndroidGradleProperties =
13-
configPlugins.withAndroidGradleProperties ??
14-
configPlugins.withGradleProperties;
14+
typeof configPlugins.withAndroidGradleProperties === 'function'
15+
? configPlugins.withAndroidGradleProperties
16+
: configPlugins.withGradleProperties;
1517

1618
if (typeof withAndroidGradleProperties !== 'function') {
1719
throw new Error(
@@ -25,7 +27,9 @@ const PODFILE_BLOCK_START = '# @preeternal/react-native-file-hash begin';
2527
const PODFILE_BLOCK_END = '# @preeternal/react-native-file-hash end';
2628

2729
function normalizeEngine(rawEngine) {
28-
const engine = (rawEngine ?? 'native').toString().toLowerCase();
30+
const normalized =
31+
rawEngine == null ? '' : String(rawEngine).trim().toLowerCase();
32+
const engine = normalized === '' ? 'native' : normalized;
2933
if (!VALID_ENGINES.has(engine)) {
3034
throw new Error(
3135
`${PLUGIN_NAME}: invalid engine '${rawEngine}'. Expected 'native' or 'zig'.`

0 commit comments

Comments
 (0)