commit-and-tag-version 13.4.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,13 @@
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
+
5
12
  ## [13.4.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.3.0...v13.4.0) (2026-11-24)
6
13
 
7
14
 
package/README.md CHANGED
@@ -441,6 +441,22 @@ All config file formats can be used:
441
441
  commit-and-tag-version -c ./path/to/.versionrc[.js|.cjs|.mjs|.json]
442
442
  ```
443
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
+
444
460
  ### Signing Commits and Tags
445
461
 
446
462
  If you have your GPG key set up, add the `--sign` or `-s` flag to your `commit-and-tag-version` command.
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',
@@ -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
+ }
@@ -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.4.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",
@@ -63,18 +63,18 @@
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
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",
@@ -85,6 +85,6 @@
85
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
  }
@@ -151,6 +151,42 @@ describe('config files', function () {
151
151
  expect(content).toContain(issueUrlFormat);
152
152
  });
153
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
+
154
190
  it('passes gitRawCommitsOpts through to ConventionalChangelog.commits (#197)', async function () {
155
191
  const format =
156
192
  '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae';
@@ -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
+ });