Skip to content

Commit a9289c9

Browse files
committed
Only patch index.*.js if any other file was patched
1 parent 23badab commit a9289c9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

scripts/postlink

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let OBJC_HEADER = '\
1010
#endif';
1111

1212
let cachedDsn = null;
13+
let patchedAny = false;
1314

1415
function getDsn(platform) {
1516
return inquirer.prompt([{
@@ -53,7 +54,9 @@ function patchAppDelegate(contents) {
5354
}
5455

5556
function 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

101105
Promise.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

Comments
 (0)