Skip to content

Commit

Permalink
fix: Resolve whatBump is not a function error (#105)
Browse files Browse the repository at this point in the history
* fix: Resolve pending preset promise

* fix: Get recommended version bump

* chore: Remove redundant if logic

* refactor: Avoid code repetition

* docs: Explain how to use the whatBump config option to skip releasing a new version

* refactor: Make whatBump's value conventional
  • Loading branch information
oluwatobiss authored Oct 29, 2024
1 parent 04cc0aa commit 5e0af0c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ for the configuration object to pass as `preset`.
- This option will be passed as the first argument to
[`bumper.bump`](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/README.md#api)
- [Type definition for `whatBump` → look for `Preset['whatBump']`](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/src/types.ts)
- Use the `false` Boolean value to skip releasing a new version.

```json
{
"plugins": {
"@release-it/conventional-changelog": {
"whatBump": false
}
}
}
```

### `ignoreRecommendedBump`

Expand Down
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,30 @@ class ConventionalChangelog extends Plugin {
try {
const bumper = new Bumper();

if (options.preset) bumper.loadPreset(options.preset);
if (options.preset) await bumper.loadPreset(options.preset).preset;

if (options.tagOpts) bumper.tag(options.tagOpts);

if (options.commitsOpts) bumper.commits(options.commitsOpts, options.parserOpts);

const result = await bumper.bump(options.whatBump);
async function getWhatBump() {
if (options.whatBump === false) {
return () => ({ releaseType: null });
} else {
const bumperPreset = await bumper.preset;

if (bumperPreset === null) return () => ({ releaseType: null });

return bumperPreset.whatBump || bumperPreset.recommendedBumpOpts.whatBump;
}
}

const result = await bumper.bump(await getWhatBump());

this.debug({ result });

let { releaseType } = result;

if (releaseType == undefined) {
return;
}

if (increment) {
this.log.warn(`The recommended bump is "${releaseType}", but is overridden with "${increment}".`);
releaseType = increment;
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ test('should not bump when recommended bump returns null', async () => {
}
});

test('should not bump when whatBump === false', async () => {
setup();
sh.exec(`git tag 1.0.0`);
add('fix', 'bar');
add('feat', 'baz');
{
const options = getOptions({ whatBump: false });
const { version } = await runTasks(...options);
assert.equal(version, undefined);
}
});

// TODO Prepare test and verify results influenced by parserOpts and writerOpts
test.skip('should pass parserOpts and writerOpts', async t => {
setup();
Expand Down

0 comments on commit 5e0af0c

Please sign in to comment.