Skip to content

Commit

Permalink
fix(list): display mismatches from version groups
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Sep 17, 2020
1 parent c2f6199 commit 43ba18d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/commands/fix-mismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { getHighestVersion } from './lib/get-highest-version';
import { getWrappers, SourceWrapper } from './lib/get-wrappers';
import { getMismatchedDependencies } from './lib/installations/get-mismatched-dependencies';
import { log } from './lib/log';
import { matchesFilter } from './lib/matches-filter';

type Options = Pick<SyncpackConfig, 'dev' | 'filter' | 'indent' | 'peer' | 'prod' | 'source' | 'versionGroups'>;

export const fixMismatches = (wrappers: SourceWrapper[], options: Options): void => {
const iterator = getMismatchedDependencies(wrappers, options);
const mismatches = Array.from(iterator).filter(({ name }) => name.search(new RegExp(options.filter)) !== -1);
const mismatches = Array.from(iterator).filter(matchesFilter(options));

mismatches.forEach((installedPackage) => {
const versions = installedPackage.installations.map((installation) => installation.version);
Expand Down
7 changes: 7 additions & 0 deletions src/commands/lib/matches-filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SyncpackConfig } from '../../constants';
import { InstalledPackage } from './installations/get-dependencies';

type Options = Pick<SyncpackConfig, 'filter'>;

export const matchesFilter = (options: { filter: string }) => ({ name }: InstalledPackage): boolean =>
name.search(new RegExp(options.filter)) !== -1;
3 changes: 2 additions & 1 deletion src/commands/list-mismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { InstalledPackage } from './lib/installations/get-dependencies';
import { getMismatchedDependencies } from './lib/installations/get-mismatched-dependencies';
import { sortByName } from './lib/installations/sort-by-name';
import { log } from './lib/log';
import { matchesFilter } from './lib/matches-filter';

type Options = Pick<SyncpackConfig, 'dev' | 'filter' | 'peer' | 'prod' | 'source' | 'versionGroups'>;

export const listMismatches = (wrappers: SourceWrapper[], options: Options): InstalledPackage[] => {
const iterator = getMismatchedDependencies(wrappers, options);
const mismatches = Array.from(iterator).filter(({ name }) => name.search(new RegExp(options.filter)) !== -1);
const mismatches = Array.from(iterator).filter(matchesFilter(options));

mismatches.sort(sortByName).forEach(({ name, installations }) => {
log(chalk`{red ✕ ${name}}`);
Expand Down
11 changes: 7 additions & 4 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import chalk from 'chalk';
import { SyncpackConfig } from '../constants';
import { getWrappers, SourceWrapper } from './lib/get-wrappers';
import { getDependencies } from './lib/installations/get-dependencies';
import { getMismatchedDependencies } from './lib/installations/get-mismatched-dependencies';
import { sortByName } from './lib/installations/sort-by-name';
import { log } from './lib/log';
import { matchesFilter } from './lib/matches-filter';

type Options = Pick<SyncpackConfig, 'dev' | 'filter' | 'peer' | 'prod' | 'source'>;
type Options = Pick<SyncpackConfig, 'dev' | 'filter' | 'peer' | 'prod' | 'source' | 'versionGroups'>;

export const list = (wrappers: SourceWrapper[], options: Options): void => {
const iterator = getDependencies(wrappers, options);
const packages = Array.from(iterator).filter(({ name }) => name.search(new RegExp(options.filter)) !== -1);
const packages = Array.from(getDependencies(wrappers, options)).filter(matchesFilter(options));
const mismatches = Array.from(getMismatchedDependencies(wrappers, options)).filter(matchesFilter(options));

packages.sort(sortByName).forEach(({ name, installations }) => {
const versions = installations.map(({ version }) => version);
const uniques = Array.from(new Set(versions));
const hasMismatches = uniques.length > 1;
const mismatch = mismatches.find((mismatch) => mismatch.name === name);
const hasMismatches = mismatch !== undefined;
const uniquesList = uniques.sort().join(', ');
const message = hasMismatches
? chalk`{red ✕ ${name}} {dim.red ${uniquesList}}`
Expand Down

0 comments on commit 43ba18d

Please sign in to comment.