package-versioner 0.5.2 → 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
 
@@ -334,7 +351,7 @@ function formatTag(version, versionPrefix, packageName, tagTemplate = "${prefix}
334
351
  const template = packageName ? packageTagTemplate : tagTemplate;
335
352
  return createTemplateString(template, variables);
336
353
  }
337
- function formatTagPrefix(versionPrefix, scope) {
354
+ function formatVersionPrefix(versionPrefix, scope) {
338
355
  if (!versionPrefix) return "";
339
356
  const cleanPrefix = versionPrefix.replace(/\/$/, "");
340
357
  if (scope) {
@@ -395,13 +412,55 @@ async function lastMergeBranchName(branches, baseBranch) {
395
412
  return null;
396
413
  }
397
414
  }
398
- async function getLatestTagForPackage(packageName, tagPrefix) {
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
- tagPrefix
423
+ tagPrefix: versionPrefix
402
424
  });
403
- const packageTagPattern = tagPrefix ? new RegExp(`^${escapeRegExp(tagPrefix)}${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
 
@@ -446,11 +506,11 @@ var import_node_process3 = require("process");
446
506
  var import_conventional_recommended_bump = require("conventional-recommended-bump");
447
507
  var import_semver = __toESM(require("semver"), 1);
448
508
  var STANDARD_BUMP_TYPES = ["major", "minor", "patch"];
449
- async function calculateVersion(config, options, forcedType, configPrereleaseIdentifier) {
509
+ async function calculateVersion(config, options) {
450
510
  const { latestTag, type, path: pkgPath, name, branchPattern } = options;
451
511
  const { preset } = config;
452
- const tagPrefix = options.versionPrefix || config.versionPrefix || "v";
453
- const prereleaseIdentifier = options.prereleaseIdentifier || configPrereleaseIdentifier;
512
+ const originalPrefix = options.versionPrefix || "";
513
+ const prereleaseIdentifier = options.prereleaseIdentifier || config.prereleaseIdentifier;
454
514
  const initialVersion = prereleaseIdentifier ? `0.0.1-${prereleaseIdentifier}` : "0.0.1";
455
515
  const hasNoTags = !latestTag || latestTag === "";
456
516
  function determineTagSearchPattern(packageName, prefix) {
@@ -459,9 +519,9 @@ async function calculateVersion(config, options, forcedType, configPrereleaseIde
459
519
  }
460
520
  return prefix;
461
521
  }
462
- const tagSearchPattern = determineTagSearchPattern(name, tagPrefix);
522
+ const tagSearchPattern = determineTagSearchPattern(name, originalPrefix);
463
523
  const escapedTagPattern = escapeRegExp(tagSearchPattern);
464
- const specifiedType = forcedType || type;
524
+ const specifiedType = type;
465
525
  if (specifiedType) {
466
526
  if (hasNoTags) {
467
527
  return getPackageVersionFallback(
@@ -681,7 +741,7 @@ var PackageProcessor = class {
681
741
  for (const pkg of pkgsToConsider) {
682
742
  const name = pkg.packageJson.name;
683
743
  const pkgPath = pkg.dir;
684
- const formattedPrefix = formatTagPrefix(this.versionPrefix);
744
+ const formattedPrefix = formatVersionPrefix(this.versionPrefix);
685
745
  let latestTagResult = "";
686
746
  try {
687
747
  latestTagResult = await getLatestTagForPackage(name, this.versionPrefix);
@@ -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;
@@ -713,7 +797,7 @@ var PackageProcessor = class {
713
797
  branchPattern: this.config.branchPattern,
714
798
  baseBranch: this.config.baseBranch,
715
799
  prereleaseIdentifier: this.config.prereleaseIdentifier,
716
- type: this.config.forceType
800
+ type: this.config.type
717
801
  });
718
802
  if (!nextVersion) {
719
803
  continue;
@@ -809,14 +893,15 @@ function createSyncedStrategy(config) {
809
893
  dryRun,
810
894
  skipHooks
811
895
  } = config;
812
- const formattedPrefix = formatTagPrefix(versionPrefix || "v");
896
+ const formattedPrefix = formatVersionPrefix(versionPrefix || "v");
813
897
  const latestTag = await getLatestTag();
814
898
  const nextVersion = await calculateVersion(config, {
815
899
  latestTag,
816
900
  versionPrefix: formattedPrefix,
817
901
  branchPattern,
818
902
  baseBranch,
819
- prereleaseIdentifier
903
+ prereleaseIdentifier,
904
+ type: config.type
820
905
  });
821
906
  if (!nextVersion) {
822
907
  log("No version change needed", "info");
@@ -887,7 +972,7 @@ function createSingleStrategy(config) {
887
972
  throw createVersionError("PACKAGE_NOT_FOUND" /* PACKAGE_NOT_FOUND */, packageName);
888
973
  }
889
974
  const pkgPath = pkg.dir;
890
- const formattedPrefix = formatTagPrefix(versionPrefix || "v");
975
+ const formattedPrefix = formatVersionPrefix(versionPrefix || "v");
891
976
  let latestTagResult = await getLatestTagForPackage(packageName, formattedPrefix);
892
977
  if (!latestTagResult) {
893
978
  const globalTagResult = await getLatestTag();
@@ -900,7 +985,8 @@ function createSingleStrategy(config) {
900
985
  latestTag,
901
986
  versionPrefix: formattedPrefix,
902
987
  path: pkgPath,
903
- name: packageName
988
+ name: packageName,
989
+ type: config.type
904
990
  });
905
991
  } catch (error) {
906
992
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -957,11 +1043,12 @@ function createAsyncStrategy(config) {
957
1043
  skipHooks: config.skipHooks || false,
958
1044
  getLatestTag: dependencies.getLatestTag,
959
1045
  fullConfig: config,
1046
+ // Extract common version configuration properties
960
1047
  config: {
961
1048
  branchPattern: config.branchPattern || [],
962
1049
  baseBranch: config.baseBranch || "main",
963
1050
  prereleaseIdentifier: config.prereleaseIdentifier,
964
- forceType: config.forceType
1051
+ type: config.type
965
1052
  }
966
1053
  };
967
1054
  const packageProcessor = new PackageProcessor(processorOptions);
@@ -1085,14 +1172,32 @@ var VersionEngine = class {
1085
1172
  };
1086
1173
 
1087
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
+ }
1088
1190
  async function run() {
1191
+ const buildTimestamp = (/* @__PURE__ */ new Date()).toISOString();
1192
+ const packageVersion = getPackageVersion();
1193
+ log(`package-versioner v${packageVersion} (Build: ${buildTimestamp})`, "debug");
1089
1194
  const program = new import_commander.Command();
1090
1195
  program.name("package-versioner").description(
1091
1196
  "A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits."
1092
- ).version(process.env.npm_package_version || "0.0.0").option(
1197
+ ).version(packageVersion).option(
1093
1198
  "-c, --config <path>",
1094
1199
  "Path to config file (defaults to version.config.json in current directory)"
1095
- ).option("-d, --dry-run", "Dry run (no changes made)", false).option("-b, --bump <type>", "Force specific bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --synced", "Force 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);
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);
1096
1201
  const options = program.opts();
1097
1202
  if (options.json) {
1098
1203
  enableJsonOutput(options.dryRun);
@@ -1102,7 +1207,7 @@ async function run() {
1102
1207
  log(`Loaded configuration from ${options.config || "version.config.json"}`, "info");
1103
1208
  if (options.dryRun) config.dryRun = true;
1104
1209
  if (options.synced) config.synced = true;
1105
- if (options.bump) config.forceType = options.bump;
1210
+ if (options.bump) config.type = options.bump;
1106
1211
  if (options.prerelease)
1107
1212
  config.prereleaseIdentifier = options.prerelease === true ? "rc" : options.prerelease;
1108
1213
  const cliTargets = options.target ? options.target.split(",").map((t) => t.trim()) : [];
@@ -1137,3 +1242,7 @@ run().catch((error) => {
1137
1242
  console.error("Fatal error:", error);
1138
1243
  process.exit(1);
1139
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
@@ -311,7 +318,7 @@ function formatTag(version, versionPrefix, packageName, tagTemplate = "${prefix}
311
318
  const template = packageName ? packageTagTemplate : tagTemplate;
312
319
  return createTemplateString(template, variables);
313
320
  }
314
- function formatTagPrefix(versionPrefix, scope) {
321
+ function formatVersionPrefix(versionPrefix, scope) {
315
322
  if (!versionPrefix) return "";
316
323
  const cleanPrefix = versionPrefix.replace(/\/$/, "");
317
324
  if (scope) {
@@ -372,13 +379,55 @@ async function lastMergeBranchName(branches, baseBranch) {
372
379
  return null;
373
380
  }
374
381
  }
375
- async function getLatestTagForPackage(packageName, tagPrefix) {
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
- tagPrefix
390
+ tagPrefix: versionPrefix
379
391
  });
380
- const packageTagPattern = tagPrefix ? new RegExp(`^${escapeRegExp(tagPrefix)}${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
 
@@ -422,11 +472,11 @@ import { cwd as cwd3 } from "node:process";
422
472
  import { Bumper } from "conventional-recommended-bump";
423
473
  import semver from "semver";
424
474
  var STANDARD_BUMP_TYPES = ["major", "minor", "patch"];
425
- async function calculateVersion(config, options, forcedType, configPrereleaseIdentifier) {
475
+ async function calculateVersion(config, options) {
426
476
  const { latestTag, type, path: pkgPath, name, branchPattern } = options;
427
477
  const { preset } = config;
428
- const tagPrefix = options.versionPrefix || config.versionPrefix || "v";
429
- const prereleaseIdentifier = options.prereleaseIdentifier || configPrereleaseIdentifier;
478
+ const originalPrefix = options.versionPrefix || "";
479
+ const prereleaseIdentifier = options.prereleaseIdentifier || config.prereleaseIdentifier;
430
480
  const initialVersion = prereleaseIdentifier ? `0.0.1-${prereleaseIdentifier}` : "0.0.1";
431
481
  const hasNoTags = !latestTag || latestTag === "";
432
482
  function determineTagSearchPattern(packageName, prefix) {
@@ -435,9 +485,9 @@ async function calculateVersion(config, options, forcedType, configPrereleaseIde
435
485
  }
436
486
  return prefix;
437
487
  }
438
- const tagSearchPattern = determineTagSearchPattern(name, tagPrefix);
488
+ const tagSearchPattern = determineTagSearchPattern(name, originalPrefix);
439
489
  const escapedTagPattern = escapeRegExp(tagSearchPattern);
440
- const specifiedType = forcedType || type;
490
+ const specifiedType = type;
441
491
  if (specifiedType) {
442
492
  if (hasNoTags) {
443
493
  return getPackageVersionFallback(
@@ -657,7 +707,7 @@ var PackageProcessor = class {
657
707
  for (const pkg of pkgsToConsider) {
658
708
  const name = pkg.packageJson.name;
659
709
  const pkgPath = pkg.dir;
660
- const formattedPrefix = formatTagPrefix(this.versionPrefix);
710
+ const formattedPrefix = formatVersionPrefix(this.versionPrefix);
661
711
  let latestTagResult = "";
662
712
  try {
663
713
  latestTagResult = await getLatestTagForPackage(name, this.versionPrefix);
@@ -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;
@@ -689,7 +763,7 @@ var PackageProcessor = class {
689
763
  branchPattern: this.config.branchPattern,
690
764
  baseBranch: this.config.baseBranch,
691
765
  prereleaseIdentifier: this.config.prereleaseIdentifier,
692
- type: this.config.forceType
766
+ type: this.config.type
693
767
  });
694
768
  if (!nextVersion) {
695
769
  continue;
@@ -785,14 +859,15 @@ function createSyncedStrategy(config) {
785
859
  dryRun,
786
860
  skipHooks
787
861
  } = config;
788
- const formattedPrefix = formatTagPrefix(versionPrefix || "v");
862
+ const formattedPrefix = formatVersionPrefix(versionPrefix || "v");
789
863
  const latestTag = await getLatestTag();
790
864
  const nextVersion = await calculateVersion(config, {
791
865
  latestTag,
792
866
  versionPrefix: formattedPrefix,
793
867
  branchPattern,
794
868
  baseBranch,
795
- prereleaseIdentifier
869
+ prereleaseIdentifier,
870
+ type: config.type
796
871
  });
797
872
  if (!nextVersion) {
798
873
  log("No version change needed", "info");
@@ -802,7 +877,7 @@ function createSyncedStrategy(config) {
802
877
  const updatedPackages = [];
803
878
  try {
804
879
  const rootPkgPath = path3.join(packages.root, "package.json");
805
- if (fs4.existsSync(rootPkgPath)) {
880
+ if (fs5.existsSync(rootPkgPath)) {
806
881
  updatePackageVersion(rootPkgPath, nextVersion);
807
882
  files.push(rootPkgPath);
808
883
  updatedPackages.push("root");
@@ -863,7 +938,7 @@ function createSingleStrategy(config) {
863
938
  throw createVersionError("PACKAGE_NOT_FOUND" /* PACKAGE_NOT_FOUND */, packageName);
864
939
  }
865
940
  const pkgPath = pkg.dir;
866
- const formattedPrefix = formatTagPrefix(versionPrefix || "v");
941
+ const formattedPrefix = formatVersionPrefix(versionPrefix || "v");
867
942
  let latestTagResult = await getLatestTagForPackage(packageName, formattedPrefix);
868
943
  if (!latestTagResult) {
869
944
  const globalTagResult = await getLatestTag();
@@ -876,7 +951,8 @@ function createSingleStrategy(config) {
876
951
  latestTag,
877
952
  versionPrefix: formattedPrefix,
878
953
  path: pkgPath,
879
- name: packageName
954
+ name: packageName,
955
+ type: config.type
880
956
  });
881
957
  } catch (error) {
882
958
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -933,11 +1009,12 @@ function createAsyncStrategy(config) {
933
1009
  skipHooks: config.skipHooks || false,
934
1010
  getLatestTag: dependencies.getLatestTag,
935
1011
  fullConfig: config,
1012
+ // Extract common version configuration properties
936
1013
  config: {
937
1014
  branchPattern: config.branchPattern || [],
938
1015
  baseBranch: config.baseBranch || "main",
939
1016
  prereleaseIdentifier: config.prereleaseIdentifier,
940
- forceType: config.forceType
1017
+ type: config.type
941
1018
  }
942
1019
  };
943
1020
  const packageProcessor = new PackageProcessor(processorOptions);
@@ -1061,14 +1138,31 @@ var VersionEngine = class {
1061
1138
  };
1062
1139
 
1063
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
+ }
1064
1155
  async function run() {
1156
+ const buildTimestamp = (/* @__PURE__ */ new Date()).toISOString();
1157
+ const packageVersion = getPackageVersion();
1158
+ log(`package-versioner v${packageVersion} (Build: ${buildTimestamp})`, "debug");
1065
1159
  const program = new Command();
1066
1160
  program.name("package-versioner").description(
1067
1161
  "A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits."
1068
- ).version(process.env.npm_package_version || "0.0.0").option(
1162
+ ).version(packageVersion).option(
1069
1163
  "-c, --config <path>",
1070
1164
  "Path to config file (defaults to version.config.json in current directory)"
1071
- ).option("-d, --dry-run", "Dry run (no changes made)", false).option("-b, --bump <type>", "Force specific bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --synced", "Force 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);
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);
1072
1166
  const options = program.opts();
1073
1167
  if (options.json) {
1074
1168
  enableJsonOutput(options.dryRun);
@@ -1078,7 +1172,7 @@ async function run() {
1078
1172
  log(`Loaded configuration from ${options.config || "version.config.json"}`, "info");
1079
1173
  if (options.dryRun) config.dryRun = true;
1080
1174
  if (options.synced) config.synced = true;
1081
- if (options.bump) config.forceType = options.bump;
1175
+ if (options.bump) config.type = options.bump;
1082
1176
  if (options.prerelease)
1083
1177
  config.prereleaseIdentifier = options.prerelease === true ? "rc" : options.prerelease;
1084
1178
  const cliTargets = options.target ? options.target.split(",").map((t) => t.trim()) : [];
@@ -1113,3 +1207,6 @@ run().catch((error) => {
1113
1207
  console.error("Fatal error:", error);
1114
1208
  process.exit(1);
1115
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.2",
4
+ "version": "0.5.4",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",