@@ -6,6 +6,8 @@ import {BinaryUrl} from './binary';
6
6
import { XmlConfigSource } from './config_source' ;
7
7
8
8
export class ChromeXml extends XmlConfigSource {
9
+ maxVersion = Config . binaryVersions ( ) . maxChrome ;
10
+
9
11
constructor ( ) {
10
12
super ( 'chrome' , Config . cdnUrls ( ) [ 'chrome' ] ) ;
11
13
}
@@ -66,44 +68,26 @@ export class ChromeXml extends XmlConfigSource {
66
68
let latestVersion = '' ;
67
69
for ( let item of list ) {
68
70
// Get a semantic version
69
- let version = item . split ( '/' ) [ 0 ] ;
71
+ const version = item . split ( '/' ) [ 0 ] ;
70
72
if ( semver . valid ( version ) == null ) {
71
- // This supports downloading 74.0.3729.6
72
- try {
73
- const newRegex = / ( \d + .\d + .\d + ) .\d + / g;
74
- const exec = newRegex . exec ( version ) ;
75
- if ( exec ) {
76
- version = exec [ 1 ] ;
77
- }
78
- } catch ( _ ) {
79
- // no-op: if this does not work, use the other regex pattern.
80
- }
73
+ const iterVersion = getValidSemver ( version ) ;
81
74
82
- // This supports downloading 2.46
83
- try {
84
- const oldRegex = / ( \d + .\d + ) / g;
85
- const exec = oldRegex . exec ( version ) ;
86
- if ( exec ) {
87
- version = exec [ 1 ] + '.0' ;
88
- }
89
- } catch ( _ ) {
90
- // no-op: is this is not valid, do not throw here.
91
- }
92
-
93
- if ( ! semver . valid ( version ) ) {
75
+ if ( ! semver . valid ( iterVersion ) ) {
94
76
throw new Error ( 'invalid Chromedriver version' ) ;
95
77
}
96
78
// First time: use the version found.
97
79
if ( chromedriverVersion == null ) {
98
- chromedriverVersion = version ;
80
+ chromedriverVersion = iterVersion ;
99
81
latest = item ;
100
82
latestVersion = item . split ( '/' ) [ 0 ] ;
101
- } else if ( semver . gt ( version , chromedriverVersion ) ) {
83
+ } else if (
84
+ iterVersion . startsWith ( this . maxVersion ) &&
85
+ semver . gt ( iterVersion , chromedriverVersion ) ) {
102
86
// After the first time, make sure the semantic version is greater.
103
- chromedriverVersion = version ;
87
+ chromedriverVersion = iterVersion ;
104
88
latest = item ;
105
89
latestVersion = item . split ( '/' ) [ 0 ] ;
106
- } else if ( version === chromedriverVersion ) {
90
+ } else if ( iterVersion === chromedriverVersion ) {
107
91
// If the semantic version is the same, check os arch.
108
92
// For 64-bit systems, prefer the 64-bit version.
109
93
if ( this . osarch === 'x64' ) {
@@ -123,17 +107,18 @@ export class ChromeXml extends XmlConfigSource {
123
107
*/
124
108
private getSpecificChromeDriverVersion ( inputVersion : string ) : Promise < BinaryUrl > {
125
109
return this . getVersionList ( ) . then ( list => {
126
- let itemFound = '' ;
127
- let specificVersion = semver . valid ( inputVersion ) ? inputVersion : inputVersion + '.0' ;
110
+ const specificVersion = getValidSemver ( inputVersion ) ;
128
111
112
+ let itemFound = '' ;
129
113
for ( let item of list ) {
130
114
// Get a semantic version.
131
115
let version = item . split ( '/' ) [ 0 ] ;
132
116
if ( semver . valid ( version ) == null ) {
133
- version += '.0' ;
134
- if ( semver . valid ( version ) ) {
117
+ const lookUpVersion = getValidSemver ( version ) ;
118
+
119
+ if ( semver . valid ( lookUpVersion ) ) {
135
120
// Check to see if the specified version matches.
136
- if ( version === specificVersion ) {
121
+ if ( lookUpVersion === specificVersion ) {
137
122
// When item found is null, check the os arch
138
123
// 64-bit version works OR not 64-bit version and the path does not have '64'
139
124
if ( itemFound == '' ) {
@@ -162,3 +147,40 @@ export class ChromeXml extends XmlConfigSource {
162
147
} ) ;
163
148
}
164
149
}
150
+
151
+ /**
152
+ * Chromedriver is the only binary that does not conform to semantic versioning
153
+ * and either has too little number of digits or too many. To get this to be in
154
+ * semver, we will either add a '.0' at the end or chop off the last set of
155
+ * digits. This is so we can compare to find the latest and greatest.
156
+ *
157
+ * Example:
158
+ * 2.46 -> 2.46.0
159
+ * 75.0.3770.8 -> 75.0.3770
160
+ *
161
+ * @param version
162
+ */
163
+ export function getValidSemver ( version : string ) : string {
164
+ let lookUpVersion = '' ;
165
+ // This supports downloading 2.46
166
+ try {
167
+ const oldRegex = / ( \d + .\d + ) / g;
168
+ const exec = oldRegex . exec ( version ) ;
169
+ if ( exec ) {
170
+ lookUpVersion = exec [ 1 ] + '.0' ;
171
+ }
172
+ } catch ( _ ) {
173
+ // no-op: is this is not valid, do not throw here.
174
+ }
175
+ // This supports downloading 74.0.3729.6
176
+ try {
177
+ const newRegex = / ( \d + .\d + .\d + ) .\d + / g;
178
+ const exec = newRegex . exec ( version ) ;
179
+ if ( exec ) {
180
+ lookUpVersion = exec [ 1 ] ;
181
+ }
182
+ } catch ( _ ) {
183
+ // no-op: if this does not work, use the other regex pattern.
184
+ }
185
+ return lookUpVersion ;
186
+ }
0 commit comments