From 13d49d9b453949fc10303af107b90ace8d5791d2 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Mon, 18 Nov 2024 07:34:28 -0800 Subject: [PATCH] comments, add other types --- src/changefile/changeTypes.ts | 12 +++++++++++- src/changefile/getQuestionsForPackage.ts | 19 ++++++++++++------- src/types/ChangeFilePrompt.ts | 11 ++++++----- src/types/ChangeInfo.ts | 3 ++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/changefile/changeTypes.ts b/src/changefile/changeTypes.ts index faa88ac65..06226650a 100644 --- a/src/changefile/changeTypes.ts +++ b/src/changefile/changeTypes.ts @@ -1,4 +1,4 @@ -import { ChangeSet, ChangeType } from '../types/ChangeInfo'; +import { ChangeSet, ChangeType, PrereleaseChangeType } from '../types/ChangeInfo'; /** * List of all change types from least to most significant. @@ -14,6 +14,16 @@ export const SortedChangeTypes: ChangeType[] = [ 'major', ]; +/** + * All the prerelease change types. + */ +export const PrereleaseChangeTypes: ChangeType[] = [ + 'prerelease', + 'prepatch', + 'preminor', + 'premajor', +] satisfies PrereleaseChangeType[]; + /** * Change type with the smallest weight. */ diff --git a/src/changefile/getQuestionsForPackage.ts b/src/changefile/getQuestionsForPackage.ts index 1aa542440..9337260e0 100644 --- a/src/changefile/getQuestionsForPackage.ts +++ b/src/changefile/getQuestionsForPackage.ts @@ -5,9 +5,14 @@ import { BeachballOptions } from '../types/BeachballOptions'; import { ChangeTypeDescriptions, DefaultPrompt } from '../types/ChangeFilePrompt'; import { getDisallowedChangeTypes } from './getDisallowedChangeTypes'; import { PackageGroups, PackageInfos } from '../types/PackageInfo'; +import { PrereleaseChangeTypes } from './changeTypes'; -const defaultChangeTypeDescriptions: ChangeTypeDescriptions = { +const defaultChangeTypeDescriptions: Required = { prerelease: 'bump prerelease version', + // TODO: these pre* types are included for completeness but currently won't be shown + prepatch: 'bump to prerelease of the next patch version', + preminor: 'bump to prerelease of the next minor version', + premajor: 'bump to prerelease of the next major version', patch: { general: 'bug fixes; no API changes', v0: 'bug fixes; new features; backwards-compatible API changes (ok in patches for version < 1)', @@ -21,7 +26,6 @@ const defaultChangeTypeDescriptions: ChangeTypeDescriptions = { general: 'breaking changes; major feature', v0: 'official release', }, - // TODO: add an option to show other pre* versions, and add their text }; /** @@ -70,10 +74,11 @@ function getChangeTypePrompt(params: { return; } - const omittedChangeTypes = [...disallowedChangeTypes]; - // if the current version doesn't include a prerelease part, omit the prerelease option - if (!semver.prerelease(packageInfo.version)) { - omittedChangeTypes.push('prerelease'); + // TODO: conditionally add other prerelease types later + const omittedChangeTypes = new Set([...disallowedChangeTypes, ...PrereleaseChangeTypes]); + // if the current version includes a prerelease part, show the prerelease option + if (semver.prerelease(packageInfo.version)) { + omittedChangeTypes.add('prerelease'); } const isVersion0 = semver.major(packageInfo.version) === 0; // this is used to determine padding length since it's the longest @@ -82,7 +87,7 @@ function getChangeTypePrompt(params: { const changeTypeChoices: prompts.Choice[] = Object.entries( packageInfo.combinedOptions.changeFilePrompt?.changeTypeDescriptions || defaultChangeTypeDescriptions ) - .filter(([changeType]) => !omittedChangeTypes.includes(changeType as ChangeType)) + .filter(([changeType]) => !omittedChangeTypes.has(changeType as ChangeType)) .map(([changeType, descriptions]): prompts.Choice => { const label = getChangeTypeLabel(changeType); // use the appropriate message for 0.x or >= 1.x (if different) diff --git a/src/types/ChangeFilePrompt.ts b/src/types/ChangeFilePrompt.ts index 5ab0b4131..3cd776058 100644 --- a/src/types/ChangeFilePrompt.ts +++ b/src/types/ChangeFilePrompt.ts @@ -25,13 +25,14 @@ export type ChangeTypeDescriptions = { /** * Options for customizing change file prompt. - * The package name is provided so that the prompt can be customized by package if desired. */ export interface ChangeFilePromptOptions { /** - * Get custom change file prompt questions. - * The questions MUST result in an answers object `{ comment: string; type: ChangeType }`. - * If you just want to customize the descriptions of each change type, use `changeTypeDescriptions`. + * Get custom change file prompt questions. The questions MUST result in an answers object + * `{ comment: string; type: ChangeType }`, though any extra properties returned will be preserved. + * + * (If you just want to customize the descriptions of each change type, use `changeTypeDescriptions`.) + * * @param defaultPrompt Default prompt questions * @param pkg Package name, so that changelog customizations can be specified at the package level */ @@ -39,7 +40,7 @@ export interface ChangeFilePromptOptions { /** * Custom descriptions for each change type. This is good for if you only want to customize the - * descriptions, not the whole prompt. + * descriptions, not the whole prompt. (Any types not included here will use the defaults.) * * Each description can either be a single string, or one string for 0.x versions (which follow * different semver rules) and one string for general use with versions >= 1. diff --git a/src/types/ChangeInfo.ts b/src/types/ChangeInfo.ts index b0e007d93..aa94029ad 100644 --- a/src/types/ChangeInfo.ts +++ b/src/types/ChangeInfo.ts @@ -1,4 +1,5 @@ -export type ChangeType = 'prerelease' | 'prepatch' | 'patch' | 'preminor' | 'minor' | 'premajor' | 'major' | 'none'; +export type PrereleaseChangeType = 'prerelease' | 'prepatch' | 'preminor' | 'premajor'; +export type ChangeType = PrereleaseChangeType | 'patch' | 'minor' | 'major' | 'none'; /** * Info saved in each change file.