Skip to content

Commit abb8617

Browse files
caugnerddbeckElchi3
authored
feat(schemas)!: separate public from internal schema (#29041)
Add a public schema for `data.json`, separate from the internal browser/compat file schemas, and refine schema descriptions. BREAKING CHANGES: - `CompatStatement.source_file` is now required. - `BrowserStatement.upstream` is narrowed to `UpstreamBrowserName`, a subset of `BrowserName`. Co-authored-by: Daniel D. Beck <daniel@ddbeck.com> Co-authored-by: Florian Scholz <fs@florianscholz.com>
1 parent c3e4c25 commit abb8617

91 files changed

Lines changed: 1681 additions & 784 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ jobs:
133133
- name: Format
134134
run: |
135135
# sed command prefixes each line of output with [base] or [pr]
136-
cd base/build && npx prettier --write . | sed "s/^/[base] /" &
137-
cd pr/build && npx prettier --write . | sed "s/^/[pr] /" &
136+
cd base/build && npx prettier --ignore-path /dev/null --write . | sed "s/^/[base] /" &
137+
cd pr/build && npx prettier --ignore-path /dev/null --write . | sed "s/^/[pr] /" &
138138
wait
139139
140140
- name: Diff

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ __enumerating__*/
33
.idea
44
*.log
55
/node_modules/
6-
/build/
7-
!/scripts/build/
86
yarn.lock
97
.eslintcache
108
.nyc_output/
119
coverage.lcov
1210
coverage/
13-
types/types.d.ts
11+
/types/internal.d.ts
12+
/types/public.d.ts
1413
.DS_Store

.lefthook.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ pre-commit:
1616
glob: "**/*.json"
1717
exclude:
1818
- .vscode/*.json
19+
- build/*.json
1920
- browsers/*.json
2021
- schemas/*.json
22+
- types/*.json
2123
run: npm run lint:fix {staged_files} && git add lint/common/standard-track-exceptions.txt
2224
stage_fixed: true
2325

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ LICENSE
1111
/build/
1212
coverage/
1313
.features.json
14-
types.d.ts
14+
/types/internal.d.ts
15+
/types/public.d.ts

build/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!.gitignore
3+
!.npmignore
4+
!tsconfig.json

build/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.gitignore
2+
.npmignore
3+
tsconfig.json

build/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"skipLibCheck": false
5+
},
6+
"include": ["*.d.ts", "*.d.mts"],
7+
"exclude": []
8+
}

eslint.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export default [
3434
'CODE_OF_CONDUCT.md',
3535
'build/',
3636
'**/coverage/',
37-
'**/types.d.ts',
37+
'types/internal.d.ts',
38+
'types/public.d.ts',
3839
],
3940
},
4041
...fixupConfigRules(
@@ -83,9 +84,7 @@ export default [
8384
'@typescript-eslint/no-explicit-any': 'off',
8485
'@typescript-eslint/no-floating-promises': 'error',
8586
'@typescript-eslint/no-unused-expressions': 'error',
86-
'@typescript-eslint/no-unused-vars': 'off',
87-
88-
'no-unused-vars': [
87+
'@typescript-eslint/no-unused-vars': [
8988
'error',
9089
{
9190
argsIgnorePattern: '^_',
@@ -172,6 +171,7 @@ export default [
172171
'no-return-assign': 'error',
173172
'no-self-compare': 'error',
174173
'no-unused-expressions': 'error',
174+
'no-unused-vars': 'off', // Using @typescript-eslint/no-unused-vars instead.
175175
'no-useless-call': 'error',
176176

177177
'prefer-arrow-functions/prefer-arrow-functions': [

index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This file is a part of @mdn/browser-compat-data
22
* See LICENSE file for more information. */
33

4-
/** @import {CompatData} from './types/types.js' */
4+
/** @import {InternalCompatData, InternalCompatStatement} from './types/index.js' */
55

66
import fs from 'node:fs/promises';
77
import path from 'node:path';
@@ -17,10 +17,12 @@ const dirname = fileURLToPath(new URL('.', import.meta.url));
1717

1818
/**
1919
* Recursively load one or more directories passed as arguments.
20-
* @param {...string} dirs The directories to load
21-
* @returns {Promise<CompatData>} All of the browser compatibility data
20+
* @template {keyof InternalCompatData} Dir
21+
* @param {...Dir} dirs The directories to load
22+
* @returns {Promise<Pick<InternalCompatData, Dir>>} All of the browser compatibility data
2223
*/
2324
const load = async (...dirs) => {
25+
/** @type {Partial<Pick<InternalCompatData, Dir>>} */
2426
const result = {};
2527

2628
for (const dir of dirs) {
@@ -35,13 +37,16 @@ const load = async (...dirs) => {
3537
for (const fp of paths) {
3638
try {
3739
const rawcontents = await fs.readFile(fp);
38-
/** @type {CompatData} */
40+
/** @type {InternalCompatData} */
3941
const contents = JSON.parse(rawcontents.toString('utf8'));
4042

41-
// Add source_file props
43+
// Add source_file props. The `source_file` field is part of the public
44+
// `CompatStatement` shape, not the internal one, so cast at the assignment.
4245
const walker = walk(undefined, contents);
4346
for (const { compat } of walker) {
44-
compat.source_file = normalizePath(path.relative(dirname, fp));
47+
/** @type {InternalCompatStatement & { source_file: string }} */ (
48+
compat
49+
).source_file = normalizePath(path.relative(dirname, fp));
4550
}
4651

4752
extend(result, contents);
@@ -54,7 +59,10 @@ const load = async (...dirs) => {
5459
}
5560
}
5661

57-
return /** @type {CompatData} */ (result);
62+
return /** @type {Pick<InternalCompatData, Dir>} */ (result);
5863
};
5964

60-
export default await load(...dataFolders);
65+
/** @type {InternalCompatData} */
66+
const bcd = await load(...dataFolders);
67+
68+
export default bcd;

index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/* This file is a part of @mdn/browser-compat-data
22
* See LICENSE file for more information. */
33

4-
/** @import {CompatStatement} from './types/types.js' */
4+
/** @import {InternalCompatStatement} from './types/index.js' */
55

66
import assert from 'node:assert/strict';
77

88
import bcd from './index.js';
99

1010
describe('Using BCD', () => {
1111
it('subscript notation', () => {
12-
/** @type {CompatStatement | undefined} */
12+
/** @type {InternalCompatStatement | undefined} */
1313
const data = bcd['api']['AbortController']['__compat'];
1414
assert.ok(data);
1515
});
1616

1717
it('dot notation', () => {
18-
/** @type {CompatStatement | undefined} */
18+
/** @type {InternalCompatStatement | undefined} */
1919
const data = bcd.api.AbortController.__compat;
2020
assert.ok(data);
2121
});

0 commit comments

Comments
 (0)