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/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/gi-types b/gi-types index 396fe1471..c10cb90f2 160000 --- a/gi-types +++ b/gi-types @@ -1 +1 @@ -Subproject commit 396fe147142e28a921f0745eff1a562c7a551843 +Subproject commit c10cb90f221ce0507e5538cccb50eb5544048772 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 5b6ff274c..be7f4e3fd 100644 --- a/src/langs/typescript/meson.build +++ b/src/langs/typescript/meson.build @@ -5,10 +5,18 @@ configure_file( configuration: bin_conf, ) -install_data( - ['types/ambient.d.ts'], - install_dir: join_paths(pkgdatadir, 'langs/typescript'), - preserve_path: true, +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', + install_dir: join_paths(pkgdatadir, 'langs/typescript/types'), + configuration: bin_conf, ) install_subdir( 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", + ] +} diff --git a/src/langs/typescript/template/tsconfig.json b/src/langs/typescript/template/tsconfig.json index 2fc945907..d7f723deb 100644 --- a/src/langs/typescript/template/tsconfig.json +++ b/src/langs/typescript/template/tsconfig.json @@ -1,20 +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": ".", - "paths": { - "*": ["*", "@pkgdatadir@/langs/typescript/gi-types/*"] - }, - "skipLibCheck": true + "skipLibCheck": true, + "lib": ["ES2022"] }, "include": [ "main.ts", - "@pkgdatadir@/langs/typescript/types/ambient.d.ts", - "@pkgdatadir@/langs/typescript/gi-types/gi.d.ts" + "@pkgdatadir@/langs/typescript/gi-types/index.d.ts", + "@pkgdatadir@/langs/typescript/types/workbench.d.ts" ] } diff --git a/src/langs/typescript/types/ambient.d.ts b/src/langs/typescript/types/ambient.d.ts deleted file mode 100644 index e1d519f27..000000000 --- a/src/langs/typescript/types/ambient.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -// import Adw from "gi://Adw"; -// 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; -// application: Adw.Application; -// builder: Gtk.Builder; -// template: string; -// resolve(path: string): string; -// preview(object: Gtk.Widget): void; -// build(params: Record): void; -// }; - -// global workbench object -declare const workbench: any; diff --git a/src/langs/typescript/types/workbench.d.ts b/src/langs/typescript/types/workbench.d.ts new file mode 100644 index 000000000..e6cf2592d --- /dev/null +++ b/src/langs/typescript/types/workbench.d.ts @@ -0,0 +1,20 @@ +/// +/// +/// + +import Gtk from "gi://Gtk?version=4.0"; +import Adw from "gi://Adw"; +import GObject from "gi://GObject"; + +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; + }; +}