18
18
import { execSync } from 'child_process' ;
19
19
import * as os from 'os' ;
20
20
import * as path from 'path' ;
21
- import { assert , getFromENV } from '../helper' ;
21
+ import { getFromENV } from '../helper' ;
22
22
23
23
export type BrowserName = 'chromium' | 'webkit' | 'firefox' ;
24
24
export type BrowserPlatform = 'win32' | 'win64' | 'mac10.13' | 'mac10.14' | 'mac10.15' | 'linux' ;
@@ -40,9 +40,10 @@ export const hostPlatform = ((): BrowserPlatform => {
40
40
return platform as BrowserPlatform ;
41
41
} ) ( ) ;
42
42
43
- function getRelativeExecutablePath ( browserName : BrowserName ) : string [ ] | undefined {
44
- if ( browserName === 'chromium' ) {
45
- return new Map < BrowserPlatform , string [ ] > ( [
43
+ export function executablePath ( browserPath : string , browser : BrowserDescriptor ) : string | undefined {
44
+ let tokens : string [ ] | undefined ;
45
+ if ( browser . name === 'chromium' ) {
46
+ tokens = new Map < BrowserPlatform , string [ ] > ( [
46
47
[ 'linux' , [ 'chrome-linux' , 'chrome' ] ] ,
47
48
[ 'mac10.13' , [ 'chrome-mac' , 'Chromium.app' , 'Contents' , 'MacOS' , 'Chromium' ] ] ,
48
49
[ 'mac10.14' , [ 'chrome-mac' , 'Chromium.app' , 'Contents' , 'MacOS' , 'Chromium' ] ] ,
@@ -52,8 +53,8 @@ function getRelativeExecutablePath(browserName: BrowserName): string[] | undefin
52
53
] ) . get ( hostPlatform ) ;
53
54
}
54
55
55
- if ( browserName === 'firefox' ) {
56
- return new Map < BrowserPlatform , string [ ] > ( [
56
+ if ( browser . name === 'firefox' ) {
57
+ tokens = new Map < BrowserPlatform , string [ ] > ( [
57
58
[ 'linux' , [ 'firefox' , 'firefox' ] ] ,
58
59
[ 'mac10.13' , [ 'firefox' , 'Nightly.app' , 'Contents' , 'MacOS' , 'firefox' ] ] ,
59
60
[ 'mac10.14' , [ 'firefox' , 'Nightly.app' , 'Contents' , 'MacOS' , 'firefox' ] ] ,
@@ -63,8 +64,8 @@ function getRelativeExecutablePath(browserName: BrowserName): string[] | undefin
63
64
] ) . get ( hostPlatform ) ;
64
65
}
65
66
66
- if ( browserName === 'webkit' ) {
67
- return new Map < BrowserPlatform , string [ ] | undefined > ( [
67
+ if ( browser . name === 'webkit' ) {
68
+ tokens = new Map < BrowserPlatform , string [ ] | undefined > ( [
68
69
[ 'linux' , [ 'pw_run.sh' ] ] ,
69
70
[ 'mac10.13' , undefined ] ,
70
71
[ 'mac10.14' , [ 'pw_run.sh' ] ] ,
@@ -73,19 +74,19 @@ function getRelativeExecutablePath(browserName: BrowserName): string[] | undefin
73
74
[ 'win64' , [ 'Playwright.exe' ] ] ,
74
75
] ) . get ( hostPlatform ) ;
75
76
}
77
+ return tokens ? path . join ( browserPath , ...tokens ) : undefined ;
76
78
}
77
79
78
80
export function browsersPath ( packagePath : string ) : string {
79
81
const result = getFromENV ( 'PLAYWRIGHT_BROWSERS_PATH' ) ;
80
82
return result || path . join ( packagePath , '.local-browsers' ) ;
81
83
}
82
84
83
- export function browserDirectory ( packagePath : string , browser : BrowserDescriptor ) : string {
84
- return path . join ( browsersPath ( packagePath ) , `${ browser . name } -${ browser . revision } ` ) ;
85
+ export function browserDirectory ( browsersPath : string , browser : BrowserDescriptor ) : string {
86
+ return path . join ( browsersPath , `${ browser . name } -${ browser . revision } ` ) ;
85
87
}
86
88
87
- export function executablePath ( packagePath : string , browser : BrowserDescriptor ) : string {
88
- const relativePath = getRelativeExecutablePath ( browser . name ) ;
89
- assert ( relativePath , `Unsupported platform for ${ browser . name } : ${ hostPlatform } ` ) ;
90
- return path . join ( browserDirectory ( packagePath , browser ) , ...relativePath ) ;
89
+ export function isBrowserDirectory ( browserPath : string ) : boolean {
90
+ const baseName = path . basename ( browserPath ) ;
91
+ return baseName . startsWith ( 'chromium-' ) || baseName . startsWith ( 'firefox-' ) || baseName . startsWith ( 'webkit-' ) ;
91
92
}
0 commit comments