browserslist 4.18.0 → 4.19.2

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
@@ -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.18.0",
3
+ "version": "4.19.2",
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) {