@oclif/core 1.24.1 → 1.24.3

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.
@@ -677,9 +677,7 @@ async function toCached(c, plugin) {
677
677
  }
678
678
  }
679
679
  }
680
- // v2 commands have args as an object, so we need to normalize it to an array for forwards compatibility
681
- const normalized = (Array.isArray(c.args) ? c.args ?? [] : Object.values(c.args ?? {}));
682
- const argsPromise = normalized.map(async (a) => ({
680
+ const argsPromise = (0, util_3.ensureArgArray)(c.args).map(async (a) => ({
683
681
  name: a.name,
684
682
  description: a.description,
685
683
  required: a.required,
@@ -707,7 +705,7 @@ async function toCached(c, plugin) {
707
705
  args,
708
706
  };
709
707
  // do not include these properties in manifest
710
- const ignoreCommandProperties = ['plugin', '_flags', '_enableJsonFlag', '_globalFlags'];
708
+ const ignoreCommandProperties = ['plugin', '_flags', '_enableJsonFlag', '_globalFlags', '_baseFlags'];
711
709
  const stdKeys = Object.keys(stdProperties);
712
710
  const keysToAdd = Object.keys(c).filter(property => ![...stdKeys, ...ignoreCommandProperties].includes(property));
713
711
  const additionalProperties = {};
@@ -31,7 +31,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
31
31
  v.name = k;
32
32
  return v;
33
33
  }), f => [!f.char, f.char, f.name]);
34
- const args = (cmd.args || []).filter(a => !a.hidden);
34
+ const args = (0, util_1.ensureArgArray)(cmd.args).filter(a => !a.hidden);
35
35
  const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
36
36
  const body = generate({ cmd, flags, args }, header);
37
37
  // Generate can return a list of sections
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocOpts = void 0;
4
+ const util_1 = require("../util");
4
5
  /**
5
6
  * DocOpts - See http://docopt.org/.
6
7
  *
@@ -75,7 +76,7 @@ class DocOpts {
75
76
  toString() {
76
77
  const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
77
78
  if (this.cmd.args) {
78
- const a = this.cmd.args?.map(arg => `[${arg.name.toUpperCase()}]`) || [];
79
+ const a = (0, util_1.ensureArgArray)(this.cmd.args).map(arg => `[${arg.name.toUpperCase()}]`) || [];
79
80
  opts.push(...a);
80
81
  }
81
82
  try {
package/lib/main.js CHANGED
@@ -71,6 +71,6 @@ async function run(argv = process.argv.slice(2), options) {
71
71
  // command id.
72
72
  if (config.pjson.oclif.default === '.' && id === '.' && argv[0] === '.')
73
73
  argvSlice = ['.', ...argvSlice];
74
- await config.runCommand(id, argvSlice, cmd);
74
+ return config.runCommand(id, argvSlice, cmd);
75
75
  }
76
76
  exports.run = run;
package/lib/util.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ArgInput } from './interfaces';
1
2
  export declare function compact<T>(a: (T | undefined)[]): T[];
2
3
  export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
3
4
  type SortTypes = string | number | undefined | boolean;
@@ -7,4 +8,14 @@ export declare function isProd(): boolean;
7
8
  export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
8
9
  export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
9
10
  export declare function capitalize(s: string): string;
11
+ /**
12
+ * Ensure that the args are in an array instead of an object. This is required to ensure
13
+ * forwards compatibility with the new arg format in v2.
14
+ *
15
+ * @param args The args to ensure are in an array
16
+ * @returns ArgInput
17
+ */
18
+ export declare function ensureArgArray(args?: ArgInput | {
19
+ [name: string]: any;
20
+ }): ArgInput;
10
21
  export {};
package/lib/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
3
+ exports.ensureArgArray = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
4
4
  function compact(a) {
5
5
  return a.filter((a) => Boolean(a));
6
6
  }
@@ -62,3 +62,14 @@ function capitalize(s) {
62
62
  return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
63
63
  }
64
64
  exports.capitalize = capitalize;
65
+ /**
66
+ * Ensure that the args are in an array instead of an object. This is required to ensure
67
+ * forwards compatibility with the new arg format in v2.
68
+ *
69
+ * @param args The args to ensure are in an array
70
+ * @returns ArgInput
71
+ */
72
+ function ensureArgArray(args) {
73
+ return Array.isArray(args) ? args ?? [] : Object.entries(args ?? {}).map(([name, arg]) => ({ ...arg, name }));
74
+ }
75
+ exports.ensureArgArray = ensureArgArray;
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": "1.24.1",
4
+ "version": "1.24.3",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {