@visulima/cerebro 3.0.0-alpha.10 → 3.0.0-alpha.12
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/CHANGELOG.md +55 -0
- package/LICENSE.md +471 -4345
- package/README.md +26 -0
- package/dist/commands/completion-command.d.ts +6 -5
- package/dist/commands/help-command.d.ts +9 -9
- package/dist/commands/help-command.js +1 -1
- package/dist/commands/readme-command.d.ts +6 -5
- package/dist/commands/readme-command.js +3 -12
- package/dist/commands/version-command.d.ts +4 -3
- package/dist/index.d.ts +422 -95
- package/dist/index.js +2 -1
- package/dist/logger/create-pail-logger.d.ts +779 -8
- package/dist/packem_shared/{Cerebro-bgCm5Tb1.js → Cerebro-f9jDcQQy.js} +69 -7
- package/dist/packem_shared/{index-CS31xKFe.js → index--1UArng3.js} +4 -1
- package/dist/packem_shared/index.d-Br8HpP0A.d.ts +93 -0
- package/dist/packem_shared/lazyNamed-B278Tf9_.js +6 -0
- package/dist/packem_shared/plugin-manager.d-Du-YXFui.d.ts +541 -0
- package/dist/plugins/error-handler-plugin.d.ts +21 -19
- package/dist/plugins/runtime-version-check-plugin.d.ts +22 -20
- package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +21 -8
- package/dist/util/general/compile-cache.d.ts +38 -38
- package/dist/util/general/heap-tuning.d.ts +14 -77
- package/package.json +22 -22
- package/dist/cli.d.ts +0 -225
- package/dist/constants.d.ts +0 -29
- package/dist/default-env.d.ts +0 -7
- package/dist/default-options.d.ts +0 -3
- package/dist/empty-toolbox.d.ts +0 -15
- package/dist/errors/cerebro-error.d.ts +0 -10
- package/dist/errors/command-not-found-error.d.ts +0 -9
- package/dist/errors/command-validation-error.d.ts +0 -10
- package/dist/errors/completion-error.d.ts +0 -9
- package/dist/errors/conflicting-options-error.d.ts +0 -10
- package/dist/errors/plugin-error.d.ts +0 -9
- package/dist/errors/update-notifier-error.d.ts +0 -7
- package/dist/plugin-manager.d.ts +0 -53
- package/dist/plugins/update-notifier/cache.d.ts +0 -11
- package/dist/plugins/update-notifier/get-distribution-version.d.ts +0 -2
- package/dist/plugins/update-notifier/has-new-version.d.ts +0 -14
- package/dist/types/cli.d.ts +0 -113
- package/dist/types/command-line-usage.d.ts +0 -37
- package/dist/types/command.d.ts +0 -136
- package/dist/types/option-types.d.ts +0 -83
- package/dist/types/options.d.ts +0 -4
- package/dist/types/plugin.d.ts +0 -53
- package/dist/types/toolbox.d.ts +0 -96
- package/dist/util/arg-processing/get-boolean-values.d.ts +0 -7
- package/dist/util/arg-processing/get-parameter-option.d.ts +0 -7
- package/dist/util/arg-processing/map-option-type-label.d.ts +0 -3
- package/dist/util/arg-processing/option-is-boolean.d.ts +0 -9
- package/dist/util/arg-processing/remove-boolean-values.d.ts +0 -9
- package/dist/util/command-line-commands.d.ts +0 -10
- package/dist/util/command-line-usage/get-terminal-width.d.ts +0 -7
- package/dist/util/command-line-usage/index.d.ts +0 -3
- package/dist/util/command-line-usage/section/base-section.d.ts +0 -8
- package/dist/util/command-line-usage/section/content-section.d.ts +0 -65
- package/dist/util/command-line-usage/section/option-list-section.d.ts +0 -44
- package/dist/util/command-processing/command-processor.d.ts +0 -37
- package/dist/util/command-processing/command-validation.d.ts +0 -17
- package/dist/util/command-processing/nested-command-parser.d.ts +0 -25
- package/dist/util/command-processing/option-processor.d.ts +0 -44
- package/dist/util/data-processing/list-missing-arguments.d.ts +0 -15
- package/dist/util/data-processing/merge-arguments.d.ts +0 -7
- package/dist/util/general/find-alternatives.d.ts +0 -8
- package/dist/util/general/hide-bin.d.ts +0 -2
- package/dist/util/general/parse-raw-command.d.ts +0 -7
- package/dist/util/general/register-exception-handler.d.ts +0 -9
- package/dist/util/general/runtime-process.d.ts +0 -65
- package/dist/util/general/semver-gt.d.ts +0 -2
- package/dist/util/general/validate-input.d.ts +0 -24
- package/dist/util/process-env-variables.d.ts +0 -9
- package/dist/util/security.d.ts +0 -58
- package/dist/util/text-processing/template-format.d.ts +0 -5
|
@@ -17,7 +17,6 @@ const __cjs_getBuiltinModule = (module) => {
|
|
|
17
17
|
return __cjs_require(module);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
import HelpCommand from '../commands/help-command.js';
|
|
21
20
|
import { VERBOSITY_DEBUG, POSITIONALS_KEY, VERBOSITY_QUIET, VERBOSITY_VERBOSE, VERBOSITY_NORMAL } from './VERBOSITY_QUIET-Dp46zlLW.js';
|
|
22
21
|
import { C as CerebroError } from './cerebro-error-GmJ3jN7Q.js';
|
|
23
22
|
import { d as getEnv, f as getArgv, o as onProcessEvent, e as exitProcess, g as getCwd, h as getExecPath, i as getExecArgv } from './runtime-process-B6ZplyWn.js';
|
|
@@ -1126,12 +1125,26 @@ class EmptyToolbox {
|
|
|
1126
1125
|
env;
|
|
1127
1126
|
logger;
|
|
1128
1127
|
runtime;
|
|
1128
|
+
rawUnknown;
|
|
1129
1129
|
constructor(commandName, command) {
|
|
1130
1130
|
this.commandName = commandName;
|
|
1131
1131
|
this.command = command;
|
|
1132
1132
|
}
|
|
1133
1133
|
}
|
|
1134
1134
|
|
|
1135
|
+
class CommandLoaderError extends CerebroError {
|
|
1136
|
+
commandName;
|
|
1137
|
+
constructor(commandName, reason, cause) {
|
|
1138
|
+
super(`Failed to load command "${commandName}": ${reason}`, "COMMAND_LOADER_ERROR", { commandName, reason });
|
|
1139
|
+
this.name = "CommandLoaderError";
|
|
1140
|
+
this.commandName = commandName;
|
|
1141
|
+
this.hint = `Ensure the loader resolves to a module with a default export that is the command handler function.`;
|
|
1142
|
+
if (cause !== void 0) {
|
|
1143
|
+
this.cause = cause;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1135
1148
|
const argumentNameRegExp = /^-{1,2}(\w+)(=(.+))?$/;
|
|
1136
1149
|
const getParameterOption = (argument, options, optionMapByName, optionMapByAlias) => {
|
|
1137
1150
|
const regExpResult = argumentNameRegExp.exec(argument);
|
|
@@ -1284,15 +1297,36 @@ const buildOptionMaps = (commandOptions) => {
|
|
|
1284
1297
|
}
|
|
1285
1298
|
return { optionMapByAlias, optionMapByName };
|
|
1286
1299
|
};
|
|
1300
|
+
const loadLazyHandler = async (command) => {
|
|
1301
|
+
if (typeof command.__resolvedExecute__ === "function") {
|
|
1302
|
+
return command.__resolvedExecute__;
|
|
1303
|
+
}
|
|
1304
|
+
if (typeof command.loader !== "function") {
|
|
1305
|
+
throw new CommandLoaderError(command.name, "no execute or loader defined");
|
|
1306
|
+
}
|
|
1307
|
+
let loadedModule;
|
|
1308
|
+
try {
|
|
1309
|
+
loadedModule = await command.loader();
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
throw new CommandLoaderError(command.name, error instanceof Error ? error.message : String(error), error);
|
|
1312
|
+
}
|
|
1313
|
+
const handler = loadedModule.default;
|
|
1314
|
+
if (typeof handler !== "function") {
|
|
1315
|
+
throw new CommandLoaderError(command.name, "loader did not return a module with a default-exported handler function");
|
|
1316
|
+
}
|
|
1317
|
+
command.__resolvedExecute__ = handler;
|
|
1318
|
+
return handler;
|
|
1319
|
+
};
|
|
1287
1320
|
const prepareToolbox = (command, parsedArgs, booleanValues, extraOptions) => {
|
|
1288
1321
|
const toolbox = new EmptyToolbox(command.name, command);
|
|
1289
|
-
const { _all, positionals } = parsedArgs;
|
|
1322
|
+
const { _all, _unknown, positionals } = parsedArgs;
|
|
1290
1323
|
const hasBooleanValues = Object.keys(booleanValues).length > 0;
|
|
1291
1324
|
const mergedAll = hasBooleanValues ? { ..._all, ...booleanValues } : _all;
|
|
1292
1325
|
if (POSITIONALS_KEY in mergedAll) {
|
|
1293
1326
|
delete mergedAll[POSITIONALS_KEY];
|
|
1294
1327
|
}
|
|
1295
1328
|
toolbox.argument = positionals?.[POSITIONALS_KEY] ?? [];
|
|
1329
|
+
toolbox.rawUnknown = [..._unknown ?? []];
|
|
1296
1330
|
const hasExtraOptions = Object.keys(extraOptions).length > 0;
|
|
1297
1331
|
toolbox.options = hasExtraOptions ? { ...mergedAll, ...extraOptions } : mergedAll;
|
|
1298
1332
|
toolbox.env = processEnvVariables(command.env);
|
|
@@ -1341,7 +1375,13 @@ const processCommandArgs = (command, commandArguments, defaultOptions) => {
|
|
|
1341
1375
|
});
|
|
1342
1376
|
return { arguments_, booleanValues, parsedArgs };
|
|
1343
1377
|
};
|
|
1344
|
-
const executeCommand = async (command, toolbox, _commandArgs) =>
|
|
1378
|
+
const executeCommand = async (command, toolbox, _commandArgs) => {
|
|
1379
|
+
if (typeof command.execute === "function") {
|
|
1380
|
+
return command.execute(toolbox);
|
|
1381
|
+
}
|
|
1382
|
+
const handler = await loadLazyHandler(command);
|
|
1383
|
+
return handler(toolbox);
|
|
1384
|
+
};
|
|
1345
1385
|
|
|
1346
1386
|
class CommandValidationError extends CerebroError {
|
|
1347
1387
|
commandName;
|
|
@@ -2820,7 +2860,10 @@ class Cli {
|
|
|
2820
2860
|
this.#logger.debug(`command '${pathKey}' found, parsing command args: ${commandArguments.join(", ")}`);
|
|
2821
2861
|
const { arguments_, booleanValues, parsedArgs } = processCommandArgs(command, commandArguments, this.#getAllGlobalOptions());
|
|
2822
2862
|
const hasBooleanValues = Object.keys(booleanValues).length > 0;
|
|
2823
|
-
|
|
2863
|
+
let commandArgs = parsedArgs;
|
|
2864
|
+
if (hasBooleanValues) {
|
|
2865
|
+
commandArgs = { ...parsedArgs, _all: { ...parsedArgs._all, ...booleanValues } };
|
|
2866
|
+
}
|
|
2824
2867
|
validateRequiredOptions(arguments_, commandArgs, command);
|
|
2825
2868
|
const toolbox = prepareToolbox(command, parsedArgs, booleanValues, extraOptions);
|
|
2826
2869
|
toolbox.runtime = this;
|
|
@@ -3004,6 +3047,22 @@ class Cli {
|
|
|
3004
3047
|
addCommand(command) {
|
|
3005
3048
|
validateObject(command, "Command");
|
|
3006
3049
|
validateCommandName(command.name);
|
|
3050
|
+
const hasExecute = typeof command.execute === "function";
|
|
3051
|
+
const hasLoader = typeof command.loader === "function";
|
|
3052
|
+
if (hasExecute && hasLoader) {
|
|
3053
|
+
throw new CerebroError(
|
|
3054
|
+
`Command "${command.name}" cannot define both "execute" and "loader" — choose one`,
|
|
3055
|
+
"INVALID_COMMAND",
|
|
3056
|
+
{ commandName: command.name }
|
|
3057
|
+
);
|
|
3058
|
+
}
|
|
3059
|
+
if (!hasExecute && !hasLoader) {
|
|
3060
|
+
throw new CerebroError(
|
|
3061
|
+
`Command "${command.name}" must define either "execute" or "loader"`,
|
|
3062
|
+
"INVALID_COMMAND",
|
|
3063
|
+
{ commandName: command.name }
|
|
3064
|
+
);
|
|
3065
|
+
}
|
|
3007
3066
|
if (command.alias) {
|
|
3008
3067
|
if (typeof command.alias === "string") {
|
|
3009
3068
|
validateCommandName(command.alias);
|
|
@@ -3102,7 +3161,9 @@ class Cli {
|
|
|
3102
3161
|
}
|
|
3103
3162
|
const existingNames = new Set(this.#customGlobalOptions.map((o) => o.name));
|
|
3104
3163
|
if (existingNames.has(optionDefinition.name)) {
|
|
3105
|
-
throw new CerebroError(`Global option "--${optionDefinition.name}" has already been added`, "DUPLICATE_OPTION", {
|
|
3164
|
+
throw new CerebroError(`Global option "--${optionDefinition.name}" has already been added`, "DUPLICATE_OPTION", {
|
|
3165
|
+
optionName: optionDefinition.name
|
|
3166
|
+
});
|
|
3106
3167
|
}
|
|
3107
3168
|
optionDefinition.group = "global";
|
|
3108
3169
|
mapOptionTypeLabel(optionDefinition);
|
|
@@ -3233,6 +3294,7 @@ class Cli {
|
|
|
3233
3294
|
async run(extraOptions = {}) {
|
|
3234
3295
|
const { autoDispose = true, shouldExitProcess = true, ...otherExtraOptions } = extraOptions;
|
|
3235
3296
|
if (!this.#commands.has("help")) {
|
|
3297
|
+
const { default: HelpCommand } = await import('../commands/help-command.js');
|
|
3236
3298
|
this.addCommand(new HelpCommand(this.#commands));
|
|
3237
3299
|
}
|
|
3238
3300
|
const commandNames = this.#getCommandNames();
|
|
@@ -3314,7 +3376,7 @@ class Cli {
|
|
|
3314
3376
|
throw new CommandNotFoundError(pathKey, alternatives);
|
|
3315
3377
|
}
|
|
3316
3378
|
}
|
|
3317
|
-
if (typeof command.execute !== "function") {
|
|
3379
|
+
if (typeof command.execute !== "function" && typeof command.loader !== "function") {
|
|
3318
3380
|
this.#logger.error(`Command "${command.name}" has no function to execute.`);
|
|
3319
3381
|
return shouldExitProcess ? exitProcess(1) : void 0;
|
|
3320
3382
|
}
|
|
@@ -3396,7 +3458,7 @@ class Cli {
|
|
|
3396
3458
|
const alternatives = findAlternatives(pathKey || commandName, allCommandPaths);
|
|
3397
3459
|
throw new CommandNotFoundError(commandName, alternatives);
|
|
3398
3460
|
}
|
|
3399
|
-
if (typeof command.execute !== "function") {
|
|
3461
|
+
if (typeof command.execute !== "function" && typeof command.loader !== "function") {
|
|
3400
3462
|
throw new CerebroError(`Command "${command.name}" has no function to execute`, "INVALID_COMMAND", { commandName: command.name });
|
|
3401
3463
|
}
|
|
3402
3464
|
const sanitizedArgv = sanitizeArguments(providedArgv);
|
|
@@ -213,7 +213,10 @@ class OptionListSection extends BaseSection {
|
|
|
213
213
|
});
|
|
214
214
|
definitions.forEach((definition) => {
|
|
215
215
|
const typedDefinition = definition;
|
|
216
|
-
table.addRow([
|
|
216
|
+
table.addRow([
|
|
217
|
+
this.getOptionNames(typedDefinition, data.reverseNameOrder ?? false, data.isArgument ?? false),
|
|
218
|
+
templateFormat(typedDefinition.description)
|
|
219
|
+
]);
|
|
217
220
|
});
|
|
218
221
|
this.add(table.toString());
|
|
219
222
|
this.lines.push("");
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
type ColorizeMethod = (value: string) => string;
|
|
2
|
+
type CodeFrameOptions = {
|
|
3
|
+
color?: {
|
|
4
|
+
gutter?: ColorizeMethod;
|
|
5
|
+
marker?: ColorizeMethod;
|
|
6
|
+
message?: ColorizeMethod;
|
|
7
|
+
};
|
|
8
|
+
linesAbove?: number;
|
|
9
|
+
linesBelow?: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
showGutter?: boolean;
|
|
13
|
+
showLineNumbers?: boolean;
|
|
14
|
+
tabWidth?: number | false;
|
|
15
|
+
};
|
|
16
|
+
interface ErrorProperties {
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
hint?: ErrorHint;
|
|
19
|
+
location?: ErrorLocation;
|
|
20
|
+
message?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
stack?: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
}
|
|
25
|
+
interface ErrorLocation {
|
|
26
|
+
column?: number;
|
|
27
|
+
file?: string;
|
|
28
|
+
line?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A message that explains to the user how they can fix the error.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const error = new VisulimaError({
|
|
35
|
+
* hint: "Try running `npm install` to install missing dependencies.",
|
|
36
|
+
* location: {
|
|
37
|
+
* file: "src/index.ts",
|
|
38
|
+
* line: 1,
|
|
39
|
+
* column: 1,
|
|
40
|
+
* },
|
|
41
|
+
* message: "Cannot find module 'react'",
|
|
42
|
+
* name: "ModuleNotFoundError",
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* For more complex hints, you can pass an array of strings or a single string in markdown format.
|
|
47
|
+
*/
|
|
48
|
+
type ErrorHint = string[] | string;
|
|
49
|
+
declare class VisulimaError extends Error {
|
|
50
|
+
loc: ErrorLocation | undefined;
|
|
51
|
+
title: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* A message that explains to the user how they can fix the error.
|
|
54
|
+
*/
|
|
55
|
+
hint: ErrorHint | undefined;
|
|
56
|
+
type: string;
|
|
57
|
+
constructor({
|
|
58
|
+
cause,
|
|
59
|
+
hint,
|
|
60
|
+
location,
|
|
61
|
+
message,
|
|
62
|
+
name,
|
|
63
|
+
stack,
|
|
64
|
+
title
|
|
65
|
+
}: ErrorProperties);
|
|
66
|
+
setLocation(location: ErrorLocation): void;
|
|
67
|
+
setName(name: string): void;
|
|
68
|
+
setMessage(message: string): void;
|
|
69
|
+
setHint(hint: ErrorHint): void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Will return an array of all causes in the error in the order they occurred.
|
|
73
|
+
*/
|
|
74
|
+
type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
|
|
75
|
+
color: CodeFrameOptions["color"] & {
|
|
76
|
+
fileLine: ColorizeMethod;
|
|
77
|
+
hint: ColorizeMethod;
|
|
78
|
+
method: ColorizeMethod;
|
|
79
|
+
title: ColorizeMethod;
|
|
80
|
+
};
|
|
81
|
+
cwd: string;
|
|
82
|
+
displayShortPath: boolean;
|
|
83
|
+
filterStacktrace: ((line: string) => boolean) | undefined;
|
|
84
|
+
framesMaxLimit: number;
|
|
85
|
+
hideErrorCauseCodeView: boolean;
|
|
86
|
+
hideErrorCodeView: boolean;
|
|
87
|
+
hideErrorErrorsCodeView: boolean;
|
|
88
|
+
hideErrorTitle: boolean;
|
|
89
|
+
hideMessage: boolean;
|
|
90
|
+
indentation: number | " ";
|
|
91
|
+
prefix: string;
|
|
92
|
+
};
|
|
93
|
+
export { Options$1 as O, VisulimaError as V };
|