-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't merge array properties with custom opts (#616)
With a custom "headerCorrespondence" of two entries, commit message subjects couldn't be parsed due to merge with the default (Angular). For example, the following custom parser opts (ESLint style) wouldn't work because "headerCorrespondence" is `['type', 'subject', 'subject']` after the merge. ```js { headerPattern: /^(.*):\s(.*)$/, headerCorrespondence: ['type', 'subject'], } ``` Fixes #594
- Loading branch information
Showing
2 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import {sync} from 'conventional-commits-parser'; | ||
import defaultChangelogOpts from 'conventional-changelog-angular'; | ||
import {merge} from 'lodash'; | ||
import {isArray, mergeWith} from 'lodash'; | ||
|
||
export default parse; | ||
|
||
async function parse(message, parser = sync, parserOpts = undefined) { | ||
const defaultOpts = (await defaultChangelogOpts).parserOpts; | ||
const parsed = parser(message, merge({}, defaultOpts, parserOpts)); | ||
const parsed = parser( | ||
message, | ||
mergeWith({}, defaultOpts, parserOpts, (objValue, srcValue) => { | ||
if (isArray(objValue)) return srcValue; | ||
}) | ||
); | ||
parsed.raw = message; | ||
return parsed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters