@oclif/core 3.0.0-beta.2 → 3.0.0-beta.4
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/README.md +9 -7
- package/lib/command.d.ts +2 -0
- package/lib/command.js +4 -4
- package/lib/config/config.d.ts +7 -13
- package/lib/config/config.js +85 -139
- package/lib/config/index.d.ts +2 -1
- package/lib/config/index.js +2 -1
- package/lib/config/plugin-loader.d.ts +30 -0
- package/lib/config/plugin-loader.js +129 -0
- package/lib/config/plugin.d.ts +4 -10
- package/lib/config/plugin.js +19 -16
- package/lib/config/ts-node.js +2 -2
- package/lib/errors/config.js +5 -5
- package/lib/errors/handle.d.ts +2 -2
- package/lib/errors/handle.js +4 -5
- package/lib/errors/index.d.ts +1 -1
- package/lib/errors/index.js +1 -1
- package/lib/errors/logger.js +3 -3
- package/lib/execute.d.ts +49 -0
- package/lib/execute.js +62 -0
- package/lib/flags.js +6 -4
- package/lib/help/index.js +3 -3
- package/lib/index.d.ts +9 -7
- package/lib/index.js +13 -19
- package/lib/interfaces/config.d.ts +25 -26
- package/lib/interfaces/parser.d.ts +14 -66
- package/lib/interfaces/pjson.d.ts +1 -0
- package/lib/interfaces/plugin.d.ts +4 -1
- package/lib/main.d.ts +1 -49
- package/lib/main.js +7 -62
- package/lib/module-loader.d.ts +1 -2
- package/lib/module-loader.js +4 -4
- package/lib/parser/errors.js +1 -1
- package/lib/parser/parse.js +1 -34
- package/lib/performance.d.ts +1 -1
- package/lib/performance.js +2 -3
- package/lib/screen.js +2 -2
- package/lib/settings.d.ts +2 -1
- package/lib/settings.js +2 -2
- package/lib/{cli-ux → ux}/action/base.js +2 -2
- package/lib/{cli-ux → ux}/action/spinner.js +1 -1
- package/lib/{cli-ux → ux}/config.d.ts +0 -1
- package/lib/{cli-ux → ux}/config.js +6 -10
- package/lib/{cli-ux → ux}/exit.d.ts +1 -1
- package/lib/{cli-ux → ux}/exit.js +1 -1
- package/lib/ux/flush.d.ts +1 -0
- package/lib/ux/flush.js +27 -0
- package/lib/{cli-ux → ux}/index.d.ts +8 -27
- package/lib/{cli-ux → ux}/index.js +21 -80
- package/lib/{cli-ux → ux}/prompt.js +2 -2
- package/lib/{cli-ux → ux}/styled/json.js +3 -3
- package/package.json +17 -14
- package/flush.d.ts +0 -3
- package/flush.js +0 -1
- package/handle.js +0 -1
- package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
- package/lib/cli-ux/action/pride-spinner.js +0 -30
- /package/lib/{cli-ux → ux}/action/base.d.ts +0 -0
- /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
- /package/lib/{cli-ux → ux}/action/simple.js +0 -0
- /package/lib/{cli-ux → ux}/action/spinner.d.ts +0 -0
- /package/lib/{cli-ux → ux}/action/spinners.d.ts +0 -0
- /package/lib/{cli-ux → ux}/action/spinners.js +0 -0
- /package/lib/{cli-ux → ux}/list.d.ts +0 -0
- /package/lib/{cli-ux → ux}/list.js +0 -0
- /package/lib/{cli-ux → ux}/prompt.d.ts +0 -0
- /package/lib/{cli-ux → ux}/stream.d.ts +0 -0
- /package/lib/{cli-ux → ux}/stream.js +0 -0
- /package/lib/{cli-ux → ux}/styled/index.d.ts +0 -0
- /package/lib/{cli-ux → ux}/styled/index.js +0 -0
- /package/lib/{cli-ux → ux}/styled/json.d.ts +0 -0
- /package/lib/{cli-ux → ux}/styled/object.d.ts +0 -0
- /package/lib/{cli-ux → ux}/styled/object.js +0 -0
- /package/lib/{cli-ux → ux}/styled/progress.d.ts +0 -0
- /package/lib/{cli-ux → ux}/styled/progress.js +0 -0
- /package/lib/{cli-ux → ux}/styled/table.d.ts +0 -0
- /package/lib/{cli-ux → ux}/styled/table.js +0 -0
- /package/lib/{cli-ux → ux}/styled/tree.d.ts +0 -0
- /package/lib/{cli-ux → ux}/styled/tree.js +0 -0
- /package/lib/{cli-ux → ux}/wait.d.ts +0 -0
- /package/lib/{cli-ux → ux}/wait.js +0 -0
|
@@ -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.default.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.default.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/config/plugin.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CLIError } from '../errors';
|
|
2
1
|
import { Plugin as IPlugin, PluginOptions } from '../interfaces/plugin';
|
|
3
2
|
import { Manifest } from '../interfaces/manifest';
|
|
4
3
|
import { PJSON } from '../interfaces/pjson';
|
|
@@ -26,16 +25,11 @@ export declare class Plugin implements IPlugin {
|
|
|
26
25
|
children: Plugin[];
|
|
27
26
|
hasManifest: boolean;
|
|
28
27
|
private _commandsDir;
|
|
28
|
+
private flexibleTaxonomy;
|
|
29
29
|
protected _debug: (..._: any) => void;
|
|
30
30
|
protected warned: boolean;
|
|
31
31
|
constructor(options: PluginOptions);
|
|
32
|
-
|
|
33
|
-
* Loads a plugin
|
|
34
|
-
* @param isWritingManifest - if true, exclude selected data from manifest
|
|
35
|
-
* default is false to maintain backwards compatibility
|
|
36
|
-
* @returns Promise<void>
|
|
37
|
-
*/
|
|
38
|
-
load(isWritingManifest?: boolean): Promise<void>;
|
|
32
|
+
load(): Promise<void>;
|
|
39
33
|
get topics(): Topic[];
|
|
40
34
|
get commandsDir(): string | undefined;
|
|
41
35
|
get commandIDs(): string[];
|
|
@@ -45,7 +39,7 @@ export declare class Plugin implements IPlugin {
|
|
|
45
39
|
findCommand(id: string, opts?: {
|
|
46
40
|
must: boolean;
|
|
47
41
|
}): Promise<Command.Class | undefined>;
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
private _manifest;
|
|
43
|
+
private warn;
|
|
50
44
|
private addErrorScope;
|
|
51
45
|
}
|
package/lib/config/plugin.js
CHANGED
|
@@ -90,7 +90,6 @@ async function findRoot(name, root) {
|
|
|
90
90
|
class Plugin {
|
|
91
91
|
constructor(options) {
|
|
92
92
|
this.options = options;
|
|
93
|
-
// static loadedPlugins: {[name: string]: Plugin} = {}
|
|
94
93
|
this._base = `${_pjson.name}@${_pjson.version}`;
|
|
95
94
|
this.valid = false;
|
|
96
95
|
this.alreadyLoaded = false;
|
|
@@ -100,27 +99,22 @@ class Plugin {
|
|
|
100
99
|
this._debug = (0, util_2.Debug)();
|
|
101
100
|
this.warned = false;
|
|
102
101
|
}
|
|
103
|
-
|
|
104
|
-
* Loads a plugin
|
|
105
|
-
* @param isWritingManifest - if true, exclude selected data from manifest
|
|
106
|
-
* default is false to maintain backwards compatibility
|
|
107
|
-
* @returns Promise<void>
|
|
108
|
-
*/
|
|
109
|
-
async load(isWritingManifest) {
|
|
102
|
+
async load() {
|
|
110
103
|
this.type = this.options.type || 'core';
|
|
111
104
|
this.tag = this.options.tag;
|
|
112
105
|
const root = await findRoot(this.options.name, this.options.root);
|
|
113
106
|
if (!root)
|
|
114
|
-
throw new
|
|
107
|
+
throw new errors_1.CLIError(`could not find package.json with ${(0, util_1.inspect)(this.options)}`);
|
|
115
108
|
this.root = root;
|
|
116
109
|
this._debug('reading %s plugin %s', this.type, root);
|
|
117
110
|
this.pjson = await (0, util_3.loadJSON)(path.join(root, 'package.json'));
|
|
111
|
+
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
118
112
|
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
119
113
|
this.name = this.pjson.name;
|
|
120
114
|
this.alias = this.options.name ?? this.pjson.name;
|
|
121
115
|
const pjsonPath = path.join(root, 'package.json');
|
|
122
116
|
if (!this.name)
|
|
123
|
-
throw new
|
|
117
|
+
throw new errors_1.CLIError(`no name in ${pjsonPath}`);
|
|
124
118
|
if (!(0, util_4.isProd)() && !this.pjson.files)
|
|
125
119
|
this.warn(`files attribute must be specified in ${pjsonPath}`);
|
|
126
120
|
// eslint-disable-next-line new-cap
|
|
@@ -133,7 +127,7 @@ class Plugin {
|
|
|
133
127
|
this.pjson.oclif = this.pjson['cli-engine'] || {};
|
|
134
128
|
}
|
|
135
129
|
this.hooks = (0, util_3.mapValues)(this.pjson.oclif.hooks || {}, i => Array.isArray(i) ? i : [i]);
|
|
136
|
-
this.manifest = await this._manifest(
|
|
130
|
+
this.manifest = await this._manifest();
|
|
137
131
|
this.commands = Object
|
|
138
132
|
.entries(this.manifest.commands)
|
|
139
133
|
.map(([id, c]) => ({
|
|
@@ -156,7 +150,7 @@ class Plugin {
|
|
|
156
150
|
get commandIDs() {
|
|
157
151
|
if (!this.commandsDir)
|
|
158
152
|
return [];
|
|
159
|
-
const marker = performance_1.
|
|
153
|
+
const marker = performance_1.default.mark(`plugin.commandIDs#${this.name}`, { plugin: this.name });
|
|
160
154
|
this._debug(`loading IDs from ${this.commandsDir}`);
|
|
161
155
|
const patterns = [
|
|
162
156
|
'**/*.+(js|cjs|mjs|ts|tsx)',
|
|
@@ -176,7 +170,7 @@ class Plugin {
|
|
|
176
170
|
return ids;
|
|
177
171
|
}
|
|
178
172
|
async findCommand(id, opts = {}) {
|
|
179
|
-
const marker = performance_1.
|
|
173
|
+
const marker = performance_1.default.mark(`plugin.findCommand#${this.name}.${id}`, { id, plugin: this.name });
|
|
180
174
|
const fetch = async () => {
|
|
181
175
|
if (!this.commandsDir)
|
|
182
176
|
return;
|
|
@@ -212,7 +206,10 @@ class Plugin {
|
|
|
212
206
|
marker?.stop();
|
|
213
207
|
return cmd;
|
|
214
208
|
}
|
|
215
|
-
async _manifest(
|
|
209
|
+
async _manifest() {
|
|
210
|
+
const ignoreManifest = Boolean(this.options.ignoreManifest);
|
|
211
|
+
const errorOnManifestCreate = Boolean(this.options.errorOnManifestCreate);
|
|
212
|
+
const respectNoCacheDefault = Boolean(this.options.respectNoCacheDefault);
|
|
216
213
|
const readManifest = async (dotfile = false) => {
|
|
217
214
|
try {
|
|
218
215
|
const p = path.join(this.root, `${dotfile ? '.' : ''}oclif.manifest.json`);
|
|
@@ -236,7 +233,7 @@ class Plugin {
|
|
|
236
233
|
}
|
|
237
234
|
}
|
|
238
235
|
};
|
|
239
|
-
const marker = performance_1.
|
|
236
|
+
const marker = performance_1.default.mark(`plugin.manifest#${this.name}`, { plugin: this.name });
|
|
240
237
|
if (!ignoreManifest) {
|
|
241
238
|
const manifest = await readManifest();
|
|
242
239
|
if (manifest) {
|
|
@@ -249,7 +246,13 @@ class Plugin {
|
|
|
249
246
|
version: this.version,
|
|
250
247
|
commands: (await Promise.all(this.commandIDs.map(async (id) => {
|
|
251
248
|
try {
|
|
252
|
-
|
|
249
|
+
const cached = await (0, config_1.toCached)(await this.findCommand(id, { must: true }), this, respectNoCacheDefault);
|
|
250
|
+
if (this.flexibleTaxonomy) {
|
|
251
|
+
const permutations = (0, util_2.getCommandIdPermutations)(id);
|
|
252
|
+
const aliasPermutations = cached.aliases.flatMap(a => (0, util_2.getCommandIdPermutations)(a));
|
|
253
|
+
return [id, { ...cached, permutations, aliasPermutations }];
|
|
254
|
+
}
|
|
255
|
+
return [id, cached];
|
|
253
256
|
}
|
|
254
257
|
catch (error) {
|
|
255
258
|
const scope = 'toCached';
|
package/lib/config/ts-node.js
CHANGED
|
@@ -98,7 +98,7 @@ function tsPath(root, orig, plugin) {
|
|
|
98
98
|
return orig;
|
|
99
99
|
orig = orig.startsWith(root) ? orig : path.join(root, orig);
|
|
100
100
|
// NOTE: The order of these checks matter!
|
|
101
|
-
if (settings_1.
|
|
101
|
+
if (settings_1.default.tsnodeEnabled === false) {
|
|
102
102
|
debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
|
|
103
103
|
return orig;
|
|
104
104
|
}
|
|
@@ -124,7 +124,7 @@ function tsPath(root, orig, plugin) {
|
|
|
124
124
|
return orig;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
if (settings_1.
|
|
127
|
+
if (settings_1.default.tsnodeEnabled === undefined && (0, util_1.isProd)() && plugin?.type !== 'link') {
|
|
128
128
|
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
|
|
129
129
|
return orig;
|
|
130
130
|
}
|
package/lib/errors/config.js
CHANGED
|
@@ -15,24 +15,24 @@ function displayWarnings() {
|
|
|
15
15
|
exports.config = {
|
|
16
16
|
errorLogger: undefined,
|
|
17
17
|
get debug() {
|
|
18
|
-
return Boolean(settings_1.
|
|
18
|
+
return Boolean(settings_1.default.debug);
|
|
19
19
|
},
|
|
20
20
|
set debug(enabled) {
|
|
21
|
-
settings_1.
|
|
21
|
+
settings_1.default.debug = enabled;
|
|
22
22
|
if (enabled)
|
|
23
23
|
displayWarnings();
|
|
24
24
|
},
|
|
25
25
|
get errlog() {
|
|
26
|
-
return settings_1.
|
|
26
|
+
return settings_1.default.errlog;
|
|
27
27
|
},
|
|
28
28
|
set errlog(errlog) {
|
|
29
29
|
if (errlog) {
|
|
30
30
|
this.errorLogger = new logger_1.Logger(errlog);
|
|
31
|
-
settings_1.
|
|
31
|
+
settings_1.default.errlog = errlog;
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
delete this.errorLogger;
|
|
35
|
-
delete settings_1.
|
|
35
|
+
delete settings_1.default.errlog;
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
};
|
package/lib/errors/handle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { OclifError, PrettyPrintableError } from '../interfaces';
|
|
2
|
-
export
|
|
2
|
+
export default function handle(err: Error & Partial<PrettyPrintableError> & Partial<OclifError> & {
|
|
3
3
|
skipOclifErrorHandling?: boolean;
|
|
4
|
-
})
|
|
4
|
+
}): Promise<void>;
|
package/lib/errors/handle.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handle = void 0;
|
|
4
3
|
/* eslint-disable no-process-exit */
|
|
5
4
|
/* eslint-disable unicorn/no-process-exit */
|
|
6
5
|
const config_1 = require("./config");
|
|
@@ -8,7 +7,7 @@ const pretty_print_1 = require("./errors/pretty-print");
|
|
|
8
7
|
const _1 = require(".");
|
|
9
8
|
const clean = require("clean-stack");
|
|
10
9
|
const cli_1 = require("./errors/cli");
|
|
11
|
-
|
|
10
|
+
async function handle(err) {
|
|
12
11
|
try {
|
|
13
12
|
if (!err)
|
|
14
13
|
err = new cli_1.CLIError('no error?');
|
|
@@ -25,7 +24,7 @@ const handle = (err) => {
|
|
|
25
24
|
if (stack) {
|
|
26
25
|
config_1.config.errorLogger.log(stack);
|
|
27
26
|
}
|
|
28
|
-
config_1.config.errorLogger.flush()
|
|
27
|
+
await config_1.config.errorLogger.flush()
|
|
29
28
|
.then(() => process.exit(exitCode))
|
|
30
29
|
.catch(console.error);
|
|
31
30
|
}
|
|
@@ -37,5 +36,5 @@ const handle = (err) => {
|
|
|
37
36
|
console.error(error.stack);
|
|
38
37
|
process.exit(1);
|
|
39
38
|
}
|
|
40
|
-
}
|
|
41
|
-
exports.
|
|
39
|
+
}
|
|
40
|
+
exports.default = handle;
|
package/lib/errors/index.d.ts
CHANGED
package/lib/errors/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.memoizedWarn = exports.warn = exports.error = exports.exit = exports.config = exports.Logger = exports.CLIError = exports.ModuleLoadError = exports.ExitError = exports.handle = void 0;
|
|
4
4
|
var handle_1 = require("./handle");
|
|
5
|
-
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.
|
|
5
|
+
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.default; } });
|
|
6
6
|
var exit_1 = require("./errors/exit");
|
|
7
7
|
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
|
8
8
|
var module_load_1 = require("./errors/module-load");
|
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/execute.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Interfaces from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Load and run oclif CLI
|
|
4
|
+
*
|
|
5
|
+
* @param options - options to load the CLI
|
|
6
|
+
* @returns Promise<void>
|
|
7
|
+
*
|
|
8
|
+
* @example For ESM dev.js
|
|
9
|
+
* ```
|
|
10
|
+
* #!/usr/bin/env node
|
|
11
|
+
* void (async () => {
|
|
12
|
+
* const oclif = await import('@oclif/core')
|
|
13
|
+
* await oclif.execute({development: true, dir: import.meta.url})
|
|
14
|
+
* })()
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example For ESM run.js
|
|
18
|
+
* ```
|
|
19
|
+
* #!/usr/bin/env node
|
|
20
|
+
* void (async () => {
|
|
21
|
+
* const oclif = await import('@oclif/core')
|
|
22
|
+
* await oclif.execute({dir: import.meta.url})
|
|
23
|
+
* })()
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example For CJS dev.js
|
|
27
|
+
* ```
|
|
28
|
+
* #!/usr/bin/env node
|
|
29
|
+
* void (async () => {
|
|
30
|
+
* const oclif = await import('@oclif/core')
|
|
31
|
+
* await oclif.execute({development: true, dir: __dirname})
|
|
32
|
+
* })()
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example For CJS run.js
|
|
36
|
+
* ```
|
|
37
|
+
* #!/usr/bin/env node
|
|
38
|
+
* void (async () => {
|
|
39
|
+
* const oclif = await import('@oclif/core')
|
|
40
|
+
* await oclif.execute({dir: __dirname})
|
|
41
|
+
* })()
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export default function execute(options: {
|
|
45
|
+
dir: string;
|
|
46
|
+
args?: string[];
|
|
47
|
+
loadOptions?: Interfaces.LoadOptions;
|
|
48
|
+
development?: boolean;
|
|
49
|
+
}): Promise<unknown>;
|
package/lib/execute.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const settings_1 = require("./settings");
|
|
4
|
+
const flush_1 = require("./ux/flush");
|
|
5
|
+
const handle_1 = require("./errors/handle");
|
|
6
|
+
const main_1 = require("./main");
|
|
7
|
+
/**
|
|
8
|
+
* Load and run oclif CLI
|
|
9
|
+
*
|
|
10
|
+
* @param options - options to load the CLI
|
|
11
|
+
* @returns Promise<void>
|
|
12
|
+
*
|
|
13
|
+
* @example For ESM dev.js
|
|
14
|
+
* ```
|
|
15
|
+
* #!/usr/bin/env node
|
|
16
|
+
* void (async () => {
|
|
17
|
+
* const oclif = await import('@oclif/core')
|
|
18
|
+
* await oclif.execute({development: true, dir: import.meta.url})
|
|
19
|
+
* })()
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example For ESM run.js
|
|
23
|
+
* ```
|
|
24
|
+
* #!/usr/bin/env node
|
|
25
|
+
* void (async () => {
|
|
26
|
+
* const oclif = await import('@oclif/core')
|
|
27
|
+
* await oclif.execute({dir: import.meta.url})
|
|
28
|
+
* })()
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example For CJS dev.js
|
|
32
|
+
* ```
|
|
33
|
+
* #!/usr/bin/env node
|
|
34
|
+
* void (async () => {
|
|
35
|
+
* const oclif = await import('@oclif/core')
|
|
36
|
+
* await oclif.execute({development: true, dir: __dirname})
|
|
37
|
+
* })()
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example For CJS run.js
|
|
41
|
+
* ```
|
|
42
|
+
* #!/usr/bin/env node
|
|
43
|
+
* void (async () => {
|
|
44
|
+
* const oclif = await import('@oclif/core')
|
|
45
|
+
* await oclif.execute({dir: __dirname})
|
|
46
|
+
* })()
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async function execute(options) {
|
|
50
|
+
if (options.development) {
|
|
51
|
+
// In dev mode -> use ts-node and dev plugins
|
|
52
|
+
process.env.NODE_ENV = 'development';
|
|
53
|
+
settings_1.default.debug = true;
|
|
54
|
+
}
|
|
55
|
+
return (0, main_1.default)(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
|
|
56
|
+
.then(async (result) => {
|
|
57
|
+
(0, flush_1.default)();
|
|
58
|
+
return result;
|
|
59
|
+
})
|
|
60
|
+
.catch(async (error) => (0, handle_1.default)(error));
|
|
61
|
+
}
|
|
62
|
+
exports.default = execute;
|
package/lib/flags.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.help = exports.version = exports.string = exports.url = exports.file = e
|
|
|
4
4
|
const url_1 = require("url");
|
|
5
5
|
const help_1 = require("./help");
|
|
6
6
|
const util_1 = require("./util");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
7
8
|
function custom(defaults) {
|
|
8
9
|
return (options = {}) => {
|
|
9
10
|
return {
|
|
@@ -29,12 +30,12 @@ exports.boolean = boolean;
|
|
|
29
30
|
exports.integer = custom({
|
|
30
31
|
parse: async (input, _, opts) => {
|
|
31
32
|
if (!/^-?\d+$/.test(input))
|
|
32
|
-
throw new
|
|
33
|
+
throw new errors_1.CLIError(`Expected an integer but received: ${input}`);
|
|
33
34
|
const num = Number.parseInt(input, 10);
|
|
34
35
|
if (opts.min !== undefined && num < opts.min)
|
|
35
|
-
throw new
|
|
36
|
+
throw new errors_1.CLIError(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
|
|
36
37
|
if (opts.max !== undefined && num > opts.max)
|
|
37
|
-
throw new
|
|
38
|
+
throw new errors_1.CLIError(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
|
|
38
39
|
return num;
|
|
39
40
|
},
|
|
40
41
|
});
|
|
@@ -84,7 +85,8 @@ const help = (opts = {}) => {
|
|
|
84
85
|
description: 'Show CLI help.',
|
|
85
86
|
...opts,
|
|
86
87
|
parse: async (_, cmd) => {
|
|
87
|
-
|
|
88
|
+
const Help = await (0, help_1.loadHelpClass)(cmd.config);
|
|
89
|
+
await new Help(cmd.config, cmd.config.pjson.helpOptions).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
|
|
88
90
|
cmd.exit(0);
|
|
89
91
|
},
|
|
90
92
|
});
|
package/lib/help/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const util_1 = require("../util");
|
|
|
10
10
|
const util_2 = require("./util");
|
|
11
11
|
const formatter_1 = require("./formatter");
|
|
12
12
|
const config_1 = require("../config/config");
|
|
13
|
-
const stream_1 = require("../
|
|
13
|
+
const stream_1 = require("../ux/stream");
|
|
14
14
|
var command_2 = require("./command");
|
|
15
15
|
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
|
|
16
16
|
var util_3 = require("./util");
|
|
@@ -91,7 +91,7 @@ class Help extends HelpBase {
|
|
|
91
91
|
const command = this.config.findCommand(subject);
|
|
92
92
|
if (command) {
|
|
93
93
|
if (command.hasDynamicHelp && command.pluginType !== 'jit') {
|
|
94
|
-
const dynamicCommand = await (0, config_1.toCached)(await command.load()
|
|
94
|
+
const dynamicCommand = await (0, config_1.toCached)(await command.load());
|
|
95
95
|
await this.showCommandHelp(dynamicCommand);
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
@@ -123,7 +123,7 @@ class Help extends HelpBase {
|
|
|
123
123
|
const depth = name.split(':').length;
|
|
124
124
|
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
125
125
|
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
126
|
-
const plugin = this.config.plugins.
|
|
126
|
+
const plugin = this.config.plugins.get(command.pluginName);
|
|
127
127
|
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
|
|
128
128
|
if (state) {
|
|
129
129
|
this.log(state === 'deprecated' ?
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Command } from './command';
|
|
2
|
-
import
|
|
2
|
+
import run from './main';
|
|
3
|
+
import execute from './execute';
|
|
4
|
+
import handle from './errors/handle';
|
|
3
5
|
import { Config, Plugin, tsPath, toCached } from './config';
|
|
4
6
|
import * as Interfaces from './interfaces';
|
|
5
7
|
import * as Errors from './errors';
|
|
@@ -9,10 +11,10 @@ import { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
|
|
|
9
11
|
import { toStandardizedId, toConfiguredId } from './help/util';
|
|
10
12
|
import * as Parser from './parser';
|
|
11
13
|
import { Hook } from './interfaces/hooks';
|
|
12
|
-
import
|
|
14
|
+
import settings, { Settings } from './settings';
|
|
13
15
|
import { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
14
|
-
import
|
|
15
|
-
import { stderr, stdout } from './
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
export { Args, Command, CommandHelp, Config, Errors, Flags,
|
|
16
|
+
import ux from './ux';
|
|
17
|
+
import { stderr, stdout } from './ux/stream';
|
|
18
|
+
import Performance from './performance';
|
|
19
|
+
import flush from './ux/flush';
|
|
20
|
+
export { Args, Command, CommandHelp, Config, Errors, execute, Flags, flush, handle, Help, HelpBase, HelpSection, HelpSectionKeyValueTable, HelpSectionRenderer, Hook, Interfaces, loadHelpClass, Parser, Performance, Plugin, run, settings, Settings, stderr, stdout, toCached, toConfiguredId, toStandardizedId, tsPath, ux, };
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const semver = require("semver");
|
|
3
|
+
exports.ux = exports.tsPath = exports.toStandardizedId = exports.toConfiguredId = exports.toCached = exports.stdout = exports.stderr = exports.settings = exports.run = exports.Plugin = exports.Performance = exports.Parser = exports.loadHelpClass = exports.Interfaces = exports.HelpBase = exports.Help = exports.handle = exports.flush = exports.Flags = exports.execute = exports.Errors = exports.Config = exports.CommandHelp = exports.Command = exports.Args = void 0;
|
|
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");
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
exports.run = main_1.default;
|
|
8
|
+
const execute_1 = require("./execute");
|
|
9
|
+
exports.execute = execute_1.default;
|
|
10
|
+
const handle_1 = require("./errors/handle");
|
|
11
|
+
exports.handle = handle_1.default;
|
|
10
12
|
const config_1 = require("./config");
|
|
11
13
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
12
14
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
@@ -31,17 +33,16 @@ Object.defineProperty(exports, "toConfiguredId", { enumerable: true, get: functi
|
|
|
31
33
|
const Parser = require("./parser");
|
|
32
34
|
exports.Parser = Parser;
|
|
33
35
|
const settings_1 = require("./settings");
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
exports.ux =
|
|
37
|
-
const
|
|
38
|
-
const stream_1 = require("./cli-ux/stream");
|
|
36
|
+
exports.settings = settings_1.default;
|
|
37
|
+
const ux_1 = require("./ux");
|
|
38
|
+
exports.ux = ux_1.default;
|
|
39
|
+
const stream_1 = require("./ux/stream");
|
|
39
40
|
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_1.stderr; } });
|
|
40
41
|
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_1.stdout; } });
|
|
41
42
|
const performance_1 = require("./performance");
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
exports.flush =
|
|
43
|
+
exports.Performance = performance_1.default;
|
|
44
|
+
const flush_1 = require("./ux/flush");
|
|
45
|
+
exports.flush = flush_1.default;
|
|
45
46
|
function checkCWD() {
|
|
46
47
|
try {
|
|
47
48
|
process.cwd();
|
|
@@ -52,11 +53,4 @@ function checkCWD() {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
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
56
|
checkCWD();
|
|
62
|
-
checkNodeVersion();
|