Skip to content

[build-properties] Expand extraMavenRepos support#26895

Merged
Kudo merged 8 commits intoexpo:mainfrom
bpeltonc:extraMavenRepos-expanded-functionality
Feb 26, 2024
Merged

[build-properties] Expand extraMavenRepos support#26895
Kudo merged 8 commits intoexpo:mainfrom
bpeltonc:extraMavenRepos-expanded-functionality

Conversation

@bpeltonc
Copy link
Copy Markdown
Contributor

@bpeltonc bpeltonc commented Feb 2, 2024

  • Allow users to specify authentication scheme and credentials for repositories added to the project via android.extraMavenRepos per Gradle/Maven documentation.

Why

Support was added in Expo Build Properties 0.8.0 to allow users to specify additional Maven repositories to be included with an Android build, but this initial implementation is somewhat naive and only offers the user a small portion of the functionality Gradle and Maven offers, namely only allowing users to add repositories that don't require credentials. Users who would like to include Maven repositories that do require credentials are precluded from using Expo Build Properties to add them and would appreciate the ability to use the extraMavenRepos support to include these repos in their builds as well.

How

  1. I provided TypeScript definitions for Maven repository-related objects conforming to the protocols outlined in the Gradle documentation and modified the extraMavenRepos definition to accept an array of either these objects or strings, providing backwards-compatibility to consumers of this library who upgrade to this version and averting introducing breaking changes.
  2. I adjusted the AJV schema to properly validate user-provided values against the newly-defined types.
  3. I made updates to expo-modules-autolinking to accept the new properties and include them in the autolinking script.
  4. I wrote automated tests to ensure user-provided values are properly validated against the Gradle protocols as expressed in the TypeScript defintions and to ensure those values were passed in the expected data structure to the expo-modules-autolinking package.

Test Plan

One of the projects I work on specifies an extra Maven repository that requires a credentialed login. I specified a object in the android.extraMavenRepos section of my app.config.ts file that included a url, credentials object, and authentication scheme. Then I ran npx expo prebuild --clean and npx expo android:run. With correct credentials, the app builds and runs successfully, and the feature provided by the repo is usable from within the Expo application.

For reviewers of this PR, the main obstacle in testing will likely be finding a Maven repository that needs credentials for access, and obtaining valid credentials. I wish I could provide the credentials I used to test, but they are, of course, sensitive. Hopefully, we can collaborate on devising an easier way to test this PR.

Checklist

- Allow users to specify authentication scheme and credentials for
    repositories added to the project via `android.extraMavenRepos`
@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Feb 2, 2024
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Feb 2, 2024
@brentvatne
Copy link
Copy Markdown
Member

thank you for the PR! @Kudo is OOO at the moment and is the best person to review, he'll back late next week

Copy link
Copy Markdown
Contributor

@lukmccall lukmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good. Let's wait for @Kudo, but if you ask me, we can merge it ;)

@bpeltonc
Copy link
Copy Markdown
Contributor Author

@Kudo Would you mind reviewing/merging this when you have the chance?

Copy link
Copy Markdown
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i missed this and thanks for your reminder as well as the great pr! i like the pr much for having great test coverage / comment / and nice code. i'm just leave a comment for not using typescript enum. let me know how do you feel for that.

Comment thread packages/expo-build-properties/src/pluginConfig.ts Outdated
Brandon Pelton-Cox added 2 commits February 23, 2024 06:34
- Change the `authentication` property to use a string union instead
    of a TS enum
…peltonc/expo into extraMavenRepos-expanded-functionality
Comment thread packages/expo-modules-autolinking/src/types.ts Outdated
- Convert `AndroidMavenRepositoryAuthenticationScheme` to string union
@Kudo
Copy link
Copy Markdown
Contributor

Kudo commented Feb 23, 2024

sorry there're more 🤦‍♂️ i still dunno how to push directly to a pr where authors allowing maintainer to edit. please help me to edit the change again.

commit b119bc25b01cbde4cd459d248b9f91f1700f2c1e
diff --git a/packages/expo-modules-autolinking/build/types.d.ts b/packages/expo-modules-autolinking/build/types.d.ts
index 9146e0306c..587d9149c8 100644
Binary files a/packages/expo-modules-autolinking/build/types.d.ts and b/packages/expo-modules-autolinking/build/types.d.ts differ
diff --git a/packages/expo-modules-autolinking/build/types.js b/packages/expo-modules-autolinking/build/types.js
index 7e60b199d7..11e638d1ee 100644
Binary files a/packages/expo-modules-autolinking/build/types.js and b/packages/expo-modules-autolinking/build/types.js differ
diff --git a/packages/expo-modules-autolinking/build/types.js.map b/packages/expo-modules-autolinking/build/types.js.map
index 066206f0cc..9c759e3f5a 100644
Binary files a/packages/expo-modules-autolinking/build/types.js.map and b/packages/expo-modules-autolinking/build/types.js.map differ
diff --git a/packages/expo-modules-autolinking/src/autolinking/__tests__/extraDependencies-test.ts b/packages/expo-modules-autolinking/src/autolinking/__tests__/extraDependencies-test.ts
index 9473adbf54..7317bce7ba 100644
--- a/packages/expo-modules-autolinking/src/autolinking/__tests__/extraDependencies-test.ts
+++ b/packages/expo-modules-autolinking/src/autolinking/__tests__/extraDependencies-test.ts
@@ -1,6 +1,5 @@
 import { getConfig } from '@expo/config';
 
-import { AndroidMavenRepositoryAuthenticationScheme } from '../../types';
 import { getBuildPropertiesAsync, resolveExtraDependenciesAsync } from '../extraDependencies';
 
 jest.mock('@expo/config', () => ({
@@ -105,7 +104,7 @@ describe(resolveExtraDependenciesAsync, () => {
                       username: 'user',
                       password: 'password',
                     },
-                    authentication: AndroidMavenRepositoryAuthenticationScheme.BasicAuthentication,
+                    authentication: 'basic',
                   },
                 ],
               },
@@ -148,8 +147,7 @@ describe(resolveExtraDependenciesAsync, () => {
                       name: 'token',
                       value: 'some_token',
                     },
-                    authentication:
-                      AndroidMavenRepositoryAuthenticationScheme.HttpHeaderAuthentication,
+                    authentication: 'header',
                   },
                 ],
               },
@@ -192,7 +190,7 @@ describe(resolveExtraDependenciesAsync, () => {
                       username: 'user',
                       password: 'password',
                     },
-                    authentication: AndroidMavenRepositoryAuthenticationScheme.DigestAuthentication,
+                    authentication: 'digest',
                   },
                 ],
               },
diff --git a/packages/expo-modules-autolinking/src/types.ts b/packages/expo-modules-autolinking/src/types.ts
index fbee9d9816..44569036ec 100644
--- a/packages/expo-modules-autolinking/src/types.ts
+++ b/packages/expo-modules-autolinking/src/types.ts
@@ -228,12 +228,6 @@ export interface RawExpoModuleConfig {
   };
 }
 
-export enum AndroidMavenRepositoryAuthenticationScheme {
-  BasicAuthentication = 'basic',
-  DigestAuthentication = 'digest',
-  HttpHeaderAuthentication = 'header',
-}
-
 interface AndroidMavenRepositoryPasswordCredentials {
   username: string;
   password: string;

@bpeltonc
Copy link
Copy Markdown
Contributor Author

Thanks for being thorough and catching all this. I'll get all this fixed and do a full sweep and test of my original PR before I push another hasty commit. I should have caught this.

@bpeltonc
Copy link
Copy Markdown
Contributor Author

Removed all references to that enum and replaced them all with string unions, ran all the tests and build packagers again for both packages, and (after fixing a bug!) tested it again successfully linking a maven repo that requires basic authentication. I'm confident this is ready to go and addresses all your comments, @Kudo

Copy link
Copy Markdown
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything looks good and i'm going to merge this pr. thanks again for the fantastic contribution 👏

@Kudo Kudo merged commit fca8a63 into expo:main Feb 26, 2024
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants