package-versioner 0.5.3 → 0.6.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.
- package/README.md +20 -2
- package/dist/index.cjs +410 -156
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +397 -156
- package/docs/VERSIONING_STRATEGIES.md +30 -1
- package/package.json +10 -8
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 fs8 = __toESM(require("fs"), 1);
|
|
38
|
+
var import_node_path6 = __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,
|
|
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 (
|
|
161
|
+
switch (level) {
|
|
146
162
|
case "success":
|
|
147
163
|
chalkFn = import_chalk.default.green;
|
|
148
164
|
break;
|
|
@@ -159,22 +175,23 @@ function log(message, status = "info") {
|
|
|
159
175
|
chalkFn = import_chalk.default.blue;
|
|
160
176
|
}
|
|
161
177
|
if (isJsonOutputMode()) {
|
|
162
|
-
if (
|
|
178
|
+
if (level === "error") {
|
|
163
179
|
chalkFn(message);
|
|
164
180
|
console.error(message);
|
|
165
181
|
}
|
|
166
182
|
return;
|
|
167
183
|
}
|
|
168
|
-
|
|
169
|
-
|
|
184
|
+
const formattedMessage = level === "debug" ? `[DEBUG] ${message}` : message;
|
|
185
|
+
if (level === "error") {
|
|
186
|
+
console.error(chalkFn(formattedMessage));
|
|
170
187
|
} else {
|
|
171
|
-
console.log(chalkFn(
|
|
188
|
+
console.log(chalkFn(formattedMessage));
|
|
172
189
|
}
|
|
173
190
|
}
|
|
174
191
|
|
|
175
192
|
// src/core/versionStrategies.ts
|
|
176
|
-
var
|
|
177
|
-
var
|
|
193
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
194
|
+
var path5 = __toESM(require("path"), 1);
|
|
178
195
|
|
|
179
196
|
// src/git/commands.ts
|
|
180
197
|
var import_node_process2 = require("process");
|
|
@@ -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
|
-
|
|
404
|
-
|
|
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);
|
|
@@ -414,15 +473,84 @@ async function getLatestTagForPackage(packageName, versionPrefix) {
|
|
|
414
473
|
}
|
|
415
474
|
|
|
416
475
|
// src/package/packageManagement.ts
|
|
476
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
477
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
478
|
+
|
|
479
|
+
// src/cargo/cargoHandler.ts
|
|
417
480
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
418
481
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
482
|
+
var TOML = __toESM(require("smol-toml"), 1);
|
|
483
|
+
function getCargoInfo(cargoPath) {
|
|
484
|
+
var _a;
|
|
485
|
+
if (!import_node_fs2.default.existsSync(cargoPath)) {
|
|
486
|
+
log(`Cargo.toml file not found at: ${cargoPath}`, "error");
|
|
487
|
+
throw new Error(`Cargo.toml file not found at: ${cargoPath}`);
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
const fileContent = import_node_fs2.default.readFileSync(cargoPath, "utf8");
|
|
491
|
+
const cargo = TOML.parse(fileContent);
|
|
492
|
+
if (!((_a = cargo.package) == null ? void 0 : _a.name)) {
|
|
493
|
+
log(`Package name not found in: ${cargoPath}`, "error");
|
|
494
|
+
throw new Error(`Package name not found in: ${cargoPath}`);
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
name: cargo.package.name,
|
|
498
|
+
version: cargo.package.version || "0.0.0",
|
|
499
|
+
path: cargoPath,
|
|
500
|
+
dir: import_node_path2.default.dirname(cargoPath),
|
|
501
|
+
content: cargo
|
|
502
|
+
};
|
|
503
|
+
} catch (error) {
|
|
504
|
+
log(`Error reading Cargo.toml: ${cargoPath}`, "error");
|
|
505
|
+
if (error instanceof Error) {
|
|
506
|
+
log(error.message, "error");
|
|
507
|
+
throw error;
|
|
508
|
+
}
|
|
509
|
+
throw new Error(`Failed to process Cargo.toml at ${cargoPath}`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function isCargoToml(filePath) {
|
|
513
|
+
return import_node_path2.default.basename(filePath) === "Cargo.toml";
|
|
514
|
+
}
|
|
515
|
+
function updateCargoVersion(cargoPath, version) {
|
|
516
|
+
var _a;
|
|
517
|
+
try {
|
|
518
|
+
const originalContent = import_node_fs2.default.readFileSync(cargoPath, "utf8");
|
|
519
|
+
const cargo = TOML.parse(originalContent);
|
|
520
|
+
const packageName = (_a = cargo.package) == null ? void 0 : _a.name;
|
|
521
|
+
if (!packageName) {
|
|
522
|
+
throw new Error(`No package name found in ${cargoPath}`);
|
|
523
|
+
}
|
|
524
|
+
if (!cargo.package) {
|
|
525
|
+
cargo.package = { name: packageName, version };
|
|
526
|
+
} else {
|
|
527
|
+
cargo.package.version = version;
|
|
528
|
+
}
|
|
529
|
+
const updatedContent = TOML.stringify(cargo);
|
|
530
|
+
import_node_fs2.default.writeFileSync(cargoPath, updatedContent);
|
|
531
|
+
addPackageUpdate(packageName, version, cargoPath);
|
|
532
|
+
log(`Updated Cargo.toml at ${cargoPath} to version ${version}`, "success");
|
|
533
|
+
} catch (error) {
|
|
534
|
+
log(`Failed to update Cargo.toml at ${cargoPath}`, "error");
|
|
535
|
+
if (error instanceof Error) {
|
|
536
|
+
log(error.message, "error");
|
|
537
|
+
}
|
|
538
|
+
throw error;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/package/packageManagement.ts
|
|
419
543
|
function updatePackageVersion(packagePath, version) {
|
|
544
|
+
if (isCargoToml(packagePath)) {
|
|
545
|
+
updateCargoVersion(packagePath, version);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
420
548
|
try {
|
|
421
|
-
const packageContent =
|
|
549
|
+
const packageContent = import_node_fs3.default.readFileSync(packagePath, "utf8");
|
|
422
550
|
const packageJson = JSON.parse(packageContent);
|
|
423
551
|
const packageName = packageJson.name;
|
|
424
552
|
packageJson.version = version;
|
|
425
|
-
|
|
553
|
+
import_node_fs3.default.writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}
|
|
426
554
|
`);
|
|
427
555
|
addPackageUpdate(packageName, version, packagePath);
|
|
428
556
|
log(`Updated package.json at ${packagePath} to version ${version}`, "success");
|
|
@@ -436,124 +564,218 @@ function updatePackageVersion(packagePath, version) {
|
|
|
436
564
|
}
|
|
437
565
|
|
|
438
566
|
// src/package/packageProcessor.ts
|
|
439
|
-
var
|
|
567
|
+
var fs6 = __toESM(require("fs"), 1);
|
|
568
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
440
569
|
var import_node_process4 = require("process");
|
|
441
570
|
|
|
442
571
|
// src/core/versionCalculator.ts
|
|
443
|
-
var fs3 = __toESM(require("fs"), 1);
|
|
444
|
-
var path2 = __toESM(require("path"), 1);
|
|
445
572
|
var import_node_process3 = require("process");
|
|
446
573
|
var import_conventional_recommended_bump = require("conventional-recommended-bump");
|
|
447
|
-
var
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
574
|
+
var import_semver2 = __toESM(require("semver"), 1);
|
|
575
|
+
|
|
576
|
+
// src/utils/manifestHelpers.ts
|
|
577
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
578
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
579
|
+
function getVersionFromManifests(packageDir) {
|
|
580
|
+
const packageJsonPath = import_node_path4.default.join(packageDir, "package.json");
|
|
581
|
+
const cargoTomlPath = import_node_path4.default.join(packageDir, "Cargo.toml");
|
|
582
|
+
if (import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
583
|
+
try {
|
|
584
|
+
const packageJson = JSON.parse(import_node_fs4.default.readFileSync(packageJsonPath, "utf-8"));
|
|
585
|
+
if (packageJson.version) {
|
|
586
|
+
log(`Found version ${packageJson.version} in package.json`, "debug");
|
|
587
|
+
return {
|
|
588
|
+
version: packageJson.version,
|
|
589
|
+
manifestFound: true,
|
|
590
|
+
manifestPath: packageJsonPath,
|
|
591
|
+
manifestType: "package.json"
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
log("No version field found in package.json", "debug");
|
|
595
|
+
} catch (packageJsonError) {
|
|
596
|
+
const errMsg = packageJsonError instanceof Error ? packageJsonError.message : String(packageJsonError);
|
|
597
|
+
log(`Error reading package.json: ${errMsg}`, "warning");
|
|
459
598
|
}
|
|
460
|
-
return prefix;
|
|
461
599
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
log(
|
|
479
|
-
`Cleaning prerelease identifier from ${currentVersion} for ${specifiedType} bump`,
|
|
480
|
-
"debug"
|
|
481
|
-
);
|
|
482
|
-
return bumpVersion(currentVersion, specifiedType, prereleaseIdentifier);
|
|
600
|
+
if (import_node_fs4.default.existsSync(cargoTomlPath)) {
|
|
601
|
+
try {
|
|
602
|
+
const cargoInfo = getCargoInfo(cargoTomlPath);
|
|
603
|
+
if (cargoInfo.version) {
|
|
604
|
+
log(`Found version ${cargoInfo.version} in Cargo.toml`, "debug");
|
|
605
|
+
return {
|
|
606
|
+
version: cargoInfo.version,
|
|
607
|
+
manifestFound: true,
|
|
608
|
+
manifestPath: cargoTomlPath,
|
|
609
|
+
manifestType: "Cargo.toml"
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
log("No version field found in Cargo.toml", "debug");
|
|
613
|
+
} catch (cargoTomlError) {
|
|
614
|
+
const errMsg = cargoTomlError instanceof Error ? cargoTomlError.message : String(cargoTomlError);
|
|
615
|
+
log(`Error reading Cargo.toml: ${errMsg}`, "warning");
|
|
483
616
|
}
|
|
484
|
-
return import_semver.default.inc(currentVersion, specifiedType, prereleaseIdentifier) || "";
|
|
485
617
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
618
|
+
return {
|
|
619
|
+
version: null,
|
|
620
|
+
manifestFound: false,
|
|
621
|
+
manifestPath: "",
|
|
622
|
+
manifestType: null
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function throwIfNoManifestsFound(packageDir) {
|
|
626
|
+
const packageJsonPath = import_node_path4.default.join(packageDir, "package.json");
|
|
627
|
+
const cargoTomlPath = import_node_path4.default.join(packageDir, "Cargo.toml");
|
|
628
|
+
throw new Error(
|
|
629
|
+
`Neither package.json nor Cargo.toml found at ${packageDir}. Checked paths: ${packageJsonPath}, ${cargoTomlPath}. Cannot determine version.`
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/utils/versionUtils.ts
|
|
634
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
635
|
+
var import_semver = __toESM(require("semver"), 1);
|
|
636
|
+
var TOML2 = __toESM(require("smol-toml"), 1);
|
|
637
|
+
var STANDARD_BUMP_TYPES = ["major", "minor", "patch"];
|
|
638
|
+
function bumpVersion(currentVersion, bumpType, prereleaseIdentifier) {
|
|
639
|
+
if (import_semver.default.prerelease(currentVersion) && STANDARD_BUMP_TYPES.includes(bumpType)) {
|
|
640
|
+
const parsed = import_semver.default.parse(currentVersion);
|
|
641
|
+
if (bumpType === "major" && (parsed == null ? void 0 : parsed.major) === 1 && parsed.minor === 0 && parsed.patch === 0 && import_semver.default.prerelease(currentVersion)) {
|
|
642
|
+
return `${parsed.major}.${parsed.minor}.${parsed.patch}`;
|
|
491
643
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
644
|
+
log(`Cleaning prerelease identifier from ${currentVersion} for ${bumpType} bump`, "debug");
|
|
645
|
+
return import_semver.default.inc(currentVersion, bumpType) || "";
|
|
646
|
+
}
|
|
647
|
+
return import_semver.default.inc(currentVersion, bumpType, prereleaseIdentifier) || "";
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/core/versionCalculator.ts
|
|
651
|
+
async function calculateVersion(config, options) {
|
|
652
|
+
const {
|
|
653
|
+
latestTag = "",
|
|
654
|
+
type,
|
|
655
|
+
versionPrefix = "",
|
|
656
|
+
branchPattern,
|
|
657
|
+
baseBranch,
|
|
658
|
+
prereleaseIdentifier,
|
|
659
|
+
path: pkgPath,
|
|
660
|
+
name
|
|
661
|
+
} = options;
|
|
662
|
+
const preset = config.preset || "conventional-commits";
|
|
663
|
+
const initialVersion = "0.1.0";
|
|
664
|
+
try {
|
|
665
|
+
let determineTagSearchPattern2 = function(packageName, prefix) {
|
|
666
|
+
if (packageName) {
|
|
667
|
+
const escapedPackageName = escapeRegExp(packageName);
|
|
668
|
+
const escapedPrefix = escapeRegExp(prefix);
|
|
669
|
+
return `${escapedPackageName}[@]?${escapedPrefix}`;
|
|
504
670
|
}
|
|
505
|
-
|
|
506
|
-
|
|
671
|
+
return escapeRegExp(prefix);
|
|
672
|
+
};
|
|
673
|
+
var determineTagSearchPattern = determineTagSearchPattern2;
|
|
674
|
+
const hasNoTags = !latestTag;
|
|
675
|
+
const originalPrefix = versionPrefix;
|
|
676
|
+
const tagSearchPattern = determineTagSearchPattern2(name, originalPrefix);
|
|
677
|
+
const escapedTagPattern = escapeRegExp(tagSearchPattern);
|
|
678
|
+
const specifiedType = type;
|
|
679
|
+
if (specifiedType) {
|
|
507
680
|
if (hasNoTags) {
|
|
508
681
|
return getPackageVersionFallback(
|
|
509
682
|
pkgPath,
|
|
510
683
|
name,
|
|
511
|
-
|
|
684
|
+
specifiedType,
|
|
512
685
|
prereleaseIdentifier,
|
|
513
686
|
initialVersion
|
|
514
687
|
);
|
|
515
688
|
}
|
|
516
|
-
const cleanedTag =
|
|
517
|
-
const currentVersion =
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
try {
|
|
523
|
-
const bumper = new import_conventional_recommended_bump.Bumper();
|
|
524
|
-
bumper.loadPreset(preset);
|
|
525
|
-
const recommendedBump = await bumper.bump();
|
|
526
|
-
const releaseTypeFromCommits = recommendedBump == null ? void 0 : recommendedBump.releaseType;
|
|
527
|
-
if (hasNoTags) {
|
|
528
|
-
if (releaseTypeFromCommits) {
|
|
529
|
-
return getPackageVersionFallback(
|
|
530
|
-
pkgPath,
|
|
531
|
-
name,
|
|
532
|
-
releaseTypeFromCommits,
|
|
533
|
-
prereleaseIdentifier,
|
|
534
|
-
initialVersion
|
|
689
|
+
const cleanedTag = import_semver2.default.clean(latestTag) || latestTag;
|
|
690
|
+
const currentVersion = import_semver2.default.clean(cleanedTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
691
|
+
if (STANDARD_BUMP_TYPES.includes(specifiedType) && import_semver2.default.prerelease(currentVersion)) {
|
|
692
|
+
log(
|
|
693
|
+
`Cleaning prerelease identifier from ${currentVersion} for ${specifiedType} bump`,
|
|
694
|
+
"debug"
|
|
535
695
|
);
|
|
696
|
+
return bumpVersion(currentVersion, specifiedType, prereleaseIdentifier);
|
|
536
697
|
}
|
|
537
|
-
return
|
|
698
|
+
return import_semver2.default.inc(currentVersion, specifiedType, prereleaseIdentifier) || "";
|
|
538
699
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
700
|
+
if (branchPattern && branchPattern.length > 0) {
|
|
701
|
+
const currentBranch = getCurrentBranch();
|
|
702
|
+
if (baseBranch) {
|
|
703
|
+
lastMergeBranchName(branchPattern, baseBranch);
|
|
704
|
+
}
|
|
705
|
+
const branchToCheck = currentBranch;
|
|
706
|
+
let branchVersionType;
|
|
707
|
+
for (const pattern of branchPattern) {
|
|
708
|
+
if (!pattern.includes(":")) {
|
|
709
|
+
log(`Invalid branch pattern "${pattern}" - missing colon. Skipping.`, "warning");
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
const [patternRegex, releaseType] = pattern.split(":");
|
|
713
|
+
if (new RegExp(patternRegex).test(branchToCheck)) {
|
|
714
|
+
branchVersionType = releaseType;
|
|
715
|
+
log(`Using branch pattern ${patternRegex} for version type ${releaseType}`, "debug");
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (branchVersionType) {
|
|
720
|
+
if (hasNoTags) {
|
|
721
|
+
return getPackageVersionFallback(
|
|
722
|
+
pkgPath,
|
|
723
|
+
name,
|
|
724
|
+
branchVersionType,
|
|
725
|
+
prereleaseIdentifier,
|
|
726
|
+
initialVersion
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
const cleanedTag = import_semver2.default.clean(latestTag) || latestTag;
|
|
730
|
+
const currentVersion = import_semver2.default.clean(cleanedTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
731
|
+
log(`Applying ${branchVersionType} bump based on branch pattern`, "debug");
|
|
732
|
+
return import_semver2.default.inc(currentVersion, branchVersionType, void 0) || "";
|
|
733
|
+
}
|
|
547
734
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
735
|
+
try {
|
|
736
|
+
const bumper = new import_conventional_recommended_bump.Bumper();
|
|
737
|
+
bumper.loadPreset(preset);
|
|
738
|
+
const recommendedBump = await bumper.bump();
|
|
739
|
+
const releaseTypeFromCommits = recommendedBump == null ? void 0 : recommendedBump.releaseType;
|
|
740
|
+
if (hasNoTags) {
|
|
741
|
+
if (releaseTypeFromCommits) {
|
|
742
|
+
return getPackageVersionFallback(
|
|
743
|
+
pkgPath,
|
|
744
|
+
name,
|
|
745
|
+
releaseTypeFromCommits,
|
|
746
|
+
prereleaseIdentifier,
|
|
747
|
+
initialVersion
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
return initialVersion;
|
|
751
|
+
}
|
|
752
|
+
const checkPath = pkgPath || (0, import_node_process3.cwd)();
|
|
753
|
+
const commitsLength = getCommitsLength(checkPath);
|
|
754
|
+
if (commitsLength === 0) {
|
|
755
|
+
log(
|
|
756
|
+
`No new commits found for ${name || "project"} since ${latestTag}, skipping version bump`,
|
|
757
|
+
"info"
|
|
758
|
+
);
|
|
759
|
+
return "";
|
|
760
|
+
}
|
|
761
|
+
if (!releaseTypeFromCommits) {
|
|
762
|
+
log(
|
|
763
|
+
`No relevant commits found for ${name || "project"} since ${latestTag}, skipping version bump`,
|
|
764
|
+
"info"
|
|
765
|
+
);
|
|
766
|
+
return "";
|
|
767
|
+
}
|
|
768
|
+
const currentVersion = import_semver2.default.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
769
|
+
return import_semver2.default.inc(currentVersion, releaseTypeFromCommits, prereleaseIdentifier) || "";
|
|
770
|
+
} catch (error) {
|
|
771
|
+
log(`Failed to calculate version for ${name || "project"}`, "error");
|
|
772
|
+
console.error(error);
|
|
773
|
+
if (error instanceof Error && error.message.includes("No names found")) {
|
|
774
|
+
log("No tags found, proceeding with initial version calculation (if applicable).", "info");
|
|
775
|
+
return initialVersion;
|
|
776
|
+
}
|
|
777
|
+
throw error;
|
|
554
778
|
}
|
|
555
|
-
const currentVersion = import_semver.default.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
556
|
-
return import_semver.default.inc(currentVersion, releaseTypeFromCommits, prereleaseIdentifier) || "";
|
|
557
779
|
} catch (error) {
|
|
558
780
|
log(`Failed to calculate version for ${name || "project"}`, "error");
|
|
559
781
|
console.error(error);
|
|
@@ -566,51 +788,37 @@ async function calculateVersion(config, options) {
|
|
|
566
788
|
}
|
|
567
789
|
function getPackageVersionFallback(pkgPath, name, releaseType, prereleaseIdentifier, initialVersion) {
|
|
568
790
|
const packageDir = pkgPath || (0, import_node_process3.cwd)();
|
|
569
|
-
const
|
|
570
|
-
if (
|
|
571
|
-
throw new Error(`package.json not found at ${packageJsonPath}. Cannot determine version.`);
|
|
572
|
-
}
|
|
573
|
-
try {
|
|
574
|
-
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
575
|
-
if (!packageJson.version) {
|
|
576
|
-
log(`No version found in package.json. Using initial version ${initialVersion}`, "info");
|
|
577
|
-
return initialVersion;
|
|
578
|
-
}
|
|
791
|
+
const manifestResult = getVersionFromManifests(packageDir);
|
|
792
|
+
if (manifestResult.manifestFound && manifestResult.version) {
|
|
579
793
|
log(
|
|
580
|
-
`No tags found for ${name || "package"}, using
|
|
794
|
+
`No tags found for ${name || "package"}, using ${manifestResult.manifestType} version: ${manifestResult.version} as base`,
|
|
581
795
|
"info"
|
|
582
796
|
);
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
}
|
|
591
|
-
log(
|
|
592
|
-
`Cleaning prerelease identifier from ${packageJson.version} for ${releaseType} bump`,
|
|
593
|
-
"debug"
|
|
594
|
-
);
|
|
595
|
-
return bumpVersion(packageJson.version, releaseType, prereleaseIdentifier);
|
|
596
|
-
}
|
|
597
|
-
return import_semver.default.inc(packageJson.version, releaseType, prereleaseIdentifier) || initialVersion;
|
|
598
|
-
} catch (err) {
|
|
599
|
-
throw new Error(
|
|
600
|
-
`Error reading package.json: ${err instanceof Error ? err.message : String(err)}`
|
|
797
|
+
return calculateNextVersion(
|
|
798
|
+
manifestResult.version,
|
|
799
|
+
manifestResult.manifestType || "manifest",
|
|
800
|
+
name,
|
|
801
|
+
releaseType,
|
|
802
|
+
prereleaseIdentifier,
|
|
803
|
+
initialVersion
|
|
601
804
|
);
|
|
602
805
|
}
|
|
806
|
+
throwIfNoManifestsFound(packageDir);
|
|
603
807
|
}
|
|
604
|
-
function
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
808
|
+
function calculateNextVersion(version, manifestType, name, releaseType, prereleaseIdentifier, initialVersion) {
|
|
809
|
+
log(
|
|
810
|
+
`No tags found for ${name || "package"}, using ${manifestType} version: ${version} as base`,
|
|
811
|
+
"info"
|
|
812
|
+
);
|
|
813
|
+
if (STANDARD_BUMP_TYPES.includes(releaseType) && import_semver2.default.prerelease(version)) {
|
|
814
|
+
if (version === "1.0.0-next.0" && releaseType === "major") {
|
|
815
|
+
log(`Cleaning prerelease identifier from ${version} for ${releaseType} bump`, "debug");
|
|
816
|
+
return "1.0.0";
|
|
609
817
|
}
|
|
610
|
-
log(`Cleaning prerelease identifier from ${
|
|
611
|
-
return
|
|
818
|
+
log(`Cleaning prerelease identifier from ${version} for ${releaseType} bump`, "debug");
|
|
819
|
+
return bumpVersion(version, releaseType, prereleaseIdentifier);
|
|
612
820
|
}
|
|
613
|
-
return
|
|
821
|
+
return import_semver2.default.inc(version, releaseType, prereleaseIdentifier) || initialVersion;
|
|
614
822
|
}
|
|
615
823
|
|
|
616
824
|
// src/package/packageProcessor.ts
|
|
@@ -694,14 +902,31 @@ var PackageProcessor = class {
|
|
|
694
902
|
}
|
|
695
903
|
if (!latestTagResult) {
|
|
696
904
|
try {
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
905
|
+
const packageDir = pkgPath;
|
|
906
|
+
let manifestFallbackUsed = false;
|
|
907
|
+
const manifestResult = getVersionFromManifests(packageDir);
|
|
908
|
+
if (manifestResult.manifestFound && manifestResult.version) {
|
|
909
|
+
log(
|
|
910
|
+
`Using ${manifestResult.manifestType} version ${manifestResult.version} for ${name} as no package-specific tags found`,
|
|
911
|
+
"info"
|
|
912
|
+
);
|
|
913
|
+
log(
|
|
914
|
+
`FALLBACK: Using package version from ${manifestResult.manifestType} instead of global tag`,
|
|
915
|
+
"debug"
|
|
916
|
+
);
|
|
917
|
+
latestTagResult = `${this.versionPrefix || ""}${manifestResult.version}`;
|
|
918
|
+
manifestFallbackUsed = true;
|
|
919
|
+
}
|
|
920
|
+
if (!manifestFallbackUsed) {
|
|
921
|
+
const globalTagResult = await this.getLatestTag();
|
|
922
|
+
if (globalTagResult) {
|
|
923
|
+
latestTagResult = globalTagResult;
|
|
924
|
+
log(`Using global tag ${globalTagResult} as fallback for package ${name}`, "info");
|
|
925
|
+
}
|
|
701
926
|
}
|
|
702
927
|
} catch (error) {
|
|
703
928
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
704
|
-
log(`Error getting
|
|
929
|
+
log(`Error getting fallback version, using empty tag value: ${errorMessage}`, "warning");
|
|
705
930
|
}
|
|
706
931
|
}
|
|
707
932
|
const latestTag = latestTagResult;
|
|
@@ -718,7 +943,14 @@ var PackageProcessor = class {
|
|
|
718
943
|
if (!nextVersion) {
|
|
719
944
|
continue;
|
|
720
945
|
}
|
|
721
|
-
|
|
946
|
+
const packageJsonPath = import_node_path5.default.join(pkgPath, "package.json");
|
|
947
|
+
const cargoTomlPath = import_node_path5.default.join(pkgPath, "Cargo.toml");
|
|
948
|
+
if (fs6.existsSync(packageJsonPath)) {
|
|
949
|
+
updatePackageVersion(packageJsonPath, nextVersion);
|
|
950
|
+
}
|
|
951
|
+
if (fs6.existsSync(cargoTomlPath)) {
|
|
952
|
+
updatePackageVersion(cargoTomlPath, nextVersion);
|
|
953
|
+
}
|
|
722
954
|
const packageTag = formatTag(
|
|
723
955
|
nextVersion,
|
|
724
956
|
this.versionPrefix,
|
|
@@ -749,7 +981,7 @@ var PackageProcessor = class {
|
|
|
749
981
|
log("No targeted packages required a version update.", "info");
|
|
750
982
|
return { updatedPackages: [], tags };
|
|
751
983
|
}
|
|
752
|
-
const filesToCommit = updatedPackagesInfo.map((info) =>
|
|
984
|
+
const filesToCommit = updatedPackagesInfo.map((info) => import_node_path5.default.join(info.path, "package.json"));
|
|
753
985
|
const packageNames = updatedPackagesInfo.map((p) => p.name).join(", ");
|
|
754
986
|
const representativeVersion = ((_a = updatedPackagesInfo[0]) == null ? void 0 : _a.version) || "multiple";
|
|
755
987
|
let commitMessage = this.commitMessageTemplate || "chore(release): publish packages";
|
|
@@ -826,8 +1058,8 @@ function createSyncedStrategy(config) {
|
|
|
826
1058
|
const files = [];
|
|
827
1059
|
const updatedPackages = [];
|
|
828
1060
|
try {
|
|
829
|
-
const rootPkgPath =
|
|
830
|
-
if (
|
|
1061
|
+
const rootPkgPath = path5.join(packages.root, "package.json");
|
|
1062
|
+
if (import_node_fs6.default.existsSync(rootPkgPath)) {
|
|
831
1063
|
updatePackageVersion(rootPkgPath, nextVersion);
|
|
832
1064
|
files.push(rootPkgPath);
|
|
833
1065
|
updatedPackages.push("root");
|
|
@@ -839,7 +1071,7 @@ function createSyncedStrategy(config) {
|
|
|
839
1071
|
if (!shouldProcessPackage(pkg, config)) {
|
|
840
1072
|
continue;
|
|
841
1073
|
}
|
|
842
|
-
const packageJsonPath =
|
|
1074
|
+
const packageJsonPath = path5.join(pkg.dir, "package.json");
|
|
843
1075
|
updatePackageVersion(packageJsonPath, nextVersion);
|
|
844
1076
|
files.push(packageJsonPath);
|
|
845
1077
|
updatedPackages.push(pkg.packageJson.name);
|
|
@@ -912,7 +1144,7 @@ function createSingleStrategy(config) {
|
|
|
912
1144
|
log(`No version change needed for ${packageName}`, "info");
|
|
913
1145
|
return;
|
|
914
1146
|
}
|
|
915
|
-
const packageJsonPath =
|
|
1147
|
+
const packageJsonPath = path5.join(pkgPath, "package.json");
|
|
916
1148
|
updatePackageVersion(packageJsonPath, nextVersion);
|
|
917
1149
|
log(`Updated package ${packageName} to version ${nextVersion}`, "success");
|
|
918
1150
|
const nextTag = formatTag(
|
|
@@ -1088,11 +1320,29 @@ var VersionEngine = class {
|
|
|
1088
1320
|
};
|
|
1089
1321
|
|
|
1090
1322
|
// src/index.ts
|
|
1323
|
+
var import_meta = {};
|
|
1324
|
+
function getPackageVersion() {
|
|
1325
|
+
try {
|
|
1326
|
+
const packageJsonPath = import_node_path6.default.resolve(
|
|
1327
|
+
import_node_path6.default.dirname(import_meta.url.replace("file:", "")),
|
|
1328
|
+
"../package.json"
|
|
1329
|
+
);
|
|
1330
|
+
const packageJsonContent = fs8.readFileSync(packageJsonPath, "utf-8");
|
|
1331
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
1332
|
+
return packageJson.version || "0.0.0";
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
console.error("Failed to read package version:", error);
|
|
1335
|
+
return "0.0.0";
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1091
1338
|
async function run() {
|
|
1339
|
+
const buildTimestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1340
|
+
const packageVersion = getPackageVersion();
|
|
1341
|
+
log(`package-versioner v${packageVersion} (Build: ${buildTimestamp})`, "debug");
|
|
1092
1342
|
const program = new import_commander.Command();
|
|
1093
1343
|
program.name("package-versioner").description(
|
|
1094
1344
|
"A lightweight yet powerful CLI tool for automated semantic versioning based on Git history and conventional commits."
|
|
1095
|
-
).version(
|
|
1345
|
+
).version(packageVersion).option(
|
|
1096
1346
|
"-c, --config <path>",
|
|
1097
1347
|
"Path to config file (defaults to version.config.json in current directory)"
|
|
1098
1348
|
).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);
|
|
@@ -1107,7 +1357,7 @@ async function run() {
|
|
|
1107
1357
|
if (options.synced) config.synced = true;
|
|
1108
1358
|
if (options.bump) config.type = options.bump;
|
|
1109
1359
|
if (options.prerelease)
|
|
1110
|
-
config.prereleaseIdentifier = options.prerelease === true ? "
|
|
1360
|
+
config.prereleaseIdentifier = options.prerelease === true ? "next" : options.prerelease;
|
|
1111
1361
|
const cliTargets = options.target ? options.target.split(",").map((t) => t.trim()) : [];
|
|
1112
1362
|
const engine = new VersionEngine(config, !!options.json);
|
|
1113
1363
|
if (config.synced) {
|
|
@@ -1140,3 +1390,7 @@ run().catch((error) => {
|
|
|
1140
1390
|
console.error("Fatal error:", error);
|
|
1141
1391
|
process.exit(1);
|
|
1142
1392
|
});
|
|
1393
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1394
|
+
0 && (module.exports = {
|
|
1395
|
+
run
|
|
1396
|
+
});
|