Skip to content

Commit

Permalink
fix: React Native Xcode updates
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT committed Oct 2, 2019
1 parent e143935 commit dafb248
Show file tree
Hide file tree
Showing 4 changed files with 1,610 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.0.1

* Strip only `Sentry*` frameworks for Cordova
* Guard Xcode project updates for react-native

## v1.0.0

* Support for new `@sentry/react-native`
Expand Down
11 changes: 9 additions & 2 deletions lib/Helper/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export function patchMatchingFile(
encoding: 'utf-8',
});
rv = rv.then(() => func(contents, match, ...args)).then(newContents => {
if (newContents !== null && contents !== undefined && contents !== newContents) {
if (
newContents !== null &&
contents !== undefined &&
contents !== newContents
) {
fs.writeFileSync(match, newContents);
}
});
Expand All @@ -37,7 +41,10 @@ export function exists(globPattern: string): boolean {
}, true);
}

export function matchesContent(globPattern: string, contentPattern: RegExp): boolean {
export function matchesContent(
globPattern: string,
contentPattern: RegExp,
): boolean {
const matches = glob.sync(globPattern, {
ignore: IGNORE_PATTERN,
});
Expand Down
31 changes: 20 additions & 11 deletions lib/Steps/Integrations/ReactNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ import { MobileProject } from './MobileProject';

const xcode = require('xcode');

const OBJC_HEADER =
'\
#if __has_include(<React/RNSentry.h>)\n\
#import <React/RNSentry.h> // This is used for versions of react >= 0.40\n\
#else\n\
#import "RNSentry.h" // This is used for versions of react < 0.40\n\
#endif';

export class ReactNative extends MobileProject {
protected answers: Answers;
protected sentryCli: SentryCli;
Expand Down Expand Up @@ -48,11 +40,13 @@ export class ReactNative extends MobileProject {
'ios/*.xcodeproj/project.pbxproj',
this.patchXcodeProj.bind(this),
);
dim(`✅ Patched build script in Xcode project.`);
} else {
await patchMatchingFile(
'**/app/build.gradle',
this.patchBuildGradle.bind(this),
);
dim(`✅ Patched build.gradle file.`);
}
await patchMatchingFile(
`index.${platform}.js`,
Expand All @@ -67,7 +61,10 @@ export class ReactNative extends MobileProject {
answers,
platform,
);
dim(`✅ Patched App.js file.`);
await this.addSentryProperties(platform, sentryCliProperties);
dim(`✅ Added sentry.properties file to ${platform}`);

green(`Successfully set up ${platform} for react-native`);
} catch (e) {
red(e);
Expand Down Expand Up @@ -295,9 +292,21 @@ export class ReactNative extends MobileProject {
}
}

this.patchExistingXcodeBuildScripts(buildScripts);
this.addNewXcodeBuildPhaseForSymbols(buildScripts, proj);
this.addZLibToXcode(proj);
try {
this.patchExistingXcodeBuildScripts(buildScripts);
} catch (e) {
red(e);
}
try {
this.addNewXcodeBuildPhaseForSymbols(buildScripts, proj);
} catch (e) {
red(e);
}
try {
this.addZLibToXcode(proj);
} catch (e) {
red(e);
}

// we always modify the xcode file in memory but we only want to save it
// in case the user wants configuration for ios. This is why we check
Expand Down
Loading

0 comments on commit dafb248

Please sign in to comment.