@visulima/cerebro 3.0.0-alpha.11 → 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 +25 -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 +1 -1
- 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-CXEIHSN2.js → Cerebro-f9jDcQQy.js} +60 -5
- package/dist/packem_shared/{index-DNXLgme3.js → index--1UArng3.js} +1 -2
- 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/plugins/update-notifier/update-notifier-plugin.js +1 -2
- package/dist/util/general/compile-cache.d.ts +38 -38
- package/dist/util/general/heap-tuning.d.ts +14 -77
- package/package.json +17 -17
- 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 -16
- 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 -120
- 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';
|
|
@@ -1133,6 +1132,19 @@ class EmptyToolbox {
|
|
|
1133
1132
|
}
|
|
1134
1133
|
}
|
|
1135
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
|
+
|
|
1136
1148
|
const argumentNameRegExp = /^-{1,2}(\w+)(=(.+))?$/;
|
|
1137
1149
|
const getParameterOption = (argument, options, optionMapByName, optionMapByAlias) => {
|
|
1138
1150
|
const regExpResult = argumentNameRegExp.exec(argument);
|
|
@@ -1285,6 +1297,26 @@ const buildOptionMaps = (commandOptions) => {
|
|
|
1285
1297
|
}
|
|
1286
1298
|
return { optionMapByAlias, optionMapByName };
|
|
1287
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
|
+
};
|
|
1288
1320
|
const prepareToolbox = (command, parsedArgs, booleanValues, extraOptions) => {
|
|
1289
1321
|
const toolbox = new EmptyToolbox(command.name, command);
|
|
1290
1322
|
const { _all, _unknown, positionals } = parsedArgs;
|
|
@@ -1294,7 +1326,7 @@ const prepareToolbox = (command, parsedArgs, booleanValues, extraOptions) => {
|
|
|
1294
1326
|
delete mergedAll[POSITIONALS_KEY];
|
|
1295
1327
|
}
|
|
1296
1328
|
toolbox.argument = positionals?.[POSITIONALS_KEY] ?? [];
|
|
1297
|
-
toolbox.rawUnknown =
|
|
1329
|
+
toolbox.rawUnknown = [..._unknown ?? []];
|
|
1298
1330
|
const hasExtraOptions = Object.keys(extraOptions).length > 0;
|
|
1299
1331
|
toolbox.options = hasExtraOptions ? { ...mergedAll, ...extraOptions } : mergedAll;
|
|
1300
1332
|
toolbox.env = processEnvVariables(command.env);
|
|
@@ -1343,7 +1375,13 @@ const processCommandArgs = (command, commandArguments, defaultOptions) => {
|
|
|
1343
1375
|
});
|
|
1344
1376
|
return { arguments_, booleanValues, parsedArgs };
|
|
1345
1377
|
};
|
|
1346
|
-
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
|
+
};
|
|
1347
1385
|
|
|
1348
1386
|
class CommandValidationError extends CerebroError {
|
|
1349
1387
|
commandName;
|
|
@@ -3009,6 +3047,22 @@ class Cli {
|
|
|
3009
3047
|
addCommand(command) {
|
|
3010
3048
|
validateObject(command, "Command");
|
|
3011
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
|
+
}
|
|
3012
3066
|
if (command.alias) {
|
|
3013
3067
|
if (typeof command.alias === "string") {
|
|
3014
3068
|
validateCommandName(command.alias);
|
|
@@ -3240,6 +3294,7 @@ class Cli {
|
|
|
3240
3294
|
async run(extraOptions = {}) {
|
|
3241
3295
|
const { autoDispose = true, shouldExitProcess = true, ...otherExtraOptions } = extraOptions;
|
|
3242
3296
|
if (!this.#commands.has("help")) {
|
|
3297
|
+
const { default: HelpCommand } = await import('../commands/help-command.js');
|
|
3243
3298
|
this.addCommand(new HelpCommand(this.#commands));
|
|
3244
3299
|
}
|
|
3245
3300
|
const commandNames = this.#getCommandNames();
|
|
@@ -3321,7 +3376,7 @@ class Cli {
|
|
|
3321
3376
|
throw new CommandNotFoundError(pathKey, alternatives);
|
|
3322
3377
|
}
|
|
3323
3378
|
}
|
|
3324
|
-
if (typeof command.execute !== "function") {
|
|
3379
|
+
if (typeof command.execute !== "function" && typeof command.loader !== "function") {
|
|
3325
3380
|
this.#logger.error(`Command "${command.name}" has no function to execute.`);
|
|
3326
3381
|
return shouldExitProcess ? exitProcess(1) : void 0;
|
|
3327
3382
|
}
|
|
@@ -3403,7 +3458,7 @@ class Cli {
|
|
|
3403
3458
|
const alternatives = findAlternatives(pathKey || commandName, allCommandPaths);
|
|
3404
3459
|
throw new CommandNotFoundError(commandName, alternatives);
|
|
3405
3460
|
}
|
|
3406
|
-
if (typeof command.execute !== "function") {
|
|
3461
|
+
if (typeof command.execute !== "function" && typeof command.loader !== "function") {
|
|
3407
3462
|
throw new CerebroError(`Command "${command.name}" has no function to execute`, "INVALID_COMMAND", { commandName: command.name });
|
|
3408
3463
|
}
|
|
3409
3464
|
const sanitizedArgv = sanitizeArguments(providedArgv);
|
|
@@ -124,8 +124,7 @@ class ContentSection extends BaseSection {
|
|
|
124
124
|
table.addRow([templateFormat(content)]);
|
|
125
125
|
return table.toString();
|
|
126
126
|
}
|
|
127
|
-
if (Array.isArray(content) &&
|
|
128
|
-
content.every((value) => typeof value === "string" || Array.isArray(value) && value.every((value2) => typeof value2 === "string"))) {
|
|
127
|
+
if (Array.isArray(content) && content.every((value) => typeof value === "string" || Array.isArray(value) && value.every((value2) => typeof value2 === "string"))) {
|
|
129
128
|
const table = createTable({
|
|
130
129
|
showHeader: false,
|
|
131
130
|
style: {
|
|
@@ -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 };
|