@oclif/core 3.0.0-beta.9 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +4 -2
  2. package/flush.d.ts +3 -0
  3. package/flush.js +1 -0
  4. package/handle.js +1 -0
  5. package/lib/args.d.ts +2 -2
  6. package/lib/args.js +17 -18
  7. package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
  8. package/lib/{ux → cli-ux}/action/base.js +126 -120
  9. package/lib/{ux → cli-ux}/action/simple.js +25 -30
  10. package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
  11. package/lib/{ux → cli-ux}/action/spinner.js +45 -37
  12. package/lib/{ux → cli-ux}/action/spinners.js +187 -187
  13. package/lib/cli-ux/action/types.d.ts +5 -0
  14. package/lib/cli-ux/action/types.js +2 -0
  15. package/lib/{ux → cli-ux}/config.d.ts +5 -5
  16. package/lib/{ux → cli-ux}/config.js +17 -17
  17. package/lib/{ux → cli-ux}/exit.js +3 -0
  18. package/lib/cli-ux/flush.d.ts +1 -0
  19. package/lib/cli-ux/flush.js +28 -0
  20. package/lib/cli-ux/index.d.ts +39 -0
  21. package/lib/{ux → cli-ux}/index.js +74 -88
  22. package/lib/{ux → cli-ux}/list.js +3 -3
  23. package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
  24. package/lib/{ux → cli-ux}/prompt.js +35 -25
  25. package/lib/{ux → cli-ux}/stream.d.ts +6 -6
  26. package/lib/{ux → cli-ux}/stream.js +11 -10
  27. package/lib/cli-ux/styled/index.d.ts +4 -0
  28. package/lib/cli-ux/styled/index.js +11 -0
  29. package/lib/{ux → cli-ux}/styled/object.js +7 -9
  30. package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
  31. package/lib/{ux → cli-ux}/styled/table.js +130 -133
  32. package/lib/{ux → cli-ux}/styled/tree.js +11 -13
  33. package/lib/cli-ux/wait.js +5 -0
  34. package/lib/command.d.ts +82 -88
  35. package/lib/command.js +196 -175
  36. package/lib/config/config.d.ts +89 -90
  37. package/lib/config/config.js +466 -566
  38. package/lib/config/index.d.ts +0 -1
  39. package/lib/config/index.js +1 -3
  40. package/lib/config/plugin-loader.d.ts +12 -12
  41. package/lib/config/plugin-loader.js +72 -56
  42. package/lib/config/plugin.d.ts +25 -24
  43. package/lib/config/plugin.js +188 -154
  44. package/lib/config/ts-node.d.ts +2 -1
  45. package/lib/config/ts-node.js +71 -58
  46. package/lib/config/util.d.ts +1 -11
  47. package/lib/config/util.js +6 -59
  48. package/lib/errors/config.d.ts +1 -1
  49. package/lib/errors/config.js +6 -6
  50. package/lib/errors/errors/cli.d.ts +7 -7
  51. package/lib/errors/errors/cli.js +20 -16
  52. package/lib/errors/errors/exit.d.ts +1 -4
  53. package/lib/errors/errors/exit.js +1 -1
  54. package/lib/errors/errors/module-load.d.ts +1 -4
  55. package/lib/errors/errors/module-load.js +1 -1
  56. package/lib/errors/errors/pretty-print.d.ts +1 -1
  57. package/lib/errors/errors/pretty-print.js +12 -10
  58. package/lib/errors/handle.d.ts +12 -2
  59. package/lib/errors/handle.js +26 -14
  60. package/lib/errors/index.d.ts +10 -10
  61. package/lib/errors/index.js +25 -24
  62. package/lib/errors/logger.d.ts +2 -2
  63. package/lib/errors/logger.js +14 -13
  64. package/lib/execute.d.ts +6 -6
  65. package/lib/execute.js +10 -9
  66. package/lib/flags.d.ts +103 -32
  67. package/lib/flags.js +79 -45
  68. package/lib/help/command.d.ts +16 -14
  69. package/lib/help/command.js +178 -163
  70. package/lib/help/docopts.d.ts +5 -5
  71. package/lib/help/docopts.js +50 -54
  72. package/lib/help/formatter.d.ts +37 -37
  73. package/lib/help/formatter.js +66 -55
  74. package/lib/help/index.d.ts +25 -21
  75. package/lib/help/index.js +169 -147
  76. package/lib/help/root.d.ts +1 -1
  77. package/lib/help/root.js +15 -17
  78. package/lib/help/util.d.ts +2 -8
  79. package/lib/help/util.js +8 -28
  80. package/lib/index.d.ts +19 -20
  81. package/lib/index.js +37 -43
  82. package/lib/interfaces/config.d.ts +67 -66
  83. package/lib/interfaces/errors.d.ts +5 -5
  84. package/lib/interfaces/help.d.ts +17 -17
  85. package/lib/interfaces/hooks.d.ts +49 -49
  86. package/lib/interfaces/index.d.ts +7 -7
  87. package/lib/interfaces/manifest.d.ts +1 -1
  88. package/lib/interfaces/parser.d.ts +175 -51
  89. package/lib/interfaces/pjson.d.ts +41 -41
  90. package/lib/interfaces/plugin.d.ts +47 -41
  91. package/lib/interfaces/s3-manifest.d.ts +7 -7
  92. package/lib/interfaces/topic.d.ts +1 -1
  93. package/lib/interfaces/ts-config.d.ts +7 -7
  94. package/lib/main.d.ts +2 -2
  95. package/lib/main.js +16 -16
  96. package/lib/module-loader.d.ts +67 -77
  97. package/lib/module-loader.js +183 -150
  98. package/lib/parser/errors.d.ts +7 -7
  99. package/lib/parser/errors.js +29 -22
  100. package/lib/parser/help.js +5 -5
  101. package/lib/parser/index.js +2 -2
  102. package/lib/parser/parse.d.ts +9 -6
  103. package/lib/parser/parse.js +253 -221
  104. package/lib/parser/validate.js +53 -33
  105. package/lib/performance.d.ts +43 -32
  106. package/lib/performance.js +133 -91
  107. package/lib/screen.js +2 -2
  108. package/lib/settings.d.ts +11 -12
  109. package/lib/settings.js +2 -2
  110. package/lib/util/aggregate-flags.d.ts +2 -0
  111. package/lib/util/aggregate-flags.js +13 -0
  112. package/lib/util/cache-command.d.ts +3 -0
  113. package/lib/util/cache-command.js +109 -0
  114. package/lib/util/cache-default-value.d.ts +2 -0
  115. package/lib/util/cache-default-value.js +28 -0
  116. package/lib/util/ensure-arg-object.d.ts +12 -0
  117. package/lib/util/ensure-arg-object.js +14 -0
  118. package/lib/util/fs.d.ts +7 -0
  119. package/lib/util/fs.js +54 -0
  120. package/lib/util/os.d.ts +19 -0
  121. package/lib/util/os.js +28 -0
  122. package/lib/{util.d.ts → util/util.d.ts} +7 -16
  123. package/lib/util/util.js +98 -0
  124. package/package.json +35 -37
  125. package/lib/util.js +0 -126
  126. package/lib/ux/flush.d.ts +0 -1
  127. package/lib/ux/flush.js +0 -27
  128. package/lib/ux/index.d.ts +0 -58
  129. package/lib/ux/styled/index.d.ts +0 -6
  130. package/lib/ux/styled/index.js +0 -13
  131. package/lib/ux/styled/json.d.ts +0 -1
  132. package/lib/ux/styled/json.js +0 -15
  133. package/lib/ux/wait.js +0 -7
  134. package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
  135. package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
  136. package/lib/{ux → cli-ux}/exit.d.ts +2 -2
  137. package/lib/{ux → cli-ux}/list.d.ts +0 -0
  138. package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
  139. package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
  140. package/lib/{ux → cli-ux}/styled/progress.js +0 -0
  141. package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
  142. /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
@@ -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");
@@ -1,30 +1,30 @@
1
1
  import { Plugin as IPlugin } from '../interfaces/plugin';
2
2
  type PluginLoaderOptions = {
3
- root: string;
4
3
  plugins?: IPlugin[] | PluginsMap;
4
+ root: string;
5
5
  };
6
6
  type LoadOpts = {
7
- devPlugins?: boolean;
8
- userPlugins?: boolean;
9
7
  dataDir: string;
10
- rootPlugin: IPlugin;
8
+ devPlugins?: boolean;
11
9
  force?: boolean;
10
+ rootPlugin: IPlugin;
11
+ userPlugins?: boolean;
12
12
  };
13
13
  type PluginsMap = Map<string, IPlugin>;
14
14
  export default class PluginLoader {
15
15
  options: PluginLoaderOptions;
16
- plugins: PluginsMap;
17
- errors: (string | Error)[];
18
16
  private pluginsProvided;
17
+ errors: (Error | string)[];
18
+ plugins: PluginsMap;
19
19
  constructor(options: PluginLoaderOptions);
20
- loadRoot(): Promise<IPlugin>;
21
- loadChildren(opts: LoadOpts): Promise<{
22
- plugins: PluginsMap;
23
- errors: (string | Error)[];
24
- }>;
25
20
  private loadCorePlugins;
26
21
  private loadDevPlugins;
27
- private loadUserPlugins;
28
22
  private loadPlugins;
23
+ private loadUserPlugins;
24
+ loadChildren(opts: LoadOpts): Promise<{
25
+ errors: (Error | string)[];
26
+ plugins: PluginsMap;
27
+ }>;
28
+ loadRoot(): Promise<IPlugin>;
29
29
  }
30
30
  export {};
@@ -1,44 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const path = require("path");
4
- const Plugin = require("./plugin");
5
- const util_1 = require("./util");
6
- const util_2 = require("../util");
3
+ const tslib_1 = require("tslib");
4
+ const node_path_1 = require("node:path");
7
5
  const performance_1 = require("../performance");
6
+ const fs_1 = require("../util/fs");
7
+ const util_1 = require("../util/util");
8
+ const Plugin = tslib_1.__importStar(require("./plugin"));
9
+ const util_2 = require("./util");
8
10
  // eslint-disable-next-line new-cap
9
- const debug = (0, util_1.Debug)();
11
+ const debug = (0, util_2.Debug)();
10
12
  class PluginLoader {
13
+ options;
14
+ pluginsProvided = false;
15
+ errors = [];
16
+ plugins = new Map();
11
17
  constructor(options) {
12
18
  this.options = options;
13
- this.plugins = new Map();
14
- this.errors = [];
15
- this.pluginsProvided = false;
16
19
  if (options.plugins) {
17
20
  this.pluginsProvided = true;
18
- this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map(p => [p.name, p])) : options.plugins;
21
+ this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map((p) => [p.name, p])) : options.plugins;
19
22
  }
20
23
  }
21
- async loadRoot() {
22
- let rootPlugin;
23
- if (this.pluginsProvided) {
24
- const plugins = [...this.plugins.values()];
25
- rootPlugin = plugins.find(p => p.root === this.options.root) ?? plugins[0];
26
- }
27
- else {
28
- rootPlugin = new Plugin.Plugin({ root: this.options.root });
29
- await rootPlugin.load();
30
- }
31
- this.plugins.set(rootPlugin.name, rootPlugin);
32
- return rootPlugin;
33
- }
34
- async loadChildren(opts) {
35
- if (!this.pluginsProvided || opts.force) {
36
- await this.loadUserPlugins(opts);
37
- await this.loadDevPlugins(opts);
38
- await this.loadCorePlugins(opts);
39
- }
40
- return { plugins: this.plugins, errors: this.errors };
41
- }
42
24
  async loadCorePlugins(opts) {
43
25
  if (opts.rootPlugin.pjson.oclif.plugins) {
44
26
  await this.loadPlugins(opts.rootPlugin.root, 'core', opts.rootPlugin.pjson.oclif.plugins);
@@ -47,10 +29,10 @@ class PluginLoader {
47
29
  async loadDevPlugins(opts) {
48
30
  if (opts.devPlugins !== false) {
49
31
  // do not load oclif.devPlugins in production
50
- if ((0, util_2.isProd)())
32
+ if ((0, util_1.isProd)())
51
33
  return;
52
34
  try {
53
- const devPlugins = opts.rootPlugin.pjson.oclif.devPlugins;
35
+ const { devPlugins } = opts.rootPlugin.pjson.oclif;
54
36
  if (devPlugins)
55
37
  await this.loadPlugins(opts.rootPlugin.root, 'dev', devPlugins);
56
38
  }
@@ -59,54 +41,38 @@ class PluginLoader {
59
41
  }
60
42
  }
61
43
  }
62
- async loadUserPlugins(opts) {
63
- if (opts.userPlugins !== false) {
64
- try {
65
- const userPJSONPath = path.join(opts.dataDir, 'package.json');
66
- debug('reading user plugins pjson %s', userPJSONPath);
67
- const pjson = await (0, util_1.loadJSON)(userPJSONPath);
68
- if (!pjson.oclif)
69
- pjson.oclif = { schema: 1 };
70
- if (!pjson.oclif.plugins)
71
- pjson.oclif.plugins = [];
72
- await this.loadPlugins(userPJSONPath, 'user', pjson.oclif.plugins.filter((p) => p.type === 'user'));
73
- await this.loadPlugins(userPJSONPath, 'link', pjson.oclif.plugins.filter((p) => p.type === 'link'));
74
- }
75
- catch (error) {
76
- if (error.code !== 'ENOENT')
77
- process.emitWarning(error);
78
- }
79
- }
80
- }
81
44
  async loadPlugins(root, type, plugins, parent) {
82
45
  if (!plugins || plugins.length === 0)
83
46
  return;
84
- const mark = performance_1.default.mark(`config.loadPlugins#${type}`);
47
+ const mark = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadPlugins#${type}`);
85
48
  debug('loading plugins', plugins);
86
49
  await Promise.all((plugins || []).map(async (plugin) => {
87
50
  try {
88
51
  const name = typeof plugin === 'string' ? plugin : plugin.name;
89
52
  const opts = {
90
53
  name,
91
- type,
92
54
  root,
55
+ type,
93
56
  };
94
57
  if (typeof plugin !== 'string') {
95
58
  opts.tag = plugin.tag || opts.tag;
96
59
  opts.root = plugin.root || opts.root;
97
60
  }
61
+ if (parent) {
62
+ opts.parent = parent;
63
+ }
98
64
  if (this.plugins.has(name))
99
65
  return;
100
- const pluginMarker = performance_1.default.mark(`plugin.load#${name}`);
66
+ const pluginMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.load#${name}`);
101
67
  const instance = new Plugin.Plugin(opts);
102
68
  await instance.load();
103
69
  pluginMarker?.addDetails({
104
- hasManifest: instance.hasManifest,
105
70
  commandCount: instance.commands.length,
71
+ hasManifest: instance.hasManifest,
72
+ name: instance.name,
106
73
  topicCount: instance.topics.length,
107
74
  type: instance.type,
108
75
  usesMain: Boolean(instance.pjson.main),
109
- name: instance.name,
110
76
  });
111
77
  pluginMarker?.stop();
112
78
  this.plugins.set(instance.name, instance);
@@ -125,5 +91,55 @@ class PluginLoader {
125
91
  mark?.addDetails({ pluginCount: plugins.length });
126
92
  mark?.stop();
127
93
  }
94
+ async loadUserPlugins(opts) {
95
+ if (opts.userPlugins !== false) {
96
+ try {
97
+ const userPJSONPath = (0, node_path_1.join)(opts.dataDir, 'package.json');
98
+ debug('reading user plugins pjson %s', userPJSONPath);
99
+ const pjson = await (0, fs_1.readJson)(userPJSONPath);
100
+ if (!pjson.oclif)
101
+ pjson.oclif = { schema: 1 };
102
+ if (!pjson.oclif.plugins)
103
+ pjson.oclif.plugins = [];
104
+ await this.loadPlugins(userPJSONPath, 'user', pjson.oclif.plugins.filter((p) => p.type === 'user'));
105
+ await this.loadPlugins(userPJSONPath, 'link', pjson.oclif.plugins.filter((p) => p.type === 'link'));
106
+ }
107
+ catch (error) {
108
+ if (error.code !== 'ENOENT')
109
+ process.emitWarning(error);
110
+ }
111
+ }
112
+ }
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
+ }
128
144
  }
129
145
  exports.default = PluginLoader;
@@ -1,45 +1,46 @@
1
- import { Plugin as IPlugin, PluginOptions } from '../interfaces/plugin';
1
+ import { Command } from '../command';
2
2
  import { Manifest } from '../interfaces/manifest';
3
3
  import { PJSON } from '../interfaces/pjson';
4
+ import { Plugin as IPlugin, PluginOptions } from '../interfaces/plugin';
4
5
  import { Topic } from '../interfaces/topic';
5
- import { Command } from '../command';
6
6
  export declare class Plugin implements IPlugin {
7
7
  options: PluginOptions;
8
8
  _base: string;
9
- name: string;
10
- version: string;
11
- pjson: PJSON.Plugin;
12
- type: string;
13
- moduleType: 'module' | 'commonjs';
14
- root: string;
9
+ private _commandsDir;
10
+ protected _debug: (..._: any) => void;
11
+ private flexibleTaxonomy;
15
12
  alias: string;
16
- tag?: string;
17
- manifest: Manifest;
13
+ alreadyLoaded: boolean;
14
+ children: Plugin[];
18
15
  commands: Command.Loadable[];
16
+ hasManifest: boolean;
19
17
  hooks: {
20
18
  [k: string]: string[];
21
19
  };
22
- valid: boolean;
23
- alreadyLoaded: boolean;
20
+ isRoot: boolean;
21
+ manifest: Manifest;
22
+ moduleType: 'commonjs' | 'module';
23
+ name: string;
24
24
  parent: Plugin | undefined;
25
- children: Plugin[];
26
- hasManifest: boolean;
27
- private _commandsDir;
28
- private flexibleTaxonomy;
29
- protected _debug: (..._: any) => void;
25
+ pjson: PJSON.Plugin;
26
+ root: string;
27
+ tag?: string;
28
+ type: string;
29
+ valid: boolean;
30
+ version: string;
30
31
  protected warned: boolean;
31
32
  constructor(options: PluginOptions);
32
- load(): Promise<void>;
33
- get topics(): Topic[];
34
- get commandsDir(): string | undefined;
35
- get commandIDs(): string[];
33
+ private _manifest;
34
+ private addErrorScope;
35
+ private warn;
36
36
  findCommand(id: string, opts: {
37
37
  must: true;
38
38
  }): Promise<Command.Class>;
39
39
  findCommand(id: string, opts?: {
40
40
  must: boolean;
41
41
  }): Promise<Command.Class | undefined>;
42
- private _manifest;
43
- private warn;
44
- private addErrorScope;
42
+ load(): Promise<void>;
43
+ get commandIDs(): string[];
44
+ get commandsDir(): string | undefined;
45
+ get topics(): Topic[];
45
46
  }