Skip to content

Commit

Permalink
fix: clarify types
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 21, 2024
1 parent 3340c3a commit 64b7669
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {readFileSync} from 'node:fs'
import {join} from 'node:path'

import {Config} from './config/config'
import {Configuration, Plugin} from './interfaces'
import {OclifConfiguration, Plugin} from './interfaces'

type OclifCoreInfo = {name: string; version: string}

type CacheContents = {
rootPlugin: Plugin
config: Config
exitCodes: Configuration['exitCodes']
exitCodes: OclifConfiguration['exitCodes']
'@oclif/core': OclifCoreInfo
}

Expand All @@ -36,7 +36,7 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
public get(key: 'config'): Config | undefined
public get(key: '@oclif/core'): OclifCoreInfo
public get(key: 'rootPlugin'): Plugin | undefined
public get(key: 'exitCodes'): Configuration['exitCodes'] | undefined
public get(key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined
public get(key: keyof CacheContents): ValueOf<CacheContents> | undefined {
return super.get(key)
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Cache from '../cache'
import {Command} from '../command'
import {CLIError, error, exit, warn} from '../errors'
import {getHelpFlagAdditions} from '../help/util'
import {Configuration, Hook, Hooks, PJSON, S3Templates, Topic, UserPJSON} from '../interfaces'
import {Hook, Hooks, OclifConfiguration, PJSON, S3Templates, Topic, UserPJSON} from '../interfaces'
import {ArchTypes, Config as IConfig, LoadOptions, PlatformTypes, VersionDetails} from '../interfaces/config'
import {Plugin as IPlugin, Options} from '../interfaces/plugin'
import {Theme} from '../interfaces/theme'
Expand Down Expand Up @@ -104,7 +104,7 @@ export class Config implements IConfig {
public shell!: string
public theme?: Theme | undefined
public topicSeparator: ' ' | ':' = ':'
public updateConfig!: NonNullable<Configuration['update']>
public updateConfig!: NonNullable<OclifConfiguration['update']>
public userAgent!: string
public userPJSON?: UserPJSON | undefined
public valid!: boolean
Expand Down Expand Up @@ -601,7 +601,7 @@ export class Config implements IConfig {
): string {
if (typeof ext === 'object') options = ext
else if (ext) options.ext = ext
const template = this.updateConfig.s3.templates?.[options.platform ? 'target' : 'vanilla'][type] ?? ''
const template = this.updateConfig.s3?.templates?.[options.platform ? 'target' : 'vanilla'][type] ?? ''
return ejs.render(template, {...(this as any), ...options})
}

Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Command} from '../command'
import {Hook, Hooks} from './hooks'
import {Configuration, PJSON, S3Templates} from './pjson'
import {OclifConfiguration, PJSON, S3Templates} from './pjson'
import {Options, Plugin} from './plugin'
import {Theme} from './theme'
import {Topic} from './topic'
Expand Down Expand Up @@ -115,7 +115,7 @@ export interface Config {
readonly theme?: Theme | undefined
topicSeparator: ' ' | ':'
readonly topics: Topic[]
readonly updateConfig: NonNullable<Configuration['update']>
readonly updateConfig: NonNullable<OclifConfiguration['update']>
/**
* user agent to use for http calls
*
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type {Hook, Hooks} from './hooks'
export type {Logger} from './logger'
export type {Manifest} from './manifest'
export type {Arg, BooleanFlag, CustomOptions, Deprecation, Flag, FlagDefinition, OptionFlag} from './parser'
export type {Configuration, PJSON, S3, S3Templates, UserPJSON} from './pjson'
export type {OclifConfiguration, PJSON, S3, S3Templates, UserPJSON} from './pjson'
export type {Options, Plugin, PluginOptions} from './plugin'
export type {S3Manifest} from './s3-manifest'
export type {Theme} from './theme'
Expand Down
11 changes: 6 additions & 5 deletions src/interfaces/pjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type S3 = {
folder?: string | undefined
gz?: boolean | undefined
host?: string | undefined
indexVersionLimit?: number | undefined
templates?:
| {
target: S3Templates
Expand All @@ -116,7 +117,7 @@ export type S3 = {
xz?: boolean | undefined
}

export type Configuration = {
export type OclifConfiguration = {
/**
* Flags in addition to --help that should trigger help output.
*/
Expand Down Expand Up @@ -241,7 +242,7 @@ export type Configuration = {
[k: string]: {
description?: string
hidden?: boolean
subtopics?: Configuration['topics']
subtopics?: OclifConfiguration['topics']
}
}
update?: {
Expand All @@ -250,12 +251,12 @@ export type Configuration = {
rollout?: number
}
disableNpmLookup?: boolean
node: {
node?: {
targets?: string[]
version?: string
options?: string | string[]
}
s3: S3
s3?: S3
}
'warn-if-update-available'?: {
authorization?: string
Expand Down Expand Up @@ -299,6 +300,6 @@ export type PJSON = {
dependencies?: {[name: string]: string}
devDependencies?: {[name: string]: string}
name: string
oclif: Configuration
oclif: OclifConfiguration
version: string
}
1 change: 0 additions & 1 deletion test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ describe('Config', () => {
...pjson,
oclif: {
...pjson.oclif,
// @ts-expect-error - not worth stubbing out every single required prop on s3
update: {
s3: {
host: 'https://bar.com/a/',
Expand Down

0 comments on commit 64b7669

Please sign in to comment.