Skip to content

Commit

Permalink
Only patch index.*.js if any other file was patched
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed May 18, 2017
1 parent 23badab commit a9289c9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/postlink
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let OBJC_HEADER = '\
#endif';

let cachedDsn = null;
let patchedAny = false;

function getDsn(platform) {
return inquirer.prompt([{
Expand Down Expand Up @@ -53,7 +54,9 @@ function patchAppDelegate(contents) {
}

function patchIndexJs(contents, filename) {
if (contents.match(/Sentry.config\(/)) {
// since the init call could live in other places too, we really only
// want to do this if we managed to patch any of the other files as well.
if (contents.match(/Sentry.config\(/) && patchedAny) {
return Promise.resolve(contents);
}

Expand Down Expand Up @@ -91,6 +94,7 @@ function patchMatchingFile(pattern, func) {
});
rv = rv.then(() => func(contents, match)).then(function(newContents) {
if (contents != newContents) {
patchedAny = true;
fs.writeFileSync(match, newContents);
}
});
Expand All @@ -100,8 +104,8 @@ function patchMatchingFile(pattern, func) {

Promise.resolve()
.then(() => patchMatchingFile('**/AppDelegate.m', patchAppDelegate))
.then(() => patchMatchingFile('index.*.js', patchIndexJs))
.then(() => patchMatchingFile('**/app/build.gradle', patchBuildGradle))
.then(() => patchMatchingFile('index.*.js', patchIndexJs))
.catch(function(e) {
console.log('Could not link react-native-sentry: ' + e);
return Promise.resolve();
Expand Down

0 comments on commit a9289c9

Please sign in to comment.