@oclif/core 3.0.0-beta.17 → 3.0.0-beta.18
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/cli-ux/action/base.js +7 -7
- package/lib/cli-ux/action/simple.js +1 -4
- package/lib/cli-ux/action/spinner.js +5 -2
- package/lib/cli-ux/config.js +4 -6
- package/lib/cli-ux/exit.js +3 -0
- package/lib/cli-ux/flush.js +5 -4
- package/lib/cli-ux/index.js +1 -1
- package/lib/cli-ux/stream.js +1 -0
- package/lib/cli-ux/styled/json.js +5 -3
- package/lib/cli-ux/styled/table.js +3 -0
- package/lib/cli-ux/styled/tree.js +1 -3
- package/lib/command.d.ts +6 -14
- package/lib/command.js +81 -68
- package/lib/config/config.d.ts +0 -1
- package/lib/config/config.js +43 -163
- package/lib/config/index.d.ts +0 -1
- package/lib/config/index.js +1 -3
- package/lib/config/plugin-loader.js +5 -4
- package/lib/config/plugin.d.ts +1 -0
- package/lib/config/plugin.js +31 -14
- package/lib/config/ts-node.js +9 -3
- package/lib/config/util.d.ts +0 -6
- package/lib/config/util.js +1 -13
- package/lib/errors/errors/cli.js +3 -1
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/handle.js +2 -2
- package/lib/errors/logger.js +3 -2
- package/lib/flags.d.ts +2 -2
- package/lib/help/command.js +3 -0
- package/lib/help/docopts.js +3 -0
- package/lib/help/formatter.js +12 -1
- package/lib/help/index.d.ts +5 -1
- package/lib/help/index.js +32 -8
- package/lib/help/root.js +5 -2
- package/lib/help/util.d.ts +1 -7
- package/lib/help/util.js +1 -21
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -3
- package/lib/interfaces/parser.d.ts +8 -7
- package/lib/interfaces/plugin.d.ts +5 -0
- package/lib/module-loader.js +2 -2
- package/lib/parser/errors.js +6 -0
- package/lib/parser/parse.js +9 -2
- package/lib/performance.js +11 -3
- package/lib/util/aggregate-flags.d.ts +2 -0
- package/lib/util/aggregate-flags.js +15 -0
- package/lib/util/cache-command.d.ts +3 -0
- package/lib/util/cache-command.js +100 -0
- package/lib/util/cache-default-value.d.ts +2 -0
- package/lib/util/cache-default-value.js +28 -0
- package/lib/{util.d.ts → util/index.d.ts} +7 -2
- package/lib/{util.js → util/index.js} +13 -16
- package/package.json +9 -5
package/lib/config/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Config = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ejs = tslib_1.__importStar(require("ejs"));
|
|
6
6
|
const errors_1 = require("../errors");
|
|
@@ -11,8 +11,9 @@ const util_2 = require("../util");
|
|
|
11
11
|
const node_path_1 = require("node:path");
|
|
12
12
|
const performance_1 = require("../performance");
|
|
13
13
|
const plugin_loader_1 = tslib_1.__importDefault(require("./plugin-loader"));
|
|
14
|
+
const is_wsl_1 = tslib_1.__importDefault(require("is-wsl"));
|
|
14
15
|
const node_util_1 = require("node:util");
|
|
15
|
-
const
|
|
16
|
+
const util_3 = require("../help/util");
|
|
16
17
|
const module_loader_1 = require("../module-loader");
|
|
17
18
|
const settings_1 = require("../settings");
|
|
18
19
|
const stream_1 = require("../cli-ux/stream");
|
|
@@ -24,15 +25,11 @@ function channelFromVersion(version) {
|
|
|
24
25
|
const m = version.match(/[^-]+(?:-([^.]+))?/);
|
|
25
26
|
return (m && m[1]) || 'stable';
|
|
26
27
|
}
|
|
27
|
-
const WSL = require('is-wsl');
|
|
28
28
|
function isConfig(o) {
|
|
29
29
|
return o && Boolean(o._base);
|
|
30
30
|
}
|
|
31
31
|
class Permutations extends Map {
|
|
32
|
-
|
|
33
|
-
super(...arguments);
|
|
34
|
-
this.validPermutations = new Map();
|
|
35
|
-
}
|
|
32
|
+
validPermutations = new Map();
|
|
36
33
|
add(permutation, commandId) {
|
|
37
34
|
this.validPermutations.set(permutation, commandId);
|
|
38
35
|
for (const id of (0, util_1.collectUsableIds)([permutation])) {
|
|
@@ -58,17 +55,45 @@ class Permutations extends Map {
|
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
class Config {
|
|
58
|
+
options;
|
|
59
|
+
_base = BASE;
|
|
60
|
+
arch;
|
|
61
|
+
bin;
|
|
62
|
+
binPath;
|
|
63
|
+
cacheDir;
|
|
64
|
+
channel;
|
|
65
|
+
configDir;
|
|
66
|
+
dataDir;
|
|
67
|
+
debug = 0;
|
|
68
|
+
dirname;
|
|
69
|
+
errlog;
|
|
70
|
+
flexibleTaxonomy;
|
|
71
|
+
home;
|
|
72
|
+
name;
|
|
73
|
+
npmRegistry;
|
|
74
|
+
pjson;
|
|
75
|
+
platform;
|
|
76
|
+
plugins = new Map();
|
|
77
|
+
root;
|
|
78
|
+
shell;
|
|
79
|
+
topicSeparator = ':';
|
|
80
|
+
userAgent;
|
|
81
|
+
userPJSON;
|
|
82
|
+
valid;
|
|
83
|
+
version;
|
|
84
|
+
windows;
|
|
85
|
+
binAliases;
|
|
86
|
+
nsisCustomization;
|
|
87
|
+
warned = false;
|
|
88
|
+
commandPermutations = new Permutations();
|
|
89
|
+
topicPermutations = new Permutations();
|
|
90
|
+
_commands = new Map();
|
|
91
|
+
_topics = new Map();
|
|
92
|
+
_commandIDs;
|
|
93
|
+
pluginLoader;
|
|
94
|
+
static _rootPlugin;
|
|
61
95
|
constructor(options) {
|
|
62
96
|
this.options = options;
|
|
63
|
-
this._base = BASE;
|
|
64
|
-
this.debug = 0;
|
|
65
|
-
this.plugins = new Map();
|
|
66
|
-
this.topicSeparator = ':';
|
|
67
|
-
this.warned = false;
|
|
68
|
-
this.commandPermutations = new Permutations();
|
|
69
|
-
this.topicPermutations = new Permutations();
|
|
70
|
-
this._commands = new Map();
|
|
71
|
-
this._topics = new Map();
|
|
72
97
|
}
|
|
73
98
|
static async load(opts = module.filename || __dirname) {
|
|
74
99
|
// Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
|
|
@@ -119,7 +144,7 @@ class Config {
|
|
|
119
144
|
this.channel = this.options.channel || channelFromVersion(this.version);
|
|
120
145
|
this.valid = Config._rootPlugin.valid;
|
|
121
146
|
this.arch = ((0, node_os_1.arch)() === 'ia32' ? 'x86' : (0, node_os_1.arch)());
|
|
122
|
-
this.platform =
|
|
147
|
+
this.platform = is_wsl_1.default ? 'wsl' : (0, util_2.getPlatform)();
|
|
123
148
|
this.windows = this.platform === 'win32';
|
|
124
149
|
this.bin = this.pjson.oclif.bin || this.name;
|
|
125
150
|
this.binAliases = this.pjson.oclif.binAliases;
|
|
@@ -379,7 +404,7 @@ class Config {
|
|
|
379
404
|
* @returns string[]
|
|
380
405
|
*/
|
|
381
406
|
findMatches(partialCmdId, argv) {
|
|
382
|
-
const flags = argv.filter(arg => !(0,
|
|
407
|
+
const flags = argv.filter(arg => !(0, util_3.getHelpFlagAdditions)(this).includes(arg) && arg.startsWith('-')).map(a => a.replaceAll('-', ''));
|
|
383
408
|
const possibleMatches = [...this.commandPermutations.get(partialCmdId)].map(k => this._commands.get(k));
|
|
384
409
|
const matches = possibleMatches.filter(command => {
|
|
385
410
|
const cmdFlags = Object.entries(command.flags).flatMap(([flag, def]) => def.char ? [def.char, flag] : [flag]);
|
|
@@ -694,148 +719,3 @@ class Config {
|
|
|
694
719
|
}
|
|
695
720
|
}
|
|
696
721
|
exports.Config = Config;
|
|
697
|
-
// when no manifest exists, the default is calculated. This may throw, so we need to catch it
|
|
698
|
-
const defaultFlagToCached = async (flag, respectNoCacheDefault) => {
|
|
699
|
-
if (respectNoCacheDefault && flag.noCacheDefault)
|
|
700
|
-
return;
|
|
701
|
-
// Prefer the defaultHelp function (returns a friendly string for complex types)
|
|
702
|
-
if (typeof flag.defaultHelp === 'function') {
|
|
703
|
-
try {
|
|
704
|
-
return await flag.defaultHelp({ options: flag, flags: {} });
|
|
705
|
-
}
|
|
706
|
-
catch {
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
// if not specified, try the default function
|
|
711
|
-
if (typeof flag.default === 'function') {
|
|
712
|
-
try {
|
|
713
|
-
return await flag.default({ options: flag, flags: {} });
|
|
714
|
-
}
|
|
715
|
-
catch { }
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
return flag.default;
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
const defaultArgToCached = async (arg, respectNoCacheDefault) => {
|
|
722
|
-
if (respectNoCacheDefault && arg.noCacheDefault)
|
|
723
|
-
return;
|
|
724
|
-
// Prefer the defaultHelp function (returns a friendly string for complex types)
|
|
725
|
-
if (typeof arg.defaultHelp === 'function') {
|
|
726
|
-
try {
|
|
727
|
-
return await arg.defaultHelp({ options: arg, flags: {} });
|
|
728
|
-
}
|
|
729
|
-
catch {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
// if not specified, try the default function
|
|
734
|
-
if (typeof arg.default === 'function') {
|
|
735
|
-
try {
|
|
736
|
-
return await arg.default({ options: arg, flags: {} });
|
|
737
|
-
}
|
|
738
|
-
catch { }
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
return arg.default;
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
async function toCached(c, plugin, respectNoCacheDefault = false) {
|
|
745
|
-
const flags = {};
|
|
746
|
-
for (const [name, flag] of Object.entries(c.flags || {})) {
|
|
747
|
-
if (flag.type === 'boolean') {
|
|
748
|
-
flags[name] = {
|
|
749
|
-
name,
|
|
750
|
-
type: flag.type,
|
|
751
|
-
char: flag.char,
|
|
752
|
-
summary: flag.summary,
|
|
753
|
-
description: flag.description,
|
|
754
|
-
hidden: flag.hidden,
|
|
755
|
-
required: flag.required,
|
|
756
|
-
helpLabel: flag.helpLabel,
|
|
757
|
-
helpGroup: flag.helpGroup,
|
|
758
|
-
allowNo: flag.allowNo,
|
|
759
|
-
dependsOn: flag.dependsOn,
|
|
760
|
-
relationships: flag.relationships,
|
|
761
|
-
exclusive: flag.exclusive,
|
|
762
|
-
deprecated: flag.deprecated,
|
|
763
|
-
deprecateAliases: c.deprecateAliases,
|
|
764
|
-
aliases: flag.aliases,
|
|
765
|
-
charAliases: flag.charAliases,
|
|
766
|
-
delimiter: flag.delimiter,
|
|
767
|
-
noCacheDefault: flag.noCacheDefault,
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
flags[name] = {
|
|
772
|
-
name,
|
|
773
|
-
type: flag.type,
|
|
774
|
-
char: flag.char,
|
|
775
|
-
summary: flag.summary,
|
|
776
|
-
description: flag.description,
|
|
777
|
-
hidden: flag.hidden,
|
|
778
|
-
required: flag.required,
|
|
779
|
-
helpLabel: flag.helpLabel,
|
|
780
|
-
helpValue: flag.helpValue,
|
|
781
|
-
helpGroup: flag.helpGroup,
|
|
782
|
-
multiple: flag.multiple,
|
|
783
|
-
options: flag.options,
|
|
784
|
-
dependsOn: flag.dependsOn,
|
|
785
|
-
relationships: flag.relationships,
|
|
786
|
-
exclusive: flag.exclusive,
|
|
787
|
-
default: await defaultFlagToCached(flag, respectNoCacheDefault),
|
|
788
|
-
deprecated: flag.deprecated,
|
|
789
|
-
deprecateAliases: c.deprecateAliases,
|
|
790
|
-
aliases: flag.aliases,
|
|
791
|
-
charAliases: flag.charAliases,
|
|
792
|
-
delimiter: flag.delimiter,
|
|
793
|
-
noCacheDefault: flag.noCacheDefault,
|
|
794
|
-
};
|
|
795
|
-
// a command-level placeholder in the manifest so that oclif knows it should regenerate the command during help-time
|
|
796
|
-
if (typeof flag.defaultHelp === 'function') {
|
|
797
|
-
c.hasDynamicHelp = true;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
const args = {};
|
|
802
|
-
for (const [name, arg] of Object.entries((0, util_2.ensureArgObject)(c.args))) {
|
|
803
|
-
args[name] = {
|
|
804
|
-
name,
|
|
805
|
-
description: arg.description,
|
|
806
|
-
required: arg.required,
|
|
807
|
-
options: arg.options,
|
|
808
|
-
default: await defaultArgToCached(arg, respectNoCacheDefault),
|
|
809
|
-
hidden: arg.hidden,
|
|
810
|
-
noCacheDefault: arg.noCacheDefault,
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
const stdProperties = {
|
|
814
|
-
id: c.id,
|
|
815
|
-
summary: c.summary,
|
|
816
|
-
description: c.description,
|
|
817
|
-
strict: c.strict,
|
|
818
|
-
usage: c.usage,
|
|
819
|
-
pluginName: plugin && plugin.name,
|
|
820
|
-
pluginAlias: plugin && plugin.alias,
|
|
821
|
-
pluginType: plugin && plugin.type,
|
|
822
|
-
hidden: c.hidden,
|
|
823
|
-
state: c.state,
|
|
824
|
-
aliases: c.aliases || [],
|
|
825
|
-
examples: c.examples || c.example,
|
|
826
|
-
deprecationOptions: c.deprecationOptions,
|
|
827
|
-
deprecateAliases: c.deprecateAliases,
|
|
828
|
-
flags,
|
|
829
|
-
args,
|
|
830
|
-
};
|
|
831
|
-
// do not include these properties in manifest
|
|
832
|
-
const ignoreCommandProperties = ['plugin', '_flags', '_enableJsonFlag', '_globalFlags', '_baseFlags'];
|
|
833
|
-
const stdKeys = Object.keys(stdProperties);
|
|
834
|
-
const keysToAdd = Object.keys(c).filter(property => ![...stdKeys, ...ignoreCommandProperties].includes(property));
|
|
835
|
-
const additionalProperties = {};
|
|
836
|
-
for (const key of keysToAdd) {
|
|
837
|
-
additionalProperties[key] = c[key];
|
|
838
|
-
}
|
|
839
|
-
return { ...stdProperties, ...additionalProperties };
|
|
840
|
-
}
|
|
841
|
-
exports.toCached = toCached;
|
package/lib/config/index.d.ts
CHANGED
package/lib/config/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsPath = exports.Plugin = exports.
|
|
3
|
+
exports.tsPath = exports.Plugin = exports.Config = void 0;
|
|
4
4
|
var config_1 = require("./config");
|
|
5
5
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
6
|
-
var config_2 = require("./config");
|
|
7
|
-
Object.defineProperty(exports, "toCached", { enumerable: true, get: function () { return config_2.toCached; } });
|
|
8
6
|
var plugin_1 = require("./plugin");
|
|
9
7
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugin_1.Plugin; } });
|
|
10
8
|
var ts_node_1 = require("./ts-node");
|
|
@@ -9,11 +9,12 @@ const node_path_1 = require("node:path");
|
|
|
9
9
|
// eslint-disable-next-line new-cap
|
|
10
10
|
const debug = (0, util_2.Debug)();
|
|
11
11
|
class PluginLoader {
|
|
12
|
+
options;
|
|
13
|
+
plugins = new Map();
|
|
14
|
+
errors = [];
|
|
15
|
+
pluginsProvided = false;
|
|
12
16
|
constructor(options) {
|
|
13
17
|
this.options = options;
|
|
14
|
-
this.plugins = new Map();
|
|
15
|
-
this.errors = [];
|
|
16
|
-
this.pluginsProvided = false;
|
|
17
18
|
if (options.plugins) {
|
|
18
19
|
this.pluginsProvided = true;
|
|
19
20
|
this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map(p => [p.name, p])) : options.plugins;
|
|
@@ -27,7 +28,7 @@ class PluginLoader {
|
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
30
|
const marker = performance_1.Performance.mark('plugin.load#root');
|
|
30
|
-
rootPlugin = new Plugin.Plugin({ root: this.options.root });
|
|
31
|
+
rootPlugin = new Plugin.Plugin({ root: this.options.root, isRoot: true });
|
|
31
32
|
await rootPlugin.load();
|
|
32
33
|
marker?.addDetails({
|
|
33
34
|
hasManifest: rootPlugin.hasManifest ?? false,
|
package/lib/config/plugin.d.ts
CHANGED
package/lib/config/plugin.js
CHANGED
|
@@ -7,9 +7,9 @@ const util_2 = require("../util");
|
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
8
|
const module_loader_1 = require("../module-loader");
|
|
9
9
|
const performance_1 = require("../performance");
|
|
10
|
+
const cache_command_1 = require("../util/cache-command");
|
|
10
11
|
const node_util_1 = require("node:util");
|
|
11
12
|
const globby_1 = require("globby");
|
|
12
|
-
const config_1 = require("./config");
|
|
13
13
|
const ts_node_1 = require("./ts-node");
|
|
14
14
|
const _pjson = (0, util_2.requireJson)(__dirname, '..', '..', 'package.json');
|
|
15
15
|
function topicsToArray(input, base) {
|
|
@@ -17,9 +17,9 @@ function topicsToArray(input, base) {
|
|
|
17
17
|
return [];
|
|
18
18
|
base = base ? `${base}:` : '';
|
|
19
19
|
if (Array.isArray(input)) {
|
|
20
|
-
return [...input,
|
|
20
|
+
return [...input, input.flatMap(t => topicsToArray(t.subtopics, `${base}${t.name}`))];
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return Object.keys(input).flatMap(k => {
|
|
23
23
|
input[k].name = k;
|
|
24
24
|
return [{ ...input[k], name: `${base}${k}` }, ...topicsToArray(input[k].subtopics, `${base}${input[k].name}`)];
|
|
25
25
|
});
|
|
@@ -95,20 +95,37 @@ const search = (cmd) => {
|
|
|
95
95
|
return Object.values(cmd).find((cmd) => typeof cmd.run === 'function');
|
|
96
96
|
};
|
|
97
97
|
class Plugin {
|
|
98
|
+
options;
|
|
99
|
+
_base = `${_pjson.name}@${_pjson.version}`;
|
|
100
|
+
name;
|
|
101
|
+
version;
|
|
102
|
+
pjson;
|
|
103
|
+
type;
|
|
104
|
+
moduleType;
|
|
105
|
+
root;
|
|
106
|
+
alias;
|
|
107
|
+
tag;
|
|
108
|
+
manifest;
|
|
109
|
+
commands;
|
|
110
|
+
hooks;
|
|
111
|
+
valid = false;
|
|
112
|
+
alreadyLoaded = false;
|
|
113
|
+
parent;
|
|
114
|
+
children = [];
|
|
115
|
+
hasManifest = false;
|
|
116
|
+
isRoot = false;
|
|
117
|
+
_commandsDir;
|
|
118
|
+
flexibleTaxonomy;
|
|
119
|
+
// eslint-disable-next-line new-cap
|
|
120
|
+
_debug = (0, util_1.Debug)();
|
|
121
|
+
warned = false;
|
|
98
122
|
constructor(options) {
|
|
99
123
|
this.options = options;
|
|
100
|
-
this._base = `${_pjson.name}@${_pjson.version}`;
|
|
101
|
-
this.valid = false;
|
|
102
|
-
this.alreadyLoaded = false;
|
|
103
|
-
this.children = [];
|
|
104
|
-
this.hasManifest = false;
|
|
105
|
-
// eslint-disable-next-line new-cap
|
|
106
|
-
this._debug = (0, util_1.Debug)();
|
|
107
|
-
this.warned = false;
|
|
108
124
|
}
|
|
109
125
|
async load() {
|
|
110
126
|
this.type = this.options.type || 'core';
|
|
111
127
|
this.tag = this.options.tag;
|
|
128
|
+
this.isRoot = this.options.isRoot ?? false;
|
|
112
129
|
if (this.options.parent)
|
|
113
130
|
this.parent = this.options.parent;
|
|
114
131
|
// Linked plugins already have a root so there's no need to search for it.
|
|
@@ -138,7 +155,7 @@ class Plugin {
|
|
|
138
155
|
else {
|
|
139
156
|
this.pjson.oclif = this.pjson['cli-engine'] || {};
|
|
140
157
|
}
|
|
141
|
-
this.hooks = (0,
|
|
158
|
+
this.hooks = (0, util_2.mapValues)(this.pjson.oclif.hooks || {}, i => Array.isArray(i) ? i : [i]);
|
|
142
159
|
this.manifest = await this._manifest();
|
|
143
160
|
this.commands = Object
|
|
144
161
|
.entries(this.manifest.commands)
|
|
@@ -255,7 +272,7 @@ class Plugin {
|
|
|
255
272
|
version: this.version,
|
|
256
273
|
commands: (await Promise.all(this.commandIDs.map(async (id) => {
|
|
257
274
|
try {
|
|
258
|
-
const cached = await (0,
|
|
275
|
+
const cached = await (0, cache_command_1.cacheCommand)(await this.findCommand(id, { must: true }), this, respectNoCacheDefault);
|
|
259
276
|
if (this.flexibleTaxonomy) {
|
|
260
277
|
const permutations = (0, util_1.getCommandIdPermutations)(id);
|
|
261
278
|
const aliasPermutations = cached.aliases.flatMap(a => (0, util_1.getCommandIdPermutations)(a));
|
|
@@ -264,7 +281,7 @@ class Plugin {
|
|
|
264
281
|
return [id, cached];
|
|
265
282
|
}
|
|
266
283
|
catch (error) {
|
|
267
|
-
const scope = '
|
|
284
|
+
const scope = 'cacheCommand';
|
|
268
285
|
if (Boolean(errorOnManifestCreate) === false)
|
|
269
286
|
this.warn(error, scope);
|
|
270
287
|
else
|
package/lib/config/ts-node.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.tsPath = exports.TS_CONFIGS = void 0;
|
|
4
4
|
const util_1 = require("../util");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
|
-
const config_1 = require("./config");
|
|
7
6
|
const util_2 = require("./util");
|
|
8
7
|
const node_fs_1 = require("node:fs");
|
|
9
8
|
const errors_1 = require("../errors");
|
|
@@ -12,6 +11,11 @@ const settings_1 = require("../settings");
|
|
|
12
11
|
const debug = (0, util_2.Debug)('ts-node');
|
|
13
12
|
exports.TS_CONFIGS = {};
|
|
14
13
|
const REGISTERED = new Set();
|
|
14
|
+
/**
|
|
15
|
+
* Cache the root plugin so that we can reference it later when determining if
|
|
16
|
+
* we should skip ts-node registration for an ESM plugin.
|
|
17
|
+
*/
|
|
18
|
+
let ROOT_PLUGIN;
|
|
15
19
|
function loadTSConfig(root) {
|
|
16
20
|
if (exports.TS_CONFIGS[root])
|
|
17
21
|
return exports.TS_CONFIGS[root];
|
|
@@ -105,6 +109,8 @@ function registerTSNode(root) {
|
|
|
105
109
|
return tsconfig;
|
|
106
110
|
}
|
|
107
111
|
function tsPath(root, orig, plugin) {
|
|
112
|
+
if (plugin?.isRoot)
|
|
113
|
+
ROOT_PLUGIN = plugin;
|
|
108
114
|
if (!orig)
|
|
109
115
|
return orig;
|
|
110
116
|
orig = orig.startsWith(root) ? orig : (0, node_path_1.join)(root, orig);
|
|
@@ -126,8 +132,8 @@ function tsPath(root, orig, plugin) {
|
|
|
126
132
|
* We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM.
|
|
127
133
|
* In other words, this allows plugins to be auto-transpiled when developing locally using `bin/dev.js`.
|
|
128
134
|
*/
|
|
129
|
-
if ((isProduction ||
|
|
130
|
-
debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${
|
|
135
|
+
if ((isProduction || ROOT_PLUGIN?.moduleType === 'commonjs') && plugin?.moduleType === 'module') {
|
|
136
|
+
debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${ROOT_PLUGIN?.moduleType})))`);
|
|
131
137
|
if (plugin.type === 'link')
|
|
132
138
|
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
133
139
|
return orig;
|
package/lib/config/util.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export declare function flatMap<T, U>(arr: T[], fn: (i: T) => U[]): U[];
|
|
2
|
-
export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
|
|
3
|
-
[P in keyof T]: T[P];
|
|
4
|
-
}, fn: (i: T[keyof T], k: keyof T) => TResult): {
|
|
5
|
-
[P in keyof T]: TResult;
|
|
6
|
-
};
|
|
7
1
|
export declare function resolvePackage(id: string, paths: {
|
|
8
2
|
paths: string[];
|
|
9
3
|
}): string;
|
package/lib/config/util.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.resolvePackage =
|
|
3
|
+
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.resolvePackage = void 0;
|
|
4
4
|
const debug = require('debug');
|
|
5
|
-
function flatMap(arr, fn) {
|
|
6
|
-
return arr.reduce((arr, i) => [...arr, ...fn(i)], []);
|
|
7
|
-
}
|
|
8
|
-
exports.flatMap = flatMap;
|
|
9
|
-
function mapValues(obj, fn) {
|
|
10
|
-
return Object.entries(obj)
|
|
11
|
-
.reduce((o, [k, v]) => {
|
|
12
|
-
o[k] = fn(v, k);
|
|
13
|
-
return o;
|
|
14
|
-
}, {});
|
|
15
|
-
}
|
|
16
|
-
exports.mapValues = mapValues;
|
|
17
5
|
function resolvePackage(id, paths) {
|
|
18
6
|
return require.resolve(id, paths);
|
|
19
7
|
}
|
package/lib/errors/errors/cli.js
CHANGED
|
@@ -20,9 +20,11 @@ function addOclifExitCode(error, options) {
|
|
|
20
20
|
}
|
|
21
21
|
exports.addOclifExitCode = addOclifExitCode;
|
|
22
22
|
class CLIError extends Error {
|
|
23
|
+
oclif = {};
|
|
24
|
+
code;
|
|
25
|
+
suggestions;
|
|
23
26
|
constructor(error, options = {}) {
|
|
24
27
|
super(error instanceof Error ? error.message : error);
|
|
25
|
-
this.oclif = {};
|
|
26
28
|
addOclifExitCode(this, options);
|
|
27
29
|
this.code = options.code;
|
|
28
30
|
this.suggestions = options.suggestions;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExitError = void 0;
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
class ExitError extends cli_1.CLIError {
|
|
6
|
+
code = 'EEXIT';
|
|
6
7
|
constructor(exitCode = 1) {
|
|
7
8
|
super(`EEXIT: ${exitCode}`, { exit: exitCode });
|
|
8
|
-
this.code = 'EEXIT';
|
|
9
9
|
}
|
|
10
10
|
render() {
|
|
11
11
|
return '';
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModuleLoadError = void 0;
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
class ModuleLoadError extends cli_1.CLIError {
|
|
6
|
+
code = 'MODULE_NOT_FOUND';
|
|
6
7
|
constructor(message) {
|
|
7
8
|
super(`[MODULE_NOT_FOUND] ${message}`, { exit: 1 });
|
|
8
|
-
this.code = 'MODULE_NOT_FOUND';
|
|
9
9
|
this.name = 'ModuleLoadError';
|
|
10
10
|
}
|
|
11
11
|
}
|
package/lib/errors/handle.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handle = exports.Exit = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const cli_1 = require("./errors/cli");
|
|
6
|
-
const
|
|
6
|
+
const exit_1 = require("./errors/exit");
|
|
7
7
|
const clean_stack_1 = tslib_1.__importDefault(require("clean-stack"));
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
const pretty_print_1 = tslib_1.__importDefault(require("./errors/pretty-print"));
|
|
@@ -23,7 +23,7 @@ async function handle(err) {
|
|
|
23
23
|
err = new cli_1.CLIError('no error?');
|
|
24
24
|
if (err.message === 'SIGINT')
|
|
25
25
|
exports.Exit.exit(1);
|
|
26
|
-
const shouldPrint = !(err instanceof
|
|
26
|
+
const shouldPrint = !(err instanceof exit_1.ExitError) && !err.skipOclifErrorHandling;
|
|
27
27
|
const pretty = (0, pretty_print_1.default)(err);
|
|
28
28
|
const stack = (0, clean_stack_1.default)(err.stack || '', { pretty: true });
|
|
29
29
|
if (shouldPrint) {
|
package/lib/errors/logger.js
CHANGED
|
@@ -17,10 +17,11 @@ function chomp(s) {
|
|
|
17
17
|
return s;
|
|
18
18
|
}
|
|
19
19
|
class Logger {
|
|
20
|
+
file;
|
|
21
|
+
flushing = Promise.resolve();
|
|
22
|
+
buffer = [];
|
|
20
23
|
constructor(file) {
|
|
21
24
|
this.file = file;
|
|
22
|
-
this.flushing = Promise.resolve();
|
|
23
|
-
this.buffer = [];
|
|
24
25
|
}
|
|
25
26
|
log(msg) {
|
|
26
27
|
msg = stripAnsi(chomp(msg));
|
package/lib/flags.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare function custom<T = string, P extends CustomOptions = CustomOptio
|
|
|
12
12
|
multiple: true;
|
|
13
13
|
requiredOrDefaulted: true;
|
|
14
14
|
}>;
|
|
15
|
-
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T
|
|
15
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<NotArray<T>, P>> & {
|
|
16
16
|
multiple?: false | undefined;
|
|
17
17
|
} & ({
|
|
18
18
|
required: true;
|
|
@@ -22,7 +22,7 @@ export declare function custom<T = string, P extends CustomOptions = CustomOptio
|
|
|
22
22
|
multiple: false;
|
|
23
23
|
requiredOrDefaulted: true;
|
|
24
24
|
}>;
|
|
25
|
-
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T
|
|
25
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<NotArray<T>, P>> & {
|
|
26
26
|
default?: OptionFlag<NotArray<T>, P>['default'] | undefined;
|
|
27
27
|
multiple?: false | undefined;
|
|
28
28
|
required?: false | undefined;
|
package/lib/help/command.js
CHANGED
package/lib/help/docopts.js
CHANGED
package/lib/help/formatter.js
CHANGED
|
@@ -11,12 +11,23 @@ const widest_line_1 = tslib_1.__importDefault(require("widest-line"));
|
|
|
11
11
|
const string_width_1 = tslib_1.__importDefault(require("string-width"));
|
|
12
12
|
const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
|
|
13
13
|
class HelpFormatter {
|
|
14
|
+
indentSpacing = 2;
|
|
15
|
+
/**
|
|
16
|
+
* Takes a string and replaces `<%= prop =>` with the value of prop, where prop is anything on
|
|
17
|
+
* `config=Interfaces.Config` or `opts=Interface.HelpOptions`.
|
|
18
|
+
*
|
|
19
|
+
* ```javascript
|
|
20
|
+
* `<%= config.bin =>` // will resolve to the bin defined in `pjson.oclif`.
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
render;
|
|
14
24
|
constructor(config, opts = {}) {
|
|
15
|
-
this.indentSpacing = 2;
|
|
16
25
|
this.config = config;
|
|
17
26
|
this.opts = { maxWidth: screen_1.stdtermwidth, ...opts };
|
|
18
27
|
this.render = (0, util_1.template)(this);
|
|
19
28
|
}
|
|
29
|
+
config;
|
|
30
|
+
opts;
|
|
20
31
|
/**
|
|
21
32
|
* Wrap text according to `opts.maxWidth` which is typically set to the terminal width. All text
|
|
22
33
|
* will be rendered before bring wrapped, otherwise it could mess up the lengths.
|
package/lib/help/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Command } from '../command';
|
|
|
3
3
|
import { CommandHelp } from './command';
|
|
4
4
|
import { HelpFormatter } from './formatter';
|
|
5
5
|
export { CommandHelp } from './command';
|
|
6
|
-
export { standardizeIDFromArgv,
|
|
6
|
+
export { standardizeIDFromArgv, getHelpFlagAdditions, normalizeArgv } from './util';
|
|
7
7
|
export declare abstract class HelpBase extends HelpFormatter {
|
|
8
8
|
constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>);
|
|
9
9
|
/**
|
|
@@ -39,3 +39,7 @@ export declare class Help extends HelpBase {
|
|
|
39
39
|
protected command(command: Command.Class): string;
|
|
40
40
|
protected log(...args: string[]): void;
|
|
41
41
|
}
|
|
42
|
+
interface HelpBaseDerived {
|
|
43
|
+
new (config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>): HelpBase;
|
|
44
|
+
}
|
|
45
|
+
export declare function loadHelpClass(config: Interfaces.Config): Promise<HelpBaseDerived>;
|