@oclif/core 2.14.0 → 3.0.0-beta.10
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 +8 -6
- package/flush.js +1 -1
- package/handle.js +1 -1
- package/lib/cli-ux/action/base.js +2 -2
- package/lib/cli-ux/config.d.ts +0 -1
- package/lib/cli-ux/config.js +1 -4
- package/lib/cli-ux/exit.d.ts +1 -1
- package/lib/cli-ux/exit.js +1 -1
- package/lib/cli-ux/flush.d.ts +1 -0
- package/lib/cli-ux/flush.js +28 -0
- package/lib/cli-ux/index.d.ts +1 -3
- package/lib/cli-ux/index.js +7 -31
- package/lib/cli-ux/styled/json.js +1 -1
- package/lib/command.d.ts +2 -0
- package/lib/config/config.d.ts +8 -12
- package/lib/config/config.js +73 -162
- 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 +5 -10
- package/lib/config/plugin.js +21 -17
- package/lib/config/ts-node.d.ts +3 -2
- package/lib/config/ts-node.js +83 -36
- package/lib/errors/errors/cli.d.ts +1 -0
- package/lib/errors/errors/cli.js +1 -0
- package/lib/errors/handle.d.ts +2 -2
- package/lib/errors/handle.js +3 -3
- package/lib/errors/index.d.ts +1 -0
- package/lib/errors/index.js +8 -1
- package/lib/execute.d.ts +49 -0
- package/lib/execute.js +62 -0
- package/lib/flags.js +4 -3
- package/lib/help/index.js +2 -2
- package/lib/index.d.ts +6 -4
- package/lib/index.js +9 -6
- package/lib/interfaces/config.d.ts +25 -26
- package/lib/interfaces/index.d.ts +14 -14
- package/lib/interfaces/parser.d.ts +14 -66
- package/lib/interfaces/pjson.d.ts +2 -0
- package/lib/interfaces/plugin.d.ts +8 -3
- package/lib/interfaces/ts-config.d.ts +9 -0
- package/lib/main.d.ts +1 -54
- package/lib/main.js +10 -72
- package/lib/module-loader.d.ts +1 -2
- package/lib/module-loader.js +5 -5
- package/lib/parser/parse.js +1 -34
- package/lib/performance.d.ts +1 -1
- package/lib/performance.js +1 -2
- package/package.json +14 -13
- package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
- package/lib/cli-ux/action/pride-spinner.js +0 -30
package/README.md
CHANGED
|
@@ -11,7 +11,9 @@ base library for oclif CLIs
|
|
|
11
11
|
Migrating
|
|
12
12
|
=====
|
|
13
13
|
|
|
14
|
-
See the [migration guide](./
|
|
14
|
+
See the [v2 migration guide](./guides/V2_MIGRATION.md) for an overview of breaking changes that occurred between v1 and v2.
|
|
15
|
+
|
|
16
|
+
See the [v3 migration guide](./guides/V3_MIGRATION.md) for an overview of breaking changes that occurred between v2 and v3.
|
|
15
17
|
|
|
16
18
|
CLI UX
|
|
17
19
|
=====
|
|
@@ -28,7 +30,7 @@ You can, however, use `@oclif/core` in a standalone script like this:
|
|
|
28
30
|
#!/usr/bin/env ts-node
|
|
29
31
|
|
|
30
32
|
import * as fs from 'fs'
|
|
31
|
-
import {Command, Flags} from '@oclif/core'
|
|
33
|
+
import {Command, Flags, flush, handle} from '@oclif/core'
|
|
32
34
|
|
|
33
35
|
class LS extends Command {
|
|
34
36
|
static description = 'List the files in a directory.'
|
|
@@ -50,10 +52,10 @@ class LS extends Command {
|
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
LS.run().then(() => {
|
|
54
|
-
|
|
55
|
-
}, () => {
|
|
56
|
-
|
|
55
|
+
LS.run().then(async () => {
|
|
56
|
+
await flush()
|
|
57
|
+
}, async (err) => {
|
|
58
|
+
await handle(err)
|
|
57
59
|
})
|
|
58
60
|
```
|
|
59
61
|
|
package/flush.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./lib').flush
|
|
1
|
+
module.exports = require('./lib/cli-ux/flush').flush
|
package/handle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = error => require('./lib/errors/handle').handle(error)
|
|
1
|
+
module.exports = async error => require('./lib/errors/handle').handle(error)
|
|
@@ -31,8 +31,8 @@ class ActionBase {
|
|
|
31
31
|
this._stdout(false);
|
|
32
32
|
}
|
|
33
33
|
get globals() {
|
|
34
|
-
global
|
|
35
|
-
const globals = global
|
|
34
|
+
global.ux = global.ux || {};
|
|
35
|
+
const globals = global.ux;
|
|
36
36
|
globals.action = globals.action || {};
|
|
37
37
|
return globals;
|
|
38
38
|
}
|
package/lib/cli-ux/config.d.ts
CHANGED
package/lib/cli-ux/config.js
CHANGED
|
@@ -4,20 +4,17 @@ exports.config = exports.Config = void 0;
|
|
|
4
4
|
const util_1 = require("../util");
|
|
5
5
|
const spinner_1 = require("./action/spinner");
|
|
6
6
|
const spinner_2 = require("./action/spinner");
|
|
7
|
-
const pride_spinner_1 = require("./action/pride-spinner");
|
|
8
7
|
const g = global;
|
|
9
|
-
const globals = g
|
|
8
|
+
const globals = g.ux || (g.ux = {});
|
|
10
9
|
const actionType = (Boolean(process.stderr.isTTY) &&
|
|
11
10
|
!process.env.CI &&
|
|
12
11
|
!['dumb', 'emacs-color'].includes(process.env.TERM) &&
|
|
13
12
|
'spinner') || 'simple';
|
|
14
13
|
const Action = actionType === 'spinner' ? spinner_1.default : spinner_2.default;
|
|
15
|
-
const PrideAction = actionType === 'spinner' ? pride_spinner_1.default : spinner_2.default;
|
|
16
14
|
class Config {
|
|
17
15
|
constructor() {
|
|
18
16
|
this.outputLevel = 'info';
|
|
19
17
|
this.action = new Action();
|
|
20
|
-
this.prideAction = new PrideAction();
|
|
21
18
|
this.errorsHandled = false;
|
|
22
19
|
this.showStackTrace = true;
|
|
23
20
|
}
|
package/lib/cli-ux/exit.d.ts
CHANGED
package/lib/cli-ux/exit.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function flush(ms?: number): Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flush = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
function timeout(p, ms) {
|
|
6
|
+
function wait(ms, unref = false) {
|
|
7
|
+
return new Promise(resolve => {
|
|
8
|
+
const t = setTimeout(() => resolve(null), ms);
|
|
9
|
+
if (unref)
|
|
10
|
+
t.unref();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return Promise.race([p, wait(ms, true).then(() => __1.Errors.error('timed out'))]);
|
|
14
|
+
}
|
|
15
|
+
async function _flush() {
|
|
16
|
+
const p = new Promise(resolve => {
|
|
17
|
+
__1.stdout.once('drain', () => resolve(null));
|
|
18
|
+
});
|
|
19
|
+
const flushed = __1.stdout.write('');
|
|
20
|
+
if (flushed) {
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}
|
|
23
|
+
return p;
|
|
24
|
+
}
|
|
25
|
+
async function flush(ms = 10000) {
|
|
26
|
+
await timeout(_flush(), ms);
|
|
27
|
+
}
|
|
28
|
+
exports.flush = flush;
|
package/lib/cli-ux/index.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare class ux {
|
|
|
16
16
|
static get anykey(): typeof uxPrompt.anykey;
|
|
17
17
|
static get confirm(): typeof uxPrompt.confirm;
|
|
18
18
|
static get action(): ActionBase;
|
|
19
|
-
static get prideAction(): ActionBase;
|
|
20
19
|
static styledObject(obj: any, keys?: string[]): void;
|
|
21
20
|
static styledHeader(header: string): void;
|
|
22
21
|
static get styledJSON(): typeof styled.styledJSON;
|
|
@@ -44,7 +43,6 @@ declare const exit: typeof Errors.exit;
|
|
|
44
43
|
declare const flush: typeof ux.flush;
|
|
45
44
|
declare const info: typeof ux.info;
|
|
46
45
|
declare const log: typeof ux.log;
|
|
47
|
-
declare const prideAction: ActionBase;
|
|
48
46
|
declare const progress: typeof styled.progress;
|
|
49
47
|
declare const prompt: typeof uxPrompt.prompt;
|
|
50
48
|
declare const styledHeader: typeof ux.styledHeader;
|
|
@@ -56,4 +54,4 @@ declare const tree: typeof styled.tree;
|
|
|
56
54
|
declare const url: typeof ux.url;
|
|
57
55
|
declare const wait: (ms?: number) => Promise<void>;
|
|
58
56
|
declare const warn: typeof Errors.warn;
|
|
59
|
-
export { action, ActionBase, annotation, anykey, config, Config, confirm, debug, done, error, exit, ExitError, flush, info, IPromptOptions, log,
|
|
57
|
+
export { action, ActionBase, annotation, anykey, config, Config, confirm, debug, done, error, exit, ExitError, flush, info, IPromptOptions, log, progress, prompt, styledHeader, styledJSON, styledObject, table, Table, trace, tree, url, wait, warn, };
|
package/lib/cli-ux/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.Table = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.
|
|
3
|
+
exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.Table = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.log = exports.info = exports.flush = exports.ExitError = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.Config = exports.config = exports.anykey = exports.annotation = exports.ActionBase = exports.action = exports.ux = void 0;
|
|
4
4
|
const Errors = require("../errors");
|
|
5
5
|
const util = require("util");
|
|
6
6
|
const chalk = require("chalk");
|
|
@@ -17,27 +17,8 @@ Object.defineProperty(exports, "Table", { enumerable: true, get: function () { r
|
|
|
17
17
|
const uxPrompt = require("./prompt");
|
|
18
18
|
const wait_1 = require("./wait");
|
|
19
19
|
const stream_1 = require("./stream");
|
|
20
|
+
const flush_1 = require("./flush");
|
|
20
21
|
const hyperlinker = require('hyperlinker');
|
|
21
|
-
function timeout(p, ms) {
|
|
22
|
-
function wait(ms, unref = false) {
|
|
23
|
-
return new Promise(resolve => {
|
|
24
|
-
const t = setTimeout(() => resolve(null), ms);
|
|
25
|
-
if (unref)
|
|
26
|
-
t.unref();
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return Promise.race([p, wait(ms, true).then(() => Errors.error('timed out'))]);
|
|
30
|
-
}
|
|
31
|
-
async function _flush() {
|
|
32
|
-
const p = new Promise(resolve => {
|
|
33
|
-
stream_1.stdout.once('drain', () => resolve(null));
|
|
34
|
-
});
|
|
35
|
-
const flushed = stream_1.stdout.write('');
|
|
36
|
-
if (flushed) {
|
|
37
|
-
return Promise.resolve();
|
|
38
|
-
}
|
|
39
|
-
return p;
|
|
40
|
-
}
|
|
41
22
|
class ux {
|
|
42
23
|
static get prompt() {
|
|
43
24
|
return uxPrompt.prompt;
|
|
@@ -54,9 +35,6 @@ class ux {
|
|
|
54
35
|
static get action() {
|
|
55
36
|
return config_1.config.action;
|
|
56
37
|
}
|
|
57
|
-
static get prideAction() {
|
|
58
|
-
return config_1.config.prideAction;
|
|
59
|
-
}
|
|
60
38
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
61
39
|
static styledObject(obj, keys) {
|
|
62
40
|
this.info(styled.styledObject(obj, keys));
|
|
@@ -118,7 +96,7 @@ class ux {
|
|
|
118
96
|
}
|
|
119
97
|
}
|
|
120
98
|
static async flush(ms = 10000) {
|
|
121
|
-
await
|
|
99
|
+
await (0, flush_1.flush)(ms);
|
|
122
100
|
}
|
|
123
101
|
}
|
|
124
102
|
exports.ux = ux;
|
|
@@ -145,8 +123,6 @@ const info = ux.info;
|
|
|
145
123
|
exports.info = info;
|
|
146
124
|
const log = ux.log;
|
|
147
125
|
exports.log = log;
|
|
148
|
-
const prideAction = ux.prideAction;
|
|
149
|
-
exports.prideAction = prideAction;
|
|
150
126
|
const progress = ux.progress;
|
|
151
127
|
exports.progress = progress;
|
|
152
128
|
const prompt = ux.prompt;
|
|
@@ -169,7 +145,7 @@ const wait = ux.wait;
|
|
|
169
145
|
exports.wait = wait;
|
|
170
146
|
const warn = Errors.warn;
|
|
171
147
|
exports.warn = warn;
|
|
172
|
-
const
|
|
148
|
+
const uxProcessExitHandler = async () => {
|
|
173
149
|
try {
|
|
174
150
|
await ux.done();
|
|
175
151
|
}
|
|
@@ -180,7 +156,7 @@ const cliuxProcessExitHandler = async () => {
|
|
|
180
156
|
};
|
|
181
157
|
// to avoid MaxListenersExceededWarning
|
|
182
158
|
// only attach named listener once
|
|
183
|
-
const
|
|
184
|
-
if (!
|
|
185
|
-
process.once('exit',
|
|
159
|
+
const uxListener = process.listeners('exit').find(fn => fn.name === uxProcessExitHandler.name);
|
|
160
|
+
if (!uxListener) {
|
|
161
|
+
process.once('exit', uxProcessExitHandler);
|
|
186
162
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const chalk = require("chalk");
|
|
4
|
-
const index_1 = require("
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
function styledJSON(obj) {
|
|
6
6
|
const json = JSON.stringify(obj, null, 2);
|
|
7
7
|
if (!chalk.level) {
|
package/lib/command.d.ts
CHANGED
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;
|
|
@@ -22,7 +21,7 @@ export declare class Config implements IConfig {
|
|
|
22
21
|
npmRegistry?: string;
|
|
23
22
|
pjson: PJSON.CLI;
|
|
24
23
|
platform: PlatformTypes;
|
|
25
|
-
plugins: IPlugin
|
|
24
|
+
plugins: Map<string, IPlugin>;
|
|
26
25
|
root: string;
|
|
27
26
|
shell: string;
|
|
28
27
|
topicSeparator: ':' | ' ';
|
|
@@ -39,13 +38,15 @@ export declare class Config implements IConfig {
|
|
|
39
38
|
private _commands;
|
|
40
39
|
private _topics;
|
|
41
40
|
private _commandIDs;
|
|
41
|
+
private pluginLoader;
|
|
42
|
+
private static _rootPlugin;
|
|
42
43
|
constructor(options: Options);
|
|
43
44
|
static load(opts?: LoadOptions): Promise<Config>;
|
|
45
|
+
static get rootPlugin(): IPlugin | undefined;
|
|
44
46
|
load(): Promise<void>;
|
|
45
|
-
loadPluginsAndCommands(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
loadUserPlugins(): Promise<void>;
|
|
47
|
+
loadPluginsAndCommands(opts?: {
|
|
48
|
+
force: boolean;
|
|
49
|
+
}): Promise<void>;
|
|
49
50
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number, captureErrors?: boolean): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
50
51
|
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable | null): Promise<T>;
|
|
51
52
|
scopedEnvVar(k: string): string | undefined;
|
|
@@ -112,11 +113,6 @@ export declare class Config implements IConfig {
|
|
|
112
113
|
protected macosCacheDir(): string | undefined;
|
|
113
114
|
protected _shell(): string;
|
|
114
115
|
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
116
|
protected warn(err: string | Error | {
|
|
121
117
|
name: string;
|
|
122
118
|
detail: string;
|
|
@@ -158,4 +154,4 @@ export declare class Config implements IConfig {
|
|
|
158
154
|
*/
|
|
159
155
|
private insertLegacyPlugins;
|
|
160
156
|
}
|
|
161
|
-
export declare function toCached(c: Command.Class, plugin?: IPlugin
|
|
157
|
+
export declare function toCached(c: Command.Class, plugin?: IPlugin, respectNoCacheDefault?: boolean): Promise<Command.Cached>;
|