Skip to content

Commit

Permalink
Merge pull request #2308 from bugsnag/je/plat-13608-generate-rncli-fi…
Browse files Browse the repository at this point in the history
…xture

[PLAT-13608] Enable source maps when generating a react native fixutre
  • Loading branch information
joshedney authored Feb 10, 2025
2 parents 52c6662 + c98472a commit 3a41311
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/generate-react-native-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const PEER_DEPENDENCIES = [
`@bugsnag/plugin-react-native-navigation@${notifierVersion}`
]

const SOURCE_MAP_DEPENDENCIES = [
`@bugsnag/react-native-cli@${notifierVersion}`
]

const reactNavigationVersion = '6.1.18'
const reactNavigationNativeStackVersion = '6.11.0'
const reactNativeScreensVersion = '3.35.0'
Expand Down Expand Up @@ -83,6 +87,10 @@ if (!process.env.SKIP_GENERATE_FIXTURE) {

installFixtureDependencies()

if (process.env.ENABLE_SOURCE_MAPS === 'true' || process.env.ENABLE_SOURCE_MAPS === '1') {
enableSourceMaps()
}

// link react-native-navigation using rnn-link tool
if (process.env.REACT_NATIVE_NAVIGATION === 'true' || process.env.REACT_NATIVE_NAVIGATION === '1') {
execSync('npx rnn-link', { cwd: fixtureDir, stdio: 'inherit' })
Expand Down Expand Up @@ -146,6 +154,11 @@ function installFixtureDependencies () {
PEER_DEPENDENCIES.push(...REACT_NAVIGATION_PEER_DEPENDENCIES)
}

// add source map dependencies
if (process.env.ENABLE_SOURCE_MAPS === 'true' || process.env.ENABLE_SOURCE_MAPS === '1') {
PEER_DEPENDENCIES.push(...SOURCE_MAP_DEPENDENCIES)
}

const fixtureDependencyArgs = PEER_DEPENDENCIES.join(' ')

// install test fixture dependencies
Expand Down Expand Up @@ -290,3 +303,9 @@ class MainActivity : ReactActivity() {
mainActivityContents = mainActivityContents.replace(mainActivityPattern, mainActivityReplacement)
fs.writeFileSync(mainActivityPath, mainActivityContents)
}

function enableSourceMaps () {
common.changeDir(`${ROOT_DIR}/scripts`)
const initCommand = `./init-rn-cli.sh ${notifierVersion} ${reactNativeVersion} ${fixtureDir}`
common.run(initCommand, true)
}
66 changes: 66 additions & 0 deletions scripts/init-rn-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/expect -f

set timeout -1
set notifierVersion [lindex $argv 0];
set rnVersion [lindex $argv 1];
set fixturePath [lindex $argv 2];
set rnVersionInt ""
set substringToTrim ".expo.ejected"

# Extract the substring starting from the third character
set rnVersionInt [string range $rnVersion 2 end]

# Replace underscore (_) with a period (.)
set rnVersionInt2 [string map {_ .} $rnVersionInt]

set rnVersionInt3 [string map [list $substringToTrim ""] $rnVersionInt2]

# Convert float string to float value using bc
regsub -all {^0+} $rnVersionInt3 "" $rnVersionInt3

puts "Using notifier version: $notifierVersion"
puts "Using React Native version: $rnVersion"

cd $fixturePath
spawn ./node_modules/.bin/bugsnag-react-native-cli init

expect "Do you want to continue anyway?"
send -- "Y\r"

expect "Are you using Bugsnag on-premise?"
send -- "Y\r"

expect "What is your Bugsnag notify endpoint?"
send -- http://bs-local.com:9339/notify\r

expect "What is your Bugsnag sessions endpoint?"
send -- http://bs-local.com:9339/sessions\r

expect "What is your Bugsnag upload endpoint?"
send -- http://localhost:9339\r

expect "What is your Bugsnag build endpoint?"
send -- http://localhost:9339/builds\r

expect "Enter version of the Bugsnag Android Gradle plugin you want to use"
send -- r

expect "What is your Bugsnag project API key?"
send -- "1234567890ABCDEF1234567890ABCDEF\r"

expect "Do you want to install the BugSnag CLI to allow you to upload JavaScript source maps?"
send -- y

expect "If you want the latest version of @bugsnag/cli hit enter, otherwise type the version you want"
send -- r

expect "See https://docs.bugsnag.com/platforms/react-native/react-native/showing-full-stacktraces for details."
send -- r

expect "Do you want to update your Xcode build phase to output JavaScript source maps?"
send -- y

expect "This will enable you to see full native stacktraces. It can't be done automatically."
send -- r

expect eof

0 comments on commit 3a41311

Please sign in to comment.