@oclif/core 3.26.6 → 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.
Files changed (124) hide show
  1. package/lib/args.d.ts +4 -4
  2. package/lib/cache.d.ts +3 -3
  3. package/lib/cache.js +1 -1
  4. package/lib/command.d.ts +18 -18
  5. package/lib/command.js +12 -21
  6. package/lib/config/config.d.ts +14 -40
  7. package/lib/config/config.js +120 -153
  8. package/lib/config/plugin-loader.d.ts +6 -6
  9. package/lib/config/plugin-loader.js +4 -28
  10. package/lib/config/plugin.d.ts +3 -3
  11. package/lib/config/plugin.js +7 -11
  12. package/lib/config/ts-path.d.ts +1 -1
  13. package/lib/config/ts-path.js +1 -2
  14. package/lib/config/util.d.ts +1 -1
  15. package/lib/config/util.js +5 -21
  16. package/lib/errors/error.js +5 -8
  17. package/lib/errors/errors/cli.d.ts +5 -5
  18. package/lib/errors/errors/cli.js +5 -5
  19. package/lib/errors/errors/pretty-print.d.ts +2 -2
  20. package/lib/errors/errors/pretty-print.js +2 -2
  21. package/lib/errors/exit.d.ts +1 -0
  22. package/lib/errors/exit.js +8 -0
  23. package/lib/errors/handle.js +4 -11
  24. package/lib/errors/index.d.ts +1 -3
  25. package/lib/errors/index.js +5 -12
  26. package/lib/errors/warn.d.ts +5 -0
  27. package/lib/errors/warn.js +10 -5
  28. package/lib/execute.js +1 -1
  29. package/lib/flags.d.ts +4 -4
  30. package/lib/{cli-ux/flush.js → flush.js} +2 -2
  31. package/lib/help/command.js +6 -5
  32. package/lib/help/formatter.d.ts +3 -3
  33. package/lib/help/formatter.js +8 -9
  34. package/lib/help/index.d.ts +1 -0
  35. package/lib/help/index.js +23 -17
  36. package/lib/help/root.js +3 -3
  37. package/lib/index.d.ts +6 -7
  38. package/lib/index.js +8 -12
  39. package/lib/interfaces/config.d.ts +9 -20
  40. package/lib/interfaces/errors.d.ts +5 -5
  41. package/lib/interfaces/flags.d.ts +2 -2
  42. package/lib/interfaces/index.d.ts +2 -1
  43. package/lib/interfaces/logger.d.ts +9 -0
  44. package/lib/interfaces/parser.d.ts +6 -6
  45. package/lib/interfaces/pjson.d.ts +217 -151
  46. package/lib/interfaces/plugin.d.ts +26 -24
  47. package/lib/interfaces/theme.d.ts +30 -19
  48. package/lib/interfaces/theme.js +2 -19
  49. package/lib/interfaces/topic.d.ts +2 -2
  50. package/lib/logger.d.ts +14 -0
  51. package/lib/logger.js +90 -0
  52. package/lib/main.js +5 -3
  53. package/lib/parser/errors.d.ts +1 -1
  54. package/lib/parser/errors.js +5 -5
  55. package/lib/parser/help.js +2 -2
  56. package/lib/parser/parse.js +2 -1
  57. package/lib/performance.js +3 -2
  58. package/lib/settings.d.ts +5 -11
  59. package/lib/util/determine-priority.d.ts +21 -0
  60. package/lib/util/determine-priority.js +55 -0
  61. package/lib/util/find-root.d.ts +1 -0
  62. package/lib/util/find-root.js +19 -19
  63. package/lib/util/fs.js +12 -0
  64. package/lib/util/ids.d.ts +1 -1
  65. package/lib/util/read-pjson.d.ts +7 -0
  66. package/lib/util/read-pjson.js +60 -0
  67. package/lib/util/read-tsconfig.js +3 -8
  68. package/lib/{cli-ux → ux}/action/base.d.ts +5 -7
  69. package/lib/{cli-ux → ux}/action/base.js +0 -3
  70. package/lib/{cli-ux → ux}/action/spinner.d.ts +5 -4
  71. package/lib/{cli-ux → ux}/action/spinner.js +16 -39
  72. package/lib/ux/action/types.d.ts +5 -0
  73. package/lib/ux/action/types.js +2 -0
  74. package/lib/ux/colorize-json.d.ts +28 -0
  75. package/lib/ux/colorize-json.js +67 -0
  76. package/lib/ux/index.d.ts +69 -0
  77. package/lib/ux/index.js +88 -0
  78. package/lib/{cli-ux → ux}/list.d.ts +1 -1
  79. package/lib/{cli-ux → ux}/list.js +1 -2
  80. package/lib/ux/theme.d.ts +9 -0
  81. package/lib/ux/theme.js +43 -0
  82. package/lib/ux/write.d.ts +2 -0
  83. package/lib/ux/write.js +22 -0
  84. package/package.json +37 -42
  85. package/flush.d.ts +0 -3
  86. package/flush.js +0 -1
  87. package/handle.js +0 -1
  88. package/lib/cli-ux/action/spinners.d.ts +0 -251
  89. package/lib/cli-ux/action/spinners.js +0 -374
  90. package/lib/cli-ux/action/types.d.ts +0 -5
  91. package/lib/cli-ux/config.d.ts +0 -25
  92. package/lib/cli-ux/config.js +0 -52
  93. package/lib/cli-ux/exit.d.ts +0 -8
  94. package/lib/cli-ux/exit.js +0 -16
  95. package/lib/cli-ux/index.d.ts +0 -133
  96. package/lib/cli-ux/index.js +0 -183
  97. package/lib/cli-ux/prompt.d.ts +0 -32
  98. package/lib/cli-ux/prompt.js +0 -185
  99. package/lib/cli-ux/stream.d.ts +0 -23
  100. package/lib/cli-ux/stream.js +0 -43
  101. package/lib/cli-ux/styled/index.d.ts +0 -4
  102. package/lib/cli-ux/styled/index.js +0 -36
  103. package/lib/cli-ux/styled/object.d.ts +0 -1
  104. package/lib/cli-ux/styled/object.js +0 -39
  105. package/lib/cli-ux/styled/progress.d.ts +0 -2
  106. package/lib/cli-ux/styled/progress.js +0 -8
  107. package/lib/cli-ux/styled/table.d.ts +0 -45
  108. package/lib/cli-ux/styled/table.js +0 -345
  109. package/lib/cli-ux/styled/tree.d.ts +0 -9
  110. package/lib/cli-ux/styled/tree.js +0 -37
  111. package/lib/cli-ux/theme.d.ts +0 -11
  112. package/lib/cli-ux/theme.js +0 -61
  113. package/lib/cli-ux/wait.d.ts +0 -2
  114. package/lib/cli-ux/wait.js +0 -5
  115. package/lib/cli-ux/write.d.ts +0 -8
  116. package/lib/cli-ux/write.js +0 -15
  117. package/lib/errors/config.d.ts +0 -6
  118. package/lib/errors/config.js +0 -38
  119. package/lib/errors/logger.d.ts +0 -8
  120. package/lib/errors/logger.js +0 -45
  121. /package/lib/{cli-ux/flush.d.ts → flush.d.ts} +0 -0
  122. /package/lib/{cli-ux/action/types.js → interfaces/logger.js} +0 -0
  123. /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
  124. /package/lib/{cli-ux → ux}/action/simple.js +0 -0
@@ -1,21 +1,32 @@
1
- export declare const STANDARD_CHALK: readonly ["white", "black", "blue", "yellow", "green", "red", "magenta", "cyan", "gray", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite", "bgGray", "bgBlackBright", "bgRedBright", "bgGreenBright", "bgYellowBright", "bgBlueBright", "bgMagentaBright", "bgCyanBright", "bgWhiteBright", "bold", "underline", "dim", "italic", "strikethrough"];
2
- export type StandardChalk = (typeof STANDARD_CHALK)[number];
3
- export declare const THEME_KEYS: readonly ["alias", "bin", "command", "commandSummary", "dollarSign", "flag", "flagDefaultValue", "flagOptions", "flagRequired", "flagSeparator", "sectionDescription", "sectionHeader", "topic", "version"];
4
- export type ThemeKey = (typeof THEME_KEYS)[number];
1
+ export declare const STANDARD_ANSI: readonly ["white", "black", "blue", "yellow", "green", "red", "magenta", "cyan", "gray", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite", "bgGray", "bgBlackBright", "bgRedBright", "bgGreenBright", "bgYellowBright", "bgBlueBright", "bgMagentaBright", "bgCyanBright", "bgWhiteBright", "bold", "underline", "dim", "italic", "strikethrough"];
2
+ export type StandardAnsi = (typeof STANDARD_ANSI)[number];
3
+ export type JsonTheme = {
4
+ brace?: string | StandardAnsi;
5
+ bracket?: string | StandardAnsi;
6
+ colon?: string | StandardAnsi;
7
+ comma?: string | StandardAnsi;
8
+ key?: string | StandardAnsi;
9
+ string?: string | StandardAnsi;
10
+ number?: string | StandardAnsi;
11
+ boolean?: string | StandardAnsi;
12
+ null?: string | StandardAnsi;
13
+ };
5
14
  export type Theme = {
6
- [key: string | ThemeKey]: string | StandardChalk | undefined;
7
- alias?: string | StandardChalk;
8
- bin?: string | StandardChalk;
9
- command?: string | StandardChalk;
10
- commandSummary?: string | StandardChalk;
11
- dollarSign?: string | StandardChalk;
12
- flag?: string | StandardChalk;
13
- flagDefaultValue?: string | StandardChalk;
14
- flagOptions?: string | StandardChalk;
15
- flagRequired?: string | StandardChalk;
16
- flagSeparator?: string | StandardChalk;
17
- sectionDescription?: string | StandardChalk;
18
- sectionHeader?: string | StandardChalk;
19
- topic?: string | StandardChalk;
20
- version?: string | StandardChalk;
15
+ [key: string]: string | StandardAnsi | Theme | undefined;
16
+ alias?: string | StandardAnsi;
17
+ bin?: string | StandardAnsi;
18
+ command?: string | StandardAnsi;
19
+ commandSummary?: string | StandardAnsi;
20
+ dollarSign?: string | StandardAnsi;
21
+ flag?: string | StandardAnsi;
22
+ flagDefaultValue?: string | StandardAnsi;
23
+ flagOptions?: string | StandardAnsi;
24
+ flagRequired?: string | StandardAnsi;
25
+ flagSeparator?: string | StandardAnsi;
26
+ json?: JsonTheme;
27
+ sectionDescription?: string | StandardAnsi;
28
+ sectionHeader?: string | StandardAnsi;
29
+ spinner?: string | StandardAnsi;
30
+ topic?: string | StandardAnsi;
31
+ version?: string | StandardAnsi;
21
32
  };
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.THEME_KEYS = exports.STANDARD_CHALK = void 0;
4
- // chalk doesn't export a list of standard colors, so we have to supply our own
5
- exports.STANDARD_CHALK = [
3
+ exports.STANDARD_ANSI = void 0;
4
+ exports.STANDARD_ANSI = [
6
5
  'white',
7
6
  'black',
8
7
  'blue',
@@ -43,19 +42,3 @@ exports.STANDARD_CHALK = [
43
42
  'italic',
44
43
  'strikethrough',
45
44
  ];
46
- exports.THEME_KEYS = [
47
- 'alias',
48
- 'bin',
49
- 'command',
50
- 'commandSummary',
51
- 'dollarSign',
52
- 'flag',
53
- 'flagDefaultValue',
54
- 'flagOptions',
55
- 'flagRequired',
56
- 'flagSeparator',
57
- 'sectionDescription',
58
- 'sectionHeader',
59
- 'topic',
60
- 'version',
61
- ];
@@ -1,5 +1,5 @@
1
1
  export interface Topic {
2
- description?: string;
3
- hidden?: boolean;
2
+ description?: string | undefined;
3
+ hidden?: boolean | undefined;
4
4
  name: string;
5
5
  }
@@ -0,0 +1,14 @@
1
+ import { LoadOptions } from './interfaces/config';
2
+ import { Logger } from './interfaces/logger';
3
+ /**
4
+ * Returns a logger instance for the given namespace.
5
+ * If a namespace is provided, a child logger is returned.
6
+ * If no namespace is provided, the root logger is returned.
7
+ */
8
+ export declare function getLogger(namespace?: string): Logger;
9
+ /**
10
+ * Convenience function to create a debug function for a specific namespace
11
+ */
12
+ export declare function makeDebug(namespace: string): Logger['debug'];
13
+ export declare function setLogger(loadOptions: LoadOptions): void;
14
+ export declare function clearLoggers(): void;
package/lib/logger.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clearLoggers = exports.setLogger = exports.makeDebug = exports.getLogger = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const OCLIF_NS = 'oclif';
9
+ function makeLogger(namespace = OCLIF_NS) {
10
+ const debug = (0, debug_1.default)(namespace);
11
+ return {
12
+ child: (ns, delimiter) => makeLogger(`${namespace}${delimiter ?? ':'}${ns}`),
13
+ debug,
14
+ error: (formatter, ...args) => makeLogger(`${namespace}:error`).debug(formatter, ...args),
15
+ info: debug,
16
+ namespace,
17
+ trace: debug,
18
+ warn: debug,
19
+ };
20
+ }
21
+ /**
22
+ * Cache of logger instances. This is used to prevent creating multiple logger instances for the same namespace.
23
+ *
24
+ * The root logger is stored under the 'root' key as well as it's namespace.
25
+ */
26
+ const cachedLoggers = new Map();
27
+ /**
28
+ * Returns a logger instance for the given namespace.
29
+ * If a namespace is provided, a child logger is returned.
30
+ * If no namespace is provided, the root logger is returned.
31
+ */
32
+ function getLogger(namespace) {
33
+ let rootLogger = cachedLoggers.get('root');
34
+ if (!rootLogger) {
35
+ set(makeLogger(OCLIF_NS));
36
+ }
37
+ rootLogger = cachedLoggers.get('root');
38
+ if (namespace) {
39
+ const cachedLogger = cachedLoggers.get(namespace);
40
+ if (cachedLogger)
41
+ return cachedLogger;
42
+ const logger = rootLogger.child(namespace);
43
+ cachedLoggers.set(namespace, logger);
44
+ return logger;
45
+ }
46
+ return rootLogger;
47
+ }
48
+ exports.getLogger = getLogger;
49
+ function ensureItMatchesInterface(newLogger) {
50
+ return (typeof newLogger.child === 'function' &&
51
+ typeof newLogger.debug === 'function' &&
52
+ typeof newLogger.error === 'function' &&
53
+ typeof newLogger.info === 'function' &&
54
+ typeof newLogger.trace === 'function' &&
55
+ typeof newLogger.warn === 'function' &&
56
+ typeof newLogger.namespace === 'string');
57
+ }
58
+ function set(newLogger) {
59
+ if (cachedLoggers.has(newLogger.namespace))
60
+ return;
61
+ if (cachedLoggers.has('root'))
62
+ return;
63
+ if (ensureItMatchesInterface(newLogger)) {
64
+ cachedLoggers.set(newLogger.namespace, newLogger);
65
+ cachedLoggers.set('root', newLogger);
66
+ }
67
+ else {
68
+ process.emitWarning('Logger does not match the Logger interface. Using default logger.');
69
+ }
70
+ }
71
+ /**
72
+ * Convenience function to create a debug function for a specific namespace
73
+ */
74
+ function makeDebug(namespace) {
75
+ return (formatter, ...args) => getLogger(namespace).debug(formatter, ...args);
76
+ }
77
+ exports.makeDebug = makeDebug;
78
+ function setLogger(loadOptions) {
79
+ if (loadOptions && typeof loadOptions !== 'string' && 'logger' in loadOptions && loadOptions.logger) {
80
+ set(loadOptions.logger);
81
+ }
82
+ else {
83
+ set(makeLogger(OCLIF_NS));
84
+ }
85
+ }
86
+ exports.setLogger = setLogger;
87
+ function clearLoggers() {
88
+ cachedLoggers.clear();
89
+ }
90
+ exports.clearLoggers = clearLoggers;
package/lib/main.js CHANGED
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.run = exports.versionAddition = exports.helpAddition = void 0;
7
7
  const node_url_1 = require("node:url");
8
8
  const cache_1 = __importDefault(require("./cache"));
9
- const cli_ux_1 = require("./cli-ux");
10
9
  const config_1 = require("./config");
11
10
  const help_1 = require("./help");
11
+ const logger_1 = require("./logger");
12
12
  const performance_1 = require("./performance");
13
13
  const symbols_1 = require("./symbols");
14
- const debug = require('debug')('oclif:main');
14
+ const ux_1 = require("./ux");
15
15
  const helpAddition = (argv, config) => {
16
16
  if (argv.length === 0 && !config.isSingleCommandCLI)
17
17
  return true;
@@ -48,6 +48,8 @@ async function run(argv, options) {
48
48
  const help = new Help(config, config.pjson.oclif.helpOptions ?? config.pjson.helpOptions);
49
49
  await help.showHelp(argv);
50
50
  };
51
+ (0, logger_1.setLogger)(options);
52
+ const { debug } = (0, logger_1.getLogger)('main');
51
53
  debug(`process.execPath: ${process.execPath}`);
52
54
  debug(`process.execArgv: ${process.execArgv}`);
53
55
  debug('process.argv: %O', process.argv);
@@ -67,7 +69,7 @@ async function run(argv, options) {
67
69
  await config.runHook('init', { argv: argvSlice, id });
68
70
  // display version if applicable
69
71
  if ((0, exports.versionAddition)(argv, config)) {
70
- cli_ux_1.ux.log(config.userAgent);
72
+ ux_1.ux.stdout(config.userAgent);
71
73
  await collectPerf();
72
74
  return;
73
75
  }
@@ -3,7 +3,7 @@ import { Arg, ArgInput, CLIParseErrorOptions, OptionFlag } from '../interfaces/p
3
3
  export { CLIError } from '../errors';
4
4
  export type Validation = {
5
5
  name: string;
6
- reason?: string;
6
+ reason?: string | undefined;
7
7
  status: 'failed' | 'success';
8
8
  validationFn: string;
9
9
  };
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const ansis_1 = __importDefault(require("ansis"));
8
8
  const cache_1 = __importDefault(require("../cache"));
9
- const list_1 = require("../cli-ux/list");
10
9
  const errors_1 = require("../errors");
11
10
  const util_1 = require("../util/util");
11
+ const list_1 = __importDefault(require("../ux/list"));
12
12
  var errors_2 = require("../errors");
13
13
  Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
14
14
  class CLIParseError extends errors_1.CLIError {
@@ -27,7 +27,7 @@ class InvalidArgsSpecError extends CLIParseError {
27
27
  let message = 'Invalid argument spec';
28
28
  const namedArgs = Object.values(args).filter((a) => a.name);
29
29
  if (namedArgs.length > 0) {
30
- const list = (0, list_1.renderList)(namedArgs.map((a) => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
30
+ const list = (0, list_1.default)(namedArgs.map((a) => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
31
31
  message += `:\n${list}`;
32
32
  }
33
33
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.invalidArgsSpec ?? exit, message, parse });
@@ -41,7 +41,7 @@ class RequiredArgsError extends CLIParseError {
41
41
  let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
42
42
  const namedArgs = args.filter((a) => a.name);
43
43
  if (namedArgs.length > 0) {
44
- const list = (0, list_1.renderList)(namedArgs.map((a) => {
44
+ const list = (0, list_1.default)(namedArgs.map((a) => {
45
45
  const description = a.options ? `(${a.options.join('|')}) ${a.description}` : a.description;
46
46
  return [a.name, description];
47
47
  }));
@@ -97,7 +97,7 @@ class FailedFlagValidationError extends CLIParseError {
97
97
  const reasons = failed.map((r) => r.reason);
98
98
  const deduped = (0, util_1.uniq)(reasons);
99
99
  const errString = deduped.length === 1 ? 'error' : 'errors';
100
- const message = `The following ${errString} occurred:\n ${chalk_1.default.dim(deduped.join('\n '))}`;
100
+ const message = `The following ${errString} occurred:\n ${ansis_1.default.dim(deduped.join('\n '))}`;
101
101
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.failedFlagValidation ?? exit, message, parse });
102
102
  }
103
103
  }
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.flagUsages = exports.flagUsage = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const ansis_1 = __importDefault(require("ansis"));
8
8
  const util_1 = require("../util/util");
9
9
  function flagUsage(flag, options = {}) {
10
10
  const label = [];
@@ -21,7 +21,7 @@ function flagUsage(flag, options = {}) {
21
21
  let description = flag.summary || flag.description || '';
22
22
  if (options.displayRequired && flag.required)
23
23
  description = `(required) ${description}`;
24
- description = description ? chalk_1.default.dim(description) : undefined;
24
+ description = description ? ansis_1.default.dim(description) : undefined;
25
25
  return [` ${label.join(',').trim()}${usage}`, description];
26
26
  }
27
27
  exports.flagUsage = flagUsage;
@@ -7,13 +7,14 @@ exports.Parser = exports.readStdin = void 0;
7
7
  /* eslint-disable no-await-in-loop */
8
8
  const node_readline_1 = require("node:readline");
9
9
  const cache_1 = __importDefault(require("../cache"));
10
+ const logger_1 = require("../logger");
10
11
  const util_1 = require("../util/util");
11
12
  const errors_1 = require("./errors");
12
13
  let debug;
13
14
  try {
14
15
  debug =
15
16
  process.env.CLI_FLAGS_DEBUG === '1'
16
- ? require('debug')('../parser')
17
+ ? (0, logger_1.makeDebug)('parser')
17
18
  : () => {
18
19
  // noop
19
20
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Performance = exports.OCLIF_MARKER_OWNER = void 0;
4
4
  const node_perf_hooks_1 = require("node:perf_hooks");
5
+ const logger_1 = require("./logger");
5
6
  const settings_1 = require("./settings");
6
7
  exports.OCLIF_MARKER_OWNER = '@oclif/core';
7
8
  class Marker {
@@ -143,7 +144,7 @@ class Performance {
143
144
  static debug() {
144
145
  if (!Performance.enabled)
145
146
  return;
146
- const oclifDebug = require('debug')('oclif-perf');
147
+ const oclifDebug = (0, logger_1.makeDebug)('perf');
147
148
  const processUpTime = (process.uptime() * 1000).toFixed(4);
148
149
  oclifDebug('Process Uptime: %sms', processUpTime);
149
150
  oclifDebug('Oclif Time: %sms', Performance.oclifPerf['oclif.runMs'].toFixed(4));
@@ -176,7 +177,7 @@ class Performance {
176
177
  if (Performance.oclifPerf['oclif.configLoadMs'] > Performance.oclifPerf['oclif.runMs']) {
177
178
  oclifDebug('! Config load time is greater than total oclif time. This might mean that Config was instantiated before oclif was run.');
178
179
  }
179
- const nonCoreDebug = require('debug')('non-oclif-perf');
180
+ const nonCoreDebug = (0, logger_1.makeDebug)('non-oclif-perf');
180
181
  const nonCorePerf = Performance.results;
181
182
  if (nonCorePerf.size > 0) {
182
183
  nonCoreDebug('Non-Core Performance Measurements:');
package/lib/settings.d.ts CHANGED
@@ -5,25 +5,19 @@ export type Settings = {
5
5
  * Environment Variable:
6
6
  * OCLIF_COLUMNS=80
7
7
  */
8
- columns?: number;
8
+ columns?: number | undefined;
9
9
  /**
10
10
  * Show additional debug output without DEBUG. Mainly shows stackstraces.
11
11
  *
12
12
  * Useful to set in the ./bin/dev.js script.
13
13
  * oclif.settings.debug = true;
14
14
  */
15
- debug?: boolean;
16
- /**
17
- * The path to the error.log file.
18
- *
19
- * NOTE: This is read-only and setting it will have no effect.
20
- */
21
- errlog?: string;
15
+ debug?: boolean | undefined;
22
16
  /**
23
17
  * Enable performance tracking. Resulting data is available in the `perf` property of the `Config` class.
24
18
  * This will be overridden by the `enablePerf` property passed into Config constructor.
25
19
  */
26
- performanceEnabled?: boolean;
20
+ performanceEnabled?: boolean | undefined;
27
21
  /**
28
22
  * Try to use ts-node to load typescript source files instead of javascript files.
29
23
  * Defaults to true in development and test environments (e.g. using bin/dev.js or
@@ -31,12 +25,12 @@ export type Settings = {
31
25
  *
32
26
  * @deprecated use enableAutoTranspile instead.
33
27
  */
34
- tsnodeEnabled?: boolean;
28
+ tsnodeEnabled?: boolean | undefined;
35
29
  /**
36
30
  * Enable automatic transpilation of TypeScript files to JavaScript.
37
31
  *
38
32
  * Defaults to true in development and test environments (e.g. using bin/dev.js or NODE_ENV=development or NODE_ENV=test).
39
33
  */
40
- enableAutoTranspile?: boolean;
34
+ enableAutoTranspile?: boolean | undefined;
41
35
  };
42
36
  export declare const settings: Settings;
@@ -0,0 +1,21 @@
1
+ import { Command } from '../command';
2
+ /**
3
+ * This function is responsible for locating the correct plugin to use for a named command id
4
+ * It searches the {Config} registered commands to match either the raw command id or the command alias
5
+ * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
6
+ * create the same command or command alias.
7
+ *
8
+ * In the case of more than one found command, the function will select the command based on the order in which
9
+ * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
10
+ * is selected as the command to run.
11
+ *
12
+ * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
13
+ * is present, this function defers to the core plugin.
14
+ *
15
+ * If there is not a core plugin command present, this function will return the first
16
+ * plugin as discovered (will not change the order)
17
+ *
18
+ * @param commands commands to determine the priority of
19
+ * @returns command instance {Command.Loadable} or undefined
20
+ */
21
+ export declare function determinePriority(plugins: string[], commands: Command.Loadable[]): Command.Loadable;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determinePriority = void 0;
4
+ /**
5
+ * This function is responsible for locating the correct plugin to use for a named command id
6
+ * It searches the {Config} registered commands to match either the raw command id or the command alias
7
+ * It is possible that more than one command will be found. This is due the ability of two distinct plugins to
8
+ * create the same command or command alias.
9
+ *
10
+ * In the case of more than one found command, the function will select the command based on the order in which
11
+ * the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
12
+ * is selected as the command to run.
13
+ *
14
+ * Commands can also be present from either an install or a link. When a command is one of these and a core plugin
15
+ * is present, this function defers to the core plugin.
16
+ *
17
+ * If there is not a core plugin command present, this function will return the first
18
+ * plugin as discovered (will not change the order)
19
+ *
20
+ * @param commands commands to determine the priority of
21
+ * @returns command instance {Command.Loadable} or undefined
22
+ */
23
+ function determinePriority(plugins, commands) {
24
+ const commandPlugins = commands.sort((a, b) => {
25
+ const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
26
+ const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
27
+ const aIndex = plugins.indexOf(pluginAliasA);
28
+ const bIndex = plugins.indexOf(pluginAliasB);
29
+ // When both plugin types are 'core' plugins sort based on index
30
+ if (a.pluginType === 'core' && b.pluginType === 'core') {
31
+ // If b appears first in the pjson.plugins sort it first
32
+ return aIndex - bIndex;
33
+ }
34
+ // if b is a core plugin and a is not sort b first
35
+ if (b.pluginType === 'core' && a.pluginType !== 'core') {
36
+ return 1;
37
+ }
38
+ // if a is a core plugin and b is not sort a first
39
+ if (a.pluginType === 'core' && b.pluginType !== 'core') {
40
+ return -1;
41
+ }
42
+ // if a is a jit plugin and b is not sort b first
43
+ if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
44
+ return 1;
45
+ }
46
+ // if b is a jit plugin and a is not sort a first
47
+ if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
48
+ return -1;
49
+ }
50
+ // neither plugin is core, so do not change the order
51
+ return 0;
52
+ });
53
+ return commandPlugins[0];
54
+ }
55
+ exports.determinePriority = determinePriority;
@@ -1,3 +1,4 @@
1
+ export declare function debug(...scope: string[]): (..._: any) => void;
1
2
  /**
2
3
  * Returns the root directory of the plugin.
3
4
  *
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findRoot = void 0;
7
- const debug_1 = __importDefault(require("debug"));
3
+ exports.findRoot = exports.debug = void 0;
8
4
  const node_path_1 = require("node:path");
5
+ const logger_1 = require("../logger");
9
6
  const fs_1 = require("./fs");
10
- const debug = (0, debug_1.default)('find-root');
7
+ function debug(...scope) {
8
+ return (formatter, ...args) => (0, logger_1.getLogger)(['find-root', ...scope].join(':')).debug(formatter, ...args);
9
+ }
10
+ exports.debug = debug;
11
11
  // essentially just "cd .."
12
12
  function* up(from) {
13
13
  while ((0, node_path_1.dirname)(from) !== from) {
@@ -25,11 +25,11 @@ function* up(from) {
25
25
  async function findPluginRoot(root, name) {
26
26
  // If we know the plugin name then we just need to traverse the file
27
27
  // system until we find the directory that matches the plugin name.
28
- debug.extend(name ?? 'root-plugin')(`Finding root starting at ${root}`);
28
+ debug(name ?? 'root-plugin')(`Finding root starting at ${root}`);
29
29
  if (name) {
30
30
  for (const next of up(root)) {
31
31
  if (next.endsWith((0, node_path_1.basename)(name))) {
32
- debug.extend(name)('Found root based on plugin name!');
32
+ debug(name)('Found root based on plugin name!');
33
33
  return next;
34
34
  }
35
35
  }
@@ -44,9 +44,9 @@ async function findPluginRoot(root, name) {
44
44
  }
45
45
  try {
46
46
  const cur = (0, node_path_1.join)(next, 'package.json');
47
- debug.extend(name ?? 'root-plugin')(`Checking ${cur}`);
47
+ debug(name ?? 'root-plugin')(`Checking ${cur}`);
48
48
  if (await (0, fs_1.safeReadJson)(cur)) {
49
- debug.extend(name ?? 'root-plugin')('Found root by traversing up from starting point!');
49
+ debug(name ?? 'root-plugin')('Found root by traversing up from starting point!');
50
50
  return (0, node_path_1.dirname)(cur);
51
51
  }
52
52
  }
@@ -60,7 +60,7 @@ async function findPluginRoot(root, name) {
60
60
  * See https://github.com/oclif/config/pull/289#issuecomment-983904051
61
61
  */
62
62
  async function findRootLegacy(name, root) {
63
- debug.extend(name ?? 'root-plugin')('Finding root using legacy method');
63
+ debug(name ?? 'root-plugin')('Finding root using legacy method');
64
64
  for (const next of up(root)) {
65
65
  let cur;
66
66
  if (name) {
@@ -106,7 +106,7 @@ function findPnpRoot(name, root) {
106
106
  maybeRequirePnpApi(root);
107
107
  if (!pnp)
108
108
  return;
109
- debug.extend(name)('Finding root for using pnp method');
109
+ debug(name)('Finding root for using pnp method');
110
110
  const seen = new Set();
111
111
  const traverseDependencyTree = (locator, parentPkg) => {
112
112
  // Prevent infinite recursion when A depends on B which depends on A
@@ -158,29 +158,29 @@ function findPnpRoot(name, root) {
158
158
  */
159
159
  async function findRoot(name, root) {
160
160
  if (name) {
161
- debug.extend(name)(`Finding root using ${root}`);
161
+ debug(name)(`Finding root using ${root}`);
162
162
  let pkgPath;
163
163
  try {
164
164
  pkgPath = require.resolve(name, { paths: [root] });
165
- debug.extend(name)(`Found starting point with require.resolve`);
165
+ debug(name)(`Found starting point with require.resolve`);
166
166
  }
167
167
  catch {
168
- debug.extend(name)(`require.resolve could not find plugin starting point`);
168
+ debug(name)(`require.resolve could not find plugin starting point`);
169
169
  }
170
170
  if (pkgPath) {
171
171
  const found = await findPluginRoot((0, node_path_1.dirname)(pkgPath), name);
172
172
  if (found) {
173
- debug.extend(name)(`Found root at ${found}`);
173
+ debug(name)(`Found root at ${found}`);
174
174
  return found;
175
175
  }
176
176
  }
177
177
  const found = process.versions.pnp ? findPnpRoot(name, root) : await findRootLegacy(name, root);
178
- debug.extend(name)(found ? `Found root at ${found}` : 'No root found!');
178
+ debug(name)(found ? `Found root at ${found}` : 'No root found!');
179
179
  return found;
180
180
  }
181
- debug.extend('root-plugin')(`Finding root plugin using ${root}`);
181
+ debug('root-plugin')(`Finding root plugin using ${root}`);
182
182
  const found = await findPluginRoot(root);
183
- debug.extend('root-plugin')(found ? `Found root at ${found}` : 'No root found!');
183
+ debug('root-plugin')(found ? `Found root at ${found}` : 'No root found!');
184
184
  return found;
185
185
  }
186
186
  exports.findRoot = findRoot;
package/lib/util/fs.js CHANGED
@@ -43,17 +43,29 @@ const fileExists = async (input) => {
43
43
  return input;
44
44
  };
45
45
  exports.fileExists = fileExists;
46
+ const cache = new Map();
46
47
  async function readJson(path) {
48
+ if (cache.has(path)) {
49
+ return JSON.parse(cache.get(path));
50
+ }
47
51
  const contents = await (0, promises_1.readFile)(path, 'utf8');
52
+ cache.set(path, contents);
48
53
  return JSON.parse(contents);
49
54
  }
50
55
  exports.readJson = readJson;
51
56
  function readJsonSync(path, parse = true) {
57
+ if (cache.has(path)) {
58
+ return JSON.parse(cache.get(path));
59
+ }
52
60
  const contents = (0, node_fs_1.readFileSync)(path, 'utf8');
61
+ cache.set(path, contents);
53
62
  return parse ? JSON.parse(contents) : contents;
54
63
  }
55
64
  exports.readJsonSync = readJsonSync;
56
65
  async function safeReadJson(path) {
66
+ if (cache.has(path)) {
67
+ return JSON.parse(cache.get(path));
68
+ }
57
69
  try {
58
70
  return await readJson(path);
59
71
  }
package/lib/util/ids.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Config } from '../interfaces';
1
+ import { type Config } from '../interfaces/config';
2
2
  export declare function toStandardizedId(commandID: string, config: Config): string;
3
3
  export declare function toConfiguredId(commandID: string, config: Config): string;
@@ -0,0 +1,7 @@
1
+ import { PJSON } from '../interfaces';
2
+ /**
3
+ * Read the package.json file from a given path and add the oclif config (found by cosmiconfig) if it exists.
4
+ *
5
+ * We can assume that the package.json file exists because the plugin root has already been loaded at this point.
6
+ */
7
+ export declare function readPjson(path: string): Promise<PJSON>;