Skip to content

Commit

Permalink
fix(release): ensure @org/package style names are wrapped in quotes i…
Browse files Browse the repository at this point in the history
…n plan files
  • Loading branch information
JamesHenry committed Jul 29, 2024
1 parent 132ce96 commit 99cf75e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
18 changes: 2 additions & 16 deletions packages/nx/src/command-line/release/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -136,7 +137,7 @@ export async function releasePlan(args: PlanOptions): Promise<string | number> {
}

const versionPlanMessage = args.message || (await promptForMessage());
const versionPlanFileContent = getVersionPlanFileContent(
const versionPlanFileContent = generateVersionPlanContent(
versionPlanBumps,
versionPlanMessage
);
Expand Down Expand Up @@ -229,18 +230,3 @@ async function _promptForMessage(): Promise<string> {
process.exit(0);
}
}

function getVersionPlanFileContent(
bumps: Record<string, string>,
message: string
): string {
return `---
${Object.entries(bumps)
.filter(([_, version]) => version !== 'none')
.map(([projectOrGroup, version]) => `${projectOrGroup}: ${version}`)
.join('\n')}
---
${message}
`;
}
Original file line number Diff line number Diff line change
@@ -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
"
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function generateVersionPlanContent(
bumps: Record<string, string>,
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}
`;
}

0 comments on commit 99cf75e

Please sign in to comment.