@oclif/core 3.0.0-beta.9 → 3.0.1

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 (142) hide show
  1. package/README.md +4 -2
  2. package/flush.d.ts +3 -0
  3. package/flush.js +1 -0
  4. package/handle.js +1 -0
  5. package/lib/args.d.ts +2 -2
  6. package/lib/args.js +17 -18
  7. package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
  8. package/lib/{ux → cli-ux}/action/base.js +126 -120
  9. package/lib/{ux → cli-ux}/action/simple.js +25 -30
  10. package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
  11. package/lib/{ux → cli-ux}/action/spinner.js +45 -37
  12. package/lib/{ux → cli-ux}/action/spinners.js +187 -187
  13. package/lib/cli-ux/action/types.d.ts +5 -0
  14. package/lib/cli-ux/action/types.js +2 -0
  15. package/lib/{ux → cli-ux}/config.d.ts +5 -5
  16. package/lib/{ux → cli-ux}/config.js +17 -17
  17. package/lib/{ux → cli-ux}/exit.js +3 -0
  18. package/lib/cli-ux/flush.d.ts +1 -0
  19. package/lib/cli-ux/flush.js +28 -0
  20. package/lib/cli-ux/index.d.ts +39 -0
  21. package/lib/{ux → cli-ux}/index.js +74 -88
  22. package/lib/{ux → cli-ux}/list.js +3 -3
  23. package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
  24. package/lib/{ux → cli-ux}/prompt.js +35 -25
  25. package/lib/{ux → cli-ux}/stream.d.ts +6 -6
  26. package/lib/{ux → cli-ux}/stream.js +11 -10
  27. package/lib/cli-ux/styled/index.d.ts +4 -0
  28. package/lib/cli-ux/styled/index.js +11 -0
  29. package/lib/{ux → cli-ux}/styled/object.js +7 -9
  30. package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
  31. package/lib/{ux → cli-ux}/styled/table.js +130 -133
  32. package/lib/{ux → cli-ux}/styled/tree.js +11 -13
  33. package/lib/cli-ux/wait.js +5 -0
  34. package/lib/command.d.ts +82 -88
  35. package/lib/command.js +196 -175
  36. package/lib/config/config.d.ts +89 -90
  37. package/lib/config/config.js +466 -566
  38. package/lib/config/index.d.ts +0 -1
  39. package/lib/config/index.js +1 -3
  40. package/lib/config/plugin-loader.d.ts +12 -12
  41. package/lib/config/plugin-loader.js +72 -56
  42. package/lib/config/plugin.d.ts +25 -24
  43. package/lib/config/plugin.js +188 -154
  44. package/lib/config/ts-node.d.ts +2 -1
  45. package/lib/config/ts-node.js +71 -58
  46. package/lib/config/util.d.ts +1 -11
  47. package/lib/config/util.js +6 -59
  48. package/lib/errors/config.d.ts +1 -1
  49. package/lib/errors/config.js +6 -6
  50. package/lib/errors/errors/cli.d.ts +7 -7
  51. package/lib/errors/errors/cli.js +20 -16
  52. package/lib/errors/errors/exit.d.ts +1 -4
  53. package/lib/errors/errors/exit.js +1 -1
  54. package/lib/errors/errors/module-load.d.ts +1 -4
  55. package/lib/errors/errors/module-load.js +1 -1
  56. package/lib/errors/errors/pretty-print.d.ts +1 -1
  57. package/lib/errors/errors/pretty-print.js +12 -10
  58. package/lib/errors/handle.d.ts +12 -2
  59. package/lib/errors/handle.js +26 -14
  60. package/lib/errors/index.d.ts +10 -10
  61. package/lib/errors/index.js +25 -24
  62. package/lib/errors/logger.d.ts +2 -2
  63. package/lib/errors/logger.js +14 -13
  64. package/lib/execute.d.ts +6 -6
  65. package/lib/execute.js +10 -9
  66. package/lib/flags.d.ts +103 -32
  67. package/lib/flags.js +79 -45
  68. package/lib/help/command.d.ts +16 -14
  69. package/lib/help/command.js +178 -163
  70. package/lib/help/docopts.d.ts +5 -5
  71. package/lib/help/docopts.js +50 -54
  72. package/lib/help/formatter.d.ts +37 -37
  73. package/lib/help/formatter.js +66 -55
  74. package/lib/help/index.d.ts +25 -21
  75. package/lib/help/index.js +169 -147
  76. package/lib/help/root.d.ts +1 -1
  77. package/lib/help/root.js +15 -17
  78. package/lib/help/util.d.ts +2 -8
  79. package/lib/help/util.js +8 -28
  80. package/lib/index.d.ts +19 -20
  81. package/lib/index.js +37 -43
  82. package/lib/interfaces/config.d.ts +67 -66
  83. package/lib/interfaces/errors.d.ts +5 -5
  84. package/lib/interfaces/help.d.ts +17 -17
  85. package/lib/interfaces/hooks.d.ts +49 -49
  86. package/lib/interfaces/index.d.ts +7 -7
  87. package/lib/interfaces/manifest.d.ts +1 -1
  88. package/lib/interfaces/parser.d.ts +175 -51
  89. package/lib/interfaces/pjson.d.ts +45 -41
  90. package/lib/interfaces/plugin.d.ts +47 -41
  91. package/lib/interfaces/s3-manifest.d.ts +7 -7
  92. package/lib/interfaces/topic.d.ts +1 -1
  93. package/lib/interfaces/ts-config.d.ts +7 -7
  94. package/lib/main.d.ts +2 -2
  95. package/lib/main.js +16 -16
  96. package/lib/module-loader.d.ts +67 -77
  97. package/lib/module-loader.js +183 -150
  98. package/lib/parser/errors.d.ts +7 -7
  99. package/lib/parser/errors.js +29 -22
  100. package/lib/parser/help.js +5 -5
  101. package/lib/parser/index.js +2 -2
  102. package/lib/parser/parse.d.ts +9 -6
  103. package/lib/parser/parse.js +253 -221
  104. package/lib/parser/validate.js +53 -33
  105. package/lib/performance.d.ts +43 -32
  106. package/lib/performance.js +133 -91
  107. package/lib/screen.js +2 -2
  108. package/lib/settings.d.ts +11 -12
  109. package/lib/settings.js +2 -2
  110. package/lib/util/aggregate-flags.d.ts +2 -0
  111. package/lib/util/aggregate-flags.js +13 -0
  112. package/lib/util/cache-command.d.ts +3 -0
  113. package/lib/util/cache-command.js +109 -0
  114. package/lib/util/cache-default-value.d.ts +2 -0
  115. package/lib/util/cache-default-value.js +28 -0
  116. package/lib/util/ensure-arg-object.d.ts +12 -0
  117. package/lib/util/ensure-arg-object.js +14 -0
  118. package/lib/util/fs.d.ts +7 -0
  119. package/lib/util/fs.js +54 -0
  120. package/lib/util/os.d.ts +19 -0
  121. package/lib/util/os.js +28 -0
  122. package/lib/{util.d.ts → util/util.d.ts} +7 -16
  123. package/lib/util/util.js +98 -0
  124. package/package.json +35 -37
  125. package/lib/util.js +0 -126
  126. package/lib/ux/flush.d.ts +0 -1
  127. package/lib/ux/flush.js +0 -27
  128. package/lib/ux/index.d.ts +0 -58
  129. package/lib/ux/styled/index.d.ts +0 -6
  130. package/lib/ux/styled/index.js +0 -13
  131. package/lib/ux/styled/json.d.ts +0 -1
  132. package/lib/ux/styled/json.js +0 -15
  133. package/lib/ux/wait.js +0 -7
  134. package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
  135. package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
  136. package/lib/{ux → cli-ux}/exit.d.ts +2 -2
  137. package/lib/{ux → cli-ux}/list.d.ts +0 -0
  138. package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
  139. package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
  140. package/lib/{ux → cli-ux}/styled/progress.js +0 -0
  141. package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
  142. /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
@@ -1,22 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = exports.Config = void 0;
4
- const util_1 = require("../util");
5
- const spinner_1 = require("./action/spinner");
6
- const spinner_2 = require("./action/spinner");
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = require("../util/fs");
6
+ const simple_1 = tslib_1.__importDefault(require("./action/simple"));
7
+ const spinner_1 = tslib_1.__importDefault(require("./action/spinner"));
7
8
  const g = global;
8
9
  const globals = g.ux || (g.ux = {});
9
10
  const actionType = (Boolean(process.stderr.isTTY) &&
10
11
  !process.env.CI &&
11
12
  !['dumb', 'emacs-color'].includes(process.env.TERM) &&
12
- 'spinner') || 'simple';
13
- const Action = actionType === 'spinner' ? spinner_1.default : spinner_2.default;
13
+ 'spinner') ||
14
+ 'simple';
15
+ const Action = actionType === 'spinner' ? spinner_1.default : simple_1.default;
14
16
  class Config {
15
- constructor() {
16
- this.outputLevel = 'info';
17
- this.action = new Action();
18
- this.errorsHandled = false;
19
- this.showStackTrace = true;
17
+ action = new Action();
18
+ errorsHandled = false;
19
+ outputLevel = 'info';
20
+ showStackTrace = true;
21
+ get context() {
22
+ return globals.context || {};
23
+ }
24
+ set context(v) {
25
+ globals.context = v;
20
26
  }
21
27
  get debug() {
22
28
  return globals.debug || process.env.DEBUG === '*';
@@ -24,16 +30,10 @@ class Config {
24
30
  set debug(v) {
25
31
  globals.debug = v;
26
32
  }
27
- get context() {
28
- return globals.context || {};
29
- }
30
- set context(v) {
31
- globals.context = v;
32
- }
33
33
  }
34
34
  exports.Config = Config;
35
35
  function fetch() {
36
- const major = (0, util_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
36
+ const major = (0, fs_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
37
37
  if (globals[major])
38
38
  return globals[major];
39
39
  globals[major] = new Config();
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExitError = void 0;
4
4
  class ExitError extends Error {
5
+ code;
6
+ error;
7
+ ux;
5
8
  constructor(status, error) {
6
9
  const code = 'EEXIT';
7
10
  super(error ? error.message : `${code}: ${status}`);
@@ -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 errors_1 = require("../errors");
5
+ const stream_1 = require("./stream");
6
+ function timeout(p, ms) {
7
+ function wait(ms, unref = false) {
8
+ return new Promise((resolve) => {
9
+ const t = setTimeout(() => resolve(null), ms);
10
+ if (unref)
11
+ t.unref();
12
+ });
13
+ }
14
+ return Promise.race([p, wait(ms, true).then(() => (0, errors_1.error)('timed out'))]);
15
+ }
16
+ async function _flush() {
17
+ const p = new Promise((resolve) => {
18
+ stream_1.stdout.once('drain', () => resolve(null));
19
+ });
20
+ const flushed = stream_1.stdout.write('');
21
+ if (flushed)
22
+ return;
23
+ return p;
24
+ }
25
+ async function flush(ms = 10000) {
26
+ await timeout(_flush(), ms);
27
+ }
28
+ exports.flush = flush;
@@ -0,0 +1,39 @@
1
+ import * as Errors from '../errors';
2
+ import { ActionBase } from './action/base';
3
+ import { Config } from './config';
4
+ import * as uxPrompt from './prompt';
5
+ import * as styled from './styled';
6
+ import uxWait from './wait';
7
+ export declare class ux {
8
+ static config: Config;
9
+ static get action(): ActionBase;
10
+ static annotation(text: string, annotation: string): void;
11
+ /**
12
+ * "press anykey to continue"
13
+ */
14
+ static get anykey(): typeof uxPrompt.anykey;
15
+ static get confirm(): typeof uxPrompt.confirm;
16
+ static debug(format: string, ...args: string[]): void;
17
+ static done(): Promise<void>;
18
+ static flush(ms?: number): Promise<void>;
19
+ static info(format: string, ...args: string[]): void;
20
+ static log(format?: string, ...args: string[]): void;
21
+ static get progress(): typeof styled.progress;
22
+ static get prompt(): typeof uxPrompt.prompt;
23
+ static styledHeader(header: string): void;
24
+ static styledJSON(obj: unknown): void;
25
+ static styledObject(obj: any, keys?: string[]): void;
26
+ static get table(): typeof styled.Table.table;
27
+ static trace(format: string, ...args: string[]): void;
28
+ static get tree(): typeof styled.tree;
29
+ static url(text: string, uri: string, params?: {}): void;
30
+ static get wait(): typeof uxWait;
31
+ }
32
+ declare const action: ActionBase, annotation: typeof ux.annotation, anykey: typeof uxPrompt.anykey, confirm: typeof uxPrompt.confirm, debug: typeof ux.debug, done: typeof ux.done, flush: typeof ux.flush, info: typeof ux.info, log: typeof ux.log, progress: typeof styled.progress, prompt: typeof uxPrompt.prompt, styledHeader: typeof ux.styledHeader, styledJSON: typeof ux.styledJSON, styledObject: typeof ux.styledObject, table: typeof styled.Table.table, trace: typeof ux.trace, tree: typeof styled.tree, url: typeof ux.url, wait: (ms?: number) => Promise<void>;
33
+ declare const error: typeof Errors.error, exit: typeof Errors.exit, warn: typeof Errors.warn;
34
+ export { action, annotation, anykey, confirm, debug, done, error, exit, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, warn, };
35
+ export { ActionBase } from './action/base';
36
+ export { Config, config } from './config';
37
+ export { ExitError } from './exit';
38
+ export { IPromptOptions } from './prompt';
39
+ export { Table } from './styled';
@@ -1,29 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Table = exports.ExitError = exports.Config = exports.config = exports.ActionBase = exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.log = exports.info = exports.flush = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.anykey = exports.annotation = exports.action = void 0;
3
+ exports.Table = exports.ExitError = exports.config = exports.Config = exports.ActionBase = exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.log = exports.info = exports.flush = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.anykey = exports.annotation = exports.action = exports.ux = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const Errors = require("../errors");
6
- const util = require("util");
7
- const chalk = require("chalk");
8
- const base_1 = require("./action/base");
9
- Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function () { return base_1.ActionBase; } });
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const node_util_1 = require("node:util");
7
+ const Errors = tslib_1.__importStar(require("../errors"));
10
8
  const config_1 = require("./config");
11
- Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
12
- Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
13
- const exit_1 = require("./exit");
14
- Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
15
- const styled = require("./styled");
16
- const styled_1 = require("./styled");
17
- Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return styled_1.Table; } });
18
- tslib_1.__exportStar(require("./styled/table"), exports);
19
- const uxPrompt = require("./prompt");
20
- const wait_1 = require("./wait");
9
+ const flush_1 = require("./flush");
10
+ const uxPrompt = tslib_1.__importStar(require("./prompt"));
21
11
  const stream_1 = require("./stream");
22
- const _flush = require("./flush");
12
+ const styled = tslib_1.__importStar(require("./styled"));
13
+ const wait_1 = tslib_1.__importDefault(require("./wait"));
23
14
  const hyperlinker = require('hyperlinker');
24
15
  class ux {
25
- static get prompt() {
26
- return uxPrompt.prompt;
16
+ static config = config_1.config;
17
+ static get action() {
18
+ return config_1.config.action;
19
+ }
20
+ static annotation(text, annotation) {
21
+ const supports = require('supports-hyperlinks');
22
+ if (supports.stdout) {
23
+ // \u001b]8;;https://google.com\u0007sometext\u001b]8;;\u0007
24
+ this.log(`\u001B]1337;AddAnnotation=${text.length}|${annotation}\u0007${text}`);
25
+ }
26
+ else {
27
+ this.log(text);
28
+ }
27
29
  }
28
30
  /**
29
31
  * "press anykey to continue"
@@ -34,49 +36,55 @@ class ux {
34
36
  static get confirm() {
35
37
  return uxPrompt.confirm;
36
38
  }
37
- static get action() {
38
- return config_1.config.action;
39
- }
40
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
41
- static styledObject(obj, keys) {
42
- this.info(styled.styledObject(obj, keys));
43
- }
44
- static styledHeader(header) {
45
- this.info(chalk.dim('=== ') + chalk.bold(header) + '\n');
39
+ static debug(format, ...args) {
40
+ if (['debug', 'trace'].includes(this.config.outputLevel)) {
41
+ stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
42
+ }
46
43
  }
47
- static get styledJSON() {
48
- return styled.styledJSON;
44
+ static async done() {
45
+ config_1.config.action.stop();
49
46
  }
50
- static get table() {
51
- return styled.Table.table;
47
+ static async flush(ms = 10000) {
48
+ await (0, flush_1.flush)(ms);
52
49
  }
53
- static get tree() {
54
- return styled.tree;
50
+ static info(format, ...args) {
51
+ stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
55
52
  }
56
- static get wait() {
57
- return wait_1.default;
53
+ static log(format, ...args) {
54
+ this.info(format || '', ...args);
58
55
  }
59
56
  static get progress() {
60
57
  return styled.progress;
61
58
  }
62
- static async done() {
63
- config_1.config.action.stop();
59
+ static get prompt() {
60
+ return uxPrompt.prompt;
64
61
  }
65
- static trace(format, ...args) {
66
- if (this.config.outputLevel === 'trace') {
67
- stream_1.stdout.write(util.format(format, ...args) + '\n');
68
- }
62
+ static styledHeader(header) {
63
+ this.info(chalk_1.default.dim('=== ') + chalk_1.default.bold(header) + '\n');
69
64
  }
70
- static debug(format, ...args) {
71
- if (['trace', 'debug'].includes(this.config.outputLevel)) {
72
- stream_1.stdout.write(util.format(format, ...args) + '\n');
65
+ static styledJSON(obj) {
66
+ const json = JSON.stringify(obj, null, 2);
67
+ if (!chalk_1.default.level) {
68
+ info(json);
69
+ return;
73
70
  }
71
+ const cardinal = require('cardinal');
72
+ const theme = require('cardinal/themes/jq');
73
+ this.info(cardinal.highlight(json, { json: true, theme }));
74
74
  }
75
- static info(format, ...args) {
76
- stream_1.stdout.write(util.format(format, ...args) + '\n');
75
+ static styledObject(obj, keys) {
76
+ this.info(styled.styledObject(obj, keys));
77
77
  }
78
- static log(format, ...args) {
79
- this.info(format || '', ...args);
78
+ static get table() {
79
+ return styled.Table.table;
80
+ }
81
+ static trace(format, ...args) {
82
+ if (this.config.outputLevel === 'trace') {
83
+ stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
84
+ }
85
+ }
86
+ static get tree() {
87
+ return styled.tree;
80
88
  }
81
89
  static url(text, uri, params = {}) {
82
90
  const supports = require('supports-hyperlinks');
@@ -87,65 +95,34 @@ class ux {
87
95
  this.log(uri);
88
96
  }
89
97
  }
90
- static annotation(text, annotation) {
91
- const supports = require('supports-hyperlinks');
92
- if (supports.stdout) {
93
- // \u001b]8;;https://google.com\u0007sometext\u001b]8;;\u0007
94
- this.log(`\u001B]1337;AddAnnotation=${text.length}|${annotation}\u0007${text}`);
95
- }
96
- else {
97
- this.log(text);
98
- }
99
- }
100
- static async flush(ms = 10000) {
101
- await _flush.default(ms);
98
+ static get wait() {
99
+ return wait_1.default;
102
100
  }
103
101
  }
104
- exports.default = ux;
105
- ux.config = config_1.config;
106
- const action = ux.action;
102
+ exports.ux = ux;
103
+ const { action, annotation, anykey, confirm, debug, done, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, } = ux;
107
104
  exports.action = action;
108
- const annotation = ux.annotation;
109
105
  exports.annotation = annotation;
110
- const anykey = ux.anykey;
111
106
  exports.anykey = anykey;
112
- const confirm = ux.confirm;
113
107
  exports.confirm = confirm;
114
- const debug = ux.debug;
115
108
  exports.debug = debug;
116
- const done = ux.done;
117
109
  exports.done = done;
118
- const error = Errors.error;
119
- exports.error = error;
120
- const exit = Errors.exit;
121
- exports.exit = exit;
122
- const flush = ux.flush;
123
110
  exports.flush = flush;
124
- const info = ux.info;
125
111
  exports.info = info;
126
- const log = ux.log;
127
112
  exports.log = log;
128
- const progress = ux.progress;
129
113
  exports.progress = progress;
130
- const prompt = ux.prompt;
131
114
  exports.prompt = prompt;
132
- const styledHeader = ux.styledHeader;
133
115
  exports.styledHeader = styledHeader;
134
- const styledJSON = ux.styledJSON;
135
116
  exports.styledJSON = styledJSON;
136
- const styledObject = ux.styledObject;
137
117
  exports.styledObject = styledObject;
138
- const table = ux.table;
139
118
  exports.table = table;
140
- const trace = ux.trace;
141
119
  exports.trace = trace;
142
- const tree = ux.tree;
143
120
  exports.tree = tree;
144
- const url = ux.url;
145
121
  exports.url = url;
146
- const wait = ux.wait;
147
122
  exports.wait = wait;
148
- const warn = Errors.warn;
123
+ const { error, exit, warn } = Errors;
124
+ exports.error = error;
125
+ exports.exit = exit;
149
126
  exports.warn = warn;
150
127
  const uxProcessExitHandler = async () => {
151
128
  try {
@@ -158,7 +135,16 @@ const uxProcessExitHandler = async () => {
158
135
  };
159
136
  // to avoid MaxListenersExceededWarning
160
137
  // only attach named listener once
161
- const uxListener = process.listeners('exit').find(fn => fn.name === uxProcessExitHandler.name);
138
+ const uxListener = process.listeners('exit').find((fn) => fn.name === uxProcessExitHandler.name);
162
139
  if (!uxListener) {
163
140
  process.once('exit', uxProcessExitHandler);
164
141
  }
142
+ var base_1 = require("./action/base");
143
+ Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function () { return base_1.ActionBase; } });
144
+ var config_2 = require("./config");
145
+ Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_2.Config; } });
146
+ Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_2.config; } });
147
+ var exit_1 = require("./exit");
148
+ Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
149
+ var styled_1 = require("./styled");
150
+ Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return styled_1.Table; } });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderList = void 0;
4
4
  const screen_1 = require("../screen");
5
- const util_1 = require("../util");
5
+ const util_1 = require("../util/util");
6
6
  const wordwrap = require('wordwrap');
7
7
  function linewrap(length, s) {
8
8
  return wordwrap(length, screen_1.stdtermwidth, {
@@ -13,8 +13,8 @@ function renderList(items) {
13
13
  if (items.length === 0) {
14
14
  return '';
15
15
  }
16
- const maxLength = (0, util_1.maxBy)(items, item => item[0].length)?.[0].length ?? 0;
17
- const lines = items.map(i => {
16
+ const maxLength = (0, util_1.maxBy)(items, (item) => item[0].length)?.[0].length ?? 0;
17
+ const lines = items.map((i) => {
18
18
  let left = i[0];
19
19
  let right = i[1];
20
20
  if (!right) {
@@ -1,12 +1,12 @@
1
1
  export interface IPromptOptions {
2
+ default?: string;
2
3
  prompt?: string;
3
- type?: 'normal' | 'mask' | 'hide' | 'single';
4
- timeout?: number;
5
4
  /**
6
5
  * Requires user input if true, otherwise allows empty input
7
6
  */
8
7
  required?: boolean;
9
- default?: string;
8
+ timeout?: number;
9
+ type?: 'hide' | 'mask' | 'normal' | 'single';
10
10
  }
11
11
  /**
12
12
  * prompt for input
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.anykey = exports.confirm = exports.prompt = void 0;
4
- const Errors = require("../errors");
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const Errors = tslib_1.__importStar(require("../errors"));
5
7
  const config_1 = require("./config");
6
- const chalk = require("chalk");
7
8
  const stream_1 = require("./stream");
8
9
  function normal(options, retries = 100) {
9
10
  if (retries < 0)
@@ -20,7 +21,7 @@ function normal(options, retries = 100) {
20
21
  process.stdin.setEncoding('utf8');
21
22
  stream_1.stderr.write(options.prompt);
22
23
  process.stdin.resume();
23
- process.stdin.once('data', b => {
24
+ process.stdin.once('data', (b) => {
24
25
  if (timer)
25
26
  clearTimeout(timer);
26
27
  process.stdin.pause();
@@ -40,7 +41,7 @@ function getPrompt(name, type, defaultValue) {
40
41
  defaultValue = '*'.repeat(defaultValue.length);
41
42
  }
42
43
  if (name && defaultValue)
43
- prompt = name + ' ' + chalk.yellow('[' + defaultValue + ']') + ': ';
44
+ prompt = name + ' ' + chalk_1.default.yellow('[' + defaultValue + ']') + ': ';
44
45
  else if (name)
45
46
  prompt = `${name}: `;
46
47
  return prompt;
@@ -57,43 +58,53 @@ async function single(options) {
57
58
  }
58
59
  function replacePrompt(prompt) {
59
60
  const ansiEscapes = require('ansi-escapes');
60
- stream_1.stderr.write(ansiEscapes.cursorHide + ansiEscapes.cursorUp(1) + ansiEscapes.cursorLeft + prompt +
61
- ansiEscapes.cursorDown(1) + ansiEscapes.cursorLeft + ansiEscapes.cursorShow);
61
+ stream_1.stderr.write(ansiEscapes.cursorHide +
62
+ ansiEscapes.cursorUp(1) +
63
+ ansiEscapes.cursorLeft +
64
+ prompt +
65
+ ansiEscapes.cursorDown(1) +
66
+ ansiEscapes.cursorLeft +
67
+ ansiEscapes.cursorShow);
62
68
  }
63
69
  async function _prompt(name, inputOptions = {}) {
64
70
  const prompt = getPrompt(name, inputOptions.type, inputOptions.default);
65
71
  const options = {
72
+ default: '',
66
73
  isTTY: Boolean(process.env.TERM !== 'dumb' && process.stdin.isTTY),
67
74
  name,
68
75
  prompt,
69
- type: 'normal',
70
76
  required: true,
71
- default: '',
77
+ type: 'normal',
72
78
  ...inputOptions,
73
79
  };
74
80
  const passwordPrompt = require('password-prompt');
75
81
  switch (options.type) {
76
- case 'normal':
82
+ case 'normal': {
77
83
  return normal(options);
78
- case 'single':
84
+ }
85
+ case 'single': {
79
86
  return single(options);
80
- case 'mask':
87
+ }
88
+ case 'mask': {
81
89
  return passwordPrompt(options.prompt, {
90
+ default: options.default,
82
91
  method: options.type,
83
92
  required: options.required,
84
- default: options.default,
85
93
  }).then((value) => {
86
94
  replacePrompt(getPrompt(name, 'hide', inputOptions.default));
87
95
  return value;
88
96
  });
89
- case 'hide':
97
+ }
98
+ case 'hide': {
90
99
  return passwordPrompt(options.prompt, {
100
+ default: options.default,
91
101
  method: options.type,
92
102
  required: options.required,
93
- default: options.default,
94
103
  });
95
- default:
104
+ }
105
+ default: {
96
106
  throw new Error(`unexpected type ${options.type}`);
107
+ }
97
108
  }
98
109
  }
99
110
  /**
@@ -103,9 +114,7 @@ async function _prompt(name, inputOptions = {}) {
103
114
  * @returns Promise<string>
104
115
  */
105
116
  async function prompt(name, options = {}) {
106
- return config_1.default.action.pauseAsync(() => {
107
- return _prompt(name, options);
108
- }, chalk.cyan('?'));
117
+ return config_1.config.action.pauseAsync(() => _prompt(name, options), chalk_1.default.cyan('?'));
109
118
  }
110
119
  exports.prompt = prompt;
111
120
  /**
@@ -114,9 +123,10 @@ exports.prompt = prompt;
114
123
  * @returns Promise<boolean>
115
124
  */
116
125
  function confirm(message) {
117
- return config_1.default.action.pauseAsync(async () => {
126
+ return config_1.config.action.pauseAsync(async () => {
118
127
  const confirm = async () => {
119
- const response = (await _prompt(message)).toLowerCase();
128
+ const raw = await _prompt(message);
129
+ const response = raw.toLowerCase();
120
130
  if (['n', 'no'].includes(response))
121
131
  return false;
122
132
  if (['y', 'yes'].includes(response))
@@ -124,7 +134,7 @@ function confirm(message) {
124
134
  return confirm();
125
135
  };
126
136
  return confirm();
127
- }, chalk.cyan('?'));
137
+ }, chalk_1.default.cyan('?'));
128
138
  }
129
139
  exports.confirm = confirm;
130
140
  /**
@@ -135,11 +145,11 @@ exports.confirm = confirm;
135
145
  async function anykey(message) {
136
146
  const tty = Boolean(process.stdin.setRawMode);
137
147
  if (!message) {
138
- message = tty ?
139
- `Press any key to continue or ${chalk.yellow('q')} to exit` :
140
- `Press enter to continue or ${chalk.yellow('q')} to exit`;
148
+ message = tty
149
+ ? `Press any key to continue or ${chalk_1.default.yellow('q')} to exit`
150
+ : `Press enter to continue or ${chalk_1.default.yellow('q')} to exit`;
141
151
  }
142
- const char = await prompt(message, { type: 'single', required: false });
152
+ const char = await prompt(message, { required: false, type: 'single' });
143
153
  if (tty)
144
154
  stream_1.stderr.write('\n');
145
155
  if (char === 'q')
@@ -2,15 +2,15 @@
2
2
  * A wrapper around process.stdout and process.stderr that allows us to mock out the streams for testing.
3
3
  */
4
4
  declare class Stream {
5
- channel: 'stdout' | 'stderr';
6
- constructor(channel: 'stdout' | 'stderr');
7
- get isTTY(): boolean;
5
+ channel: 'stderr' | 'stdout';
6
+ constructor(channel: 'stderr' | 'stdout');
7
+ emit(event: string, ...args: any[]): boolean;
8
8
  getWindowSize(): number[];
9
- write(data: string): boolean;
10
- read(): boolean;
11
9
  on(event: string, listener: (...args: any[]) => void): Stream;
12
10
  once(event: string, listener: (...args: any[]) => void): Stream;
13
- emit(event: string, ...args: any[]): boolean;
11
+ read(): boolean;
12
+ write(data: string): boolean;
13
+ get isTTY(): boolean;
14
14
  }
15
15
  export declare const stdout: Stream;
16
16
  export declare const stderr: Stream;
@@ -5,21 +5,16 @@ exports.stderr = exports.stdout = void 0;
5
5
  * A wrapper around process.stdout and process.stderr that allows us to mock out the streams for testing.
6
6
  */
7
7
  class Stream {
8
+ channel;
8
9
  constructor(channel) {
9
10
  this.channel = channel;
10
11
  }
11
- get isTTY() {
12
- return process[this.channel].isTTY;
12
+ emit(event, ...args) {
13
+ return process[this.channel].emit(event, ...args);
13
14
  }
14
15
  getWindowSize() {
15
16
  return process[this.channel].getWindowSize();
16
17
  }
17
- write(data) {
18
- return process[this.channel].write(data);
19
- }
20
- read() {
21
- return process[this.channel].read();
22
- }
23
18
  on(event, listener) {
24
19
  process[this.channel].on(event, listener);
25
20
  return this;
@@ -28,8 +23,14 @@ class Stream {
28
23
  process[this.channel].once(event, listener);
29
24
  return this;
30
25
  }
31
- emit(event, ...args) {
32
- return process[this.channel].emit(event, ...args);
26
+ read() {
27
+ return process[this.channel].read();
28
+ }
29
+ write(data) {
30
+ return process[this.channel].write(data);
31
+ }
32
+ get isTTY() {
33
+ return process[this.channel].isTTY;
33
34
  }
34
35
  }
35
36
  exports.stdout = new Stream('stdout');
@@ -0,0 +1,4 @@
1
+ export { default as styledObject } from './object';
2
+ export { default as progress } from './progress';
3
+ export * as Table from './table';
4
+ export { default as tree } from './tree';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tree = exports.Table = exports.progress = exports.styledObject = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var object_1 = require("./object");
6
+ Object.defineProperty(exports, "styledObject", { enumerable: true, get: function () { return tslib_1.__importDefault(object_1).default; } });
7
+ var progress_1 = require("./progress");
8
+ Object.defineProperty(exports, "progress", { enumerable: true, get: function () { return tslib_1.__importDefault(progress_1).default; } });
9
+ exports.Table = tslib_1.__importStar(require("./table"));
10
+ var tree_1 = require("./tree");
11
+ Object.defineProperty(exports, "tree", { enumerable: true, get: function () { return tslib_1.__importDefault(tree_1).default; } });