@oclif/core 3.0.4 → 3.0.5-dev.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.
- package/lib/cli-ux/action/base.d.ts +12 -12
- package/lib/cli-ux/action/base.js +78 -78
- package/lib/cli-ux/stream.d.ts +1 -1
- package/lib/cli-ux/stream.js +3 -3
- package/lib/cli-ux/styled/table.js +64 -64
- package/lib/command.d.ts +8 -8
- package/lib/command.js +32 -32
- package/lib/config/config.d.ts +50 -50
- package/lib/config/config.js +210 -210
- package/lib/config/plugin-loader.d.ts +5 -5
- package/lib/config/plugin-loader.js +32 -32
- package/lib/config/plugin.d.ts +10 -10
- package/lib/config/plugin.js +145 -133
- package/lib/errors/errors/cli.d.ts +2 -2
- package/lib/errors/errors/cli.js +9 -9
- package/lib/help/command.d.ts +2 -2
- package/lib/help/command.js +11 -11
- package/lib/help/docopts.d.ts +1 -1
- package/lib/help/docopts.js +20 -20
- package/lib/help/index.d.ts +3 -3
- package/lib/help/index.js +25 -25
- package/lib/parser/parse.d.ts +2 -2
- package/lib/parser/parse.js +89 -89
- package/lib/performance.d.ts +2 -2
- package/lib/performance.js +2 -2
- package/lib/util/fs.d.ts +13 -1
- package/lib/util/fs.js +29 -14
- package/package.json +2 -3
package/lib/config/config.js
CHANGED
|
@@ -58,14 +58,6 @@ class Permutations extends Map {
|
|
|
58
58
|
}
|
|
59
59
|
class Config {
|
|
60
60
|
options;
|
|
61
|
-
_base = BASE;
|
|
62
|
-
_commandIDs;
|
|
63
|
-
_commands = new Map();
|
|
64
|
-
static _rootPlugin;
|
|
65
|
-
_topics = new Map();
|
|
66
|
-
commandPermutations = new Permutations();
|
|
67
|
-
pluginLoader;
|
|
68
|
-
topicPermutations = new Permutations();
|
|
69
61
|
arch;
|
|
70
62
|
bin;
|
|
71
63
|
binAliases;
|
|
@@ -94,6 +86,14 @@ class Config {
|
|
|
94
86
|
version;
|
|
95
87
|
warned = false;
|
|
96
88
|
windows;
|
|
89
|
+
_base = BASE;
|
|
90
|
+
_commandIDs;
|
|
91
|
+
_commands = new Map();
|
|
92
|
+
static _rootPlugin;
|
|
93
|
+
_topics = new Map();
|
|
94
|
+
commandPermutations = new Permutations();
|
|
95
|
+
pluginLoader;
|
|
96
|
+
topicPermutations = new Permutations();
|
|
97
97
|
constructor(options) {
|
|
98
98
|
this.options = options;
|
|
99
99
|
}
|
|
@@ -130,190 +130,32 @@ class Config {
|
|
|
130
130
|
static get rootPlugin() {
|
|
131
131
|
return Config._rootPlugin;
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
if (this.
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (enabled)
|
|
139
|
-
return 1;
|
|
140
|
-
}
|
|
141
|
-
catch { }
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
144
|
-
_shell() {
|
|
145
|
-
let shellPath;
|
|
146
|
-
const { COMSPEC } = process.env;
|
|
147
|
-
const SHELL = process.env.SHELL ?? (0, node_os_1.userInfo)().shell?.split(node_path_1.sep)?.pop();
|
|
148
|
-
if (SHELL) {
|
|
149
|
-
shellPath = SHELL.split('/');
|
|
150
|
-
}
|
|
151
|
-
else if (this.windows && COMSPEC) {
|
|
152
|
-
shellPath = COMSPEC.split(/\\|\//);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
shellPath = ['unknown'];
|
|
156
|
-
}
|
|
157
|
-
return shellPath.at(-1) ?? 'unknown';
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* This method is responsible for locating the correct plugin to use for a named command id
|
|
161
|
-
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
|
162
|
-
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
|
163
|
-
* create the same command or command alias.
|
|
164
|
-
*
|
|
165
|
-
* In the case of more than one found command, the function will select the command based on the order in which
|
|
166
|
-
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
|
167
|
-
* is selected as the command to run.
|
|
168
|
-
*
|
|
169
|
-
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
|
170
|
-
* is present, this function defers to the core plugin.
|
|
171
|
-
*
|
|
172
|
-
* If there is not a core plugin command present, this function will return the first
|
|
173
|
-
* plugin as discovered (will not change the order)
|
|
174
|
-
*
|
|
175
|
-
* @param commands commands to determine the priority of
|
|
176
|
-
* @returns command instance {Command.Loadable} or undefined
|
|
177
|
-
*/
|
|
178
|
-
determinePriority(commands) {
|
|
179
|
-
const oclifPlugins = this.pjson.oclif?.plugins ?? [];
|
|
180
|
-
const commandPlugins = commands.sort((a, b) => {
|
|
181
|
-
const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
|
|
182
|
-
const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
|
|
183
|
-
const aIndex = oclifPlugins.indexOf(pluginAliasA);
|
|
184
|
-
const bIndex = oclifPlugins.indexOf(pluginAliasB);
|
|
185
|
-
// When both plugin types are 'core' plugins sort based on index
|
|
186
|
-
if (a.pluginType === 'core' && b.pluginType === 'core') {
|
|
187
|
-
// If b appears first in the pjson.plugins sort it first
|
|
188
|
-
return aIndex - bIndex;
|
|
189
|
-
}
|
|
190
|
-
// if b is a core plugin and a is not sort b first
|
|
191
|
-
if (b.pluginType === 'core' && a.pluginType !== 'core') {
|
|
192
|
-
return 1;
|
|
193
|
-
}
|
|
194
|
-
// if a is a core plugin and b is not sort a first
|
|
195
|
-
if (a.pluginType === 'core' && b.pluginType !== 'core') {
|
|
196
|
-
return -1;
|
|
197
|
-
}
|
|
198
|
-
// if a is a jit plugin and b is not sort b first
|
|
199
|
-
if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
|
|
200
|
-
return 1;
|
|
201
|
-
}
|
|
202
|
-
// if b is a jit plugin and a is not sort a first
|
|
203
|
-
if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
|
|
204
|
-
return -1;
|
|
205
|
-
}
|
|
206
|
-
// neither plugin is core, so do not change the order
|
|
207
|
-
return 0;
|
|
208
|
-
});
|
|
209
|
-
return commandPlugins[0];
|
|
210
|
-
}
|
|
211
|
-
getCmdLookupId(id) {
|
|
212
|
-
if (this._commands.has(id))
|
|
213
|
-
return id;
|
|
214
|
-
if (this.commandPermutations.hasValid(id))
|
|
215
|
-
return this.commandPermutations.getValid(id);
|
|
216
|
-
return id;
|
|
217
|
-
}
|
|
218
|
-
getTopicLookupId(id) {
|
|
219
|
-
if (this._topics.has(id))
|
|
220
|
-
return id;
|
|
221
|
-
if (this.topicPermutations.hasValid(id))
|
|
222
|
-
return this.topicPermutations.getValid(id);
|
|
223
|
-
return id;
|
|
133
|
+
get commandIDs() {
|
|
134
|
+
if (this._commandIDs)
|
|
135
|
+
return this._commandIDs;
|
|
136
|
+
this._commandIDs = this.commands.map((c) => c.id);
|
|
137
|
+
return this._commandIDs;
|
|
224
138
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
*
|
|
228
|
-
* Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
|
|
229
|
-
* with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
|
|
230
|
-
*
|
|
231
|
-
* @param plugins array of oclif-compatible plugins
|
|
232
|
-
* @returns void
|
|
233
|
-
*/
|
|
234
|
-
insertLegacyPlugins(plugins) {
|
|
235
|
-
for (const plugin of plugins) {
|
|
236
|
-
this.plugins.set(plugin.name, plugin);
|
|
237
|
-
this.loadCommands(plugin);
|
|
238
|
-
}
|
|
139
|
+
get commands() {
|
|
140
|
+
return [...this._commands.values()];
|
|
239
141
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return (Object.keys(this.pjson.oclif.jitPlugins ?? {}).includes(c.pluginName ?? '') &&
|
|
243
|
-
Boolean(c?.pluginName && !this.plugins.has(c.pluginName)));
|
|
142
|
+
get isProd() {
|
|
143
|
+
return (0, util_2.isProd)();
|
|
244
144
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
for (const command of plugin.commands) {
|
|
248
|
-
// set canonical command id
|
|
249
|
-
if (this._commands.has(command.id)) {
|
|
250
|
-
const prioritizedCommand = this.determinePriority([this._commands.get(command.id), command]);
|
|
251
|
-
this._commands.set(prioritizedCommand.id, prioritizedCommand);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
this._commands.set(command.id, command);
|
|
255
|
-
}
|
|
256
|
-
// v3 moved command id permutations to the manifest, but some plugins may not have
|
|
257
|
-
// the new manifest yet. For those, we need to calculate the permutations here.
|
|
258
|
-
const permutations = this.flexibleTaxonomy && command.permutations === undefined
|
|
259
|
-
? (0, util_3.getCommandIdPermutations)(command.id)
|
|
260
|
-
: command.permutations ?? [command.id];
|
|
261
|
-
// set every permutation
|
|
262
|
-
for (const permutation of permutations) {
|
|
263
|
-
this.commandPermutations.add(permutation, command.id);
|
|
264
|
-
}
|
|
265
|
-
// set command aliases
|
|
266
|
-
for (const alias of command.aliases ?? []) {
|
|
267
|
-
if (this._commands.has(alias)) {
|
|
268
|
-
const prioritizedCommand = this.determinePriority([this._commands.get(alias), command]);
|
|
269
|
-
this._commands.set(alias, { ...prioritizedCommand, id: alias });
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
this._commands.set(alias, { ...command, id: alias });
|
|
273
|
-
}
|
|
274
|
-
// set every permutation of the aliases
|
|
275
|
-
// v3 moved command alias permutations to the manifest, but some plugins may not have
|
|
276
|
-
// the new manifest yet. For those, we need to calculate the permutations here.
|
|
277
|
-
const aliasPermutations = this.flexibleTaxonomy && command.aliasPermutations === undefined
|
|
278
|
-
? (0, util_3.getCommandIdPermutations)(alias)
|
|
279
|
-
: command.permutations ?? [alias];
|
|
280
|
-
// set every permutation
|
|
281
|
-
for (const permutation of aliasPermutations) {
|
|
282
|
-
this.commandPermutations.add(permutation, command.id);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
marker?.addDetails({ commandCount: plugin.commands.length });
|
|
287
|
-
marker?.stop();
|
|
145
|
+
get topics() {
|
|
146
|
+
return [...this._topics.values()];
|
|
288
147
|
}
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const permutations = this.flexibleTaxonomy ? (0, util_3.getCommandIdPermutations)(topic.name) : [topic.name];
|
|
301
|
-
for (const permutation of permutations) {
|
|
302
|
-
this.topicPermutations.add(permutation, topic.name);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
// Add missing topics for displaying help when partial commands are entered.
|
|
306
|
-
for (const c of plugin.commands.filter((c) => !c.hidden)) {
|
|
307
|
-
const parts = c.id.split(':');
|
|
308
|
-
while (parts.length > 0) {
|
|
309
|
-
const name = parts.join(':');
|
|
310
|
-
if (name && !this._topics.has(name)) {
|
|
311
|
-
this._topics.set(name, { description: c.summary || c.description, name });
|
|
312
|
-
}
|
|
313
|
-
parts.pop();
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
marker?.stop();
|
|
148
|
+
get versionDetails() {
|
|
149
|
+
const [cliVersion, architecture, nodeVersion] = this.userAgent.split(' ');
|
|
150
|
+
return {
|
|
151
|
+
architecture,
|
|
152
|
+
cliVersion,
|
|
153
|
+
nodeVersion,
|
|
154
|
+
osVersion: `${(0, node_os_1.type)()} ${(0, node_os_1.release)()}`,
|
|
155
|
+
pluginVersions: Object.fromEntries([...this.plugins.values()].map((p) => [p.name, { root: p.root, type: p.type, version: p.version }])),
|
|
156
|
+
rootPath: this.root,
|
|
157
|
+
shell: this.shell,
|
|
158
|
+
};
|
|
317
159
|
}
|
|
318
160
|
dir(category) {
|
|
319
161
|
const base = process.env[`XDG_${category.toUpperCase()}_HOME`] ||
|
|
@@ -705,32 +547,190 @@ class Config {
|
|
|
705
547
|
windowsUserprofileHome() {
|
|
706
548
|
return process.env.USERPROFILE;
|
|
707
549
|
}
|
|
708
|
-
|
|
709
|
-
if (this.
|
|
710
|
-
return
|
|
711
|
-
|
|
712
|
-
|
|
550
|
+
_debug() {
|
|
551
|
+
if (this.scopedEnvVarTrue('DEBUG'))
|
|
552
|
+
return 1;
|
|
553
|
+
try {
|
|
554
|
+
const { enabled } = require('debug')(this.bin);
|
|
555
|
+
if (enabled)
|
|
556
|
+
return 1;
|
|
557
|
+
}
|
|
558
|
+
catch { }
|
|
559
|
+
return 0;
|
|
713
560
|
}
|
|
714
|
-
|
|
715
|
-
|
|
561
|
+
_shell() {
|
|
562
|
+
let shellPath;
|
|
563
|
+
const { COMSPEC } = process.env;
|
|
564
|
+
const SHELL = process.env.SHELL ?? (0, node_os_1.userInfo)().shell?.split(node_path_1.sep)?.pop();
|
|
565
|
+
if (SHELL) {
|
|
566
|
+
shellPath = SHELL.split('/');
|
|
567
|
+
}
|
|
568
|
+
else if (this.windows && COMSPEC) {
|
|
569
|
+
shellPath = COMSPEC.split(/\\|\//);
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
shellPath = ['unknown'];
|
|
573
|
+
}
|
|
574
|
+
return shellPath.at(-1) ?? 'unknown';
|
|
716
575
|
}
|
|
717
|
-
|
|
718
|
-
|
|
576
|
+
/**
|
|
577
|
+
* This method is responsible for locating the correct plugin to use for a named command id
|
|
578
|
+
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
|
579
|
+
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
|
580
|
+
* create the same command or command alias.
|
|
581
|
+
*
|
|
582
|
+
* In the case of more than one found command, the function will select the command based on the order in which
|
|
583
|
+
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
|
584
|
+
* is selected as the command to run.
|
|
585
|
+
*
|
|
586
|
+
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
|
587
|
+
* is present, this function defers to the core plugin.
|
|
588
|
+
*
|
|
589
|
+
* If there is not a core plugin command present, this function will return the first
|
|
590
|
+
* plugin as discovered (will not change the order)
|
|
591
|
+
*
|
|
592
|
+
* @param commands commands to determine the priority of
|
|
593
|
+
* @returns command instance {Command.Loadable} or undefined
|
|
594
|
+
*/
|
|
595
|
+
determinePriority(commands) {
|
|
596
|
+
const oclifPlugins = this.pjson.oclif?.plugins ?? [];
|
|
597
|
+
const commandPlugins = commands.sort((a, b) => {
|
|
598
|
+
const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
|
|
599
|
+
const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
|
|
600
|
+
const aIndex = oclifPlugins.indexOf(pluginAliasA);
|
|
601
|
+
const bIndex = oclifPlugins.indexOf(pluginAliasB);
|
|
602
|
+
// When both plugin types are 'core' plugins sort based on index
|
|
603
|
+
if (a.pluginType === 'core' && b.pluginType === 'core') {
|
|
604
|
+
// If b appears first in the pjson.plugins sort it first
|
|
605
|
+
return aIndex - bIndex;
|
|
606
|
+
}
|
|
607
|
+
// if b is a core plugin and a is not sort b first
|
|
608
|
+
if (b.pluginType === 'core' && a.pluginType !== 'core') {
|
|
609
|
+
return 1;
|
|
610
|
+
}
|
|
611
|
+
// if a is a core plugin and b is not sort a first
|
|
612
|
+
if (a.pluginType === 'core' && b.pluginType !== 'core') {
|
|
613
|
+
return -1;
|
|
614
|
+
}
|
|
615
|
+
// if a is a jit plugin and b is not sort b first
|
|
616
|
+
if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
|
|
617
|
+
return 1;
|
|
618
|
+
}
|
|
619
|
+
// if b is a jit plugin and a is not sort a first
|
|
620
|
+
if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
|
|
621
|
+
return -1;
|
|
622
|
+
}
|
|
623
|
+
// neither plugin is core, so do not change the order
|
|
624
|
+
return 0;
|
|
625
|
+
});
|
|
626
|
+
return commandPlugins[0];
|
|
719
627
|
}
|
|
720
|
-
|
|
721
|
-
|
|
628
|
+
getCmdLookupId(id) {
|
|
629
|
+
if (this._commands.has(id))
|
|
630
|
+
return id;
|
|
631
|
+
if (this.commandPermutations.hasValid(id))
|
|
632
|
+
return this.commandPermutations.getValid(id);
|
|
633
|
+
return id;
|
|
722
634
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
635
|
+
getTopicLookupId(id) {
|
|
636
|
+
if (this._topics.has(id))
|
|
637
|
+
return id;
|
|
638
|
+
if (this.topicPermutations.hasValid(id))
|
|
639
|
+
return this.topicPermutations.getValid(id);
|
|
640
|
+
return id;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Insert legacy plugins
|
|
644
|
+
*
|
|
645
|
+
* Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
|
|
646
|
+
* with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
|
|
647
|
+
*
|
|
648
|
+
* @param plugins array of oclif-compatible plugins
|
|
649
|
+
* @returns void
|
|
650
|
+
*/
|
|
651
|
+
insertLegacyPlugins(plugins) {
|
|
652
|
+
for (const plugin of plugins) {
|
|
653
|
+
this.plugins.set(plugin.name, plugin);
|
|
654
|
+
this.loadCommands(plugin);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
isJitPluginCommand(c) {
|
|
658
|
+
// Return true if the command's plugin is listed under oclif.jitPlugins AND if the plugin hasn't been loaded to this.plugins
|
|
659
|
+
return (Object.keys(this.pjson.oclif.jitPlugins ?? {}).includes(c.pluginName ?? '') &&
|
|
660
|
+
Boolean(c?.pluginName && !this.plugins.has(c.pluginName)));
|
|
661
|
+
}
|
|
662
|
+
loadCommands(plugin) {
|
|
663
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadCommands#${plugin.name}`, { plugin: plugin.name });
|
|
664
|
+
for (const command of plugin.commands) {
|
|
665
|
+
// set canonical command id
|
|
666
|
+
if (this._commands.has(command.id)) {
|
|
667
|
+
const prioritizedCommand = this.determinePriority([this._commands.get(command.id), command]);
|
|
668
|
+
this._commands.set(prioritizedCommand.id, prioritizedCommand);
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
this._commands.set(command.id, command);
|
|
672
|
+
}
|
|
673
|
+
// v3 moved command id permutations to the manifest, but some plugins may not have
|
|
674
|
+
// the new manifest yet. For those, we need to calculate the permutations here.
|
|
675
|
+
const permutations = this.flexibleTaxonomy && command.permutations === undefined
|
|
676
|
+
? (0, util_3.getCommandIdPermutations)(command.id)
|
|
677
|
+
: command.permutations ?? [command.id];
|
|
678
|
+
// set every permutation
|
|
679
|
+
for (const permutation of permutations) {
|
|
680
|
+
this.commandPermutations.add(permutation, command.id);
|
|
681
|
+
}
|
|
682
|
+
// set command aliases
|
|
683
|
+
for (const alias of command.aliases ?? []) {
|
|
684
|
+
if (this._commands.has(alias)) {
|
|
685
|
+
const prioritizedCommand = this.determinePriority([this._commands.get(alias), command]);
|
|
686
|
+
this._commands.set(alias, { ...prioritizedCommand, id: alias });
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
this._commands.set(alias, { ...command, id: alias });
|
|
690
|
+
}
|
|
691
|
+
// set every permutation of the aliases
|
|
692
|
+
// v3 moved command alias permutations to the manifest, but some plugins may not have
|
|
693
|
+
// the new manifest yet. For those, we need to calculate the permutations here.
|
|
694
|
+
const aliasPermutations = this.flexibleTaxonomy && command.aliasPermutations === undefined
|
|
695
|
+
? (0, util_3.getCommandIdPermutations)(alias)
|
|
696
|
+
: command.permutations ?? [alias];
|
|
697
|
+
// set every permutation
|
|
698
|
+
for (const permutation of aliasPermutations) {
|
|
699
|
+
this.commandPermutations.add(permutation, command.id);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
marker?.addDetails({ commandCount: plugin.commands.length });
|
|
704
|
+
marker?.stop();
|
|
705
|
+
}
|
|
706
|
+
loadTopics(plugin) {
|
|
707
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
708
|
+
for (const topic of (0, util_2.compact)(plugin.topics)) {
|
|
709
|
+
const existing = this._topics.get(topic.name);
|
|
710
|
+
if (existing) {
|
|
711
|
+
existing.description = topic.description || existing.description;
|
|
712
|
+
existing.hidden = existing.hidden || topic.hidden;
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
this._topics.set(topic.name, topic);
|
|
716
|
+
}
|
|
717
|
+
const permutations = this.flexibleTaxonomy ? (0, util_3.getCommandIdPermutations)(topic.name) : [topic.name];
|
|
718
|
+
for (const permutation of permutations) {
|
|
719
|
+
this.topicPermutations.add(permutation, topic.name);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
// Add missing topics for displaying help when partial commands are entered.
|
|
723
|
+
for (const c of plugin.commands.filter((c) => !c.hidden)) {
|
|
724
|
+
const parts = c.id.split(':');
|
|
725
|
+
while (parts.length > 0) {
|
|
726
|
+
const name = parts.join(':');
|
|
727
|
+
if (name && !this._topics.has(name)) {
|
|
728
|
+
this._topics.set(name, { description: c.summary || c.description, name });
|
|
729
|
+
}
|
|
730
|
+
parts.pop();
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
marker?.stop();
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
736
|
exports.Config = Config;
|
|
@@ -13,18 +13,18 @@ type LoadOpts = {
|
|
|
13
13
|
type PluginsMap = Map<string, IPlugin>;
|
|
14
14
|
export default class PluginLoader {
|
|
15
15
|
options: PluginLoaderOptions;
|
|
16
|
-
private pluginsProvided;
|
|
17
16
|
errors: (Error | string)[];
|
|
18
17
|
plugins: PluginsMap;
|
|
18
|
+
private pluginsProvided;
|
|
19
19
|
constructor(options: PluginLoaderOptions);
|
|
20
|
-
private loadCorePlugins;
|
|
21
|
-
private loadDevPlugins;
|
|
22
|
-
private loadPlugins;
|
|
23
|
-
private loadUserPlugins;
|
|
24
20
|
loadChildren(opts: LoadOpts): Promise<{
|
|
25
21
|
errors: (Error | string)[];
|
|
26
22
|
plugins: PluginsMap;
|
|
27
23
|
}>;
|
|
28
24
|
loadRoot(): Promise<IPlugin>;
|
|
25
|
+
private loadCorePlugins;
|
|
26
|
+
private loadDevPlugins;
|
|
27
|
+
private loadPlugins;
|
|
28
|
+
private loadUserPlugins;
|
|
29
29
|
}
|
|
30
30
|
export {};
|
|
@@ -11,9 +11,9 @@ const util_2 = require("./util");
|
|
|
11
11
|
const debug = (0, util_2.Debug)();
|
|
12
12
|
class PluginLoader {
|
|
13
13
|
options;
|
|
14
|
-
pluginsProvided = false;
|
|
15
14
|
errors = [];
|
|
16
15
|
plugins = new Map();
|
|
16
|
+
pluginsProvided = false;
|
|
17
17
|
constructor(options) {
|
|
18
18
|
this.options = options;
|
|
19
19
|
if (options.plugins) {
|
|
@@ -21,6 +21,37 @@ class PluginLoader {
|
|
|
21
21
|
this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map((p) => [p.name, p])) : options.plugins;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
async loadChildren(opts) {
|
|
25
|
+
if (!this.pluginsProvided || opts.force) {
|
|
26
|
+
await this.loadUserPlugins(opts);
|
|
27
|
+
await this.loadDevPlugins(opts);
|
|
28
|
+
await this.loadCorePlugins(opts);
|
|
29
|
+
}
|
|
30
|
+
return { errors: this.errors, plugins: this.plugins };
|
|
31
|
+
}
|
|
32
|
+
async loadRoot() {
|
|
33
|
+
let rootPlugin;
|
|
34
|
+
if (this.pluginsProvided) {
|
|
35
|
+
const plugins = [...this.plugins.values()];
|
|
36
|
+
rootPlugin = plugins.find((p) => p.root === this.options.root) ?? plugins[0];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
|
|
40
|
+
rootPlugin = new Plugin.Plugin({ isRoot: true, root: this.options.root });
|
|
41
|
+
await rootPlugin.load();
|
|
42
|
+
marker?.addDetails({
|
|
43
|
+
commandCount: rootPlugin.commands.length,
|
|
44
|
+
hasManifest: rootPlugin.hasManifest ?? false,
|
|
45
|
+
name: rootPlugin.name,
|
|
46
|
+
topicCount: rootPlugin.topics.length,
|
|
47
|
+
type: rootPlugin.type,
|
|
48
|
+
usesMain: Boolean(rootPlugin.pjson.main),
|
|
49
|
+
});
|
|
50
|
+
marker?.stop();
|
|
51
|
+
}
|
|
52
|
+
this.plugins.set(rootPlugin.name, rootPlugin);
|
|
53
|
+
return rootPlugin;
|
|
54
|
+
}
|
|
24
55
|
async loadCorePlugins(opts) {
|
|
25
56
|
if (opts.rootPlugin.pjson.oclif.plugins) {
|
|
26
57
|
await this.loadPlugins(opts.rootPlugin.root, 'core', opts.rootPlugin.pjson.oclif.plugins);
|
|
@@ -110,36 +141,5 @@ class PluginLoader {
|
|
|
110
141
|
}
|
|
111
142
|
}
|
|
112
143
|
}
|
|
113
|
-
async loadChildren(opts) {
|
|
114
|
-
if (!this.pluginsProvided || opts.force) {
|
|
115
|
-
await this.loadUserPlugins(opts);
|
|
116
|
-
await this.loadDevPlugins(opts);
|
|
117
|
-
await this.loadCorePlugins(opts);
|
|
118
|
-
}
|
|
119
|
-
return { errors: this.errors, plugins: this.plugins };
|
|
120
|
-
}
|
|
121
|
-
async loadRoot() {
|
|
122
|
-
let rootPlugin;
|
|
123
|
-
if (this.pluginsProvided) {
|
|
124
|
-
const plugins = [...this.plugins.values()];
|
|
125
|
-
rootPlugin = plugins.find((p) => p.root === this.options.root) ?? plugins[0];
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
|
|
129
|
-
rootPlugin = new Plugin.Plugin({ isRoot: true, root: this.options.root });
|
|
130
|
-
await rootPlugin.load();
|
|
131
|
-
marker?.addDetails({
|
|
132
|
-
commandCount: rootPlugin.commands.length,
|
|
133
|
-
hasManifest: rootPlugin.hasManifest ?? false,
|
|
134
|
-
name: rootPlugin.name,
|
|
135
|
-
topicCount: rootPlugin.topics.length,
|
|
136
|
-
type: rootPlugin.type,
|
|
137
|
-
usesMain: Boolean(rootPlugin.pjson.main),
|
|
138
|
-
});
|
|
139
|
-
marker?.stop();
|
|
140
|
-
}
|
|
141
|
-
this.plugins.set(rootPlugin.name, rootPlugin);
|
|
142
|
-
return rootPlugin;
|
|
143
|
-
}
|
|
144
144
|
}
|
|
145
145
|
exports.default = PluginLoader;
|
package/lib/config/plugin.d.ts
CHANGED
|
@@ -5,10 +5,6 @@ import { Plugin as IPlugin, PluginOptions } from '../interfaces/plugin';
|
|
|
5
5
|
import { Topic } from '../interfaces/topic';
|
|
6
6
|
export declare class Plugin implements IPlugin {
|
|
7
7
|
options: PluginOptions;
|
|
8
|
-
_base: string;
|
|
9
|
-
private _commandsDir;
|
|
10
|
-
protected _debug: (..._: any) => void;
|
|
11
|
-
private flexibleTaxonomy;
|
|
12
8
|
alias: string;
|
|
13
9
|
alreadyLoaded: boolean;
|
|
14
10
|
children: Plugin[];
|
|
@@ -29,10 +25,14 @@ export declare class Plugin implements IPlugin {
|
|
|
29
25
|
valid: boolean;
|
|
30
26
|
version: string;
|
|
31
27
|
protected warned: boolean;
|
|
28
|
+
_base: string;
|
|
29
|
+
private _commandsDir;
|
|
30
|
+
protected _debug: (..._: any) => void;
|
|
31
|
+
private flexibleTaxonomy;
|
|
32
32
|
constructor(options: PluginOptions);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
get commandIDs(): string[];
|
|
34
|
+
get commandsDir(): string | undefined;
|
|
35
|
+
get topics(): Topic[];
|
|
36
36
|
findCommand(id: string, opts: {
|
|
37
37
|
must: true;
|
|
38
38
|
}): Promise<Command.Class>;
|
|
@@ -40,7 +40,7 @@ export declare class Plugin implements IPlugin {
|
|
|
40
40
|
must: boolean;
|
|
41
41
|
}): Promise<Command.Class | undefined>;
|
|
42
42
|
load(): Promise<void>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
private _manifest;
|
|
44
|
+
private addErrorScope;
|
|
45
|
+
private warn;
|
|
46
46
|
}
|