@oclif/core 3.7.1 → 3.9.0

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.
@@ -458,11 +458,11 @@ class Config {
458
458
  const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runHook#${p.name}(${hook})`);
459
459
  try {
460
460
  /* eslint-disable no-await-in-loop */
461
- const { filePath, isESM, module } = await (0, module_loader_1.loadWithData)(p, (0, node_path_1.join)(p.root, hook));
461
+ const { filePath, isESM, module } = await (0, module_loader_1.loadWithData)(p, hook);
462
462
  debug('start', isESM ? '(import)' : '(require)', filePath);
463
463
  const result = timeout
464
- ? await withTimeout(timeout, search(module).call(context, { ...opts, config: this }))
465
- : await search(module).call(context, { ...opts, config: this });
464
+ ? await withTimeout(timeout, search(module).call(context, { ...opts, config: this, context }))
465
+ : await search(module).call(context, { ...opts, config: this, context });
466
466
  final.successes.push({ plugin: p, result });
467
467
  if (p.name === '@oclif/plugin-legacy' && event === 'init') {
468
468
  this.insertLegacyPlugins(result);
@@ -163,7 +163,7 @@ class Plugin {
163
163
  else {
164
164
  this.pjson.oclif = this.pjson['cli-engine'] || {};
165
165
  }
166
- this.hooks = (0, util_1.mapValues)(this.pjson.oclif.hooks || {}, (i) => (Array.isArray(i) ? i : [i]));
166
+ this.hooks = (0, util_1.mapValues)(this.pjson.oclif.hooks ?? {}, (i) => (0, util_1.castArray)(i).map((i) => (0, ts_node_1.tsPath)(this.root, i, this)));
167
167
  this.manifest = await this._manifest();
168
168
  this.commands = Object.entries(this.manifest.commands)
169
169
  .map(([id, c]) => ({
package/lib/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { toConfiguredId, toStandardizedId } from './help/util';
14
14
  export * as Interfaces from './interfaces';
15
15
  export { Hook } from './interfaces/hooks';
16
16
  export { run } from './main';
17
+ export * as ModuleLoader from './module-loader';
17
18
  export * as Parser from './parser';
18
19
  export { Performance } from './performance';
19
20
  export { Settings, settings } from './settings';
package/lib/index.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.settings = exports.Performance = exports.Parser = exports.run = exports.Interfaces = exports.toStandardizedId = exports.toConfiguredId = exports.loadHelpClass = exports.HelpBase = exports.Help = exports.CommandHelp = exports.Flags = exports.execute = exports.handle = exports.Errors = exports.Plugin = exports.Config = exports.Command = exports.stdout = exports.stderr = exports.flush = exports.ux = exports.Args = void 0;
29
+ exports.settings = exports.Performance = exports.Parser = exports.ModuleLoader = exports.run = exports.Interfaces = exports.toStandardizedId = exports.toConfiguredId = exports.loadHelpClass = exports.HelpBase = exports.Help = exports.CommandHelp = exports.Flags = exports.execute = exports.handle = exports.Errors = exports.Plugin = exports.Config = exports.Command = exports.stdout = exports.stderr = exports.flush = exports.ux = exports.Args = void 0;
30
30
  const write_1 = __importDefault(require("./cli-ux/write"));
31
31
  function checkCWD() {
32
32
  try {
@@ -69,6 +69,7 @@ Object.defineProperty(exports, "toStandardizedId", { enumerable: true, get: func
69
69
  exports.Interfaces = __importStar(require("./interfaces"));
70
70
  var main_1 = require("./main");
71
71
  Object.defineProperty(exports, "run", { enumerable: true, get: function () { return main_1.run; } });
72
+ exports.ModuleLoader = __importStar(require("./module-loader"));
72
73
  exports.Parser = __importStar(require("./parser"));
73
74
  var performance_1 = require("./performance");
74
75
  Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return performance_1.Performance; } });
@@ -5,6 +5,16 @@ interface HookMeta {
5
5
  options: Record<string, unknown>;
6
6
  return: any;
7
7
  }
8
+ type Context = {
9
+ debug(...args: any[]): void;
10
+ error(message: Error | string, options?: {
11
+ code?: string;
12
+ exit?: number;
13
+ }): void;
14
+ exit(code?: number): void;
15
+ log(message?: any, ...args: any[]): void;
16
+ warn(message: string): void;
17
+ };
8
18
  export interface Hooks {
9
19
  [event: string]: HookMeta;
10
20
  command_incomplete: {
@@ -84,6 +94,7 @@ export interface Hooks {
84
94
  }
85
95
  export type Hook<T extends keyof P, P extends Hooks = Hooks> = (this: Hook.Context, options: P[T]['options'] & {
86
96
  config: Config;
97
+ context: Context;
87
98
  }) => Promise<P[T]['return']>;
88
99
  export declare namespace Hook {
89
100
  type Init = Hook<'init'>;
@@ -16,7 +16,7 @@ import { Config as IConfig, Plugin as IPlugin } from './interfaces';
16
16
  *
17
17
  * @returns {Promise<*>} The entire ESM module from dynamic import or CJS module by require.
18
18
  */
19
- export declare function load(config: IConfig | IPlugin, modulePath: string): Promise<any>;
19
+ export declare function load<T = any>(config: IConfig | IPlugin, modulePath: string): Promise<T>;
20
20
  /**
21
21
  * Loads a module and returns an object with the module and data about the module.
22
22
  *
@@ -34,10 +34,10 @@ export declare function load(config: IConfig | IPlugin, modulePath: string): Pro
34
34
  * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
35
35
  * file path and whether the module is ESM.
36
36
  */
37
- export declare function loadWithData(config: IConfig | IPlugin, modulePath: string): Promise<{
37
+ export declare function loadWithData<T = any>(config: IConfig | IPlugin, modulePath: string): Promise<{
38
38
  filePath: string;
39
39
  isESM: boolean;
40
- module: any;
40
+ module: T;
41
41
  }>;
42
42
  /**
43
43
  * Loads a module and returns an object with the module and data about the module.
@@ -54,10 +54,10 @@ export declare function loadWithData(config: IConfig | IPlugin, modulePath: stri
54
54
  * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
55
55
  * file path and whether the module is ESM.
56
56
  */
57
- export declare function loadWithDataFromManifest(cached: Command.Cached, modulePath: string): Promise<{
57
+ export declare function loadWithDataFromManifest<T = any>(cached: Command.Cached, modulePath: string): Promise<{
58
58
  filePath: string;
59
59
  isESM: boolean;
60
- module: any;
60
+ module: T;
61
61
  }>;
62
62
  /**
63
63
  * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
@@ -36,7 +36,7 @@ async function load(config, modulePath) {
36
36
  try {
37
37
  ;
38
38
  ({ filePath, isESM } = resolvePath(config, modulePath));
39
- return isESM ? await import((0, node_url_1.pathToFileURL)(filePath).href) : require(filePath);
39
+ return (isESM ? await import((0, node_url_1.pathToFileURL)(filePath).href) : require(filePath));
40
40
  }
41
41
  catch (error) {
42
42
  if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "3.7.1",
4
+ "version": "3.9.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {