commit-and-tag-version 13.0.0 → 13.1.1

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.
@@ -11,16 +11,16 @@ jobs:
11
11
  strategy:
12
12
  matrix:
13
13
  node: [22, lts/*, 24]
14
- os: [ubuntu-latest, windows-latest]
14
+ os: [ubuntu-latest, windows-latest, macos-latest]
15
15
  env:
16
16
  OS: ${{ matrix.os }}
17
17
  NODE_VERSION: ${{ matrix.node }}
18
18
  steps:
19
- - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4
19
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
20
20
  - run: git fetch --prune --unshallow
21
21
  - run: git config --global user.name 'Actions'
22
22
  - run: git config --global user.email 'dummy@example.org'
23
- - uses: actions/setup-node@v6
23
+ - uses: actions/setup-node@v7
24
24
  with:
25
25
  node-version: ${{ matrix.node }}
26
26
  - run: node --version
@@ -21,11 +21,11 @@ jobs:
21
21
  release-type: node
22
22
  package-name: commit-and-tag-version
23
23
  # The logic below handles the npm publication:
24
- - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4
24
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
25
25
  # these if statements ensure that a publication only occurs when
26
26
  # a new release is created:
27
27
  if: ${{ steps.release.outputs.release_created }}
28
- - uses: actions/setup-node@v6
28
+ - uses: actions/setup-node@v7
29
29
  with:
30
30
  node-version: 22
31
31
  registry-url: 'https://registry.npmjs.org'
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
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.1.1](https://github.com/absolute-version/commit-and-tag-version/compare/v13.1.0...v13.1.1) (2026-07-28)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Fix issue where prereleases were calculated from the wrong base (fixes [#310](https://github.com/absolute-version/commit-and-tag-version/issues/310)) ([1261803](https://github.com/absolute-version/commit-and-tag-version/commit/12618033a5b1a6c8bf3fd2aa65ceb062b6180c3a))
11
+
12
+ ## [13.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.0.0...v13.1.0) (2026-07-21)
13
+
14
+
15
+ ### Features
16
+
17
+ * support ESM configuration files ([#306](https://github.com/absolute-version/commit-and-tag-version/issues/306)) ([9e0e5ab](https://github.com/absolute-version/commit-and-tag-version/commit/9e0e5ab7ec8cf8a465b63d3858634126cd040542))
18
+
5
19
  ## [13.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.7.3...v13.0.0) (2026-07-18)
6
20
 
7
21
 
package/README.md CHANGED
@@ -188,9 +188,9 @@ You can configure `commit-and-tag-version` either by:
188
188
  > Note for users who have migrated to
189
189
  > `commit-and-tag-version` from `standard-version`: the previous package.json configuration key of `standard-version` will still work.
190
190
 
191
- 2. Creating a `.versionrc`, `.versionrc.json` or `.versionrc.js`.
191
+ 2. Creating a `.versionrc`, `.versionrc.json`, `.versionrc.js`, `.versionrc.cjs` or `.versionrc.mjs`.
192
192
 
193
- - If you are using a `.versionrc.js` your default export must be a configuration object, or a function returning a configuration object.
193
+ - If you are using a `.versionrc.js`, `.versionrc.cjs` or `.versionrc.mjs` your default export must be a configuration object, or a function returning a configuration object. Both CommonJS and ES module configs are supported (ES module configs require Node.js >= 22.12).
194
194
 
195
195
  Any of the command line parameters accepted by `commit-and-tag-version` can instead
196
196
  be provided via configuration. Please refer to the [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec/) for details on available configuration options.
@@ -342,7 +342,7 @@ commit-and-tag-version -c ./path/to/.versionrc.js
342
342
  All config file formats can be used:
343
343
 
344
344
  ```sh
345
- commit-and-tag-version -c ./path/to/.versionrc[.js|.cjs|.json]
345
+ commit-and-tag-version -c ./path/to/.versionrc[.js|.cjs|.mjs|.json]
346
346
  ```
347
347
 
348
348
  ### Signing Commits and Tags
@@ -8,6 +8,7 @@ const require = createRequire(import.meta.url);
8
8
  const CONFIGURATION_FILES = [
9
9
  '.versionrc',
10
10
  '.versionrc.cjs',
11
+ '.versionrc.mjs',
11
12
  '.versionrc.json',
12
13
  '.versionrc.js',
13
14
  ];
@@ -23,8 +24,17 @@ export function getConfiguration(configFile) {
23
24
  return config;
24
25
  }
25
26
  const ext = path.extname(configPath);
26
- if (ext === '.js' || ext === '.cjs') {
27
- const jsConfiguration = require(configPath);
27
+ if (ext === '.js' || ext === '.cjs' || ext === '.mjs') {
28
+ let jsConfiguration = require(configPath);
29
+ // ES modules arrive as a namespace wrapper (via Node's `require(esm)`,
30
+ // available since 22.12); the configuration is its default export.
31
+ if (
32
+ jsConfiguration != null &&
33
+ (jsConfiguration.__esModule ||
34
+ jsConfiguration[Symbol.toStringTag] === 'Module')
35
+ ) {
36
+ jsConfiguration = jsConfiguration.default;
37
+ }
28
38
  if (typeof jsConfiguration === 'function') {
29
39
  config = jsConfiguration();
30
40
  } else {
@@ -291,6 +291,10 @@ async function bumpVersion(releaseAs, currentVersion, args) {
291
291
  prefix: args.lernaPackage
292
292
  ? packagePrefix(args.lernaPackage)
293
293
  : args.tagPrefix,
294
+ // Measure the recommendation from the last stable release rather than
295
+ // the most recent tag: commits released only in prereleases still count
296
+ // towards the next version (#310).
297
+ skipUnstable: true,
294
298
  })
295
299
  .commits({ path: args.path }, args.parserOpts);
296
300
 
@@ -1,6 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import { ConventionalChangelog } from 'conventional-changelog';
3
3
  import fs from 'fs';
4
+ import semver from 'semver';
4
5
  import checkpoint from '../checkpoint.js';
5
6
  import presetLoader from '../preset-loader.js';
6
7
  import runLifecycleScript from '../run-lifecycle-script.js';
@@ -57,7 +58,10 @@ async function outputChangelog(args, newVersion) {
57
58
  const generator = new ConventionalChangelog()
58
59
  .readPackage()
59
60
  .loadPreset(presetLoader(args))
60
- .tags({ prefix: args.tagPrefix })
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 })
61
65
  .options({
62
66
  releaseCount: args.releaseCount,
63
67
  ...(args.verbose
@@ -68,7 +72,16 @@ async function outputChangelog(args, newVersion) {
68
72
  })
69
73
  .context({ version: newVersion })
70
74
  .commits({ merges: null, path: args.path }, args.parserOpts)
71
- .writer(args.writerOpts || {});
75
+ .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 || {}),
84
+ });
72
85
 
73
86
  let content = '';
74
87
  for await (const chunk of generator.write()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "13.0.0",
3
+ "version": "13.1.1",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -47,19 +47,19 @@
47
47
  "homepage": "https://github.com/absolute-version/commit-and-tag-version#readme",
48
48
  "dependencies": {
49
49
  "@conventional-changelog/git-client": "3.1.0",
50
- "chalk": "^2.4.2",
50
+ "chalk": "^5.6.2",
51
51
  "conventional-changelog": "8.1.0",
52
52
  "conventional-changelog-config-spec": "2.1.0",
53
53
  "conventional-changelog-conventionalcommits": "10.2.1",
54
54
  "conventional-recommended-bump": "12.1.0",
55
- "detect-indent": "^6.1.0",
55
+ "detect-indent": "^7.0.2",
56
56
  "detect-newline": "^3.1.0",
57
57
  "dotgitignore": "^2.1.0",
58
58
  "fast-xml-parser": "^5.5.6",
59
59
  "figures": "^3.2.0",
60
60
  "find-up": "^5.0.0",
61
61
  "semver": "^7.7.2",
62
- "yaml": "^2.6.0",
62
+ "yaml": "^2.9.0",
63
63
  "yargs": "^17.7.2"
64
64
  },
65
65
  "devDependencies": {
@@ -70,13 +70,13 @@
70
70
  "eslint": "^9.13.0",
71
71
  "eslint-config-prettier": "^10.1.8",
72
72
  "eslint-plugin-import": "^2.31.0",
73
- "eslint-plugin-n": "^17.21.3",
73
+ "eslint-plugin-n": "^18.2.2",
74
74
  "eslint-plugin-promise": "^7.2.1",
75
75
  "istanbul-lib-instrument": "^6.0.3",
76
76
  "pirates": "^4.0.7",
77
77
  "prettier": "^3.3.3",
78
78
  "shelljs": "^0.10.0",
79
- "strip-ansi": "^6.0.1",
79
+ "strip-ansi": "^7.2.0",
80
80
  "vitest": "^4.1.0"
81
81
  }
82
82
  }
package/test/core.spec.js CHANGED
@@ -90,6 +90,13 @@ const mockReadFilesFromDisk = ({
90
90
  realTestFiles,
91
91
  }) =>
92
92
  vi.spyOn(fs, 'readFileSync').mockImplementation((path, opts) => {
93
+ // The ESM module loader reads files through fs with non-string paths
94
+ // (URL/Buffer/fd). Those aren't test fixtures, so pass them straight to
95
+ // real fs; only string paths get the fixture handling below.
96
+ if (typeof path !== 'string') {
97
+ return readFileSyncActual(path, opts);
98
+ }
99
+
93
100
  if (path === 'CHANGELOG.md') {
94
101
  if (existingChangelog) {
95
102
  return existingChangelog;
@@ -149,6 +156,12 @@ const mockReadFilesFromDisk = ({
149
156
  */
150
157
  const mockFsLStat = ({ fs, lstatSyncActual, testFiles, realTestFiles }) =>
151
158
  vi.spyOn(fs, 'lstatSync').mockImplementation((path) => {
159
+ // See readFileSync mock: non-string paths come from the module loader,
160
+ // not the test fixtures, so delegate them to real fs.
161
+ if (typeof path !== 'string') {
162
+ return lstatSyncActual(path);
163
+ }
164
+
152
165
  if (testFiles) {
153
166
  const file = testFiles.find((otherFile) => {
154
167
  return path.includes(otherFile.path);
@@ -0,0 +1,97 @@
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+ import { execFileSync } from 'child_process';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const CLI = fileURLToPath(new URL('../bin/cli.js', import.meta.url));
7
+
8
+ /**
9
+ * These tests spawn the real CLI in a child process instead of using the usual
10
+ * in-process harness. That is deliberate: `getConfiguration` loads ESM config
11
+ * files through Node's `require(esm)` (available since 22.12), and under vitest
12
+ * that require is intercepted by the module runner, which throws a Babel
13
+ * SyntaxError on ESM sources — a failure mode that does not exist in
14
+ * production. Only a child process observes the real behavior.
15
+ */
16
+
17
+ function setupTestDirectory() {
18
+ shell.rm('-rf', 'esm-config-temp');
19
+ shell.config.silent = true;
20
+ shell.mkdir('esm-config-temp');
21
+ shell.cd('esm-config-temp');
22
+ shell.exec('git init');
23
+ shell.exec('git config commit.gpgSign false');
24
+ shell.exec('git config core.autocrlf false');
25
+ shell.exec('git commit --allow-empty -m"root-commit"');
26
+ }
27
+
28
+ function resetShell() {
29
+ shell.cd('../');
30
+ shell.rm('-rf', 'esm-config-temp');
31
+ }
32
+
33
+ function runCli() {
34
+ return execFileSync(process.execPath, [CLI, '--dry-run'], {
35
+ encoding: 'utf-8',
36
+ });
37
+ }
38
+
39
+ describe('ESM config files', function () {
40
+ beforeEach(function () {
41
+ setupTestDirectory();
42
+
43
+ fs.writeFileSync(
44
+ 'package.json',
45
+ JSON.stringify({ version: '1.0.0' }),
46
+ 'utf-8',
47
+ );
48
+ });
49
+
50
+ afterEach(function () {
51
+ resetShell();
52
+ });
53
+
54
+ it('reads an ES module config-object from .versionrc.js', function () {
55
+ fs.writeFileSync(
56
+ '.versionrc.js',
57
+ 'export default { tagPrefix: "custom-" }',
58
+ 'utf-8',
59
+ );
60
+
61
+ const output = runCli();
62
+ expect(output).toContain('tagging release custom-1.0.1');
63
+ });
64
+
65
+ it('reads an ES module config from .versionrc.mjs', function () {
66
+ fs.writeFileSync(
67
+ '.versionrc.mjs',
68
+ 'export default { tagPrefix: "custom-" }',
69
+ 'utf-8',
70
+ );
71
+
72
+ const output = runCli();
73
+ expect(output).toContain('tagging release custom-1.0.1');
74
+ });
75
+
76
+ it('evaluates an ES module config-function', function () {
77
+ fs.writeFileSync(
78
+ '.versionrc.mjs',
79
+ 'export default function () { return { tagPrefix: "custom-" }; }',
80
+ 'utf-8',
81
+ );
82
+
83
+ const output = runCli();
84
+ expect(output).toContain('tagging release custom-1.0.1');
85
+ });
86
+
87
+ it('applies the same configuration when written as CommonJS', function () {
88
+ fs.writeFileSync(
89
+ '.versionrc.js',
90
+ 'module.exports = { tagPrefix: "custom-" }',
91
+ 'utf-8',
92
+ );
93
+
94
+ const output = runCli();
95
+ expect(output).toContain('tagging release custom-1.0.1');
96
+ });
97
+ });
@@ -0,0 +1,137 @@
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+ import { execFileSync } from 'child_process';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const CLI = fileURLToPath(new URL('../bin/cli.js', import.meta.url));
7
+
8
+ /**
9
+ * Regression tests for #310: the bump recommendation and the changelog were
10
+ * generated from commits since the most recent tag of any kind, while the
11
+ * "current version" resolution ignores prereleases with other identifiers.
12
+ * Commits released only in a prerelease fell between the two windows and were
13
+ * counted by neither. These tests spawn the real CLI in a real git repository
14
+ * because the in-process harness mocks the git client's raw commit stream
15
+ * without honouring the `from` range, so it cannot observe the bug.
16
+ */
17
+
18
+ function setupTestDirectory() {
19
+ shell.rm('-rf', 'prerelease-window-temp');
20
+ shell.config.silent = true;
21
+ shell.mkdir('prerelease-window-temp');
22
+ shell.cd('prerelease-window-temp');
23
+ shell.exec('git init');
24
+ shell.exec('git config commit.gpgSign false');
25
+ shell.exec('git config core.autocrlf false');
26
+ shell.exec('git config user.email "test@example.com"');
27
+ shell.exec('git config user.name "Test"');
28
+ shell.exec('git commit --allow-empty -m"root-commit"');
29
+ }
30
+
31
+ function resetShell() {
32
+ shell.cd('../');
33
+ shell.rm('-rf', 'prerelease-window-temp');
34
+ }
35
+
36
+ function runCli(...args) {
37
+ return execFileSync(process.execPath, [CLI, ...args], {
38
+ encoding: 'utf-8',
39
+ });
40
+ }
41
+
42
+ function commit(message) {
43
+ shell.exec(`git commit --allow-empty -m"${message}"`);
44
+ }
45
+
46
+ function tags() {
47
+ return shell.exec('git tag').stdout.split('\n').filter(Boolean);
48
+ }
49
+
50
+ /**
51
+ * Extract one release's section from CHANGELOG.md. Version headings look like
52
+ * `## 1.1.0 (2026-01-01)` or `# [1.1.0](compare-url) (2026-01-01)` depending
53
+ * on whether a repository URL is known, so match both forms and cut at the
54
+ * next version heading.
55
+ */
56
+ function changelogSection(version) {
57
+ const changelog = fs.readFileSync('CHANGELOG.md', 'utf-8');
58
+ const escaped = version.replace(/[.[\]]/g, '\\$&');
59
+ const start = changelog.search(new RegExp(`^#+ \\[?${escaped}[\\] ]`, 'm'));
60
+ expect(start, `no changelog section for ${version}`).toBeGreaterThan(-1);
61
+ const rest = changelog.slice(start);
62
+ const headingEnd = rest.indexOf('\n') + 1;
63
+ const next = rest.slice(headingEnd).search(/^#+ \[?[0-9]/m);
64
+ return next === -1 ? rest : rest.slice(0, headingEnd + next);
65
+ }
66
+
67
+ describe('prerelease bump and changelog windows (#310)', function () {
68
+ beforeEach(function () {
69
+ setupTestDirectory();
70
+ runCli('--first-release');
71
+ });
72
+
73
+ afterEach(function () {
74
+ resetShell();
75
+ });
76
+
77
+ it('bumps from the last stable release when switching prerelease identifiers', function () {
78
+ commit('feat: add feat');
79
+ runCli('--prerelease', 'dev');
80
+ expect(tags()).toContain('v1.1.0-dev.0');
81
+
82
+ commit('fix: add fix');
83
+ runCli('--prerelease', 'rc');
84
+
85
+ // Before the fix the feat was invisible: only the fix commit (since the
86
+ // dev tag) was considered, recommending a prepatch from v1.0.0.
87
+ expect(tags()).toContain('v1.1.0-rc.0');
88
+ expect(tags()).not.toContain('v1.0.1-rc.0');
89
+ });
90
+
91
+ it('includes changes from earlier prereleases in a new prerelease changelog', function () {
92
+ commit('feat: add feat');
93
+ runCli('--prerelease', 'dev');
94
+ commit('fix: add fix');
95
+ runCli('--prerelease', 'rc');
96
+
97
+ const rcSection = changelogSection('1.1.0-rc.0');
98
+ expect(rcSection).toContain('add feat');
99
+ expect(rcSection).toContain('add fix');
100
+ });
101
+
102
+ it('graduates a prerelease with --noBumpWhenEmptyChanges', function () {
103
+ commit('feat: add feat');
104
+ runCli('--prerelease', 'rc');
105
+ expect(tags()).toContain('v1.1.0-rc.0');
106
+
107
+ // Before the fix no commits were found since the rc tag, so the CLI
108
+ // refused to bump at all.
109
+ runCli('--noBumpWhenEmptyChanges');
110
+ expect(tags()).toContain('v1.1.0');
111
+ expect(changelogSection('1.1.0')).toContain('add feat');
112
+ });
113
+
114
+ it('continues a prerelease with the same identifier', function () {
115
+ commit('feat: add feat');
116
+ runCli('--prerelease', 'dev');
117
+ commit('fix: add fix');
118
+ runCli('--prerelease', 'dev');
119
+ expect(tags()).toContain('v1.1.0-dev.1');
120
+
121
+ // Prerelease sections are cumulative: each one covers everything since
122
+ // the last stable release.
123
+ const devSection = changelogSection('1.1.0-dev.1');
124
+ expect(devSection).toContain('add feat');
125
+ expect(devSection).toContain('add fix');
126
+ });
127
+
128
+ it('escalates a continued prerelease when a bigger change lands', function () {
129
+ commit('fix: add fix');
130
+ runCli('--prerelease', 'rc');
131
+ expect(tags()).toContain('v1.0.1-rc.0');
132
+
133
+ commit('feat: add feat');
134
+ runCli('--prerelease', 'rc');
135
+ expect(tags()).toContain('v1.1.0-rc.0');
136
+ });
137
+ });