Skip to content

Commit 842123f

Browse files
Merge pull request #1015 from DataDog/marcosaia/fix/react-navigation-script-failures
[FIX] Fix react-navigation script errors
2 parents bbb779a + 1e826ad commit 842123f

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

packages/react-navigation/fix-react-navigation-import-in-dependencies.sh

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,62 @@
55
# With this script we find all the js files in these packages, then replace @react-navigation/native with the
66
# correct import name.
77

8-
# sets directory to this one - see https://stackoverflow.com/a/3355423
9-
cd "$(dirname "$0")"
8+
# Sets directory to this one - see https://stackoverflow.com/a/3355423
9+
cd "$(dirname "$0")" || {
10+
echo "[@datadog/mobile-react-navigation] WARNING: Failed to change directory."
11+
}
1012

11-
find ../../node_modules/@react-navigation/stack-v5/. -name '*.js' -print0 | xargs -0 sed -i '' 's/@react-navigation\/native\"/@react-navigation\/native-v5\"/g'
12-
find ../../node_modules/@react-navigation/stack-v6/. -name '*.js' -print0 | xargs -0 sed -i '' 's/@react-navigation\/native\"/@react-navigation\/native-v6\"/g'
13-
find ../../node_modules/@react-navigation/elements/. -name '*.js' -print0 | xargs -0 sed -i '' 's/@react-navigation\/native\"/@react-navigation\/native-v6\"/g'
13+
# Detect OS for sed compatibility
14+
# macOS uses BSD sed (requires -i ''), Linux uses GNU sed (just -i)
15+
if [[ "$OSTYPE" == "darwin"* ]]; then
16+
SED_INPLACE=(-i '')
17+
else
18+
SED_INPLACE=(-i)
19+
fi
20+
21+
# Track whether any warnings occurred
22+
had_warnings=false
23+
24+
# Helper function to run find/sed safely
25+
safe_replace() {
26+
local dir=$1
27+
local replace=$2
28+
29+
if [ -d "$dir" ]; then
30+
echo "[@datadog/mobile-react-navigation] Processing $dir ..."
31+
# Capture stderr from sed and print if non-empty
32+
local sed_errors
33+
sed_errors=$(find "$dir" -name '*.js' -print0 2>/dev/null | \
34+
xargs -0 sed "${SED_INPLACE[@]}" "$replace" 2>&1)
35+
if [ $? -ne 0 ]; then
36+
echo "[@datadog/mobile-react-navigation] WARNING: Replacement failed for $dir"
37+
echo "[@datadog/mobile-react-navigation] Error details:"
38+
echo "$sed_errors"
39+
had_warnings=true
40+
elif [ -n "$sed_errors" ]; then
41+
# Sometimes sed emits warnings but exits successfully
42+
echo "[@datadog/mobile-react-navigation] NOTE: sed produced warnings for $dir:"
43+
echo "$sed_errors"
44+
had_warnings=true
45+
fi
46+
else
47+
echo "[@datadog/mobile-react-navigation] WARNING: Directory not found: $dir"
48+
had_warnings=true
49+
fi
50+
}
51+
52+
safe_replace "../../node_modules/@react-navigation/stack-v5/." 's/@react-navigation\/native"/@react-navigation\/native-v5"/g'
53+
safe_replace "../../node_modules/@react-navigation/stack-v6/." 's/@react-navigation\/native"/@react-navigation\/native-v6"/g'
54+
safe_replace "../../node_modules/@react-navigation/elements/." 's/@react-navigation\/native"/@react-navigation\/native-v6"/g'
55+
56+
# Final summary
57+
if [ "$had_warnings" = true ]; then
58+
echo ""
59+
echo "[@datadog/mobile-react-navigation] ⚠️ IMPORTANT: Script completed with warnings."
60+
echo "[@datadog/mobile-react-navigation] React Navigation imports may not have been updated correctly."
61+
echo "[@datadog/mobile-react-navigation] Please review the logs above — your project’s navigation might not work as expected."
62+
else
63+
echo "[@datadog/mobile-react-navigation] ✅ Completed successfully with no warnings."
64+
fi
65+
66+
exit 0

0 commit comments

Comments
 (0)