Skip to content

Commit e2973e2

Browse files
committed
feat(conventional-changelog-conventionalcommits): scope, scopeOnly and bumpStrict options were added
1 parent 521912a commit e2973e2

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

packages/conventional-changelog-conventionalcommits/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,13 @@ or json config like that:
7878
This last json config way passes the `preset` object to the `conventional-changelog-preset-loader` package, that in turn, passes this same `preset` object as the config for the `conventional-changelog-conventionalcommits`.
7979

8080
See [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec) for available configuration options.
81+
82+
## Specific Options
83+
84+
| Option | Description |
85+
|--------|-------------|
86+
| ignoreCommits | Ignore commits that match the provided regex. |
87+
| types | An array of types to include in the changelog. Default value can be accessed from `DEFAULT_COMMIT_TYPES` export. |
88+
| bumpStrict | If set to `true`, the version will be bumped only if there are breaking changes or if the commit type is in the `types` array. Default value is `false`. |
89+
| scope | Scope name to filter commits. By default, commits without scope are included. |
90+
| scopeOnly | If set to `true`, only commits with the specified scope will be included. Default value is `false`. |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function matchScope(config = {}, commit) {
2+
const {
3+
scope: targetScope,
4+
scopeOnly = false
5+
} = config
6+
const includesScope = commit.scope?.split(',').includes(targetScope)
7+
8+
return !targetScope
9+
|| (scopeOnly && includesScope)
10+
|| (!scopeOnly && (!commit.scope || includesScope))
11+
}

packages/conventional-changelog-conventionalcommits/src/whatBump.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
1-
export function createWhatBump(config) {
1+
import { DEFAULT_COMMIT_TYPES } from './constants.js'
2+
import { matchScope } from './utils.js'
3+
4+
export function createWhatBump(config = {}) {
5+
const {
6+
types = DEFAULT_COMMIT_TYPES,
7+
bumpStrict = false
8+
} = config
9+
const hiddenTypes = bumpStrict && types.reduce((hiddenTypes, type) => {
10+
if (type.hidden) {
11+
hiddenTypes.push(type.type)
12+
}
13+
14+
return hiddenTypes
15+
}, [])
16+
217
return function whatBump(commits) {
318
let level = 2
419
let breakings = 0
520
let features = 0
21+
let bugfixes = 0
622

723
commits.forEach((commit) => {
24+
if (!matchScope(config, commit)) {
25+
return
26+
}
27+
828
if (commit.notes.length > 0) {
929
breakings += commit.notes.length
1030
level = 0
11-
} else if (commit.type === 'feat' || commit.type === 'feature') {
12-
features += 1
31+
} else
32+
if (commit.type === 'feat' || commit.type === 'feature') {
33+
features += 1
1334

14-
if (level === 2) {
15-
level = 1
16-
}
17-
}
35+
if (level === 2) {
36+
level = 1
37+
}
38+
} else
39+
if (bumpStrict && !hiddenTypes.includes(commit.type)) {
40+
bugfixes += 1
41+
}
1842
})
1943

2044
if (config?.preMajor && level < 2) {
2145
level++
22-
}
46+
} else
47+
if (bumpStrict && level === 2 && !breakings && !features && !bugfixes) {
48+
return null
49+
}
2350

2451
return {
2552
level,

packages/conventional-changelog-conventionalcommits/src/writer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { resolve } from 'path'
33
import { fileURLToPath } from 'url'
44
import compareFunc from 'compare-func'
55
import { DEFAULT_COMMIT_TYPES } from './constants.js'
6+
import { matchScope } from './utils.js'
67

78
const dirname = fileURLToPath(new URL('.', import.meta.url))
89
const COMMIT_HASH_LENGTH = 7
@@ -90,16 +91,18 @@ function getWriterOpts(config) {
9091
}
9192
})
9293

93-
// breaking changes attached to any type are still displayed.
94-
if (discard && (entry === undefined
95-
|| entry.hidden)) {
94+
if (
95+
// breaking changes attached to any type are still displayed.
96+
discard && (entry === undefined || entry.hidden)
97+
|| !matchScope(config, commit)
98+
) {
9699
return undefined
97100
}
98101

99102
const type = entry
100103
? entry.section
101104
: commit.type
102-
const scope = commit.scope === '*'
105+
const scope = commit.scope === '*' || config.scope
103106
? ''
104107
: commit.scope
105108
const shortHash = typeof commit.hash === 'string'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy