fork-version 5.1.7 → 5.2.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Fork Version
|
|
2
2
|
|
|
3
|
+
## [5.2.0](https://github.com/eglavin/fork-version/compare/v5.1.7...v5.2.0) (2026-05-27)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* support version prefix ([e1ee015](https://github.com/eglavin/fork-version/commit/e1ee015dbf07109b28565821af537aa9554a85c6))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Refactor
|
|
12
|
+
|
|
13
|
+
* handle version suffix property if defined in an ms-build project ([1f569d6](https://github.com/eglavin/fork-version/commit/1f569d60f7d3f9226c5d445df4529922de9e73f0))
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## [5.1.7](https://github.com/eglavin/fork-version/compare/v5.1.6...v5.1.7) (2026-05-05)
|
|
4
17
|
|
|
5
18
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { extractPrerelease } from "../utils/extract-prerelease.js";
|
|
1
2
|
import { MissingPropertyException } from "../services/file-manager.js";
|
|
2
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
4
|
import * as cheerio from "cheerio/slim";
|
|
@@ -15,6 +16,19 @@ import * as cheerio from "cheerio/slim";
|
|
|
15
16
|
* </PropertyGroup>
|
|
16
17
|
* </Project>
|
|
17
18
|
* ```
|
|
19
|
+
*
|
|
20
|
+
* ms-build projects can also use VersionPrefix and VersionSuffix properties instead of Version, in
|
|
21
|
+
* which case the full version is determined by concatenating the prefix and suffix.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```xml
|
|
25
|
+
* <Project Sdk="Microsoft.NET.Sdk">
|
|
26
|
+
* <PropertyGroup>
|
|
27
|
+
* <VersionPrefix>1.2.3</VersionPrefix>
|
|
28
|
+
* <VersionSuffix>beta.1</VersionSuffix>
|
|
29
|
+
* </PropertyGroup>
|
|
30
|
+
* </Project>
|
|
31
|
+
* ```
|
|
18
32
|
*/
|
|
19
33
|
var MSBuildProject = class {
|
|
20
34
|
#cheerioOptions = {
|
|
@@ -23,17 +37,36 @@ var MSBuildProject = class {
|
|
|
23
37
|
};
|
|
24
38
|
async read(filePath) {
|
|
25
39
|
const fileContents = await readFile(filePath, "utf8");
|
|
26
|
-
const
|
|
40
|
+
const $ = cheerio.load(fileContents, this.#cheerioOptions);
|
|
41
|
+
const version = $("Project > PropertyGroup > Version").text();
|
|
27
42
|
if (version) return {
|
|
28
43
|
path: filePath,
|
|
29
44
|
version
|
|
30
45
|
};
|
|
46
|
+
const versionPrefix = $("Project > PropertyGroup > VersionPrefix").text();
|
|
47
|
+
const versionSuffix = $("Project > PropertyGroup > VersionSuffix").text();
|
|
48
|
+
if (versionPrefix) return {
|
|
49
|
+
path: filePath,
|
|
50
|
+
version: versionSuffix ? `${versionPrefix}-${versionSuffix}` : versionPrefix
|
|
51
|
+
};
|
|
31
52
|
throw new MissingPropertyException("MSBuild", "Version");
|
|
32
53
|
}
|
|
33
54
|
async write(fileState, newVersion) {
|
|
34
55
|
const fileContents = await readFile(fileState.path, "utf8");
|
|
35
56
|
const $ = cheerio.load(fileContents, this.#cheerioOptions);
|
|
36
|
-
$("Project > PropertyGroup > Version")
|
|
57
|
+
const version = $("Project > PropertyGroup > Version");
|
|
58
|
+
if (version.length) version.text(newVersion);
|
|
59
|
+
else {
|
|
60
|
+
const versionPrefix = $("Project > PropertyGroup > VersionPrefix");
|
|
61
|
+
const versionSuffix = $("Project > PropertyGroup > VersionSuffix");
|
|
62
|
+
if (versionPrefix.length) {
|
|
63
|
+
const { prefix, suffix } = extractPrerelease(newVersion);
|
|
64
|
+
versionPrefix.text(prefix);
|
|
65
|
+
if (suffix) if (versionSuffix.length) versionSuffix.text(suffix);
|
|
66
|
+
else $(`\n<VersionSuffix>${suffix}</VersionSuffix>`).insertAfter(versionPrefix);
|
|
67
|
+
else versionSuffix.remove();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
37
70
|
const updatedContent = $.xml().replaceAll("\"/>", "\" />");
|
|
38
71
|
await writeFile(fileState.path, updatedContent, "utf8");
|
|
39
72
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/utils/extract-prerelease.ts
|
|
2
|
+
/**
|
|
3
|
+
* This function is used to split a version string into its prefix and suffix components.
|
|
4
|
+
*
|
|
5
|
+
* Example version strings:
|
|
6
|
+
* - `1.2.3`
|
|
7
|
+
* - `1.2.3-alpha.0`
|
|
8
|
+
* - `1.2.3-0`
|
|
9
|
+
*
|
|
10
|
+
* In the above examples, the prefix is `1.2.3` and the suffixes are `undefined`, `alpha.0`, and `0` respectively.
|
|
11
|
+
*
|
|
12
|
+
* @param version The version string to split.
|
|
13
|
+
* @return An object containing the prefix and suffix of the version string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const versionWithPrerelease = "1.2.3-alpha.0";
|
|
18
|
+
* const { prefix, suffix } = extractPrerelease(versionWithPrerelease);
|
|
19
|
+
* console.log(prefix); // Output: "1.2.3"
|
|
20
|
+
* console.log(suffix); // Output: "alpha.0"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function extractPrerelease(version) {
|
|
24
|
+
const hyphenIndex = version.indexOf("-");
|
|
25
|
+
if (hyphenIndex === -1) return {
|
|
26
|
+
prefix: version,
|
|
27
|
+
suffix: void 0
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
prefix: version.substring(0, hyphenIndex),
|
|
31
|
+
suffix: version.substring(hyphenIndex + 1) || void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { extractPrerelease };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fork-version",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Fork-Version automates version control tasks such as determining, updating, and committing versions, files, and changelogs, simplifying the process when adhering to the conventional commit standard.",
|
|
6
6
|
"keywords": [
|