package-versioner 0.5.3 → 0.5.4

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.
package/dist/index.cjs CHANGED
@@ -6,6 +6,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
9
13
  var __copyProps = (to, from, except, desc) => {
10
14
  if (from && typeof from === "object" || typeof from === "function") {
11
15
  for (let key of __getOwnPropNames(from))
@@ -22,8 +26,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
26
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
27
  mod
24
28
  ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
30
 
26
31
  // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ run: () => run
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var fs6 = __toESM(require("fs"), 1);
38
+ var import_node_path4 = __toESM(require("path"), 1);
27
39
  var import_commander = require("commander");
28
40
 
29
41
  // src/config.ts
@@ -140,9 +152,13 @@ function printJsonOutput() {
140
152
  }
141
153
 
142
154
  // src/utils/logging.ts
143
- function log(message, status = "info") {
155
+ function log(message, level = "info") {
156
+ const showDebug = process.env.DEBUG === "true" || process.env.DEBUG === "1";
157
+ if (level === "debug" && !showDebug) {
158
+ return;
159
+ }
144
160
  let chalkFn;
145
- switch (status) {
161
+ switch (level) {
146
162
  case "success":
147
163
  chalkFn = import_chalk.default.green;
148
164
  break;
@@ -159,16 +175,17 @@ function log(message, status = "info") {
159
175
  chalkFn = import_chalk.default.blue;
160
176
  }
161
177
  if (isJsonOutputMode()) {
162
- if (status === "error") {
178
+ if (level === "error") {
163
179
  chalkFn(message);
164
180
  console.error(message);
165
181
  }
166
182
  return;
167
183
  }
168
- if (status === "error") {
169
- console.error(chalkFn(message));
184
+ const formattedMessage = level === "debug" ? `[DEBUG] ${message}` : message;
185
+ if (level === "error") {
186
+ console.error(chalkFn(formattedMessage));
170
187
  } else {
171
- console.log(chalkFn(message));
188
+ console.log(chalkFn(formattedMessage));
172
189
  }
173
190
  }
174
191
 
@@ -397,11 +414,53 @@ async function lastMergeBranchName(branches, baseBranch) {
397
414
  }
398
415
  async function getLatestTagForPackage(packageName, versionPrefix) {
399
416
  try {
417
+ const escapedPackageName = escapeRegExp(packageName);
418
+ log(
419
+ `Looking for tags for package ${packageName} with prefix ${versionPrefix || "none"}`,
420
+ "debug"
421
+ );
400
422
  const allTags = await (0, import_git_semver_tags.getSemverTags)({
401
423
  tagPrefix: versionPrefix
402
424
  });
403
- const packageTagPattern = versionPrefix ? new RegExp(`^${escapeRegExp(versionPrefix)}${escapeRegExp(packageName)}@`) : new RegExp(`^${escapeRegExp(packageName)}@`);
404
- const packageTags = allTags.filter((tag) => packageTagPattern.test(tag));
425
+ log(`Retrieved ${allTags.length} tags: ${allTags.join(", ")}`, "debug");
426
+ let packageTags = [];
427
+ if (versionPrefix) {
428
+ const pattern1 = new RegExp(`^${escapedPackageName}@${escapeRegExp(versionPrefix)}`);
429
+ packageTags = allTags.filter((tag) => pattern1.test(tag));
430
+ if (packageTags.length > 0) {
431
+ log(
432
+ `Found ${packageTags.length} package tags using pattern: packageName@${versionPrefix}...`,
433
+ "debug"
434
+ );
435
+ log(`Using tag: ${packageTags[0]}`, "debug");
436
+ return packageTags[0];
437
+ }
438
+ }
439
+ if (versionPrefix) {
440
+ const pattern2 = new RegExp(`^${escapeRegExp(versionPrefix)}${escapedPackageName}@`);
441
+ packageTags = allTags.filter((tag) => pattern2.test(tag));
442
+ if (packageTags.length > 0) {
443
+ log(
444
+ `Found ${packageTags.length} package tags using pattern: ${versionPrefix}packageName@...`,
445
+ "debug"
446
+ );
447
+ log(`Using tag: ${packageTags[0]}`, "debug");
448
+ return packageTags[0];
449
+ }
450
+ }
451
+ const pattern3 = new RegExp(`^${escapedPackageName}@`);
452
+ packageTags = allTags.filter((tag) => pattern3.test(tag));
453
+ log(`Found ${packageTags.length} package tags for ${packageName}`, "debug");
454
+ if (packageTags.length === 0) {
455
+ log("No matching tags found for pattern: packageName@version", "debug");
456
+ if (allTags.length > 0) {
457
+ log(`Available tags: ${allTags.join(", ")}`, "debug");
458
+ } else {
459
+ log("No tags available in the repository", "debug");
460
+ }
461
+ } else {
462
+ log(`Using tag: ${packageTags[0]}`, "debug");
463
+ }
405
464
  return packageTags[0] || "";
406
465
  } catch (error) {
407
466
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -436,6 +495,7 @@ function updatePackageVersion(packagePath, version) {
436
495
  }
437
496
 
438
497
  // src/package/packageProcessor.ts
498
+ var fs4 = __toESM(require("fs"), 1);
439
499
  var import_node_path3 = __toESM(require("path"), 1);
440
500
  var import_node_process4 = require("process");
441
501
 
@@ -694,14 +754,38 @@ var PackageProcessor = class {
694
754
  }
695
755
  if (!latestTagResult) {
696
756
  try {
697
- const globalTagResult = await this.getLatestTag();
698
- latestTagResult = globalTagResult || "";
699
- if (globalTagResult) {
700
- log(`Using global tag ${globalTagResult} as fallback for package ${name}`, "info");
757
+ const packageJsonPath = import_node_path3.default.join(pkgPath, "package.json");
758
+ let usedPackageJsonFallback = false;
759
+ if (fs4.existsSync(packageJsonPath)) {
760
+ try {
761
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
762
+ if (packageJson.version) {
763
+ log(
764
+ `Using package.json version ${packageJson.version} for ${name} as no package-specific tags found`,
765
+ "info"
766
+ );
767
+ log(
768
+ "FALLBACK: Using package version from package.json instead of global tag",
769
+ "debug"
770
+ );
771
+ latestTagResult = `${this.versionPrefix || ""}${packageJson.version}`;
772
+ usedPackageJsonFallback = true;
773
+ }
774
+ } catch (packageJsonError) {
775
+ const errMsg = packageJsonError instanceof Error ? packageJsonError.message : String(packageJsonError);
776
+ log(`Error reading package.json for ${name}: ${errMsg}`, "warning");
777
+ }
778
+ }
779
+ if (!usedPackageJsonFallback) {
780
+ const globalTagResult = await this.getLatestTag();
781
+ if (globalTagResult) {
782
+ latestTagResult = globalTagResult;
783
+ log(`Using global tag ${globalTagResult} as fallback for package ${name}`, "info");
784
+ }
701
785
  }
702
786
  } catch (error) {
703
787
  const errorMessage = error instanceof Error ? error.message : String(error);
704
- log(`Error getting global tag, using empty tag value: ${errorMessage}`, "warning");
788
+ log(`Error getting fallback version, using empty tag value: ${errorMessage}`, "warning");
705
789
  }
706
790
  }
707
791
  const latestTag = latestTagResult;
@@ -1088,11 +1172,29 @@ var VersionEngine = class {
1088
1172
  };
1089
1173
 
1090
1174
  // src/index.ts
1175
+ var import_meta = {};
1176
+ function getPackageVersion() {
1177
+ try {
1178
+ const packageJsonPath = import_node_path4.default.resolve(
1179
+ import_node_path4.default.dirname(import_meta.url.replace("file:", "")),
1180
+ "../package.json"
1181
+ );
1182
+ const packageJsonContent = fs6.readFileSync(packageJsonPath, "utf-8");
1183
+ const packageJson = JSON.parse(packageJsonContent);
1184
+ return packageJson.version || "0.0.0";
1185
+ } catch (error) {
1186
+ console.error("Failed to read package version:", error);
1187
+ return "0.0.0";
1188
+ }
1189
+ }
1091
1190
  async function run() {
1191
+ const buildTimestamp = (/* @__PURE__ */ new Date()).toISOString();
1192
+ const packageVersion = getPackageVersion();
1193
+ log(`package-versioner v${packageVersion} (Build: ${buildTimestamp})`, "debug");
1092
1194
  const program = new import_commander.Command();
1093
1195
  program.name("package-versioner").description(
1094
1196
  "A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits."
1095
- ).version(process.env.npm_package_version || "0.0.0").option(
1197
+ ).version(packageVersion).option(
1096
1198
  "-c, --config <path>",
1097
1199
  "Path to config file (defaults to version.config.json in current directory)"
1098
1200
  ).option("-d, --dry-run", "Dry run (no changes made)", false).option("-b, --bump <type>", "Specify bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --synced", "Use synchronized versioning across all packages").option("-j, --json", "Output results as JSON", false).option("-t, --target <packages>", "Comma-delimited list of package names to target").parse(process.argv);
@@ -1140,3 +1242,7 @@ run().catch((error) => {
1140
1242
  console.error("Fatal error:", error);
1141
1243
  process.exit(1);
1142
1244
  });
1245
+ // Annotate the CommonJS export names for ESM import in node:
1246
+ 0 && (module.exports = {
1247
+ run
1248
+ });
package/dist/index.d.cts CHANGED
@@ -1 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * Main execution function for package-versioner
4
+ */
5
+ declare function run(): Promise<void>;
6
+
7
+ export { run };
package/dist/index.d.ts CHANGED
@@ -1 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * Main execution function for package-versioner
4
+ */
5
+ declare function run(): Promise<void>;
6
+
7
+ export { run };
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
+ import * as fs6 from "node:fs";
5
+ import path4 from "node:path";
4
6
  import { Command } from "commander";
5
7
 
6
8
  // src/config.ts
@@ -117,9 +119,13 @@ function printJsonOutput() {
117
119
  }
118
120
 
119
121
  // src/utils/logging.ts
120
- function log(message, status = "info") {
122
+ function log(message, level = "info") {
123
+ const showDebug = process.env.DEBUG === "true" || process.env.DEBUG === "1";
124
+ if (level === "debug" && !showDebug) {
125
+ return;
126
+ }
121
127
  let chalkFn;
122
- switch (status) {
128
+ switch (level) {
123
129
  case "success":
124
130
  chalkFn = chalk.green;
125
131
  break;
@@ -136,21 +142,22 @@ function log(message, status = "info") {
136
142
  chalkFn = chalk.blue;
137
143
  }
138
144
  if (isJsonOutputMode()) {
139
- if (status === "error") {
145
+ if (level === "error") {
140
146
  chalkFn(message);
141
147
  console.error(message);
142
148
  }
143
149
  return;
144
150
  }
145
- if (status === "error") {
146
- console.error(chalkFn(message));
151
+ const formattedMessage = level === "debug" ? `[DEBUG] ${message}` : message;
152
+ if (level === "error") {
153
+ console.error(chalkFn(formattedMessage));
147
154
  } else {
148
- console.log(chalkFn(message));
155
+ console.log(chalkFn(formattedMessage));
149
156
  }
150
157
  }
151
158
 
152
159
  // src/core/versionStrategies.ts
153
- import fs4 from "node:fs";
160
+ import fs5 from "node:fs";
154
161
  import * as path3 from "node:path";
155
162
 
156
163
  // src/git/commands.ts
@@ -374,11 +381,53 @@ async function lastMergeBranchName(branches, baseBranch) {
374
381
  }
375
382
  async function getLatestTagForPackage(packageName, versionPrefix) {
376
383
  try {
384
+ const escapedPackageName = escapeRegExp(packageName);
385
+ log(
386
+ `Looking for tags for package ${packageName} with prefix ${versionPrefix || "none"}`,
387
+ "debug"
388
+ );
377
389
  const allTags = await getSemverTags({
378
390
  tagPrefix: versionPrefix
379
391
  });
380
- const packageTagPattern = versionPrefix ? new RegExp(`^${escapeRegExp(versionPrefix)}${escapeRegExp(packageName)}@`) : new RegExp(`^${escapeRegExp(packageName)}@`);
381
- const packageTags = allTags.filter((tag) => packageTagPattern.test(tag));
392
+ log(`Retrieved ${allTags.length} tags: ${allTags.join(", ")}`, "debug");
393
+ let packageTags = [];
394
+ if (versionPrefix) {
395
+ const pattern1 = new RegExp(`^${escapedPackageName}@${escapeRegExp(versionPrefix)}`);
396
+ packageTags = allTags.filter((tag) => pattern1.test(tag));
397
+ if (packageTags.length > 0) {
398
+ log(
399
+ `Found ${packageTags.length} package tags using pattern: packageName@${versionPrefix}...`,
400
+ "debug"
401
+ );
402
+ log(`Using tag: ${packageTags[0]}`, "debug");
403
+ return packageTags[0];
404
+ }
405
+ }
406
+ if (versionPrefix) {
407
+ const pattern2 = new RegExp(`^${escapeRegExp(versionPrefix)}${escapedPackageName}@`);
408
+ packageTags = allTags.filter((tag) => pattern2.test(tag));
409
+ if (packageTags.length > 0) {
410
+ log(
411
+ `Found ${packageTags.length} package tags using pattern: ${versionPrefix}packageName@...`,
412
+ "debug"
413
+ );
414
+ log(`Using tag: ${packageTags[0]}`, "debug");
415
+ return packageTags[0];
416
+ }
417
+ }
418
+ const pattern3 = new RegExp(`^${escapedPackageName}@`);
419
+ packageTags = allTags.filter((tag) => pattern3.test(tag));
420
+ log(`Found ${packageTags.length} package tags for ${packageName}`, "debug");
421
+ if (packageTags.length === 0) {
422
+ log("No matching tags found for pattern: packageName@version", "debug");
423
+ if (allTags.length > 0) {
424
+ log(`Available tags: ${allTags.join(", ")}`, "debug");
425
+ } else {
426
+ log("No tags available in the repository", "debug");
427
+ }
428
+ } else {
429
+ log(`Using tag: ${packageTags[0]}`, "debug");
430
+ }
382
431
  return packageTags[0] || "";
383
432
  } catch (error) {
384
433
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -412,6 +461,7 @@ function updatePackageVersion(packagePath, version) {
412
461
  }
413
462
 
414
463
  // src/package/packageProcessor.ts
464
+ import * as fs4 from "node:fs";
415
465
  import path2 from "node:path";
416
466
  import { exit } from "node:process";
417
467
 
@@ -670,14 +720,38 @@ var PackageProcessor = class {
670
720
  }
671
721
  if (!latestTagResult) {
672
722
  try {
673
- const globalTagResult = await this.getLatestTag();
674
- latestTagResult = globalTagResult || "";
675
- if (globalTagResult) {
676
- log(`Using global tag ${globalTagResult} as fallback for package ${name}`, "info");
723
+ const packageJsonPath = path2.join(pkgPath, "package.json");
724
+ let usedPackageJsonFallback = false;
725
+ if (fs4.existsSync(packageJsonPath)) {
726
+ try {
727
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
728
+ if (packageJson.version) {
729
+ log(
730
+ `Using package.json version ${packageJson.version} for ${name} as no package-specific tags found`,
731
+ "info"
732
+ );
733
+ log(
734
+ "FALLBACK: Using package version from package.json instead of global tag",
735
+ "debug"
736
+ );
737
+ latestTagResult = `${this.versionPrefix || ""}${packageJson.version}`;
738
+ usedPackageJsonFallback = true;
739
+ }
740
+ } catch (packageJsonError) {
741
+ const errMsg = packageJsonError instanceof Error ? packageJsonError.message : String(packageJsonError);
742
+ log(`Error reading package.json for ${name}: ${errMsg}`, "warning");
743
+ }
744
+ }
745
+ if (!usedPackageJsonFallback) {
746
+ const globalTagResult = await this.getLatestTag();
747
+ if (globalTagResult) {
748
+ latestTagResult = globalTagResult;
749
+ log(`Using global tag ${globalTagResult} as fallback for package ${name}`, "info");
750
+ }
677
751
  }
678
752
  } catch (error) {
679
753
  const errorMessage = error instanceof Error ? error.message : String(error);
680
- log(`Error getting global tag, using empty tag value: ${errorMessage}`, "warning");
754
+ log(`Error getting fallback version, using empty tag value: ${errorMessage}`, "warning");
681
755
  }
682
756
  }
683
757
  const latestTag = latestTagResult;
@@ -803,7 +877,7 @@ function createSyncedStrategy(config) {
803
877
  const updatedPackages = [];
804
878
  try {
805
879
  const rootPkgPath = path3.join(packages.root, "package.json");
806
- if (fs4.existsSync(rootPkgPath)) {
880
+ if (fs5.existsSync(rootPkgPath)) {
807
881
  updatePackageVersion(rootPkgPath, nextVersion);
808
882
  files.push(rootPkgPath);
809
883
  updatedPackages.push("root");
@@ -1064,11 +1138,28 @@ var VersionEngine = class {
1064
1138
  };
1065
1139
 
1066
1140
  // src/index.ts
1141
+ function getPackageVersion() {
1142
+ try {
1143
+ const packageJsonPath = path4.resolve(
1144
+ path4.dirname(import.meta.url.replace("file:", "")),
1145
+ "../package.json"
1146
+ );
1147
+ const packageJsonContent = fs6.readFileSync(packageJsonPath, "utf-8");
1148
+ const packageJson = JSON.parse(packageJsonContent);
1149
+ return packageJson.version || "0.0.0";
1150
+ } catch (error) {
1151
+ console.error("Failed to read package version:", error);
1152
+ return "0.0.0";
1153
+ }
1154
+ }
1067
1155
  async function run() {
1156
+ const buildTimestamp = (/* @__PURE__ */ new Date()).toISOString();
1157
+ const packageVersion = getPackageVersion();
1158
+ log(`package-versioner v${packageVersion} (Build: ${buildTimestamp})`, "debug");
1068
1159
  const program = new Command();
1069
1160
  program.name("package-versioner").description(
1070
1161
  "A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits."
1071
- ).version(process.env.npm_package_version || "0.0.0").option(
1162
+ ).version(packageVersion).option(
1072
1163
  "-c, --config <path>",
1073
1164
  "Path to config file (defaults to version.config.json in current directory)"
1074
1165
  ).option("-d, --dry-run", "Dry run (no changes made)", false).option("-b, --bump <type>", "Specify bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --synced", "Use synchronized versioning across all packages").option("-j, --json", "Output results as JSON", false).option("-t, --target <packages>", "Comma-delimited list of package names to target").parse(process.argv);
@@ -1116,3 +1207,6 @@ run().catch((error) => {
1116
1207
  console.error("Fatal error:", error);
1117
1208
  process.exit(1);
1118
1209
  });
1210
+ export {
1211
+ run
1212
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "package-versioner",
3
3
  "description": "A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits.",
4
- "version": "0.5.3",
4
+ "version": "0.5.4",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",