From 1cd65a959e786ad5454bd3a2a2134f95a9976ec8 Mon Sep 17 00:00:00 2001 From: Angelo Verlain Date: Mon, 5 Aug 2024 02:26:13 +0200 Subject: [PATCH 1/6] feat: switch to my ts-for-gir type definitions will require you to do ``` git submodule sync git submodule update --init --recursive --remote ``` --- .gitmodules | 3 +-- gi-types | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 02339e69e..d74f78178 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,5 +9,4 @@ url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git [submodule "src/langs/typescript/template/gi-types"] path = gi-types - url = https://gitlab.gnome.org/BrainBlasted/gi-typescript-definitions.git - branch = nightly + url = https://github.com/vixalien/gi-typescript-definitions.git diff --git a/gi-types b/gi-types index 396fe1471..c10cb90f2 160000 --- a/gi-types +++ b/gi-types @@ -1 +1 @@ -Subproject commit 396fe147142e28a921f0745eff1a562c7a551843 +Subproject commit c10cb90f221ce0507e5538cccb50eb5544048772 From a295914d910598ae0b7d9168dc526379da27ab1a Mon Sep 17 00:00:00 2001 From: Angelo Verlain Date: Mon, 5 Aug 2024 13:03:49 +0200 Subject: [PATCH 2/6] chore: remove GJS types in favor of the ones in `gi-types` --- src/langs/typescript/template/tsconfig.json | 8 ++--- src/langs/typescript/types/ambient.d.ts | 37 ++------------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/src/langs/typescript/template/tsconfig.json b/src/langs/typescript/template/tsconfig.json index 2fc945907..232a11ba8 100644 --- a/src/langs/typescript/template/tsconfig.json +++ b/src/langs/typescript/template/tsconfig.json @@ -7,14 +7,12 @@ "target": "ESNext", "outDir": "compiled_javascript", "baseUrl": ".", - "paths": { - "*": ["*", "@pkgdatadir@/langs/typescript/gi-types/*"] - }, "skipLibCheck": true }, "include": [ "main.ts", - "@pkgdatadir@/langs/typescript/types/ambient.d.ts", - "@pkgdatadir@/langs/typescript/gi-types/gi.d.ts" + "@pkgdatadir@/langs/typescript/gi-types/gi.d.ts", + "@pkgdatadir@/langs/typescript/gi-types/gjs.d.ts", + "@pkgdatadir@/langs/typescript/types/ambient.d.ts" ] } diff --git a/src/langs/typescript/types/ambient.d.ts b/src/langs/typescript/types/ambient.d.ts index e1d519f27..fde758f86 100644 --- a/src/langs/typescript/types/ambient.d.ts +++ b/src/langs/typescript/types/ambient.d.ts @@ -2,39 +2,6 @@ // import Gtk from "gi://Gtk?version=4.0"; // import GObject from "gi://GObject"; -// additional type declarations for GJS - -// additional GJS log utils -declare function print(...args: any[]): void; -declare function log(...args: any[]): void; - -// GJS pkg global -declare const pkg: { - version: string; - name: string; -}; - -// old GJS global imports -// used like: imports.format.printf("..."); -declare module imports { - // format import - const format: { - format(this: String, ...args: any[]): string; - printf(fmt: string, ...args: any[]): string; - vprintf(fmt: string, args: any[]): string; - }; -} - -// gettext import -declare module "gettext" { - export function gettext(id: string): string; - export function ngettext( - singular: string, - plural: string, - n: number, - ): string; -} - // TODO: uncomment correct typings after we switch to `ts-for-gir` // declare const workbench: { // window: Adw.ApplicationWindow; @@ -47,4 +14,6 @@ declare module "gettext" { // }; // global workbench object -declare const workbench: any; +declare const workbench: { + hello: "world"; +}; From 872c254489389f68c4441d6efbb490a8bd839070 Mon Sep 17 00:00:00 2001 From: Angelo Verlain Date: Mon, 5 Aug 2024 13:22:03 +0200 Subject: [PATCH 3/6] chore: use ES2022 and and the index.d.ts --- src/langs/typescript/template/tsconfig.json | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/langs/typescript/template/tsconfig.json b/src/langs/typescript/template/tsconfig.json index 232a11ba8..42904bc9a 100644 --- a/src/langs/typescript/template/tsconfig.json +++ b/src/langs/typescript/template/tsconfig.json @@ -1,18 +1,16 @@ { "compilerOptions": { - "module": "ESNext", + "module": "ES2022", "moduleResolution": "Bundler", - // TODO: should probably be fixed to ES2023, or whatever standard is - // currently supported by the latest GJS - "target": "ESNext", + "target": "ES2022", "outDir": "compiled_javascript", "baseUrl": ".", - "skipLibCheck": true + "skipLibCheck": true, + "lib": ["ES2022"] }, "include": [ "main.ts", - "@pkgdatadir@/langs/typescript/gi-types/gi.d.ts", - "@pkgdatadir@/langs/typescript/gi-types/gjs.d.ts", + "@pkgdatadir@/langs/typescript/gi-types/index.d.ts", "@pkgdatadir@/langs/typescript/types/ambient.d.ts" ] } From d1d3b7858d4a54467f123d57e4bb1a3bc2912298 Mon Sep 17 00:00:00 2001 From: Angelo Verlain Date: Tue, 20 Aug 2024 18:44:24 +0200 Subject: [PATCH 4/6] fix: workbench ambient.d.ts not working --- src/langs/typescript/meson.build | 9 ++++--- src/langs/typescript/types/ambient.d.ts | 35 +++++++++++++------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/langs/typescript/meson.build b/src/langs/typescript/meson.build index 5b6ff274c..2cf57dd3a 100644 --- a/src/langs/typescript/meson.build +++ b/src/langs/typescript/meson.build @@ -5,10 +5,11 @@ configure_file( configuration: bin_conf, ) -install_data( - ['types/ambient.d.ts'], - install_dir: join_paths(pkgdatadir, 'langs/typescript'), - preserve_path: true, +configure_file( + input: 'types/ambient.d.ts', + output: 'ambient.d.ts', + install_dir: join_paths(pkgdatadir, 'langs/typescript/types'), + configuration: bin_conf, ) install_subdir( diff --git a/src/langs/typescript/types/ambient.d.ts b/src/langs/typescript/types/ambient.d.ts index fde758f86..e6cf2592d 100644 --- a/src/langs/typescript/types/ambient.d.ts +++ b/src/langs/typescript/types/ambient.d.ts @@ -1,19 +1,20 @@ -// import Adw from "gi://Adw"; -// import Gtk from "gi://Gtk?version=4.0"; -// import GObject from "gi://GObject"; +/// +/// +/// -// TODO: uncomment correct typings after we switch to `ts-for-gir` -// declare const workbench: { -// window: Adw.ApplicationWindow; -// application: Adw.Application; -// builder: Gtk.Builder; -// template: string; -// resolve(path: string): string; -// preview(object: Gtk.Widget): void; -// build(params: Record): void; -// }; +import Gtk from "gi://Gtk?version=4.0"; +import Adw from "gi://Adw"; +import GObject from "gi://GObject"; -// global workbench object -declare const workbench: { - hello: "world"; -}; +declare global { + // global workbench object + declare const workbench: { + window: Adw.ApplicationWindow; + application: Adw.Application; + builder: Gtk.Builder; + template: string; + resolve(path: string): string; + preview(object: Gtk.Widget): void; + build(params: Record): void; + }; +} From 0ae9994fd7de15d689c6f2f943bf99ccd582c20b Mon Sep 17 00:00:00 2001 From: Angelo Verlain Date: Tue, 20 Aug 2024 19:00:18 +0200 Subject: [PATCH 5/6] chore: rename `ambient.d.ts` to `workbench.d.ts` --- src/langs/javascript/template/jsconfig.json | 2 +- src/langs/typescript/meson.build | 4 ++-- src/langs/typescript/template/tsconfig.json | 2 +- src/langs/typescript/types/{ambient.d.ts => workbench.d.ts} | 0 4 files changed, 4 insertions(+), 4 deletions(-) rename src/langs/typescript/types/{ambient.d.ts => workbench.d.ts} (100%) diff --git a/src/langs/javascript/template/jsconfig.json b/src/langs/javascript/template/jsconfig.json index 835b0797c..07e30922a 100644 --- a/src/langs/javascript/template/jsconfig.json +++ b/src/langs/javascript/template/jsconfig.json @@ -15,7 +15,7 @@ }, "include": [ "main.js", - "@pkgdatadir@/langs/typescript/types/ambient.d.ts", + "@pkgdatadir@/langs/typescript/types/workbench.d.ts", "@pkgdatadir@/langs/typescript/gi-types/gi.d.ts" ] } diff --git a/src/langs/typescript/meson.build b/src/langs/typescript/meson.build index 2cf57dd3a..015df1fa4 100644 --- a/src/langs/typescript/meson.build +++ b/src/langs/typescript/meson.build @@ -6,8 +6,8 @@ configure_file( ) configure_file( - input: 'types/ambient.d.ts', - output: 'ambient.d.ts', + input: 'types/workbench.d.ts', + output: 'workbench.d.ts', install_dir: join_paths(pkgdatadir, 'langs/typescript/types'), configuration: bin_conf, ) diff --git a/src/langs/typescript/template/tsconfig.json b/src/langs/typescript/template/tsconfig.json index 42904bc9a..d7f723deb 100644 --- a/src/langs/typescript/template/tsconfig.json +++ b/src/langs/typescript/template/tsconfig.json @@ -11,6 +11,6 @@ "include": [ "main.ts", "@pkgdatadir@/langs/typescript/gi-types/index.d.ts", - "@pkgdatadir@/langs/typescript/types/ambient.d.ts" + "@pkgdatadir@/langs/typescript/types/workbench.d.ts" ] } diff --git a/src/langs/typescript/types/ambient.d.ts b/src/langs/typescript/types/workbench.d.ts similarity index 100% rename from src/langs/typescript/types/ambient.d.ts rename to src/langs/typescript/types/workbench.d.ts From aa930148cb9521ef0372dc2129698bee7fef5c2a Mon Sep 17 00:00:00 2001 From: Angelo Verlain Date: Tue, 20 Aug 2024 19:09:29 +0200 Subject: [PATCH 6/6] feat: compile typescript demos to javascript at build time --- build-aux/library.js | 21 +++++++++++++++++++ src/langs/typescript/meson.build | 7 +++++++ .../typescript/template/tsconfig.demos.json | 14 +++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/langs/typescript/template/tsconfig.demos.json diff --git a/build-aux/library.js b/build-aux/library.js index fa7b4fe91..c5fe3c967 100755 --- a/build-aux/library.js +++ b/build-aux/library.js @@ -24,6 +24,8 @@ Gio._promisify( Gio._promisify(Gio.File.prototype, "copy_async", "copy_finish"); +Gio._promisify(Gio.Subprocess.prototype, "wait_async", "wait_finish"); + const loop = new GLib.MainLoop(null, false); const [pkgdatadir] = programArgs; @@ -95,6 +97,9 @@ const demos = []; demos.push(demo); } + // compile TypeScript demos to JavaScript + await compileTypeScriptFiles(); + await Gio.File.new_for_path(pkgdatadir) .get_child("demos/index.json") .replace_contents_async( @@ -114,6 +119,22 @@ const demos = []; loop.quit(); }); +async function compileTypeScriptFiles() { + const tsc_launcher = new Gio.SubprocessLauncher(); + tsc_launcher.set_cwd( + Gio.File.new_for_path(pkgdatadir).get_child("demos").get_path() + ); + + const tsc = tsc_launcher.spawnv(["tsc"]); + await tsc.wait_async(null); + + // TODO: maybe throw when the result is false + const successful = tsc.get_successful(); + tsc_launcher.close(); + + if (!successful) throw new Error("One or several errors happened while compiling TypeScript demos to JavaScript") +} + async function copyDemo(source, destination) { try { destination.make_directory_with_parents(null); diff --git a/src/langs/typescript/meson.build b/src/langs/typescript/meson.build index 015df1fa4..be7f4e3fd 100644 --- a/src/langs/typescript/meson.build +++ b/src/langs/typescript/meson.build @@ -5,6 +5,13 @@ configure_file( configuration: bin_conf, ) +configure_file( + input: 'template/tsconfig.demos.json', + output: 'tsconfig.json', + install_dir: join_paths(pkgdatadir, 'demos'), + configuration: bin_conf, +) + configure_file( input: 'types/workbench.d.ts', output: 'workbench.d.ts', diff --git a/src/langs/typescript/template/tsconfig.demos.json b/src/langs/typescript/template/tsconfig.demos.json new file mode 100644 index 000000000..733fb9c0c --- /dev/null +++ b/src/langs/typescript/template/tsconfig.demos.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "ES2022", + "moduleResolution": "Bundler", + "target": "ES2022", + "skipLibCheck": true, + "lib": ["ES2022"], + }, + "include": [ + "./**/*.ts", + "@pkgdatadir@/langs/typescript/gi-types/index.d.ts", + "@pkgdatadir@/langs/typescript/types/workbench.d.ts", + ] +}