Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {Reporter} from '../../reporters/index.js';
import type Config from '../../config.js';
import {execCommand, makeEnv} from '../../util/execute-lifecycle-script.js';
import {dynamicRequire} from '../../util/dynamic-require.js';
import {callThroughHook} from '../../util/hooks.js';
import {MessageError} from '../../errors.js';
import {checkOne as checkCompatibility} from '../../package-compatibility.js';
import * as fs from '../../util/fs.js';
Expand Down Expand Up @@ -91,9 +92,11 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}
}

async function runCommand(args): Promise<void> {
const action = args.shift();
function runCommand([action, ...args]): Promise<void> {
return callThroughHook('runScript', () => realRunCommand(action, args), {action, args});
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/util/hooks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* @flow */

export type YarnHook = 'resolveStep' | 'fetchStep' | 'linkStep' | 'buildStep' | 'pnpStep' | 'auditStep';
export type YarnHook = 'resolveStep' | 'fetchStep' | 'linkStep' | 'buildStep' | 'pnpStep' | 'auditStep' | 'runScript';

const YARN_HOOKS_KEY = 'experimentalYarnHooks';

export function callThroughHook<T>(type: YarnHook, fn: () => T): T {
export function callThroughHook<T>(type: YarnHook, fn: () => T, context?: any): T {
if (typeof global === 'undefined') {
return fn();
}
Expand All @@ -13,11 +13,11 @@ export function callThroughHook<T>(type: YarnHook, fn: () => T): T {
return fn();
}

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

if (!hook) {
return fn();
}

return hook(fn);
return hook(fn, context);
}