@@ -12,14 +12,13 @@ const log = require('proc-log')
12
12
13
13
const { dirname, resolve, relative } = require ( 'path' )
14
14
const { 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 ' )
21
21
const moveFile = require ( '@npmcli/move-file' )
22
- const rimraf = promisify ( require ( 'rimraf' ) )
23
22
const PackageJson = require ( '@npmcli/package-json' )
24
23
const packageContents = require ( '@npmcli/installed-package-contents' )
25
24
const runScript = require ( '@npmcli/run-script' )
@@ -175,7 +174,7 @@ module.exports = cls => class Reifier extends cls {
175
174
// we do NOT want to set ownership on this folder, especially
176
175
// recursively, because it can have other side effects to do that
177
176
// 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 } )
179
178
180
179
// do not allow the top-level node_modules to be a symlink
181
180
await this [ _validateNodeModules ] ( resolve ( this . path , 'node_modules' ) )
@@ -433,10 +432,10 @@ module.exports = cls => class Reifier extends cls {
433
432
// handled the most common cause of ENOENT (dir doesn't exist yet),
434
433
// then just ignore any ENOENT.
435
434
if ( er . code === 'ENOENT' ) {
436
- return didMkdirp ? null : mkdirp ( dirname ( to ) ) . then ( ( ) =>
435
+ return didMkdirp ? null : mkdir ( dirname ( to ) , { recursive : true } ) . then ( ( ) =>
437
436
this [ _renamePath ] ( from , to , true ) )
438
437
} 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 ) )
440
439
} else {
441
440
throw er
442
441
}
@@ -518,7 +517,7 @@ module.exports = cls => class Reifier extends cls {
518
517
await this [ _renamePath ] ( d , retired )
519
518
}
520
519
}
521
- const made = await mkdirp ( node . path )
520
+ const made = await mkdir ( node . path , { recursive : true } )
522
521
this [ _sparseTreeDirs ] . add ( node . path )
523
522
this [ _sparseTreeRoots ] . add ( made )
524
523
} ) )
@@ -533,7 +532,7 @@ module.exports = cls => class Reifier extends cls {
533
532
const failures = [ ]
534
533
const targets = [ ...roots , ...Object . keys ( this [ _retiredPaths ] ) ]
535
534
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 ] ) ) )
537
536
return promiseAllRejectLate ( unlinks ) . then ( ( ) => {
538
537
// eslint-disable-next-line promise/always-return
539
538
if ( failures . length ) {
@@ -630,7 +629,7 @@ module.exports = cls => class Reifier extends cls {
630
629
return
631
630
}
632
631
log . warn ( 'reify' , 'Removing non-directory' , nm )
633
- await rimraf ( nm )
632
+ await rm ( nm , { recursive : true , force : true } )
634
633
}
635
634
636
635
async [ _extractOrLink ] ( node ) {
@@ -664,7 +663,7 @@ module.exports = cls => class Reifier extends cls {
664
663
await this [ _validateNodeModules ] ( nm )
665
664
666
665
if ( node . isLink ) {
667
- await rimraf ( node . path )
666
+ await rm ( node . path , { recursive : true , force : true } )
668
667
await this [ _symlink ] ( node )
669
668
} else {
670
669
await debug ( async ( ) => {
@@ -690,7 +689,7 @@ module.exports = cls => class Reifier extends cls {
690
689
const dir = dirname ( node . path )
691
690
const target = node . realpath
692
691
const rel = relative ( dir , target )
693
- await mkdirp ( dir )
692
+ await mkdir ( dir , { recursive : true } )
694
693
return symlink ( rel , node . path , 'junction' )
695
694
}
696
695
@@ -953,7 +952,7 @@ module.exports = cls => class Reifier extends cls {
953
952
954
953
// ok! actually unpack stuff into their target locations!
955
954
// 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
957
956
// tree entirely and try to put everything back where it was.
958
957
[ _unpackNewModules ] ( ) {
959
958
process . emit ( 'time' , 'reify:unpack' )
@@ -1034,7 +1033,8 @@ module.exports = cls => class Reifier extends cls {
1034
1033
return promiseAllRejectLate ( diff . unchanged . map ( node => {
1035
1034
// no need to roll back links, since we'll just delete them anyway
1036
1035
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 ) )
1038
1038
}
1039
1039
1040
1040
// will have been moved/unpacked along with bundler
@@ -1050,7 +1050,7 @@ module.exports = cls => class Reifier extends cls {
1050
1050
// skip it.
1051
1051
const bd = node . package . bundleDependencies
1052
1052
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 ) )
1054
1054
} ) )
1055
1055
} ) )
1056
1056
. then ( ( ) => process . emit ( 'timeEnd' , 'reify:unretire' ) )
@@ -1124,15 +1124,15 @@ module.exports = cls => class Reifier extends cls {
1124
1124
// the tree is pretty much built now, so it's cleanup time.
1125
1125
// remove the retired folders, and any deleted nodes
1126
1126
// 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 .
1128
1128
async [ _removeTrash ] ( ) {
1129
1129
process . emit ( 'time' , 'reify:trash' )
1130
1130
const promises = [ ]
1131
1131
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 ] ) )
1133
1133
1134
1134
for ( const path of this [ _trashList ] ) {
1135
- promises . push ( rm ( path ) )
1135
+ promises . push ( _rm ( path ) )
1136
1136
}
1137
1137
1138
1138
await promiseAllRejectLate ( promises )
0 commit comments