commit-and-tag-version 13.0.0 → 13.1.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.
@@ -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,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.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v13.0.0...v13.1.0) (2026-07-21)
6
+
7
+
8
+ ### Features
9
+
10
+ * 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))
11
+
5
12
  ## [13.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.7.3...v13.0.0) (2026-07-18)
6
13
 
7
14
 
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 {
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.0",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -47,12 +47,12 @@
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",
@@ -76,7 +76,7 @@
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
+ });