From e766cde3cf8979721ee6d17b3fb4e82e11265ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3n=20Molleda?= Date: Thu, 10 Oct 2019 13:21:59 -0700 Subject: [PATCH] Breaking: Extract compat information to new package Fix #3035 --- packages/utils-compat-data/.gitignore | 1 + packages/utils-compat-data/.npmrc | 1 + packages/utils-compat-data/LICENSE.txt | 201 ++++++++++++++++++ packages/utils-compat-data/README.md | 194 +++++++++++++++++ packages/utils-compat-data/package.json | 76 +++++++ .../scripts/mdn-browser-compat-data.js | 2 +- .../utils-compat-data/scripts/tsconfig.json | 15 ++ .../src}/browsers.ts | 0 .../compat => utils-compat-data/src}/cache.ts | 0 .../compat => utils-compat-data/src}/css.ts | 0 .../src}/helpers.ts | 0 .../compat => utils-compat-data/src}/html.ts | 0 .../compat => utils-compat-data/src}/index.ts | 0 .../src}/support.ts | 8 + .../tests}/browsers.ts | 2 +- .../tests}/support.ts | 2 +- packages/utils-compat-data/tsconfig.json | 15 ++ packages/utils/package.json | 2 - packages/utils/src/chromium-finder.ts | 2 + packages/utils/src/compat/.gitignore | 1 - .../config/get-hints-from-configuration.ts | 2 +- packages/utils/src/index.ts | 1 - packages/utils/tests/content-type.ts | 1 + 23 files changed, 518 insertions(+), 8 deletions(-) create mode 100644 packages/utils-compat-data/.gitignore create mode 100644 packages/utils-compat-data/.npmrc create mode 100644 packages/utils-compat-data/LICENSE.txt create mode 100644 packages/utils-compat-data/README.md create mode 100644 packages/utils-compat-data/package.json rename packages/{utils => utils-compat-data}/scripts/mdn-browser-compat-data.js (98%) create mode 100644 packages/utils-compat-data/scripts/tsconfig.json rename packages/{utils/src/compat => utils-compat-data/src}/browsers.ts (100%) rename packages/{utils/src/compat => utils-compat-data/src}/cache.ts (100%) rename packages/{utils/src/compat => utils-compat-data/src}/css.ts (100%) rename packages/{utils/src/compat => utils-compat-data/src}/helpers.ts (100%) rename packages/{utils/src/compat => utils-compat-data/src}/html.ts (100%) rename packages/{utils/src/compat => utils-compat-data/src}/index.ts (100%) rename packages/{utils/src/compat => utils-compat-data/src}/support.ts (92%) rename packages/{utils/tests/compat => utils-compat-data/tests}/browsers.ts (99%) rename packages/{utils/tests/compat => utils-compat-data/tests}/support.ts (98%) create mode 100644 packages/utils-compat-data/tsconfig.json delete mode 100644 packages/utils/src/compat/.gitignore diff --git a/packages/utils-compat-data/.gitignore b/packages/utils-compat-data/.gitignore new file mode 100644 index 00000000000..2bcedfe4a1b --- /dev/null +++ b/packages/utils-compat-data/.gitignore @@ -0,0 +1 @@ +src/browser-compat-data.ts diff --git a/packages/utils-compat-data/.npmrc b/packages/utils-compat-data/.npmrc new file mode 100644 index 00000000000..43c97e719a5 --- /dev/null +++ b/packages/utils-compat-data/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/utils-compat-data/LICENSE.txt b/packages/utils-compat-data/LICENSE.txt new file mode 100644 index 00000000000..540e41dcbd4 --- /dev/null +++ b/packages/utils-compat-data/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright JS Foundation and other contributors, https://js.foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/utils-compat-data/README.md b/packages/utils-compat-data/README.md new file mode 100644 index 00000000000..46b7ae54932 --- /dev/null +++ b/packages/utils-compat-data/README.md @@ -0,0 +1,194 @@ +# Utils compat data (`@hint/utils-compat-data`) + +This package allows you to easily query the data from [mdn-browser-compat-data][] +to learn about the support status of a feature. + +The type of information you can query is explained below: + +## API + +The supported datasets are CSS and HTML. Most of the exposed functionality +uses a `FeatureQuery` to indicate the type of information you are querying. +You can retrieve information for: + +* Attributes: + +```ts +export type AttributeQuery = { + attribute: string; + element?: string; + value?: string; +}; +``` + +* Elements: + +```ts +export type ElementQuery = { + element: string; +}; +``` + +* Declarations: + +```ts +export type DeclarationQuery = { + property: string; + value?: string; +}; +``` + +* Rules: + +```ts +export type RuleQuery = { + rule: string; +}; +``` + +* Selectors: + +```ts +export type SelectorQuery = { + selector: string; +}; +``` + +Most of the functions accept a `FeatureQuery` and a list of browser +ids to check. This package accepts two different formats of browsers +ids: browserslist or MDN. + +The friendly names and ids for each one are as follows: + +| Browser name | [Browserslist][bl browsers] | [MDN][mdn browsers] | +| ------------ | ------------ | --------- | +| Chrome | chrome | chrome | +| Chrome Android | and_chr | chrome_android | +| Edge | edge | edge | +| Firefox | ff | firefox | +| Firefox Android | and_ff | firefox_android | +| Internet Explorer | ie | ie | +| Opera | opera | opera | +| Opera Android | op_mobile | opera_android | +| QQ Android | and_qq | qq_android | +| Safari | safari | safari | +| Safari iOS | ios_saf | safari_ios | +| Samsung Internet | samsung | samgsunginternet_android | +| UC Android | and_uc | uc_android | +| Webview Android | android | webview_android | + +You can check the next sections for example on how to use `FeatureQuery`s +and list of browsers. + +### `getFriendlyName` + +Get the friendly name of a browser from an id. + +```js +import { getFriendlyName } from '@hint/utils-compat-data'; + +console.log(getFriendlyName('and_ff')); // "Firefox Android" +console.log(getFriendlyName('ie')); // "Internet Explorer" +``` + +### `getUnsupported` + +Filter the list of given `browsers` to return those that do not support the +given CSS or HTML feature. + +It accepts a `FeatureQuery` and a list of browsers. + +```js +import { getUnsupported } from '@hint/utils-compat-data'; + +console.log(getUnsupported({ element: 'details' }, ['chrome 74', 'ie 11'])); // ['ie 11'] +console.log(getUnsupported( + { + attribute: 'rel', + element: 'link', + value: 'noopener' + }, + ['edge 12', 'firefox 63'])); // ['edge 12'] +``` + +### `getUnsupportedDetails` + +Get browsers without support with details on when support was added or removed. + +Similar to `getUnsupported`, but returns an object with both a list of: + +* `browsers` which were unsupported and a map of browsers to `browserDetails` +* to get additional information (e.g. what version the feature is added in). + +It accepts a `FeatureQuery` and a list of browsers. + +```js +import { getUnsupportedDetails } from '@hint/utils-compat-data'; + +const unsupportedInfo = getUnsupportedDetails( + { property: 'appearance' }, + ['chrome 75', 'firefox 63']); +``` + +`unsupportedInfo` will look something like the following: + +```json +{ + "browsers": [ "chrome 75", "firefox 63" ], + "details": { + "chrome 75": { + "alternative": { + "name": "-webkit-appearance", + "versionAdded": 1 + } + }, + "firefox 63": { + "alternative": { + "name": "-moz-appearance", + "versionAdded": 1 + } + } + } +} +``` + +**Note**: `details` is a `Map` that uses the browser versions as keys. + +### `getSupported` + +Filters the list of `browsers` with those that support the given CSS or HTML feature. +This is the opposite of `getUnsupported`. + +It accepts a `FeatureQuery` and a list of browsers. + +```js +import { getSupported } from '@hint/utils-compat-data'; + +console.log(getSupported({ element: 'details' }, ['chrome 74', 'ie 11'])); // ['chrome 74'] +console.log(getSupported( + { + attribute: 'rel', + element: 'link', + value: 'noopener' + }, + ['edge 12', 'firefox 63'])); // ['firefox 63'] +``` + +### `isSupported` + +Query MDN for support of CSS or HTML features. It returns `true` if all +the `browsers` support it, `false` otherwise. + +It accepts a `FeatureQuery` and a list of browsers. + +```js +import { isSupported } from '@hint/utils-compat-data'; + +console.log(isSupported({ element: 'details' }, ['ie 11'])); // false +``` + + + +[bl browsers]: https://github.com/browserslist/browserslist#browsers +[mdn browsers]: https://github.com/mdn/browser-compat-data/tree/master/browsers +[mdn-browser-compat-data]: https://www.npmjs.com/package/mdn-browser-compat-data diff --git a/packages/utils-compat-data/package.json b/packages/utils-compat-data/package.json new file mode 100644 index 00000000000..9f89ecd2107 --- /dev/null +++ b/packages/utils-compat-data/package.json @@ -0,0 +1,76 @@ +{ + "ava": { + "failFast": false, + "files": [ + "dist/tests/**/*.js" + ], + "timeout": "1m" + }, + "dependencies": { + "mdn-browser-compat-data": "^0.0.96", + "postcss": "^7.0.18", + "postcss-selector-parser": "^6.0.2", + "postcss-value-parser": "^4.0.2", + "semver": "^6.3.0" + }, + "description": "hint tools", + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^1.13.0", + "@typescript-eslint/parser": "^1.12.0", + "ava": "^1.3.1", + "cpx": "^1.5.0", + "eslint": "^5.15.1", + "eslint-plugin-import": "^2.18.2", + "eslint-plugin-markdown": "^1.0.0", + "npm-run-all": "^4.1.5", + "nyc": "^14.1.0", + "rimraf": "^3.0.0", + "typescript": "^3.6.3" + }, + "engines": { + "node": ">=8.0.0" + }, + "files": [ + "dist/src" + ], + "homepage": "https://webhint.io/", + "keywords": [ + "hint", + "hint-utils", + "tools", + "utils", + "webhint" + ], + "license": "Apache-2.0", + "main": "./dist/src/index.js", + "name": "@hint/utils-compat-data", + "nyc": { + "extends": "../../.nycrc" + }, + "peerDependencies": {}, + "repository": { + "directory": "packages/utils-compat-data", + "type": "git", + "url": "https://github.com/webhintio/hint.git" + }, + "scripts": { + "ava": "ava", + "build": "npm-run-all build:*", + "build-release": "npm run clean && npm run prebuild && npm run build:assets && tsc --inlineSourceMap false --removeComments true", + "build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist", + "build:ts": "tsc -b", + "clean": "rimraf dist", + "lint": "npm-run-all lint:*", + "lint:dependencies": "node ../../scripts/lint-dependencies.js", + "lint:js": "eslint . --cache --ext js --ext md --ext ts --ignore-path ../../.eslintignore --report-unused-disable-directives", + "lint:md": "node ../../scripts/lint-markdown.js", + "prebuild": "npm-run-all prebuild:*", + "prebuild:mdn": "node ./scripts/mdn-browser-compat-data.js", + "test": "npm run lint && npm run build && npm run test-only", + "test-only": "nyc ava", + "test-release": "npm run lint && npm run build-release && ava", + "watch": "npm run build && npm-run-all --parallel -c watch:*", + "watch:ts": "npm run build:ts -- --watch" + }, + "version": "1.0.0" +} diff --git a/packages/utils/scripts/mdn-browser-compat-data.js b/packages/utils-compat-data/scripts/mdn-browser-compat-data.js similarity index 98% rename from packages/utils/scripts/mdn-browser-compat-data.js rename to packages/utils-compat-data/scripts/mdn-browser-compat-data.js index 8f365413bc4..e7953682426 100644 --- a/packages/utils/scripts/mdn-browser-compat-data.js +++ b/packages/utils-compat-data/scripts/mdn-browser-compat-data.js @@ -1,7 +1,7 @@ const fs = require('fs'); const mdn = require('mdn-browser-compat-data'); const path = require('path'); -const filename = path.resolve(`${__dirname}/../src/compat/browser-compat-data.ts`); +const filename = path.resolve(`${__dirname}/../src/browser-compat-data.ts`); /** * Determine if a given support statement qualifies as "always supported" by diff --git a/packages/utils-compat-data/scripts/tsconfig.json b/packages/utils-compat-data/scripts/tsconfig.json new file mode 100644 index 00000000000..6b4a69df74f --- /dev/null +++ b/packages/utils-compat-data/scripts/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "allowJs": true, + "alwaysStrict": true, + "checkJs": true, + "moduleResolution": "node", + "noUnusedLocals": true, + "resolveJsonModule": true, + "strict": true, + "target": "esnext" + }, + "include": [ + "**/*.js" + ] +} diff --git a/packages/utils/src/compat/browsers.ts b/packages/utils-compat-data/src/browsers.ts similarity index 100% rename from packages/utils/src/compat/browsers.ts rename to packages/utils-compat-data/src/browsers.ts diff --git a/packages/utils/src/compat/cache.ts b/packages/utils-compat-data/src/cache.ts similarity index 100% rename from packages/utils/src/compat/cache.ts rename to packages/utils-compat-data/src/cache.ts diff --git a/packages/utils/src/compat/css.ts b/packages/utils-compat-data/src/css.ts similarity index 100% rename from packages/utils/src/compat/css.ts rename to packages/utils-compat-data/src/css.ts diff --git a/packages/utils/src/compat/helpers.ts b/packages/utils-compat-data/src/helpers.ts similarity index 100% rename from packages/utils/src/compat/helpers.ts rename to packages/utils-compat-data/src/helpers.ts diff --git a/packages/utils/src/compat/html.ts b/packages/utils-compat-data/src/html.ts similarity index 100% rename from packages/utils/src/compat/html.ts rename to packages/utils-compat-data/src/html.ts diff --git a/packages/utils/src/compat/index.ts b/packages/utils-compat-data/src/index.ts similarity index 100% rename from packages/utils/src/compat/index.ts rename to packages/utils-compat-data/src/index.ts diff --git a/packages/utils/src/compat/support.ts b/packages/utils-compat-data/src/support.ts similarity index 92% rename from packages/utils/src/compat/support.ts rename to packages/utils-compat-data/src/support.ts index 022d003990d..66824cdc03c 100644 --- a/packages/utils/src/compat/support.ts +++ b/packages/utils-compat-data/src/support.ts @@ -17,6 +17,7 @@ import { } from './html'; export { + AlternativeDetails, getFriendlyName, UnsupportedBrowsers } from './browsers'; @@ -60,6 +61,9 @@ export const getUnsupported = (feature: FeatureQuery, browsers: string[]): strin return data && data.browsers; }; +/** + * Using the given `browsers` list, returns those that support the given `feature`. + */ export const getSupported = (feature: FeatureQuery, browsers: string[]): string[] | null => { const unsupported = getUnsupported(feature, browsers); @@ -74,6 +78,10 @@ export const getSupported = (feature: FeatureQuery, browsers: string[]): string[ return supported.length ? supported : null; }; + +/** + * Returns `true` if all the `browsers` support the given `feature`, `false` otherwise. + */ export const isSupported = (feature: FeatureQuery, browsers: string[]): boolean => { return !getUnsupported(feature, browsers); }; diff --git a/packages/utils/tests/compat/browsers.ts b/packages/utils-compat-data/tests/browsers.ts similarity index 99% rename from packages/utils/tests/compat/browsers.ts rename to packages/utils-compat-data/tests/browsers.ts index 3adf2c86f5c..a2553490e00 100644 --- a/packages/utils/tests/compat/browsers.ts +++ b/packages/utils-compat-data/tests/browsers.ts @@ -1,7 +1,7 @@ import test from 'ava'; import { Identifier } from 'mdn-browser-compat-data/types'; -import { getUnsupportedBrowsers } from '../../src/compat/browsers'; +import { getUnsupportedBrowsers } from '../src/browsers'; test('Handles complex support', (t) => { /* eslint-disable */ diff --git a/packages/utils/tests/compat/support.ts b/packages/utils-compat-data/tests/support.ts similarity index 98% rename from packages/utils/tests/compat/support.ts rename to packages/utils-compat-data/tests/support.ts index f960f46c1ca..cd0b46d1123 100644 --- a/packages/utils/tests/compat/support.ts +++ b/packages/utils-compat-data/tests/support.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import { getSupported, getUnsupported, isSupported } from '../../src/compat'; +import { getSupported, getUnsupported, isSupported } from '../src/'; test('isSupported works', (t) => { t.true(isSupported({ element: 'details' }, ['chrome 74'])); diff --git a/packages/utils-compat-data/tsconfig.json b/packages/utils-compat-data/tsconfig.json new file mode 100644 index 00000000000..ecc8bfb8543 --- /dev/null +++ b/packages/utils-compat-data/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "outDir": "dist", + "strict": true + }, + "exclude": [ + "dist", + "node_modules" + ], + "extends": "../../tsconfig.json", + "include": [ + "src/**/*.ts", + "tests/**/*.ts" + ] +} diff --git a/packages/utils/package.json b/packages/utils/package.json index 4c8beebd82a..ed4cb0cd8e7 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -22,7 +22,6 @@ "is-wsl": "^2.1.1", "jsonc-parser": "^2.1.1", "lodash": "^4.17.15", - "mdn-browser-compat-data": "^0.0.96", "npm-registry-fetch": "^5.0.0", "parse5": "^5.1.0", "parse5-htmlparser2-tree-adapter": "^5.1.0", @@ -99,7 +98,6 @@ "lint:js": "eslint . --cache --ext js --ext md --ext ts --ignore-path ../../.eslintignore --report-unused-disable-directives", "lint:md": "node ../../scripts/lint-markdown.js", "prebuild": "npm-run-all prebuild:*", - "prebuild:mdn": "node ./scripts/mdn-browser-compat-data.js", "prebuild:mime-db": "node ./scripts/mime-db.js", "test": "npm run lint && npm run build && npm run test-only", "test-only": "nyc ava", diff --git a/packages/utils/src/chromium-finder.ts b/packages/utils/src/chromium-finder.ts index 0553cc8c9d5..4edb4501de9 100644 --- a/packages/utils/src/chromium-finder.ts +++ b/packages/utils/src/chromium-finder.ts @@ -102,6 +102,7 @@ const darwin = (browser: Browser) => { const platformBrowserInfo = browserVariables.get('darwin')!; const suffixes = platformBrowserInfo.get(browser); + /* istanbul ignore if */ if (!suffixes) { throw new Error(ERRORS.NotSupportedBrowser); } @@ -247,6 +248,7 @@ const win32 = (browser: Browser) => { const suffixes = info.get(browser); + /* istanbul ignore if */ if (!suffixes) { throw new Error(ERRORS.NotSupportedBrowser); } diff --git a/packages/utils/src/compat/.gitignore b/packages/utils/src/compat/.gitignore deleted file mode 100644 index ad51bcbe0e1..00000000000 --- a/packages/utils/src/compat/.gitignore +++ /dev/null @@ -1 +0,0 @@ -browser-compat-data.ts diff --git a/packages/utils/src/config/get-hints-from-configuration.ts b/packages/utils/src/config/get-hints-from-configuration.ts index a752b7a8a23..4e37a44b695 100644 --- a/packages/utils/src/config/get-hints-from-configuration.ts +++ b/packages/utils/src/config/get-hints-from-configuration.ts @@ -15,7 +15,7 @@ const getHintsFromExtend = (extendName: string, parentConfigs: string[] = []) => ...getHintsFromExtends(configuration.extends, [extendName, ...parentConfigs]), // eslint-disable-line no-use-before-define,@typescript-eslint/no-use-before-define ...normalizeHints(configuration.hints || {}) }; - } catch (e) { // If the configuration doesn't exists, ignore it and returns an empty object. + } catch (e) /* istanbul ignore next */ { // If the configuration doesn't exists, ignore it and returns an empty object. return {}; } }; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 1375ef16a6a..bc9e6b82b47 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -21,7 +21,6 @@ export * from './types/npm'; export * from './types/html'; export * from './types/problem-location'; export * from './types/category'; -export * from './compat'; export * from './config'; export * from './dom/html'; export * from './has-yarnlock'; diff --git a/packages/utils/tests/content-type.ts b/packages/utils/tests/content-type.ts index 8959921d41a..981373d39cb 100644 --- a/packages/utils/tests/content-type.ts +++ b/packages/utils/tests/content-type.ts @@ -78,6 +78,7 @@ test('determineMediaTypeBasedOnFileExtension returns null if not recognized exte test('getType returns the right group for a variety of mediaTypes', (t) => { const mediaTypes = { '': 'unknown', + 'application/javascript': 'script', 'application/json': 'json', 'application/manifest+json': 'manifest', 'application/vnd.ms-fontobject': 'font',