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

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