@@ -124,4 +124,44 @@ module.exports = {
124124 utils . which ( 'ccache' ) ,
125125 ] ) . then ( v => utils . determineFound ( 'ccache' , v [ 0 ] , v [ 1 ] ) ) ;
126126 } ,
127+
128+ get7zInfo : ( ) => {
129+ utils . log ( 'trace' , 'get7zInfo' ) ;
130+ const candidates = [ '7z' , '7zz' ] ;
131+
132+ const findFirstWhich = ( ) =>
133+ Promise . all ( candidates . map ( bin => utils . which ( bin ) ) ) . then ( paths => {
134+ const idx = paths . findIndex ( Boolean ) ;
135+ return idx >= 0 ? { bin : candidates [ idx ] , path : paths [ idx ] } : null ;
136+ } ) ;
137+
138+ if ( utils . isWindows ) {
139+ // Try default install location first
140+ return utils . windowsExeExists ( '7-Zip/7z.exe' ) . then ( filePath => {
141+ if ( filePath ) {
142+ return Promise . all ( [
143+ utils . run ( `powershell "& '${ filePath } ' i | Write-Output"` ) . then ( utils . findVersion ) ,
144+ Promise . resolve ( filePath ) ,
145+ ] ) . then ( v => utils . determineFound ( '7z' , v [ 0 ] , v [ 1 ] ) ) ;
146+ }
147+ // Fallback to PATH candidates
148+ return findFirstWhich ( ) . then ( found => {
149+ if ( ! found ) return utils . determineFound ( '7z' , '' , undefined ) ;
150+ return Promise . all ( [
151+ utils . run ( `${ found . bin } i` ) . then ( utils . findVersion ) ,
152+ Promise . resolve ( found . path ) ,
153+ ] ) . then ( v => utils . determineFound ( '7z' , v [ 0 ] , v [ 1 ] ) ) ;
154+ } ) ;
155+ } ) ;
156+ }
157+
158+ // macOS/Linux: find on PATH among common names
159+ return findFirstWhich ( ) . then ( found => {
160+ if ( ! found ) return utils . determineFound ( '7z' , '' , undefined ) ;
161+ return Promise . all ( [
162+ utils . run ( `${ found . bin } i` ) . then ( utils . findVersion ) ,
163+ Promise . resolve ( found . path ) ,
164+ ] ) . then ( v => utils . determineFound ( '7z' , v [ 0 ] , v [ 1 ] ) ) ;
165+ } ) ;
166+ } ,
127167} ;
0 commit comments