commit-and-tag-version 11.0.0 → 11.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
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.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.1.0...v11.2.0) (2023-03-15)
6
+
7
+
8
+ ### Features
9
+
10
+ * implement detect pm name ([174a8bd](https://github.com/absolute-version/commit-and-tag-version/commit/174a8bd00106dcc2a6b1c5bcb75bf3fbfd0317da))
11
+ * support config npmClient ([c33686a](https://github.com/absolute-version/commit-and-tag-version/commit/c33686aec080162645466ed962d64133f71e4214))
12
+ * Support customizing the npm publish hint message with a new option: `npmPublishHint` ([1f77110](https://github.com/absolute-version/commit-and-tag-version/commit/1f77110deefa8a394a37c421eb3d313f6c87aea5))
13
+
14
+ ## [11.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.0.0...v11.1.0) (2023-02-14)
15
+
16
+
17
+ ### Features
18
+
19
+ * Expose release count option ([40d27f8](https://github.com/absolute-version/commit-and-tag-version/commit/40d27f8782c0621f6ec0ab796b4ae674ec6d43c8))
20
+ * replace the changelog if releaseCount = 0 ([d18af90](https://github.com/absolute-version/commit-and-tag-version/commit/d18af9040fdc2a5798681fa747a43a71cb75e47b))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * ensure git signatures are not present ([268800b](https://github.com/absolute-version/commit-and-tag-version/commit/268800b3c5e01993902cb0df0d123ac8b3388359))
26
+
5
27
  ## [11.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v10.1.0...v11.0.0) (2023-01-17)
6
28
 
7
29
 
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
- _How It Works:_
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`.
@@ -343,6 +380,27 @@ If you've already run `commit-and-tag-version` when creating your release, you m
343
380
  the version, by using `commit-and-tag-version --skip.bump`. By default, tagging with an already existing tag make `git` fails.
344
381
  You can add the `--tag-force` flag to make use of `-f` option when calling `git tag`, then the existing version tag will be replaced.
345
382
 
383
+ ### Generate changelogs for old releases
384
+
385
+ Normally only the changelog for the last release will be generated and prepended to the `changelog.md`. If you want to generate changelogs for previous releases you can do so by setting the `releaseCount` option like described [here](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-core#releasecount).
386
+
387
+ When setting releaseCount=0 the whole changelog gets regenerated and replaced.
388
+
389
+ You can set the option either in the`.versionrc` file or inside `package.json` like below
390
+
391
+ ```json
392
+ //.versionrc
393
+ {
394
+ "releaseCount": 0
395
+ }
396
+
397
+ //package.json
398
+
399
+ "commit-and-tag-version": {
400
+ "releaseCount": 0
401
+ }
402
+ ```
403
+
346
404
  ### CLI Help
347
405
 
348
406
  ```sh
package/command.js CHANGED
@@ -73,6 +73,11 @@ const yargs = require('yargs')
73
73
  type: 'string',
74
74
  default: defaults.tagPrefix
75
75
  })
76
+ .option('release-count', {
77
+ describe: 'How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to 0 to regenerate all.',
78
+ type: 'number',
79
+ default: defaults.releaseCount
80
+ })
76
81
  .option('tag-force', {
77
82
  describe: 'Allow tag replacement',
78
83
  type: 'boolean',
@@ -116,6 +121,11 @@ const yargs = require('yargs')
116
121
  type: 'string',
117
122
  describe: 'Name of the package from which the tags will be extracted'
118
123
  })
124
+ .option('npmPublishHint', {
125
+ type: 'string',
126
+ default: defaults.npmPublishHint,
127
+ describe: 'Customized publishing hint'
128
+ })
119
129
  .check((argv) => {
120
130
  if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
121
131
  throw Error('scripts must be an object')
package/defaults.js CHANGED
@@ -8,12 +8,14 @@ const defaults = {
8
8
  commitAll: false,
9
9
  silent: false,
10
10
  tagPrefix: 'v',
11
+ releaseCount: 1,
11
12
  scripts: {},
12
13
  skip: {},
13
14
  dryRun: false,
14
15
  tagForce: false,
15
16
  gitTagFallback: true,
16
- preset: require.resolve('conventional-changelog-conventionalcommits')
17
+ preset: require.resolve('conventional-changelog-conventionalcommits'),
18
+ npmPublishHint: undefined
17
19
  }
18
20
 
19
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
+ }
@@ -23,7 +23,7 @@ function outputChangelog (args, newVersion) {
23
23
  createIfMissing(args)
24
24
  const header = args.header
25
25
 
26
- let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8')
26
+ let oldContent = args.dryRun || args.releaseCount === 0 ? '' : fs.readFileSync(args.infile, 'utf-8')
27
27
  const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
28
28
  // find the position of the last release and remove header:
29
29
  if (oldContentStart !== -1) {
@@ -34,8 +34,9 @@ function outputChangelog (args, newVersion) {
34
34
  const changelogStream = conventionalChangelog({
35
35
  debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
36
36
  preset: presetLoader(args),
37
- tagPrefix: args.tagPrefix
38
- }, context, { merges: null, path: args.path }, args.parserOpts, args.writerOpts)
37
+ tagPrefix: args.tagPrefix,
38
+ releaseCount: args.releaseCount
39
+ }, context, { merges: null, path: args.path, showSignature: false }, args.parserOpts, args.writerOpts)
39
40
  .on('error', function (err) {
40
41
  return reject(err)
41
42
  })
@@ -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
- message += ' && npm publish'
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'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "11.0.0",
3
+ "version": "11.2.0",
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"
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,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
+ })