Skip to content

Commit 0254d7a

Browse files
committedMay 25, 2024
feat: support latest conventional-changelog packages
BREAKING CHANGE: by supporting the latest major versions of conventional-changelog packages, we are dropping support for previous major versions of those packages due to the breaking changes between majors. this only impacts your project if you are installing alongside semantic-release, so updating those packages to latest version should be the only change you need for this update. no action should be necessary if you are using default semantic-release config
1 parent 7a2902e commit 0254d7a

File tree

5 files changed

+1405
-1938
lines changed

5 files changed

+1405
-1938
lines changed
 

‎index.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isUndefined } from "lodash-es";
2-
import { sync as parser } from "conventional-commits-parser";
3-
import filter from "conventional-commits-filter";
2+
import { CommitParser } from "conventional-commits-parser";
3+
import { filterRevertedCommitsSync } from "conventional-commits-filter";
44
import debugFactory from "debug";
55
import loadParserConfig from "./lib/load-parser-config.js";
66
import loadReleaseRules from "./lib/load-release-rules.js";
@@ -31,7 +31,8 @@ export async function analyzeCommits(pluginConfig, context) {
3131
const config = await loadParserConfig(pluginConfig, context);
3232
let releaseType = null;
3333

34-
filter(
34+
const parser = new CommitParser(config)
35+
const filteredCommits = filterRevertedCommitsSync(
3536
commits
3637
.filter(({ message, hash }) => {
3738
if (!message.trim()) {
@@ -41,9 +42,15 @@ export async function analyzeCommits(pluginConfig, context) {
4142

4243
return true;
4344
})
44-
.map(({ message, ...commitProps }) => ({ rawMsg: message, message, ...commitProps, ...parser(message, config) }))
45-
).every(({ rawMsg, ...commit }) => {
46-
logger.log(`Analyzing commit: %s`, rawMsg);
45+
.map((rawCommit) => ({
46+
...rawCommit,
47+
...parser.parse(rawCommit.message)
48+
}))
49+
);
50+
51+
for (const { message, ...commit } of filteredCommits) {
52+
console.log(`Analyzing commit: %s`, message)
53+
logger.log(`Analyzing commit: %s`, message);
4754
let commitReleaseType;
4855

4956
// Determine release type based on custom releaseRules
@@ -71,11 +78,10 @@ export async function analyzeCommits(pluginConfig, context) {
7178

7279
// Break loop if releaseType is the highest
7380
if (releaseType === RELEASE_TYPES[0]) {
74-
return false;
81+
break;
7582
}
83+
}
7684

77-
return true;
78-
});
7985
logger.log("Analysis of %s commits complete: %s release", commits.length, releaseType || "no");
8086

8187
return releaseType;

‎lib/load-parser-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ export default async ({ preset, config, parserOpts, presetConfig }, { cwd }) =>
3030
loadedConfig = await conventionalChangelogAngular();
3131
}
3232

33-
return { ...loadedConfig.parserOpts, ...parserOpts };
33+
return { ...loadedConfig.parser, ...parserOpts };
3434
};

‎package-lock.json

+1,376-1,916
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
"Gregor Martynus (https://twitter.com/gr2m)"
1919
],
2020
"dependencies": {
21-
"conventional-changelog-angular": "^7.0.0",
22-
"conventional-commits-filter": "^4.0.0",
23-
"conventional-commits-parser": "^5.0.0",
21+
"conventional-changelog-angular": "^8.0.0",
22+
"conventional-changelog-writer": "^8.0.0",
23+
"conventional-commits-filter": "^5.0.0",
24+
"conventional-commits-parser": "^6.0.0",
2425
"debug": "^4.0.0",
2526
"import-from-esm": "^1.0.3",
2627
"lodash-es": "^4.17.21",
@@ -29,12 +30,12 @@
2930
"devDependencies": {
3031
"ava": "6.1.3",
3132
"c8": "9.1.0",
32-
"conventional-changelog-atom": "4.0.0",
33-
"conventional-changelog-conventionalcommits": "7.0.2",
34-
"conventional-changelog-ember": "4.0.0",
35-
"conventional-changelog-eslint": "5.0.0",
36-
"conventional-changelog-express": "4.0.0",
37-
"conventional-changelog-jshint": "4.0.0",
33+
"conventional-changelog-atom": "5.0.0",
34+
"conventional-changelog-conventionalcommits": "8.0.0",
35+
"conventional-changelog-ember": "5.0.0",
36+
"conventional-changelog-eslint": "6.0.0",
37+
"conventional-changelog-express": "5.0.0",
38+
"conventional-changelog-jshint": "5.0.0",
3839
"lockfile-lint": "4.13.2",
3940
"ls-engines": "0.9.1",
4041
"npm-run-all2": "6.2.0",

‎test/integration.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ test('Accept a partial "parseOpts" object as option', async (t) => {
9999

100100
test("Exclude commits if they have a matching revert commits", async (t) => {
101101
const commits = [
102-
{ message: "fix(scope): First fix" },
103-
{ hash: "456", message: "revert: feat(scope): First feature\n\nThis reverts commit 123.\n" },
104-
{ hash: "123", message: "feat(scope): First feature" },
102+
{ hash: "df012f1", message: "fix(scope): First fix" },
103+
{ hash: "df012f2", message: "revert: feat(scope): First feature\n\nThis reverts commit df012f3.\n" },
104+
{ hash: "df012f3", message: "feat(scope): First feature" },
105105
];
106106
const releaseType = await analyzeCommits({}, { cwd, commits, logger: t.context.logger });
107107

0 commit comments

Comments
 (0)
Please sign in to comment.