@oclif/core
Advanced tools
Comparing version 4.2.4 to 4.2.5
@@ -20,3 +20,3 @@ import { URL } from 'node:url'; | ||
*/ | ||
export declare function custom<T = string, P = Record<string, unknown>>(defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>; | ||
export declare function custom<T = string, P = Record<string, unknown>>(_defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>; | ||
export declare const boolean: ArgDefinition<boolean, Record<string, unknown>>; | ||
@@ -23,0 +23,0 @@ export declare const integer: ArgDefinition<number, { |
import { Config } from './config/config'; | ||
import { OclifConfiguration, Plugin } from './interfaces'; | ||
type OclifCoreInfo = { | ||
name: string; | ||
version: string; | ||
}; | ||
type CacheContents = { | ||
@@ -13,2 +9,6 @@ rootPlugin: Plugin; | ||
}; | ||
type OclifCoreInfo = { | ||
name: string; | ||
version: string; | ||
}; | ||
type ValueOf<T> = T[keyof T]; | ||
@@ -22,8 +22,8 @@ /** | ||
static getInstance(): Cache; | ||
get(key: 'config'): Config | undefined; | ||
get(key: '@oclif/core'): OclifCoreInfo; | ||
get(key: 'rootPlugin'): Plugin | undefined; | ||
get(key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined; | ||
get(_key: 'config'): Config | undefined; | ||
get(_key: '@oclif/core'): OclifCoreInfo; | ||
get(_key: 'rootPlugin'): Plugin | undefined; | ||
get(_key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined; | ||
private getOclifCoreMeta; | ||
} | ||
export {}; |
@@ -14,2 +14,3 @@ import { Config } from './config'; | ||
config: Config; | ||
private static readonly _base; | ||
/** An array of aliases for this command. */ | ||
@@ -76,9 +77,4 @@ static aliases: string[]; | ||
id: string | undefined; | ||
private static readonly _base; | ||
constructor(argv: string[], config: Config); | ||
/** | ||
* actual command run code goes here | ||
*/ | ||
abstract run(): Promise<any>; | ||
/** | ||
* instantiate and run the command | ||
@@ -93,2 +89,3 @@ * | ||
protected get ctor(): typeof Command; | ||
protected _run<T>(): Promise<T>; | ||
protected catch(err: CommandError): Promise<any>; | ||
@@ -116,2 +113,6 @@ error(input: Error | string, options: { | ||
protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A>>; | ||
/** | ||
* actual command run code goes here | ||
*/ | ||
abstract run(): Promise<any>; | ||
protected toErrorJson(err: unknown): any; | ||
@@ -122,3 +123,2 @@ protected toSuccessJson(result: unknown): any; | ||
protected warnIfFlagDeprecated(flags: Record<string, unknown>): void; | ||
protected _run<T>(): Promise<T>; | ||
private removeEnvVar; | ||
@@ -125,0 +125,0 @@ } |
@@ -69,2 +69,3 @@ "use strict"; | ||
config; | ||
static _base = `${pjson.name}@${pjson.version}`; | ||
/** An array of aliases for this command. */ | ||
@@ -131,3 +132,2 @@ static aliases = []; | ||
id; | ||
static _base = `${pjson.name}@${pjson.version}`; | ||
constructor(argv, config) { | ||
@@ -176,2 +176,22 @@ this.argv = argv; | ||
} | ||
async _run() { | ||
let err; | ||
let result; | ||
try { | ||
// remove redirected env var to allow subsessions to run autoupdated client | ||
this.removeEnvVar('REDIRECTED'); | ||
await this.init(); | ||
result = await this.run(); | ||
} | ||
catch (error) { | ||
err = error; | ||
await this.catch(error); | ||
} | ||
finally { | ||
await this.finally(err); | ||
} | ||
if (result && this.jsonEnabled()) | ||
this.logJson(this.toSuccessJson(result)); | ||
return result; | ||
} | ||
async catch(err) { | ||
@@ -201,3 +221,3 @@ process.exitCode = process.exitCode ?? err.exitCode ?? 1; | ||
this.debug('init version: %s argv: %o', this.ctor._base, this.argv); | ||
const g = global; | ||
const g = globalThis; | ||
g['http-call'] = g['http-call'] || {}; | ||
@@ -223,5 +243,5 @@ g['http-call'].userAgent = this.config.userAgent; | ||
? // If '--' is not present, then check for `--json` in this.argv | ||
jsonIndex > -1 | ||
jsonIndex !== -1 | ||
: // If '--' is present, return true only the --json flag exists and is before the '--' | ||
jsonIndex > -1 && jsonIndex < passThroughIndex; | ||
jsonIndex !== -1 && jsonIndex < passThroughIndex; | ||
} | ||
@@ -310,22 +330,2 @@ log(message = '', ...args) { | ||
} | ||
async _run() { | ||
let err; | ||
let result; | ||
try { | ||
// remove redirected env var to allow subsessions to run autoupdated client | ||
this.removeEnvVar('REDIRECTED'); | ||
await this.init(); | ||
result = await this.run(); | ||
} | ||
catch (error) { | ||
err = error; | ||
await this.catch(error); | ||
} | ||
finally { | ||
await this.finally(err); | ||
} | ||
if (result && this.jsonEnabled()) | ||
this.logJson(this.toSuccessJson(result)); | ||
return result; | ||
} | ||
removeEnvVar(envVar) { | ||
@@ -332,0 +332,0 @@ const keys = []; |
@@ -47,8 +47,9 @@ import { Command } from '../command'; | ||
static load(opts?: LoadOptions): Promise<Config>; | ||
static get rootPlugin(): IPlugin | undefined; | ||
get commandIDs(): string[]; | ||
get commands(): Command.Loadable[]; | ||
protected get isProd(): boolean; | ||
static get rootPlugin(): IPlugin | undefined; | ||
get topics(): Topic[]; | ||
get versionDetails(): VersionDetails; | ||
protected _shell(): string; | ||
protected dir(category: 'cache' | 'config' | 'data'): string; | ||
@@ -105,3 +106,3 @@ findCommand(id: string, opts: { | ||
* this DOES NOT account for bin aliases, use scopedEnvVarKeys instead which will account for bin aliases | ||
* @param {string} k, the unscoped key you want to get the value for | ||
* @param k {string}, the unscoped key you want to get the value for | ||
* @returns {string} returns the env var key | ||
@@ -112,3 +113,3 @@ */ | ||
* gets the scoped env var keys for a given key, including bin aliases | ||
* @param {string} k, the env key e.g. 'debug' | ||
* @param k {string}, the env key e.g. 'debug' | ||
* @returns {string[]} e.g. ['SF_DEBUG', 'SFDX_DEBUG'] | ||
@@ -121,3 +122,2 @@ */ | ||
protected windowsUserprofileHome(): string | undefined; | ||
protected _shell(): string; | ||
private buildS3Config; | ||
@@ -133,3 +133,2 @@ private getCmdLookupId; | ||
* @param plugins array of oclif-compatible plugins | ||
* @returns void | ||
*/ | ||
@@ -136,0 +135,0 @@ private insertLegacyPlugins; |
@@ -181,5 +181,2 @@ "use strict"; | ||
} | ||
static get rootPlugin() { | ||
return this.rootPlugin; | ||
} | ||
get commandIDs() { | ||
@@ -197,2 +194,5 @@ if (this._commandIDs) | ||
} | ||
static get rootPlugin() { | ||
return this.rootPlugin; | ||
} | ||
get topics() { | ||
@@ -213,2 +213,23 @@ return [...this._topics.values()]; | ||
} | ||
_shell() { | ||
let shellPath; | ||
const { COMSPEC } = process.env; | ||
const SHELL = process.env.SHELL ?? (0, node_os_1.userInfo)().shell?.split(node_path_1.sep)?.pop(); | ||
if (SHELL) { | ||
shellPath = SHELL.split('/'); | ||
} | ||
else if (this.windows && process.title.toLowerCase().includes('powershell')) { | ||
shellPath = ['powershell']; | ||
} | ||
else if (this.windows && process.title.toLowerCase().includes('command prompt')) { | ||
shellPath = ['cmd.exe']; | ||
} | ||
else if (this.windows && COMSPEC) { | ||
shellPath = COMSPEC.split(/\\|\//); | ||
} | ||
else { | ||
shellPath = ['unknown']; | ||
} | ||
return shellPath.at(-1) ?? 'unknown'; | ||
} | ||
dir(category) { | ||
@@ -385,4 +406,4 @@ const base = process.env[`XDG_${category.toUpperCase()}_HOME`] || | ||
const [defaultTheme, userTheme] = await Promise.all([ | ||
await getDefaultTheme(), | ||
await (0, fs_1.safeReadJson)(userThemeFile), | ||
getDefaultTheme(), | ||
(0, fs_1.safeReadJson)(userThemeFile), | ||
]); | ||
@@ -438,3 +459,3 @@ // Merge the default theme with the user theme, giving the user theme precedence. | ||
const command = await c.load(); | ||
await this.runHook('prerun', { Command: command, argv }); | ||
await this.runHook('prerun', { argv, Command: command }); | ||
const result = (await command.run(argv, this)); | ||
@@ -448,3 +469,3 @@ // If plugins:uninstall was run, we need to remove all the uninstalled plugins | ||
} | ||
await this.runHook('postrun', { Command: command, argv, result }); | ||
await this.runHook('postrun', { argv, Command: command, result }); | ||
marker?.addDetails({ command: id, plugin: c.pluginName }); | ||
@@ -569,3 +590,3 @@ marker?.stop(); | ||
* this DOES NOT account for bin aliases, use scopedEnvVarKeys instead which will account for bin aliases | ||
* @param {string} k, the unscoped key you want to get the value for | ||
* @param k {string}, the unscoped key you want to get the value for | ||
* @returns {string} returns the env var key | ||
@@ -581,3 +602,3 @@ */ | ||
* gets the scoped env var keys for a given key, including bin aliases | ||
* @param {string} k, the env key e.g. 'debug' | ||
* @param k {string}, the env key e.g. 'debug' | ||
* @returns {string[]} e.g. ['SF_DEBUG', 'SFDX_DEBUG'] | ||
@@ -603,23 +624,2 @@ */ | ||
} | ||
_shell() { | ||
let shellPath; | ||
const { COMSPEC } = process.env; | ||
const SHELL = process.env.SHELL ?? (0, node_os_1.userInfo)().shell?.split(node_path_1.sep)?.pop(); | ||
if (SHELL) { | ||
shellPath = SHELL.split('/'); | ||
} | ||
else if (this.windows && process.title.toLowerCase().includes('powershell')) { | ||
shellPath = ['powershell']; | ||
} | ||
else if (this.windows && process.title.toLowerCase().includes('command prompt')) { | ||
shellPath = ['cmd.exe']; | ||
} | ||
else if (this.windows && COMSPEC) { | ||
shellPath = COMSPEC.split(/\\|\//); | ||
} | ||
else { | ||
shellPath = ['unknown']; | ||
} | ||
return shellPath.at(-1) ?? 'unknown'; | ||
} | ||
buildS3Config() { | ||
@@ -673,3 +673,2 @@ const s3 = this.pjson.oclif.update?.s3; | ||
* @param plugins array of oclif-compatible plugins | ||
* @returns void | ||
*/ | ||
@@ -676,0 +675,0 @@ insertLegacyPlugins(plugins) { |
@@ -8,2 +8,4 @@ import { Command } from '../command'; | ||
options: PluginOptions; | ||
_base: string; | ||
protected _debug: (..._: any) => void; | ||
alias: string; | ||
@@ -30,4 +32,2 @@ alreadyLoaded: boolean; | ||
version: string; | ||
_base: string; | ||
protected _debug: (..._: any) => void; | ||
private commandCache; | ||
@@ -34,0 +34,0 @@ private commandDiscoveryOpts; |
@@ -84,2 +84,4 @@ "use strict"; | ||
options; | ||
_base = `${_pjson.name}@${_pjson.version}`; | ||
_debug = (0, util_2.makeDebug)(); | ||
alias; | ||
@@ -105,4 +107,2 @@ alreadyLoaded = false; | ||
version; | ||
_base = `${_pjson.name}@${_pjson.version}`; | ||
_debug = (0, util_2.makeDebug)(); | ||
commandCache; | ||
@@ -167,2 +167,3 @@ commandDiscoveryOpts; | ||
} | ||
// eslint-disable-next-line complexity | ||
async load() { | ||
@@ -169,0 +170,0 @@ this.type = this.options.type ?? 'core'; |
@@ -20,3 +20,3 @@ import { OclifError, PrettyPrintableError } from '../../interfaces/errors'; | ||
* @deprecated `render` Errors display should be handled by display function, like pretty-print | ||
* @return {string} returns a string representing the dispay of the error | ||
* @returns {string} returns a string representing the display of the error | ||
*/ | ||
@@ -23,0 +23,0 @@ render(): string; |
@@ -23,3 +23,3 @@ "use strict"; | ||
} | ||
error.oclif.exit = options?.exit === undefined ? cache_1.default.getInstance().get('exitCodes')?.default ?? 2 : options.exit; | ||
error.oclif.exit = options?.exit === undefined ? (cache_1.default.getInstance().get('exitCodes')?.default ?? 2) : options.exit; | ||
return error; | ||
@@ -38,2 +38,3 @@ } | ||
} | ||
// eslint-disable-next-line getter-return | ||
get bang() { | ||
@@ -50,3 +51,3 @@ try { | ||
* @deprecated `render` Errors display should be handled by display function, like pretty-print | ||
* @return {string} returns a string representing the dispay of the error | ||
* @returns {string} returns a string representing the display of the error | ||
*/ | ||
@@ -72,2 +73,3 @@ render() { | ||
} | ||
// eslint-disable-next-line getter-return | ||
get bang() { | ||
@@ -74,0 +76,0 @@ try { |
@@ -5,5 +5,2 @@ import { LoadOptions } from './interfaces'; | ||
* | ||
* @param options - options to load the CLI | ||
* @returns Promise<void> | ||
* | ||
* @example For ESM dev.js | ||
@@ -10,0 +7,0 @@ * ``` |
@@ -12,5 +12,2 @@ "use strict"; | ||
* | ||
* @param options - options to load the CLI | ||
* @returns Promise<void> | ||
* | ||
* @example For ESM dev.js | ||
@@ -17,0 +14,0 @@ * ``` |
@@ -167,2 +167,3 @@ "use strict"; | ||
const noChar = flags.reduce((previous, current) => previous && current.char === undefined, true); | ||
// eslint-disable-next-line complexity | ||
return flags.map((flag) => { | ||
@@ -169,0 +170,0 @@ let left = this.flagHelpLabel(flag); |
@@ -57,3 +57,3 @@ import { Command } from '../command'; | ||
* @param spacing the final number of spaces this text will be indented | ||
* @return the formatted indented text | ||
* @returns the formatted indented text | ||
*/ | ||
@@ -60,0 +60,0 @@ indent(body: string, spacing?: number): string; |
@@ -60,3 +60,3 @@ "use strict"; | ||
* @param spacing the final number of spaces this text will be indented | ||
* @return the formatted indented text | ||
* @returns the formatted indented text | ||
*/ | ||
@@ -63,0 +63,0 @@ indent(body, spacing = this.indentSpacing) { |
@@ -25,2 +25,3 @@ import { Command } from '../command'; | ||
constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>); | ||
private get _topics(); | ||
protected get sortedCommands(): Command.Loadable[]; | ||
@@ -42,3 +43,2 @@ protected get sortedTopics(): Interfaces.Topic[]; | ||
protected summary(c: Command.Loadable): string | undefined; | ||
private get _topics(); | ||
} | ||
@@ -45,0 +45,0 @@ interface HelpBaseDerived { |
@@ -56,2 +56,15 @@ "use strict"; | ||
} | ||
/* | ||
* _topics is to work around Interfaces.topics mistakenly including commands that do | ||
* not have children, as well as topics. A topic has children, either commands or other topics. When | ||
* this is fixed upstream config.topics should return *only* topics with children, | ||
* and this can be removed. | ||
*/ | ||
get _topics() { | ||
return this.config.topics.filter((topic) => { | ||
// it is assumed a topic has a child if it has children | ||
const hasChild = this.config.topics.some((subTopic) => subTopic.name.includes(`${topic.name}:`)); | ||
return hasChild; | ||
}); | ||
} | ||
get sortedCommands() { | ||
@@ -151,3 +164,3 @@ let { commands } = this.config; | ||
log(...args) { | ||
this.opts.sendToStderr ? ux_1.ux.stderr(args) : ux_1.ux.stdout(args); | ||
return this.opts.sendToStderr ? ux_1.ux.stderr(args) : ux_1.ux.stdout(args); | ||
} | ||
@@ -308,15 +321,2 @@ async showCommandHelp(command) { | ||
} | ||
/* | ||
* _topics is to work around Interfaces.topics mistakenly including commands that do | ||
* not have children, as well as topics. A topic has children, either commands or other topics. When | ||
* this is fixed upstream config.topics should return *only* topics with children, | ||
* and this can be removed. | ||
*/ | ||
get _topics() { | ||
return this.config.topics.filter((topic) => { | ||
// it is assumed a topic has a child if it has children | ||
const hasChild = this.config.topics.some((subTopic) => subTopic.name.includes(`${topic.name}:`)); | ||
return hasChild; | ||
}); | ||
} | ||
} | ||
@@ -323,0 +323,0 @@ exports.Help = Help; |
@@ -99,3 +99,3 @@ "use strict"; | ||
const additionalHelpFlags = config.pjson.oclif.additionalHelpFlags ?? []; | ||
return [...new Set([...helpFlags, ...additionalHelpFlags]).values()]; | ||
return [...new Set([...additionalHelpFlags, ...helpFlags]).values()]; | ||
} | ||
@@ -102,0 +102,0 @@ function formatFlagDeprecationWarning(flag, opts) { |
@@ -52,4 +52,4 @@ "use strict"; | ||
try { | ||
const path = require('node:path'); | ||
const semver = require('semver'); | ||
const path = require('node:path'); | ||
const root = path.join(__dirname, '..'); | ||
@@ -56,0 +56,0 @@ const pjson = require(path.join(root, 'package.json')); |
@@ -114,4 +114,4 @@ import { Command } from '../command'; | ||
readonly theme?: Theme | undefined; | ||
readonly topics: Topic[]; | ||
topicSeparator: ' ' | ':'; | ||
readonly topics: Topic[]; | ||
readonly updateConfig: NonNullable<OclifConfiguration['update']>; | ||
@@ -118,0 +118,0 @@ /** |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.isPathModule = isPathModule; | ||
const getPackageType = require('get-package-type'); | ||
const node_fs_1 = require("node:fs"); | ||
@@ -14,3 +15,2 @@ const node_path_1 = require("node:path"); | ||
const fs_1 = require("./util/fs"); | ||
const getPackageType = require('get-package-type'); | ||
/** | ||
@@ -17,0 +17,0 @@ * Defines file extension resolution when source files do not have an extension. |
@@ -26,5 +26,5 @@ import { OutputArgs, OutputFlags, ParserInput, ParserOutput } from '../interfaces/parser'; | ||
constructor(input: T); | ||
private get _argTokens(); | ||
parse(): Promise<ParserOutput<TFlags, BFlags, TArgs>>; | ||
private _args; | ||
private get _argTokens(); | ||
private _debugInput; | ||
@@ -31,0 +31,0 @@ private _debugOutput; |
@@ -36,5 +36,5 @@ "use strict"; | ||
return null; | ||
if (global.oclif?.stdinCache) { | ||
debug('resolved stdin from global cache', global.oclif.stdinCache); | ||
return global.oclif.stdinCache; | ||
if (globalThis.oclif?.stdinCache) { | ||
debug('resolved stdin from global cache', globalThis.oclif.stdinCache); | ||
return globalThis.oclif.stdinCache; | ||
} | ||
@@ -57,3 +57,3 @@ return new Promise((resolve) => { | ||
debug('resolved from stdin', result); | ||
global.oclif = { ...global.oclif, stdinCache: result }; | ||
globalThis.oclif = { ...globalThis.oclif, stdinCache: result }; | ||
resolve(result); | ||
@@ -94,2 +94,5 @@ }); | ||
} | ||
get _argTokens() { | ||
return this.raw.filter((o) => o.type === 'arg'); | ||
} | ||
async parse() { | ||
@@ -241,5 +244,2 @@ this._debugInput(); | ||
} | ||
get _argTokens() { | ||
return this.raw.filter((o) => o.type === 'arg'); | ||
} | ||
_debugInput() { | ||
@@ -246,0 +246,0 @@ debug('input: %s', this.argv.join(' ')); |
@@ -195,8 +195,8 @@ "use strict"; | ||
} | ||
case 'none': { | ||
return validateExclusive(name, relationship.flags); | ||
} | ||
case 'some': { | ||
return validateSome(name, relationship.flags); | ||
} | ||
case 'none': { | ||
return validateExclusive(name, relationship.flags); | ||
} | ||
default: { | ||
@@ -203,0 +203,0 @@ throw new Error(`Unknown relationship type: ${relationship.type}`); |
@@ -56,6 +56,4 @@ type Details = Record<string, boolean | number | string | string[]>; | ||
* Add debug logs for plugin loading performance | ||
* @returns void | ||
*/ | ||
static debug(): void; | ||
static get enabled(): boolean; | ||
static getResult(owner: string, name: string): PerfResult | undefined; | ||
@@ -71,2 +69,3 @@ /** | ||
static mark(owner: string, name: string, details?: Details): Marker | undefined; | ||
static get enabled(): boolean; | ||
static get oclifPerf(): PerfHighlights | Record<string, never>; | ||
@@ -73,0 +72,0 @@ /** returns a map of owner, PerfResult[]. Excludes oclif PerfResult, which you can get from oclifPerf */ |
@@ -65,2 +65,3 @@ "use strict"; | ||
return new Promise((resolve) => { | ||
// eslint-disable-next-line complexity | ||
const perfObserver = new node_perf_hooks_1.PerformanceObserver((items) => { | ||
@@ -85,3 +86,3 @@ for (const entry of items.getEntries()) { | ||
const commandLoadTime = command | ||
? Performance.getResult(exports.OCLIF_MARKER_OWNER, `plugin.findCommand#${command.details.plugin}.${command.details.command}`)?.duration ?? 0 | ||
? (Performance.getResult(exports.OCLIF_MARKER_OWNER, `plugin.findCommand#${command.details.plugin}.${command.details.command}`)?.duration ?? 0) | ||
: 0; | ||
@@ -144,3 +145,2 @@ const pluginLoadTimes = Object.fromEntries(oclifResults | ||
* Add debug logs for plugin loading performance | ||
* @returns void | ||
*/ | ||
@@ -195,5 +195,2 @@ static debug() { | ||
} | ||
static get enabled() { | ||
return settings_1.settings.performanceEnabled ?? false; | ||
} | ||
static getResult(owner, name) { | ||
@@ -217,2 +214,5 @@ return Performance._results.get(owner)?.find((r) => r.name === name); | ||
} | ||
static get enabled() { | ||
return settings_1.settings.performanceEnabled ?? false; | ||
} | ||
static get oclifPerf() { | ||
@@ -219,0 +219,0 @@ if (!Performance.enabled) |
@@ -5,4 +5,4 @@ "use strict"; | ||
// Set global.oclif to the new object if it wasn't set before | ||
if (!global.oclif) | ||
global.oclif = {}; | ||
exports.settings = global.oclif; | ||
if (!globalThis.oclif) | ||
globalThis.oclif = {}; | ||
exports.settings = globalThis.oclif; |
@@ -77,4 +77,4 @@ "use strict"; | ||
const [flags, args] = await Promise.all([ | ||
await cacheFlags((0, aggregate_flags_1.aggregateFlags)(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault), | ||
await cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault), | ||
cacheFlags((0, aggregate_flags_1.aggregateFlags)(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault), | ||
cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault), | ||
]); | ||
@@ -114,3 +114,3 @@ const stdProperties = { | ||
// Add in any additional properties that are not standard command properties. | ||
const stdKeysAndIgnored = new Set([...Object.keys(stdProperties), ...ignoreCommandProperties]); | ||
const stdKeysAndIgnored = new Set([...ignoreCommandProperties, ...Object.keys(stdProperties)]); | ||
const keysToAdd = Object.keys(cmd).filter((property) => !stdKeysAndIgnored.has(property)); | ||
@@ -117,0 +117,0 @@ const additionalProperties = Object.fromEntries(keysToAdd.map((key) => [key, cmd[key]])); |
@@ -17,6 +17,3 @@ import { Command } from '../command'; | ||
* plugin as discovered (will not change the order) | ||
* | ||
* @param commands commands to determine the priority of | ||
* @returns command instance {Command.Loadable} or undefined | ||
*/ | ||
export declare function determinePriority(plugins: string[], commands: Command.Loadable[]): Command.Loadable; |
@@ -19,5 +19,2 @@ "use strict"; | ||
* plugin as discovered (will not change the order) | ||
* | ||
* @param commands commands to determine the priority of | ||
* @returns command instance {Command.Loadable} or undefined | ||
*/ | ||
@@ -24,0 +21,0 @@ function determinePriority(plugins, commands) { |
@@ -13,2 +13,3 @@ import { Options } from './types'; | ||
private stdmockOrigs; | ||
private get globals(); | ||
protected get output(): string | undefined; | ||
@@ -21,6 +22,2 @@ protected set output(output: string | undefined); | ||
set task(task: Task | undefined); | ||
pause(fn: () => any, icon?: string): Promise<any>; | ||
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>; | ||
start(action: string, status?: string, opts?: Options): void; | ||
stop(msg?: string): void; | ||
protected _flushStdout(): void; | ||
@@ -34,4 +31,7 @@ protected _pause(_?: string): void; | ||
protected _write(std: 'stderr' | 'stdout', s: string | string[]): void; | ||
private get globals(); | ||
pause(fn: () => any, icon?: string): Promise<any>; | ||
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>; | ||
start(action: string, status?: string, opts?: Options): void; | ||
stop(msg?: string): void; | ||
} | ||
export {}; |
@@ -14,2 +14,9 @@ "use strict"; | ||
}; | ||
get globals() { | ||
; | ||
globalThis.ux = globalThis.ux || {}; | ||
const globals = globalThis.ux; | ||
globals.action = globals.action || {}; | ||
return globals; | ||
} | ||
get output() { | ||
@@ -44,48 +51,2 @@ return this.globals.output; | ||
} | ||
pause(fn, icon) { | ||
const { task } = this; | ||
const active = task && task.active; | ||
if (task && active) { | ||
this._pause(icon); | ||
this._stdout(false); | ||
task.active = false; | ||
} | ||
const ret = fn(); | ||
if (task && active) { | ||
this._resume(); | ||
} | ||
return ret; | ||
} | ||
async pauseAsync(fn, icon) { | ||
const { task } = this; | ||
const active = task && task.active; | ||
if (task && active) { | ||
this._pause(icon); | ||
this._stdout(false); | ||
task.active = false; | ||
} | ||
const ret = await fn(); | ||
if (task && active) { | ||
this._resume(); | ||
} | ||
return ret; | ||
} | ||
start(action, status, opts = {}) { | ||
this.std = opts.stdout ? 'stdout' : 'stderr'; | ||
const task = { action, active: Boolean(this.task && this.task.active), status }; | ||
this.task = task; | ||
this._start(opts); | ||
task.active = true; | ||
this._stdout(true); | ||
} | ||
stop(msg = 'done') { | ||
const { task } = this; | ||
if (!task) { | ||
return; | ||
} | ||
this._stop(msg); | ||
task.active = false; | ||
this.task = undefined; | ||
this._stdout(false); | ||
} | ||
// flush mocked stdout/stderr | ||
@@ -164,2 +125,6 @@ _flushStdout() { | ||
switch (std) { | ||
case 'stderr': { | ||
this.stdmockOrigs.stderr.apply(process.stderr, (0, util_1.castArray)(s)); | ||
break; | ||
} | ||
case 'stdout': { | ||
@@ -169,6 +134,2 @@ this.stdmockOrigs.stdout.apply(process.stdout, (0, util_1.castArray)(s)); | ||
} | ||
case 'stderr': { | ||
this.stdmockOrigs.stderr.apply(process.stderr, (0, util_1.castArray)(s)); | ||
break; | ||
} | ||
default: { | ||
@@ -179,10 +140,49 @@ throw new Error(`invalid std: ${std}`); | ||
} | ||
get globals() { | ||
; | ||
global.ux = global.ux || {}; | ||
const globals = global.ux; | ||
globals.action = globals.action || {}; | ||
return globals; | ||
pause(fn, icon) { | ||
const { task } = this; | ||
const active = task && task.active; | ||
if (task && active) { | ||
this._pause(icon); | ||
this._stdout(false); | ||
task.active = false; | ||
} | ||
const ret = fn(); | ||
if (task && active) { | ||
this._resume(); | ||
} | ||
return ret; | ||
} | ||
async pauseAsync(fn, icon) { | ||
const { task } = this; | ||
const active = task && task.active; | ||
if (task && active) { | ||
this._pause(icon); | ||
this._stdout(false); | ||
task.active = false; | ||
} | ||
const ret = await fn(); | ||
if (task && active) { | ||
this._resume(); | ||
} | ||
return ret; | ||
} | ||
start(action, status, opts = {}) { | ||
this.std = opts.stdout ? 'stdout' : 'stderr'; | ||
const task = { action, active: Boolean(this.task && this.task.active), status }; | ||
this.task = task; | ||
this._start(opts); | ||
task.active = true; | ||
this._stdout(true); | ||
} | ||
stop(msg = 'done') { | ||
const { task } = this; | ||
if (!task) { | ||
return; | ||
} | ||
this._stop(msg); | ||
task.active = false; | ||
this.task = undefined; | ||
this._stdout(false); | ||
} | ||
} | ||
exports.ActionBase = ActionBase; |
import { ActionBase, ActionType } from './base'; | ||
export default class SimpleAction extends ActionBase { | ||
type: ActionType; | ||
private _flush; | ||
protected _pause(icon?: string): void; | ||
private _render; | ||
protected _resume(): void; | ||
@@ -11,2 +9,4 @@ protected _start(): void; | ||
protected _updateStatus(status: string, prevStatus?: string, newline?: boolean): void; | ||
private _flush; | ||
private _render; | ||
} |
@@ -6,6 +6,2 @@ "use strict"; | ||
type = 'simple'; | ||
_flush() { | ||
this._write(this.std, '\n'); | ||
this._flushStdout(); | ||
} | ||
_pause(icon) { | ||
@@ -17,9 +13,2 @@ if (icon) | ||
} | ||
_render(action, status) { | ||
if (!this.task) | ||
return; | ||
if (this.task.active) | ||
this._flush(); | ||
this._write(this.std, status ? `${action}... ${status}` : `${action}...`); | ||
} | ||
_resume() { | ||
@@ -48,3 +37,14 @@ // Not implemented | ||
} | ||
_flush() { | ||
this._write(this.std, '\n'); | ||
this._flushStdout(); | ||
} | ||
_render(action, status) { | ||
if (!this.task) | ||
return; | ||
if (this.task.active) | ||
this._flush(); | ||
this._write(this.std, status ? `${action}... ${status}` : `${action}...`); | ||
} | ||
} | ||
exports.default = SimpleAction; |
@@ -10,11 +10,11 @@ import { ActionBase, ActionType } from './base'; | ||
constructor(); | ||
protected _frame(): string; | ||
protected _pause(icon?: string): void; | ||
protected _start(opts: Options): void; | ||
protected _stop(status: string): void; | ||
protected colorize(s: string): string; | ||
protected _frame(): string; | ||
private _lines; | ||
protected _pause(icon?: string): void; | ||
private _render; | ||
private _reset; | ||
protected _start(opts: Options): void; | ||
protected _stop(status: string): void; | ||
private getFrames; | ||
} |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ansiEscapes = require('ansi-escapes'); | ||
const ansis_1 = __importDefault(require("ansis")); | ||
@@ -13,3 +14,2 @@ const cli_spinners_1 = __importDefault(require("cli-spinners")); | ||
const base_1 = require("./base"); | ||
const ansiEscapes = require('ansi-escapes'); | ||
class SpinnerAction extends base_1.ActionBase { | ||
@@ -26,5 +26,2 @@ type = 'spinner'; | ||
} | ||
colorize(s) { | ||
return (0, theme_1.colorize)(this.color, s); | ||
} | ||
_frame() { | ||
@@ -35,7 +32,2 @@ const frame = this.frames[this.frameIndex]; | ||
} | ||
_lines(s) { | ||
return ansis_1.default.strip(s).split('\n') | ||
.map((l) => Math.ceil(l.length / screen_1.errtermwidth)) | ||
.reduce((c, i) => c + i, 0); | ||
} | ||
_pause(icon) { | ||
@@ -49,19 +41,2 @@ if (this.spinner) | ||
} | ||
_render(icon) { | ||
if (!this.task) | ||
return; | ||
this._reset(); | ||
this._flushStdout(); | ||
const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || ''; | ||
const status = this.task.status ? ` ${this.task.status}` : ''; | ||
this.output = `${this.task.action}...${frame}${status}\n`; | ||
this._write(this.std, this.output); | ||
} | ||
_reset() { | ||
if (!this.output) | ||
return; | ||
const lines = this._lines(this.output); | ||
this._write(this.std, ansiEscapes.cursorLeft + ansiEscapes.cursorUp(lines) + ansiEscapes.eraseDown); | ||
this.output = undefined; | ||
} | ||
_start(opts) { | ||
@@ -87,2 +62,27 @@ this.color = cache_1.default.getInstance().get('config')?.theme?.spinner ?? this.color; | ||
} | ||
colorize(s) { | ||
return (0, theme_1.colorize)(this.color, s); | ||
} | ||
_lines(s) { | ||
return ansis_1.default.strip(s).split('\n') | ||
.map((l) => Math.ceil(l.length / screen_1.errtermwidth)) | ||
.reduce((c, i) => c + i, 0); | ||
} | ||
_render(icon) { | ||
if (!this.task) | ||
return; | ||
this._reset(); | ||
this._flushStdout(); | ||
const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || ''; | ||
const status = this.task.status ? ` ${this.task.status}` : ''; | ||
this.output = `${this.task.action}...${frame}${status}\n`; | ||
this._write(this.std, this.output); | ||
} | ||
_reset() { | ||
if (!this.output) | ||
return; | ||
const lines = this._lines(this.output); | ||
this._write(this.std, ansiEscapes.cursorLeft + ansiEscapes.cursorUp(lines) + ansiEscapes.eraseDown); | ||
this.output = undefined; | ||
} | ||
getFrames(opts) { | ||
@@ -89,0 +89,0 @@ if (opts?.style) |
@@ -37,5 +37,5 @@ "use strict"; | ||
// @ts-expect-error because `this` is not typed | ||
// eslint-disable-next-line no-bitwise | ||
// eslint-disable-next-line no-bitwise, @typescript-eslint/no-unused-expressions | ||
~thisPos ? stack.splice(thisPos + 1) : stack.push(this); | ||
// eslint-disable-next-line no-bitwise | ||
// eslint-disable-next-line no-bitwise, @typescript-eslint/no-unused-expressions | ||
~thisPos ? keys.splice(thisPos, Number.POSITIVE_INFINITY, key) : keys.push(key); | ||
@@ -42,0 +42,0 @@ // @ts-expect-error because `this` is not typed |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = renderList; | ||
const wordwrap = require('wordwrap'); | ||
const screen_1 = require("../screen"); | ||
const util_1 = require("../util/util"); | ||
const wordwrap = require('wordwrap'); | ||
function linewrap(length, s) { | ||
@@ -8,0 +8,0 @@ return wordwrap(length, screen_1.stdtermwidth, { |
{ | ||
"name": "@oclif/core", | ||
"description": "base library for oclif CLIs", | ||
"version": "4.2.4", | ||
"version": "4.2.5", | ||
"author": "Salesforce", | ||
@@ -29,2 +29,3 @@ "bugs": "https://github.com/oclif/core/issues", | ||
"@commitlint/config-conventional": "^19", | ||
"@eslint/compat": "^1.2.5", | ||
"@oclif/plugin-help": "^6", | ||
@@ -53,6 +54,5 @@ "@oclif/plugin-plugins": "^5", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.57.1", | ||
"eslint-config-oclif": "^5.2.2", | ||
"eslint-config-oclif-typescript": "^3.1.13", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint": "^9", | ||
"eslint-config-oclif": "^6", | ||
"eslint-config-prettier": "^10", | ||
"husky": "^9.1.7", | ||
@@ -101,2 +101,3 @@ "lint-staged": "^15", | ||
"./logger": "./lib/logger.js", | ||
"./package.json": "./package.json", | ||
"./parser": "./lib/parser/index.js", | ||
@@ -124,3 +125,3 @@ "./performance": "./lib/performance.js", | ||
"format": "prettier --write \"+(src|test)/**/*.+(ts|js|json)\"", | ||
"lint": "eslint . --ext .ts", | ||
"lint": "eslint", | ||
"posttest": "yarn lint && yarn test:circular-deps", | ||
@@ -127,0 +128,0 @@ "prepack": "yarn run build", |
406209
10211
5
1
101