4
4
// if there's a symlink already, pointing into our pkg, remove it first
5
5
// then create the symlink
6
6
7
- const { promisify } = require ( 'util' )
8
7
const { resolve, dirname } = require ( 'path' )
9
- const mkdirp = require ( 'mkdirp-infer-owner' )
10
- const fs = require ( 'fs' )
11
- const symlink = promisify ( fs . symlink )
12
- const readlink = promisify ( fs . readlink )
13
- const lstat = promisify ( fs . lstat )
8
+ const { lstat, mkdir, readlink, rm, symlink } = require ( 'fs/promises' )
14
9
const throwNonEnoent = er => {
15
10
if ( er . code !== 'ENOENT' ) {
16
11
throw er
17
12
}
18
13
}
19
14
15
+ const rmOpts = {
16
+ recursive : true ,
17
+ force : true ,
18
+ }
19
+
20
20
// even in --force mode, we never create a link over a link we've
21
21
// already created. you can have multiple packages in a tree trying
22
22
// to contend for the same bin, or the same manpage listed multiple times,
23
23
// which creates a race condition and nondeterminism.
24
24
const seen = new Set ( )
25
25
26
- // disable glob in our rimraf calls
27
- const rimraf = promisify ( require ( 'rimraf' ) )
28
- const rm = path => rimraf ( path , { glob : false } )
29
-
30
26
const SKIP = Symbol ( 'skip - missing or already installed' )
31
27
const CLOBBER = Symbol ( 'clobber - ours or in forceful mode' )
32
28
@@ -52,7 +48,7 @@ const linkGently = async ({ path, to, from, absFrom, force }) => {
52
48
// exists! maybe clobber if we can
53
49
if ( stTo ) {
54
50
if ( ! stTo . isSymbolicLink ( ) ) {
55
- return force && rm ( to ) . then ( ( ) => CLOBBER )
51
+ return force && rm ( to , rmOpts ) . then ( ( ) => CLOBBER )
56
52
}
57
53
58
54
return readlink ( to ) . then ( target => {
@@ -62,14 +58,14 @@ const linkGently = async ({ path, to, from, absFrom, force }) => {
62
58
63
59
target = resolve ( dirname ( to ) , target )
64
60
if ( target . indexOf ( path ) === 0 || force ) {
65
- return rm ( to ) . then ( ( ) => CLOBBER )
61
+ return rm ( to , rmOpts ) . then ( ( ) => CLOBBER )
66
62
}
67
63
// neither skip nor clobber
68
64
return false
69
65
} )
70
66
} else {
71
67
// doesn't exist, dir might not either
72
- return mkdirp ( dirname ( to ) )
68
+ return mkdir ( dirname ( to ) , { recursive : true } )
73
69
}
74
70
} )
75
71
. then ( skipOrClobber => {
@@ -78,7 +74,7 @@ const linkGently = async ({ path, to, from, absFrom, force }) => {
78
74
}
79
75
return symlink ( from , to , 'file' ) . catch ( er => {
80
76
if ( skipOrClobber === CLOBBER || force ) {
81
- return rm ( to ) . then ( ( ) => symlink ( from , to , 'file' ) )
77
+ return rm ( to , rmOpts ) . then ( ( ) => symlink ( from , to , 'file' ) )
82
78
}
83
79
throw er
84
80
} ) . then ( ( ) => true )
0 commit comments