From 386dae1f8b4d9431bbe7622cd418c9139dd0631f Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 9 Jul 2021 16:45:08 +0200 Subject: [PATCH 1/5] Update README to match the new code This should match better with the code after #1034. --- README.md | 65 +++++++++---------------------------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 95d2d78f4..aff8706b3 100644 --- a/README.md +++ b/README.md @@ -34,82 +34,37 @@ To deploy: npm run migrate ``` -The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in. +The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in. ## Contribution Guidelines -The `dom.generated.d.ts`, `webworker.generated.d.ts` and `dom.iterable.generated.d.ts` files from the TypeScript repo are used as baselines. +The files in the `baselines/` directory from the TypeScript repo are used as baselines. For each pull request, we will run the script and compare the generated files with the baseline files. In order to make the tests pass, please update the baseline as well in any pull requests. -It's recommended to first check which spec the wrong type belongs to. Say we are to update `IntersectionObserver` which belongs to [`Intersection Observer`](https://www.w3.org/TR/intersection-observer/) spec, and then we can do: +### When the type is missing -1. First check we have the spec name `Intersection Observer` in `inputfiles/idlSources.json`. If not, add it. -2. Run `npm run fetch-idl "Intersection Observer" && npm run build && npm run baseline-accept`. +It's possible that the automated algorithm decided that it's not well supported by browsers and thus removed it. Say we we want to add a new interface named `Foo`. Check if there is a document about that interface in [MDN](https://developer.mozilla.org/). If there is, see the browser compatibility section and check whether it's supported by two or more browsers. (Chrome, Firefox, and Safari are the relevant browsers. Supports from multiple Chromium-based browsers are counted as one support.) -If the above didn't fix the type issues, we can fix them via json files as a last resort. -There are three json files that are typically used to alter the type generation: `addedTypes.json`, `overridingTypes.json`, and `removedTypes.json`. -`comments.json` can used to add comments to the types. -Finally, `knownTypes.json` determine which types are available in a certain environment in case it couldn't be automatically determined. +If all the conditions are fulfilled, it could be that the type is incorrectly removed by `inputfiles/removedTypes.jsonc`. Try finding the relevant item there and run `npm run build && npm run baseline-accept`. -The format of each file can be inferred from their existing content. +If conditions are not fulfilled but you think MDN is wrong, please file an issue at https://github.com/mdn/browser-compat-data/issues/. The type will be automatically added in a few weeks when MDN fixes their data. -The common steps to send a pull request are: +### When the type exists but is wrong -0. Open or refer to an issue in the [TypeScript repo](https://github.com/Microsoft/TypeScript) which might get moved back to this repo. -1. Update an IDL or add missing elements to `inputfiles/addedTypes.json`, overriding elements to `inputfiles/overridingTypes.json`, or elements to remove to `inputfiles/removedTypes.json`. -2. Run the build script locally to obtain new `dom.generated.d.ts` and `webworker.generated.d.ts`. -3. Update the files in the `baselines` folder using the newly generated files under `generated` folder (`npm run baseline-accept`). +It's possible that the type is too specific or too general. First you need to check whether `inputfiles/overridingTypes.jsonc` or `inputfiles/addedTypes.jsonc` have a relevant item, which can be fixed if exists. If they don't, add one in `overridingTypes.jsonc`. Run `npm run build && npm run baseline-accept` to make sure the resulting changes are what you want. -### What are the TypeScript team's heuristics for PRs to the DOM APIs - -Changes to this repo can have pretty drastic ecosystem effects, because these types are included by default in TypeScript. -Due to this, we tend to be quite conservative with our approach to introducing changes. -To give you a sense of whether we will accept changes, you can use these heuristics to know up-front if we'll be open to merging. - -#### Fixes - -> For example, changing a type on a field, or nullability references - -- Does the PR show examples of the changes being used in spec examples or reputable websites like MDN? -- Did this change come from an IDL update? -- Does the change appear to be high-impact on a well-used API? -- Would the changes introduce a lot of breaking changes to existing code? For example the large corpus of typed code in DefinitelyTyped. - -#### Additions - -> For example, adding a new spec or subsection via a new or updated IDL file - -- Does the new objects or fields show up in [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data)? If not, it's likely too soon. -- Is the IDL source from WHATWG? - - Are the additions available in at least two of [Firefox](https://searchfox.org/mozilla-central/search?q=&path=), [Safari](https://webkit-search.igalia.com/webkit/search?q=&path=) and Chromium? -- Is the IDL source from W3C? - - What stage of the [W3C process](https://en.wikipedia.org/wiki/World_Wide_Web_Consortium#Specification_maturation) is the proposal for these changes: We aim for Proposed recommendation, but can accept Candidate recommendation for stable looking proposals. - - If it's at Working draft the additions available in all three of Firefox, Safari and Chromium -- Could any types added at the global scope have naming conflicts? -- Are the new features going to be used by a lot of people? - -#### Removals - -> For example, removing a browser-specific section of code - -- Do the removed objects or fields show up in [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data)? If so, are they marked as deprecated? -- Does an internet search for the fields show results in blogs/recommendations? -- When was the deprecation (this can be hard to find) but was it at least 2 years ago if so? - -## Build Instructions +If you are familiar with Web IDL, you may also want to check whether the upstream IDL itself can be made more specific. Doing so will reduce the need for manual overridings in this repository and thus can be more helpful. # This repo ## Code Structure -- `src/index.ts`: handles the emitting of the `.d.ts` files. +- `src/build.ts`: handles the emitting of the `.d.ts` files. - `src/test.ts`: verifies the output by comparing the `generated/` and `baseline/` contents. ## Input Files -- `browser.webidl.preprocessed.json`: a JSON file generated by Microsoft Edge. **Do not edit this file**. - - Due to the different update schedules between Edge and TypeScript, this may not be the most up-to-date version of the spec. - `mdn/apiDescriptions.json`: a JSON file generated by fetching API descriptions from [MDN](https://developer.mozilla.org/en-US/docs/Web/API). **Do not edit this file**. - `addedTypes.json`: types that should exist in either browser or webworker but are missing from the Edge spec. The format of the file mimics that of `browser.webidl.preprocessed.json`. - `overridingTypes.json`: types that are defined in the spec file but has a better or more up-to-date definitions in the json files. From 7eba60f2b9621a3c7f1dcb7e32462f66cf224fc3 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 9 Jul 2021 18:38:16 +0200 Subject: [PATCH 2/5] feedback --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c59a5cabc..995e28f8c 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ In order to make the tests pass, please update the baseline as well in any pull ### When the type is missing -It's possible that the automated algorithm decided that it's not well supported by browsers and thus removed it. Say we we want to add a new interface named `Foo`. Check if there is a document about that interface in [MDN](https://developer.mozilla.org/). If there is, see the browser compatibility section and check whether it's supported by two or more browsers. (Chrome, Firefox, and Safari are the relevant browsers. Supports from multiple Chromium-based browsers are counted as one support.) +It's possible that the automated algorithm decided that it's not well supported by browsers and thus removed it. Say we we want to add a new interface named `Foo`. Check if there is a document about that interface in [MDN](https://developer.mozilla.org/). If there is, see the browser compatibility section and check whether it's supported by two or more browser engines. (Note that Chromium-based browsers use the same browser engine and thus support from them counts as a single support.) If all the conditions are fulfilled, it could be that the type is incorrectly removed by `inputfiles/removedTypes.jsonc`. Try finding the relevant item there and run `npm run build && npm run baseline-accept`. @@ -66,9 +66,9 @@ If you are familiar with Web IDL, you may also want to check whether the upstrea ## Input Files - `mdn/apiDescriptions.json`: a JSON file generated by fetching API descriptions from [MDN](https://developer.mozilla.org/en-US/docs/Web/API). **Do not edit this file**. -- `addedTypes.json`: types that should exist in either browser or webworker but are missing from the Edge spec. The format of the file mimics that of `browser.webidl.preprocessed.json`. -- `overridingTypes.json`: types that are defined in the spec file but has a better or more up-to-date definitions in the json files. -- `removedTypes.json`: types that are defined in the spec file but should be removed. +- `addedTypes.jsonc`: types that should exist but are missing from the spec data. +- `overridingTypes.jsonc`: types that are defined in the spec but has TypeScript-friendly modifications in the json files. +- `removedTypes.jsonc`: types that are defined in the spec but should be removed. - `comments.json`: comment strings to be embedded in the generated .js files. - `deprecatedMessage.json`: the reason why one type is deprecated. The reason why it is a separate file rather than merge in comment.json is mdn/apiDescriptions.json would also possibly be deprecated. From 2ce5f038d2cb8e67829150df7b29bf17b28fbafd Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 9 Jul 2021 23:40:42 +0200 Subject: [PATCH 3/5] link to contribution guidelines --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 995e28f8c..48f898c33 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This tool is used to generate the web-based `lib.dom.d.ts` file which is include A feature needs to be supported by two or more major browser engines to be included here, to make sure there is a good consensus among vendors: __Gecko__ (Firefox), __Blink__ (Chrome/Edge), and __WebKit__ (Safari). -If the condition is met but still is not available here, first check the heuristics below and then please [file an issue](hthttps://github.com/microsoft/TypeScript-DOM-lib-generator/issues/new). +If the condition is met but still is not available here, first check the [contribution guidelines](#contribution-guidelines) below and then please [file an issue](hthttps://github.com/microsoft/TypeScript-DOM-lib-generator/issues/new). ## Build Instructions @@ -46,7 +46,7 @@ In order to make the tests pass, please update the baseline as well in any pull It's possible that the automated algorithm decided that it's not well supported by browsers and thus removed it. Say we we want to add a new interface named `Foo`. Check if there is a document about that interface in [MDN](https://developer.mozilla.org/). If there is, see the browser compatibility section and check whether it's supported by two or more browser engines. (Note that Chromium-based browsers use the same browser engine and thus support from them counts as a single support.) -If all the conditions are fulfilled, it could be that the type is incorrectly removed by `inputfiles/removedTypes.jsonc`. Try finding the relevant item there and run `npm run build && npm run baseline-accept`. +If all the conditions are fulfilled, it could be that the type is incorrectly removed by `inputfiles/removedTypes.jsonc`. Try finding and removing the relevant item there and run `npm run build && npm run baseline-accept`. If conditions are not fulfilled but you think MDN is wrong, please file an issue at https://github.com/mdn/browser-compat-data/issues/. The type will be automatically added in a few weeks when MDN fixes their data. @@ -54,7 +54,7 @@ If conditions are not fulfilled but you think MDN is wrong, please file an issue It's possible that the type is too specific or too general. First you need to check whether `inputfiles/overridingTypes.jsonc` or `inputfiles/addedTypes.jsonc` have a relevant item, which can be fixed if exists. If they don't, add one in `overridingTypes.jsonc`. Run `npm run build && npm run baseline-accept` to make sure the resulting changes are what you want. -If you are familiar with Web IDL, you may also want to check whether the upstream IDL itself can be made more specific. Doing so will reduce the need for manual overridings in this repository and thus can be more helpful. +If you are familiar with Web IDL, you may also want to check whether the upstream IDL itself can be made more specific. Doing so will reduce the need for manual overrides in this repository and thus can be more helpful. # This repo From 4aabbfa9e4daf294f3997cc8adde95ed40f9373a Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 16 Jul 2021 17:42:52 +0200 Subject: [PATCH 4/5] Update README.md Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48f898c33..59e9d572d 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ In order to make the tests pass, please update the baseline as well in any pull ### When the type is missing -It's possible that the automated algorithm decided that it's not well supported by browsers and thus removed it. Say we we want to add a new interface named `Foo`. Check if there is a document about that interface in [MDN](https://developer.mozilla.org/). If there is, see the browser compatibility section and check whether it's supported by two or more browser engines. (Note that Chromium-based browsers use the same browser engine and thus support from them counts as a single support.) +It's possible that the automated algorithm decided that it's not well supported by browsers and thus removed it. Say we want to add a new interface named `Foo`. Check if there is a document about that interface in [MDN](https://developer.mozilla.org/). If there is, see the browser compatibility section and check whether it's supported by two or more browser engines. (Note that Chromium-based browsers use the same browser engine and thus support from them counts as a single support.) If all the conditions are fulfilled, it could be that the type is incorrectly removed by `inputfiles/removedTypes.jsonc`. Try finding and removing the relevant item there and run `npm run build && npm run baseline-accept`. From d47bac7e0cb465d6dc1a6d0f0a5386cd0da437e1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 27 Jul 2021 17:54:55 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59e9d572d..618121b5e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ If you are familiar with Web IDL, you may also want to check whether the upstrea - `mdn/apiDescriptions.json`: a JSON file generated by fetching API descriptions from [MDN](https://developer.mozilla.org/en-US/docs/Web/API). **Do not edit this file**. - `addedTypes.jsonc`: types that should exist but are missing from the spec data. -- `overridingTypes.jsonc`: types that are defined in the spec but has TypeScript-friendly modifications in the json files. +- `overridingTypes.jsonc`: types that are defined in the spec but have TypeScript-friendly modifications in the json files. - `removedTypes.jsonc`: types that are defined in the spec but should be removed. - `comments.json`: comment strings to be embedded in the generated .js files. - `deprecatedMessage.json`: the reason why one type is deprecated. The reason why it is a separate file rather than merge in comment.json is mdn/apiDescriptions.json would also possibly be deprecated.