browserslist 4.6.5 → 4.7.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.
Files changed (5) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +24 -19
  3. package/index.js +23 -35
  4. package/node.js +26 -14
  5. package/package.json +11 -4
package/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
+ ## 4.7.2
5
+ * Add cache for query parsing.
6
+ * Improve config caching (by Kārlis Gaņģis).
7
+
8
+ ## 4.7.1
9
+ * Improve caching.
10
+
11
+ ## 4.7
12
+ * Add PhantomJS queries.
13
+ * Improve docs (by Dorian Koehring).
14
+
15
+ ## 4.6.6
16
+ * Remove Safari from `dead` query.
17
+
4
18
  ## 4.6.5
5
19
  * Add Samsung 4 browser to `dead` query.
6
20
  * Remove dirty fix for `android all` error.
package/README.md CHANGED
@@ -45,7 +45,6 @@ Browserslist will take queries from tool option,
45
45
  `browserslist` config, `.browserslistrc` config,
46
46
  `browserslist` section in `package.json` or environment variables.
47
47
 
48
- You can test Browserslist queries in [online demo].
49
48
  [Browserslist Example] shows how every tool uses Browserslist.
50
49
 
51
50
  [cult-img]: https://cultofmartians.com/assets/badges/badge.svg
@@ -62,7 +61,6 @@ You can test Browserslist queries in [online demo].
62
61
  [postcss-preset-env]: https://github.com/jonathantneal/postcss-preset-env
63
62
  [postcss-normalize]: https://github.com/jonathantneal/postcss-normalize
64
63
  [Autoprefixer]: https://github.com/postcss/autoprefixer
65
- [online demo]: https://browserl.ist/
66
64
  [Can I Use]: https://caniuse.com/
67
65
  [Babel]: https://github.com/babel/babel/tree/master/packages/babel-preset-env
68
66
  [obsolete-webpack-plugin]: https://github.com/ElemeFE/obsolete-webpack-plugin
@@ -73,16 +71,17 @@ You can test Browserslist queries in [online demo].
73
71
  2. [Best Practices](#best-practices)
74
72
  3. [Queries](#queries)
75
73
  4. [Config File](#config-file)
76
- 5. [Configuring for Different Environments](#configuring-for-different-environments)
77
- 6. [Custom Usage Data](#custom-usage-data)
78
- 7. [JS API](#js-api)
79
- 8. [Environment Variables](#environment-variables)
80
- 9. [Cache](#cache)
74
+ 5. [Shareable Configs](#shareable-configs)
75
+ 6. [Configuring for Different Environments](#configuring-for-different-environments)
76
+ 7. [Custom Usage Data](#custom-usage-data)
77
+ 8. [JS API](#js-api)
78
+ 9. [Environment Variables](#environment-variables)
79
+ 10. [Cache](#cache)
81
80
 
82
81
  ## Tools
83
82
 
84
- * [`browserslist-ga`] downloads your website browsers statistics
85
- to use it in `> 0.5% in my stats` query.
83
+ * [`browserslist-ga`] and [`browserslist-ga-export`] download your website
84
+ browsers statistics to use it in `> 0.5% in my stats` query.
86
85
  * [`browserslist-useragent-regexp`] compiles Browserslist query to a RegExp
87
86
  to test browser useragent.
88
87
  * [`browserslist-useragent-ruby`] is a Ruby library to checks browser
@@ -94,12 +93,13 @@ You can test Browserslist queries in [online demo].
94
93
  target browsers. This CLI tool is built-in and available in any project
95
94
  with Autoprefixer.
96
95
 
96
+ [`browserslist-useragent-regexp`]: https://github.com/browserslist/browserslist-useragent-regexp
97
97
  [`browserslist-useragent-ruby`]: https://github.com/browserslist/browserslist-useragent-ruby
98
+ [`browserslist-browserstack`]: https://github.com/xeroxinteractive/browserslist-browserstack
99
+ [`browserslist-ga-export`]: https://github.com/browserslist/browserslist-ga-export
98
100
  [`browserslist-useragent`]: https://github.com/pastelsky/browserslist-useragent
99
- [`browserslist-useragent-regexp`]: https://github.com/browserslist/browserslist-useragent-regexp
100
101
  [`browserslist-ga`]: https://github.com/browserslist/browserslist-ga
101
102
  [`caniuse-api`]: https://github.com/Nyalab/caniuse-api
102
- [`browserslist-browserstack`]: https://github.com/xeroxinteractive/browserslist-browserstack
103
103
 
104
104
 
105
105
  ## Best Practices
@@ -133,7 +133,7 @@ You can test Browserslist queries in [online demo].
133
133
  ## Queries
134
134
 
135
135
  Browserslist will use browsers and Node.js versions query
136
- from one of this sources:
136
+ from one of these sources:
137
137
 
138
138
  1. `browserslist` key in `package.json` file in current or parent directories.
139
139
  **We recommend this way.**
@@ -194,6 +194,8 @@ You can specify the browser and Node.js versions by queries (case insensitive):
194
194
  `>=`, `<` and `<=` work too. It also works with Node.js.
195
195
  * `iOS 7`: the iOS browser version 7 directly.
196
196
  * `Firefox ESR`: the latest [Firefox ESR] version.
197
+ * `PhantomJS 2.1` and `PhantomJS 1.9`: selects Safari versions similar
198
+ to PhantomJS runtime.
197
199
  * `unreleased versions` or `unreleased Chrome versions`:
198
200
  alpha and beta versions.
199
201
  * `last 2 major versions` or `last 2 iOS major versions`:
@@ -407,8 +409,10 @@ If you have a website, you can query against the usage statistics of your site.
407
409
  npx browserslist-ga
408
410
  ```
409
411
 
410
- Of course, you can generate usage statistics file by any other method.
411
- File format should be like:
412
+ Or you can use [`browserslist-ga-export`] to convert Google Analytics data without giving a password for Google account.
413
+
414
+ You can generate usage statistics file by any other method. File format should
415
+ be like:
412
416
 
413
417
  ```js
414
418
  {
@@ -424,12 +428,13 @@ File format should be like:
424
428
  }
425
429
  ```
426
430
 
427
- Note that you can query against your custom usage data
428
- while also querying against global or regional data.
429
- For example, the query `> 1% in my stats, > 5% in US, 10%` is permitted.
431
+ Note that you can query against your custom usage data while also querying
432
+ against global or regional data. For example, the query
433
+ `> 1% in my stats, > 5% in US, 10%` is permitted.
430
434
 
431
- [`browserslist-ga`]: https://github.com/browserslist/browserslist-ga
432
- [Can I Use]: https://caniuse.com/
435
+ [`browserslist-ga-export`]: https://github.com/browserslist/browserslist-ga-export
436
+ [`browserslist-ga`]: https://github.com/browserslist/browserslist-ga
437
+ [Can I Use]: https://caniuse.com/
433
438
 
434
439
 
435
440
  ## JS API
package/index.js CHANGED
@@ -10,10 +10,7 @@ var env = require('./node') // Will load browser.js in webpack
10
10
  var FLOAT_RANGE = /^\d+(\.\d+)?(-\d+(\.\d+)?)*$/
11
11
  var YEAR = 365.259641 * 24 * 60 * 60 * 1000
12
12
 
13
- // Enum values MUST be powers of 2, so combination are safe
14
- /** @constant {number} */
15
13
  var QUERY_OR = 1
16
- /** @constant {number} */
17
14
  var QUERY_AND = 2
18
15
 
19
16
  function isVersionsMatch (versionA, versionB) {
@@ -265,14 +262,10 @@ function resolve (queries, context) {
265
262
  case QUERY_AND:
266
263
  if (isExclude) {
267
264
  return result.filter(function (j) {
268
- // remove result items that are in array
269
- // (the relative complement of array in result)
270
265
  return array.indexOf(j) === -1
271
266
  })
272
267
  } else {
273
268
  return result.filter(function (j) {
274
- // remove result items not in array
275
- // (intersect of result and array)
276
269
  return array.indexOf(j) !== -1
277
270
  })
278
271
  }
@@ -287,7 +280,6 @@ function resolve (queries, context) {
287
280
  return !filter[j]
288
281
  })
289
282
  }
290
- // union of result and array
291
283
  return result.concat(array)
292
284
  }
293
285
  }
@@ -297,6 +289,8 @@ function resolve (queries, context) {
297
289
  }, [])
298
290
  }
299
291
 
292
+ var cache = { }
293
+
300
294
  /**
301
295
  * Return array of browsers by selection queries.
302
296
  *
@@ -358,7 +352,10 @@ function browserslist (queries, opts) {
358
352
  }
359
353
  }
360
354
 
361
- var result = resolve(queries, context).sort(function (name1, name2) {
355
+ var cacheKey = JSON.stringify([queries, context])
356
+ if (cache[cacheKey]) return cache[cacheKey]
357
+
358
+ var result = uniq(resolve(queries, context)).sort(function (name1, name2) {
362
359
  name1 = name1.split(' ')
363
360
  name2 = name2.split(' ')
364
361
  if (name1[0] === name2[0]) {
@@ -371,39 +368,20 @@ function browserslist (queries, opts) {
371
368
  return compare(name1[0], name2[0])
372
369
  }
373
370
  })
374
-
375
- return uniq(result)
371
+ if (!process.env.BROWSERSLIST_DISABLE_CACHE) {
372
+ cache[cacheKey] = result
373
+ }
374
+ return result
376
375
  }
377
376
 
378
- /**
379
- * @typedef {object} BrowserslistQuery
380
- * @property {number} type A type constant like QUERY_OR @see QUERY_OR.
381
- * @property {string} queryString A query like "not ie < 11".
382
- */
383
-
384
- /**
385
- * Parse a browserslist string query
386
- * @param {string} queries One or more queries as a string
387
- * @returns {BrowserslistQuery[]} An array of BrowserslistQuery
388
- */
389
377
  function parse (queries) {
390
378
  var qs = []
391
-
392
379
  do {
393
380
  queries = doMatch(queries, qs)
394
381
  } while (queries)
395
-
396
382
  return qs
397
383
  }
398
384
 
399
- /**
400
- * Find query matches in a string. This function is meant to be called
401
- * repeatedly with the returned query string until there is no more matches.
402
- * @param {string} string A string with one or more queries.
403
- * @param {BrowserslistQuery[]} qs Out parameter,
404
- * will be filled with `BrowserslistQuery`.
405
- * @returns {string} The rest of the query string minus the matched part.
406
- */
407
385
  function doMatch (string, qs) {
408
386
  var or = /^(?:,\s*|\s+OR\s+)(.*)/i
409
387
  var and = /^\s+AND\s+(.*)/i
@@ -857,7 +835,7 @@ var QUERIES = [
857
835
  {
858
836
  regexp: /^(firefox|ff|fx)\s+esr$/i,
859
837
  select: function () {
860
- return ['firefox 68', 'firefox 60']
838
+ return ['firefox 68']
861
839
  }
862
840
  },
863
841
  {
@@ -918,6 +896,18 @@ var QUERIES = [
918
896
  return resolve(queries, context)
919
897
  }
920
898
  },
899
+ {
900
+ regexp: /^phantomjs\s+1.9$/i,
901
+ select: function () {
902
+ return ['safari 5']
903
+ }
904
+ },
905
+ {
906
+ regexp: /^phantomjs\s+2.1$/i,
907
+ select: function () {
908
+ return ['safari 6']
909
+ }
910
+ },
921
911
  {
922
912
  regexp: /^(\w+)\s+(tp|[\d.]+)$/i,
923
913
  select: function (context, name, version) {
@@ -964,8 +954,6 @@ var QUERIES = [
964
954
  'ie <= 10', 'ie_mob <= 10',
965
955
  'bb <= 10',
966
956
  'op_mob <= 12.1',
967
- 'safari <= 11',
968
- 'ios_saf <= 11',
969
957
  'samsung 4'
970
958
  ]
971
959
  return resolve(dead, context)
package/node.js CHANGED
@@ -42,7 +42,8 @@ function isFile (file) {
42
42
  }
43
43
 
44
44
  function eachParent (file, callback) {
45
- var loc = path.resolve(file)
45
+ var dir = isFile(file) ? path.dirname(file) : file
46
+ var loc = path.resolve(dir)
46
47
  do {
47
48
  var result = callback(loc)
48
49
  if (typeof result !== 'undefined') return result
@@ -83,7 +84,8 @@ function parsePackage (file) {
83
84
  var config = JSON.parse(fs.readFileSync(file))
84
85
  if (config.browserlist && !config.browserslist) {
85
86
  throw new BrowserslistError(
86
- '`browserlist` key instead of `browserslist` in ' + file)
87
+ '`browserlist` key instead of `browserslist` in ' + file
88
+ )
87
89
  }
88
90
  var list = config.browserslist
89
91
  if (Array.isArray(list) || typeof list === 'string') {
@@ -116,7 +118,8 @@ module.exports = {
116
118
  var queries = require(require.resolve(name, { paths: ['.'] }))
117
119
  if (!Array.isArray(queries)) {
118
120
  throw new BrowserslistError(
119
- '`' + name + '` config exports not an array of queries')
121
+ '`' + name + '` config exports not an array of queries'
122
+ )
120
123
  }
121
124
  return queries
122
125
  },
@@ -214,7 +217,8 @@ module.exports = {
214
217
  sections.forEach(function (section) {
215
218
  if (result[section]) {
216
219
  throw new BrowserslistError(
217
- 'Duplicate section ' + section + ' in Browserslist config')
220
+ 'Duplicate section ' + section + ' in Browserslist config'
221
+ )
218
222
  }
219
223
  result[section] = []
220
224
  })
@@ -238,12 +242,14 @@ module.exports = {
238
242
  findConfig: function findConfig (from) {
239
243
  from = path.resolve(from)
240
244
 
241
- var cacheKey = isFile(from) ? path.dirname(from) : from
242
- if (cacheKey in configCache) {
243
- return configCache[cacheKey]
244
- }
245
-
245
+ var passed = []
246
246
  var resolved = eachParent(from, function (dir) {
247
+ if (dir in configCache) {
248
+ return configCache[dir]
249
+ }
250
+
251
+ passed.push(dir)
252
+
247
253
  var config = path.join(dir, 'browserslist')
248
254
  var pkg = path.join(dir, 'package.json')
249
255
  var rc = path.join(dir, '.browserslistrc')
@@ -255,19 +261,23 @@ module.exports = {
255
261
  } catch (e) {
256
262
  if (e.name === 'BrowserslistError') throw e
257
263
  console.warn(
258
- '[Browserslist] Could not parse ' + pkg + '. Ignoring it.')
264
+ '[Browserslist] Could not parse ' + pkg + '. Ignoring it.'
265
+ )
259
266
  }
260
267
  }
261
268
 
262
269
  if (isFile(config) && pkgBrowserslist) {
263
270
  throw new BrowserslistError(
264
- dir + ' contains both browserslist and package.json with browsers')
271
+ dir + ' contains both browserslist and package.json with browsers'
272
+ )
265
273
  } else if (isFile(rc) && pkgBrowserslist) {
266
274
  throw new BrowserslistError(
267
- dir + ' contains both .browserslistrc and package.json with browsers')
275
+ dir + ' contains both .browserslistrc and package.json with browsers'
276
+ )
268
277
  } else if (isFile(config) && isFile(rc)) {
269
278
  throw new BrowserslistError(
270
- dir + ' contains both .browserslistrc and browserslist')
279
+ dir + ' contains both .browserslistrc and browserslist'
280
+ )
271
281
  } else if (isFile(config)) {
272
282
  return module.exports.readConfig(config)
273
283
  } else if (isFile(rc)) {
@@ -277,7 +287,9 @@ module.exports = {
277
287
  }
278
288
  })
279
289
  if (!process.env.BROWSERSLIST_DISABLE_CACHE) {
280
- configCache[cacheKey] = resolved
290
+ passed.forEach(function (dir) {
291
+ configCache[dir] = resolved
292
+ })
281
293
  }
282
294
  return resolved
283
295
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserslist",
3
- "version": "4.6.5",
3
+ "version": "4.7.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",
@@ -11,13 +11,20 @@
11
11
  "license": "MIT",
12
12
  "repository": "browserslist/browserslist",
13
13
  "dependencies": {
14
- "caniuse-lite": "^1.0.30000984",
15
- "electron-to-chromium": "^1.3.191",
16
- "node-releases": "^1.1.25"
14
+ "caniuse-lite": "^1.0.30001004",
15
+ "electron-to-chromium": "^1.3.295",
16
+ "node-releases": "^1.1.38"
17
17
  },
18
18
  "bin": "./cli.js",
19
19
  "browser": {
20
20
  "./node.js": "./browser.js",
21
21
  "path": false
22
+ },
23
+ "eslintIgnore": [
24
+ "test/fixtures"
25
+ ],
26
+ "sharec": {
27
+ "config": "@logux/sharec-config",
28
+ "version": "0.5.4"
22
29
  }
23
30
  }