17
17
import path from 'path' ;
18
18
import { canAccessFile } from '../../utils/utils' ;
19
19
20
- function darwin ( channel : string ) : string | undefined {
20
+ function darwin ( channel : string ) : string [ ] | undefined {
21
21
switch ( channel ) {
22
- case 'chrome' : return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' ;
23
- case 'chrome-beta' : return '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta' ;
24
- case 'chrome-dev' : return '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev' ;
25
- case 'chrome-canary' : return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary' ;
26
- case 'msedge' : return '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' ;
27
- case 'msedge-beta' : return '/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta' ;
28
- case 'msedge-dev' : return '/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev' ;
29
- case 'msedge-canary' : return '/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary' ;
22
+ case 'chrome' : return [ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' ] ;
23
+ case 'chrome-beta' : return [ '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta' ] ;
24
+ case 'chrome-dev' : return [ '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev' ] ;
25
+ case 'chrome-canary' : return [ '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary' ] ;
26
+ case 'msedge' : return [ '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' ] ;
27
+ case 'msedge-beta' : return [ '/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta' ] ;
28
+ case 'msedge-dev' : return [ '/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev' ] ;
29
+ case 'msedge-canary' : return [ '/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary' ] ;
30
30
}
31
31
}
32
32
33
- function linux ( channel : string ) : string | undefined {
33
+ function linux ( channel : string ) : string [ ] | undefined {
34
34
switch ( channel ) {
35
- case 'chrome' : return '/opt/google/chrome/chrome' ;
36
- case 'chrome-beta' : return '/opt/google/chrome-beta/chrome' ;
37
- case 'chrome-dev' : return '/opt/google/chrome-unstable/chrome' ;
38
- case 'msedge-dev' : return '/opt/microsoft/msedge-dev/msedge' ;
35
+ case 'chrome' : return [ '/opt/google/chrome/chrome' ] ;
36
+ case 'chrome-beta' : return [ '/opt/google/chrome-beta/chrome' ] ;
37
+ case 'chrome-dev' : return [ '/opt/google/chrome-unstable/chrome' ] ;
38
+ case 'msedge-dev' : return [ '/opt/microsoft/msedge-dev/msedge' ] ;
39
39
}
40
40
}
41
41
42
- function win32 ( channel : string ) : string | undefined {
42
+ function win32 ( channel : string ) : string [ ] | undefined {
43
43
let suffix : string | undefined ;
44
44
switch ( channel ) {
45
45
case 'chrome' : suffix = `\\Google\\Chrome\\Application\\chrome.exe` ; break ;
@@ -56,29 +56,27 @@ function win32(channel: string): string | undefined {
56
56
const prefixes = [
57
57
process . env . LOCALAPPDATA , process . env . PROGRAMFILES , process . env [ 'PROGRAMFILES(X86)' ]
58
58
] . filter ( Boolean ) as string [ ] ;
59
-
60
- let result : string | undefined ;
61
- prefixes . forEach ( prefix => {
62
- const chromePath = path . join ( prefix , suffix ! ) ;
63
- if ( canAccessFile ( chromePath ) )
64
- result = chromePath ;
65
- } ) ;
66
- return result ;
59
+ return prefixes . map ( prefix => path . join ( prefix , suffix ! ) ) ;
67
60
}
68
61
69
62
export function findChromiumChannel ( channel : string ) : string {
70
- let result : string | undefined ;
63
+ let installationPaths : string [ ] | undefined ;
71
64
if ( process . platform === 'linux' )
72
- result = linux ( channel ) ;
65
+ installationPaths = linux ( channel ) ;
73
66
else if ( process . platform === 'win32' )
74
- result = win32 ( channel ) ;
67
+ installationPaths = win32 ( channel ) ;
75
68
else if ( process . platform === 'darwin' )
76
- result = darwin ( channel ) ;
69
+ installationPaths = darwin ( channel ) ;
77
70
78
- if ( ! result )
71
+ if ( ! installationPaths )
79
72
throw new Error ( `Chromium distribution '${ channel } ' is not supported on ${ process . platform } ` ) ;
80
73
81
- if ( canAccessFile ( result ) )
74
+ let result : string | undefined ;
75
+ installationPaths . forEach ( chromePath => {
76
+ if ( canAccessFile ( chromePath ) )
77
+ result = chromePath ;
78
+ } ) ;
79
+ if ( result )
82
80
return result ;
83
- throw new Error ( `Chromium distribution was not found : ${ channel } ` ) ;
81
+ throw new Error ( `Chromium distribution is not installed on the system : ${ channel } ` ) ;
84
82
}
0 commit comments