@oclif/core 3.25.3 → 3.26.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.js CHANGED
@@ -243,7 +243,14 @@ class Command {
243
243
  ...options,
244
244
  flags: (0, aggregate_flags_1.aggregateFlags)(options.flags, options.baseFlags, options.enableJsonFlag),
245
245
  };
246
- const results = await Parser.parse(argv, opts);
246
+ const hookResult = await this.config.runHook('preparse', { argv: [...argv], options: opts });
247
+ // Since config.runHook will only run the hook for the root plugin, hookResult.successes will always have a length of 0 or 1
248
+ // But to be extra safe, we find the result that matches the root plugin.
249
+ const argvToParse = hookResult.successes?.length
250
+ ? hookResult.successes.find((s) => s.plugin.root === cache_1.default.getInstance().get('rootPlugin')?.root)?.result ?? argv
251
+ : argv;
252
+ this.argv = [...argvToParse];
253
+ const results = await Parser.parse(argvToParse, opts);
247
254
  this.warnIfFlagDeprecated(results.flags ?? {});
248
255
  return results;
249
256
  }
@@ -50,6 +50,7 @@ const util_3 = require("./util");
50
50
  const debug = (0, util_3.Debug)();
51
51
  const _pjson = cache_1.default.getInstance().get('@oclif/core');
52
52
  const BASE = `${_pjson.name}@${_pjson.version}`;
53
+ const ROOT_ONLY_HOOKS = new Set(['preparse']);
53
54
  function channelFromVersion(version) {
54
55
  const m = version.match(/[^-]+(?:-([^.]+))?/);
55
56
  return (m && m[1]) || 'stable';
@@ -468,7 +469,8 @@ class Config {
468
469
  failures: [],
469
470
  successes: [],
470
471
  };
471
- const promises = [...this.plugins.values()].map(async (p) => {
472
+ const plugins = ROOT_ONLY_HOOKS.has(event) ? [this.rootPlugin] : [...this.plugins.values()];
473
+ const promises = plugins.map(async (p) => {
472
474
  const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':'));
473
475
  const context = {
474
476
  config: this,
@@ -1,5 +1,6 @@
1
1
  import { Command } from '../command';
2
2
  import { Config } from './config';
3
+ import { Input, OutputFlags } from './parser';
3
4
  import { Plugin } from './plugin';
4
5
  interface HookMeta {
5
6
  options: Record<string, unknown>;
@@ -70,6 +71,13 @@ export interface Hooks {
70
71
  };
71
72
  return: void;
72
73
  };
74
+ preparse: {
75
+ options: {
76
+ argv: string[];
77
+ options: Input<OutputFlags<any>, OutputFlags<any>, OutputFlags<any>>;
78
+ };
79
+ return: string[];
80
+ };
73
81
  prerun: {
74
82
  options: {
75
83
  Command: Command.Class;
@@ -97,14 +105,47 @@ export type Hook<T extends keyof P, P extends Hooks = Hooks> = (this: Hook.Conte
97
105
  context: Context;
98
106
  }) => Promise<P[T]['return']>;
99
107
  export declare namespace Hook {
108
+ /**
109
+ * Runs when the CLI is initialized before a command is executed.
110
+ */
100
111
  type Init = Hook<'init'>;
112
+ /**
113
+ * Runs before the `plugins install` command from @oclif/plugin-plugins is run.
114
+ */
101
115
  type PluginsPreinstall = Hook<'plugins:preinstall'>;
116
+ /**
117
+ * Runs after the `init` hook, after a command is found but before it is executed.
118
+ */
102
119
  type Prerun = Hook<'prerun'>;
120
+ /**
121
+ * Runs after a command is successfully executed. Does not run if the command fails.
122
+ */
103
123
  type Postrun = Hook<'postrun'>;
124
+ /**
125
+ * Runs before the CLI is updated by `update` command from @oclif/plugin-update.
126
+ */
104
127
  type Preupdate = Hook<'preupdate'>;
128
+ /**
129
+ * Runs before a command's flags and args are parsed. Useful for modifying the command line arguments before they are parsed.
130
+ *
131
+ * The return value is a string[] of the modified arguments.
132
+ */
133
+ type Preparse = Hook<'preparse'>;
134
+ /**
135
+ * Runs once the `update` command from @oclif/plugin-update is run.
136
+ */
105
137
  type Update = Hook<'update'>;
138
+ /**
139
+ * Runs when a command is not found.
140
+ */
106
141
  type CommandNotFound = Hook<'command_not_found'>;
142
+ /**
143
+ * Runs when a partial command is entered and no matching command is found.
144
+ */
107
145
  type CommandIncomplete = Hook<'command_incomplete'>;
146
+ /**
147
+ * Runs when a command from an uninstalled JIT plugins is run.
148
+ */
108
149
  type JitPluginNotInstalled = Hook<'jit_plugin_not_installed'>;
109
150
  interface Context {
110
151
  config: Config;
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.25.3",
4
+ "version": "3.26.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -21,7 +21,7 @@
21
21
  "indent-string": "^4.0.0",
22
22
  "is-wsl": "^2.2.0",
23
23
  "js-yaml": "^3.14.1",
24
- "minimatch": "^9.0.3",
24
+ "minimatch": "^9.0.4",
25
25
  "natural-orderby": "^2.0.3",
26
26
  "object-treeify": "^1.1.33",
27
27
  "password-prompt": "^1.1.3",
@@ -39,7 +39,7 @@
39
39
  "@oclif/plugin-help": "^6",
40
40
  "@oclif/plugin-plugins": "^4",
41
41
  "@oclif/prettier-config": "^0.2.1",
42
- "@oclif/test": "^3.2.1",
42
+ "@oclif/test": "^3.2.8",
43
43
  "@types/ansi-styles": "^3.2.1",
44
44
  "@types/benchmark": "^2.1.5",
45
45
  "@types/chai": "^4.3.11",
@@ -65,21 +65,21 @@
65
65
  "commitlint": "^17.8.1",
66
66
  "cross-env": "^7.0.3",
67
67
  "eslint": "^8.57.0",
68
- "eslint-config-oclif": "^5.1.0",
69
- "eslint-config-oclif-typescript": "^3.1.2",
68
+ "eslint-config-oclif": "^5.1.1",
69
+ "eslint-config-oclif-typescript": "^3.1.3",
70
70
  "eslint-config-prettier": "^9.1.0",
71
- "fancy-test": "^3.0.13",
71
+ "fancy-test": "^3.0.14",
72
72
  "globby": "^11.1.0",
73
73
  "husky": "^8",
74
74
  "lint-staged": "^14.0.1",
75
75
  "madge": "^6.1.0",
76
- "mocha": "^10.3.0",
76
+ "mocha": "^10.4.0",
77
77
  "nyc": "^15.1.0",
78
78
  "prettier": "^3.2.5",
79
79
  "shx": "^0.3.4",
80
80
  "sinon": "^16.1.3",
81
81
  "ts-node": "^10.9.2",
82
- "tsd": "^0.30.6",
82
+ "tsd": "^0.31.0",
83
83
  "typescript": "^5"
84
84
  },
85
85
  "engines": {