Convert the game engine (GDJS) and the extensions to TypeScript#2157
Convert the game engine (GDJS) and the extensions to TypeScript#2157
Conversation
|
Did you profile the code to verify that there is no regression in performance?
Nice, I was tired of having to skim through the changes made by prettier when trying to read the changes of a PR/commit |
|
The micro benchmarks in GDJS/tests/benchmarks have not changed much, I don't think there will be anything noticeable. I've looked at the generated output of a few classes, and it's what you would expect (nothing added much by esbuild) and very similar to what we would write by hand. So I'm not worried. |
|
The generated docs by better-docs seem to have some confusion, there are pages for a |
|
Docs are fixed - and I decided to switch to a cleaner theme (better docs has huge headings, and some very small fonts on the contrary). Unfortunately types in functions are gone and are not parsed by better docs typescript module for JSDoc :/ I'll probably 1) release a new GDevelop version without this then 2) Merge this so we have time to find any regression before releasing a new version. |
|
I think typedoc should be a good choice as cloudflare uses it. |
Only show in developer changelog
|
I've rebased this on master, made a few more checks and this seems to work properly for examples that I've tried :) I'll merge this soon. I think the PR that will be impacted the most is the one with array/booleans @arthuro555 but I believe it should not be too complicated to port your changes. This will also include changes from #2152. |
Don't show in changelog
Don't show in changelog
Don't show in changelog
Also adapt custom behavior code generation to use a (partial) ES6 class (methods are still added using prototype) Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in changelog
Don't show in the changelog
|
I think I've verified almost all feature in terms of extensions. I'll merge this tomorrow - the sooner the better. You'll only have to re-run |
This converts all the game engine (GDJS "Runtime") and the extensions to TypeScript.
The conversion was semi-automated with a bunch of tools (lebab, gents) and specific scripts.
This brings a lot of nice things:
Classandextends.There are a lot of
anyremaining but this can easily be fixed as we work on files.All the files are processed using esbuild to transpile them back to JavaScript. It's really fast (<500ms on my MacBook) so should be almost invisible. This is done by a script
npm run buildin GDJS, which is run automatically by GDevelop when a change is observed (like what is done currently).Type checking is done by the TypeScript compiler (as before). You can run it manually (
npm run check-typesin GDJS folder) but I recommend you use VSCode (or another IDE/text editor that has TypeScript support). They should work out of the box thanks to thetsconfig.jsonfile.This also adds auto-formatting of all the TypeScript files (so everything is auto-formatted like in newIDE).
Still to do:
How can I try this and help finding issues?
CircleCI should build a version for us. In the meantime, getting the branch and running
npm installin GDJS should be sufficient.Even if most of the changes were done automatically, there were manual fixes and it's possible that some things have been broken. Please report any game/example/extension that is broken.
I have a PR opened, should I restart it?
No, please continue as you do. We'll convert what you've did to TypeScript later (before or after merging, depending on the complexity of the PR).
I'm afraid TypeScript will be too complicated for me
As we're "transpiling" .ts files separately from type checking, you can continue writing code without types or with errors, and you'll still be able to have it working.
Of course, we'll correct all types before merging a PR.
Can we write TypeScript in JavaScript events inside GDevelop?
No, still only JavaScript is supported (though the builtin editor understands TypeScript, so you benefit from auto-completions and JSDoc type annotations).
This is because the transpiling is not done by GDevelop, but by a separate program only in development.
All things considered, I think this is a good step in the direction of modernizing the codebase and having it ready for the next 5 years to come :)