Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(release): normalize changelog line wrapping when formatting entries (#3571)

Cindy Zhang10f7797d0380
diff --git a/scripts/format-changelogs.mjs b/scripts/format-changelogs.mjs
index 88bd8da2bb..2bbf7dd095 100755
--- a/scripts/format-changelogs.mjs
+++ b/scripts/format-changelogs.mjs
@@ -100,6 +100,65 @@ function splitBullets(body) {
return bullets;
}
+// Reflow a bullet's continuation body into consistent line wrapping.
+//
+// Changeset authors wrap prose inconsistently — some write one long line, some
+// hard-wrap mid-sentence at ~75 chars. Since the release notes are compiled
+// verbatim from these entries, that inconsistency shows up in the published
+// changelog. This collapses each soft-wrapped prose paragraph into a single
+// line (Markdown reflows visually), indents continuation content two spaces so
+// it stays inside the list item, and leaves structural content untouched:
+// blank lines (paragraph breaks), fenced code blocks, and sub-bullets.
+function reflowBulletBody(rest) {
+ if (!rest) return '';
+ const lines = rest.split('\n');
+ const out = [];
+ let para = [];
+ let inFence = false;
+
+ const flush = () => {
+ if (para.length) {
+ out.push(' ' + para.join(' '));
+ para = [];
+ }
+ };
+
+ for (const raw of lines) {
+ const line = raw.replace(/\s+$/, '');
+ const trimmed = line.trim();
+
+ if (/^```/.test(trimmed)) {
+ flush();
+ out.push(' ' + trimmed);
+ inFence = !inFence;
+ continue;
+ }
+ if (inFence) {
+ // Preserve code verbatim, but keep it inside the list item.
+ out.push(' ' + line.replace(/^ {0,2}/, ''));
+ continue;
+ }
+ if (trimmed === '') {
+ flush();
+ out.push('');
+ continue;
+ }
+ // Sub-bullets keep their own line; flush preceding prose first.
+ if (/^[-*]\s+/.test(trimmed)) {
+ flush();
+ out.push(' ' + trimmed);
+ continue;
+ }
+ para.push(trimmed);
+ }
+ flush();
+
+ return out
+ .join('\n')
+ .replace(/\n{3,}/g, '\n\n')
+ .replace(/\n+$/, '');
+}
+
// Parse one rendered bullet: "- [cat] headline — thanks @a, @b"
function parseBullet(bullet) {
const firstNl = bullet.indexOf('\n');
@@ -123,7 +182,7 @@ function parseBullet(bullet) {
})
.trim();
- return {category, text, contributors, extra: rest.trimEnd()};
+ return {category, text, contributors, extra: reflowBulletBody(rest)};
}
function formatVersionBlock(version, body) {
@@ -254,4 +313,9 @@ function main() {
else console.log('✓ no CHANGELOGs needed formatting');
}
-main();
+// Run as a script, but stay importable for unit tests.
+if (process.argv[1] === fileURLToPath(import.meta.url)) {
+ main();
+}
+
+export {reflowBulletBody, formatVersionBlock};
diff --git a/scripts/format-changelogs.test.mjs b/scripts/format-changelogs.test.mjs
new file mode 100644
index 0000000000..6ae39dc4eb
--- /dev/null
+++ b/scripts/format-changelogs.test.mjs
@@ -0,0 +1,101 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file format-changelogs.test.mjs
+ * Unit tests for the changelog line-wrapping normalizer.
+ *
+ * Guards the behavior that keeps published changelog prose consistently
+ * wrapped regardless of how each changeset author wrote their entry.
+ */
+
+import {describe, it, expect} from 'vitest';
+import {reflowBulletBody, formatVersionBlock} from './format-changelogs.mjs';
+
+describe('reflowBulletBody', () => {
+ it('collapses a hard-wrapped prose paragraph into a single indented line', () => {
+ const input = [
+ ' The label and optionalRequired styles never set an explicit lineHeight,',
+ ' so both fell back to line-height normal, producing mismatched boxes.',
+ ].join('\n');
+ expect(reflowBulletBody(input)).toBe(
+ ' The label and optionalRequired styles never set an explicit lineHeight, so both fell back to line-height normal, producing mismatched boxes.',
+ );
+ });
+
+ it('leaves an already single-line paragraph unchanged (aside from indent)', () => {
+ expect(reflowBulletBody(' One flowing line already.')).toBe(
+ ' One flowing line already.',
+ );
+ });
+
+ it('preserves paragraph breaks (blank lines)', () => {
+ const input = [' First paragraph', ' wrapped.', '', ' Second one.'].join(
+ '\n',
+ );
+ expect(reflowBulletBody(input)).toBe(
+ [' First paragraph wrapped.', '', ' Second one.'].join('\n'),
+ );
+ });
+
+ it('keeps sub-bullets on their own lines', () => {
+ const input = [
+ ' Intro sentence',
+ ' continues here.',
+ ' - first item',
+ ' - second item',
+ ].join('\n');
+ expect(reflowBulletBody(input)).toBe(
+ [
+ ' Intro sentence continues here.',
+ ' - first item',
+ ' - second item',
+ ].join('\n'),
+ );
+ });
+
+ it('preserves fenced code blocks verbatim', () => {
+ const input = [
+ ' Run this:',
+ ' ```sh',
+ ' npx astryx upgrade --apply',
+ ' ```',
+ ].join('\n');
+ expect(reflowBulletBody(input)).toBe(
+ [' Run this:', ' ```sh', ' npx astryx upgrade --apply', ' ```'].join(
+ '\n',
+ ),
+ );
+ });
+
+ it('returns empty string for empty input', () => {
+ expect(reflowBulletBody('')).toBe('');
+ });
+
+ it('is idempotent', () => {
+ const input = [' A wrapped', ' paragraph.', '', ' - a bullet'].join(
+ '\n',
+ );
+ const once = reflowBulletBody(input);
+ expect(reflowBulletBody(once)).toBe(once);
+ });
+});
+
+describe('formatVersionBlock line-wrapping', () => {
+ it('normalizes wrapping across entries so hard-wrapped and single-line prose match', () => {
+ const body = [
+ '### Patch Changes',
+ '',
+ '- [fix] FieldLabel vertical align. — thanks @athz',
+ ' The label styles never set an explicit lineHeight,',
+ ' so both fell back to line-height normal.',
+ '- [fix] A single flowing line the author wrote on one line (#3466) — thanks @arham766',
+ ].join('\n');
+ const out = formatVersionBlock('0.9.9', body);
+ expect(out).toContain(
+ '- FieldLabel vertical align.\n The label styles never set an explicit lineHeight, so both fell back to line-height normal.',
+ );
+ expect(out).toContain(
+ '- A single flowing line the author wrote on one line (#3466)',
+ );
+ });
+});