From d5cbb8d3cb0ac96269fff70c9174b820339e46e8 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Tue, 27 Mar 2018 11:32:31 -0700 Subject: [PATCH] Add MultiHook and _pluginCompat to Tapable (#24527) * Fix Tapable types * .. * Clean up * Undo instance member change * Add constructor to Hookmap --- types/tapable/index.d.ts | 18 ++++++++++++++++++ types/tapable/tapable-tests.ts | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/types/tapable/index.d.ts b/types/tapable/index.d.ts index c044a245ce..502b408e9e 100644 --- a/types/tapable/index.d.ts +++ b/types/tapable/index.d.ts @@ -9,6 +9,9 @@ export declare abstract class Tapable { [propName: string]: Tapable.Handler[] } + /** @deprecated Private internals. Do not use directly */ + _pluginCompat: Hook; + /** * @deprecated Tapable.plugin is deprecated. Use new API on `.hooks` instead * Register plugin(s) @@ -275,7 +278,9 @@ export class HookInterceptor { context: boolean; } +/** A HookMap is a helper class for a Map with Hooks */ export class HookMap { + constructor(fn: () => Hook); get: (key: any) => Hook | undefined; for: (key: any) => Hook; tap: (key: any, name: string | Tap, fn: (arg1: T1, arg2: T2, arg3: T3, ...args: any[]) => any) => void; @@ -287,3 +292,16 @@ export class HookMap { export class HookMapInterceptor { factory: (key: any, hook: Hook) => Hook; } + +/** + * A helper Hook-like class to redirect taps to multiple other hooks + * + * ``` + * const { MultiHook } = require("tapable"); + * + * this.hooks.allHooks = new MultiHook([this.hooks.hookA, this.hooks.hookB]); + * ``` + */ +export class MultiHook { + constructor(hooks: Hook[]) +} diff --git a/types/tapable/tapable-tests.ts b/types/tapable/tapable-tests.ts index 4d82e60a66..c78196c194 100644 --- a/types/tapable/tapable-tests.ts +++ b/types/tapable/tapable-tests.ts @@ -1,4 +1,4 @@ -import {Tapable} from "tapable"; +import {Tapable, MultiHook, SyncHook} from "tapable"; class DllPlugin { apply(compiler: Compiler) { @@ -43,3 +43,5 @@ compiler.applyPluginsAsyncWaterfall('doSomething', 'a', callback); compiler.applyPluginsParallel('doSomething', 'a', 'b'); compiler.applyPluginsParallelBailResult('doSomething', 'a', 'b'); compiler.applyPluginsParallelBailResult1('doSomething', 'a', callback); + +const multi = new MultiHook([new SyncHook(['hi'])]);