Skip to content

Commit ec2fce5

Browse files
committed
fix(expo): preserve AppDelegate declaration whitespace
1 parent 672b203 commit ec2fce5

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

packages/react-native-app-auth/plugin/src/__tests__/app-delegate.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ describe('applyExpo53AppDelegatePatch', () => {
5555
);
5656
});
5757

58+
it('preserves whitespace before the class opening brace', () => {
59+
const result = applyExpo53AppDelegatePatch(
60+
expo56AppDelegate.replace(
61+
'class AppDelegate: ExpoAppDelegate {',
62+
`class AppDelegate: ExpoAppDelegate,
63+
UIApplicationDelegate
64+
{`
65+
)
66+
);
67+
68+
expect(result).toContain(`class AppDelegate: ExpoAppDelegate,
69+
UIApplicationDelegate, RNAppAuthAuthorizationFlowManager
70+
{`);
71+
});
72+
5873
it('does not duplicate an existing multiline AppAuth delegate property', () => {
5974
const appDelegateWithMultilineProperty = expo56AppDelegate.replace(
6075
' var reactNativeFactory: RCTReactNativeFactory?',

packages/react-native-app-auth/plugin/src/ios/app-delegate.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ export const applyExpo53AppDelegatePatch = (contents: string): string => {
1818
contents = contents.replace(
1919
/^(\s*(?:public\s+)?class\s+AppDelegate\s*:\s*ExpoAppDelegate)([^{]*)(\{)/m,
2020
(match, declaration, conformances, openingBrace) => {
21-
const trimmedConformances = conformances.trim();
22-
if (trimmedConformances.includes(APP_AUTH_PROTOCOL)) {
21+
if (conformances.includes(APP_AUTH_PROTOCOL)) {
2322
return match;
2423
}
2524

26-
return `${declaration}${trimmedConformances}, ${APP_AUTH_PROTOCOL} ${openingBrace}`;
25+
const trailingWhitespace = conformances.match(/\s*$/)?.[0] ?? '';
26+
const existingConformances = conformances.slice(
27+
0,
28+
conformances.length - trailingWhitespace.length
29+
);
30+
31+
return `${declaration}${existingConformances}, ${APP_AUTH_PROTOCOL}${trailingWhitespace}${openingBrace}`;
2732
}
2833
);
2934

0 commit comments

Comments
 (0)