22
33const config = process . binding ( 'config' ) ;
44const prefix = `(${ process . release . name } :${ process . pid } ) ` ;
5+ const errors = require ( 'internal/errors' ) ;
56
67exports . setup = setupProcessWarnings ;
78
8- var errors ;
9- var fs ;
109var cachedFd ;
1110var acquiringFd = false ;
1211function nop ( ) { }
1312
14- function lazyErrors ( ) {
15- if ( ! errors )
16- errors = require ( 'internal/errors' ) ;
17- return errors ;
18- }
19-
20- function lazyFs ( ) {
21- if ( ! fs )
22- fs = require ( 'fs' ) ;
23- return fs ;
24- }
13+ // Lazily loaded
14+ var fs = null ;
2515
2616function writeOut ( message ) {
2717 if ( console && typeof console . error === 'function' )
@@ -31,7 +21,8 @@ function writeOut(message) {
3121
3222function onClose ( fd ) {
3323 return function ( ) {
34- lazyFs ( ) . close ( fd , nop ) ;
24+ if ( fs === null ) fs = require ( 'fs' ) ;
25+ fs . close ( fd , nop ) ;
3526 } ;
3627}
3728
@@ -53,14 +44,16 @@ function onAcquired(message) {
5344 return function ( err , fd ) {
5445 if ( err )
5546 return writeOut ( message ) ;
56- lazyFs ( ) . appendFile ( fd , `${ message } \n` , nop ) ;
47+ if ( fs === null ) fs = require ( 'fs' ) ;
48+ fs . appendFile ( fd , `${ message } \n` , nop ) ;
5749 } ;
5850}
5951
6052function acquireFd ( cb ) {
6153 if ( cachedFd === undefined && ! acquiringFd ) {
6254 acquiringFd = true ;
63- lazyFs ( ) . open ( config . warningFile , 'a' , onOpen ( cb ) ) ;
55+ if ( fs === null ) fs = require ( 'fs' ) ;
56+ fs . open ( config . warningFile , 'a' , onOpen ( cb ) ) ;
6457 } else if ( cachedFd !== undefined && ! acquiringFd ) {
6558 cb ( null , cachedFd ) ;
6659 } else {
@@ -112,7 +105,6 @@ function setupProcessWarnings() {
112105 // process.emitWarning(str[, type[, code]][, ctor])
113106 // process.emitWarning(str[, options])
114107 process . emitWarning = function ( warning , type , code , ctor , now ) {
115- const errors = lazyErrors ( ) ;
116108 var detail ;
117109 if ( type !== null && typeof type === 'object' && ! Array . isArray ( type ) ) {
118110 ctor = type . ctor ;
0 commit comments