Skip to content

Commit

Permalink
Add ignoreUnknownVersions option
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 14, 2018
1 parent 9902a9f commit 74b1ace
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -406,6 +406,17 @@ If a query is missing, Browserslist will look for a config file.
You can provide a `path` option (that聽can聽be聽a聽file) to聽find聽the聽config聽file
relatively to it.

Options:

* `path`: file or a directory path to look for config file. Default is `.`.
* `env`: what environment section use from config. Default is `production`.
* `stats`: custom usage statistics data.
* `config`: path to config if you want to set it manually.
* `ignoreUnknownVersions`: do not throw on direct query (like `ie 12`).
Default is `false.`
* `dangerousExtend`: Disable security checks for `extend` query.
Default is `false.`

For non-JS environment and debug purpose you can use CLI tool:

```sh
Expand Down
17 changes: 13 additions & 4 deletions index.js
Expand Up @@ -157,12 +157,16 @@ function resolve (queries, context) {
* @param {object} opts Options.
* @param {string} [opts.path="."] Path to processed file.
* It will be used to find config files.
* @param {string} [opts.env="development"] Processing environment.
* It will be used to take right
* queries from config file.
* @param {string} [opts.env="production"] Processing environment.
* It will be used to take right
* queries from config file.
* @param {string} [opts.config] Path to config file with queries.
* @param {object} [opts.stats] Custom browser usage statistics
* for "> 1% in my stats" query.
* @param {boolean} [opts.ignoreUnknownVersions=false] Do not throw on unknown
* version in direct query.
* @param {boolean} [opts.dangerousExtend] Disable security checks
* for extend query.
* @return {string[]} Array with browser names in Can I Use.
*
* @example
Expand Down Expand Up @@ -193,7 +197,10 @@ function browserslist (queries, opts) {
'Browser queries must be an array. Got ' + typeof queries + '.')
}

var context = { dangerousExtend: opts.dangerousExtend }
var context = {
ignoreUnknownVersions: opts.ignoreUnknownVersions,
dangerousExtend: opts.dangerousExtend
}

var stats = env.getStat(opts)
if (stats) {
Expand Down Expand Up @@ -618,6 +625,8 @@ var QUERIES = [
alias = normalizeVersion(data, alias)
if (alias) {
version = alias
} else if (context.ignoreUnknownVersions) {
return []
} else {
throw new BrowserslistError(
'Unknown version ' + version + ' of ' + name)
Expand Down
5 changes: 5 additions & 0 deletions test/direct.test.js
Expand Up @@ -22,6 +22,11 @@ it('raises on unknown version', () => {
}).toThrowError('Unknown version 1 of IE')
})

it('ignores unknown versions on request', () => {
expect(browserslist('IE 1, IE 9', { ignoreUnknownVersions: true }))
.toEqual(['ie 9'])
})

it('works with joined versions from Can I Use', () => {
expect(browserslist('ios 7.0')).toEqual(['ios_saf 7.0-7.1'])
expect(browserslist('ios 7.1')).toEqual(['ios_saf 7.0-7.1'])
Expand Down

0 comments on commit 74b1ace

Please sign in to comment.