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

Draft: Switch to ts-for-gir for TypeScript definitions #979

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions build-aux/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gi-types
2 changes: 1 addition & 1 deletion src/langs/javascript/template/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
16 changes: 12 additions & 4 deletions src/langs/typescript/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions src/langs/typescript/template/tsconfig.demos.json
Original file line number Diff line number Diff line change
@@ -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",
]
}
16 changes: 6 additions & 10 deletions src/langs/typescript/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
50 changes: 0 additions & 50 deletions src/langs/typescript/types/ambient.d.ts

This file was deleted.

20 changes: 20 additions & 0 deletions src/langs/typescript/types/workbench.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="@pkgdatadir@/langs/typescript/gi-types/adw-1.d.ts" />
/// <reference path="@pkgdatadir@/langs/typescript/gi-types/gtk-4.0.d.ts" />
/// <reference path="@pkgdatadir@/langs/typescript/gi-types/gobject-2.0.d.ts" />

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<string, Function | GObject.Object>): void;
};
}
Loading