@oclif/core 3.13.0 → 3.13.2

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.
@@ -1,6 +1,7 @@
1
- import { Plugin } from '../interfaces';
1
+ import { PJSON, Plugin } from './interfaces';
2
2
  type CacheContents = {
3
3
  rootPlugin: Plugin;
4
+ exitCodes: PJSON.Plugin['oclif']['exitCodes'];
4
5
  };
5
6
  type ValueOf<T> = T[keyof T];
6
7
  /**
@@ -10,5 +11,6 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
10
11
  static instance: Cache;
11
12
  static getInstance(): Cache;
12
13
  get(key: 'rootPlugin'): Plugin | undefined;
14
+ get(key: 'exitCodes'): PJSON.Plugin['oclif']['exitCodes'] | undefined;
13
15
  }
14
16
  export {};
@@ -32,6 +32,7 @@ const is_wsl_1 = __importDefault(require("is-wsl"));
32
32
  const node_os_1 = require("node:os");
33
33
  const node_path_1 = require("node:path");
34
34
  const node_url_1 = require("node:url");
35
+ const cache_1 = __importDefault(require("../cache"));
35
36
  const cli_ux_1 = require("../cli-ux");
36
37
  const theme_1 = require("../cli-ux/theme");
37
38
  const errors_1 = require("../errors");
@@ -42,7 +43,6 @@ const settings_1 = require("../settings");
42
43
  const fs_1 = require("../util/fs");
43
44
  const os_1 = require("../util/os");
44
45
  const util_2 = require("../util/util");
45
- const cache_1 = __importDefault(require("./cache"));
46
46
  const plugin_loader_1 = __importDefault(require("./plugin-loader"));
47
47
  const ts_node_1 = require("./ts-node");
48
48
  const util_3 = require("./util");
@@ -265,7 +265,9 @@ class Config {
265
265
  this.rootPlugin = await this.pluginLoader.loadRoot();
266
266
  // Cache the root plugin so that we can reference it later when determining if
267
267
  // we should skip ts-node registration for an ESM plugin.
268
- cache_1.default.getInstance().set('rootPlugin', this.rootPlugin);
268
+ const cache = cache_1.default.getInstance();
269
+ cache.set('rootPlugin', this.rootPlugin);
270
+ cache.set('exitCodes', this.rootPlugin.pjson.oclif.exitCodes ?? {});
269
271
  this.root = this.rootPlugin.root;
270
272
  this.pjson = this.rootPlugin.pjson;
271
273
  this.plugins.set(this.rootPlugin.name, this.rootPlugin);
@@ -259,6 +259,8 @@ class Plugin {
259
259
  return ids;
260
260
  }
261
261
  async getCommandsDir() {
262
+ if (this.commandsDir)
263
+ return this.commandsDir;
262
264
  this.commandsDir = await (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this);
263
265
  return this.commandsDir;
264
266
  }
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.tsPath = exports.TS_CONFIGS = void 0;
7
7
  const node_path_1 = require("node:path");
8
+ const cache_1 = __importDefault(require("../cache"));
8
9
  const errors_1 = require("../errors");
9
10
  const settings_1 = require("../settings");
10
11
  const fs_1 = require("../util/fs");
11
12
  const util_1 = require("../util/util");
12
- const cache_1 = __importDefault(require("./cache"));
13
13
  const util_2 = require("./util");
14
14
  // eslint-disable-next-line new-cap
15
15
  const debug = (0, util_2.Debug)('ts-node');
@@ -8,6 +8,7 @@ const chalk_1 = __importDefault(require("chalk"));
8
8
  const clean_stack_1 = __importDefault(require("clean-stack"));
9
9
  const indent_string_1 = __importDefault(require("indent-string"));
10
10
  const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
11
+ const cache_1 = __importDefault(require("../../cache"));
11
12
  const screen_1 = require("../../screen");
12
13
  const config_1 = require("../config");
13
14
  /**
@@ -18,7 +19,7 @@ function addOclifExitCode(error, options) {
18
19
  ;
19
20
  error.oclif = {};
20
21
  }
21
- error.oclif.exit = options?.exit === undefined ? 2 : options.exit;
22
+ error.oclif.exit = options?.exit === undefined ? cache_1.default.getInstance().get('exitCodes')?.default ?? 2 : options.exit;
22
23
  return error;
23
24
  }
24
25
  exports.addOclifExitCode = addOclifExitCode;
@@ -11,6 +11,7 @@ export type CLIParseErrorOptions = {
11
11
  input?: ParserInput;
12
12
  output?: ParserOutput;
13
13
  };
14
+ exit?: number;
14
15
  };
15
16
  export type OutputArgs<T extends ParserInput['args']> = {
16
17
  [P in keyof T]: any;
@@ -29,6 +29,15 @@ export declare namespace PJSON {
29
29
  default?: string;
30
30
  description?: string;
31
31
  devPlugins?: string[];
32
+ exitCodes?: {
33
+ default?: number;
34
+ failedFlagParsing?: number;
35
+ failedFlagValidation?: number;
36
+ invalidArgsSpec?: number;
37
+ nonExistentFlag?: number;
38
+ requiredArgs?: number;
39
+ unexpectedArgs?: number;
40
+ };
32
41
  flexibleTaxonomy?: boolean;
33
42
  helpClass?: string;
34
43
  helpOptions?: HelpOptions;
@@ -1,6 +1,5 @@
1
1
  import { CLIError } from '../errors';
2
- import { Flag, OptionFlag } from '../interfaces';
3
- import { Arg, ArgInput, CLIParseErrorOptions } from '../interfaces/parser';
2
+ import { Arg, ArgInput, CLIParseErrorOptions, OptionFlag } from '../interfaces/parser';
4
3
  export { CLIError } from '../errors';
5
4
  export type Validation = {
6
5
  name: string;
@@ -16,32 +15,26 @@ export declare class CLIParseError extends CLIError {
16
15
  }
17
16
  export declare class InvalidArgsSpecError extends CLIParseError {
18
17
  args: ArgInput;
19
- constructor({ args, parse }: CLIParseErrorOptions & {
18
+ constructor({ args, exit, parse }: CLIParseErrorOptions & {
20
19
  args: ArgInput;
21
20
  });
22
21
  }
23
22
  export declare class RequiredArgsError extends CLIParseError {
24
23
  args: Arg<any>[];
25
- constructor({ args, flagsWithMultiple, parse, }: CLIParseErrorOptions & {
24
+ constructor({ args, exit, flagsWithMultiple, parse, }: CLIParseErrorOptions & {
26
25
  args: Arg<any>[];
27
26
  flagsWithMultiple?: string[];
28
27
  });
29
28
  }
30
- export declare class RequiredFlagError extends CLIParseError {
31
- flag: Flag<any>;
32
- constructor({ flag, parse }: CLIParseErrorOptions & {
33
- flag: Flag<any>;
34
- });
35
- }
36
29
  export declare class UnexpectedArgsError extends CLIParseError {
37
30
  args: unknown[];
38
- constructor({ args, parse }: CLIParseErrorOptions & {
31
+ constructor({ args, exit, parse }: CLIParseErrorOptions & {
39
32
  args: unknown[];
40
33
  });
41
34
  }
42
35
  export declare class NonExistentFlagsError extends CLIParseError {
43
36
  flags: string[];
44
- constructor({ flags, parse }: CLIParseErrorOptions & {
37
+ constructor({ exit, flags, parse }: CLIParseErrorOptions & {
45
38
  flags: string[];
46
39
  });
47
40
  }
@@ -52,7 +45,13 @@ export declare class ArgInvalidOptionError extends CLIParseError {
52
45
  constructor(arg: Arg<any>, input: string);
53
46
  }
54
47
  export declare class FailedFlagValidationError extends CLIParseError {
55
- constructor({ failed, parse }: CLIParseErrorOptions & {
48
+ constructor({ exit, failed, parse }: CLIParseErrorOptions & {
56
49
  failed: Validation[];
57
50
  });
58
51
  }
52
+ export declare class FailedFlagParsingError extends CLIParseError {
53
+ constructor({ flag, message }: {
54
+ flag: string;
55
+ message: string;
56
+ });
57
+ }
@@ -3,40 +3,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
6
+ exports.FailedFlagParsingError = exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const cache_1 = __importDefault(require("../cache"));
8
9
  const list_1 = require("../cli-ux/list");
9
10
  const errors_1 = require("../errors");
10
11
  const util_1 = require("../util/util");
11
- const help_1 = require("./help");
12
12
  var errors_2 = require("../errors");
13
13
  Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
14
14
  class CLIParseError extends errors_1.CLIError {
15
15
  parse;
16
16
  constructor(options) {
17
17
  options.message += '\nSee more help with --help';
18
- super(options.message);
18
+ super(options.message, { exit: options.exit });
19
19
  this.parse = options.parse;
20
20
  }
21
21
  }
22
22
  exports.CLIParseError = CLIParseError;
23
23
  class InvalidArgsSpecError extends CLIParseError {
24
24
  args;
25
- constructor({ args, parse }) {
25
+ constructor({ args, exit, parse }) {
26
26
  let message = 'Invalid argument spec';
27
27
  const namedArgs = Object.values(args).filter((a) => a.name);
28
28
  if (namedArgs.length > 0) {
29
29
  const list = (0, list_1.renderList)(namedArgs.map((a) => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
30
30
  message += `:\n${list}`;
31
31
  }
32
- super({ message, parse });
32
+ super({ exit: cache_1.default.getInstance().get('exitCodes')?.invalidArgsSpec ?? exit, message, parse });
33
33
  this.args = args;
34
34
  }
35
35
  }
36
36
  exports.InvalidArgsSpecError = InvalidArgsSpecError;
37
37
  class RequiredArgsError extends CLIParseError {
38
38
  args;
39
- constructor({ args, flagsWithMultiple, parse, }) {
39
+ constructor({ args, exit, flagsWithMultiple, parse, }) {
40
40
  let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
41
41
  const namedArgs = args.filter((a) => a.name);
42
42
  if (namedArgs.length > 0) {
@@ -48,35 +48,25 @@ class RequiredArgsError extends CLIParseError {
48
48
  message += `\n\nNote: ${flags} allow${flagsWithMultiple.length === 1 ? 's' : ''} multiple values. Because of this you need to provide all arguments before providing ${flagsWithMultiple.length === 1 ? 'that flag' : 'those flags'}.`;
49
49
  message += '\nAlternatively, you can use "--" to signify the end of the flags and the beginning of arguments.';
50
50
  }
51
- super({ message, parse });
51
+ super({ exit: cache_1.default.getInstance().get('exitCodes')?.requiredArgs ?? exit, message, parse });
52
52
  this.args = args;
53
53
  }
54
54
  }
55
55
  exports.RequiredArgsError = RequiredArgsError;
56
- class RequiredFlagError extends CLIParseError {
57
- flag;
58
- constructor({ flag, parse }) {
59
- const usage = (0, list_1.renderList)((0, help_1.flagUsages)([flag], { displayRequired: false }));
60
- const message = `Missing required flag:\n${usage}`;
61
- super({ message, parse });
62
- this.flag = flag;
63
- }
64
- }
65
- exports.RequiredFlagError = RequiredFlagError;
66
56
  class UnexpectedArgsError extends CLIParseError {
67
57
  args;
68
- constructor({ args, parse }) {
58
+ constructor({ args, exit, parse }) {
69
59
  const message = `Unexpected argument${args.length === 1 ? '' : 's'}: ${args.join(', ')}`;
70
- super({ message, parse });
60
+ super({ exit: cache_1.default.getInstance().get('exitCodes')?.unexpectedArgs ?? exit, message, parse });
71
61
  this.args = args;
72
62
  }
73
63
  }
74
64
  exports.UnexpectedArgsError = UnexpectedArgsError;
75
65
  class NonExistentFlagsError extends CLIParseError {
76
66
  flags;
77
- constructor({ flags, parse }) {
67
+ constructor({ exit, flags, parse }) {
78
68
  const message = `Nonexistent flag${flags.length === 1 ? '' : 's'}: ${flags.join(', ')}`;
79
- super({ message, parse });
69
+ super({ exit: cache_1.default.getInstance().get('exitCodes')?.nonExistentFlag ?? exit, message, parse });
80
70
  this.flags = flags;
81
71
  }
82
72
  }
@@ -96,12 +86,22 @@ class ArgInvalidOptionError extends CLIParseError {
96
86
  }
97
87
  exports.ArgInvalidOptionError = ArgInvalidOptionError;
98
88
  class FailedFlagValidationError extends CLIParseError {
99
- constructor({ failed, parse }) {
89
+ constructor({ exit, failed, parse }) {
100
90
  const reasons = failed.map((r) => r.reason);
101
91
  const deduped = (0, util_1.uniq)(reasons);
102
92
  const errString = deduped.length === 1 ? 'error' : 'errors';
103
93
  const message = `The following ${errString} occurred:\n ${chalk_1.default.dim(deduped.join('\n '))}`;
104
- super({ message, parse });
94
+ super({ exit: cache_1.default.getInstance().get('exitCodes')?.failedFlagValidation ?? exit, message, parse });
105
95
  }
106
96
  }
107
97
  exports.FailedFlagValidationError = FailedFlagValidationError;
98
+ class FailedFlagParsingError extends CLIParseError {
99
+ constructor({ flag, message }) {
100
+ super({
101
+ exit: cache_1.default.getInstance().get('exitCodes')?.failedFlagParsing,
102
+ message: `Parsing --${flag} \n\t${message}`,
103
+ parse: {},
104
+ });
105
+ }
106
+ }
107
+ exports.FailedFlagParsingError = FailedFlagParsingError;
@@ -257,8 +257,7 @@ class Parser {
257
257
  return await flag.parse(input, ctx, flag);
258
258
  }
259
259
  catch (error) {
260
- error.message = `Parsing --${flag.name} \n\t${error.message}\nSee more help with --help`;
261
- throw error;
260
+ throw new errors_1.FailedFlagParsingError({ flag: flag.name, message: error.message });
262
261
  }
263
262
  };
264
263
  /* Could add a valueFunction (if there is a value/env/default) and could metadata.
@@ -7,12 +7,18 @@ async function validate(parse) {
7
7
  let cachedResolvedFlags;
8
8
  function validateArgs() {
9
9
  if (parse.output.nonExistentFlags?.length > 0) {
10
- throw new errors_1.NonExistentFlagsError({ flags: parse.output.nonExistentFlags, parse });
10
+ throw new errors_1.NonExistentFlagsError({
11
+ flags: parse.output.nonExistentFlags,
12
+ parse,
13
+ });
11
14
  }
12
15
  const maxArgs = Object.keys(parse.input.args).length;
13
16
  if (parse.input.strict && parse.output.argv.length > maxArgs) {
14
17
  const extras = parse.output.argv.slice(maxArgs);
15
- throw new errors_1.UnexpectedArgsError({ args: extras, parse });
18
+ throw new errors_1.UnexpectedArgsError({
19
+ args: extras,
20
+ parse,
21
+ });
16
22
  }
17
23
  const missingRequiredArgs = [];
18
24
  let hasOptional = false;
@@ -23,7 +29,10 @@ async function validate(parse) {
23
29
  else if (hasOptional) {
24
30
  // (required arg) check whether an optional has occurred before
25
31
  // optionals should follow required, not before
26
- throw new errors_1.InvalidArgsSpecError({ args: parse.input.args, parse });
32
+ throw new errors_1.InvalidArgsSpecError({
33
+ args: parse.input.args,
34
+ parse,
35
+ });
27
36
  }
28
37
  if (arg.required && !parse.output.args[name] && parse.output.args[name] !== 0) {
29
38
  missingRequiredArgs.push(arg);
@@ -33,7 +42,11 @@ async function validate(parse) {
33
42
  const flagsWithMultiple = Object.entries(parse.input.flags)
34
43
  .filter(([_, flagDef]) => flagDef.type === 'option' && Boolean(flagDef.multiple))
35
44
  .map(([name]) => name);
36
- throw new errors_1.RequiredArgsError({ args: missingRequiredArgs, flagsWithMultiple, parse });
45
+ throw new errors_1.RequiredArgsError({
46
+ args: missingRequiredArgs,
47
+ flagsWithMultiple,
48
+ parse,
49
+ });
37
50
  }
38
51
  }
39
52
  async function validateFlags() {
@@ -57,7 +70,10 @@ async function validate(parse) {
57
70
  const results = await Promise.all(promises);
58
71
  const failed = results.filter((r) => r.status === 'failed');
59
72
  if (failed.length > 0)
60
- throw new errors_1.FailedFlagValidationError({ failed, parse });
73
+ throw new errors_1.FailedFlagValidationError({
74
+ failed,
75
+ parse,
76
+ });
61
77
  }
62
78
  async function resolveFlags(flags) {
63
79
  if (cachedResolvedFlags)
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": "3.13.0",
4
+ "version": "3.13.2",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
File without changes