refactor(push): unify file modification approach and improve dependency resolution
Simplify Honor push plugin to use withDangerousMod consistently for all file modifications, replacing the withSettingsGradle approach that silently drops writes in Expo SDK 56+ multi-vendor plugin scenarios. Enhance Huawei push plugin to create missing dependencyResolutionManagement block instead of only appending to existing ones, ensuring CI build paths work reliably when Gradle's dependencyResolutionManagement takes precedence. Remove inline settings.gradle/build.gradle generation from CI workflow, relying on expo prebuild for Gradle file generation.
This commit is contained in:
@@ -42,14 +42,33 @@ const withHuaweiPush = (config, options = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure Huawei Maven repo in dependencyResolutionManagement (Gradle 9+)
|
||||
// Ensure Huawei Maven repo in dependencyResolutionManagement (Gradle 7+).
|
||||
// CI build paths require this block (Gradle dependencyResolutionManagement
|
||||
// takes precedence over allprojects.repositories when configured).
|
||||
// Create the block if it doesn't exist, otherwise inject Huawei into it.
|
||||
if (!config.modResults.contents.match(/dependencyResolutionManagement[\s\S]*developer\.huawei\.com\/repo/)) {
|
||||
const depMgmtPattern = /dependencyResolutionManagement\s*\{[\s\S]*?repositories\s*\{/;
|
||||
if (depMgmtPattern.test(config.modResults.contents)) {
|
||||
// Block exists — append Huawei to its repositories
|
||||
config.modResults.contents = config.modResults.contents.replace(
|
||||
depMgmtPattern,
|
||||
`$&\n maven { url 'https://developer.huawei.com/repo/' }`
|
||||
);
|
||||
} else {
|
||||
// Block doesn't exist — create it after the `plugins { ... }` block
|
||||
// (or after pluginManagement if no plugins block) so it sits where
|
||||
// Gradle expects it.
|
||||
const block = `\ndependencyResolutionManagement {\n repositories {\n maven { url 'https://developer.huawei.com/repo/' }\n google()\n mavenCentral()\n maven { url 'https://www.jitpack.io' }\n }\n}\n`;
|
||||
const pluginsBlockEnd = /(\nplugins\s*\{[\s\S]*?\n\})/;
|
||||
if (pluginsBlockEnd.test(config.modResults.contents)) {
|
||||
config.modResults.contents = config.modResults.contents.replace(
|
||||
pluginsBlockEnd,
|
||||
`$1\n${block}`
|
||||
);
|
||||
} else {
|
||||
// Fallback: append to end
|
||||
config.modResults.contents = config.modResults.contents + block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user