@@ -7,11 +7,8 @@ import decompressTargz from 'decompress-targz';
77import decompressUnzip from 'decompress-unzip' ;
88import fs from 'graceful-fs' ;
99import makeDir from 'make-dir' ;
10- import pify from 'pify' ;
1110import stripDirs from 'strip-dirs' ;
1211
13- const fsP = pify ( fs ) ;
14-
1512const runPlugins = ( input , options ) => {
1613 if ( options . plugins . length === 0 ) {
1714 return Promise . resolve ( [ ] ) ;
@@ -21,7 +18,7 @@ const runPlugins = (input, options) => {
2118 return Promise . all ( options . plugins . map ( x => x ( input , options ) ) ) . then ( files => files . reduce ( ( a , b ) => a . concat ( b ) ) ) ;
2219} ;
2320
24- const safeMakeDir = ( dir , realOutputPath ) => fsP . realpath ( dir )
21+ const safeMakeDir = ( dir , realOutputPath ) => fs . promises . realpath ( dir )
2522 . catch ( _ => {
2623 const parent = path . dirname ( dir ) ;
2724 return safeMakeDir ( parent , realOutputPath ) ;
@@ -31,10 +28,10 @@ const safeMakeDir = (dir, realOutputPath) => fsP.realpath(dir)
3128 throw new Error ( 'Refusing to create a directory outside the output path.' ) ;
3229 }
3330
34- return makeDir ( dir ) . then ( fsP . realpath ) ;
31+ return makeDir ( dir ) . then ( fs . promises . realpath ) ;
3532 } ) ;
3633
37- const preventWritingThroughSymlink = ( destination , realOutputPath ) => fsP . readlink ( destination )
34+ const preventWritingThroughSymlink = ( destination , realOutputPath ) => fs . promises . readlink ( destination )
3835 // Either no file exists, or it's not a symlink. In either case, this is
3936 // not an escape we need to worry about in this phase.
4037 . catch ( _ => null )
@@ -76,14 +73,14 @@ const extractFile = (input, output, options) => runPlugins(input, options).then(
7673
7774 if ( x . type === 'directory' ) {
7875 return makeDir ( output )
79- . then ( outputPath => fsP . realpath ( outputPath ) )
76+ . then ( outputPath => fs . promises . realpath ( outputPath ) )
8077 . then ( realOutputPath => safeMakeDir ( dest , realOutputPath ) )
81- . then ( ( ) => fsP . utimes ( dest , now , x . mtime ) )
78+ . then ( ( ) => fs . promises . utimes ( dest , now , x . mtime ) )
8279 . then ( ( ) => x ) ;
8380 }
8481
8582 return makeDir ( output )
86- . then ( outputPath => fsP . realpath ( outputPath ) )
83+ . then ( outputPath => fs . promises . realpath ( outputPath ) )
8784 . then ( realOutputPath =>
8885 // Attempt to ensure parent directory exists (failing if it's outside the output dir)
8986 safeMakeDir ( path . dirname ( dest ) , realOutputPath ) . then ( ( ) => realOutputPath ) ,
@@ -95,28 +92,28 @@ const extractFile = (input, output, options) => runPlugins(input, options).then(
9592
9693 return realOutputPath ;
9794 } )
98- . then ( realOutputPath => fsP . realpath ( path . dirname ( dest ) )
95+ . then ( realOutputPath => fs . promises . realpath ( path . dirname ( dest ) )
9996 . then ( realDestinationDir => {
10097 if ( realDestinationDir . indexOf ( realOutputPath ) !== 0 ) {
10198 throw new Error ( `Refusing to write outside output directory: ${ realDestinationDir } ` ) ;
10299 }
103100 } ) )
104101 . then ( ( ) => {
105102 if ( x . type === 'link' ) {
106- return fsP . link ( x . linkname , dest ) ;
103+ return fs . promises . link ( x . linkname , dest ) ;
107104 }
108105
109106 if ( x . type === 'symlink' && process . platform === 'win32' ) {
110- return fsP . link ( x . linkname , dest ) ;
107+ return fs . promises . link ( x . linkname , dest ) ;
111108 }
112109
113110 if ( x . type === 'symlink' ) {
114- return fsP . symlink ( x . linkname , dest ) ;
111+ return fs . promises . symlink ( x . linkname , dest ) ;
115112 }
116113
117- return fsP . writeFile ( dest , x . data , { mode} ) ;
114+ return fs . promises . writeFile ( dest , x . data , { mode} ) ;
118115 } )
119- . then ( ( ) => x . type === 'file' && fsP . utimes ( dest , now , x . mtime ) )
116+ . then ( ( ) => x . type === 'file' && fs . promises . utimes ( dest , now , x . mtime ) )
120117 . then ( ( ) => x ) ;
121118 } ) ) ;
122119} ) ;
@@ -141,7 +138,7 @@ const decompress = (input, output, options) => {
141138 ...options ,
142139 } ;
143140
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 ) ;
145142
146143 return read . then ( buf => extractFile ( buf , output , options ) ) ;
147144} ;
0 commit comments