@oclif/core 3.26.6 → 4.0.0-beta.10

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.
Files changed (124) hide show
  1. package/lib/args.d.ts +4 -4
  2. package/lib/cache.d.ts +3 -3
  3. package/lib/cache.js +1 -1
  4. package/lib/command.d.ts +18 -18
  5. package/lib/command.js +12 -21
  6. package/lib/config/config.d.ts +14 -40
  7. package/lib/config/config.js +120 -153
  8. package/lib/config/plugin-loader.d.ts +6 -6
  9. package/lib/config/plugin-loader.js +4 -28
  10. package/lib/config/plugin.d.ts +3 -3
  11. package/lib/config/plugin.js +7 -11
  12. package/lib/config/ts-path.d.ts +1 -1
  13. package/lib/config/ts-path.js +1 -2
  14. package/lib/config/util.d.ts +1 -1
  15. package/lib/config/util.js +5 -21
  16. package/lib/errors/error.js +5 -8
  17. package/lib/errors/errors/cli.d.ts +5 -5
  18. package/lib/errors/errors/cli.js +5 -5
  19. package/lib/errors/errors/pretty-print.d.ts +2 -2
  20. package/lib/errors/errors/pretty-print.js +2 -2
  21. package/lib/errors/exit.d.ts +1 -0
  22. package/lib/errors/exit.js +8 -0
  23. package/lib/errors/handle.js +4 -11
  24. package/lib/errors/index.d.ts +1 -3
  25. package/lib/errors/index.js +5 -12
  26. package/lib/errors/warn.d.ts +5 -0
  27. package/lib/errors/warn.js +10 -5
  28. package/lib/execute.js +1 -1
  29. package/lib/flags.d.ts +4 -4
  30. package/lib/{cli-ux/flush.js → flush.js} +2 -2
  31. package/lib/help/command.js +6 -5
  32. package/lib/help/formatter.d.ts +3 -3
  33. package/lib/help/formatter.js +8 -9
  34. package/lib/help/index.d.ts +1 -0
  35. package/lib/help/index.js +23 -17
  36. package/lib/help/root.js +3 -3
  37. package/lib/index.d.ts +6 -7
  38. package/lib/index.js +8 -12
  39. package/lib/interfaces/config.d.ts +9 -20
  40. package/lib/interfaces/errors.d.ts +5 -5
  41. package/lib/interfaces/flags.d.ts +2 -2
  42. package/lib/interfaces/index.d.ts +2 -1
  43. package/lib/interfaces/logger.d.ts +9 -0
  44. package/lib/interfaces/parser.d.ts +6 -6
  45. package/lib/interfaces/pjson.d.ts +217 -151
  46. package/lib/interfaces/plugin.d.ts +26 -24
  47. package/lib/interfaces/theme.d.ts +30 -19
  48. package/lib/interfaces/theme.js +2 -19
  49. package/lib/interfaces/topic.d.ts +2 -2
  50. package/lib/logger.d.ts +14 -0
  51. package/lib/logger.js +90 -0
  52. package/lib/main.js +5 -3
  53. package/lib/parser/errors.d.ts +1 -1
  54. package/lib/parser/errors.js +5 -5
  55. package/lib/parser/help.js +2 -2
  56. package/lib/parser/parse.js +2 -1
  57. package/lib/performance.js +3 -2
  58. package/lib/settings.d.ts +5 -11
  59. package/lib/util/determine-priority.d.ts +21 -0
  60. package/lib/util/determine-priority.js +55 -0
  61. package/lib/util/find-root.d.ts +1 -0
  62. package/lib/util/find-root.js +19 -19
  63. package/lib/util/fs.js +12 -0
  64. package/lib/util/ids.d.ts +1 -1
  65. package/lib/util/read-pjson.d.ts +7 -0
  66. package/lib/util/read-pjson.js +60 -0
  67. package/lib/util/read-tsconfig.js +3 -8
  68. package/lib/{cli-ux → ux}/action/base.d.ts +5 -7
  69. package/lib/{cli-ux → ux}/action/base.js +0 -3
  70. package/lib/{cli-ux → ux}/action/spinner.d.ts +5 -4
  71. package/lib/{cli-ux → ux}/action/spinner.js +16 -39
  72. package/lib/ux/action/types.d.ts +5 -0
  73. package/lib/ux/action/types.js +2 -0
  74. package/lib/ux/colorize-json.d.ts +28 -0
  75. package/lib/ux/colorize-json.js +67 -0
  76. package/lib/ux/index.d.ts +69 -0
  77. package/lib/ux/index.js +88 -0
  78. package/lib/{cli-ux → ux}/list.d.ts +1 -1
  79. package/lib/{cli-ux → ux}/list.js +1 -2
  80. package/lib/ux/theme.d.ts +9 -0
  81. package/lib/ux/theme.js +43 -0
  82. package/lib/ux/write.d.ts +2 -0
  83. package/lib/ux/write.js +22 -0
  84. package/package.json +37 -42
  85. package/flush.d.ts +0 -3
  86. package/flush.js +0 -1
  87. package/handle.js +0 -1
  88. package/lib/cli-ux/action/spinners.d.ts +0 -251
  89. package/lib/cli-ux/action/spinners.js +0 -374
  90. package/lib/cli-ux/action/types.d.ts +0 -5
  91. package/lib/cli-ux/config.d.ts +0 -25
  92. package/lib/cli-ux/config.js +0 -52
  93. package/lib/cli-ux/exit.d.ts +0 -8
  94. package/lib/cli-ux/exit.js +0 -16
  95. package/lib/cli-ux/index.d.ts +0 -133
  96. package/lib/cli-ux/index.js +0 -183
  97. package/lib/cli-ux/prompt.d.ts +0 -32
  98. package/lib/cli-ux/prompt.js +0 -185
  99. package/lib/cli-ux/stream.d.ts +0 -23
  100. package/lib/cli-ux/stream.js +0 -43
  101. package/lib/cli-ux/styled/index.d.ts +0 -4
  102. package/lib/cli-ux/styled/index.js +0 -36
  103. package/lib/cli-ux/styled/object.d.ts +0 -1
  104. package/lib/cli-ux/styled/object.js +0 -39
  105. package/lib/cli-ux/styled/progress.d.ts +0 -2
  106. package/lib/cli-ux/styled/progress.js +0 -8
  107. package/lib/cli-ux/styled/table.d.ts +0 -45
  108. package/lib/cli-ux/styled/table.js +0 -345
  109. package/lib/cli-ux/styled/tree.d.ts +0 -9
  110. package/lib/cli-ux/styled/tree.js +0 -37
  111. package/lib/cli-ux/theme.d.ts +0 -11
  112. package/lib/cli-ux/theme.js +0 -61
  113. package/lib/cli-ux/wait.d.ts +0 -2
  114. package/lib/cli-ux/wait.js +0 -5
  115. package/lib/cli-ux/write.d.ts +0 -8
  116. package/lib/cli-ux/write.js +0 -15
  117. package/lib/errors/config.d.ts +0 -6
  118. package/lib/errors/config.js +0 -38
  119. package/lib/errors/logger.d.ts +0 -8
  120. package/lib/errors/logger.js +0 -45
  121. /package/lib/{cli-ux/flush.d.ts → flush.d.ts} +0 -0
  122. /package/lib/{cli-ux/action/types.js → interfaces/logger.js} +0 -0
  123. /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
  124. /package/lib/{cli-ux → ux}/action/simple.js +0 -0
package/lib/args.d.ts CHANGED
@@ -21,14 +21,14 @@ import { Arg, ArgDefinition } from './interfaces/parser';
21
21
  export declare function custom<T = string, P = Record<string, unknown>>(defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>;
22
22
  export declare const boolean: ArgDefinition<boolean, Record<string, unknown>>;
23
23
  export declare const integer: ArgDefinition<number, {
24
- max?: number | undefined;
25
- min?: number | undefined;
24
+ max?: number;
25
+ min?: number;
26
26
  }>;
27
27
  export declare const directory: ArgDefinition<string, {
28
- exists?: boolean | undefined;
28
+ exists?: boolean;
29
29
  }>;
30
30
  export declare const file: ArgDefinition<string, {
31
- exists?: boolean | undefined;
31
+ exists?: boolean;
32
32
  }>;
33
33
  /**
34
34
  * Initializes a string as a URL. Throws an error
package/lib/cache.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Config } from './config/config';
2
- import { PJSON, 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: PJSON.Plugin['oclif']['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'): PJSON.Plugin['oclif']['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
@@ -109,7 +109,7 @@ export declare abstract class Command {
109
109
  log(message?: string, ...args: any[]): void;
110
110
  protected logJson(json: unknown): void;
111
111
  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>>;
112
+ protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, A>>;
113
113
  protected toErrorJson(err: unknown): any;
114
114
  protected toSuccessJson(result: unknown): any;
115
115
  warn(input: Error | string): Error | string;
@@ -143,15 +143,15 @@ export declare namespace Command {
143
143
  */
144
144
  type Cached = {
145
145
  [key: string]: unknown;
146
- aliasPermutations?: string[];
146
+ aliasPermutations?: string[] | undefined;
147
147
  aliases: string[];
148
148
  args: {
149
149
  [name: string]: Arg.Cached;
150
150
  };
151
- deprecateAliases?: boolean;
152
- deprecationOptions?: Deprecation;
153
- description?: string;
154
- examples?: Example[];
151
+ deprecateAliases?: boolean | undefined;
152
+ deprecationOptions?: Deprecation | undefined;
153
+ description?: string | undefined;
154
+ examples?: Example[] | undefined;
155
155
  flags: {
156
156
  [name: string]: Flag.Cached;
157
157
  };
@@ -159,22 +159,22 @@ export declare namespace Command {
159
159
  hidden: boolean;
160
160
  hiddenAliases: string[];
161
161
  id: string;
162
- isESM?: boolean;
163
- permutations?: string[];
164
- pluginAlias?: string;
165
- pluginName?: string;
166
- pluginType?: string;
167
- relativePath?: string[];
168
- state?: 'beta' | 'deprecated' | string;
169
- strict?: boolean;
170
- summary?: string;
171
- type?: string;
172
- usage?: string | string[];
162
+ isESM?: boolean | undefined;
163
+ permutations?: string[] | undefined;
164
+ pluginAlias?: string | undefined;
165
+ pluginName?: string | undefined;
166
+ pluginType?: string | undefined;
167
+ relativePath?: string[] | undefined;
168
+ state?: 'beta' | 'deprecated' | string | undefined;
169
+ strict?: boolean | undefined;
170
+ summary?: string | undefined;
171
+ type?: string | undefined;
172
+ usage?: string | string[] | undefined;
173
173
  };
174
174
  type Flag = IFlag<any>;
175
175
  namespace Flag {
176
176
  type Cached = Omit<Flag, 'input' | 'parse'> & (BooleanFlagProps | OptionFlagProps) & {
177
- hasDynamicHelp?: boolean;
177
+ hasDynamicHelp?: boolean | undefined;
178
178
  };
179
179
  type Any = Cached | Flag;
180
180
  }
package/lib/command.js CHANGED
@@ -27,18 +27,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Command = void 0;
30
- const chalk_1 = __importDefault(require("chalk"));
30
+ const ansis_1 = __importDefault(require("ansis"));
31
31
  const node_url_1 = require("node:url");
32
32
  const node_util_1 = require("node:util");
33
33
  const cache_1 = __importDefault(require("./cache"));
34
- const cli_ux_1 = require("./cli-ux");
35
34
  const config_1 = require("./config");
36
35
  const Errors = __importStar(require("./errors"));
37
36
  const util_1 = require("./help/util");
37
+ const logger_1 = require("./logger");
38
38
  const Parser = __importStar(require("./parser"));
39
39
  const aggregate_flags_1 = require("./util/aggregate-flags");
40
40
  const ids_1 = require("./util/ids");
41
41
  const util_2 = require("./util/util");
42
+ const ux_1 = require("./ux");
42
43
  const pjson = cache_1.default.getInstance().get('@oclif/core');
43
44
  /**
44
45
  * swallows stdout epipe errors
@@ -123,7 +124,7 @@ class Command {
123
124
  this.config = config;
124
125
  this.id = this.ctor.id;
125
126
  try {
126
- this.debug = require('debug')(this.id ? `${this.config.bin}:${this.id}` : this.config.bin);
127
+ this.debug = (0, logger_1.makeDebug)(this.id ? `${this.config.bin}:${this.id}` : this.config.bin);
127
128
  }
128
129
  catch {
129
130
  this.debug = () => {
@@ -147,6 +148,9 @@ class Command {
147
148
  opts = (0, node_url_1.fileURLToPath)(opts);
148
149
  }
149
150
  const config = await config_1.Config.load(opts || require.main?.filename || __dirname);
151
+ const cache = cache_1.default.getInstance();
152
+ if (!cache.has('config'))
153
+ cache.set('config', config);
150
154
  const cmd = new this(argv, config);
151
155
  if (!cmd.id) {
152
156
  const id = cmd.constructor.name.toLowerCase();
@@ -167,7 +171,7 @@ class Command {
167
171
  if (!err.message)
168
172
  throw err;
169
173
  try {
170
- cli_ux_1.ux.action.stop(chalk_1.default.bold.red('!'));
174
+ ux_1.ux.action.stop(ansis_1.default.bold.red('!'));
171
175
  }
172
176
  catch { }
173
177
  throw err;
@@ -179,22 +183,9 @@ class Command {
179
183
  exit(code = 0) {
180
184
  Errors.exit(code);
181
185
  }
182
- async finally(_) {
183
- try {
184
- const { config } = Errors;
185
- if (config.errorLogger)
186
- await config.errorLogger.flush();
187
- }
188
- catch (error) {
189
- console.error(error);
190
- }
191
- }
186
+ async finally(_) { }
192
187
  async init() {
193
188
  this.debug('init version: %s argv: %o', this.ctor._base, this.argv);
194
- if (this.config.debug)
195
- Errors.config.debug = true;
196
- if (this.config.errlog)
197
- Errors.config.errlog = this.config.errlog;
198
189
  const g = global;
199
190
  g['http-call'] = g['http-call'] || {};
200
191
  g['http-call'].userAgent = this.config.userAgent;
@@ -223,16 +214,16 @@ class Command {
223
214
  log(message = '', ...args) {
224
215
  if (!this.jsonEnabled()) {
225
216
  message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
226
- cli_ux_1.ux.info(message, ...args);
217
+ ux_1.ux.stdout(message, ...args);
227
218
  }
228
219
  }
229
220
  logJson(json) {
230
- cli_ux_1.ux.styledJSON(json);
221
+ ux_1.ux.stdout(ux_1.ux.colorizeJson(json, { pretty: true, theme: this.config.theme?.json }));
231
222
  }
232
223
  logToStderr(message = '', ...args) {
233
224
  if (!this.jsonEnabled()) {
234
225
  message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
235
- cli_ux_1.ux.logToStderr(message, ...args);
226
+ ux_1.ux.stderr(message, ...args);
236
227
  }
237
228
  }
238
229
  async parse(options, argv = this.argv) {
@@ -1,5 +1,5 @@
1
1
  import { Command } from '../command';
2
- import { Hook, Hooks, PJSON, Topic } 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';
@@ -7,30 +7,29 @@ export declare class Config implements IConfig {
7
7
  options: Options;
8
8
  arch: ArchTypes;
9
9
  bin: string;
10
- binAliases?: string[];
11
- binPath?: string;
10
+ binAliases?: string[] | undefined;
11
+ binPath?: string | undefined;
12
12
  cacheDir: string;
13
13
  channel: string;
14
14
  configDir: string;
15
15
  dataDir: string;
16
- debug: number;
17
16
  dirname: string;
18
- errlog: string;
19
17
  flexibleTaxonomy: boolean;
20
18
  home: string;
21
19
  isSingleCommandCLI: boolean;
22
20
  name: string;
23
- npmRegistry?: string;
24
- nsisCustomization?: string;
25
- pjson: PJSON.CLI;
21
+ npmRegistry?: string | undefined;
22
+ nsisCustomization?: string | undefined;
23
+ pjson: PJSON;
26
24
  platform: PlatformTypes;
27
25
  plugins: Map<string, IPlugin>;
28
26
  root: string;
29
27
  shell: string;
30
- theme?: Theme;
28
+ theme?: Theme | undefined;
31
29
  topicSeparator: ' ' | ':';
30
+ updateConfig: NonNullable<OclifConfiguration['update']>;
32
31
  userAgent: string;
33
- userPJSON?: PJSON.User;
32
+ userPJSON?: UserPJSON | undefined;
34
33
  valid: boolean;
35
34
  version: string;
36
35
  protected warned: boolean;
@@ -93,14 +92,11 @@ export declare class Config implements IConfig {
93
92
  loadPluginsAndCommands(opts?: {
94
93
  force: boolean;
95
94
  }): Promise<void>;
96
- loadThemes(): Promise<{
97
- file: string | undefined;
98
- theme: Theme | undefined;
99
- }>;
95
+ loadTheme(): Promise<Theme | undefined>;
100
96
  protected macosCacheDir(): string | undefined;
101
97
  runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable | null): Promise<T>;
102
98
  runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number, captureErrors?: boolean): Promise<Hook.Result<Hooks[T]['return']>>;
103
- s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
99
+ s3Key(type: keyof S3Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
104
100
  s3Url(key: string): string;
105
101
  scopedEnvVar(k: string): string | undefined;
106
102
  /**
@@ -116,35 +112,11 @@ export declare class Config implements IConfig {
116
112
  */
117
113
  scopedEnvVarKeys(k: string): string[];
118
114
  scopedEnvVarTrue(k: string): boolean;
119
- protected warn(err: {
120
- detail: string;
121
- name: string;
122
- } | Error | string, scope?: string): void;
123
115
  protected windowsHome(): string | undefined;
124
116
  protected windowsHomedriveHome(): string | undefined;
125
117
  protected windowsUserprofileHome(): string | undefined;
126
- protected _debug(): number;
127
118
  protected _shell(): string;
128
- /**
129
- * This method is responsible for locating the correct plugin to use for a named command id
130
- * It searches the {Config} registered commands to match either the raw command id or the command alias
131
- * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
132
- * create the same command or command alias.
133
- *
134
- * In the case of more than one found command, the function will select the command based on the order in which
135
- * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
136
- * is selected as the command to run.
137
- *
138
- * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
139
- * is present, this function defers to the core plugin.
140
- *
141
- * If there is not a core plugin command present, this function will return the first
142
- * plugin as discovered (will not change the order)
143
- *
144
- * @param commands commands to determine the priority of
145
- * @returns command instance {Command.Loadable} or undefined
146
- */
147
- private determinePriority;
119
+ private buildS3Config;
148
120
  private getCmdLookupId;
149
121
  private getTopicLookupId;
150
122
  /**
@@ -160,4 +132,6 @@ export declare class Config implements IConfig {
160
132
  private isJitPluginCommand;
161
133
  private loadCommands;
162
134
  private loadTopics;
135
+ private maybeAdjustDebugSetting;
136
+ private warn;
163
137
  }