Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android CLI plugin regex lookup includes comments, fails the build #2497

Open
tjzel opened this issue Sep 6, 2024 · 3 comments
Open

Android CLI plugin regex lookup includes comments, fails the build #2497

tjzel opened this issue Sep 6, 2024 · 3 comments

Comments

@tjzel
Copy link

tjzel commented Sep 6, 2024

Recently I was confused when my build started to use wrong namespace, therefore failing to compile. When I changed the namespace I left a comment with the old namespace in build.gradle. Turns out the namespace is extracted from build.gradle (among other properties) with a regex. In my opinion this is short-sighted, since it causes the following flow to fail the build process:

// this is a namespace "fix"

// more build.gradle code

namespace "com.library"

In such scenario the plugin registers the namespace as fix.

export function parseNamespaceFromBuildGradleFile(buildGradle: string) {
// search for namespace = inside the build.gradle file via regex
const matchArray = buildGradle.match(/namespace\s*[=]*\s*["'](.+?)["']/);
if (matchArray && matchArray.length > 0) {
return matchArray[1];
} else {
return null;
}
}

@szymonrybczak
Copy link
Collaborator

Hey @tjzel! It's an edge case and in my opinion there's no good way of solving this issue because composing config is done before running build.

We'd need to fallback to other namespace in this scenario when Android build fails, but IMO this adds more a lot more complexity and unnecessary logic. Same issue probably applies to other regexes that we have to get values to compose config.

@tjzel
Copy link
Author

tjzel commented Sep 13, 2024

It makes my wonder why regex parsing is still the way for CLI to read config files. Wouldn't it be better to use some gradle parser instead?

@thymikee
Copy link
Member

@tjzel it's fast and already there working fine for most cases. Last time I checked there was no official nor usable Gradle to JS parser. If there's something worth integrating out there that's lightweight and fast, I'm happy to review a PR with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants