Custom `preset` configuration options not respected for `conventionalcommits` loader
Hi @jscutlery team !
Thanks a lot for the awesome library !
I believe I've encountered a bug with how the conventionalcommits preset consumes its custom config upstream.
Namely, let's say you have the following project.json configuration in your project:
{
// other config
"name": "@some-namespace/some-project-name",
"targets": {
"version": {
"executor": "@jscutlery/semver:version",
"options": {
"dryRun": false,
"baseBranch": "main",
"preset": {
"name": "conventionalcommits",
"preMajor": true,
"types": [
// types config here, not important
]
},
"push": true,
"postTargets": [
"post-target1",
"post-target2",
"post-target3",
]
}
},
}
}
Despite preMajor being set to true (and @some-namespace/some-project-name's version being <1.0.0) semantic versioning for conventional commits will not be respected and versioning would be done as if preMajor were false (so, feat commits will bump minor, BREAKING CHANGE ones will bump major etc).
The reason behind this stems from one of the dependencies being used, specifically pointing to this line here. The version of conventional-recommended-bump is ^9.0.0 rather than the latest one and this one contains a bug which fails to pass the config from here properly.
The reference to the conventionalRecommendedBump function in v9.0.0 is this one, while the offending line is this one. Since options.preset is always going to be there regardless (and will match options.config.name), that means that we'll always load the preset by its name hence always loading the default one (and ignoring any customization that's been set). Now, since the preset loader (from the same ref) is able to gracefully load an object as well, the following patch indeed fixes the issue and once again respects the preset customizations we've set:
diff --git a/node_modules/conventional-recommended-bump/index.js b/node_modules/conventional-recommended-bump/index.js
index d71b897..4725802 100644
--- a/node_modules/conventional-recommended-bump/index.js
+++ b/node_modules/conventional-recommended-bump/index.js
@@ -21,7 +21,11 @@ async function conventionalRecommendedBump (optionsArgument, parserOptsArgument)
let config = options.config || {}
if (options.preset) {
- config = await loadPreset(options.preset)
+ if (config) {
+ config = await loadPreset(config)
+ } else {
+ config = await loadPreset(options.preset)
+ }
}
const whatBump = options.whatBump ||
Even though this is not specifically an issue with your library, looking at the newer versions I believe that conventional-recommended-bump have since fixed their issue in the latest versions and so those ones should probably be used.
I of course tried doing something like:
"resolutions": {
"conventional-recommended-bump": "11.2.0"
}
however it wasn't that simple and probably requires a couple of other parts of the code changed to work. Or, at the very least if upgrading is cumbersome I think that the patch should be good enough for the time being.
Thanks a bunch in advance !