@@ -28,7 +28,7 @@ const fsReaddirAsync = util.promisify(fs.readdir.bind(fs));
28
28
const fsReadFileAsync = util . promisify ( fs . readFile . bind ( fs ) ) ;
29
29
const fsUnlinkAsync = util . promisify ( fs . unlink . bind ( fs ) ) ;
30
30
const fsWriteFileAsync = util . promisify ( fs . writeFile . bind ( fs ) ) ;
31
- const rmAsync = util . promisify ( removeFolder ) ;
31
+ const removeFolderAsync = util . promisify ( removeFolder ) ;
32
32
33
33
export async function installBrowsersWithProgressBar ( packagePath : string ) {
34
34
const browsersPath = browserPaths . browsersPath ( packagePath ) ;
@@ -60,27 +60,18 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
60
60
}
61
61
}
62
62
63
- // 2. Delete all stale browser extract directories and .zip files.
64
- // NOTE: this must not run concurrently with other installations.
65
- let staleFiles = ( await fsReaddirAsync ( browsersPath ) ) . map ( file => path . join ( browsersPath , file ) ) ;
66
- staleFiles = staleFiles . filter ( file => browserPaths . isBrowserZipFile ( file ) || browserPaths . isBrowserExtractDirectory ( file ) ) ;
67
- for ( const staleFile of staleFiles ) {
68
- logPolitely ( 'Removing leftover from interrupted installation ' + staleFile ) ;
69
- await rmAsync ( staleFile ) . catch ( e => { } ) ;
70
- }
71
-
72
- // 3. Delete all unused browsers.
63
+ // 2. Delete all unused browsers.
73
64
let downloadedBrowsers = ( await fsReaddirAsync ( browsersPath ) ) . map ( file => path . join ( browsersPath , file ) ) ;
74
65
downloadedBrowsers = downloadedBrowsers . filter ( file => browserPaths . isBrowserDirectory ( file ) ) ;
75
66
const directories = new Set < string > ( downloadedBrowsers ) ;
76
67
for ( const browser of allBrowsers )
77
68
directories . delete ( browserPaths . browserDirectory ( browsersPath , browser ) ) ;
78
69
for ( const directory of directories ) {
79
70
logPolitely ( 'Removing unused browser at ' + directory ) ;
80
- await rmAsync ( directory ) . catch ( e => { } ) ;
71
+ await removeFolderAsync ( directory ) . catch ( e => { } ) ;
81
72
}
82
73
83
- // 4 . Install missing browsers for this package.
74
+ // 3 . Install missing browsers for this package.
84
75
const myBrowsers = JSON . parse ( ( await fsReadFileAsync ( path . join ( packagePath , 'browsers.json' ) ) ) . toString ( ) ) [ 'browsers' ] as browserPaths . BrowserDescriptor [ ] ;
85
76
for ( const browser of myBrowsers ) {
86
77
const browserPath = browserPaths . browserDirectory ( browsersPath , browser ) ;
0 commit comments