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

Version transitions in CLI outputs #12739

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/upgrade/src/actions/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions packages/upgrade/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions packages/upgrade/test/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading