commit-and-tag-version 11.1.0 → 11.2.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.
- package/CHANGELOG.md +16 -0
- package/README.md +64 -1
- package/command.js +5 -0
- package/defaults.js +2 -1
- package/lib/detect-package-manager.js +53 -0
- package/lib/lifecycles/tag.js +9 -1
- package/lib/stringify-package.js +36 -0
- package/lib/updaters/types/json.js +1 -1
- package/package.json +4 -2
- package/test/git.spec.js +8 -0
- package/test/stringify-package.spec.js +39 -0
- package/test/utils.spec.js +52 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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
|
+
## [11.2.1](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.0...v11.2.1) (2023-04-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **dep:** add stringify-package to project source, removing the deprecation warning on npm install ([#65](https://github.com/absolute-version/commit-and-tag-version/issues/65)) ([3a959a7](https://github.com/absolute-version/commit-and-tag-version/commit/3a959a7eba86ad42b98592167df7c67f00b661a0))
|
|
11
|
+
|
|
12
|
+
## [11.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.1.0...v11.2.0) (2023-03-15)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* implement detect pm name ([174a8bd](https://github.com/absolute-version/commit-and-tag-version/commit/174a8bd00106dcc2a6b1c5bcb75bf3fbfd0317da))
|
|
18
|
+
* support config npmClient ([c33686a](https://github.com/absolute-version/commit-and-tag-version/commit/c33686aec080162645466ed962d64133f71e4214))
|
|
19
|
+
* Support customizing the npm publish hint message with a new option: `npmPublishHint` ([1f77110](https://github.com/absolute-version/commit-and-tag-version/commit/1f77110deefa8a394a37c421eb3d313f6c87aea5))
|
|
20
|
+
|
|
5
21
|
## [11.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.0.0...v11.1.0) (2023-02-14)
|
|
6
22
|
|
|
7
23
|
|
package/README.md
CHANGED
|
@@ -15,7 +15,44 @@ A utility for versioning using [semver](https://semver.org/) and CHANGELOG gener
|
|
|
15
15
|
|
|
16
16
|
_Having problems? Want to contribute? Join us on the [node-tooling community Slack](http://devtoolscommunity.herokuapp.com)_.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
- [Commit and Tag Version](#commit-and-tag-version)
|
|
19
|
+
- [How It Works:](#how-it-works)
|
|
20
|
+
- [`bumpFiles`, `packageFiles` and `updaters`](#bumpfiles-packagefiles-and-updaters)
|
|
21
|
+
- [Gradle Support (Java/Kotlin)](#gradle-support-javakotlin)
|
|
22
|
+
- [Installing `commit-and-tag-version`](#installing-commit-and-tag-version)
|
|
23
|
+
- [As a local `npm run` script](#as-a-local-npm-run-script)
|
|
24
|
+
- [As global `bin`](#as-global-bin)
|
|
25
|
+
- [Using `npx`](#using-npx)
|
|
26
|
+
- [Configuration](#configuration)
|
|
27
|
+
- [Customizing CHANGELOG Generation](#customizing-changelog-generation)
|
|
28
|
+
- [Deeper customization](#deeper-customization)
|
|
29
|
+
- [CLI Usage](#cli-usage)
|
|
30
|
+
- [First Release](#first-release)
|
|
31
|
+
- [Cutting Releases](#cutting-releases)
|
|
32
|
+
- [Release as a Pre-Release](#release-as-a-pre-release)
|
|
33
|
+
- [Release as a Target Type Imperatively (`npm version`-like)](#release-as-a-target-type-imperatively-npm-version-like)
|
|
34
|
+
- [Prevent Git Hooks](#prevent-git-hooks)
|
|
35
|
+
- [Signing Commits and Tags](#signing-commits-and-tags)
|
|
36
|
+
- [Lifecycle Scripts](#lifecycle-scripts)
|
|
37
|
+
- [Skipping Lifecycle Steps](#skipping-lifecycle-steps)
|
|
38
|
+
- [Committing Generated Artifacts in the Release Commit](#committing-generated-artifacts-in-the-release-commit)
|
|
39
|
+
- [Dry Run Mode](#dry-run-mode)
|
|
40
|
+
- [Prefix Tags](#prefix-tags)
|
|
41
|
+
- [Tag replacement](#tag-replacement)
|
|
42
|
+
- [Generate changelogs for old releases](#generate-changelogs-for-old-releases)
|
|
43
|
+
- [CLI Help](#cli-help)
|
|
44
|
+
- [Code Usage](#code-usage)
|
|
45
|
+
- [FAQ](#faq)
|
|
46
|
+
- [How is `commit-and-tag-version` different from `semantic-release`?](#how-is-commit-and-tag-version-different-from-semantic-release)
|
|
47
|
+
- [Should I always squash commits when merging PRs?](#should-i-always-squash-commits-when-merging-prs)
|
|
48
|
+
- [Can I use `commit-and-tag-version` for additional metadata files, languages or version files?](#can-i-use-commit-and-tag-version-for-additional-metadata-files-languages-or-version-files)
|
|
49
|
+
- [Custom `updater`s](#custom-updaters)
|
|
50
|
+
- [`readVersion(contents = string): string`](#readversioncontents--string-string)
|
|
51
|
+
- [`writeVersion(contents = string, version: string): string`](#writeversioncontents--string-version-string-string)
|
|
52
|
+
- [License](#license)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### How It Works:
|
|
19
56
|
|
|
20
57
|
1. Follow the [Conventional Commits Specification](https://conventionalcommits.org) in your repository.
|
|
21
58
|
2. When you're ready to release, run `commit-and-tag-version`.
|
|
@@ -515,6 +552,32 @@ module.exports.writeVersion = function (contents, version) {
|
|
|
515
552
|
};
|
|
516
553
|
```
|
|
517
554
|
|
|
555
|
+
### Why do breaking changes before 1.0.0 not trigger a 1.0.0 release?
|
|
556
|
+
|
|
557
|
+
Below 1.0.0, the semver specification doesn't give any guarantees about the
|
|
558
|
+
meaning of version numbers. However, with npm there is a community convention,
|
|
559
|
+
and implementation-defined behaviour: If your version is between 0.1.0 and
|
|
560
|
+
1.0.0, npm treats an update to the minor version as a breaking change - that is
|
|
561
|
+
^0.1.0 will match 0.1.2 but not 0.2.0. Rust's cargo package manager also behaves
|
|
562
|
+
the same way.
|
|
563
|
+
|
|
564
|
+
This tool (via conventional-commits) also follows that convention - breaking
|
|
565
|
+
changes below v1.0.0 are treated as a minor version bump. Here's an example
|
|
566
|
+
series of commits with tagged versions:
|
|
567
|
+
|
|
568
|
+
```
|
|
569
|
+
1017b00 chore: initial commit
|
|
570
|
+
9e2ba95 (tag: v0.0.2) chore(release): 0.0.2
|
|
571
|
+
3598012 fix!: Example breaking change
|
|
572
|
+
1a4994a (tag: v0.1.0) chore(release): 0.1.0
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
Semver's only guarantee is "all bets are off", but npm has made a choice about
|
|
576
|
+
what bets to make. `commit-and-tag-version` follows the same convention (along
|
|
577
|
+
with other package managers for other ecosystems).
|
|
578
|
+
|
|
579
|
+
When you are ready to release v1.0.0, add `--release-as 1.0.0` to the options.
|
|
580
|
+
|
|
518
581
|
## License
|
|
519
582
|
|
|
520
583
|
ISC
|
package/command.js
CHANGED
|
@@ -121,6 +121,11 @@ const yargs = require('yargs')
|
|
|
121
121
|
type: 'string',
|
|
122
122
|
describe: 'Name of the package from which the tags will be extracted'
|
|
123
123
|
})
|
|
124
|
+
.option('npmPublishHint', {
|
|
125
|
+
type: 'string',
|
|
126
|
+
default: defaults.npmPublishHint,
|
|
127
|
+
describe: 'Customized publishing hint'
|
|
128
|
+
})
|
|
124
129
|
.check((argv) => {
|
|
125
130
|
if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
|
|
126
131
|
throw Error('scripts must be an object')
|
package/defaults.js
CHANGED
|
@@ -14,7 +14,8 @@ const defaults = {
|
|
|
14
14
|
dryRun: false,
|
|
15
15
|
tagForce: false,
|
|
16
16
|
gitTagFallback: true,
|
|
17
|
-
preset: require.resolve('conventional-changelog-conventionalcommits')
|
|
17
|
+
preset: require.resolve('conventional-changelog-conventionalcommits'),
|
|
18
|
+
npmPublishHint: undefined
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modified from <https://github.com/egoist/detect-package-manager/blob/main/src/index.ts>
|
|
3
|
+
* the original code is licensed under MIT
|
|
4
|
+
* modified to support only detecting lock file and not detecting global package manager
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { promises: fs } = require('fs')
|
|
8
|
+
const { resolve } = require('path')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Check if a path exists
|
|
12
|
+
*/
|
|
13
|
+
async function pathExists (p) {
|
|
14
|
+
try {
|
|
15
|
+
await fs.access(p)
|
|
16
|
+
return true
|
|
17
|
+
} catch {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getTypeofLockFile (cwd = '.') {
|
|
23
|
+
return Promise.all([
|
|
24
|
+
pathExists(resolve(cwd, 'yarn.lock')),
|
|
25
|
+
pathExists(resolve(cwd, 'package-lock.json')),
|
|
26
|
+
pathExists(resolve(cwd, 'pnpm-lock.yaml'))
|
|
27
|
+
]).then(([isYarn, isNpm, isPnpm]) => {
|
|
28
|
+
let value = null
|
|
29
|
+
|
|
30
|
+
if (isYarn) {
|
|
31
|
+
value = 'yarn'
|
|
32
|
+
} else if (isPnpm) {
|
|
33
|
+
value = 'pnpm'
|
|
34
|
+
} else if (isNpm) {
|
|
35
|
+
value = 'npm'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return value
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const detectPMByLockFile = async (cwd) => {
|
|
43
|
+
const type = await getTypeofLockFile(cwd)
|
|
44
|
+
if (type) {
|
|
45
|
+
return type
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return 'npm'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
detectPMByLockFile
|
|
53
|
+
}
|
package/lib/lifecycles/tag.js
CHANGED
|
@@ -5,6 +5,7 @@ const figures = require('figures')
|
|
|
5
5
|
const formatCommitMessage = require('../format-commit-message')
|
|
6
6
|
const runExecFile = require('../run-execFile')
|
|
7
7
|
const runLifecycleScript = require('../run-lifecycle-script')
|
|
8
|
+
const { detectPMByLockFile } = require('../detect-package-manager')
|
|
8
9
|
|
|
9
10
|
module.exports = async function (newVersion, pkgPrivate, args) {
|
|
10
11
|
if (args.skip.tag) return
|
|
@@ -13,6 +14,12 @@ module.exports = async function (newVersion, pkgPrivate, args) {
|
|
|
13
14
|
await runLifecycleScript(args, 'posttag')
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
async function detectPublishHint () {
|
|
18
|
+
const npmClientName = await detectPMByLockFile()
|
|
19
|
+
const publishCommand = 'publish'
|
|
20
|
+
return `${npmClientName} ${publishCommand}`
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
async function execTag (newVersion, pkgPrivate, args) {
|
|
17
24
|
const tagOption = []
|
|
18
25
|
if (args.sign) {
|
|
@@ -28,7 +35,8 @@ async function execTag (newVersion, pkgPrivate, args) {
|
|
|
28
35
|
const currentBranch = await runExecFile('', 'git', ['rev-parse', '--abbrev-ref', 'HEAD'])
|
|
29
36
|
let message = 'git push --follow-tags origin ' + currentBranch.trim()
|
|
30
37
|
if (pkgPrivate !== true && bump.getUpdatedConfigs()['package.json']) {
|
|
31
|
-
|
|
38
|
+
const npmPublishHint = args.npmPublishHint || await detectPublishHint()
|
|
39
|
+
message += ` && ${npmPublishHint}`
|
|
32
40
|
if (args.prerelease !== undefined) {
|
|
33
41
|
if (args.prerelease === '') {
|
|
34
42
|
message += ' --tag prerelease'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright npm, Inc
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
6
|
+
copyright notice and this permission notice appear in all copies.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
|
|
16
|
+
https://github.com/npm/stringify-package/blob/main/LICENSE
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict'
|
|
20
|
+
|
|
21
|
+
module.exports = stringifyPackage
|
|
22
|
+
|
|
23
|
+
const DEFAULT_INDENT = 2
|
|
24
|
+
const CRLF = '\r\n'
|
|
25
|
+
const LF = '\n'
|
|
26
|
+
|
|
27
|
+
function stringifyPackage (data, indent, newline) {
|
|
28
|
+
indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT)
|
|
29
|
+
const json = JSON.stringify(data, null, indent)
|
|
30
|
+
|
|
31
|
+
if (newline === CRLF) {
|
|
32
|
+
return json.replace(/\n/g, CRLF) + CRLF
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return json + LF
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-and-tag-version",
|
|
3
|
-
"version": "11.1
|
|
3
|
+
"version": "11.2.1",
|
|
4
4
|
"description": "replacement for `npm version` with automatic CHANGELOG generation",
|
|
5
5
|
"bin": "bin/cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"standard"
|
|
32
32
|
],
|
|
33
33
|
"author": "Ben Coe <ben@npmjs.com>",
|
|
34
|
+
"contributors": [
|
|
35
|
+
"Timothy Jones <timothy.l.jones@gmail.com> (https://github.com/TimothyJones)"
|
|
36
|
+
],
|
|
34
37
|
"license": "ISC",
|
|
35
38
|
"bugs": {
|
|
36
39
|
"url": "https://github.com/absolute-version/commit-and-tag-version/issues"
|
|
@@ -49,7 +52,6 @@
|
|
|
49
52
|
"find-up": "^5.0.0",
|
|
50
53
|
"git-semver-tags": "^4.0.0",
|
|
51
54
|
"semver": "^7.1.1",
|
|
52
|
-
"stringify-package": "^1.0.1",
|
|
53
55
|
"yargs": "^17.0.0"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
package/test/git.spec.js
CHANGED
|
@@ -397,6 +397,14 @@ describe('git', function () {
|
|
|
397
397
|
.should.match(/npm publish/)
|
|
398
398
|
})
|
|
399
399
|
|
|
400
|
+
it('can display publish hints with custom npm client name', async function () {
|
|
401
|
+
const flush = mock({ bump: 'patch' })
|
|
402
|
+
await exec('--npmPublishHint "yarn publish"')
|
|
403
|
+
flush()
|
|
404
|
+
.stdout.join('')
|
|
405
|
+
.should.match(/yarn publish/)
|
|
406
|
+
})
|
|
407
|
+
|
|
400
408
|
it('does not display `npm publish` if the package is private', async function () {
|
|
401
409
|
writePackageJson('1.0.0', { private: true })
|
|
402
410
|
const flush = mock({ bump: 'patch' })
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* global describe it */
|
|
2
|
+
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
const stringifyPackage = require('../lib/stringify-package')
|
|
6
|
+
|
|
7
|
+
require('chai').should()
|
|
8
|
+
|
|
9
|
+
describe('stringifyPackage()', function () {
|
|
10
|
+
const dummy = { name: 'dummy' }
|
|
11
|
+
|
|
12
|
+
it('with no params uses \\n', function () {
|
|
13
|
+
stringifyPackage(dummy).should.match(/\n$/m)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('uses \\n', function () {
|
|
17
|
+
stringifyPackage(dummy, 2, '\n').should.match(/\n$/m)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('uses \\r\\n', function () {
|
|
21
|
+
stringifyPackage(dummy, 2, '\r\n').should.match(/\r\n$/m)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('with no params uses 2-space indent', function () {
|
|
25
|
+
stringifyPackage(dummy).should.match(/^ {2}"name": "dummy"/m)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('uses 2-space indent', function () {
|
|
29
|
+
stringifyPackage(dummy, 2, '\n').should.match(/^ {2}"name": "dummy"/m)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('uses 4-space indent', function () {
|
|
33
|
+
stringifyPackage(dummy, 4, '\n').should.match(/^ {4}"name": "dummy"/m)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('0 works', function () {
|
|
37
|
+
stringifyPackage(dummy, 0).split(/\r\n|\r|\n/).length.should.equal(2)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* global describe it */
|
|
2
|
+
|
|
3
|
+
const mockery = require('mockery')
|
|
4
|
+
const { promises: fsp } = require('fs')
|
|
5
|
+
require('chai').should()
|
|
6
|
+
|
|
7
|
+
function mockNpm () {
|
|
8
|
+
mockery.enable({ warnOnUnregistered: false, useCleanCache: true })
|
|
9
|
+
let lockFile = ''
|
|
10
|
+
|
|
11
|
+
const fsMock = {
|
|
12
|
+
promises: {
|
|
13
|
+
access: async function (path) {
|
|
14
|
+
if (lockFile && path.endsWith(lockFile)) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
await fsp.access(path)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
mockery.registerMock('fs', fsMock)
|
|
22
|
+
return {
|
|
23
|
+
setLockFile (file) {
|
|
24
|
+
lockFile = file
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('utils', () => {
|
|
30
|
+
it('detectPMByLockFile should work', async function () {
|
|
31
|
+
const { setLockFile } = mockNpm()
|
|
32
|
+
const { detectPMByLockFile } = require('../lib/detect-package-manager')
|
|
33
|
+
|
|
34
|
+
let pm = await detectPMByLockFile()
|
|
35
|
+
pm.should.equal('npm')
|
|
36
|
+
|
|
37
|
+
setLockFile('yarn.lock')
|
|
38
|
+
pm = await detectPMByLockFile()
|
|
39
|
+
pm.should.equal('yarn')
|
|
40
|
+
|
|
41
|
+
setLockFile('package-lock.json')
|
|
42
|
+
pm = await detectPMByLockFile()
|
|
43
|
+
pm.should.equal('npm')
|
|
44
|
+
|
|
45
|
+
setLockFile('pnpm-lock.yaml')
|
|
46
|
+
pm = await detectPMByLockFile()
|
|
47
|
+
pm.should.equal('pnpm')
|
|
48
|
+
|
|
49
|
+
mockery.deregisterAll()
|
|
50
|
+
mockery.disable()
|
|
51
|
+
})
|
|
52
|
+
})
|