@mznjs/mbump 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,9 +5,9 @@ import { dirname, join, resolve } from "node:path";
5
5
  import { consola } from "consola";
6
6
  import ora from "ora";
7
7
  import { execSync } from "node:child_process";
8
+ import process from "node:process";
8
9
  import semver from "semver";
9
10
  import * as toml from "toml";
10
- import process from "node:process";
11
11
 
12
12
  //#region src/utils/logger.ts
13
13
  const logger = consola.create({ formatOptions: { date: false } });
@@ -65,7 +65,7 @@ const BASE_CONFIG = {
65
65
  dryRun: false,
66
66
  verbose: false,
67
67
  allowUncommitted: false,
68
- npm: false
68
+ publish: false
69
69
  },
70
70
  git: {
71
71
  commitMessage: "chore: bump version to {{newVersion}}",
@@ -689,6 +689,44 @@ var GitManager = class {
689
689
  return null;
690
690
  }
691
691
  }
692
+ getCurrentBranch() {
693
+ try {
694
+ const output = execSync("git rev-parse --abbrev-ref HEAD", {
695
+ cwd: this.rootDir,
696
+ encoding: "utf8",
697
+ stdio: "pipe"
698
+ });
699
+ return output.trim() || null;
700
+ } catch {
701
+ return null;
702
+ }
703
+ }
704
+ getDefaultRemote() {
705
+ try {
706
+ const branch = this.getCurrentBranch();
707
+ if (!branch) return null;
708
+ const output = execSync(`git config branch.${branch}.remote`, {
709
+ cwd: this.rootDir,
710
+ encoding: "utf8",
711
+ stdio: "pipe"
712
+ });
713
+ const upstreamRemote = output.trim();
714
+ if (upstreamRemote) return upstreamRemote;
715
+ } catch {}
716
+ try {
717
+ const output = execSync("git remote", {
718
+ cwd: this.rootDir,
719
+ encoding: "utf8",
720
+ stdio: "pipe"
721
+ });
722
+ const remotes = output.trim().split("\n").filter(Boolean);
723
+ if (remotes.length > 0) {
724
+ const origin = remotes.find((r) => r === "origin");
725
+ return origin || remotes[0];
726
+ }
727
+ } catch {}
728
+ return null;
729
+ }
692
730
  getCommitsSinceLastTag() {
693
731
  try {
694
732
  const lastTag = this.getLastTag();
@@ -765,13 +803,17 @@ var GitManager = class {
765
803
  }
766
804
  push(includeTags = true) {
767
805
  try {
768
- execSync("git push", {
806
+ const remote = this.getDefaultRemote();
807
+ const branch = this.getCurrentBranch();
808
+ let pushCommand = "git push";
809
+ if (remote) pushCommand = branch ? `git push ${remote} ${branch}` : `git push ${remote}`;
810
+ execSync(pushCommand, {
769
811
  cwd: this.rootDir,
770
812
  stdio: "pipe"
771
813
  });
772
814
  logger_default.debug("Git push");
773
815
  if (includeTags) {
774
- execSync("git push --tags", {
816
+ execSync(remote ? `git push ${remote} --tags` : "git push --tags", {
775
817
  cwd: this.rootDir,
776
818
  stdio: "pipe"
777
819
  });
@@ -781,7 +823,7 @@ var GitManager = class {
781
823
  throw new Error(`Git push failed: ${error$1.message}`);
782
824
  }
783
825
  }
784
- commitAndPush(message, push = true, createTag = false, tagVersion, tagPrefix = "v") {
826
+ commitAndPush(message, push = true, createTag = false, tagVersion, tagPrefix = "v", tagName) {
785
827
  try {
786
828
  execSync("git config --local core.autocrlf false", {
787
829
  cwd: this.rootDir,
@@ -792,7 +834,16 @@ var GitManager = class {
792
834
  }
793
835
  this.addFiles(["-u"]);
794
836
  this.commit(message);
795
- if (createTag && tagVersion) this.createTag(tagVersion, tagPrefix);
837
+ if (createTag && tagVersion) if (tagName) try {
838
+ execSync(`git tag -a ${tagName} -m "Release ${tagName}"`, {
839
+ cwd: this.rootDir,
840
+ stdio: "pipe"
841
+ });
842
+ logger_default.success(`已创建 tag: ${tagName}`);
843
+ } catch (error$1) {
844
+ throw new Error(`创建 Tag 失败: ${error$1.message}`);
845
+ }
846
+ else this.createTag(tagVersion, tagPrefix);
796
847
  if (push) try {
797
848
  this.push(createTag);
798
849
  } catch (error$1) {
@@ -801,182 +852,6 @@ var GitManager = class {
801
852
  }
802
853
  };
803
854
 
804
- //#endregion
805
- //#region src/core/RustManager.ts
806
- var RustManager = class {
807
- cargoTomlPath;
808
- gitManager;
809
- changelogManager;
810
- rootDir;
811
- constructor(rootDir) {
812
- this.rootDir = rootDir;
813
- this.cargoTomlPath = join(rootDir, "Cargo.toml");
814
- this.gitManager = new GitManager(rootDir);
815
- this.changelogManager = new ChangelogManager(rootDir);
816
- }
817
- exists() {
818
- return existsSync(this.cargoTomlPath);
819
- }
820
- getCurrentVersion() {
821
- try {
822
- const content = readFileSync(this.cargoTomlPath, "utf8");
823
- const parsed = toml.parse(content);
824
- if (parsed.package && typeof parsed.package.version === "string") return parsed.package.version;
825
- return null;
826
- } catch {
827
- return null;
828
- }
829
- }
830
- getPackageName() {
831
- try {
832
- const content = readFileSync(this.cargoTomlPath, "utf8");
833
- const parsed = toml.parse(content);
834
- if (parsed.package && typeof parsed.package.name === "string") return parsed.package.name;
835
- return null;
836
- } catch {
837
- return null;
838
- }
839
- }
840
- updateVersion(releaseType, options = {}) {
841
- const { dryRun: dryRun$1 = false, verbose = false, customVersion = null, autoCommit = true, push = true, tag = true, changelog = true, allowUncommitted = false } = options;
842
- if (!this.exists()) throw new Error(`Cargo.toml 文件不存在: ${this.cargoTomlPath}`);
843
- const oldVersion = this.getCurrentVersion();
844
- if (!oldVersion) throw new Error(`Cargo.toml 文件中未找到 [package] 部分的 version 字段`);
845
- const packageName = this.getPackageName() || "rust";
846
- let newVersion = null;
847
- if (customVersion) {
848
- if (!semver.valid(customVersion)) throw new Error(`无效的自定义版本号: ${customVersion}`);
849
- newVersion = customVersion;
850
- } else {
851
- let semverType = releaseType;
852
- let prerelease;
853
- if (releaseType === "pre-patch") {
854
- semverType = "prepatch";
855
- prerelease = "beta";
856
- } else if (releaseType === "pre-minor") {
857
- semverType = "preminor";
858
- prerelease = "beta";
859
- } else if (releaseType === "pre-major") {
860
- semverType = "premajor";
861
- prerelease = "beta";
862
- } else if (releaseType === "prerelease") {
863
- semverType = "prerelease";
864
- prerelease = "beta";
865
- }
866
- if (prerelease) newVersion = semver.inc(oldVersion, semverType, prerelease);
867
- else newVersion = semver.inc(oldVersion, semverType);
868
- if (!newVersion) throw new Error(`无法计算新版本,当前版本 "${oldVersion}",版本类型 "${releaseType}"`);
869
- }
870
- if (!semver.valid(newVersion)) throw new Error(`计算出的新版本 "${newVersion}" 不是有效的 semver 版本号`);
871
- if (verbose) {
872
- logger_default.info(`读取 Cargo.toml: ${this.cargoTomlPath}`);
873
- logger_default.info(`当前版本: ${oldVersion}`);
874
- logger_default.info(`新版本: ${newVersion}`);
875
- }
876
- if (!dryRun$1 && autoCommit && !allowUncommitted && this.gitManager.hasUncommittedChanges()) throw new Error("存在未提交的更改,请先提交或使用 --allow-uncommitted 选项");
877
- if (dryRun$1) {
878
- const tagName = `${packageName}@${newVersion}`;
879
- logger_default.info(`\n🔍 Dry-run 模式 - Cargo.toml 版本更新预览:`);
880
- logger_default.info(` 当前版本: ${oldVersion}`);
881
- logger_default.info(` 新版本: ${newVersion}`);
882
- logger_default.info(` Tag: ${tag ? tagName : "跳过"}`);
883
- logger_default.info(` CHANGELOG: ${changelog ? "是" : "跳过"}`);
884
- logger_default.info(` Git Commit: ${autoCommit ? "是" : "否"}`);
885
- logger_default.info(` Git Push: ${push ? "是" : "否"}`);
886
- logger_default.info(`\n✅ 以上为预览,未执行任何实际操作`);
887
- return {
888
- success: true,
889
- oldVersion,
890
- newVersion
891
- };
892
- }
893
- this.writeVersion(newVersion);
894
- const verifiedVersion = this.getCurrentVersion();
895
- if (verifiedVersion !== newVersion) throw new Error(`版本更新验证失败,期望版本 "${newVersion}",实际版本 "${verifiedVersion}"`);
896
- logger_default.success(`Cargo.toml 版本更新完成: ${oldVersion} → ${newVersion}`);
897
- if (changelog) try {
898
- const commits = this.gitManager.getCommitsSinceLastTag();
899
- this.changelogManager.updateChangelog(newVersion, commits);
900
- logger_default.success(`已更新 CHANGELOG.md`);
901
- } catch (error$1) {
902
- logger_default.warn(`更新 CHANGELOG.md 失败: ${error$1.message}`);
903
- }
904
- if (autoCommit) {
905
- try {
906
- this.gitManager.addFiles(["-u"]);
907
- this.gitManager.commit(`chore: bump version to ${newVersion}`);
908
- logger_default.success(`已提交更改`);
909
- } catch (error$1) {
910
- logger_default.warn(`提交更改失败: ${error$1.message}`);
911
- }
912
- if (tag) {
913
- const tagName = `${packageName}@${newVersion}`;
914
- try {
915
- execSync(`git tag -a ${tagName} -m "Release ${tagName}"`, {
916
- cwd: this.rootDir,
917
- stdio: "pipe"
918
- });
919
- logger_default.success(`已创建 tag: ${tagName}`);
920
- } catch (error$1) {
921
- logger_default.warn(`创建 tag ${tagName} 失败: ${error$1.message}`);
922
- }
923
- }
924
- if (push) try {
925
- this.gitManager.push(tag);
926
- logger_default.success(`已推送 commits 和 tags`);
927
- } catch (error$1) {
928
- logger_default.warn(`推送失败: ${error$1.message}`);
929
- }
930
- }
931
- return {
932
- success: true,
933
- oldVersion,
934
- newVersion
935
- };
936
- }
937
- writeVersion(newVersion) {
938
- try {
939
- const content = readFileSync(this.cargoTomlPath, "utf8");
940
- const lines = content.split("\n");
941
- let inPackageSection = false;
942
- let versionUpdated = false;
943
- const newLines = lines.map((line) => {
944
- const trimmedLine = line.trim();
945
- if (trimmedLine.startsWith("[package]")) {
946
- inPackageSection = true;
947
- return line;
948
- }
949
- if (trimmedLine.startsWith("[") && inPackageSection) {
950
- inPackageSection = false;
951
- return line;
952
- }
953
- if (inPackageSection) {
954
- const versionMatch = trimmedLine.match(/^version\s*=\s*["'](.+?)["']/);
955
- if (versionMatch) {
956
- versionUpdated = true;
957
- const spaces = line.match(/^\s*/)?.[0] || "";
958
- const quote = versionMatch[0].includes("\"") ? "\"" : "'";
959
- return `${spaces}version = ${quote}${newVersion}${quote}`;
960
- }
961
- }
962
- return line;
963
- });
964
- if (!versionUpdated) {
965
- let packageSectionIndex = -1;
966
- for (let i = 0; i < lines.length; i++) if (lines[i].trim().startsWith("[package]")) {
967
- packageSectionIndex = i;
968
- break;
969
- }
970
- if (packageSectionIndex !== -1) newLines.splice(packageSectionIndex + 1, 0, `version = "${newVersion}"`);
971
- else newLines.unshift("[package]", `version = "${newVersion}"`);
972
- }
973
- writeFileSync(this.cargoTomlPath, newLines.join("\n"), { encoding: "utf8" });
974
- } catch (error$1) {
975
- throw new Error(`写入 Cargo.toml 失败: ${error$1.message}`);
976
- }
977
- }
978
- };
979
-
980
855
  //#endregion
981
856
  //#region src/utils/security.ts
982
857
  var security_exports = {};
@@ -1059,6 +934,84 @@ function getPatch(version) {
1059
934
  return parsed?.patch ?? null;
1060
935
  }
1061
936
 
937
+ //#endregion
938
+ //#region src/core/VersionProvider.ts
939
+ var NodeVersionProvider = class {
940
+ type = "node";
941
+ getVersionFilePaths(rootDir) {
942
+ return [`${rootDir}/package.json`];
943
+ }
944
+ getPackageInfo(filePath) {
945
+ const content = readFileSync(filePath, "utf8");
946
+ const parsed = JSON.parse(content);
947
+ return parsed;
948
+ }
949
+ updateVersion(filePath, newVersion) {
950
+ const content = readFileSync(filePath, "utf8");
951
+ const parsed = JSON.parse(content);
952
+ parsed.version = newVersion;
953
+ writeFileSync(filePath, JSON.stringify(parsed, null, 2));
954
+ }
955
+ getDefaultTagFormat(packageName, version, isDefaultPackage) {
956
+ return isDefaultPackage ? `v${version}` : `${packageName}@${version}`;
957
+ }
958
+ };
959
+ var RustVersionProvider = class {
960
+ type = "rust";
961
+ getVersionFilePaths(rootDir) {
962
+ return [`${rootDir}/Cargo.toml`];
963
+ }
964
+ getPackageInfo(filePath) {
965
+ const content = readFileSync(filePath, "utf8");
966
+ const parsed = toml.parse(content);
967
+ return {
968
+ name: parsed.package?.name || "rust",
969
+ version: parsed.package?.version || "0.0.0",
970
+ description: parsed.package?.description || ""
971
+ };
972
+ }
973
+ updateVersion(filePath, newVersion) {
974
+ const content = readFileSync(filePath, "utf8");
975
+ const lines = content.split("\n");
976
+ let inPackageSection = false;
977
+ let versionUpdated = false;
978
+ const newLines = lines.map((line) => {
979
+ const trimmedLine = line.trim();
980
+ if (trimmedLine.startsWith("[package]")) {
981
+ inPackageSection = true;
982
+ return line;
983
+ }
984
+ if (trimmedLine.startsWith("[") && inPackageSection) {
985
+ inPackageSection = false;
986
+ return line;
987
+ }
988
+ if (inPackageSection) {
989
+ const versionMatch = trimmedLine.match(/^version\s*=\s*["'](.+?)["']/);
990
+ if (versionMatch) {
991
+ versionUpdated = true;
992
+ const spaces = line.match(/^\s*/)?.[0] || "";
993
+ const quote = versionMatch[0].includes("\"") ? "\"" : "'";
994
+ return `${spaces}version = ${quote}${newVersion}${quote}`;
995
+ }
996
+ }
997
+ return line;
998
+ });
999
+ if (!versionUpdated) {
1000
+ let packageSectionIndex = -1;
1001
+ for (let i = 0; i < lines.length; i++) if (lines[i].trim().startsWith("[package]")) {
1002
+ packageSectionIndex = i;
1003
+ break;
1004
+ }
1005
+ if (packageSectionIndex !== -1) newLines.splice(packageSectionIndex + 1, 0, `version = "${newVersion}"`);
1006
+ else newLines.unshift("[package]", `version = "${newVersion}"`);
1007
+ }
1008
+ writeFileSync(filePath, newLines.join("\n"), { encoding: "utf8" });
1009
+ }
1010
+ getDefaultTagFormat(packageName, version, _isDefaultPackage) {
1011
+ return `${packageName}@${version}`;
1012
+ }
1013
+ };
1014
+
1062
1015
  //#endregion
1063
1016
  //#region src/core/VersionManager.ts
1064
1017
  var VersionManager = class {
@@ -1071,8 +1024,9 @@ var VersionManager = class {
1071
1024
  packageCache = new Map();
1072
1025
  gitManager;
1073
1026
  changelogManager;
1027
+ versionProvider;
1074
1028
  constructor(options = {}) {
1075
- const { packagePaths, configPath, config, rootDir = process.cwd() } = options;
1029
+ const { packagePaths, configPath, config, rootDir = process.cwd(), projectType = "node" } = options;
1076
1030
  this.config = config || (configPath ? loadConfig(dirname(configPath)) : loadConfig(rootDir));
1077
1031
  this.rootDir = rootDir;
1078
1032
  this.packagePaths = packagePaths || this.config.packagePaths;
@@ -1081,9 +1035,22 @@ var VersionManager = class {
1081
1035
  this.gitPush = this.gitConfig.push !== false;
1082
1036
  this.gitManager = new GitManager(rootDir);
1083
1037
  this.changelogManager = new ChangelogManager(rootDir);
1038
+ this.versionProvider = projectType === "rust" ? new RustVersionProvider() : new NodeVersionProvider();
1084
1039
  if (!this.packagePaths || typeof this.packagePaths !== "object" || Object.keys(this.packagePaths).length === 0) throw new Error("配置错误:未找到有效的包路径配置");
1085
1040
  this._preloadPackageCache();
1086
1041
  }
1042
+ _isDefaultPackage(pkgKey) {
1043
+ const pkgPath = this.config.packagePaths[pkgKey];
1044
+ if (!pkgPath) return false;
1045
+ const isDefaultKey = pkgKey === "default";
1046
+ const resolvedPkgDir = resolve(dirname(pkgPath));
1047
+ const resolvedRootDir = resolve(this.rootDir);
1048
+ const isNodeRoot = pkgPath.endsWith("package.json") && resolvedPkgDir === resolvedRootDir;
1049
+ const isRustRoot = pkgPath.includes("Cargo.toml");
1050
+ const isSinglePackageMode = Object.keys(this.config.packagePaths).length === 1;
1051
+ const isPathModeRoot = isSinglePackageMode && isNodeRoot;
1052
+ return isDefaultKey || isNodeRoot && !isPathModeRoot || isRustRoot;
1053
+ }
1087
1054
  /**
1088
1055
  * 预加载所有包信息到缓存,避免后续重复读取文件
1089
1056
  */
@@ -1126,7 +1093,7 @@ var VersionManager = class {
1126
1093
  };
1127
1094
  }
1128
1095
  async previewUpdate(pkgName, releaseType = "patch", options = {}) {
1129
- const { packagePaths = this.packagePaths, customVersion = null, autoCommit = this.gitConfig.autoCommit !== false, push = this.gitConfig.push !== false, npm = false, changelog = this.gitConfig.changelog !== false, tagPrefix = this.gitConfig.tagPrefix || "v", packageVersionSelections } = options;
1096
+ const { packagePaths = this.packagePaths, customVersion = null, autoCommit = this.gitConfig.autoCommit !== false, push = this.gitConfig.push !== false, publish = false, changelog = this.gitConfig.changelog !== false, packageVersionSelections } = options;
1130
1097
  const packages = [];
1131
1098
  if (pkgName === "all" && packageVersionSelections) for (const [packageName, selection] of Object.entries(packageVersionSelections)) {
1132
1099
  const pkgPath = packagePaths[packageName];
@@ -1178,8 +1145,8 @@ var VersionManager = class {
1178
1145
  throw new Error(`版本计算失败: ${error$1.message}`);
1179
1146
  }
1180
1147
  if (!newVersion) throw new Error(`无法计算新版本号,当前版本: ${pkg.version},类型: ${selection.type}`);
1181
- const isDefaultPackage = packageName === "default" || packagePaths[packageName] === "package.json";
1182
- const tagName = isDefaultPackage ? `${tagPrefix}${newVersion}` : `${pkg.name}@${newVersion}`;
1148
+ const isDefaultPackage = this._isDefaultPackage(packageName);
1149
+ const tagName = this.versionProvider.getDefaultTagFormat(pkg.name, newVersion, isDefaultPackage);
1183
1150
  packages.push({
1184
1151
  name: packageName,
1185
1152
  oldVersion: pkg.version,
@@ -1190,9 +1157,9 @@ var VersionManager = class {
1190
1157
  });
1191
1158
  }
1192
1159
  else {
1193
- const targets = pkgName === "all" ? Object.values(packagePaths) : [packagePaths[pkgName]];
1194
- if (!targets.length || targets.some((path) => !path)) throw new Error(`无效的包名: ${pkgName}`);
1195
- for (const pkgPath of targets) {
1160
+ const targets = pkgName === "all" ? Object.entries(packagePaths) : [[pkgName, packagePaths[pkgName]]];
1161
+ if (!targets.length || targets.some(([, path]) => !path)) throw new Error(`无效的包名: ${pkgName}`);
1162
+ for (const [packageName, pkgPath] of targets) {
1196
1163
  const pkg = this.getPackageInfo(pkgPath);
1197
1164
  let newVersion = null;
1198
1165
  if (customVersion) {
@@ -1240,8 +1207,8 @@ var VersionManager = class {
1240
1207
  throw new Error(`版本计算失败: ${error$1.message}`);
1241
1208
  }
1242
1209
  if (!newVersion) throw new Error(`无法计算新版本号,当前版本: ${pkg.version},类型: ${releaseType}`);
1243
- const isDefaultPackage = pkgName === "default" || packagePaths[pkgName] === "package.json";
1244
- const tagName = isDefaultPackage ? `${tagPrefix}${newVersion}` : `${pkg.name}@${newVersion}`;
1210
+ const isDefaultPackage = this._isDefaultPackage(packageName);
1211
+ const tagName = this.versionProvider.getDefaultTagFormat(pkg.name, newVersion, isDefaultPackage);
1245
1212
  packages.push({
1246
1213
  name: pkg.name,
1247
1214
  oldVersion: pkg.version,
@@ -1256,11 +1223,11 @@ var VersionManager = class {
1256
1223
  packages,
1257
1224
  autoCommit,
1258
1225
  push,
1259
- npm
1226
+ publish
1260
1227
  };
1261
1228
  }
1262
1229
  async updateVersion(pkgName, releaseType = "patch", options = {}) {
1263
- const { dryRun: dryRun$1 = false, verbose = false, packagePaths = this.packagePaths, customVersion = null, autoCommit = this.gitConfig.autoCommit !== false, npm = false, changelog = this.gitConfig.changelog !== false, tag = this.gitConfig.tag !== false, tagPrefix = this.gitConfig.tagPrefix || "v", isBatchMode = false } = options;
1230
+ const { dryRun: dryRun$1 = false, verbose = false, packagePaths = this.packagePaths, customVersion = null, autoCommit = this.gitConfig.autoCommit !== false, publish = false, changelog = this.gitConfig.changelog !== false, tag = this.gitConfig.tag !== false, tagPrefix = this.gitConfig.tagPrefix || "v", isBatchMode = false } = options;
1264
1231
  const result = {
1265
1232
  success: false,
1266
1233
  updatedPackages: [],
@@ -1322,8 +1289,8 @@ var VersionManager = class {
1322
1289
  if (!newVersion) throw new Error(`无法计算新版本号,当前版本: ${pkg.version},类型: ${releaseType}`);
1323
1290
  if (!finalVersion) {
1324
1291
  finalVersion = newVersion;
1325
- const isDefaultPackage$1 = pkgName === "default" || this.config.packagePaths[pkgName] === "package.json";
1326
- const versionTag = isDefaultPackage$1 ? `${tagPrefix}${newVersion}` : `${pkg.name}@${newVersion}`;
1292
+ const isDefaultPackage$1 = pkgName === "all" ? this._isDefaultPackage(Object.keys(packagePaths)[0]) : this._isDefaultPackage(pkgName);
1293
+ const versionTag = this.versionProvider.getDefaultTagFormat(pkg.name, newVersion, isDefaultPackage$1);
1327
1294
  if (!dryRun$1 && this.gitManager.checkVersionExists(newVersion, tagPrefix, isDefaultPackage$1 ? void 0 : pkg.name)) throw new Error(`版本 ${versionTag} 已存在,请使用其他版本`);
1328
1295
  }
1329
1296
  if (dryRun$1) logger_default.dryRun(`将更新 ${pkg.name} 从 v${pkg.version} 到 v${newVersion}`);
@@ -1342,7 +1309,7 @@ var VersionManager = class {
1342
1309
  pkgKey: pkgName
1343
1310
  });
1344
1311
  }
1345
- const isDefaultPackage = pkgName === "default" || this.config.packagePaths[pkgName] === "package.json";
1312
+ const isDefaultPackage = pkgName === "all" ? this._isDefaultPackage(Object.keys(packagePaths)[0]) : this._isDefaultPackage(pkgName);
1346
1313
  if (!dryRun$1 && changelog && finalVersion) if (isBatchMode && !isDefaultPackage) logger_default.info(`子包 ${pkgName} 跳过 CHANGELOG 生成`);
1347
1314
  else try {
1348
1315
  const commits = this.gitManager.getCommitsSinceLastTag();
@@ -1356,12 +1323,14 @@ var VersionManager = class {
1356
1323
  } catch (changelogError) {
1357
1324
  logger_default.warn(`CHANGELOG生成失败: ${changelogError.message}`);
1358
1325
  }
1359
- if (!dryRun$1 && npm) for (const pkgPath of targets) {
1326
+ if (!dryRun$1 && publish) for (const pkgPath of targets) {
1360
1327
  const pkg = this.getPackageInfo(pkgPath);
1361
1328
  const pkgDir = dirname(pkgPath);
1362
1329
  logger_default.info(`\n发布 ${pkg.name}...`);
1363
1330
  try {
1364
- const publishCmd = this.publishConfig.command || "pnpm publish --access public --no-git-checks";
1331
+ let publishCmd;
1332
+ if (this.versionProvider.type === "rust") publishCmd = "cargo publish";
1333
+ else publishCmd = this.publishConfig.command || "pnpm publish --access public --no-git-checks";
1365
1334
  if (!validateCommand(publishCmd)) throw new Error(`不安全的发布命令: ${publishCmd}`);
1366
1335
  if (verbose) logger_default.debug(`执行命令: ${publishCmd} (在目录: ${pkgDir})`);
1367
1336
  const { execSync: execSync$1 } = await import("node:child_process");
@@ -1378,18 +1347,20 @@ var VersionManager = class {
1378
1347
  let commitMessage;
1379
1348
  const updatedPackage = result.updatedPackages[0];
1380
1349
  const newVersion = updatedPackage.newVersion;
1381
- const isDefaultPackage$1 = pkgName === "default" || this.config.packagePaths[pkgName] === "package.json";
1350
+ const isDefaultPackage$1 = pkgName === "all" ? this._isDefaultPackage(Object.keys(packagePaths)[0]) : this._isDefaultPackage(pkgName);
1382
1351
  if (this.gitConfig.commitMessage && this.gitConfig.commitMessage !== "chore: bump version to {{newVersion}}") commitMessage = this.gitConfig.commitMessage.replace(/\{\{newVersion\}\}/g, newVersion);
1383
1352
  else if (pkgName === "all") {
1384
1353
  const versionInfo = result.updatedPackages.map((pkg) => `${pkg.name}@${pkg.newVersion}`).join(", ");
1385
1354
  commitMessage = `chore: bump version for all packages\n\n${versionInfo}`;
1386
1355
  } else commitMessage = `chore: bump version for ${pkgName} to v${newVersion}`;
1387
- if (isDefaultPackage$1) this.gitManager.commitAndPush(commitMessage, this.gitPush, tag, newVersion, tagPrefix);
1356
+ let tagName;
1357
+ if (tagPrefix !== "v") tagName = `${tagPrefix}${newVersion}`;
1358
+ else tagName = this.versionProvider.getDefaultTagFormat(updatedPackage.name, newVersion, isDefaultPackage$1);
1359
+ if (isDefaultPackage$1) this.gitManager.commitAndPush(commitMessage, this.gitPush, tag, newVersion, tagPrefix, tagName);
1388
1360
  else {
1389
1361
  const { execSync: execSync$1 } = await import("node:child_process");
1390
1362
  this.gitManager.addFiles(["-u"]);
1391
1363
  this.gitManager.commit(commitMessage);
1392
- const tagName = `${updatedPackage.name}@${newVersion}`;
1393
1364
  try {
1394
1365
  execSync$1(`git tag -a ${tagName} -m "Release ${tagName}"`, {
1395
1366
  cwd: this.rootDir,
@@ -1419,7 +1390,7 @@ var VersionManager = class {
1419
1390
  failText: "版本更新失败"
1420
1391
  });
1421
1392
  }
1422
- async gitCommitAndPush(push = true, updatedPackages, tag = this.gitConfig.tag !== false, tagPrefix = this.gitConfig.tagPrefix || "v") {
1393
+ async gitCommitAndPush(push = true, updatedPackages, tag = this.gitConfig.tag !== false) {
1423
1394
  try {
1424
1395
  const commitMessage = "chore: bump versions for multiple packages";
1425
1396
  if (tag && updatedPackages && updatedPackages.length > 0) {
@@ -1427,10 +1398,8 @@ var VersionManager = class {
1427
1398
  this.gitManager.commit(commitMessage);
1428
1399
  const { execSync: execSync$1 } = await import("node:child_process");
1429
1400
  for (const pkg of updatedPackages) {
1430
- let tagName;
1431
1401
  const isMainPackage = pkg.pkgKey === "default";
1432
- if (isMainPackage) tagName = `${tagPrefix}${pkg.newVersion}`;
1433
- else tagName = `${pkg.name}@${pkg.newVersion}`;
1402
+ const tagName = this.versionProvider.getDefaultTagFormat(pkg.name, pkg.newVersion, isMainPackage);
1434
1403
  try {
1435
1404
  execSync$1(`git tag -a ${tagName} -m "Release ${tagName}"`, {
1436
1405
  cwd: this.rootDir,
@@ -1460,7 +1429,7 @@ var VersionManager = class {
1460
1429
  const cached = this.packageCache.get(pkgPath);
1461
1430
  if (cached) return cached;
1462
1431
  try {
1463
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
1432
+ const pkg = this.versionProvider.getPackageInfo(pkgPath);
1464
1433
  this.packageCache.set(pkgPath, pkg);
1465
1434
  return pkg;
1466
1435
  } catch (error$1) {
@@ -1470,7 +1439,7 @@ var VersionManager = class {
1470
1439
  savePackageInfo(pkgPath, pkg) {
1471
1440
  if (!validatePath(pkgPath, this.rootDir)) throw new Error(`不安全的文件路径: ${pkgPath}`);
1472
1441
  try {
1473
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
1442
+ this.versionProvider.updateVersion(pkgPath, pkg.version);
1474
1443
  this.packageCache.set(pkgPath, pkg);
1475
1444
  } catch (error$1) {
1476
1445
  throw new Error(`写入文件失败 ${pkgPath}: ${error$1.message}`);
@@ -1518,5 +1487,5 @@ function isAbsolutePath(path) {
1518
1487
  }
1519
1488
 
1520
1489
  //#endregion
1521
- export { BASE_CONFIG, ChangelogManager, GitManager, RustManager, VersionManager, clearConfigCache, isPathLike, loadConfig, loadConfigAsync, logger_default, path_exports, security_exports, semver_exports };
1522
- //# sourceMappingURL=path-BvKf4Pq-.js.map
1490
+ export { BASE_CONFIG, ChangelogManager, GitManager, NodeVersionProvider, RustVersionProvider, VersionManager, clearConfigCache, isPathLike, loadConfig, loadConfigAsync, logger_default, path_exports, security_exports, semver_exports };
1491
+ //# sourceMappingURL=path-CDDLZPST.js.map