Skip to content

Commit

Permalink
fix: support changelog-presets using async factory funcs
Browse files Browse the repository at this point in the history
 - new 7.x.x versions of conventional changelog presets use async
   factory functions createPreset (see conventional-changelog/conventional-changelog#1045)
  • Loading branch information
amorscher committed Oct 21, 2023
1 parent 572ab7f commit 5bc9a46
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

// https://github.com/conventional-changelog/conventional-changelog/blob/b516084ef6a725197f148236c0ddbfae7ffe3e6f/packages/conventional-changelog-angular/conventional-recommended-bump.js
const parserOpts = require("./parser-opts");
const writerOpts = require("./writer-opts");
const whatBump = require("./what-bump");

async function createPreset(config) {
return {
conventionalChangelog: {
parserOpts,
writerOpts,
},
recommendedBumpOpts: {
parserOpts,
whatBump,
},
};
}
module.exports = createPreset;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { ChangelogPresetConfig } from "./constants";
const cfgCache = new Map();

function isFunction(config: any) {
return Object.prototype.toString.call(config) === "[object Function]";
return (
Object.prototype.toString.call(config) === "[object Function]" ||
Object.prototype.toString.call(config) === "[object AsyncFunction]"
);
}

function resolveConfigPromise(presetPackageName: string, presetConfig: object) {
Expand Down
15 changes: 15 additions & 0 deletions libs/core/src/lib/conventional-commits/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ describe("conventional-commits", () => {
expect(bump).toBe("1.1.0");
});

it("supports async function presets", async () => {
const cwd = await initFixture("fixed");
const [pkg1] = await getPackages(cwd);

// make a change in package-1
await pkg1.set("changed", 1).serialize();
await gitAdd(cwd, pkg1.manifestLocation);
await gitCommit(cwd, "feat: changed 1");

const bump = await recommendVersion(pkg1, "fixed", {
changelogPreset: "./scripts/local-preset-async.js",
});
expect(bump).toBe("1.1.0");
});

it("supports custom tagPrefix in fixed mode", async () => {
const cwd = await initFixture("fixed");

Expand Down

0 comments on commit 5bc9a46

Please sign in to comment.