@visulima/cerebro 3.0.0-alpha.11 → 3.0.0-alpha.13

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 (74) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE.md +471 -4345
  3. package/README.md +26 -0
  4. package/dist/commands/completion-command.d.ts +6 -5
  5. package/dist/commands/help-command.d.ts +9 -9
  6. package/dist/commands/help-command.js +63 -1
  7. package/dist/commands/readme-command.d.ts +6 -5
  8. package/dist/commands/readme-command.js +1 -1
  9. package/dist/commands/version-command.d.ts +4 -3
  10. package/dist/index.d.ts +422 -95
  11. package/dist/index.js +2 -1
  12. package/dist/logger/create-pail-logger.d.ts +779 -8
  13. package/dist/packem_shared/{Cerebro-CXEIHSN2.js → Cerebro-C1h3DXwy.js} +66 -8
  14. package/dist/packem_shared/{index-DNXLgme3.js → index--1UArng3.js} +1 -2
  15. package/dist/packem_shared/index.d-Br8HpP0A.d.ts +93 -0
  16. package/dist/packem_shared/lazyNamed-B278Tf9_.js +6 -0
  17. package/dist/packem_shared/plugin-manager.d-Du-YXFui.d.ts +541 -0
  18. package/dist/plugins/error-handler-plugin.d.ts +21 -19
  19. package/dist/plugins/runtime-version-check-plugin.d.ts +22 -20
  20. package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +21 -8
  21. package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -2
  22. package/dist/util/general/compile-cache.d.ts +38 -38
  23. package/dist/util/general/heap-tuning.d.ts +14 -77
  24. package/package.json +18 -18
  25. package/dist/cli.d.ts +0 -225
  26. package/dist/constants.d.ts +0 -29
  27. package/dist/default-env.d.ts +0 -7
  28. package/dist/default-options.d.ts +0 -3
  29. package/dist/empty-toolbox.d.ts +0 -16
  30. package/dist/errors/cerebro-error.d.ts +0 -10
  31. package/dist/errors/command-not-found-error.d.ts +0 -9
  32. package/dist/errors/command-validation-error.d.ts +0 -10
  33. package/dist/errors/completion-error.d.ts +0 -9
  34. package/dist/errors/conflicting-options-error.d.ts +0 -10
  35. package/dist/errors/plugin-error.d.ts +0 -9
  36. package/dist/errors/update-notifier-error.d.ts +0 -7
  37. package/dist/plugin-manager.d.ts +0 -53
  38. package/dist/plugins/update-notifier/cache.d.ts +0 -11
  39. package/dist/plugins/update-notifier/get-distribution-version.d.ts +0 -2
  40. package/dist/plugins/update-notifier/has-new-version.d.ts +0 -14
  41. package/dist/types/cli.d.ts +0 -113
  42. package/dist/types/command-line-usage.d.ts +0 -37
  43. package/dist/types/command.d.ts +0 -136
  44. package/dist/types/option-types.d.ts +0 -83
  45. package/dist/types/options.d.ts +0 -4
  46. package/dist/types/plugin.d.ts +0 -53
  47. package/dist/types/toolbox.d.ts +0 -120
  48. package/dist/util/arg-processing/get-boolean-values.d.ts +0 -7
  49. package/dist/util/arg-processing/get-parameter-option.d.ts +0 -7
  50. package/dist/util/arg-processing/map-option-type-label.d.ts +0 -3
  51. package/dist/util/arg-processing/option-is-boolean.d.ts +0 -9
  52. package/dist/util/arg-processing/remove-boolean-values.d.ts +0 -9
  53. package/dist/util/command-line-commands.d.ts +0 -10
  54. package/dist/util/command-line-usage/get-terminal-width.d.ts +0 -7
  55. package/dist/util/command-line-usage/index.d.ts +0 -3
  56. package/dist/util/command-line-usage/section/base-section.d.ts +0 -8
  57. package/dist/util/command-line-usage/section/content-section.d.ts +0 -65
  58. package/dist/util/command-line-usage/section/option-list-section.d.ts +0 -44
  59. package/dist/util/command-processing/command-processor.d.ts +0 -37
  60. package/dist/util/command-processing/command-validation.d.ts +0 -17
  61. package/dist/util/command-processing/nested-command-parser.d.ts +0 -25
  62. package/dist/util/command-processing/option-processor.d.ts +0 -44
  63. package/dist/util/data-processing/list-missing-arguments.d.ts +0 -15
  64. package/dist/util/data-processing/merge-arguments.d.ts +0 -7
  65. package/dist/util/general/find-alternatives.d.ts +0 -8
  66. package/dist/util/general/hide-bin.d.ts +0 -2
  67. package/dist/util/general/parse-raw-command.d.ts +0 -7
  68. package/dist/util/general/register-exception-handler.d.ts +0 -9
  69. package/dist/util/general/runtime-process.d.ts +0 -65
  70. package/dist/util/general/semver-gt.d.ts +0 -2
  71. package/dist/util/general/validate-input.d.ts +0 -24
  72. package/dist/util/process-env-variables.d.ts +0 -9
  73. package/dist/util/security.d.ts +0 -58
  74. 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 = (_unknown ?? []).slice();
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) => command.execute(toolbox);
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;
@@ -1493,18 +1531,21 @@ const parseNestedCommand = (availableCommands, argv) => {
1493
1531
  return { argv: [], commandPath: void 0 };
1494
1532
  }
1495
1533
  const pathKeyParts = [];
1534
+ let bestMatch;
1496
1535
  for (let depth = 1; depth <= argv.length; depth += 1) {
1497
1536
  const argument = argv[depth - 1];
1498
- if (argument === void 0) {
1537
+ if (argument === void 0 || argument.startsWith("-")) {
1499
1538
  break;
1500
1539
  }
1501
1540
  pathKeyParts.push(argument);
1502
1541
  const pathKey = pathKeyParts.join(" ");
1503
1542
  if (availableCommands.has(pathKey)) {
1504
- const remainingArgv = argv.slice(depth);
1505
- return { argv: remainingArgv, commandPath: [...pathKeyParts] };
1543
+ bestMatch = { commandPath: [...pathKeyParts], depth };
1506
1544
  }
1507
1545
  }
1546
+ if (bestMatch) {
1547
+ return { argv: argv.slice(bestMatch.depth), commandPath: bestMatch.commandPath };
1548
+ }
1508
1549
  return { argv, commandPath: void 0 };
1509
1550
  };
1510
1551
  const getCommandPathKey = (commandPath) => commandPath.join(" ");
@@ -3009,6 +3050,22 @@ class Cli {
3009
3050
  addCommand(command) {
3010
3051
  validateObject(command, "Command");
3011
3052
  validateCommandName(command.name);
3053
+ const hasExecute = typeof command.execute === "function";
3054
+ const hasLoader = typeof command.loader === "function";
3055
+ if (hasExecute && hasLoader) {
3056
+ throw new CerebroError(
3057
+ `Command "${command.name}" cannot define both "execute" and "loader" — choose one`,
3058
+ "INVALID_COMMAND",
3059
+ { commandName: command.name }
3060
+ );
3061
+ }
3062
+ if (!hasExecute && !hasLoader) {
3063
+ throw new CerebroError(
3064
+ `Command "${command.name}" must define either "execute" or "loader"`,
3065
+ "INVALID_COMMAND",
3066
+ { commandName: command.name }
3067
+ );
3068
+ }
3012
3069
  if (command.alias) {
3013
3070
  if (typeof command.alias === "string") {
3014
3071
  validateCommandName(command.alias);
@@ -3240,6 +3297,7 @@ class Cli {
3240
3297
  async run(extraOptions = {}) {
3241
3298
  const { autoDispose = true, shouldExitProcess = true, ...otherExtraOptions } = extraOptions;
3242
3299
  if (!this.#commands.has("help")) {
3300
+ const { default: HelpCommand } = await import('../commands/help-command.js');
3243
3301
  this.addCommand(new HelpCommand(this.#commands));
3244
3302
  }
3245
3303
  const commandNames = this.#getCommandNames();
@@ -3321,7 +3379,7 @@ class Cli {
3321
3379
  throw new CommandNotFoundError(pathKey, alternatives);
3322
3380
  }
3323
3381
  }
3324
- if (typeof command.execute !== "function") {
3382
+ if (typeof command.execute !== "function" && typeof command.loader !== "function") {
3325
3383
  this.#logger.error(`Command "${command.name}" has no function to execute.`);
3326
3384
  return shouldExitProcess ? exitProcess(1) : void 0;
3327
3385
  }
@@ -3403,7 +3461,7 @@ class Cli {
3403
3461
  const alternatives = findAlternatives(pathKey || commandName, allCommandPaths);
3404
3462
  throw new CommandNotFoundError(commandName, alternatives);
3405
3463
  }
3406
- if (typeof command.execute !== "function") {
3464
+ if (typeof command.execute !== "function" && typeof command.loader !== "function") {
3407
3465
  throw new CerebroError(`Command "${command.name}" has no function to execute`, "INVALID_COMMAND", { commandName: command.name });
3408
3466
  }
3409
3467
  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) && // eslint-disable-next-line @typescript-eslint/no-shadow
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 };
@@ -0,0 +1,6 @@
1
+ const lazyNamed = (load, key) => async () => {
2
+ const module_ = await load();
3
+ return { default: module_[key] };
4
+ };
5
+
6
+ export { lazyNamed };