From 1f9571b2b9839a5513fe2c03a90ff36235e8efe2 Mon Sep 17 00:00:00 2001 From: enu <135520429+gnify@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:03:32 +0300 Subject: [PATCH] Version transitions in CLI outputs (#12739) Co-authored-by: Florian Lefebvre --- .changeset/happy-radios-drive.md | 5 +++++ packages/upgrade/src/actions/install.ts | 2 +- packages/upgrade/src/messages.ts | 7 +++++-- packages/upgrade/test/install.test.js | 18 +++++++++--------- 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .changeset/happy-radios-drive.md diff --git a/.changeset/happy-radios-drive.md b/.changeset/happy-radios-drive.md new file mode 100644 index 0000000000..a8dde10c52 --- /dev/null +++ b/.changeset/happy-radios-drive.md @@ -0,0 +1,5 @@ +--- +'@astrojs/upgrade': patch +--- + +Updates displayed data to show both source and target versions diff --git a/packages/upgrade/src/actions/install.ts b/packages/upgrade/src/actions/install.ts index 6e593b976b..ac62b15986 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/src/messages.ts b/packages/upgrade/src/messages.ts index 17548371c8..032faa1ac9 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 = `from v${fromVersion} to 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 4ceaa81c84..c4d56dfbe5 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 from v1.0.0 to 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 from v1.0.0 to 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 from v1.0.0 to 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 from v1.0.0 to 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 from v1.0.0 to v2.0.0'), true); + assert.equal(fixture.hasMessage('▲ b can be updated from v6.0.0 to 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 from v1.0.0 to v1.0.1'), true); + assert.equal(fixture.hasMessage('● minor can be updated from v1.0.0 to v1.2.0'), true); + assert.equal(fixture.hasMessage('▲ major can be updated from v1.0.0 to v3.0.0'), true); assert.equal(prompted, true); assert.equal(exitCode, undefined); assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true);