File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -4,26 +4,26 @@ let { writeFile } = require("fs/promises");
44let { mkdirSync } = require ( "fs" ) ;
55let path = require ( "path" ) ;
66
7- let KNOWN = { } ; // avoids redundant `mkdirp ` invocations
8- let LOCKS = { } ;
7+ let KNOWN = new Set ( ) ; // avoids redundant `mkdir ` invocations
8+ let LOCKS = new Map ( ) ;
99
1010// avoids concurrent write operations and creates target directory if necessary
1111module . exports = function createFile ( filepath , contents ) {
12- let lock = LOCKS [ filepath ] ;
12+ let lock = LOCKS . get ( filepath ) ;
1313 if ( lock ) { // defer
1414 return lock . then ( _ => createFile ( filepath , contents ) ) ;
1515 }
1616
1717 // create directory if necessary
18- if ( ! KNOWN [ filepath ] ) {
19- KNOWN [ filepath ] = true ;
18+ if ( ! KNOWN . has ( filepath ) ) {
19+ KNOWN . add ( filepath ) ;
2020 // NB: `sync` avoids race condition for subsequent operations
2121 mkdirSync ( path . dirname ( filepath ) , { recursive : true } ) ;
2222 }
2323
2424 let prom = writeFile ( filepath , contents ) ;
25- LOCKS [ filepath ] = prom ;
25+ LOCKS . set ( filepath , prom ) ;
2626 return prom . then ( _ => {
27- delete LOCKS [ filepath ] ;
27+ LOCKS . delete ( filepath ) ;
2828 } ) ;
2929} ;
You can’t perform that action at this time.
0 commit comments