@oclif/core 4.0.0-beta.8 → 4.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cache.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Config } from './config/config';
2
- import { Configuration, Plugin } from './interfaces';
2
+ import { OclifConfiguration, Plugin } from './interfaces';
3
3
  type OclifCoreInfo = {
4
4
  name: string;
5
5
  version: string;
@@ -7,7 +7,7 @@ type OclifCoreInfo = {
7
7
  type CacheContents = {
8
8
  rootPlugin: Plugin;
9
9
  config: Config;
10
- exitCodes: Configuration['exitCodes'];
10
+ exitCodes: OclifConfiguration['exitCodes'];
11
11
  '@oclif/core': OclifCoreInfo;
12
12
  };
13
13
  type ValueOf<T> = T[keyof T];
@@ -21,7 +21,7 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
21
21
  get(key: 'config'): Config | undefined;
22
22
  get(key: '@oclif/core'): OclifCoreInfo;
23
23
  get(key: 'rootPlugin'): Plugin | undefined;
24
- get(key: 'exitCodes'): Configuration['exitCodes'] | undefined;
24
+ get(key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined;
25
25
  private getOclifCoreMeta;
26
26
  }
27
27
  export {};
package/lib/cache.js CHANGED
@@ -28,7 +28,7 @@ class Cache extends Map {
28
28
  try {
29
29
  return {
30
30
  name: '@oclif/core',
31
- version: JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8')),
31
+ version: JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8')).version,
32
32
  };
33
33
  }
34
34
  catch {
package/lib/command.d.ts CHANGED
@@ -15,7 +15,6 @@ export declare abstract class Command {
15
15
  static aliases: string[];
16
16
  /** An order-dependent object of arguments for the command */
17
17
  static args: ArgInput;
18
- static baseFlags: FlagInput;
19
18
  /**
20
19
  * Emit deprecation warning when a command alias is used
21
20
  */
@@ -109,7 +108,7 @@ export declare abstract class Command {
109
108
  log(message?: string, ...args: any[]): void;
110
109
  protected logJson(json: unknown): void;
111
110
  logToStderr(message?: string, ...args: any[]): void;
112
- protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A>>;
111
+ protected parse<F extends FlagOutput, A extends ArgOutput>(options?: Input<F, A>, argv?: string[]): Promise<ParserOutput<F, A>>;
113
112
  protected toErrorJson(err: unknown): any;
114
113
  protected toSuccessJson(result: unknown): any;
115
114
  warn(input: Error | string): Error | string;
package/lib/command.js CHANGED
@@ -61,7 +61,6 @@ class Command {
61
61
  static aliases = [];
62
62
  /** An order-dependent object of arguments for the command */
63
63
  static args = {};
64
- static baseFlags;
65
64
  /**
66
65
  * Emit deprecation warning when a command alias is used
67
66
  */
@@ -148,6 +147,9 @@ class Command {
148
147
  opts = (0, node_url_1.fileURLToPath)(opts);
149
148
  }
150
149
  const config = await config_1.Config.load(opts || require.main?.filename || __dirname);
150
+ const cache = cache_1.default.getInstance();
151
+ if (!cache.has('config'))
152
+ cache.set('config', config);
151
153
  const cmd = new this(argv, config);
152
154
  if (!cmd.id) {
153
155
  const id = cmd.constructor.name.toLowerCase();
@@ -229,7 +231,7 @@ class Command {
229
231
  const opts = {
230
232
  context: this,
231
233
  ...options,
232
- flags: (0, aggregate_flags_1.aggregateFlags)(options.flags, options.baseFlags, options.enableJsonFlag),
234
+ flags: (0, aggregate_flags_1.aggregateFlags)(options.flags, options.enableJsonFlag),
233
235
  };
234
236
  const hookResult = await this.config.runHook('preparse', { argv: [...argv], options: opts });
235
237
  // Since config.runHook will only run the hook for the root plugin, hookResult.successes will always have a length of 0 or 1
@@ -266,7 +268,7 @@ class Command {
266
268
  }
267
269
  }
268
270
  warnIfFlagDeprecated(flags) {
269
- const allFlags = (0, aggregate_flags_1.aggregateFlags)(this.ctor.flags, this.ctor.baseFlags, this.ctor.enableJsonFlag);
271
+ const allFlags = (0, aggregate_flags_1.aggregateFlags)(this.ctor.flags, this.ctor.enableJsonFlag);
270
272
  for (const flag of Object.keys(flags)) {
271
273
  const flagDef = allFlags[flag];
272
274
  const deprecated = flagDef?.deprecated;
@@ -1,5 +1,5 @@
1
1
  import { Command } from '../command';
2
- import { Configuration, Hook, Hooks, PJSON, S3Templates, Topic, UserPJSON } from '../interfaces';
2
+ import { Hook, Hooks, OclifConfiguration, PJSON, S3Templates, Topic, UserPJSON } from '../interfaces';
3
3
  import { ArchTypes, Config as IConfig, LoadOptions, PlatformTypes, VersionDetails } from '../interfaces/config';
4
4
  import { Plugin as IPlugin, Options } from '../interfaces/plugin';
5
5
  import { Theme } from '../interfaces/theme';
@@ -27,7 +27,7 @@ export declare class Config implements IConfig {
27
27
  shell: string;
28
28
  theme?: Theme | undefined;
29
29
  topicSeparator: ' ' | ':';
30
- updateConfig: NonNullable<Configuration['update']>;
30
+ updateConfig: NonNullable<OclifConfiguration['update']>;
31
31
  userAgent: string;
32
32
  userPJSON?: UserPJSON | undefined;
33
33
  valid: boolean;
@@ -117,26 +117,6 @@ export declare class Config implements IConfig {
117
117
  protected windowsUserprofileHome(): string | undefined;
118
118
  protected _shell(): string;
119
119
  private buildS3Config;
120
- /**
121
- * This method is responsible for locating the correct plugin to use for a named command id
122
- * It searches the {Config} registered commands to match either the raw command id or the command alias
123
- * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
124
- * create the same command or command alias.
125
- *
126
- * In the case of more than one found command, the function will select the command based on the order in which
127
- * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
128
- * is selected as the command to run.
129
- *
130
- * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
131
- * is present, this function defers to the core plugin.
132
- *
133
- * If there is not a core plugin command present, this function will return the first
134
- * plugin as discovered (will not change the order)
135
- *
136
- * @param commands commands to determine the priority of
137
- * @returns command instance {Command.Loadable} or undefined
138
- */
139
- private determinePriority;
140
120
  private getCmdLookupId;
141
121
  private getTopicLookupId;
142
122
  /**
@@ -39,6 +39,7 @@ const logger_1 = require("../logger");
39
39
  const module_loader_1 = require("../module-loader");
40
40
  const performance_1 = require("../performance");
41
41
  const settings_1 = require("../settings");
42
+ const determine_priority_1 = require("../util/determine-priority");
42
43
  const fs_1 = require("../util/fs");
43
44
  const os_1 = require("../util/os");
44
45
  const util_2 = require("../util/util");
@@ -532,7 +533,7 @@ class Config {
532
533
  options = ext;
533
534
  else if (ext)
534
535
  options.ext = ext;
535
- const template = this.updateConfig.s3.templates?.[options.platform ? 'target' : 'vanilla'][type] ?? '';
536
+ const template = this.updateConfig.s3?.templates?.[options.platform ? 'target' : 'vanilla'][type] ?? '';
536
537
  return ejs.render(template, { ...this, ...options });
537
538
  }
538
539
  s3Url(key) {
@@ -622,58 +623,6 @@ class Config {
622
623
  templates,
623
624
  };
624
625
  }
625
- /**
626
- * This method is responsible for locating the correct plugin to use for a named command id
627
- * It searches the {Config} registered commands to match either the raw command id or the command alias
628
- * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
629
- * create the same command or command alias.
630
- *
631
- * In the case of more than one found command, the function will select the command based on the order in which
632
- * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
633
- * is selected as the command to run.
634
- *
635
- * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
636
- * is present, this function defers to the core plugin.
637
- *
638
- * If there is not a core plugin command present, this function will return the first
639
- * plugin as discovered (will not change the order)
640
- *
641
- * @param commands commands to determine the priority of
642
- * @returns command instance {Command.Loadable} or undefined
643
- */
644
- determinePriority(commands) {
645
- const oclifPlugins = this.pjson.oclif?.plugins ?? [];
646
- const commandPlugins = commands.sort((a, b) => {
647
- const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
648
- const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
649
- const aIndex = oclifPlugins.indexOf(pluginAliasA);
650
- const bIndex = oclifPlugins.indexOf(pluginAliasB);
651
- // When both plugin types are 'core' plugins sort based on index
652
- if (a.pluginType === 'core' && b.pluginType === 'core') {
653
- // If b appears first in the pjson.plugins sort it first
654
- return aIndex - bIndex;
655
- }
656
- // if b is a core plugin and a is not sort b first
657
- if (b.pluginType === 'core' && a.pluginType !== 'core') {
658
- return 1;
659
- }
660
- // if a is a core plugin and b is not sort a first
661
- if (a.pluginType === 'core' && b.pluginType !== 'core') {
662
- return -1;
663
- }
664
- // if a is a jit plugin and b is not sort b first
665
- if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
666
- return 1;
667
- }
668
- // if b is a jit plugin and a is not sort a first
669
- if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
670
- return -1;
671
- }
672
- // neither plugin is core, so do not change the order
673
- return 0;
674
- });
675
- return commandPlugins[0];
676
- }
677
626
  getCmdLookupId(id) {
678
627
  if (this._commands.has(id))
679
628
  return id;
@@ -701,7 +650,7 @@ class Config {
701
650
  for (const plugin of plugins) {
702
651
  this.plugins.set(plugin.name, plugin);
703
652
  // Delete all commands from the legacy plugin so that we can re-add them.
704
- // This is necessary because this.determinePriority will pick the initial
653
+ // This is necessary because determinePriority will pick the initial
705
654
  // command that was added, which won't have been converted by PluginLegacy yet.
706
655
  for (const cmd of plugin.commands ?? []) {
707
656
  this._commands.delete(cmd.id);
@@ -722,7 +671,10 @@ class Config {
722
671
  for (const command of plugin.commands) {
723
672
  // set canonical command id
724
673
  if (this._commands.has(command.id)) {
725
- const prioritizedCommand = this.determinePriority([this._commands.get(command.id), command]);
674
+ const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
675
+ this._commands.get(command.id),
676
+ command,
677
+ ]);
726
678
  this._commands.set(prioritizedCommand.id, prioritizedCommand);
727
679
  }
728
680
  else {
@@ -739,7 +691,10 @@ class Config {
739
691
  }
740
692
  const handleAlias = (alias, hidden = false) => {
741
693
  if (this._commands.has(alias)) {
742
- const prioritizedCommand = this.determinePriority([this._commands.get(alias), command]);
694
+ const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
695
+ this._commands.get(alias),
696
+ command,
697
+ ]);
743
698
  this._commands.set(alias, { ...prioritizedCommand, id: alias });
744
699
  }
745
700
  else {
@@ -1,34 +1,11 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  const minimatch_1 = require("minimatch");
27
4
  const node_path_1 = require("node:path");
28
5
  const performance_1 = require("../performance");
29
6
  const fs_1 = require("../util/fs");
30
7
  const util_1 = require("../util/util");
31
- const Plugin = __importStar(require("./plugin"));
8
+ const plugin_1 = require("./plugin");
32
9
  const util_2 = require("./util");
33
10
  const debug = (0, util_2.makeDebug)();
34
11
  function findMatchingDependencies(dependencies, patterns) {
@@ -62,7 +39,7 @@ class PluginLoader {
62
39
  }
63
40
  else {
64
41
  const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
65
- rootPlugin = new Plugin.Plugin({ isRoot: true, pjson, root: this.options.root });
42
+ rootPlugin = new plugin_1.Plugin({ isRoot: true, pjson, root: this.options.root });
66
43
  await rootPlugin.load();
67
44
  marker?.addDetails({
68
45
  commandCount: rootPlugin.commands.length,
@@ -154,7 +131,7 @@ class PluginLoader {
154
131
  if (this.plugins.has(name))
155
132
  return;
156
133
  const pluginMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.load#${name}`);
157
- const instance = new Plugin.Plugin(opts);
134
+ const instance = new plugin_1.Plugin(opts);
158
135
  await instance.load();
159
136
  pluginMarker?.addDetails({
160
137
  commandCount: instance.commands.length,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Command } from '../command';
3
3
  import { Hook, Hooks } from './hooks';
4
- import { Configuration, PJSON, S3Templates } from './pjson';
4
+ import { OclifConfiguration, PJSON, S3Templates } from './pjson';
5
5
  import { Options, Plugin } from './plugin';
6
6
  import { Theme } from './theme';
7
7
  import { Topic } from './topic';
@@ -114,7 +114,7 @@ export interface Config {
114
114
  readonly theme?: Theme | undefined;
115
115
  topicSeparator: ' ' | ':';
116
116
  readonly topics: Topic[];
117
- readonly updateConfig: NonNullable<Configuration['update']>;
117
+ readonly updateConfig: NonNullable<OclifConfiguration['update']>;
118
118
  /**
119
119
  * user agent to use for http calls
120
120
  *
@@ -3,12 +3,12 @@ import { FlagInput } from './parser';
3
3
  * Infer the flags that are returned by Command.parse. This is useful for when you want to assign the flags as a class property.
4
4
  *
5
5
  * @example
6
- * export type StatusFlags = Interfaces.InferredFlags<typeof Status.flags & typeof Status.baseFlags>
6
+ * export type StatusFlags = Interfaces.InferredFlags<typeof Status.flags>
7
7
  *
8
8
  * export abstract class BaseCommand extends Command {
9
9
  * static enableJsonFlag = true
10
10
  *
11
- * static baseFlags = {
11
+ * static flags = {
12
12
  * config: Flags.string({
13
13
  * description: 'specify config file',
14
14
  * }),
@@ -17,6 +17,7 @@ import { FlagInput } from './parser';
17
17
  *
18
18
  * export default class Status extends BaseCommand {
19
19
  * static flags = {
20
+ * ...BaseCommand.flags,
20
21
  * force: Flags.boolean({char: 'f', description: 'a flag'}),
21
22
  * }
22
23
  *
@@ -74,7 +74,7 @@ export interface Hooks {
74
74
  preparse: {
75
75
  options: {
76
76
  argv: string[];
77
- options: Input<OutputFlags<any>, OutputFlags<any>, OutputFlags<any>>;
77
+ options: Input<OutputFlags<any>, OutputFlags<any>>;
78
78
  };
79
79
  return: string[];
80
80
  };
@@ -8,7 +8,7 @@ export type { Hook, Hooks } from './hooks';
8
8
  export type { Logger } from './logger';
9
9
  export type { Manifest } from './manifest';
10
10
  export type { Arg, BooleanFlag, CustomOptions, Deprecation, Flag, FlagDefinition, OptionFlag } from './parser';
11
- export type { Configuration, PJSON, S3, S3Templates, UserPJSON } from './pjson';
11
+ export type { OclifConfiguration, PJSON, S3, S3Templates, UserPJSON } from './pjson';
12
12
  export type { Options, Plugin, PluginOptions } from './plugin';
13
13
  export type { S3Manifest } from './s3-manifest';
14
14
  export type { Theme } from './theme';
@@ -426,9 +426,8 @@ export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches =
426
426
  }>>;
427
427
  };
428
428
  export type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
429
- export type Input<TFlags extends FlagOutput, BFlags extends FlagOutput, AFlags extends ArgOutput> = {
429
+ export type Input<TFlags extends FlagOutput, AFlags extends ArgOutput> = {
430
430
  flags?: FlagInput<TFlags>;
431
- baseFlags?: FlagInput<BFlags>;
432
431
  enableJsonFlag?: true | false;
433
432
  args?: ArgInput<AFlags>;
434
433
  strict?: boolean | undefined;
@@ -102,13 +102,14 @@ export type S3 = {
102
102
  folder?: string | undefined;
103
103
  gz?: boolean | undefined;
104
104
  host?: string | undefined;
105
+ indexVersionLimit?: number | undefined;
105
106
  templates?: {
106
107
  target: S3Templates;
107
108
  vanilla: S3Templates;
108
109
  } | undefined;
109
110
  xz?: boolean | undefined;
110
111
  };
111
- export type Configuration = {
112
+ export type OclifConfiguration = {
112
113
  /**
113
114
  * Flags in addition to --help that should trigger help output.
114
115
  */
@@ -237,7 +238,7 @@ export type Configuration = {
237
238
  [k: string]: {
238
239
  description?: string;
239
240
  hidden?: boolean;
240
- subtopics?: Configuration['topics'];
241
+ subtopics?: OclifConfiguration['topics'];
241
242
  };
242
243
  };
243
244
  update?: {
@@ -246,12 +247,12 @@ export type Configuration = {
246
247
  rollout?: number;
247
248
  };
248
249
  disableNpmLookup?: boolean;
249
- node: {
250
+ node?: {
250
251
  targets?: string[];
251
252
  version?: string;
252
253
  options?: string | string[];
253
254
  };
254
- s3: S3;
255
+ s3?: S3;
255
256
  };
256
257
  'warn-if-update-available'?: {
257
258
  authorization?: string;
@@ -296,6 +297,6 @@ export type PJSON = {
296
297
  [name: string]: string;
297
298
  };
298
299
  name: string;
299
- oclif: Configuration;
300
+ oclif: OclifConfiguration;
300
301
  version: string;
301
302
  };
@@ -1,3 +1,3 @@
1
1
  import { Input, OutputArgs, OutputFlags, ParserOutput } from '../interfaces/parser';
2
2
  export { flagUsages } from './help';
3
- export declare function parse<TFlags extends OutputFlags<any>, BFlags extends OutputFlags<any>, TArgs extends OutputArgs<any>>(argv: string[], options: Input<TFlags, BFlags, TArgs>): Promise<ParserOutput<TFlags, BFlags, TArgs>>;
3
+ export declare function parse<TFlags extends OutputFlags<any>, TArgs extends OutputArgs<any>>(argv: string[], options: Input<TFlags, TArgs>): Promise<ParserOutput<TFlags, TArgs>>;
@@ -1,2 +1,2 @@
1
1
  import { FlagInput, FlagOutput } from '../interfaces/parser';
2
- export declare function aggregateFlags<F extends FlagOutput, B extends FlagOutput>(flags: FlagInput<F> | undefined, baseFlags: FlagInput<B> | undefined, enableJsonFlag: boolean | undefined): FlagInput<F>;
2
+ export declare function aggregateFlags<F extends FlagOutput>(flags: FlagInput<F> | undefined, enableJsonFlag: boolean | undefined): FlagInput<F>;
@@ -6,8 +6,7 @@ const json = (0, flags_1.boolean)({
6
6
  description: 'Format output as json.',
7
7
  helpGroup: 'GLOBAL',
8
8
  });
9
- function aggregateFlags(flags, baseFlags, enableJsonFlag) {
10
- const combinedFlags = { ...baseFlags, ...flags };
11
- return (enableJsonFlag ? { json, ...combinedFlags } : combinedFlags);
9
+ function aggregateFlags(flags, enableJsonFlag) {
10
+ return (enableJsonFlag ? { json, ...flags } : flags);
12
11
  }
13
12
  exports.aggregateFlags = aggregateFlags;
@@ -6,8 +6,7 @@ const cache_default_value_1 = require("./cache-default-value");
6
6
  const ensure_arg_object_1 = require("./ensure-arg-object");
7
7
  const util_1 = require("./util");
8
8
  // In order to collect static properties up the inheritance chain, we need to recursively
9
- // access the prototypes until there's nothing left. This allows us to combine baseFlags
10
- // and flags as well as add in the json flag if enableJsonFlag is enabled.
9
+ // access the prototypes until there's nothing left.
11
10
  function mergePrototype(result, cmd) {
12
11
  const proto = Object.getPrototypeOf(cmd);
13
12
  const filteredProto = (0, util_1.pickBy)(proto, (v) => v !== undefined);
@@ -71,10 +70,10 @@ async function cacheCommand(uncachedCmd, plugin, respectNoCacheDefault = false)
71
70
  const cmd = mergePrototype(uncachedCmd, uncachedCmd);
72
71
  // @ts-expect-error because v2 commands have flags stored in _flags
73
72
  const uncachedFlags = cmd.flags ?? cmd._flags;
74
- // @ts-expect-error because v2 commands have base flags stored in _baseFlags
73
+ // @ts-expect-error because v2 commands have base flags stored in `_baseFlags` and v4 commands never have `baseFlags`
75
74
  const uncachedBaseFlags = cmd.baseFlags ?? cmd._baseFlags;
76
75
  const [flags, args] = await Promise.all([
77
- await cacheFlags((0, aggregate_flags_1.aggregateFlags)(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault),
76
+ await cacheFlags((0, aggregate_flags_1.aggregateFlags)({ ...uncachedFlags, ...uncachedBaseFlags }, cmd.enableJsonFlag), respectNoCacheDefault),
78
77
  await cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault),
79
78
  ]);
80
79
  const stdProperties = {
@@ -0,0 +1,21 @@
1
+ import { Command } from '../command';
2
+ /**
3
+ * This function is responsible for locating the correct plugin to use for a named command id
4
+ * It searches the {Config} registered commands to match either the raw command id or the command alias
5
+ * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
6
+ * create the same command or command alias.
7
+ *
8
+ * In the case of more than one found command, the function will select the command based on the order in which
9
+ * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
10
+ * is selected as the command to run.
11
+ *
12
+ * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
13
+ * is present, this function defers to the core plugin.
14
+ *
15
+ * If there is not a core plugin command present, this function will return the first
16
+ * plugin as discovered (will not change the order)
17
+ *
18
+ * @param commands commands to determine the priority of
19
+ * @returns command instance {Command.Loadable} or undefined
20
+ */
21
+ export declare function determinePriority(plugins: string[], commands: Command.Loadable[]): Command.Loadable;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determinePriority = void 0;
4
+ /**
5
+ * This function is responsible for locating the correct plugin to use for a named command id
6
+ * It searches the {Config} registered commands to match either the raw command id or the command alias
7
+ * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
8
+ * create the same command or command alias.
9
+ *
10
+ * In the case of more than one found command, the function will select the command based on the order in which
11
+ * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
12
+ * is selected as the command to run.
13
+ *
14
+ * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
15
+ * is present, this function defers to the core plugin.
16
+ *
17
+ * If there is not a core plugin command present, this function will return the first
18
+ * plugin as discovered (will not change the order)
19
+ *
20
+ * @param commands commands to determine the priority of
21
+ * @returns command instance {Command.Loadable} or undefined
22
+ */
23
+ function determinePriority(plugins, commands) {
24
+ const commandPlugins = commands.sort((a, b) => {
25
+ const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
26
+ const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
27
+ const aIndex = plugins.indexOf(pluginAliasA);
28
+ const bIndex = plugins.indexOf(pluginAliasB);
29
+ // When both plugin types are 'core' plugins sort based on index
30
+ if (a.pluginType === 'core' && b.pluginType === 'core') {
31
+ // If b appears first in the pjson.plugins sort it first
32
+ return aIndex - bIndex;
33
+ }
34
+ // if b is a core plugin and a is not sort b first
35
+ if (b.pluginType === 'core' && a.pluginType !== 'core') {
36
+ return 1;
37
+ }
38
+ // if a is a core plugin and b is not sort a first
39
+ if (a.pluginType === 'core' && b.pluginType !== 'core') {
40
+ return -1;
41
+ }
42
+ // if a is a jit plugin and b is not sort b first
43
+ if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
44
+ return 1;
45
+ }
46
+ // if b is a jit plugin and a is not sort a first
47
+ if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
48
+ return -1;
49
+ }
50
+ // neither plugin is core, so do not change the order
51
+ return 0;
52
+ });
53
+ return commandPlugins[0];
54
+ }
55
+ exports.determinePriority = determinePriority;
package/lib/ux/theme.d.ts CHANGED
@@ -6,4 +6,4 @@ import { StandardAnsi, Theme } from '../interfaces/theme';
6
6
  * @returns colorized string
7
7
  */
8
8
  export declare function colorize(color: string | StandardAnsi | undefined, text: string): string;
9
- export declare function parseTheme(theme: Record<string, string>): Theme;
9
+ export declare function parseTheme(theme: Record<string, string | Record<string, string>>): Theme;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.0.0-beta.8",
4
+ "version": "4.0.0-beta.9",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -28,6 +28,7 @@
28
28
  "@oclif/plugin-help": "^6",
29
29
  "@oclif/plugin-plugins": "^5",
30
30
  "@oclif/prettier-config": "^0.2.1",
31
+ "@oclif/test": "^4",
31
32
  "@types/benchmark": "^2.1.5",
32
33
  "@types/chai": "^4.3.11",
33
34
  "@types/chai-as-promised": "^7.1.8",
@@ -57,7 +58,7 @@
57
58
  "nyc": "^15.1.0",
58
59
  "prettier": "^3.2.5",
59
60
  "shx": "^0.3.4",
60
- "sinon": "^17",
61
+ "sinon": "^18",
61
62
  "ts-node": "^10.9.2",
62
63
  "tsd": "^0.31.0",
63
64
  "typescript": "^5"
@@ -112,20 +113,18 @@
112
113
  },
113
114
  "scripts": {
114
115
  "build": "shx rm -rf lib && tsc",
115
- "commitlint": "commitlint",
116
116
  "compile": "tsc",
117
117
  "format": "prettier --write \"+(src|test)/**/*.+(ts|js|json)\"",
118
118
  "lint": "eslint . --ext .ts",
119
119
  "posttest": "yarn lint && yarn test:circular-deps",
120
120
  "prepack": "yarn run build",
121
121
  "prepare": "husky",
122
- "pretest": "yarn build && tsc -p test --noEmit --skipLibCheck",
123
- "test:circular-deps": "madge lib/ -c",
122
+ "test:circular-deps": "yarn build && madge lib/ -c",
124
123
  "test:debug": "nyc mocha --debug-brk --inspect \"test/**/*.test.ts\"",
125
124
  "test:integration": "mocha --forbid-only \"test/**/*.integration.ts\" --parallel --timeout 1200000",
126
125
  "test:interoperability": "cross-env DEBUG=integration:* ts-node test/integration/interop.ts",
127
126
  "test:perf": "ts-node test/perf/parser.perf.ts",
128
- "test": "nyc mocha --forbid-only \"test/**/*.test.ts\""
127
+ "test": "nyc mocha --forbid-only \"test/**/*.test.ts\" --parallel"
129
128
  },
130
129
  "types": "lib/index.d.ts"
131
130
  }