node-gtk 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -190
- package/bin/node-gtk.js +31 -0
- package/lib/bootstrap.js +22 -4
- package/lib/index.js +25 -0
- package/lib/loop.js +34 -0
- package/lib/overrides/GLib-2.0.js +12 -9
- package/lib/overrides/Gio-2.0.js +26 -0
- package/lib/overrides/Gtk-3.0.js +17 -12
- package/lib/overrides/Gtk-4.0.js +4 -2
- package/lib/register-class.js +1 -1
- package/package.json +9 -2
- package/scripts/build-test-fixtures.js +237 -0
- package/scripts/ci.sh +5 -3
- package/src/boxed.cc +33 -3
- package/src/boxed.h +13 -0
- package/src/callback.cc +12 -0
- package/src/callback.h +1 -0
- package/src/closure.cc +110 -2
- package/src/function.cc +68 -7
- package/src/function.h +1 -0
- package/src/gi.cc +72 -0
- package/src/gobject.cc +148 -27
- package/src/loop.cc +39 -3
- package/src/loop.h +2 -0
- package/src/type.cc +3 -2
- package/src/value.cc +369 -31
- package/src/value.h +22 -0
- package/tools/README.md +91 -0
- package/tools/generate-types.js +1045 -0
- package/lib/binding/node-v102-linux-x64/node_gtk.node +0 -0
- package/lib/binding/node-v108-linux-x64/node_gtk.node +0 -0
- package/lib/binding/node-v115-linux-x64/node_gtk.node +0 -0
- package/lib/binding/node-v127-linux-x64/node_gtk.node +0 -0
- package/lib/binding/node-v93-linux-x64/node_gtk.node +0 -0
package/tools/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# node-gtk TypeScript types — PROTOTYPE (Model B: generate-on-demand)
|
|
2
|
+
|
|
3
|
+
Types are generated **on the user's machine** from the GObject-Introspection
|
|
4
|
+
typelibs they actually have installed, using node-gtk's own runtime introspection
|
|
5
|
+
(`require('node-gtk')._GIRepository`, the libgirepository C API exposed to JS).
|
|
6
|
+
Because the generator reads the same typelibs and applies the same name/shape
|
|
7
|
+
rules as `lib/bootstrap.js`, the output matches what node-gtk produces at runtime
|
|
8
|
+
— and it matches *their* library versions, not a bundled snapshot.
|
|
9
|
+
|
|
10
|
+
## User workflow
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
# 1. generate types for the namespaces you use (+ their dependency closure).
|
|
14
|
+
# Output defaults to ./node_modules/.node-gtk-types (hidden, gitignored).
|
|
15
|
+
npx node-gtk generate-types Gtk-4.0
|
|
16
|
+
|
|
17
|
+
# 2. point tsconfig at the generated shim
|
|
18
|
+
```
|
|
19
|
+
```jsonc
|
|
20
|
+
// tsconfig.json
|
|
21
|
+
{
|
|
22
|
+
"compilerOptions": {
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"paths": { "node-gtk": ["./node_modules/.node-gtk-types/node-gtk.d.ts"] }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
```ts
|
|
29
|
+
// 3. write code — gi.require() is typed by string-literal overloads
|
|
30
|
+
import * as gi from 'node-gtk'
|
|
31
|
+
const Gtk = gi.require('Gtk', '4.0') // inferred as the Gtk-4.0 namespace
|
|
32
|
+
const win = new Gtk.ApplicationWindow({ title: 'Hi', defaultWidth: 400 })
|
|
33
|
+
win.on('close-request', () => false)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`generate-types` emits one `<Namespace>-<version>.d.ts` per namespace plus a
|
|
37
|
+
`node-gtk.d.ts` module shim. The shim overloads `require()` so each
|
|
38
|
+
`gi.require('Ns','ver')` resolves to the matching generated namespace; namespaces
|
|
39
|
+
you didn't generate fall back to `any`. Because the default output lives under
|
|
40
|
+
`node_modules`, it's treated as a generated cache — wire it into a `postinstall`
|
|
41
|
+
script so it regenerates after install.
|
|
42
|
+
|
|
43
|
+
## Pieces (prototype)
|
|
44
|
+
|
|
45
|
+
- `bin/node-gtk.js` — CLI entry (`package.json` `"bin"`); dispatches `generate-types`.
|
|
46
|
+
- `tools/generate-types.js` — the generator. `run(argv)` / `generate(roots, outdir)`.
|
|
47
|
+
- `examples/ts-demo/` — `app.ts` (valid, typechecks clean) and `app-errors.ts`
|
|
48
|
+
(4 deliberate mistakes, all caught). Generate types into `.node-gtk-types/` first
|
|
49
|
+
(see that dir's `.gitignore`).
|
|
50
|
+
|
|
51
|
+
## Verify the demo
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
node bin/node-gtk.js generate-types Gtk-4.0 --outdir examples/ts-demo/.node-gtk-types
|
|
55
|
+
node_modules/.bin/tsc -p examples/ts-demo/tsconfig.json # passes clean
|
|
56
|
+
sed 's/app.ts/app-errors.ts/' examples/ts-demo/tsconfig.json > examples/ts-demo/tsconfig.errors.json
|
|
57
|
+
node_modules/.bin/tsc -p examples/ts-demo/tsconfig.errors.json # 4 errors caught
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Fidelity
|
|
61
|
+
|
|
62
|
+
The generated `.d.ts` for the full Gtk-3.0, Gtk-4.0, and Adw/GtkSource stacks
|
|
63
|
+
type-check with **0 errors even without `skipLibCheck`**. Modelled faithfully:
|
|
64
|
+
|
|
65
|
+
- OUT/INOUT params surfaced via the return value as node-gtk does
|
|
66
|
+
(`getStartIter(): TextIter`, `getIterAtLine(n): [boolean, TextIter]`).
|
|
67
|
+
- Callback argument types expanded (e.g. `Gio.AsyncReadyCallback`).
|
|
68
|
+
- 64-bit ints return `bigint` (full precision, #323/#149); params accept
|
|
69
|
+
`number | bigint`.
|
|
70
|
+
- Enum methods and interface constants emitted (declaration-merged).
|
|
71
|
+
- GObject override conflicts reconciled as overloads, so subclass methods stay
|
|
72
|
+
assignable to inherited ones; multiple-interface signal/method conflicts
|
|
73
|
+
resolved with a unified, assignable-to-all declaration.
|
|
74
|
+
- Interfaces emit both a type and a value, so constructor functions and
|
|
75
|
+
constants work (`Gio.File.newForPath(...)`).
|
|
76
|
+
- Relative imports use `.js` extensions, so the output works under
|
|
77
|
+
`moduleResolution` node16/nodenext (and bundler). `skipLibCheck` is no longer
|
|
78
|
+
required for the GTK stack, though it remains a fine default.
|
|
79
|
+
- **JSDoc comments** from the `.gir` XML — class/method/property/signal/enum
|
|
80
|
+
docs, with `@param`/`@returns`/`@deprecated` — so editors show GNOME's API docs
|
|
81
|
+
on hover. The typelib doesn't carry docs, so this reads the matching
|
|
82
|
+
`<Namespace>-<version>.gir` from `$XDG_DATA_DIRS/gir-1.0` (shipped by the
|
|
83
|
+
library's `-dev`/`-devel` package). Best-effort: if the `.gir` is absent, types
|
|
84
|
+
still generate without comments. Pass `--no-docs` for leaner output (~5× smaller).
|
|
85
|
+
|
|
86
|
+
## Remaining limitations
|
|
87
|
+
|
|
88
|
+
- **Overriding an inherited method that collides by name** in a user subclass
|
|
89
|
+
(e.g. a gutter renderer's `activate(iter, …)` vs `GtkWidget.activate()`)
|
|
90
|
+
requires the override to satisfy both signatures — an inherent consequence of
|
|
91
|
+
the GObject API reusing a name, not specific to these types.
|