@release-change/commit-analyser 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Victor Brito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @release-change/commit-analyser
2
+
3
+ Functions used internally in release-change to analyse the commits, based on the Conventional Commits specification
4
+
5
+ ![License: MIT](https://img.shields.io/github/license/release-change/release-change)
6
+ [![ESM-only package](https://img.shields.io/badge/package-ESM--only-ffe536)](https://nodejs.org/api/esm.html)
7
+ [![Conventional Commits 1.0.0](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
8
+ [![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev/)
9
+ ![NPM latest version](https://img.shields.io/npm/v/%40release-change%2Fcommit-analyser/latest)
10
+ ![Node support](https://img.shields.io/node/v/%40release-change%2Fcommit-analyser)
11
+ ![Build status](https://img.shields.io/github/actions/workflow/status/release-change/release-change/run-tests.yml)
12
+
13
+ ## Copyright & licence
14
+
15
+ © 2025-present Victor Brito — Released under the [MIT licence](./LICENSE).
@@ -0,0 +1,13 @@
1
+ import type { Context, ReleaseType } from "@release-change/shared";
2
+ /**
3
+ * Adjusts the release type based on the internal dependencies.
4
+ *
5
+ * The root package is considered to have all other internal packages as dependencies.
6
+ *
7
+ * For each package, the existing release types are kept.
8
+ * @param context - The context where the CLI is running.
9
+ * @param releaseTypesMap - The map of release types.
10
+ * @return The adjusted map of release types.
11
+ */
12
+ export declare const adjustReleaseType: (context: Context, releaseTypesMap: Map<string, Set<ReleaseType>>) => Map<string, Set<ReleaseType>>;
13
+ //# sourceMappingURL=adjust-release-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adjust-release-type.d.ts","sourceRoot":"","sources":["../src/adjust-release-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAMnE;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAC5B,SAAS,OAAO,EAChB,iBAAiB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,KAC7C,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAwB9B,CAAC"}
@@ -0,0 +1,38 @@
1
+ import path from "node:path";
2
+ import { getPackageDependencies } from "@release-change/get-packages";
3
+ /**
4
+ * Adjusts the release type based on the internal dependencies.
5
+ *
6
+ * The root package is considered to have all other internal packages as dependencies.
7
+ *
8
+ * For each package, the existing release types are kept.
9
+ * @param context - The context where the CLI is running.
10
+ * @param releaseTypesMap - The map of release types.
11
+ * @return The adjusted map of release types.
12
+ */
13
+ export const adjustReleaseType = (context, releaseTypesMap) => {
14
+ const { cwd, packages } = context;
15
+ const completedReleaseTypesMap = new Map(releaseTypesMap);
16
+ for (const packageItem of packages) {
17
+ const { name, pathname } = packageItem;
18
+ const dependencies = name
19
+ ? getPackageDependencies(path.join(cwd, pathname, "package.json"))
20
+ : packages.map(packageItem => packageItem.name);
21
+ if (dependencies?.length) {
22
+ const releaseTypes = completedReleaseTypesMap.get(name) ?? new Set();
23
+ for (const dependency of dependencies) {
24
+ if (completedReleaseTypesMap.has(dependency)) {
25
+ const dependencyReleaseTypes = completedReleaseTypesMap.get(dependency);
26
+ if (dependencyReleaseTypes) {
27
+ for (const dependencyReleaseType of dependencyReleaseTypes) {
28
+ releaseTypes.add(dependencyReleaseType);
29
+ }
30
+ }
31
+ }
32
+ }
33
+ completedReleaseTypesMap.set(name, releaseTypes);
34
+ }
35
+ }
36
+ return completedReleaseTypesMap;
37
+ };
38
+ //# sourceMappingURL=adjust-release-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adjust-release-type.js","sourceRoot":"","sources":["../src/adjust-release-type.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,eAA8C,EACf,EAAE;IACjC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,KAAK,MAAM,WAAW,IAAI,QAAQ,EAAE,CAAC;QACnC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;QACvC,MAAM,YAAY,GAAG,IAAI;YACvB,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;YAClE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,YAAY,EAAE,MAAM,EAAE,CAAC;YACzB,MAAM,YAAY,GAAG,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAe,CAAC;YAClF,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;gBACtC,IAAI,wBAAwB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC7C,MAAM,sBAAsB,GAAG,wBAAwB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBACxE,IAAI,sBAAsB,EAAE,CAAC;wBAC3B,KAAK,MAAM,qBAAqB,IAAI,sBAAsB,EAAE,CAAC;4BAC3D,YAAY,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;wBAC1C,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD,wBAAwB,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ReleaseType } from "@release-change/shared";
2
+ export type PackageReleaseType = {
3
+ name: string;
4
+ releaseType: ReleaseType;
5
+ };
6
+ //# sourceMappingURL=commit-analyser.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-analyser.types.d.ts","sourceRoot":"","sources":["../src/commit-analyser.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=commit-analyser.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-analyser.types.js","sourceRoot":"","sources":["../src/commit-analyser.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ export declare const INDENTED_BLANK_LINE_SEPARATOR: RegExp;
2
+ export declare const BLANK_LINE_SEPARATOR: string;
3
+ export declare const COMMIT_ABBREVIATED_SHA_LENGTH = 7;
4
+ export declare const COMMIT_FOOTER_KEY: RegExp;
5
+ export declare const BREAKING_CHANGE: RegExp;
6
+ export declare const COMMIT_MESSAGE: RegExp;
7
+ export declare const COMMIT_PREFIX_MAJOR: RegExp;
8
+ export declare const COMMIT_PREFIX_MINOR: RegExp;
9
+ export declare const COMMIT_PREFIX_PATCH: RegExp;
10
+ export declare const ISSUE_ID: RegExp;
11
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,QAAa,CAAC;AACxD,eAAO,MAAM,oBAAoB,QAAiB,CAAC;AACnD,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAC/C,eAAO,MAAM,iBAAiB,QAAwB,CAAC;AACvD,eAAO,MAAM,eAAe,QAAgC,CAAC;AAC7D,eAAO,MAAM,cAAc,QAA6D,CAAC;AACzF,eAAO,MAAM,mBAAmB,QAAgC,CAAC;AACjE,eAAO,MAAM,mBAAmB,QAA6B,CAAC;AAC9D,eAAO,MAAM,mBAAmB,QAA4B,CAAC;AAC7D,eAAO,MAAM,QAAQ,QAA+B,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const INDENTED_BLANK_LINE_SEPARATOR = /\n\s*\n/g;
2
+ export const BLANK_LINE_SEPARATOR = "\n".repeat(2);
3
+ export const COMMIT_ABBREVIATED_SHA_LENGTH = 7;
4
+ export const COMMIT_FOOTER_KEY = /^[-a-z]+:\s(\w|#)+/i;
5
+ export const BREAKING_CHANGE = /^BREAKING(\s|-)CHANGE:\s\w+/;
6
+ export const COMMIT_MESSAGE = /^[a-z]+(?:\((?<scope>[^)]+)\))?!?:\s(?<description>.+)$/i;
7
+ export const COMMIT_PREFIX_MAJOR = /^[a-z]+(\([^)]+\))?!:\s\w+/i;
8
+ export const COMMIT_PREFIX_MINOR = /^feat(\([^)]+\))?:\s\w+/i;
9
+ export const COMMIT_PREFIX_PATCH = /^fix(\([^)]+\))?:\s\w+/i;
10
+ export const ISSUE_ID = /(?<!\S)#(?<issueId>\d+)\b/g;
11
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CAAC;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,0DAA0D,CAAC;AACzF,MAAM,CAAC,MAAM,mBAAmB,GAAG,6BAA6B,CAAC;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAC7D,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Commit, Context } from "@release-change/shared";
2
+ /**
3
+ * Gets the Git tags associated with the commit.
4
+ * @param commit - The commit to analyse.
5
+ * @param context - The context where the CLI is running.
6
+ * @return An array of the Git tags.
7
+ */
8
+ export declare const getGitTags: (commit: Commit, context: Context) => string[];
9
+ //# sourceMappingURL=get-git-tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-git-tags.d.ts","sourceRoot":"","sources":["../src/get-git-tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAI9D;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,EAAE,SAAS,OAAO,KAAG,MAAM,EAwBnE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { formatDetailedError } from "@release-change/shared";
2
+ /**
3
+ * Gets the Git tags associated with the commit.
4
+ * @param commit - The commit to analyse.
5
+ * @param context - The context where the CLI is running.
6
+ * @return An array of the Git tags.
7
+ */
8
+ export const getGitTags = (commit, context) => {
9
+ const { config: { isMonorepo }, nextRelease } = context;
10
+ if (nextRelease) {
11
+ const { modifiedFiles } = commit;
12
+ return isMonorepo && modifiedFiles
13
+ ? nextRelease
14
+ .filter(packageNextRelease => packageNextRelease.pathname === "." ||
15
+ modifiedFiles.some(file => file.startsWith(packageNextRelease.pathname)))
16
+ .map(packageNextRelease => packageNextRelease.gitTag)
17
+ : nextRelease.map(packageNextRelease => packageNextRelease.gitTag);
18
+ }
19
+ throw formatDetailedError({
20
+ title: "Failed to get the Git tags",
21
+ message: "No next release found.",
22
+ details: {
23
+ output: "nextRelease: undefined"
24
+ }
25
+ });
26
+ };
27
+ //# sourceMappingURL=get-git-tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-git-tags.js","sourceRoot":"","sources":["../src/get-git-tags.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAY,EAAE;IACvE,MAAM,EACJ,MAAM,EAAE,EAAE,UAAU,EAAE,EACtB,WAAW,EACZ,GAAG,OAAO,CAAC;IACZ,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;QACjC,OAAO,UAAU,IAAI,aAAa;YAChC,CAAC,CAAC,WAAW;iBACR,MAAM,CACL,kBAAkB,CAAC,EAAE,CACnB,kBAAkB,CAAC,QAAQ,KAAK,GAAG;gBACnC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAC3E;iBACA,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC;YACzD,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,4BAA4B;QACnC,OAAO,EAAE,wBAAwB;QACjC,OAAO,EAAE;YACP,MAAM,EAAE,wBAAwB;SACjC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Commit, Context } from "@release-change/shared";
2
+ import type { PackageReleaseType } from "./commit-analyser.types.js";
3
+ /**
4
+ * Gets the release type from the commits which have been committed since the previous release or the beginning.
5
+ *
6
+ * The release type can be one of the following, from most to least important:
7
+ * 1. `"major"`,
8
+ * 2. `"minor"`,
9
+ * 3. `"patch"`,
10
+ * 4. `null`.
11
+ *
12
+ * In a monorepo context, the release type is also determined according to the internal dependencies.
13
+ * @param commits - The commits to analyse.
14
+ * @param context - The context where the CLI is running.
15
+ * @return An array of objects containing the most important release type found for each package if commits are parsed successfully, `null` if there are no commits or an error is thrown.
16
+ */
17
+ export declare const getReleaseType: (commits: Commit[], context: Context) => PackageReleaseType[];
18
+ //# sourceMappingURL=get-release-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-release-type.d.ts","sourceRoot":"","sources":["../src/get-release-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAe,MAAM,wBAAwB,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AASrE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,EAAE,SAAS,OAAO,KAAG,kBAAkB,EA+EtF,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { inspect } from "node:util";
2
+ import { setLogger } from "@release-change/logger";
3
+ import { agreeInNumber } from "@release-change/shared";
4
+ import { adjustReleaseType } from "./adjust-release-type.js";
5
+ /**
6
+ * Gets the release type from the commits which have been committed since the previous release or the beginning.
7
+ *
8
+ * The release type can be one of the following, from most to least important:
9
+ * 1. `"major"`,
10
+ * 2. `"minor"`,
11
+ * 3. `"patch"`,
12
+ * 4. `null`.
13
+ *
14
+ * In a monorepo context, the release type is also determined according to the internal dependencies.
15
+ * @param commits - The commits to analyse.
16
+ * @param context - The context where the CLI is running.
17
+ * @return An array of objects containing the most important release type found for each package if commits are parsed successfully, `null` if there are no commits or an error is thrown.
18
+ */
19
+ export const getReleaseType = (commits, context) => {
20
+ const { config, packages } = context;
21
+ const { debug } = config;
22
+ const logger = setLogger(debug);
23
+ logger.setScope("commit-analyser");
24
+ const packageReleaseTypes = packages.map(packageItem => ({
25
+ name: packageItem.name,
26
+ releaseType: null
27
+ }));
28
+ if (debug)
29
+ logger.setDebugScope("commit-analyser:get-release-type");
30
+ const totalCommits = commits.length;
31
+ if (totalCommits) {
32
+ const packagesPaths = packages.map(packageItem => packageItem.pathname);
33
+ const releaseTypesPerPackage = new Map();
34
+ for (const commit of commits) {
35
+ const { releaseType, modifiedFiles } = commit;
36
+ if (modifiedFiles?.length) {
37
+ for (const modifiedFile of modifiedFiles) {
38
+ const relatedPackagePath = packagesPaths.find(packagePath => modifiedFile.startsWith(packagePath));
39
+ const relatedPackageName = packages.find(packageItem => packageItem.pathname === relatedPackagePath)?.name ?? "";
40
+ const releaseTypes = releaseTypesPerPackage.get(relatedPackageName) ?? new Set();
41
+ releaseTypes.add(releaseType);
42
+ releaseTypesPerPackage.set(relatedPackageName, releaseTypes);
43
+ }
44
+ }
45
+ else {
46
+ const releaseTypes = releaseTypesPerPackage.get("") ?? new Set();
47
+ releaseTypes.add(releaseType);
48
+ releaseTypesPerPackage.set("", releaseTypes);
49
+ }
50
+ if (debug) {
51
+ logger.logDebug(`Release types by package for commit “${commit.message}”:`);
52
+ logger.logDebug(inspect(releaseTypesPerPackage));
53
+ }
54
+ }
55
+ const adjustedReleaseTypesPerPackage = new Map(adjustReleaseType(context, releaseTypesPerPackage));
56
+ if (debug) {
57
+ logger.logDebug("Overall adjusted release types by package:");
58
+ logger.logDebug(inspect(adjustedReleaseTypesPerPackage));
59
+ }
60
+ const commitWord = agreeInNumber(totalCommits, ["commit", "commits"]);
61
+ logger.logSuccess(`Analysis of ${totalCommits} ${commitWord} complete.`);
62
+ const packageReleaseTypes = [];
63
+ for (const [name, releaseTypes] of adjustedReleaseTypesPerPackage) {
64
+ const packageName = `${name ? name : "root"} package`;
65
+ let releaseType;
66
+ switch (true) {
67
+ case releaseTypes.has("major"): {
68
+ releaseType = "major";
69
+ logger.logSuccess(`For ${packageName}: major release.`);
70
+ break;
71
+ }
72
+ case releaseTypes.has("minor"): {
73
+ releaseType = "minor";
74
+ logger.logSuccess(`For ${packageName}: minor release.`);
75
+ break;
76
+ }
77
+ case releaseTypes.has("patch"): {
78
+ releaseType = "patch";
79
+ logger.logSuccess(`For ${packageName}: patch release.`);
80
+ break;
81
+ }
82
+ default: {
83
+ releaseType = null;
84
+ logger.logSuccess(`For ${packageName}: no release.`);
85
+ break;
86
+ }
87
+ }
88
+ packageReleaseTypes.push({ name, releaseType });
89
+ }
90
+ return packageReleaseTypes;
91
+ }
92
+ logger.logWarn("No commits to analyse: no release.");
93
+ return packageReleaseTypes;
94
+ };
95
+ //# sourceMappingURL=get-release-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-release-type.js","sourceRoot":"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AAC;IAC7B,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;IACrD,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type { PackageReleaseType } from "./commit-analyser.types.js";
2
+ export { getGitTags } from "./get-git-tags.js";
3
+ export { getReleaseType } from "./get-release-type.js";
4
+ export { parseCommit } from "./parse-commit.js";
5
+ export { setReleaseType } from "./set-release-type.js";
6
+ export { COMMIT_ABBREVIATED_SHA_LENGTH, COMMIT_MESSAGE, ISSUE_ID } from "./constants.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { getGitTags } from "./get-git-tags.js";
2
+ export { getReleaseType } from "./get-release-type.js";
3
+ export { parseCommit } from "./parse-commit.js";
4
+ export { setReleaseType } from "./set-release-type.js";
5
+ export { COMMIT_ABBREVIATED_SHA_LENGTH, COMMIT_MESSAGE, ISSUE_ID } from "./constants.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Commit, Context } from "@release-change/shared";
2
+ /**
3
+ * Parses a commit.
4
+ * @param commit - The commit to parse.
5
+ * @param context - The context where the CLI is running.
6
+ * @return The commit as an object, with the message, the footer and the modified files (if in a monorepo context).
7
+ */
8
+ export declare const parseCommit: (commit: string, context: Context) => Commit;
9
+ //# sourceMappingURL=parse-commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-commit.d.ts","sourceRoot":"","sources":["../src/parse-commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAgB9D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,EAAE,SAAS,OAAO,KAAG,MA+E9D,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { inspect } from "node:util";
2
+ import { setLogger } from "@release-change/logger";
3
+ import { formatDetailedError } from "@release-change/shared";
4
+ import { setReleaseType } from "./set-release-type.js";
5
+ import { BLANK_LINE_SEPARATOR, BREAKING_CHANGE, COMMIT_FOOTER_KEY, INDENTED_BLANK_LINE_SEPARATOR } from "./constants.js";
6
+ /**
7
+ * Parses a commit.
8
+ * @param commit - The commit to parse.
9
+ * @param context - The context where the CLI is running.
10
+ * @return The commit as an object, with the message, the footer and the modified files (if in a monorepo context).
11
+ */
12
+ export const parseCommit = (commit, context) => {
13
+ const { config } = context;
14
+ const { debug, isMonorepo } = config;
15
+ const logger = setLogger(debug);
16
+ const parsedCommit = {
17
+ isMergeCommit: false,
18
+ sha: null,
19
+ message: "",
20
+ body: [],
21
+ footer: [],
22
+ releaseType: null
23
+ };
24
+ const commitSections = commit
25
+ .replaceAll(INDENTED_BLANK_LINE_SEPARATOR, BLANK_LINE_SEPARATOR)
26
+ .split(BLANK_LINE_SEPARATOR);
27
+ const [commitHeader, ...commitRest] = commitSections;
28
+ if (commitHeader) {
29
+ parsedCommit.isMergeCommit = commitHeader.split("\n").some(line => line.startsWith("Merge"));
30
+ const [commitSha] = commitHeader.split("\n");
31
+ if (commitSha)
32
+ parsedCommit.sha = commitSha.replace(/^commit\s([0-9a-f]+).*$/, "$1");
33
+ const [commitMessage, ...commitOptionalSections] = commitRest
34
+ .map(line => line.trim())
35
+ .filter(Boolean);
36
+ if (commitMessage) {
37
+ parsedCommit.message = commitMessage;
38
+ const commitOptionalSectionsWithoutFileNames = isMonorepo
39
+ ? commitOptionalSections.slice(0, -1)
40
+ : commitOptionalSections;
41
+ const commitBody = commitOptionalSectionsWithoutFileNames.filter(line => !line.match(COMMIT_FOOTER_KEY) && !line.match(BREAKING_CHANGE));
42
+ const commitFooter = commitOptionalSectionsWithoutFileNames.filter(line => Boolean(line.match(COMMIT_FOOTER_KEY) || line.match(BREAKING_CHANGE)));
43
+ parsedCommit.body = commitBody.map(line => line.trim());
44
+ parsedCommit.footer = commitFooter.flatMap(line => line.split("\n").map(line => line.trim()));
45
+ parsedCommit.releaseType = setReleaseType(parsedCommit.message, parsedCommit.footer, context);
46
+ if (isMonorepo) {
47
+ const commitModifiedFiles = commitOptionalSections
48
+ .slice(-1)
49
+ .filter(line => !line.match(COMMIT_FOOTER_KEY) && !line.match(BREAKING_CHANGE))
50
+ .flatMap(line => line
51
+ .split("\n")
52
+ .map(line => line.trim())
53
+ .filter(file => file.match(/^[0-9a-zA-Z-_./]+$/)));
54
+ if (commitModifiedFiles.length)
55
+ parsedCommit.modifiedFiles = commitModifiedFiles;
56
+ else if (!commitHeader?.match(/^merge:/im)) {
57
+ throw formatDetailedError({
58
+ title: "Failed to parse commit",
59
+ message: "No modified files found while this repository is a monorepo.",
60
+ details: {
61
+ output: "commitModifiedFiles.length: 0"
62
+ }
63
+ });
64
+ }
65
+ }
66
+ if (debug) {
67
+ logger.setDebugScope("commit-analyser:parse-commit");
68
+ logger.logDebug(inspect(parsedCommit, { depth: Number.POSITIVE_INFINITY }));
69
+ }
70
+ return parsedCommit;
71
+ }
72
+ throw formatDetailedError({
73
+ title: "Failed to parse commit",
74
+ message: "No message found.",
75
+ details: {
76
+ output: "commitMessage: undefined"
77
+ }
78
+ });
79
+ }
80
+ throw formatDetailedError({
81
+ title: "Failed to parse commit",
82
+ message: "No header found.",
83
+ details: {
84
+ output: "commitHeader: undefined"
85
+ }
86
+ });
87
+ };
88
+ //# sourceMappingURL=parse-commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-commit.js","sourceRoot":"","sources":["../src/parse-commit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,gBAAgB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAU,EAAE;IACtE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACrC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,YAAY,GAAW;QAC3B,aAAa,EAAE,KAAK;QACpB,GAAG,EAAE,IAAI;QACT,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,IAAI;KAClB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D;wBACvE,OAAO,EAAE;4BACP,MAAM,EAAE,+BAA+B;yBACxC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,aAAa,CAAC,8BAA8B,CAAC,CAAC;gBACrD,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,wBAAwB;YAC/B,OAAO,EAAE,mBAAmB;YAC5B,OAAO,EAAE;gBACP,MAAM,EAAE,0BAA0B;aACnC;SACF,CAAC,CAAC;IACL,CAAC;IACD,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,wBAAwB;QAC/B,OAAO,EAAE,kBAAkB;QAC3B,OAAO,EAAE;YACP,MAAM,EAAE,yBAAyB;SAClC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Context, ReleaseType } from "@release-change/shared";
2
+ /**
3
+ * Sets the release type, based on commit message and footer.
4
+ * @param commitMessage - The parsed commit message.
5
+ * @param commitFooter - The parsed commit footer.
6
+ * @param context - The context where the CLI is running.
7
+ * @return One of `"major"`, `"minor"` and `"patch"` if the commit correlates with a version change, `null` otherwise.
8
+ */
9
+ export declare const setReleaseType: (commitMessage: string, commitFooter: string[], context: Context) => ReleaseType;
10
+ //# sourceMappingURL=set-release-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-release-type.d.ts","sourceRoot":"","sources":["../src/set-release-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAWnE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACzB,eAAe,MAAM,EACrB,cAAc,MAAM,EAAE,EACtB,SAAS,OAAO,KACf,WAuBF,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { setLogger } from "@release-change/logger";
2
+ import { BREAKING_CHANGE, COMMIT_PREFIX_MAJOR, COMMIT_PREFIX_MINOR, COMMIT_PREFIX_PATCH } from "./constants.js";
3
+ /**
4
+ * Sets the release type, based on commit message and footer.
5
+ * @param commitMessage - The parsed commit message.
6
+ * @param commitFooter - The parsed commit footer.
7
+ * @param context - The context where the CLI is running.
8
+ * @return One of `"major"`, `"minor"` and `"patch"` if the commit correlates with a version change, `null` otherwise.
9
+ */
10
+ export const setReleaseType = (commitMessage, commitFooter, context) => {
11
+ const { config } = context;
12
+ const logger = setLogger(config.debug);
13
+ logger.setScope("commit-analyser");
14
+ logger.logInfo(`Analysing commit “${commitMessage}”…`);
15
+ const releaseType = commitFooter.some(line => line.match(BREAKING_CHANGE)) ||
16
+ commitMessage.match(COMMIT_PREFIX_MAJOR)
17
+ ? "major"
18
+ : commitMessage.match(COMMIT_PREFIX_MINOR)
19
+ ? "minor"
20
+ : commitMessage.match(COMMIT_PREFIX_PATCH)
21
+ ? "patch"
22
+ : null;
23
+ const releaseTypeInfoMessage = releaseType
24
+ ? `The release type for the commit is ${releaseType}.`
25
+ : "The commit does not trigger a release.";
26
+ if (config.debug) {
27
+ logger.setDebugScope("commit-analyser:set-release-type");
28
+ logger.logDebug(`Release type: ${releaseType}`);
29
+ }
30
+ logger.logInfo(releaseTypeInfoMessage);
31
+ return releaseType;
32
+ };
33
+ //# sourceMappingURL=set-release-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-release-type.js","sourceRoot":"","sources":["../src/set-release-type.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,aAAqB,EACrB,YAAsB,EACtB,OAAgB,EACH,EAAE;IACf,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,qBAAqB,aAAa,IAAI,CAAC,CAAC;IACvD,MAAM,WAAW,GACf,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACtD,aAAa,CAAC,KAAK,CAAC,mBAAmB,CAAC;QACtC,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,mBAAmB,CAAC;YACxC,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,mBAAmB,CAAC;gBACxC,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,IAAI,CAAC;IACf,MAAM,sBAAsB,GAAG,WAAW;QACxC,CAAC,CAAC,sCAAsC,WAAW,GAAG;QACtD,CAAC,CAAC,wCAAwC,CAAC;IAC7C,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,CAAC,aAAa,CAAC,kCAAkC,CAAC,CAAC;QACzD,MAAM,CAAC,QAAQ,CAAC,iBAAiB,WAAW,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACvC,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@release-change/commit-analyser",
3
+ "version": "0.1.0",
4
+ "description": "Functions used internally in release-change to analyse the commits, based on the Conventional Commits specification",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/release-change/release-change",
7
+ "bugs": {
8
+ "url": "https://github.com/release-change/release-change/issues"
9
+ },
10
+ "author": "Victor Brito (https://victor-brito.dev)",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/release-change/release-change.git"
14
+ },
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ "import": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
23
+ },
24
+ "engines": {
25
+ "node": "^20.18.3 || ^22.12.0 || ^24.0.0",
26
+ "npm": ">=10.8.2",
27
+ "pnpm": ">=10.28.0"
28
+ },
29
+ "dependencies": {
30
+ "@release-change/config": "0.1.0",
31
+ "@release-change/logger": "0.1.0",
32
+ "@release-change/shared": "0.1.0",
33
+ "@release-change/get-packages": "0.1.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc",
37
+ "dev": "tsc --watch --preserveWatchOutput & vitest"
38
+ }
39
+ }