From f4627ecf4eaa147f00710beecbc8e926235caca1 Mon Sep 17 00:00:00 2001 From: Austin Fahsl Date: Wed, 20 Sep 2023 21:07:20 -0600 Subject: [PATCH] fix(release): handle case of invalid specifierSource with convent commit --- packages/nx/src/command-line/release/version.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index 71d23d9555a2b6..170db93b900efe 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -378,9 +378,19 @@ async function resolveSemverSpecifier( switch (specifierSource) { case 'conventional-commits': - const generatorOptions: { tagVersionPrefix?: string } | undefined = - releaseGroup.version.generatorOptions.currentVersionResolverMetadata; - const tagVersionPrefix = generatorOptions?.tagVersionPrefix || 'v'; + const generatorOptions = releaseGroup.version.generatorOptions; + + if (generatorOptions?.currentVersionResolver !== 'git-tag') { + throw new Error( + `Invalid currentVersionResolver "${generatorOptions?.currentVersionResolver}" provided. Must be "git-tag" when "specifierSource" is "conventional-commits"` + ); + } + + const currentVersionResolverMetadata: + | { tagVersionPrefix?: string } + | undefined = generatorOptions?.currentVersionResolverMetadata; + const tagVersionPrefix = + currentVersionResolverMetadata?.tagVersionPrefix ?? 'v'; const currentVersionTag = await getLastGitTag(`${tagVersionPrefix}*.*.*`); const currentVersion = currentVersionTag.replace(tagVersionPrefix, '');