@oclif/core 4.0.0-beta.1 → 4.0.0-beta.10
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.
- package/lib/args.d.ts +4 -4
- package/lib/cache.d.ts +3 -3
- package/lib/cache.js +1 -1
- package/lib/command.d.ts +18 -18
- package/lib/command.js +11 -20
- package/lib/config/config.d.ts +12 -37
- package/lib/config/config.js +82 -118
- package/lib/config/plugin-loader.d.ts +6 -6
- package/lib/config/plugin-loader.js +4 -28
- package/lib/config/plugin.d.ts +3 -3
- package/lib/config/plugin.js +9 -11
- package/lib/config/ts-path.d.ts +1 -1
- package/lib/config/ts-path.js +6 -7
- package/lib/config/util.d.ts +1 -1
- package/lib/config/util.js +5 -21
- package/lib/errors/error.js +3 -3
- package/lib/errors/errors/cli.d.ts +5 -5
- package/lib/errors/errors/cli.js +2 -2
- package/lib/errors/errors/pretty-print.d.ts +2 -2
- package/lib/errors/errors/pretty-print.js +2 -2
- package/lib/errors/handle.js +4 -11
- package/lib/errors/index.d.ts +0 -2
- package/lib/errors/index.js +1 -5
- package/lib/errors/warn.d.ts +2 -8
- package/lib/errors/warn.js +12 -11
- package/lib/flags.d.ts +4 -4
- package/lib/flush.js +2 -2
- package/lib/help/formatter.d.ts +3 -3
- package/lib/help/index.d.ts +1 -0
- package/lib/help/index.js +19 -10
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/interfaces/config.d.ts +9 -21
- package/lib/interfaces/errors.d.ts +5 -5
- package/lib/interfaces/flags.d.ts +2 -2
- package/lib/interfaces/index.d.ts +2 -1
- package/lib/interfaces/logger.d.ts +9 -0
- package/lib/interfaces/logger.js +2 -0
- package/lib/interfaces/parser.d.ts +6 -6
- package/lib/interfaces/pjson.d.ts +217 -150
- package/lib/interfaces/plugin.d.ts +26 -24
- package/lib/interfaces/topic.d.ts +2 -2
- package/lib/logger.d.ts +14 -0
- package/lib/logger.js +90 -0
- package/lib/main.js +5 -3
- package/lib/parser/errors.d.ts +1 -1
- package/lib/parser/parse.js +2 -1
- package/lib/performance.js +3 -2
- package/lib/settings.d.ts +5 -11
- package/lib/util/determine-priority.d.ts +21 -0
- package/lib/util/determine-priority.js +55 -0
- package/lib/util/find-root.d.ts +1 -0
- package/lib/util/find-root.js +19 -19
- package/lib/util/fs.js +12 -0
- package/lib/util/ids.d.ts +1 -1
- package/lib/util/read-pjson.d.ts +7 -0
- package/lib/util/read-pjson.js +60 -0
- package/lib/util/read-tsconfig.js +4 -9
- package/lib/ux/colorize-json.d.ts +2 -2
- package/lib/ux/index.d.ts +7 -2
- package/lib/ux/index.js +15 -3
- package/lib/ux/theme.d.ts +1 -1
- package/package.json +30 -14
- package/flush.d.ts +0 -3
- package/flush.js +0 -1
- package/handle.js +0 -1
- package/lib/errors/config.d.ts +0 -6
- package/lib/errors/config.js +0 -38
- package/lib/errors/logger.d.ts +0 -8
- package/lib/errors/logger.js +0 -48
|
@@ -1,37 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
const minimatch_1 = require("minimatch");
|
|
27
4
|
const node_path_1 = require("node:path");
|
|
28
5
|
const performance_1 = require("../performance");
|
|
29
6
|
const fs_1 = require("../util/fs");
|
|
30
7
|
const util_1 = require("../util/util");
|
|
31
|
-
const
|
|
8
|
+
const plugin_1 = require("./plugin");
|
|
32
9
|
const util_2 = require("./util");
|
|
33
|
-
|
|
34
|
-
const debug = (0, util_2.Debug)();
|
|
10
|
+
const debug = (0, util_2.makeDebug)();
|
|
35
11
|
function findMatchingDependencies(dependencies, patterns) {
|
|
36
12
|
return Object.keys(dependencies).filter((p) => patterns.some((w) => (0, minimatch_1.minimatch)(p, w)));
|
|
37
13
|
}
|
|
@@ -63,7 +39,7 @@ class PluginLoader {
|
|
|
63
39
|
}
|
|
64
40
|
else {
|
|
65
41
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
|
|
66
|
-
rootPlugin = new
|
|
42
|
+
rootPlugin = new plugin_1.Plugin({ isRoot: true, pjson, root: this.options.root });
|
|
67
43
|
await rootPlugin.load();
|
|
68
44
|
marker?.addDetails({
|
|
69
45
|
commandCount: rootPlugin.commands.length,
|
|
@@ -155,7 +131,7 @@ class PluginLoader {
|
|
|
155
131
|
if (this.plugins.has(name))
|
|
156
132
|
return;
|
|
157
133
|
const pluginMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.load#${name}`);
|
|
158
|
-
const instance = new
|
|
134
|
+
const instance = new plugin_1.Plugin(opts);
|
|
159
135
|
await instance.load();
|
|
160
136
|
pluginMarker?.addDetails({
|
|
161
137
|
commandCount: instance.commands.length,
|
package/lib/config/plugin.d.ts
CHANGED
|
@@ -19,10 +19,10 @@ export declare class Plugin implements IPlugin {
|
|
|
19
19
|
manifest: Manifest;
|
|
20
20
|
moduleType: 'commonjs' | 'module';
|
|
21
21
|
name: string;
|
|
22
|
-
parent
|
|
23
|
-
pjson: PJSON
|
|
22
|
+
parent?: Plugin | undefined;
|
|
23
|
+
pjson: PJSON;
|
|
24
24
|
root: string;
|
|
25
|
-
tag?: string;
|
|
25
|
+
tag?: string | undefined;
|
|
26
26
|
type: string;
|
|
27
27
|
valid: boolean;
|
|
28
28
|
version: string;
|
package/lib/config/plugin.js
CHANGED
|
@@ -15,6 +15,7 @@ const symbols_1 = require("../symbols");
|
|
|
15
15
|
const cache_command_1 = require("../util/cache-command");
|
|
16
16
|
const find_root_1 = require("../util/find-root");
|
|
17
17
|
const fs_1 = require("../util/fs");
|
|
18
|
+
const read_pjson_1 = require("../util/read-pjson");
|
|
18
19
|
const util_1 = require("../util/util");
|
|
19
20
|
const ts_path_1 = require("./ts-path");
|
|
20
21
|
const util_2 = require("./util");
|
|
@@ -56,12 +57,9 @@ function processCommandIds(files) {
|
|
|
56
57
|
return id === '' ? symbols_1.SINGLE_COMMAND_CLI_SYMBOL : id;
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
function determineCommandDiscoveryOptions(commandDiscovery
|
|
60
|
+
function determineCommandDiscoveryOptions(commandDiscovery) {
|
|
60
61
|
if (!commandDiscovery)
|
|
61
62
|
return;
|
|
62
|
-
if (typeof commandDiscovery === 'string' && defaultCmdId) {
|
|
63
|
-
return { strategy: 'single', target: commandDiscovery };
|
|
64
|
-
}
|
|
65
63
|
if (typeof commandDiscovery === 'string') {
|
|
66
64
|
return { globPatterns: GLOB_PATTERNS, strategy: 'pattern', target: commandDiscovery };
|
|
67
65
|
}
|
|
@@ -104,8 +102,7 @@ class Plugin {
|
|
|
104
102
|
valid = false;
|
|
105
103
|
version;
|
|
106
104
|
_base = `${_pjson.name}@${_pjson.version}`;
|
|
107
|
-
|
|
108
|
-
_debug = (0, util_2.Debug)();
|
|
105
|
+
_debug = (0, util_2.makeDebug)();
|
|
109
106
|
commandCache;
|
|
110
107
|
commandDiscoveryOpts;
|
|
111
108
|
flexibleTaxonomy;
|
|
@@ -183,15 +180,14 @@ class Plugin {
|
|
|
183
180
|
throw new errors_1.CLIError(`could not find package.json with ${(0, node_util_1.inspect)(this.options)}`);
|
|
184
181
|
this.root = root;
|
|
185
182
|
this._debug(`loading ${this.type} plugin from ${root}`);
|
|
186
|
-
this.pjson = this.options.pjson ?? (await (0,
|
|
183
|
+
this.pjson = this.options.pjson ?? (await (0, read_pjson_1.readPjson)(root));
|
|
187
184
|
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
188
185
|
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
189
186
|
this.name = this.pjson.name;
|
|
190
187
|
this.alias = this.options.name ?? this.pjson.name;
|
|
191
188
|
if (!this.name)
|
|
192
189
|
throw new errors_1.CLIError(`no name in package.json (${root})`);
|
|
193
|
-
|
|
194
|
-
this._debug = (0, util_2.Debug)(this.name);
|
|
190
|
+
this._debug = (0, util_2.makeDebug)(this.name);
|
|
195
191
|
this.version = this.pjson.version;
|
|
196
192
|
if (this.pjson.oclif) {
|
|
197
193
|
this.valid = true;
|
|
@@ -203,7 +199,7 @@ class Plugin {
|
|
|
203
199
|
k,
|
|
204
200
|
(0, util_1.castArray)(v).map((v) => determineHookOptions(v)),
|
|
205
201
|
]));
|
|
206
|
-
this.commandDiscoveryOpts = determineCommandDiscoveryOptions(this.pjson.oclif?.commands
|
|
202
|
+
this.commandDiscoveryOpts = determineCommandDiscoveryOptions(this.pjson.oclif?.commands);
|
|
207
203
|
this._debug('command discovery options', this.commandDiscoveryOpts);
|
|
208
204
|
this.manifest = await this._manifest();
|
|
209
205
|
this.commands = Object.entries(this.manifest.commands)
|
|
@@ -278,7 +274,7 @@ class Plugin {
|
|
|
278
274
|
throw this.addErrorScope(error, scope);
|
|
279
275
|
}
|
|
280
276
|
})))
|
|
281
|
-
// eslint-disable-next-line unicorn/
|
|
277
|
+
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
|
282
278
|
.filter((f) => Boolean(f))
|
|
283
279
|
.reduce((commands, [id, c]) => {
|
|
284
280
|
commands[id] = c;
|
|
@@ -298,6 +294,8 @@ class Plugin {
|
|
|
298
294
|
scope && `task: ${scope}`,
|
|
299
295
|
`plugin: ${this.name}`,
|
|
300
296
|
`root: ${this.root}`,
|
|
297
|
+
...(err.code ? [`code: ${err.code}`] : []),
|
|
298
|
+
...(err.message ? [`message: ${err.message}`] : []),
|
|
301
299
|
'See more details with DEBUG=*',
|
|
302
300
|
]).join('\n');
|
|
303
301
|
return err;
|
package/lib/config/ts-path.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare const TS_CONFIGS: Record<string, TSConfig | undefined>;
|
|
|
6
6
|
* if there is a tsconfig and the original sources exist, it attempts to require ts-node
|
|
7
7
|
*/
|
|
8
8
|
export declare function tsPath(root: string, orig: string, plugin: Plugin): Promise<string>;
|
|
9
|
-
export declare function tsPath(root: string, orig: string | undefined, plugin?: Plugin): Promise<string | undefined>;
|
|
9
|
+
export declare function tsPath(root: string, orig: string | undefined, plugin?: Plugin | undefined): Promise<string | undefined>;
|
package/lib/config/ts-path.js
CHANGED
|
@@ -13,8 +13,7 @@ const fs_1 = require("../util/fs");
|
|
|
13
13
|
const read_tsconfig_1 = require("../util/read-tsconfig");
|
|
14
14
|
const util_1 = require("../util/util");
|
|
15
15
|
const util_2 = require("./util");
|
|
16
|
-
|
|
17
|
-
const debug = (0, util_2.Debug)('ts-path');
|
|
16
|
+
const debug = (0, util_2.makeDebug)('ts-path');
|
|
18
17
|
exports.TS_CONFIGS = {};
|
|
19
18
|
const REGISTERED = new Set();
|
|
20
19
|
function determineRuntime() {
|
|
@@ -76,7 +75,7 @@ async function loadTSConfig(root) {
|
|
|
76
75
|
if (isErrno(error))
|
|
77
76
|
return;
|
|
78
77
|
debug(`Could not parse tsconfig.json. Skipping typescript path lookup for ${root}.`);
|
|
79
|
-
(0, warn_1.
|
|
78
|
+
(0, warn_1.memoizedWarn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
async function registerTSNode(root, tsconfig) {
|
|
@@ -91,7 +90,7 @@ async function registerTSNode(root, tsconfig) {
|
|
|
91
90
|
}
|
|
92
91
|
catch {
|
|
93
92
|
debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`);
|
|
94
|
-
(0, warn_1.
|
|
93
|
+
(0, warn_1.memoizedWarn)(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`);
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
96
|
const typeRoots = [(0, node_path_1.join)(root, 'node_modules', '@types')];
|
|
@@ -220,7 +219,7 @@ async function determinePath(root, orig) {
|
|
|
220
219
|
}
|
|
221
220
|
debug(`No source file found. Returning default path ${orig}`);
|
|
222
221
|
if (!(0, util_1.isProd)())
|
|
223
|
-
(0, warn_1.
|
|
222
|
+
(0, warn_1.memoizedWarn)(`Could not find source for ${orig} based on tsconfig. Defaulting to compiled source.`);
|
|
224
223
|
return orig;
|
|
225
224
|
}
|
|
226
225
|
async function tsPath(root, orig, plugin) {
|
|
@@ -243,12 +242,12 @@ async function tsPath(root, orig, plugin) {
|
|
|
243
242
|
if (cannotTranspileEsm(rootPlugin, plugin, isProduction)) {
|
|
244
243
|
debug(`Skipping typescript path lookup for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})`);
|
|
245
244
|
if (plugin?.type === 'link')
|
|
246
|
-
(0, warn_1.
|
|
245
|
+
(0, warn_1.memoizedWarn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
247
246
|
return orig;
|
|
248
247
|
}
|
|
249
248
|
if (cannotUseTsNode(root, plugin, isProduction)) {
|
|
250
249
|
debug(`Skipping typescript path lookup for ${root} because ts-node is run in node version ${process.version}"`);
|
|
251
|
-
(0, warn_1.
|
|
250
|
+
(0, warn_1.memoizedWarn)(`ts-node executable cannot transpile ESM in Node 20. Existing compiled source will be used instead. See https://github.com/oclif/core/issues/817.`);
|
|
252
251
|
return orig;
|
|
253
252
|
}
|
|
254
253
|
try {
|
package/lib/config/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function makeDebug(...scope: string[]): (..._: any) => void;
|
|
2
2
|
export declare function getPermutations(arr: string[]): Array<string[]>;
|
|
3
3
|
export declare function getCommandIdPermutations(commandId: string): string[];
|
|
4
4
|
/**
|
package/lib/config/util.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
return;
|
|
8
|
-
process.on('warning', (warning) => {
|
|
9
|
-
console.error(warning.stack);
|
|
10
|
-
if (warning.detail)
|
|
11
|
-
console.error(warning.detail);
|
|
12
|
-
});
|
|
3
|
+
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.makeDebug = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
function makeDebug(...scope) {
|
|
6
|
+
return (formatter, ...args) => (0, logger_1.getLogger)(['config', ...scope].join(':')).debug(formatter, ...args);
|
|
13
7
|
}
|
|
14
|
-
|
|
15
|
-
if (!debug)
|
|
16
|
-
return (..._) => {
|
|
17
|
-
// noop
|
|
18
|
-
};
|
|
19
|
-
const d = debug(['config', ...scope].join(':'));
|
|
20
|
-
if (d.enabled)
|
|
21
|
-
displayWarnings();
|
|
22
|
-
return (...args) => d(...args);
|
|
23
|
-
}
|
|
24
|
-
exports.Debug = Debug;
|
|
8
|
+
exports.makeDebug = makeDebug;
|
|
25
9
|
// Adapted from https://github.com/angus-c/just/blob/master/packages/array-permutations/index.js
|
|
26
10
|
function getPermutations(arr) {
|
|
27
11
|
if (arr.length === 0)
|
package/lib/errors/error.js
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.error = void 0;
|
|
27
|
+
const logger_1 = require("../logger");
|
|
27
28
|
const write_1 = require("../ux/write");
|
|
28
|
-
const config_1 = require("./config");
|
|
29
29
|
const cli_1 = require("./errors/cli");
|
|
30
30
|
const pretty_print_1 = __importStar(require("./errors/pretty-print"));
|
|
31
31
|
function error(input, options = {}) {
|
|
@@ -44,8 +44,8 @@ function error(input, options = {}) {
|
|
|
44
44
|
const message = (0, pretty_print_1.default)(err);
|
|
45
45
|
if (message)
|
|
46
46
|
(0, write_1.stderr)(message);
|
|
47
|
-
if (
|
|
48
|
-
|
|
47
|
+
if (err?.stack)
|
|
48
|
+
(0, logger_1.getLogger)().error(err.stack);
|
|
49
49
|
}
|
|
50
50
|
else
|
|
51
51
|
throw err;
|
|
@@ -3,15 +3,15 @@ import { OclifError, PrettyPrintableError } from '../../interfaces/errors';
|
|
|
3
3
|
* properties specific to internal oclif error handling
|
|
4
4
|
*/
|
|
5
5
|
export declare function addOclifExitCode(error: Record<string, any>, options?: {
|
|
6
|
-
exit?: false | number;
|
|
6
|
+
exit?: false | number | undefined;
|
|
7
7
|
}): OclifError;
|
|
8
8
|
export declare class CLIError extends Error implements OclifError {
|
|
9
|
-
code?: string;
|
|
9
|
+
code?: string | undefined;
|
|
10
10
|
oclif: OclifError['oclif'];
|
|
11
|
-
skipOclifErrorHandling?: boolean;
|
|
12
|
-
suggestions?: string[];
|
|
11
|
+
skipOclifErrorHandling?: boolean | undefined;
|
|
12
|
+
suggestions?: string[] | undefined;
|
|
13
13
|
constructor(error: Error | string, options?: {
|
|
14
|
-
exit?: false | number;
|
|
14
|
+
exit?: false | number | undefined;
|
|
15
15
|
} & PrettyPrintableError);
|
|
16
16
|
get bang(): string | undefined;
|
|
17
17
|
get stack(): string;
|
package/lib/errors/errors/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ const indent_string_1 = __importDefault(require("indent-string"));
|
|
|
10
10
|
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
11
11
|
const cache_1 = __importDefault(require("../../cache"));
|
|
12
12
|
const screen_1 = require("../../screen");
|
|
13
|
-
const
|
|
13
|
+
const settings_1 = require("../../settings");
|
|
14
14
|
/**
|
|
15
15
|
* properties specific to internal oclif error handling
|
|
16
16
|
*/
|
|
@@ -48,7 +48,7 @@ class CLIError extends Error {
|
|
|
48
48
|
* @return {string} returns a string representing the dispay of the error
|
|
49
49
|
*/
|
|
50
50
|
render() {
|
|
51
|
-
if (
|
|
51
|
+
if (settings_1.settings.debug) {
|
|
52
52
|
return this.stack;
|
|
53
53
|
}
|
|
54
54
|
let output = `${this.name}: ${this.message}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PrettyPrintableError } from '../../interfaces/errors';
|
|
2
2
|
type CLIErrorDisplayOptions = {
|
|
3
|
-
bang?: string;
|
|
4
|
-
name?: string;
|
|
3
|
+
bang?: string | undefined;
|
|
4
|
+
name?: string | undefined;
|
|
5
5
|
};
|
|
6
6
|
export declare function applyPrettyPrintOptions(error: Error, options: PrettyPrintableError): PrettyPrintableError;
|
|
7
7
|
export default function prettyPrint(error: Error & PrettyPrintableError & CLIErrorDisplayOptions): string | undefined;
|
|
@@ -7,7 +7,7 @@ exports.applyPrettyPrintOptions = void 0;
|
|
|
7
7
|
const indent_string_1 = __importDefault(require("indent-string"));
|
|
8
8
|
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
9
9
|
const screen_1 = require("../../screen");
|
|
10
|
-
const
|
|
10
|
+
const settings_1 = require("../../settings");
|
|
11
11
|
function applyPrettyPrintOptions(error, options) {
|
|
12
12
|
const prettyErrorKeys = ['message', 'code', 'ref', 'suggestions'];
|
|
13
13
|
for (const key of prettyErrorKeys) {
|
|
@@ -30,7 +30,7 @@ const formatSuggestions = (suggestions) => {
|
|
|
30
30
|
return `${label}\n${(0, indent_string_1.default)(multiple, 2)}`;
|
|
31
31
|
};
|
|
32
32
|
function prettyPrint(error) {
|
|
33
|
-
if (
|
|
33
|
+
if (settings_1.settings.debug) {
|
|
34
34
|
return error.stack;
|
|
35
35
|
}
|
|
36
36
|
const { bang, code, message, name: errorSuffix, ref, suggestions } = error;
|
package/lib/errors/handle.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.handle = exports.Exit = void 0;
|
|
|
7
7
|
const clean_stack_1 = __importDefault(require("clean-stack"));
|
|
8
8
|
const cache_1 = __importDefault(require("../cache"));
|
|
9
9
|
const index_1 = require("../help/index");
|
|
10
|
-
const
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
11
|
const cli_1 = require("./errors/cli");
|
|
12
12
|
const exit_1 = require("./errors/exit");
|
|
13
13
|
const pretty_print_1 = __importDefault(require("./errors/pretty-print"));
|
|
@@ -46,17 +46,10 @@ async function handle(err) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
const exitCode = err.oclif?.exit ?? 1;
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
config_1.config.errorLogger.log(stack);
|
|
52
|
-
}
|
|
53
|
-
await config_1.config.errorLogger
|
|
54
|
-
.flush()
|
|
55
|
-
.then(() => exports.Exit.exit(exitCode))
|
|
56
|
-
.catch(console.error);
|
|
49
|
+
if (err.code !== 'EEXIT' && stack) {
|
|
50
|
+
(0, logger_1.getLogger)().error(stack);
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
exports.Exit.exit(exitCode);
|
|
52
|
+
exports.Exit.exit(exitCode);
|
|
60
53
|
}
|
|
61
54
|
catch (error) {
|
|
62
55
|
console.error(err.stack);
|
package/lib/errors/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { PrettyPrintableError } from '../interfaces';
|
|
2
|
-
export { config } from './config';
|
|
3
2
|
export { error } from './error';
|
|
4
3
|
export { CLIError } from './errors/cli';
|
|
5
4
|
export { ExitError } from './errors/exit';
|
|
6
5
|
export { ModuleLoadError } from './errors/module-load';
|
|
7
6
|
export { exit } from './exit';
|
|
8
7
|
export { handle } from './handle';
|
|
9
|
-
export { Logger } from './logger';
|
|
10
8
|
export { warn } from './warn';
|
package/lib/errors/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.warn = exports.
|
|
4
|
-
var config_1 = require("./config");
|
|
5
|
-
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
|
3
|
+
exports.warn = exports.handle = exports.exit = exports.ModuleLoadError = exports.ExitError = exports.CLIError = exports.error = void 0;
|
|
6
4
|
var error_1 = require("./error");
|
|
7
5
|
Object.defineProperty(exports, "error", { enumerable: true, get: function () { return error_1.error; } });
|
|
8
6
|
var cli_1 = require("./errors/cli");
|
|
@@ -15,7 +13,5 @@ var exit_2 = require("./exit");
|
|
|
15
13
|
Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_2.exit; } });
|
|
16
14
|
var handle_1 = require("./handle");
|
|
17
15
|
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
|
18
|
-
var logger_1 = require("./logger");
|
|
19
|
-
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
20
16
|
var warn_1 = require("./warn");
|
|
21
17
|
Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return warn_1.warn; } });
|
package/lib/errors/warn.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
type Options = {
|
|
2
|
-
/**
|
|
3
|
-
* If true, will only print the same warning once.
|
|
4
|
-
*/
|
|
5
|
-
ignoreDuplicates?: boolean;
|
|
6
|
-
};
|
|
7
1
|
/**
|
|
8
2
|
* Prints a pretty warning message to stderr.
|
|
9
3
|
*
|
|
10
4
|
* @param input The error or string to print.
|
|
11
|
-
* @param options.ignoreDuplicates If true, will only print the same warning once.
|
|
12
5
|
*/
|
|
13
|
-
export declare function warn(input: Error | string
|
|
6
|
+
export declare function warn(input: Error | string): void;
|
|
7
|
+
export declare function memoizedWarn(input: Error | string): void;
|
|
14
8
|
export default warn;
|
package/lib/errors/warn.js
CHANGED
|
@@ -3,23 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.warn = void 0;
|
|
6
|
+
exports.memoizedWarn = exports.warn = void 0;
|
|
7
|
+
const logger_1 = require("../logger");
|
|
7
8
|
const write_1 = require("../ux/write");
|
|
8
|
-
const config_1 = require("./config");
|
|
9
9
|
const cli_1 = require("./errors/cli");
|
|
10
10
|
const pretty_print_1 = __importDefault(require("./errors/pretty-print"));
|
|
11
|
-
const WARNINGS = new Set();
|
|
12
11
|
/**
|
|
13
12
|
* Prints a pretty warning message to stderr.
|
|
14
13
|
*
|
|
15
14
|
* @param input The error or string to print.
|
|
16
|
-
* @param options.ignoreDuplicates If true, will only print the same warning once.
|
|
17
15
|
*/
|
|
18
|
-
function warn(input
|
|
19
|
-
const ignoreDuplicates = options?.ignoreDuplicates ?? true;
|
|
20
|
-
if (ignoreDuplicates && WARNINGS.has(input))
|
|
21
|
-
return;
|
|
22
|
-
WARNINGS.add(input);
|
|
16
|
+
function warn(input) {
|
|
23
17
|
let err;
|
|
24
18
|
if (typeof input === 'string') {
|
|
25
19
|
err = new cli_1.CLIError.Warn(input);
|
|
@@ -33,8 +27,15 @@ function warn(input, options) {
|
|
|
33
27
|
const message = (0, pretty_print_1.default)(err);
|
|
34
28
|
if (message)
|
|
35
29
|
(0, write_1.stderr)(message);
|
|
36
|
-
if (
|
|
37
|
-
|
|
30
|
+
if (err?.stack)
|
|
31
|
+
(0, logger_1.getLogger)().error(err.stack);
|
|
38
32
|
}
|
|
39
33
|
exports.warn = warn;
|
|
34
|
+
const WARNINGS = new Set();
|
|
35
|
+
function memoizedWarn(input) {
|
|
36
|
+
if (!WARNINGS.has(input))
|
|
37
|
+
warn(input);
|
|
38
|
+
WARNINGS.add(input);
|
|
39
|
+
}
|
|
40
|
+
exports.memoizedWarn = memoizedWarn;
|
|
40
41
|
exports.default = warn;
|
package/lib/flags.d.ts
CHANGED
|
@@ -72,8 +72,8 @@ export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>):
|
|
|
72
72
|
* - `max` option allows to set a maximum value.
|
|
73
73
|
*/
|
|
74
74
|
export declare const integer: FlagDefinition<number, {
|
|
75
|
-
max?: number
|
|
76
|
-
min?: number
|
|
75
|
+
max?: number;
|
|
76
|
+
min?: number;
|
|
77
77
|
}, {
|
|
78
78
|
multiple: false;
|
|
79
79
|
requiredOrDefaulted: false;
|
|
@@ -84,7 +84,7 @@ export declare const integer: FlagDefinition<number, {
|
|
|
84
84
|
* - `exists` option allows you to throw an error if the directory does not exist.
|
|
85
85
|
*/
|
|
86
86
|
export declare const directory: FlagDefinition<string, {
|
|
87
|
-
exists?: boolean
|
|
87
|
+
exists?: boolean;
|
|
88
88
|
}, {
|
|
89
89
|
multiple: false;
|
|
90
90
|
requiredOrDefaulted: false;
|
|
@@ -95,7 +95,7 @@ export declare const directory: FlagDefinition<string, {
|
|
|
95
95
|
* - `exists` option allows you to throw an error if the file does not exist.
|
|
96
96
|
*/
|
|
97
97
|
export declare const file: FlagDefinition<string, {
|
|
98
|
-
exists?: boolean
|
|
98
|
+
exists?: boolean;
|
|
99
99
|
}, {
|
|
100
100
|
multiple: false;
|
|
101
101
|
requiredOrDefaulted: false;
|
package/lib/flush.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.flush = void 0;
|
|
4
|
-
const
|
|
4
|
+
const error_1 = require("./errors/error");
|
|
5
5
|
function timeout(p, ms) {
|
|
6
6
|
function wait(ms, unref = false) {
|
|
7
7
|
return new Promise((resolve) => {
|
|
@@ -10,7 +10,7 @@ function timeout(p, ms) {
|
|
|
10
10
|
t.unref();
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
return Promise.race([p, wait(ms, true).then(() => (0,
|
|
13
|
+
return Promise.race([p, wait(ms, true).then(() => (0, error_1.error)('timed out'))]);
|
|
14
14
|
}
|
|
15
15
|
async function _flush() {
|
|
16
16
|
const p = new Promise((resolve) => {
|
package/lib/help/formatter.d.ts
CHANGED
|
@@ -59,9 +59,9 @@ export declare class HelpFormatter {
|
|
|
59
59
|
indent(body: string, spacing?: number): string;
|
|
60
60
|
renderList(input: (string | undefined)[][], opts: {
|
|
61
61
|
indentation: number;
|
|
62
|
-
multiline?: boolean;
|
|
63
|
-
spacer?: string;
|
|
64
|
-
stripAnsi?: boolean;
|
|
62
|
+
multiline?: boolean | undefined;
|
|
63
|
+
spacer?: string | undefined;
|
|
64
|
+
stripAnsi?: boolean | undefined;
|
|
65
65
|
}): string;
|
|
66
66
|
section(header: string, body: [string, string | undefined][] | HelpSection | HelpSectionKeyValueTable | string): string;
|
|
67
67
|
/**
|
package/lib/help/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as Interfaces from '../interfaces';
|
|
|
3
3
|
import { CommandHelp } from './command';
|
|
4
4
|
import { HelpFormatter } from './formatter';
|
|
5
5
|
export { CommandHelp } from './command';
|
|
6
|
+
export { HelpFormatter, type HelpSection, type HelpSectionKeyValueTable, type HelpSectionRenderer } from './formatter';
|
|
6
7
|
export { getHelpFlagAdditions, normalizeArgv, standardizeIDFromArgv } from './util';
|
|
7
8
|
export declare abstract class HelpBase extends HelpFormatter {
|
|
8
9
|
constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>);
|
package/lib/help/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadHelpClass = exports.Help = exports.HelpBase = exports.standardizeIDFromArgv = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.CommandHelp = void 0;
|
|
6
|
+
exports.loadHelpClass = exports.Help = exports.HelpBase = exports.standardizeIDFromArgv = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.HelpFormatter = exports.CommandHelp = void 0;
|
|
7
7
|
const ansis_1 = __importDefault(require("ansis"));
|
|
8
8
|
const ts_path_1 = require("../config/ts-path");
|
|
9
9
|
const error_1 = require("../errors/error");
|
|
@@ -12,7 +12,7 @@ const symbols_1 = require("../symbols");
|
|
|
12
12
|
const cache_default_value_1 = require("../util/cache-default-value");
|
|
13
13
|
const ids_1 = require("../util/ids");
|
|
14
14
|
const util_1 = require("../util/util");
|
|
15
|
-
const ux_1 =
|
|
15
|
+
const ux_1 = require("../ux");
|
|
16
16
|
const theme_1 = require("../ux/theme");
|
|
17
17
|
const command_1 = require("./command");
|
|
18
18
|
const formatter_1 = require("./formatter");
|
|
@@ -20,6 +20,8 @@ const root_1 = __importDefault(require("./root"));
|
|
|
20
20
|
const util_2 = require("./util");
|
|
21
21
|
var command_2 = require("./command");
|
|
22
22
|
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
|
|
23
|
+
var formatter_2 = require("./formatter");
|
|
24
|
+
Object.defineProperty(exports, "HelpFormatter", { enumerable: true, get: function () { return formatter_2.HelpFormatter; } });
|
|
23
25
|
var util_3 = require("./util");
|
|
24
26
|
Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
|
|
25
27
|
Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
|
|
@@ -144,7 +146,7 @@ class Help extends HelpBase {
|
|
|
144
146
|
return new this.CommandHelpClass(command, this.config, this.opts);
|
|
145
147
|
}
|
|
146
148
|
log(...args) {
|
|
147
|
-
this.opts.sendToStderr ? ux_1.
|
|
149
|
+
this.opts.sendToStderr ? ux_1.ux.stderr(args) : ux_1.ux.stdout(args);
|
|
148
150
|
}
|
|
149
151
|
async showCommandHelp(command) {
|
|
150
152
|
const name = command.id;
|
|
@@ -314,17 +316,24 @@ exports.Help = Help;
|
|
|
314
316
|
function extractClass(exported) {
|
|
315
317
|
return exported && exported.default ? exported.default : exported;
|
|
316
318
|
}
|
|
319
|
+
function determineLocation(helpClass) {
|
|
320
|
+
if (typeof helpClass === 'string')
|
|
321
|
+
return { identifier: 'default', target: helpClass };
|
|
322
|
+
if (!helpClass.identifier)
|
|
323
|
+
return { ...helpClass, identifier: 'default' };
|
|
324
|
+
return helpClass;
|
|
325
|
+
}
|
|
317
326
|
async function loadHelpClass(config) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (configuredClass) {
|
|
327
|
+
if (config.pjson.oclif?.helpClass) {
|
|
328
|
+
const { identifier, target } = determineLocation(config.pjson.oclif?.helpClass);
|
|
321
329
|
try {
|
|
322
|
-
const path = (await (0, ts_path_1.tsPath)(config.root,
|
|
323
|
-
const
|
|
324
|
-
|
|
330
|
+
const path = (await (0, ts_path_1.tsPath)(config.root, target)) ?? target;
|
|
331
|
+
const module = await (0, module_loader_1.load)(config, path);
|
|
332
|
+
const helpClass = module[identifier] ?? (identifier === 'default' ? extractClass(module) : undefined);
|
|
333
|
+
return extractClass(helpClass);
|
|
325
334
|
}
|
|
326
335
|
catch (error) {
|
|
327
|
-
throw new Error(`Unable to load configured help class "${
|
|
336
|
+
throw new Error(`Unable to load configured help class "${target}", failed with message:\n${error.message}`);
|
|
328
337
|
}
|
|
329
338
|
}
|
|
330
339
|
return Help;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ export { handle } from './errors/handle';
|
|
|
6
6
|
export { execute } from './execute';
|
|
7
7
|
export * as Flags from './flags';
|
|
8
8
|
export { flush } from './flush';
|
|
9
|
-
export { CommandHelp, Help, HelpBase, loadHelpClass } from './help';
|
|
10
|
-
export { HelpSection, HelpSectionKeyValueTable, HelpSectionRenderer } from './help/formatter';
|
|
9
|
+
export { CommandHelp, Help, HelpBase, type HelpSection, type HelpSectionKeyValueTable, type HelpSectionRenderer, loadHelpClass, } from './help';
|
|
11
10
|
export * as Interfaces from './interfaces';
|
|
12
|
-
export { Hook } from './interfaces/hooks';
|
|
11
|
+
export { type Hook } from './interfaces/hooks';
|
|
12
|
+
export { getLogger } from './logger';
|
|
13
13
|
export { run } from './main';
|
|
14
14
|
export * as ModuleLoader from './module-loader';
|
|
15
15
|
export * as Parser from './parser';
|
|
16
16
|
export { Performance } from './performance';
|
|
17
|
-
export { Settings, settings } from './settings';
|
|
17
|
+
export { type Settings, settings } from './settings';
|
|
18
18
|
export { toConfiguredId, toStandardizedId } from './util/ids';
|
|
19
|
-
export {
|
|
19
|
+
export { ux } from './ux';
|