Skip to content

Commit 53783b5

Browse files
authored
Adds an undocumented run hook (#7557)
* Adds an undocumented run hook * Fixes lint
1 parent 7496345 commit 53783b5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/cli/commands/run.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {Reporter} from '../../reporters/index.js';
44
import type Config from '../../config.js';
55
import {execCommand, makeEnv} from '../../util/execute-lifecycle-script.js';
66
import {dynamicRequire} from '../../util/dynamic-require.js';
7+
import {callThroughHook} from '../../util/hooks.js';
78
import {MessageError} from '../../errors.js';
89
import {checkOne as checkCompatibility} from '../../package-compatibility.js';
910
import * as fs from '../../util/fs.js';
@@ -91,9 +92,11 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
9192
}
9293
}
9394

94-
async function runCommand(args): Promise<void> {
95-
const action = args.shift();
95+
function runCommand([action, ...args]): Promise<void> {
96+
return callThroughHook('runScript', () => realRunCommand(action, args), {action, args});
97+
}
9698

99+
async function realRunCommand(action, args): Promise<void> {
97100
// build up list of commands
98101
const cmds = [];
99102

src/util/hooks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* @flow */
22

3-
export type YarnHook = 'resolveStep' | 'fetchStep' | 'linkStep' | 'buildStep' | 'pnpStep' | 'auditStep';
3+
export type YarnHook = 'resolveStep' | 'fetchStep' | 'linkStep' | 'buildStep' | 'pnpStep' | 'auditStep' | 'runScript';
44

55
const YARN_HOOKS_KEY = 'experimentalYarnHooks';
66

7-
export function callThroughHook<T>(type: YarnHook, fn: () => T): T {
7+
export function callThroughHook<T>(type: YarnHook, fn: () => T, context?: any): T {
88
if (typeof global === 'undefined') {
99
return fn();
1010
}
@@ -13,11 +13,11 @@ export function callThroughHook<T>(type: YarnHook, fn: () => T): T {
1313
return fn();
1414
}
1515

16-
const hook: (() => T) => T = global[YARN_HOOKS_KEY][type];
16+
const hook: (() => T, context?: any) => T = global[YARN_HOOKS_KEY][type];
1717

1818
if (!hook) {
1919
return fn();
2020
}
2121

22-
return hook(fn);
22+
return hook(fn, context);
2323
}

0 commit comments

Comments
 (0)