Skip to content

Commit 30b94f8

Browse files
authored
fix: handle libraries using build.gradle.kts files (#2543)
* fix: handle libraries using build.gradle.kts files * chore: apply review
1 parent 134e23e commit 30b94f8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/cli-platform-android/src/config/__tests__/findLibraryName.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('android::findLibraryName', () => {
8686
});
8787

8888
it('returns the library name if declared with inside a build.gradle.kts file', () => {
89-
expect(findLibraryName('/', '/valid/singlequotes')).toBe('justalibrary');
89+
expect(findLibraryName('/', '/valid/gradlekts')).toBe('justalibrary');
9090
});
9191

9292
it('returns the library name if defined inside codegenConfig', () => {

packages/cli-platform-android/src/config/findLibraryName.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ export function findLibraryName(root: string, sourceDir: string) {
1515
}
1616

1717
// If not, we check if the library specified it in the build.gradle file.
18-
let buildGradleContents = '';
18+
let match: RegExpMatchArray | null = null;
1919
if (fs.existsSync(buildGradlePath)) {
20-
buildGradleContents = fs.readFileSync(buildGradlePath, 'utf-8');
20+
const buildGradleContents = fs.readFileSync(buildGradlePath, 'utf-8');
21+
match = buildGradleContents.match(/libraryName = ["'](.+)["']/);
2122
} else if (fs.existsSync(buildGradleKtsPath)) {
22-
buildGradleContents = fs.readFileSync(buildGradleKtsPath, 'utf-8');
23+
const buildGradleContents = fs.readFileSync(buildGradleKtsPath, 'utf-8');
24+
match = buildGradleContents.match(/libraryName\.set\(["'](.+)["']\)/);
2325
} else {
2426
return undefined;
2527
}
2628

27-
const match = buildGradleContents.match(/libraryName = ["'](.+)["']/);
28-
2929
if (match) {
3030
return match[1];
3131
} else {

0 commit comments

Comments
 (0)