fork-version 4.1.10 → 5.0.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/CHANGELOG.md +20 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +54 -193
- package/dist/commands/inspect.d.ts +9 -0
- package/dist/commands/inspect.js +41 -0
- package/dist/commands/main.d.ts +16 -0
- package/dist/commands/main.js +30 -0
- package/dist/commands/validate-config.d.ts +6 -0
- package/dist/commands/validate-config.js +11 -0
- package/dist/commit-parser/commit-parser.d.ts +114 -0
- package/dist/commit-parser/commit-parser.js +327 -0
- package/dist/commit-parser/filter-reverted-commits.d.ts +17 -0
- package/dist/commit-parser/filter-reverted-commits.js +34 -0
- package/dist/commit-parser/options.d.ts +74 -0
- package/dist/commit-parser/options.js +70 -0
- package/dist/commit-parser/parser-error.js +14 -0
- package/dist/commit-parser/types.d.ts +53 -0
- package/dist/config/changelog-preset-config.js +41 -0
- package/dist/config/cli-arguments.d.ts +109 -0
- package/dist/config/cli-arguments.js +141 -0
- package/dist/config/defaults.js +38 -0
- package/dist/config/define-config.d.ts +9 -0
- package/dist/config/define-config.js +9 -0
- package/dist/config/load-config.js +45 -0
- package/dist/config/merge-files.js +12 -0
- package/dist/config/schema.d.ts +50 -0
- package/dist/config/schema.js +61 -0
- package/dist/config/types.d.ts +279 -0
- package/dist/config/user-config.d.ts +6 -0
- package/dist/config/user-config.js +50 -0
- package/dist/detect-git-host/detect-git-host.js +35 -0
- package/dist/detect-git-host/host-azure-devops.js +28 -0
- package/dist/detect-git-host/host-bitbucket.js +28 -0
- package/dist/detect-git-host/host-github.js +32 -0
- package/dist/detect-git-host/host-gitlab.js +48 -0
- package/dist/files/arm-bicep.js +38 -0
- package/dist/files/file-manager.d.ts +56 -0
- package/dist/files/file-manager.js +87 -0
- package/dist/files/install-shield-ism.js +55 -0
- package/dist/files/json-package.js +64 -0
- package/dist/files/ms-build-project.js +55 -0
- package/dist/files/plain-text.js +31 -0
- package/dist/files/yaml-package.js +57 -0
- package/dist/index.d.ts +21 -655
- package/dist/index.js +19 -10
- package/dist/process/changelog.d.ts +7 -0
- package/dist/process/changelog.js +69 -0
- package/dist/process/commit.d.ts +9 -0
- package/dist/process/commit.js +22 -0
- package/dist/process/get-commits.d.ts +14 -0
- package/dist/process/get-commits.js +25 -0
- package/dist/process/get-current-version.d.ts +13 -0
- package/dist/process/get-current-version.js +35 -0
- package/dist/process/get-next-version.d.ts +21 -0
- package/dist/process/get-next-version.js +72 -0
- package/dist/process/tag.d.ts +8 -0
- package/dist/process/tag.js +15 -0
- package/dist/services/git.d.ts +141 -0
- package/dist/services/git.js +236 -0
- package/dist/services/logger.d.ts +18 -0
- package/dist/services/logger.js +35 -0
- package/dist/utils/clean-tag.js +21 -0
- package/dist/utils/escape-regex.js +17 -0
- package/dist/utils/file-state.js +19 -0
- package/dist/utils/format-commit-message.js +13 -0
- package/dist/utils/parse-regexp-string.js +31 -0
- package/dist/utils/release-type.js +47 -0
- package/dist/utils/trim-string-array.js +20 -0
- package/package.json +11 -29
- package/dist/chunk-33WIJWQZ.cjs +0 -2306
- package/dist/chunk-33WIJWQZ.cjs.map +0 -1
- package/dist/chunk-L5UDUEHE.js +0 -2262
- package/dist/chunk-L5UDUEHE.js.map +0 -1
- package/dist/cli.cjs +0 -205
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/index.cjs +0 -80
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -655
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { fileExists } from "../utils/file-state.js";
|
|
2
|
+
import { JSONPackage } from "./json-package.js";
|
|
3
|
+
import { YAMLPackage } from "./yaml-package.js";
|
|
4
|
+
import { PlainText } from "./plain-text.js";
|
|
5
|
+
import { MSBuildProject } from "./ms-build-project.js";
|
|
6
|
+
import { ARMBicep } from "./arm-bicep.js";
|
|
7
|
+
import { InstallShieldISM } from "./install-shield-ism.js";
|
|
8
|
+
import { basename, isAbsolute, resolve } from "node:path";
|
|
9
|
+
//#region src/files/file-manager.ts
|
|
10
|
+
/**
|
|
11
|
+
* Exception thrown if a file manager encounters a file missing a required property,
|
|
12
|
+
* such as the "version" property in a JSON package file.
|
|
13
|
+
*/
|
|
14
|
+
var MissingPropertyException = class extends Error {
|
|
15
|
+
fileType;
|
|
16
|
+
propertyName;
|
|
17
|
+
constructor(fileType, propertyName) {
|
|
18
|
+
super(`Missing '${propertyName}' property in ${fileType}`);
|
|
19
|
+
this.name = "MissingPropertyException";
|
|
20
|
+
this.fileType = fileType;
|
|
21
|
+
this.propertyName = propertyName;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var FileManager = class {
|
|
25
|
+
#config;
|
|
26
|
+
#logger;
|
|
27
|
+
#fileManagers = [];
|
|
28
|
+
constructor(config, logger) {
|
|
29
|
+
this.#config = config;
|
|
30
|
+
this.#logger = logger;
|
|
31
|
+
this.#fileManagers = [
|
|
32
|
+
new JSONPackage(),
|
|
33
|
+
new YAMLPackage(),
|
|
34
|
+
new PlainText(),
|
|
35
|
+
new MSBuildProject(),
|
|
36
|
+
new ARMBicep(),
|
|
37
|
+
new InstallShieldISM()
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the state from the given file name.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* fileManager.read("package.json");
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @returns
|
|
49
|
+
* ```json
|
|
50
|
+
* { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
read(pathOrName) {
|
|
54
|
+
const _fileName = pathOrName.toLowerCase();
|
|
55
|
+
const filePath = isAbsolute(pathOrName) ? pathOrName : resolve(this.#config.path, pathOrName);
|
|
56
|
+
if (!fileExists(filePath)) return;
|
|
57
|
+
for (const fileManager of this.#fileManagers) if (fileManager.isSupportedFile(_fileName)) {
|
|
58
|
+
try {
|
|
59
|
+
return fileManager.read(filePath);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof MissingPropertyException) this.#logger.warn(`[File Manager] Missing '${error.propertyName}' property in ${error.fileType} file: ${basename(_fileName)}`);
|
|
62
|
+
else throw new Error(`An unexpected error occurred while reading file: ${filePath}`, { cause: error });
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.#logger.error(`[File Manager] Unsupported file: ${pathOrName}`);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Write the new version to the given file.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* fileManager.write(
|
|
74
|
+
* { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
|
|
75
|
+
* "1.2.3"
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
write(fileState, newVersion) {
|
|
80
|
+
if (this.#config.dryRun) return;
|
|
81
|
+
const _fileName = fileState.name.toLowerCase();
|
|
82
|
+
for (const fileManager of this.#fileManagers) if (fileManager.isSupportedFile(_fileName)) return fileManager.write(fileState, newVersion);
|
|
83
|
+
this.#logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { FileManager, MissingPropertyException };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MissingPropertyException } from "./file-manager.js";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import * as cheerio from "cheerio/slim";
|
|
5
|
+
//#region src/files/install-shield-ism.ts
|
|
6
|
+
/**
|
|
7
|
+
* An InstallShield ISM file can be either XML or binary, only the XML format is supported
|
|
8
|
+
* by this file manager. The XML format typically contains a "Property" table with a
|
|
9
|
+
* "ProductVersion" property.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```xml
|
|
13
|
+
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
14
|
+
* <?xml-stylesheet type="text/xsl" href="is.xsl" ?>
|
|
15
|
+
* <!DOCTYPE msi [
|
|
16
|
+
* ...
|
|
17
|
+
* ]>
|
|
18
|
+
* <msi version="2.0" xmlns:dt="urn:schemas-microsoft-com:datatypes">
|
|
19
|
+
*
|
|
20
|
+
* <table name="Property">
|
|
21
|
+
* <row><td>ProductVersion</td><td>1.2.3</td><td/></row>
|
|
22
|
+
* </table>
|
|
23
|
+
*
|
|
24
|
+
* </msi>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
var InstallShieldISM = class {
|
|
28
|
+
#cheerioOptions = {
|
|
29
|
+
xmlMode: true,
|
|
30
|
+
xml: { decodeEntities: false }
|
|
31
|
+
};
|
|
32
|
+
read(filePath) {
|
|
33
|
+
const fileContents = readFileSync(filePath, "utf8");
|
|
34
|
+
const version = cheerio.load(fileContents, this.#cheerioOptions)("msi > table[name=\"Property\"] > row > td:contains(\"ProductVersion\")").next().text().trim();
|
|
35
|
+
if (version) return {
|
|
36
|
+
name: basename(filePath),
|
|
37
|
+
path: filePath,
|
|
38
|
+
version
|
|
39
|
+
};
|
|
40
|
+
throw new MissingPropertyException("InstallShield ISM", "ProductVersion");
|
|
41
|
+
}
|
|
42
|
+
write(fileState, newVersion) {
|
|
43
|
+
const fileContents = readFileSync(fileState.path, "utf8");
|
|
44
|
+
const $ = cheerio.load(fileContents, this.#cheerioOptions);
|
|
45
|
+
const versionCell = $("msi > table[name=\"Property\"] > row > td:contains(\"ProductVersion\")").next();
|
|
46
|
+
if (versionCell.length > 0) versionCell.text(newVersion);
|
|
47
|
+
const updatedContent = $.xml().replaceAll("\"/>", "\" />");
|
|
48
|
+
writeFileSync(fileState.path, updatedContent, "utf8");
|
|
49
|
+
}
|
|
50
|
+
isSupportedFile(fileName) {
|
|
51
|
+
return fileName.endsWith(".ism");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { InstallShieldISM };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MissingPropertyException } from "./file-manager.js";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { applyEdits, modify, parse as parse$1 } from "jsonc-parser";
|
|
5
|
+
//#region src/files/json-package.ts
|
|
6
|
+
/**
|
|
7
|
+
* A json package file should have a version property, like what can be seen
|
|
8
|
+
* in the package.json file in the root of this project.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```json
|
|
12
|
+
* {
|
|
13
|
+
* "name": "fork-version",
|
|
14
|
+
* "version": "1.2.3",
|
|
15
|
+
* "private": true,
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
var JSONPackage = class {
|
|
20
|
+
/** Options for parsing JSON and JSONC files. */
|
|
21
|
+
#jsoncOptions = {
|
|
22
|
+
allowEmptyContent: false,
|
|
23
|
+
allowTrailingComma: true,
|
|
24
|
+
disallowComments: false
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Sets a new string value at the given path in a JSON or JSONC string.
|
|
28
|
+
* @param jsonc the JSON or JSONC string (the contents of a file)
|
|
29
|
+
* @param jsonPath path to the value to set, as an array of segments
|
|
30
|
+
* @param newString string to set the value to
|
|
31
|
+
* @returns the JSON or JSONC string with the value set
|
|
32
|
+
*/
|
|
33
|
+
#setStringInJsonc(jsonc, jsonPath, newString) {
|
|
34
|
+
return applyEdits(jsonc, modify(jsonc, jsonPath, newString, {}));
|
|
35
|
+
}
|
|
36
|
+
read(filePath) {
|
|
37
|
+
const fileContents = readFileSync(filePath, "utf8");
|
|
38
|
+
const parseErrors = [];
|
|
39
|
+
const parsedJson = parse$1(fileContents, parseErrors, this.#jsoncOptions);
|
|
40
|
+
if (parsedJson?.version && parseErrors.length === 0) return {
|
|
41
|
+
name: basename(filePath),
|
|
42
|
+
path: filePath,
|
|
43
|
+
version: parsedJson.version,
|
|
44
|
+
isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
|
|
45
|
+
};
|
|
46
|
+
throw new MissingPropertyException("JSON", "version");
|
|
47
|
+
}
|
|
48
|
+
write(fileState, newVersion) {
|
|
49
|
+
let fileContents = readFileSync(fileState.path, "utf8");
|
|
50
|
+
const parsedJson = parse$1(fileContents, [], this.#jsoncOptions);
|
|
51
|
+
fileContents = this.#setStringInJsonc(fileContents, ["version"], newVersion);
|
|
52
|
+
if (parsedJson?.packages?.[""]) fileContents = this.#setStringInJsonc(fileContents, [
|
|
53
|
+
"packages",
|
|
54
|
+
"",
|
|
55
|
+
"version"
|
|
56
|
+
], newVersion);
|
|
57
|
+
writeFileSync(fileState.path, fileContents, "utf8");
|
|
58
|
+
}
|
|
59
|
+
isSupportedFile(fileName) {
|
|
60
|
+
return fileName.endsWith(".json") || fileName.endsWith(".jsonc");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { JSONPackage };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MissingPropertyException } from "./file-manager.js";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import * as cheerio from "cheerio/slim";
|
|
5
|
+
//#region src/files/ms-build-project.ts
|
|
6
|
+
/**
|
|
7
|
+
* A ms-build file is an xml file with a version property under the Project > PropertyGroup node.
|
|
8
|
+
*
|
|
9
|
+
* [Microsoft Learn - MSBuild Reference](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2022)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```xml
|
|
13
|
+
* <Project Sdk="Microsoft.NET.Sdk">
|
|
14
|
+
* <PropertyGroup>
|
|
15
|
+
* <Version>1.2.3</Version>
|
|
16
|
+
* </PropertyGroup>
|
|
17
|
+
* </Project>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
var MSBuildProject = class {
|
|
21
|
+
#cheerioOptions = {
|
|
22
|
+
xmlMode: true,
|
|
23
|
+
xml: { decodeEntities: false }
|
|
24
|
+
};
|
|
25
|
+
read(filePath) {
|
|
26
|
+
const fileContents = readFileSync(filePath, "utf8");
|
|
27
|
+
const version = cheerio.load(fileContents, this.#cheerioOptions)("Project > PropertyGroup > Version").text();
|
|
28
|
+
if (version) return {
|
|
29
|
+
name: basename(filePath),
|
|
30
|
+
path: filePath,
|
|
31
|
+
version
|
|
32
|
+
};
|
|
33
|
+
throw new MissingPropertyException("MSBuild", "Version");
|
|
34
|
+
}
|
|
35
|
+
write(fileState, newVersion) {
|
|
36
|
+
const fileContents = readFileSync(fileState.path, "utf8");
|
|
37
|
+
const $ = cheerio.load(fileContents, this.#cheerioOptions);
|
|
38
|
+
$("Project > PropertyGroup > Version").text(newVersion);
|
|
39
|
+
const updatedContent = $.xml().replaceAll("\"/>", "\" />");
|
|
40
|
+
writeFileSync(fileState.path, updatedContent, "utf8");
|
|
41
|
+
}
|
|
42
|
+
isSupportedFile(fileName) {
|
|
43
|
+
return [
|
|
44
|
+
".csproj",
|
|
45
|
+
".dbproj",
|
|
46
|
+
".esproj",
|
|
47
|
+
".fsproj",
|
|
48
|
+
".props",
|
|
49
|
+
".vbproj",
|
|
50
|
+
".vcxproj"
|
|
51
|
+
].findIndex((ext) => fileName.endsWith(ext)) !== -1;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { MSBuildProject };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MissingPropertyException } from "./file-manager.js";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
//#region src/files/plain-text.ts
|
|
5
|
+
/**
|
|
6
|
+
* A plain text file will have just the version as the content.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```txt
|
|
10
|
+
* 1.2.3
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
var PlainText = class {
|
|
14
|
+
read(filePath) {
|
|
15
|
+
const fileContents = readFileSync(filePath, "utf8").trim();
|
|
16
|
+
if (fileContents) return {
|
|
17
|
+
name: basename(filePath),
|
|
18
|
+
path: filePath,
|
|
19
|
+
version: fileContents
|
|
20
|
+
};
|
|
21
|
+
throw new MissingPropertyException("Plain Text", "version");
|
|
22
|
+
}
|
|
23
|
+
write(fileState, newVersion) {
|
|
24
|
+
writeFileSync(fileState.path, newVersion, "utf8");
|
|
25
|
+
}
|
|
26
|
+
isSupportedFile(fileName) {
|
|
27
|
+
return fileName.endsWith("version.txt");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { PlainText };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MissingPropertyException } from "./file-manager.js";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { parse as parse$1, parseDocument } from "yaml";
|
|
5
|
+
//#region src/files/yaml-package.ts
|
|
6
|
+
/**
|
|
7
|
+
* A yaml package file should have a version property on the top level, like what can be seen
|
|
8
|
+
* in [this example project](https://github.com/eglavin/wordionary/blob/01ae9b9d604cecdf9d320ed6028a727be5e5349e/pubspec.yaml#L19C1-L19C17).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```yaml
|
|
12
|
+
* name: wordionary
|
|
13
|
+
* description: "A Flutter project."
|
|
14
|
+
* publish_to: 'none'
|
|
15
|
+
* version: 1.2.3
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var YAMLPackage = class {
|
|
19
|
+
/**
|
|
20
|
+
* If the version is returned with a "+" symbol in the value then the version might be from a
|
|
21
|
+
* flutter `pubspec.yaml` file, if so we want to retain the input builderNumber by splitting it
|
|
22
|
+
* and joining it again later.
|
|
23
|
+
*/
|
|
24
|
+
#handleBuildNumber(fileVersion) {
|
|
25
|
+
const [version, builderNumber] = fileVersion.split("+");
|
|
26
|
+
if (/^\d+$/.test(builderNumber)) return {
|
|
27
|
+
version,
|
|
28
|
+
builderNumber
|
|
29
|
+
};
|
|
30
|
+
return { version: fileVersion };
|
|
31
|
+
}
|
|
32
|
+
read(filePath) {
|
|
33
|
+
const fileVersion = parse$1(readFileSync(filePath, "utf-8"))?.version;
|
|
34
|
+
if (fileVersion) {
|
|
35
|
+
const parsedVersion = this.#handleBuildNumber(fileVersion);
|
|
36
|
+
return {
|
|
37
|
+
name: basename(filePath),
|
|
38
|
+
path: filePath,
|
|
39
|
+
version: parsedVersion.version || "",
|
|
40
|
+
builderNumber: parsedVersion.builderNumber ?? void 0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
throw new MissingPropertyException("YAML", "version");
|
|
44
|
+
}
|
|
45
|
+
write(fileState, newVersion) {
|
|
46
|
+
const yamlDocument = parseDocument(readFileSync(fileState.path, "utf8"));
|
|
47
|
+
let newFileVersion = newVersion;
|
|
48
|
+
if (fileState.builderNumber !== void 0) newFileVersion += `+${fileState.builderNumber}`;
|
|
49
|
+
yamlDocument.set("version", newFileVersion);
|
|
50
|
+
writeFileSync(fileState.path, yamlDocument.toString(), "utf8");
|
|
51
|
+
}
|
|
52
|
+
isSupportedFile(fileName) {
|
|
53
|
+
return fileName.endsWith(".yaml") || fileName.endsWith(".yml");
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { YAMLPackage };
|