11'use strict' ;
22
33const { promisify} = require ( 'util' ) ;
4- const { lstat, readdir} = require ( 'fs' ) . promises ;
4+ const { lstat, readdir} = require ( 'fs/promises' ) ;
55const path = require ( 'path' ) ;
66const { EventEmitter} = require ( 'events' ) ;
77
@@ -14,7 +14,7 @@ const tryToCatch = require('try-to-catch');
1414 information about the file the link references.
1515*/
1616
17- module . exports = promisify ( ( dir , options , callback ) => {
17+ module . exports = promisify ( async ( dir , options , callback ) => {
1818 const emitter = new EventEmitter ( ) ;
1919
2020 let total = 0 ;
@@ -40,10 +40,10 @@ module.exports = promisify((dir, options, callback) => {
4040 callback ( null , format . size ( total ) ) ;
4141 } ) ;
4242
43- processDir ( dir , options , emitter ) ;
43+ await processDir ( dir , options , emitter ) ;
4444} ) ;
4545
46- function processDir ( dir , options , emitter ) {
46+ async function processDir ( dir , options , emitter ) {
4747 const { stopOnError} = options ;
4848 let wasError = false ;
4949 let asyncRunning = 0 ;
@@ -59,7 +59,7 @@ function processDir(dir, options, emitter) {
5959 emitter . emit ( 'end' ) ;
6060 } ;
6161
62- getDirInfo ( dir ) ;
62+ await getDirInfo ( dir ) ;
6363
6464 async function getDirInfo ( dir ) {
6565 const [ error , stat ] = await tryToCatch ( lstat , dir ) ;
@@ -92,7 +92,7 @@ function processDir(dir, options, emitter) {
9292 asyncRunning -- ;
9393
9494 if ( ! readError )
95- return onReaddir ( dir , files ) ;
95+ return await onReaddir ( dir , files ) ;
9696
9797 if ( readError && stopOnError ) {
9898 wasError = true ;
@@ -102,7 +102,7 @@ function processDir(dir, options, emitter) {
102102 execCallBack ( ) ;
103103 }
104104
105- function onReaddir ( dir , files ) {
105+ async function onReaddir ( dir , files ) {
106106 const n = files . length ;
107107
108108 fileCounter += n ;
@@ -112,7 +112,7 @@ function processDir(dir, options, emitter) {
112112
113113 for ( const file of files ) {
114114 const dirPath = path . join ( dir , file ) ;
115- getDirInfo ( dirPath ) ;
115+ await getDirInfo ( dirPath ) ;
116116 }
117117 }
118118}
0 commit comments