-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate and publish TypeScript type definitions #57
Comments
See also jsmnbom/definitelytyped-firefox-webext-browser#39 There also exist an attempt to manually create and maintain the definitions: https://github.com/ctrlxc/thunderbird-web-ext-types (more recent fork of https://github.com/kelseasy/web-ext-types). |
I have never worked with TypeScript. Our schema files are located at : Could you give it a try and run them through the linked generator? |
Can try to take a closer look in the next weeks, but no promises. I consider this more a nice to have (as I already created the definitions I currently need manually), and nothing urgent. |
I tried, but it doesn't work out of the box. We'd have to understand the inner workings of the generator to adapt it to thunderbird. It seems not to be a problem with the schema format but with parts of the content; some types seem to be too complex for the generator. |
I forked that project for the Firefox declarations, and made the (many) changes that were needed to get it to produce Thunderbird declarations. The library |
Nice! What version of Thunderbird were you using to generate these definitions? Can I include this information on our official API documentation? |
Thanks a lot for creating the generated declarations for Thunderbird. I successfully switched from my (incomplete) manually created ones to it. One issue I found was with optional return types, e.g. The Firefox declarations seem to support optional return types, but does it with manual overwrites by setting Note that the documentation in the schema for optional return types seems to be incomplete. E.g. |
The current version is based on Thunderbird 109.0, specifically the tag
Sure. Is there a more systematic way of getting API information? I have used a combination of
It's all a lot of trial-and-error. You'd think that there must be a systematic way to find out which parts of the Gecko API have been implemented in Thunderbird. Is there?
I see what you mean. I'll put on the Todo-list to put this in src/tb-overrides.ts and to have a look into automatic recognition of optional return values, so the number of overrides can be limited to those where the schemas are incomplete. |
I have now added this and a few other items to src/tb-overrides.ts so they have the correct return type, like
In an earlier version, the Firefox declaration generator did that: when a schema indicated an optional callback parameter, it added I have now also done that for the Thunderbird schemas, which suffer from exactly the same problem. Out of 13 callbacks with an optional parameter in the schemas, 3 are documented as returning
In version |
Guys! By the way, do you have any tutorials/documentation about developing addons for Thunderbird using Typescript? I'm trying but i fails. |
@JimDanner I want to help generate the typings for newer versions of Thunderbird. I tried for v115 but your script errored on me. This is not the place to discuss difficulties I encountered with definitelytyped-thunderbird-webext-browser, but your repo has Github issues disabled. Can you enable |
Hi @ringods, thanks for making the effort! I have opened the Issues page on the repository. I've also run the program myself on the TB 115 API and got an error due to a silly change in Thunderbird's documentation webpage – it now lists the names of the APIs as tabs API etc., whereas it used to be tabs and so on. The program uses those names, so it failed as it was looking for a "tabs API" namespace. I have added code that strips off " API" and now it works again on my system. Also tried it on the bleeding-edge version TB 127, and there it turns out they added an undocumented function with... a nameless parameter. Really. So that tripped up the program too, and I added some more code to deal with it. I still need to check if other things in the API have changed (sadly, much has to be adjusted manually), and then create a fully updated output file. Anyway, please pull the new version, see if it works for you, and file an issue if it doesn't. |
I would not call this a silly change, with all due respect. The page will undergo massive changes in the future. I would propose to work with the schema files directly, and not with the documentation, which I generate from these schema files: https://searchfox.org/comm-central/source/mail/components/extensions/schemas |
So far, using the documentation webpage has been unavoidable. It is the only place I know where the program can see
If there's a place where that information is available – preferably in a systematic and stable form – I would prefer to use that. Regarding the addition of "API" after the names of Thunderbird's APIs, perhaps it isn't silly, but it's not very useful either and I don't understand why it was done in the table for Thunderbird and not in the table right below it for Gecko. |
The list of APIs supported by Thunderbird is generated from the title of the individual API pages. "API" was added to the title because other feedback I got indicated that this helps readability. The list of supported Firefox APIs is curated and not generated and was not modified. Thanks for pointing it out. The list of supported Firefox APIs can be taken from here: My curated list only includes useful and manually tested Firefox APIs. I will think about a solution for the link to the documentation. How is Firefox solving this? |
I've often wondered how the integration of Gecko is done by the Thunderbird developers: they must make an explicit choice somewhere which parts of the browser and its WebExtensions API they compile into Thunderbird. For example, the By the way, the Also, I have added various APIs to the list manually, as you can see in my code. It works, it just seems a bit arbitrary and not very rigorous. I discovered these things 'the hard way', by seeing errors in the results. If things change, it will depend on coincidence how long it takes to find out.
If I recall correctly, the Firefox typedef generator doesn't include links to the documentation pages. It also has a much easier time, as it can simply download all the JSON files from the two folders in the Firefox source code, without having to figure out which ones are implemented. |
I will bring this up at the next Thunderbird Council meeting as part of my WECG motion, but it think it would be much better for the Thunderbird developers to take over maintenance of the TS type definitions, as they could much more easily resolve the many issues @JimDanner described above, as well as produce more regular updates of the definitions when they update the MailExtension documentation, which will become more important as Thunderbird moves towards monthly releases. Having official Thunderbird TS type definitions, as well as documentation on how to use them would be extremely helpful for WebExtension developers by allowing them to easily perform type checking on their extensions. Another issue currently is for extensions supporting both Thunderbird and Firefox, and using APIs exclusive to both. In that case, developers cannot use the existing Thunderbird or Firefox type definitions, as they do not cover all APIs. It would be great if Thunderbird could collaborate with Mozilla to publish separate TS type definitions that cover the superset of extension APIs supported by both clients, which I believe could be accomplished by joining the WECG. (I should note that I am not advocating for developers to write their extensions in TS. Using TS results in obfuscated code, which is unnecessary for extensions that generally do not need to support older browsers and causes a performance degradation, as well as being the antithesis of open source. However, the TS type definitions can also be used to perform type checking on regular JS code by adding JSDoc comments, which is what Thunderbird should document and encourage add-on developers to do. See TinyWebEx/AddonTemplate#5 for more information.) |
You are right, forgot about those as that is considered bad practice, but we have no choice. The missing link is here: alarms is in the folder I mentioned: I did not add it to our documentation, because I missed it. Will add it. Edit: I added the list of supported Firefox APIs to our docs to make it easier for developers to see, which of the Firefox APIs work for Thunderbird as well. That is a manual process. If this is what you refer to as an 'emergent phenomenon', then yes. Help on that matter is always appreciated. |
OK, the list in
To be clear, I think this is another illustration of why the Thunderbird developers might want to be a bit more explicit about the choices they make in the integration of Gecko. @tdulcet I agree that the application developers are in the best position to publish API documentation, including the sort that's published at DefinitelyTyped in the form of They could take a look at some of my code, in particular the parts download.ts, tb-overrides.ts and perhaps desc-to-docs.ts; and a few documentation files I have written: Reserved words and Typefiles, to appreciate the types of complications that the generator deals with, e.g.:
|
From your experience with parsing of schema files, do you happen to know a nodeJS project, which can generate a pure manifest V2 or manifest V3 schema file from our mixed schema files? |
Don't know of any, unfortunately. |
Our schema files have |
@JimDanner : How is your generator (or the upstream project at https://github.com/jsmnbom/definitelytyped-firefox-webext-browser) dealing with Manifest V3? Since there are differences to Manifest V2, I assume your generated type definition can only be for Manifest V2 or Manifest V3, right? Reason I am asking: Would you benefit from a clean set of schema files for Manifest V2 and another clean set of schema files for Manifest V3? Also: Are there any discussions in the upstream project you may be aware of, to not use the raw schema files as source, but the output from the addons-linter project? The JSON from the linter looks a bit different, but already does some of the heavy lifting (for example untangle the mess regarding the browserAction API / action API schema files, which use an $import statement). The output can be found here: https://github.com/mozilla/addons-linter/tree/master/src/schema/imported We are in the process of making the linter work with Thunderbird extensions. |
Ok, this is what is gonna happen: Once this issue is fixed, we will most probably drop our own out-of-date fork of the Note: This file does not yet include the schema fixes regarding missing/wrong return values. That will hopefully be ready with the next Beta. The zip file has a In the end, I hope this set of schema files will be the base for:
(I am still unsure if we should instead use the output from the linter as base for the typescript definition file and our documentation, as it has some of the heavy lifting done already, but a slightly different format, see my last comment.) We will officially provide that schema zip-file somewhere once this process has been implemented, probably in our own (reworked) addons-linter repo. The next step is to convert our current meta-data into browser-compat-data used by MDN and the linter. After that, there should be no need to manually parse our documentation page. All information are either in the browser-compat-data or the provided schema zip-file. |
The generator is manifest-version-unaware: it just uses the JSON files it's told to download, without looking at the version. So it would benefit from separate sets of schemas for the two versions.
Probably not, the upstream project isn't very active. Addons-linter looks interesting (though converting its output into a
I think these are good developments; there's no use in doing double work. However, the idea that there are "no further quirks" may be a bit optimistic. As it is, the Firefox generator has a long list of manual fixes for issues with the schemas; it remains to be seen whether addons-linter solves all of them. Further, if the definitelytyped-firefox-webext-browser definition-file generator will be used, I'm not sure it will be able to handle all of the Thunderbird-specific issues I discovered while adjusting it for Thunderbird:
Also, my fork addresses a few issues the Firefox generator ignores or gets wrong, such as
|
I see. The descriptions are piped into Sphinx to build our documentation. It will be difficult to remove them. But why do you need to manually change some? We should try to eliminate the need for that.
That is unexpexted. Even Javascript Map has a delete function. Hm.
See #56 (comment)
Isn't this fixed with the pending schema updates?
Here is the output from the linter. It is mostly the same, but does not use
Ok, I do not see how we can fix this in the schema files, as these root namespaces are not defined in the schema, IIRC. So after all, it looks like we will still need a special fork of the generator project, for Thunderbird. This will be even more true, if the linter output is considered as input format. But I cannot do that. Your knowledge regarding typescript is superior to mine (which is basically non-exiting). It would be a huge waste of time if I had to start maintaining the project. I stand by what I said earlier:
I will try my best to generate the input data you need, to minimize your aditional / manual work. |
Yes, it would be good to eliminate those cases. For example, the function Creates (opens) a new window with any optional sizing, position or default URL provided.
When loading a page into a popup window, same-site links are opened within the same
window, all other links are opened in the user's default browser. To override this behavior,
add-ons have to register a
`content script <https://bugzilla.mozilla.org/show_bug.cgi?id=1618828#c3>`__ ,
capture click events and handle them manually. Same-site links with targets other than
<value>_self</value> are opened in a new tab in the most recent ``normal`` Thunderbird
window. This includes (if I understand reStructuredText correctly) a link with link text There are similar problems with the function
The problem in the TypeScript declaration file may be that
Let's assume it is.
That suggests that the linter can be an improvement over the current situation.
That sounds like a reasonable way forward. |
That is exactly what that reStructuredText notation for inline links does. Nothing has been left out. There is a different notation, which uses placeholders, which has a single underscore at the end. I try not to use it, except for the index.
Could you replace that specific reStructuredText notation using regular expressions, something like this?
This way you do not have to deal with individual descriptions, but just replace the correct reStructuredText notation for inline links with whatever you need? You could also just leave out the link by not using
I will keep this in mind when creating new APIs. |
Ah, I see, the quick ref omits that syntax (only mentions the single-underscore variant) but it's mentioned in the full specification. I'll test your regex and see if the conversion of descripotions can be fully automated. |
I have two follow-up question regarding @tdulcet request for a universal typescript definition, which should support all vendors.
Since @JimDanner 's project provides a specific type definition for Thunderbird, developers know that if something is proposed from the typescript definition file in the IDE, it should work in the most recent version of Thunderbird - but it may still have false positives, because a feature may only work for 115 but not for 102. That will only be caught by the addons-linter, using compat data. If the developer is using a universal typescript definition file, including supported features from Firefox or even other vendors, this will become more difficult, right? Is this at all desired?
In the early days of me working on the APIs, I added Thunderbird functions to namespaces, which are also used by Firefox. Specifically I guess this makes creating add-ons in Firefox and Thunderbird difficult as well, does it? Would it help to clearly separate these additions by moving them into a sub namespace, something like |
Thank you @jobisoft for your all your work and for taking the initiative to resolve those issues described by @JimDanner. Once this is finished, it should be a huge improvement for TB add-on developers. To answer your questions:
|
Would that not require the universal type definition to only include the overlap of all vendors? A set of shared APIs, which would reduce the available APIs to a minimum? How could that lead to more add-ons supporting TB ? |
If I may, I would like to share my experience with TypeScript addons development in Thunderbird / Safari / Firefox / Chrome / Edge. I'm using Note that if the API definitions are missing, then one have to use |
No, that would not be helpful. What is needed instead is Universal type definitions that cover the superset of APIs supported across all WebExtention clients. Then add-ons could for example use both TB and FF exclusive APIs in the same add-on, while still having type checking and other advanced IDE features, such as function signatures and autocompletion. Note that this was not something I was proposing MZLA do themselves, but instead collaborate with Mozilla, Google and Apple to create as part of the WECG. However, if MZLA wants to do it alone, it would likely benefit TB much more than it would the browsers considering the disparate set of APIs supported by TB.
While there are obviously no guarantees, I believe any changes that make it easier for add-on developers to support TB or otherwise inform them of the available MailExtension APIs in TB would result in more TB add-ons. Of course, documenting the MailExtension APIs on MDN and making some of the other changes I proposed to the Council would help significantly as well. |
@JimDanner : I found this: So Firefox does use a reference system in their descriptions. Will look at it and see if we can use the same. |
I have published the first version of The repository contains a script, which pulls all the relevant schema files for Thunderbird and does some post-processing (like manifest version split). The official documentation is based on these files now as well (only the "latest" branch so far): During the next week I will check, if really all Firefox APIs which are baked into Thunderbird work. The documentation lists all of them now, but I do not think all of them are meaningful. For example:
If I conclude that they are not working, I will probably remove them from the generated schema files (and therefore from the documentation). Have you worked with any of them and know if they are in any way helpful and working in Thunderbird? These scheme files include some additional data, for example links to the documentation. I hope this is now everything you need. The schema files have been re-worked massively to get rid of all reStructuredText notation in favour of inline Once the dust has settled, we could also add the processed schema files for the latest beta and/or esr directly to the repository, if that is desired. |
For Firefox there exists published TypeScript definitions for WebExtension, that can be easily installed and used via npm.
They seem to be generated by https://github.com/jsmnbom/definitelytyped-firefox-webext-browser (and published to https://github.com/DefinitelyTyped/DefinitelyTyped).
It would be nice to have something similar for Thunderbird.
The text was updated successfully, but these errors were encountered: