@oclif/core 3.0.0-beta.19 → 3.0.0-beta.20
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/args.js +5 -4
- package/lib/cli-ux/action/base.js +1 -1
- package/lib/cli-ux/config.js +2 -2
- package/lib/cli-ux/list.js +2 -2
- package/lib/cli-ux/styled/table.js +1 -1
- package/lib/command.js +4 -3
- package/lib/config/config.js +12 -10
- package/lib/config/plugin-loader.js +4 -3
- package/lib/config/plugin.js +12 -11
- package/lib/config/ts-node.js +4 -3
- package/lib/flags.js +3 -3
- package/lib/help/command.js +3 -2
- package/lib/help/docopts.js +2 -2
- package/lib/help/index.js +16 -16
- package/lib/help/root.js +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -2
- package/lib/parser/errors.js +2 -2
- package/lib/parser/help.js +2 -2
- package/lib/parser/parse.js +7 -7
- package/lib/parser/validate.js +2 -2
- package/lib/util/cache-command.js +4 -3
- package/lib/util/ensure-arg-object.d.ts +12 -0
- package/lib/util/ensure-arg-object.js +14 -0
- package/lib/util/fs.d.ts +7 -0
- package/lib/util/fs.js +54 -0
- package/lib/util/os.d.ts +19 -0
- package/lib/util/os.js +28 -0
- package/lib/util/util.d.ts +22 -0
- package/lib/util/util.js +98 -0
- package/package.json +4 -4
- package/lib/util/index.d.ts +0 -60
- package/lib/util/index.js +0 -185
package/lib/args.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
|
|
4
|
-
const
|
|
4
|
+
const fs_1 = require("./util/fs");
|
|
5
5
|
const node_url_1 = require("node:url");
|
|
6
|
+
const util_1 = require("./util/util");
|
|
6
7
|
function custom(defaults) {
|
|
7
8
|
return (options = {}) => ({
|
|
8
9
|
parse: async (i, _context, _opts) => i,
|
|
@@ -14,7 +15,7 @@ function custom(defaults) {
|
|
|
14
15
|
}
|
|
15
16
|
exports.custom = custom;
|
|
16
17
|
exports.boolean = custom({
|
|
17
|
-
parse: async (b) => Boolean(b) && (0,
|
|
18
|
+
parse: async (b) => Boolean(b) && (0, util_1.isNotFalsy)(b),
|
|
18
19
|
});
|
|
19
20
|
exports.integer = custom({
|
|
20
21
|
async parse(input, _, opts) {
|
|
@@ -31,14 +32,14 @@ exports.integer = custom({
|
|
|
31
32
|
exports.directory = custom({
|
|
32
33
|
async parse(input, _, opts) {
|
|
33
34
|
if (opts.exists)
|
|
34
|
-
return (0,
|
|
35
|
+
return (0, fs_1.dirExists)(input);
|
|
35
36
|
return input;
|
|
36
37
|
},
|
|
37
38
|
});
|
|
38
39
|
exports.file = custom({
|
|
39
40
|
async parse(input, _, opts) {
|
|
40
41
|
if (opts.exists)
|
|
41
|
-
return (0,
|
|
42
|
+
return (0, fs_1.fileExists)(input);
|
|
42
43
|
return input;
|
|
43
44
|
},
|
|
44
45
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActionBase = void 0;
|
|
4
4
|
const stream_1 = require("../stream");
|
|
5
|
-
const util_1 = require("../../util");
|
|
5
|
+
const util_1 = require("../../util/util");
|
|
6
6
|
const node_util_1 = require("node:util");
|
|
7
7
|
class ActionBase {
|
|
8
8
|
type;
|
package/lib/cli-ux/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config = exports.Config = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const fs_1 = require("../util/fs");
|
|
6
6
|
const simple_1 = tslib_1.__importDefault(require("./action/simple"));
|
|
7
7
|
const spinner_1 = tslib_1.__importDefault(require("./action/spinner"));
|
|
8
8
|
const g = global;
|
|
@@ -33,7 +33,7 @@ class Config {
|
|
|
33
33
|
}
|
|
34
34
|
exports.Config = Config;
|
|
35
35
|
function fetch() {
|
|
36
|
-
const major = (0,
|
|
36
|
+
const major = (0, fs_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
|
|
37
37
|
if (globals[major])
|
|
38
38
|
return globals[major];
|
|
39
39
|
globals[major] = new Config();
|
package/lib/cli-ux/list.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderList = void 0;
|
|
4
|
-
const
|
|
4
|
+
const util_1 = require("../util/util");
|
|
5
5
|
const screen_1 = require("../screen");
|
|
6
6
|
const wordwrap = require('wordwrap');
|
|
7
7
|
function linewrap(length, s) {
|
|
@@ -13,7 +13,7 @@ function renderList(items) {
|
|
|
13
13
|
if (items.length === 0) {
|
|
14
14
|
return '';
|
|
15
15
|
}
|
|
16
|
-
const maxLength = (0,
|
|
16
|
+
const maxLength = (0, util_1.maxBy)(items, (item) => item[0].length)?.[0].length ?? 0;
|
|
17
17
|
const lines = items.map((i) => {
|
|
18
18
|
let left = i[0];
|
|
19
19
|
let right = i[1];
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.table = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const F = tslib_1.__importStar(require("../../flags"));
|
|
6
|
-
const util_1 = require("../../util");
|
|
6
|
+
const util_1 = require("../../util/util");
|
|
7
7
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
8
|
const node_util_1 = require("node:util");
|
|
9
9
|
const natural_orderby_1 = require("natural-orderby");
|
package/lib/command.js
CHANGED
|
@@ -6,14 +6,15 @@ const Errors = tslib_1.__importStar(require("./errors"));
|
|
|
6
6
|
const Parser = tslib_1.__importStar(require("./parser"));
|
|
7
7
|
const node_util_1 = require("node:util");
|
|
8
8
|
const util_1 = require("./help/util");
|
|
9
|
-
const index_1 = require("./util/index");
|
|
10
9
|
const stream_1 = require("./cli-ux/stream");
|
|
11
10
|
const config_1 = require("./config");
|
|
12
11
|
const aggregate_flags_1 = require("./util/aggregate-flags");
|
|
13
12
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
13
|
const node_url_1 = require("node:url");
|
|
14
|
+
const fs_1 = require("./util/fs");
|
|
15
|
+
const util_2 = require("./util/util");
|
|
15
16
|
const cli_ux_1 = require("./cli-ux");
|
|
16
|
-
const pjson = (0,
|
|
17
|
+
const pjson = (0, fs_1.requireJson)(__dirname, '..', 'package.json');
|
|
17
18
|
/**
|
|
18
19
|
* swallows stdout epipe errors
|
|
19
20
|
* this occurs when stdout closes such as when piping to head
|
|
@@ -214,7 +215,7 @@ class Command {
|
|
|
214
215
|
}
|
|
215
216
|
const deprecateAliases = flagDef?.deprecateAliases;
|
|
216
217
|
if (deprecateAliases) {
|
|
217
|
-
const aliases = (0,
|
|
218
|
+
const aliases = (0, util_2.uniq)([...(flagDef?.aliases ?? []), ...(flagDef?.charAliases ?? [])]).map((a) => a.length === 1 ? `-${a}` : `--${a}`);
|
|
218
219
|
if (aliases.length === 0)
|
|
219
220
|
return;
|
|
220
221
|
const foundAliases = aliases.filter((alias) => this.argv.some((a) => a.startsWith(alias)));
|
package/lib/config/config.js
CHANGED
|
@@ -7,19 +7,21 @@ const errors_1 = require("../errors");
|
|
|
7
7
|
const util_1 = require("./util");
|
|
8
8
|
const node_url_1 = require("node:url");
|
|
9
9
|
const node_os_1 = require("node:os");
|
|
10
|
-
const
|
|
10
|
+
const util_2 = require("../util/util");
|
|
11
|
+
const os_1 = require("../util/os");
|
|
11
12
|
const node_path_1 = require("node:path");
|
|
12
13
|
const performance_1 = require("../performance");
|
|
13
14
|
const plugin_loader_1 = tslib_1.__importDefault(require("./plugin-loader"));
|
|
14
15
|
const is_wsl_1 = tslib_1.__importDefault(require("is-wsl"));
|
|
15
16
|
const node_util_1 = require("node:util");
|
|
16
|
-
const
|
|
17
|
+
const util_3 = require("../help/util");
|
|
17
18
|
const module_loader_1 = require("../module-loader");
|
|
19
|
+
const fs_1 = require("../util/fs");
|
|
18
20
|
const settings_1 = require("../settings");
|
|
19
21
|
const stream_1 = require("../cli-ux/stream");
|
|
20
22
|
// eslint-disable-next-line new-cap
|
|
21
23
|
const debug = (0, util_1.Debug)();
|
|
22
|
-
const _pjson = (0,
|
|
24
|
+
const _pjson = (0, fs_1.requireJson)(__dirname, '..', '..', 'package.json');
|
|
23
25
|
const BASE = `${_pjson.name}@${_pjson.version}`;
|
|
24
26
|
function channelFromVersion(version) {
|
|
25
27
|
const m = version.match(/[^-]+(?:-([^.]+))?/);
|
|
@@ -145,7 +147,7 @@ class Config {
|
|
|
145
147
|
this.channel = this.options.channel || channelFromVersion(this.version);
|
|
146
148
|
this.valid = Config._rootPlugin.valid;
|
|
147
149
|
this.arch = (0, node_os_1.arch)() === 'ia32' ? 'x86' : (0, node_os_1.arch)();
|
|
148
|
-
this.platform = is_wsl_1.default ? 'wsl' : (0,
|
|
150
|
+
this.platform = is_wsl_1.default ? 'wsl' : (0, os_1.getPlatform)();
|
|
149
151
|
this.windows = this.platform === 'win32';
|
|
150
152
|
this.bin = this.pjson.oclif.bin || this.name;
|
|
151
153
|
this.binAliases = this.pjson.oclif.binAliases;
|
|
@@ -160,7 +162,7 @@ class Config {
|
|
|
160
162
|
this.userAgent = `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;
|
|
161
163
|
this.shell = this._shell();
|
|
162
164
|
this.debug = this._debug();
|
|
163
|
-
this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0,
|
|
165
|
+
this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0, os_1.getHomeDir)() || (0, node_os_1.tmpdir)();
|
|
164
166
|
this.cacheDir = this.scopedEnvVar('CACHE_DIR') || this.macosCacheDir() || this.dir('cache');
|
|
165
167
|
this.configDir = this.scopedEnvVar('CONFIG_DIR') || this.dir('config');
|
|
166
168
|
this.dataDir = this.scopedEnvVar('DATA_DIR') || this.dir('data');
|
|
@@ -408,7 +410,7 @@ class Config {
|
|
|
408
410
|
*/
|
|
409
411
|
findMatches(partialCmdId, argv) {
|
|
410
412
|
const flags = argv
|
|
411
|
-
.filter((arg) => !(0,
|
|
413
|
+
.filter((arg) => !(0, util_3.getHelpFlagAdditions)(this).includes(arg) && arg.startsWith('-'))
|
|
412
414
|
.map((a) => a.replaceAll('-', ''));
|
|
413
415
|
const possibleMatches = [...this.commandPermutations.get(partialCmdId)].map((k) => this._commands.get(k));
|
|
414
416
|
const matches = possibleMatches.filter((command) => {
|
|
@@ -537,7 +539,7 @@ class Config {
|
|
|
537
539
|
if (err instanceof Error) {
|
|
538
540
|
const modifiedErr = err;
|
|
539
541
|
modifiedErr.name = `${err.name} Plugin: ${this.name}`;
|
|
540
|
-
modifiedErr.detail = (0,
|
|
542
|
+
modifiedErr.detail = (0, util_2.compact)([
|
|
541
543
|
err.detail,
|
|
542
544
|
`module: ${this._base}`,
|
|
543
545
|
scope && `task: ${scope}`,
|
|
@@ -551,7 +553,7 @@ class Config {
|
|
|
551
553
|
// err is an object
|
|
552
554
|
process.emitWarning('Config.warn expected either a string or Error, but instead received an object');
|
|
553
555
|
err.name = `${err.name} Plugin: ${this.name}`;
|
|
554
|
-
err.detail = (0,
|
|
556
|
+
err.detail = (0, util_2.compact)([
|
|
555
557
|
err.detail,
|
|
556
558
|
`module: ${this._base}`,
|
|
557
559
|
scope && `task: ${scope}`,
|
|
@@ -562,7 +564,7 @@ class Config {
|
|
|
562
564
|
process.emitWarning(JSON.stringify(err));
|
|
563
565
|
}
|
|
564
566
|
get isProd() {
|
|
565
|
-
return (0,
|
|
567
|
+
return (0, util_2.isProd)();
|
|
566
568
|
}
|
|
567
569
|
isJitPluginCommand(c) {
|
|
568
570
|
// Return true if the command's plugin is listed under oclif.jitPlugins AND if the plugin hasn't been loaded to this.plugins
|
|
@@ -629,7 +631,7 @@ class Config {
|
|
|
629
631
|
}
|
|
630
632
|
loadTopics(plugin) {
|
|
631
633
|
const marker = performance_1.Performance.mark(`config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
632
|
-
for (const topic of (0,
|
|
634
|
+
for (const topic of (0, util_2.compact)(plugin.topics)) {
|
|
633
635
|
const existing = this._topics.get(topic.name);
|
|
634
636
|
if (existing) {
|
|
635
637
|
existing.description = topic.description || existing.description;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const Plugin = tslib_1.__importStar(require("./plugin"));
|
|
5
|
-
const index_1 = require("../util/index");
|
|
6
5
|
const util_1 = require("./util");
|
|
7
6
|
const performance_1 = require("../performance");
|
|
7
|
+
const util_2 = require("../util/util");
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
|
+
const fs_1 = require("../util/fs");
|
|
9
10
|
// eslint-disable-next-line new-cap
|
|
10
11
|
const debug = (0, util_1.Debug)();
|
|
11
12
|
class PluginLoader {
|
|
@@ -59,7 +60,7 @@ class PluginLoader {
|
|
|
59
60
|
async loadDevPlugins(opts) {
|
|
60
61
|
if (opts.devPlugins !== false) {
|
|
61
62
|
// do not load oclif.devPlugins in production
|
|
62
|
-
if ((0,
|
|
63
|
+
if ((0, util_2.isProd)())
|
|
63
64
|
return;
|
|
64
65
|
try {
|
|
65
66
|
const { devPlugins } = opts.rootPlugin.pjson.oclif;
|
|
@@ -76,7 +77,7 @@ class PluginLoader {
|
|
|
76
77
|
try {
|
|
77
78
|
const userPJSONPath = (0, node_path_1.join)(opts.dataDir, 'package.json');
|
|
78
79
|
debug('reading user plugins pjson %s', userPJSONPath);
|
|
79
|
-
const pjson = await (0,
|
|
80
|
+
const pjson = await (0, fs_1.readJson)(userPJSONPath);
|
|
80
81
|
if (!pjson.oclif)
|
|
81
82
|
pjson.oclif = { schema: 1 };
|
|
82
83
|
if (!pjson.oclif.plugins)
|
package/lib/config/plugin.js
CHANGED
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Plugin = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
5
|
const util_1 = require("./util");
|
|
6
|
-
const
|
|
6
|
+
const util_2 = require("../util/util");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const fs_1 = require("../util/fs");
|
|
8
9
|
const module_loader_1 = require("../module-loader");
|
|
9
10
|
const performance_1 = require("../performance");
|
|
10
11
|
const cache_command_1 = require("../util/cache-command");
|
|
11
12
|
const node_util_1 = require("node:util");
|
|
12
13
|
const globby_1 = require("globby");
|
|
13
14
|
const ts_node_1 = require("./ts-node");
|
|
14
|
-
const _pjson = (0,
|
|
15
|
+
const _pjson = (0, fs_1.requireJson)(__dirname, '..', '..', 'package.json');
|
|
15
16
|
function topicsToArray(input, base) {
|
|
16
17
|
if (!input)
|
|
17
18
|
return [];
|
|
@@ -36,7 +37,7 @@ async function findSourcesRoot(root) {
|
|
|
36
37
|
for (const next of up(root)) {
|
|
37
38
|
const cur = (0, node_path_1.join)(next, 'package.json');
|
|
38
39
|
// eslint-disable-next-line no-await-in-loop
|
|
39
|
-
if (await (0,
|
|
40
|
+
if (await (0, fs_1.exists)(cur))
|
|
40
41
|
return (0, node_path_1.dirname)(cur);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -57,11 +58,11 @@ async function findRootLegacy(name, root) {
|
|
|
57
58
|
if (name) {
|
|
58
59
|
cur = (0, node_path_1.join)(next, 'node_modules', name, 'package.json');
|
|
59
60
|
// eslint-disable-next-line no-await-in-loop
|
|
60
|
-
if (await (0,
|
|
61
|
+
if (await (0, fs_1.exists)(cur))
|
|
61
62
|
return (0, node_path_1.dirname)(cur);
|
|
62
63
|
try {
|
|
63
64
|
// eslint-disable-next-line no-await-in-loop
|
|
64
|
-
const pkg = await (0,
|
|
65
|
+
const pkg = await (0, fs_1.readJson)((0, node_path_1.join)(next, 'package.json'));
|
|
65
66
|
if (pkg.name === name)
|
|
66
67
|
return next;
|
|
67
68
|
}
|
|
@@ -70,7 +71,7 @@ async function findRootLegacy(name, root) {
|
|
|
70
71
|
else {
|
|
71
72
|
cur = (0, node_path_1.join)(next, 'package.json');
|
|
72
73
|
// eslint-disable-next-line no-await-in-loop
|
|
73
|
-
if (await (0,
|
|
74
|
+
if (await (0, fs_1.exists)(cur))
|
|
74
75
|
return (0, node_path_1.dirname)(cur);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -136,7 +137,7 @@ class Plugin {
|
|
|
136
137
|
throw new errors_1.CLIError(`could not find package.json with ${(0, node_util_1.inspect)(this.options)}`);
|
|
137
138
|
this.root = root;
|
|
138
139
|
this._debug('reading %s plugin %s', this.type, root);
|
|
139
|
-
this.pjson = await (0,
|
|
140
|
+
this.pjson = await (0, fs_1.readJson)((0, node_path_1.join)(root, 'package.json'));
|
|
140
141
|
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
141
142
|
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
142
143
|
this.name = this.pjson.name;
|
|
@@ -144,7 +145,7 @@ class Plugin {
|
|
|
144
145
|
const pjsonPath = (0, node_path_1.join)(root, 'package.json');
|
|
145
146
|
if (!this.name)
|
|
146
147
|
throw new errors_1.CLIError(`no name in ${pjsonPath}`);
|
|
147
|
-
if (!(0,
|
|
148
|
+
if (!(0, util_2.isProd)() && !this.pjson.files)
|
|
148
149
|
this.warn(`files attribute must be specified in ${pjsonPath}`);
|
|
149
150
|
// eslint-disable-next-line new-cap
|
|
150
151
|
this._debug = (0, util_1.Debug)(this.name);
|
|
@@ -155,7 +156,7 @@ class Plugin {
|
|
|
155
156
|
else {
|
|
156
157
|
this.pjson.oclif = this.pjson['cli-engine'] || {};
|
|
157
158
|
}
|
|
158
|
-
this.hooks = (0,
|
|
159
|
+
this.hooks = (0, util_2.mapValues)(this.pjson.oclif.hooks || {}, (i) => (Array.isArray(i) ? i : [i]));
|
|
159
160
|
this.manifest = await this._manifest();
|
|
160
161
|
this.commands = Object.entries(this.manifest.commands)
|
|
161
162
|
.map(([id, c]) => ({
|
|
@@ -235,7 +236,7 @@ class Plugin {
|
|
|
235
236
|
const readManifest = async (dotfile = false) => {
|
|
236
237
|
try {
|
|
237
238
|
const p = (0, node_path_1.join)(this.root, `${dotfile ? '.' : ''}oclif.manifest.json`);
|
|
238
|
-
const manifest = await (0,
|
|
239
|
+
const manifest = await (0, fs_1.readJson)(p);
|
|
239
240
|
if (!process.env.OCLIF_NEXT_VERSION && manifest.version.split('-')[0] !== this.version.split('-')[0]) {
|
|
240
241
|
process.emitWarning(`Mismatched version in ${this.name} plugin manifest. Expected: ${this.version} Received: ${manifest.version}\nThis usually means you have an oclif.manifest.json file that should be deleted in development. This file should be automatically generated when publishing.`);
|
|
241
242
|
}
|
|
@@ -304,7 +305,7 @@ class Plugin {
|
|
|
304
305
|
}
|
|
305
306
|
addErrorScope(err, scope) {
|
|
306
307
|
err.name = `${err.name} Plugin: ${this.name}`;
|
|
307
|
-
err.detail = (0,
|
|
308
|
+
err.detail = (0, util_2.compact)([
|
|
308
309
|
err.detail,
|
|
309
310
|
`module: ${this._base}`,
|
|
310
311
|
scope && `task: ${scope}`,
|
package/lib/config/ts-node.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsPath = exports.TS_CONFIGS = void 0;
|
|
4
|
-
const index_1 = require("../util/index");
|
|
5
4
|
const node_path_1 = require("node:path");
|
|
6
5
|
const util_1 = require("./util");
|
|
7
6
|
const node_fs_1 = require("node:fs");
|
|
7
|
+
const util_2 = require("../util/util");
|
|
8
8
|
const errors_1 = require("../errors");
|
|
9
|
+
const fs_1 = require("../util/fs");
|
|
9
10
|
const settings_1 = require("../settings");
|
|
10
11
|
// eslint-disable-next-line new-cap
|
|
11
12
|
const debug = (0, util_1.Debug)('ts-node');
|
|
@@ -35,7 +36,7 @@ function loadTSConfig(root) {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
if ((0, node_fs_1.existsSync)(tsconfigPath) && typescript) {
|
|
38
|
-
const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0,
|
|
39
|
+
const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0, fs_1.readJsonSync)(tsconfigPath, false)).config;
|
|
39
40
|
if (!tsconfig || !tsconfig.compilerOptions) {
|
|
40
41
|
throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it ` +
|
|
41
42
|
'did not contain a "compilerOptions" section.');
|
|
@@ -117,7 +118,7 @@ function tsPath(root, orig, plugin) {
|
|
|
117
118
|
debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
|
|
118
119
|
return orig;
|
|
119
120
|
}
|
|
120
|
-
const isProduction = (0,
|
|
121
|
+
const isProduction = (0, util_2.isProd)();
|
|
121
122
|
/**
|
|
122
123
|
* Skip ts-node registration for ESM plugins.
|
|
123
124
|
* The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
|
package/lib/flags.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.option = exports.help = exports.version = exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
|
|
4
|
-
const
|
|
4
|
+
const fs_1 = require("./util/fs");
|
|
5
5
|
const errors_1 = require("./errors");
|
|
6
6
|
const node_url_1 = require("node:url");
|
|
7
7
|
const help_1 = require("./help");
|
|
@@ -57,14 +57,14 @@ exports.integer = custom({
|
|
|
57
57
|
exports.directory = custom({
|
|
58
58
|
async parse(input, _, opts) {
|
|
59
59
|
if (opts.exists)
|
|
60
|
-
return (0,
|
|
60
|
+
return (0, fs_1.dirExists)(input);
|
|
61
61
|
return input;
|
|
62
62
|
},
|
|
63
63
|
});
|
|
64
64
|
exports.file = custom({
|
|
65
65
|
async parse(input, _, opts) {
|
|
66
66
|
if (opts.exists)
|
|
67
|
-
return (0,
|
|
67
|
+
return (0, fs_1.fileExists)(input);
|
|
68
68
|
return input;
|
|
69
69
|
},
|
|
70
70
|
});
|
package/lib/help/command.js
CHANGED
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CommandHelp = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const formatter_1 = require("./formatter");
|
|
6
|
-
const util_1 = require("../util");
|
|
6
|
+
const util_1 = require("../util/util");
|
|
7
7
|
const docopts_1 = require("./docopts");
|
|
8
8
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
+
const ensure_arg_object_1 = require("../util/ensure-arg-object");
|
|
9
10
|
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
10
11
|
// Don't use os.EOL because we need to ensure that a string
|
|
11
12
|
// written on any platform, that may use \r\n or \n, will be
|
|
@@ -34,7 +35,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
34
35
|
v.name = k;
|
|
35
36
|
return v;
|
|
36
37
|
}), (f) => [!f.char, f.char, f.name]);
|
|
37
|
-
const args = Object.values((0,
|
|
38
|
+
const args = Object.values((0, ensure_arg_object_1.ensureArgObject)(cmd.args)).filter((a) => !a.hidden);
|
|
38
39
|
const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
|
|
39
40
|
const body = generate({ cmd, flags, args }, header);
|
|
40
41
|
// Generate can return a list of sections
|
package/lib/help/docopts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocOpts = void 0;
|
|
4
|
-
const
|
|
4
|
+
const ensure_arg_object_1 = require("../util/ensure-arg-object");
|
|
5
5
|
/**
|
|
6
6
|
* DocOpts - See http://docopt.org/.
|
|
7
7
|
*
|
|
@@ -79,7 +79,7 @@ class DocOpts {
|
|
|
79
79
|
toString() {
|
|
80
80
|
const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
|
|
81
81
|
if (this.cmd.args) {
|
|
82
|
-
const a = Object.values((0,
|
|
82
|
+
const a = Object.values((0, ensure_arg_object_1.ensureArgObject)(this.cmd.args)).map((arg) => arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`) || [];
|
|
83
83
|
opts.push(...a);
|
|
84
84
|
}
|
|
85
85
|
try {
|
package/lib/help/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadHelpClass = exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const util_1 = require("../util/util");
|
|
6
|
+
const util_2 = require("./util");
|
|
7
7
|
const command_1 = require("./command");
|
|
8
8
|
const formatter_1 = require("./formatter");
|
|
9
9
|
const root_1 = tslib_1.__importDefault(require("./root"));
|
|
@@ -15,13 +15,13 @@ const stream_1 = require("../cli-ux/stream");
|
|
|
15
15
|
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
16
16
|
var command_2 = require("./command");
|
|
17
17
|
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return
|
|
20
|
-
Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return
|
|
21
|
-
Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return
|
|
18
|
+
var util_3 = require("./util");
|
|
19
|
+
Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_3.standardizeIDFromArgv; } });
|
|
20
|
+
Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
|
|
21
|
+
Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
|
|
22
22
|
function getHelpSubject(args, config) {
|
|
23
23
|
// for each help flag that starts with '--' create a new flag with same name sans '--'
|
|
24
|
-
const mergedHelpFlags = (0,
|
|
24
|
+
const mergedHelpFlags = (0, util_2.getHelpFlagAdditions)(config);
|
|
25
25
|
for (const arg of args) {
|
|
26
26
|
if (arg === '--')
|
|
27
27
|
return;
|
|
@@ -58,15 +58,15 @@ class Help extends HelpBase {
|
|
|
58
58
|
get sortedCommands() {
|
|
59
59
|
let { commands } = this.config;
|
|
60
60
|
commands = commands.filter((c) => this.opts.all || !c.hidden);
|
|
61
|
-
commands = (0,
|
|
62
|
-
commands = (0,
|
|
61
|
+
commands = (0, util_1.sortBy)(commands, (c) => c.id);
|
|
62
|
+
commands = (0, util_1.uniqBy)(commands, (c) => c.id);
|
|
63
63
|
return commands;
|
|
64
64
|
}
|
|
65
65
|
get sortedTopics() {
|
|
66
66
|
let topics = this._topics;
|
|
67
67
|
topics = topics.filter((t) => this.opts.all || !t.hidden);
|
|
68
|
-
topics = (0,
|
|
69
|
-
topics = (0,
|
|
68
|
+
topics = (0, util_1.sortBy)(topics, (t) => t.name);
|
|
69
|
+
topics = (0, util_1.uniqBy)(topics, (t) => t.name);
|
|
70
70
|
return topics;
|
|
71
71
|
}
|
|
72
72
|
constructor(config, opts = {}) {
|
|
@@ -74,9 +74,9 @@ class Help extends HelpBase {
|
|
|
74
74
|
}
|
|
75
75
|
async showHelp(argv) {
|
|
76
76
|
const originalArgv = argv.slice(1);
|
|
77
|
-
argv = argv.filter((arg) => !(0,
|
|
77
|
+
argv = argv.filter((arg) => !(0, util_2.getHelpFlagAdditions)(this.config).includes(arg));
|
|
78
78
|
if (this.config.topicSeparator !== ':')
|
|
79
|
-
argv = (0,
|
|
79
|
+
argv = (0, util_2.standardizeIDFromArgv)(argv, this.config);
|
|
80
80
|
const subject = getHelpSubject(argv, this.config);
|
|
81
81
|
if (!subject) {
|
|
82
82
|
if (this.config.pjson.oclif.default) {
|
|
@@ -134,13 +134,13 @@ class Help extends HelpBase {
|
|
|
134
134
|
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
|
|
135
135
|
if (state) {
|
|
136
136
|
this.log(state === 'deprecated'
|
|
137
|
-
? `${(0,
|
|
137
|
+
? `${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}\n`
|
|
138
138
|
: `This command is in ${state}.\n`);
|
|
139
139
|
}
|
|
140
140
|
if (command.deprecateAliases && command.aliases.includes(name)) {
|
|
141
141
|
const actualCmd = this.config.commands.find((c) => c.aliases.includes(name));
|
|
142
142
|
const opts = { ...command.deprecationOptions, ...(actualCmd ? { to: actualCmd.id } : {}) };
|
|
143
|
-
this.log(`${(0,
|
|
143
|
+
this.log(`${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), opts)}\n`);
|
|
144
144
|
}
|
|
145
145
|
const summary = this.summary(command);
|
|
146
146
|
if (summary) {
|
|
@@ -251,7 +251,7 @@ class Help extends HelpBase {
|
|
|
251
251
|
let topicID = `${topic.name}:COMMAND`;
|
|
252
252
|
if (this.config.topicSeparator !== ':')
|
|
253
253
|
topicID = topicID.replaceAll(':', this.config.topicSeparator);
|
|
254
|
-
let output = (0,
|
|
254
|
+
let output = (0, util_1.compact)([
|
|
255
255
|
summary,
|
|
256
256
|
this.section(this.opts.usageHeader || 'USAGE', `$ ${this.config.bin} ${topicID}`),
|
|
257
257
|
description && this.section('DESCRIPTION', this.wrap(description)),
|
package/lib/help/root.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const formatter_1 = require("./formatter");
|
|
5
|
-
const
|
|
5
|
+
const util_1 = require("../util/util");
|
|
6
6
|
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
7
7
|
class RootHelp extends formatter_1.HelpFormatter {
|
|
8
8
|
config;
|
|
@@ -16,7 +16,7 @@ class RootHelp extends formatter_1.HelpFormatter {
|
|
|
16
16
|
let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
|
|
17
17
|
description = this.render(description);
|
|
18
18
|
description = description.split('\n')[0];
|
|
19
|
-
let output = (0,
|
|
19
|
+
let output = (0, util_1.compact)([description, this.version(), this.usage(), this.description()]).join('\n\n');
|
|
20
20
|
if (this.opts.stripAnsi)
|
|
21
21
|
output = (0, strip_ansi_1.default)(output);
|
|
22
22
|
return output;
|
package/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * as Flags from './flags';
|
|
|
5
5
|
export * as Parser from './parser';
|
|
6
6
|
export * as ux from './cli-ux';
|
|
7
7
|
export { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
|
|
8
|
-
export { Config, Plugin
|
|
8
|
+
export { Config, Plugin } from './config';
|
|
9
9
|
export { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
10
10
|
export { Settings, settings } from './settings';
|
|
11
11
|
export { stdout, stderr } from './cli-ux/stream';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.run = exports.handle = exports.flush = exports.execute = exports.Performance = exports.Command = exports.toStandardizedId = exports.toConfiguredId = exports.stderr = exports.stdout = exports.settings = exports.
|
|
3
|
+
exports.run = exports.handle = exports.flush = exports.execute = exports.Performance = exports.Command = exports.toStandardizedId = exports.toConfiguredId = exports.stderr = exports.stdout = exports.settings = exports.Plugin = exports.Config = exports.loadHelpClass = exports.Help = exports.HelpBase = exports.CommandHelp = exports.ux = exports.Parser = exports.Flags = exports.Interfaces = exports.Errors = exports.Args = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const stream_1 = require("./cli-ux/stream");
|
|
6
6
|
function checkCWD() {
|
|
@@ -28,7 +28,6 @@ Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: functio
|
|
|
28
28
|
var config_1 = require("./config");
|
|
29
29
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
30
30
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
31
|
-
Object.defineProperty(exports, "tsPath", { enumerable: true, get: function () { return config_1.tsPath; } });
|
|
32
31
|
var settings_1 = require("./settings");
|
|
33
32
|
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
34
33
|
var stream_2 = require("./cli-ux/stream");
|
package/lib/parser/errors.js
CHANGED
|
@@ -6,7 +6,7 @@ const errors_1 = require("../errors");
|
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
7
|
const help_1 = require("./help");
|
|
8
8
|
const list_1 = require("../cli-ux/list");
|
|
9
|
-
const
|
|
9
|
+
const util_1 = require("../util/util");
|
|
10
10
|
var errors_2 = require("../errors");
|
|
11
11
|
Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
|
|
12
12
|
class CLIParseError extends errors_1.CLIError {
|
|
@@ -96,7 +96,7 @@ exports.ArgInvalidOptionError = ArgInvalidOptionError;
|
|
|
96
96
|
class FailedFlagValidationError extends CLIParseError {
|
|
97
97
|
constructor({ parse, failed }) {
|
|
98
98
|
const reasons = failed.map((r) => r.reason);
|
|
99
|
-
const deduped = (0,
|
|
99
|
+
const deduped = (0, util_1.uniq)(reasons);
|
|
100
100
|
const errString = deduped.length === 1 ? 'error' : 'errors';
|
|
101
101
|
const message = `The following ${errString} occurred:\n ${chalk_1.default.dim(deduped.join('\n '))}`;
|
|
102
102
|
super({ parse, message });
|
package/lib/parser/help.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.flagUsages = exports.flagUsage = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
-
const
|
|
6
|
+
const util_1 = require("../util/util");
|
|
7
7
|
function flagUsage(flag, options = {}) {
|
|
8
8
|
const label = [];
|
|
9
9
|
if (flag.helpLabel) {
|
|
@@ -26,6 +26,6 @@ exports.flagUsage = flagUsage;
|
|
|
26
26
|
function flagUsages(flags, options = {}) {
|
|
27
27
|
if (flags.length === 0)
|
|
28
28
|
return [];
|
|
29
|
-
return (0,
|
|
29
|
+
return (0, util_1.sortBy)(flags, (f) => [f.char ? -1 : 1, f.char, f.name]).map((f) => flagUsage(f, options));
|
|
30
30
|
}
|
|
31
31
|
exports.flagUsages = flagUsages;
|
package/lib/parser/parse.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Parser = void 0;
|
|
4
4
|
/* eslint-disable no-await-in-loop */
|
|
5
5
|
const errors_1 = require("./errors");
|
|
6
|
-
const
|
|
6
|
+
const util_1 = require("../util/util");
|
|
7
7
|
const node_readline_1 = require("node:readline");
|
|
8
8
|
let debug;
|
|
9
9
|
try {
|
|
@@ -75,7 +75,7 @@ class Parser {
|
|
|
75
75
|
this.context = input.context ?? {};
|
|
76
76
|
this.argv = [...input.argv];
|
|
77
77
|
this._setNames();
|
|
78
|
-
this.booleanFlags = (0,
|
|
78
|
+
this.booleanFlags = (0, util_1.pickBy)(input.flags, (f) => f.type === 'boolean');
|
|
79
79
|
this.flagAliases = Object.fromEntries(Object.values(input.flags).flatMap((flag) => [...(flag.aliases ?? []), ...(flag.charAliases ?? [])].map((a) => [a, flag])));
|
|
80
80
|
}
|
|
81
81
|
async parse() {
|
|
@@ -197,10 +197,10 @@ class Parser {
|
|
|
197
197
|
// user provided some input
|
|
198
198
|
if (tokenLength) {
|
|
199
199
|
// boolean
|
|
200
|
-
if (fws.inputFlag.flag.type === 'boolean' && (0,
|
|
200
|
+
if (fws.inputFlag.flag.type === 'boolean' && (0, util_1.last)(fws.tokens)?.input) {
|
|
201
201
|
return {
|
|
202
202
|
...fws,
|
|
203
|
-
valueFunction: async (i) => parseFlagOrThrowError((0,
|
|
203
|
+
valueFunction: async (i) => parseFlagOrThrowError((0, util_1.last)(i.tokens)?.input !== `--no-${i.inputFlag.name}`, i.inputFlag.flag, this.context, (0, util_1.last)(i.tokens)),
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
206
|
// multiple with custom delimiter
|
|
@@ -215,7 +215,7 @@ class Parser {
|
|
|
215
215
|
.replace(/^"(.*)"$/, '$1')
|
|
216
216
|
.replace(/^'(.*)'$/, '$1'))
|
|
217
217
|
.map(async (v) => parseFlagOrThrowError(v, i.inputFlag.flag, this.context, {
|
|
218
|
-
...(0,
|
|
218
|
+
...(0, util_1.last)(i.tokens),
|
|
219
219
|
input: v,
|
|
220
220
|
}))))
|
|
221
221
|
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
@@ -233,7 +233,7 @@ class Parser {
|
|
|
233
233
|
if (fws.inputFlag.flag.type === 'option') {
|
|
234
234
|
return {
|
|
235
235
|
...fws,
|
|
236
|
-
valueFunction: async (i) => parseFlagOrThrowError(validateOptions(i.inputFlag.flag, (0,
|
|
236
|
+
valueFunction: async (i) => parseFlagOrThrowError(validateOptions(i.inputFlag.flag, (0, util_1.last)(fws.tokens)?.input), i.inputFlag.flag, this.context, (0, util_1.last)(fws.tokens)),
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -249,7 +249,7 @@ class Parser {
|
|
|
249
249
|
if (fws.inputFlag.flag.type === 'boolean') {
|
|
250
250
|
return {
|
|
251
251
|
...fws,
|
|
252
|
-
valueFunction: async (i) => (0,
|
|
252
|
+
valueFunction: async (i) => (0, util_1.isTruthy)(process.env[i.inputFlag.flag.env] ?? 'false'),
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
}
|
package/lib/parser/validate.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validate = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
|
-
const
|
|
5
|
+
const util_1 = require("../util/util");
|
|
6
6
|
async function validate(parse) {
|
|
7
7
|
let cachedResolvedFlags;
|
|
8
8
|
function validateArgs() {
|
|
@@ -82,7 +82,7 @@ async function validate(parse) {
|
|
|
82
82
|
.filter((flagName) => flag.exactlyOne && flag.exactlyOne.includes(flagName)); // and in the exactlyOne list
|
|
83
83
|
if (intersection.length === 0) {
|
|
84
84
|
// the command's exactlyOne may or may not include itself, so we'll use Set to add + de-dupe
|
|
85
|
-
const deduped = (0,
|
|
85
|
+
const deduped = (0, util_1.uniq)(flag.exactlyOne?.map((flag) => `--${flag}`) ?? []).join(', ');
|
|
86
86
|
const reason = `Exactly one of the following must be provided: ${deduped}`;
|
|
87
87
|
return { ...base, status: 'failed', reason };
|
|
88
88
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cacheCommand = void 0;
|
|
4
|
-
const index_1 = require("./index");
|
|
5
4
|
const aggregate_flags_1 = require("./aggregate-flags");
|
|
6
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");
|
|
7
8
|
// In order to collect static properties up the inheritance chain, we need to recursively
|
|
8
9
|
// access the prototypes until there's nothing left. This allows us to combine baseFlags
|
|
9
10
|
// and flags as well as add in the json flag if enableJsonFlag is enabled.
|
|
10
11
|
function mergePrototype(result, cmd) {
|
|
11
12
|
const proto = Object.getPrototypeOf(cmd);
|
|
12
|
-
const filteredProto = (0,
|
|
13
|
+
const filteredProto = (0, util_1.pickBy)(proto, (v) => v !== undefined);
|
|
13
14
|
return Object.keys(proto).length > 0 ? mergePrototype({ ...filteredProto, ...result }, proto) : result;
|
|
14
15
|
}
|
|
15
16
|
async function cacheFlags(cmdFlags, respectNoCacheDefault) {
|
|
@@ -68,7 +69,7 @@ async function cacheArgs(cmdArgs, respectNoCacheDefault) {
|
|
|
68
69
|
async function cacheCommand(uncachedCmd, plugin, respectNoCacheDefault = false) {
|
|
69
70
|
const cmd = mergePrototype(uncachedCmd, uncachedCmd);
|
|
70
71
|
const flags = await cacheFlags((0, aggregate_flags_1.aggregateFlags)(cmd.flags, cmd.baseFlags, cmd.enableJsonFlag), respectNoCacheDefault);
|
|
71
|
-
const args = await cacheArgs((0,
|
|
72
|
+
const args = await cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault);
|
|
72
73
|
const stdProperties = {
|
|
73
74
|
id: cmd.id,
|
|
74
75
|
summary: cmd.summary,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ArgInput } from '../interfaces/parser';
|
|
2
|
+
import { Command } from '../command';
|
|
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?: any[] | ArgInput | {
|
|
11
|
+
[name: string]: Command.Arg.Cached;
|
|
12
|
+
}): 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;
|
package/lib/util/fs.d.ts
ADDED
|
@@ -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 promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
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;
|
package/lib/util/os.d.ts
ADDED
|
@@ -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;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function pickBy<T extends {
|
|
2
|
+
[s: string]: T[keyof T];
|
|
3
|
+
} | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
|
|
4
|
+
export declare function compact<T>(a: (T | undefined)[]): T[];
|
|
5
|
+
export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
|
|
6
|
+
export declare function last<T>(arr?: T[]): T | undefined;
|
|
7
|
+
type SortTypes = string | number | undefined | boolean;
|
|
8
|
+
export declare function sortBy<T>(arr: T[], fn: (i: T) => SortTypes | SortTypes[]): T[];
|
|
9
|
+
export declare function castArray<T>(input?: T | T[]): T[];
|
|
10
|
+
export declare function isProd(): boolean;
|
|
11
|
+
export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
|
|
12
|
+
export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
|
|
13
|
+
export declare function capitalize(s: string): string;
|
|
14
|
+
export declare function isTruthy(input: string): boolean;
|
|
15
|
+
export declare function isNotFalsy(input: string): boolean;
|
|
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
|
+
};
|
|
22
|
+
export {};
|
package/lib/util/util.js
ADDED
|
@@ -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.find((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 ['true', '1', 'yes', 'y'].includes(input.toLowerCase());
|
|
82
|
+
}
|
|
83
|
+
exports.isTruthy = isTruthy;
|
|
84
|
+
function isNotFalsy(input) {
|
|
85
|
+
return !['false', '0', 'no', 'n'].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.
|
|
4
|
+
"version": "3.0.0-beta.20",
|
|
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",
|
|
@@ -40,15 +39,16 @@
|
|
|
40
39
|
"@oclif/test": "^3.0.1",
|
|
41
40
|
"@types/ansi-styles": "^3.2.1",
|
|
42
41
|
"@types/benchmark": "^2.1.2",
|
|
43
|
-
"@types/chai": "^4.3.4",
|
|
44
42
|
"@types/chai-as-promised": "^7.1.5",
|
|
43
|
+
"@types/chai": "^4.3.4",
|
|
45
44
|
"@types/clean-stack": "^2.1.1",
|
|
45
|
+
"@types/cli-progress": "^3.11.0",
|
|
46
46
|
"@types/ejs": "^3.1.2",
|
|
47
47
|
"@types/indent-string": "^4.0.1",
|
|
48
48
|
"@types/js-yaml": "^3.12.7",
|
|
49
49
|
"@types/mocha": "^10.0.2",
|
|
50
|
-
"@types/node": "^18",
|
|
51
50
|
"@types/node-notifier": "^8.0.2",
|
|
51
|
+
"@types/node": "^18",
|
|
52
52
|
"@types/slice-ansi": "^4.0.0",
|
|
53
53
|
"@types/strip-ansi": "^5.2.1",
|
|
54
54
|
"@types/supports-color": "^8.1.1",
|
package/lib/util/index.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ArgInput } from '../interfaces/parser';
|
|
3
|
-
import { Command } from '../command';
|
|
4
|
-
export declare function pickBy<T extends {
|
|
5
|
-
[s: string]: T[keyof T];
|
|
6
|
-
} | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
|
|
7
|
-
export declare function compact<T>(a: (T | undefined)[]): T[];
|
|
8
|
-
export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
|
|
9
|
-
export declare function last<T>(arr?: T[]): T | undefined;
|
|
10
|
-
type SortTypes = string | number | undefined | boolean;
|
|
11
|
-
export declare function sortBy<T>(arr: T[], fn: (i: T) => SortTypes | SortTypes[]): T[];
|
|
12
|
-
export declare function castArray<T>(input?: T | T[]): T[];
|
|
13
|
-
export declare function isProd(): boolean;
|
|
14
|
-
export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
|
|
15
|
-
export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
|
|
16
|
-
export declare function capitalize(s: string): string;
|
|
17
|
-
export declare function exists(path: string): Promise<boolean>;
|
|
18
|
-
export declare const dirExists: (input: string) => Promise<string>;
|
|
19
|
-
export declare const fileExists: (input: string) => Promise<string>;
|
|
20
|
-
export declare function isTruthy(input: string): boolean;
|
|
21
|
-
export declare function isNotFalsy(input: string): boolean;
|
|
22
|
-
export declare function requireJson<T>(...pathParts: string[]): T;
|
|
23
|
-
/**
|
|
24
|
-
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
|
|
25
|
-
* defined args as an array.
|
|
26
|
-
*
|
|
27
|
-
* @param args Either an array of args or an object of args
|
|
28
|
-
* @returns ArgInput
|
|
29
|
-
*/
|
|
30
|
-
export declare function ensureArgObject(args?: any[] | ArgInput | {
|
|
31
|
-
[name: string]: Command.Arg.Cached;
|
|
32
|
-
}): ArgInput;
|
|
33
|
-
export declare function uniq<T>(arr: T[]): T[];
|
|
34
|
-
/**
|
|
35
|
-
* Call os.homedir() and return the result
|
|
36
|
-
*
|
|
37
|
-
* Wrapping this allows us to stub these in tests since os.homedir() is
|
|
38
|
-
* non-configurable and non-writable.
|
|
39
|
-
*
|
|
40
|
-
* @returns The user's home directory
|
|
41
|
-
*/
|
|
42
|
-
export declare function getHomeDir(): string;
|
|
43
|
-
/**
|
|
44
|
-
* Call os.platform() and return the result
|
|
45
|
-
*
|
|
46
|
-
* Wrapping this allows us to stub these in tests since os.platform() is
|
|
47
|
-
* non-configurable and non-writable.
|
|
48
|
-
*
|
|
49
|
-
* @returns The process' platform
|
|
50
|
-
*/
|
|
51
|
-
export declare function getPlatform(): NodeJS.Platform;
|
|
52
|
-
export declare function readJson<T = unknown>(path: string): Promise<T>;
|
|
53
|
-
export declare function readJsonSync(path: string, parse: false): string;
|
|
54
|
-
export declare function readJsonSync<T = unknown>(path: string, parse?: true): T;
|
|
55
|
-
export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
|
|
56
|
-
[P in keyof T]: T[P];
|
|
57
|
-
}, fn: (i: T[keyof T], k: keyof T) => TResult): {
|
|
58
|
-
[P in keyof T]: TResult;
|
|
59
|
-
};
|
|
60
|
-
export {};
|
package/lib/util/index.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapValues = exports.readJsonSync = exports.readJson = exports.getPlatform = exports.getHomeDir = exports.uniq = exports.ensureArgObject = exports.requireJson = exports.isNotFalsy = exports.isTruthy = exports.fileExists = exports.dirExists = exports.exists = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.last = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_os_1 = require("node:os");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const debug = require('debug');
|
|
9
|
-
function pickBy(obj, fn) {
|
|
10
|
-
return Object.entries(obj).reduce((o, [k, v]) => {
|
|
11
|
-
if (fn(v))
|
|
12
|
-
o[k] = v;
|
|
13
|
-
return o;
|
|
14
|
-
}, {});
|
|
15
|
-
}
|
|
16
|
-
exports.pickBy = pickBy;
|
|
17
|
-
function compact(a) {
|
|
18
|
-
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
|
19
|
-
return a.filter((a) => Boolean(a));
|
|
20
|
-
}
|
|
21
|
-
exports.compact = compact;
|
|
22
|
-
function uniqBy(arr, fn) {
|
|
23
|
-
return arr.filter((a, i) => {
|
|
24
|
-
const aVal = fn(a);
|
|
25
|
-
return !arr.find((b, j) => j > i && fn(b) === aVal);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.uniqBy = uniqBy;
|
|
29
|
-
function last(arr) {
|
|
30
|
-
if (!arr)
|
|
31
|
-
return;
|
|
32
|
-
return arr.at(-1);
|
|
33
|
-
}
|
|
34
|
-
exports.last = last;
|
|
35
|
-
function compare(a, b) {
|
|
36
|
-
a = a === undefined ? 0 : a;
|
|
37
|
-
b = b === undefined ? 0 : b;
|
|
38
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
39
|
-
if (a.length === 0 && b.length === 0)
|
|
40
|
-
return 0;
|
|
41
|
-
const diff = compare(a[0], b[0]);
|
|
42
|
-
if (diff !== 0)
|
|
43
|
-
return diff;
|
|
44
|
-
return compare(a.slice(1), b.slice(1));
|
|
45
|
-
}
|
|
46
|
-
if (a < b)
|
|
47
|
-
return -1;
|
|
48
|
-
if (a > b)
|
|
49
|
-
return 1;
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
function sortBy(arr, fn) {
|
|
53
|
-
return arr.sort((a, b) => compare(fn(a), fn(b)));
|
|
54
|
-
}
|
|
55
|
-
exports.sortBy = sortBy;
|
|
56
|
-
function castArray(input) {
|
|
57
|
-
if (input === undefined)
|
|
58
|
-
return [];
|
|
59
|
-
return Array.isArray(input) ? input : [input];
|
|
60
|
-
}
|
|
61
|
-
exports.castArray = castArray;
|
|
62
|
-
function isProd() {
|
|
63
|
-
return !['development', 'test'].includes(process.env.NODE_ENV ?? '');
|
|
64
|
-
}
|
|
65
|
-
exports.isProd = isProd;
|
|
66
|
-
function maxBy(arr, fn) {
|
|
67
|
-
if (arr.length === 0) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
return arr.reduce((maxItem, i) => {
|
|
71
|
-
const curr = fn(i);
|
|
72
|
-
const max = fn(maxItem);
|
|
73
|
-
return curr > max ? i : maxItem;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
exports.maxBy = maxBy;
|
|
77
|
-
function sumBy(arr, fn) {
|
|
78
|
-
return arr.reduce((sum, i) => sum + fn(i), 0);
|
|
79
|
-
}
|
|
80
|
-
exports.sumBy = sumBy;
|
|
81
|
-
function capitalize(s) {
|
|
82
|
-
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
|
|
83
|
-
}
|
|
84
|
-
exports.capitalize = capitalize;
|
|
85
|
-
async function exists(path) {
|
|
86
|
-
try {
|
|
87
|
-
await (0, promises_1.access)(path);
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.exists = exists;
|
|
95
|
-
const dirExists = async (input) => {
|
|
96
|
-
if (!(await exists(input))) {
|
|
97
|
-
throw new Error(`No directory found at ${input}`);
|
|
98
|
-
}
|
|
99
|
-
const fileStat = await (0, promises_1.stat)(input);
|
|
100
|
-
if (!fileStat.isDirectory()) {
|
|
101
|
-
throw new Error(`${input} exists but is not a directory`);
|
|
102
|
-
}
|
|
103
|
-
return input;
|
|
104
|
-
};
|
|
105
|
-
exports.dirExists = dirExists;
|
|
106
|
-
const fileExists = async (input) => {
|
|
107
|
-
if (!(await exists(input))) {
|
|
108
|
-
throw new Error(`No file found at ${input}`);
|
|
109
|
-
}
|
|
110
|
-
const fileStat = await (0, promises_1.stat)(input);
|
|
111
|
-
if (!fileStat.isFile()) {
|
|
112
|
-
throw new Error(`${input} exists but is not a file`);
|
|
113
|
-
}
|
|
114
|
-
return input;
|
|
115
|
-
};
|
|
116
|
-
exports.fileExists = fileExists;
|
|
117
|
-
function isTruthy(input) {
|
|
118
|
-
return ['true', '1', 'yes', 'y'].includes(input.toLowerCase());
|
|
119
|
-
}
|
|
120
|
-
exports.isTruthy = isTruthy;
|
|
121
|
-
function isNotFalsy(input) {
|
|
122
|
-
return !['false', '0', 'no', 'n'].includes(input.toLowerCase());
|
|
123
|
-
}
|
|
124
|
-
exports.isNotFalsy = isNotFalsy;
|
|
125
|
-
function requireJson(...pathParts) {
|
|
126
|
-
return JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(...pathParts), 'utf8'));
|
|
127
|
-
}
|
|
128
|
-
exports.requireJson = requireJson;
|
|
129
|
-
/**
|
|
130
|
-
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
|
|
131
|
-
* defined args as an array.
|
|
132
|
-
*
|
|
133
|
-
* @param args Either an array of args or an object of args
|
|
134
|
-
* @returns ArgInput
|
|
135
|
-
*/
|
|
136
|
-
function ensureArgObject(args) {
|
|
137
|
-
return (Array.isArray(args) ? (args ?? []).reduce((x, y) => ({ ...x, [y.name]: y }), {}) : args ?? {});
|
|
138
|
-
}
|
|
139
|
-
exports.ensureArgObject = ensureArgObject;
|
|
140
|
-
function uniq(arr) {
|
|
141
|
-
return [...new Set(arr)].sort();
|
|
142
|
-
}
|
|
143
|
-
exports.uniq = uniq;
|
|
144
|
-
/**
|
|
145
|
-
* Call os.homedir() and return the result
|
|
146
|
-
*
|
|
147
|
-
* Wrapping this allows us to stub these in tests since os.homedir() is
|
|
148
|
-
* non-configurable and non-writable.
|
|
149
|
-
*
|
|
150
|
-
* @returns The user's home directory
|
|
151
|
-
*/
|
|
152
|
-
function getHomeDir() {
|
|
153
|
-
return (0, node_os_1.homedir)();
|
|
154
|
-
}
|
|
155
|
-
exports.getHomeDir = getHomeDir;
|
|
156
|
-
/**
|
|
157
|
-
* Call os.platform() and return the result
|
|
158
|
-
*
|
|
159
|
-
* Wrapping this allows us to stub these in tests since os.platform() is
|
|
160
|
-
* non-configurable and non-writable.
|
|
161
|
-
*
|
|
162
|
-
* @returns The process' platform
|
|
163
|
-
*/
|
|
164
|
-
function getPlatform() {
|
|
165
|
-
return (0, node_os_1.platform)();
|
|
166
|
-
}
|
|
167
|
-
exports.getPlatform = getPlatform;
|
|
168
|
-
async function readJson(path) {
|
|
169
|
-
debug('config')('readJson %s', path);
|
|
170
|
-
const contents = await (0, promises_1.readFile)(path, 'utf8');
|
|
171
|
-
return JSON.parse(contents);
|
|
172
|
-
}
|
|
173
|
-
exports.readJson = readJson;
|
|
174
|
-
function readJsonSync(path, parse = true) {
|
|
175
|
-
const contents = (0, node_fs_1.readFileSync)(path, 'utf8');
|
|
176
|
-
return parse ? JSON.parse(contents) : contents;
|
|
177
|
-
}
|
|
178
|
-
exports.readJsonSync = readJsonSync;
|
|
179
|
-
function mapValues(obj, fn) {
|
|
180
|
-
return Object.entries(obj).reduce((o, [k, v]) => {
|
|
181
|
-
o[k] = fn(v, k);
|
|
182
|
-
return o;
|
|
183
|
-
}, {});
|
|
184
|
-
}
|
|
185
|
-
exports.mapValues = mapValues;
|