Skip to content

Commit

Permalink
Merge pull request #104 from webpack/feature/name
Browse files Browse the repository at this point in the history
give all constructors a name argument
  • Loading branch information
sokra authored Jul 9, 2019
2 parents e225fba + 51eec78 commit 71a4153
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/AsyncParallelBailHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function AsyncParallelBailHook(args = []) {
const hook = new Hook(args);
function AsyncParallelBailHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = AsyncParallelBailHook;
hook.compile = COMPILE;
hook._call = undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/AsyncParallelHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function AsyncParallelHook(args = []) {
const hook = new Hook(args);
function AsyncParallelHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = AsyncParallelHook;
hook.compile = COMPILE;
hook._call = undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/AsyncSeriesBailHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function AsyncSeriesBailHook(args = []) {
const hook = new Hook(args);
function AsyncSeriesBailHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = AsyncSeriesBailHook;
hook.compile = COMPILE;
hook._call = undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/AsyncSeriesHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function AsyncSeriesHook(args = []) {
const hook = new Hook(args);
function AsyncSeriesHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = AsyncSeriesHook;
hook.compile = COMPILE;
hook._call = undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/AsyncSeriesLoopHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function AsyncSeriesLoopHook(args = []) {
const hook = new Hook(args);
function AsyncSeriesLoopHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = AsyncSeriesLoopHook;
hook.compile = COMPILE;
hook._call = undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/AsyncSeriesWaterfallHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const COMPILE = function(options) {
return factory.create(options);
};

function AsyncSeriesWaterfallHook(args = []) {
function AsyncSeriesWaterfallHook(args = [], name = undefined) {
if (args.length < 1)
throw new Error("Waterfall hooks must have at least one argument");
const hook = new Hook(args);
const hook = new Hook(args, name);
hook.constructor = AsyncSeriesWaterfallHook;
hook.compile = COMPILE;
hook._call = undefined;
Expand Down
3 changes: 2 additions & 1 deletion lib/HookMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const util = require("util");
const defaultFactory = (key, hook) => hook;

class HookMap {
constructor(factory) {
constructor(factory, name = undefined) {
this._map = new Map();
this.name = name;
this._factory = factory;
this._interceptors = [];
}
Expand Down
8 changes: 6 additions & 2 deletions lib/MultiHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
const Hook = require("./Hook");

class MultiHook {
constructor(hooks) {
constructor(hooks, name = undefined) {
this.hooks = hooks;
this.name = name;
}

tap(options, fn) {
Expand Down Expand Up @@ -43,7 +44,10 @@ class MultiHook {
}

withOptions(options) {
return new MultiHook(this.hooks.map(h => h.withOptions(options)));
return new MultiHook(
this.hooks.map(h => h.withOptions(options)),
this.name
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/SyncBailHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function SyncBailHook(args = []) {
const hook = new Hook(args);
function SyncBailHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = SyncBailHook;
hook.tapAsync = TAP_ASYNC;
hook.tapPromise = TAP_PROMISE;
Expand Down
4 changes: 2 additions & 2 deletions lib/SyncHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function SyncHook(args = []) {
const hook = new Hook(args);
function SyncHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = SyncHook;
hook.tapAsync = TAP_ASYNC;
hook.tapPromise = TAP_PROMISE;
Expand Down
4 changes: 2 additions & 2 deletions lib/SyncLoopHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const COMPILE = function(options) {
return factory.create(options);
};

function SyncLoopHook(args = []) {
const hook = new Hook(args);
function SyncLoopHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = SyncLoopHook;
hook.tapAsync = TAP_ASYNC;
hook.tapPromise = TAP_PROMISE;
Expand Down
4 changes: 2 additions & 2 deletions lib/SyncWaterfallHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ const COMPILE = function(options) {
return factory.create(options);
};

function SyncWaterfallHook(args = []) {
function SyncWaterfallHook(args = [], name = undefined) {
if (args.length < 1)
throw new Error("Waterfall hooks must have at least one argument");
const hook = new Hook(args);
const hook = new Hook(args, name);
hook.constructor = SyncWaterfallHook;
hook.tapAsync = TAP_ASYNC;
hook.tapPromise = TAP_PROMISE;
Expand Down
6 changes: 4 additions & 2 deletions tapable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ interface HookMapInterceptor<H> {
}

export class HookMap<H> {
constructor(factory: HookFactory<H>);
constructor(factory: HookFactory<H>, name?: string);
name: string | undefined;
get(key: any): H | undefined;
for(key: any): H;
intercept(interceptor: HookMapInterceptor<H>): void;
}

export class MultiHook<H> {
constructor(hooks: H[]);
constructor(hooks: H[], name?: string);
name: string | undefined;
tap(options: string | Tap, fn?: Function): void;
tapAsync(options: string | Tap, fn?: Function): void;
tapPromise(options: string | Tap, fn?: Function): void;
Expand Down

0 comments on commit 71a4153

Please sign in to comment.