@@ -20,6 +20,8 @@ const importSerializer = "const { withSentryConfig } = require('@sentry/react-na
2020
2121let config = fs . readFileSync ( configFilePath , 'utf8' ) . split ( '\n' ) ;
2222
23+ const sentryOptions = '{ annotateReactComponents: true }' ;
24+
2325const isPatched = config . includes ( importSerializer ) ;
2426if ( ! isPatched ) {
2527 config = [ importSerializer , ...config ] ;
@@ -35,11 +37,18 @@ if (!isPatched) {
3537 lineParsed [ 1 ] = lineParsed [ 1 ] . slice ( 0 , - 1 ) ;
3638 }
3739
38- lineParsed [ 1 ] = `= withSentryConfig(${ lineParsed [ 1 ] } ${ endsWithSemicolon ? ');' : '' } ` ;
40+ lineParsed [ 1 ] = `= withSentryConfig(${ lineParsed [ 1 ] } ${ endsWithSemicolon ? `, ${ sentryOptions } );` : '' } ` ;
3941 config [ moduleExportsLineIndex ] = lineParsed . join ( '' ) ;
4042
4143 if ( endOfModuleExportsIndex !== - 1 ) {
42- config [ endOfModuleExportsIndex ] = '});' ;
44+ config [ endOfModuleExportsIndex ] = `}, ${ sentryOptions } );` ;
45+ }
46+
47+ // RN Before 0.72 does not include default config in the metro.config.js
48+ // We have to specify babelTransformerPath manually
49+ const transformerIndex = config . findIndex ( line => line . includes ( 'transformer: {' ) ) ;
50+ if ( transformerIndex !== - 1 ) {
51+ config [ transformerIndex ] = `transformer: { babelTransformerPath: require.resolve('metro-babel-transformer'),` ;
4352 }
4453
4554 fs . writeFileSync ( configFilePath , config . join ( '\n' ) , 'utf8' ) ;
0 commit comments