From 99cf75e4fb6df5b6c7c03d2e6857358147f30281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJamesHenry=E2=80=9D?= Date: Mon, 29 Jul 2024 13:31:39 +0400 Subject: [PATCH] fix(release): ensure @org/package style names are wrapped in quotes in plan files --- packages/nx/src/command-line/release/plan.ts | 18 ++--------- .../generate-version-plan-content.spec.ts | 32 +++++++++++++++++++ .../utils/generate-version-plan-content.ts | 21 ++++++++++++ 3 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 packages/nx/src/command-line/release/utils/generate-version-plan-content.spec.ts create mode 100644 packages/nx/src/command-line/release/utils/generate-version-plan-content.ts diff --git a/packages/nx/src/command-line/release/plan.ts b/packages/nx/src/command-line/release/plan.ts index d7b489790d0f8..b8dc176fa38ca 100644 --- a/packages/nx/src/command-line/release/plan.ts +++ b/packages/nx/src/command-line/release/plan.ts @@ -15,6 +15,7 @@ import { } from './config/config'; import { filterReleaseGroups } from './config/filter-release-groups'; import { getVersionPlansAbsolutePath } from './config/version-plans'; +import { generateVersionPlanContent } from './utils/generate-version-plan-content'; import { parseConventionalCommitsMessage } from './utils/git'; import { printDiff } from './utils/print-changes'; @@ -136,7 +137,7 @@ export async function releasePlan(args: PlanOptions): Promise { } const versionPlanMessage = args.message || (await promptForMessage()); - const versionPlanFileContent = getVersionPlanFileContent( + const versionPlanFileContent = generateVersionPlanContent( versionPlanBumps, versionPlanMessage ); @@ -229,18 +230,3 @@ async function _promptForMessage(): Promise { process.exit(0); } } - -function getVersionPlanFileContent( - bumps: Record, - message: string -): string { - return `--- -${Object.entries(bumps) - .filter(([_, version]) => version !== 'none') - .map(([projectOrGroup, version]) => `${projectOrGroup}: ${version}`) - .join('\n')} ---- - -${message} -`; -} diff --git a/packages/nx/src/command-line/release/utils/generate-version-plan-content.spec.ts b/packages/nx/src/command-line/release/utils/generate-version-plan-content.spec.ts new file mode 100644 index 0000000000000..51d3b9b488544 --- /dev/null +++ b/packages/nx/src/command-line/release/utils/generate-version-plan-content.spec.ts @@ -0,0 +1,32 @@ +import { generateVersionPlanContent } from './generate-version-plan-content'; + +describe('generateVersionPlanContent()', () => { + it('should generate the version plan content', () => { + expect(generateVersionPlanContent({ proj: '1.0.0' }, 'message')) + .toMatchInlineSnapshot(` + "--- + proj: 1.0.0 + --- + + message + " + `); + }); + + it('should wrap project keys in quotes if they start with an @ symbol', () => { + expect( + generateVersionPlanContent( + { '@proj/foo': '1.0.0', 'a-b-c': '2.3.4' }, + 'message' + ) + ).toMatchInlineSnapshot(` + "--- + '@proj/foo': 1.0.0 + a-b-c: 2.3.4 + --- + + message + " + `); + }); +}); diff --git a/packages/nx/src/command-line/release/utils/generate-version-plan-content.ts b/packages/nx/src/command-line/release/utils/generate-version-plan-content.ts new file mode 100644 index 0000000000000..da3b9949b8c6e --- /dev/null +++ b/packages/nx/src/command-line/release/utils/generate-version-plan-content.ts @@ -0,0 +1,21 @@ +export function generateVersionPlanContent( + bumps: Record, + message: string +): string { + return `--- +${Object.entries(bumps) + .filter(([_, version]) => version !== 'none') + .map(([projectOrGroup, version]) => { + let key = projectOrGroup; + // frontmatter parsing will blow up if we don't wrap @org/package style project names in quotes + if (key.startsWith('@')) { + key = `'${key}'`; + } + return `${key}: ${version}`; + }) + .join('\n')} +--- + +${message} +`; +}