Skip to content
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

[WIP] PoC Typescript support #11276

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

[WIP] PoC Typescript support #11276

wants to merge 13 commits into from

Conversation

Gr3q
Copy link
Contributor

@Gr3q Gr3q commented Nov 6, 2022

Currently with shitty structure for internal use (within Cinnamon repo) only. c lib declarations are copy-pasted from GIR2TS for now

TODO:

  • ts declaration generation from .gir files doesn't respect the shadowed-by property, needs to be fixed.
  • ts declaration generation from .gir files doesn't handle array types well in some cases, needs to be fixed.
  • ts declaration generation from .gir files doesn't handle user_data and types for callbacks (generics), needs to be fixed
  • Better internal structure on where to output js and d.ts files

#11272

@ItzSwirlz
Copy link
Contributor

Yeah.. all the dependencies are a slight problem. This would also mean that this TS would have to integrate with CJS otherwise everyone would have to install Node

But having to bootstrap the other Gir's isn't ideal - it's like what Gtk-Rs is doing and for one repo that's a bit crazy

@clefebvre clefebvre changed the title PoC Typescript support [WIP] PoC Typescript support Nov 17, 2022
@ItzSwirlz
Copy link
Contributor

ItzSwirlz commented Jan 4, 2023

GNOME's sound recorder just ported to TS. They are using Yarn and this tool: https://gitlab.gnome.org/ewlsh/gi.ts

It will probably be way cleaner if we go with the gi.ts route. There is still a types folder but IMO assuming that it is okay to have TS and it's bindings in the main cinnamon repository (meaning it is a requirement to be built and maintained by distributors) then I think this is feasible

Next move forward personally would be trying to work with gi.ts

Edit: the current files changed looks close enough to what a result of gi.ts would look like but if TS and bindings are being bundled into Cinnamon, may I suggest writing some example applets/desklets/extensions to show that this works?

@Gr3q
Copy link
Contributor Author

Gr3q commented Jan 4, 2023

I'm in the process of trying out gi.ts but currently I have trouble building the declarations for Cinnamon with it.

For examples of spices, here they are:
https://github.com/linuxmint/cinnamon-spices-applets/tree/master/weather%40mockturtl
https://github.com/linuxmint/cinnamon-spices-applets/tree/master/radio%40driglu4it
https://github.com/linuxmint/cinnamon-spices-extensions/tree/master/gTile%40shuairan

They are either using the declarations in the applets repo (it was requested to be bundled for review) or the npm package. Both of them are basically the files included in this WIP. All of them are using webpack for convenience (and to get around annoying import issues with require).

Edit: I managed to build it with a minor modification to gi.ts (had to comment out lib/src/generic/meta generic modifiers, doesn't exist in our version). I will try if they are actually working as expected with the existing spices. I'm still a bit sad that I can't get it to include docstrings, they are really useful.

@Gr3q
Copy link
Contributor Author

Gr3q commented Jan 29, 2023

I finally had time to check https://gitlab.gnome.org/ewlsh/gi.ts against the current weather applet codebase.

After the minor fix (mentioned in the previous comment) to gi.tss codebase it works fine. You can specifically provide where it should pull .gir files from and specify all top-level dependencies for Cinnamon, it will pull in the other libs theose depend on.

It doesn't inject them under imports, a declaration file is needed somewhere:

import * as Atk from "atk";
import * as St from "st";
import * as Gio from "gio";
import * as GLib from "glib";
import * as Soup from "soup";
import * as Clutter from "clutter";
import * as Gtk from "gtk";
import * as GObject from "gobject";

declare global {
    const _: (text: string) => string;
    const logError: (...args: any[]) => void;
 
    namespace imports {
        namespace gi {
            export {
               St,
               Clutter,
               Atk,
               Gio,
               GLib,
               Soup,
               Gtk,
               GObject
        }
    }
}

The location of the file above should depend on where we store/generate the declaration files or where injection actually happens.

It also can be broken up to more files - Typescript automatically merges global declarations - but in the end an applet or any codebase using them need to reference them in their tsconfig.json for it to work, so a standardized place would be useful.

So far the only problem I found is that I have a hard time override/extend the gi.ts declarations because the way they need to be exported into imports.gi. For example add function is missing from BoxLayout so the weather applet still doesn't built because it uses that.

Currently the only way I can see for extending is directly modify gi.ts codebase to inject the missing functions. It's not that nice, but considering the fact it already does that I don't think it should be a problem. It needs to be forked with minor changes anyway.

Gr3q/cinnamon-spices-applets#12 - changes for weather applet built against gi.ts declarations, missing function manually injected for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants