commit-and-tag-version 13.2.0 → 13.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [13.2.2](https://github.com/absolute-version/commit-and-tag-version/compare/v13.2.1...v13.2.2) (2026-10-13)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * accept parser and writer options from conventional-changelog 7+ presets ([#351](https://github.com/absolute-version/commit-and-tag-version/issues/351)) ([18b7416](https://github.com/absolute-version/commit-and-tag-version/commit/18b7416bd86651b1b0a62af212165baba0e771a7)), closes [#328](https://github.com/absolute-version/commit-and-tag-version/issues/328)
11
+ * list only the changes since the previous prerelease with the same name in each prerelease changelog section, instead of repeating everything since the last stable release. Stable releases, and the first prerelease with a new name, still list everything since the last stable release. (fixes [#349](https://github.com/absolute-version/commit-and-tag-version/issues/349)) ([#350](https://github.com/absolute-version/commit-and-tag-version/issues/350)) ([a95edce](https://github.com/absolute-version/commit-and-tag-version/commit/a95edce7b350bb31376a1fd9553d2a81b43fcbfc))
12
+
13
+ ## [13.2.1](https://github.com/absolute-version/commit-and-tag-version/compare/v13.2.0...v13.2.1) (2026-09-14)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * bring back the blank line between release notes sections ([#341](https://github.com/absolute-version/commit-and-tag-version/issues/341)) ([4248f1a](https://github.com/absolute-version/commit-and-tag-version/commit/4248f1ab142784e84b4dc3fb19d02a25b92705a3))
19
+
5
20
  ## [13.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.1.2...v13.2.0) (2026-09-08)
6
21
 
7
22
 
package/README.md CHANGED
@@ -225,6 +225,8 @@ You can override both [parser](https://github.com/conventional-changelog/convent
225
225
  }
226
226
  ```
227
227
 
228
+ `parser` and `writer` are accepted as aliases of `parserOpts` and `writerOpts`, matching the shape of presets built on conventional-changelog 7+, so such a preset can be used directly as the configuration (e.g. `commit-and-tag-version --config ./my-preset.js`). If both are set, `parserOpts`/`writerOpts` take precedence.
229
+
228
230
  ## CLI Usage
229
231
 
230
232
  > **NOTE:** To pass nested configurations to the CLI without defining them in the `package.json` use dot notation as the parameters `e.g. --skip.changelog`.
@@ -242,7 +244,7 @@ commit-and-tag-version --first-release
242
244
  npx commit-and-tag-version --first-release
243
245
  ```
244
246
 
245
- This will tag a release **without bumping the version `bumpFiles`[1]()**.
247
+ This will tag a release **without bumping the version `bumpFiles`[1](<>)**.
246
248
 
247
249
  When you are ready, push the git tag and `npm publish` your first release. \o/
248
250
 
@@ -299,6 +301,29 @@ commit-and-tag-version --prerelease xyz # Creates v1.4.3-xyz.1 (auto-incremente
299
301
 
300
302
  This behavior applies to both named prereleases (e.g., `-alpha.0`, `-beta.1`) and unnamed prereleases (e.g., `-0`, `-1`), ensuring that you can safely cut multiple prerelease versions without encountering git tag conflicts.
301
303
 
304
+ #### What Each Changelog Section Covers
305
+
306
+ Each release's changelog section starts where the previous release ended, and which earlier release counts as "previous" depends on what you are releasing:
307
+
308
+ - A stable release covers everything since the last stable release, including changes that already appeared in prereleases.
309
+ - A prerelease covers everything since the most recent tag that is either a stable release or a prerelease with the same name. Prereleases with other names are ignored.
310
+
311
+ For example, starting from `v1.0.0`:
312
+
313
+ ```bash
314
+ # feat: add a
315
+ commit-and-tag-version --prerelease alpha # v1.1.0-alpha.0 lists "add a"
316
+ # feat: add b
317
+ commit-and-tag-version --prerelease alpha # v1.1.0-alpha.1 lists "add b" only
318
+ # fix: correct c
319
+ commit-and-tag-version --prerelease beta # v1.1.0-beta.0 lists a, b and c: it is the first beta
320
+ commit-and-tag-version # v1.1.0 lists a, b and c
321
+ ```
322
+
323
+ The compare link in each heading starts from the same tag, so `v1.1.0-alpha.1` links to `v1.1.0-alpha.0...v1.1.0-alpha.1` and `v1.1.0` links to `v1.0.0...v1.1.0`.
324
+
325
+ Unnamed prereleases (e.g., `-0`, `-1`) are treated as sharing one name.
326
+
302
327
  #### Keeping Prereleases out of a Final Changelog
303
328
 
304
329
  `commit-and-tag-version` does not currently provide a general-purpose option to
@@ -663,7 +688,7 @@ module.exports.writeVersion = function (contents, version) {
663
688
  ### Why do breaking changes before 1.0.0 not trigger a 1.0.0 release?
664
689
 
665
690
  Below 1.0.0, the semver specification doesn't give any guarantees about the
666
- meaning of version numbers.
691
+ meaning of version numbers.
667
692
 
668
693
  However, with npm there is a community convention,
669
694
  and implementation-defined behaviour: If your version is between 0.1.0 and
@@ -7,7 +7,7 @@ import path from 'path';
7
7
  import semver from 'semver';
8
8
  import { ConventionalGitClient } from '@conventional-changelog/git-client';
9
9
  import checkpoint from '../checkpoint.js';
10
- import presetLoader from '../preset-loader.js';
10
+ import presetLoader, { getParserOpts } from '../preset-loader.js';
11
11
  import runLifecycleScript from '../run-lifecycle-script.js';
12
12
  import writeFile from '../write-file.js';
13
13
  import { resolveUpdaterObjectFromArgument } from '../updaters/index.js';
@@ -296,7 +296,7 @@ async function bumpVersion(releaseAs, currentVersion, args) {
296
296
  // towards the next version (#310).
297
297
  skipUnstable: true,
298
298
  })
299
- .commits({ path: args.path }, args.parserOpts);
299
+ .commits({ path: args.path }, getParserOpts(args));
300
300
 
301
301
  if (args.verbose) {
302
302
  bumper.options({
@@ -1,9 +1,13 @@
1
+ import { ConventionalGitClient } from '@conventional-changelog/git-client';
1
2
  import chalk from 'chalk';
2
3
  import { ConventionalChangelog } from 'conventional-changelog';
3
4
  import fs from 'fs';
4
5
  import semver from 'semver';
5
6
  import checkpoint from '../checkpoint.js';
6
- import presetLoader from '../preset-loader.js';
7
+ import presetLoader, {
8
+ getParserOpts,
9
+ getWriterOpts,
10
+ } from '../preset-loader.js';
7
11
  import runLifecycleScript from '../run-lifecycle-script.js';
8
12
  import writeFile from '../write-file.js';
9
13
 
@@ -42,6 +46,52 @@ function extractChangelogBody(oldContent) {
42
46
  : oldContent;
43
47
  }
44
48
 
49
+ /**
50
+ * The prerelease identifier of a version: 'alpha' for 1.0.0-alpha.1, '' for an
51
+ * unnamed prerelease such as 1.0.0-0, and null for a stable version.
52
+ */
53
+ function prereleaseChannel(version) {
54
+ const prerelease = semver.prerelease(version);
55
+ if (!prerelease) return null;
56
+ return typeof prerelease[0] === 'string' ? prerelease[0] : '';
57
+ }
58
+
59
+ /**
60
+ * Whether an earlier release ends the changelog section of the version being
61
+ * released. Stable releases always do. Prereleases only do for a later
62
+ * prerelease with the same identifier, so that:
63
+ * - a stable release, or the first prerelease with a new identifier, covers
64
+ * everything since the last stable release, including changes that only
65
+ * appeared in other prereleases (#310)
66
+ * - a continued prerelease only covers changes since the previous prerelease
67
+ * with that identifier, rather than repeating them every time (#349)
68
+ */
69
+ function isReleaseBoundary(version, newVersion) {
70
+ if (!semver.valid(version)) return false;
71
+ const channel = prereleaseChannel(version);
72
+ return channel === null || channel === prereleaseChannel(newVersion);
73
+ }
74
+
75
+ /**
76
+ * Git client that only reports the tags which are release boundaries for the
77
+ * version being released, so the changelog's commit range, section splits
78
+ * and compare links all agree on where the previous release was.
79
+ */
80
+ class ReleaseBoundaryGitClient extends ConventionalGitClient {
81
+ constructor(cwd, newVersion) {
82
+ super(cwd);
83
+ this.newVersion = newVersion;
84
+ }
85
+
86
+ async *getSemverTags(params = {}) {
87
+ for await (const tag of super.getSemverTags(params)) {
88
+ if (isReleaseBoundary(tag.replace(params.prefix, ''), this.newVersion)) {
89
+ yield tag;
90
+ }
91
+ }
92
+ }
93
+ }
94
+
45
95
  async function outputChangelog(args, newVersion) {
46
96
  createIfMissing(args);
47
97
  const header = args.header;
@@ -55,13 +105,12 @@ async function outputChangelog(args, newVersion) {
55
105
 
56
106
  const changelogFrontMatter = extractFrontMatter(oldContent);
57
107
 
58
- const generator = new ConventionalChangelog()
108
+ const generator = new ConventionalChangelog(
109
+ new ReleaseBoundaryGitClient(process.cwd(), newVersion),
110
+ )
59
111
  .readPackage()
60
112
  .loadPreset(presetLoader(args))
61
- // skipUnstable keeps the changelog window aligned with the bump logic:
62
- // both cover all commits since the last stable release, so changes that
63
- // only appeared in prereleases are not dropped from the release (#310).
64
- .tags({ prefix: args.tagPrefix, skipUnstable: true })
113
+ .tags({ prefix: args.tagPrefix })
65
114
  .options({
66
115
  releaseCount: args.releaseCount,
67
116
  ...(args.verbose
@@ -71,16 +120,13 @@ async function outputChangelog(args, newVersion) {
71
120
  : {}),
72
121
  })
73
122
  .context({ version: newVersion })
74
- .commits({ merges: null, path: args.path }, args.parserOpts)
123
+ .commits({ merges: null, path: args.path }, getParserOpts(args))
75
124
  .writer({
76
- // Split sections at stable release tags only, so commits already
77
- // released in intermediate prereleases stay in this release's section
78
- // rather than being regenerated under the prerelease's heading (#310).
79
- generateOn: (commit) =>
80
- Boolean(
81
- semver.valid(commit.version) && !semver.prerelease(commit.version),
82
- ),
83
- ...(args.writerOpts || {}),
125
+ // Split sections at the same tags the commit range is built from, so
126
+ // commits released in other prereleases stay in this release's section
127
+ // rather than being regenerated under that prerelease's heading.
128
+ generateOn: (commit) => isReleaseBoundary(commit.version, newVersion),
129
+ ...(getWriterOpts(args) || {}),
84
130
  });
85
131
 
86
132
  let content = '';
@@ -97,7 +143,7 @@ async function outputChangelog(args, newVersion) {
97
143
  changelogFrontMatter +
98
144
  header +
99
145
  '\n' +
100
- (content + oldContentBody).replace(/\n+$/, '\n'),
146
+ (content + '\n' + oldContentBody).replace(/\n+$/, '\n'),
101
147
  );
102
148
  }
103
149
 
@@ -66,6 +66,27 @@ function translateSpecOptionsToPresetConfig(preset) {
66
66
  return preset;
67
67
  }
68
68
 
69
+ /**
70
+ * Presets built on conventional-changelog >= 7 return their parser and writer
71
+ * options under `parser` and `writer` (older presets used `parserOpts` and
72
+ * `writerOpts`). Accept both shapes so a preset object can be used directly as
73
+ * the configuration (e.g. `--config ./my-preset.js`). When both are present,
74
+ * the `*Opts` keys take precedence.
75
+ */
76
+ function mergeOptions(newStyle, legacy) {
77
+ if (newStyle === undefined) return legacy;
78
+ if (legacy === undefined) return newStyle;
79
+ return { ...newStyle, ...legacy };
80
+ }
81
+
82
+ export function getParserOpts(args) {
83
+ return mergeOptions(args.parser, args.parserOpts);
84
+ }
85
+
86
+ export function getWriterOpts(args) {
87
+ return mergeOptions(args.writer, args.writerOpts);
88
+ }
89
+
69
90
  export default (args) => {
70
91
  let preset = args.preset || DEFAULT_PRESET;
71
92
  if (preset === DEFAULT_PRESET) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "13.2.0",
3
+ "version": "13.2.2",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -51,13 +51,13 @@
51
51
  "chalk": "^6.0.0",
52
52
  "conventional-changelog": "8.1.0",
53
53
  "conventional-changelog-config-spec": "2.1.0",
54
- "conventional-changelog-conventionalcommits": "10.2.1",
54
+ "conventional-changelog-conventionalcommits": "10.4.0",
55
55
  "conventional-recommended-bump": "12.1.0",
56
56
  "detect-indent": "^7.0.2",
57
57
  "detect-newline": "^3.1.0",
58
58
  "dotgitignore": "^2.1.0",
59
59
  "fast-xml-parser": "^5.10.1",
60
- "figures": "^3.2.0",
60
+ "figures": "^6.1.0",
61
61
  "find-up": "^5.0.0",
62
62
  "semver": "^7.7.2",
63
63
  "yaml": "^2.9.0",
@@ -66,11 +66,11 @@
66
66
  "devDependencies": {
67
67
  "@eslint/js": "^10.0.1",
68
68
  "@vitest/coverage-istanbul": "^4.1.11",
69
- "@vitest/eslint-plugin": "^1.6.26",
70
- "conventional-changelog-angular": "^9.2.1",
69
+ "@vitest/eslint-plugin": "^1.6.27",
70
+ "conventional-changelog-angular": "^9.4.0",
71
71
  "eslint": "^10.8.1",
72
72
  "eslint-config-prettier": "^10.1.8",
73
- "globals": "^17.11.0",
73
+ "globals": "^17.12.0",
74
74
  "istanbul-lib-instrument": "^6.0.3",
75
75
  "pirates": "^4.0.7",
76
76
  "prettier": "^3.9.6",
package/test/core.spec.js CHANGED
@@ -389,7 +389,13 @@ describe('cli', function () {
389
389
  verifyNewChangelogContentEquals({
390
390
  writeFileSyncSpy,
391
391
  expectedContent:
392
- frontMatter + '\n' + header + '\n' + changelog101 + changelog100,
392
+ frontMatter +
393
+ '\n' +
394
+ header +
395
+ '\n' +
396
+ changelog101 +
397
+ '\n' +
398
+ changelog100,
393
399
  });
394
400
  });
395
401
 
@@ -417,7 +423,13 @@ describe('cli', function () {
417
423
  verifyNewChangelogContentEquals({
418
424
  writeFileSyncSpy,
419
425
  expectedContent:
420
- frontMatter + '\n' + header + '\n' + changelog101 + changelog100,
426
+ frontMatter +
427
+ '\n' +
428
+ header +
429
+ '\n' +
430
+ changelog101 +
431
+ '\n' +
432
+ changelog100,
421
433
  });
422
434
  });
423
435
 
@@ -446,7 +458,7 @@ describe('cli', function () {
446
458
  await exec();
447
459
  verifyNewChangelogContentEquals({
448
460
  writeFileSyncSpy,
449
- expectedContent: header + '\n' + changelog2 + changelog1,
461
+ expectedContent: header + '\n' + changelog2 + '\n' + changelog1,
450
462
  });
451
463
  });
452
464
 
@@ -90,6 +90,43 @@ export default {
90
90
  expect(output).not.toContain('commitPartial is not a function');
91
91
  });
92
92
 
93
+ it('uses the parser and writer options of a preset used as the config', function () {
94
+ // conventional-changelog >= 7 presets return `parser` and `writer`
95
+ // instead of `parserOpts` and `writerOpts` (#328).
96
+ fs.writeFileSync(
97
+ '.versionrc.js',
98
+ `import createPreset from 'conventional-changelog-conventionalcommits'
99
+
100
+ export default function () {
101
+ return createPreset({
102
+ types: [{ type: 'feat', section: 'Shiny Features' }],
103
+ })
104
+ }`,
105
+ 'utf-8',
106
+ );
107
+ shell.exec('git commit --allow-empty -m"feat: add a shiny thing"');
108
+
109
+ const output = runCli();
110
+ expect(output).toContain('Shiny Features');
111
+ expect(output).toContain('add a shiny thing');
112
+ });
113
+
114
+ it('accepts `parser` options in place of `parserOpts`', function () {
115
+ fs.writeFileSync(
116
+ '.versionrc.js',
117
+ "export default { parser: { noteKeywords: ['HEADS-UP'] } }",
118
+ 'utf-8',
119
+ );
120
+ shell.exec(
121
+ 'git commit --allow-empty -m"fix: rename an option" -m"HEADS-UP: the old name is gone"',
122
+ );
123
+
124
+ const output = runCli();
125
+ expect(output).toContain(
126
+ 'bumping version in package.json from 1.0.0 to 2.0.0',
127
+ );
128
+ });
129
+
93
130
  it('reads an ES module config from .versionrc.mjs', function () {
94
131
  fs.writeFileSync(
95
132
  '.versionrc.mjs',
@@ -118,11 +118,50 @@ describe('prerelease bump and changelog windows (#310)', function () {
118
118
  runCli('--prerelease', 'dev');
119
119
  expect(tags()).toContain('v1.1.0-dev.1');
120
120
 
121
- // Prerelease sections are cumulative: each one covers everything since
122
- // the last stable release.
121
+ // Only the changes since the previous prerelease with this identifier
122
+ // are listed; the feat is already in the dev.0 section (#349).
123
123
  const devSection = changelogSection('1.1.0-dev.1');
124
- expect(devSection).toContain('add feat');
124
+ expect(devSection).not.toContain('add feat');
125
125
  expect(devSection).toContain('add fix');
126
+ expect(devSection).toContain('v1.1.0-dev.0...v1.1.0-dev.1');
127
+ expect(changelogSection('1.1.0-dev.0')).toContain('add feat');
128
+ });
129
+
130
+ it('lists each change once across continued prereleases and again in the stable release', function () {
131
+ commit('feat: add a');
132
+ runCli('--prerelease', 'alpha');
133
+ commit('feat: add b');
134
+ runCli('--prerelease', 'alpha');
135
+ commit('fix: correct c');
136
+ runCli('--prerelease', 'alpha');
137
+
138
+ const prereleases = fs
139
+ .readFileSync('CHANGELOG.md', 'utf-8')
140
+ .split(/^#+ \[?1\.0\.0[\] ]/m)[0];
141
+ expect(prereleases.match(/add a/g)).toHaveLength(1);
142
+ expect(prereleases.match(/add b/g)).toHaveLength(1);
143
+ expect(prereleases.match(/correct c/g)).toHaveLength(1);
144
+
145
+ runCli();
146
+ const stableSection = changelogSection('1.1.0');
147
+ expect(stableSection).toContain('add a');
148
+ expect(stableSection).toContain('add b');
149
+ expect(stableSection).toContain('correct c');
150
+ expect(stableSection).toContain('v1.0.0...v1.1.0');
151
+ });
152
+
153
+ it('covers other prereleases when returning to an earlier identifier', function () {
154
+ commit('feat: add feat');
155
+ runCli('--prerelease', 'dev');
156
+ commit('fix: add fix');
157
+ runCli('--prerelease', 'rc');
158
+ commit('fix: second fix');
159
+ runCli('--prerelease', 'dev');
160
+
161
+ const devSection = changelogSection('1.1.0-dev.1');
162
+ expect(devSection).not.toContain('add feat');
163
+ expect(devSection).toContain('add fix');
164
+ expect(devSection).toContain('second fix');
126
165
  });
127
166
 
128
167
  it('escalates a continued prerelease when a bigger change lands', function () {