commit-and-tag-version 12.7.3 → 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.
Files changed (55) hide show
  1. package/.github/workflows/ci.yaml +8 -15
  2. package/.github/workflows/release-please.yml +2 -2
  3. package/CHANGELOG.md +29 -0
  4. package/MIGRATION.md +51 -0
  5. package/README.md +25 -24
  6. package/bin/cli.js +2 -2
  7. package/command.js +9 -4
  8. package/defaults.js +5 -3
  9. package/eslint.config.mjs +52 -42
  10. package/index.js +12 -12
  11. package/lib/checkpoint.js +5 -5
  12. package/lib/configuration.js +21 -8
  13. package/lib/detect-package-manager.js +4 -8
  14. package/lib/format-commit-message.js +2 -2
  15. package/lib/latest-semver-tag.js +30 -30
  16. package/lib/lifecycles/bump.js +97 -65
  17. package/lib/lifecycles/changelog.js +48 -60
  18. package/lib/lifecycles/commit.js +8 -8
  19. package/lib/lifecycles/tag.js +10 -10
  20. package/lib/preset-loader.js +73 -9
  21. package/lib/print-error.js +3 -3
  22. package/lib/run-exec.js +6 -5
  23. package/lib/run-execFile.js +6 -5
  24. package/lib/run-lifecycle-script.js +6 -6
  25. package/lib/stringify-package.js +1 -5
  26. package/lib/updaters/index.js +25 -12
  27. package/lib/updaters/types/csproj.js +4 -4
  28. package/lib/updaters/types/gradle.js +4 -4
  29. package/lib/updaters/types/json.js +9 -9
  30. package/lib/updaters/types/maven.js +10 -6
  31. package/lib/updaters/types/openapi.js +6 -6
  32. package/lib/updaters/types/plain-text.js +4 -4
  33. package/lib/updaters/types/python.js +4 -4
  34. package/lib/updaters/types/yaml.js +6 -6
  35. package/lib/write-file.js +3 -3
  36. package/package.json +20 -15
  37. package/test/commit-message-config.integration-test.js +23 -10
  38. package/test/config-files.integration-test.js +25 -10
  39. package/test/config-keys.integration-test.js +20 -7
  40. package/test/core.spec.js +82 -37
  41. package/test/esm-config.integration-test.js +97 -0
  42. package/test/git.integration-test.js +23 -15
  43. package/test/invalid-config.integration-test.js +19 -9
  44. package/test/mocks/pom-6.3.1-attrs-lf.xml +1 -0
  45. package/test/mocks/pom-6.4.0-attrs-lf.xml +1 -0
  46. package/test/mocks/vitest-mocks.js +260 -0
  47. package/test/package.json +3 -0
  48. package/test/pre-commit-hook.integration-test.js +22 -14
  49. package/test/preset.integration-test.js +7 -5
  50. package/test/setup-coverage.js +47 -0
  51. package/test/stringify-package.spec.js +1 -3
  52. package/test/utils.spec.js +3 -4
  53. package/vitest.config.js +26 -0
  54. package/jest.config.js +0 -28
  55. package/test/mocks/jest-mocks.js +0 -66
@@ -1,14 +1,27 @@
1
- const path = require('path');
2
- const JSON_BUMP_FILES = require('../../defaults').bumpFiles;
1
+ import path from 'path';
2
+ import { createRequire } from 'module';
3
+ import defaults from '../../defaults.js';
4
+ import * as json from './types/json.js';
5
+ import * as plainText from './types/plain-text.js';
6
+ import * as maven from './types/maven.js';
7
+ import * as gradle from './types/gradle.js';
8
+ import * as csproj from './types/csproj.js';
9
+ import * as yaml from './types/yaml.js';
10
+ import * as openapi from './types/openapi.js';
11
+ import * as python from './types/python.js';
12
+
13
+ const require = createRequire(import.meta.url);
14
+
15
+ const JSON_BUMP_FILES = defaults.bumpFiles;
3
16
  const updatersByType = {
4
- json: require('./types/json'),
5
- 'plain-text': require('./types/plain-text'),
6
- maven: require('./types/maven'),
7
- gradle: require('./types/gradle'),
8
- csproj: require('./types/csproj'),
9
- yaml: require('./types/yaml'),
10
- openapi: require('./types/openapi'),
11
- python: require('./types/python'),
17
+ json,
18
+ 'plain-text': plainText,
19
+ maven,
20
+ gradle,
21
+ csproj,
22
+ yaml,
23
+ openapi,
24
+ python,
12
25
  };
13
26
  const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt'];
14
27
 
@@ -76,7 +89,7 @@ function isValidUpdater(obj) {
76
89
  );
77
90
  }
78
91
 
79
- module.exports.resolveUpdaterObjectFromArgument = function (arg) {
92
+ export function resolveUpdaterObjectFromArgument(arg) {
80
93
  /**
81
94
  * If an Object was not provided, we assume it's the path/filename
82
95
  * of the updater.
@@ -117,4 +130,4 @@ module.exports.resolveUpdaterObjectFromArgument = function (arg) {
117
130
  }
118
131
 
119
132
  return updater;
120
- };
133
+ }
@@ -1,6 +1,6 @@
1
1
  const versionRegex = /<Version>(.*)<\/Version>/;
2
2
 
3
- module.exports.readVersion = function (contents) {
3
+ export function readVersion(contents) {
4
4
  const matches = versionRegex.exec(contents);
5
5
  if (matches === null || matches.length !== 2) {
6
6
  throw new Error(
@@ -8,8 +8,8 @@ module.exports.readVersion = function (contents) {
8
8
  );
9
9
  }
10
10
  return matches[1];
11
- };
11
+ }
12
12
 
13
- module.exports.writeVersion = function (contents, version) {
13
+ export function writeVersion(contents, version) {
14
14
  return contents.replace(versionRegex, `<Version>${version}</Version>`);
15
- };
15
+ }
@@ -1,6 +1,6 @@
1
1
  const versionRegex = /^version\s*=\s*['"]([\d.]+.*)['"]/m;
2
2
 
3
- module.exports.readVersion = function (contents) {
3
+ export function readVersion(contents) {
4
4
  const matches = versionRegex.exec(contents);
5
5
  if (matches === null) {
6
6
  throw new Error(
@@ -9,10 +9,10 @@ module.exports.readVersion = function (contents) {
9
9
  }
10
10
 
11
11
  return matches[1];
12
- };
12
+ }
13
13
 
14
- module.exports.writeVersion = function (contents, version) {
14
+ export function writeVersion(contents, version) {
15
15
  return contents.replace(versionRegex, () => {
16
16
  return `version = "${version}"`;
17
17
  });
18
- };
18
+ }
@@ -1,12 +1,12 @@
1
- const stringifyPackage = require('../../stringify-package');
2
- const detectIndent = require('detect-indent');
3
- const detectNewline = require('detect-newline');
1
+ import detectIndent from 'detect-indent';
2
+ import detectNewline from 'detect-newline';
3
+ import stringifyPackage from '../../stringify-package.js';
4
4
 
5
- module.exports.readVersion = function (contents) {
5
+ export function readVersion(contents) {
6
6
  return JSON.parse(contents).version;
7
- };
7
+ }
8
8
 
9
- module.exports.writeVersion = function (contents, version) {
9
+ export function writeVersion(contents, version) {
10
10
  const json = JSON.parse(contents);
11
11
  const indent = detectIndent(contents).indent;
12
12
  const newline = detectNewline(contents);
@@ -18,8 +18,8 @@ module.exports.writeVersion = function (contents, version) {
18
18
  }
19
19
 
20
20
  return stringifyPackage(json, indent, newline);
21
- };
21
+ }
22
22
 
23
- module.exports.isPrivate = function (contents) {
23
+ export function isPrivate(contents) {
24
24
  return JSON.parse(contents).private;
25
- };
25
+ }
@@ -1,5 +1,5 @@
1
- const detectNewline = require('detect-newline');
2
- const { XMLParser, XMLBuilder } = require('fast-xml-parser');
1
+ import detectNewline from 'detect-newline';
2
+ import { XMLParser, XMLBuilder } from 'fast-xml-parser';
3
3
 
4
4
  const CRLF = '\r\n';
5
5
  const LF = '\n';
@@ -12,6 +12,8 @@ function pomDocument(contents) {
12
12
  parseTagValue: false,
13
13
  // Don't coerce attribute values to numbers/booleans (e.g. keep port="8080" as a string)
14
14
  parseAttributeValue: false,
15
+ // Preserve comments
16
+ commentPropName: '#comment',
15
17
  });
16
18
  return parser.parse(contents);
17
19
  }
@@ -28,12 +30,12 @@ function pomVersion(document) {
28
30
  return version;
29
31
  }
30
32
 
31
- module.exports.readVersion = function (contents) {
33
+ export function readVersion(contents) {
32
34
  const document = pomDocument(contents);
33
35
  return pomVersion(document);
34
- };
36
+ }
35
37
 
36
- module.exports.writeVersion = function (contents, version) {
38
+ export function writeVersion(contents, version) {
37
39
  const newline = detectNewline(contents);
38
40
  const document = pomDocument(contents);
39
41
 
@@ -45,6 +47,8 @@ module.exports.writeVersion = function (contents, version) {
45
47
  // Write fork="true" instead of shorthand fork (which is invalid in XML)
46
48
  suppressBooleanAttributes: false,
47
49
  format: true,
50
+ // Preserve comments
51
+ commentPropName: '#comment',
48
52
  });
49
53
  const xml = builder.build(document);
50
54
 
@@ -53,4 +57,4 @@ module.exports.writeVersion = function (contents, version) {
53
57
  }
54
58
 
55
59
  return xml + LF;
56
- };
60
+ }
@@ -1,15 +1,15 @@
1
- const yaml = require('yaml');
2
- const detectNewline = require('detect-newline');
1
+ import yaml from 'yaml';
2
+ import detectNewline from 'detect-newline';
3
3
 
4
- module.exports.readVersion = function (contents) {
4
+ export function readVersion(contents) {
5
5
  return yaml.parse(contents).info.version;
6
- };
6
+ }
7
7
 
8
- module.exports.writeVersion = function (contents, version) {
8
+ export function writeVersion(contents, version) {
9
9
  const newline = detectNewline(contents);
10
10
  const document = yaml.parseDocument(contents);
11
11
 
12
12
  document.get('info').set('version', version);
13
13
 
14
14
  return document.toString().replace(/\r?\n/g, newline);
15
- };
15
+ }
@@ -1,7 +1,7 @@
1
- module.exports.readVersion = function (contents) {
1
+ export function readVersion(contents) {
2
2
  return contents;
3
- };
3
+ }
4
4
 
5
- module.exports.writeVersion = function (_contents, version) {
5
+ export function writeVersion(_contents, version) {
6
6
  return version;
7
- };
7
+ }
@@ -14,17 +14,17 @@ const getVersionIndex = function (lines) {
14
14
  return { version, lineNumber };
15
15
  };
16
16
 
17
- module.exports.readVersion = function (contents) {
17
+ export function readVersion(contents) {
18
18
  const lines = contents.split('\n');
19
19
  const versionIndex = getVersionIndex(lines);
20
20
  return versionIndex.version;
21
- };
21
+ }
22
22
 
23
- module.exports.writeVersion = function (contents, version) {
23
+ export function writeVersion(contents, version) {
24
24
  const lines = contents.split('\n');
25
25
  const versionIndex = getVersionIndex(lines);
26
26
  const versionLine = lines[versionIndex.lineNumber];
27
27
  const newVersionLine = versionLine.replace(versionIndex.version, version);
28
28
  lines[versionIndex.lineNumber] = newVersionLine;
29
29
  return lines.join('\n');
30
- };
30
+ }
@@ -1,15 +1,15 @@
1
- const yaml = require('yaml');
2
- const detectNewline = require('detect-newline');
1
+ import yaml from 'yaml';
2
+ import detectNewline from 'detect-newline';
3
3
 
4
- module.exports.readVersion = function (contents) {
4
+ export function readVersion(contents) {
5
5
  return yaml.parse(contents).version;
6
- };
6
+ }
7
7
 
8
- module.exports.writeVersion = function (contents, version) {
8
+ export function writeVersion(contents, version) {
9
9
  const newline = detectNewline(contents);
10
10
  const document = yaml.parseDocument(contents);
11
11
 
12
12
  document.set('version', version);
13
13
 
14
14
  return document.toString().replace(/\r?\n/g, newline);
15
- };
15
+ }
package/lib/write-file.js CHANGED
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
1
+ import fs from 'fs';
2
2
 
3
- module.exports = function (args, filePath, content) {
3
+ export default function (args, filePath, content) {
4
4
  if (args.dryRun) return;
5
5
  fs.writeFileSync(filePath, content, 'utf8');
6
- };
6
+ }
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "12.7.3",
3
+ "version": "13.1.0",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
+ "type": "module",
6
+ "main": "index.js",
5
7
  "bin": {
6
8
  "commit-and-tag-version": "bin/cli.js"
7
9
  },
@@ -12,9 +14,9 @@
12
14
  "format:base": "prettier \"./**/*.{ts,js}\"",
13
15
  "format:fix": "npm run format:base -- --write",
14
16
  "format:check": "npm run format:base -- --check",
15
- "test": "jest",
16
- "test:unit": "jest --testPathIgnorePatterns test/git.integration-test.js",
17
- "test:git-integration": "jest --testPathPattern test/git.integration-test.js",
17
+ "test": "vitest run --coverage",
18
+ "test:unit": "vitest run --exclude 'test/*.integration-test.js'",
19
+ "test:git-integration": "vitest run test/git.integration-test.js",
18
20
  "release": "bin/cli.js"
19
21
  },
20
22
  "repository": {
@@ -22,7 +24,7 @@
22
24
  "url": "git+https://github.com/absolute-version/commit-and-tag-version.git"
23
25
  },
24
26
  "engines": {
25
- "node": ">=18"
27
+ "node": ">=22"
26
28
  },
27
29
  "keywords": [
28
30
  "conventional-changelog",
@@ -44,34 +46,37 @@
44
46
  },
45
47
  "homepage": "https://github.com/absolute-version/commit-and-tag-version#readme",
46
48
  "dependencies": {
47
- "chalk": "^2.4.2",
48
- "conventional-changelog": "4.0.0",
49
+ "@conventional-changelog/git-client": "3.1.0",
50
+ "chalk": "^5.6.2",
51
+ "conventional-changelog": "8.1.0",
49
52
  "conventional-changelog-config-spec": "2.1.0",
50
- "conventional-changelog-conventionalcommits": "6.1.0",
51
- "conventional-recommended-bump": "7.0.1",
52
- "detect-indent": "^6.1.0",
53
+ "conventional-changelog-conventionalcommits": "10.2.1",
54
+ "conventional-recommended-bump": "12.1.0",
55
+ "detect-indent": "^7.0.2",
53
56
  "detect-newline": "^3.1.0",
54
57
  "dotgitignore": "^2.1.0",
55
58
  "fast-xml-parser": "^5.5.6",
56
59
  "figures": "^3.2.0",
57
60
  "find-up": "^5.0.0",
58
- "git-semver-tags": "^5.0.1",
59
61
  "semver": "^7.7.2",
60
62
  "yaml": "^2.6.0",
61
63
  "yargs": "^17.7.2"
62
64
  },
63
65
  "devDependencies": {
64
66
  "@eslint/js": "^9.36.0",
67
+ "@vitest/coverage-istanbul": "^4.1.0",
68
+ "@vitest/eslint-plugin": "^1.6.23",
69
+ "conventional-changelog-angular": "^9.2.1",
65
70
  "eslint": "^9.13.0",
66
71
  "eslint-config-prettier": "^10.1.8",
67
72
  "eslint-plugin-import": "^2.31.0",
68
- "eslint-plugin-jest": "^28.8.3",
69
73
  "eslint-plugin-n": "^17.21.3",
70
74
  "eslint-plugin-promise": "^7.2.1",
71
- "jest": "^29.7.0",
72
- "jest-serial-runner": "^1.2.1",
75
+ "istanbul-lib-instrument": "^6.0.3",
76
+ "pirates": "^4.0.7",
73
77
  "prettier": "^3.3.3",
74
78
  "shelljs": "^0.10.0",
75
- "strip-ansi": "^6.0.1"
79
+ "strip-ansi": "^7.2.0",
80
+ "vitest": "^4.1.0"
76
81
  }
77
82
  }
@@ -1,16 +1,29 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const fs = require('fs');
5
-
6
- const mockers = require('./mocks/jest-mocks');
7
-
8
- function exec(opt = '') {
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
15
+
16
+ vi.spyOn(console, 'info').mockImplementation(() => {});
17
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
18
+
19
+ async function exec(opt = '') {
20
+ vi.resetModules();
21
+ const { default: cli } = await import('../command');
9
22
  if (typeof opt === 'string') {
10
- const cli = require('../command');
11
23
  opt = cli.parse(`commit-and-tag-version ${opt}`);
12
24
  }
13
- return require('../index')(opt);
25
+ const { default: standardVersion } = await import('../index');
26
+ return standardVersion(opt);
14
27
  }
15
28
 
16
29
  /**
@@ -1,15 +1,30 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const fs = require('fs');
5
-
6
- const mockers = require('./mocks/jest-mocks');
7
-
8
- function exec() {
9
- const cli = require('../command');
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
15
+
16
+ vi.spyOn(console, 'info').mockImplementation(() => {});
17
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
18
+
19
+ // command.js must be loaded AFTER shell.cd() changes CWD, because yargs.config()
20
+ // reads .versionrc at module load time. Use dynamic import with vi.resetModules().
21
+ async function exec() {
22
+ vi.resetModules();
23
+ const { default: cli } = await import('../command');
10
24
  const opt = cli.parse('commit-and-tag-version');
11
25
  opt.skip = { commit: true, tag: true };
12
- return require('../index')(opt);
26
+ const { default: standardVersion } = await import('../index');
27
+ return standardVersion(opt);
13
28
  }
14
29
 
15
30
  /**
@@ -1,15 +1,28 @@
1
- 'use strict';
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
2
3
 
3
- const shell = require('shelljs');
4
- const fs = require('fs');
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
5
15
 
6
- const mockers = require('./mocks/jest-mocks');
16
+ vi.spyOn(console, 'info').mockImplementation(() => {});
17
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
7
18
 
8
- function exec() {
9
- const cli = require('../command');
19
+ async function exec() {
20
+ vi.resetModules();
21
+ const { default: cli } = await import('../command');
10
22
  const opt = cli.parse('commit-and-tag-version');
11
23
  opt.skip = { commit: true, tag: true };
12
- return require('../index')(opt);
24
+ const { default: standardVersion } = await import('../index');
25
+ return standardVersion(opt);
13
26
  }
14
27
 
15
28
  /**