commit-and-tag-version 9.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.
Files changed (43) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintrc +6 -0
  3. package/.github/ISSUE_TEMPLATE/ask-a-question.md +7 -0
  4. package/.github/ISSUE_TEMPLATE/bug-report.md +29 -0
  5. package/.github/workflows/ci.yaml +33 -0
  6. package/.github/workflows/release-please.yml +31 -0
  7. package/.versionrc +10 -0
  8. package/CHANGELOG.md +524 -0
  9. package/LICENSE.txt +16 -0
  10. package/README.md +480 -0
  11. package/bin/cli.js +14 -0
  12. package/command.js +145 -0
  13. package/defaults.js +40 -0
  14. package/index.js +92 -0
  15. package/lib/checkpoint.js +12 -0
  16. package/lib/configuration.js +41 -0
  17. package/lib/format-commit-message.js +4 -0
  18. package/lib/latest-semver-tag.js +17 -0
  19. package/lib/lifecycles/bump.js +172 -0
  20. package/lib/lifecycles/changelog.js +66 -0
  21. package/lib/lifecycles/commit.js +69 -0
  22. package/lib/lifecycles/tag.js +39 -0
  23. package/lib/preset-loader.js +17 -0
  24. package/lib/print-error.js +12 -0
  25. package/lib/run-exec.js +18 -0
  26. package/lib/run-execFile.js +18 -0
  27. package/lib/run-lifecycle-script.js +13 -0
  28. package/lib/updaters/index.js +85 -0
  29. package/lib/updaters/types/json.js +25 -0
  30. package/lib/updaters/types/plain-text.js +7 -0
  31. package/lib/write-file.js +6 -0
  32. package/package.json +69 -0
  33. package/renovate.json +9 -0
  34. package/test/config-files.spec.js +179 -0
  35. package/test/core.spec.js +850 -0
  36. package/test/git.spec.js +468 -0
  37. package/test/mocks/VERSION-1.0.0.txt +1 -0
  38. package/test/mocks/VERSION-6.3.1.txt +1 -0
  39. package/test/mocks/manifest-6.3.1.json +3 -0
  40. package/test/mocks/mix.exs +28 -0
  41. package/test/mocks/updater/customer-updater.js +12 -0
  42. package/test/mocks/version.txt +0 -0
  43. package/test/preset.spec.js +52 -0
@@ -0,0 +1,25 @@
1
+ const stringifyPackage = require('stringify-package')
2
+ const detectIndent = require('detect-indent')
3
+ const detectNewline = require('detect-newline')
4
+
5
+ module.exports.readVersion = function (contents) {
6
+ return JSON.parse(contents).version
7
+ }
8
+
9
+ module.exports.writeVersion = function (contents, version) {
10
+ const json = JSON.parse(contents)
11
+ const indent = detectIndent(contents).indent
12
+ const newline = detectNewline(contents)
13
+ json.version = version
14
+
15
+ if (json.packages && json.packages['']) {
16
+ // package-lock v2 stores version there too
17
+ json.packages[''].version = version
18
+ }
19
+
20
+ return stringifyPackage(json, indent, newline)
21
+ }
22
+
23
+ module.exports.isPrivate = function (contents) {
24
+ return JSON.parse(contents).private
25
+ }
@@ -0,0 +1,7 @@
1
+ module.exports.readVersion = function (contents) {
2
+ return contents
3
+ }
4
+
5
+ module.exports.writeVersion = function (_contents, version) {
6
+ return version
7
+ }
@@ -0,0 +1,6 @@
1
+ const fs = require('fs')
2
+
3
+ module.exports = function (args, filePath, content) {
4
+ if (args.dryRun) return
5
+ fs.writeFileSync(filePath, content, 'utf8')
6
+ }
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "commit-and-tag-version",
3
+ "version": "9.5.0",
4
+ "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
+ "bin": "bin/cli.js",
6
+ "scripts": {
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",
12
+ "release": "bin/cli.js"
13
+ },
14
+ "nyc": {
15
+ "exclude": [
16
+ "tmp/**"
17
+ ]
18
+ },
19
+ "repository": "absolute-version/commit-and-tag-version",
20
+ "engines": {
21
+ "node": ">=10"
22
+ },
23
+ "keywords": [
24
+ "conventional-changelog",
25
+ "recommended",
26
+ "changelog",
27
+ "automatic",
28
+ "workflow",
29
+ "version",
30
+ "angular",
31
+ "standard"
32
+ ],
33
+ "author": "Ben Coe <ben@npmjs.com>",
34
+ "license": "ISC",
35
+ "bugs": {
36
+ "url": "https://github.com/absolute-version/commit-and-tag-version/issues"
37
+ },
38
+ "homepage": "https://github.com/absolute-version/commit-and-tag-version#readme",
39
+ "dependencies": {
40
+ "chalk": "^2.4.2",
41
+ "conventional-changelog": "3.1.25",
42
+ "conventional-changelog-config-spec": "2.1.0",
43
+ "conventional-changelog-conventionalcommits": "4.6.3",
44
+ "conventional-recommended-bump": "6.1.0",
45
+ "detect-indent": "^6.0.0",
46
+ "detect-newline": "^3.1.0",
47
+ "dotgitignore": "^2.1.0",
48
+ "figures": "^3.1.0",
49
+ "find-up": "^5.0.0",
50
+ "git-semver-tags": "^4.0.0",
51
+ "semver": "^7.1.1",
52
+ "stringify-package": "^1.0.1",
53
+ "yargs": "^16.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "chai": "^4.2.0",
57
+ "eslint": "^7.14.0",
58
+ "eslint-config-standard": "^16.0.2",
59
+ "eslint-plugin-import": "^2.22.1",
60
+ "eslint-plugin-node": "^11.1.0",
61
+ "eslint-plugin-promise": "^5.0.0",
62
+ "mocha": "^8.2.1",
63
+ "mock-fs": "^4.13.0",
64
+ "mockery": "^2.1.0",
65
+ "nyc": "^15.1.0",
66
+ "shelljs": "^0.8.4",
67
+ "std-mocks": "^1.0.1"
68
+ }
69
+ }
package/renovate.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": [
3
+ "config:base"
4
+ ],
5
+ "pinVersions": false,
6
+ "rebaseStalePrs": true,
7
+ "gitAuthor": null,
8
+ "ignoreDeps": ["decamelize"]
9
+ }
@@ -0,0 +1,179 @@
1
+ /* global describe it beforeEach afterEach */
2
+
3
+ 'use strict'
4
+
5
+ const shell = require('shelljs')
6
+ const fs = require('fs')
7
+ const { Readable } = require('stream')
8
+ const mockery = require('mockery')
9
+ const stdMocks = require('std-mocks')
10
+
11
+ require('chai').should()
12
+
13
+ function exec () {
14
+ const cli = require('../command')
15
+ const opt = cli.parse('commit-and-tag-version')
16
+ opt.skip = { commit: true, tag: true }
17
+ return require('../index')(opt)
18
+ }
19
+
20
+ /**
21
+ * Mock external conventional-changelog modules
22
+ *
23
+ * Mocks should be unregistered in test cleanup by calling unmock()
24
+ *
25
+ * bump?: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) }
26
+ * changelog?: string | Error | Array<string | Error | (opt) => string | null>
27
+ * tags?: string[] | Error
28
+ */
29
+ function mock ({ bump, changelog, tags } = {}) {
30
+ mockery.enable({ warnOnUnregistered: false, useCleanCache: true })
31
+
32
+ mockery.registerMock('conventional-recommended-bump', function (opt, cb) {
33
+ if (typeof bump === 'function') bump(opt, cb)
34
+ else if (bump instanceof Error) cb(bump)
35
+ else cb(null, bump ? { releaseType: bump } : {})
36
+ })
37
+
38
+ if (!Array.isArray(changelog)) changelog = [changelog]
39
+ mockery.registerMock(
40
+ 'conventional-changelog',
41
+ (opt) =>
42
+ new Readable({
43
+ read (_size) {
44
+ const next = changelog.shift()
45
+ if (next instanceof Error) {
46
+ this.destroy(next)
47
+ } else if (typeof next === 'function') {
48
+ this.push(next(opt))
49
+ } else {
50
+ this.push(next ? Buffer.from(next, 'utf8') : null)
51
+ }
52
+ }
53
+ })
54
+ )
55
+
56
+ mockery.registerMock('git-semver-tags', function (cb) {
57
+ if (tags instanceof Error) cb(tags)
58
+ else cb(null, tags | [])
59
+ })
60
+
61
+ stdMocks.use()
62
+ return () => stdMocks.flush()
63
+ }
64
+
65
+ describe('config files', () => {
66
+ beforeEach(function () {
67
+ shell.rm('-rf', 'tmp')
68
+ shell.config.silent = true
69
+ shell.mkdir('tmp')
70
+ shell.cd('tmp')
71
+ fs.writeFileSync(
72
+ 'package.json',
73
+ JSON.stringify({ version: '1.0.0' }),
74
+ 'utf-8'
75
+ )
76
+ })
77
+
78
+ afterEach(function () {
79
+ shell.cd('../')
80
+ shell.rm('-rf', 'tmp')
81
+
82
+ mockery.deregisterAll()
83
+ mockery.disable()
84
+ stdMocks.restore()
85
+
86
+ // push out prints from the Mocha reporter
87
+ const { stdout } = stdMocks.flush()
88
+ for (const str of stdout) {
89
+ if (str.startsWith(' ')) process.stdout.write(str)
90
+ }
91
+ })
92
+
93
+ const configKeys = ['commit-and-tag-version', 'standard-version']
94
+
95
+ configKeys.forEach((configKey) => {
96
+ it(`reads config from package.json key '${configKey}'`, async function () {
97
+ const issueUrlFormat =
98
+ 'https://commit-and-tag-version.company.net/browse/{{id}}'
99
+ mock({
100
+ bump: 'minor',
101
+ changelog: ({ preset }) => preset.issueUrlFormat
102
+ })
103
+ const pkg = {
104
+ version: '1.0.0',
105
+ repository: { url: 'git+https://company@scm.org/office/app.git' },
106
+ [configKey]: { issueUrlFormat }
107
+ }
108
+ fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')
109
+
110
+ await exec()
111
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
112
+ content.should.include(issueUrlFormat)
113
+ })
114
+ })
115
+
116
+ it('reads config from .versionrc', async function () {
117
+ const issueUrlFormat = 'http://www.foo.com/{{id}}'
118
+ const changelog = ({ preset }) => preset.issueUrlFormat
119
+ mock({ bump: 'minor', changelog })
120
+ fs.writeFileSync('.versionrc', JSON.stringify({ issueUrlFormat }), 'utf-8')
121
+
122
+ await exec()
123
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
124
+ content.should.include(issueUrlFormat)
125
+ })
126
+
127
+ it('reads config from .versionrc.json', async function () {
128
+ const issueUrlFormat = 'http://www.foo.com/{{id}}'
129
+ const changelog = ({ preset }) => preset.issueUrlFormat
130
+ mock({ bump: 'minor', changelog })
131
+ fs.writeFileSync(
132
+ '.versionrc.json',
133
+ JSON.stringify({ issueUrlFormat }),
134
+ 'utf-8'
135
+ )
136
+
137
+ await exec()
138
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
139
+ content.should.include(issueUrlFormat)
140
+ })
141
+
142
+ it('evaluates a config-function from .versionrc.js', async function () {
143
+ const issueUrlFormat = 'http://www.foo.com/{{id}}'
144
+ const src = `module.exports = function() { return ${JSON.stringify({
145
+ issueUrlFormat
146
+ })} }`
147
+ const changelog = ({ preset }) => preset.issueUrlFormat
148
+ mock({ bump: 'minor', changelog })
149
+ fs.writeFileSync('.versionrc.js', src, 'utf-8')
150
+
151
+ await exec()
152
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
153
+ content.should.include(issueUrlFormat)
154
+ })
155
+
156
+ it('evaluates a config-object from .versionrc.js', async function () {
157
+ const issueUrlFormat = 'http://www.foo.com/{{id}}'
158
+ const src = `module.exports = ${JSON.stringify({ issueUrlFormat })}`
159
+ const changelog = ({ preset }) => preset.issueUrlFormat
160
+ mock({ bump: 'minor', changelog })
161
+ fs.writeFileSync('.versionrc.js', src, 'utf-8')
162
+
163
+ await exec()
164
+ const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
165
+ content.should.include(issueUrlFormat)
166
+ })
167
+
168
+ it('throws an error when a non-object is returned from .versionrc.js', async function () {
169
+ mock({ bump: 'minor' })
170
+ fs.writeFileSync('.versionrc.js', 'module.exports = 3', 'utf-8')
171
+ try {
172
+ await exec()
173
+ /* istanbul ignore next */
174
+ throw new Error('Unexpected success')
175
+ } catch (error) {
176
+ error.message.should.match(/Invalid configuration/)
177
+ }
178
+ })
179
+ })