@releasekit/version 0.2.0 → 0.3.0-next.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.
@@ -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,
@@ -208,22 +206,6 @@ import semver3 from "semver";
208
206
  // src/git/repository.ts
209
207
  import { existsSync, statSync } from "fs";
210
208
  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
209
  function getCurrentBranch() {
228
210
  const result = execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
229
211
  return result.toString().trim();
@@ -592,13 +574,13 @@ import { parseCargoToml as parseCargoToml2 } from "@releasekit/config";
592
574
  import semver2 from "semver";
593
575
 
594
576
  // src/git/tagVerification.ts
595
- function verifyTag(tagName, cwd4) {
577
+ function verifyTag(tagName, cwd3) {
596
578
  if (!tagName || tagName.trim() === "") {
597
579
  return { exists: false, reachable: false, error: "Empty tag name" };
598
580
  }
599
581
  try {
600
582
  execSync("git", ["rev-parse", "--verify", tagName], {
601
- cwd: cwd4,
583
+ cwd: cwd3,
602
584
  stdio: "ignore"
603
585
  });
604
586
  return { exists: true, reachable: true };
@@ -695,11 +677,11 @@ var VersionMismatchError = class extends Error {
695
677
  this.name = "VersionMismatchError";
696
678
  }
697
679
  };
698
- async function getBestVersionSource(tagName, packageVersion, cwd4, mismatchStrategy = "error", strictReachable = false) {
680
+ async function getBestVersionSource(tagName, packageVersion, cwd3, mismatchStrategy = "error", strictReachable = false) {
699
681
  if (!tagName?.trim()) {
700
682
  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
683
  }
702
- const verification = verifyTag(tagName, cwd4);
684
+ const verification = verifyTag(tagName, cwd3);
703
685
  if (!verification.exists || !verification.reachable) {
704
686
  if (strictReachable) {
705
687
  throw new Error(
@@ -966,7 +948,6 @@ async function calculateVersion(config, options) {
966
948
  // src/package/packageProcessor.ts
967
949
  import * as fs5 from "fs";
968
950
  import path4 from "path";
969
- import { exit } from "process";
970
951
 
971
952
  // src/changelog/commitParser.ts
972
953
  var CONVENTIONAL_COMMIT_REGEX = /^(\w+)(?:\(([^)]+)\))?(!)?: (.+)(?:\n\n([\s\S]*))?/;
@@ -1140,168 +1121,6 @@ function extractIssueIds(body) {
1140
1121
  return issueIds;
1141
1122
  }
1142
1123
 
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
1124
  // src/utils/packageMatching.ts
1306
1125
  import micromatch from "micromatch";
1307
1126
  function matchesPackageTarget(packageName, target) {
@@ -1373,7 +1192,6 @@ var PackageProcessor = class {
1373
1192
  tagTemplate;
1374
1193
  commitMessageTemplate;
1375
1194
  dryRun;
1376
- skipHooks;
1377
1195
  getLatestTag;
1378
1196
  config;
1379
1197
  // Config for version calculation
@@ -1384,7 +1202,6 @@ var PackageProcessor = class {
1384
1202
  this.tagTemplate = options.tagTemplate;
1385
1203
  this.commitMessageTemplate = options.commitMessageTemplate || "";
1386
1204
  this.dryRun = options.dryRun || false;
1387
- this.skipHooks = options.skipHooks || false;
1388
1205
  this.getLatestTag = options.getLatestTag;
1389
1206
  this.config = options.config;
1390
1207
  this.fullConfig = options.fullConfig;
@@ -1587,19 +1404,12 @@ var PackageProcessor = class {
1587
1404
  this.tagTemplate,
1588
1405
  this.fullConfig.packageSpecificTags
1589
1406
  );
1590
- const tagMessage = `chore(release): ${name} ${nextVersion}`;
1591
1407
  addTag(packageTag);
1592
1408
  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 {
1409
+ if (this.dryRun) {
1602
1410
  log(`[DRY RUN] Would create tag: ${packageTag}`, "info");
1411
+ } else {
1412
+ log(`Version ${nextVersion} prepared (tag: ${packageTag})`, "success");
1603
1413
  }
1604
1414
  updatedPackagesInfo.push({ name, version: nextVersion, path: pkgPath });
1605
1415
  }
@@ -1607,30 +1417,6 @@ var PackageProcessor = class {
1607
1417
  log("No packages required a version update.", "info");
1608
1418
  return { updatedPackages: [], tags };
1609
1419
  }
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
1420
  const packageNames = updatedPackagesInfo.map((p) => p.name).join(", ");
1635
1421
  const representativeVersion = updatedPackagesInfo[0]?.version || "multiple";
1636
1422
  let commitMessage = this.commitMessageTemplate || "chore(release): publish packages";
@@ -1647,21 +1433,7 @@ var PackageProcessor = class {
1647
1433
  commitMessage = `chore(release): ${packageNames} ${representativeVersion}`;
1648
1434
  }
1649
1435
  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
- }
1436
+ if (this.dryRun) {
1665
1437
  log(`[DRY RUN] Would commit with message: "${commitMessage}"`, "info");
1666
1438
  }
1667
1439
  return {
@@ -1714,7 +1486,6 @@ function createSyncStrategy(config) {
1714
1486
  commitMessage = `chore(release): v\${version}`,
1715
1487
  prereleaseIdentifier,
1716
1488
  dryRun,
1717
- skipHooks,
1718
1489
  mainPackage
1719
1490
  } = config;
1720
1491
  const formattedPrefix = formatVersionPrefix(versionPrefix || "v");
@@ -1864,7 +1635,13 @@ function createSyncStrategy(config) {
1864
1635
  config.packageSpecificTags || false
1865
1636
  );
1866
1637
  const formattedCommitMessage = formatCommitMessage(commitMessage, nextVersion, commitPackageName, void 0);
1867
- await createGitCommitAndTag(files, nextTag, formattedCommitMessage, skipHooks, dryRun);
1638
+ addTag(nextTag);
1639
+ setCommitMessage(formattedCommitMessage);
1640
+ if (!dryRun) {
1641
+ log(`Version ${nextVersion} prepared (tag: ${nextTag})`, "success");
1642
+ } else {
1643
+ log(`Would create tag: ${nextTag}`, "info");
1644
+ }
1868
1645
  } catch (error) {
1869
1646
  if (BaseVersionError.isVersionError(error)) {
1870
1647
  log(`Synced Strategy failed: ${error.message} (${error.code})`, "error");
@@ -1879,14 +1656,7 @@ function createSyncStrategy(config) {
1879
1656
  function createSingleStrategy(config) {
1880
1657
  return async (packages) => {
1881
1658
  try {
1882
- const {
1883
- mainPackage,
1884
- versionPrefix,
1885
- tagTemplate,
1886
- commitMessage = `chore(release): \${version}`,
1887
- dryRun,
1888
- skipHooks
1889
- } = config;
1659
+ const { mainPackage, versionPrefix, tagTemplate, commitMessage = `chore(release): \${version}`, dryRun } = config;
1890
1660
  let packageName;
1891
1661
  if (mainPackage) {
1892
1662
  packageName = mainPackage;
@@ -2006,9 +1776,10 @@ function createSingleStrategy(config) {
2006
1776
  log(`Updated package ${packageName} to version ${nextVersion}`, "success");
2007
1777
  const tagName = formatTag(nextVersion, formattedPrefix, packageName, tagTemplate, config.packageSpecificTags);
2008
1778
  const commitMsg = formatCommitMessage(commitMessage, nextVersion, packageName);
1779
+ addTag(tagName);
1780
+ setCommitMessage(commitMsg);
2009
1781
  if (!dryRun) {
2010
- await createGitCommitAndTag(filesToCommit, tagName, commitMsg, skipHooks, dryRun);
2011
- log(`Created tag: ${tagName}`, "success");
1782
+ log(`Version ${nextVersion} prepared (tag: ${tagName})`, "success");
2012
1783
  } else {
2013
1784
  log(`Would create tag: ${tagName}`, "info");
2014
1785
  }
@@ -2033,7 +1804,6 @@ function createAsyncStrategy(config) {
2033
1804
  tagTemplate: config.tagTemplate,
2034
1805
  commitMessageTemplate: config.commitMessage || "",
2035
1806
  dryRun: config.dryRun || false,
2036
- skipHooks: config.skipHooks || false,
2037
1807
  getLatestTag: dependencies.getLatestTag,
2038
1808
  fullConfig: config,
2039
1809
  // Extract common version configuration properties
@@ -2096,9 +1866,13 @@ function createStrategyMap(config) {
2096
1866
  }
2097
1867
 
2098
1868
  // src/core/versionEngine.ts
2099
- import { cwd as cwd3 } from "process";
1869
+ import { cwd as cwd2 } from "process";
2100
1870
  import { getPackagesSync } from "@manypkg/get-packages";
2101
1871
 
1872
+ // src/errors/gitError.ts
1873
+ var GitError = class extends BaseVersionError {
1874
+ };
1875
+
2102
1876
  // src/utils/packageFiltering.ts
2103
1877
  import path6 from "path";
2104
1878
  import micromatch2 from "micromatch";
@@ -2204,13 +1978,13 @@ var VersionEngine = class {
2204
1978
  if (this.workspaceCache) {
2205
1979
  return this.workspaceCache;
2206
1980
  }
2207
- const pkgsResult = getPackagesSync(cwd3());
1981
+ const pkgsResult = getPackagesSync(cwd2());
2208
1982
  if (!pkgsResult || !pkgsResult.packages) {
2209
1983
  throw createVersionError("PACKAGES_NOT_FOUND" /* PACKAGES_NOT_FOUND */);
2210
1984
  }
2211
1985
  if (!pkgsResult.root) {
2212
1986
  log("Root path is undefined in packages result, setting to current working directory", "warning");
2213
- pkgsResult.root = cwd3();
1987
+ pkgsResult.root = cwd2();
2214
1988
  }
2215
1989
  if (this.config.packages && this.config.packages.length > 0) {
2216
1990
  const originalCount = pkgsResult.packages.length;