package-versioner 0.5.4 → 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 +318 -170
- package/dist/index.js +317 -170
- package/docs/VERSIONING_STRATEGIES.md +30 -1
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
4
|
+
import * as fs7 from "node:fs";
|
|
5
|
+
import path5 from "node:path";
|
|
6
6
|
import { Command } from "commander";
|
|
7
7
|
|
|
8
8
|
// src/config.ts
|
|
@@ -157,8 +157,8 @@ function log(message, level = "info") {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// src/core/versionStrategies.ts
|
|
160
|
-
import
|
|
161
|
-
import * as
|
|
160
|
+
import fs6 from "node:fs";
|
|
161
|
+
import * as path4 from "node:path";
|
|
162
162
|
|
|
163
163
|
// src/git/commands.ts
|
|
164
164
|
import { cwd as cwd2 } from "node:process";
|
|
@@ -440,14 +440,83 @@ async function getLatestTagForPackage(packageName, versionPrefix) {
|
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
// src/package/packageManagement.ts
|
|
443
|
+
import fs3 from "node:fs";
|
|
444
|
+
|
|
445
|
+
// src/cargo/cargoHandler.ts
|
|
443
446
|
import fs2 from "node:fs";
|
|
447
|
+
import path from "node:path";
|
|
448
|
+
import * as TOML from "smol-toml";
|
|
449
|
+
function getCargoInfo(cargoPath) {
|
|
450
|
+
var _a;
|
|
451
|
+
if (!fs2.existsSync(cargoPath)) {
|
|
452
|
+
log(`Cargo.toml file not found at: ${cargoPath}`, "error");
|
|
453
|
+
throw new Error(`Cargo.toml file not found at: ${cargoPath}`);
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
const fileContent = fs2.readFileSync(cargoPath, "utf8");
|
|
457
|
+
const cargo = TOML.parse(fileContent);
|
|
458
|
+
if (!((_a = cargo.package) == null ? void 0 : _a.name)) {
|
|
459
|
+
log(`Package name not found in: ${cargoPath}`, "error");
|
|
460
|
+
throw new Error(`Package name not found in: ${cargoPath}`);
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
name: cargo.package.name,
|
|
464
|
+
version: cargo.package.version || "0.0.0",
|
|
465
|
+
path: cargoPath,
|
|
466
|
+
dir: path.dirname(cargoPath),
|
|
467
|
+
content: cargo
|
|
468
|
+
};
|
|
469
|
+
} catch (error) {
|
|
470
|
+
log(`Error reading Cargo.toml: ${cargoPath}`, "error");
|
|
471
|
+
if (error instanceof Error) {
|
|
472
|
+
log(error.message, "error");
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
throw new Error(`Failed to process Cargo.toml at ${cargoPath}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function isCargoToml(filePath) {
|
|
479
|
+
return path.basename(filePath) === "Cargo.toml";
|
|
480
|
+
}
|
|
481
|
+
function updateCargoVersion(cargoPath, version) {
|
|
482
|
+
var _a;
|
|
483
|
+
try {
|
|
484
|
+
const originalContent = fs2.readFileSync(cargoPath, "utf8");
|
|
485
|
+
const cargo = TOML.parse(originalContent);
|
|
486
|
+
const packageName = (_a = cargo.package) == null ? void 0 : _a.name;
|
|
487
|
+
if (!packageName) {
|
|
488
|
+
throw new Error(`No package name found in ${cargoPath}`);
|
|
489
|
+
}
|
|
490
|
+
if (!cargo.package) {
|
|
491
|
+
cargo.package = { name: packageName, version };
|
|
492
|
+
} else {
|
|
493
|
+
cargo.package.version = version;
|
|
494
|
+
}
|
|
495
|
+
const updatedContent = TOML.stringify(cargo);
|
|
496
|
+
fs2.writeFileSync(cargoPath, updatedContent);
|
|
497
|
+
addPackageUpdate(packageName, version, cargoPath);
|
|
498
|
+
log(`Updated Cargo.toml at ${cargoPath} to version ${version}`, "success");
|
|
499
|
+
} catch (error) {
|
|
500
|
+
log(`Failed to update Cargo.toml at ${cargoPath}`, "error");
|
|
501
|
+
if (error instanceof Error) {
|
|
502
|
+
log(error.message, "error");
|
|
503
|
+
}
|
|
504
|
+
throw error;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// src/package/packageManagement.ts
|
|
444
509
|
function updatePackageVersion(packagePath, version) {
|
|
510
|
+
if (isCargoToml(packagePath)) {
|
|
511
|
+
updateCargoVersion(packagePath, version);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
445
514
|
try {
|
|
446
|
-
const packageContent =
|
|
515
|
+
const packageContent = fs3.readFileSync(packagePath, "utf8");
|
|
447
516
|
const packageJson = JSON.parse(packageContent);
|
|
448
517
|
const packageName = packageJson.name;
|
|
449
518
|
packageJson.version = version;
|
|
450
|
-
|
|
519
|
+
fs3.writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}
|
|
451
520
|
`);
|
|
452
521
|
addPackageUpdate(packageName, version, packagePath);
|
|
453
522
|
log(`Updated package.json at ${packagePath} to version ${version}`, "success");
|
|
@@ -461,125 +530,217 @@ function updatePackageVersion(packagePath, version) {
|
|
|
461
530
|
}
|
|
462
531
|
|
|
463
532
|
// src/package/packageProcessor.ts
|
|
464
|
-
import * as
|
|
465
|
-
import
|
|
533
|
+
import * as fs5 from "node:fs";
|
|
534
|
+
import path3 from "node:path";
|
|
466
535
|
import { exit } from "node:process";
|
|
467
536
|
|
|
468
537
|
// src/core/versionCalculator.ts
|
|
469
|
-
import * as fs3 from "node:fs";
|
|
470
|
-
import * as path from "node:path";
|
|
471
538
|
import { cwd as cwd3 } from "node:process";
|
|
472
539
|
import { Bumper } from "conventional-recommended-bump";
|
|
473
|
-
import
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
540
|
+
import semver2 from "semver";
|
|
541
|
+
|
|
542
|
+
// src/utils/manifestHelpers.ts
|
|
543
|
+
import fs4 from "node:fs";
|
|
544
|
+
import path2 from "node:path";
|
|
545
|
+
function getVersionFromManifests(packageDir) {
|
|
546
|
+
const packageJsonPath = path2.join(packageDir, "package.json");
|
|
547
|
+
const cargoTomlPath = path2.join(packageDir, "Cargo.toml");
|
|
548
|
+
if (fs4.existsSync(packageJsonPath)) {
|
|
549
|
+
try {
|
|
550
|
+
const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
|
|
551
|
+
if (packageJson.version) {
|
|
552
|
+
log(`Found version ${packageJson.version} in package.json`, "debug");
|
|
553
|
+
return {
|
|
554
|
+
version: packageJson.version,
|
|
555
|
+
manifestFound: true,
|
|
556
|
+
manifestPath: packageJsonPath,
|
|
557
|
+
manifestType: "package.json"
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
log("No version field found in package.json", "debug");
|
|
561
|
+
} catch (packageJsonError) {
|
|
562
|
+
const errMsg = packageJsonError instanceof Error ? packageJsonError.message : String(packageJsonError);
|
|
563
|
+
log(`Error reading package.json: ${errMsg}`, "warning");
|
|
485
564
|
}
|
|
486
|
-
return prefix;
|
|
487
565
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
log(
|
|
505
|
-
`Cleaning prerelease identifier from ${currentVersion} for ${specifiedType} bump`,
|
|
506
|
-
"debug"
|
|
507
|
-
);
|
|
508
|
-
return bumpVersion(currentVersion, specifiedType, prereleaseIdentifier);
|
|
566
|
+
if (fs4.existsSync(cargoTomlPath)) {
|
|
567
|
+
try {
|
|
568
|
+
const cargoInfo = getCargoInfo(cargoTomlPath);
|
|
569
|
+
if (cargoInfo.version) {
|
|
570
|
+
log(`Found version ${cargoInfo.version} in Cargo.toml`, "debug");
|
|
571
|
+
return {
|
|
572
|
+
version: cargoInfo.version,
|
|
573
|
+
manifestFound: true,
|
|
574
|
+
manifestPath: cargoTomlPath,
|
|
575
|
+
manifestType: "Cargo.toml"
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
log("No version field found in Cargo.toml", "debug");
|
|
579
|
+
} catch (cargoTomlError) {
|
|
580
|
+
const errMsg = cargoTomlError instanceof Error ? cargoTomlError.message : String(cargoTomlError);
|
|
581
|
+
log(`Error reading Cargo.toml: ${errMsg}`, "warning");
|
|
509
582
|
}
|
|
510
|
-
return semver.inc(currentVersion, specifiedType, prereleaseIdentifier) || "";
|
|
511
583
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
584
|
+
return {
|
|
585
|
+
version: null,
|
|
586
|
+
manifestFound: false,
|
|
587
|
+
manifestPath: "",
|
|
588
|
+
manifestType: null
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
function throwIfNoManifestsFound(packageDir) {
|
|
592
|
+
const packageJsonPath = path2.join(packageDir, "package.json");
|
|
593
|
+
const cargoTomlPath = path2.join(packageDir, "Cargo.toml");
|
|
594
|
+
throw new Error(
|
|
595
|
+
`Neither package.json nor Cargo.toml found at ${packageDir}. Checked paths: ${packageJsonPath}, ${cargoTomlPath}. Cannot determine version.`
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// src/utils/versionUtils.ts
|
|
600
|
+
import semver from "semver";
|
|
601
|
+
import * as TOML2 from "smol-toml";
|
|
602
|
+
var STANDARD_BUMP_TYPES = ["major", "minor", "patch"];
|
|
603
|
+
function bumpVersion(currentVersion, bumpType, prereleaseIdentifier) {
|
|
604
|
+
if (semver.prerelease(currentVersion) && STANDARD_BUMP_TYPES.includes(bumpType)) {
|
|
605
|
+
const parsed = semver.parse(currentVersion);
|
|
606
|
+
if (bumpType === "major" && (parsed == null ? void 0 : parsed.major) === 1 && parsed.minor === 0 && parsed.patch === 0 && semver.prerelease(currentVersion)) {
|
|
607
|
+
return `${parsed.major}.${parsed.minor}.${parsed.patch}`;
|
|
517
608
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
609
|
+
log(`Cleaning prerelease identifier from ${currentVersion} for ${bumpType} bump`, "debug");
|
|
610
|
+
return semver.inc(currentVersion, bumpType) || "";
|
|
611
|
+
}
|
|
612
|
+
return semver.inc(currentVersion, bumpType, prereleaseIdentifier) || "";
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/core/versionCalculator.ts
|
|
616
|
+
async function calculateVersion(config, options) {
|
|
617
|
+
const {
|
|
618
|
+
latestTag = "",
|
|
619
|
+
type,
|
|
620
|
+
versionPrefix = "",
|
|
621
|
+
branchPattern,
|
|
622
|
+
baseBranch,
|
|
623
|
+
prereleaseIdentifier,
|
|
624
|
+
path: pkgPath,
|
|
625
|
+
name
|
|
626
|
+
} = options;
|
|
627
|
+
const preset = config.preset || "conventional-commits";
|
|
628
|
+
const initialVersion = "0.1.0";
|
|
629
|
+
try {
|
|
630
|
+
let determineTagSearchPattern2 = function(packageName, prefix) {
|
|
631
|
+
if (packageName) {
|
|
632
|
+
const escapedPackageName = escapeRegExp(packageName);
|
|
633
|
+
const escapedPrefix = escapeRegExp(prefix);
|
|
634
|
+
return `${escapedPackageName}[@]?${escapedPrefix}`;
|
|
530
635
|
}
|
|
531
|
-
|
|
532
|
-
|
|
636
|
+
return escapeRegExp(prefix);
|
|
637
|
+
};
|
|
638
|
+
var determineTagSearchPattern = determineTagSearchPattern2;
|
|
639
|
+
const hasNoTags = !latestTag;
|
|
640
|
+
const originalPrefix = versionPrefix;
|
|
641
|
+
const tagSearchPattern = determineTagSearchPattern2(name, originalPrefix);
|
|
642
|
+
const escapedTagPattern = escapeRegExp(tagSearchPattern);
|
|
643
|
+
const specifiedType = type;
|
|
644
|
+
if (specifiedType) {
|
|
533
645
|
if (hasNoTags) {
|
|
534
646
|
return getPackageVersionFallback(
|
|
535
647
|
pkgPath,
|
|
536
648
|
name,
|
|
537
|
-
|
|
649
|
+
specifiedType,
|
|
538
650
|
prereleaseIdentifier,
|
|
539
651
|
initialVersion
|
|
540
652
|
);
|
|
541
653
|
}
|
|
542
|
-
const cleanedTag =
|
|
543
|
-
const currentVersion =
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
try {
|
|
549
|
-
const bumper = new Bumper();
|
|
550
|
-
bumper.loadPreset(preset);
|
|
551
|
-
const recommendedBump = await bumper.bump();
|
|
552
|
-
const releaseTypeFromCommits = recommendedBump == null ? void 0 : recommendedBump.releaseType;
|
|
553
|
-
if (hasNoTags) {
|
|
554
|
-
if (releaseTypeFromCommits) {
|
|
555
|
-
return getPackageVersionFallback(
|
|
556
|
-
pkgPath,
|
|
557
|
-
name,
|
|
558
|
-
releaseTypeFromCommits,
|
|
559
|
-
prereleaseIdentifier,
|
|
560
|
-
initialVersion
|
|
654
|
+
const cleanedTag = semver2.clean(latestTag) || latestTag;
|
|
655
|
+
const currentVersion = semver2.clean(cleanedTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
656
|
+
if (STANDARD_BUMP_TYPES.includes(specifiedType) && semver2.prerelease(currentVersion)) {
|
|
657
|
+
log(
|
|
658
|
+
`Cleaning prerelease identifier from ${currentVersion} for ${specifiedType} bump`,
|
|
659
|
+
"debug"
|
|
561
660
|
);
|
|
661
|
+
return bumpVersion(currentVersion, specifiedType, prereleaseIdentifier);
|
|
562
662
|
}
|
|
563
|
-
return
|
|
663
|
+
return semver2.inc(currentVersion, specifiedType, prereleaseIdentifier) || "";
|
|
564
664
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
665
|
+
if (branchPattern && branchPattern.length > 0) {
|
|
666
|
+
const currentBranch = getCurrentBranch();
|
|
667
|
+
if (baseBranch) {
|
|
668
|
+
lastMergeBranchName(branchPattern, baseBranch);
|
|
669
|
+
}
|
|
670
|
+
const branchToCheck = currentBranch;
|
|
671
|
+
let branchVersionType;
|
|
672
|
+
for (const pattern of branchPattern) {
|
|
673
|
+
if (!pattern.includes(":")) {
|
|
674
|
+
log(`Invalid branch pattern "${pattern}" - missing colon. Skipping.`, "warning");
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
const [patternRegex, releaseType] = pattern.split(":");
|
|
678
|
+
if (new RegExp(patternRegex).test(branchToCheck)) {
|
|
679
|
+
branchVersionType = releaseType;
|
|
680
|
+
log(`Using branch pattern ${patternRegex} for version type ${releaseType}`, "debug");
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (branchVersionType) {
|
|
685
|
+
if (hasNoTags) {
|
|
686
|
+
return getPackageVersionFallback(
|
|
687
|
+
pkgPath,
|
|
688
|
+
name,
|
|
689
|
+
branchVersionType,
|
|
690
|
+
prereleaseIdentifier,
|
|
691
|
+
initialVersion
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
const cleanedTag = semver2.clean(latestTag) || latestTag;
|
|
695
|
+
const currentVersion = semver2.clean(cleanedTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
696
|
+
log(`Applying ${branchVersionType} bump based on branch pattern`, "debug");
|
|
697
|
+
return semver2.inc(currentVersion, branchVersionType, void 0) || "";
|
|
698
|
+
}
|
|
573
699
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
700
|
+
try {
|
|
701
|
+
const bumper = new Bumper();
|
|
702
|
+
bumper.loadPreset(preset);
|
|
703
|
+
const recommendedBump = await bumper.bump();
|
|
704
|
+
const releaseTypeFromCommits = recommendedBump == null ? void 0 : recommendedBump.releaseType;
|
|
705
|
+
if (hasNoTags) {
|
|
706
|
+
if (releaseTypeFromCommits) {
|
|
707
|
+
return getPackageVersionFallback(
|
|
708
|
+
pkgPath,
|
|
709
|
+
name,
|
|
710
|
+
releaseTypeFromCommits,
|
|
711
|
+
prereleaseIdentifier,
|
|
712
|
+
initialVersion
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
return initialVersion;
|
|
716
|
+
}
|
|
717
|
+
const checkPath = pkgPath || cwd3();
|
|
718
|
+
const commitsLength = getCommitsLength(checkPath);
|
|
719
|
+
if (commitsLength === 0) {
|
|
720
|
+
log(
|
|
721
|
+
`No new commits found for ${name || "project"} since ${latestTag}, skipping version bump`,
|
|
722
|
+
"info"
|
|
723
|
+
);
|
|
724
|
+
return "";
|
|
725
|
+
}
|
|
726
|
+
if (!releaseTypeFromCommits) {
|
|
727
|
+
log(
|
|
728
|
+
`No relevant commits found for ${name || "project"} since ${latestTag}, skipping version bump`,
|
|
729
|
+
"info"
|
|
730
|
+
);
|
|
731
|
+
return "";
|
|
732
|
+
}
|
|
733
|
+
const currentVersion = semver2.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
734
|
+
return semver2.inc(currentVersion, releaseTypeFromCommits, prereleaseIdentifier) || "";
|
|
735
|
+
} catch (error) {
|
|
736
|
+
log(`Failed to calculate version for ${name || "project"}`, "error");
|
|
737
|
+
console.error(error);
|
|
738
|
+
if (error instanceof Error && error.message.includes("No names found")) {
|
|
739
|
+
log("No tags found, proceeding with initial version calculation (if applicable).", "info");
|
|
740
|
+
return initialVersion;
|
|
741
|
+
}
|
|
742
|
+
throw error;
|
|
580
743
|
}
|
|
581
|
-
const currentVersion = semver.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
582
|
-
return semver.inc(currentVersion, releaseTypeFromCommits, prereleaseIdentifier) || "";
|
|
583
744
|
} catch (error) {
|
|
584
745
|
log(`Failed to calculate version for ${name || "project"}`, "error");
|
|
585
746
|
console.error(error);
|
|
@@ -592,51 +753,37 @@ async function calculateVersion(config, options) {
|
|
|
592
753
|
}
|
|
593
754
|
function getPackageVersionFallback(pkgPath, name, releaseType, prereleaseIdentifier, initialVersion) {
|
|
594
755
|
const packageDir = pkgPath || cwd3();
|
|
595
|
-
const
|
|
596
|
-
if (
|
|
597
|
-
throw new Error(`package.json not found at ${packageJsonPath}. Cannot determine version.`);
|
|
598
|
-
}
|
|
599
|
-
try {
|
|
600
|
-
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
601
|
-
if (!packageJson.version) {
|
|
602
|
-
log(`No version found in package.json. Using initial version ${initialVersion}`, "info");
|
|
603
|
-
return initialVersion;
|
|
604
|
-
}
|
|
756
|
+
const manifestResult = getVersionFromManifests(packageDir);
|
|
757
|
+
if (manifestResult.manifestFound && manifestResult.version) {
|
|
605
758
|
log(
|
|
606
|
-
`No tags found for ${name || "package"}, using
|
|
759
|
+
`No tags found for ${name || "package"}, using ${manifestResult.manifestType} version: ${manifestResult.version} as base`,
|
|
607
760
|
"info"
|
|
608
761
|
);
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
log(
|
|
618
|
-
`Cleaning prerelease identifier from ${packageJson.version} for ${releaseType} bump`,
|
|
619
|
-
"debug"
|
|
620
|
-
);
|
|
621
|
-
return bumpVersion(packageJson.version, releaseType, prereleaseIdentifier);
|
|
622
|
-
}
|
|
623
|
-
return semver.inc(packageJson.version, releaseType, prereleaseIdentifier) || initialVersion;
|
|
624
|
-
} catch (err) {
|
|
625
|
-
throw new Error(
|
|
626
|
-
`Error reading package.json: ${err instanceof Error ? err.message : String(err)}`
|
|
762
|
+
return calculateNextVersion(
|
|
763
|
+
manifestResult.version,
|
|
764
|
+
manifestResult.manifestType || "manifest",
|
|
765
|
+
name,
|
|
766
|
+
releaseType,
|
|
767
|
+
prereleaseIdentifier,
|
|
768
|
+
initialVersion
|
|
627
769
|
);
|
|
628
770
|
}
|
|
771
|
+
throwIfNoManifestsFound(packageDir);
|
|
629
772
|
}
|
|
630
|
-
function
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
773
|
+
function calculateNextVersion(version, manifestType, name, releaseType, prereleaseIdentifier, initialVersion) {
|
|
774
|
+
log(
|
|
775
|
+
`No tags found for ${name || "package"}, using ${manifestType} version: ${version} as base`,
|
|
776
|
+
"info"
|
|
777
|
+
);
|
|
778
|
+
if (STANDARD_BUMP_TYPES.includes(releaseType) && semver2.prerelease(version)) {
|
|
779
|
+
if (version === "1.0.0-next.0" && releaseType === "major") {
|
|
780
|
+
log(`Cleaning prerelease identifier from ${version} for ${releaseType} bump`, "debug");
|
|
781
|
+
return "1.0.0";
|
|
635
782
|
}
|
|
636
|
-
log(`Cleaning prerelease identifier from ${
|
|
637
|
-
return
|
|
783
|
+
log(`Cleaning prerelease identifier from ${version} for ${releaseType} bump`, "debug");
|
|
784
|
+
return bumpVersion(version, releaseType, prereleaseIdentifier);
|
|
638
785
|
}
|
|
639
|
-
return
|
|
786
|
+
return semver2.inc(version, releaseType, prereleaseIdentifier) || initialVersion;
|
|
640
787
|
}
|
|
641
788
|
|
|
642
789
|
// src/package/packageProcessor.ts
|
|
@@ -720,29 +867,22 @@ var PackageProcessor = class {
|
|
|
720
867
|
}
|
|
721
868
|
if (!latestTagResult) {
|
|
722
869
|
try {
|
|
723
|
-
const
|
|
724
|
-
let
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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
|
-
}
|
|
870
|
+
const packageDir = pkgPath;
|
|
871
|
+
let manifestFallbackUsed = false;
|
|
872
|
+
const manifestResult = getVersionFromManifests(packageDir);
|
|
873
|
+
if (manifestResult.manifestFound && manifestResult.version) {
|
|
874
|
+
log(
|
|
875
|
+
`Using ${manifestResult.manifestType} version ${manifestResult.version} for ${name} as no package-specific tags found`,
|
|
876
|
+
"info"
|
|
877
|
+
);
|
|
878
|
+
log(
|
|
879
|
+
`FALLBACK: Using package version from ${manifestResult.manifestType} instead of global tag`,
|
|
880
|
+
"debug"
|
|
881
|
+
);
|
|
882
|
+
latestTagResult = `${this.versionPrefix || ""}${manifestResult.version}`;
|
|
883
|
+
manifestFallbackUsed = true;
|
|
744
884
|
}
|
|
745
|
-
if (!
|
|
885
|
+
if (!manifestFallbackUsed) {
|
|
746
886
|
const globalTagResult = await this.getLatestTag();
|
|
747
887
|
if (globalTagResult) {
|
|
748
888
|
latestTagResult = globalTagResult;
|
|
@@ -768,7 +908,14 @@ var PackageProcessor = class {
|
|
|
768
908
|
if (!nextVersion) {
|
|
769
909
|
continue;
|
|
770
910
|
}
|
|
771
|
-
|
|
911
|
+
const packageJsonPath = path3.join(pkgPath, "package.json");
|
|
912
|
+
const cargoTomlPath = path3.join(pkgPath, "Cargo.toml");
|
|
913
|
+
if (fs5.existsSync(packageJsonPath)) {
|
|
914
|
+
updatePackageVersion(packageJsonPath, nextVersion);
|
|
915
|
+
}
|
|
916
|
+
if (fs5.existsSync(cargoTomlPath)) {
|
|
917
|
+
updatePackageVersion(cargoTomlPath, nextVersion);
|
|
918
|
+
}
|
|
772
919
|
const packageTag = formatTag(
|
|
773
920
|
nextVersion,
|
|
774
921
|
this.versionPrefix,
|
|
@@ -799,7 +946,7 @@ var PackageProcessor = class {
|
|
|
799
946
|
log("No targeted packages required a version update.", "info");
|
|
800
947
|
return { updatedPackages: [], tags };
|
|
801
948
|
}
|
|
802
|
-
const filesToCommit = updatedPackagesInfo.map((info) =>
|
|
949
|
+
const filesToCommit = updatedPackagesInfo.map((info) => path3.join(info.path, "package.json"));
|
|
803
950
|
const packageNames = updatedPackagesInfo.map((p) => p.name).join(", ");
|
|
804
951
|
const representativeVersion = ((_a = updatedPackagesInfo[0]) == null ? void 0 : _a.version) || "multiple";
|
|
805
952
|
let commitMessage = this.commitMessageTemplate || "chore(release): publish packages";
|
|
@@ -876,8 +1023,8 @@ function createSyncedStrategy(config) {
|
|
|
876
1023
|
const files = [];
|
|
877
1024
|
const updatedPackages = [];
|
|
878
1025
|
try {
|
|
879
|
-
const rootPkgPath =
|
|
880
|
-
if (
|
|
1026
|
+
const rootPkgPath = path4.join(packages.root, "package.json");
|
|
1027
|
+
if (fs6.existsSync(rootPkgPath)) {
|
|
881
1028
|
updatePackageVersion(rootPkgPath, nextVersion);
|
|
882
1029
|
files.push(rootPkgPath);
|
|
883
1030
|
updatedPackages.push("root");
|
|
@@ -889,7 +1036,7 @@ function createSyncedStrategy(config) {
|
|
|
889
1036
|
if (!shouldProcessPackage(pkg, config)) {
|
|
890
1037
|
continue;
|
|
891
1038
|
}
|
|
892
|
-
const packageJsonPath =
|
|
1039
|
+
const packageJsonPath = path4.join(pkg.dir, "package.json");
|
|
893
1040
|
updatePackageVersion(packageJsonPath, nextVersion);
|
|
894
1041
|
files.push(packageJsonPath);
|
|
895
1042
|
updatedPackages.push(pkg.packageJson.name);
|
|
@@ -962,7 +1109,7 @@ function createSingleStrategy(config) {
|
|
|
962
1109
|
log(`No version change needed for ${packageName}`, "info");
|
|
963
1110
|
return;
|
|
964
1111
|
}
|
|
965
|
-
const packageJsonPath =
|
|
1112
|
+
const packageJsonPath = path4.join(pkgPath, "package.json");
|
|
966
1113
|
updatePackageVersion(packageJsonPath, nextVersion);
|
|
967
1114
|
log(`Updated package ${packageName} to version ${nextVersion}`, "success");
|
|
968
1115
|
const nextTag = formatTag(
|
|
@@ -1140,11 +1287,11 @@ var VersionEngine = class {
|
|
|
1140
1287
|
// src/index.ts
|
|
1141
1288
|
function getPackageVersion() {
|
|
1142
1289
|
try {
|
|
1143
|
-
const packageJsonPath =
|
|
1144
|
-
|
|
1290
|
+
const packageJsonPath = path5.resolve(
|
|
1291
|
+
path5.dirname(import.meta.url.replace("file:", "")),
|
|
1145
1292
|
"../package.json"
|
|
1146
1293
|
);
|
|
1147
|
-
const packageJsonContent =
|
|
1294
|
+
const packageJsonContent = fs7.readFileSync(packageJsonPath, "utf-8");
|
|
1148
1295
|
const packageJson = JSON.parse(packageJsonContent);
|
|
1149
1296
|
return packageJson.version || "0.0.0";
|
|
1150
1297
|
} catch (error) {
|
|
@@ -1174,7 +1321,7 @@ async function run() {
|
|
|
1174
1321
|
if (options.synced) config.synced = true;
|
|
1175
1322
|
if (options.bump) config.type = options.bump;
|
|
1176
1323
|
if (options.prerelease)
|
|
1177
|
-
config.prereleaseIdentifier = options.prerelease === true ? "
|
|
1324
|
+
config.prereleaseIdentifier = options.prerelease === true ? "next" : options.prerelease;
|
|
1178
1325
|
const cliTargets = options.target ? options.target.split(",").map((t) => t.trim()) : [];
|
|
1179
1326
|
const engine = new VersionEngine(config, !!options.json);
|
|
1180
1327
|
if (config.synced) {
|
|
@@ -134,6 +134,35 @@ This applies to all standard bump types:
|
|
|
134
134
|
- `--bump minor`: 1.0.0-beta.1 -> 1.1.0
|
|
135
135
|
- `--bump patch`: 1.0.0-beta.1 -> 1.0.1
|
|
136
136
|
|
|
137
|
+
## Package Type Support
|
|
138
|
+
|
|
139
|
+
`package-versioner` supports both JavaScript/TypeScript projects using `package.json` and Rust projects using `Cargo.toml`:
|
|
140
|
+
|
|
141
|
+
### JavaScript/TypeScript Projects
|
|
142
|
+
|
|
143
|
+
For JavaScript/TypeScript projects, the tool looks for and updates the `version` field in `package.json` files according to the versioning strategies described above.
|
|
144
|
+
|
|
145
|
+
### Rust Projects
|
|
146
|
+
|
|
147
|
+
For Rust projects, the tool looks for and updates the `package.version` field in `Cargo.toml` files using the same versioning strategies.
|
|
148
|
+
|
|
149
|
+
When no tags are found for a project, `package-versioner` will:
|
|
150
|
+
1. Look for the `version` in `package.json` if it exists
|
|
151
|
+
2. Look for the `package.version` in `Cargo.toml` if it exists
|
|
152
|
+
3. Fall back to the configured `initialVersion` (default: "0.1.0")
|
|
153
|
+
|
|
154
|
+
### Mixed Projects with Both Manifests
|
|
155
|
+
|
|
156
|
+
When both `package.json` and `Cargo.toml` exist in the same directory, `package-versioner` will:
|
|
157
|
+
|
|
158
|
+
1. Update both manifest files independently with the same calculated version
|
|
159
|
+
2. First check `package.json` for the current version (when no tags exist)
|
|
160
|
+
3. Fall back to checking `Cargo.toml` only if `package.json` doesn't exist or doesn't have a version
|
|
161
|
+
|
|
162
|
+
This allows you to maintain consistent versioning across JavaScript and Rust components in the same package.
|
|
163
|
+
|
|
164
|
+
This dual support makes `package-versioner` suitable for both JavaScript/TypeScript and Rust repositories, as well as monorepos or projects containing both types of packages.
|
|
165
|
+
|
|
137
166
|
## Tag Templates and Configuration
|
|
138
167
|
|
|
139
168
|
`package-versioner` provides flexible configuration for how Git tags are formatted, allowing you to customize the tag structure for both single package repositories and monorepos.
|
|
@@ -184,4 +213,4 @@ This would produce tags like `release-1.2.3` instead of `v1.2.3`.
|
|
|
184
213
|
"packageTagTemplate": "${packageName}-${prefix}${version}"
|
|
185
214
|
}
|
|
186
215
|
```
|
|
187
|
-
This would produce package tags like `@scope/package-name-v1.2.3` instead of `@scope/package-name@v1.2.3`.
|
|
216
|
+
This would produce package tags like `@scope/package-name-v1.2.3` instead of `@scope/package-name@v1.2.3`.
|