browserslist 4.18.1 → 4.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli.js CHANGED
@@ -20,7 +20,7 @@ var USAGE =
20
20
  ' npx browserslist --env="environment name defined in config"\n' +
21
21
  ' npx browserslist --stats="path/to/browserlist/stats/file"\n' +
22
22
  ' npx browserslist --mobile-to-desktop\n' +
23
- ' npx browserslist --ignore-unknown-versions' +
23
+ ' npx browserslist --ignore-unknown-versions\n' +
24
24
  ' npx browserslist --update-db'
25
25
 
26
26
  function isArg(arg) {
@@ -39,6 +39,7 @@ if (isArg('--help') || isArg('-h')) {
39
39
  } else if (isArg('--version') || isArg('-v')) {
40
40
  process.stdout.write('browserslist ' + pkg.version + '\n')
41
41
  } else if (isArg('--update-db')) {
42
+ /* c8 ignore next 3 */
42
43
  updateDb(function (str) {
43
44
  process.stdout.write(str)
44
45
  })
@@ -76,8 +77,10 @@ if (isArg('--help') || isArg('-h')) {
76
77
  } else if (name === '--json') {
77
78
  mode = 'json'
78
79
  } else if (name === '--mobile-to-desktop') {
80
+ /* c8 ignore next */
79
81
  opts.mobileToDesktop = true
80
82
  } else if (name === '--ignore-unknown-versions') {
83
+ /* c8 ignore next */
81
84
  opts.ignoreUnknownVersions = true
82
85
  } else {
83
86
  error('Unknown arguments ' + args[i] + '.\n\n' + USAGE)
@@ -90,9 +93,9 @@ if (isArg('--help') || isArg('-h')) {
90
93
  } catch (e) {
91
94
  if (e.name === 'BrowserslistError') {
92
95
  error(e.message)
93
- } else {
96
+ } else /* c8 ignore start */ {
94
97
  throw e
95
- }
98
+ } /* c8 ignore end */
96
99
  }
97
100
 
98
101
  var coverage
package/index.d.ts CHANGED
@@ -36,6 +36,10 @@ declare namespace browserslist {
36
36
  * Do not throw on unknown version in direct query.
37
37
  */
38
38
  ignoreUnknownVersions?: boolean
39
+ /**
40
+ * Throw a error if env is not found.
41
+ */
42
+ throwOnMissing?: boolean
39
43
  /**
40
44
  * Disable security checks for extend query.
41
45
  */
package/index.js CHANGED
@@ -397,6 +397,7 @@ var cache = {}
397
397
  * version in direct query.
398
398
  * @param {boolean} [opts.dangerousExtend] Disable security checks
399
399
  * for extend query.
400
+ * @param {boolean} [opts.throwOnMissing] Throw error on missing env.
400
401
  * @param {boolean} [opts.mobileToDesktop] Alias mobile browsers to the desktop
401
402
  * version when Can I Use doesn't have
402
403
  * data about the specified version.
@@ -665,7 +666,7 @@ function coverQuery(context, coverage, statMode) {
665
666
  var coveraged = 0
666
667
  var result = []
667
668
  var version
668
- for (var i = 0; i <= versions.length; i++) {
669
+ for (var i = 0; i < versions.length; i++) {
669
670
  version = versions[i]
670
671
  if (usage[version] === 0) break
671
672
  coveraged += usage[version]
@@ -831,19 +832,24 @@ var QUERIES = [
831
832
  }
832
833
  var usage = context.customUsage
833
834
  return Object.keys(usage).reduce(function (result, version) {
835
+ var percentage = usage[version]
836
+ if (percentage == null) {
837
+ return result
838
+ }
839
+
834
840
  if (sign === '>') {
835
- if (usage[version] > popularity) {
841
+ if (percentage > popularity) {
836
842
  result.push(version)
837
843
  }
838
844
  } else if (sign === '<') {
839
- if (usage[version] < popularity) {
845
+ if (percentage < popularity) {
840
846
  result.push(version)
841
847
  }
842
848
  } else if (sign === '<=') {
843
- if (usage[version] <= popularity) {
849
+ if (percentage <= popularity) {
844
850
  result.push(version)
845
851
  }
846
- } else if (usage[version] >= popularity) {
852
+ } else if (percentage >= popularity) {
847
853
  result.push(version)
848
854
  }
849
855
  return result
@@ -866,19 +872,24 @@ var QUERIES = [
866
872
  }
867
873
  var usage = context.customUsage
868
874
  return Object.keys(usage).reduce(function (result, version) {
875
+ var percentage = usage[version]
876
+ if (percentage == null) {
877
+ return result
878
+ }
879
+
869
880
  if (sign === '>') {
870
- if (usage[version] > popularity) {
881
+ if (percentage > popularity) {
871
882
  result.push(version)
872
883
  }
873
884
  } else if (sign === '<') {
874
- if (usage[version] < popularity) {
885
+ if (percentage < popularity) {
875
886
  result.push(version)
876
887
  }
877
888
  } else if (sign === '<=') {
878
- if (usage[version] <= popularity) {
889
+ if (percentage <= popularity) {
879
890
  result.push(version)
880
891
  }
881
- } else if (usage[version] >= popularity) {
892
+ } else if (percentage >= popularity) {
882
893
  result.push(version)
883
894
  }
884
895
  return result
@@ -897,19 +908,24 @@ var QUERIES = [
897
908
  env.loadCountry(browserslist.usage, place, browserslist.data)
898
909
  var usage = browserslist.usage[place]
899
910
  return Object.keys(usage).reduce(function (result, version) {
911
+ var percentage = usage[version]
912
+ if (percentage == null) {
913
+ return result
914
+ }
915
+
900
916
  if (sign === '>') {
901
- if (usage[version] > popularity) {
917
+ if (percentage > popularity) {
902
918
  result.push(version)
903
919
  }
904
920
  } else if (sign === '<') {
905
- if (usage[version] < popularity) {
921
+ if (percentage < popularity) {
906
922
  result.push(version)
907
923
  }
908
924
  } else if (sign === '<=') {
909
- if (usage[version] <= popularity) {
925
+ if (percentage <= popularity) {
910
926
  result.push(version)
911
927
  }
912
- } else if (usage[version] >= popularity) {
928
+ } else if (percentage >= popularity) {
913
929
  result.push(version)
914
930
  }
915
931
  return result
@@ -1038,7 +1054,7 @@ var QUERIES = [
1038
1054
  {
1039
1055
  regexp: /^(firefox|ff|fx)\s+esr$/i,
1040
1056
  select: function () {
1041
- return ['firefox 78', 'firefox 91']
1057
+ return ['firefox 91']
1042
1058
  }
1043
1059
  },
1044
1060
  {
package/node.js CHANGED
@@ -82,6 +82,14 @@ function pickEnv(config, opts) {
82
82
  name = 'production'
83
83
  }
84
84
 
85
+ if (opts.throwOnMissing) {
86
+ if (name && name !== 'defaults' && !config[name]) {
87
+ throw new BrowserslistError(
88
+ 'Missing config for Browserslist environment `' + name + '`'
89
+ )
90
+ }
91
+ }
92
+
85
93
  return config[name] || config.defaults
86
94
  }
87
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserslist",
3
- "version": "4.18.1",
3
+ "version": "4.19.3",
4
4
  "description": "Share target browsers between different front-end tools, like Autoprefixer, Stylelint and babel-env-preset",
5
5
  "keywords": [
6
6
  "caniuse",
@@ -15,10 +15,10 @@
15
15
  "license": "MIT",
16
16
  "repository": "browserslist/browserslist",
17
17
  "dependencies": {
18
- "caniuse-lite": "^1.0.30001280",
19
- "electron-to-chromium": "^1.3.896",
18
+ "caniuse-lite": "^1.0.30001312",
19
+ "electron-to-chromium": "^1.4.71",
20
20
  "escalade": "^3.1.1",
21
- "node-releases": "^2.0.1",
21
+ "node-releases": "^2.0.2",
22
22
  "picocolors": "^1.0.0"
23
23
  },
24
24
  "engines": {
package/update-db.js CHANGED
@@ -151,12 +151,14 @@ function updateYarnLockfile(lock, latest) {
151
151
  /resolved "[^"]+"/,
152
152
  'resolved "' + latest.dist.tarball + '"'
153
153
  )
154
- lines[3] = latest.dist.integrity
155
- ? lines[3].replace(
156
- /integrity .+/,
157
- 'integrity ' + latest.dist.integrity
158
- )
159
- : ''
154
+ if (lines.length === 4) {
155
+ lines[3] = latest.dist.integrity
156
+ ? lines[3].replace(
157
+ /integrity .+/,
158
+ 'integrity ' + latest.dist.integrity
159
+ )
160
+ : ''
161
+ }
160
162
  }
161
163
  }
162
164
  })
@@ -168,64 +170,14 @@ function updateYarnLockfile(lock, latest) {
168
170
  return { content: content, versions: versions }
169
171
  }
170
172
 
171
- function updatePnpmLockfile(lock, latest) {
172
- var versions = {}
173
- var lines = lock.content.split('\n')
174
- var i
175
- var j
176
- var lineParts
177
-
178
- for (i = 0; i < lines.length; i++) {
179
- if (lines[i].indexOf('caniuse-lite:') >= 0) {
180
- lineParts = lines[i].split(/:\s?/, 2)
181
- if (lineParts[1].indexOf('/') >= 0) {
182
- var sublineParts = lineParts[1].split(/([/:])/)
183
- for (j = 0; j < sublineParts.length; j++) {
184
- if (sublineParts[j].indexOf('caniuse-lite') >= 0) {
185
- versions[sublineParts[j + 2]] = true
186
- sublineParts[j + 2] = latest.version
187
- break
188
- }
189
- }
190
- lineParts[1] = sublineParts.join('')
191
- } else {
192
- versions[lineParts[1]] = true
193
- }
194
- lines[i] = lineParts[0] + ': ' + latest.version
195
- } else if (lines[i].indexOf('/caniuse-lite') >= 0) {
196
- lineParts = lines[i].split(/([/:])/)
197
- for (j = 0; j < lineParts.length; j++) {
198
- if (lineParts[j].indexOf('caniuse-lite') >= 0) {
199
- versions[lineParts[j + 2]] = true
200
- lineParts[j + 2] = latest.version
201
- break
202
- }
203
- }
204
- lines[i] = lineParts.join('')
205
- for (i = i + 1; i < lines.length; i++) {
206
- if (lines[i].indexOf('integrity: ') !== -1) {
207
- lines[i] = lines[i].replace(
208
- /integrity: .+/,
209
- 'integrity: ' + latest.dist.integrity
210
- )
211
- } else if (lines[i].indexOf(' /') !== -1) {
212
- break
213
- }
214
- }
215
- }
216
- }
217
- return { content: lines.join('\n'), versions: versions }
218
- }
219
-
220
173
  function updateLockfile(lock, latest) {
221
174
  if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
222
175
 
223
- if (lock.mode === 'npm') {
224
- return updateNpmLockfile(lock, latest)
225
- } else if (lock.mode === 'yarn') {
176
+ if (lock.mode === 'yarn') {
226
177
  return updateYarnLockfile(lock, latest)
178
+ } else {
179
+ return updateNpmLockfile(lock, latest)
227
180
  }
228
- return updatePnpmLockfile(lock, latest)
229
181
  }
230
182
 
231
183
  function updatePackageManually(print, lock, latest) {
@@ -262,7 +214,7 @@ function updatePackageManually(print, lock, latest) {
262
214
  )
263
215
  try {
264
216
  childProcess.execSync(install + ' caniuse-lite')
265
- } catch (e) /* istanbul ignore next */ {
217
+ } catch (e) /* c8 ignore start */ {
266
218
  print(
267
219
  pico.red(
268
220
  '\n' +
@@ -275,7 +227,7 @@ function updatePackageManually(print, lock, latest) {
275
227
  )
276
228
  )
277
229
  process.exit(1)
278
- }
230
+ } /* c8 ignore end */
279
231
 
280
232
  var del = lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode + ' uninstall'
281
233
  print(
@@ -286,6 +238,27 @@ function updatePackageManually(print, lock, latest) {
286
238
  childProcess.execSync(del + ' caniuse-lite')
287
239
  }
288
240
 
241
+ function updateWith(print, cmd) {
242
+ print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
243
+ try {
244
+ childProcess.execSync(cmd)
245
+ } catch (e) /* c8 ignore start */ {
246
+ print(pico.red(e.stdout.toString()))
247
+ print(
248
+ pico.red(
249
+ '\n' +
250
+ e.stack +
251
+ '\n\n' +
252
+ 'Problem with `' +
253
+ cmd +
254
+ '` call. ' +
255
+ 'Run it manually.\n'
256
+ )
257
+ )
258
+ process.exit(1)
259
+ } /* c8 ignore end */
260
+ }
261
+
289
262
  module.exports = function updateDB(print) {
290
263
  var lock = detectLockfile()
291
264
  var latest = getLatestInfo(lock)
@@ -301,28 +274,9 @@ module.exports = function updateDB(print) {
301
274
  print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
302
275
 
303
276
  if (lock.mode === 'yarn' && lock.version !== 1) {
304
- var update = 'yarn up -R'
305
- print(
306
- 'Updating caniuse-lite version\n' +
307
- pico.yellow('$ ' + update + ' caniuse-lite') +
308
- '\n'
309
- )
310
- try {
311
- childProcess.execSync(update + ' caniuse-lite')
312
- } catch (e) /* istanbul ignore next */ {
313
- print(
314
- pico.red(
315
- '\n' +
316
- e.stack +
317
- '\n\n' +
318
- 'Problem with `' +
319
- update +
320
- ' caniuse-lite` call. ' +
321
- 'Run it manually.\n'
322
- )
323
- )
324
- process.exit(1)
325
- }
277
+ updateWith(print, 'yarn up -R caniuse-lite')
278
+ } else if (lock.mode === 'pnpm') {
279
+ updateWith(print, 'pnpm up caniuse-lite')
326
280
  } else {
327
281
  updatePackageManually(print, lock, latest)
328
282
  }
@@ -333,9 +287,9 @@ module.exports = function updateDB(print) {
333
287
  if (!browsersListRetrievalError) {
334
288
  try {
335
289
  currentBrowsersList = getBrowsersList()
336
- } catch (e) /* istanbul ignore next */ {
290
+ } catch (e) /* c8 ignore start */ {
337
291
  browsersListRetrievalError = e
338
- }
292
+ } /* c8 ignore end */
339
293
  }
340
294
 
341
295
  if (browsersListRetrievalError) {