@oclif/core 3.0.0-beta.17 → 3.0.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/lib/args.js +4 -4
  2. package/lib/cli-ux/action/base.js +8 -7
  3. package/lib/cli-ux/action/simple.js +1 -4
  4. package/lib/cli-ux/action/spinner.js +8 -7
  5. package/lib/cli-ux/action/spinners.js +1 -1
  6. package/lib/cli-ux/config.js +11 -12
  7. package/lib/cli-ux/exit.js +3 -0
  8. package/lib/cli-ux/flush.js +7 -6
  9. package/lib/cli-ux/index.js +2 -2
  10. package/lib/cli-ux/list.js +3 -3
  11. package/lib/cli-ux/prompt.js +8 -3
  12. package/lib/cli-ux/stream.js +1 -0
  13. package/lib/cli-ux/styled/json.js +5 -3
  14. package/lib/cli-ux/styled/object.js +2 -2
  15. package/lib/cli-ux/styled/table.js +26 -20
  16. package/lib/cli-ux/styled/tree.js +1 -3
  17. package/lib/cli-ux/wait.js +1 -1
  18. package/lib/command.d.ts +6 -14
  19. package/lib/command.js +86 -73
  20. package/lib/config/config.d.ts +8 -9
  21. package/lib/config/config.js +85 -199
  22. package/lib/config/index.d.ts +0 -1
  23. package/lib/config/index.js +1 -3
  24. package/lib/config/plugin-loader.js +12 -11
  25. package/lib/config/plugin.d.ts +1 -0
  26. package/lib/config/plugin.js +54 -34
  27. package/lib/config/ts-node.js +17 -13
  28. package/lib/config/util.d.ts +0 -6
  29. package/lib/config/util.js +3 -15
  30. package/lib/errors/errors/cli.js +4 -1
  31. package/lib/errors/errors/exit.js +1 -1
  32. package/lib/errors/errors/module-load.js +1 -1
  33. package/lib/errors/errors/pretty-print.js +2 -1
  34. package/lib/errors/handle.js +4 -3
  35. package/lib/errors/logger.js +5 -4
  36. package/lib/flags.d.ts +6 -6
  37. package/lib/flags.js +3 -3
  38. package/lib/help/command.js +46 -32
  39. package/lib/help/docopts.js +8 -5
  40. package/lib/help/formatter.js +19 -8
  41. package/lib/help/index.d.ts +5 -1
  42. package/lib/help/index.js +70 -49
  43. package/lib/help/root.js +7 -9
  44. package/lib/help/util.d.ts +1 -7
  45. package/lib/help/util.js +2 -22
  46. package/lib/index.d.ts +2 -2
  47. package/lib/index.js +2 -3
  48. package/lib/interfaces/hooks.d.ts +3 -3
  49. package/lib/interfaces/index.d.ts +1 -1
  50. package/lib/interfaces/parser.d.ts +19 -18
  51. package/lib/interfaces/pjson.d.ts +1 -1
  52. package/lib/interfaces/plugin.d.ts +5 -0
  53. package/lib/module-loader.d.ts +8 -8
  54. package/lib/module-loader.js +13 -10
  55. package/lib/parser/errors.d.ts +1 -1
  56. package/lib/parser/errors.js +15 -9
  57. package/lib/parser/help.js +2 -3
  58. package/lib/parser/parse.js +72 -44
  59. package/lib/parser/validate.js +37 -21
  60. package/lib/performance.js +20 -9
  61. package/lib/util/aggregate-flags.d.ts +2 -0
  62. package/lib/util/aggregate-flags.js +13 -0
  63. package/lib/util/cache-command.d.ts +3 -0
  64. package/lib/util/cache-command.js +108 -0
  65. package/lib/util/cache-default-value.d.ts +2 -0
  66. package/lib/util/cache-default-value.js +28 -0
  67. package/lib/{util.d.ts → util/index.d.ts} +7 -2
  68. package/lib/{util.js → util/index.js} +15 -20
  69. package/package.json +19 -13
@@ -1,38 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toCached = exports.Config = void 0;
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");
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 util_2 = require("../util");
10
+ const index_1 = require("../util/index");
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 help_1 = require("../help");
16
+ const util_2 = 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");
19
20
  // eslint-disable-next-line new-cap
20
21
  const debug = (0, util_1.Debug)();
21
- const _pjson = (0, util_2.requireJson)(__dirname, '..', '..', 'package.json');
22
+ const _pjson = (0, index_1.requireJson)(__dirname, '..', '..', 'package.json');
22
23
  const BASE = `${_pjson.name}@${_pjson.version}`;
23
24
  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
- constructor() {
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.
@@ -105,7 +130,8 @@ class Config {
105
130
  }
106
131
  // eslint-disable-next-line complexity
107
132
  async load() {
108
- settings_1.settings.performanceEnabled = (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
133
+ settings_1.settings.performanceEnabled =
134
+ (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
109
135
  const marker = performance_1.Performance.mark('config.load');
110
136
  this.pluginLoader = new plugin_loader_1.default({ root: this.options.root, plugins: this.options.plugins });
111
137
  Config._rootPlugin = await this.pluginLoader.loadRoot();
@@ -118,8 +144,8 @@ class Config {
118
144
  this.version = this.options.version || this.pjson.version || '0.0.0';
119
145
  this.channel = this.options.channel || channelFromVersion(this.version);
120
146
  this.valid = Config._rootPlugin.valid;
121
- this.arch = ((0, node_os_1.arch)() === 'ia32' ? 'x86' : (0, node_os_1.arch)());
122
- this.platform = WSL ? 'wsl' : (0, util_2.getPlatform)();
147
+ this.arch = (0, node_os_1.arch)() === 'ia32' ? 'x86' : (0, node_os_1.arch)();
148
+ this.platform = is_wsl_1.default ? 'wsl' : (0, index_1.getPlatform)();
123
149
  this.windows = this.platform === 'win32';
124
150
  this.bin = this.pjson.oclif.bin || this.name;
125
151
  this.binAliases = this.pjson.oclif.binAliases;
@@ -134,7 +160,7 @@ class Config {
134
160
  this.userAgent = `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;
135
161
  this.shell = this._shell();
136
162
  this.debug = this._debug();
137
- this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0, util_2.getHomeDir)() || (0, node_os_1.tmpdir)();
163
+ this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0, index_1.getHomeDir)() || (0, node_os_1.tmpdir)();
138
164
  this.cacheDir = this.scopedEnvVar('CACHE_DIR') || this.macosCacheDir() || this.dir('cache');
139
165
  this.configDir = this.scopedEnvVar('CONFIG_DIR') || this.dir('config');
140
166
  this.dataDir = this.scopedEnvVar('DATA_DIR') || this.dir('data');
@@ -155,14 +181,14 @@ class Config {
155
181
  unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-<%- platform %>-<%- arch %><%- ext %>",
156
182
  versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %><%- ext %>",
157
183
  manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>",
158
- ...s3.templates && s3.templates.target,
184
+ ...(s3.templates && s3.templates.target),
159
185
  },
160
186
  vanilla: {
161
187
  unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %><%- ext %>",
162
188
  versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %><%- ext %>",
163
189
  baseDir: '<%- bin %>',
164
190
  manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %>version",
165
- ...s3.templates && s3.templates.vanilla,
191
+ ...(s3.templates && s3.templates.vanilla),
166
192
  },
167
193
  };
168
194
  await this.loadPluginsAndCommands();
@@ -213,7 +239,7 @@ class Config {
213
239
  reject(new Error(`Timed out after ${ms} ms.`));
214
240
  }, ms).unref();
215
241
  });
216
- return Promise.race([promise, timeout]).then(result => {
242
+ return Promise.race([promise, timeout]).then((result) => {
217
243
  clearTimeout(id);
218
244
  return result;
219
245
  });
@@ -325,10 +351,10 @@ class Config {
325
351
  return result;
326
352
  }
327
353
  scopedEnvVar(k) {
328
- return process.env[this.scopedEnvVarKeys(k).find(k => process.env[k])];
354
+ return process.env[this.scopedEnvVarKeys(k).find((k) => process.env[k])];
329
355
  }
330
356
  scopedEnvVarTrue(k) {
331
- const v = process.env[this.scopedEnvVarKeys(k).find(k => process.env[k])];
357
+ const v = process.env[this.scopedEnvVarKeys(k).find((k) => process.env[k])];
332
358
  return v === '1' || v === 'true';
333
359
  }
334
360
  /**
@@ -338,7 +364,7 @@ class Config {
338
364
  */
339
365
  scopedEnvVarKey(k) {
340
366
  return [this.bin, k]
341
- .map(p => p.replaceAll('@', '').replaceAll(/[/-]/g, '_'))
367
+ .map((p) => p.replaceAll('@', '').replaceAll(/[/-]/g, '_'))
342
368
  .join('_')
343
369
  .toUpperCase();
344
370
  }
@@ -348,7 +374,9 @@ class Config {
348
374
  * @returns {string[]} e.g. ['SF_DEBUG', 'SFDX_DEBUG']
349
375
  */
350
376
  scopedEnvVarKeys(k) {
351
- return [this.bin, ...this.binAliases ?? []].filter(Boolean).map(alias => [alias.replaceAll('@', '').replaceAll(/[/-]/g, '_'), k].join('_').toUpperCase());
377
+ return [this.bin, ...(this.binAliases ?? [])]
378
+ .filter(Boolean)
379
+ .map((alias) => [alias.replaceAll('@', '').replaceAll(/[/-]/g, '_'), k].join('_').toUpperCase());
352
380
  }
353
381
  findCommand(id, opts = {}) {
354
382
  const lookupId = this.getCmdLookupId(id);
@@ -379,12 +407,14 @@ class Config {
379
407
  * @returns string[]
380
408
  */
381
409
  findMatches(partialCmdId, argv) {
382
- const flags = argv.filter(arg => !(0, help_1.getHelpFlagAdditions)(this).includes(arg) && arg.startsWith('-')).map(a => a.replaceAll('-', ''));
383
- const possibleMatches = [...this.commandPermutations.get(partialCmdId)].map(k => this._commands.get(k));
384
- const matches = possibleMatches.filter(command => {
410
+ const flags = argv
411
+ .filter((arg) => !(0, util_2.getHelpFlagAdditions)(this).includes(arg) && arg.startsWith('-'))
412
+ .map((a) => a.replaceAll('-', ''));
413
+ const possibleMatches = [...this.commandPermutations.get(partialCmdId)].map((k) => this._commands.get(k));
414
+ const matches = possibleMatches.filter((command) => {
385
415
  const cmdFlags = Object.entries(command.flags).flatMap(([flag, def]) => def.char ? [def.char, flag] : [flag]);
386
416
  // A command is a match if the provided flags belong to the full command
387
- return flags.every(f => cmdFlags.includes(f));
417
+ return flags.every((f) => cmdFlags.includes(f));
388
418
  });
389
419
  return matches;
390
420
  }
@@ -408,7 +438,7 @@ class Config {
408
438
  * @returns string[]
409
439
  */
410
440
  getAllCommandIDs() {
411
- return this.getAllCommands().map(c => c.id);
441
+ return this.getAllCommands().map((c) => c.id);
412
442
  }
413
443
  get commands() {
414
444
  return [...this._commands.values()];
@@ -416,7 +446,7 @@ class Config {
416
446
  get commandIDs() {
417
447
  if (this._commandIDs)
418
448
  return this._commandIDs;
419
- this._commandIDs = this.commands.map(c => c.id);
449
+ this._commandIDs = this.commands.map((c) => c.id);
420
450
  return this._commandIDs;
421
451
  }
422
452
  get topics() {
@@ -428,7 +458,7 @@ class Config {
428
458
  cliVersion,
429
459
  architecture,
430
460
  nodeVersion,
431
- pluginVersions: Object.fromEntries([...this.plugins.values()].map(p => [p.name, { version: p.version, type: p.type, root: p.root }])),
461
+ pluginVersions: Object.fromEntries([...this.plugins.values()].map((p) => [p.name, { version: p.version, type: p.type, root: p.root }])),
432
462
  osVersion: `${(0, node_os_1.type)()} ${(0, node_os_1.release)()}`,
433
463
  shell: this.shell,
434
464
  rootPath: this.root,
@@ -454,16 +484,16 @@ class Config {
454
484
  return [...this.plugins.values()];
455
485
  }
456
486
  dir(category) {
457
- const base = process.env[`XDG_${category.toUpperCase()}_HOME`]
458
- || (this.windows && process.env.LOCALAPPDATA)
459
- || (0, node_path_1.join)(this.home, category === 'data' ? '.local/share' : '.' + category);
487
+ const base = process.env[`XDG_${category.toUpperCase()}_HOME`] ||
488
+ (this.windows && process.env.LOCALAPPDATA) ||
489
+ (0, node_path_1.join)(this.home, category === 'data' ? '.local/share' : '.' + category);
460
490
  return (0, node_path_1.join)(base, this.dirname);
461
491
  }
462
492
  windowsHome() {
463
493
  return this.windowsHomedriveHome() || this.windowsUserprofileHome();
464
494
  }
465
495
  windowsHomedriveHome() {
466
- return (process.env.HOMEDRIVE && process.env.HOMEPATH && (0, node_path_1.join)(process.env.HOMEDRIVE, process.env.HOMEPATH));
496
+ return process.env.HOMEDRIVE && process.env.HOMEPATH && (0, node_path_1.join)(process.env.HOMEDRIVE, process.env.HOMEPATH);
467
497
  }
468
498
  windowsUserprofileHome() {
469
499
  return process.env.USERPROFILE;
@@ -507,7 +537,7 @@ class Config {
507
537
  if (err instanceof Error) {
508
538
  const modifiedErr = err;
509
539
  modifiedErr.name = `${err.name} Plugin: ${this.name}`;
510
- modifiedErr.detail = (0, util_2.compact)([
540
+ modifiedErr.detail = (0, index_1.compact)([
511
541
  err.detail,
512
542
  `module: ${this._base}`,
513
543
  scope && `task: ${scope}`,
@@ -521,7 +551,7 @@ class Config {
521
551
  // err is an object
522
552
  process.emitWarning('Config.warn expected either a string or Error, but instead received an object');
523
553
  err.name = `${err.name} Plugin: ${this.name}`;
524
- err.detail = (0, util_2.compact)([
554
+ err.detail = (0, index_1.compact)([
525
555
  err.detail,
526
556
  `module: ${this._base}`,
527
557
  scope && `task: ${scope}`,
@@ -532,11 +562,12 @@ class Config {
532
562
  process.emitWarning(JSON.stringify(err));
533
563
  }
534
564
  get isProd() {
535
- return (0, util_2.isProd)();
565
+ return (0, index_1.isProd)();
536
566
  }
537
567
  isJitPluginCommand(c) {
538
568
  // Return true if the command's plugin is listed under oclif.jitPlugins AND if the plugin hasn't been loaded to this.plugins
539
- return Object.keys(this.pjson.oclif.jitPlugins ?? {}).includes(c.pluginName ?? '') && Boolean(c?.pluginName && !this.plugins.has(c.pluginName));
569
+ return (Object.keys(this.pjson.oclif.jitPlugins ?? {}).includes(c.pluginName ?? '') &&
570
+ Boolean(c?.pluginName && !this.plugins.has(c.pluginName)));
540
571
  }
541
572
  getCmdLookupId(id) {
542
573
  if (this._commands.has(id))
@@ -598,7 +629,7 @@ class Config {
598
629
  }
599
630
  loadTopics(plugin) {
600
631
  const marker = performance_1.Performance.mark(`config.loadTopics#${plugin.name}`, { plugin: plugin.name });
601
- for (const topic of (0, util_2.compact)(plugin.topics)) {
632
+ for (const topic of (0, index_1.compact)(plugin.topics)) {
602
633
  const existing = this._topics.get(topic.name);
603
634
  if (existing) {
604
635
  existing.description = topic.description || existing.description;
@@ -613,7 +644,7 @@ class Config {
613
644
  }
614
645
  }
615
646
  // Add missing topics for displaying help when partial commands are entered.
616
- for (const c of plugin.commands.filter(c => !c.hidden)) {
647
+ for (const c of plugin.commands.filter((c) => !c.hidden)) {
617
648
  const parts = c.id.split(':');
618
649
  while (parts.length > 0) {
619
650
  const name = parts.join(':');
@@ -678,14 +709,14 @@ class Config {
678
709
  return commandPlugins[0];
679
710
  }
680
711
  /**
681
- * Insert legacy plugins
682
- *
683
- * Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
684
- * with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
685
- *
686
- * @param plugins array of oclif-compatible plugins
687
- * @returns void
688
- */
712
+ * Insert legacy plugins
713
+ *
714
+ * Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
715
+ * with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
716
+ *
717
+ * @param plugins array of oclif-compatible plugins
718
+ * @returns void
719
+ */
689
720
  insertLegacyPlugins(plugins) {
690
721
  for (const plugin of plugins) {
691
722
  this.plugins.set(plugin.name, plugin);
@@ -694,148 +725,3 @@ class Config {
694
725
  }
695
726
  }
696
727
  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;
@@ -1,4 +1,3 @@
1
1
  export { Config } from './config';
2
- export { toCached } from './config';
3
2
  export { Plugin } from './plugin';
4
3
  export { tsPath } from './ts-node';
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tsPath = exports.Plugin = exports.toCached = exports.Config = void 0;
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");
@@ -2,32 +2,33 @@
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 util_1 = require("../util");
6
- const util_2 = require("./util");
5
+ const index_1 = require("../util/index");
6
+ const util_1 = require("./util");
7
7
  const performance_1 = require("../performance");
8
8
  const node_path_1 = require("node:path");
9
9
  // eslint-disable-next-line new-cap
10
- const debug = (0, util_2.Debug)();
10
+ const debug = (0, util_1.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
- this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map(p => [p.name, p])) : options.plugins;
20
+ this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map((p) => [p.name, p])) : options.plugins;
20
21
  }
21
22
  }
22
23
  async loadRoot() {
23
24
  let rootPlugin;
24
25
  if (this.pluginsProvided) {
25
26
  const plugins = [...this.plugins.values()];
26
- rootPlugin = plugins.find(p => p.root === this.options.root) ?? plugins[0];
27
+ rootPlugin = plugins.find((p) => p.root === this.options.root) ?? plugins[0];
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,
@@ -58,7 +59,7 @@ class PluginLoader {
58
59
  async loadDevPlugins(opts) {
59
60
  if (opts.devPlugins !== false) {
60
61
  // do not load oclif.devPlugins in production
61
- if ((0, util_1.isProd)())
62
+ if ((0, index_1.isProd)())
62
63
  return;
63
64
  try {
64
65
  const { devPlugins } = opts.rootPlugin.pjson.oclif;
@@ -75,7 +76,7 @@ class PluginLoader {
75
76
  try {
76
77
  const userPJSONPath = (0, node_path_1.join)(opts.dataDir, 'package.json');
77
78
  debug('reading user plugins pjson %s', userPJSONPath);
78
- const pjson = await (0, util_1.readJson)(userPJSONPath);
79
+ const pjson = await (0, index_1.readJson)(userPJSONPath);
79
80
  if (!pjson.oclif)
80
81
  pjson.oclif = { schema: 1 };
81
82
  if (!pjson.oclif.plugins)
@@ -24,6 +24,7 @@ export declare class Plugin implements IPlugin {
24
24
  parent: Plugin | undefined;
25
25
  children: Plugin[];
26
26
  hasManifest: boolean;
27
+ isRoot: boolean;
27
28
  private _commandsDir;
28
29
  private flexibleTaxonomy;
29
30
  protected _debug: (..._: any) => void;