commit-and-tag-version 12.0.0 → 12.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 (49) hide show
  1. package/.eslintrc +43 -8
  2. package/.gitattributes +2 -0
  3. package/.github/workflows/ci.yaml +10 -3
  4. package/.prettierrc +3 -0
  5. package/CHANGELOG.md +7 -0
  6. package/README.md +4 -0
  7. package/bin/cli.js +6 -6
  8. package/command.js +43 -37
  9. package/defaults.js +12 -11
  10. package/index.js +44 -42
  11. package/jest.config.js +28 -0
  12. package/lib/checkpoint.js +19 -8
  13. package/lib/configuration.js +17 -17
  14. package/lib/detect-package-manager.js +20 -20
  15. package/lib/format-commit-message.js +3 -3
  16. package/lib/latest-semver-tag.js +13 -11
  17. package/lib/lifecycles/bump.js +136 -105
  18. package/lib/lifecycles/changelog.js +70 -51
  19. package/lib/lifecycles/commit.js +41 -42
  20. package/lib/lifecycles/tag.js +41 -31
  21. package/lib/preset-loader.js +12 -10
  22. package/lib/print-error.js +10 -7
  23. package/lib/run-exec.js +10 -10
  24. package/lib/run-execFile.js +10 -10
  25. package/lib/run-lifecycle-script.js +16 -11
  26. package/lib/stringify-package.js +10 -10
  27. package/lib/updaters/index.js +40 -33
  28. package/lib/updaters/types/csproj.js +9 -7
  29. package/lib/updaters/types/gradle.js +10 -8
  30. package/lib/updaters/types/json.js +14 -14
  31. package/lib/updaters/types/plain-text.js +4 -4
  32. package/lib/write-file.js +4 -4
  33. package/package.json +14 -21
  34. package/test/commit-message-config.integration-test.js +106 -0
  35. package/test/config-files.integration-test.js +114 -0
  36. package/test/config-keys.integration-test.js +83 -0
  37. package/test/core.spec.js +1369 -704
  38. package/test/git.integration-test.js +363 -0
  39. package/test/invalid-config.integration-test.js +73 -0
  40. package/test/mocks/jest-mocks.js +48 -0
  41. package/test/mocks/updater/customer-updater.js +5 -8
  42. package/test/mocks/updater/increment-updater.js +5 -5
  43. package/test/pre-commit-hook.integration-test.js +192 -0
  44. package/test/preset.integration-test.js +56 -0
  45. package/test/stringify-package.spec.js +18 -22
  46. package/test/utils.spec.js +25 -41
  47. package/test/config-files.spec.js +0 -176
  48. package/test/git.spec.js +0 -480
  49. package/test/preset.spec.js +0 -52
package/package.json CHANGED
@@ -1,24 +1,22 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "12.0.0",
3
+ "version": "12.1.0",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
5
  "bin": "bin/cli.js",
6
6
  "scripts": {
7
7
  "fix": "eslint . --fix",
8
- "posttest": "eslint .",
9
- "test": "nyc mocha --timeout=30000",
10
- "test:unit": "mocha --exclude test/git.spec.js",
11
- "coverage": "nyc report --reporter=lcov",
8
+ "posttest": "eslint . && npm run format:check",
9
+ "format:base": "prettier \"./**/*.{ts,js}\"",
10
+ "format:fix": "npm run format:base -- --write",
11
+ "format:check": "npm run format:base -- --check",
12
+ "test": "jest",
13
+ "test:unit": "jest --testPathIgnorePatterns test/git.integration-test.js",
14
+ "test:git-integration": "jest --testPathPattern test/git.integration-test.js",
12
15
  "release": "bin/cli.js"
13
16
  },
14
- "nyc": {
15
- "exclude": [
16
- "tmp/**"
17
- ]
18
- },
19
17
  "repository": "absolute-version/commit-and-tag-version",
20
18
  "engines": {
21
- "node": ">=14"
19
+ "node": ">=18"
22
20
  },
23
21
  "keywords": [
24
22
  "conventional-changelog",
@@ -55,21 +53,16 @@
55
53
  "yargs": "^17.7.2"
56
54
  },
57
55
  "devDependencies": {
58
- "@fintechstudios/eslint-plugin-chai-as-promised": "^3.1.0",
59
- "chai": "^4.3.10",
60
- "chai-as-promised": "^7.1.1",
61
56
  "eslint": "^8.52.0",
62
- "eslint-config-standard": "^17.1.0",
57
+ "eslint-config-prettier": "^9.0.0",
63
58
  "eslint-plugin-import": "^2.29.0",
64
- "eslint-plugin-mocha": "^10.2.0",
59
+ "eslint-plugin-jest": "^27.6.0",
65
60
  "eslint-plugin-n": "^15.2.0",
66
61
  "eslint-plugin-promise": "^6.1.1",
67
- "mocha": "^10.2.0",
68
- "mock-fs": "^5.2.0",
69
- "mockery": "^2.1.0",
70
- "nyc": "^15.1.0",
62
+ "jest": "^29.7.0",
63
+ "jest-serial-runner": "^1.2.1",
64
+ "prettier": "3.0.3",
71
65
  "shelljs": "^0.8.5",
72
- "std-mocks": "^1.0.1",
73
66
  "strip-ansi": "^6.0.0"
74
67
  }
75
68
  }
@@ -0,0 +1,106 @@
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 = '') {
9
+ if (typeof opt === 'string') {
10
+ const cli = require('../command');
11
+ opt = cli.parse(`commit-and-tag-version ${opt}`);
12
+ }
13
+ return require('../index')(opt);
14
+ }
15
+
16
+ /**
17
+ * Mock external conventional-changelog modules
18
+ *
19
+ * bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
20
+ * changelog?: string | Error | Array<string | Error | (opt) => string | null>
21
+ * tags?: string[] | Error
22
+ */
23
+ function mock({ bump, changelog, tags }) {
24
+ if (bump === undefined) throw new Error('bump must be defined for mock()');
25
+
26
+ mockers.mockRecommendedBump({ bump });
27
+
28
+ if (!Array.isArray(changelog)) changelog = [changelog];
29
+ mockers.mockConventionalChangelog({ changelog });
30
+
31
+ mockers.mockGitSemverTags({ tags });
32
+ }
33
+
34
+ function writePackageJson(version, option) {
35
+ const pkg = Object.assign({}, option, { version });
36
+ fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8');
37
+ }
38
+
39
+ function setupTempGitRepo() {
40
+ shell.rm('-rf', 'commit-message-config-temp');
41
+ shell.config.silent = true;
42
+ shell.mkdir('commit-message-config-temp');
43
+ shell.cd('commit-message-config-temp');
44
+ shell.exec('git init');
45
+ shell.exec('git config commit.gpgSign false');
46
+ shell.exec('git config core.autocrlf false');
47
+ shell.exec('git commit --allow-empty -m"root-commit"');
48
+ }
49
+
50
+ function setup() {
51
+ setupTempGitRepo();
52
+ writePackageJson('1.0.0');
53
+ }
54
+
55
+ function reset() {
56
+ shell.cd('../');
57
+ shell.rm('-rf', 'commit-message-config-temp');
58
+ }
59
+
60
+ describe('configuration', function () {
61
+ beforeEach(function () {
62
+ setup();
63
+ });
64
+
65
+ afterEach(function () {
66
+ reset();
67
+ });
68
+
69
+ it('.versionrc : releaseCommitMessageFormat', async function () {
70
+ fs.writeFileSync(
71
+ '.versionrc',
72
+ JSON.stringify({
73
+ releaseCommitMessageFormat:
74
+ 'This commit represents release: {{currentTag}}',
75
+ }),
76
+ 'utf-8',
77
+ );
78
+ mock({ bump: 'minor' });
79
+ await exec('');
80
+ expect(shell.exec('git log --oneline -n1').stdout).toMatch(
81
+ 'This commit represents release: 1.1.0',
82
+ );
83
+ });
84
+
85
+ it('--releaseCommitMessageFormat', async function () {
86
+ mock({ bump: 'minor' });
87
+ await exec('--releaseCommitMessageFormat="{{currentTag}} is the version."');
88
+ expect(shell.exec('git log --oneline -n1').stdout).toContain(
89
+ '1.1.0 is the version.',
90
+ );
91
+ });
92
+
93
+ it('[LEGACY] supports --message (and single %s replacement)', async function () {
94
+ mock({ bump: 'minor' });
95
+ await exec('--message="V:%s"');
96
+ expect(shell.exec('git log --oneline -n1').stdout).toContain('V:1.1.0');
97
+ });
98
+
99
+ it('[LEGACY] supports -m (and multiple %s replacements)', async function () {
100
+ mock({ bump: 'minor' });
101
+ await exec('--message="V:%s is the %s."');
102
+ expect(shell.exec('git log --oneline -n1').stdout).toContain(
103
+ 'V:1.1.0 is the 1.1.0.',
104
+ );
105
+ });
106
+ });
@@ -0,0 +1,114 @@
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');
10
+ const opt = cli.parse('commit-and-tag-version');
11
+ opt.skip = { commit: true, tag: true };
12
+ return require('../index')(opt);
13
+ }
14
+
15
+ /**
16
+ * Mock external conventional-changelog modules
17
+ *
18
+ * Mocks should be unregistered in test cleanup by calling unmock()
19
+ *
20
+ * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
21
+ * changelog?: string | Error | Array<string | Error | (opt) => string | null>
22
+ * tags?: string[] | Error
23
+ */
24
+ function mock({ bump, changelog, tags } = {}) {
25
+ mockers.mockRecommendedBump({ bump });
26
+
27
+ if (!Array.isArray(changelog)) changelog = [changelog];
28
+
29
+ mockers.mockConventionalChangelog({ changelog });
30
+
31
+ mockers.mockGitSemverTags({ tags });
32
+ }
33
+
34
+ function setupTestDirectory() {
35
+ shell.rm('-rf', 'config-files-temp');
36
+ shell.config.silent = true;
37
+ shell.mkdir('config-files-temp');
38
+ shell.cd('config-files-temp');
39
+ }
40
+
41
+ function resetShell() {
42
+ shell.cd('../');
43
+ shell.rm('-rf', 'config-files-temp');
44
+ }
45
+
46
+ describe('config files', function () {
47
+ beforeEach(function () {
48
+ setupTestDirectory();
49
+
50
+ fs.writeFileSync(
51
+ 'package.json',
52
+ JSON.stringify({ version: '1.0.0' }),
53
+ 'utf-8',
54
+ );
55
+ });
56
+
57
+ afterEach(function () {
58
+ resetShell();
59
+ 4;
60
+ });
61
+
62
+ it('reads config from .versionrc', async function () {
63
+ const issueUrlFormat = 'http://www.foo.com/{{id}}';
64
+ const changelog = ({ preset }) => preset.issueUrlFormat;
65
+
66
+ mock({ bump: 'minor', changelog });
67
+ fs.writeFileSync('.versionrc', JSON.stringify({ issueUrlFormat }), 'utf-8');
68
+
69
+ await exec();
70
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
71
+ expect(content).toContain(issueUrlFormat);
72
+ });
73
+
74
+ it('reads config from .versionrc.json', async function () {
75
+ const issueUrlFormat = 'http://www.foo.com/{{id}}';
76
+ const changelog = ({ preset }) => preset.issueUrlFormat;
77
+ mock({ bump: 'minor', changelog });
78
+ fs.writeFileSync(
79
+ '.versionrc.json',
80
+ JSON.stringify({ issueUrlFormat }),
81
+ 'utf-8',
82
+ );
83
+
84
+ await exec();
85
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
86
+ expect(content).toContain(issueUrlFormat);
87
+ });
88
+
89
+ it('evaluates a config-function from .versionrc.js', async function () {
90
+ const issueUrlFormat = 'http://www.foo.com/{{id}}';
91
+ const src = `module.exports = function() { return ${JSON.stringify({
92
+ issueUrlFormat,
93
+ })} }`;
94
+ const changelog = ({ preset }) => preset.issueUrlFormat;
95
+ mock({ bump: 'minor', changelog });
96
+ fs.writeFileSync('.versionrc.js', src, 'utf-8');
97
+
98
+ await exec();
99
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
100
+ expect(content).toContain(issueUrlFormat);
101
+ });
102
+
103
+ it('evaluates a config-object from .versionrc.js', async function () {
104
+ const issueUrlFormat = 'http://www.foo.com/{{id}}';
105
+ const src = `module.exports = ${JSON.stringify({ issueUrlFormat })}`;
106
+ const changelog = ({ preset }) => preset.issueUrlFormat;
107
+ mock({ bump: 'minor', changelog });
108
+ fs.writeFileSync('.versionrc.js', src, 'utf-8');
109
+
110
+ await exec();
111
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
112
+ expect(content).toContain(issueUrlFormat);
113
+ });
114
+ });
@@ -0,0 +1,83 @@
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');
10
+ const opt = cli.parse('commit-and-tag-version');
11
+ opt.skip = { commit: true, tag: true };
12
+ return require('../index')(opt);
13
+ }
14
+
15
+ /**
16
+ * Mock external conventional-changelog modules
17
+ *
18
+ * Mocks should be unregistered in test cleanup by calling unmock()
19
+ *
20
+ * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
21
+ * changelog?: string | Error | Array<string | Error | (opt) => string | null>
22
+ * tags?: string[] | Error
23
+ */
24
+ function mock({ bump, changelog, tags } = {}) {
25
+ mockers.mockRecommendedBump({ bump });
26
+
27
+ if (!Array.isArray(changelog)) changelog = [changelog];
28
+
29
+ mockers.mockConventionalChangelog({ changelog });
30
+
31
+ mockers.mockGitSemverTags({ tags });
32
+ }
33
+
34
+ function setupTempGitRepo() {
35
+ shell.rm('-rf', 'config-keys-temp');
36
+ shell.config.silent = true;
37
+ shell.mkdir('config-keys-temp');
38
+ shell.cd('config-keys-temp');
39
+ }
40
+
41
+ function resetShell() {
42
+ shell.cd('../');
43
+ shell.rm('-rf', 'config-keys-temp');
44
+ }
45
+
46
+ describe('config files', function () {
47
+ beforeEach(function () {
48
+ setupTempGitRepo();
49
+
50
+ fs.writeFileSync(
51
+ 'package.json',
52
+ JSON.stringify({ version: '1.0.0' }),
53
+ 'utf-8',
54
+ );
55
+ });
56
+
57
+ afterEach(function () {
58
+ resetShell();
59
+ });
60
+
61
+ const configKeys = ['commit-and-tag-version', 'standard-version'];
62
+
63
+ configKeys.forEach((configKey) => {
64
+ it(`reads config from package.json key '${configKey}'`, async function () {
65
+ const issueUrlFormat =
66
+ 'https://commit-and-tag-version.company.net/browse/{{id}}';
67
+ mock({
68
+ bump: 'minor',
69
+ changelog: ({ preset }) => preset.issueUrlFormat,
70
+ });
71
+ const pkg = {
72
+ version: '1.0.0',
73
+ repository: { url: 'git+https://company@scm.org/office/app.git' },
74
+ [configKey]: { issueUrlFormat },
75
+ };
76
+ fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8');
77
+
78
+ await exec();
79
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
80
+ expect(content).toMatch(issueUrlFormat);
81
+ });
82
+ });
83
+ });