@@ -32,7 +32,7 @@ const fsUnlinkAsync = util.promisify(fs.unlink.bind(fs));
32
32
const fsWriteFileAsync = util . promisify ( fs . writeFile . bind ( fs ) ) ;
33
33
const removeFolderAsync = util . promisify ( removeFolder ) ;
34
34
35
- export async function installBrowsersWithProgressBar ( packagePath : string ) {
35
+ export async function installBrowsersWithProgressBar ( packagePath : string , browserNames ?: browserPaths . BrowserName [ ] ) {
36
36
// PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD should have a value of 0 or 1
37
37
if ( getAsBooleanFromENV ( 'PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD' ) ) {
38
38
browserFetcher . logPolitely ( 'Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set' ) ;
@@ -59,11 +59,11 @@ export async function installBrowsersWithProgressBar(packagePath: string) {
59
59
60
60
await fsMkdirAsync ( linksDir , { recursive : true } ) ;
61
61
await fsWriteFileAsync ( path . join ( linksDir , sha1 ( packagePath ) ) , packagePath ) ;
62
- await validateCache ( packagePath , browsersPath , linksDir ) ;
62
+ await validateCache ( packagePath , browsersPath , linksDir , browserNames ) ;
63
63
await releaseLock ( ) ;
64
64
}
65
65
66
- async function validateCache ( packagePath : string , browsersPath : string , linksDir : string ) {
66
+ async function validateCache ( packagePath : string , browsersPath : string , linksDir : string , browserNames ?: browserPaths . BrowserName [ ] ) {
67
67
// 1. Collect used downloads and package descriptors.
68
68
const usedBrowserPaths : Set < string > = new Set ( ) ;
69
69
for ( const fileName of await fsReaddirAsync ( linksDir ) ) {
@@ -99,7 +99,7 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
99
99
}
100
100
101
101
// 3. Install missing browsers for this package.
102
- const myBrowsersToDownload = await readBrowsersToDownload ( packagePath ) ;
102
+ const myBrowsersToDownload = await readBrowsersToDownload ( packagePath , browserNames ) ;
103
103
for ( const browser of myBrowsersToDownload ) {
104
104
await browserFetcher . downloadBrowserWithProgressBar ( browsersPath , browser ) . catch ( e => {
105
105
throw new Error ( `Failed to download ${ browser . name } , caused by\n${ e . stack } ` ) ;
@@ -108,11 +108,13 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
108
108
}
109
109
}
110
110
111
- async function readBrowsersToDownload ( packagePath : string ) {
111
+ async function readBrowsersToDownload ( packagePath : string , browserNames ?: browserPaths . BrowserName [ ] ) {
112
112
const browsers = JSON . parse ( ( await fsReadFileAsync ( path . join ( packagePath , 'browsers.json' ) ) ) . toString ( ) ) [ 'browsers' ] as browserPaths . BrowserDescriptor [ ] ;
113
113
// Older versions do not have "download" field. We assume they need all browsers
114
114
// from the list. So we want to skip all browsers that are explicitly marked as "download: false".
115
- return browsers . filter ( browser => browser . download !== false ) ;
115
+ return browsers . filter ( browser => {
116
+ return browserNames ? browserNames . includes ( browser . name ) : browser . download !== false ;
117
+ } ) ;
116
118
}
117
119
118
120
function sha1 ( data : string ) : string {
0 commit comments