conventional-changelog/conventional-changelog

Question: with `conventional-changelog-recommended-bump` v10 how do I provide a custom preset?

Closed this issue · 3 comments

favna commented

Hi there,

Before with v9 of the library it was possible to provide a custom template through options like seen here: https://github.com/favware/cliff-jumper/blob/ab8d611813a18efedfdba0df07ccfb98005fbaa3/src/commands/get-conventional-bump.ts#L18-L112. However with v10 all these options are gone and only loadPreset is left. How can I ensure that my library can still use the custom preset with v10?

For the most part my custom preset is the same as the angular preset, with the exception that I have provided a breakingHeaderPattern to config.parserOpts so I would also accept a way to use the Angular preset but override that option only.

That said, assuming that would be through classInstanceOfBumper.getPreset / .preset, those are completely untyped in the published bundle of the package so that doesn't help much either
bumper.d.ts:

export declare class Bumper {
    private readonly gitClient;
    private preset;
    private whatBump;
    private tagGetter;
    private commitsGetter;
    constructor(cwdOrGitClient?: string | ConventionalGitClient);
    private getLastSemverTag;
    private getCommits;
    private getPreset;

@favna Hi.

new Bumper().commits({}, parserOpts).bump(whatBump)
favna commented

@dangreen And what happened to the lernaPackage

lernaTags: !!options.lernaPackage,
package: options.lernaPackage,
options that were in bump before?

@favna

Sorry for blind spots in documentation, I will fix that.

new Bumper()
  .commits({
    path: '...'
  }, parserOpts)
  .tag({
    prefix: packagePrefix(lernaPackage)
  })
  .bump(whatBump)

bumper.commits(params: GetCommitsParams & Params, parserOptions?: ParserStreamOptions): this

export interface GitLogParams {
/**
* Read commits from specific path.
*/
path?: string | string[]
/**
* Start commits range.
*/
from?: string
/**
* End commits range.
*/
to?: string
/**
* Commits format.
*/
format?: string
/**
* Pattern to filter commits.
*/
ignore?: RegExp
}
export interface GetCommitsParams extends GitLogParams {
/**
* Enable revert commits filter.
*/
filterReverts?: boolean
}

bumper.tag(paramsOrTag: GetSemverTagsParams & Params | string): this

export interface GetSemverTagsParams {
/**
* Get semver tags with specific prefix.
*/
prefix?: string | RegExp
/**
* Skip semver tags with unstable versions.
*/
skipUnstable?: boolean
/**
* Clean version from prefix and trash.
*/
clean?: boolean
}

/**
* Helper to get package tag prefix.
* @param packageName
* @returns Tag prefix.
*/
export function packagePrefix(packageName?: string) {
if (!packageName) {
return /^.+@/
}
return `${packageName}@`
}