commit-and-tag-version 13.3.0 → 13.5.0

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,26 @@
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.5.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.4.0...v13.5.0) (2026-11-25)
6
+
7
+
8
+ ### Features
9
+
10
+ * **config:** support multiple --config files ([#366](https://github.com/absolute-version/commit-and-tag-version/issues/366)) ([3322a9f](https://github.com/absolute-version/commit-and-tag-version/commit/3322a9f3ca68840fb07419465ef588d96408f0b5))
11
+
12
+ ## [13.4.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.3.0...v13.4.0) (2026-11-24)
13
+
14
+
15
+ ### Features
16
+
17
+ * **changelog:** allow overriding the changelog context ([#370](https://github.com/absolute-version/commit-and-tag-version/issues/370)) ([f4be71f](https://github.com/absolute-version/commit-and-tag-version/commit/f4be71ff0d05b44bceae1fea78523f67d1986e3c))
18
+ * pass gitRawCommitsOpts through to changelog and bump ([#367](https://github.com/absolute-version/commit-and-tag-version/issues/367)) ([2d37feb](https://github.com/absolute-version/commit-and-tag-version/commit/2d37feb551160c4dbbd9b07e790557cac16f9bb6)), closes [#197](https://github.com/absolute-version/commit-and-tag-version/issues/197)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * use an explicit releaseAs version when the bump step is skipped ([#368](https://github.com/absolute-version/commit-and-tag-version/issues/368)) ([66b20aa](https://github.com/absolute-version/commit-and-tag-version/commit/66b20aa5181f6ee89346bd9249cdcc8915c3b7a3))
24
+
5
25
  ## [13.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.2.2...v13.3.0) (2026-10-15)
6
26
 
7
27
 
package/README.md CHANGED
@@ -211,6 +211,27 @@ Suppose you're using GitLab, rather than GitHub, you might modify the following
211
211
 
212
212
  Making these URLs match GitLab's format, rather than GitHub's.
213
213
 
214
+ ### Overriding the changelog context
215
+
216
+ The values the changelog template renders from can be overridden with the
217
+ `context` option. For example, to generate a changelog without link markup:
218
+
219
+ ```json
220
+ {
221
+ "commit-and-tag-version": {
222
+ "context": {
223
+ "linkCompare": false,
224
+ "linkReferences": false
225
+ }
226
+ }
227
+ }
228
+ ```
229
+
230
+ `linkCompare` controls the link on the version heading, and `linkReferences`
231
+ controls the commit hash and `closes #123` links. The `version` key is overwritten by commit-and-tag-version, any other key is passed to the
232
+ [conventional-changelog writer context](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer)
233
+ unchanged.
234
+
214
235
  ### Deeper customization
215
236
 
216
237
  You can override both [parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser) and [writer](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer) options (they will be merged into the preset we just mentioned). As an example, to list commits in the order that they were committed:
@@ -227,6 +248,22 @@ You can override both [parser](https://github.com/conventional-changelog/convent
227
248
 
228
249
  `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
250
 
251
+ You can also pass commit-fetch options through to conventional-changelog via `gitRawCommitsOpts` (or the modern `commits` alias). This is useful for including extra git fields such as author name/email so a custom writer template can render them (#197):
252
+
253
+ ```js
254
+ export default {
255
+ gitRawCommitsOpts: {
256
+ format:
257
+ '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae',
258
+ },
259
+ writerOpts: {
260
+ // commit.authorName / commit.authorEmail are then available
261
+ },
262
+ };
263
+ ```
264
+
265
+ `commits` is accepted as an alias of `gitRawCommitsOpts`. If both are set, `gitRawCommitsOpts` takes precedence. Lifecycle-owned fields (`path`, and `merges` for changelog generation) always win over user overrides.
266
+
230
267
  Custom writer templates must be render functions rather than Handlebars strings; see the [v13 migration guide](MIGRATION.md#custom-writer-templates-use-render-functions). The official [`@conventional-changelog/template`](https://conventional-changelog.js.org/template/) helpers are re-exported from this package, so they can be imported without installing anything else — including under strict package managers such as pnpm:
231
268
 
232
269
  ```js
@@ -404,6 +441,22 @@ All config file formats can be used:
404
441
  commit-and-tag-version -c ./path/to/.versionrc[.js|.cjs|.mjs|.json]
405
442
  ```
406
443
 
444
+ Pass `--config` / `-c` multiple times to merge configuration files. Files are
445
+ applied in order, and later files override earlier ones. Option names are normalized
446
+ to camelCase before merging, so `tagPrefix` and `tag-prefix` refer to the same option.
447
+ Nested objects such as `skip` and `scripts` are shallow-merged, but arrays such as
448
+ `types` and `bumpFiles` are replaced, not combined. Explicit command-line options
449
+ still take precedence over configuration files. If an explicitly specified config
450
+ file cannot be found, a warning is printed and the remaining files are still loaded.
451
+ This is useful in a monorepo when each package has a small local config and shares
452
+ common settings from the repo root:
453
+
454
+ ```sh
455
+ commit-and-tag-version \
456
+ -c ../../.versionrc.json \
457
+ -c ./.versionrc.json
458
+ ```
459
+
407
460
  ### Signing Commits and Tags
408
461
 
409
462
  If you have your GPG key set up, add the `--sign` or `-s` flag to your `commit-and-tag-version` command.
@@ -471,6 +524,8 @@ by adding the following to your package.json:
471
524
 
472
525
  To set these options via the command line, use `commit-and-tag-version --skip.changelog`
473
526
 
527
+ When the `bump` step is skipped, no files are updated and the remaining steps use the current version. If you also pass an explicit version with `--release-as` (e.g. `--skip.bump --release-as 1.5.0`), the changelog, commit and tag use that version instead.
528
+
474
529
  ### Committing Generated Artifacts in the Release Commit
475
530
 
476
531
  If you want to commit generated artifacts in the release commit, you can use the `--commit-all` or `-a` flag. You will need to stage the artifacts you want to commit, so your `release` command could look like this:
package/command.js CHANGED
@@ -1,13 +1,10 @@
1
- import { createRequire } from 'module';
1
+ import createYargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
2
3
  import spec from 'conventional-changelog-config-spec';
3
4
  import { getConfiguration } from './lib/configuration.js';
4
5
  import defaults from './defaults.js';
5
6
 
6
- const require = createRequire(import.meta.url);
7
-
8
- // Load the CommonJS build of yargs: the yargs ESM entrypoint does not provide
9
- // the argv singleton, and its help output wraps differently.
10
- const yargs = require('yargs')
7
+ const yargs = createYargs(hideBin(process.argv))
11
8
  .usage('Usage: $0 [options]')
12
9
  .option('packageFiles', {
13
10
  default: defaults.packageFiles,
@@ -139,9 +136,11 @@ const yargs = require('yargs')
139
136
  })
140
137
  .option('config', {
141
138
  type: 'string',
139
+ array: true,
142
140
  default: defaults.config,
143
141
  alias: 'c',
144
- describe: 'Path to a custom configuration file',
142
+ describe:
143
+ 'Path to a custom configuration file; pass multiple times to merge configs (later files override earlier ones)',
145
144
  })
146
145
  .option('noBumpWhenEmptyChanges', {
147
146
  type: 'boolean',
package/defaults.js CHANGED
@@ -18,6 +18,7 @@ const defaults = {
18
18
  preset: 'conventional-changelog-conventionalcommits',
19
19
  npmPublishHint: undefined,
20
20
  config: undefined,
21
+ context: {},
21
22
  };
22
23
 
23
24
  /**
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import { createRequire } from 'module';
3
3
  import fs from 'fs';
4
- import findUp from 'find-up';
4
+ import { findUpSync } from 'find-up';
5
5
 
6
6
  const require = createRequire(import.meta.url);
7
7
 
@@ -13,16 +13,54 @@ const CONFIGURATION_FILES = [
13
13
  '.versionrc.js',
14
14
  ];
15
15
 
16
- export function getConfiguration(configFile) {
17
- let config = {};
18
-
19
- // If the user has provided a configuration file via the `--config` argument, we use that.
20
- const configurationFiles = configFile ?? CONFIGURATION_FILES;
16
+ // Normalize only option names; nested maps can contain user-defined keys.
17
+ function normalizeConfigurationKeys(config) {
18
+ return Object.fromEntries(
19
+ Object.entries(config).map(([key, value]) => [
20
+ key.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()),
21
+ value,
22
+ ]),
23
+ );
24
+ }
21
25
 
22
- const configPath = findUp.sync(configurationFiles);
23
- if (!configPath) {
24
- return config;
26
+ /**
27
+ * Deep-merge plain objects one level for nested config maps (e.g. `skip`,
28
+ * `scripts`). Arrays and non-objects are replaced by the override value.
29
+ * Later configs win on key conflicts.
30
+ * @param {Record<string, unknown>} base
31
+ * @param {Record<string, unknown>} override
32
+ * @returns {Record<string, unknown>}
33
+ */
34
+ export function mergeConfiguration(base, override) {
35
+ base = normalizeConfigurationKeys(base);
36
+ const result = { ...base };
37
+ for (const [key, value] of Object.entries(
38
+ normalizeConfigurationKeys(override),
39
+ )) {
40
+ const existing = base[key];
41
+ if (
42
+ value != null &&
43
+ typeof value === 'object' &&
44
+ !Array.isArray(value) &&
45
+ existing != null &&
46
+ typeof existing === 'object' &&
47
+ !Array.isArray(existing)
48
+ ) {
49
+ result[key] = { ...existing, ...value };
50
+ } else {
51
+ result[key] = value;
52
+ }
25
53
  }
54
+ return result;
55
+ }
56
+
57
+ /**
58
+ * Load a single configuration file from an absolute path.
59
+ * @param {string} configPath
60
+ * @returns {Record<string, unknown>}
61
+ */
62
+ function loadConfigurationFromPath(configPath) {
63
+ let config;
26
64
  const ext = path.extname(configPath);
27
65
  if (ext === '.js' || ext === '.cjs' || ext === '.mjs') {
28
66
  let jsConfiguration = require(configPath);
@@ -48,7 +86,7 @@ export function getConfiguration(configFile) {
48
86
  * @todo we could eventually have deeper validation of the configuration (using `ajv`) and
49
87
  * provide a more helpful error.
50
88
  */
51
- if (typeof config !== 'object') {
89
+ if (typeof config !== 'object' || config === null || Array.isArray(config)) {
52
90
  throw Error(
53
91
  `[commit-and-tag-version] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}.`,
54
92
  );
@@ -56,3 +94,50 @@ export function getConfiguration(configFile) {
56
94
 
57
95
  return config;
58
96
  }
97
+
98
+ /**
99
+ * Resolve `--config` / `-c` values to a list of paths to load, or `null` to
100
+ * fall back to discovering a default `.versionrc*` via find-up.
101
+ * @param {string | string[] | undefined | null} configFile
102
+ * @returns {string[] | null}
103
+ */
104
+ function normalizeConfigFiles(configFile) {
105
+ if (configFile == null) {
106
+ return null;
107
+ }
108
+ const files = (Array.isArray(configFile) ? configFile : [configFile]).filter(
109
+ (file) => typeof file === 'string' && file.length > 0,
110
+ );
111
+ return files.length > 0 ? files : null;
112
+ }
113
+
114
+ /**
115
+ * @param {string | string[] | undefined | null} configFile
116
+ * @returns {Record<string, unknown>}
117
+ */
118
+ export function getConfiguration(configFile) {
119
+ const explicitFiles = normalizeConfigFiles(configFile);
120
+
121
+ // Auto-discover a single default config when `--config` was not passed.
122
+ if (explicitFiles == null) {
123
+ const configPath = findUpSync(CONFIGURATION_FILES);
124
+ if (!configPath) {
125
+ return {};
126
+ }
127
+ return loadConfigurationFromPath(configPath);
128
+ }
129
+
130
+ // One or more explicit `--config` paths: load in order and merge (later wins).
131
+ let config = {};
132
+ for (const file of explicitFiles) {
133
+ const configPath = findUpSync(file);
134
+ if (!configPath) {
135
+ console.warn(
136
+ `[commit-and-tag-version] Configuration file \`${file}\` was not found.`,
137
+ );
138
+ continue;
139
+ }
140
+ config = mergeConfiguration(config, loadConfigurationFromPath(configPath));
141
+ }
142
+ return config;
143
+ }
@@ -7,7 +7,10 @@ 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, { getParserOpts } from '../preset-loader.js';
10
+ import presetLoader, {
11
+ getParserOpts,
12
+ getGitRawCommitsOpts,
13
+ } from '../preset-loader.js';
11
14
  import runLifecycleScript from '../run-lifecycle-script.js';
12
15
  import writeFile from '../write-file.js';
13
16
  import { resolveUpdaterObjectFromArgument } from '../updaters/index.js';
@@ -93,7 +96,13 @@ async function Bump(args, version) {
93
96
  // time we perform the version bump step.
94
97
  configsToUpdate = {};
95
98
 
96
- if (args.skip.bump) return version;
99
+ if (args.skip.bump) {
100
+ // No files are bumped, but an explicit releaseAs version is still the
101
+ // version used by the changelog, commit and tag steps.
102
+ return semver.valid(args.releaseAs)
103
+ ? versionFromReleaseAs(args, version)
104
+ : version;
105
+ }
97
106
 
98
107
  if (
99
108
  args.releaseAs &&
@@ -117,36 +126,7 @@ async function Bump(args, version) {
117
126
 
118
127
  if (!args.firstRelease) {
119
128
  if (semver.valid(args.releaseAs)) {
120
- const releaseAs = new semver.SemVer(args.releaseAs);
121
- if (
122
- isString(args.prerelease) &&
123
- releaseAs.prerelease.length &&
124
- releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease
125
- ) {
126
- // If both releaseAs and the prerelease identifier are supplied, they must match. The behavior
127
- // for a mismatch is undefined, so error out instead.
128
- throw new Error(
129
- 'releaseAs and prerelease have conflicting prerelease identifiers',
130
- );
131
- } else if (isString(args.prerelease) && releaseAs.prerelease.length) {
132
- newVersion = releaseAs.version;
133
- } else if (isString(args.prerelease)) {
134
- newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`;
135
- } else {
136
- newVersion = releaseAs.version;
137
- }
138
-
139
- // Check if the previous version is the same version and prerelease, and increment if so
140
- if (
141
- isString(args.prerelease) &&
142
- ['prerelease', null].includes(semver.diff(version, newVersion)) &&
143
- semver.lte(newVersion, version)
144
- ) {
145
- newVersion = semver.inc(version, 'prerelease', args.prerelease);
146
- }
147
-
148
- // Append any build info from releaseAs
149
- newVersion = semvarToVersionStr(newVersion, releaseAs.build);
129
+ newVersion = versionFromReleaseAs(args, version);
150
130
  } else {
151
131
  const release = await bumpVersion(args.releaseAs, version, args);
152
132
 
@@ -184,6 +164,47 @@ async function Bump(args, version) {
184
164
  return newVersion;
185
165
  }
186
166
 
167
+ /**
168
+ * Compute the new version from an explicit `releaseAs` version, taking the
169
+ * `prerelease` option into account.
170
+ * @param args config object
171
+ * @param {string} version the current version
172
+ * @return {string}
173
+ */
174
+ function versionFromReleaseAs(args, version) {
175
+ let newVersion;
176
+ const releaseAs = new semver.SemVer(args.releaseAs);
177
+ if (
178
+ isString(args.prerelease) &&
179
+ releaseAs.prerelease.length &&
180
+ releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease
181
+ ) {
182
+ // If both releaseAs and the prerelease identifier are supplied, they must match. The behavior
183
+ // for a mismatch is undefined, so error out instead.
184
+ throw new Error(
185
+ 'releaseAs and prerelease have conflicting prerelease identifiers',
186
+ );
187
+ } else if (isString(args.prerelease) && releaseAs.prerelease.length) {
188
+ newVersion = releaseAs.version;
189
+ } else if (isString(args.prerelease)) {
190
+ newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`;
191
+ } else {
192
+ newVersion = releaseAs.version;
193
+ }
194
+
195
+ // Check if the previous version is the same version and prerelease, and increment if so
196
+ if (
197
+ isString(args.prerelease) &&
198
+ ['prerelease', null].includes(semver.diff(version, newVersion)) &&
199
+ semver.lte(newVersion, version)
200
+ ) {
201
+ newVersion = semver.inc(version, 'prerelease', args.prerelease);
202
+ }
203
+
204
+ // Append any build info from releaseAs
205
+ return semvarToVersionStr(newVersion, releaseAs.build);
206
+ }
207
+
187
208
  Bump.getUpdatedConfigs = function () {
188
209
  return configsToUpdate;
189
210
  };
@@ -296,7 +317,13 @@ async function bumpVersion(releaseAs, currentVersion, args) {
296
317
  // towards the next version (#310).
297
318
  skipUnstable: true,
298
319
  })
299
- .commits({ path: args.path }, getParserOpts(args));
320
+ .commits(
321
+ {
322
+ ...(getGitRawCommitsOpts(args) || {}),
323
+ path: args.path,
324
+ },
325
+ getParserOpts(args),
326
+ );
300
327
 
301
328
  if (args.verbose) {
302
329
  bumper.options({
@@ -7,6 +7,7 @@ import checkpoint from '../checkpoint.js';
7
7
  import presetLoader, {
8
8
  getParserOpts,
9
9
  getWriterOpts,
10
+ getGitRawCommitsOpts,
10
11
  } from '../preset-loader.js';
11
12
  import runLifecycleScript from '../run-lifecycle-script.js';
12
13
  import writeFile from '../write-file.js';
@@ -119,8 +120,15 @@ async function outputChangelog(args, newVersion) {
119
120
  }
120
121
  : {}),
121
122
  })
122
- .context({ version: newVersion })
123
- .commits({ merges: null, path: args.path }, getParserOpts(args))
123
+ .context({ ...args.context, version: newVersion })
124
+ .commits(
125
+ {
126
+ ...(getGitRawCommitsOpts(args) || {}),
127
+ merges: null,
128
+ path: args.path,
129
+ },
130
+ getParserOpts(args),
131
+ )
124
132
  .writer({
125
133
  // Split sections at the same tags the commit range is built from, so
126
134
  // commits released in other prereleases stay in this release's section
@@ -87,6 +87,17 @@ export function getWriterOpts(args) {
87
87
  return mergeOptions(args.writer, args.writerOpts);
88
88
  }
89
89
 
90
+ /**
91
+ * Commit-fetch options passed to ConventionalChangelog.commits() /
92
+ * Bumper.commits() (GetCommitsParams). Accept the legacy
93
+ * `gitRawCommitsOpts` name (from older conventional-changelog) and the
94
+ * modern `commits` alias. When both are present, `gitRawCommitsOpts`
95
+ * takes precedence.
96
+ */
97
+ export function getGitRawCommitsOpts(args) {
98
+ return mergeOptions(args.commits, args.gitRawCommitsOpts);
99
+ }
100
+
90
101
  export default (args) => {
91
102
  let preset = args.preset || DEFAULT_PRESET;
92
103
  if (preset === DEFAULT_PRESET) {
@@ -1,5 +1,5 @@
1
1
  import detectIndent from 'detect-indent';
2
- import detectNewline from 'detect-newline';
2
+ import { detectNewline } from 'detect-newline';
3
3
  import stringifyPackage from '../../stringify-package.js';
4
4
 
5
5
  export function readVersion(contents) {
@@ -1,4 +1,4 @@
1
- import detectNewline from 'detect-newline';
1
+ import { detectNewline } from 'detect-newline';
2
2
  import { XMLParser, XMLBuilder } from 'fast-xml-parser';
3
3
 
4
4
  const CRLF = '\r\n';
@@ -1,5 +1,5 @@
1
1
  import yaml from 'yaml';
2
- import detectNewline from 'detect-newline';
2
+ import { detectNewline } from 'detect-newline';
3
3
 
4
4
  export function readVersion(contents) {
5
5
  return yaml.parse(contents).info.version;
@@ -1,5 +1,5 @@
1
1
  import yaml from 'yaml';
2
- import detectNewline from 'detect-newline';
2
+ import { detectNewline } from 'detect-newline';
3
3
 
4
4
  export function readVersion(contents) {
5
5
  return yaml.parse(contents).version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "13.3.0",
3
+ "version": "13.5.0",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -58,23 +58,23 @@
58
58
  "@conventional-changelog/git-client": "3.1.0",
59
59
  "@conventional-changelog/template": "1.4.0",
60
60
  "chalk": "^6.0.1",
61
- "conventional-changelog": "8.1.0",
61
+ "conventional-changelog": "8.1.3",
62
62
  "conventional-changelog-config-spec": "2.1.0",
63
63
  "conventional-changelog-conventionalcommits": "10.4.0",
64
64
  "conventional-recommended-bump": "12.1.0",
65
65
  "detect-indent": "^7.0.2",
66
- "detect-newline": "^3.1.0",
66
+ "detect-newline": "^4.0.1",
67
67
  "dotgitignore": "^2.1.0",
68
- "fast-xml-parser": "^5.10.1",
68
+ "fast-xml-parser": "^5.11.2",
69
69
  "figures": "^6.1.0",
70
- "find-up": "^5.0.0",
70
+ "find-up": "^8.0.0",
71
71
  "semver": "^7.7.2",
72
72
  "yaml": "^2.9.0",
73
- "yargs": "^17.7.2"
73
+ "yargs": "^18.2.0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@eslint/js": "^10.0.1",
77
- "@vitest/coverage-istanbul": "^4.1.11",
77
+ "@vitest/coverage-istanbul": "^5.1.1",
78
78
  "@vitest/eslint-plugin": "^1.6.27",
79
79
  "conventional-changelog-angular": "^9.4.0",
80
80
  "eslint": "^10.8.1",
@@ -82,9 +82,9 @@
82
82
  "globals": "^17.12.0",
83
83
  "istanbul-lib-instrument": "^6.0.3",
84
84
  "pirates": "^4.0.7",
85
- "prettier": "^3.9.6",
85
+ "prettier": "^3.9.10",
86
86
  "shelljs": "^0.10.0",
87
87
  "strip-ansi": "^7.2.0",
88
- "vitest": "^4.1.0"
88
+ "vitest": "^5.1.1"
89
89
  }
90
90
  }
@@ -0,0 +1,75 @@
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+
4
+ const repoUrl = 'https://github.com/example/changelog-context';
5
+
6
+ async function exec(opt) {
7
+ vi.resetModules();
8
+ const { default: cli } = await import('../command');
9
+ opt = cli.parse(`commit-and-tag-version ${opt} --silent`);
10
+ opt.skip = { commit: true, tag: true };
11
+ const { default: standardVersion } = await import('../index');
12
+ return standardVersion(opt);
13
+ }
14
+
15
+ function setupTempGitRepo(versionrc) {
16
+ shell.rm('-rf', 'changelog-context-temp');
17
+ shell.config.silent = true;
18
+ shell.mkdir('changelog-context-temp');
19
+ shell.cd('changelog-context-temp');
20
+ shell.exec('git init');
21
+ shell.exec('git config commit.gpgSign false');
22
+ shell.exec('git config core.autocrlf false');
23
+ fs.writeFileSync(
24
+ 'package.json',
25
+ JSON.stringify({
26
+ name: 'changelog-context',
27
+ version: '1.0.0',
28
+ repository: { type: 'git', url: `${repoUrl}.git` },
29
+ }),
30
+ 'utf-8',
31
+ );
32
+ if (versionrc) {
33
+ fs.writeFileSync('.versionrc', JSON.stringify(versionrc), 'utf-8');
34
+ }
35
+ shell.exec('git add -A');
36
+ shell.exec('git commit -m "chore: initial commit"');
37
+ shell.exec('git tag v1.0.0');
38
+ shell.exec('git commit --allow-empty -m "feat: A feature commit."');
39
+ }
40
+
41
+ function resetShell() {
42
+ shell.cd('../');
43
+ shell.rm('-rf', 'changelog-context-temp');
44
+ }
45
+
46
+ describe('changelog context', function () {
47
+ afterEach(function () {
48
+ resetShell();
49
+ });
50
+
51
+ it('links the compare range and commit hashes by default', async function () {
52
+ setupTempGitRepo();
53
+
54
+ await exec();
55
+
56
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
57
+ expect(content).toContain(`${repoUrl}/compare/v1.0.0...v1.1.0`);
58
+ expect(content).toMatch(new RegExp(`${repoUrl}/commit/[0-9a-f]{40}`));
59
+ });
60
+
61
+ it('applies the configured context to the changelog', async function () {
62
+ setupTempGitRepo({
63
+ context: { linkCompare: false, linkReferences: false },
64
+ });
65
+
66
+ await exec();
67
+
68
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
69
+ expect(content).toContain('## 1.1.0');
70
+ expect(content).toContain('### Features');
71
+ expect(content).toContain('A feature commit.');
72
+ expect(content).not.toContain(`${repoUrl}/compare/`);
73
+ expect(content).not.toContain(`${repoUrl}/commit/`);
74
+ });
75
+ });
@@ -150,4 +150,63 @@ describe('config files', function () {
150
150
  const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
151
151
  expect(content).toContain(issueUrlFormat);
152
152
  });
153
+
154
+ it('merges multiple config files via getConfiguration (later overrides earlier)', async function () {
155
+ const issueUrlFormat = 'http://www.merged.com/{{id}}';
156
+ const changelog = ({ preset }) => preset.issueUrlFormat;
157
+ mock({ bump: 'minor', changelog });
158
+ fs.mkdirSync('shared');
159
+ fs.mkdirSync('pkg');
160
+ fs.writeFileSync(
161
+ 'shared/.versionrc.json',
162
+ JSON.stringify({
163
+ issueUrlFormat: 'http://www.shared.com/{{id}}',
164
+ skip: { tag: true },
165
+ }),
166
+ 'utf-8',
167
+ );
168
+ fs.writeFileSync(
169
+ 'pkg/.versionrc.json',
170
+ JSON.stringify({ issueUrlFormat }),
171
+ 'utf-8',
172
+ );
173
+
174
+ vi.resetModules();
175
+ const { getConfiguration } = await import('../lib/configuration.js');
176
+ const config = getConfiguration([
177
+ 'shared/.versionrc.json',
178
+ 'pkg/.versionrc.json',
179
+ ]);
180
+ const { default: standardVersion } = await import('../index');
181
+ await standardVersion({
182
+ ...config,
183
+ skip: { commit: true, tag: true },
184
+ });
185
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
186
+ expect(content).toContain(issueUrlFormat);
187
+ expect(content).not.toContain('http://www.shared.com/{{id}}');
188
+ });
189
+
190
+ it('passes gitRawCommitsOpts through to ConventionalChangelog.commits (#197)', async function () {
191
+ const format =
192
+ '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae';
193
+ let seenCommits;
194
+ mock({
195
+ bump: 'minor',
196
+ changelog: ({ commits }) => {
197
+ seenCommits = commits;
198
+ return '## changelog\n';
199
+ },
200
+ });
201
+ // Use `.versionrc` (not `.versionrc.js`) so findUp picks this file before
202
+ // the repo-root `.versionrc` when walking from the temp directory.
203
+ fs.writeFileSync(
204
+ '.versionrc',
205
+ JSON.stringify({ gitRawCommitsOpts: { format } }),
206
+ 'utf-8',
207
+ );
208
+
209
+ await exec();
210
+ expect(seenCommits).toMatchObject({ format, merges: null });
211
+ });
153
212
  });
@@ -0,0 +1,140 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import { spawnSync } from 'child_process';
5
+
6
+ const commandUrl = new URL('../command.js', import.meta.url).href;
7
+
8
+ // Parse real CLI options in a fresh process, without running any release steps.
9
+ function parseConfiguration(cwd, args = []) {
10
+ const result = spawnSync(
11
+ process.execPath,
12
+ [
13
+ '--input-type=module',
14
+ '--eval',
15
+ `import cli from ${JSON.stringify(commandUrl)}; console.log(JSON.stringify(cli.argv));`,
16
+ '--',
17
+ 'commit-and-tag-version',
18
+ ...args,
19
+ ],
20
+ { cwd, encoding: 'utf8' },
21
+ );
22
+ expect(result.error).toBeUndefined();
23
+ expect(result.status).toBe(0);
24
+ return { options: JSON.parse(result.stdout), stderr: result.stderr };
25
+ }
26
+
27
+ describe('configuration CLI precedence', function () {
28
+ let tmpDir;
29
+
30
+ beforeEach(function () {
31
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cats-config-cli-'));
32
+ });
33
+
34
+ afterEach(function () {
35
+ fs.rmSync(tmpDir, { recursive: true, force: true });
36
+ });
37
+
38
+ function writeConfig(file, config) {
39
+ fs.writeFileSync(path.join(tmpDir, file), JSON.stringify(config));
40
+ }
41
+
42
+ it.each([
43
+ ['kebab.json', 'camel.json', 'camel@v'],
44
+ ['camel.json', 'kebab.json', 'kebab@v'],
45
+ ])('uses the later file for -c %s -c %s', function (first, last, expected) {
46
+ writeConfig('kebab.json', { 'tag-prefix': 'kebab@v' });
47
+ writeConfig('camel.json', { tagPrefix: 'camel@v' });
48
+ const { options, stderr } = parseConfiguration(tmpDir, [
49
+ '-c',
50
+ first,
51
+ '-c',
52
+ last,
53
+ ]);
54
+ expect(options.tagPrefix).toBe(expected);
55
+ expect(options['tag-prefix']).toBe(expected);
56
+ expect(stderr).toBe('');
57
+ });
58
+
59
+ it.each(['--tag-prefix', '--tagPrefix', '-t'])(
60
+ 'keeps %s above both config-file styles',
61
+ function (flag) {
62
+ writeConfig('first.json', { 'tag-prefix': 'shared@v' });
63
+ writeConfig('last.json', { tagPrefix: 'pkg@v' });
64
+ const { options, stderr } = parseConfiguration(tmpDir, [
65
+ '-c',
66
+ 'first.json',
67
+ '--config',
68
+ 'last.json',
69
+ flag,
70
+ 'cli@v',
71
+ ]);
72
+ expect(options.tagPrefix).toBe('cli@v');
73
+ expect(options['tag-prefix']).toBe('cli@v');
74
+ expect(stderr).toBe('');
75
+ },
76
+ );
77
+
78
+ it('warns for a missing file and still parses the remaining configs', function () {
79
+ writeConfig('first.json', {
80
+ 'tag-prefix': 'shared@v',
81
+ skip: { tag: true },
82
+ });
83
+ writeConfig('last.json', { tagPrefix: 'pkg@v', skip: { commit: true } });
84
+ const { options, stderr } = parseConfiguration(tmpDir, [
85
+ '-c',
86
+ 'first.json',
87
+ '-c',
88
+ 'missing.json',
89
+ '-c',
90
+ 'last.json',
91
+ ]);
92
+ expect(options.tagPrefix).toBe('pkg@v');
93
+ expect(options.skip).toEqual({ tag: true, commit: true });
94
+ expect(stderr.trim()).toBe(
95
+ '[commit-and-tag-version] Configuration file `missing.json` was not found.',
96
+ );
97
+ });
98
+
99
+ it('replaces array aliases while shallow-merging nested objects', function () {
100
+ writeConfig('first.json', {
101
+ 'bump-files': ['package.json'],
102
+ types: [{ type: 'feat', section: 'Features' }],
103
+ scripts: { prerelease: './shared.sh' },
104
+ });
105
+ writeConfig('last.json', {
106
+ bumpFiles: ['Cargo.toml'],
107
+ types: [{ type: 'fix', section: 'Fixes' }],
108
+ scripts: { postbump: './pkg.sh' },
109
+ });
110
+ const { options } = parseConfiguration(tmpDir, [
111
+ '-c',
112
+ 'first.json',
113
+ '-c',
114
+ 'last.json',
115
+ ]);
116
+ expect(options.bumpFiles).toEqual(['Cargo.toml']);
117
+ expect(options.types).toEqual([{ type: 'fix', section: 'Fixes' }]);
118
+ expect(options.scripts).toEqual({
119
+ prerelease: './shared.sh',
120
+ postbump: './pkg.sh',
121
+ });
122
+ });
123
+
124
+ it('still supports a single explicit config', function () {
125
+ writeConfig('single.json', { 'tag-prefix': 'single@v' });
126
+ const { options, stderr } = parseConfiguration(tmpDir, [
127
+ '--config',
128
+ 'single.json',
129
+ ]);
130
+ expect(options.tagPrefix).toBe('single@v');
131
+ expect(stderr).toBe('');
132
+ });
133
+
134
+ it('still auto-discovers a default config without --config', function () {
135
+ writeConfig('.versionrc.json', { 'tag-prefix': 'default@v' });
136
+ const { options, stderr } = parseConfiguration(tmpDir);
137
+ expect(options.tagPrefix).toBe('default@v');
138
+ expect(stderr).toBe('');
139
+ });
140
+ });
@@ -0,0 +1,187 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import { getConfiguration, mergeConfiguration } from '../lib/configuration.js';
5
+
6
+ describe('mergeConfiguration', function () {
7
+ it.each([
8
+ ['tag-prefix', 'tagPrefix'],
9
+ ['tagPrefix', 'tag-prefix'],
10
+ ])('normalizes %s and %s before merging', function (firstKey, lastKey) {
11
+ expect(
12
+ mergeConfiguration(
13
+ { [firstKey]: 'shared@v', 'bump-files': ['package.json'] },
14
+ { [lastKey]: 'pkg@v', bumpFiles: ['Cargo.toml'] },
15
+ ),
16
+ ).toEqual({ tagPrefix: 'pkg@v', bumpFiles: ['Cargo.toml'] });
17
+ });
18
+
19
+ it('preserves nested keys and replaces types rather than combining them', function () {
20
+ expect(
21
+ mergeConfiguration(
22
+ {
23
+ types: [{ type: 'feat', section: 'Features' }],
24
+ scripts: { 'custom-hook': './shared.sh' },
25
+ },
26
+ {
27
+ types: [{ type: 'fix', section: 'Fixes' }],
28
+ scripts: { postbump: './pkg.sh' },
29
+ },
30
+ ),
31
+ ).toEqual({
32
+ types: [{ type: 'fix', section: 'Fixes' }],
33
+ scripts: { 'custom-hook': './shared.sh', postbump: './pkg.sh' },
34
+ });
35
+ });
36
+
37
+ it('shallow-merges nested plain objects and replaces other values', function () {
38
+ expect(
39
+ mergeConfiguration(
40
+ {
41
+ tagPrefix: 'v',
42
+ skip: { tag: true, changelog: false },
43
+ scripts: { prerelease: './a.sh' },
44
+ bumpFiles: ['package.json'],
45
+ },
46
+ {
47
+ tagPrefix: 'pkg@v',
48
+ skip: { commit: true },
49
+ scripts: { postbump: './b.sh' },
50
+ bumpFiles: ['Cargo.toml'],
51
+ },
52
+ ),
53
+ ).toEqual({
54
+ tagPrefix: 'pkg@v',
55
+ skip: { tag: true, changelog: false, commit: true },
56
+ scripts: { prerelease: './a.sh', postbump: './b.sh' },
57
+ bumpFiles: ['Cargo.toml'],
58
+ });
59
+ });
60
+ });
61
+
62
+ describe('getConfiguration', function () {
63
+ let tmpDir;
64
+ let previousCwd;
65
+
66
+ beforeEach(function () {
67
+ previousCwd = process.cwd();
68
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cats-config-'));
69
+ process.chdir(tmpDir);
70
+ });
71
+
72
+ afterEach(function () {
73
+ process.chdir(previousCwd);
74
+ fs.rmSync(tmpDir, { recursive: true, force: true });
75
+ });
76
+
77
+ it('returns an empty object when no config file is present', function () {
78
+ expect(getConfiguration()).toEqual({});
79
+ });
80
+
81
+ it('loads a single explicit config path', function () {
82
+ fs.mkdirSync('shared');
83
+ fs.writeFileSync(
84
+ 'shared/.versionrc.json',
85
+ JSON.stringify({ tagPrefix: 'shared@v', skip: { tag: true } }),
86
+ );
87
+
88
+ expect(getConfiguration('shared/.versionrc.json')).toEqual({
89
+ tagPrefix: 'shared@v',
90
+ skip: { tag: true },
91
+ });
92
+ });
93
+
94
+ it('merges multiple explicit config paths (later overrides earlier)', function () {
95
+ fs.mkdirSync('shared');
96
+ fs.mkdirSync('pkg');
97
+ fs.writeFileSync(
98
+ 'shared/.versionrc.json',
99
+ JSON.stringify({
100
+ skip: { tag: true },
101
+ scripts: { prerelease: './shared.sh' },
102
+ tagPrefix: 'v',
103
+ }),
104
+ );
105
+ fs.writeFileSync(
106
+ 'pkg/.versionrc.json',
107
+ JSON.stringify({
108
+ path: '.',
109
+ tagPrefix: 'mypackage@v',
110
+ scripts: { postbump: './pkg.sh' },
111
+ }),
112
+ );
113
+
114
+ expect(
115
+ getConfiguration(['shared/.versionrc.json', 'pkg/.versionrc.json']),
116
+ ).toEqual({
117
+ skip: { tag: true },
118
+ scripts: { prerelease: './shared.sh', postbump: './pkg.sh' },
119
+ tagPrefix: 'mypackage@v',
120
+ path: '.',
121
+ });
122
+ });
123
+
124
+ it('treats an empty array like an omitted --config (auto-discover)', function () {
125
+ fs.writeFileSync(
126
+ '.versionrc.json',
127
+ JSON.stringify({ issueUrlFormat: 'https://example.test/{{id}}' }),
128
+ );
129
+ expect(getConfiguration([])).toEqual({
130
+ issueUrlFormat: 'https://example.test/{{id}}',
131
+ });
132
+ });
133
+
134
+ it('treats yargs array default [null] like an omitted --config', function () {
135
+ fs.writeFileSync(
136
+ '.versionrc.json',
137
+ JSON.stringify({ issueUrlFormat: 'https://example.test/{{id}}' }),
138
+ );
139
+ expect(getConfiguration([null])).toEqual({
140
+ issueUrlFormat: 'https://example.test/{{id}}',
141
+ });
142
+ });
143
+
144
+ it('warns and returns an empty config when an explicit path cannot be found', function () {
145
+ fs.writeFileSync(
146
+ '.versionrc.json',
147
+ JSON.stringify({ tagPrefix: 'default@v' }),
148
+ );
149
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
150
+ try {
151
+ expect(getConfiguration('missing/.versionrc.json')).toEqual({});
152
+ expect(warn).toHaveBeenCalledExactlyOnceWith(
153
+ '[commit-and-tag-version] Configuration file `missing/.versionrc.json` was not found.',
154
+ );
155
+ } finally {
156
+ warn.mockRestore();
157
+ }
158
+ });
159
+
160
+ it.each([0, 1, 2])(
161
+ 'skips a missing config at index %i and loads the others',
162
+ function (index) {
163
+ fs.writeFileSync(
164
+ 'first.json',
165
+ JSON.stringify({ tagPrefix: 'first@v', skip: { tag: true } }),
166
+ );
167
+ fs.writeFileSync(
168
+ 'last.json',
169
+ JSON.stringify({ tagPrefix: 'last@v', skip: { commit: true } }),
170
+ );
171
+ const files = ['first.json', 'last.json'];
172
+ files.splice(index, 0, 'missing.json');
173
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
174
+ try {
175
+ expect(getConfiguration(files)).toEqual({
176
+ tagPrefix: 'last@v',
177
+ skip: { tag: true, commit: true },
178
+ });
179
+ expect(warn).toHaveBeenCalledExactlyOnceWith(
180
+ '[commit-and-tag-version] Configuration file `missing.json` was not found.',
181
+ );
182
+ } finally {
183
+ warn.mockRestore();
184
+ }
185
+ },
186
+ );
187
+ });
@@ -216,6 +216,16 @@ describe('git', function () {
216
216
  expect(shell.exec('git describe').stdout).toMatch(/v1\.1\.0/);
217
217
  });
218
218
 
219
+ it('uses an explicit releaseAs version when the bump is skipped', async function () {
220
+ mock({ bump: 'minor' });
221
+ await exec('--skip.bump --release-as 1.5.0');
222
+ expect(getPackageVersion()).toEqual('1.0.0');
223
+ expect(shell.exec('git describe').stdout).toMatch(/v1\.5\.0/);
224
+ expect(shell.exec('git log --oneline -n1').stdout).toMatch(
225
+ /chore\(release\): 1\.5\.0/,
226
+ );
227
+ });
228
+
219
229
  it('allows the commit phase to be skipped', async function () {
220
230
  const changelogContent = 'legacy header format<a name="1.0.0">\n';
221
231
  writePackageJson('1.0.0');
@@ -1,5 +1,10 @@
1
1
  import { promises as fsp } from 'fs';
2
2
  import { detectPMByLockFile } from '../lib/detect-package-manager';
3
+ import {
4
+ getParserOpts,
5
+ getWriterOpts,
6
+ getGitRawCommitsOpts,
7
+ } from '../lib/preset-loader.js';
3
8
 
4
9
  let mockFs;
5
10
 
@@ -33,3 +38,38 @@ describe('utils', function () {
33
38
  expect(pm).toEqual('pnpm');
34
39
  });
35
40
  });
41
+
42
+ describe('preset-loader option aliases', function () {
43
+ it('getGitRawCommitsOpts merges commits and prefers gitRawCommitsOpts', function () {
44
+ expect(getGitRawCommitsOpts({})).toBeUndefined();
45
+ expect(
46
+ getGitRawCommitsOpts({ commits: { format: 'from-commits' } }),
47
+ ).toEqual({ format: 'from-commits' });
48
+ expect(
49
+ getGitRawCommitsOpts({
50
+ gitRawCommitsOpts: { format: 'legacy' },
51
+ }),
52
+ ).toEqual({ format: 'legacy' });
53
+ expect(
54
+ getGitRawCommitsOpts({
55
+ commits: { format: 'new', reverse: true },
56
+ gitRawCommitsOpts: { format: 'legacy' },
57
+ }),
58
+ ).toEqual({ format: 'legacy', reverse: true });
59
+ });
60
+
61
+ it('getParserOpts / getWriterOpts prefer *Opts over modern aliases', function () {
62
+ expect(
63
+ getParserOpts({
64
+ parser: { noteKeywords: ['A'] },
65
+ parserOpts: { noteKeywords: ['B'] },
66
+ }),
67
+ ).toEqual({ noteKeywords: ['B'] });
68
+ expect(
69
+ getWriterOpts({
70
+ writer: { commitsSort: false },
71
+ writerOpts: { commitsSort: true },
72
+ }),
73
+ ).toEqual({ commitsSort: true });
74
+ });
75
+ });