@ts-for-gir/lib 4.0.0-beta.1 → 4.0.0-beta.3

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.
Files changed (249) hide show
  1. package/lib/dependency-manager.d.ts +90 -11
  2. package/lib/dependency-manager.js +209 -35
  3. package/lib/dependency-manager.js.map +1 -1
  4. package/lib/generators/dts-inline.d.ts +2 -2
  5. package/lib/generators/dts-inline.js +7 -7
  6. package/lib/generators/dts-inline.js.map +1 -1
  7. package/lib/generators/dts-modules.d.ts +2 -2
  8. package/lib/generators/dts-modules.js +9 -9
  9. package/lib/generators/dts-modules.js.map +1 -1
  10. package/lib/generators/dts.d.ts +2 -2
  11. package/lib/generators/dts.js +8 -8
  12. package/lib/generators/dts.js.map +1 -1
  13. package/lib/generators/generator.d.ts +3 -3
  14. package/lib/generators/generator.js.map +1 -1
  15. package/lib/generators/json.d.ts +2 -2
  16. package/lib/generators/json.js +14 -14
  17. package/lib/generators/json.js.map +1 -1
  18. package/lib/generics/visitor.js +5 -9
  19. package/lib/generics/visitor.js.map +1 -1
  20. package/lib/gir/alias.d.ts +2 -2
  21. package/lib/gir/alias.js +3 -3
  22. package/lib/gir/alias.js.map +1 -1
  23. package/lib/gir/base.d.ts +3 -3
  24. package/lib/gir/base.js.map +1 -1
  25. package/lib/gir/class.d.ts +5 -5
  26. package/lib/gir/class.js +32 -33
  27. package/lib/gir/class.js.map +1 -1
  28. package/lib/gir/const.d.ts +2 -2
  29. package/lib/gir/const.js +1 -1
  30. package/lib/gir/const.js.map +1 -1
  31. package/lib/gir/enum.d.ts +5 -5
  32. package/lib/gir/enum.js +7 -7
  33. package/lib/gir/enum.js.map +1 -1
  34. package/lib/gir/function.d.ts +9 -9
  35. package/lib/gir/function.js +4 -4
  36. package/lib/gir/function.js.map +1 -1
  37. package/lib/gir/nodes.d.ts +1 -1
  38. package/lib/gir/nodes.js +1 -1
  39. package/lib/gir/nodes.js.map +1 -1
  40. package/lib/gir/property.d.ts +2 -2
  41. package/lib/gir/property.js.map +1 -1
  42. package/lib/gir/registry.d.ts +6 -6
  43. package/lib/gir/registry.js +3 -3
  44. package/lib/gir/registry.js.map +1 -1
  45. package/lib/gir/signal.d.ts +2 -2
  46. package/lib/gir/signal.js.map +1 -1
  47. package/lib/gir/util.d.ts +3 -3
  48. package/lib/gir/util.js +17 -14
  49. package/lib/gir/util.js.map +1 -1
  50. package/lib/gir-module.d.ts +21 -27
  51. package/lib/gir-module.js +140 -144
  52. package/lib/gir-module.js.map +1 -1
  53. package/lib/gir.d.ts +42 -40
  54. package/lib/gir.js +26 -22
  55. package/lib/gir.js.map +1 -1
  56. package/lib/index.d.ts +0 -1
  57. package/lib/index.js +0 -1
  58. package/lib/index.js.map +1 -1
  59. package/lib/library-version.d.ts +2 -0
  60. package/lib/library-version.js +13 -0
  61. package/lib/library-version.js.map +1 -1
  62. package/lib/logger.d.ts +18 -16
  63. package/lib/logger.js +28 -26
  64. package/lib/logger.js.map +1 -1
  65. package/lib/registry.d.ts +0 -1
  66. package/lib/registry.js +0 -1
  67. package/lib/registry.js.map +1 -1
  68. package/lib/transformation.d.ts +5 -3
  69. package/lib/transformation.js +7 -0
  70. package/lib/transformation.js.map +1 -1
  71. package/lib/types/dependency.d.ts +13 -1
  72. package/lib/types/format.d.ts +1 -0
  73. package/lib/types/format.js +2 -0
  74. package/lib/types/format.js.map +1 -0
  75. package/lib/types/gir-module-resolved-by.d.ts +5 -0
  76. package/lib/types/index.d.ts +7 -2
  77. package/lib/types/index.js +7 -2
  78. package/lib/types/index.js.map +1 -1
  79. package/lib/types/metadata.d.ts +8 -0
  80. package/lib/types/metadata.js +2 -0
  81. package/lib/types/metadata.js.map +1 -0
  82. package/lib/types/options-base.d.ts +4 -0
  83. package/lib/types/options-base.js +2 -0
  84. package/lib/types/options-base.js.map +1 -0
  85. package/lib/types/{generate-config.d.ts → options-generation.d.ts} +2 -3
  86. package/lib/types/options-generation.js +2 -0
  87. package/lib/types/options-generation.js.map +1 -0
  88. package/lib/types/options-load.d.ts +5 -0
  89. package/lib/types/options-load.js +2 -0
  90. package/lib/types/options-load.js.map +1 -0
  91. package/lib/types/options-transform.d.ts +4 -0
  92. package/lib/types/options-transform.js +2 -0
  93. package/lib/types/options-transform.js.map +1 -0
  94. package/lib/types/output-format.d.ts +1 -0
  95. package/lib/types/output-format.js +2 -0
  96. package/lib/types/output-format.js.map +1 -0
  97. package/lib/types/property-case.d.ts +1 -0
  98. package/lib/types/property-case.js +2 -0
  99. package/lib/types/property-case.js.map +1 -0
  100. package/lib/types/template-data.d.ts +2 -2
  101. package/lib/utils.d.ts +8 -1
  102. package/lib/utils.js +58 -13
  103. package/lib/utils.js.map +1 -1
  104. package/lib/validators/interface.js +1 -1
  105. package/lib/validators/interface.js.map +1 -1
  106. package/package.json +8 -7
  107. package/lib/conflict-resolver.d.ts +0 -119
  108. package/lib/conflict-resolver.js +0 -893
  109. package/lib/conflict-resolver.js.map +0 -1
  110. package/lib/generators/dts/gio.d.ts +0 -2
  111. package/lib/generators/dts/gio.js +0 -9
  112. package/lib/generators/dts/gio.js.map +0 -1
  113. package/lib/gir-factory.d.ts +0 -52
  114. package/lib/gir-factory.js +0 -340
  115. package/lib/gir-factory.js.map +0 -1
  116. package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +0 -2
  117. package/lib/injection/callbacks/gjs/Gio-2.0.js +0 -36
  118. package/lib/injection/callbacks/gjs/Gio-2.0.js.map +0 -1
  119. package/lib/injection/callbacks/gjs/index.d.ts +0 -2
  120. package/lib/injection/callbacks/gjs/index.js +0 -3
  121. package/lib/injection/callbacks/gjs/index.js.map +0 -1
  122. package/lib/injection/callbacks/index.d.ts +0 -3
  123. package/lib/injection/callbacks/index.js +0 -3
  124. package/lib/injection/callbacks/index.js.map +0 -1
  125. package/lib/injection/classes/gjs/gio-2.0.d.ts +0 -5
  126. package/lib/injection/classes/gjs/gio-2.0.js +0 -254
  127. package/lib/injection/classes/gjs/gio-2.0.js.map +0 -1
  128. package/lib/injection/classes/gjs/glib-2.0.d.ts +0 -2
  129. package/lib/injection/classes/gjs/glib-2.0.js +0 -225
  130. package/lib/injection/classes/gjs/glib-2.0.js.map +0 -1
  131. package/lib/injection/classes/gjs/gobject-2.0.d.ts +0 -2
  132. package/lib/injection/classes/gjs/gobject-2.0.js +0 -634
  133. package/lib/injection/classes/gjs/gobject-2.0.js.map +0 -1
  134. package/lib/injection/classes/gjs/index.d.ts +0 -2
  135. package/lib/injection/classes/gjs/index.js +0 -5
  136. package/lib/injection/classes/gjs/index.js.map +0 -1
  137. package/lib/injection/classes/glib-2.0.d.ts +0 -2
  138. package/lib/injection/classes/glib-2.0.js +0 -35
  139. package/lib/injection/classes/glib-2.0.js.map +0 -1
  140. package/lib/injection/classes/index.d.ts +0 -3
  141. package/lib/injection/classes/index.js +0 -4
  142. package/lib/injection/classes/index.js.map +0 -1
  143. package/lib/injection/index.d.ts +0 -3
  144. package/lib/injection/index.js +0 -4
  145. package/lib/injection/index.js.map +0 -1
  146. package/lib/injection/injector.d.ts +0 -16
  147. package/lib/injection/injector.js +0 -138
  148. package/lib/injection/injector.js.map +0 -1
  149. package/lib/symtable.d.ts +0 -24
  150. package/lib/symtable.js +0 -63
  151. package/lib/symtable.js.map +0 -1
  152. package/lib/types/conflict-child-element.d.ts +0 -10
  153. package/lib/types/conflict-child-element.js +0 -2
  154. package/lib/types/conflict-child-element.js.map +0 -1
  155. package/lib/types/conflict-grouped-element.d.ts +0 -6
  156. package/lib/types/conflict-grouped-element.js +0 -2
  157. package/lib/types/conflict-grouped-element.js.map +0 -1
  158. package/lib/types/conflict-grouped-elements.d.ts +0 -4
  159. package/lib/types/conflict-grouped-elements.js +0 -2
  160. package/lib/types/conflict-grouped-elements.js.map +0 -1
  161. package/lib/types/generate-config.js +0 -2
  162. package/lib/types/generate-config.js.map +0 -1
  163. package/lib/types/injection-callback.d.ts +0 -16
  164. package/lib/types/injection-callback.js +0 -2
  165. package/lib/types/injection-callback.js.map +0 -1
  166. package/lib/types/injection-class.d.ts +0 -25
  167. package/lib/types/injection-class.js +0 -2
  168. package/lib/types/injection-class.js.map +0 -1
  169. package/lib/types/injection-function.d.ts +0 -7
  170. package/lib/types/injection-function.js +0 -2
  171. package/lib/types/injection-function.js.map +0 -1
  172. package/lib/types/injection-generic-parameter.d.ts +0 -2
  173. package/lib/types/injection-generic-parameter.js +0 -2
  174. package/lib/types/injection-generic-parameter.js.map +0 -1
  175. package/lib/types/injection-instance-parameter.d.ts +0 -2
  176. package/lib/types/injection-instance-parameter.js +0 -2
  177. package/lib/types/injection-instance-parameter.js.map +0 -1
  178. package/lib/types/injection-parameter.d.ts +0 -8
  179. package/lib/types/injection-parameter.js +0 -2
  180. package/lib/types/injection-parameter.js.map +0 -1
  181. package/lib/types/injection-property.d.ts +0 -4
  182. package/lib/types/injection-property.js +0 -2
  183. package/lib/types/injection-property.js.map +0 -1
  184. package/lib/types/injection-type.d.ts +0 -2
  185. package/lib/types/injection-type.js +0 -2
  186. package/lib/types/injection-type.js.map +0 -1
  187. package/lib/types/injection.d.ts +0 -5
  188. package/lib/types/injection.js +0 -2
  189. package/lib/types/injection.js.map +0 -1
  190. package/lib/types/promisify-func.d.ts +0 -7
  191. package/lib/types/promisify-func.js +0 -2
  192. package/lib/types/promisify-func.js.map +0 -1
  193. package/lib/types/sym-table-items.d.ts +0 -4
  194. package/lib/types/sym-table-items.js +0 -2
  195. package/lib/types/sym-table-items.js.map +0 -1
  196. package/lib/types/ts-alias.d.ts +0 -10
  197. package/lib/types/ts-alias.js +0 -2
  198. package/lib/types/ts-alias.js.map +0 -1
  199. package/lib/types/ts-callback-interface.d.ts +0 -10
  200. package/lib/types/ts-callback-interface.js +0 -2
  201. package/lib/types/ts-callback-interface.js.map +0 -1
  202. package/lib/types/ts-callback.d.ts +0 -17
  203. package/lib/types/ts-callback.js +0 -2
  204. package/lib/types/ts-callback.js.map +0 -1
  205. package/lib/types/ts-class.d.ts +0 -85
  206. package/lib/types/ts-class.js +0 -2
  207. package/lib/types/ts-class.js.map +0 -1
  208. package/lib/types/ts-enum.d.ts +0 -12
  209. package/lib/types/ts-enum.js +0 -2
  210. package/lib/types/ts-enum.js.map +0 -1
  211. package/lib/types/ts-function.d.ts +0 -55
  212. package/lib/types/ts-function.js +0 -2
  213. package/lib/types/ts-function.js.map +0 -1
  214. package/lib/types/ts-generic-parameter.d.ts +0 -8
  215. package/lib/types/ts-generic-parameter.js +0 -2
  216. package/lib/types/ts-generic-parameter.js.map +0 -1
  217. package/lib/types/ts-instance-parameter.d.ts +0 -4
  218. package/lib/types/ts-instance-parameter.js +0 -2
  219. package/lib/types/ts-instance-parameter.js.map +0 -1
  220. package/lib/types/ts-member.d.ts +0 -10
  221. package/lib/types/ts-member.js +0 -2
  222. package/lib/types/ts-member.js.map +0 -1
  223. package/lib/types/ts-method.d.ts +0 -5
  224. package/lib/types/ts-method.js +0 -2
  225. package/lib/types/ts-method.js.map +0 -1
  226. package/lib/types/ts-parameter.d.ts +0 -15
  227. package/lib/types/ts-parameter.js +0 -2
  228. package/lib/types/ts-parameter.js.map +0 -1
  229. package/lib/types/ts-property.d.ts +0 -17
  230. package/lib/types/ts-property.js +0 -2
  231. package/lib/types/ts-property.js.map +0 -1
  232. package/lib/types/ts-signal.d.ts +0 -17
  233. package/lib/types/ts-signal.js +0 -2
  234. package/lib/types/ts-signal.js.map +0 -1
  235. package/lib/types/ts-type-name.d.ts +0 -1
  236. package/lib/types/ts-type-name.js +0 -2
  237. package/lib/types/ts-type-name.js.map +0 -1
  238. package/lib/types/ts-type-separator.d.ts +0 -1
  239. package/lib/types/ts-type-separator.js +0 -2
  240. package/lib/types/ts-type-separator.js.map +0 -1
  241. package/lib/types/ts-type.d.ts +0 -26
  242. package/lib/types/ts-type.js +0 -2
  243. package/lib/types/ts-type.js.map +0 -1
  244. package/lib/types/ts-var.d.ts +0 -17
  245. package/lib/types/ts-var.js +0 -2
  246. package/lib/types/ts-var.js.map +0 -1
  247. package/lib/types.d.ts +0 -23
  248. package/lib/types.js +0 -2
  249. package/lib/types.js.map +0 -1
@@ -1,9 +1,8 @@
1
1
  import { Transformation } from './transformation.js';
2
2
  import { Logger } from './logger.js';
3
3
  import { DependencyManager } from './dependency-manager.js';
4
- import { SymTable } from './symtable.js';
5
4
  import { LibraryVersion } from './library-version.js';
6
- import type { Dependency, GirRepository, GirConstantElement, TsDocTag, ParsedGir, GirInfoAttrs, GenerateConfig } from './types/index.js';
5
+ import type { Dependency, GirConstantElement, TsDocTag, GirInfoAttrs, OptionsGeneration } from './types/index.js';
7
6
  import { GirNSMember } from './gir.js';
8
7
  import { IntrospectedAlias } from './gir/alias.js';
9
8
  import { IntrospectedNamespaceMember } from './gir/base.js';
@@ -13,39 +12,37 @@ import { IntrospectedFunction, IntrospectedFunctionParameter, IntrospectedClassF
13
12
  import { NSRegistry } from './gir/registry.js';
14
13
  import { GirVisitor } from './visitor.js';
15
14
  export declare class GirModule {
15
+ readonly dependency: Dependency;
16
16
  /**
17
17
  * E.g. 'Gtk'
18
18
  */
19
- namespace: string;
19
+ get namespace(): string;
20
20
  /**
21
21
  * E.g. '4.0'
22
22
  */
23
- version: string;
23
+ get version(): string;
24
24
  /**
25
25
  * E.g. 'Gtk-4.0'
26
26
  */
27
- packageName: string;
27
+ get packageName(): string;
28
28
  /**
29
29
  * E.g. 'Gtk40'
30
30
  * Is used in the generated index.d.ts, for example: `import * as Gtk40 from "./Gtk-4.0.js";`
31
31
  */
32
- importNamespace: string;
33
- importName: string;
32
+ get importNamespace(): string;
33
+ get importName(): string;
34
+ get importPath(): string;
34
35
  prefixes: string[];
35
36
  /**
36
37
  * The version of the library as an object.
37
38
  * E.g. `{ major: 4, minor: 0, patch: 0 }` or as string `4.0.0`'
38
39
  */
39
- libraryVersion: LibraryVersion;
40
- dependencies: Dependency[];
41
- private _transitiveDependencies;
42
- set transitiveDependencies(deps: Dependency[]);
40
+ get libraryVersion(): LibraryVersion;
41
+ protected _dependencies: Dependency[] | null;
42
+ protected _transitiveDependencies: Dependency[] | null;
43
+ get dependencies(): Dependency[];
43
44
  get transitiveDependencies(): Dependency[];
44
45
  get allDependencies(): Dependency[];
45
- /**
46
- * Used to find namespaces that are used in other modules
47
- */
48
- symTable: SymTable;
49
46
  transformation: Transformation;
50
47
  dependencyManager: DependencyManager;
51
48
  log: Logger;
@@ -57,7 +54,6 @@ export declare class GirModule {
57
54
  constNames: {
58
55
  [varName: string]: GirConstantElement;
59
56
  };
60
- readonly name: string;
61
57
  readonly c_prefixes: string[];
62
58
  private _members?;
63
59
  private _enum_constants?;
@@ -65,12 +61,12 @@ export declare class GirModule {
65
61
  __dts__references?: string[];
66
62
  package_version: readonly [string, string] | readonly [string, string, string];
67
63
  parent: NSRegistry;
68
- config: GenerateConfig;
69
- constructor(repo: GirRepository, name: string, version: string, prefixes: string[], config: GenerateConfig);
64
+ config: OptionsGeneration;
65
+ constructor(dependency: Dependency, prefixes: string[], config: OptionsGeneration);
66
+ initDependencies(): Promise<void>;
67
+ initTransitiveDependencies(transitiveDependencies: Dependency[]): Promise<void>;
70
68
  get ns(): this;
71
69
  private checkTransitiveDependencies;
72
- private getTsDoc;
73
- private getTsDocGirElementTags;
74
70
  getTsDocReturnTags(girElement?: IntrospectedFunction | IntrospectedClassFunction): TsDocTag[];
75
71
  getTsDocInParamTags(inParams?: IntrospectedFunctionParameter[]): TsDocTag[];
76
72
  registerResolveName(resolveName: string, namespace: string, name: string): void;
@@ -80,8 +76,8 @@ export declare class GirModule {
80
76
  getImportsForCPrefix(c_prefix: string): GirModule[];
81
77
  hasImport(name: string): boolean;
82
78
  private _getImport;
83
- getInstalledImport(name: string): GirModule | null;
84
- assertInstalledImport(name: string): GirModule;
79
+ getInstalledImport(_namespace: string): GirModule | null;
80
+ assertInstalledImport(_namespace: string): GirModule;
85
81
  getMembers(name: string): IntrospectedNamespaceMember[];
86
82
  getMemberWithoutOverrides(name: string): GirNSMember | null | undefined;
87
83
  assertClass(name: string): IntrospectedBaseClass;
@@ -97,11 +93,9 @@ export declare class GirModule {
97
93
  * libraries that are newer than default.
98
94
  */
99
95
  ___dts___addReference(reference: string): void;
100
- static load(repo: ParsedGir, config: GenerateConfig, registry: NSRegistry): GirModule;
101
- /**
102
- * Start processing the typescript data
103
- */
104
- start(girModules: GirModule[]): void;
96
+ static load(dependency: Dependency, config: OptionsGeneration, registry: NSRegistry): Promise<GirModule>;
97
+ /** Start to parse all the data from the XML we need for the typescript generation */
98
+ parse(): void;
105
99
  }
106
100
  export declare const isIntrospectable: (e: {
107
101
  $?: GirInfoAttrs;
package/lib/gir-module.js CHANGED
@@ -1,11 +1,9 @@
1
1
  // TODO move this class into a web-worker? https://www.npmjs.com/package/web-worker
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
- import { IGNORE_GIR_TYPE_TS_DOC_TYPES, Transformation } from './transformation.js';
3
+ import { Transformation } from './transformation.js';
4
4
  import { Logger } from './logger.js';
5
5
  import { DependencyManager } from './dependency-manager.js';
6
6
  import { find } from './utils.js';
7
- import { SymTable } from './symtable.js';
8
- import { LibraryVersion } from './library-version.js';
9
7
  import { ClosureType, TypeIdentifier, PromiseType, VoidType, BooleanType, TupleType, BinaryType, NullableType, ObjectType, } from './gir.js';
10
8
  import { IntrospectedAlias } from './gir/alias.js';
11
9
  import { IntrospectedBase } from './gir/base.js';
@@ -15,45 +13,73 @@ import { IntrospectedEnum, IntrospectedError } from './gir/enum.js';
15
13
  import { IntrospectedFunction, IntrospectedCallback, } from './gir/function.js';
16
14
  import { isPrimitiveType } from './gir/util.js';
17
15
  export class GirModule {
16
+ dependency;
18
17
  /**
19
18
  * E.g. 'Gtk'
20
19
  */
21
- namespace;
20
+ get namespace() {
21
+ return this.dependency.namespace;
22
+ }
22
23
  /**
23
24
  * E.g. '4.0'
24
25
  */
25
- version;
26
+ get version() {
27
+ return this.dependency.version;
28
+ }
26
29
  /**
27
30
  * E.g. 'Gtk-4.0'
28
31
  */
29
- packageName;
32
+ get packageName() {
33
+ return this.dependency.packageName;
34
+ }
30
35
  /**
31
36
  * E.g. 'Gtk40'
32
37
  * Is used in the generated index.d.ts, for example: `import * as Gtk40 from "./Gtk-4.0.js";`
33
38
  */
34
- importNamespace;
35
- importName;
39
+ get importNamespace() {
40
+ return this.dependency.importNamespace;
41
+ }
42
+ get importName() {
43
+ return this.dependency.importName;
44
+ }
45
+ get importPath() {
46
+ return this.dependency.importPath;
47
+ }
36
48
  prefixes = [];
37
49
  /**
38
50
  * The version of the library as an object.
39
51
  * E.g. `{ major: 4, minor: 0, patch: 0 }` or as string `4.0.0`'
40
52
  */
41
- libraryVersion;
42
- dependencies = [];
43
- _transitiveDependencies = [];
44
- set transitiveDependencies(deps) {
45
- this._transitiveDependencies = this.checkTransitiveDependencies(deps);
53
+ get libraryVersion() {
54
+ // GObject and Gio are following the version of GLib
55
+ if (this.namespace === 'GObject' || this.namespace === 'Gio') {
56
+ const dep = this.allDependencies.find((girModule) => girModule.namespace === 'GLib');
57
+ if (dep) {
58
+ return dep.libraryVersion;
59
+ }
60
+ }
61
+ return this.dependency.libraryVersion;
62
+ }
63
+ _dependencies = null;
64
+ _transitiveDependencies = null;
65
+ get dependencies() {
66
+ if (!this._dependencies) {
67
+ throw new Error('dependencies is not initialized, run initDependencies() first');
68
+ }
69
+ return this._dependencies;
46
70
  }
47
71
  get transitiveDependencies() {
72
+ if (!this._transitiveDependencies) {
73
+ throw new Error('transitiveDependencies is not initialized, run initTransitiveDependencies() first');
74
+ }
48
75
  return this._transitiveDependencies;
49
76
  }
50
77
  get allDependencies() {
78
+ if (!this.dependencies) {
79
+ throw new Error('dependencies is not initialized, run init() first');
80
+ }
51
81
  return [...new Set([...this.dependencies, ...this.transitiveDependencies])];
52
82
  }
53
- /**
54
- * Used to find namespaces that are used in other modules
55
- */
56
- symTable;
57
83
  transformation;
58
84
  dependencyManager;
59
85
  log;
@@ -63,7 +89,6 @@ export class GirModule {
63
89
  * Please note: Such a case is only known for Zeitgeist-2.0 with the constant "ATTACHMENT"
64
90
  */
65
91
  constNames = {};
66
- name;
67
92
  c_prefixes;
68
93
  _members;
69
94
  _enum_constants;
@@ -72,68 +97,48 @@ export class GirModule {
72
97
  package_version;
73
98
  parent;
74
99
  config;
75
- constructor(repo, name, version, prefixes, config) {
76
- this.name = name;
77
- this.version = version;
100
+ constructor(dependency, prefixes, config) {
101
+ this.dependency = dependency;
78
102
  this.c_prefixes = [...prefixes];
79
103
  this.package_version = ['0', '0'];
80
104
  this.config = config;
105
+ // TODO: Make this a singleton
81
106
  this.dependencyManager = DependencyManager.getInstance(this.config);
82
- this.dependencies = this.dependencyManager.fromGirIncludes(repo.include || []);
107
+ }
108
+ async initDependencies() {
109
+ this._dependencies = await this.dependencyManager.fromGirIncludes(this.dependency.girXML?.repository[0]?.include || []);
110
+ }
111
+ async initTransitiveDependencies(transitiveDependencies) {
112
+ this._transitiveDependencies = await this.checkTransitiveDependencies(transitiveDependencies);
83
113
  }
84
114
  get ns() {
85
115
  return this;
86
116
  }
87
- checkTransitiveDependencies(transitiveDependencies) {
117
+ async checkTransitiveDependencies(transitiveDependencies) {
88
118
  // Always pull in GObject-2.0, as we may need it for e.g. GObject-2.0.type
89
119
  if (this.packageName !== 'GObject-2.0') {
90
120
  if (!find(transitiveDependencies, (x) => x.packageName === 'GObject-2.0')) {
91
- transitiveDependencies.push(this.dependencyManager.get('GObject', '2.0'));
121
+ transitiveDependencies.push(await this.dependencyManager.get('GObject', '2.0'));
92
122
  }
93
123
  }
94
124
  // Add missing dependencies
95
125
  if (this.packageName === 'UnityExtras-7.0') {
96
126
  if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-7.0')) {
97
- transitiveDependencies.push(this.dependencyManager.get('Unity', '7.0'));
127
+ transitiveDependencies.push(await this.dependencyManager.get('Unity', '7.0'));
98
128
  }
99
129
  }
100
130
  if (this.packageName === 'UnityExtras-6.0') {
101
131
  if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-6.0')) {
102
- transitiveDependencies.push(this.dependencyManager.get('Unity', '6.0'));
132
+ transitiveDependencies.push(await this.dependencyManager.get('Unity', '6.0'));
103
133
  }
104
134
  }
105
135
  if (this.packageName === 'GTop-2.0') {
106
136
  if (!find(transitiveDependencies, (x) => x.packageName === 'GLib-2.0')) {
107
- transitiveDependencies.push(this.dependencyManager.get('GLib', '2.0'));
137
+ transitiveDependencies.push(await this.dependencyManager.get('GLib', '2.0'));
108
138
  }
109
139
  }
110
140
  return transitiveDependencies;
111
141
  }
112
- getTsDoc(girDoc) {
113
- const tsDoc = {
114
- text: '',
115
- tags: [],
116
- };
117
- if (girDoc.doc?.[0]?._) {
118
- // TODO: Somehow _ is not a string
119
- let text = `${girDoc.doc?.[0]?._ || ''}`;
120
- text = this.transformation.transformGirDocText(text);
121
- tsDoc.text = text;
122
- }
123
- return tsDoc;
124
- }
125
- getTsDocGirElementTags(tsTypeName, girTypeName) {
126
- const tags = [];
127
- if (!girTypeName || IGNORE_GIR_TYPE_TS_DOC_TYPES.includes(girTypeName)) {
128
- return tags;
129
- }
130
- tags.push({
131
- tagName: girTypeName,
132
- paramName: '',
133
- text: '',
134
- });
135
- return tags;
136
- }
137
142
  getTsDocReturnTags(girElement) {
138
143
  const girReturnValue = girElement?.returnTypeDoc;
139
144
  if (!girReturnValue) {
@@ -200,58 +205,58 @@ export class GirModule {
200
205
  hasImport(name) {
201
206
  return this.dependencies.some((dep) => dep.importName === name);
202
207
  }
203
- _getImport(name) {
204
- if (name === this.name) {
208
+ _getImport(namespace) {
209
+ if (namespace === this.namespace) {
205
210
  return this;
206
211
  }
207
- const dep = this.dependencies.find((dep) => dep.namespace === name) ??
208
- this.transitiveDependencies.find((dep) => dep.namespace === name);
212
+ const dep = this.dependencies?.find((dep) => dep.namespace === namespace) ??
213
+ this.transitiveDependencies.find((dep) => dep.namespace === namespace);
209
214
  // Handle finding imports via their other prefixes
210
215
  if (!dep) {
211
- this.log.info(`Failed to find namespace ${name} in dependencies, resolving via c:prefixes`);
216
+ this.log.info(`Failed to find namespace ${namespace} in dependencies, resolving via c:prefixes`);
212
217
  // TODO: It might make more sense to move this conversion _before_
213
218
  // the _getImport call.
214
- const resolvedNamespaces = this.dependencyManager.namespacesForPrefix(name);
219
+ const resolvedNamespaces = this.dependencyManager.namespacesForPrefix(namespace);
215
220
  if (resolvedNamespaces.length > 0) {
216
- this.log.info(`Found namespaces for prefix ${name}: ${resolvedNamespaces.map((r) => `${r.name} (${r.version})`).join(', ')}`);
221
+ this.log.info(`Found namespaces for prefix ${namespace}: ${resolvedNamespaces.map((r) => `${r.namespace} (${r.version})`).join(', ')}`);
217
222
  }
218
223
  for (const resolvedNamespace of resolvedNamespaces) {
219
- if (resolvedNamespace.name === this.name && resolvedNamespace.version === this.version) {
224
+ if (resolvedNamespace.namespace === this.namespace && resolvedNamespace.version === this.version) {
220
225
  return this;
221
226
  }
222
- const dep = this.dependencies.find((dep) => dep.namespace === resolvedNamespace.name && dep.version === resolvedNamespace.version) ??
223
- this.transitiveDependencies.find((dep) => dep.namespace === resolvedNamespace.name && dep.version === resolvedNamespace.version);
227
+ const dep = this.dependencies?.find((dep) => dep.namespace === resolvedNamespace.namespace && dep.version === resolvedNamespace.version) ??
228
+ this.transitiveDependencies.find((dep) => dep.namespace === resolvedNamespace.namespace && dep.version === resolvedNamespace.version);
224
229
  if (dep) {
225
- return this.parent.namespace(resolvedNamespace.name, dep.version);
230
+ return this.parent.namespace(resolvedNamespace.namespace, dep.version);
226
231
  }
227
232
  }
228
233
  }
229
234
  let version = dep?.version;
230
235
  if (!version) {
231
- version = this.parent.assertDefaultVersionOf(name);
236
+ version = this.parent.assertDefaultVersionOf(namespace);
232
237
  }
233
- return this.parent.namespace(name, version);
238
+ return this.parent.namespace(namespace, version);
234
239
  }
235
- getInstalledImport(name) {
236
- if (name === this.name) {
240
+ getInstalledImport(_namespace) {
241
+ if (_namespace === this.namespace) {
237
242
  return this;
238
243
  }
239
- const dep = this.dependencies.find((dep) => dep.namespace === name) ??
240
- this.transitiveDependencies.find((dep) => dep.namespace === name);
244
+ const dep = this.dependencies?.find((dep) => dep.namespace === _namespace) ??
245
+ this.transitiveDependencies.find((dep) => dep.namespace === _namespace);
241
246
  let version = dep?.version;
242
247
  if (!version) {
243
- version = this.parent.defaultVersionOf(name) ?? undefined;
248
+ version = this.parent.defaultVersionOf(_namespace) ?? undefined;
244
249
  }
245
250
  if (!version) {
246
251
  return null;
247
252
  }
248
- const namespace = this.parent.namespace(name, version);
253
+ const namespace = this.parent.namespace(_namespace, version);
249
254
  return namespace;
250
255
  }
251
- assertInstalledImport(name) {
252
- const namespace = this._getImport(name);
256
+ assertInstalledImport(_namespace) {
257
+ const namespace = this._getImport(_namespace);
253
258
  if (!namespace) {
254
- throw new Error(`Failed to import ${name} in ${this.name}, not installed or accessible.`);
259
+ throw new Error(`Failed to import ${_namespace} in ${this.namespace}, not installed or accessible.`);
255
260
  }
256
261
  return namespace;
257
262
  }
@@ -282,7 +287,7 @@ export class GirModule {
282
287
  assertClass(name) {
283
288
  const clazz = this.getClass(name);
284
289
  if (!clazz) {
285
- throw new Error(`Class ${name} does not exist in namespace ${this.name}.`);
290
+ throw new Error(`Class ${name} does not exist in namespace ${this.namespace}.`);
286
291
  }
287
292
  return clazz;
288
293
  }
@@ -342,22 +347,17 @@ export class GirModule {
342
347
  this.__dts__references ??= [];
343
348
  this.__dts__references.push(reference);
344
349
  }
345
- static load(repo, config, registry) {
346
- const ns = repo.repository[0]?.namespace?.[0];
347
- if (!ns)
348
- throw new Error(`Missing namespace in ${repo.repository[0].package[0].$.name}`);
350
+ static async load(dependency, config, registry) {
351
+ const girXML = dependency.girXML;
352
+ const ns = girXML?.repository[0]?.namespace?.[0];
353
+ if (!girXML) {
354
+ throw new Error(`Failed to load gir xml of ${dependency.packageName}`);
355
+ }
356
+ if (!ns) {
357
+ throw new Error(`Missing namespace in ${girXML.repository[0].package[0].$.name}`);
358
+ }
349
359
  const modName = ns.$['name'];
350
360
  const version = ns.$['version'];
351
- // TODO: Hardcoding HarfBuzz here leads to issues when loading...
352
- // Hardcode harfbuzz version for now...
353
- // if (modName === 'HarfBuzz' && version === '0.0') {
354
- // version = '2.0'
355
- // }
356
- const options = {
357
- loadDocs: !config.noComments,
358
- propertyCase: 'both',
359
- verbose: config.verbose,
360
- };
361
361
  if (!modName) {
362
362
  throw new Error('Invalid GIR file: no namespace name specified.');
363
363
  }
@@ -365,112 +365,130 @@ export class GirModule {
365
365
  throw new Error('Invalid GIR file: no version name specified.');
366
366
  }
367
367
  const c_prefix = ns.$?.['c:identifier-prefixes']?.split(',') ?? [];
368
- if (options.verbose) {
369
- console.debug(`Parsing ${modName}...`);
370
- }
371
- const building = new GirModule(repo.repository[0], modName, version, c_prefix, config);
368
+ const building = new GirModule(dependency, c_prefix, config);
369
+ await building.initDependencies();
372
370
  building.parent = registry;
373
371
  // Set the namespace object here to prevent re-parsing the namespace if
374
372
  // another namespace imports it.
375
373
  registry.register(building);
376
- const prefixes = repo.repository[0]?.$?.['c:identifier-prefixes']?.split(',');
374
+ const prefixes = girXML.repository[0]?.$?.['c:identifier-prefixes']?.split(',');
377
375
  const unknownPrefixes = prefixes?.filter((pre) => pre !== modName);
378
376
  if (unknownPrefixes && unknownPrefixes.length > 0) {
379
- console.log(`Found additional prefixes for ${modName}: ${unknownPrefixes.join(', ')}`);
377
+ Logger.log(`Found additional prefixes for ${modName}: ${unknownPrefixes.join(', ')}`);
380
378
  building.prefixes.push(...unknownPrefixes);
381
379
  }
380
+ building.transformation = Transformation.getSingleton(config);
381
+ building.log = new Logger(config.verbose, `GirModule(${building.packageName})`);
382
+ return building;
383
+ }
384
+ /** Start to parse all the data from the XML we need for the typescript generation */
385
+ parse() {
386
+ this.log.debug(`Parsing ${this.dependency.packageName}...`);
387
+ const girXML = this.dependency.girXML;
388
+ const ns = girXML?.repository[0]?.namespace?.[0];
389
+ const options = {
390
+ loadDocs: !this.config.noComments,
391
+ propertyCase: 'both',
392
+ verbose: this.config.verbose,
393
+ };
394
+ if (!girXML) {
395
+ throw new Error(`Failed to load gir xml of ${this.dependency.packageName}`);
396
+ }
397
+ if (!ns) {
398
+ throw new Error(`Missing namespace in ${girXML.repository[0].package[0].$.name}`);
399
+ }
382
400
  const importConflicts = (el) => {
383
- return !building.hasImport(el.name);
401
+ return !this.hasImport(el.name);
384
402
  };
385
403
  if (ns.enumeration) {
386
404
  // Get the requested enums
387
405
  ns.enumeration
388
406
  ?.map((enumeration) => {
389
407
  if (enumeration.$['glib:error-domain']) {
390
- return IntrospectedError.fromXML(enumeration, building, options);
408
+ return IntrospectedError.fromXML(enumeration, this, options);
391
409
  }
392
410
  else {
393
- return IntrospectedEnum.fromXML(enumeration, building, options);
411
+ return IntrospectedEnum.fromXML(enumeration, this, options);
394
412
  }
395
413
  })
396
- .forEach((c) => building.members.set(c.name, c));
414
+ .forEach((c) => this.members.set(c.name, c));
397
415
  }
398
416
  // Constants
399
417
  if (ns.constant) {
400
418
  ns.constant
401
419
  ?.filter(isIntrospectable)
402
- .map((constant) => IntrospectedConstant.fromXML(constant, building, options))
420
+ .map((constant) => IntrospectedConstant.fromXML(constant, this, options))
403
421
  .filter(importConflicts)
404
- .forEach((c) => building.members.set(c.name, c));
422
+ .forEach((c) => this.members.set(c.name, c));
405
423
  }
406
424
  // Get the requested functions
407
425
  if (ns.function) {
408
426
  ns.function
409
427
  ?.filter(isIntrospectable)
410
- .map((func) => IntrospectedFunction.fromXML(func, building, options))
428
+ .map((func) => IntrospectedFunction.fromXML(func, this, options))
411
429
  .filter(importConflicts)
412
- .forEach((c) => building.members.set(c.name, c));
430
+ .forEach((c) => this.members.set(c.name, c));
413
431
  }
414
432
  if (ns.callback) {
415
433
  ns.callback
416
434
  ?.filter(isIntrospectable)
417
- .map((callback) => IntrospectedCallback.fromXML(callback, building, options))
435
+ .map((callback) => IntrospectedCallback.fromXML(callback, this, options))
418
436
  .filter(importConflicts)
419
- .forEach((c) => building.members.set(c.name, c));
437
+ .forEach((c) => this.members.set(c.name, c));
420
438
  }
421
439
  if (ns['glib:boxed']) {
422
440
  ns['glib:boxed']
423
441
  ?.filter(isIntrospectable)
424
442
  .map((boxed) => new IntrospectedAlias({
425
443
  name: boxed.$['glib:name'],
426
- namespace: building,
444
+ namespace: this,
427
445
  type: new NullableType(ObjectType),
428
446
  }))
429
- .forEach((c) => building.members.set(c.name, c));
447
+ .forEach((c) => this.members.set(c.name, c));
430
448
  }
431
449
  // Bitfield is a type of enum
432
450
  if (ns.bitfield) {
433
451
  ns.bitfield
434
452
  ?.filter(isIntrospectable)
435
- .map((field) => IntrospectedEnum.fromXML(field, building, options, true))
436
- .forEach((c) => building.members.set(c.name, c));
453
+ .map((field) => IntrospectedEnum.fromXML(field, this, options, true))
454
+ .forEach((c) => this.members.set(c.name, c));
437
455
  }
438
456
  // The `enum_constants` map maps the C identifiers (GTK_BUTTON_TYPE_Y)
439
457
  // to the name of the enum (Button) to resolve references (Gtk.Button.Y)
440
- Array.from(building.members.values())
458
+ Array.from(this.members.values())
441
459
  .filter((m) => m instanceof IntrospectedEnum)
442
460
  .forEach((m) => {
443
461
  m.members.forEach((member) => {
444
- building.enum_constants.set(member.c_identifier, [m.name, member.name]);
462
+ this.enum_constants.set(member.c_identifier, [m.name, member.name]);
445
463
  });
446
464
  });
447
465
  // Get the requested classes
448
466
  if (ns.class) {
449
467
  ns.class
450
468
  ?.filter(isIntrospectable)
451
- .map((klass) => IntrospectedClass.fromXML(klass, building, options))
469
+ .map((klass) => IntrospectedClass.fromXML(klass, this, options))
452
470
  .filter(importConflicts)
453
- .forEach((c) => building.members.set(c.name, c));
471
+ .forEach((c) => this.members.set(c.name, c));
454
472
  }
455
473
  if (ns.record) {
456
474
  ns.record
457
475
  ?.filter(isIntrospectable)
458
- .map((record) => IntrospectedRecord.fromXML(record, building, options))
476
+ .map((record) => IntrospectedRecord.fromXML(record, this, options))
459
477
  .filter(importConflicts)
460
- .forEach((c) => building.members.set(c.name, c));
478
+ .forEach((c) => this.members.set(c.name, c));
461
479
  }
462
480
  if (ns.union) {
463
481
  ns.union
464
482
  ?.filter(isIntrospectable)
465
- .map((union) => IntrospectedRecord.fromXML(union, building, options))
483
+ .map((union) => IntrospectedRecord.fromXML(union, this, options))
466
484
  .filter(importConflicts)
467
- .forEach((c) => building.members.set(c.name, c));
485
+ .forEach((c) => this.members.set(c.name, c));
468
486
  }
469
487
  if (ns.interface) {
470
488
  ns.interface
471
- ?.map((inter) => IntrospectedInterface.fromXML(inter, building, options))
489
+ ?.map((inter) => IntrospectedInterface.fromXML(inter, this, options))
472
490
  .filter(importConflicts)
473
- .forEach((c) => building.members.set(c.name, c));
491
+ .forEach((c) => this.members.set(c.name, c));
474
492
  }
475
493
  if (ns.alias) {
476
494
  ns.alias
@@ -481,7 +499,7 @@ export class GirModule {
481
499
  ?.filter((t) => !!(t && t.$.name))
482
500
  .map((t) => {
483
501
  if (t.$.name &&
484
- !building.hasSymbol(t.$.name) &&
502
+ !this.hasSymbol(t.$.name) &&
485
503
  !isPrimitiveType(t.$.name) &&
486
504
  !t.$.name.includes('.')) {
487
505
  return { $: { name: 'unknown', 'c:type': 'unknown' } };
@@ -490,31 +508,9 @@ export class GirModule {
490
508
  });
491
509
  return b;
492
510
  })
493
- .map((alias) => IntrospectedAlias.fromXML(alias, building, options))
511
+ .map((alias) => IntrospectedAlias.fromXML(alias, this, options))
494
512
  .filter((alias) => alias != null)
495
- .forEach((c) => building.members.set(c.name, c));
496
- }
497
- building.namespace = building.ns.name;
498
- building.version = building.ns.version;
499
- building.packageName = `${building.namespace}-${building.version}`;
500
- building.libraryVersion = new LibraryVersion(ns.constant, building.version);
501
- building.transformation = new Transformation(config);
502
- building.log = new Logger(config.verbose, building.packageName || 'GirModule');
503
- building.importNamespace = building.transformation.transformModuleNamespaceName(building.packageName);
504
- building.importName = building.transformation.transformImportName(building.packageName);
505
- building.symTable = new SymTable(building.config, building.packageName, building.namespace);
506
- return building;
507
- }
508
- /**
509
- * Start processing the typescript data
510
- */
511
- start(girModules) {
512
- // GObject and Gio are following the version of GLib
513
- if (this.namespace === 'GObject' || this.namespace === 'Gio') {
514
- const glibModule = girModules.find((girModule) => girModule.namespace === 'GLib');
515
- if (glibModule) {
516
- this.libraryVersion = glibModule.libraryVersion;
517
- }
513
+ .forEach((c) => this.members.set(c.name, c));
518
514
  }
519
515
  }
520
516
  }