Skip to content

Commit

Permalink
feat(conventional-changelog-presets): supported new preset format
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the new preset format is a breaking change when compared to the previous preset format. updating to support the new format means that the old preset format is no longer supported. update your preset to the latest version to maintain compatibility
  • Loading branch information
travi committed Sep 1, 2023
1 parent eb505f2 commit a681671
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 55 deletions.
12 changes: 3 additions & 9 deletions lib/load-changelog-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ export default async ({ preset, config, parserOpts, writerOpts, presetConfig },

if (preset) {
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage);
loadedConfig = await (importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage))(presetConfig);
} else if (config) {
loadedConfig = importFrom.silent(__dirname, config) || importFrom(cwd, config);
loadedConfig = await (importFrom.silent(__dirname, config) || importFrom(cwd, config))();
} else {
loadedConfig = conventionalChangelogAngular;
loadedConfig = await conventionalChangelogAngular();
}

loadedConfig = await (typeof loadedConfig === "function"
? isPlainObject(presetConfig)
? loadedConfig(presetConfig)
: promisify(loadedConfig)()
: loadedConfig);

return {
parserOpts: { ...loadedConfig.parserOpts, ...parserOpts },
writerOpts: { ...loadedConfig.writerOpts, ...writerOpts },
Expand Down
84 changes: 54 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Gregor Martynus (https://twitter.com/gr2m)"
],
"dependencies": {
"conventional-changelog-angular": "^6.0.0",
"conventional-changelog-angular": "^7.0.0",
"conventional-changelog-writer": "^6.0.0",
"conventional-commits-filter": "^4.0.0",
"conventional-commits-parser": "^5.0.0",
Expand All @@ -25,12 +25,12 @@
"devDependencies": {
"ava": "5.3.1",
"c8": "8.0.1",
"conventional-changelog-atom": "3.0.0",
"conventional-changelog-atom": "4.0.0",
"conventional-changelog-conventionalcommits": "7.0.1",
"conventional-changelog-ember": "3.0.0",
"conventional-changelog-eslint": "4.0.0",
"conventional-changelog-express": "3.0.0",
"conventional-changelog-jshint": "3.0.0",
"conventional-changelog-ember": "4.0.0",
"conventional-changelog-eslint": "5.0.0",
"conventional-changelog-express": "4.0.0",
"conventional-changelog-jshint": "4.0.0",
"escape-string-regexp": "5.0.0",
"fs-extra": "11.1.1",
"prettier": "3.0.3",
Expand Down Expand Up @@ -92,8 +92,8 @@
"lint:fix": "prettier --write \"*.{js,json,md}\" \".github/**/*.{md,yml}\" \"{bin,lib,test}/*.js\"",
"pretest": "npm run lint",
"semantic-release": "semantic-release",
"test": "c8 ava -v",
"test:ci": "c8 ava -v"
"test": "c8 ava --verbose",
"test:ci": "c8 ava --verbose"
},
"type": "module",
"ava": {
Expand Down
3 changes: 2 additions & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import escape from "escape-string-regexp";
import { temporaryDirectory } from "tempy";
import * as td from "testdouble";
import streamBuffers from "stream-buffers";
import conventionalChangelogEslint from "conventional-changelog-eslint";

const cwd = process.cwd();
const host = "https://github.com";
Expand Down Expand Up @@ -178,7 +179,7 @@ test.serial('Accept a "parseOpts" and "writerOpts" objects as option', async (t)
referenceActions: ["keyword"],
issuePrefixes: ["#", "JIRA-"],
},
writerOpts: (await promisify((await import("conventional-changelog-eslint")).default)()).writerOpts,
writerOpts: (await conventionalChangelogEslint()).writerOpts,
},
{ cwd, options: { repositoryUrl }, lastRelease, nextRelease, commits }
);
Expand Down
15 changes: 8 additions & 7 deletions test/load-changelog-config.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from "ava";
import conventionalChangelogAngular from "conventional-changelog-angular";
import loadChangelogConfig from "../lib/load-changelog-config.js";

const cwd = process.cwd();
Expand Down Expand Up @@ -42,7 +43,7 @@ loadConfig.title = (providedTitle, config) => `${providedTitle} Load "${config}"

test('Load "conventional-changelog-angular" by default', async (t) => {
const changelogConfig = await loadChangelogConfig({}, { cwd });
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.deepEqual(changelogConfig.parserOpts, angularChangelogConfig.parserOpts);
t.deepEqual(changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
Expand All @@ -54,7 +55,7 @@ test('Accept a "parserOpts" object as option', async (t) => {
headerCorrespondence: ["tag", "shortDesc"],
};
const changelogConfig = await loadChangelogConfig({ parserOpts: customParserOptions }, { cwd });
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.is(customParserOptions.headerPattern, changelogConfig.parserOpts.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, changelogConfig.parserOpts.headerCorrespondence);
Expand All @@ -65,7 +66,7 @@ test('Accept a "parserOpts" object as option', async (t) => {
test('Accept a "writerOpts" object as option', async (t) => {
const customWriterOptions = { commitGroupsSort: "title", commitsSort: ["scope", "subject"] };
const changelogConfig = await loadChangelogConfig({ writerOpts: customWriterOptions }, { cwd });
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.is(customWriterOptions.commitGroupsSort, changelogConfig.writerOpts.commitGroupsSort);
t.deepEqual(customWriterOptions.commitsSort, changelogConfig.writerOpts.commitsSort);
Expand All @@ -79,7 +80,7 @@ test('Accept a partial "parserOpts" object as option that overwrite a preset', a
headerCorrespondence: ["tag", "shortDesc"],
};
const changelogConfig = await loadChangelogConfig({ parserOpts: customParserOptions, preset: "angular" }, { cwd });
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.is(customParserOptions.headerPattern, changelogConfig.parserOpts.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, changelogConfig.parserOpts.headerCorrespondence);
Expand All @@ -90,7 +91,7 @@ test('Accept a partial "parserOpts" object as option that overwrite a preset', a
test('Accept a "writerOpts" object as option that overwrite a preset', async (t) => {
const customWriterOptions = { commitGroupsSort: "title", commitsSort: ["scope", "subject"] };
const changelogConfig = await loadChangelogConfig({ writerOpts: customWriterOptions, preset: "angular" }, { cwd });
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.is(customWriterOptions.commitGroupsSort, changelogConfig.writerOpts.commitGroupsSort);
t.deepEqual(customWriterOptions.commitsSort, changelogConfig.writerOpts.commitsSort);
Expand All @@ -110,7 +111,7 @@ test('Accept a partial "parserOpts" object as option that overwrite a config', a
},
{ cwd }
);
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.is(customParserOptions.headerPattern, changelogConfig.parserOpts.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, changelogConfig.parserOpts.headerCorrespondence);
Expand All @@ -127,7 +128,7 @@ test('Accept a "writerOpts" object as option that overwrite a config', async (t)
},
{ cwd }
);
const angularChangelogConfig = await (await import("conventional-changelog-angular")).default;
const angularChangelogConfig = await conventionalChangelogAngular();

t.is(customWriterOptions.commitGroupsSort, changelogConfig.writerOpts.commitGroupsSort);
t.deepEqual(customWriterOptions.commitsSort, changelogConfig.writerOpts.commitsSort);
Expand Down

0 comments on commit a681671

Please sign in to comment.