@oclif/core 3.25.3 → 3.26.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.
- package/lib/command.js +8 -1
- package/lib/config/config.js +3 -1
- package/lib/interfaces/hooks.d.ts +8 -0
- package/package.json +1 -1
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
|
|
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
|
}
|
package/lib/config/config.js
CHANGED
|
@@ -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
|
|
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;
|