Skip to content

Commit 34d9809

Browse files
authored
chore: type Target using string literals and export type RunOptions (#1097)
1 parent 37d1d3b commit 34d9809

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ export async function run(runOptions: RunOptions = {}, { cli }: { cli?: boolean
145145
}
146146

147147
export default run
148+
149+
export type { RunOptions }

src/lib/initOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { deepPatternPrefix } from '../constants'
66
import programError from './programError'
77
import getPackageFileName from './getPackageFileName'
88
import { print } from '../logging'
9-
import { Options, RunOptions } from '../types'
9+
import { Options, RunOptions, Target } from '../types'
1010

1111
/** Initializes, validates, sets defaults, and consolidates program options. */
1212
function initOptions(runOptions: RunOptions, { cli }: { cli?: boolean } = {}): Options {
@@ -76,9 +76,9 @@ function initOptions(runOptions: RunOptions, { cli }: { cli?: boolean } = {}): O
7676
programError(options, chalk.red(`Cannot specify both --packageFile and --deep. --deep is an alias for --packageFile '${deepPatternPrefix}package.json'`))
7777
}
7878

79-
const target = options.newest ? 'newest'
79+
const target: Target = options.newest ? 'newest'
8080
: options.greatest ? 'greatest'
81-
: options.target || options.semverLevel || 'latest'
81+
: options.target || (options as any).semverLevel || 'latest'
8282

8383
const autoPre = target === 'newest' || target === 'greatest'
8484

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export type FilterFunction = (packageName: string, versionRange: SemVer[]) => bo
2929
export type FilterRejectPattern = string | string[] | RegExp | RegExp[] | FilterFunction
3030

3131
export type TargetFunction = (packageName: string, versionRange: SemVer[]) => string
32-
export type Target = string | TargetFunction
32+
export type TargetString = 'latest' | 'newest' | 'greatest' | 'minor' | 'patch'
33+
export type Target = TargetString | TargetFunction
3334

3435
export interface Packument {
3536
name: string,

test/queryVersions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('queryVersions', function () {
4141
})
4242

4343
it('return an error for an unsupported target', () => {
44-
const a = queryVersions({ async: '1.5.1' }, { target: 'foo', loglevel: 'silent' })
44+
const a = queryVersions({ async: '1.5.1' }, { target: 'foo', loglevel: 'silent' } as any)
4545
return a.should.be.rejected
4646
})
4747

0 commit comments

Comments
 (0)