Skip to content

Commit 60ef411

Browse files
authored
Merge pull request #81 from ooflorent/deprecate_context
Deprecate context option
2 parents 95177ba + e45b35a commit 60ef411

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

lib/Hook.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
*/
55
"use strict";
66

7+
const util = require("util");
8+
9+
const deprecateContext = util.deprecate(() => {},
10+
"Hook.context is deprecated and will be removed");
11+
712
class Hook {
813
constructor(args) {
914
if (!Array.isArray(args)) args = [];
@@ -35,9 +40,10 @@ class Hook {
3540
throw new Error(
3641
"Invalid arguments to tap(options: Object, fn: function)"
3742
);
38-
options = Object.assign({ type: "sync", fn: fn }, options);
3943
if (typeof options.name !== "string" || options.name === "")
4044
throw new Error("Missing name for tap");
45+
if (typeof options.context !== "undefined") deprecateContext();
46+
options = Object.assign({ type: "sync", fn: fn }, options);
4147
options = this._runRegisterInterceptors(options);
4248
this._insert(options);
4349
}
@@ -48,9 +54,10 @@ class Hook {
4854
throw new Error(
4955
"Invalid arguments to tapAsync(options: Object, fn: function)"
5056
);
51-
options = Object.assign({ type: "async", fn: fn }, options);
5257
if (typeof options.name !== "string" || options.name === "")
5358
throw new Error("Missing name for tapAsync");
59+
if (typeof options.context !== "undefined") deprecateContext();
60+
options = Object.assign({ type: "async", fn: fn }, options);
5461
options = this._runRegisterInterceptors(options);
5562
this._insert(options);
5663
}
@@ -61,9 +68,10 @@ class Hook {
6168
throw new Error(
6269
"Invalid arguments to tapPromise(options: Object, fn: function)"
6370
);
64-
options = Object.assign({ type: "promise", fn: fn }, options);
6571
if (typeof options.name !== "string" || options.name === "")
6672
throw new Error("Missing name for tapPromise");
73+
if (typeof options.context !== "undefined") deprecateContext();
74+
options = Object.assign({ type: "promise", fn: fn }, options);
6775
options = this._runRegisterInterceptors(options);
6876
this._insert(options);
6977
}
@@ -72,7 +80,9 @@ class Hook {
7280
for (const interceptor of this.interceptors) {
7381
if (interceptor.register) {
7482
const newOptions = interceptor.register(options);
75-
if (newOptions !== undefined) options = newOptions;
83+
if (newOptions !== undefined) {
84+
options = newOptions;
85+
}
7686
}
7787
}
7888
return options;
@@ -87,8 +97,8 @@ class Hook {
8797
const base = this._withOptionsBase || this;
8898
const newHook = Object.create(base);
8999

90-
(newHook.tapAsync = (opt, fn) => base.tapAsync(mergeOptions(opt), fn)),
91-
(newHook.tap = (opt, fn) => base.tap(mergeOptions(opt), fn));
100+
newHook.tap = (opt, fn) => base.tap(mergeOptions(opt), fn);
101+
newHook.tapAsync = (opt, fn) => base.tapAsync(mergeOptions(opt), fn);
92102
newHook.tapPromise = (opt, fn) => base.tapPromise(mergeOptions(opt), fn);
93103
newHook._withOptions = options;
94104
newHook._withOptionsBase = base;
@@ -103,8 +113,9 @@ class Hook {
103113
this._resetCompilation();
104114
this.interceptors.push(Object.assign({}, interceptor));
105115
if (interceptor.register) {
106-
for (let i = 0; i < this.taps.length; i++)
116+
for (let i = 0; i < this.taps.length; i++) {
107117
this.taps[i] = interceptor.register(this.taps[i]);
118+
}
108119
}
109120
}
110121

@@ -117,12 +128,15 @@ class Hook {
117128
_insert(item) {
118129
this._resetCompilation();
119130
let before;
120-
if (typeof item.before === "string") before = new Set([item.before]);
121-
else if (Array.isArray(item.before)) {
131+
if (typeof item.before === "string") {
132+
before = new Set([item.before]);
133+
} else if (Array.isArray(item.before)) {
122134
before = new Set(item.before);
123135
}
124136
let stage = 0;
125-
if (typeof item.stage === "number") stage = item.stage;
137+
if (typeof item.stage === "number") {
138+
stage = item.stage;
139+
}
126140
let i = this.taps.length;
127141
while (i > 0) {
128142
i--;

0 commit comments

Comments
 (0)