browserslist 4.16.8 → 4.17.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.
Files changed (3) hide show
  1. package/README.md +2 -641
  2. package/package.json +5 -5
  3. package/update-db.js +66 -36
package/README.md CHANGED
@@ -62,644 +62,5 @@ Browserslist will take queries from tool option,
62
62
  [Babel]: https://github.com/babel/babel/tree/master/packages/babel-preset-env
63
63
  [obsolete-webpack-plugin]: https://github.com/ElemeFE/obsolete-webpack-plugin
64
64
 
65
- ## Table of Contents
66
-
67
- * [Tools](#tools)
68
- * [Text Editors](#text-editors)
69
- * [Best Practices](#best-practices)
70
- * [Browsers Data Updating](#browsers-data-updating)
71
- * [Queries](#queries)
72
- * [Query Composition](#query-composition)
73
- * [Full List](#full-list)
74
- * [Debug](#debug)
75
- * [Browsers](#browsers)
76
- * [Config File](#config-file)
77
- * [`package.json`](#packagejson)
78
- * [`.browserslistrc`](#browserslistrc)
79
- * [Shareable Configs](#shareable-configs)
80
- * [Configuring for Different Environments](#configuring-for-different-environments)
81
- * [Custom Usage Data](#custom-usage-data)
82
- * [JS API](#js-api)
83
- * [Environment Variables](#environment-variables)
84
- * [Cache](#cache)
85
- * [Security Contact](#security-contact)
86
- * [For Enterprise](#for-enterprise)
87
-
88
- ## Tools
89
-
90
- * [`browserl.ist`](https://browserl.ist/) is an online tool to check
91
- what browsers will be selected by some query.
92
- * [`browserslist-ga`] and [`browserslist-ga-export`] download your website
93
- browsers statistics to use it in `> 0.5% in my stats` query.
94
- * [`browserslist-useragent-regexp`] compiles Browserslist query to a RegExp
95
- to test browser useragent.
96
- * [`browserslist-useragent-ruby`] is a Ruby library to checks browser
97
- by user agent string to match Browserslist.
98
- * [`browserslist-browserstack`] runs BrowserStack tests for all browsers
99
- in Browserslist config.
100
- * [`browserslist-adobe-analytics`] use Adobe Analytics data to target browsers.
101
- * [`caniuse-api`] returns browsers which support some specific feature.
102
- * Run `npx browserslist` in your project directory to see project’s
103
- target browsers. This CLI tool is built-in and available in any project
104
- with Autoprefixer.
105
-
106
- [`browserslist-useragent-regexp`]: https://github.com/browserslist/browserslist-useragent-regexp
107
- [`browserslist-adobe-analytics`]: https://github.com/xeroxinteractive/browserslist-adobe-analytics
108
- [`browserslist-useragent-ruby`]: https://github.com/browserslist/browserslist-useragent-ruby
109
- [`browserslist-browserstack`]: https://github.com/xeroxinteractive/browserslist-browserstack
110
- [`browserslist-ga-export`]: https://github.com/browserslist/browserslist-ga-export
111
- [`browserslist-useragent`]: https://github.com/pastelsky/browserslist-useragent
112
- [`browserslist-ga`]: https://github.com/browserslist/browserslist-ga
113
- [`caniuse-api`]: https://github.com/Nyalab/caniuse-api
114
-
115
-
116
- ### Text Editors
117
-
118
- These extensions will add syntax highlighting for `.browserslistrc` files.
119
-
120
- * [VS Code](https://marketplace.visualstudio.com/items?itemName=webben.browserslist)
121
- * [Vim](https://github.com/browserslist/vim-browserslist)
122
-
123
- ## Best Practices
124
-
125
- * There is a `defaults` query, which gives a reasonable configuration
126
- for most users:
127
-
128
- ```json
129
- "browserslist": [
130
- "defaults"
131
- ]
132
- ```
133
-
134
- * If you want to change the default set of browsers, we recommend combining
135
- `last 2 versions`, `not dead` with a usage number like `> 0.2%`. This is
136
- because `last n versions` on its own does not add popular old versions, while
137
- only using a percentage above `0.2%` will in the long run make popular
138
- browsers even more popular. We might run into a monopoly and stagnation
139
- situation, as we had with Internet Explorer 6. Please use this setting
140
- with caution.
141
- * Select browsers directly (`last 2 Chrome versions`) only if you are making
142
- a web app for a kiosk with one browser. There are a lot of browsers
143
- on the market. If you are making general web app you should respect
144
- browsers diversity.
145
- * Don’t remove browsers just because you don’t know them. Opera Mini has
146
- 100 million users in Africa and it is more popular in the global market
147
- than Microsoft Edge. Chinese QQ Browsers has more market share than Firefox
148
- and desktop Safari combined.
149
-
150
-
151
- ## Browsers Data Updating
152
-
153
- `npx browserslist@latest --update-db` updates `caniuse-lite` version
154
- in your npm, yarn or pnpm lock file.
155
-
156
- You need to do it regularly for two reasons:
157
-
158
- 1. To use the latest browser’s versions and statistics in queries like
159
- `last 2 versions` or `>1%`. For example, if you created your project
160
- 2 years ago and did not update your dependencies, `last 1 version`
161
- will return 2 year old browsers.
162
- 2. `caniuse-lite` deduplication: to synchronize version in different tools.
163
-
164
- > What is deduplication?
165
-
166
- Due to how npm architecture is setup, you may have a situation
167
- where you have multiple versions of a single dependency required.
168
-
169
- Imagine you begin a project, and you add `autoprefixer` as a dependency.
170
- npm looks for the latest `caniuse-lite` version (1.0.30000700) and adds it to
171
- `package-lock.json` under `autoprefixer` dependencies.
172
-
173
- A year later, you decide to add Babel. At this moment, we have a
174
- new version of `canuse-lite` (1.0.30000900). npm took the latest version
175
- and added it to your lock file under `@babel/preset-env` dependencies.
176
-
177
- Now your lock file looks like this:
178
-
179
- ```ocaml
180
- autoprefixer 7.1.4
181
- browserslist 3.1.1
182
- caniuse-lite 1.0.30000700
183
- @babel/preset-env 7.10.0
184
- browserslist 4.13.0
185
- caniuse-lite 1.0.30000900
186
- ```
187
-
188
- As you can see, we now have two versions of `caniuse-lite` installed.
189
-
190
-
191
- ## Queries
192
-
193
- Browserslist will use browsers and Node.js versions query
194
- from one of these sources:
195
-
196
- 1. `browserslist` key in `package.json` file in current or parent directories.
197
- **We recommend this way.**
198
- 2. `.browserslistrc` config file in current or parent directories.
199
- 3. `browserslist` config file in current or parent directories.
200
- 4. `BROWSERSLIST` environment variable.
201
- 5. If the above methods did not produce a valid result
202
- Browserslist will use defaults:
203
- `> 0.5%, last 2 versions, Firefox ESR, not dead`.
204
-
205
-
206
- ### Query Composition
207
-
208
- An `or` combiner can use the keyword `or` as well as `,`.
209
- `last 1 version or > 1%` is equal to `last 1 version, > 1%`.
210
-
211
- `and` query combinations are also supported to perform an
212
- intersection of all the previous queries:
213
- `last 1 version or chrome > 75 and > 1%` will select
214
- (`browser last version` or `Chrome since 76`) and `more than 1% marketshare`.
215
-
216
- There are 3 different ways to combine queries as depicted below. First you start
217
- with a single query and then we combine the queries to get our final list.
218
-
219
- Obviously you can *not* start with a `not` combiner, since there is no left-hand
220
- side query to combine it with. The left-hand is always resolved as `and`
221
- combiner even if `or` is used (this is an API implementation specificity).
222
-
223
- | Query combiner type | Illustration | Example |
224
- | ------------------- | :----------: | ------- |
225
- |`or`/`,` combiner <br> (union) | ![Union of queries](img/union.svg) | `> .5% or last 2 versions` <br> `> .5%, last 2 versions` |
226
- | `and` combiner <br> (intersection) | ![intersection of queries](img/intersection.svg) | `> .5% and last 2 versions` |
227
- | `not` combiner <br> (relative complement) | ![Relative complement of queries](img/complement.svg) | All those three are equivalent to the first one <br> `> .5% and not last 2 versions` <br> `> .5% or not last 2 versions` <br> `> .5%, not last 2 versions` |
228
-
229
- _A quick way to test your query is to do `npx browserslist '> 0.5%, not IE 11'`
230
- in your terminal._
231
-
232
- ### Full List
233
-
234
- You can specify the browser and Node.js versions by queries (case insensitive):
235
-
236
- * `defaults`: Browserslist’s default browsers
237
- (`> 0.5%, last 2 versions, Firefox ESR, not dead`).
238
- * By usage statistics:
239
- * `> 5%`: browsers versions selected by global usage statistics.
240
- `>=`, `<` and `<=` work too.
241
- * `> 5% in US`: uses USA usage statistics.
242
- It accepts [two-letter country code].
243
- * `> 5% in alt-AS`: uses Asia region usage statistics.
244
- List of all region codes can be found at [`caniuse-lite/data/regions`].
245
- * `> 5% in my stats`: uses [custom usage data].
246
- * `> 5% in browserslist-config-mycompany stats`: uses [custom usage data]
247
- from `browserslist-config-mycompany/browserslist-stats.json`.
248
- * `cover 99.5%`: most popular browsers that provide coverage.
249
- * `cover 99.5% in US`: same as above, with [two-letter country code].
250
- * `cover 99.5% in my stats`: uses [custom usage data].
251
- * Last versions:
252
- * `last 2 versions`: the last 2 versions for *each* browser.
253
- * `last 2 Chrome versions`: the last 2 versions of Chrome browser.
254
- * `last 2 major versions` or `last 2 iOS major versions`:
255
- all minor/patch releases of last 2 major versions.
256
- * `dead`: browsers without official support or updates for 24 months.
257
- Right now it is `IE 10`, `IE_Mob 11`, `BlackBerry 10`, `BlackBerry 7`,
258
- `Samsung 4` and `OperaMobile 12.1`.
259
- * Node.js versions:
260
- * `node 10` and `node 10.4`: selects latest Node.js `10.x.x`
261
- or `10.4.x` release.
262
- * `current node`: Node.js version used by Browserslist right now.
263
- * `maintained node versions`: all Node.js versions, which are [still maintained]
264
- by Node.js Foundation.
265
- * Browsers versions:
266
- * `iOS 7`: the iOS browser version 7 directly.
267
- * `Firefox > 20`: versions of Firefox newer than 20.
268
- `>=`, `<` and `<=` work too. It also works with Node.js.
269
- * `ie 6-8`: selects an inclusive range of versions.
270
- * `Firefox ESR`: the latest [Firefox Extended Support Release].
271
- * `PhantomJS 2.1` and `PhantomJS 1.9`: selects Safari versions similar
272
- to PhantomJS runtime.
273
- * `extends browserslist-config-mycompany`: take queries from
274
- `browserslist-config-mycompany` npm package.
275
- * `supports es6-module`: browsers with support for specific features.
276
- `es6-module` here is the `feat` parameter at the URL of the [Can I Use]
277
- page. A list of all available features can be found at
278
- [`caniuse-lite/data/features`].
279
- * `browserslist config`: the browsers defined in Browserslist config. Useful
280
- in Differential Serving to modify user’s config like
281
- `browserslist config and supports es6-module`.
282
- * `since 2015` or `last 2 years`: all versions released since year 2015
283
- (also `since 2015-03` and `since 2015-03-10`).
284
- * `unreleased versions` or `unreleased Chrome versions`:
285
- alpha and beta versions.
286
- * `not ie <= 8`: exclude IE 8 and lower from previous queries.
287
-
288
- You can add `not ` to any query.
289
-
290
- [`caniuse-lite/data/regions`]: https://github.com/ben-eb/caniuse-lite/tree/master/data/regions
291
- [`caniuse-lite/data/features`]: https://github.com/ben-eb/caniuse-lite/tree/master/data/features
292
- [two-letter country code]: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
293
- [custom usage data]: #custom-usage-data
294
- [still maintained]: https://github.com/nodejs/Release
295
- [Can I Use]: https://caniuse.com/
296
- [Firefox Extended Support Release]: https://support.mozilla.org/en-US/kb/choosing-firefox-update-channel
297
-
298
-
299
- ### Debug
300
-
301
- Run `npx browserslist` in project directory to see what browsers was selected
302
- by your queries.
303
-
304
- ```sh
305
- $ npx browserslist
306
- and_chr 61
307
- and_ff 56
308
- and_qq 1.2
309
- and_uc 11.4
310
- android 56
311
- baidu 7.12
312
- bb 10
313
- chrome 62
314
- edge 16
315
- firefox 56
316
- ios_saf 11
317
- opera 48
318
- safari 11
319
- samsung 5
320
- ```
321
-
322
-
323
- ### Browsers
324
-
325
- Names are case insensitive:
326
-
327
- * `Android` for Android WebView.
328
- * `Baidu` for Baidu Browser.
329
- * `BlackBerry` or `bb` for Blackberry browser.
330
- * `Chrome` for Google Chrome.
331
- * `ChromeAndroid` or `and_chr` for Chrome for Android
332
- * `Edge` for Microsoft Edge.
333
- * `Electron` for Electron framework. It will be converted to Chrome version.
334
- * `Explorer` or `ie` for Internet Explorer.
335
- * `ExplorerMobile` or `ie_mob` for Internet Explorer Mobile.
336
- * `Firefox` or `ff` for Mozilla Firefox.
337
- * `FirefoxAndroid` or `and_ff` for Firefox for Android.
338
- * `iOS` or `ios_saf` for iOS Safari.
339
- * `Node` for Node.js.
340
- * `Opera` for Opera.
341
- * `OperaMini` or `op_mini` for Opera Mini.
342
- * `OperaMobile` or `op_mob` for Opera Mobile.
343
- * `QQAndroid` or `and_qq` for QQ Browser for Android.
344
- * `Safari` for desktop Safari.
345
- * `Samsung` for Samsung Internet.
346
- * `UCAndroid` or `and_uc` for UC Browser for Android.
347
- * `kaios` for KaiOS Browser.
348
-
349
-
350
- ## Config File
351
-
352
- ### `package.json`
353
-
354
- If you want to reduce config files in project root, you can specify
355
- browsers in `package.json` with `browserslist` key:
356
-
357
- ```json
358
- {
359
- "private": true,
360
- "dependencies": {
361
- "autoprefixer": "^6.5.4"
362
- },
363
- "browserslist": [
364
- "last 1 version",
365
- "> 1%",
366
- "IE 10"
367
- ]
368
- }
369
- ```
370
-
371
-
372
- ### `.browserslistrc`
373
-
374
- Separated Browserslist config should be named `.browserslistrc`
375
- and have browsers queries split by a new line.
376
- Each line is combined with the `or` combiner. Comments starts with `#` symbol:
377
-
378
- ```yaml
379
- # Browsers that we support
380
-
381
- last 1 version
382
- > 1%
383
- IE 10 # sorry
384
- ```
385
-
386
- Browserslist will check config in every directory in `path`.
387
- So, if tool process `app/styles/main.css`, you can put config to root,
388
- `app/` or `app/styles`.
389
-
390
- You can specify direct path in `BROWSERSLIST_CONFIG` environment variables.
391
-
392
-
393
- ## Shareable Configs
394
-
395
- You can use the following query to reference an exported Browserslist config
396
- from another package:
397
-
398
- ```json
399
- "browserslist": [
400
- "extends browserslist-config-mycompany"
401
- ]
402
- ```
403
-
404
- For security reasons, external configuration only supports packages that have
405
- the `browserslist-config-` prefix. npm scoped packages are also supported, by
406
- naming or prefixing the module with `@scope/browserslist-config`, such as
407
- `@scope/browserslist-config` or `@scope/browserslist-config-mycompany`.
408
-
409
- If you don’t accept Browserslist queries from users, you can disable the
410
- validation by using the or `BROWSERSLIST_DANGEROUS_EXTEND` environment variable.
411
-
412
- ```sh
413
- BROWSERSLIST_DANGEROUS_EXTEND=1 npx webpack
414
- ```
415
-
416
- Because this uses `npm`'s resolution, you can also reference specific files
417
- in a package:
418
-
419
- ```json
420
- "browserslist": [
421
- "extends browserslist-config-mycompany/desktop",
422
- "extends browserslist-config-mycompany/mobile"
423
- ]
424
- ```
425
-
426
- When writing a shared Browserslist package, just export an array.
427
- `browserslist-config-mycompany/index.js`:
428
-
429
- ```js
430
- module.exports = [
431
- 'last 1 version',
432
- '> 1%',
433
- 'ie 10'
434
- ]
435
- ```
436
-
437
- You can also include a `browserslist-stats.json` file as part of your shareable
438
- config at the root and query it using
439
- `> 5% in browserslist-config-mycompany stats`. It uses the same format
440
- as `extends` and the `dangerousExtend` property as above.
441
-
442
- You can export configs for different environments and select environment
443
- by `BROWSERSLIST_ENV` or `env` option in your tool:
444
-
445
- ```js
446
- module.exports = {
447
- development: [
448
- 'last 1 version'
449
- ],
450
- production: [
451
- 'last 1 version',
452
- '> 1%',
453
- 'ie 10'
454
- ]
455
- }
456
- ```
457
-
458
-
459
- ## Configuring for Different Environments
460
-
461
- You can also specify different browser queries for various environments.
462
- Browserslist will choose query according to `BROWSERSLIST_ENV` or `NODE_ENV`
463
- variables. If none of them is declared, Browserslist will firstly look
464
- for `production` queries and then use defaults.
465
-
466
- In `package.json`:
467
-
468
- ```js
469
- "browserslist": {
470
- "production": [
471
- "> 1%",
472
- "ie 10"
473
- ],
474
- "modern": [
475
- "last 1 chrome version",
476
- "last 1 firefox version"
477
- ],
478
- "ssr": [
479
- "node 12"
480
- ]
481
- }
482
- ```
483
-
484
- In `.browserslistrc` config:
485
-
486
- ```ini
487
- [production]
488
- > 1%
489
- ie 10
490
-
491
- [modern]
492
- last 1 chrome version
493
- last 1 firefox version
494
-
495
- [ssr]
496
- node 12
497
- ```
498
-
499
-
500
- ## Custom Usage Data
501
-
502
- If you have a website, you can query against the usage statistics of your site.
503
- [`browserslist-ga`] will ask access to Google Analytics and then generate
504
- `browserslist-stats.json`:
505
-
506
- ```
507
- npx browserslist-ga
508
- ```
509
-
510
- Or you can use [`browserslist-ga-export`] to convert Google Analytics data without giving a password for Google account.
511
-
512
- You can generate usage statistics file by any other method. File format should
513
- be like:
514
-
515
- ```js
516
- {
517
- "ie": {
518
- "6": 0.01,
519
- "7": 0.4,
520
- "8": 1.5
521
- },
522
- "chrome": {
523
-
524
- },
525
-
526
- }
527
- ```
528
-
529
- Note that you can query against your custom usage data while also querying
530
- against global or regional data. For example, the query
531
- `> 1% in my stats, > 5% in US, 10%` is permitted.
532
-
533
- [`browserslist-ga-export`]: https://github.com/browserslist/browserslist-ga-export
534
- [`browserslist-ga`]: https://github.com/browserslist/browserslist-ga
535
- [Can I Use]: https://caniuse.com/
536
-
537
-
538
- ## JS API
539
-
540
- ```js
541
- const browserslist = require('browserslist')
542
-
543
- // Your CSS/JS build tool code
544
- function process (source, opts) {
545
- const browsers = browserslist(opts.overrideBrowserslist, {
546
- stats: opts.stats,
547
- path: opts.file,
548
- env: opts.env
549
- })
550
- // Your code to add features for selected browsers
551
- }
552
- ```
553
-
554
- Queries can be a string `"> 1%, IE 10"`
555
- or an array `['> 1%', 'IE 10']`.
556
-
557
- If a query is missing, Browserslist will look for a config file.
558
- You can provide a `path` option (that can be a file) to find the config file
559
- relatively to it.
560
-
561
- Options:
562
-
563
- * `path`: file or a directory path to look for config file. Default is `.`.
564
- * `env`: what environment section use from config. Default is `production`.
565
- * `stats`: custom usage statistics data.
566
- * `config`: path to config if you want to set it manually.
567
- * `ignoreUnknownVersions`: do not throw on direct query (like `ie 12`).
568
- Default is `false`.
569
- * `dangerousExtend`: Disable security checks for `extend` query.
570
- Default is `false`.
571
- * `mobileToDesktop`: Use desktop browsers if Can I Use doesn’t have data
572
- about this mobile version. For instance, Browserslist will return
573
- `chrome 20` on `and_chr 20` query (Can I Use has only data only about
574
- latest versions of mobile browsers). Default is `false`.
575
-
576
- For non-JS environment and debug purpose you can use CLI tool:
577
-
578
- ```sh
579
- browserslist "> 1%, IE 10"
580
- ```
581
-
582
- You can get total users coverage for selected browsers by JS API:
583
-
584
- ```js
585
- browserslist.coverage(browserslist('> 1%'))
586
- //=> 81.4
587
- ```
588
-
589
- ```js
590
- browserslist.coverage(browserslist('> 1% in US'), 'US')
591
- //=> 83.1
592
- ```
593
-
594
- ```js
595
- browserslist.coverage(browserslist('> 1% in my stats'), 'my stats')
596
- //=> 83.1
597
- ```
598
-
599
- ```js
600
- browserslist.coverage(browserslist('> 1% in my stats', { stats }), stats)
601
- //=> 82.2
602
- ```
603
-
604
- Or by CLI:
605
-
606
- ```sh
607
- $ browserslist --coverage "> 1%"
608
- These browsers account for 81.4% of all users globally
609
- ```
610
-
611
- ```sh
612
- $ browserslist --coverage=US "> 1% in US"
613
- These browsers account for 83.1% of all users in the US
614
- ```
615
-
616
- ```sh
617
- $ browserslist --coverage "> 1% in my stats"
618
- These browsers account for 83.1% of all users in custom statistics
619
- ```
620
-
621
- ```sh
622
- $ browserslist --coverage "> 1% in my stats" --stats=./stats.json
623
- These browsers account for 83.1% of all users in custom statistics
624
- ```
625
-
626
-
627
- ## Environment Variables
628
-
629
- If a tool uses Browserslist inside, you can change the Browserslist settings
630
- with [environment variables]:
631
-
632
- * `BROWSERSLIST` with browsers queries.
633
-
634
- ```sh
635
- BROWSERSLIST="> 5%" npx webpack
636
- ```
637
-
638
- * `BROWSERSLIST_CONFIG` with path to config file.
639
-
640
- ```sh
641
- BROWSERSLIST_CONFIG=./config/browserslist npx webpack
642
- ```
643
-
644
- * `BROWSERSLIST_ENV` with environments string.
645
-
646
- ```sh
647
- BROWSERSLIST_ENV="development" npx webpack
648
- ```
649
-
650
- * `BROWSERSLIST_STATS` with path to the custom usage data
651
- for `> 1% in my stats` query.
652
-
653
- ```sh
654
- BROWSERSLIST_STATS=./config/usage_data.json npx webpack
655
- ```
656
-
657
- * `BROWSERSLIST_DISABLE_CACHE` if you want to disable config reading cache.
658
-
659
- ```sh
660
- BROWSERSLIST_DISABLE_CACHE=1 npx webpack
661
- ```
662
-
663
- * `BROWSERSLIST_DANGEROUS_EXTEND` to disable security shareable config
664
- name check.
665
-
666
- ```sh
667
- BROWSERSLIST_DANGEROUS_EXTEND=1 npx webpack
668
- ```
669
-
670
- [environment variables]: https://en.wikipedia.org/wiki/Environment_variable
671
-
672
-
673
- ## Cache
674
-
675
- Browserslist caches the configuration it reads from `package.json` and
676
- `browserslist` files, as well as knowledge about the existence of files,
677
- for the duration of the hosting process.
678
-
679
- To clear these caches, use:
680
-
681
- ```js
682
- browserslist.clearCaches()
683
- ```
684
-
685
- To disable the caching altogether, set the `BROWSERSLIST_DISABLE_CACHE`
686
- environment variable.
687
-
688
-
689
- ## Security Contact
690
-
691
- To report a security vulnerability, please use the [Tidelift security contact].
692
- Tidelift will coordinate the fix and disclosure.
693
-
694
- [Tidelift security contact]: https://tidelift.com/security
695
-
696
-
697
- ## For Enterprise
698
-
699
- Available as part of the Tidelift Subscription.
700
-
701
- The maintainers of `browserslist` and thousands of other packages are working
702
- with Tidelift to deliver commercial support and maintenance for the open source
703
- dependencies you use to build your applications. Save time, reduce risk,
704
- and improve code health, while paying the maintainers of the exact dependencies
705
- you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-browserslist?utm_source=npm-browserslist&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
65
+ ## Docs
66
+ Read **[full docs](https://github.com/browserslist/browserslist#readme)** on GitHub.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserslist",
3
- "version": "4.16.8",
3
+ "version": "4.17.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,11 +15,11 @@
15
15
  "license": "MIT",
16
16
  "repository": "browserslist/browserslist",
17
17
  "dependencies": {
18
- "caniuse-lite": "^1.0.30001251",
19
- "colorette": "^1.3.0",
20
- "electron-to-chromium": "^1.3.811",
18
+ "caniuse-lite": "^1.0.30001264",
19
+ "electron-to-chromium": "^1.3.857",
21
20
  "escalade": "^3.1.1",
22
- "node-releases": "^1.1.75"
21
+ "node-releases": "^1.1.77",
22
+ "picocolors": "^0.2.1"
23
23
  },
24
24
  "engines": {
25
25
  "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
package/update-db.js CHANGED
@@ -1,16 +1,11 @@
1
1
  var childProcess = require('child_process')
2
- var colorette = require('colorette')
3
2
  var escalade = require('escalade/sync')
3
+ var pico = require('picocolors')
4
4
  var path = require('path')
5
5
  var fs = require('fs')
6
6
 
7
7
  var BrowserslistError = require('./error')
8
8
 
9
- var red = colorette.red
10
- var bold = colorette.bold
11
- var green = colorette.green
12
- var yellow = colorette.yellow
13
-
14
9
  function detectLockfile () {
15
10
  var packageDir = escalade('.', function (dir, names) {
16
11
  return names.indexOf('package.json') !== -1 ? dir : ''
@@ -33,7 +28,10 @@ function detectLockfile () {
33
28
  } else if (fs.existsSync(lockfileNpm)) {
34
29
  return { mode: 'npm', file: lockfileNpm }
35
30
  } else if (fs.existsSync(lockfileYarn)) {
36
- return { mode: 'yarn', file: lockfileYarn }
31
+ var lock = { mode: 'yarn', file: lockfileYarn }
32
+ lock.content = fs.readFileSync(lock.file).toString()
33
+ lock.version = /# yarn lockfile v1/.test(lock.content) ? 1 : 2
34
+ return lock
37
35
  } else if (fs.existsSync(lockfileShrinkwrap)) {
38
36
  return { mode: 'npm', file: lockfileShrinkwrap }
39
37
  }
@@ -44,9 +42,15 @@ function detectLockfile () {
44
42
 
45
43
  function getLatestInfo (lock) {
46
44
  if (lock.mode === 'yarn') {
47
- return JSON.parse(
48
- childProcess.execSync('yarn info caniuse-lite --json').toString()
49
- ).data
45
+ if (lock.version === 1) {
46
+ return JSON.parse(
47
+ childProcess.execSync('yarn info caniuse-lite --json').toString()
48
+ ).data
49
+ } else {
50
+ return JSON.parse(
51
+ childProcess.execSync('yarn npm info caniuse-lite --json').toString()
52
+ )
53
+ }
50
54
  }
51
55
  return JSON.parse(
52
56
  childProcess.execSync('npm show caniuse-lite --json').toString()
@@ -88,9 +92,9 @@ function diffBrowsersLists (old, current) {
88
92
  return intersection.indexOf(version) === -1
89
93
  })
90
94
  return removedVersions.map(function (version) {
91
- return red('- ' + browser + ' ' + version)
95
+ return pico.red('- ' + browser + ' ' + version)
92
96
  }).concat(addedVersions.map(function (version) {
93
- return green('+ ' + browser + ' ' + version)
97
+ return pico.green('+ ' + browser + ' ' + version)
94
98
  }))
95
99
  })
96
100
  .reduce(function (result, array) {
@@ -187,7 +191,7 @@ function updatePnpmLockfile (lock, latest) {
187
191
  }
188
192
 
189
193
  function updateLockfile (lock, latest) {
190
- lock.content = fs.readFileSync(lock.file).toString()
194
+ if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
191
195
 
192
196
  if (lock.mode === 'npm') {
193
197
  return updateNpmLockfile(lock, latest)
@@ -197,28 +201,14 @@ function updateLockfile (lock, latest) {
197
201
  return updatePnpmLockfile(lock, latest)
198
202
  }
199
203
 
200
- module.exports = function updateDB (print) {
201
- var lock = detectLockfile()
202
- var latest = getLatestInfo(lock)
203
- var browsersListRetrievalError
204
- var oldBrowsersList
205
- try {
206
- oldBrowsersList = getBrowsersList()
207
- } catch (e) {
208
- browsersListRetrievalError = e
209
- }
210
-
211
- print(
212
- 'Latest version: ' + bold(green(latest.version)) + '\n'
213
- )
214
-
204
+ function updatePackageManually (print, lock, latest) {
215
205
  var lockfileData = updateLockfile(lock, latest)
216
206
  var caniuseVersions = Object.keys(lockfileData.versions).sort()
217
207
  if (caniuseVersions.length === 1 &&
218
208
  caniuseVersions[0] === latest.version) {
219
209
  print(
220
- 'Installed version: ' + bold(green(latest.version)) + '\n' +
221
- bold(green('caniuse-lite is up to date')) + '\n'
210
+ 'Installed version: ' + pico.bold(pico.green(latest.version)) + '\n' +
211
+ pico.bold(pico.green('caniuse-lite is up to date')) + '\n'
222
212
  )
223
213
  return
224
214
  }
@@ -229,7 +219,7 @@ module.exports = function updateDB (print) {
229
219
  print(
230
220
  'Installed version' +
231
221
  (caniuseVersions.length === 1 ? ': ' : 's: ') +
232
- bold(red(caniuseVersions.join(', '))) +
222
+ pico.bold(pico.red(caniuseVersions.join(', '))) +
233
223
  '\n' +
234
224
  'Removing old caniuse-lite from lock file\n'
235
225
  )
@@ -238,13 +228,13 @@ module.exports = function updateDB (print) {
238
228
  var install = lock.mode === 'yarn' ? 'yarn add -W' : lock.mode + ' install'
239
229
  print(
240
230
  'Installing new caniuse-lite version\n' +
241
- yellow('$ ' + install + ' caniuse-lite') + '\n'
231
+ pico.yellow('$ ' + install + ' caniuse-lite') + '\n'
242
232
  )
243
233
  try {
244
234
  childProcess.execSync(install + ' caniuse-lite')
245
235
  } catch (e) /* istanbul ignore next */ {
246
236
  print(
247
- red(
237
+ pico.red(
248
238
  '\n' +
249
239
  e.stack + '\n\n' +
250
240
  'Problem with `' + install + ' caniuse-lite` call. ' +
@@ -257,9 +247,49 @@ module.exports = function updateDB (print) {
257
247
  var del = lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode + ' uninstall'
258
248
  print(
259
249
  'Cleaning package.json dependencies from caniuse-lite\n' +
260
- yellow('$ ' + del + ' caniuse-lite') + '\n'
250
+ pico.yellow('$ ' + del + ' caniuse-lite') + '\n'
261
251
  )
262
252
  childProcess.execSync(del + ' caniuse-lite')
253
+ }
254
+
255
+ module.exports = function updateDB (print) {
256
+ var lock = detectLockfile()
257
+ var latest = getLatestInfo(lock)
258
+
259
+ var browsersListRetrievalError
260
+ var oldBrowsersList
261
+ try {
262
+ oldBrowsersList = getBrowsersList()
263
+ } catch (e) {
264
+ browsersListRetrievalError = e
265
+ }
266
+
267
+ print(
268
+ 'Latest version: ' + pico.bold(pico.green(latest.version)) + '\n'
269
+ )
270
+
271
+ if (lock.mode === 'yarn' && lock.version !== 1) {
272
+ var update = 'yarn up -R'
273
+ print(
274
+ 'Updating caniuse-lite version\n' +
275
+ pico.yellow('$ ' + update + ' caniuse-lite') + '\n'
276
+ )
277
+ try {
278
+ childProcess.execSync(update + ' caniuse-lite')
279
+ } catch (e) /* istanbul ignore next */ {
280
+ print(
281
+ pico.red(
282
+ '\n' +
283
+ e.stack + '\n\n' +
284
+ 'Problem with `' + update + ' caniuse-lite` call. ' +
285
+ 'Run it manually.\n'
286
+ )
287
+ )
288
+ process.exit(1)
289
+ }
290
+ } else {
291
+ updatePackageManually(print, lock, latest)
292
+ }
263
293
 
264
294
  print('caniuse-lite has been successfully updated\n')
265
295
 
@@ -274,7 +304,7 @@ module.exports = function updateDB (print) {
274
304
 
275
305
  if (browsersListRetrievalError) {
276
306
  print(
277
- red(
307
+ pico.red(
278
308
  '\n' +
279
309
  browsersListRetrievalError.stack + '\n\n' +
280
310
  'Problem with browser list retrieval.\n' +
@@ -290,7 +320,7 @@ module.exports = function updateDB (print) {
290
320
  print('\nTarget browser changes:\n')
291
321
  print(targetBrowserChanges + '\n')
292
322
  } else {
293
- print('\n' + green('No target browser changes') + '\n')
323
+ print('\n' + pico.green('No target browser changes') + '\n')
294
324
  }
295
325
  }
296
326
  }