browserslist 4.18.1 → 4.19.0

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
@@ -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.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
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.0",
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,8 +15,8 @@
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.30001286",
19
+ "electron-to-chromium": "^1.4.17",
20
20
  "escalade": "^3.1.1",
21
21
  "node-releases": "^2.0.1",
22
22
  "picocolors": "^1.0.0"
@@ -24,6 +24,7 @@
24
24
  "engines": {
25
25
  "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
26
26
  },
27
+ "packageManager": "pnpm@6.23.6",
27
28
  "bin": {
28
29
  "browserslist": "cli.js"
29
30
  },
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
  })
@@ -179,6 +181,7 @@ function updatePnpmLockfile(lock, latest) {
179
181
  if (lines[i].indexOf('caniuse-lite:') >= 0) {
180
182
  lineParts = lines[i].split(/:\s?/, 2)
181
183
  if (lineParts[1].indexOf('/') >= 0) {
184
+ /* c8 ignore start */
182
185
  var sublineParts = lineParts[1].split(/([/:])/)
183
186
  for (j = 0; j < sublineParts.length; j++) {
184
187
  if (sublineParts[j].indexOf('caniuse-lite') >= 0) {
@@ -188,6 +191,7 @@ function updatePnpmLockfile(lock, latest) {
188
191
  }
189
192
  }
190
193
  lineParts[1] = sublineParts.join('')
194
+ /* c8 ignore stop */
191
195
  } else {
192
196
  versions[lineParts[1]] = true
193
197
  }
@@ -220,12 +224,13 @@ function updatePnpmLockfile(lock, latest) {
220
224
  function updateLockfile(lock, latest) {
221
225
  if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
222
226
 
223
- if (lock.mode === 'npm') {
224
- return updateNpmLockfile(lock, latest)
225
- } else if (lock.mode === 'yarn') {
227
+ if (lock.mode === 'yarn') {
226
228
  return updateYarnLockfile(lock, latest)
229
+ } else if (lock.mode === 'pnpm') {
230
+ return updatePnpmLockfile(lock, latest)
231
+ } else {
232
+ return updateNpmLockfile(lock, latest)
227
233
  }
228
- return updatePnpmLockfile(lock, latest)
229
234
  }
230
235
 
231
236
  function updatePackageManually(print, lock, latest) {
@@ -262,7 +267,7 @@ function updatePackageManually(print, lock, latest) {
262
267
  )
263
268
  try {
264
269
  childProcess.execSync(install + ' caniuse-lite')
265
- } catch (e) /* istanbul ignore next */ {
270
+ } catch (e) /* c8 ignore start */ {
266
271
  print(
267
272
  pico.red(
268
273
  '\n' +
@@ -275,7 +280,7 @@ function updatePackageManually(print, lock, latest) {
275
280
  )
276
281
  )
277
282
  process.exit(1)
278
- }
283
+ } /* c8 ignore end */
279
284
 
280
285
  var del = lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode + ' uninstall'
281
286
  print(
@@ -286,6 +291,27 @@ function updatePackageManually(print, lock, latest) {
286
291
  childProcess.execSync(del + ' caniuse-lite')
287
292
  }
288
293
 
294
+ function updateWith(print, cmd) {
295
+ print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
296
+ try {
297
+ childProcess.execSync(cmd)
298
+ } catch (e) /* c8 ignore start */ {
299
+ print(pico.red(e.stdout.toString()))
300
+ print(
301
+ pico.red(
302
+ '\n' +
303
+ e.stack +
304
+ '\n\n' +
305
+ 'Problem with `' +
306
+ cmd +
307
+ '` call. ' +
308
+ 'Run it manually.\n'
309
+ )
310
+ )
311
+ process.exit(1)
312
+ } /* c8 ignore end */
313
+ }
314
+
289
315
  module.exports = function updateDB(print) {
290
316
  var lock = detectLockfile()
291
317
  var latest = getLatestInfo(lock)
@@ -301,28 +327,7 @@ module.exports = function updateDB(print) {
301
327
  print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
302
328
 
303
329
  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
- }
330
+ updateWith(print, 'yarn up -R caniuse-lite')
326
331
  } else {
327
332
  updatePackageManually(print, lock, latest)
328
333
  }
@@ -333,9 +338,9 @@ module.exports = function updateDB(print) {
333
338
  if (!browsersListRetrievalError) {
334
339
  try {
335
340
  currentBrowsersList = getBrowsersList()
336
- } catch (e) /* istanbul ignore next */ {
341
+ } catch (e) /* c8 ignore start */ {
337
342
  browsersListRetrievalError = e
338
- }
343
+ } /* c8 ignore end */
339
344
  }
340
345
 
341
346
  if (browsersListRetrievalError) {