@oclif/core 3.0.0-beta.9 → 3.0.0

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 (142) hide show
  1. package/README.md +4 -2
  2. package/flush.d.ts +3 -0
  3. package/flush.js +1 -0
  4. package/handle.js +1 -0
  5. package/lib/args.d.ts +2 -2
  6. package/lib/args.js +17 -18
  7. package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
  8. package/lib/{ux → cli-ux}/action/base.js +126 -120
  9. package/lib/{ux → cli-ux}/action/simple.js +25 -30
  10. package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
  11. package/lib/{ux → cli-ux}/action/spinner.js +45 -37
  12. package/lib/{ux → cli-ux}/action/spinners.js +187 -187
  13. package/lib/cli-ux/action/types.d.ts +5 -0
  14. package/lib/cli-ux/action/types.js +2 -0
  15. package/lib/{ux → cli-ux}/config.d.ts +5 -5
  16. package/lib/{ux → cli-ux}/config.js +17 -17
  17. package/lib/{ux → cli-ux}/exit.js +3 -0
  18. package/lib/cli-ux/flush.d.ts +1 -0
  19. package/lib/cli-ux/flush.js +28 -0
  20. package/lib/cli-ux/index.d.ts +39 -0
  21. package/lib/{ux → cli-ux}/index.js +74 -88
  22. package/lib/{ux → cli-ux}/list.js +3 -3
  23. package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
  24. package/lib/{ux → cli-ux}/prompt.js +35 -25
  25. package/lib/{ux → cli-ux}/stream.d.ts +6 -6
  26. package/lib/{ux → cli-ux}/stream.js +11 -10
  27. package/lib/cli-ux/styled/index.d.ts +4 -0
  28. package/lib/cli-ux/styled/index.js +11 -0
  29. package/lib/{ux → cli-ux}/styled/object.js +7 -9
  30. package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
  31. package/lib/{ux → cli-ux}/styled/table.js +130 -133
  32. package/lib/{ux → cli-ux}/styled/tree.js +11 -13
  33. package/lib/cli-ux/wait.js +5 -0
  34. package/lib/command.d.ts +82 -88
  35. package/lib/command.js +196 -175
  36. package/lib/config/config.d.ts +89 -90
  37. package/lib/config/config.js +466 -566
  38. package/lib/config/index.d.ts +0 -1
  39. package/lib/config/index.js +1 -3
  40. package/lib/config/plugin-loader.d.ts +12 -12
  41. package/lib/config/plugin-loader.js +72 -56
  42. package/lib/config/plugin.d.ts +25 -24
  43. package/lib/config/plugin.js +188 -154
  44. package/lib/config/ts-node.d.ts +2 -1
  45. package/lib/config/ts-node.js +71 -58
  46. package/lib/config/util.d.ts +1 -11
  47. package/lib/config/util.js +6 -59
  48. package/lib/errors/config.d.ts +1 -1
  49. package/lib/errors/config.js +6 -6
  50. package/lib/errors/errors/cli.d.ts +7 -7
  51. package/lib/errors/errors/cli.js +20 -16
  52. package/lib/errors/errors/exit.d.ts +1 -4
  53. package/lib/errors/errors/exit.js +1 -1
  54. package/lib/errors/errors/module-load.d.ts +1 -4
  55. package/lib/errors/errors/module-load.js +1 -1
  56. package/lib/errors/errors/pretty-print.d.ts +1 -1
  57. package/lib/errors/errors/pretty-print.js +12 -10
  58. package/lib/errors/handle.d.ts +12 -2
  59. package/lib/errors/handle.js +26 -14
  60. package/lib/errors/index.d.ts +10 -10
  61. package/lib/errors/index.js +25 -24
  62. package/lib/errors/logger.d.ts +2 -2
  63. package/lib/errors/logger.js +14 -13
  64. package/lib/execute.d.ts +6 -6
  65. package/lib/execute.js +10 -9
  66. package/lib/flags.d.ts +103 -32
  67. package/lib/flags.js +79 -45
  68. package/lib/help/command.d.ts +16 -14
  69. package/lib/help/command.js +178 -163
  70. package/lib/help/docopts.d.ts +5 -5
  71. package/lib/help/docopts.js +50 -54
  72. package/lib/help/formatter.d.ts +37 -37
  73. package/lib/help/formatter.js +66 -55
  74. package/lib/help/index.d.ts +25 -21
  75. package/lib/help/index.js +169 -147
  76. package/lib/help/root.d.ts +1 -1
  77. package/lib/help/root.js +15 -17
  78. package/lib/help/util.d.ts +2 -8
  79. package/lib/help/util.js +8 -28
  80. package/lib/index.d.ts +19 -20
  81. package/lib/index.js +37 -43
  82. package/lib/interfaces/config.d.ts +67 -66
  83. package/lib/interfaces/errors.d.ts +5 -5
  84. package/lib/interfaces/help.d.ts +17 -17
  85. package/lib/interfaces/hooks.d.ts +49 -49
  86. package/lib/interfaces/index.d.ts +7 -7
  87. package/lib/interfaces/manifest.d.ts +1 -1
  88. package/lib/interfaces/parser.d.ts +175 -51
  89. package/lib/interfaces/pjson.d.ts +41 -41
  90. package/lib/interfaces/plugin.d.ts +47 -41
  91. package/lib/interfaces/s3-manifest.d.ts +7 -7
  92. package/lib/interfaces/topic.d.ts +1 -1
  93. package/lib/interfaces/ts-config.d.ts +7 -7
  94. package/lib/main.d.ts +2 -2
  95. package/lib/main.js +16 -16
  96. package/lib/module-loader.d.ts +67 -77
  97. package/lib/module-loader.js +183 -150
  98. package/lib/parser/errors.d.ts +7 -7
  99. package/lib/parser/errors.js +29 -22
  100. package/lib/parser/help.js +5 -5
  101. package/lib/parser/index.js +2 -2
  102. package/lib/parser/parse.d.ts +9 -6
  103. package/lib/parser/parse.js +253 -221
  104. package/lib/parser/validate.js +53 -33
  105. package/lib/performance.d.ts +43 -32
  106. package/lib/performance.js +133 -91
  107. package/lib/screen.js +2 -2
  108. package/lib/settings.d.ts +11 -12
  109. package/lib/settings.js +2 -2
  110. package/lib/util/aggregate-flags.d.ts +2 -0
  111. package/lib/util/aggregate-flags.js +13 -0
  112. package/lib/util/cache-command.d.ts +3 -0
  113. package/lib/util/cache-command.js +109 -0
  114. package/lib/util/cache-default-value.d.ts +2 -0
  115. package/lib/util/cache-default-value.js +28 -0
  116. package/lib/util/ensure-arg-object.d.ts +12 -0
  117. package/lib/util/ensure-arg-object.js +14 -0
  118. package/lib/util/fs.d.ts +7 -0
  119. package/lib/util/fs.js +54 -0
  120. package/lib/util/os.d.ts +19 -0
  121. package/lib/util/os.js +28 -0
  122. package/lib/{util.d.ts → util/util.d.ts} +7 -16
  123. package/lib/util/util.js +98 -0
  124. package/package.json +35 -37
  125. package/lib/util.js +0 -126
  126. package/lib/ux/flush.d.ts +0 -1
  127. package/lib/ux/flush.js +0 -27
  128. package/lib/ux/index.d.ts +0 -58
  129. package/lib/ux/styled/index.d.ts +0 -6
  130. package/lib/ux/styled/index.js +0 -13
  131. package/lib/ux/styled/json.d.ts +0 -1
  132. package/lib/ux/styled/json.js +0 -15
  133. package/lib/ux/wait.js +0 -7
  134. package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
  135. package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
  136. package/lib/{ux → cli-ux}/exit.d.ts +2 -2
  137. package/lib/{ux → cli-ux}/list.d.ts +0 -0
  138. package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
  139. package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
  140. package/lib/{ux → cli-ux}/styled/progress.js +0 -0
  141. package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
  142. /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.aggregateFlags = void 0;
4
+ const flags_1 = require("../flags");
5
+ const json = (0, flags_1.boolean)({
6
+ description: 'Format output as json.',
7
+ helpGroup: 'GLOBAL',
8
+ });
9
+ function aggregateFlags(flags, baseFlags, enableJsonFlag) {
10
+ const combinedFlags = { ...baseFlags, ...flags };
11
+ return (enableJsonFlag ? { json, ...combinedFlags } : combinedFlags);
12
+ }
13
+ exports.aggregateFlags = aggregateFlags;
@@ -0,0 +1,3 @@
1
+ import { Command } from '../command';
2
+ import { Plugin as IPlugin } from '../interfaces/plugin';
3
+ export declare function cacheCommand(uncachedCmd: Command.Class, plugin?: IPlugin, respectNoCacheDefault?: boolean): Promise<Command.Cached>;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cacheCommand = void 0;
4
+ const aggregate_flags_1 = require("./aggregate-flags");
5
+ const cache_default_value_1 = require("./cache-default-value");
6
+ const ensure_arg_object_1 = require("./ensure-arg-object");
7
+ const util_1 = require("./util");
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.
11
+ function mergePrototype(result, cmd) {
12
+ const proto = Object.getPrototypeOf(cmd);
13
+ const filteredProto = (0, util_1.pickBy)(proto, (v) => v !== undefined);
14
+ return Object.keys(proto).length > 0 ? mergePrototype({ ...filteredProto, ...result }, proto) : result;
15
+ }
16
+ async function cacheFlags(cmdFlags, respectNoCacheDefault) {
17
+ const promises = Object.entries(cmdFlags).map(async ([name, flag]) => [
18
+ name,
19
+ {
20
+ aliases: flag.aliases,
21
+ char: flag.char,
22
+ charAliases: flag.charAliases,
23
+ dependsOn: flag.dependsOn,
24
+ deprecateAliases: flag.deprecateAliases,
25
+ deprecated: flag.deprecated,
26
+ description: flag.description,
27
+ exclusive: flag.exclusive,
28
+ helpGroup: flag.helpGroup,
29
+ helpLabel: flag.helpLabel,
30
+ hidden: flag.hidden,
31
+ name,
32
+ noCacheDefault: flag.noCacheDefault,
33
+ relationships: flag.relationships,
34
+ required: flag.required,
35
+ summary: flag.summary,
36
+ ...(flag.type === 'boolean'
37
+ ? {
38
+ allowNo: flag.allowNo,
39
+ type: flag.type,
40
+ }
41
+ : {
42
+ default: await (0, cache_default_value_1.cacheDefaultValue)(flag, respectNoCacheDefault),
43
+ delimiter: flag.delimiter,
44
+ hasDynamicHelp: typeof flag.defaultHelp === 'function',
45
+ helpValue: flag.helpValue,
46
+ multiple: flag.multiple,
47
+ options: flag.options,
48
+ type: flag.type,
49
+ }),
50
+ },
51
+ ]);
52
+ return Object.fromEntries(await Promise.all(promises));
53
+ }
54
+ async function cacheArgs(cmdArgs, respectNoCacheDefault) {
55
+ const promises = Object.entries(cmdArgs).map(async ([name, arg]) => [
56
+ name,
57
+ {
58
+ default: await (0, cache_default_value_1.cacheDefaultValue)(arg, respectNoCacheDefault),
59
+ description: arg.description,
60
+ hidden: arg.hidden,
61
+ name,
62
+ noCacheDefault: arg.noCacheDefault,
63
+ options: arg.options,
64
+ required: arg.required,
65
+ },
66
+ ]);
67
+ return Object.fromEntries(await Promise.all(promises));
68
+ }
69
+ async function cacheCommand(uncachedCmd, plugin, respectNoCacheDefault = false) {
70
+ const cmd = mergePrototype(uncachedCmd, uncachedCmd);
71
+ const flags = await cacheFlags((0, aggregate_flags_1.aggregateFlags)(cmd.flags, cmd.baseFlags, cmd.enableJsonFlag), respectNoCacheDefault);
72
+ const args = await cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault);
73
+ const stdProperties = {
74
+ aliases: cmd.aliases || [],
75
+ args,
76
+ deprecateAliases: cmd.deprecateAliases,
77
+ deprecationOptions: cmd.deprecationOptions,
78
+ description: cmd.description,
79
+ examples: cmd.examples || cmd.example,
80
+ flags,
81
+ hasDynamicHelp: Object.values(flags).some((f) => f.hasDynamicHelp),
82
+ hidden: cmd.hidden,
83
+ id: cmd.id,
84
+ pluginAlias: plugin && plugin.alias,
85
+ pluginName: plugin && plugin.name,
86
+ pluginType: plugin && plugin.type,
87
+ state: cmd.state,
88
+ strict: cmd.strict,
89
+ summary: cmd.summary,
90
+ usage: cmd.usage,
91
+ };
92
+ // do not include these properties in manifest
93
+ const ignoreCommandProperties = [
94
+ 'plugin',
95
+ '_flags',
96
+ '_enableJsonFlag',
97
+ '_globalFlags',
98
+ '_baseFlags',
99
+ 'baseFlags',
100
+ '_--',
101
+ '_base',
102
+ ];
103
+ // Add in any additional properties that are not standard command properties.
104
+ const stdKeysAndIgnored = new Set([...Object.keys(stdProperties), ...ignoreCommandProperties]);
105
+ const keysToAdd = Object.keys(cmd).filter((property) => !stdKeysAndIgnored.has(property));
106
+ const additionalProperties = Object.fromEntries(keysToAdd.map((key) => [key, cmd[key]]));
107
+ return { ...stdProperties, ...additionalProperties };
108
+ }
109
+ exports.cacheCommand = cacheCommand;
@@ -0,0 +1,2 @@
1
+ import { Arg, OptionFlag } from '../interfaces/parser';
2
+ export declare const cacheDefaultValue: (flagOrArg: Arg<any> | OptionFlag<any>, respectNoCacheDefault: boolean) => Promise<any>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cacheDefaultValue = void 0;
4
+ // when no manifest exists, the default is calculated. This may throw, so we need to catch it
5
+ const cacheDefaultValue = async (flagOrArg, respectNoCacheDefault) => {
6
+ if (respectNoCacheDefault && flagOrArg.noCacheDefault)
7
+ return;
8
+ // Prefer the defaultHelp function (returns a friendly string for complex types)
9
+ if (typeof flagOrArg.defaultHelp === 'function') {
10
+ try {
11
+ return await flagOrArg.defaultHelp({ flags: {}, options: flagOrArg });
12
+ }
13
+ catch {
14
+ return;
15
+ }
16
+ }
17
+ // if not specified, try the default function
18
+ if (typeof flagOrArg.default === 'function') {
19
+ try {
20
+ return await flagOrArg.default({ flags: {}, options: flagOrArg });
21
+ }
22
+ catch { }
23
+ }
24
+ else {
25
+ return flagOrArg.default;
26
+ }
27
+ };
28
+ exports.cacheDefaultValue = cacheDefaultValue;
@@ -0,0 +1,12 @@
1
+ import { Command } from '../command';
2
+ import { ArgInput } from '../interfaces/parser';
3
+ /**
4
+ * Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
5
+ * defined args as an array.
6
+ *
7
+ * @param args Either an array of args or an object of args
8
+ * @returns ArgInput
9
+ */
10
+ export declare function ensureArgObject(args?: {
11
+ [name: string]: Command.Arg.Cached;
12
+ } | ArgInput | any[]): ArgInput;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureArgObject = void 0;
4
+ /**
5
+ * Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
6
+ * defined args as an array.
7
+ *
8
+ * @param args Either an array of args or an object of args
9
+ * @returns ArgInput
10
+ */
11
+ function ensureArgObject(args) {
12
+ return (Array.isArray(args) ? (args ?? []).reduce((x, y) => ({ ...x, [y.name]: y }), {}) : args ?? {});
13
+ }
14
+ exports.ensureArgObject = ensureArgObject;
@@ -0,0 +1,7 @@
1
+ export declare function requireJson<T>(...pathParts: string[]): T;
2
+ export declare function exists(path: string): Promise<boolean>;
3
+ export declare const dirExists: (input: string) => Promise<string>;
4
+ export declare const fileExists: (input: string) => Promise<string>;
5
+ export declare function readJson<T = unknown>(path: string): Promise<T>;
6
+ export declare function readJsonSync(path: string, parse: false): string;
7
+ export declare function readJsonSync<T = unknown>(path: string, parse?: true): T;
package/lib/util/fs.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readJsonSync = exports.readJson = exports.fileExists = exports.dirExists = exports.exists = exports.requireJson = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_path_1 = require("node:path");
7
+ const debug = require('debug');
8
+ function requireJson(...pathParts) {
9
+ return JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(...pathParts), 'utf8'));
10
+ }
11
+ exports.requireJson = requireJson;
12
+ async function exists(path) {
13
+ try {
14
+ await (0, promises_1.access)(path);
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ exports.exists = exists;
22
+ const dirExists = async (input) => {
23
+ if (!(await exists(input))) {
24
+ throw new Error(`No directory found at ${input}`);
25
+ }
26
+ const fileStat = await (0, promises_1.stat)(input);
27
+ if (!fileStat.isDirectory()) {
28
+ throw new Error(`${input} exists but is not a directory`);
29
+ }
30
+ return input;
31
+ };
32
+ exports.dirExists = dirExists;
33
+ const fileExists = async (input) => {
34
+ if (!(await exists(input))) {
35
+ throw new Error(`No file found at ${input}`);
36
+ }
37
+ const fileStat = await (0, promises_1.stat)(input);
38
+ if (!fileStat.isFile()) {
39
+ throw new Error(`${input} exists but is not a file`);
40
+ }
41
+ return input;
42
+ };
43
+ exports.fileExists = fileExists;
44
+ async function readJson(path) {
45
+ debug('config')('readJson %s', path);
46
+ const contents = await (0, promises_1.readFile)(path, 'utf8');
47
+ return JSON.parse(contents);
48
+ }
49
+ exports.readJson = readJson;
50
+ function readJsonSync(path, parse = true) {
51
+ const contents = (0, node_fs_1.readFileSync)(path, 'utf8');
52
+ return parse ? JSON.parse(contents) : contents;
53
+ }
54
+ exports.readJsonSync = readJsonSync;
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Call os.homedir() and return the result
4
+ *
5
+ * Wrapping this allows us to stub these in tests since os.homedir() is
6
+ * non-configurable and non-writable.
7
+ *
8
+ * @returns The user's home directory
9
+ */
10
+ export declare function getHomeDir(): string;
11
+ /**
12
+ * Call os.platform() and return the result
13
+ *
14
+ * Wrapping this allows us to stub these in tests since os.platform() is
15
+ * non-configurable and non-writable.
16
+ *
17
+ * @returns The process' platform
18
+ */
19
+ export declare function getPlatform(): NodeJS.Platform;
package/lib/util/os.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPlatform = exports.getHomeDir = void 0;
4
+ const node_os_1 = require("node:os");
5
+ /**
6
+ * Call os.homedir() and return the result
7
+ *
8
+ * Wrapping this allows us to stub these in tests since os.homedir() is
9
+ * non-configurable and non-writable.
10
+ *
11
+ * @returns The user's home directory
12
+ */
13
+ function getHomeDir() {
14
+ return (0, node_os_1.homedir)();
15
+ }
16
+ exports.getHomeDir = getHomeDir;
17
+ /**
18
+ * Call os.platform() and return the result
19
+ *
20
+ * Wrapping this allows us to stub these in tests since os.platform() is
21
+ * non-configurable and non-writable.
22
+ *
23
+ * @returns The process' platform
24
+ */
25
+ function getPlatform() {
26
+ return (0, node_os_1.platform)();
27
+ }
28
+ exports.getPlatform = getPlatform;
@@ -1,31 +1,22 @@
1
- import { Command } from './command';
2
- import { ArgInput } from './interfaces/parser';
3
1
  export declare function pickBy<T extends {
4
2
  [s: string]: T[keyof T];
5
3
  } | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
6
4
  export declare function compact<T>(a: (T | undefined)[]): T[];
7
5
  export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
8
6
  export declare function last<T>(arr?: T[]): T | undefined;
9
- type SortTypes = string | number | undefined | boolean;
7
+ type SortTypes = boolean | number | string | undefined;
10
8
  export declare function sortBy<T>(arr: T[], fn: (i: T) => SortTypes | SortTypes[]): T[];
11
9
  export declare function castArray<T>(input?: T | T[]): T[];
12
10
  export declare function isProd(): boolean;
13
11
  export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
14
12
  export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
15
13
  export declare function capitalize(s: string): string;
16
- export declare const dirExists: (input: string) => Promise<string>;
17
- export declare const fileExists: (input: string) => Promise<string>;
18
14
  export declare function isTruthy(input: string): boolean;
19
15
  export declare function isNotFalsy(input: string): boolean;
20
- export declare function requireJson<T>(...pathParts: string[]): T;
21
- /**
22
- * Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
23
- * defined args as an array.
24
- *
25
- * @param args Either an array of args or an object of args
26
- * @returns ArgInput
27
- */
28
- export declare function ensureArgObject(args?: any[] | ArgInput | {
29
- [name: string]: Command.Arg.Cached;
30
- }): ArgInput;
16
+ export declare function uniq<T>(arr: T[]): T[];
17
+ export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
18
+ [P in keyof T]: T[P];
19
+ }, fn: (i: T[keyof T], k: keyof T) => TResult): {
20
+ [P in keyof T]: TResult;
21
+ };
31
22
  export {};
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapValues = exports.uniq = exports.isNotFalsy = exports.isTruthy = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.last = exports.uniqBy = exports.compact = exports.pickBy = void 0;
4
+ function pickBy(obj, fn) {
5
+ return Object.entries(obj).reduce((o, [k, v]) => {
6
+ if (fn(v))
7
+ o[k] = v;
8
+ return o;
9
+ }, {});
10
+ }
11
+ exports.pickBy = pickBy;
12
+ function compact(a) {
13
+ // eslint-disable-next-line unicorn/prefer-native-coercion-functions
14
+ return a.filter((a) => Boolean(a));
15
+ }
16
+ exports.compact = compact;
17
+ function uniqBy(arr, fn) {
18
+ return arr.filter((a, i) => {
19
+ const aVal = fn(a);
20
+ return !arr.some((b, j) => j > i && fn(b) === aVal);
21
+ });
22
+ }
23
+ exports.uniqBy = uniqBy;
24
+ function last(arr) {
25
+ if (!arr)
26
+ return;
27
+ return arr.at(-1);
28
+ }
29
+ exports.last = last;
30
+ function compare(a, b) {
31
+ a = a === undefined ? 0 : a;
32
+ b = b === undefined ? 0 : b;
33
+ if (Array.isArray(a) && Array.isArray(b)) {
34
+ if (a.length === 0 && b.length === 0)
35
+ return 0;
36
+ const diff = compare(a[0], b[0]);
37
+ if (diff !== 0)
38
+ return diff;
39
+ return compare(a.slice(1), b.slice(1));
40
+ }
41
+ if (a < b)
42
+ return -1;
43
+ if (a > b)
44
+ return 1;
45
+ return 0;
46
+ }
47
+ function sortBy(arr, fn) {
48
+ return arr.sort((a, b) => compare(fn(a), fn(b)));
49
+ }
50
+ exports.sortBy = sortBy;
51
+ function castArray(input) {
52
+ if (input === undefined)
53
+ return [];
54
+ return Array.isArray(input) ? input : [input];
55
+ }
56
+ exports.castArray = castArray;
57
+ function isProd() {
58
+ return !['development', 'test'].includes(process.env.NODE_ENV ?? '');
59
+ }
60
+ exports.isProd = isProd;
61
+ function maxBy(arr, fn) {
62
+ if (arr.length === 0) {
63
+ return undefined;
64
+ }
65
+ return arr.reduce((maxItem, i) => {
66
+ const curr = fn(i);
67
+ const max = fn(maxItem);
68
+ return curr > max ? i : maxItem;
69
+ });
70
+ }
71
+ exports.maxBy = maxBy;
72
+ function sumBy(arr, fn) {
73
+ return arr.reduce((sum, i) => sum + fn(i), 0);
74
+ }
75
+ exports.sumBy = sumBy;
76
+ function capitalize(s) {
77
+ return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
78
+ }
79
+ exports.capitalize = capitalize;
80
+ function isTruthy(input) {
81
+ return ['1', 'true', 'y', 'yes'].includes(input.toLowerCase());
82
+ }
83
+ exports.isTruthy = isTruthy;
84
+ function isNotFalsy(input) {
85
+ return !['0', 'false', 'n', 'no'].includes(input.toLowerCase());
86
+ }
87
+ exports.isNotFalsy = isNotFalsy;
88
+ function uniq(arr) {
89
+ return [...new Set(arr)].sort();
90
+ }
91
+ exports.uniq = uniq;
92
+ function mapValues(obj, fn) {
93
+ return Object.entries(obj).reduce((o, [k, v]) => {
94
+ o[k] = fn(v, k);
95
+ return o;
96
+ }, {});
97
+ }
98
+ exports.mapValues = mapValues;
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "3.0.0-beta.9",
4
+ "version": "3.0.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
8
- "@types/cli-progress": "^3.11.0",
9
8
  "ansi-escapes": "^4.3.2",
10
9
  "ansi-styles": "^4.3.0",
11
10
  "cardinal": "^2.1.1",
@@ -28,32 +27,28 @@
28
27
  "strip-ansi": "^6.0.1",
29
28
  "supports-color": "^8.1.1",
30
29
  "supports-hyperlinks": "^2.2.0",
31
- "ts-node": "^10.9.1",
32
- "tslib": "^2.5.0",
33
30
  "widest-line": "^3.1.0",
34
31
  "wordwrap": "^1.0.0",
35
32
  "wrap-ansi": "^7.0.0"
36
33
  },
37
34
  "devDependencies": {
38
- "@commitlint/config-conventional": "^12.1.4",
35
+ "@commitlint/config-conventional": "^17.7.0",
39
36
  "@oclif/plugin-help": "^5.2.8",
40
37
  "@oclif/plugin-plugins": "^3.3.0",
41
- "@oclif/test": "^2.4.7",
38
+ "@oclif/prettier-config": "^0.2.1",
39
+ "@oclif/test": "^3.0.1",
42
40
  "@types/ansi-styles": "^3.2.1",
43
41
  "@types/benchmark": "^2.1.2",
44
42
  "@types/chai": "^4.3.4",
45
43
  "@types/chai-as-promised": "^7.1.5",
46
44
  "@types/clean-stack": "^2.1.1",
45
+ "@types/cli-progress": "^3.11.0",
47
46
  "@types/ejs": "^3.1.2",
48
- "@types/glob": "^8.1.0",
49
47
  "@types/indent-string": "^4.0.1",
50
48
  "@types/js-yaml": "^3.12.7",
51
- "@types/mocha": "^8.2.3",
52
- "@types/nock": "^11.1.0",
53
- "@types/node": "^16",
49
+ "@types/mocha": "^10.0.2",
50
+ "@types/node": "^18",
54
51
  "@types/node-notifier": "^8.0.2",
55
- "@types/proxyquire": "^1.3.28",
56
- "@types/shelljs": "^0.8.12",
57
52
  "@types/slice-ansi": "^4.0.0",
58
53
  "@types/strip-ansi": "^5.2.1",
59
54
  "@types/supports-color": "^8.1.1",
@@ -62,28 +57,36 @@
62
57
  "benchmark": "^2.1.4",
63
58
  "chai": "^4.3.7",
64
59
  "chai-as-promised": "^7.1.1",
65
- "commitlint": "^12.1.4",
60
+ "commitlint": "^17.7.2",
66
61
  "cross-env": "^7.0.3",
67
- "eslint": "^7.32.0",
68
- "eslint-config-oclif": "^4.0.0",
69
- "eslint-config-oclif-typescript": "^1.0.3",
70
- "fancy-test": "^2.0.16",
62
+ "eslint": "^8.50.0",
63
+ "eslint-config-oclif": "^5.0.0",
64
+ "eslint-config-oclif-typescript": "^2.0.1",
65
+ "eslint-config-prettier": "^9.0.0",
66
+ "eslint-plugin-perfectionist": "^2.1.0",
67
+ "fancy-test": "^3.0.1",
71
68
  "globby": "^11.1.0",
72
- "husky": "6",
69
+ "husky": "^8",
70
+ "lint-staged": "^14.0.1",
71
+ "madge": "^6.1.0",
73
72
  "mocha": "^10.2.0",
74
- "nock": "^13.3.0",
75
- "proxyquire": "^2.1.3",
76
- "shelljs": "^0.8.5",
73
+ "nyc": "^15.1.0",
74
+ "prettier": "^3.0.3",
77
75
  "shx": "^0.3.4",
78
76
  "sinon": "^11.1.2",
79
- "tsd": "^0.25.0",
80
- "typescript": "^4.9.5"
77
+ "ts-node": "^10.9.1",
78
+ "tsd": "^0.29.0",
79
+ "tslib": "^2.5.0",
80
+ "typescript": "^5"
81
81
  },
82
82
  "engines": {
83
- "node": ">=16.0.0"
83
+ "node": ">=18.0.0"
84
84
  },
85
85
  "files": [
86
- "/lib"
86
+ "/lib",
87
+ "/flush.js",
88
+ "/flush.d.ts",
89
+ "/handle.js"
87
90
  ],
88
91
  "homepage": "https://github.com/oclif/core",
89
92
  "keywords": [
@@ -91,14 +94,6 @@
91
94
  ],
92
95
  "license": "MIT",
93
96
  "main": "./lib/index.js",
94
- "exports": {
95
- ".": "./lib/index.js",
96
- "./execute": "./lib/execute.js",
97
- "./flush": "./lib/ux/flush.js",
98
- "./handle": "./lib/errors/handle.js",
99
- "./run": "./lib/main.js",
100
- "./settings": "./lib/settings.js"
101
- },
102
97
  "repository": "oclif/core",
103
98
  "oclif": {
104
99
  "bin": "oclif",
@@ -114,14 +109,17 @@
114
109
  "build": "shx rm -rf lib && tsc",
115
110
  "commitlint": "commitlint",
116
111
  "compile": "tsc",
117
- "lint": "eslint . --ext .ts --config .eslintrc",
118
- "posttest": "yarn lint",
112
+ "format": "prettier --write \"+(src|test)/**/*.+(ts|js|json)\"",
113
+ "lint": "eslint . --ext .ts",
114
+ "posttest": "yarn lint && yarn test:circular-deps",
119
115
  "prepack": "yarn run build",
120
- "pretest": "yarn build --noEmit && tsc -p test --noEmit --skipLibCheck",
116
+ "prepare": "husky install",
117
+ "pretest": "yarn build && tsc -p test --noEmit --skipLibCheck",
118
+ "test:circular-deps": "madge lib/ -c",
121
119
  "test:e2e": "mocha --forbid-only \"test/**/*.e2e.ts\" --parallel --timeout 1200000",
122
120
  "test:esm-cjs": "cross-env DEBUG=e2e:* ts-node test/integration/esm-cjs.ts",
123
121
  "test:perf": "ts-node test/perf/parser.perf.ts",
124
- "test": "mocha --forbid-only \"test/**/*.test.ts\""
122
+ "test": "nyc mocha --forbid-only \"test/**/*.test.ts\""
125
123
  },
126
124
  "types": "lib/index.d.ts"
127
125
  }