Skip to content

Commit

Permalink
fix: handle libraries using build.gradle.kts files (#2543)
Browse files Browse the repository at this point in the history
* fix: handle libraries using build.gradle.kts files

* chore: apply review
  • Loading branch information
bang9 authored Nov 4, 2024
1 parent 134e23e commit 30b94f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('android::findLibraryName', () => {
});

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

it('returns the library name if defined inside codegenConfig', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli-platform-android/src/config/findLibraryName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ export function findLibraryName(root: string, sourceDir: string) {
}

// If not, we check if the library specified it in the build.gradle file.
let buildGradleContents = '';
let match: RegExpMatchArray | null = null;
if (fs.existsSync(buildGradlePath)) {
buildGradleContents = fs.readFileSync(buildGradlePath, 'utf-8');
const buildGradleContents = fs.readFileSync(buildGradlePath, 'utf-8');
match = buildGradleContents.match(/libraryName = ["'](.+)["']/);
} else if (fs.existsSync(buildGradleKtsPath)) {
buildGradleContents = fs.readFileSync(buildGradleKtsPath, 'utf-8');
const buildGradleContents = fs.readFileSync(buildGradleKtsPath, 'utf-8');
match = buildGradleContents.match(/libraryName\.set\(["'](.+)["']\)/);
} else {
return undefined;
}

const match = buildGradleContents.match(/libraryName = ["'](.+)["']/);

if (match) {
return match[1];
} else {
Expand Down

0 comments on commit 30b94f8

Please sign in to comment.