@oclif/core 3.0.0-beta.17 → 3.0.0-beta.19

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 (69) hide show
  1. package/lib/args.js +4 -4
  2. package/lib/cli-ux/action/base.js +8 -7
  3. package/lib/cli-ux/action/simple.js +1 -4
  4. package/lib/cli-ux/action/spinner.js +8 -7
  5. package/lib/cli-ux/action/spinners.js +1 -1
  6. package/lib/cli-ux/config.js +11 -12
  7. package/lib/cli-ux/exit.js +3 -0
  8. package/lib/cli-ux/flush.js +7 -6
  9. package/lib/cli-ux/index.js +2 -2
  10. package/lib/cli-ux/list.js +3 -3
  11. package/lib/cli-ux/prompt.js +8 -3
  12. package/lib/cli-ux/stream.js +1 -0
  13. package/lib/cli-ux/styled/json.js +5 -3
  14. package/lib/cli-ux/styled/object.js +2 -2
  15. package/lib/cli-ux/styled/table.js +26 -20
  16. package/lib/cli-ux/styled/tree.js +1 -3
  17. package/lib/cli-ux/wait.js +1 -1
  18. package/lib/command.d.ts +6 -14
  19. package/lib/command.js +86 -73
  20. package/lib/config/config.d.ts +8 -9
  21. package/lib/config/config.js +85 -199
  22. package/lib/config/index.d.ts +0 -1
  23. package/lib/config/index.js +1 -3
  24. package/lib/config/plugin-loader.js +12 -11
  25. package/lib/config/plugin.d.ts +1 -0
  26. package/lib/config/plugin.js +54 -34
  27. package/lib/config/ts-node.js +17 -13
  28. package/lib/config/util.d.ts +0 -6
  29. package/lib/config/util.js +3 -15
  30. package/lib/errors/errors/cli.js +4 -1
  31. package/lib/errors/errors/exit.js +1 -1
  32. package/lib/errors/errors/module-load.js +1 -1
  33. package/lib/errors/errors/pretty-print.js +2 -1
  34. package/lib/errors/handle.js +4 -3
  35. package/lib/errors/logger.js +5 -4
  36. package/lib/flags.d.ts +6 -6
  37. package/lib/flags.js +3 -3
  38. package/lib/help/command.js +46 -32
  39. package/lib/help/docopts.js +8 -5
  40. package/lib/help/formatter.js +19 -8
  41. package/lib/help/index.d.ts +5 -1
  42. package/lib/help/index.js +70 -49
  43. package/lib/help/root.js +7 -9
  44. package/lib/help/util.d.ts +1 -7
  45. package/lib/help/util.js +2 -22
  46. package/lib/index.d.ts +2 -2
  47. package/lib/index.js +2 -3
  48. package/lib/interfaces/hooks.d.ts +3 -3
  49. package/lib/interfaces/index.d.ts +1 -1
  50. package/lib/interfaces/parser.d.ts +19 -18
  51. package/lib/interfaces/pjson.d.ts +1 -1
  52. package/lib/interfaces/plugin.d.ts +5 -0
  53. package/lib/module-loader.d.ts +8 -8
  54. package/lib/module-loader.js +13 -10
  55. package/lib/parser/errors.d.ts +1 -1
  56. package/lib/parser/errors.js +15 -9
  57. package/lib/parser/help.js +2 -3
  58. package/lib/parser/parse.js +72 -44
  59. package/lib/parser/validate.js +37 -21
  60. package/lib/performance.js +20 -9
  61. package/lib/util/aggregate-flags.d.ts +2 -0
  62. package/lib/util/aggregate-flags.js +13 -0
  63. package/lib/util/cache-command.d.ts +3 -0
  64. package/lib/util/cache-command.js +108 -0
  65. package/lib/util/cache-default-value.d.ts +2 -0
  66. package/lib/util/cache-default-value.js +28 -0
  67. package/lib/{util.d.ts → util/index.d.ts} +7 -2
  68. package/lib/{util.js → util/index.js} +15 -20
  69. package/package.json +19 -13
@@ -3,23 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Plugin = void 0;
4
4
  const errors_1 = require("../errors");
5
5
  const util_1 = require("./util");
6
- const util_2 = require("../util");
6
+ const index_1 = require("../util/index");
7
7
  const node_path_1 = require("node:path");
8
8
  const module_loader_1 = require("../module-loader");
9
9
  const performance_1 = require("../performance");
10
+ const cache_command_1 = require("../util/cache-command");
10
11
  const node_util_1 = require("node:util");
11
12
  const globby_1 = require("globby");
12
- const config_1 = require("./config");
13
13
  const ts_node_1 = require("./ts-node");
14
- const _pjson = (0, util_2.requireJson)(__dirname, '..', '..', 'package.json');
14
+ const _pjson = (0, index_1.requireJson)(__dirname, '..', '..', 'package.json');
15
15
  function topicsToArray(input, base) {
16
16
  if (!input)
17
17
  return [];
18
18
  base = base ? `${base}:` : '';
19
19
  if (Array.isArray(input)) {
20
- return [...input, ...(0, util_1.flatMap)(input, t => topicsToArray(t.subtopics, `${base}${t.name}`))];
20
+ return [...input, input.flatMap((t) => topicsToArray(t.subtopics, `${base}${t.name}`))];
21
21
  }
22
- return (0, util_1.flatMap)(Object.keys(input), k => {
22
+ return Object.keys(input).flatMap((k) => {
23
23
  input[k].name = k;
24
24
  return [{ ...input[k], name: `${base}${k}` }, ...topicsToArray(input[k].subtopics, `${base}${input[k].name}`)];
25
25
  });
@@ -36,7 +36,7 @@ async function findSourcesRoot(root) {
36
36
  for (const next of up(root)) {
37
37
  const cur = (0, node_path_1.join)(next, 'package.json');
38
38
  // eslint-disable-next-line no-await-in-loop
39
- if (await (0, util_2.exists)(cur))
39
+ if (await (0, index_1.exists)(cur))
40
40
  return (0, node_path_1.dirname)(cur);
41
41
  }
42
42
  }
@@ -57,11 +57,11 @@ async function findRootLegacy(name, root) {
57
57
  if (name) {
58
58
  cur = (0, node_path_1.join)(next, 'node_modules', name, 'package.json');
59
59
  // eslint-disable-next-line no-await-in-loop
60
- if (await (0, util_2.exists)(cur))
60
+ if (await (0, index_1.exists)(cur))
61
61
  return (0, node_path_1.dirname)(cur);
62
62
  try {
63
63
  // eslint-disable-next-line no-await-in-loop
64
- const pkg = await (0, util_2.readJson)((0, node_path_1.join)(next, 'package.json'));
64
+ const pkg = await (0, index_1.readJson)((0, node_path_1.join)(next, 'package.json'));
65
65
  if (pkg.name === name)
66
66
  return next;
67
67
  }
@@ -70,7 +70,7 @@ async function findRootLegacy(name, root) {
70
70
  else {
71
71
  cur = (0, node_path_1.join)(next, 'package.json');
72
72
  // eslint-disable-next-line no-await-in-loop
73
- if (await (0, util_2.exists)(cur))
73
+ if (await (0, index_1.exists)(cur))
74
74
  return (0, node_path_1.dirname)(cur);
75
75
  }
76
76
  }
@@ -86,7 +86,7 @@ async function findRoot(name, root) {
86
86
  }
87
87
  return findSourcesRoot(root);
88
88
  }
89
- const cachedCommandCanBeUsed = (manifest, id) => Boolean(manifest?.commands[id] && ('isESM' in manifest.commands[id] && 'relativePath' in manifest.commands[id]));
89
+ const cachedCommandCanBeUsed = (manifest, id) => Boolean(manifest?.commands[id] && 'isESM' in manifest.commands[id] && 'relativePath' in manifest.commands[id]);
90
90
  const search = (cmd) => {
91
91
  if (typeof cmd.run === 'function')
92
92
  return cmd;
@@ -95,20 +95,37 @@ const search = (cmd) => {
95
95
  return Object.values(cmd).find((cmd) => typeof cmd.run === 'function');
96
96
  };
97
97
  class Plugin {
98
+ options;
99
+ _base = `${_pjson.name}@${_pjson.version}`;
100
+ name;
101
+ version;
102
+ pjson;
103
+ type;
104
+ moduleType;
105
+ root;
106
+ alias;
107
+ tag;
108
+ manifest;
109
+ commands;
110
+ hooks;
111
+ valid = false;
112
+ alreadyLoaded = false;
113
+ parent;
114
+ children = [];
115
+ hasManifest = false;
116
+ isRoot = false;
117
+ _commandsDir;
118
+ flexibleTaxonomy;
119
+ // eslint-disable-next-line new-cap
120
+ _debug = (0, util_1.Debug)();
121
+ warned = false;
98
122
  constructor(options) {
99
123
  this.options = options;
100
- this._base = `${_pjson.name}@${_pjson.version}`;
101
- this.valid = false;
102
- this.alreadyLoaded = false;
103
- this.children = [];
104
- this.hasManifest = false;
105
- // eslint-disable-next-line new-cap
106
- this._debug = (0, util_1.Debug)();
107
- this.warned = false;
108
124
  }
109
125
  async load() {
110
126
  this.type = this.options.type || 'core';
111
127
  this.tag = this.options.tag;
128
+ this.isRoot = this.options.isRoot ?? false;
112
129
  if (this.options.parent)
113
130
  this.parent = this.options.parent;
114
131
  // Linked plugins already have a root so there's no need to search for it.
@@ -119,7 +136,7 @@ class Plugin {
119
136
  throw new errors_1.CLIError(`could not find package.json with ${(0, node_util_1.inspect)(this.options)}`);
120
137
  this.root = root;
121
138
  this._debug('reading %s plugin %s', this.type, root);
122
- this.pjson = await (0, util_2.readJson)((0, node_path_1.join)(root, 'package.json'));
139
+ this.pjson = await (0, index_1.readJson)((0, node_path_1.join)(root, 'package.json'));
123
140
  this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
124
141
  this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
125
142
  this.name = this.pjson.name;
@@ -127,7 +144,7 @@ class Plugin {
127
144
  const pjsonPath = (0, node_path_1.join)(root, 'package.json');
128
145
  if (!this.name)
129
146
  throw new errors_1.CLIError(`no name in ${pjsonPath}`);
130
- if (!(0, util_2.isProd)() && !this.pjson.files)
147
+ if (!(0, index_1.isProd)() && !this.pjson.files)
131
148
  this.warn(`files attribute must be specified in ${pjsonPath}`);
132
149
  // eslint-disable-next-line new-cap
133
150
  this._debug = (0, util_1.Debug)(this.name);
@@ -138,10 +155,9 @@ class Plugin {
138
155
  else {
139
156
  this.pjson.oclif = this.pjson['cli-engine'] || {};
140
157
  }
141
- this.hooks = (0, util_1.mapValues)(this.pjson.oclif.hooks || {}, i => Array.isArray(i) ? i : [i]);
158
+ this.hooks = (0, index_1.mapValues)(this.pjson.oclif.hooks || {}, (i) => (Array.isArray(i) ? i : [i]));
142
159
  this.manifest = await this._manifest();
143
- this.commands = Object
144
- .entries(this.manifest.commands)
160
+ this.commands = Object.entries(this.manifest.commands)
145
161
  .map(([id, c]) => ({
146
162
  ...c,
147
163
  pluginAlias: this.alias,
@@ -164,12 +180,8 @@ class Plugin {
164
180
  return [];
165
181
  const marker = performance_1.Performance.mark(`plugin.commandIDs#${this.name}`, { plugin: this.name });
166
182
  this._debug(`loading IDs from ${this.commandsDir}`);
167
- const patterns = [
168
- '**/*.+(js|cjs|mjs|ts|tsx)',
169
- '!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js)?(x)',
170
- ];
171
- const ids = (0, globby_1.sync)(patterns, { cwd: this.commandsDir })
172
- .map(file => {
183
+ const patterns = ['**/*.+(js|cjs|mjs|ts|tsx)', '!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js)?(x)'];
184
+ const ids = (0, globby_1.sync)(patterns, { cwd: this.commandsDir }).map((file) => {
173
185
  const p = (0, node_path_1.parse)(file);
174
186
  const topics = p.dir.split('/');
175
187
  const command = p.name !== 'index' && p.name;
@@ -190,6 +202,7 @@ class Plugin {
190
202
  let isESM;
191
203
  let filePath;
192
204
  try {
205
+ ;
193
206
  ({ isESM, module, filePath } = cachedCommandCanBeUsed(this.manifest, id)
194
207
  ? await (0, module_loader_1.loadWithDataFromManifest)(this.manifest.commands[id], this.root)
195
208
  : await (0, module_loader_1.loadWithData)(this, (0, node_path_1.join)(this.commandsDir ?? this.pjson.oclif.commands, ...id.split(':'))));
@@ -222,7 +235,7 @@ class Plugin {
222
235
  const readManifest = async (dotfile = false) => {
223
236
  try {
224
237
  const p = (0, node_path_1.join)(this.root, `${dotfile ? '.' : ''}oclif.manifest.json`);
225
- const manifest = await (0, util_2.readJson)(p);
238
+ const manifest = await (0, index_1.readJson)(p);
226
239
  if (!process.env.OCLIF_NEXT_VERSION && manifest.version.split('-')[0] !== this.version.split('-')[0]) {
227
240
  process.emitWarning(`Mismatched version in ${this.name} plugin manifest. Expected: ${this.version} Received: ${manifest.version}\nThis usually means you have an oclif.manifest.json file that should be deleted in development. This file should be automatically generated when publishing.`);
228
241
  }
@@ -255,16 +268,16 @@ class Plugin {
255
268
  version: this.version,
256
269
  commands: (await Promise.all(this.commandIDs.map(async (id) => {
257
270
  try {
258
- const cached = await (0, config_1.toCached)(await this.findCommand(id, { must: true }), this, respectNoCacheDefault);
271
+ const cached = await (0, cache_command_1.cacheCommand)(await this.findCommand(id, { must: true }), this, respectNoCacheDefault);
259
272
  if (this.flexibleTaxonomy) {
260
273
  const permutations = (0, util_1.getCommandIdPermutations)(id);
261
- const aliasPermutations = cached.aliases.flatMap(a => (0, util_1.getCommandIdPermutations)(a));
274
+ const aliasPermutations = cached.aliases.flatMap((a) => (0, util_1.getCommandIdPermutations)(a));
262
275
  return [id, { ...cached, permutations, aliasPermutations }];
263
276
  }
264
277
  return [id, cached];
265
278
  }
266
279
  catch (error) {
267
- const scope = 'toCached';
280
+ const scope = 'cacheCommand';
268
281
  if (Boolean(errorOnManifestCreate) === false)
269
282
  this.warn(error, scope);
270
283
  else
@@ -291,7 +304,14 @@ class Plugin {
291
304
  }
292
305
  addErrorScope(err, scope) {
293
306
  err.name = `${err.name} Plugin: ${this.name}`;
294
- err.detail = (0, util_2.compact)([err.detail, `module: ${this._base}`, scope && `task: ${scope}`, `plugin: ${this.name}`, `root: ${this.root}`, 'See more details with DEBUG=*']).join('\n');
307
+ err.detail = (0, index_1.compact)([
308
+ err.detail,
309
+ `module: ${this._base}`,
310
+ scope && `task: ${scope}`,
311
+ `plugin: ${this.name}`,
312
+ `root: ${this.root}`,
313
+ 'See more details with DEBUG=*',
314
+ ]).join('\n');
295
315
  return err;
296
316
  }
297
317
  }
@@ -1,17 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsPath = exports.TS_CONFIGS = void 0;
4
- const util_1 = require("../util");
4
+ const index_1 = require("../util/index");
5
5
  const node_path_1 = require("node:path");
6
- const config_1 = require("./config");
7
- const util_2 = require("./util");
6
+ const util_1 = require("./util");
8
7
  const node_fs_1 = require("node:fs");
9
8
  const errors_1 = require("../errors");
10
9
  const settings_1 = require("../settings");
11
10
  // eslint-disable-next-line new-cap
12
- const debug = (0, util_2.Debug)('ts-node');
11
+ const debug = (0, util_1.Debug)('ts-node');
13
12
  exports.TS_CONFIGS = {};
14
13
  const REGISTERED = new Set();
14
+ /**
15
+ * Cache the root plugin so that we can reference it later when determining if
16
+ * we should skip ts-node registration for an ESM plugin.
17
+ */
18
+ let ROOT_PLUGIN;
15
19
  function loadTSConfig(root) {
16
20
  if (exports.TS_CONFIGS[root])
17
21
  return exports.TS_CONFIGS[root];
@@ -31,10 +35,10 @@ function loadTSConfig(root) {
31
35
  }
32
36
  }
33
37
  if ((0, node_fs_1.existsSync)(tsconfigPath) && typescript) {
34
- const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0, util_1.readJsonSync)(tsconfigPath, false)).config;
38
+ const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0, index_1.readJsonSync)(tsconfigPath, false)).config;
35
39
  if (!tsconfig || !tsconfig.compilerOptions) {
36
- throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it `
37
- + 'did not contain a "compilerOptions" section.');
40
+ throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it ` +
41
+ 'did not contain a "compilerOptions" section.');
38
42
  }
39
43
  exports.TS_CONFIGS[root] = tsconfig;
40
44
  return tsconfig;
@@ -58,9 +62,7 @@ function registerTSNode(root) {
58
62
  (0, errors_1.memoizedWarn)(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`);
59
63
  return;
60
64
  }
61
- const typeRoots = [
62
- (0, node_path_1.join)(root, 'node_modules', '@types'),
63
- ];
65
+ const typeRoots = [(0, node_path_1.join)(root, 'node_modules', '@types')];
64
66
  const rootDirs = [];
65
67
  if (tsconfig.compilerOptions.rootDirs) {
66
68
  for (const r of tsconfig.compilerOptions.rootDirs) {
@@ -105,6 +107,8 @@ function registerTSNode(root) {
105
107
  return tsconfig;
106
108
  }
107
109
  function tsPath(root, orig, plugin) {
110
+ if (plugin?.isRoot)
111
+ ROOT_PLUGIN = plugin;
108
112
  if (!orig)
109
113
  return orig;
110
114
  orig = orig.startsWith(root) ? orig : (0, node_path_1.join)(root, orig);
@@ -113,7 +117,7 @@ function tsPath(root, orig, plugin) {
113
117
  debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
114
118
  return orig;
115
119
  }
116
- const isProduction = (0, util_1.isProd)();
120
+ const isProduction = (0, index_1.isProd)();
117
121
  /**
118
122
  * Skip ts-node registration for ESM plugins.
119
123
  * The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
@@ -126,8 +130,8 @@ function tsPath(root, orig, plugin) {
126
130
  * We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM.
127
131
  * In other words, this allows plugins to be auto-transpiled when developing locally using `bin/dev.js`.
128
132
  */
129
- if ((isProduction || config_1.Config.rootPlugin?.moduleType === 'commonjs') && plugin?.moduleType === 'module') {
130
- debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${config_1.Config.rootPlugin?.moduleType})))`);
133
+ if ((isProduction || ROOT_PLUGIN?.moduleType === 'commonjs') && plugin?.moduleType === 'module') {
134
+ debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${ROOT_PLUGIN?.moduleType})))`);
131
135
  if (plugin.type === 'link')
132
136
  (0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
133
137
  return orig;
@@ -1,9 +1,3 @@
1
- export declare function flatMap<T, U>(arr: T[], fn: (i: T) => U[]): U[];
2
- export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
3
- [P in keyof T]: T[P];
4
- }, fn: (i: T[keyof T], k: keyof T) => TResult): {
5
- [P in keyof T]: TResult;
6
- };
7
1
  export declare function resolvePackage(id: string, paths: {
8
2
  paths: string[];
9
3
  }): string;
@@ -1,19 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.resolvePackage = exports.mapValues = exports.flatMap = void 0;
3
+ exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.resolvePackage = void 0;
4
4
  const debug = require('debug');
5
- function flatMap(arr, fn) {
6
- return arr.reduce((arr, i) => [...arr, ...fn(i)], []);
7
- }
8
- exports.flatMap = flatMap;
9
- function mapValues(obj, fn) {
10
- return Object.entries(obj)
11
- .reduce((o, [k, v]) => {
12
- o[k] = fn(v, k);
13
- return o;
14
- }, {});
15
- }
16
- exports.mapValues = mapValues;
17
5
  function resolvePackage(id, paths) {
18
6
  return require.resolve(id, paths);
19
7
  }
@@ -60,7 +48,7 @@ function getPermutations(arr) {
60
48
  }
61
49
  exports.getPermutations = getPermutations;
62
50
  function getCommandIdPermutations(commandId) {
63
- return getPermutations(commandId.split(':')).flatMap(c => c.join(':'));
51
+ return getPermutations(commandId.split(':')).flatMap((c) => c.join(':'));
64
52
  }
65
53
  exports.getCommandIdPermutations = getCommandIdPermutations;
66
54
  /**
@@ -82,5 +70,5 @@ exports.getCommandIdPermutations = getCommandIdPermutations;
82
70
  * @param commandIds string[]
83
71
  * @returns string[]
84
72
  */
85
- const collectUsableIds = (commandIds) => new Set(commandIds.flatMap(id => id.split(':').map((_, i, a) => a.slice(0, i + 1).join(':'))));
73
+ const collectUsableIds = (commandIds) => new Set(commandIds.flatMap((id) => id.split(':').map((_, i, a) => a.slice(0, i + 1).join(':'))));
86
74
  exports.collectUsableIds = collectUsableIds;
@@ -13,6 +13,7 @@ const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
13
13
  */
14
14
  function addOclifExitCode(error, options) {
15
15
  if (!('oclif' in error)) {
16
+ ;
16
17
  error.oclif = {};
17
18
  }
18
19
  error.oclif.exit = options?.exit === undefined ? 2 : options.exit;
@@ -20,9 +21,11 @@ function addOclifExitCode(error, options) {
20
21
  }
21
22
  exports.addOclifExitCode = addOclifExitCode;
22
23
  class CLIError extends Error {
24
+ oclif = {};
25
+ code;
26
+ suggestions;
23
27
  constructor(error, options = {}) {
24
28
  super(error instanceof Error ? error.message : error);
25
- this.oclif = {};
26
29
  addOclifExitCode(this, options);
27
30
  this.code = options.code;
28
31
  this.suggestions = options.suggestions;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExitError = void 0;
4
4
  const cli_1 = require("./cli");
5
5
  class ExitError extends cli_1.CLIError {
6
+ code = 'EEXIT';
6
7
  constructor(exitCode = 1) {
7
8
  super(`EEXIT: ${exitCode}`, { exit: exitCode });
8
- this.code = 'EEXIT';
9
9
  }
10
10
  render() {
11
11
  return '';
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModuleLoadError = void 0;
4
4
  const cli_1 = require("./cli");
5
5
  class ModuleLoadError extends cli_1.CLIError {
6
+ code = 'MODULE_NOT_FOUND';
6
7
  constructor(message) {
7
8
  super(`[MODULE_NOT_FOUND] ${message}`, { exit: 1 });
8
- this.code = 'MODULE_NOT_FOUND';
9
9
  this.name = 'ModuleLoadError';
10
10
  }
11
11
  }
@@ -11,6 +11,7 @@ function applyPrettyPrintOptions(error, options) {
11
11
  for (const key of prettyErrorKeys) {
12
12
  const applyOptionsKey = !(key in error) && options[key];
13
13
  if (applyOptionsKey) {
14
+ ;
14
15
  error[key] = options[key];
15
16
  }
16
17
  }
@@ -23,7 +24,7 @@ const formatSuggestions = (suggestions) => {
23
24
  return undefined;
24
25
  if (suggestions.length === 1)
25
26
  return `${label} ${suggestions[0]}`;
26
- const multiple = suggestions.map(suggestion => `* ${suggestion}`).join('\n');
27
+ const multiple = suggestions.map((suggestion) => `* ${suggestion}`).join('\n');
27
28
  return `${label}\n${(0, indent_string_1.default)(multiple, 2)}`;
28
29
  };
29
30
  function prettyPrint(error) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handle = exports.Exit = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cli_1 = require("./errors/cli");
6
- const _1 = require(".");
6
+ const exit_1 = require("./errors/exit");
7
7
  const clean_stack_1 = tslib_1.__importDefault(require("clean-stack"));
8
8
  const config_1 = require("./config");
9
9
  const pretty_print_1 = tslib_1.__importDefault(require("./errors/pretty-print"));
@@ -23,7 +23,7 @@ async function handle(err) {
23
23
  err = new cli_1.CLIError('no error?');
24
24
  if (err.message === 'SIGINT')
25
25
  exports.Exit.exit(1);
26
- const shouldPrint = !(err instanceof _1.ExitError) && !err.skipOclifErrorHandling;
26
+ const shouldPrint = !(err instanceof exit_1.ExitError) && !err.skipOclifErrorHandling;
27
27
  const pretty = (0, pretty_print_1.default)(err);
28
28
  const stack = (0, clean_stack_1.default)(err.stack || '', { pretty: true });
29
29
  if (shouldPrint) {
@@ -34,7 +34,8 @@ async function handle(err) {
34
34
  if (stack) {
35
35
  config_1.config.errorLogger.log(stack);
36
36
  }
37
- await config_1.config.errorLogger.flush()
37
+ await config_1.config.errorLogger
38
+ .flush()
38
39
  .then(() => exports.Exit.exit(exitCode))
39
40
  .catch(console.error);
40
41
  }
@@ -6,7 +6,7 @@ const node_path_1 = require("node:path");
6
6
  const stripAnsi = require("strip-ansi");
7
7
  const timestamp = () => new Date().toISOString();
8
8
  let timer;
9
- const wait = (ms) => new Promise(resolve => {
9
+ const wait = (ms) => new Promise((resolve) => {
10
10
  if (timer)
11
11
  timer.unref();
12
12
  timer = setTimeout(() => resolve(null), ms);
@@ -17,14 +17,15 @@ function chomp(s) {
17
17
  return s;
18
18
  }
19
19
  class Logger {
20
+ file;
21
+ flushing = Promise.resolve();
22
+ buffer = [];
20
23
  constructor(file) {
21
24
  this.file = file;
22
- this.flushing = Promise.resolve();
23
- this.buffer = [];
24
25
  }
25
26
  log(msg) {
26
27
  msg = stripAnsi(chomp(msg));
27
- const lines = msg.split('\n').map(l => `${timestamp()} ${l}`.trimEnd());
28
+ const lines = msg.split('\n').map((l) => `${timestamp()} ${l}`.trimEnd());
28
29
  this.buffer.push(...lines);
29
30
  this.flush(50).catch(console.error);
30
31
  }
package/lib/flags.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare function custom<T = string, P extends CustomOptions = CustomOptio
12
12
  multiple: true;
13
13
  requiredOrDefaulted: true;
14
14
  }>;
15
- export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T, P>> & {
15
+ export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<NotArray<T>, P>> & {
16
16
  multiple?: false | undefined;
17
17
  } & ({
18
18
  required: true;
@@ -22,7 +22,7 @@ export declare function custom<T = string, P extends CustomOptions = CustomOptio
22
22
  multiple: false;
23
23
  requiredOrDefaulted: true;
24
24
  }>;
25
- export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T, P>> & {
25
+ export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<NotArray<T>, P>> & {
26
26
  default?: OptionFlag<NotArray<T>, P>['default'] | undefined;
27
27
  multiple?: false | undefined;
28
28
  required?: false | undefined;
@@ -84,7 +84,7 @@ export declare function option<T extends readonly string[], P extends CustomOpti
84
84
  required: true;
85
85
  } | {
86
86
  default: OptionFlag<ElementType<T>[], P>['default'] | undefined;
87
- })): FlagDefinition<typeof defaults.options[number], P, {
87
+ })): FlagDefinition<(typeof defaults.options)[number], P, {
88
88
  multiple: true;
89
89
  requiredOrDefaulted: true;
90
90
  }>;
@@ -95,7 +95,7 @@ export declare function option<T extends readonly string[], P extends CustomOpti
95
95
  required: true;
96
96
  } | {
97
97
  default: OptionFlag<ElementType<T>, P>['default'];
98
- })): FlagDefinition<typeof defaults.options[number], P, {
98
+ })): FlagDefinition<(typeof defaults.options)[number], P, {
99
99
  multiple: false;
100
100
  requiredOrDefaulted: true;
101
101
  }>;
@@ -104,7 +104,7 @@ export declare function option<T extends readonly string[], P extends CustomOpti
104
104
  default?: OptionFlag<ElementType<T>, P>['default'] | undefined;
105
105
  multiple?: false | undefined;
106
106
  required?: false | undefined;
107
- }): FlagDefinition<typeof defaults.options[number], P, {
107
+ }): FlagDefinition<(typeof defaults.options)[number], P, {
108
108
  multiple: false;
109
109
  requiredOrDefaulted: false;
110
110
  }>;
@@ -113,7 +113,7 @@ export declare function option<T extends readonly string[], P extends CustomOpti
113
113
  multiple: true;
114
114
  default?: OptionFlag<ElementType<T>[], P>['default'] | undefined;
115
115
  required?: false | undefined;
116
- }): FlagDefinition<typeof defaults.options[number], P, {
116
+ }): FlagDefinition<(typeof defaults.options)[number], P, {
117
117
  multiple: true;
118
118
  requiredOrDefaulted: false;
119
119
  }>;
package/lib/flags.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.option = exports.help = exports.version = exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
4
- const util_1 = require("./util");
4
+ const index_1 = require("./util/index");
5
5
  const errors_1 = require("./errors");
6
6
  const node_url_1 = require("node:url");
7
7
  const help_1 = require("./help");
@@ -57,14 +57,14 @@ exports.integer = custom({
57
57
  exports.directory = custom({
58
58
  async parse(input, _, opts) {
59
59
  if (opts.exists)
60
- return (0, util_1.dirExists)(input);
60
+ return (0, index_1.dirExists)(input);
61
61
  return input;
62
62
  },
63
63
  });
64
64
  exports.file = custom({
65
65
  async parse(input, _, opts) {
66
66
  if (opts.exists)
67
- return (0, util_1.fileExists)(input);
67
+ return (0, index_1.fileExists)(input);
68
68
  return input;
69
69
  },
70
70
  });