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

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 (85) hide show
  1. package/README.md +9 -7
  2. package/lib/command.d.ts +2 -0
  3. package/lib/command.js +4 -4
  4. package/lib/config/config.d.ts +9 -12
  5. package/lib/config/config.js +90 -137
  6. package/lib/config/index.d.ts +2 -1
  7. package/lib/config/index.js +2 -1
  8. package/lib/config/plugin-loader.d.ts +30 -0
  9. package/lib/config/plugin-loader.js +129 -0
  10. package/lib/config/plugin.d.ts +5 -10
  11. package/lib/config/plugin.js +21 -17
  12. package/lib/config/ts-node.d.ts +3 -2
  13. package/lib/config/ts-node.js +83 -36
  14. package/lib/errors/config.js +5 -5
  15. package/lib/errors/errors/cli.d.ts +1 -0
  16. package/lib/errors/errors/cli.js +1 -0
  17. package/lib/errors/handle.d.ts +2 -2
  18. package/lib/errors/handle.js +4 -5
  19. package/lib/errors/index.d.ts +2 -1
  20. package/lib/errors/index.js +9 -2
  21. package/lib/errors/logger.js +3 -3
  22. package/lib/execute.d.ts +49 -0
  23. package/lib/execute.js +62 -0
  24. package/lib/flags.js +6 -4
  25. package/lib/help/index.js +3 -3
  26. package/lib/index.d.ts +9 -7
  27. package/lib/index.js +13 -19
  28. package/lib/interfaces/config.d.ts +26 -26
  29. package/lib/interfaces/parser.d.ts +14 -66
  30. package/lib/interfaces/pjson.d.ts +2 -0
  31. package/lib/interfaces/plugin.d.ts +8 -1
  32. package/lib/interfaces/ts-config.d.ts +9 -0
  33. package/lib/main.d.ts +1 -54
  34. package/lib/main.js +11 -73
  35. package/lib/module-loader.d.ts +1 -2
  36. package/lib/module-loader.js +9 -9
  37. package/lib/parser/errors.js +1 -1
  38. package/lib/parser/parse.js +1 -34
  39. package/lib/performance.d.ts +1 -1
  40. package/lib/performance.js +2 -3
  41. package/lib/screen.js +2 -2
  42. package/lib/settings.d.ts +2 -1
  43. package/lib/settings.js +2 -2
  44. package/lib/{cli-ux → ux}/action/base.js +2 -2
  45. package/lib/{cli-ux → ux}/action/spinner.js +1 -1
  46. package/lib/{cli-ux → ux}/config.d.ts +0 -1
  47. package/lib/{cli-ux → ux}/config.js +6 -10
  48. package/lib/{cli-ux → ux}/exit.d.ts +1 -1
  49. package/lib/{cli-ux → ux}/exit.js +1 -1
  50. package/lib/ux/flush.d.ts +1 -0
  51. package/lib/ux/flush.js +27 -0
  52. package/lib/{cli-ux → ux}/index.d.ts +8 -27
  53. package/lib/{cli-ux → ux}/index.js +21 -80
  54. package/lib/{cli-ux → ux}/prompt.js +2 -2
  55. package/lib/{cli-ux → ux}/styled/json.js +3 -3
  56. package/package.json +24 -19
  57. package/flush.d.ts +0 -3
  58. package/flush.js +0 -1
  59. package/handle.js +0 -1
  60. package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
  61. package/lib/cli-ux/action/pride-spinner.js +0 -30
  62. /package/lib/{cli-ux → ux}/action/base.d.ts +0 -0
  63. /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
  64. /package/lib/{cli-ux → ux}/action/simple.js +0 -0
  65. /package/lib/{cli-ux → ux}/action/spinner.d.ts +0 -0
  66. /package/lib/{cli-ux → ux}/action/spinners.d.ts +0 -0
  67. /package/lib/{cli-ux → ux}/action/spinners.js +0 -0
  68. /package/lib/{cli-ux → ux}/list.d.ts +0 -0
  69. /package/lib/{cli-ux → ux}/list.js +0 -0
  70. /package/lib/{cli-ux → ux}/prompt.d.ts +0 -0
  71. /package/lib/{cli-ux → ux}/stream.d.ts +0 -0
  72. /package/lib/{cli-ux → ux}/stream.js +0 -0
  73. /package/lib/{cli-ux → ux}/styled/index.d.ts +0 -0
  74. /package/lib/{cli-ux → ux}/styled/index.js +0 -0
  75. /package/lib/{cli-ux → ux}/styled/json.d.ts +0 -0
  76. /package/lib/{cli-ux → ux}/styled/object.d.ts +0 -0
  77. /package/lib/{cli-ux → ux}/styled/object.js +0 -0
  78. /package/lib/{cli-ux → ux}/styled/progress.d.ts +0 -0
  79. /package/lib/{cli-ux → ux}/styled/progress.js +0 -0
  80. /package/lib/{cli-ux → ux}/styled/table.d.ts +0 -0
  81. /package/lib/{cli-ux → ux}/styled/table.js +0 -0
  82. /package/lib/{cli-ux → ux}/styled/tree.d.ts +0 -0
  83. /package/lib/{cli-ux → ux}/styled/tree.js +0 -0
  84. /package/lib/{cli-ux → ux}/wait.d.ts +0 -0
  85. /package/lib/{cli-ux → ux}/wait.js +0 -0
package/lib/main.js CHANGED
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.execute = exports.run = exports.versionAddition = exports.helpAddition = void 0;
3
+ exports.versionAddition = exports.helpAddition = void 0;
4
4
  const url_1 = require("url");
5
5
  const util_1 = require("util");
6
6
  const url_2 = require("url");
7
7
  const config_1 = require("./config");
8
8
  const help_1 = require("./help");
9
- const settings_1 = require("./settings");
10
- const _1 = require(".");
11
- const path_1 = require("path");
12
- const stream_1 = require("./cli-ux/stream");
9
+ const stream_1 = require("./ux/stream");
13
10
  const performance_1 = require("./performance");
11
+ const debug = require('debug')('oclif:main');
14
12
  const log = (message = '', ...args) => {
15
13
  message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
16
14
  stream_1.stdout.write((0, util_1.format)(message, ...args) + '\n');
@@ -37,14 +35,17 @@ const versionAddition = (argv, config) => {
37
35
  };
38
36
  exports.versionAddition = versionAddition;
39
37
  async function run(argv, options) {
40
- const marker = performance_1.Performance.mark('main.run');
41
- const initMarker = performance_1.Performance.mark('main.run#init');
38
+ const marker = performance_1.default.mark('main.run');
39
+ const initMarker = performance_1.default.mark('main.run#init');
42
40
  const collectPerf = async () => {
43
41
  marker?.stop();
44
42
  initMarker?.stop();
45
- await performance_1.Performance.collect();
46
- performance_1.Performance.debug();
43
+ await performance_1.default.collect();
44
+ performance_1.default.debug();
47
45
  };
46
+ debug(`process.execPath: ${process.execPath}`);
47
+ debug(`process.execArgv: ${process.execArgv}`);
48
+ debug('process.argv: %O', process.argv);
48
49
  argv = argv ?? process.argv.slice(2);
49
50
  // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
50
51
  if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
@@ -92,67 +93,4 @@ async function run(argv, options) {
92
93
  await collectPerf();
93
94
  }
94
95
  }
95
- exports.run = run;
96
- function getTsConfigPath(dir, type) {
97
- return type === 'cjs' ? (0, path_1.join)(dir, '..', 'tsconfig.json') : (0, path_1.join)((0, path_1.dirname)((0, url_1.fileURLToPath)(dir)), '..', 'tsconfig.json');
98
- }
99
- /**
100
- * Load and run oclif CLI
101
- *
102
- * @param options - options to load the CLI
103
- * @returns Promise<void>
104
- *
105
- * @example For ESM dev.js
106
- * ```
107
- * #!/usr/bin/env ts-node
108
- * // eslint-disable-next-line node/shebang
109
- * (async () => {
110
- * const oclif = await import('@oclif/core')
111
- * await oclif.execute({type: 'esm', development: true, dir: import.meta.url})
112
- * })()
113
- * ```
114
- *
115
- * @example For ESM run.js
116
- * ```
117
- * #!/usr/bin/env node
118
- * // eslint-disable-next-line node/shebang
119
- * (async () => {
120
- * const oclif = await import('@oclif/core')
121
- * await oclif.execute({type: 'esm', dir: import.meta.url})
122
- * })()
123
- * ```
124
- *
125
- * @example For CJS dev.js
126
- * ```
127
- * #!/usr/bin/env node
128
- * // eslint-disable-next-line node/shebang
129
- * (async () => {
130
- * const oclif = await import('@oclif/core')
131
- * await oclif.execute({type: 'cjs', development: true, dir: __dirname})
132
- * })()
133
- * ```
134
- *
135
- * @example For CJS run.js
136
- * ```
137
- * #!/usr/bin/env node
138
- * // eslint-disable-next-line node/shebang
139
- * (async () => {
140
- * const oclif = await import('@oclif/core')
141
- * await oclif.execute({type: 'cjs', dir: import.meta.url})
142
- * })()
143
- * ```
144
- */
145
- async function execute(options) {
146
- if (options.development) {
147
- // In dev mode -> use ts-node and dev plugins
148
- process.env.NODE_ENV = 'development';
149
- require('ts-node').register({
150
- project: getTsConfigPath(options.dir, options.type),
151
- });
152
- settings_1.settings.debug = true;
153
- }
154
- await run(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
155
- .then(async () => (0, _1.flush)())
156
- .catch(_1.Errors.handle);
157
- }
158
- exports.execute = execute;
96
+ exports.default = run;
@@ -1,5 +1,4 @@
1
- import { Config as IConfig } from './interfaces';
2
- import { Plugin as IPlugin } from './interfaces';
1
+ import { Config as IConfig, Plugin as IPlugin } from './interfaces';
3
2
  /**
4
3
  * Provides a static class with several utility methods to work with Oclif config / plugin to load ESM or CJS Node
5
4
  * modules and source files.
@@ -2,15 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
4
  const url = require("url");
5
- const fs = require("fs-extra");
5
+ const fs_1 = require("fs");
6
6
  const errors_1 = require("./errors");
7
- const Config = require("./config");
7
+ const config_1 = require("./config");
8
8
  const getPackageType = require('get-package-type');
9
9
  /**
10
10
  * Defines file extension resolution when source files do not have an extension.
11
11
  */
12
12
  // eslint-disable-next-line camelcase
13
13
  const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'];
14
+ const isPlugin = (config) => {
15
+ return config.type !== undefined;
16
+ };
14
17
  /**
15
18
  * Provides a static class with several utility methods to work with Oclif config / plugin to load ESM or CJS Node
16
19
  * modules and source files.
@@ -120,21 +123,18 @@ class ModuleLoader {
120
123
  static resolvePath(config, modulePath) {
121
124
  let isESM;
122
125
  let filePath;
123
- const isPlugin = (config) => {
124
- return config.type !== undefined;
125
- };
126
126
  try {
127
127
  filePath = require.resolve(modulePath);
128
128
  isESM = ModuleLoader.isPathModule(filePath);
129
129
  }
130
130
  catch {
131
- filePath = isPlugin(config) ? Config.tsPath(config.root, modulePath, config.type) : Config.tsPath(config.root, modulePath);
131
+ filePath = (isPlugin(config) ? (0, config_1.tsPath)(config.root, modulePath, config) : (0, config_1.tsPath)(config.root, modulePath)) ?? modulePath;
132
132
  let fileExists = false;
133
133
  let isDirectory = false;
134
- if (fs.existsSync(filePath)) {
134
+ if ((0, fs_1.existsSync)(filePath)) {
135
135
  fileExists = true;
136
136
  try {
137
- if (fs.lstatSync(filePath)?.isDirectory?.()) {
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 (fs.existsSync(testPath)) {
170
+ if ((0, fs_1.existsSync)(testPath)) {
171
171
  return testPath;
172
172
  }
173
173
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
4
4
  const errors_1 = require("../errors");
5
5
  const help_1 = require("./help");
6
- const list_1 = require("../cli-ux/list");
6
+ const list_1 = require("../ux/list");
7
7
  const chalk = require("chalk");
8
8
  const util_1 = require("../config/util");
9
9
  var errors_2 = require("../errors");
@@ -13,33 +13,7 @@ try {
13
13
  catch {
14
14
  debug = () => { };
15
15
  }
16
- /**
17
- * Support reading from stdin in Node 14 and older.
18
- *
19
- * This generally works for Node 14 and older EXCEPT when it's being
20
- * run from another process, in which case it will hang indefinitely. Because
21
- * of that issue we updated this to use AbortController but since AbortController
22
- * is only available in Node 16 and newer, we have to keep this legacy version.
23
- *
24
- * See these issues for more details on the hanging indefinitely bug:
25
- * https://github.com/oclif/core/issues/330
26
- * https://github.com/oclif/core/pull/363
27
- *
28
- * @returns Promise<string | null>
29
- */
30
- const readStdinLegacy = async () => {
31
- const { stdin } = process;
32
- let result;
33
- if (stdin.isTTY)
34
- return null;
35
- result = '';
36
- stdin.setEncoding('utf8');
37
- for await (const chunk of stdin) {
38
- result += chunk;
39
- }
40
- return result;
41
- };
42
- const readStdinWithTimeout = async () => {
16
+ const readStdin = async () => {
43
17
  const { stdin, stdout } = process;
44
18
  // process.stdin.isTTY is true whenever it's running in a terminal.
45
19
  // process.stdin.isTTY is undefined when it's running in a pipe, e.g. echo 'foo' | my-cli command
@@ -74,13 +48,6 @@ const readStdinWithTimeout = async () => {
74
48
  }, { once: true });
75
49
  });
76
50
  };
77
- const readStdin = async () => {
78
- const { stdin, version } = process;
79
- debug('stdin.isTTY', stdin.isTTY);
80
- const nodeMajorVersion = Number(version.split('.')[0].replace(/^v/, ''));
81
- debug('node version', nodeMajorVersion);
82
- return nodeMajorVersion > 14 ? readStdinWithTimeout() : readStdinLegacy();
83
- };
84
51
  function isNegativeNumber(input) {
85
52
  return /^-\d/g.test(input);
86
53
  }
@@ -32,7 +32,7 @@ declare class Marker {
32
32
  stop(): void;
33
33
  measure(): void;
34
34
  }
35
- export declare class Performance {
35
+ export default class Performance {
36
36
  private static markers;
37
37
  private static _results;
38
38
  private static _highlights;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Performance = void 0;
4
3
  const perf_hooks_1 = require("perf_hooks");
5
4
  const settings_1 = require("./settings");
6
5
  class Marker {
@@ -30,7 +29,7 @@ class Marker {
30
29
  }
31
30
  class Performance {
32
31
  static get enabled() {
33
- return settings_1.settings.performanceEnabled ?? false;
32
+ return settings_1.default.performanceEnabled ?? false;
34
33
  }
35
34
  static get results() {
36
35
  if (!Performance.enabled)
@@ -174,6 +173,6 @@ class Performance {
174
173
  }
175
174
  }
176
175
  }
177
- exports.Performance = Performance;
176
+ exports.default = Performance;
178
177
  Performance.markers = {};
179
178
  Performance._results = [];
package/lib/screen.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errtermwidth = exports.stdtermwidth = void 0;
4
- const stream_1 = require("./cli-ux/stream");
4
+ const stream_1 = require("./ux/stream");
5
5
  const settings_1 = require("./settings");
6
6
  function termwidth(stream) {
7
7
  if (!stream.isTTY) {
@@ -16,6 +16,6 @@ function termwidth(stream) {
16
16
  }
17
17
  return width;
18
18
  }
19
- const columns = Number.parseInt(process.env.OCLIF_COLUMNS, 10) || settings_1.settings.columns;
19
+ const columns = Number.parseInt(process.env.OCLIF_COLUMNS, 10) || settings_1.default.columns;
20
20
  exports.stdtermwidth = columns || termwidth(stream_1.stdout);
21
21
  exports.errtermwidth = columns || termwidth(stream_1.stderr);
package/lib/settings.d.ts CHANGED
@@ -36,4 +36,5 @@ export type Settings = {
36
36
  */
37
37
  performanceEnabled?: boolean;
38
38
  };
39
- export declare const settings: Settings;
39
+ declare const settings: Settings;
40
+ export default settings;
package/lib/settings.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settings = void 0;
4
3
  // Set global.oclif to the new object if it wasn't set before
5
4
  if (!global.oclif)
6
5
  global.oclif = {};
7
- exports.settings = global.oclif;
6
+ const settings = global.oclif;
7
+ exports.default = settings;
@@ -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 default function flush(ms?: number): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __1 = require("..");
4
+ function timeout(p, ms) {
5
+ function wait(ms, unref = false) {
6
+ return new Promise(resolve => {
7
+ const t = setTimeout(() => resolve(null), ms);
8
+ if (unref)
9
+ t.unref();
10
+ });
11
+ }
12
+ return Promise.race([p, wait(ms, true).then(() => __1.Errors.error('timed out'))]);
13
+ }
14
+ async function _flush() {
15
+ const p = new Promise(resolve => {
16
+ __1.stdout.once('drain', () => resolve(null));
17
+ });
18
+ const flushed = __1.stdout.write('');
19
+ if (flushed) {
20
+ return Promise.resolve();
21
+ }
22
+ return p;
23
+ }
24
+ async function flush(ms = 10000) {
25
+ await timeout(_flush(), ms);
26
+ }
27
+ exports.default = flush;
@@ -1,4 +1,3 @@
1
- import * as Errors from '../errors';
2
1
  import { ActionBase } from './action/base';
3
2
  import { config, Config } from './config';
4
3
  import { ExitError } from './exit';
@@ -7,7 +6,7 @@ import * as styled from './styled';
7
6
  import { Table } from './styled';
8
7
  import * as uxPrompt from './prompt';
9
8
  import uxWait from './wait';
10
- export declare class ux {
9
+ export default class ux {
11
10
  static config: Config;
12
11
  static get prompt(): typeof uxPrompt.prompt;
13
12
  /**
@@ -16,7 +15,6 @@ export declare class ux {
16
15
  static get anykey(): typeof uxPrompt.anykey;
17
16
  static get confirm(): typeof uxPrompt.confirm;
18
17
  static get action(): ActionBase;
19
- static get prideAction(): ActionBase;
20
18
  static styledObject(obj: any, keys?: string[]): void;
21
19
  static styledHeader(header: string): void;
22
20
  static get styledJSON(): typeof styled.styledJSON;
@@ -32,28 +30,11 @@ export declare class ux {
32
30
  static url(text: string, uri: string, params?: {}): void;
33
31
  static annotation(text: string, annotation: string): void;
34
32
  static flush(ms?: number): Promise<void>;
33
+ static error(err: Error | string, options?: {
34
+ code?: string;
35
+ exit?: number;
36
+ }): never;
37
+ static exit(code?: number): never;
38
+ static warn(err: Error | string): void;
35
39
  }
36
- declare const action: ActionBase;
37
- declare const annotation: typeof ux.annotation;
38
- declare const anykey: typeof uxPrompt.anykey;
39
- declare const confirm: typeof uxPrompt.confirm;
40
- declare const debug: typeof ux.debug;
41
- declare const done: typeof ux.done;
42
- declare const error: typeof Errors.error;
43
- declare const exit: typeof Errors.exit;
44
- declare const flush: typeof ux.flush;
45
- declare const info: typeof ux.info;
46
- declare const log: typeof ux.log;
47
- declare const prideAction: ActionBase;
48
- declare const progress: typeof styled.progress;
49
- declare const prompt: typeof uxPrompt.prompt;
50
- declare const styledHeader: typeof ux.styledHeader;
51
- declare const styledJSON: typeof styled.styledJSON;
52
- declare const styledObject: typeof ux.styledObject;
53
- declare const table: typeof styled.Table.table;
54
- declare const trace: typeof ux.trace;
55
- declare const tree: typeof styled.tree;
56
- declare const url: typeof ux.url;
57
- declare const wait: (ms?: number) => Promise<void>;
58
- 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, };
40
+ export { ActionBase, config, Config, ExitError, IPromptOptions, Table, };
@@ -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.Table = exports.ExitError = exports.Config = exports.config = exports.ActionBase = 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,15 +35,12 @@ 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
- this.info(styled.styledObject(obj, keys));
40
+ this.log(styled.styledObject(obj, keys));
63
41
  }
64
42
  static styledHeader(header) {
65
- this.info(chalk.dim('=== ') + chalk.bold(header) + '\n');
43
+ this.log(chalk.dim('=== ') + chalk.bold(header) + '\n');
66
44
  }
67
45
  static get styledJSON() {
68
46
  return styled.styledJSON;
@@ -83,12 +61,12 @@ class ux {
83
61
  config_1.config.action.stop();
84
62
  }
85
63
  static trace(format, ...args) {
86
- if (this.config.outputLevel === 'trace') {
64
+ if (ux.config.outputLevel === 'trace') {
87
65
  stream_1.stdout.write(util.format(format, ...args) + '\n');
88
66
  }
89
67
  }
90
68
  static debug(format, ...args) {
91
- if (['trace', 'debug'].includes(this.config.outputLevel)) {
69
+ if (['trace', 'debug'].includes(ux.config.outputLevel)) {
92
70
  stream_1.stdout.write(util.format(format, ...args) + '\n');
93
71
  }
94
72
  }
@@ -118,58 +96,21 @@ class ux {
118
96
  }
119
97
  }
120
98
  static async flush(ms = 10000) {
121
- await timeout(_flush(), ms);
99
+ await (0, flush_1.default)(ms);
100
+ }
101
+ static error(err, options = {}) {
102
+ throw Errors.error(err, options);
103
+ }
104
+ static exit(code = 0) {
105
+ throw Errors.exit(code);
106
+ }
107
+ static warn(err) {
108
+ Errors.warn(err);
122
109
  }
123
110
  }
124
- exports.ux = ux;
111
+ exports.default = ux;
125
112
  ux.config = config_1.config;
126
- const action = ux.action;
127
- exports.action = action;
128
- const annotation = ux.annotation;
129
- exports.annotation = annotation;
130
- const anykey = ux.anykey;
131
- exports.anykey = anykey;
132
- const confirm = ux.confirm;
133
- exports.confirm = confirm;
134
- const debug = ux.debug;
135
- exports.debug = debug;
136
- const done = ux.done;
137
- exports.done = done;
138
- const error = Errors.error;
139
- exports.error = error;
140
- const exit = Errors.exit;
141
- exports.exit = exit;
142
- const flush = ux.flush;
143
- exports.flush = flush;
144
- const info = ux.info;
145
- exports.info = info;
146
- const log = ux.log;
147
- exports.log = log;
148
- const prideAction = ux.prideAction;
149
- exports.prideAction = prideAction;
150
- const progress = ux.progress;
151
- exports.progress = progress;
152
- const prompt = ux.prompt;
153
- exports.prompt = prompt;
154
- const styledHeader = ux.styledHeader;
155
- exports.styledHeader = styledHeader;
156
- const styledJSON = ux.styledJSON;
157
- exports.styledJSON = styledJSON;
158
- const styledObject = ux.styledObject;
159
- exports.styledObject = styledObject;
160
- const table = ux.table;
161
- exports.table = table;
162
- const trace = ux.trace;
163
- exports.trace = trace;
164
- const tree = ux.tree;
165
- exports.tree = tree;
166
- const url = ux.url;
167
- exports.url = url;
168
- const wait = ux.wait;
169
- exports.wait = wait;
170
- const warn = Errors.warn;
171
- exports.warn = warn;
172
- const cliuxProcessExitHandler = async () => {
113
+ const uxProcessExitHandler = async () => {
173
114
  try {
174
115
  await ux.done();
175
116
  }
@@ -180,7 +121,7 @@ const cliuxProcessExitHandler = async () => {
180
121
  };
181
122
  // to avoid MaxListenersExceededWarning
182
123
  // 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);
124
+ const uxListener = process.listeners('exit').find(fn => fn.name === uxProcessExitHandler.name);
125
+ if (!uxListener) {
126
+ process.once('exit', uxProcessExitHandler);
186
127
  }
@@ -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);