@@ -10,6 +10,7 @@ let OBJC_HEADER = '\
1010#endif';
1111
1212let cachedDsn = null;
13+ let patchedAny = false;
1314
1415function getDsn(platform) {
1516 return inquirer.prompt([{
@@ -53,7 +54,9 @@ function patchAppDelegate(contents) {
5354}
5455
5556function patchIndexJs(contents, filename) {
56- if (contents.match(/Sentry.config\(/)) {
57+ // since the init call could live in other places too, we really only
58+ // want to do this if we managed to patch any of the other files as well.
59+ if (contents.match(/Sentry.config\(/) && patchedAny) {
5760 return Promise.resolve(contents);
5861 }
5962
@@ -91,6 +94,7 @@ function patchMatchingFile(pattern, func) {
9194 });
9295 rv = rv.then(() => func(contents, match)).then(function(newContents) {
9396 if (contents != newContents) {
97+ patchedAny = true;
9498 fs.writeFileSync(match, newContents);
9599 }
96100 });
@@ -100,8 +104,8 @@ function patchMatchingFile(pattern, func) {
100104
101105Promise.resolve()
102106 .then(() => patchMatchingFile('**/AppDelegate.m', patchAppDelegate))
103- .then(() => patchMatchingFile('index.*.js', patchIndexJs))
104107 .then(() => patchMatchingFile('**/app/build.gradle', patchBuildGradle))
108+ .then(() => patchMatchingFile('index.*.js', patchIndexJs))
105109 .catch(function(e) {
106110 console.log('Could not link react-native-sentry: ' + e);
107111 return Promise.resolve();
0 commit comments