@oclif/core 3.8.0 → 3.9.1

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/lib/command.d.ts CHANGED
@@ -97,8 +97,7 @@ export declare abstract class Command {
97
97
  code?: string;
98
98
  exit?: number;
99
99
  } & PrettyPrintableError): never;
100
- exit(code: number): never;
101
- exit(code: 0): void;
100
+ exit(code?: number): never;
102
101
  protected finally(_: Error | undefined): Promise<any>;
103
102
  protected init(): Promise<any>;
104
103
  /**
@@ -461,8 +461,8 @@ class Config {
461
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);
@@ -5,7 +5,7 @@ export { CLIError } from './errors/cli';
5
5
  export { ExitError } from './errors/exit';
6
6
  export { ModuleLoadError } from './errors/module-load';
7
7
  export { handle } from './handle';
8
- export declare function exit(code?: number): void;
8
+ export declare function exit(code?: number): never;
9
9
  export declare function error(input: Error | string, options: {
10
10
  exit: false;
11
11
  } & PrettyPrintableError): void;
@@ -39,9 +39,7 @@ Object.defineProperty(exports, "ModuleLoadError", { enumerable: true, get: funct
39
39
  var handle_1 = require("./handle");
40
40
  Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
41
41
  function exit(code = 0) {
42
- if (code !== 0) {
43
- throw new exit_1.ExitError(code);
44
- }
42
+ throw new exit_1.ExitError(code);
45
43
  }
46
44
  exports.exit = exit;
47
45
  function error(input, options = {}) {
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.8.0",
4
+ "version": "3.9.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {