Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(release): ensure @org/package style names are wrapped in quotes in version plans #27177

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
`;
}