@oclif/core 3.0.0-beta.13 → 3.0.0-beta.15

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 (77) hide show
  1. package/README.md +3 -1
  2. package/lib/args.d.ts +1 -1
  3. package/lib/args.js +13 -15
  4. package/lib/cli-ux/action/base.d.ts +1 -1
  5. package/lib/cli-ux/action/base.js +20 -15
  6. package/lib/cli-ux/action/simple.js +10 -8
  7. package/lib/cli-ux/action/spinner.js +11 -10
  8. package/lib/cli-ux/config.js +8 -7
  9. package/lib/cli-ux/flush.js +2 -3
  10. package/lib/cli-ux/index.d.ts +10 -28
  11. package/lib/cli-ux/index.js +26 -45
  12. package/lib/cli-ux/list.js +1 -1
  13. package/lib/cli-ux/prompt.js +24 -19
  14. package/lib/cli-ux/styled/index.d.ts +5 -6
  15. package/lib/cli-ux/styled/index.js +11 -11
  16. package/lib/cli-ux/styled/json.js +3 -2
  17. package/lib/cli-ux/styled/object.js +6 -8
  18. package/lib/cli-ux/styled/table.d.ts +4 -4
  19. package/lib/cli-ux/styled/table.js +36 -45
  20. package/lib/cli-ux/wait.js +3 -5
  21. package/lib/command.d.ts +7 -5
  22. package/lib/command.js +35 -28
  23. package/lib/config/config.d.ts +2 -2
  24. package/lib/config/config.js +57 -43
  25. package/lib/config/plugin-loader.js +25 -11
  26. package/lib/config/plugin.d.ts +1 -1
  27. package/lib/config/plugin.js +66 -56
  28. package/lib/config/ts-node.d.ts +2 -1
  29. package/lib/config/ts-node.js +41 -34
  30. package/lib/config/util.d.ts +1 -5
  31. package/lib/config/util.js +5 -46
  32. package/lib/errors/config.js +1 -1
  33. package/lib/errors/errors/cli.d.ts +1 -1
  34. package/lib/errors/errors/cli.js +14 -13
  35. package/lib/errors/errors/exit.d.ts +0 -3
  36. package/lib/errors/errors/module-load.d.ts +0 -3
  37. package/lib/errors/errors/pretty-print.js +9 -8
  38. package/lib/errors/handle.d.ts +12 -2
  39. package/lib/errors/handle.js +23 -14
  40. package/lib/errors/index.d.ts +2 -2
  41. package/lib/errors/index.js +20 -19
  42. package/lib/errors/logger.js +4 -4
  43. package/lib/execute.d.ts +5 -5
  44. package/lib/execute.js +6 -5
  45. package/lib/flags.d.ts +102 -31
  46. package/lib/flags.js +75 -42
  47. package/lib/help/command.d.ts +2 -0
  48. package/lib/help/command.js +32 -32
  49. package/lib/help/docopts.js +2 -9
  50. package/lib/help/formatter.d.ts +1 -1
  51. package/lib/help/formatter.js +17 -17
  52. package/lib/help/index.d.ts +2 -2
  53. package/lib/help/index.js +22 -21
  54. package/lib/help/root.js +2 -2
  55. package/lib/help/util.d.ts +1 -1
  56. package/lib/help/util.js +9 -9
  57. package/lib/index.d.ts +19 -20
  58. package/lib/index.js +38 -42
  59. package/lib/interfaces/config.d.ts +5 -4
  60. package/lib/interfaces/errors.d.ts +1 -1
  61. package/lib/interfaces/parser.d.ts +168 -45
  62. package/lib/interfaces/plugin.d.ts +1 -0
  63. package/lib/main.d.ts +1 -1
  64. package/lib/main.js +16 -16
  65. package/lib/module-loader.d.ts +67 -77
  66. package/lib/module-loader.js +179 -149
  67. package/lib/parser/errors.d.ts +2 -2
  68. package/lib/parser/errors.js +4 -3
  69. package/lib/parser/help.js +3 -2
  70. package/lib/parser/parse.d.ts +3 -0
  71. package/lib/parser/parse.js +56 -52
  72. package/lib/parser/validate.js +9 -5
  73. package/lib/performance.d.ts +6 -2
  74. package/lib/performance.js +23 -12
  75. package/lib/util.d.ts +25 -1
  76. package/lib/util.js +93 -29
  77. package/package.json +10 -15
@@ -1,4 +1,5 @@
1
- import { Plugin } from '../interfaces';
1
+ import { Plugin, TSConfig } from '../interfaces';
2
+ export declare const TS_CONFIGS: Record<string, TSConfig>;
2
3
  /**
3
4
  * Convert a path from the compiled ./lib files to the ./src typescript source
4
5
  * this is for developing typescript plugins/CLIs
@@ -1,37 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tsPath = void 0;
4
- const fs = require("fs");
5
- const path = require("path");
6
- const settings_1 = require("../settings");
3
+ exports.tsPath = exports.TS_CONFIGS = void 0;
7
4
  const util_1 = require("../util");
5
+ const node_path_1 = require("node:path");
6
+ const config_1 = require("./config");
8
7
  const util_2 = require("./util");
8
+ const node_fs_1 = require("node:fs");
9
9
  const errors_1 = require("../errors");
10
+ const settings_1 = require("../settings");
10
11
  // eslint-disable-next-line new-cap
11
12
  const debug = (0, util_2.Debug)('ts-node');
12
- const TS_CONFIGS = {};
13
+ exports.TS_CONFIGS = {};
13
14
  const REGISTERED = new Set();
14
15
  function loadTSConfig(root) {
15
- if (TS_CONFIGS[root])
16
- return TS_CONFIGS[root];
17
- const tsconfigPath = path.join(root, 'tsconfig.json');
16
+ if (exports.TS_CONFIGS[root])
17
+ return exports.TS_CONFIGS[root];
18
+ const tsconfigPath = (0, node_path_1.join)(root, 'tsconfig.json');
18
19
  let typescript;
19
20
  try {
20
21
  typescript = require('typescript');
21
22
  }
22
23
  catch {
23
24
  try {
24
- typescript = require(path.join(root, 'node_modules', 'typescript'));
25
+ typescript = require((0, node_path_1.join)(root, 'node_modules', 'typescript'));
25
26
  }
26
27
  catch { }
27
28
  }
28
- if (fs.existsSync(tsconfigPath) && typescript) {
29
- const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, 'utf8')).config;
29
+ if ((0, node_fs_1.existsSync)(tsconfigPath) && typescript) {
30
+ const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0, util_1.readJsonSync)(tsconfigPath, false)).config;
30
31
  if (!tsconfig || !tsconfig.compilerOptions) {
31
- throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it ` +
32
- 'did not contain a "compilerOptions" section.');
32
+ throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it `
33
+ + 'did not contain a "compilerOptions" section.');
33
34
  }
34
- TS_CONFIGS[root] = tsconfig;
35
+ exports.TS_CONFIGS[root] = tsconfig;
35
36
  return tsconfig;
36
37
  }
37
38
  }
@@ -46,19 +47,19 @@ function registerTSNode(root) {
46
47
  debug('ts-node path:', tsNodePath);
47
48
  const tsNode = require(tsNodePath);
48
49
  const typeRoots = [
49
- path.join(root, 'node_modules', '@types'),
50
+ (0, node_path_1.join)(root, 'node_modules', '@types'),
50
51
  ];
51
52
  const rootDirs = [];
52
53
  if (tsconfig.compilerOptions.rootDirs) {
53
54
  for (const r of tsconfig.compilerOptions.rootDirs) {
54
- rootDirs.push(path.join(root, r));
55
+ rootDirs.push((0, node_path_1.join)(root, r));
55
56
  }
56
57
  }
57
58
  else if (tsconfig.compilerOptions.rootDir) {
58
- rootDirs.push(path.join(root, tsconfig.compilerOptions.rootDir));
59
+ rootDirs.push((0, node_path_1.join)(root, tsconfig.compilerOptions.rootDir));
59
60
  }
60
61
  else {
61
- rootDirs.push(path.join(root, 'src'));
62
+ rootDirs.push((0, node_path_1.join)(root, 'src'));
62
63
  }
63
64
  const conf = {
64
65
  compilerOptions: {
@@ -94,26 +95,32 @@ function registerTSNode(root) {
94
95
  function tsPath(root, orig, plugin) {
95
96
  if (!orig)
96
97
  return orig;
97
- orig = orig.startsWith(root) ? orig : path.join(root, orig);
98
+ orig = orig.startsWith(root) ? orig : (0, node_path_1.join)(root, orig);
98
99
  // NOTE: The order of these checks matter!
99
100
  if (settings_1.settings.tsnodeEnabled === false) {
100
101
  debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
101
102
  return orig;
102
103
  }
103
- // Skip ts-node registration for ESM plugins.
104
- // The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
105
- // See the following:
106
- // - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228
107
- // - https://github.com/nodejs/node/issues/49432
108
- // - https://github.com/nodejs/node/pull/49407
109
- // - https://github.com/nodejs/node/issues/34049
110
- if (plugin?.moduleType === 'module') {
111
- debug(`Skipping ts-node registration for ${root} because it's an ESM module`);
104
+ const isProduction = (0, util_1.isProd)();
105
+ /**
106
+ * Skip ts-node registration for ESM plugins.
107
+ * The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
108
+ * See the following:
109
+ * - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228
110
+ * - https://github.com/nodejs/node/issues/49432
111
+ * - https://github.com/nodejs/node/pull/49407
112
+ * - https://github.com/nodejs/node/issues/34049
113
+ *
114
+ * We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM.
115
+ * In other words, this allows plugins to be auto-transpiled when developing locally using `bin/dev.js`.
116
+ */
117
+ if ((isProduction || config_1.Config.rootPlugin?.moduleType === 'commonjs') && plugin?.moduleType === 'module') {
118
+ 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})))`);
112
119
  if (plugin.type === 'link')
113
120
  (0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
114
121
  return orig;
115
122
  }
116
- if (settings_1.settings.tsnodeEnabled === undefined && (0, util_1.isProd)() && plugin?.type !== 'link') {
123
+ if (settings_1.settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') {
117
124
  debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
118
125
  return orig;
119
126
  }
@@ -126,17 +133,17 @@ function tsPath(root, orig, plugin) {
126
133
  if (!rootDirPath || !outDir)
127
134
  return orig;
128
135
  // rewrite path from ./lib/foo to ./src/foo
129
- const lib = path.join(root, outDir); // ./lib
130
- const src = path.join(root, rootDirPath); // ./src
131
- const relative = path.relative(lib, orig); // ./commands
136
+ const lib = (0, node_path_1.join)(root, outDir); // ./lib
137
+ const src = (0, node_path_1.join)(root, rootDirPath); // ./src
138
+ const relative = (0, node_path_1.relative)(lib, orig); // ./commands
132
139
  // For hooks, it might point to a js file, not a module. Something like "./hooks/myhook.js" which doesn't need the js.
133
- const out = path.join(src, relative).replace(/\.js$/, ''); // ./src/commands
140
+ const out = (0, node_path_1.join)(src, relative).replace(/\.js$/, ''); // ./src/commands
134
141
  // this can be a directory of commands or point to a hook file
135
142
  // if it's a directory, we check if the path exists. If so, return the path to the directory.
136
143
  // For hooks, it might point to a module, not a file. Something like "./hooks/myhook"
137
144
  // That file doesn't exist, and the real file is "./hooks/myhook.ts"
138
145
  // In that case we attempt to resolve to the filename. If it fails it will revert back to the lib path
139
- if (fs.existsSync(out) || fs.existsSync(out + '.ts'))
146
+ if ((0, node_fs_1.existsSync)(out) || (0, node_fs_1.existsSync)(out + '.ts'))
140
147
  return out;
141
148
  return orig;
142
149
  }
@@ -4,13 +4,9 @@ export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
4
4
  }, fn: (i: T[keyof T], k: keyof T) => TResult): {
5
5
  [P in keyof T]: TResult;
6
6
  };
7
- export declare function exists(path: string): Promise<boolean>;
8
7
  export declare function resolvePackage(id: string, paths: {
9
8
  paths: string[];
10
9
  }): string;
11
- export declare function loadJSON(path: string): Promise<any>;
12
- export declare function compact<T>(a: (T | undefined)[]): T[];
13
- export declare function uniq<T>(arr: T[]): T[];
14
10
  export declare function Debug(...scope: string[]): (..._: any) => void;
15
11
  export declare function getPermutations(arr: string[]): Array<string[]>;
16
12
  export declare function getCommandIdPermutations(commandId: string): string[];
@@ -33,4 +29,4 @@ export declare function getCommandIdPermutations(commandId: string): string[];
33
29
  * @param commandIds string[]
34
30
  * @returns string[]
35
31
  */
36
- export declare function collectUsableIds(commandIds: string[]): Set<string>;
32
+ export declare const collectUsableIds: (commandIds: string[]) => Set<string>;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.uniq = exports.compact = exports.loadJSON = exports.resolvePackage = exports.exists = exports.mapValues = exports.flatMap = void 0;
4
- const fs = require("fs");
3
+ exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.resolvePackage = exports.mapValues = exports.flatMap = void 0;
5
4
  const debug = require('debug');
6
5
  function flatMap(arr, fn) {
7
6
  return arr.reduce((arr, i) => [...arr, ...fn(i)], []);
@@ -15,40 +14,10 @@ function mapValues(obj, fn) {
15
14
  }, {});
16
15
  }
17
16
  exports.mapValues = mapValues;
18
- function exists(path) {
19
- // eslint-disable-next-line no-promise-executor-return
20
- return new Promise(resolve => resolve(fs.existsSync(path)));
21
- }
22
- exports.exists = exists;
23
17
  function resolvePackage(id, paths) {
24
18
  return require.resolve(id, paths);
25
19
  }
26
20
  exports.resolvePackage = resolvePackage;
27
- function loadJSON(path) {
28
- debug('config')('loadJSON %s', path);
29
- return new Promise((resolve, reject) => {
30
- fs.readFile(path, 'utf8', (err, d) => {
31
- try {
32
- if (err)
33
- reject(err);
34
- else
35
- resolve(JSON.parse(d));
36
- }
37
- catch (error) {
38
- reject(error);
39
- }
40
- });
41
- });
42
- }
43
- exports.loadJSON = loadJSON;
44
- function compact(a) {
45
- return a.filter((a) => Boolean(a));
46
- }
47
- exports.compact = compact;
48
- function uniq(arr) {
49
- return [...new Set(arr)].sort();
50
- }
51
- exports.uniq = uniq;
52
21
  function displayWarnings() {
53
22
  if (process.listenerCount('warning') > 1)
54
23
  return;
@@ -60,7 +29,9 @@ function displayWarnings() {
60
29
  }
61
30
  function Debug(...scope) {
62
31
  if (!debug)
63
- return (..._) => { };
32
+ return (..._) => {
33
+ // noop
34
+ };
64
35
  const d = debug(['config', ...scope].join(':'));
65
36
  if (d.enabled)
66
37
  displayWarnings();
@@ -111,17 +82,5 @@ exports.getCommandIdPermutations = getCommandIdPermutations;
111
82
  * @param commandIds string[]
112
83
  * @returns string[]
113
84
  */
114
- function collectUsableIds(commandIds) {
115
- const usuableIds = [];
116
- for (const id of commandIds) {
117
- const parts = id.split(':');
118
- while (parts.length > 0) {
119
- const name = parts.join(':');
120
- if (name)
121
- usuableIds.push(name);
122
- parts.pop();
123
- }
124
- }
125
- return new Set(usuableIds);
126
- }
85
+ const collectUsableIds = (commandIds) => new Set(commandIds.flatMap(id => id.split(':').map((_, i, a) => a.slice(0, i + 1).join(':'))));
127
86
  exports.collectUsableIds = collectUsableIds;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = void 0;
4
- const settings_1 = require("../settings");
5
4
  const logger_1 = require("./logger");
5
+ const settings_1 = require("../settings");
6
6
  function displayWarnings() {
7
7
  if (process.listenerCount('warning') > 1)
8
8
  return;
@@ -1,4 +1,4 @@
1
- import { PrettyPrintableError, OclifError } from '../../interfaces/errors';
1
+ import { OclifError, PrettyPrintableError } from '../../interfaces/errors';
2
2
  /**
3
3
  * properties specific to internal oclif error handling
4
4
  */
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CLIError = exports.addOclifExitCode = void 0;
4
- const chalk = require("chalk");
5
- const indent = require("indent-string");
6
- const cs = require("clean-stack");
7
- const wrap = require("wrap-ansi");
8
- const screen = require("../../screen");
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
6
  const config_1 = require("../config");
7
+ const clean_stack_1 = tslib_1.__importDefault(require("clean-stack"));
8
+ const screen_1 = require("../../screen");
9
+ const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
10
+ const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
10
11
  /**
11
12
  * properties specific to internal oclif error handling
12
13
  */
@@ -27,7 +28,7 @@ class CLIError extends Error {
27
28
  this.suggestions = options.suggestions;
28
29
  }
29
30
  get stack() {
30
- return cs(super.stack, { pretty: true });
31
+ return (0, clean_stack_1.default)(super.stack, { pretty: true });
31
32
  }
32
33
  /**
33
34
  * @deprecated `render` Errors display should be handled by display function, like pretty-print
@@ -38,15 +39,15 @@ class CLIError extends Error {
38
39
  return this.stack;
39
40
  }
40
41
  let output = `${this.name}: ${this.message}`;
41
- output = wrap(output, screen.errtermwidth - 6, { trim: false, hard: true });
42
- output = indent(output, 3);
43
- output = indent(output, 1, { indent: this.bang, includeEmptyLines: true });
44
- output = indent(output, 1);
42
+ output = (0, wrap_ansi_1.default)(output, screen_1.errtermwidth - 6, { trim: false, hard: true });
43
+ output = (0, indent_string_1.default)(output, 3);
44
+ output = (0, indent_string_1.default)(output, 1, { indent: this.bang, includeEmptyLines: true });
45
+ output = (0, indent_string_1.default)(output, 1);
45
46
  return output;
46
47
  }
47
48
  get bang() {
48
49
  try {
49
- return chalk.red(process.platform === 'win32' ? '»' : '›');
50
+ return chalk_1.default.red(process.platform === 'win32' ? '»' : '›');
50
51
  }
51
52
  catch { }
52
53
  }
@@ -60,10 +61,10 @@ exports.CLIError = CLIError;
60
61
  }
61
62
  get bang() {
62
63
  try {
63
- return chalk.yellow(process.platform === 'win32' ? '»' : '›');
64
+ return chalk_1.default.yellow(process.platform === 'win32' ? '»' : '›');
64
65
  }
65
66
  catch { }
66
67
  }
67
68
  }
68
69
  CLIError.Warn = Warn;
69
- })(CLIError = exports.CLIError || (exports.CLIError = {}));
70
+ })(CLIError || (exports.CLIError = CLIError = {}));
@@ -1,9 +1,6 @@
1
1
  import { CLIError } from './cli';
2
2
  import { OclifError } from '../../interfaces';
3
3
  export declare class ExitError extends CLIError implements OclifError {
4
- oclif: {
5
- exit: number;
6
- };
7
4
  code: string;
8
5
  constructor(exitCode?: number);
9
6
  render(): string;
@@ -1,9 +1,6 @@
1
1
  import { CLIError } from './cli';
2
2
  import { OclifError } from '../../interfaces';
3
3
  export declare class ModuleLoadError extends CLIError implements OclifError {
4
- oclif: {
5
- exit: number;
6
- };
7
4
  code: string;
8
5
  constructor(message: string);
9
6
  }
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyPrettyPrintOptions = void 0;
4
- const wrap = require("wrap-ansi");
5
- const indent = require("indent-string");
6
- const screen = require("../../screen");
4
+ const tslib_1 = require("tslib");
7
5
  const config_1 = require("../config");
6
+ const screen_1 = require("../../screen");
7
+ const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
8
+ const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
8
9
  function applyPrettyPrintOptions(error, options) {
9
10
  const prettyErrorKeys = ['message', 'code', 'ref', 'suggestions'];
10
11
  for (const key of prettyErrorKeys) {
@@ -23,7 +24,7 @@ const formatSuggestions = (suggestions) => {
23
24
  if (suggestions.length === 1)
24
25
  return `${label} ${suggestions[0]}`;
25
26
  const multiple = suggestions.map(suggestion => `* ${suggestion}`).join('\n');
26
- return `${label}\n${indent(multiple, 2)}`;
27
+ return `${label}\n${(0, indent_string_1.default)(multiple, 2)}`;
27
28
  };
28
29
  function prettyPrint(error) {
29
30
  if (config_1.config.debug) {
@@ -39,10 +40,10 @@ function prettyPrint(error) {
39
40
  const formatted = [formattedHeader, formattedCode, formattedSuggestions, formattedReference]
40
41
  .filter(Boolean)
41
42
  .join('\n');
42
- let output = wrap(formatted, screen.errtermwidth - 6, { trim: false, hard: true });
43
- output = indent(output, 3);
44
- output = indent(output, 1, { indent: bang || '', includeEmptyLines: true });
45
- output = indent(output, 1);
43
+ let output = (0, wrap_ansi_1.default)(formatted, screen_1.errtermwidth - 6, { trim: false, hard: true });
44
+ output = (0, indent_string_1.default)(output, 3);
45
+ output = (0, indent_string_1.default)(output, 1, { indent: bang || '', includeEmptyLines: true });
46
+ output = (0, indent_string_1.default)(output, 1);
46
47
  return output;
47
48
  }
48
49
  exports.default = prettyPrint;
@@ -1,4 +1,14 @@
1
1
  import { OclifError, PrettyPrintableError } from '../interfaces';
2
- export declare function handle(err: Error & Partial<PrettyPrintableError> & Partial<OclifError> & {
2
+ /**
3
+ * This is an odd abstraction for process.exit, but it allows us to stub it in tests.
4
+ *
5
+ * https://github.com/sinonjs/sinon/issues/562
6
+ */
7
+ export declare const Exit: {
8
+ exit(code?: number): never;
9
+ };
10
+ type ErrorToHandle = Error & Partial<PrettyPrintableError> & Partial<OclifError> & {
3
11
  skipOclifErrorHandling?: boolean;
4
- }): Promise<void>;
12
+ };
13
+ export declare function handle(err: ErrorToHandle): Promise<void>;
14
+ export {};
@@ -1,41 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handle = void 0;
4
- /* eslint-disable no-process-exit */
5
- /* eslint-disable unicorn/no-process-exit */
6
- const config_1 = require("./config");
7
- const pretty_print_1 = require("./errors/pretty-print");
8
- const _1 = require(".");
9
- const clean = require("clean-stack");
3
+ exports.handle = exports.Exit = void 0;
4
+ const tslib_1 = require("tslib");
10
5
  const cli_1 = require("./errors/cli");
6
+ const _1 = require(".");
7
+ const clean_stack_1 = tslib_1.__importDefault(require("clean-stack"));
8
+ const config_1 = require("./config");
9
+ const pretty_print_1 = tslib_1.__importDefault(require("./errors/pretty-print"));
10
+ /**
11
+ * This is an odd abstraction for process.exit, but it allows us to stub it in tests.
12
+ *
13
+ * https://github.com/sinonjs/sinon/issues/562
14
+ */
15
+ exports.Exit = {
16
+ exit(code = 0) {
17
+ process.exit(code);
18
+ },
19
+ };
11
20
  async function handle(err) {
12
21
  try {
13
22
  if (!err)
14
23
  err = new cli_1.CLIError('no error?');
15
24
  if (err.message === 'SIGINT')
16
- process.exit(1);
25
+ exports.Exit.exit(1);
17
26
  const shouldPrint = !(err instanceof _1.ExitError) && !err.skipOclifErrorHandling;
18
27
  const pretty = (0, pretty_print_1.default)(err);
19
- const stack = clean(err.stack || '', { pretty: true });
28
+ const stack = (0, clean_stack_1.default)(err.stack || '', { pretty: true });
20
29
  if (shouldPrint) {
21
- console.error(pretty ? pretty : stack);
30
+ console.error(pretty ?? stack);
22
31
  }
23
- const exitCode = err.oclif?.exit !== undefined && err.oclif?.exit !== false ? err.oclif?.exit : 1;
32
+ const exitCode = err.oclif?.exit ?? 1;
24
33
  if (config_1.config.errorLogger && err.code !== 'EEXIT') {
25
34
  if (stack) {
26
35
  config_1.config.errorLogger.log(stack);
27
36
  }
28
37
  await config_1.config.errorLogger.flush()
29
- .then(() => process.exit(exitCode))
38
+ .then(() => exports.Exit.exit(exitCode))
30
39
  .catch(console.error);
31
40
  }
32
41
  else
33
- process.exit(exitCode);
42
+ exports.Exit.exit(exitCode);
34
43
  }
35
44
  catch (error) {
36
45
  console.error(err.stack);
37
46
  console.error(error.stack);
38
- process.exit(1);
47
+ exports.Exit.exit(1);
39
48
  }
40
49
  }
41
50
  exports.handle = handle;
@@ -1,11 +1,10 @@
1
+ import { PrettyPrintableError } from '../interfaces';
1
2
  export { handle } from './handle';
2
3
  export { ExitError } from './errors/exit';
3
4
  export { ModuleLoadError } from './errors/module-load';
4
5
  export { CLIError } from './errors/cli';
5
6
  export { Logger } from './logger';
6
7
  export { config } from './config';
7
- import { PrettyPrintableError } from '../interfaces';
8
- export { PrettyPrintableError };
9
8
  export declare function exit(code?: number): never;
10
9
  export declare function error(input: string | Error, options: {
11
10
  exit: false;
@@ -15,3 +14,4 @@ export declare function error(input: string | Error, options?: {
15
14
  } & PrettyPrintableError): never;
16
15
  export declare function warn(input: string | Error): void;
17
16
  export declare function memoizedWarn(input: string | Error): void;
17
+ export { PrettyPrintableError } from '../interfaces';
@@ -1,33 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.memoizedWarn = exports.warn = exports.error = exports.exit = exports.config = exports.Logger = exports.CLIError = exports.ModuleLoadError = exports.ExitError = exports.handle = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cli_1 = require("./errors/cli");
6
+ const pretty_print_1 = tslib_1.__importStar(require("./errors/pretty-print"));
7
+ const exit_1 = require("./errors/exit");
8
+ const config_1 = require("./config");
4
9
  var handle_1 = require("./handle");
5
10
  Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
6
- var exit_1 = require("./errors/exit");
7
- Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
11
+ var exit_2 = require("./errors/exit");
12
+ Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_2.ExitError; } });
8
13
  var module_load_1 = require("./errors/module-load");
9
14
  Object.defineProperty(exports, "ModuleLoadError", { enumerable: true, get: function () { return module_load_1.ModuleLoadError; } });
10
- var cli_1 = require("./errors/cli");
11
- Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return cli_1.CLIError; } });
15
+ var cli_2 = require("./errors/cli");
16
+ Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return cli_2.CLIError; } });
12
17
  var logger_1 = require("./logger");
13
18
  Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
14
- var config_1 = require("./config");
15
- Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
16
- const config_2 = require("./config");
17
- const cli_2 = require("./errors/cli");
18
- const exit_2 = require("./errors/exit");
19
- const pretty_print_1 = require("./errors/pretty-print");
19
+ var config_2 = require("./config");
20
+ Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_2.config; } });
20
21
  function exit(code = 0) {
21
- throw new exit_2.ExitError(code);
22
+ throw new exit_1.ExitError(code);
22
23
  }
23
24
  exports.exit = exit;
24
25
  function error(input, options = {}) {
25
26
  let err;
26
27
  if (typeof input === 'string') {
27
- err = new cli_2.CLIError(input, options);
28
+ err = new cli_1.CLIError(input, options);
28
29
  }
29
30
  else if (input instanceof Error) {
30
- err = (0, cli_2.addOclifExitCode)(input, options);
31
+ err = (0, cli_1.addOclifExitCode)(input, options);
31
32
  }
32
33
  else {
33
34
  throw new TypeError('first argument must be a string or instance of Error');
@@ -36,8 +37,8 @@ function error(input, options = {}) {
36
37
  if (options.exit === false) {
37
38
  const message = (0, pretty_print_1.default)(err);
38
39
  console.error(message);
39
- if (config_2.config.errorLogger)
40
- config_2.config.errorLogger.log(err?.stack ?? '');
40
+ if (config_1.config.errorLogger)
41
+ config_1.config.errorLogger.log(err?.stack ?? '');
41
42
  }
42
43
  else
43
44
  throw err;
@@ -46,18 +47,18 @@ exports.error = error;
46
47
  function warn(input) {
47
48
  let err;
48
49
  if (typeof input === 'string') {
49
- err = new cli_2.CLIError.Warn(input);
50
+ err = new cli_1.CLIError.Warn(input);
50
51
  }
51
52
  else if (input instanceof Error) {
52
- err = (0, cli_2.addOclifExitCode)(input);
53
+ err = (0, cli_1.addOclifExitCode)(input);
53
54
  }
54
55
  else {
55
56
  throw new TypeError('first argument must be a string or instance of Error');
56
57
  }
57
58
  const message = (0, pretty_print_1.default)(err);
58
59
  console.error(message);
59
- if (config_2.config.errorLogger)
60
- config_2.config.errorLogger.log(err?.stack ?? '');
60
+ if (config_1.config.errorLogger)
61
+ config_1.config.errorLogger.log(err?.stack ?? '');
61
62
  }
62
63
  exports.warn = warn;
63
64
  const WARNINGS = new Set();
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = void 0;
4
- const fs = require("fs/promises");
5
- const path_1 = require("path");
4
+ const promises_1 = require("node:fs/promises");
5
+ 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;
@@ -35,8 +35,8 @@ class Logger {
35
35
  return;
36
36
  const mylines = this.buffer;
37
37
  this.buffer = [];
38
- await fs.mkdir((0, path_1.dirname)(this.file), { recursive: true });
39
- await fs.appendFile(this.file, mylines.join('\n') + '\n');
38
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(this.file), { recursive: true });
39
+ await (0, promises_1.appendFile)(this.file, mylines.join('\n') + '\n');
40
40
  });
41
41
  await this.flushing;
42
42
  }
package/lib/execute.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as Interfaces from './interfaces';
1
+ import { LoadOptions } from './interfaces';
2
2
  /**
3
3
  * Load and run oclif CLI
4
4
  *
@@ -7,7 +7,7 @@ import * as Interfaces from './interfaces';
7
7
  *
8
8
  * @example For ESM dev.js
9
9
  * ```
10
- * #!/usr/bin/env node
10
+ * #!/usr/bin/env ts-node
11
11
  * void (async () => {
12
12
  * const oclif = await import('@oclif/core')
13
13
  * await oclif.execute({development: true, dir: import.meta.url})
@@ -25,7 +25,7 @@ import * as Interfaces from './interfaces';
25
25
  *
26
26
  * @example For CJS dev.js
27
27
  * ```
28
- * #!/usr/bin/env node
28
+ * #!/usr/bin/env ts-node
29
29
  * void (async () => {
30
30
  * const oclif = await import('@oclif/core')
31
31
  * await oclif.execute({development: true, dir: __dirname})
@@ -41,9 +41,9 @@ import * as Interfaces from './interfaces';
41
41
  * })()
42
42
  * ```
43
43
  */
44
- export default function execute(options: {
44
+ export declare function execute(options: {
45
45
  dir: string;
46
46
  args?: string[];
47
- loadOptions?: Interfaces.LoadOptions;
47
+ loadOptions?: LoadOptions;
48
48
  development?: boolean;
49
49
  }): Promise<unknown>;