Skip to content

Commit

Permalink
Migrate to conventional-changelog v6 + conventional-recommended-bump v10
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 6, 2024
1 parent 93cf856 commit c4b9886
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ Options are passed verbatim to
and
[conventional-changelog-core](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-core#api).

### Contents

- [`infile`](#infile)
- [`header`](#header)
- [`ignoreRecommendedBump`](#ignorerecommendedbump)
- [`strictSemVer`](#strictsemver)
- [`preset`](#preset)
- [`context`](#context)
- [`gitRawCommitsOpts`](#gitrawcommitsopts)
- [`parserOpts`](#parseropts)
- [`writerOpts`](#writeropts)
- [`bumperCommitsOpts`](#bumpercommitsopts)
- [`bumperTagOpts`](#bumpertagopts)
- [`bumperParserOpts`](#bumperparseropts)

### `preset`

Use one of:
Expand Down Expand Up @@ -69,6 +84,9 @@ See the
[Conventional Changelog Configuration Spec (v2.1.0)](https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.1.0/README.md)
for the configuration object to pass as `preset`.

This is also passed as the first argument to
[`bumper.loadPreset`](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/README.md#api).

### `infile`

Default value: `undefined`
Expand Down Expand Up @@ -213,6 +231,21 @@ module.exports = {
};
```

### `bumperTagOpts`

This option will be passed as the first argument to
[`bumper.tag`](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/README.md#api)

### `bumperCommitsOpts`

This option will be passed as the first argument to
[`bumper.commits`](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/README.md#api)

### `bumperParserOpts`

This option will be passed as the second argument to
[`bumper.parserOptions`](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/README.md#api)

## Command-line

Options for this plugin can be set from the command line. Some examples:
Expand Down
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EOL } from 'os';
import fs from 'fs';
import { Plugin } from 'release-it';
import conventionalRecommendedBump from 'conventional-recommended-bump';
import { Bumper } from 'conventional-recommended-bump';
import conventionalChangelog from 'conventional-changelog';
import semver from 'semver';
import concat from 'concat-stream';
Expand Down Expand Up @@ -37,13 +37,25 @@ class ConventionalChangelog extends Plugin {
this.debug({ increment, latestVersion, isPreRelease, preReleaseId });
this.debug('conventionalRecommendedBump', { options });
try {
const result = await conventionalRecommendedBump(options, options?.parserOpts);
const bumper = new Bumper();

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

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

if (options.bumperCommitsOpts) bumper.commits(options.bumperCommitsOpts, options.bumperParserOpts); // paramsOrCommits, parserOptions

const result = await bumper.bump(options.whatBump);

this.debug({ result });

let { releaseType } = result;

if (increment) {
this.log.warn(`The recommended bump is "${releaseType}", but is overridden with "${increment}".`);
releaseType = increment;
}

if (increment && semver.valid(increment)) {
return increment;
} else if (isPreRelease) {
Expand All @@ -59,10 +71,9 @@ class ConventionalChangelog extends Plugin {
cwd: options.cwd
});

const { releaseType: releaseTypeToLastNonPrerelease } = await conventionalRecommendedBump({
...options,
skipUnstable: true
});
bumper.tag({ ...options.bumperTagOpts, skipUnstable: true });

const { releaseType: releaseTypeToLastNonPrerelease } = await bumper.bump(options.whatBump);

const lastStableTag = tags.length > 0 ? tags[0] : null;

Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"./package.json": "./package.json"
},
"scripts": {
"test": "bron test.js --serial",
"test": "node --test test.js",
"release": "release-it"
},
"keywords": [
Expand All @@ -35,17 +35,16 @@
},
"dependencies": {
"concat-stream": "^2.0.0",
"conventional-changelog": "^5.1.0",
"conventional-recommended-bump": "^9.0.0",
"conventional-changelog": "^6.0.0",
"conventional-recommended-bump": "^10.0.0",
"git-semver-tags": "^8.0.0",
"semver": "^7.6.3"
},
"devDependencies": {
"bron": "^2.0.3",
"installed-check": "^9.3.0",
"release-it": "^17.6.0",
"release-it": "^17.7.0",
"shelljs": "^0.8.5",
"sinon": "^18.0.1",
"sinon": "^19.0.2",
"tmp": "^0.2.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'bron';
import test from 'node:test';
import { strict as assert } from 'assert';
import fs from 'fs';
import path from 'path';
Expand Down

0 comments on commit c4b9886

Please sign in to comment.