Skip to content

Commit a986e21

Browse files
authored
Merge pull request #642 from twilio/FLEXY-3666
FLEXY-3666 Update information for upgrade plugin command
2 parents ec3c06d + f9947da commit a986e21

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

packages/plugin-flex/src/__tests__/commands/flex/plugins/upgrade-plugin.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,32 @@ describe('Commands/FlexPluginsStart', () => {
320320
expect(cmd.removeLegacyPlugin).toHaveBeenCalledTimes(1);
321321
});
322322

323+
it('should call upgrade notification', async () => {
324+
const cmd = await createTest(FlexPluginsUpgradePlugin)('--yes');
325+
mockForDoRun(cmd);
326+
// @ts-ignore
327+
const upgradeNotification = jest.spyOn(cmd.prints, 'upgradeNotification');
328+
jest.spyOn(cmd, 'pkgVersion', 'get').mockReturnValue(4);
329+
330+
await cmd.doRun();
331+
332+
expect(upgradeNotification).toHaveBeenCalledTimes(1);
333+
expect(upgradeNotification).toHaveBeenCalledWith(true, '4.0.0');
334+
});
335+
336+
it('should call upgrade notification without yes flag', async () => {
337+
const cmd = await createTest(FlexPluginsUpgradePlugin)();
338+
mockForDoRun(cmd);
339+
// @ts-ignore
340+
const upgradeNotification = jest.spyOn(cmd.prints, 'upgradeNotification');
341+
jest.spyOn(cmd, 'pkgVersion', 'get').mockReturnValue(4);
342+
343+
await cmd.doRun();
344+
345+
expect(upgradeNotification).toHaveBeenCalledTimes(1);
346+
expect(upgradeNotification).toHaveBeenCalledWith(undefined, '4.0.0');
347+
});
348+
323349
it('should not call cleanupNodeModules if already latest version', async () => {
324350
const cmd = await createTest(FlexPluginsUpgradePlugin)();
325351
mockForDoRun(cmd);

packages/plugin-flex/src/commands/flex/plugins/upgrade-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export default class FlexPluginsUpgradePlugin extends FlexPlugin {
124124
return;
125125
}
126126

127-
await this.prints.upgradeNotification(this._flags.yes);
127+
const pkgJson = await this.getLatestVersionOfDep(flexPluginScript, this._flags.beta);
128+
await this.prints.upgradeNotification(this._flags.yes, pkgJson.version as string);
128129

129130
const currentPkgVersion = this.pkgVersion;
130131
switch (currentPkgVersion) {
@@ -142,7 +143,6 @@ export default class FlexPluginsUpgradePlugin extends FlexPlugin {
142143
break;
143144
}
144145

145-
const pkgJson = await this.getLatestVersionOfDep(flexPluginScript, this._flags.beta);
146146
const latestVersion = pkgJson ? semver.coerce(pkgJson.version as string)?.major : 0;
147147
if (currentPkgVersion !== latestVersion) {
148148
await this.cleanupNodeModules();

packages/plugin-flex/src/prints/upgradePlugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const cracoUpgradeGuideLink = 'https://twilio.com';
88
* Upgrade notification
99
*/
1010
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11-
const upgradeNotification = (logger: Logger) => async (skip: boolean) => {
12-
boxen.warning('You are about to upgrade your plugin to use the latest version of Flex Plugin CLI.');
11+
const upgradeNotification = (logger: Logger) => async (skip: boolean, version?: string) => {
12+
const latestVersion = version ? `version ${version}` : 'the latest version';
13+
boxen.warning(`You are about to upgrade your plugin to use ${latestVersion} of the Flex Plugin CLI.`);
1314
if (!skip) {
1415
const answer = await confirm('Please backup your plugin either locally or on GitHub. Do you want to continue?');
1516
if (!answer) {

0 commit comments

Comments
 (0)