From c3aac260f0254db7c2df5ae522b53109bc98276c Mon Sep 17 00:00:00 2001 From: Jamie Mason Date: Sun, 1 Aug 2021 13:08:06 +0100 Subject: [PATCH] refactor(core): apply changes from updated dependencies --- src/bin-fix-mismatches.ts | 18 ++++++++++-------- src/bin-format.ts | 10 ++++++---- src/bin-list-mismatches.ts | 16 +++++++++------- src/bin-list.ts | 16 +++++++++------- src/bin-set-semver-ranges.ts | 20 +++++++++++--------- src/bin.ts | 2 +- src/commands/lib/matches-filter.ts | 6 ++++-- src/commands/lib/write-if-changed.spec.ts | 2 +- src/lib/get-config.ts | 2 +- 9 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/bin-fix-mismatches.ts b/src/bin-fix-mismatches.ts index c8eedff2..06d445ef 100644 --- a/src/bin-fix-mismatches.ts +++ b/src/bin-fix-mismatches.ts @@ -2,9 +2,9 @@ import chalk from 'chalk'; import { fixMismatchesToDisk } from './commands/fix-mismatches'; -import { option } from './constants'; +import { option, SyncpackConfig } from './constants'; import { getConfig } from './lib/get-config'; -import program = require('commander'); +import { program } from 'commander'; program.description( ` @@ -55,13 +55,15 @@ program .option(...option.indent) .parse(process.argv); +const args = program as Partial; + fixMismatchesToDisk( getConfig({ - dev: program.dev, - filter: program.filter, - indent: program.indent, - peer: program.peer, - prod: program.prod, - source: program.source, + dev: args.dev, + filter: args.filter, + indent: args.indent, + peer: args.peer, + prod: args.prod, + source: args.source, }), ); diff --git a/src/bin-format.ts b/src/bin-format.ts index 9ac79720..e2a5de1f 100644 --- a/src/bin-format.ts +++ b/src/bin-format.ts @@ -2,9 +2,9 @@ import chalk from 'chalk'; import { formatToDisk } from './commands/format'; -import { option } from './constants'; +import { option, SyncpackConfig } from './constants'; import { getConfig } from './lib/get-config'; -import program = require('commander'); +import { program } from 'commander'; program.description( ` @@ -46,9 +46,11 @@ program .option(...option.indent) .parse(process.argv); +const args = program as Partial; + formatToDisk( getConfig({ - indent: program.indent, - source: program.source, + indent: args.indent, + source: args.source, }), ); diff --git a/src/bin-list-mismatches.ts b/src/bin-list-mismatches.ts index a5b76719..6ab3b259 100644 --- a/src/bin-list-mismatches.ts +++ b/src/bin-list-mismatches.ts @@ -2,9 +2,9 @@ import chalk from 'chalk'; import { listMismatchesFromDisk } from './commands/list-mismatches'; -import { option } from './constants'; +import { option, SyncpackConfig } from './constants'; import { getConfig } from './lib/get-config'; -import program = require('commander'); +import { program } from 'commander'; program.description( ` @@ -51,12 +51,14 @@ program .option(...option.filter) .parse(process.argv); +const args = program as Partial; + listMismatchesFromDisk( getConfig({ - dev: program.dev, - filter: program.filter, - peer: program.peer, - prod: program.prod, - source: program.source, + dev: args.dev, + filter: args.filter, + peer: args.peer, + prod: args.prod, + source: args.source, }), ); diff --git a/src/bin-list.ts b/src/bin-list.ts index 71fb1110..3aea77cf 100644 --- a/src/bin-list.ts +++ b/src/bin-list.ts @@ -2,9 +2,9 @@ import chalk from 'chalk'; import { listFromDisk } from './commands/list'; -import { option } from './constants'; +import { option, SyncpackConfig } from './constants'; import { getConfig } from './lib/get-config'; -import program = require('commander'); +import { program } from 'commander'; program.description(' List all dependencies required by your packages.'); @@ -47,12 +47,14 @@ program .option(...option.filter) .parse(process.argv); +const args = program as Partial; + listFromDisk( getConfig({ - dev: program.dev, - filter: program.filter, - peer: program.peer, - prod: program.prod, - source: program.source, + dev: args.dev, + filter: args.filter, + peer: args.peer, + prod: args.prod, + source: args.source, }), ); diff --git a/src/bin-set-semver-ranges.ts b/src/bin-set-semver-ranges.ts index 9ceb2bfd..7be65206 100644 --- a/src/bin-set-semver-ranges.ts +++ b/src/bin-set-semver-ranges.ts @@ -2,9 +2,9 @@ import chalk from 'chalk'; import { setSemverRangesToDisk } from './commands/set-semver-ranges'; -import { option } from './constants'; +import { option, SyncpackConfig } from './constants'; import { getConfig } from './lib/get-config'; -import program = require('commander'); +import { program } from 'commander'; program.description( ` @@ -67,14 +67,16 @@ program .option(...option.semverRange) .parse(process.argv); +const args = program as Partial; + setSemverRangesToDisk( getConfig({ - dev: program.dev, - filter: program.filter, - indent: program.indent, - peer: program.peer, - prod: program.prod, - semverRange: program.semverRange, - source: program.source, + dev: args.dev, + filter: args.filter, + indent: args.indent, + peer: args.peer, + prod: args.prod, + semverRange: args.semverRange, + source: args.source, }), ); diff --git a/src/bin.ts b/src/bin.ts index bf2d36a9..c74ac5e8 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import program = require('commander'); +import { program } from 'commander'; program .version(require('../package.json').version) diff --git a/src/commands/lib/matches-filter.ts b/src/commands/lib/matches-filter.ts index 1c4c1df5..dbdaac04 100644 --- a/src/commands/lib/matches-filter.ts +++ b/src/commands/lib/matches-filter.ts @@ -3,5 +3,7 @@ import { InstalledPackage } from './installations/get-dependencies'; type Options = Pick; -export const matchesFilter = (options: { filter: string }) => ({ name }: InstalledPackage): boolean => - name.search(new RegExp(options.filter)) !== -1; +export const matchesFilter = + (options: Options) => + ({ name }: InstalledPackage): boolean => + name.search(new RegExp(options.filter)) !== -1; diff --git a/src/commands/lib/write-if-changed.spec.ts b/src/commands/lib/write-if-changed.spec.ts index 630744c0..634c9711 100644 --- a/src/commands/lib/write-if-changed.spec.ts +++ b/src/commands/lib/write-if-changed.spec.ts @@ -9,7 +9,7 @@ describe('writeIfChanged', () => { afterEach(() => { jest.restoreAllMocks(); - jest.resetModuleRegistry(); + jest.resetModules(); }); beforeEach(() => { diff --git a/src/lib/get-config.ts b/src/lib/get-config.ts index 7d721855..70d2dfd9 100644 --- a/src/lib/get-config.ts +++ b/src/lib/get-config.ts @@ -19,7 +19,7 @@ export const getConfig = (program: Partial): SyncpackConfig => { if (isValid(configOption)) { return configOption; } - return (DEFAULT_CONFIG[name] as unknown) as T; + return DEFAULT_CONFIG[name] as unknown as T; }; const isVersionGroup = (value: any): value is VersionGroup =>