@oclif/core 3.0.0-beta.1 → 3.0.0-beta.11

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 (54) hide show
  1. package/README.md +8 -6
  2. package/flush.js +1 -1
  3. package/handle.js +1 -1
  4. package/lib/cli-ux/action/base.js +2 -2
  5. package/lib/cli-ux/action/spinner.js +1 -1
  6. package/lib/cli-ux/config.d.ts +0 -1
  7. package/lib/cli-ux/config.js +6 -10
  8. package/lib/cli-ux/exit.d.ts +1 -1
  9. package/lib/cli-ux/exit.js +1 -1
  10. package/lib/cli-ux/flush.d.ts +1 -0
  11. package/lib/cli-ux/flush.js +28 -0
  12. package/lib/cli-ux/index.d.ts +1 -3
  13. package/lib/cli-ux/index.js +7 -31
  14. package/lib/cli-ux/prompt.js +2 -2
  15. package/lib/command.d.ts +2 -0
  16. package/lib/config/config.d.ts +9 -12
  17. package/lib/config/config.js +88 -135
  18. package/lib/config/index.d.ts +2 -1
  19. package/lib/config/index.js +2 -1
  20. package/lib/config/plugin-loader.d.ts +30 -0
  21. package/lib/config/plugin-loader.js +129 -0
  22. package/lib/config/plugin.d.ts +5 -10
  23. package/lib/config/plugin.js +21 -17
  24. package/lib/config/ts-node.d.ts +3 -2
  25. package/lib/config/ts-node.js +83 -36
  26. package/lib/errors/errors/cli.d.ts +1 -0
  27. package/lib/errors/errors/cli.js +1 -0
  28. package/lib/errors/handle.d.ts +2 -2
  29. package/lib/errors/handle.js +3 -3
  30. package/lib/errors/index.d.ts +1 -0
  31. package/lib/errors/index.js +8 -1
  32. package/lib/errors/logger.js +3 -3
  33. package/lib/execute.d.ts +49 -0
  34. package/lib/execute.js +62 -0
  35. package/lib/flags.js +6 -4
  36. package/lib/help/index.js +2 -2
  37. package/lib/index.d.ts +6 -4
  38. package/lib/index.js +9 -15
  39. package/lib/interfaces/config.d.ts +26 -26
  40. package/lib/interfaces/index.d.ts +14 -14
  41. package/lib/interfaces/parser.d.ts +14 -66
  42. package/lib/interfaces/pjson.d.ts +2 -0
  43. package/lib/interfaces/plugin.d.ts +8 -1
  44. package/lib/interfaces/ts-config.d.ts +9 -0
  45. package/lib/main.d.ts +1 -54
  46. package/lib/main.js +10 -72
  47. package/lib/module-loader.d.ts +1 -2
  48. package/lib/module-loader.js +9 -9
  49. package/lib/parser/parse.js +1 -34
  50. package/lib/performance.d.ts +1 -1
  51. package/lib/performance.js +1 -2
  52. package/package.json +14 -15
  53. package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
  54. 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](./MIGRATION.md) for an overview of breaking changes that occurred between v1 and v2.
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
- require('@oclif/core/flush')
55
- }, () => {
56
- require('@oclif/core/handle')
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['cli-ux'] = global['cli-ux'] || {};
35
- const globals = global['cli-ux'];
34
+ global.ux = global.ux || {};
35
+ const globals = global.ux;
36
36
  globals.action = globals.action || {};
37
37
  return globals;
38
38
  }
@@ -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;
@@ -8,7 +8,6 @@ export interface ConfigMessage {
8
8
  export declare class Config {
9
9
  outputLevel: Levels;
10
10
  action: ActionBase;
11
- prideAction: ActionBase;
12
11
  errorsHandled: boolean;
13
12
  showStackTrace: boolean;
14
13
  get debug(): boolean;
@@ -1,25 +1,20 @@
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
- const pride_spinner_1 = require("./action/pride-spinner");
9
- const version = semver.parse((0, util_1.requireJson)(__dirname, '..', '..', 'package.json').version);
10
7
  const g = global;
11
- const globals = g['cli-ux'] || (g['cli-ux'] = {});
8
+ const globals = g.ux || (g.ux = {});
12
9
  const actionType = (Boolean(process.stderr.isTTY) &&
13
10
  !process.env.CI &&
14
11
  !['dumb', 'emacs-color'].includes(process.env.TERM) &&
15
12
  'spinner') || 'simple';
16
13
  const Action = actionType === 'spinner' ? spinner_1.default : spinner_2.default;
17
- const PrideAction = actionType === 'spinner' ? pride_spinner_1.default : spinner_2.default;
18
14
  class Config {
19
15
  constructor() {
20
16
  this.outputLevel = 'info';
21
17
  this.action = new Action();
22
- this.prideAction = new PrideAction();
23
18
  this.errorsHandled = false;
24
19
  this.showStackTrace = true;
25
20
  }
@@ -38,10 +33,11 @@ class Config {
38
33
  }
39
34
  exports.Config = Config;
40
35
  function fetch() {
41
- if (globals[version.major])
42
- return globals[version.major];
43
- globals[version.major] = new Config();
44
- return globals[version.major];
36
+ const major = (0, util_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
37
+ if (globals[major])
38
+ return globals[major];
39
+ globals[major] = new Config();
40
+ return globals[major];
45
41
  }
46
42
  exports.config = fetch();
47
43
  exports.default = exports.config;
@@ -1,5 +1,5 @@
1
1
  export declare class ExitError extends Error {
2
- 'cli-ux': {
2
+ ux: {
3
3
  exit: number;
4
4
  };
5
5
  code: 'EEXIT';
@@ -6,7 +6,7 @@ class ExitError extends Error {
6
6
  const code = 'EEXIT';
7
7
  super(error ? error.message : `${code}: ${status}`);
8
8
  this.error = error;
9
- this['cli-ux'] = { exit: status };
9
+ this.ux = { exit: status };
10
10
  this.code = code;
11
11
  }
12
12
  }
@@ -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;
@@ -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, prideAction, progress, prompt, styledHeader, styledJSON, styledObject, table, Table, trace, tree, url, wait, warn, };
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, };
@@ -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.prideAction = 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;
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 timeout(_flush(), ms);
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 cliuxProcessExitHandler = async () => {
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 cliuxListener = process.listeners('exit').find(fn => fn.name === cliuxProcessExitHandler.name);
184
- if (!cliuxListener) {
185
- process.once('exit', cliuxProcessExitHandler);
159
+ const uxListener = process.listeners('exit').find(fn => fn.name === uxProcessExitHandler.name);
160
+ if (!uxListener) {
161
+ process.once('exit', uxProcessExitHandler);
186
162
  }
@@ -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/command.d.ts CHANGED
@@ -157,6 +157,8 @@ export declare namespace Command {
157
157
  [name: string]: Arg.Cached;
158
158
  };
159
159
  hasDynamicHelp?: boolean;
160
+ permutations?: string[];
161
+ aliasPermutations?: string[];
160
162
  };
161
163
  type Flag = CompletableFlag<any>;
162
164
  namespace Flag {
@@ -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(): Promise<void>;
46
- loadCorePlugins(): Promise<void>;
47
- loadDevPlugins(): Promise<void>;
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;
@@ -104,6 +105,7 @@ export declare class Config implements IConfig {
104
105
  get versionDetails(): VersionDetails;
105
106
  s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
106
107
  s3Url(key: string): string;
108
+ getPluginsList(): IPlugin[];
107
109
  protected dir(category: 'cache' | 'data' | 'config'): string;
108
110
  protected windowsHome(): string | undefined;
109
111
  protected windowsHomedriveHome(): string | undefined;
@@ -111,11 +113,6 @@ export declare class Config implements IConfig {
111
113
  protected macosCacheDir(): string | undefined;
112
114
  protected _shell(): string;
113
115
  protected _debug(): number;
114
- protected loadPlugins(root: string, type: string, plugins: (string | {
115
- root?: string;
116
- name?: string;
117
- tag?: string;
118
- })[], parent?: Plugin.Plugin): Promise<void>;
119
116
  protected warn(err: string | Error | {
120
117
  name: string;
121
118
  detail: string;
@@ -157,4 +154,4 @@ export declare class Config implements IConfig {
157
154
  */
158
155
  private insertLegacyPlugins;
159
156
  }
160
- export declare function toCached(c: Command.Class, plugin?: IPlugin | undefined, isWritingManifest?: boolean): Promise<Command.Cached>;
157
+ export declare function toCached(c: Command.Class, plugin?: IPlugin, respectNoCacheDefault?: boolean): Promise<Command.Cached>;