@oclif/core 2.13.0 → 2.15.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/spinner.js +1 -1
- package/lib/cli-ux/config.js +5 -6
- package/lib/cli-ux/prompt.js +2 -2
- package/lib/config/config.d.ts +5 -10
- package/lib/config/config.js +26 -126
- package/lib/config/plugin-loader.d.ts +30 -0
- package/lib/config/plugin-loader.js +129 -0
- package/lib/errors/logger.js +3 -3
- package/lib/index.js +0 -9
- package/lib/interfaces/config.d.ts +0 -1
- package/lib/interfaces/plugin.d.ts +2 -3
- package/lib/module-loader.js +4 -4
- package/package.json +2 -6
|
@@ -4,7 +4,6 @@ const chalk = require("chalk");
|
|
|
4
4
|
const supportsColor = require("supports-color");
|
|
5
5
|
const stripAnsi = require('strip-ansi');
|
|
6
6
|
const ansiStyles = require('ansi-styles');
|
|
7
|
-
const ansiEscapes = require('ansi-escapes');
|
|
8
7
|
const screen_1 = require("../../screen");
|
|
9
8
|
const spinners_1 = require("./spinners");
|
|
10
9
|
const base_1 = require("./base");
|
|
@@ -65,6 +64,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
65
64
|
_reset() {
|
|
66
65
|
if (!this.output)
|
|
67
66
|
return;
|
|
67
|
+
const ansiEscapes = require('ansi-escapes');
|
|
68
68
|
const lines = this._lines(this.output);
|
|
69
69
|
this._write(this.std, ansiEscapes.cursorLeft + ansiEscapes.cursorUp(lines) + ansiEscapes.eraseDown);
|
|
70
70
|
this.output = undefined;
|
package/lib/cli-ux/config.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config = exports.Config = void 0;
|
|
4
|
-
const semver = require("semver");
|
|
5
4
|
const util_1 = require("../util");
|
|
6
5
|
const spinner_1 = require("./action/spinner");
|
|
7
6
|
const spinner_2 = require("./action/spinner");
|
|
8
7
|
const pride_spinner_1 = require("./action/pride-spinner");
|
|
9
|
-
const version = semver.parse((0, util_1.requireJson)(__dirname, '..', '..', 'package.json').version);
|
|
10
8
|
const g = global;
|
|
11
9
|
const globals = g['cli-ux'] || (g['cli-ux'] = {});
|
|
12
10
|
const actionType = (Boolean(process.stderr.isTTY) &&
|
|
@@ -38,10 +36,11 @@ class Config {
|
|
|
38
36
|
}
|
|
39
37
|
exports.Config = Config;
|
|
40
38
|
function fetch() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
const major = (0, util_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
|
|
40
|
+
if (globals[major])
|
|
41
|
+
return globals[major];
|
|
42
|
+
globals[major] = new Config();
|
|
43
|
+
return globals[major];
|
|
45
44
|
}
|
|
46
45
|
exports.config = fetch();
|
|
47
46
|
exports.default = exports.config;
|
package/lib/cli-ux/prompt.js
CHANGED
|
@@ -5,8 +5,6 @@ const Errors = require("../errors");
|
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
const chalk = require("chalk");
|
|
7
7
|
const stream_1 = require("./stream");
|
|
8
|
-
const ansiEscapes = require('ansi-escapes');
|
|
9
|
-
const passwordPrompt = require('password-prompt');
|
|
10
8
|
function normal(options, retries = 100) {
|
|
11
9
|
if (retries < 0)
|
|
12
10
|
throw new Error('no input');
|
|
@@ -58,6 +56,7 @@ async function single(options) {
|
|
|
58
56
|
return response;
|
|
59
57
|
}
|
|
60
58
|
function replacePrompt(prompt) {
|
|
59
|
+
const ansiEscapes = require('ansi-escapes');
|
|
61
60
|
stream_1.stderr.write(ansiEscapes.cursorHide + ansiEscapes.cursorUp(1) + ansiEscapes.cursorLeft + prompt +
|
|
62
61
|
ansiEscapes.cursorDown(1) + ansiEscapes.cursorLeft + ansiEscapes.cursorShow);
|
|
63
62
|
}
|
|
@@ -72,6 +71,7 @@ async function _prompt(name, inputOptions = {}) {
|
|
|
72
71
|
default: '',
|
|
73
72
|
...inputOptions,
|
|
74
73
|
};
|
|
74
|
+
const passwordPrompt = require('password-prompt');
|
|
75
75
|
switch (options.type) {
|
|
76
76
|
case 'normal':
|
|
77
77
|
return normal(options);
|
package/lib/config/config.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Options, Plugin as IPlugin } from '../interfaces/plugin';
|
|
2
2
|
import { Config as IConfig, ArchTypes, PlatformTypes, LoadOptions, VersionDetails } from '../interfaces/config';
|
|
3
3
|
import { Hook, Hooks, PJSON, Topic } from '../interfaces';
|
|
4
|
-
import * as Plugin from './plugin';
|
|
5
4
|
import { Command } from '../command';
|
|
6
5
|
export declare class Config implements IConfig {
|
|
7
6
|
options: Options;
|
|
@@ -39,13 +38,14 @@ export declare class Config implements IConfig {
|
|
|
39
38
|
private _commands;
|
|
40
39
|
private _topics;
|
|
41
40
|
private _commandIDs;
|
|
41
|
+
private pluginLoader;
|
|
42
|
+
private rootPlugin;
|
|
42
43
|
constructor(options: Options);
|
|
43
44
|
static load(opts?: LoadOptions): Promise<Config>;
|
|
44
45
|
load(): Promise<void>;
|
|
45
|
-
loadPluginsAndCommands(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
loadUserPlugins(): Promise<void>;
|
|
46
|
+
loadPluginsAndCommands(opts?: {
|
|
47
|
+
force: boolean;
|
|
48
|
+
}): Promise<void>;
|
|
49
49
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number, captureErrors?: boolean): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
50
50
|
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable | null): Promise<T>;
|
|
51
51
|
scopedEnvVar(k: string): string | undefined;
|
|
@@ -112,11 +112,6 @@ export declare class Config implements IConfig {
|
|
|
112
112
|
protected macosCacheDir(): string | undefined;
|
|
113
113
|
protected _shell(): string;
|
|
114
114
|
protected _debug(): number;
|
|
115
|
-
protected loadPlugins(root: string, type: string, plugins: (string | {
|
|
116
|
-
root?: string;
|
|
117
|
-
name?: string;
|
|
118
|
-
tag?: string;
|
|
119
|
-
})[], parent?: Plugin.Plugin): Promise<void>;
|
|
120
115
|
protected warn(err: string | Error | {
|
|
121
116
|
name: string;
|
|
122
117
|
detail: string;
|
package/lib/config/config.js
CHANGED
|
@@ -7,7 +7,6 @@ const os = require("os");
|
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const url_1 = require("url");
|
|
9
9
|
const util_1 = require("util");
|
|
10
|
-
const Plugin = require("./plugin");
|
|
11
10
|
const util_2 = require("./util");
|
|
12
11
|
const util_3 = require("../util");
|
|
13
12
|
const module_loader_1 = require("../module-loader");
|
|
@@ -15,9 +14,9 @@ const help_1 = require("../help");
|
|
|
15
14
|
const stream_1 = require("../cli-ux/stream");
|
|
16
15
|
const performance_1 = require("../performance");
|
|
17
16
|
const settings_1 = require("../settings");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
17
|
+
const os_1 = require("os");
|
|
18
|
+
const path_1 = require("path");
|
|
19
|
+
const plugin_loader_1 = require("./plugin-loader");
|
|
21
20
|
// eslint-disable-next-line new-cap
|
|
22
21
|
const debug = (0, util_2.Debug)();
|
|
23
22
|
const _pjson = (0, util_3.requireJson)(__dirname, '..', '..', 'package.json');
|
|
@@ -71,24 +70,6 @@ class Config {
|
|
|
71
70
|
this.topicPermutations = new Permutations();
|
|
72
71
|
this._commands = new Map();
|
|
73
72
|
this._topics = new Map();
|
|
74
|
-
if (options.config) {
|
|
75
|
-
if (Array.isArray(options.config.plugins) && Array.isArray(this.plugins)) {
|
|
76
|
-
// incoming config is v2 with plugins array and this config is v2 with plugins array
|
|
77
|
-
Object.assign(this, options.config);
|
|
78
|
-
}
|
|
79
|
-
else if (Array.isArray(options.config.plugins) && !Array.isArray(this.plugins)) {
|
|
80
|
-
// incoming config is v2 with plugins array and this config is v3 with plugin Map
|
|
81
|
-
Object.assign(this, options.config, { plugins: new Map(options.config.plugins.map(p => [p.name, p])) });
|
|
82
|
-
}
|
|
83
|
-
else if (!Array.isArray(options.config.plugins) && Array.isArray(this.plugins)) {
|
|
84
|
-
// incoming config is v3 with plugin Map and this config is v2 with plugins array
|
|
85
|
-
Object.assign(this, options.config, { plugins: options.config.getPluginsList() });
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// incoming config is v3 with plugin Map and this config is v3 with plugin Map
|
|
89
|
-
Object.assign(this, options.config);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
73
|
}
|
|
93
74
|
static async load(opts = module.filename || __dirname) {
|
|
94
75
|
// Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
|
|
@@ -98,8 +79,6 @@ class Config {
|
|
|
98
79
|
if (typeof opts === 'string')
|
|
99
80
|
opts = { root: opts };
|
|
100
81
|
if (isConfig(opts)) {
|
|
101
|
-
const currentConfigBase = BASE.replace('@oclif/core@', '');
|
|
102
|
-
const incomingConfigBase = opts._base.replace('@oclif/core@', '');
|
|
103
82
|
/**
|
|
104
83
|
* Reload the Config based on the version required by the command.
|
|
105
84
|
* This is needed because the command is given the Config instantiated
|
|
@@ -110,9 +89,11 @@ class Config {
|
|
|
110
89
|
* exists in the version of Config required by the command but may not exist on the
|
|
111
90
|
* root's instance of Config.
|
|
112
91
|
*/
|
|
113
|
-
if (
|
|
92
|
+
if (BASE !== opts._base) {
|
|
114
93
|
debug(`reloading config from ${opts._base} to ${BASE}`);
|
|
115
|
-
|
|
94
|
+
const config = new Config({ ...opts.options, plugins: opts.plugins });
|
|
95
|
+
await config.load();
|
|
96
|
+
return config;
|
|
116
97
|
}
|
|
117
98
|
return opts;
|
|
118
99
|
}
|
|
@@ -122,18 +103,15 @@ class Config {
|
|
|
122
103
|
}
|
|
123
104
|
// eslint-disable-next-line complexity
|
|
124
105
|
async load() {
|
|
125
|
-
if (this.options.config)
|
|
126
|
-
return;
|
|
127
106
|
settings_1.settings.performanceEnabled = (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
|
|
128
|
-
|
|
129
|
-
await
|
|
130
|
-
this.
|
|
131
|
-
this.
|
|
132
|
-
this.pjson = plugin.pjson;
|
|
107
|
+
this.pluginLoader = new plugin_loader_1.default({ root: this.options.root, plugins: this.options.plugins });
|
|
108
|
+
this.rootPlugin = await this.pluginLoader.loadRoot();
|
|
109
|
+
this.root = this.rootPlugin.root;
|
|
110
|
+
this.pjson = this.rootPlugin.pjson;
|
|
133
111
|
this.name = this.pjson.name;
|
|
134
112
|
this.version = this.options.version || this.pjson.version || '0.0.0';
|
|
135
113
|
this.channel = this.options.channel || channelFromVersion(this.version);
|
|
136
|
-
this.valid =
|
|
114
|
+
this.valid = this.rootPlugin.valid;
|
|
137
115
|
this.arch = (os.arch() === 'ia32' ? 'x86' : os.arch());
|
|
138
116
|
this.platform = WSL ? 'wsl' : os.platform();
|
|
139
117
|
this.windows = this.platform === 'win32';
|
|
@@ -192,56 +170,24 @@ class Config {
|
|
|
192
170
|
});
|
|
193
171
|
marker?.stop();
|
|
194
172
|
}
|
|
195
|
-
async loadPluginsAndCommands() {
|
|
173
|
+
async loadPluginsAndCommands(opts) {
|
|
196
174
|
const marker = performance_1.Performance.mark('config.loadPluginsAndCommands');
|
|
197
|
-
await this.
|
|
198
|
-
|
|
199
|
-
|
|
175
|
+
const { plugins, errors } = await this.pluginLoader.loadChildren({
|
|
176
|
+
devPlugins: this.options.devPlugins,
|
|
177
|
+
userPlugins: this.options.userPlugins,
|
|
178
|
+
dataDir: this.dataDir,
|
|
179
|
+
rootPlugin: this.rootPlugin,
|
|
180
|
+
force: opts?.force ?? false,
|
|
181
|
+
});
|
|
182
|
+
this.plugins = [...plugins.values()];
|
|
200
183
|
for (const plugin of this.plugins) {
|
|
201
184
|
this.loadCommands(plugin);
|
|
202
185
|
this.loadTopics(plugin);
|
|
203
186
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
async loadCorePlugins() {
|
|
207
|
-
if (this.pjson.oclif.plugins) {
|
|
208
|
-
await this.loadPlugins(this.root, 'core', this.pjson.oclif.plugins);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
async loadDevPlugins() {
|
|
212
|
-
if (this.options.devPlugins !== false) {
|
|
213
|
-
// do not load oclif.devPlugins in production
|
|
214
|
-
if (this.isProd)
|
|
215
|
-
return;
|
|
216
|
-
try {
|
|
217
|
-
const devPlugins = this.pjson.oclif.devPlugins;
|
|
218
|
-
if (devPlugins)
|
|
219
|
-
await this.loadPlugins(this.root, 'dev', devPlugins);
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
process.emitWarning(error);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async loadUserPlugins() {
|
|
227
|
-
if (this.options.userPlugins !== false) {
|
|
228
|
-
try {
|
|
229
|
-
const userPJSONPath = path.join(this.dataDir, 'package.json');
|
|
230
|
-
debug('reading user plugins pjson %s', userPJSONPath);
|
|
231
|
-
const pjson = await (0, util_2.loadJSON)(userPJSONPath);
|
|
232
|
-
this.userPJSON = pjson;
|
|
233
|
-
if (!pjson.oclif)
|
|
234
|
-
pjson.oclif = { schema: 1 };
|
|
235
|
-
if (!pjson.oclif.plugins)
|
|
236
|
-
pjson.oclif.plugins = [];
|
|
237
|
-
await this.loadPlugins(userPJSONPath, 'user', pjson.oclif.plugins.filter((p) => p.type === 'user'));
|
|
238
|
-
await this.loadPlugins(userPJSONPath, 'link', pjson.oclif.plugins.filter((p) => p.type === 'link'));
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
if (error.code !== 'ENOENT')
|
|
242
|
-
process.emitWarning(error);
|
|
243
|
-
}
|
|
187
|
+
for (const error of errors) {
|
|
188
|
+
this.warn(error);
|
|
244
189
|
}
|
|
190
|
+
marker?.stop();
|
|
245
191
|
}
|
|
246
192
|
async runHook(event, opts, timeout, captureErrors) {
|
|
247
193
|
const marker = performance_1.Performance.mark(`config.runHook#${event}`);
|
|
@@ -350,7 +296,7 @@ class Config {
|
|
|
350
296
|
if (jitResult.failures[0])
|
|
351
297
|
throw jitResult.failures[0].error;
|
|
352
298
|
if (jitResult.successes[0]) {
|
|
353
|
-
await this.loadPluginsAndCommands();
|
|
299
|
+
await this.loadPluginsAndCommands({ force: true });
|
|
354
300
|
c = this.findCommand(id) ?? c;
|
|
355
301
|
}
|
|
356
302
|
else {
|
|
@@ -523,7 +469,7 @@ class Config {
|
|
|
523
469
|
_shell() {
|
|
524
470
|
let shellPath;
|
|
525
471
|
const COMSPEC = process.env.COMSPEC;
|
|
526
|
-
const SHELL = process.env.SHELL ?? (0,
|
|
472
|
+
const SHELL = process.env.SHELL ?? (0, os_1.userInfo)().shell?.split(path_1.sep)?.pop();
|
|
527
473
|
if (SHELL) {
|
|
528
474
|
shellPath = SHELL.split('/');
|
|
529
475
|
}
|
|
@@ -546,52 +492,6 @@ class Config {
|
|
|
546
492
|
catch { }
|
|
547
493
|
return 0;
|
|
548
494
|
}
|
|
549
|
-
async loadPlugins(root, type, plugins, parent) {
|
|
550
|
-
if (!plugins || plugins.length === 0)
|
|
551
|
-
return;
|
|
552
|
-
const mark = performance_1.Performance.mark(`config.loadPlugins#${type}`);
|
|
553
|
-
debug('loading plugins', plugins);
|
|
554
|
-
await Promise.all((plugins || []).map(async (plugin) => {
|
|
555
|
-
try {
|
|
556
|
-
const opts = { type, root };
|
|
557
|
-
if (typeof plugin === 'string') {
|
|
558
|
-
opts.name = plugin;
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
opts.name = plugin.name || opts.name;
|
|
562
|
-
opts.tag = plugin.tag || opts.tag;
|
|
563
|
-
opts.root = plugin.root || opts.root;
|
|
564
|
-
}
|
|
565
|
-
const pluginMarker = performance_1.Performance.mark(`plugin.load#${opts.name}`);
|
|
566
|
-
const instance = new Plugin.Plugin(opts);
|
|
567
|
-
await instance.load();
|
|
568
|
-
pluginMarker?.addDetails({
|
|
569
|
-
hasManifest: instance.hasManifest,
|
|
570
|
-
commandCount: instance.commands.length,
|
|
571
|
-
topicCount: instance.topics.length,
|
|
572
|
-
type: instance.type,
|
|
573
|
-
usesMain: Boolean(instance.pjson.main),
|
|
574
|
-
name: instance.name,
|
|
575
|
-
});
|
|
576
|
-
pluginMarker?.stop();
|
|
577
|
-
if (this.plugins.find(p => p.name === instance.name))
|
|
578
|
-
return;
|
|
579
|
-
this.plugins.push(instance);
|
|
580
|
-
if (parent) {
|
|
581
|
-
instance.parent = parent;
|
|
582
|
-
if (!parent.children)
|
|
583
|
-
parent.children = [];
|
|
584
|
-
parent.children.push(instance);
|
|
585
|
-
}
|
|
586
|
-
await this.loadPlugins(instance.root, type, instance.pjson.oclif.plugins || [], instance);
|
|
587
|
-
}
|
|
588
|
-
catch (error) {
|
|
589
|
-
this.warn(error, 'loadPlugins');
|
|
590
|
-
}
|
|
591
|
-
}));
|
|
592
|
-
mark?.addDetails({ pluginCount: plugins.length });
|
|
593
|
-
mark?.stop();
|
|
594
|
-
}
|
|
595
495
|
warn(err, scope) {
|
|
596
496
|
if (this.warned)
|
|
597
497
|
return;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Plugin as IPlugin } from '../interfaces/plugin';
|
|
2
|
+
type PluginLoaderOptions = {
|
|
3
|
+
root: string;
|
|
4
|
+
plugins?: IPlugin[] | PluginsMap;
|
|
5
|
+
};
|
|
6
|
+
type LoadOpts = {
|
|
7
|
+
devPlugins?: boolean;
|
|
8
|
+
userPlugins?: boolean;
|
|
9
|
+
dataDir: string;
|
|
10
|
+
rootPlugin: IPlugin;
|
|
11
|
+
force?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type PluginsMap = Map<string, IPlugin>;
|
|
14
|
+
export default class PluginLoader {
|
|
15
|
+
options: PluginLoaderOptions;
|
|
16
|
+
plugins: PluginsMap;
|
|
17
|
+
errors: (string | Error)[];
|
|
18
|
+
private pluginsProvided;
|
|
19
|
+
constructor(options: PluginLoaderOptions);
|
|
20
|
+
loadRoot(): Promise<IPlugin>;
|
|
21
|
+
loadChildren(opts: LoadOpts): Promise<{
|
|
22
|
+
plugins: PluginsMap;
|
|
23
|
+
errors: (string | Error)[];
|
|
24
|
+
}>;
|
|
25
|
+
private loadCorePlugins;
|
|
26
|
+
private loadDevPlugins;
|
|
27
|
+
private loadUserPlugins;
|
|
28
|
+
private loadPlugins;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
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");
|
|
7
|
+
const performance_1 = require("../performance");
|
|
8
|
+
// eslint-disable-next-line new-cap
|
|
9
|
+
const debug = (0, util_1.Debug)();
|
|
10
|
+
class PluginLoader {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.plugins = new Map();
|
|
14
|
+
this.errors = [];
|
|
15
|
+
this.pluginsProvided = false;
|
|
16
|
+
if (options.plugins) {
|
|
17
|
+
this.pluginsProvided = true;
|
|
18
|
+
this.plugins = Array.isArray(options.plugins) ? new Map(options.plugins.map(p => [p.name, p])) : options.plugins;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
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
|
+
async loadCorePlugins(opts) {
|
|
43
|
+
if (opts.rootPlugin.pjson.oclif.plugins) {
|
|
44
|
+
await this.loadPlugins(opts.rootPlugin.root, 'core', opts.rootPlugin.pjson.oclif.plugins);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async loadDevPlugins(opts) {
|
|
48
|
+
if (opts.devPlugins !== false) {
|
|
49
|
+
// do not load oclif.devPlugins in production
|
|
50
|
+
if ((0, util_2.isProd)())
|
|
51
|
+
return;
|
|
52
|
+
try {
|
|
53
|
+
const devPlugins = opts.rootPlugin.pjson.oclif.devPlugins;
|
|
54
|
+
if (devPlugins)
|
|
55
|
+
await this.loadPlugins(opts.rootPlugin.root, 'dev', devPlugins);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
process.emitWarning(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
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
|
+
async loadPlugins(root, type, plugins, parent) {
|
|
82
|
+
if (!plugins || plugins.length === 0)
|
|
83
|
+
return;
|
|
84
|
+
const mark = performance_1.Performance.mark(`config.loadPlugins#${type}`);
|
|
85
|
+
debug('loading plugins', plugins);
|
|
86
|
+
await Promise.all((plugins || []).map(async (plugin) => {
|
|
87
|
+
try {
|
|
88
|
+
const name = typeof plugin === 'string' ? plugin : plugin.name;
|
|
89
|
+
const opts = {
|
|
90
|
+
name,
|
|
91
|
+
type,
|
|
92
|
+
root,
|
|
93
|
+
};
|
|
94
|
+
if (typeof plugin !== 'string') {
|
|
95
|
+
opts.tag = plugin.tag || opts.tag;
|
|
96
|
+
opts.root = plugin.root || opts.root;
|
|
97
|
+
}
|
|
98
|
+
if (this.plugins.has(name))
|
|
99
|
+
return;
|
|
100
|
+
const pluginMarker = performance_1.Performance.mark(`plugin.load#${name}`);
|
|
101
|
+
const instance = new Plugin.Plugin(opts);
|
|
102
|
+
await instance.load();
|
|
103
|
+
pluginMarker?.addDetails({
|
|
104
|
+
hasManifest: instance.hasManifest,
|
|
105
|
+
commandCount: instance.commands.length,
|
|
106
|
+
topicCount: instance.topics.length,
|
|
107
|
+
type: instance.type,
|
|
108
|
+
usesMain: Boolean(instance.pjson.main),
|
|
109
|
+
name: instance.name,
|
|
110
|
+
});
|
|
111
|
+
pluginMarker?.stop();
|
|
112
|
+
this.plugins.set(instance.name, instance);
|
|
113
|
+
if (parent) {
|
|
114
|
+
instance.parent = parent;
|
|
115
|
+
if (!parent.children)
|
|
116
|
+
parent.children = [];
|
|
117
|
+
parent.children.push(instance);
|
|
118
|
+
}
|
|
119
|
+
await this.loadPlugins(instance.root, type, instance.pjson.oclif.plugins || [], instance);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.errors.push(error);
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
mark?.addDetails({ pluginCount: plugins.length });
|
|
126
|
+
mark?.stop();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.default = PluginLoader;
|
package/lib/errors/logger.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
|
-
const fs = require("fs
|
|
5
|
-
const
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const path_1 = require("path");
|
|
6
6
|
const stripAnsi = require("strip-ansi");
|
|
7
7
|
const timestamp = () => new Date().toISOString();
|
|
8
8
|
let timer;
|
|
@@ -35,7 +35,7 @@ class Logger {
|
|
|
35
35
|
return;
|
|
36
36
|
const mylines = this.buffer;
|
|
37
37
|
this.buffer = [];
|
|
38
|
-
await fs.
|
|
38
|
+
await fs.mkdir((0, path_1.dirname)(this.file), { recursive: true });
|
|
39
39
|
await fs.appendFile(this.file, mylines.join('\n') + '\n');
|
|
40
40
|
});
|
|
41
41
|
await this.flushing;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stdout = exports.stderr = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Performance = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Command = exports.Args = void 0;
|
|
4
|
-
const semver = require("semver");
|
|
5
4
|
const command_1 = require("./command");
|
|
6
5
|
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
|
|
7
6
|
const main_1 = require("./main");
|
|
@@ -34,7 +33,6 @@ const settings_1 = require("./settings");
|
|
|
34
33
|
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
35
34
|
const ux = require("./cli-ux");
|
|
36
35
|
exports.ux = ux;
|
|
37
|
-
const util_2 = require("./util");
|
|
38
36
|
const stream_1 = require("./cli-ux/stream");
|
|
39
37
|
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_1.stderr; } });
|
|
40
38
|
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_1.stdout; } });
|
|
@@ -52,11 +50,4 @@ function checkCWD() {
|
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
function checkNodeVersion() {
|
|
56
|
-
const pjson = (0, util_2.requireJson)(__dirname, '..', 'package.json');
|
|
57
|
-
if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
|
|
58
|
-
stream_1.stderr.write(`WARNING\nWARNING Node version must be ${pjson.engines.node} to use this CLI\nWARNING Current node version: ${process.versions.node}\nWARNING\n`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
53
|
checkCWD();
|
|
62
|
-
checkNodeVersion();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Config } from './config';
|
|
2
1
|
import { Command } from '../command';
|
|
3
2
|
import { PJSON } from './pjson';
|
|
4
3
|
import { Topic } from './topic';
|
|
@@ -19,7 +18,7 @@ export interface Options extends PluginOptions {
|
|
|
19
18
|
channel?: string;
|
|
20
19
|
version?: string;
|
|
21
20
|
enablePerf?: boolean;
|
|
22
|
-
|
|
21
|
+
plugins?: Plugin[];
|
|
23
22
|
}
|
|
24
23
|
export interface Plugin {
|
|
25
24
|
/**
|
|
@@ -76,5 +75,5 @@ export interface Plugin {
|
|
|
76
75
|
findCommand(id: string, opts?: {
|
|
77
76
|
must: boolean;
|
|
78
77
|
}): Promise<Command.Class> | undefined;
|
|
79
|
-
load(isWritingManifest
|
|
78
|
+
load(isWritingManifest?: boolean): Promise<void>;
|
|
80
79
|
}
|
package/lib/module-loader.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const url = require("url");
|
|
5
|
-
const
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
const Config = require("./config");
|
|
8
8
|
const getPackageType = require('get-package-type');
|
|
@@ -131,10 +131,10 @@ class ModuleLoader {
|
|
|
131
131
|
filePath = isPlugin(config) ? Config.tsPath(config.root, modulePath, config.type) : Config.tsPath(config.root, modulePath);
|
|
132
132
|
let fileExists = false;
|
|
133
133
|
let isDirectory = false;
|
|
134
|
-
if (
|
|
134
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
135
135
|
fileExists = true;
|
|
136
136
|
try {
|
|
137
|
-
if (
|
|
137
|
+
if ((0, fs_1.lstatSync)(filePath)?.isDirectory?.()) {
|
|
138
138
|
fileExists = false;
|
|
139
139
|
isDirectory = true;
|
|
140
140
|
}
|
|
@@ -167,7 +167,7 @@ class ModuleLoader {
|
|
|
167
167
|
// eslint-disable-next-line camelcase
|
|
168
168
|
for (const extension of s_EXTENSIONS) {
|
|
169
169
|
const testPath = `${filePath}${extension}`;
|
|
170
|
-
if (
|
|
170
|
+
if ((0, fs_1.existsSync)(testPath)) {
|
|
171
171
|
return testPath;
|
|
172
172
|
}
|
|
173
173
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/core",
|
|
3
3
|
"description": "base library for oclif CLIs",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.15.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"cli-progress": "^3.12.0",
|
|
15
15
|
"debug": "^4.3.4",
|
|
16
16
|
"ejs": "^3.1.8",
|
|
17
|
-
"fs-extra": "^9.1.0",
|
|
18
17
|
"get-package-type": "^0.1.0",
|
|
19
18
|
"globby": "^11.1.0",
|
|
20
19
|
"hyperlinker": "^1.0.0",
|
|
@@ -24,7 +23,6 @@
|
|
|
24
23
|
"natural-orderby": "^2.0.3",
|
|
25
24
|
"object-treeify": "^1.1.33",
|
|
26
25
|
"password-prompt": "^1.1.2",
|
|
27
|
-
"semver": "^7.5.3",
|
|
28
26
|
"slice-ansi": "^4.0.0",
|
|
29
27
|
"string-width": "^4.2.3",
|
|
30
28
|
"strip-ansi": "^6.0.1",
|
|
@@ -47,7 +45,6 @@
|
|
|
47
45
|
"@types/chai-as-promised": "^7.1.5",
|
|
48
46
|
"@types/clean-stack": "^2.1.1",
|
|
49
47
|
"@types/ejs": "^3.1.2",
|
|
50
|
-
"@types/fs-extra": "^9.0.13",
|
|
51
48
|
"@types/indent-string": "^4.0.1",
|
|
52
49
|
"@types/js-yaml": "^3.12.7",
|
|
53
50
|
"@types/mocha": "^8.2.3",
|
|
@@ -55,7 +52,6 @@
|
|
|
55
52
|
"@types/node": "^16",
|
|
56
53
|
"@types/node-notifier": "^8.0.2",
|
|
57
54
|
"@types/proxyquire": "^1.3.28",
|
|
58
|
-
"@types/semver": "^7.5.0",
|
|
59
55
|
"@types/shelljs": "^0.8.11",
|
|
60
56
|
"@types/slice-ansi": "^4.0.0",
|
|
61
57
|
"@types/strip-ansi": "^5.2.1",
|
|
@@ -120,4 +116,4 @@
|
|
|
120
116
|
"test:perf": "ts-node test/perf/parser.perf.ts"
|
|
121
117
|
},
|
|
122
118
|
"types": "lib/index.d.ts"
|
|
123
|
-
}
|
|
119
|
+
}
|