@@ -12,14 +12,13 @@ const log = require('proc-log')
1212
1313const { dirname, resolve, relative } = require ( 'path' )
1414const { depth : dfwalk } = require ( 'treeverse' )
15- const fs = require ( 'fs' )
16- const { promisify } = require ( 'util' )
17- const lstat = promisify ( fs . lstat )
18- const symlink = promisify ( fs . symlink )
19- const mkdirp = require ( 'mkdirp-infer-owner' )
20- const justMkdirp = require ( 'mkdirp ' )
15+ const {
16+ lstat ,
17+ mkdir ,
18+ rm ,
19+ symlink ,
20+ } = require ( 'fs/promises ' )
2121const moveFile = require ( '@npmcli/move-file' )
22- const rimraf = promisify ( require ( 'rimraf' ) )
2322const PackageJson = require ( '@npmcli/package-json' )
2423const packageContents = require ( '@npmcli/installed-package-contents' )
2524const runScript = require ( '@npmcli/run-script' )
@@ -175,7 +174,7 @@ module.exports = cls => class Reifier extends cls {
175174 // we do NOT want to set ownership on this folder, especially
176175 // recursively, because it can have other side effects to do that
177176 // in a project directory. We just want to make it if it's missing.
178- await justMkdirp ( resolve ( this . path ) )
177+ await mkdir ( resolve ( this . path ) , { recursive : true } )
179178
180179 // do not allow the top-level node_modules to be a symlink
181180 await this [ _validateNodeModules ] ( resolve ( this . path , 'node_modules' ) )
@@ -433,10 +432,10 @@ module.exports = cls => class Reifier extends cls {
433432 // handled the most common cause of ENOENT (dir doesn't exist yet),
434433 // then just ignore any ENOENT.
435434 if ( er . code === 'ENOENT' ) {
436- return didMkdirp ? null : mkdirp ( dirname ( to ) ) . then ( ( ) =>
435+ return didMkdirp ? null : mkdir ( dirname ( to ) , { recursive : true } ) . then ( ( ) =>
437436 this [ _renamePath ] ( from , to , true ) )
438437 } else if ( er . code === 'EEXIST' ) {
439- return rimraf ( to ) . then ( ( ) => moveFile ( from , to ) )
438+ return rm ( to , { recursive : true , force : true } ) . then ( ( ) => moveFile ( from , to ) )
440439 } else {
441440 throw er
442441 }
@@ -518,7 +517,7 @@ module.exports = cls => class Reifier extends cls {
518517 await this [ _renamePath ] ( d , retired )
519518 }
520519 }
521- const made = await mkdirp ( node . path )
520+ const made = await mkdir ( node . path , { recursive : true } )
522521 this [ _sparseTreeDirs ] . add ( node . path )
523522 this [ _sparseTreeRoots ] . add ( made )
524523 } ) )
@@ -533,7 +532,7 @@ module.exports = cls => class Reifier extends cls {
533532 const failures = [ ]
534533 const targets = [ ...roots , ...Object . keys ( this [ _retiredPaths ] ) ]
535534 const unlinks = targets
536- . map ( path => rimraf ( path ) . catch ( er => failures . push ( [ path , er ] ) ) )
535+ . map ( path => rm ( path , { recursive : true , force : true } ) . catch ( er => failures . push ( [ path , er ] ) ) )
537536 return promiseAllRejectLate ( unlinks ) . then ( ( ) => {
538537 // eslint-disable-next-line promise/always-return
539538 if ( failures . length ) {
@@ -630,7 +629,7 @@ module.exports = cls => class Reifier extends cls {
630629 return
631630 }
632631 log . warn ( 'reify' , 'Removing non-directory' , nm )
633- await rimraf ( nm )
632+ await rm ( nm , { recursive : true , force : true } )
634633 }
635634
636635 async [ _extractOrLink ] ( node ) {
@@ -664,7 +663,7 @@ module.exports = cls => class Reifier extends cls {
664663 await this [ _validateNodeModules ] ( nm )
665664
666665 if ( node . isLink ) {
667- await rimraf ( node . path )
666+ await rm ( node . path , { recursive : true , force : true } )
668667 await this [ _symlink ] ( node )
669668 } else {
670669 await debug ( async ( ) => {
@@ -690,7 +689,7 @@ module.exports = cls => class Reifier extends cls {
690689 const dir = dirname ( node . path )
691690 const target = node . realpath
692691 const rel = relative ( dir , target )
693- await mkdirp ( dir )
692+ await mkdir ( dir , { recursive : true } )
694693 return symlink ( rel , node . path , 'junction' )
695694 }
696695
@@ -953,7 +952,7 @@ module.exports = cls => class Reifier extends cls {
953952
954953 // ok! actually unpack stuff into their target locations!
955954 // The sparse tree has already been created, so we walk the diff
956- // kicking off each unpack job. If any fail, we rimraf the sparse
955+ // kicking off each unpack job. If any fail, we rm the sparse
957956 // tree entirely and try to put everything back where it was.
958957 [ _unpackNewModules ] ( ) {
959958 process . emit ( 'time' , 'reify:unpack' )
@@ -1034,7 +1033,8 @@ module.exports = cls => class Reifier extends cls {
10341033 return promiseAllRejectLate ( diff . unchanged . map ( node => {
10351034 // no need to roll back links, since we'll just delete them anyway
10361035 if ( node . isLink ) {
1037- return mkdirp ( dirname ( node . path ) ) . then ( ( ) => this [ _reifyNode ] ( node ) )
1036+ return mkdir ( dirname ( node . path ) , { recursive : true , force : true } )
1037+ . then ( ( ) => this [ _reifyNode ] ( node ) )
10381038 }
10391039
10401040 // will have been moved/unpacked along with bundler
@@ -1050,7 +1050,7 @@ module.exports = cls => class Reifier extends cls {
10501050 // skip it.
10511051 const bd = node . package . bundleDependencies
10521052 const dir = bd && bd . length ? node . path + '/node_modules' : node . path
1053- return mkdirp ( dir ) . then ( ( ) => this [ _moveContents ] ( node , fromPath ) )
1053+ return mkdir ( dir , { recursive : true } ) . then ( ( ) => this [ _moveContents ] ( node , fromPath ) )
10541054 } ) )
10551055 } ) )
10561056 . then ( ( ) => process . emit ( 'timeEnd' , 'reify:unretire' ) )
@@ -1124,15 +1124,15 @@ module.exports = cls => class Reifier extends cls {
11241124 // the tree is pretty much built now, so it's cleanup time.
11251125 // remove the retired folders, and any deleted nodes
11261126 // If this fails, there isn't much we can do but tell the user about it.
1127- // Thankfully, it's pretty unlikely that it'll fail, since rimraf is a tank .
1127+ // Thankfully, it's pretty unlikely that it'll fail, since rm is a node builtin .
11281128 async [ _removeTrash ] ( ) {
11291129 process . emit ( 'time' , 'reify:trash' )
11301130 const promises = [ ]
11311131 const failures = [ ]
1132- const rm = path => rimraf ( path ) . catch ( er => failures . push ( [ path , er ] ) )
1132+ const _rm = path => rm ( path , { recursive : true , force : true } ) . catch ( er => failures . push ( [ path , er ] ) )
11331133
11341134 for ( const path of this [ _trashList ] ) {
1135- promises . push ( rm ( path ) )
1135+ promises . push ( _rm ( path ) )
11361136 }
11371137
11381138 await promiseAllRejectLate ( promises )
0 commit comments