From 2e71a3ec61f7a3b8fb91e1e41b4b0d13ec9af999 Mon Sep 17 00:00:00 2001 From: idkgene Date: Sun, 15 Dec 2024 05:20:22 +0300 Subject: [PATCH 1/2] Enhance upgrade messaging to include current version in output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated the upgrade function to include the current version in the upgrade message format. - Modified test assertions to reflect the new message format. Background & Motivation: The current output format lacks clarity in showing version changes. Adding a simple 'from → to' format improves visibility and developer experience when updating Astro packages. Before: @astrojs/tailwind can be updated to v5.1.3 After: @astrojs/tailwind can be updated v4.0.0 → v5.1.3 This change: - Makes the upgrade process "more transparent" - Simplifies version change tracking - Improves DX during updates See https://github.com/withastro/roadmap/discussions/1069 --- packages/upgrade/src/messages.ts | 7 +++++-- packages/upgrade/test/install.test.js | 18 +++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/upgrade/src/messages.ts b/packages/upgrade/src/messages.ts index 17548371c81a..a17f6062392d 100644 --- a/packages/upgrade/src/messages.ts +++ b/packages/upgrade/src/messages.ts @@ -109,14 +109,17 @@ export const info = async (prefix: string, text: string, version = '') => { ); } }; + export const upgrade = async (packageInfo: PackageInfo, text: string) => { - const { name, isMajor = false, targetVersion } = packageInfo; + const { name, isMajor = false, targetVersion, currentVersion } = packageInfo; const bg = isMajor ? (v: string) => color.bgYellow(color.black(` ${v} `)) : color.green; const style = isMajor ? color.yellow : color.green; const symbol = isMajor ? '▲' : '●'; + + const fromVersion = currentVersion.replace(/^\D+/, ''); const toVersion = targetVersion.replace(/^\D+/, ''); - const version = `v${toVersion}`; + const version = `v${fromVersion} → v${toVersion}`; const length = 12 + name.length + text.length + version.length; if (length > stdout.columns) { diff --git a/packages/upgrade/test/install.test.js b/packages/upgrade/test/install.test.js index 4ceaa81c841f..f1084c6fda89 100644 --- a/packages/upgrade/test/install.test.js +++ b/packages/upgrade/test/install.test.js @@ -39,7 +39,7 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('● astro can be updated to v1.0.1'), true); + assert.equal(fixture.hasMessage('● astro can be updated v1.0.0 → v1.0.1'), true); }); it('minor', async () => { @@ -54,7 +54,7 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('● astro can be updated to v1.2.0'), true); + assert.equal(fixture.hasMessage('● astro can be updated v1.0.0 → v1.2.0'), true); }); it('major (reject)', async () => { @@ -81,7 +81,7 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('▲ astro can be updated to v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ astro can be updated v1.0.0 → v2.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, 0); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), false); @@ -111,7 +111,7 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('▲ astro can be updated to v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ astro can be updated v1.0.0 → v2.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true); @@ -149,8 +149,8 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('▲ a can be updated to v2.0.0'), true); - assert.equal(fixture.hasMessage('▲ b can be updated to v7.0.0'), true); + assert.equal(fixture.hasMessage('▲ a can be updated v1.0.0 → v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ b can be updated v6.0.0 → v7.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); const [changelog, a, b] = fixture.messages().slice(-5); @@ -199,9 +199,9 @@ describe('install', () => { }; await install(context); assert.equal(fixture.hasMessage('◼ current is up to date on v1.0.0'), true); - assert.equal(fixture.hasMessage('● patch can be updated to v1.0.1'), true); - assert.equal(fixture.hasMessage('● minor can be updated to v1.2.0'), true); - assert.equal(fixture.hasMessage('▲ major can be updated to v3.0.0'), true); + assert.equal(fixture.hasMessage('● patch can be updated v1.0.0 → v1.0.1'), true); + assert.equal(fixture.hasMessage('● minor can be updated v1.0.0 → v1.2.0'), true); + assert.equal(fixture.hasMessage('▲ major can be updated v1.0.0 → v3.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true); From da9b3b2b5061e7b90133b1a4e8e96f25675cf115 Mon Sep 17 00:00:00 2001 From: idkgene Date: Sun, 15 Dec 2024 13:52:25 +0300 Subject: [PATCH 2/2] Simplifying upgrade message format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove 'to' particle from update messages - Adjusted spacing in version comparison output - Update tests to match the spacing Before: ▲ astro can be updated to v1.0.0 → v2.0.0 After: ▲ astro can be updated v1.0.0 → v2.0.0 --- packages/upgrade/src/actions/install.ts | 2 +- packages/upgrade/test/install.test.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/upgrade/src/actions/install.ts b/packages/upgrade/src/actions/install.ts index 6e593b976b25..ac62b1598613 100644 --- a/packages/upgrade/src/actions/install.ts +++ b/packages/upgrade/src/actions/install.ts @@ -48,7 +48,7 @@ export async function install( const majors: PackageInfo[] = []; for (const packageInfo of toInstall) { const word = ctx.dryRun ? 'can' : 'will'; - await upgrade(packageInfo, `${word} be updated to`); + await upgrade(packageInfo, `${word} be updated`); if (packageInfo.isMajor) { majors.push(packageInfo); } diff --git a/packages/upgrade/test/install.test.js b/packages/upgrade/test/install.test.js index f1084c6fda89..aace96eb93b9 100644 --- a/packages/upgrade/test/install.test.js +++ b/packages/upgrade/test/install.test.js @@ -81,7 +81,7 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('▲ astro can be updated v1.0.0 → v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ astro can be updated v1.0.0 → v2.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, 0); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), false); @@ -111,7 +111,7 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('▲ astro can be updated v1.0.0 → v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ astro can be updated v1.0.0 → v2.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true); @@ -149,8 +149,8 @@ describe('install', () => { ], }; await install(context); - assert.equal(fixture.hasMessage('▲ a can be updated v1.0.0 → v2.0.0'), true); - assert.equal(fixture.hasMessage('▲ b can be updated v6.0.0 → v7.0.0'), true); + assert.equal(fixture.hasMessage('▲ a can be updated v1.0.0 → v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ b can be updated v6.0.0 → v7.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); const [changelog, a, b] = fixture.messages().slice(-5); @@ -201,7 +201,7 @@ describe('install', () => { assert.equal(fixture.hasMessage('◼ current is up to date on v1.0.0'), true); assert.equal(fixture.hasMessage('● patch can be updated v1.0.0 → v1.0.1'), true); assert.equal(fixture.hasMessage('● minor can be updated v1.0.0 → v1.2.0'), true); - assert.equal(fixture.hasMessage('▲ major can be updated v1.0.0 → v3.0.0'), true); + assert.equal(fixture.hasMessage('▲ major can be updated v1.0.0 → v3.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true);