@ts-for-gir/lib 4.0.0-beta.41 → 4.0.0-beta.43
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/package.json +6 -6
- package/src/constants.ts +12 -46
- package/src/gir/introspected-classes.ts +28 -0
- package/src/injections/gobject.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-for-gir/lib",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.43",
|
|
4
4
|
"description": "Typescript .d.ts generator from GIR for gjs",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"type definitions"
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@ts-for-gir/tsconfig": "^4.0.0-beta.
|
|
44
|
+
"@ts-for-gir/tsconfig": "^4.0.0-beta.43",
|
|
45
45
|
"@types/ejs": "^3.1.5",
|
|
46
46
|
"@types/lodash": "^4.17.24",
|
|
47
47
|
"@types/node": "^24.12.0",
|
|
48
48
|
"rimraf": "^6.1.3",
|
|
49
|
-
"typescript": "^
|
|
49
|
+
"typescript": "^6.0.2"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@gi.ts/parser": "^4.0.0-beta.
|
|
53
|
-
"@ts-for-gir/reporter": "^4.0.0-beta.
|
|
54
|
-
"@ts-for-gir/templates": "^4.0.0-beta.
|
|
52
|
+
"@gi.ts/parser": "^4.0.0-beta.43",
|
|
53
|
+
"@ts-for-gir/reporter": "^4.0.0-beta.43",
|
|
54
|
+
"@ts-for-gir/templates": "^4.0.0-beta.43",
|
|
55
55
|
"colorette": "^2.0.20",
|
|
56
56
|
"ejs": "^5.0.1",
|
|
57
57
|
"glob": "^13.0.6",
|
package/src/constants.ts
CHANGED
|
@@ -8,61 +8,27 @@ export const PARAM_REG_EXP = /[0-9a-zA-Z_]*:/g;
|
|
|
8
8
|
export const OPT_PARAM_REG_EXP = /[0-9a-zA-Z_]*\?:/g;
|
|
9
9
|
export const NEW_LINE_REG_EXP = /[\n\r]+/g;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
* Package information interface for package.json
|
|
13
|
-
*/
|
|
14
|
-
interface Package {
|
|
15
|
-
name: string;
|
|
16
|
-
version: string;
|
|
17
|
-
description: string;
|
|
18
|
-
license: string;
|
|
19
|
-
homepage: string;
|
|
20
|
-
author: string;
|
|
21
|
-
}
|
|
11
|
+
declare const __TS_FOR_GIR_VERSION__: string;
|
|
22
12
|
|
|
23
13
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* Works both in workspace and after publishing
|
|
14
|
+
* Reads the package version, using the build-time injected value when bundled
|
|
15
|
+
* or falling back to reading package.json in development mode.
|
|
27
16
|
*/
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const currentModulePath = fileURLToPath(import.meta.url);
|
|
32
|
-
const currentDir = dirname(currentModulePath);
|
|
33
|
-
|
|
34
|
-
// Go up to the package root (src/ -> package root)
|
|
35
|
-
const packageRoot = join(currentDir, "..");
|
|
36
|
-
const packageJsonPath = join(packageRoot, "package.json");
|
|
37
|
-
|
|
38
|
-
return packageJsonPath;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
throw new Error(`Unable to resolve package.json path: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
17
|
+
function getPackageVersion(): string {
|
|
18
|
+
if (typeof __TS_FOR_GIR_VERSION__ !== "undefined") {
|
|
19
|
+
return __TS_FOR_GIR_VERSION__;
|
|
41
20
|
}
|
|
21
|
+
const currentModulePath = fileURLToPath(import.meta.url);
|
|
22
|
+
const currentDir = dirname(currentModulePath);
|
|
23
|
+
const packageJsonPath = join(currentDir, "..", "package.json");
|
|
24
|
+
const content = readFileSync(packageJsonPath, "utf-8");
|
|
25
|
+
return (JSON.parse(content) as { version: string }).version;
|
|
42
26
|
}
|
|
43
27
|
|
|
44
|
-
/**
|
|
45
|
-
* Reads and parses the current package's package.json file synchronously
|
|
46
|
-
* Contains version and metadata for this specific package
|
|
47
|
-
*/
|
|
48
|
-
function readPackageSync(): Package {
|
|
49
|
-
try {
|
|
50
|
-
const packagePath = resolvePackageJson();
|
|
51
|
-
const content = readFileSync(packagePath, "utf-8");
|
|
52
|
-
return JSON.parse(content) as Package;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
const message = error instanceof Error ? error.message : "Unknown error";
|
|
55
|
-
throw new Error(`Failed to read package.json: ${message}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Read package information once at module load
|
|
60
|
-
export const PACKAGE = readPackageSync();
|
|
61
|
-
|
|
62
28
|
export const APP_NAME = "ts-for-gir";
|
|
63
29
|
export const APP_USAGE = "TypeScript type definition generator for GObject introspection GIR files";
|
|
64
30
|
export const APP_SOURCE = "https://github.com/gjsify/ts-for-gir";
|
|
65
|
-
export const APP_VERSION =
|
|
31
|
+
export const APP_VERSION = getPackageVersion();
|
|
66
32
|
|
|
67
33
|
export const PACKAGE_DESC = (packageName: string, libraryVersion?: LibraryVersion) => {
|
|
68
34
|
if (libraryVersion) {
|
|
@@ -55,6 +55,7 @@ export interface SignalDescriptor {
|
|
|
55
55
|
signal?: IntrospectedSignal;
|
|
56
56
|
isNotifySignal?: boolean;
|
|
57
57
|
isDetailSignal?: boolean;
|
|
58
|
+
isTemplateLiteral?: boolean;
|
|
58
59
|
parameterTypes?: string[];
|
|
59
60
|
returnType?: string;
|
|
60
61
|
}
|
|
@@ -663,6 +664,19 @@ export class IntrospectedClass extends IntrospectedBaseClass {
|
|
|
663
664
|
returnType: "void",
|
|
664
665
|
});
|
|
665
666
|
});
|
|
667
|
+
|
|
668
|
+
// Add template literal catch-all for arbitrary property names.
|
|
669
|
+
// Only on GObject.Object itself — children inherit it via SignalSignatures extends.
|
|
670
|
+
if (this.isGObjectObject()) {
|
|
671
|
+
allSignals.push({
|
|
672
|
+
name: `notify::\${string}`,
|
|
673
|
+
isNotifySignal: true,
|
|
674
|
+
isDetailSignal: false,
|
|
675
|
+
isTemplateLiteral: true,
|
|
676
|
+
parameterTypes: ["GObject.ParamSpec"],
|
|
677
|
+
returnType: "void",
|
|
678
|
+
});
|
|
679
|
+
}
|
|
666
680
|
}
|
|
667
681
|
|
|
668
682
|
private addDetailedSignals(allSignals: SignalDescriptor[]): void {
|
|
@@ -670,6 +684,9 @@ export class IntrospectedClass extends IntrospectedBaseClass {
|
|
|
670
684
|
|
|
671
685
|
this.signals.forEach((signal) => {
|
|
672
686
|
if (signal.detailed) {
|
|
687
|
+
// Skip "notify" signal — already handled by addNotifySignals
|
|
688
|
+
if (signal.name === "notify") return;
|
|
689
|
+
|
|
673
690
|
propertyNames.forEach((propertyName) => {
|
|
674
691
|
allSignals.push({
|
|
675
692
|
name: `${signal.name}::${propertyName}`,
|
|
@@ -680,6 +697,17 @@ export class IntrospectedClass extends IntrospectedBaseClass {
|
|
|
680
697
|
returnType: this.getPropertyTypeString(signal.return_type),
|
|
681
698
|
});
|
|
682
699
|
});
|
|
700
|
+
|
|
701
|
+
// Add template literal catch-all for arbitrary detail strings
|
|
702
|
+
allSignals.push({
|
|
703
|
+
name: `${signal.name}::\${string}`,
|
|
704
|
+
signal: signal,
|
|
705
|
+
isNotifySignal: false,
|
|
706
|
+
isDetailSignal: true,
|
|
707
|
+
isTemplateLiteral: true,
|
|
708
|
+
parameterTypes: signal.parameters.map((p) => this.getPropertyTypeString(p.type)),
|
|
709
|
+
returnType: this.getPropertyTypeString(signal.return_type),
|
|
710
|
+
});
|
|
683
711
|
}
|
|
684
712
|
});
|
|
685
713
|
}
|
|
@@ -292,7 +292,7 @@ See https://gjs.guide/guides/gobject/basics.html#properties for more details.`;
|
|
|
292
292
|
const override = new IntrospectedClassFunction({
|
|
293
293
|
parent: ParamSpec,
|
|
294
294
|
name: "override",
|
|
295
|
-
return_type:
|
|
295
|
+
return_type: ParamSpec.getType(),
|
|
296
296
|
parameters: [
|
|
297
297
|
new IntrospectedFunctionParameter({
|
|
298
298
|
direction: GirDirection.In,
|