1
1
'use strict' ;
2
2
3
- const traceWarnings = process . traceProcessWarnings ;
4
- const noDeprecation = process . noDeprecation ;
5
- const traceDeprecation = process . traceDeprecation ;
6
- const throwDeprecation = process . throwDeprecation ;
7
3
const prefix = `(${ process . release . name } :${ process . pid } ) ` ;
8
4
9
5
exports . setup = setupProcessWarnings ;
@@ -13,8 +9,9 @@ function setupProcessWarnings() {
13
9
process . on ( 'warning' , ( warning ) => {
14
10
if ( ! ( warning instanceof Error ) ) return ;
15
11
const isDeprecation = warning . name === 'DeprecationWarning' ;
16
- if ( isDeprecation && noDeprecation ) return ;
17
- const trace = traceWarnings || ( isDeprecation && traceDeprecation ) ;
12
+ if ( isDeprecation && process . noDeprecation ) return ;
13
+ const trace = process . traceProcessWarnings ||
14
+ ( isDeprecation && process . traceDeprecation ) ;
18
15
if ( trace && warning . stack ) {
19
16
console . error ( `${ prefix } ${ warning . stack } ` ) ;
20
17
} else {
@@ -41,9 +38,12 @@ function setupProcessWarnings() {
41
38
if ( ! ( warning instanceof Error ) ) {
42
39
throw new TypeError ( '\'warning\' must be an Error object or string.' ) ;
43
40
}
44
- if ( throwDeprecation && warning . name === 'DeprecationWarning' )
45
- throw warning ;
46
- else
47
- process . nextTick ( ( ) => process . emit ( 'warning' , warning ) ) ;
41
+ if ( warning . name === 'DeprecationWarning' ) {
42
+ if ( process . noDeprecation )
43
+ return ;
44
+ if ( process . throwDeprecation )
45
+ throw warning ;
46
+ }
47
+ process . nextTick ( ( ) => process . emit ( 'warning' , warning ) ) ;
48
48
} ;
49
49
}
0 commit comments