commit-and-tag-version 11.1.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,15 @@
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
+
5
14
  ## [11.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.0.0...v11.1.0) (2023-02-14)
6
15
 
7
16
 
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`.
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
+ }
@@ -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.1.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
+ })