fork-version 4.1.4 → 4.1.7
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/CHANGELOG.md +24 -0
- package/README.md +7 -4
- package/dist/{chunk-I76EAKJC.js → chunk-5CZU5EA7.js} +170 -129
- package/dist/chunk-5CZU5EA7.js.map +1 -0
- package/dist/{chunk-CISRFIID.cjs → chunk-JYQTKLHN.cjs} +171 -131
- package/dist/chunk-JYQTKLHN.cjs.map +1 -0
- package/dist/cli.cjs +16 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +10 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +19 -23
- package/dist/index.d.cts +73 -82
- package/dist/index.d.ts +73 -82
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-CISRFIID.cjs.map +0 -1
- package/dist/chunk-I76EAKJC.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Fork Version
|
|
2
2
|
|
|
3
|
+
## [4.1.7](https://github.com/eglavin/fork-version/compare/v4.1.6...v4.1.7) (2026-03-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Refactor
|
|
7
|
+
|
|
8
|
+
* improve inspect command ([0b78aab](https://github.com/eglavin/fork-version/commit/0b78aab5dd9be49ffccba173fdb99e13eac52fbd))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## [4.1.6](https://github.com/eglavin/fork-version/compare/v4.1.5...v4.1.6) (2026-03-08)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Refactor
|
|
15
|
+
|
|
16
|
+
* remove duplicate get tags function ([ec2962a](https://github.com/eglavin/fork-version/commit/ec2962a99f0da0335079ef6fa677f3023325cdcf))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [4.1.5](https://github.com/eglavin/fork-version/compare/v4.1.4...v4.1.5) (2026-03-08)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Refactor
|
|
23
|
+
|
|
24
|
+
* remove typescript member visibility modifiers in favour of private fields ([c2e0749](https://github.com/eglavin/fork-version/commit/c2e07494bb2af69f04c0ecfc13eb342705c904aa))
|
|
25
|
+
|
|
26
|
+
|
|
3
27
|
## [4.1.4](https://github.com/eglavin/fork-version/compare/v4.1.3...v4.1.4) (2026-03-08)
|
|
4
28
|
|
|
5
29
|
|
package/README.md
CHANGED
|
@@ -94,8 +94,9 @@ Fork-Version has a number of command modes which will make the program behave di
|
|
|
94
94
|
| Command | Description |
|
|
95
95
|
| ------------------- | ---------------------------------------------------------------------- |
|
|
96
96
|
| `main` | Bumps the version, update files, generate changelog, commits, and tag. |
|
|
97
|
-
| `inspect
|
|
98
|
-
| `inspect-
|
|
97
|
+
| `inspect` | Print the current version and git tag, then exit. |
|
|
98
|
+
| `inspect-version` | Print the current version then exit. |
|
|
99
|
+
| `inspect-tag` | Print the current git tag then exit. |
|
|
99
100
|
| `validate-config` | Validates the configuration and exit. |
|
|
100
101
|
|
|
101
102
|
### Exit Codes
|
|
@@ -121,8 +122,9 @@ Usage:
|
|
|
121
122
|
|
|
122
123
|
Commands:
|
|
123
124
|
main Bumps the version, update files, generate changelog, commit, and tag. [Default when no command is provided]
|
|
124
|
-
inspect
|
|
125
|
-
inspect-
|
|
125
|
+
inspect Print the current version and git tag, then exits.
|
|
126
|
+
inspect-version Print the current version then exits.
|
|
127
|
+
inspect-tag Print the current git tag then exits.
|
|
126
128
|
validate-config Validates the configuration and exits.
|
|
127
129
|
|
|
128
130
|
General Options:
|
|
@@ -154,6 +156,7 @@ Flags:
|
|
|
154
156
|
--git-tag-fallback If unable to find a version in the given files, fallback and attempt to use the latest git tag. [Default: true]
|
|
155
157
|
--sign If true, git will sign the commit with the systems GPG key.
|
|
156
158
|
--verify If true, git will run user defined git hooks before committing.
|
|
159
|
+
--as-json Output the result as JSON.
|
|
157
160
|
|
|
158
161
|
To negate a flag you can prefix it with "no-", for example "--no-git-tag-fallback" will not fallback to the latest git tag.
|
|
159
162
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { execFile } from 'child_process';
|
|
3
|
-
import
|
|
3
|
+
import semver5 from 'semver';
|
|
4
4
|
import { resolve, join, isAbsolute, parse, basename } from 'path';
|
|
5
5
|
import { glob } from 'fs/promises';
|
|
6
6
|
import conventionalChangelogConfigSpec from 'conventional-changelog-config-spec';
|
|
@@ -80,12 +80,13 @@ var ForkConfigSchema = z.object({
|
|
|
80
80
|
* - `main` - Bumps the version, update files, generate changelog, commit, and tag.
|
|
81
81
|
* - `inspect-version` - Prints the current version and exits.
|
|
82
82
|
* - `inspect-tag` - Prints the current git tag and exits.
|
|
83
|
+
* - `inspect` - Prints the current version and git tag and exits.
|
|
83
84
|
* - `validate-config` - Validates the configuration and exits.
|
|
84
85
|
*
|
|
85
86
|
* @default "main"
|
|
86
87
|
*/
|
|
87
|
-
command: z.literal(["main", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
88
|
-
"The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
88
|
+
command: z.literal(["main", "inspect", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
89
|
+
"The command to run. Can be one of: main, inspect, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
89
90
|
),
|
|
90
91
|
/**
|
|
91
92
|
* If set, Fork-Version will print the current version and exit.
|
|
@@ -248,6 +249,11 @@ var ForkConfigSchema = z.object({
|
|
|
248
249
|
* @default false
|
|
249
250
|
*/
|
|
250
251
|
verify: z.boolean().describe("If true, git will run user defined git hooks before committing."),
|
|
252
|
+
/**
|
|
253
|
+
* Output result as JSON.
|
|
254
|
+
* @default false
|
|
255
|
+
*/
|
|
256
|
+
asJson: z.boolean().describe("Output the result as JSON."),
|
|
251
257
|
// Skip Steps
|
|
252
258
|
//
|
|
253
259
|
/**
|
|
@@ -290,8 +296,11 @@ function escapeRegex(input) {
|
|
|
290
296
|
|
|
291
297
|
// src/services/git.ts
|
|
292
298
|
var Git = class {
|
|
299
|
+
#path;
|
|
300
|
+
#dryRun;
|
|
293
301
|
constructor(config) {
|
|
294
|
-
this
|
|
302
|
+
this.#path = config.path;
|
|
303
|
+
this.#dryRun = config.dryRun ?? false;
|
|
295
304
|
this.add = this.add.bind(this);
|
|
296
305
|
this.commit = this.commit.bind(this);
|
|
297
306
|
this.tag = this.tag.bind(this);
|
|
@@ -301,8 +310,6 @@ var Git = class {
|
|
|
301
310
|
this.getRemoteUrl = this.getRemoteUrl.bind(this);
|
|
302
311
|
this.getTags = this.getTags.bind(this);
|
|
303
312
|
this.getMostRecentTag = this.getMostRecentTag.bind(this);
|
|
304
|
-
this.getCleanedTags = this.getCleanedTags.bind(this);
|
|
305
|
-
this.getHighestSemverVersionFromTags = this.getHighestSemverVersionFromTags.bind(this);
|
|
306
313
|
this.getCommits = this.getCommits.bind(this);
|
|
307
314
|
}
|
|
308
315
|
async #execGit(command, args) {
|
|
@@ -311,7 +318,7 @@ var Git = class {
|
|
|
311
318
|
"git",
|
|
312
319
|
[command, ...args],
|
|
313
320
|
{
|
|
314
|
-
cwd: this
|
|
321
|
+
cwd: this.#path,
|
|
315
322
|
maxBuffer: Infinity
|
|
316
323
|
},
|
|
317
324
|
(error, stdout, stderr) => {
|
|
@@ -335,7 +342,7 @@ var Git = class {
|
|
|
335
342
|
* ```
|
|
336
343
|
*/
|
|
337
344
|
async add(...args) {
|
|
338
|
-
if (this
|
|
345
|
+
if (this.#dryRun) {
|
|
339
346
|
return "";
|
|
340
347
|
}
|
|
341
348
|
return this.#execGit("add", args.filter(Boolean));
|
|
@@ -351,7 +358,7 @@ var Git = class {
|
|
|
351
358
|
* ```
|
|
352
359
|
*/
|
|
353
360
|
async commit(...args) {
|
|
354
|
-
if (this
|
|
361
|
+
if (this.#dryRun) {
|
|
355
362
|
return "";
|
|
356
363
|
}
|
|
357
364
|
return this.#execGit("commit", args.filter(Boolean));
|
|
@@ -367,7 +374,7 @@ var Git = class {
|
|
|
367
374
|
* ```
|
|
368
375
|
*/
|
|
369
376
|
async tag(...args) {
|
|
370
|
-
if (this
|
|
377
|
+
if (this.#dryRun) {
|
|
371
378
|
return "";
|
|
372
379
|
}
|
|
373
380
|
return this.#execGit("tag", args.filter(Boolean));
|
|
@@ -476,18 +483,18 @@ var Git = class {
|
|
|
476
483
|
if (tagPrefix) {
|
|
477
484
|
if (tag.startsWith(tagPrefix)) {
|
|
478
485
|
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
479
|
-
if (
|
|
486
|
+
if (semver5.valid(tagWithoutPrefix)) {
|
|
480
487
|
tags.push(tag);
|
|
481
488
|
}
|
|
482
489
|
}
|
|
483
|
-
} else if (/^\d/.test(tag) &&
|
|
490
|
+
} else if (/^\d/.test(tag) && semver5.valid(tag)) {
|
|
484
491
|
tags.push(tag);
|
|
485
492
|
}
|
|
486
493
|
}
|
|
487
494
|
return tags;
|
|
488
495
|
}
|
|
489
496
|
/**
|
|
490
|
-
* Returns the
|
|
497
|
+
* Returns the most recent tag from the commit history, or `undefined` if no valid semver tags are found
|
|
491
498
|
*
|
|
492
499
|
* @example
|
|
493
500
|
* ```ts
|
|
@@ -498,40 +505,6 @@ var Git = class {
|
|
|
498
505
|
const tags = await this.getTags(tagPrefix);
|
|
499
506
|
return tags[0] || void 0;
|
|
500
507
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Get cleaned semver tags, with any tag prefix's removed
|
|
503
|
-
*
|
|
504
|
-
* @example
|
|
505
|
-
* ```ts
|
|
506
|
-
* await git.getCleanedTags("v"); // ["1.2.3", "1.2.2", "1.2.1"]
|
|
507
|
-
* ```
|
|
508
|
-
*/
|
|
509
|
-
async getCleanedTags(tagPrefix) {
|
|
510
|
-
const tags = await this.getTags(tagPrefix);
|
|
511
|
-
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
512
|
-
const cleanedTags = [];
|
|
513
|
-
for (const tag of tags) {
|
|
514
|
-
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
515
|
-
const cleanedTag = semver.clean(tagWithoutPrefix);
|
|
516
|
-
if (cleanedTag) {
|
|
517
|
-
cleanedTags.push(cleanedTag);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return cleanedTags;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Get the highest semver version from git tags. This will return the highest
|
|
524
|
-
* semver version found for the given tag prefix, regardless of the commit date.
|
|
525
|
-
*
|
|
526
|
-
* @example
|
|
527
|
-
* ```ts
|
|
528
|
-
* await git.getHighestSemverVersionFromTags("v"); // "1.2.3"
|
|
529
|
-
* ```
|
|
530
|
-
*/
|
|
531
|
-
async getHighestSemverVersionFromTags(tagPrefix) {
|
|
532
|
-
const cleanedTags = await this.getCleanedTags(tagPrefix);
|
|
533
|
-
return cleanedTags.sort(semver.rcompare)[0] || void 0;
|
|
534
|
-
}
|
|
535
508
|
/**
|
|
536
509
|
* Get commit history in a parsable format
|
|
537
510
|
*
|
|
@@ -686,6 +659,7 @@ All notable changes to this project will be documented in this file. See [fork-v
|
|
|
686
659
|
gitTagFallback: true,
|
|
687
660
|
sign: false,
|
|
688
661
|
verify: false,
|
|
662
|
+
asJson: false,
|
|
689
663
|
// Skip Steps
|
|
690
664
|
skipBump: false,
|
|
691
665
|
skipChangelog: false,
|
|
@@ -695,11 +669,8 @@ All notable changes to this project will be documented in this file. See [fork-v
|
|
|
695
669
|
};
|
|
696
670
|
|
|
697
671
|
// src/config/detect-git-host.ts
|
|
698
|
-
async function detectGitHost(
|
|
699
|
-
const remoteUrl = await new Git({
|
|
700
|
-
path: cwd,
|
|
701
|
-
dryRun: false
|
|
702
|
-
}).getRemoteUrl();
|
|
672
|
+
async function detectGitHost(path) {
|
|
673
|
+
const remoteUrl = await new Git({ path }).getRemoteUrl();
|
|
703
674
|
if (remoteUrl.startsWith("https://") && remoteUrl.includes("@dev.azure.com/")) {
|
|
704
675
|
const match = /^https:\/\/(?<atorganisation>.*?)@dev.azure.com\/(?<organisation>.*?)\/(?<project>.*?)\/_git\/(?<repository>.*?)(?:\.git)?$/.exec(
|
|
705
676
|
remoteUrl
|
|
@@ -843,33 +814,34 @@ async function getUserConfig(cliArguments) {
|
|
|
843
814
|
};
|
|
844
815
|
}
|
|
845
816
|
var Logger = class {
|
|
817
|
+
#silent;
|
|
818
|
+
#debug;
|
|
846
819
|
constructor(config) {
|
|
847
|
-
this
|
|
820
|
+
this.#silent = config.silent ?? false;
|
|
821
|
+
this.#debug = config.debug ?? false;
|
|
848
822
|
this.log = this.log.bind(this);
|
|
849
823
|
this.warn = this.warn.bind(this);
|
|
850
824
|
this.error = this.error.bind(this);
|
|
851
825
|
this.debug = this.debug.bind(this);
|
|
852
826
|
this.skipping = this.skipping.bind(this);
|
|
853
|
-
this.disableLogs = this.config.silent;
|
|
854
827
|
}
|
|
855
|
-
disableLogs = false;
|
|
856
828
|
log(message) {
|
|
857
|
-
if (!this
|
|
829
|
+
if (!this.#silent) {
|
|
858
830
|
console.log(message);
|
|
859
831
|
}
|
|
860
832
|
}
|
|
861
833
|
warn(message) {
|
|
862
|
-
if (!this
|
|
834
|
+
if (!this.#silent) {
|
|
863
835
|
console.warn(styleText("yellowBright", message));
|
|
864
836
|
}
|
|
865
837
|
}
|
|
866
838
|
error(message) {
|
|
867
|
-
if (!this
|
|
839
|
+
if (!this.#silent) {
|
|
868
840
|
console.error(styleText("redBright", message));
|
|
869
841
|
}
|
|
870
842
|
}
|
|
871
843
|
debug(message, ...optionalParams) {
|
|
872
|
-
if (this
|
|
844
|
+
if (!this.#silent && this.#debug) {
|
|
873
845
|
console.debug(styleText("cyanBright", message));
|
|
874
846
|
if (optionalParams.length > 0) {
|
|
875
847
|
console.debug(...optionalParams);
|
|
@@ -877,7 +849,7 @@ var Logger = class {
|
|
|
877
849
|
}
|
|
878
850
|
}
|
|
879
851
|
skipping(message) {
|
|
880
|
-
if (!this
|
|
852
|
+
if (!this.#silent) {
|
|
881
853
|
console.log(styleText("magenta", message));
|
|
882
854
|
}
|
|
883
855
|
}
|
|
@@ -1205,66 +1177,6 @@ ${JSON.stringify(config, null, 2)}
|
|
|
1205
1177
|
\u2705 Configuration is valid.
|
|
1206
1178
|
`);
|
|
1207
1179
|
}
|
|
1208
|
-
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1209
|
-
const files = [];
|
|
1210
|
-
const versions = /* @__PURE__ */ new Set();
|
|
1211
|
-
for (const file of filesToUpdate) {
|
|
1212
|
-
if (await git.isIgnored(file)) {
|
|
1213
|
-
logger.debug(`[Git Ignored] ${file}`);
|
|
1214
|
-
continue;
|
|
1215
|
-
}
|
|
1216
|
-
const fileState = fileManager.read(file);
|
|
1217
|
-
if (fileState) {
|
|
1218
|
-
files.push(fileState);
|
|
1219
|
-
if (!config.currentVersion) {
|
|
1220
|
-
versions.add(fileState.version);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
if (config.currentVersion) {
|
|
1225
|
-
versions.add(config.currentVersion);
|
|
1226
|
-
}
|
|
1227
|
-
if (versions.size === 0 && config.gitTagFallback) {
|
|
1228
|
-
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1229
|
-
if (version) {
|
|
1230
|
-
logger.warn(`Using latest git tag as fallback`);
|
|
1231
|
-
versions.add(version);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
if (versions.size === 0) {
|
|
1235
|
-
throw new Error("Unable to find current version");
|
|
1236
|
-
} else if (versions.size > 1) {
|
|
1237
|
-
if (!config.allowMultipleVersions) {
|
|
1238
|
-
throw new Error("Found multiple versions");
|
|
1239
|
-
}
|
|
1240
|
-
logger.warn(
|
|
1241
|
-
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
const currentVersion = semver.rsort(Array.from(versions))[0];
|
|
1245
|
-
logger.log(`Current version: ${currentVersion}`);
|
|
1246
|
-
return {
|
|
1247
|
-
files,
|
|
1248
|
-
version: currentVersion
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
// src/commands/inspect-version.ts
|
|
1253
|
-
async function inspectVersion(config, logger, fileManager, git) {
|
|
1254
|
-
let foundVersion = "";
|
|
1255
|
-
try {
|
|
1256
|
-
const currentVersion = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1257
|
-
if (currentVersion) foundVersion = currentVersion.version;
|
|
1258
|
-
} catch {
|
|
1259
|
-
}
|
|
1260
|
-
console.log(foundVersion);
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
// src/commands/inspect-tag.ts
|
|
1264
|
-
async function inspectTag(config, git) {
|
|
1265
|
-
const tag = await git.getMostRecentTag(config.tagPrefix);
|
|
1266
|
-
console.log(tag ?? "");
|
|
1267
|
-
}
|
|
1268
1180
|
|
|
1269
1181
|
// src/utils/trim-string-array.ts
|
|
1270
1182
|
function trimStringArray(array) {
|
|
@@ -1728,6 +1640,12 @@ function filterRevertedCommits(parsedCommits) {
|
|
|
1728
1640
|
}
|
|
1729
1641
|
return commitsWithoutReverts;
|
|
1730
1642
|
}
|
|
1643
|
+
function cleanTag(tag, tagPrefix) {
|
|
1644
|
+
if (!tag) return void 0;
|
|
1645
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
1646
|
+
const tagWithoutPrefix = escapedTagPrefix ? tag.replace(new RegExp(`^${escapedTagPrefix}`), "") : tag;
|
|
1647
|
+
return semver5.clean(tagWithoutPrefix) ?? void 0;
|
|
1648
|
+
}
|
|
1731
1649
|
|
|
1732
1650
|
// src/process/get-commits.ts
|
|
1733
1651
|
async function getCommitsSinceTag(config, logger, git) {
|
|
@@ -1751,14 +1669,130 @@ async function getCommitsSinceTag(config, logger, git) {
|
|
|
1751
1669
|
);
|
|
1752
1670
|
return {
|
|
1753
1671
|
latestTag,
|
|
1672
|
+
latestTagVersion: cleanTag(latestTag, config.tagPrefix),
|
|
1754
1673
|
commits: filteredCommits
|
|
1755
1674
|
};
|
|
1756
1675
|
}
|
|
1676
|
+
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate, latestTagVersion) {
|
|
1677
|
+
const files = [];
|
|
1678
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1679
|
+
for (const file of filesToUpdate) {
|
|
1680
|
+
if (await git.isIgnored(file)) {
|
|
1681
|
+
logger.debug(`[Git Ignored] ${file}`);
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
const fileState = fileManager.read(file);
|
|
1685
|
+
if (fileState) {
|
|
1686
|
+
files.push(fileState);
|
|
1687
|
+
if (!config.currentVersion) {
|
|
1688
|
+
versions.add(fileState.version);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
if (config.currentVersion) {
|
|
1693
|
+
versions.add(config.currentVersion);
|
|
1694
|
+
}
|
|
1695
|
+
if (versions.size === 0 && config.gitTagFallback && latestTagVersion) {
|
|
1696
|
+
logger.warn(`Using latest git tag as fallback`);
|
|
1697
|
+
versions.add(latestTagVersion);
|
|
1698
|
+
}
|
|
1699
|
+
if (versions.size === 0) {
|
|
1700
|
+
throw new Error("Unable to find current version");
|
|
1701
|
+
} else if (versions.size > 1) {
|
|
1702
|
+
if (!config.allowMultipleVersions) {
|
|
1703
|
+
throw new Error("Found multiple versions");
|
|
1704
|
+
}
|
|
1705
|
+
logger.warn(
|
|
1706
|
+
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1709
|
+
const currentVersion = semver5.rsort(Array.from(versions))[0];
|
|
1710
|
+
logger.log(`Current version: ${currentVersion}`);
|
|
1711
|
+
return {
|
|
1712
|
+
files,
|
|
1713
|
+
version: currentVersion
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
async function inspect(config, logger, fileManager, git) {
|
|
1717
|
+
let latestTag = "";
|
|
1718
|
+
let latestVersion = "";
|
|
1719
|
+
try {
|
|
1720
|
+
const commits = await getCommitsSinceTag(config, logger, git);
|
|
1721
|
+
if (commits.latestTag) {
|
|
1722
|
+
latestTag = commits.latestTag;
|
|
1723
|
+
latestVersion = commits.latestTagVersion ?? "";
|
|
1724
|
+
}
|
|
1725
|
+
const currentVersion = await getCurrentVersion(
|
|
1726
|
+
config,
|
|
1727
|
+
logger,
|
|
1728
|
+
git,
|
|
1729
|
+
fileManager,
|
|
1730
|
+
config.files,
|
|
1731
|
+
latestVersion
|
|
1732
|
+
);
|
|
1733
|
+
if (currentVersion.version) {
|
|
1734
|
+
latestVersion = currentVersion.version;
|
|
1735
|
+
}
|
|
1736
|
+
} catch {
|
|
1737
|
+
}
|
|
1738
|
+
if (!latestVersion && !latestTag) {
|
|
1739
|
+
console.error(
|
|
1740
|
+
styleText(
|
|
1741
|
+
"yellowBright",
|
|
1742
|
+
"No version found. Make sure you have at least one tag in your repository."
|
|
1743
|
+
)
|
|
1744
|
+
);
|
|
1745
|
+
process.exit(1);
|
|
1746
|
+
return;
|
|
1747
|
+
}
|
|
1748
|
+
switch (config.command) {
|
|
1749
|
+
case "inspect-version": {
|
|
1750
|
+
console.log(
|
|
1751
|
+
config.asJson ? JSON.stringify(
|
|
1752
|
+
{
|
|
1753
|
+
version: latestVersion
|
|
1754
|
+
},
|
|
1755
|
+
null,
|
|
1756
|
+
2
|
|
1757
|
+
) : latestVersion
|
|
1758
|
+
);
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
case "inspect-tag": {
|
|
1762
|
+
console.log(
|
|
1763
|
+
config.asJson ? JSON.stringify(
|
|
1764
|
+
{
|
|
1765
|
+
tag: latestTag
|
|
1766
|
+
},
|
|
1767
|
+
null,
|
|
1768
|
+
2
|
|
1769
|
+
) : latestTag
|
|
1770
|
+
);
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
default: {
|
|
1774
|
+
console.log(
|
|
1775
|
+
config.asJson ? JSON.stringify(
|
|
1776
|
+
{
|
|
1777
|
+
version: latestVersion,
|
|
1778
|
+
tag: latestTag
|
|
1779
|
+
},
|
|
1780
|
+
null,
|
|
1781
|
+
2
|
|
1782
|
+
) : `
|
|
1783
|
+
Version: ${latestVersion}
|
|
1784
|
+
Tag: ${latestTag}
|
|
1785
|
+
`.trim()
|
|
1786
|
+
);
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1757
1791
|
function getPriority(type) {
|
|
1758
1792
|
return ["patch", "minor", "major"].indexOf(type ?? "");
|
|
1759
1793
|
}
|
|
1760
1794
|
function getVersionType(version) {
|
|
1761
|
-
const parseVersion =
|
|
1795
|
+
const parseVersion = semver5.parse(version);
|
|
1762
1796
|
if (parseVersion?.major) {
|
|
1763
1797
|
return "major";
|
|
1764
1798
|
} else if (parseVersion?.minor) {
|
|
@@ -1772,7 +1806,7 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
|
1772
1806
|
if (!preReleaseTag) {
|
|
1773
1807
|
return releaseType;
|
|
1774
1808
|
}
|
|
1775
|
-
const currentVersionsIsPreRelease = Array.isArray(
|
|
1809
|
+
const currentVersionsIsPreRelease = Array.isArray(semver5.prerelease(currentVersion));
|
|
1776
1810
|
if (currentVersionsIsPreRelease) {
|
|
1777
1811
|
const currentReleaseType = getVersionType(currentVersion);
|
|
1778
1812
|
if (currentReleaseType === releaseType || getPriority(currentReleaseType) > getPriority(releaseType)) {
|
|
@@ -1791,7 +1825,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1791
1825
|
};
|
|
1792
1826
|
}
|
|
1793
1827
|
if (config.nextVersion) {
|
|
1794
|
-
if (!
|
|
1828
|
+
if (!semver5.valid(config.nextVersion)) {
|
|
1795
1829
|
throw new Error(`Invalid Version: ${config.nextVersion}`);
|
|
1796
1830
|
}
|
|
1797
1831
|
logger.log(`Next version: ${config.nextVersion}`);
|
|
@@ -1799,7 +1833,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1799
1833
|
version: config.nextVersion
|
|
1800
1834
|
};
|
|
1801
1835
|
}
|
|
1802
|
-
const isPreMajor =
|
|
1836
|
+
const isPreMajor = semver5.lt(currentVersion, "1.0.0");
|
|
1803
1837
|
let releaseType = "patch";
|
|
1804
1838
|
const changes = {
|
|
1805
1839
|
major: 0,
|
|
@@ -1849,7 +1883,7 @@ async function getNextVersion(config, logger, commits, currentVersion) {
|
|
|
1849
1883
|
}
|
|
1850
1884
|
}
|
|
1851
1885
|
const releaseTypeOrPreRelease = getReleaseType(releaseType, currentVersion, config.preRelease);
|
|
1852
|
-
const nextVersion =
|
|
1886
|
+
const nextVersion = semver5.inc(
|
|
1853
1887
|
currentVersion,
|
|
1854
1888
|
releaseTypeOrPreRelease,
|
|
1855
1889
|
typeof config.preRelease === "string" ? config.preRelease : ""
|
|
@@ -2001,7 +2035,14 @@ async function main(config, logger, fileManager, git) {
|
|
|
2001
2035
|
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
2002
2036
|
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
2003
2037
|
const commits = await getCommitsSinceTag(config, logger, git);
|
|
2004
|
-
const current = await getCurrentVersion(
|
|
2038
|
+
const current = await getCurrentVersion(
|
|
2039
|
+
config,
|
|
2040
|
+
logger,
|
|
2041
|
+
git,
|
|
2042
|
+
fileManager,
|
|
2043
|
+
config.files,
|
|
2044
|
+
commits.latestTagVersion
|
|
2045
|
+
);
|
|
2005
2046
|
const next = await getNextVersion(config, logger, commits.commits, current.version);
|
|
2006
2047
|
logger.log("Updating files: ");
|
|
2007
2048
|
for (const outFile of current.files) {
|
|
@@ -2019,6 +2060,6 @@ async function main(config, logger, fileManager, git) {
|
|
|
2019
2060
|
};
|
|
2020
2061
|
}
|
|
2021
2062
|
|
|
2022
|
-
export { CommitParser, FileManager, ForkConfigSchema, Git, Logger, commitChanges, createParserOptions, filterRevertedCommits, getCommitsSinceTag, getCurrentVersion, getNextVersion, getUserConfig,
|
|
2023
|
-
//# sourceMappingURL=chunk-
|
|
2024
|
-
//# sourceMappingURL=chunk-
|
|
2063
|
+
export { CommitParser, FileManager, ForkConfigSchema, Git, Logger, commitChanges, createParserOptions, filterRevertedCommits, getCommitsSinceTag, getCurrentVersion, getNextVersion, getUserConfig, inspect, main, tagChanges, updateChangelog, validateConfig };
|
|
2064
|
+
//# sourceMappingURL=chunk-5CZU5EA7.js.map
|
|
2065
|
+
//# sourceMappingURL=chunk-5CZU5EA7.js.map
|