Skip to content

Commit d1e5a53

Browse files
committed
Fixed multiple prompts firing at once
1 parent c13596b commit d1e5a53

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

scripts/postlink

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ let OBJC_HEADER = '\
99
#import "RNSentry.h" // This is used for versions of react < 0.40\n\
1010
#endif';
1111

12-
let dsn = null;
12+
let cachedDsn = null;
1313

1414
function getDsn() {
15-
if (dsn !== null) {
16-
return Promise.resolve(dsn);
15+
if (cachedDsn !== null) {
16+
return Promise.resolve(cachedDsn);
1717
}
1818

1919
return inquirer.prompt([{
@@ -22,6 +22,7 @@ function getDsn() {
2222
message: 'The DSN for your mobile application',
2323
name: 'dsn',
2424
}]).then(function(answers) {
25+
cachedDsn = answers.dsn;
2526
return Promise.resolve(answers.dsn);
2627
});
2728
}
@@ -83,23 +84,25 @@ function patchMatchingFile(pattern, func) {
8384
let matches = glob.sync(pattern, {
8485
ignore: 'node_modules/**'
8586
});
86-
for (let match of matches) {
87+
let rv = Promise.resolve();
88+
matches.forEach(function(match) {
8789
let contents = fs.readFileSync(match, {
8890
encoding: 'utf-8'
8991
});
90-
func(contents).then(function(newContents) {
92+
rv = rv.then(() => func(contents)).then(function(newContents) {
9193
if (contents != newContents) {
9294
fs.writeFileSync(match, newContents);
9395
}
9496
});
95-
}
97+
});
98+
return rv;
9699
}
97100

98-
Promise.all([
99-
patchMatchingFile('**/AppDelegate.m', patchAppDelegate),
100-
patchMatchingFile('index.*.js', patchIndexJs),
101-
patchMatchingFile('**/app/build.gradle', patchBuildGradle),
102-
]).catch(function(e) {
103-
console.log('Could not link react-native-sentry: ' + e);
104-
return Promise.resolve();
105-
});
101+
Promise.resolve()
102+
.then(() => patchMatchingFile('**/AppDelegate.m', patchAppDelegate))
103+
.then(() => patchMatchingFile('index.*.js', patchIndexJs))
104+
.then(() => patchMatchingFile('**/app/build.gradle', patchBuildGradle))
105+
.catch(function(e) {
106+
console.log('Could not link react-native-sentry: ' + e);
107+
return Promise.resolve();
108+
});

0 commit comments

Comments
 (0)