package-versioner 0.4.0 → 0.4.1
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 +63 -7
- package/dist/index.js +72 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -410,13 +410,16 @@ var import_node_path3 = __toESM(require("path"), 1);
|
|
|
410
410
|
var import_node_process4 = require("process");
|
|
411
411
|
|
|
412
412
|
// src/core/versionCalculator.ts
|
|
413
|
+
var fs3 = __toESM(require("fs"), 1);
|
|
414
|
+
var path2 = __toESM(require("path"), 1);
|
|
413
415
|
var import_node_process3 = require("process");
|
|
414
416
|
var import_conventional_recommended_bump = require("conventional-recommended-bump");
|
|
415
417
|
var import_semver = __toESM(require("semver"), 1);
|
|
416
418
|
async function calculateVersion(config, options) {
|
|
417
|
-
const { latestTag, type, path:
|
|
419
|
+
const { latestTag, type, path: pkgPath, name, branchPattern, prereleaseIdentifier } = options;
|
|
418
420
|
const originalPrefix = config.tagPrefix || "v";
|
|
419
421
|
const initialVersion = prereleaseIdentifier ? `0.0.1-${prereleaseIdentifier}` : "0.0.1";
|
|
422
|
+
const hasNoTags = !latestTag || latestTag === "";
|
|
420
423
|
function determineTagSearchPattern(packageName, prefix) {
|
|
421
424
|
if (packageName) {
|
|
422
425
|
return prefix ? `${prefix}${packageName}@` : `${packageName}@`;
|
|
@@ -427,8 +430,14 @@ async function calculateVersion(config, options) {
|
|
|
427
430
|
const escapedTagPattern = escapeRegExp(tagSearchPattern);
|
|
428
431
|
let determinedReleaseType = type || null;
|
|
429
432
|
if (determinedReleaseType) {
|
|
430
|
-
if (
|
|
431
|
-
return
|
|
433
|
+
if (hasNoTags) {
|
|
434
|
+
return getPackageVersionFallback(
|
|
435
|
+
pkgPath,
|
|
436
|
+
name,
|
|
437
|
+
determinedReleaseType,
|
|
438
|
+
prereleaseIdentifier,
|
|
439
|
+
initialVersion
|
|
440
|
+
);
|
|
432
441
|
}
|
|
433
442
|
const currentVersion = import_semver.default.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
434
443
|
const standardBumpTypes = ["major", "minor", "patch"];
|
|
@@ -453,8 +462,14 @@ async function calculateVersion(config, options) {
|
|
|
453
462
|
}
|
|
454
463
|
}
|
|
455
464
|
if (determinedReleaseType) {
|
|
456
|
-
if (
|
|
457
|
-
return
|
|
465
|
+
if (hasNoTags) {
|
|
466
|
+
return getPackageVersionFallback(
|
|
467
|
+
pkgPath,
|
|
468
|
+
name,
|
|
469
|
+
determinedReleaseType,
|
|
470
|
+
prereleaseIdentifier,
|
|
471
|
+
initialVersion
|
|
472
|
+
);
|
|
458
473
|
}
|
|
459
474
|
const currentVersion = import_semver.default.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
460
475
|
return import_semver.default.inc(currentVersion, determinedReleaseType, prereleaseIdentifier) || "";
|
|
@@ -465,10 +480,19 @@ async function calculateVersion(config, options) {
|
|
|
465
480
|
bumper.loadPreset(config.preset);
|
|
466
481
|
const recommendedBump = await bumper.bump();
|
|
467
482
|
const releaseTypeFromCommits = recommendedBump.releaseType;
|
|
468
|
-
if (
|
|
483
|
+
if (hasNoTags) {
|
|
484
|
+
if (releaseTypeFromCommits) {
|
|
485
|
+
return getPackageVersionFallback(
|
|
486
|
+
pkgPath,
|
|
487
|
+
name,
|
|
488
|
+
releaseTypeFromCommits,
|
|
489
|
+
prereleaseIdentifier,
|
|
490
|
+
initialVersion
|
|
491
|
+
);
|
|
492
|
+
}
|
|
469
493
|
return initialVersion;
|
|
470
494
|
}
|
|
471
|
-
const checkPath =
|
|
495
|
+
const checkPath = pkgPath || (0, import_node_process3.cwd)();
|
|
472
496
|
const commitsLength = getCommitsLength(checkPath);
|
|
473
497
|
if (commitsLength === 0) {
|
|
474
498
|
log(
|
|
@@ -496,6 +520,38 @@ async function calculateVersion(config, options) {
|
|
|
496
520
|
throw error;
|
|
497
521
|
}
|
|
498
522
|
}
|
|
523
|
+
function getPackageVersionFallback(pkgPath, name, releaseType, prereleaseIdentifier, initialVersion) {
|
|
524
|
+
const packageDir = pkgPath || (0, import_node_process3.cwd)();
|
|
525
|
+
const packageJsonPath = path2.join(packageDir, "package.json");
|
|
526
|
+
if (!fs3.existsSync(packageJsonPath)) {
|
|
527
|
+
throw new Error(`package.json not found at ${packageJsonPath}. Cannot determine version.`);
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
530
|
+
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
531
|
+
if (!packageJson.version) {
|
|
532
|
+
log(`No version found in package.json. Using initial version ${initialVersion}`, "info");
|
|
533
|
+
return initialVersion;
|
|
534
|
+
}
|
|
535
|
+
log(
|
|
536
|
+
`No tags found for ${name || "package"}, using package.json version: ${packageJson.version} as base`,
|
|
537
|
+
"info"
|
|
538
|
+
);
|
|
539
|
+
const standardBumpTypes = ["major", "minor", "patch"];
|
|
540
|
+
if (standardBumpTypes.includes(releaseType) && import_semver.default.prerelease(packageJson.version)) {
|
|
541
|
+
log(
|
|
542
|
+
`Cleaning prerelease identifier from ${packageJson.version} for ${releaseType} bump`,
|
|
543
|
+
"debug"
|
|
544
|
+
);
|
|
545
|
+
const cleanVersion = import_semver.default.inc(packageJson.version, "patch") || packageJson.version;
|
|
546
|
+
return import_semver.default.inc(cleanVersion, releaseType) || initialVersion;
|
|
547
|
+
}
|
|
548
|
+
return import_semver.default.inc(packageJson.version, releaseType, prereleaseIdentifier) || initialVersion;
|
|
549
|
+
} catch (err) {
|
|
550
|
+
throw new Error(
|
|
551
|
+
`Error reading package.json: ${err instanceof Error ? err.message : String(err)}`
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
499
555
|
|
|
500
556
|
// src/package/packageProcessor.ts
|
|
501
557
|
var PackageProcessor = class {
|
package/dist/index.js
CHANGED
|
@@ -142,8 +142,8 @@ function log(message, status = "info") {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// src/core/versionStrategies.ts
|
|
145
|
-
import
|
|
146
|
-
import
|
|
145
|
+
import fs4 from "node:fs";
|
|
146
|
+
import path3 from "node:path";
|
|
147
147
|
|
|
148
148
|
// src/git/commands.ts
|
|
149
149
|
import { cwd as cwd2 } from "node:process";
|
|
@@ -382,17 +382,20 @@ function updatePackageVersion(packagePath, version) {
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
// src/package/packageProcessor.ts
|
|
385
|
-
import
|
|
385
|
+
import path2 from "node:path";
|
|
386
386
|
import { exit } from "node:process";
|
|
387
387
|
|
|
388
388
|
// src/core/versionCalculator.ts
|
|
389
|
+
import * as fs3 from "node:fs";
|
|
390
|
+
import * as path from "node:path";
|
|
389
391
|
import { cwd as cwd3 } from "node:process";
|
|
390
392
|
import { Bumper } from "conventional-recommended-bump";
|
|
391
393
|
import semver from "semver";
|
|
392
394
|
async function calculateVersion(config, options) {
|
|
393
|
-
const { latestTag, type, path:
|
|
395
|
+
const { latestTag, type, path: pkgPath, name, branchPattern, prereleaseIdentifier } = options;
|
|
394
396
|
const originalPrefix = config.tagPrefix || "v";
|
|
395
397
|
const initialVersion = prereleaseIdentifier ? `0.0.1-${prereleaseIdentifier}` : "0.0.1";
|
|
398
|
+
const hasNoTags = !latestTag || latestTag === "";
|
|
396
399
|
function determineTagSearchPattern(packageName, prefix) {
|
|
397
400
|
if (packageName) {
|
|
398
401
|
return prefix ? `${prefix}${packageName}@` : `${packageName}@`;
|
|
@@ -403,8 +406,14 @@ async function calculateVersion(config, options) {
|
|
|
403
406
|
const escapedTagPattern = escapeRegExp(tagSearchPattern);
|
|
404
407
|
let determinedReleaseType = type || null;
|
|
405
408
|
if (determinedReleaseType) {
|
|
406
|
-
if (
|
|
407
|
-
return
|
|
409
|
+
if (hasNoTags) {
|
|
410
|
+
return getPackageVersionFallback(
|
|
411
|
+
pkgPath,
|
|
412
|
+
name,
|
|
413
|
+
determinedReleaseType,
|
|
414
|
+
prereleaseIdentifier,
|
|
415
|
+
initialVersion
|
|
416
|
+
);
|
|
408
417
|
}
|
|
409
418
|
const currentVersion = semver.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
410
419
|
const standardBumpTypes = ["major", "minor", "patch"];
|
|
@@ -429,8 +438,14 @@ async function calculateVersion(config, options) {
|
|
|
429
438
|
}
|
|
430
439
|
}
|
|
431
440
|
if (determinedReleaseType) {
|
|
432
|
-
if (
|
|
433
|
-
return
|
|
441
|
+
if (hasNoTags) {
|
|
442
|
+
return getPackageVersionFallback(
|
|
443
|
+
pkgPath,
|
|
444
|
+
name,
|
|
445
|
+
determinedReleaseType,
|
|
446
|
+
prereleaseIdentifier,
|
|
447
|
+
initialVersion
|
|
448
|
+
);
|
|
434
449
|
}
|
|
435
450
|
const currentVersion = semver.clean(latestTag.replace(new RegExp(`^${escapedTagPattern}`), "")) || "0.0.0";
|
|
436
451
|
return semver.inc(currentVersion, determinedReleaseType, prereleaseIdentifier) || "";
|
|
@@ -441,10 +456,19 @@ async function calculateVersion(config, options) {
|
|
|
441
456
|
bumper.loadPreset(config.preset);
|
|
442
457
|
const recommendedBump = await bumper.bump();
|
|
443
458
|
const releaseTypeFromCommits = recommendedBump.releaseType;
|
|
444
|
-
if (
|
|
459
|
+
if (hasNoTags) {
|
|
460
|
+
if (releaseTypeFromCommits) {
|
|
461
|
+
return getPackageVersionFallback(
|
|
462
|
+
pkgPath,
|
|
463
|
+
name,
|
|
464
|
+
releaseTypeFromCommits,
|
|
465
|
+
prereleaseIdentifier,
|
|
466
|
+
initialVersion
|
|
467
|
+
);
|
|
468
|
+
}
|
|
445
469
|
return initialVersion;
|
|
446
470
|
}
|
|
447
|
-
const checkPath =
|
|
471
|
+
const checkPath = pkgPath || cwd3();
|
|
448
472
|
const commitsLength = getCommitsLength(checkPath);
|
|
449
473
|
if (commitsLength === 0) {
|
|
450
474
|
log(
|
|
@@ -472,6 +496,38 @@ async function calculateVersion(config, options) {
|
|
|
472
496
|
throw error;
|
|
473
497
|
}
|
|
474
498
|
}
|
|
499
|
+
function getPackageVersionFallback(pkgPath, name, releaseType, prereleaseIdentifier, initialVersion) {
|
|
500
|
+
const packageDir = pkgPath || cwd3();
|
|
501
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
502
|
+
if (!fs3.existsSync(packageJsonPath)) {
|
|
503
|
+
throw new Error(`package.json not found at ${packageJsonPath}. Cannot determine version.`);
|
|
504
|
+
}
|
|
505
|
+
try {
|
|
506
|
+
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
507
|
+
if (!packageJson.version) {
|
|
508
|
+
log(`No version found in package.json. Using initial version ${initialVersion}`, "info");
|
|
509
|
+
return initialVersion;
|
|
510
|
+
}
|
|
511
|
+
log(
|
|
512
|
+
`No tags found for ${name || "package"}, using package.json version: ${packageJson.version} as base`,
|
|
513
|
+
"info"
|
|
514
|
+
);
|
|
515
|
+
const standardBumpTypes = ["major", "minor", "patch"];
|
|
516
|
+
if (standardBumpTypes.includes(releaseType) && semver.prerelease(packageJson.version)) {
|
|
517
|
+
log(
|
|
518
|
+
`Cleaning prerelease identifier from ${packageJson.version} for ${releaseType} bump`,
|
|
519
|
+
"debug"
|
|
520
|
+
);
|
|
521
|
+
const cleanVersion = semver.inc(packageJson.version, "patch") || packageJson.version;
|
|
522
|
+
return semver.inc(cleanVersion, releaseType) || initialVersion;
|
|
523
|
+
}
|
|
524
|
+
return semver.inc(packageJson.version, releaseType, prereleaseIdentifier) || initialVersion;
|
|
525
|
+
} catch (err) {
|
|
526
|
+
throw new Error(
|
|
527
|
+
`Error reading package.json: ${err instanceof Error ? err.message : String(err)}`
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
475
531
|
|
|
476
532
|
// src/package/packageProcessor.ts
|
|
477
533
|
var PackageProcessor = class {
|
|
@@ -554,7 +610,7 @@ var PackageProcessor = class {
|
|
|
554
610
|
if (!nextVersion) {
|
|
555
611
|
continue;
|
|
556
612
|
}
|
|
557
|
-
updatePackageVersion(
|
|
613
|
+
updatePackageVersion(path2.join(pkgPath, "package.json"), nextVersion);
|
|
558
614
|
const packageTag = formatTag(nextVersion, tagPrefix);
|
|
559
615
|
const tagMessage = `chore(release): ${name} ${nextVersion}`;
|
|
560
616
|
addTag(packageTag);
|
|
@@ -579,7 +635,7 @@ var PackageProcessor = class {
|
|
|
579
635
|
log("No targeted packages required a version update.", "info");
|
|
580
636
|
return { updatedPackages: [], tags };
|
|
581
637
|
}
|
|
582
|
-
const filesToCommit = updatedPackagesInfo.map((info) =>
|
|
638
|
+
const filesToCommit = updatedPackagesInfo.map((info) => path2.join(info.path, "package.json"));
|
|
583
639
|
const packageNames = updatedPackagesInfo.map((p) => p.name).join(", ");
|
|
584
640
|
const representativeVersion = ((_a = updatedPackagesInfo[0]) == null ? void 0 : _a.version) || "multiple";
|
|
585
641
|
let commitMessage = this.commitMessageTemplate || "chore(release): publish packages";
|
|
@@ -655,8 +711,8 @@ function createSyncedStrategy(config) {
|
|
|
655
711
|
const files = [];
|
|
656
712
|
const updatedPackages = [];
|
|
657
713
|
try {
|
|
658
|
-
const rootPkgPath =
|
|
659
|
-
if (
|
|
714
|
+
const rootPkgPath = path3.join(packages.root, "package.json");
|
|
715
|
+
if (fs4.existsSync(rootPkgPath)) {
|
|
660
716
|
updatePackageVersion(rootPkgPath, nextVersion);
|
|
661
717
|
files.push(rootPkgPath);
|
|
662
718
|
updatedPackages.push("root");
|
|
@@ -668,7 +724,7 @@ function createSyncedStrategy(config) {
|
|
|
668
724
|
if (!shouldProcessPackage(pkg, config)) {
|
|
669
725
|
continue;
|
|
670
726
|
}
|
|
671
|
-
const packageJsonPath =
|
|
727
|
+
const packageJsonPath = path3.join(pkg.dir, "package.json");
|
|
672
728
|
updatePackageVersion(packageJsonPath, nextVersion);
|
|
673
729
|
files.push(packageJsonPath);
|
|
674
730
|
updatedPackages.push(pkg.packageJson.name);
|
|
@@ -733,7 +789,7 @@ function createSingleStrategy(config) {
|
|
|
733
789
|
log(`No version change needed for ${packageName}`, "info");
|
|
734
790
|
return;
|
|
735
791
|
}
|
|
736
|
-
const packageJsonPath =
|
|
792
|
+
const packageJsonPath = path3.join(pkgPath, "package.json");
|
|
737
793
|
updatePackageVersion(packageJsonPath, nextVersion);
|
|
738
794
|
log(`Updated package ${packageName} to version ${nextVersion}`, "success");
|
|
739
795
|
const nextTag = formatTag(nextVersion, tagPrefix || "v");
|
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.4.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|