From 786537efa8b4ec073359ce8aa9f1a9010c72e2a6 Mon Sep 17 00:00:00 2001 From: Austin Fahsl Date: Tue, 17 Sep 2024 04:19:33 -0600 Subject: [PATCH] fix(release): allow string array for commitArgs and tagArgs (#27797) --- packages/nx/schemas/nx-schema.json | 4 ++-- .../src/command-line/release/command-object.ts | 4 ++-- .../nx/src/command-line/release/utils/git.ts | 16 ++++++++++++---- .../nx/src/command-line/release/utils/shared.ts | 2 +- packages/nx/src/config/nx-json.ts | 8 ++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index 23998fc4d10fe..6860662ef0686 100644 --- a/packages/nx/schemas/nx-schema.json +++ b/packages/nx/schemas/nx-schema.json @@ -634,7 +634,7 @@ "description": "Custom git commit message to use when committing the changes made by this command" }, "commitArgs": { - "type": "string", + "type": ["string", "array"], "description": "Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes" }, "stageChanges": { @@ -650,7 +650,7 @@ "description": "Custom git tag message to use when tagging the changes made by this command. This defaults to be the same value as the tag itself." }, "tagArgs": { - "type": "string", + "type": ["string", "array"], "description": "Additional arguments to pass to the `git tag` command invoked behind the scenes" } } diff --git a/packages/nx/src/command-line/release/command-object.ts b/packages/nx/src/command-line/release/command-object.ts index f58774ad4f051..a9f048710db07 100644 --- a/packages/nx/src/command-line/release/command-object.ts +++ b/packages/nx/src/command-line/release/command-object.ts @@ -30,10 +30,10 @@ interface GitCommitAndTagOptions { stageChanges?: boolean; gitCommit?: boolean; gitCommitMessage?: string; - gitCommitArgs?: string; + gitCommitArgs?: string | string[]; gitTag?: boolean; gitTagMessage?: string; - gitTagArgs?: string; + gitTagArgs?: string | string[]; } export type VersionOptions = NxReleaseArgs & diff --git a/packages/nx/src/command-line/release/utils/git.ts b/packages/nx/src/command-line/release/utils/git.ts index 1cddb27dc67ff..1ce8acf7e184e 100644 --- a/packages/nx/src/command-line/release/utils/git.ts +++ b/packages/nx/src/command-line/release/utils/git.ts @@ -251,7 +251,7 @@ export async function gitCommit({ logFn, }: { messages: string[]; - additionalArgs?: string; + additionalArgs?: string | string[]; dryRun?: boolean; verbose?: boolean; logFn?: (message: string) => void; @@ -263,7 +263,11 @@ export async function gitCommit({ commandArgs.push('--message', message); } if (additionalArgs) { - commandArgs.push(...additionalArgs.split(' ')); + if (Array.isArray(additionalArgs)) { + commandArgs.push(...additionalArgs); + } else { + commandArgs.push(...additionalArgs.split(' ')); + } } if (verbose) { @@ -305,7 +309,7 @@ export async function gitTag({ }: { tag: string; message?: string; - additionalArgs?: string; + additionalArgs?: string | string[]; dryRun?: boolean; verbose?: boolean; logFn?: (message: string) => void; @@ -321,7 +325,11 @@ export async function gitTag({ message || tag, ]; if (additionalArgs) { - commandArgs.push(...additionalArgs.split(' ')); + if (Array.isArray(additionalArgs)) { + commandArgs.push(...additionalArgs); + } else { + commandArgs.push(...additionalArgs.split(' ')); + } } if (verbose) { diff --git a/packages/nx/src/command-line/release/utils/shared.ts b/packages/nx/src/command-line/release/utils/shared.ts index f83327862072a..1eb598482cc79 100644 --- a/packages/nx/src/command-line/release/utils/shared.ts +++ b/packages/nx/src/command-line/release/utils/shared.ts @@ -88,7 +88,7 @@ export async function commitChanges({ isDryRun?: boolean; isVerbose?: boolean; gitCommitMessages?: string[]; - gitCommitArgs?: string; + gitCommitArgs?: string | string[]; }) { if (!changedFiles?.length && !deletedFiles?.length) { throw new Error('Error: No changed files to commit'); diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index d91140661c33f..7aa0a244a16a1 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -123,9 +123,9 @@ export interface NxReleaseGitConfiguration { */ commitMessage?: string; /** - * Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes + * Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes. May be a string or array of strings. */ - commitArgs?: string; + commitArgs?: string | string[]; /** * Whether or not to stage the changes made by this command. Always treated as true if commit is true. */ @@ -139,9 +139,9 @@ export interface NxReleaseGitConfiguration { */ tagMessage?: string; /** - * Additional arguments to pass to the `git tag` command invoked behind the scenes + * Additional arguments to pass to the `git tag` command invoked behind the scenes. . May be a string or array of strings. */ - tagArgs?: string; + tagArgs?: string | string[]; } export interface NxReleaseConventionalCommitsConfiguration {