Skip to content

Commit

Permalink
Convert BCD to TypeScript (#16593)
Browse files Browse the repository at this point in the history
* Fold external.d.ts into dev.d.ts

* Load dev.d.ts and types.d.ts in all ts-node calls

* Install @types/yargs

* Further declare es-main module

* Remove include and add exclude

* Rename all files from .js to .ts

* Make index loading asynchronous

* Convert index to TypeScript

* TS compiler: ignore .test.ts

* Fix script run

* Update Mocha to use TypeScript compiler

* Install @types/mocha

* Revert removal of ".js" in imports

This partially reverts commit 5bdc6a2.

* Update internal TypeScript definitons

* Move auto-generated typedef to types/ folder

* Convert scripts/fix/ to TypeScript

* Update package.json

* Install TypeScript ESLint parser

* Fix ESLint issues

* Convert scripts/fix/property-order

* Extend ESLint configuration

* Convert scripts/lib/

* Turn off "no-explicit-any"

* Remove unused script

* let -> const

* Make CompatData type's properties all optional for internal testing

* Ensure index.ts outputs a type

* Fix index import

* Convert scripts/migrations/

* Revert "Make CompatData type's properties all optional for internal testing"

* Update type checks

* Convert type generator to TypeScript

* Fix TypeScript issues with migration script

* Mark browser.upstream as BrowserName

* Improve typedefs for scripts/fix/

* Install @types/deep-diff

* Convert remaining scripts

* Convert linters

* Fix ESLint issues

* Update types and JSDoc definitions

* Ensure generate-types doesn't depend on its own output

* Fix traverse script

* Fix key types

* Partially fix test-consistency

* Fix test-consistency

* Define module @desertnet/html-parser

* Fix up the linters

* Allow importing JSON

* Explicitly declare any

* Declare better-ajv-errors module

* Fix test-versions

* Remove unused imports

* Fix config

* Fix remaining issue

* Tweak type generation

* Apply suggested changes

Co-Authored-By: Anton Bershanskiy <45960703+bershanskiy@users.noreply.github.com>

* Apply suggested changes

Co-Authored-By: Anton Bershanskiy <45960703+bershanskiy@users.noreply.github.com>

* Apply suggested changes

* Fix linting issues

* Fix typescript issues

* Update unittest

* Remove unused imports

* Fix TypeScript issues

* Fix formatting

Co-authored-by: Anton Bershanskiy <45960703+bershanskiy@users.noreply.github.com>
  • Loading branch information
queengooborg and bershanskiy committed Jun 14, 2022
1 parent 727a55c commit cfcfc3d
Show file tree
Hide file tree
Showing 75 changed files with 1,813 additions and 914 deletions.
2 changes: 1 addition & 1 deletion .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"**/.nyc_output/**",
"**/coverage/**",
"**/node_modules/**",
"**/**.test.js"
"**/**.test.ts"
]
}
13 changes: 9 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
"jest": true,
"node": true
},
"plugins": ["prettier"],
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@babel/eslint-parser",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error"
"prettier/prettier": "error",
"@typescript-eslint/no-explicit-any": "off"
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ yarn.lock
.nyc_output/
coverage.lcov
coverage/
types.d.ts
types/types.d.ts
4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"loader": "ts-node/esm",
"extensions": ["ts", "tsx"]
}
10 changes: 0 additions & 10 deletions dev.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions external.d.ts

This file was deleted.

17 changes: 10 additions & 7 deletions index.js → index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */

import fs from 'node:fs';
import { CompatData } from './types/types.js';

import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

Expand All @@ -17,19 +19,20 @@ const dirname = fileURLToPath(new URL('.', import.meta.url));
* @param {string[]} dirs The directories to load
* @returns {object} All of the browser compatibility data
*/
function load(...dirs) {
let result = {};
async function load(...dirs: string[]) {
const result = {};

for (const dir of dirs) {
const paths = new fdir()
.withBasePath()
.filter((fp) => fp.endsWith('.json'))
.crawl(path.join(dirname, dir))
.sync();
.sync() as string[];

for (const fp of paths) {
try {
extend(result, JSON.parse(fs.readFileSync(fp)));
const contents = await fs.readFile(fp);
extend(result, JSON.parse(contents.toString('utf8')));
} catch (e) {
// Skip invalid JSON. Tests will flag the problem separately.
continue;
Expand All @@ -40,7 +43,7 @@ function load(...dirs) {
return result;
}

export default load(
export default (await load(
'api',
'browsers',
'css',
Expand All @@ -51,4 +54,4 @@ export default load(
'svg',
'webdriver',
'webextensions',
);
)) as CompatData;

0 comments on commit cfcfc3d

Please sign in to comment.