Skip to content
Merged
3 changes: 0 additions & 3 deletions flush.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion flush.js

This file was deleted.

1 change: 0 additions & 1 deletion handle.js

This file was deleted.

26 changes: 21 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@
"node": ">=18.0.0"
},
"files": [
"/lib",
"/flush.js",
"/flush.d.ts",
"/handle.js"
"/lib"
],
"homepage": "https://github.com/oclif/core",
"keywords": [
Expand All @@ -82,7 +79,26 @@
"argv"
],
"license": "MIT",
"main": "./lib/index.js",
"exports": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this includes all the ones I came here to check 😄

".": "./lib/index.js",
"./args": "./lib/args.js",
"./command": "./lib/command.js",
"./config": "./lib/config/index.js",
"./errors": "./lib/errors/index.js",
"./execute": "./lib/execute.js",
"./flags": "./lib/flags.js",
"./flush": "./lib/flush.js",
"./handle": "./lib/errors/handle.js",
"./help": "./lib/help/index.js",
"./hooks": "./lib/interfaces/hooks.js",
"./interfaces": "./lib/interfaces/index.js",
"./logger": "./lib/logger.js",
"./performance": "./lib/performance.js",
"./run": "./lib/main.js",
"./settings": "./lib/settings.js",
"./util/ids": "./lib/util/ids.js",
"./ux": "./lib/ux/index.js"
},
"repository": "oclif/core",
"oclif": {
"bin": "oclif",
Expand Down
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 {PJSON, Plugin} from './interfaces'
import {Configuration, Plugin} from './interfaces'

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

type CacheContents = {
rootPlugin: Plugin
config: Config
exitCodes: PJSON.Plugin['oclif']['exitCodes']
exitCodes: Configuration['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'): PJSON.Plugin['oclif']['exitCodes'] | undefined
public get(key: 'exitCodes'): Configuration['exitCodes'] | undefined
public get(key: keyof CacheContents): ValueOf<CacheContents> | undefined {
return super.get(key)
}
Expand Down
36 changes: 18 additions & 18 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as Parser from './parser'
import {aggregateFlags} from './util/aggregate-flags'
import {toConfiguredId} from './util/ids'
import {uniq} from './util/util'
import ux from './ux'
import {ux} from './ux'

const pjson = Cache.getInstance().get('@oclif/core')

Expand Down Expand Up @@ -406,36 +406,36 @@ export namespace Command {
*/
export type Cached = {
[key: string]: unknown
aliasPermutations?: string[]
aliasPermutations?: string[] | undefined
aliases: string[]
args: {[name: string]: Arg.Cached}
deprecateAliases?: boolean
deprecationOptions?: Deprecation
description?: string
examples?: Example[]
deprecateAliases?: boolean | undefined
deprecationOptions?: Deprecation | undefined
description?: string | undefined
examples?: Example[] | undefined
flags: {[name: string]: Flag.Cached}
hasDynamicHelp?: boolean
hidden: boolean
hiddenAliases: string[]
id: string
isESM?: boolean
permutations?: string[]
pluginAlias?: string
pluginName?: string
pluginType?: string
relativePath?: string[]
state?: 'beta' | 'deprecated' | string
strict?: boolean
summary?: string
type?: string
usage?: string | string[]
isESM?: boolean | undefined
permutations?: string[] | undefined
pluginAlias?: string | undefined
pluginName?: string | undefined
pluginType?: string | undefined
relativePath?: string[] | undefined
state?: 'beta' | 'deprecated' | string | undefined
strict?: boolean | undefined
summary?: string | undefined
type?: string | undefined
usage?: string | string[] | undefined
}

export type Flag = IFlag<any>

export namespace Flag {
export type Cached = Omit<Flag, 'input' | 'parse'> &
(BooleanFlagProps | OptionFlagProps) & {hasDynamicHelp?: boolean}
(BooleanFlagProps | OptionFlagProps) & {hasDynamicHelp?: boolean | undefined}
export type Any = Cached | Flag
}

Expand Down
45 changes: 25 additions & 20 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 {Hook, Hooks, PJSON, Topic} from '../interfaces'
import {Configuration, Hook, Hooks, 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 All @@ -19,7 +19,7 @@ import {settings} from '../settings'
import {safeReadJson} from '../util/fs'
import {getHomeDir, getPlatform} from '../util/os'
import {compact, isProd} from '../util/util'
import ux from '../ux'
import {ux} from '../ux'
import {parseTheme} from '../ux/theme'
import PluginLoader from './plugin-loader'
import {tsPath} from './ts-path'
Expand Down Expand Up @@ -83,8 +83,8 @@ export class Config implements IConfig {
public arch!: ArchTypes

public bin!: string
public binAliases?: string[]
public binPath?: string
public binAliases?: string[] | undefined

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should any of these be readonly? conversely, do we want people mutating them all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't be readonly because all these props are assigned in the .load method. Typescript doesn't like that

public binPath?: string | undefined
public cacheDir!: string
public channel!: string
public configDir!: string
Expand All @@ -94,18 +94,18 @@ export class Config implements IConfig {
public home!: string
public isSingleCommandCLI = false
public name!: string
public npmRegistry?: string
public nsisCustomization?: string
public pjson!: PJSON.CLI
public npmRegistry?: string | undefined
public nsisCustomization?: string | undefined
public pjson!: PJSON
public platform!: PlatformTypes
public plugins: Map<string, IPlugin> = new Map()
public root!: string
public shell!: string
public theme?: Theme
public theme?: Theme | undefined
public topicSeparator: ' ' | ':' = ':'
public updateConfig!: NonNullable<PJSON.CLI['oclif']['update']>
public updateConfig!: NonNullable<Configuration['update']>
public userAgent!: string
public userPJSON?: PJSON.User
public userPJSON?: UserPJSON | undefined
public valid!: boolean
public version!: string
protected warned = false
Expand Down Expand Up @@ -348,10 +348,9 @@ export class Config implements IConfig {
}

this.isSingleCommandCLI = Boolean(
this.pjson.oclif.default ||
(typeof this.pjson.oclif.commands !== 'string' &&
this.pjson.oclif.commands?.strategy === 'single' &&
this.pjson.oclif.commands?.target),
typeof this.pjson.oclif.commands !== 'string' &&
this.pjson.oclif.commands?.strategy === 'single' &&
this.pjson.oclif.commands?.target,
)

this.maybeAdjustDebugSetting()
Expand Down Expand Up @@ -396,13 +395,19 @@ export class Config implements IConfig {

public async loadTheme(): Promise<Theme | undefined> {
if (this.scopedEnvVarTrue('DISABLE_THEME')) return
const defaultThemeFile = this.pjson.oclif.theme
? resolve(this.root, this.pjson.oclif.theme)
: this.pjson.oclif.theme

const userThemeFile = resolve(this.configDir, 'theme.json')
const getDefaultTheme = async () => {
if (!this.pjson.oclif.theme) return
if (typeof this.pjson.oclif.theme === 'string') {
return safeReadJson<Record<string, string>>(resolve(this.root, this.pjson.oclif.theme))
}

return this.pjson.oclif.theme
}

const [defaultTheme, userTheme] = await Promise.all([
defaultThemeFile ? await safeReadJson<Record<string, string>>(defaultThemeFile) : undefined,
await getDefaultTheme(),
await safeReadJson<Record<string, string>>(userThemeFile),
])

Expand Down Expand Up @@ -589,13 +594,13 @@ export class Config implements IConfig {
}

public s3Key(
type: keyof PJSON.S3.Templates,
type: keyof S3Templates,
ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options,
options: IConfig.s3Key.Options = {},
): 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
22 changes: 12 additions & 10 deletions src/config/plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ import {makeDebug} from './util'
const debug = makeDebug()

type PluginLoaderOptions = {
plugins?: IPlugin[] | PluginsMap
plugins?: IPlugin[] | PluginsMap | undefined
root: string
}

type LoadOpts = {
dataDir: string
devPlugins?: boolean
force?: boolean
devPlugins?: boolean | undefined
force?: boolean | undefined
rootPlugin: IPlugin
userPlugins?: boolean
pluginAdditions?: {
core?: string[]
dev?: string[]
path?: string
}
userPlugins?: boolean | undefined
pluginAdditions?:
| {
core?: string[]
dev?: string[]
path?: string
}
| undefined
}

type PluginsMap = Map<string, IPlugin>
Expand Down Expand Up @@ -57,7 +59,7 @@ export default class PluginLoader {
return {errors: this.errors, plugins: this.plugins}
}

public async loadRoot({pjson}: {pjson?: PJSON.Plugin}): Promise<IPlugin> {
public async loadRoot({pjson}: {pjson?: PJSON | undefined}): Promise<IPlugin> {
let rootPlugin: IPlugin
if (this.pluginsProvided) {
const plugins = [...this.plugins.values()]
Expand Down
13 changes: 4 additions & 9 deletions src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,9 @@ function processCommandIds(files: string[]): string[] {

function determineCommandDiscoveryOptions(
commandDiscovery: string | CommandDiscovery | undefined,
defaultCmdId?: string | undefined,
): CommandDiscovery | undefined {
if (!commandDiscovery) return

if (typeof commandDiscovery === 'string' && defaultCmdId) {
return {strategy: 'single', target: commandDiscovery}
}

if (typeof commandDiscovery === 'string') {
return {globPatterns: GLOB_PATTERNS, strategy: 'pattern', target: commandDiscovery}
}
Expand Down Expand Up @@ -127,13 +122,13 @@ export class Plugin implements IPlugin {

name!: string

parent: Plugin | undefined
parent?: Plugin | undefined

pjson!: PJSON.Plugin
pjson!: PJSON

root!: string

tag?: string
tag?: string | undefined

type!: string

Expand Down Expand Up @@ -247,7 +242,7 @@ export class Plugin implements IPlugin {
]),
)

this.commandDiscoveryOpts = determineCommandDiscoveryOptions(this.pjson.oclif?.commands, this.pjson.oclif?.default)
this.commandDiscoveryOpts = determineCommandDiscoveryOptions(this.pjson.oclif?.commands)

this._debug('command discovery options', this.commandDiscoveryOpts)

Expand Down
12 changes: 10 additions & 2 deletions src/config/ts-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,16 @@ async function determinePath(root: string, orig: string): Promise<string> {
* if there is a tsconfig and the original sources exist, it attempts to require ts-node
*/
export async function tsPath(root: string, orig: string, plugin: Plugin): Promise<string>
export async function tsPath(root: string, orig: string | undefined, plugin?: Plugin): Promise<string | undefined>
export async function tsPath(root: string, orig: string | undefined, plugin?: Plugin): Promise<string | undefined> {
export async function tsPath(
root: string,
orig: string | undefined,
plugin?: Plugin | undefined,
): Promise<string | undefined>
export async function tsPath(
root: string,
orig: string | undefined,
plugin?: Plugin | undefined,
): Promise<string | undefined> {
const rootPlugin = plugin?.options.isRoot ? plugin : Cache.getInstance().get('rootPlugin')

if (!orig) return orig
Expand Down
13 changes: 8 additions & 5 deletions src/errors/errors/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {settings} from '../../settings'
* properties specific to internal oclif error handling
*/

export function addOclifExitCode(error: Record<string, any>, options?: {exit?: false | number}): OclifError {
export function addOclifExitCode(
error: Record<string, any>,
options?: {exit?: false | number | undefined},
): OclifError {
if (!('oclif' in error)) {
;(error as unknown as OclifError).oclif = {}
}
Expand All @@ -22,12 +25,12 @@ export function addOclifExitCode(error: Record<string, any>, options?: {exit?: f
}

export class CLIError extends Error implements OclifError {
code?: string
code?: string | undefined

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the value of having both ? and the | undefined ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this #960

oclif: OclifError['oclif'] = {}
skipOclifErrorHandling?: boolean
suggestions?: string[]
skipOclifErrorHandling?: boolean | undefined
suggestions?: string[] | undefined

constructor(error: Error | string, options: {exit?: false | number} & PrettyPrintableError = {}) {
constructor(error: Error | string, options: {exit?: false | number | undefined} & PrettyPrintableError = {}) {
super(error instanceof Error ? error.message : error)
addOclifExitCode(this, options)
this.code = options.code
Expand Down
2 changes: 1 addition & 1 deletion src/errors/errors/pretty-print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {errtermwidth} from '../../screen'
import {settings} from '../../settings'

// These exist for backwards compatibility with CLIError
type CLIErrorDisplayOptions = {bang?: string; name?: string}
type CLIErrorDisplayOptions = {bang?: string | undefined; name?: string | undefined}

export function applyPrettyPrintOptions(error: Error, options: PrettyPrintableError): PrettyPrintableError {
const prettyErrorKeys: (keyof PrettyPrintableError)[] = ['message', 'code', 'ref', 'suggestions']
Expand Down
2 changes: 1 addition & 1 deletion src/flush.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {error} from './errors'
import {error} from './errors/error'

function timeout(p: Promise<any>, ms: number) {
function wait(ms: number, unref = false) {
Expand Down
Loading