4
4
*/
5
5
"use strict" ;
6
6
7
+ const util = require ( "util" ) ;
8
+
9
+ const deprecateContext = util . deprecate ( ( ) => { } ,
10
+ "Hook.context is deprecated and will be removed" ) ;
11
+
7
12
class Hook {
8
13
constructor ( args ) {
9
14
if ( ! Array . isArray ( args ) ) args = [ ] ;
@@ -35,9 +40,10 @@ class Hook {
35
40
throw new Error (
36
41
"Invalid arguments to tap(options: Object, fn: function)"
37
42
) ;
38
- options = Object . assign ( { type : "sync" , fn : fn } , options ) ;
39
43
if ( typeof options . name !== "string" || options . name === "" )
40
44
throw new Error ( "Missing name for tap" ) ;
45
+ if ( typeof options . context !== "undefined" ) deprecateContext ( ) ;
46
+ options = Object . assign ( { type : "sync" , fn : fn } , options ) ;
41
47
options = this . _runRegisterInterceptors ( options ) ;
42
48
this . _insert ( options ) ;
43
49
}
@@ -48,9 +54,10 @@ class Hook {
48
54
throw new Error (
49
55
"Invalid arguments to tapAsync(options: Object, fn: function)"
50
56
) ;
51
- options = Object . assign ( { type : "async" , fn : fn } , options ) ;
52
57
if ( typeof options . name !== "string" || options . name === "" )
53
58
throw new Error ( "Missing name for tapAsync" ) ;
59
+ if ( typeof options . context !== "undefined" ) deprecateContext ( ) ;
60
+ options = Object . assign ( { type : "async" , fn : fn } , options ) ;
54
61
options = this . _runRegisterInterceptors ( options ) ;
55
62
this . _insert ( options ) ;
56
63
}
@@ -61,9 +68,10 @@ class Hook {
61
68
throw new Error (
62
69
"Invalid arguments to tapPromise(options: Object, fn: function)"
63
70
) ;
64
- options = Object . assign ( { type : "promise" , fn : fn } , options ) ;
65
71
if ( typeof options . name !== "string" || options . name === "" )
66
72
throw new Error ( "Missing name for tapPromise" ) ;
73
+ if ( typeof options . context !== "undefined" ) deprecateContext ( ) ;
74
+ options = Object . assign ( { type : "promise" , fn : fn } , options ) ;
67
75
options = this . _runRegisterInterceptors ( options ) ;
68
76
this . _insert ( options ) ;
69
77
}
@@ -72,7 +80,9 @@ class Hook {
72
80
for ( const interceptor of this . interceptors ) {
73
81
if ( interceptor . register ) {
74
82
const newOptions = interceptor . register ( options ) ;
75
- if ( newOptions !== undefined ) options = newOptions ;
83
+ if ( newOptions !== undefined ) {
84
+ options = newOptions ;
85
+ }
76
86
}
77
87
}
78
88
return options ;
@@ -87,8 +97,8 @@ class Hook {
87
97
const base = this . _withOptionsBase || this ;
88
98
const newHook = Object . create ( base ) ;
89
99
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 ) ;
92
102
newHook . tapPromise = ( opt , fn ) => base . tapPromise ( mergeOptions ( opt ) , fn ) ;
93
103
newHook . _withOptions = options ;
94
104
newHook . _withOptionsBase = base ;
@@ -103,8 +113,9 @@ class Hook {
103
113
this . _resetCompilation ( ) ;
104
114
this . interceptors . push ( Object . assign ( { } , interceptor ) ) ;
105
115
if ( interceptor . register ) {
106
- for ( let i = 0 ; i < this . taps . length ; i ++ )
116
+ for ( let i = 0 ; i < this . taps . length ; i ++ ) {
107
117
this . taps [ i ] = interceptor . register ( this . taps [ i ] ) ;
118
+ }
108
119
}
109
120
}
110
121
@@ -117,12 +128,15 @@ class Hook {
117
128
_insert ( item ) {
118
129
this . _resetCompilation ( ) ;
119
130
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 ) ) {
122
134
before = new Set ( item . before ) ;
123
135
}
124
136
let stage = 0 ;
125
- if ( typeof item . stage === "number" ) stage = item . stage ;
137
+ if ( typeof item . stage === "number" ) {
138
+ stage = item . stage ;
139
+ }
126
140
let i = this . taps . length ;
127
141
while ( i > 0 ) {
128
142
i -- ;
0 commit comments