Skip to content

Commit ecba5f9

Browse files
torifatSebastian McKenzie
authored andcommitted
Update outdated condition in upgrade-interactive (#1791)
* Update outdated condition in upgrade-interactive * Minor refactor sorting code * Fix $FlowFixMe for process.stdout.rows
1 parent 3ed3039 commit ecba5f9

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

__tests__/cli/aliases.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('shorthands and affordances', () => {
2626
expect(aliases['rm']).toBe('remove');
2727
expect(aliases['show']).toBe('info');
2828
expect(aliases['uninstall']).toBe('remove');
29-
expect(aliases['udpate']).toBe('upgrade');
29+
expect(aliases['update']).toBe('upgrade');
3030
expect(aliases['verison']).toBe('version');
3131
expect(aliases['view']).toBe('info');
3232
});

src/cli/aliases.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default ({
2828
rm: 'remove',
2929
show: 'info',
3030
uninstall: 'remove',
31-
udpate: 'upgrade',
31+
update: 'upgrade',
3232
verison: 'version',
3333
view: 'info',
3434
}: { [key: string]: ?string });

src/cli/commands/upgrade-interactive.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {Add} from './add.js';
1010
import {Install} from './install.js';
1111
import Lockfile from '../../lockfile/wrapper.js';
1212

13+
const tty = require('tty');
14+
const semver = require('semver');
15+
1316
export const requireLockfile = true;
1417

1518
export function setFlags(commander: Object) {
@@ -29,14 +32,16 @@ type InquirerResponses<K, T> = {[key: K]: Array<T>};
2932

3033
// Prompt user with Inquirer
3134
async function prompt(choices): Promise<Array<Dependency>> {
35+
let pageSize;
36+
if (process.stdout instanceof tty.WriteStream) {
37+
pageSize = process.stdout.rows - 2;
38+
}
3239
const answers: InquirerResponses<'packages', Dependency> = await inquirer.prompt([{
3340
name: 'packages',
3441
type: 'checkbox',
3542
message: 'Choose which packages to update.',
3643
choices,
37-
// Couldn't make it work, I guess I'm missing something here
38-
// $FlowFixMe: https://github.com/facebook/flow/blob/f41e66e27b227235750792c34f5a80f38bde6320/lib/node.js#L1197
39-
pageSize: process.stdout.rows - 2,
44+
pageSize,
4045
validate: (answer) => !!answer.length || 'You must choose at least one package.',
4146
}]);
4247
return answers.packages;
@@ -74,17 +79,11 @@ export async function run(
7479
return ({name, current, wanted, latest, hint});
7580
})));
7681

77-
const isDepOld = ({latest, current}) => latest !== current;
82+
const isDepOld = ({latest, current}) => latest !== 'exotic' && semver.lt(current, latest);
7883
const isDepExpected = ({current, wanted}) => current === wanted;
84+
const orderByExpected = (depA, depB) => isDepExpected(depA) && !isDepExpected(depB) ? 1 : -1;
7985

80-
const outdatedDeps = allDeps
81-
.filter(isDepOld)
82-
.sort((depA, depB) => {
83-
if (isDepExpected(depA) && !isDepExpected(depB)) {
84-
return 1;
85-
}
86-
return -1;
87-
});
86+
const outdatedDeps = allDeps.filter(isDepOld).sort(orderByExpected);
8887

8988
const getNameFromHint = (hint) => hint ? `${hint}Dependencies` : 'dependencies';
9089

0 commit comments

Comments
 (0)