From edde8f1c30618055fa4c15f1f90e970689f9dd18 Mon Sep 17 00:00:00 2001 From: lafay <2021211506@stu.hit.edu.cn> Date: Mon, 15 Jun 2026 23:05:55 +0800 Subject: [PATCH] fix(huawei-push): simplify Jiguang Maven repository injection Clean up duplicate and malformed Jiguang repo addition code in the Huawei push plugin. The previous implementation had redundant logic for injecting the repository into dependencyResolutionManagement, resulting in duplicate entries and syntax errors. Simplified to directly append the maven URL using the `$&` backreference pattern for cleaner, more maintainable code. --- plugins/withHuaweiPush.js | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/plugins/withHuaweiPush.js b/plugins/withHuaweiPush.js index a4af2bd..f49d1f4 100644 --- a/plugins/withHuaweiPush.js +++ b/plugins/withHuaweiPush.js @@ -43,31 +43,14 @@ const withHuaweiPush = (config, options = {}) => { } } - // Add Jiguang Maven repo for dependency resolution (jcore/jpush SDK) + // Add Jiguang Maven repo to dependencyResolutionManagement (for jcore/jpush SDK) if (!contents.includes('developer.jiguang.cn/maven')) { const depMgmtPattern = /dependencyResolutionManagement\s*\{[\s\S]*?repositories\s*\{/; if (depMgmtPattern.test(config.modResults.contents)) { config.modResults.contents = config.modResults.contents.replace( depMgmtPattern, - ` if (!contents.includes('developer.huawei.com/repo')) { - const repoLine = ` maven { url 'https://developer.huawei.com/repo/' }`; - const hasPluginManagement = contents.includes('pluginManagement'); - const hasRepositoriesInPM = /pluginManagement\s*\{[\s\S]*?repositories\s*\{/.test(contents); - - if (hasRepositoriesInPM) { - config.modResults.contents = contents.replace( - /(pluginManagement\s*\{[\s\S]*?repositories\s*\{)/, - `$1\n ${repoLine}` + `$&\n maven { url 'https://developer.jiguang.cn/maven' }` ); - } else if (hasPluginManagement) { - config.modResults.contents = contents.replace( - /(pluginManagement\s*\{)/, - `$1\n repositories {\n gradlePluginPortal()\n google()\n mavenCentral()\n ${repoLine}\n }` - ); - } else { - config.modResults.contents = - `pluginManagement {\n repositories {\n ${repoLine}\n }\n}\n\n` + - config.modResults.contents; } } @@ -80,9 +63,6 @@ const withHuaweiPush = (config, options = {}) => { `$&\n maven { url 'https://developer.huawei.com/repo/' }` ); } - }\n maven { url 'https://developer.jiguang.cn/maven' }` - ); - } } return config;