browserslist 4.17.6 → 4.19.1

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,6 +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
24
  ' npx browserslist --update-db'
24
25
 
25
26
  function isArg(arg) {
@@ -38,6 +39,7 @@ if (isArg('--help') || isArg('-h')) {
38
39
  } else if (isArg('--version') || isArg('-v')) {
39
40
  process.stdout.write('browserslist ' + pkg.version + '\n')
40
41
  } else if (isArg('--update-db')) {
42
+ /* c8 ignore next 3 */
41
43
  updateDb(function (str) {
42
44
  process.stdout.write(str)
43
45
  })
@@ -75,7 +77,11 @@ if (isArg('--help') || isArg('-h')) {
75
77
  } else if (name === '--json') {
76
78
  mode = 'json'
77
79
  } else if (name === '--mobile-to-desktop') {
80
+ /* c8 ignore next */
78
81
  opts.mobileToDesktop = true
82
+ } else if (name === '--ignore-unknown-versions') {
83
+ /* c8 ignore next */
84
+ opts.ignoreUnknownVersions = true
79
85
  } else {
80
86
  error('Unknown arguments ' + args[i] + '.\n\n' + USAGE)
81
87
  }
@@ -87,9 +93,9 @@ if (isArg('--help') || isArg('-h')) {
87
93
  } catch (e) {
88
94
  if (e.name === 'BrowserslistError') {
89
95
  error(e.message)
90
- } else {
96
+ } else /* c8 ignore start */ {
91
97
  throw e
92
- }
98
+ } /* c8 ignore end */
93
99
  }
94
100
 
95
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
@@ -209,7 +209,8 @@ function filterByYear(since, context) {
209
209
  var data = byName(name, context)
210
210
  if (!data) return selected
211
211
  var versions = Object.keys(data.releaseDate).filter(function (v) {
212
- return data.releaseDate[v] >= since
212
+ var date = data.releaseDate[v]
213
+ return date !== null && date >= since
213
214
  })
214
215
  return selected.concat(versions.map(nameMapper(data.name)))
215
216
  }, [])
@@ -396,6 +397,7 @@ var cache = {}
396
397
  * version in direct query.
397
398
  * @param {boolean} [opts.dangerousExtend] Disable security checks
398
399
  * for extend query.
400
+ * @param {boolean} [opts.throwOnMissing] Throw error on missing env.
399
401
  * @param {boolean} [opts.mobileToDesktop] Alias mobile browsers to the desktop
400
402
  * version when Can I Use doesn't have
401
403
  * data about the specified version.
@@ -642,7 +644,7 @@ function coverQuery(context, coverage, statMode) {
642
644
  coverage = parseFloat(coverage)
643
645
  var usage = browserslist.usage.global
644
646
  if (statMode) {
645
- if (statMode.match(/^my\s+stats$/)) {
647
+ if (statMode.match(/^my\s+stats$/i)) {
646
648
  if (!context.customUsage) {
647
649
  throw new BrowserslistError('Custom usage statistics was not provided')
648
650
  }
@@ -664,7 +666,7 @@ function coverQuery(context, coverage, statMode) {
664
666
  var coveraged = 0
665
667
  var result = []
666
668
  var version
667
- for (var i = 0; i <= versions.length; i++) {
669
+ for (var i = 0; i < versions.length; i++) {
668
670
  version = versions[i]
669
671
  if (usage[version] === 0) break
670
672
  coveraged += usage[version]
@@ -830,19 +832,24 @@ var QUERIES = [
830
832
  }
831
833
  var usage = context.customUsage
832
834
  return Object.keys(usage).reduce(function (result, version) {
835
+ var percentage = usage[version]
836
+ if (percentage == null) {
837
+ return result
838
+ }
839
+
833
840
  if (sign === '>') {
834
- if (usage[version] > popularity) {
841
+ if (percentage > popularity) {
835
842
  result.push(version)
836
843
  }
837
844
  } else if (sign === '<') {
838
- if (usage[version] < popularity) {
845
+ if (percentage < popularity) {
839
846
  result.push(version)
840
847
  }
841
848
  } else if (sign === '<=') {
842
- if (usage[version] <= popularity) {
849
+ if (percentage <= popularity) {
843
850
  result.push(version)
844
851
  }
845
- } else if (usage[version] >= popularity) {
852
+ } else if (percentage >= popularity) {
846
853
  result.push(version)
847
854
  }
848
855
  return result
@@ -865,19 +872,24 @@ var QUERIES = [
865
872
  }
866
873
  var usage = context.customUsage
867
874
  return Object.keys(usage).reduce(function (result, version) {
875
+ var percentage = usage[version]
876
+ if (percentage == null) {
877
+ return result
878
+ }
879
+
868
880
  if (sign === '>') {
869
- if (usage[version] > popularity) {
881
+ if (percentage > popularity) {
870
882
  result.push(version)
871
883
  }
872
884
  } else if (sign === '<') {
873
- if (usage[version] < popularity) {
885
+ if (percentage < popularity) {
874
886
  result.push(version)
875
887
  }
876
888
  } else if (sign === '<=') {
877
- if (usage[version] <= popularity) {
889
+ if (percentage <= popularity) {
878
890
  result.push(version)
879
891
  }
880
- } else if (usage[version] >= popularity) {
892
+ } else if (percentage >= popularity) {
881
893
  result.push(version)
882
894
  }
883
895
  return result
@@ -896,19 +908,24 @@ var QUERIES = [
896
908
  env.loadCountry(browserslist.usage, place, browserslist.data)
897
909
  var usage = browserslist.usage[place]
898
910
  return Object.keys(usage).reduce(function (result, version) {
911
+ var percentage = usage[version]
912
+ if (percentage == null) {
913
+ return result
914
+ }
915
+
899
916
  if (sign === '>') {
900
- if (usage[version] > popularity) {
917
+ if (percentage > popularity) {
901
918
  result.push(version)
902
919
  }
903
920
  } else if (sign === '<') {
904
- if (usage[version] < popularity) {
921
+ if (percentage < popularity) {
905
922
  result.push(version)
906
923
  }
907
924
  } else if (sign === '<=') {
908
- if (usage[version] <= popularity) {
925
+ if (percentage <= popularity) {
909
926
  result.push(version)
910
927
  }
911
- } else if (usage[version] >= popularity) {
928
+ } else if (percentage >= popularity) {
912
929
  result.push(version)
913
930
  }
914
931
  return result
@@ -916,11 +933,11 @@ var QUERIES = [
916
933
  }
917
934
  },
918
935
  {
919
- regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%$/,
936
+ regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%$/i,
920
937
  select: coverQuery
921
938
  },
922
939
  {
923
- regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%\s+in\s+(my\s+stats|(alt-)?\w\w)$/,
940
+ regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%\s+in\s+(my\s+stats|(alt-)?\w\w)$/i,
924
941
  select: coverQuery
925
942
  },
926
943
  {
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.17.6",
3
+ "version": "4.19.1",
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.30001274",
19
- "electron-to-chromium": "^1.3.886",
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) {