@@ -7,11 +7,8 @@ import decompressTargz from 'decompress-targz';
7
7
import decompressUnzip from 'decompress-unzip' ;
8
8
import fs from 'graceful-fs' ;
9
9
import makeDir from 'make-dir' ;
10
- import pify from 'pify' ;
11
10
import stripDirs from 'strip-dirs' ;
12
11
13
- const fsP = pify ( fs ) ;
14
-
15
12
const runPlugins = ( input , options ) => {
16
13
if ( options . plugins . length === 0 ) {
17
14
return Promise . resolve ( [ ] ) ;
@@ -21,7 +18,7 @@ const runPlugins = (input, options) => {
21
18
return Promise . all ( options . plugins . map ( x => x ( input , options ) ) ) . then ( files => files . reduce ( ( a , b ) => a . concat ( b ) ) ) ;
22
19
} ;
23
20
24
- const safeMakeDir = ( dir , realOutputPath ) => fsP . realpath ( dir )
21
+ const safeMakeDir = ( dir , realOutputPath ) => fs . promises . realpath ( dir )
25
22
. catch ( _ => {
26
23
const parent = path . dirname ( dir ) ;
27
24
return safeMakeDir ( parent , realOutputPath ) ;
@@ -31,10 +28,10 @@ const safeMakeDir = (dir, realOutputPath) => fsP.realpath(dir)
31
28
throw new Error ( 'Refusing to create a directory outside the output path.' ) ;
32
29
}
33
30
34
- return makeDir ( dir ) . then ( fsP . realpath ) ;
31
+ return makeDir ( dir ) . then ( fs . promises . realpath ) ;
35
32
} ) ;
36
33
37
- const preventWritingThroughSymlink = ( destination , realOutputPath ) => fsP . readlink ( destination )
34
+ const preventWritingThroughSymlink = ( destination , realOutputPath ) => fs . promises . readlink ( destination )
38
35
// Either no file exists, or it's not a symlink. In either case, this is
39
36
// not an escape we need to worry about in this phase.
40
37
. catch ( _ => null )
@@ -76,14 +73,14 @@ const extractFile = (input, output, options) => runPlugins(input, options).then(
76
73
77
74
if ( x . type === 'directory' ) {
78
75
return makeDir ( output )
79
- . then ( outputPath => fsP . realpath ( outputPath ) )
76
+ . then ( outputPath => fs . promises . realpath ( outputPath ) )
80
77
. then ( realOutputPath => safeMakeDir ( dest , realOutputPath ) )
81
- . then ( ( ) => fsP . utimes ( dest , now , x . mtime ) )
78
+ . then ( ( ) => fs . promises . utimes ( dest , now , x . mtime ) )
82
79
. then ( ( ) => x ) ;
83
80
}
84
81
85
82
return makeDir ( output )
86
- . then ( outputPath => fsP . realpath ( outputPath ) )
83
+ . then ( outputPath => fs . promises . realpath ( outputPath ) )
87
84
. then ( realOutputPath =>
88
85
// Attempt to ensure parent directory exists (failing if it's outside the output dir)
89
86
safeMakeDir ( path . dirname ( dest ) , realOutputPath ) . then ( ( ) => realOutputPath ) ,
@@ -95,28 +92,28 @@ const extractFile = (input, output, options) => runPlugins(input, options).then(
95
92
96
93
return realOutputPath ;
97
94
} )
98
- . then ( realOutputPath => fsP . realpath ( path . dirname ( dest ) )
95
+ . then ( realOutputPath => fs . promises . realpath ( path . dirname ( dest ) )
99
96
. then ( realDestinationDir => {
100
97
if ( realDestinationDir . indexOf ( realOutputPath ) !== 0 ) {
101
98
throw new Error ( `Refusing to write outside output directory: ${ realDestinationDir } ` ) ;
102
99
}
103
100
} ) )
104
101
. then ( ( ) => {
105
102
if ( x . type === 'link' ) {
106
- return fsP . link ( x . linkname , dest ) ;
103
+ return fs . promises . link ( x . linkname , dest ) ;
107
104
}
108
105
109
106
if ( x . type === 'symlink' && process . platform === 'win32' ) {
110
- return fsP . link ( x . linkname , dest ) ;
107
+ return fs . promises . link ( x . linkname , dest ) ;
111
108
}
112
109
113
110
if ( x . type === 'symlink' ) {
114
- return fsP . symlink ( x . linkname , dest ) ;
111
+ return fs . promises . symlink ( x . linkname , dest ) ;
115
112
}
116
113
117
- return fsP . writeFile ( dest , x . data , { mode} ) ;
114
+ return fs . promises . writeFile ( dest , x . data , { mode} ) ;
118
115
} )
119
- . then ( ( ) => x . type === 'file' && fsP . utimes ( dest , now , x . mtime ) )
116
+ . then ( ( ) => x . type === 'file' && fs . promises . utimes ( dest , now , x . mtime ) )
120
117
. then ( ( ) => x ) ;
121
118
} ) ) ;
122
119
} ) ;
@@ -141,7 +138,7 @@ const decompress = (input, output, options) => {
141
138
...options ,
142
139
} ;
143
140
144
- const read = typeof input === 'string' ? fsP . readFile ( input ) : Promise . resolve ( input ) ;
141
+ const read = typeof input === 'string' ? fs . promises . readFile ( input ) : Promise . resolve ( input ) ;
145
142
146
143
return read . then ( buf => extractFile ( buf , output , options ) ) ;
147
144
} ;
0 commit comments