@releasekit/version 0.2.0 → 0.3.0-next.1

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.
@@ -20,8 +20,7 @@ function toVersionConfig(config, gitConfig) {
20
20
  packages: [],
21
21
  updateInternalDependencies: "minor",
22
22
  versionPrefix: "",
23
- baseBranch: gitConfig?.branch,
24
- skipHooks: gitConfig?.skipHooks
23
+ baseBranch: gitConfig?.branch
25
24
  };
26
25
  }
27
26
  return {
@@ -40,7 +39,6 @@ function toVersionConfig(config, gitConfig) {
40
39
  releaseType: bp.releaseType
41
40
  })),
42
41
  defaultReleaseType: config.defaultReleaseType,
43
- skipHooks: gitConfig?.skipHooks,
44
42
  mismatchStrategy: config.mismatchStrategy,
45
43
  versionPrefix: config.versionPrefix ?? "",
46
44
  prereleaseIdentifier: config.prereleaseIdentifier,
@@ -185,14 +183,11 @@ function log(message, level = "info") {
185
183
  default:
186
184
  chalkFn = chalk.blue;
187
185
  }
186
+ const formattedMessage = level === "debug" ? `[DEBUG] ${message}` : message;
188
187
  if (isJsonOutputMode()) {
189
- if (level === "error") {
190
- chalkFn(message);
191
- console.error(message);
192
- }
188
+ console.error(chalkFn(formattedMessage));
193
189
  return;
194
190
  }
195
- const formattedMessage = level === "debug" ? `[DEBUG] ${message}` : message;
196
191
  if (level === "error") {
197
192
  console.error(chalkFn(formattedMessage));
198
193
  } else {
@@ -208,22 +203,6 @@ import semver3 from "semver";
208
203
  // src/git/repository.ts
209
204
  import { existsSync, statSync } from "fs";
210
205
  import { join } from "path";
211
- function isGitRepository(directory) {
212
- const gitDir = join(directory, ".git");
213
- if (!existsSync(gitDir)) {
214
- return false;
215
- }
216
- const stats = statSync(gitDir);
217
- if (!stats.isDirectory()) {
218
- return false;
219
- }
220
- try {
221
- execSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: directory });
222
- return true;
223
- } catch (_error) {
224
- return false;
225
- }
226
- }
227
206
  function getCurrentBranch() {
228
207
  const result = execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
229
208
  return result.toString().trim();
@@ -592,13 +571,13 @@ import { parseCargoToml as parseCargoToml2 } from "@releasekit/config";
592
571
  import semver2 from "semver";
593
572
 
594
573
  // src/git/tagVerification.ts
595
- function verifyTag(tagName, cwd4) {
574
+ function verifyTag(tagName, cwd3) {
596
575
  if (!tagName || tagName.trim() === "") {
597
576
  return { exists: false, reachable: false, error: "Empty tag name" };
598
577
  }
599
578
  try {
600
579
  execSync("git", ["rev-parse", "--verify", tagName], {
601
- cwd: cwd4,
580
+ cwd: cwd3,
602
581
  stdio: "ignore"
603
582
  });
604
583
  return { exists: true, reachable: true };
@@ -695,11 +674,11 @@ var VersionMismatchError = class extends Error {
695
674
  this.name = "VersionMismatchError";
696
675
  }
697
676
  };
698
- async function getBestVersionSource(tagName, packageVersion, cwd4, mismatchStrategy = "error", strictReachable = false) {
677
+ async function getBestVersionSource(tagName, packageVersion, cwd3, mismatchStrategy = "error", strictReachable = false) {
699
678
  if (!tagName?.trim()) {
700
679
  return packageVersion ? { source: "package", version: packageVersion, reason: "No git tag provided" } : { source: "initial", version: "0.1.0", reason: "No git tag or package version available" };
701
680
  }
702
- const verification = verifyTag(tagName, cwd4);
681
+ const verification = verifyTag(tagName, cwd3);
703
682
  if (!verification.exists || !verification.reachable) {
704
683
  if (strictReachable) {
705
684
  throw new Error(
@@ -966,7 +945,6 @@ async function calculateVersion(config, options) {
966
945
  // src/package/packageProcessor.ts
967
946
  import * as fs5 from "fs";
968
947
  import path4 from "path";
969
- import { exit } from "process";
970
948
 
971
949
  // src/changelog/commitParser.ts
972
950
  var CONVENTIONAL_COMMIT_REGEX = /^(\w+)(?:\(([^)]+)\))?(!)?: (.+)(?:\n\n([\s\S]*))?/;
@@ -1140,168 +1118,6 @@ function extractIssueIds(body) {
1140
1118
  return issueIds;
1141
1119
  }
1142
1120
 
1143
- // src/git/commands.ts
1144
- import { cwd as cwd2 } from "process";
1145
-
1146
- // src/errors/gitError.ts
1147
- var GitError = class extends BaseVersionError {
1148
- };
1149
- function createGitError(code, details) {
1150
- const messages = {
1151
- ["NOT_GIT_REPO" /* NOT_GIT_REPO */]: "Not a git repository",
1152
- ["GIT_PROCESS_ERROR" /* GIT_PROCESS_ERROR */]: "Failed to create new version",
1153
- ["NO_FILES" /* NO_FILES */]: "No files specified for commit",
1154
- ["NO_COMMIT_MESSAGE" /* NO_COMMIT_MESSAGE */]: "Commit message is required",
1155
- ["GIT_ERROR" /* GIT_ERROR */]: "Git operation failed",
1156
- ["TAG_ALREADY_EXISTS" /* TAG_ALREADY_EXISTS */]: "Git tag already exists"
1157
- };
1158
- const suggestions = {
1159
- ["NOT_GIT_REPO" /* NOT_GIT_REPO */]: [
1160
- "Initialize git repository with: git init",
1161
- "Ensure you are in the correct directory"
1162
- ],
1163
- ["TAG_ALREADY_EXISTS" /* TAG_ALREADY_EXISTS */]: [
1164
- "Delete the existing tag: git tag -d <tag-name>",
1165
- "Use a different version by incrementing manually",
1166
- "Check if this version was already released"
1167
- ],
1168
- ["GIT_PROCESS_ERROR" /* GIT_PROCESS_ERROR */]: void 0,
1169
- ["NO_FILES" /* NO_FILES */]: void 0,
1170
- ["NO_COMMIT_MESSAGE" /* NO_COMMIT_MESSAGE */]: void 0,
1171
- ["GIT_ERROR" /* GIT_ERROR */]: void 0
1172
- };
1173
- const baseMessage = messages[code];
1174
- const fullMessage = details ? `${baseMessage}: ${details}` : baseMessage;
1175
- return new GitError(fullMessage, code, suggestions[code]);
1176
- }
1177
-
1178
- // src/git/commands.ts
1179
- async function gitAdd(files) {
1180
- return execAsync("git", ["add", ...files]);
1181
- }
1182
- async function gitCommit(options) {
1183
- const args = ["commit"];
1184
- if (options.amend) {
1185
- args.push("--amend");
1186
- }
1187
- if (options.author) {
1188
- args.push("--author", options.author);
1189
- }
1190
- if (options.date) {
1191
- args.push("--date", options.date);
1192
- }
1193
- if (options.skipHooks) {
1194
- args.push("--no-verify");
1195
- }
1196
- args.push("-m", options.message);
1197
- return execAsync("git", args);
1198
- }
1199
- async function createGitTag(options) {
1200
- const { tag, message = "" } = options;
1201
- const args = ["tag", "-a", "-m", message, tag];
1202
- try {
1203
- return await execAsync("git", args);
1204
- } catch (error) {
1205
- const errorMessage = error instanceof Error ? error.message : String(error);
1206
- if (errorMessage.includes("already exists")) {
1207
- throw createGitError(
1208
- "TAG_ALREADY_EXISTS" /* TAG_ALREADY_EXISTS */,
1209
- `Tag '${tag}' already exists in the repository. Please use a different version or delete the existing tag first.`
1210
- );
1211
- }
1212
- throw createGitError("GIT_ERROR" /* GIT_ERROR */, errorMessage);
1213
- }
1214
- }
1215
- async function gitProcess(options) {
1216
- const { files, nextTag, commitMessage, skipHooks, dryRun } = options;
1217
- if (!isGitRepository(cwd2())) {
1218
- throw createGitError("NOT_GIT_REPO" /* NOT_GIT_REPO */);
1219
- }
1220
- try {
1221
- if (!dryRun) {
1222
- await gitAdd(files);
1223
- await gitCommit({
1224
- message: commitMessage,
1225
- skipHooks
1226
- });
1227
- if (nextTag) {
1228
- const tagMessage = `New Version ${nextTag} generated at ${(/* @__PURE__ */ new Date()).toISOString()}`;
1229
- await createGitTag({
1230
- tag: nextTag,
1231
- message: tagMessage
1232
- });
1233
- }
1234
- } else {
1235
- log("[DRY RUN] Would add files:", "info");
1236
- for (const file of files) {
1237
- log(` - ${file}`, "info");
1238
- }
1239
- log(`[DRY RUN] Would commit with message: "${commitMessage}"`, "info");
1240
- if (nextTag) {
1241
- log(`[DRY RUN] Would create tag: ${nextTag}`, "info");
1242
- }
1243
- }
1244
- } catch (err) {
1245
- const errorMessage = err instanceof Error ? err.message : String(err);
1246
- if (errorMessage.includes("already exists") && nextTag) {
1247
- log(`Tag '${nextTag}' already exists in the repository.`, "error");
1248
- throw createGitError(
1249
- "TAG_ALREADY_EXISTS" /* TAG_ALREADY_EXISTS */,
1250
- `Tag '${nextTag}' already exists in the repository. Please use a different version or delete the existing tag first.`
1251
- );
1252
- }
1253
- log(`Git process error: ${errorMessage}`, "error");
1254
- if (err instanceof Error && err.stack) {
1255
- console.error("Git process stack trace:");
1256
- console.error(err.stack);
1257
- }
1258
- throw createGitError("GIT_PROCESS_ERROR" /* GIT_PROCESS_ERROR */, errorMessage);
1259
- }
1260
- }
1261
- async function createGitCommitAndTag(files, nextTag, commitMessage, skipHooks, dryRun) {
1262
- try {
1263
- if (!files || files.length === 0) {
1264
- throw createGitError("NO_FILES" /* NO_FILES */);
1265
- }
1266
- if (!commitMessage) {
1267
- throw createGitError("NO_COMMIT_MESSAGE" /* NO_COMMIT_MESSAGE */);
1268
- }
1269
- setCommitMessage(commitMessage);
1270
- if (nextTag) {
1271
- addTag(nextTag);
1272
- }
1273
- await gitProcess({
1274
- files,
1275
- nextTag,
1276
- commitMessage,
1277
- skipHooks,
1278
- dryRun
1279
- });
1280
- if (!dryRun) {
1281
- log(`Created tag: ${nextTag}`, "success");
1282
- }
1283
- } catch (error) {
1284
- if (error instanceof GitError) {
1285
- throw error;
1286
- }
1287
- const errorMessage = error instanceof Error ? error.message : String(error);
1288
- log(`Failed to create git commit and tag: ${errorMessage}`, "error");
1289
- if (error instanceof Error) {
1290
- console.error("Git operation error details:");
1291
- console.error(error.stack || error.message);
1292
- if (errorMessage.includes("Command failed:")) {
1293
- const cmdOutput = errorMessage.split("Command failed:")[1];
1294
- if (cmdOutput) {
1295
- console.error("Git command output:", cmdOutput.trim());
1296
- }
1297
- }
1298
- } else {
1299
- console.error("Unknown git error:", error);
1300
- }
1301
- throw new GitError(`Git operation failed: ${errorMessage}`, "GIT_ERROR" /* GIT_ERROR */);
1302
- }
1303
- }
1304
-
1305
1121
  // src/utils/packageMatching.ts
1306
1122
  import micromatch from "micromatch";
1307
1123
  function matchesPackageTarget(packageName, target) {
@@ -1373,7 +1189,6 @@ var PackageProcessor = class {
1373
1189
  tagTemplate;
1374
1190
  commitMessageTemplate;
1375
1191
  dryRun;
1376
- skipHooks;
1377
1192
  getLatestTag;
1378
1193
  config;
1379
1194
  // Config for version calculation
@@ -1384,7 +1199,6 @@ var PackageProcessor = class {
1384
1199
  this.tagTemplate = options.tagTemplate;
1385
1200
  this.commitMessageTemplate = options.commitMessageTemplate || "";
1386
1201
  this.dryRun = options.dryRun || false;
1387
- this.skipHooks = options.skipHooks || false;
1388
1202
  this.getLatestTag = options.getLatestTag;
1389
1203
  this.config = options.config;
1390
1204
  this.fullConfig = options.fullConfig;
@@ -1587,19 +1401,12 @@ var PackageProcessor = class {
1587
1401
  this.tagTemplate,
1588
1402
  this.fullConfig.packageSpecificTags
1589
1403
  );
1590
- const tagMessage = `chore(release): ${name} ${nextVersion}`;
1591
1404
  addTag(packageTag);
1592
1405
  tags.push(packageTag);
1593
- if (!this.dryRun) {
1594
- try {
1595
- await createGitTag({ tag: packageTag, message: tagMessage });
1596
- log(`Created tag: ${packageTag}`, "success");
1597
- } catch (tagError) {
1598
- log(`Failed to create tag ${packageTag} for ${name}: ${tagError.message}`, "error");
1599
- log(tagError.stack || "No stack trace available", "error");
1600
- }
1601
- } else {
1406
+ if (this.dryRun) {
1602
1407
  log(`[DRY RUN] Would create tag: ${packageTag}`, "info");
1408
+ } else {
1409
+ log(`Version ${nextVersion} prepared (tag: ${packageTag})`, "success");
1603
1410
  }
1604
1411
  updatedPackagesInfo.push({ name, version: nextVersion, path: pkgPath });
1605
1412
  }
@@ -1607,30 +1414,6 @@ var PackageProcessor = class {
1607
1414
  log("No packages required a version update.", "info");
1608
1415
  return { updatedPackages: [], tags };
1609
1416
  }
1610
- const filesToCommit = [];
1611
- for (const info of updatedPackagesInfo) {
1612
- const packageJsonPath = path4.join(info.path, "package.json");
1613
- if (fs5.existsSync(packageJsonPath)) {
1614
- filesToCommit.push(packageJsonPath);
1615
- }
1616
- const cargoEnabled = this.fullConfig.cargo?.enabled !== false;
1617
- if (cargoEnabled) {
1618
- const cargoPaths = this.fullConfig.cargo?.paths;
1619
- if (cargoPaths && cargoPaths.length > 0) {
1620
- for (const cargoPath of cargoPaths) {
1621
- const resolvedCargoPath = path4.resolve(info.path, cargoPath, "Cargo.toml");
1622
- if (fs5.existsSync(resolvedCargoPath)) {
1623
- filesToCommit.push(resolvedCargoPath);
1624
- }
1625
- }
1626
- } else {
1627
- const cargoTomlPath = path4.join(info.path, "Cargo.toml");
1628
- if (fs5.existsSync(cargoTomlPath)) {
1629
- filesToCommit.push(cargoTomlPath);
1630
- }
1631
- }
1632
- }
1633
- }
1634
1417
  const packageNames = updatedPackagesInfo.map((p) => p.name).join(", ");
1635
1418
  const representativeVersion = updatedPackagesInfo[0]?.version || "multiple";
1636
1419
  let commitMessage = this.commitMessageTemplate || "chore(release): publish packages";
@@ -1647,21 +1430,7 @@ var PackageProcessor = class {
1647
1430
  commitMessage = `chore(release): ${packageNames} ${representativeVersion}`;
1648
1431
  }
1649
1432
  setCommitMessage(commitMessage);
1650
- if (!this.dryRun) {
1651
- try {
1652
- await gitAdd(filesToCommit);
1653
- await gitCommit({ message: commitMessage, skipHooks: this.skipHooks });
1654
- log(`Created commit for targeted release: ${packageNames}`, "success");
1655
- } catch (commitError) {
1656
- log("Failed to create commit for targeted release.", "error");
1657
- console.error(commitError);
1658
- exit(1);
1659
- }
1660
- } else {
1661
- log("[DRY RUN] Would add files:", "info");
1662
- for (const file of filesToCommit) {
1663
- log(` - ${file}`, "info");
1664
- }
1433
+ if (this.dryRun) {
1665
1434
  log(`[DRY RUN] Would commit with message: "${commitMessage}"`, "info");
1666
1435
  }
1667
1436
  return {
@@ -1714,7 +1483,6 @@ function createSyncStrategy(config) {
1714
1483
  commitMessage = `chore(release): v\${version}`,
1715
1484
  prereleaseIdentifier,
1716
1485
  dryRun,
1717
- skipHooks,
1718
1486
  mainPackage
1719
1487
  } = config;
1720
1488
  const formattedPrefix = formatVersionPrefix(versionPrefix || "v");
@@ -1864,7 +1632,13 @@ function createSyncStrategy(config) {
1864
1632
  config.packageSpecificTags || false
1865
1633
  );
1866
1634
  const formattedCommitMessage = formatCommitMessage(commitMessage, nextVersion, commitPackageName, void 0);
1867
- await createGitCommitAndTag(files, nextTag, formattedCommitMessage, skipHooks, dryRun);
1635
+ addTag(nextTag);
1636
+ setCommitMessage(formattedCommitMessage);
1637
+ if (!dryRun) {
1638
+ log(`Version ${nextVersion} prepared (tag: ${nextTag})`, "success");
1639
+ } else {
1640
+ log(`Would create tag: ${nextTag}`, "info");
1641
+ }
1868
1642
  } catch (error) {
1869
1643
  if (BaseVersionError.isVersionError(error)) {
1870
1644
  log(`Synced Strategy failed: ${error.message} (${error.code})`, "error");
@@ -1879,14 +1653,7 @@ function createSyncStrategy(config) {
1879
1653
  function createSingleStrategy(config) {
1880
1654
  return async (packages) => {
1881
1655
  try {
1882
- const {
1883
- mainPackage,
1884
- versionPrefix,
1885
- tagTemplate,
1886
- commitMessage = `chore(release): \${version}`,
1887
- dryRun,
1888
- skipHooks
1889
- } = config;
1656
+ const { mainPackage, versionPrefix, tagTemplate, commitMessage = `chore(release): \${version}`, dryRun } = config;
1890
1657
  let packageName;
1891
1658
  if (mainPackage) {
1892
1659
  packageName = mainPackage;
@@ -2006,9 +1773,10 @@ function createSingleStrategy(config) {
2006
1773
  log(`Updated package ${packageName} to version ${nextVersion}`, "success");
2007
1774
  const tagName = formatTag(nextVersion, formattedPrefix, packageName, tagTemplate, config.packageSpecificTags);
2008
1775
  const commitMsg = formatCommitMessage(commitMessage, nextVersion, packageName);
1776
+ addTag(tagName);
1777
+ setCommitMessage(commitMsg);
2009
1778
  if (!dryRun) {
2010
- await createGitCommitAndTag(filesToCommit, tagName, commitMsg, skipHooks, dryRun);
2011
- log(`Created tag: ${tagName}`, "success");
1779
+ log(`Version ${nextVersion} prepared (tag: ${tagName})`, "success");
2012
1780
  } else {
2013
1781
  log(`Would create tag: ${tagName}`, "info");
2014
1782
  }
@@ -2033,7 +1801,6 @@ function createAsyncStrategy(config) {
2033
1801
  tagTemplate: config.tagTemplate,
2034
1802
  commitMessageTemplate: config.commitMessage || "",
2035
1803
  dryRun: config.dryRun || false,
2036
- skipHooks: config.skipHooks || false,
2037
1804
  getLatestTag: dependencies.getLatestTag,
2038
1805
  fullConfig: config,
2039
1806
  // Extract common version configuration properties
@@ -2096,9 +1863,13 @@ function createStrategyMap(config) {
2096
1863
  }
2097
1864
 
2098
1865
  // src/core/versionEngine.ts
2099
- import { cwd as cwd3 } from "process";
1866
+ import { cwd as cwd2 } from "process";
2100
1867
  import { getPackagesSync } from "@manypkg/get-packages";
2101
1868
 
1869
+ // src/errors/gitError.ts
1870
+ var GitError = class extends BaseVersionError {
1871
+ };
1872
+
2102
1873
  // src/utils/packageFiltering.ts
2103
1874
  import path6 from "path";
2104
1875
  import micromatch2 from "micromatch";
@@ -2204,13 +1975,13 @@ var VersionEngine = class {
2204
1975
  if (this.workspaceCache) {
2205
1976
  return this.workspaceCache;
2206
1977
  }
2207
- const pkgsResult = getPackagesSync(cwd3());
1978
+ const pkgsResult = getPackagesSync(cwd2());
2208
1979
  if (!pkgsResult || !pkgsResult.packages) {
2209
1980
  throw createVersionError("PACKAGES_NOT_FOUND" /* PACKAGES_NOT_FOUND */);
2210
1981
  }
2211
1982
  if (!pkgsResult.root) {
2212
1983
  log("Root path is undefined in packages result, setting to current working directory", "warning");
2213
- pkgsResult.root = cwd3();
1984
+ pkgsResult.root = cwd2();
2214
1985
  }
2215
1986
  if (this.config.packages && this.config.packages.length > 0) {
2216
1987
  const originalCount = pkgsResult.packages.length;