@ts-for-gir/cli 3.0.0-beta.8 → 3.0.0-beta.9

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 (157) hide show
  1. package/README.md +318 -63
  2. package/lib/commands/generate.d.ts +3 -5
  3. package/lib/commands/generate.js +2 -3
  4. package/lib/commands/generate.js.map +1 -1
  5. package/lib/config.d.ts +4 -6
  6. package/lib/config.js +55 -51
  7. package/lib/config.js.map +1 -1
  8. package/lib/constants.d.ts +1 -1
  9. package/lib/constants.js +1 -1
  10. package/lib/constants.js.map +1 -1
  11. package/lib/dependency-manager.d.ts +34 -0
  12. package/lib/dependency-manager.js +78 -0
  13. package/lib/dependency-manager.js.map +1 -0
  14. package/lib/generation-handler.js +2 -2
  15. package/lib/generation-handler.js.map +1 -1
  16. package/lib/gir-module.d.ts +7 -6
  17. package/lib/gir-module.js +34 -23
  18. package/lib/gir-module.js.map +1 -1
  19. package/lib/messages.d.ts +4 -3
  20. package/lib/messages.js +4 -3
  21. package/lib/messages.js.map +1 -1
  22. package/lib/module-loader.d.ts +11 -8
  23. package/lib/module-loader.js +53 -50
  24. package/lib/module-loader.js.map +1 -1
  25. package/lib/symtable.d.ts +4 -4
  26. package/lib/symtable.js +1 -1
  27. package/lib/symtable.js.map +1 -1
  28. package/lib/template-processor.d.ts +4 -5
  29. package/lib/template-processor.js +18 -60
  30. package/lib/template-processor.js.map +1 -1
  31. package/lib/type-definition-generator.js +24 -22
  32. package/lib/type-definition-generator.js.map +1 -1
  33. package/lib/types/class-parent.d.ts +2 -0
  34. package/lib/types/dependency-map.d.ts +1 -1
  35. package/lib/types/dependency.d.ts +2 -1
  36. package/lib/types/file-info.d.ts +14 -0
  37. package/lib/types/file-info.js +2 -0
  38. package/lib/types/file-info.js.map +1 -0
  39. package/lib/types/generate-config.d.ts +4 -6
  40. package/lib/types/index.d.ts +1 -0
  41. package/lib/types/index.js +1 -0
  42. package/lib/types/index.js.map +1 -1
  43. package/lib/types/promisify-func.d.ts +5 -0
  44. package/lib/types/promisify-func.js +2 -0
  45. package/lib/types/promisify-func.js.map +1 -0
  46. package/lib/types/user-config.d.ts +4 -6
  47. package/lib/utils.d.ts +195 -6
  48. package/lib/utils.js +199 -17
  49. package/lib/utils.js.map +1 -1
  50. package/package.json +14 -14
  51. package/src/commands/generate.ts +2 -3
  52. package/src/config.ts +62 -52
  53. package/src/constants.ts +1 -1
  54. package/src/dependency-manager.ts +91 -0
  55. package/src/generation-handler.ts +2 -2
  56. package/src/gir-module.ts +43 -32
  57. package/src/messages.ts +4 -3
  58. package/src/module-loader.ts +59 -54
  59. package/src/symtable.ts +8 -6
  60. package/src/template-processor.ts +30 -64
  61. package/src/type-definition-generator.ts +26 -24
  62. package/src/types/class-parent.ts +2 -0
  63. package/src/types/dependency-map.ts +1 -1
  64. package/src/types/dependency.ts +3 -1
  65. package/src/types/file-info.ts +14 -0
  66. package/src/types/generate-config.ts +4 -6
  67. package/src/types/index.ts +1 -0
  68. package/src/types/user-config.ts +4 -6
  69. package/src/utils.ts +201 -18
  70. package/templates/Gjs/Gjs.d.ts +75 -8
  71. package/templates/Gjs/GnomeShell.d.ts +62 -32
  72. package/templates/Gjs/index.d.ts +3 -3
  73. package/templates/Gjs/misc/fileUtils.d.ts +5 -3
  74. package/templates/Gjs/misc/gnomeSession.d.ts +5 -3
  75. package/templates/Gjs/misc/parentalControlsManager.d.ts +42 -0
  76. package/templates/Gjs/misc/parentalControlsManager.js +6 -0
  77. package/templates/Gjs/misc/signals.d.ts +15 -0
  78. package/templates/Gjs/misc/signals.js +6 -0
  79. package/templates/Gjs/module.d.ts +0 -4
  80. package/templates/Gjs/module.js +1 -1
  81. package/templates/Gjs/tsconfig.alias.json +10 -0
  82. package/templates/Gjs/ui/accessDialog.d.ts +19 -0
  83. package/templates/Gjs/ui/accessDialog.js +6 -0
  84. package/templates/Gjs/ui/altTab.d.ts +124 -0
  85. package/templates/Gjs/ui/altTab.js +6 -0
  86. package/templates/Gjs/ui/animation.d.ts +58 -0
  87. package/templates/Gjs/ui/animation.js +6 -0
  88. package/templates/Gjs/ui/appDisplay.d.ts +204 -0
  89. package/templates/Gjs/ui/appDisplay.js +6 -0
  90. package/templates/Gjs/ui/appFavorites.d.ts +34 -0
  91. package/templates/Gjs/ui/appFavorites.js +6 -0
  92. package/templates/Gjs/ui/appMenu.d.ts +74 -0
  93. package/templates/Gjs/ui/appMenu.js +6 -0
  94. package/templates/Gjs/ui/audioDeviceSelection.d.ts +51 -0
  95. package/templates/Gjs/ui/audioDeviceSelection.js +6 -0
  96. package/templates/Gjs/ui/background.d.ts +255 -0
  97. package/templates/Gjs/ui/background.js +5 -0
  98. package/templates/Gjs/ui/backgroundMenu.d.ts +19 -0
  99. package/templates/Gjs/ui/backgroundMenu.js +5 -0
  100. package/templates/Gjs/ui/barLevel.d.ts +42 -0
  101. package/templates/Gjs/ui/barLevel.js +5 -0
  102. package/templates/Gjs/ui/boxpointer.d.ts +103 -0
  103. package/templates/Gjs/ui/boxpointer.js +5 -0
  104. package/templates/Gjs/ui/calendar.d.ts +261 -0
  105. package/templates/Gjs/ui/calendar.js +5 -0
  106. package/templates/Gjs/ui/components/__init__.d.ts +9 -0
  107. package/templates/Gjs/ui/components/__init__.js +6 -0
  108. package/templates/Gjs/ui/components/automountManager.d.ts +8 -0
  109. package/templates/Gjs/ui/components/automountManager.js +6 -0
  110. package/templates/Gjs/ui/components/autorunManager.d.ts +8 -0
  111. package/templates/Gjs/ui/components/autorunManager.js +6 -0
  112. package/templates/Gjs/ui/components/index.d.ts +6 -0
  113. package/templates/Gjs/ui/components/index.js +6 -0
  114. package/templates/Gjs/ui/components/keyring.d.ts +19 -0
  115. package/templates/Gjs/ui/components/keyring.js +6 -0
  116. package/templates/Gjs/ui/components/networkAgent.d.ts +10 -0
  117. package/templates/Gjs/ui/components/networkAgent.js +6 -0
  118. package/templates/Gjs/ui/components/polkitAgent.d.ts +19 -0
  119. package/templates/Gjs/ui/components/polkitAgent.js +6 -0
  120. package/templates/Gjs/ui/components/telepathyClient.d.ts +10 -0
  121. package/templates/Gjs/ui/components/telepathyClient.js +6 -0
  122. package/templates/Gjs/ui/dialog.d.ts +78 -0
  123. package/templates/Gjs/ui/dialog.js +0 -0
  124. package/templates/Gjs/ui/dnd.d.ts +127 -0
  125. package/templates/Gjs/ui/dnd.js +6 -0
  126. package/templates/Gjs/ui/iconGrid.d.ts +172 -0
  127. package/templates/Gjs/ui/iconGrid.js +6 -0
  128. package/templates/Gjs/ui/layout.d.ts +311 -0
  129. package/templates/Gjs/ui/layout.js +6 -0
  130. package/templates/Gjs/ui/main.d.ts +215 -0
  131. package/templates/Gjs/ui/main.js +6 -0
  132. package/templates/Gjs/ui/messageList.d.ts +113 -0
  133. package/templates/Gjs/ui/messageList.js +6 -0
  134. package/templates/Gjs/ui/messageTray.d.ts +423 -0
  135. package/templates/Gjs/ui/messageTray.js +6 -0
  136. package/templates/Gjs/ui/modalDialog.d.ts +96 -0
  137. package/templates/Gjs/ui/modalDialog.js +6 -0
  138. package/templates/Gjs/ui/mpris.d.ts +78 -0
  139. package/templates/Gjs/ui/mpris.js +6 -0
  140. package/templates/Gjs/ui/notificationDaemon.d.ts +5 -0
  141. package/templates/Gjs/ui/notificationDaemon.js +6 -0
  142. package/templates/Gjs/ui/panel.d.ts +65 -0
  143. package/templates/Gjs/ui/panel.js +6 -0
  144. package/templates/Gjs/ui/panelMenu.d.ts +51 -0
  145. package/templates/Gjs/ui/panelMenu.js +6 -0
  146. package/templates/Gjs/ui/popupMenu.d.ts +228 -0
  147. package/templates/Gjs/ui/popupMenu.js +6 -0
  148. package/templates/Gjs/ui/ripples.d.ts +44 -0
  149. package/templates/Gjs/ui/ripples.js +6 -0
  150. package/templates/Gjs/ui/search.d.ts +158 -0
  151. package/templates/Gjs/ui/search.js +6 -0
  152. package/templates/Gjs/ui/switcherPopup.d.ts +107 -0
  153. package/templates/Gjs/ui/switcherPopup.js +6 -0
  154. package/templates/Gjs/ui/userWidget.d.ts +7 -4
  155. package/templates/node-gtk/index.d.ts +3 -3
  156. package/templates/node-gtk/module.d.ts +0 -4
  157. package/templates/node-gtk/module.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/cli",
3
- "version": "3.0.0-beta.8",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "Typescript .d.ts generator from GIR for gjs and node-gtk",
5
5
  "module": "lib/index.js",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "git+https://github.com/sammydre/ts-for-gjs.git"
25
+ "url": "git+https://github.com/gjsify/ts-for-gjs.git"
26
26
  },
27
27
  "author": "Pascal Garber <pascal@artandcode.studio>",
28
28
  "files": [
@@ -33,9 +33,9 @@
33
33
  ],
34
34
  "license": "Apache-2.0",
35
35
  "bugs": {
36
- "url": "https://github.com/sammydre/ts-for-gjs/issues"
36
+ "url": "https://github.com/gjsify/ts-for-gjs/issues"
37
37
  },
38
- "homepage": "https://github.com/sammydre/ts-for-gjs#readme",
38
+ "homepage": "https://github.com/gjsify/ts-for-gjs#readme",
39
39
  "keywords": [
40
40
  "gjs",
41
41
  "typescript",
@@ -54,20 +54,21 @@
54
54
  "@types/change-case": "^2.3.1",
55
55
  "@types/columnify": "^1.5.1",
56
56
  "@types/ejs": "^3.1.1",
57
- "@types/eslint": "8.4.10",
57
+ "@types/eslint": "8.21.0",
58
58
  "@types/inquirer": "^9.0.3",
59
59
  "@types/lodash": "^4.14.191",
60
- "@types/node": "^18.11.18",
60
+ "@types/node": "^18.11.19",
61
61
  "@types/prettier": "^2.7.2",
62
62
  "@types/xml2js": "^0.4.11",
63
- "@types/yargs": "^17.0.19",
64
- "@typescript-eslint/eslint-plugin": "^5.48.2",
65
- "@typescript-eslint/parser": "^5.48.2",
66
- "eslint": "^8.32.0",
63
+ "@types/yargs": "^17.0.22",
64
+ "@typescript-eslint/eslint-plugin": "^5.50.0",
65
+ "@typescript-eslint/parser": "^5.50.0",
66
+ "eslint": "^8.33.0",
67
67
  "eslint-config-prettier": "^8.6.0",
68
68
  "eslint-plugin-prettier": "^4.2.1",
69
- "rimraf": "^4.1.0",
70
- "typescript": "^4.9.4"
69
+ "prettier": "^2.8.3",
70
+ "rimraf": "^4.1.2",
71
+ "typescript": "^4.9.5"
71
72
  },
72
73
  "dependencies": {
73
74
  "colorette": "^2.0.19",
@@ -75,11 +76,10 @@
75
76
  "cosmiconfig": "^8.0.0",
76
77
  "ejs": "^3.1.8",
77
78
  "events": "^3.3.0",
78
- "get-tsconfig": "^4.3.0",
79
+ "get-tsconfig": "^4.4.0",
79
80
  "globby": "^13.1.3",
80
81
  "inquirer": "^9.1.4",
81
82
  "lodash": "^4.17.21",
82
- "prettier": "^2.8.3",
83
83
  "tiny-glob": "^0.2.9",
84
84
  "xml2js": "^0.4.23",
85
85
  "yargs": "^17.6.2"
@@ -24,18 +24,17 @@ const builder = (yargs: Argv) => {
24
24
  .option('ignore', Config.generateOptions.ignore)
25
25
  .option('buildType', Config.generateOptions.buildType)
26
26
  .option('moduleType', Config.generateOptions.moduleType)
27
- .option('pretty', Config.generateOptions.pretty)
28
27
  .option('verbose', Config.generateOptions.verbose)
29
28
  .option('ignoreVersionConflicts', Config.generateOptions.ignoreVersionConflicts)
30
29
  .option('print', Config.generateOptions.print)
31
30
  .option('configName', Config.generateOptions.configName)
32
- .option('useNamespace', Config.generateOptions.useNamespace)
31
+ .option('noNamespace', Config.generateOptions.noNamespace)
33
32
  .option('noComments', Config.generateOptions.noComments)
34
33
  .option('noDebugComments', Config.generateOptions.noDebugComments)
35
- .option('noCheck', Config.generateOptions.noCheck)
36
34
  .option('noDOMLib', Config.generateOptions.noDOMLib)
37
35
  .option('fixConflicts', Config.generateOptions.fixConflicts)
38
36
  .option('gnomeShellTypes', Config.generateOptions.gnomeShellTypes)
37
+ .option('generateAlias', Config.generateOptions.generateAlias)
39
38
  .example(examples)
40
39
  }
41
40
 
package/src/config.ts CHANGED
@@ -9,13 +9,15 @@ import Path from 'path'
9
9
  import OS from 'os'
10
10
  import { merge, isEqual, readTsJsConfig } from './utils.js'
11
11
  import type { Environment, UserConfig, ConfigFlags, UserConfigLoadResult, GenerateConfig } from './types/index.js'
12
- import { promises as fs } from 'fs'
12
+ import { writeFile } from 'fs/promises'
13
13
  import { Logger } from './logger.js'
14
14
  import { APP_NAME, APP_USAGE } from './constants.js'
15
15
  import {
16
- WARN_USE_NAMESPACE_ON_TYPES,
17
- WARN_USE_NAMESPACE_ON_ESM,
16
+ WARN_NO_NAMESPACE_ON_TYPES,
17
+ WARN_NO_NAMESPACE_ON_ESM,
18
18
  ERROR_CONFIG_EXTENSION_UNSUPPORTED,
19
+ WARN_USE_ESM_FOR_ALIAS,
20
+ WARN_USE_GJS_FOR_ALIAS,
19
21
  } from './messages.js'
20
22
 
21
23
  export class Config {
@@ -27,8 +29,7 @@ export class Config {
27
29
  * Default cli flag and argument values
28
30
  */
29
31
  static defaults = {
30
- environments: ['gjs', 'node'],
31
- pretty: false,
32
+ environments: ['gjs'],
32
33
  print: false,
33
34
  configName: '.ts-for-girrc.js',
34
35
  outdir: './@types',
@@ -37,15 +38,15 @@ export class Config {
37
38
  ignore: [],
38
39
  verbose: false,
39
40
  ignoreVersionConflicts: false,
40
- useNamespace: false,
41
+ noNamespace: false,
41
42
  buildType: 'lib',
42
- moduleType: 'commonjs',
43
+ moduleType: 'esm',
43
44
  noComments: false,
44
45
  noDebugComments: false,
45
- noCheck: false,
46
46
  fixConflicts: true,
47
47
  noDOMLib: false,
48
48
  gnomeShellTypes: false,
49
+ generateAlias: false,
49
50
  }
50
51
 
51
52
  static configFilePath = Path.join(process.cwd(), Config.defaults.configName)
@@ -109,12 +110,6 @@ export class Config {
109
110
  default: Config.defaults.moduleType,
110
111
  normalize: true,
111
112
  },
112
- pretty: {
113
- type: 'boolean',
114
- description: 'Prettifies the generated .d.ts files',
115
- default: Config.defaults.pretty,
116
- normalize: true,
117
- },
118
113
  verbose: {
119
114
  type: 'boolean',
120
115
  alias: 'v',
@@ -141,11 +136,11 @@ export class Config {
141
136
  default: Config.defaults.configName,
142
137
  normalize: true,
143
138
  },
144
- useNamespace: {
139
+ noNamespace: {
145
140
  type: 'boolean',
146
141
  alias: 'd',
147
- description: 'Export all symbols for each module as a namespace',
148
- default: Config.defaults.useNamespace,
142
+ description: 'Do not export all symbols for each module as a namespace',
143
+ default: Config.defaults.noNamespace,
149
144
  normalize: true,
150
145
  },
151
146
  noComments: {
@@ -161,12 +156,6 @@ export class Config {
161
156
  default: Config.defaults.noDebugComments,
162
157
  normalize: true,
163
158
  },
164
- noCheck: {
165
- type: 'boolean',
166
- description: 'Disable typescript semantic checks using @ts-nocheck',
167
- default: Config.defaults.noCheck,
168
- normalize: true,
169
- },
170
159
  fixConflicts: {
171
160
  type: 'boolean',
172
161
  description: 'Fix Inheritance and implementation type conflicts',
@@ -181,10 +170,17 @@ export class Config {
181
170
  },
182
171
  gnomeShellTypes: {
183
172
  type: 'boolean',
184
- description: 'Generate types for GNOME Shell',
173
+ description: 'Generate types for GNOME Shell (Experimental)',
185
174
  default: Config.defaults.gnomeShellTypes,
186
175
  normalize: true,
187
176
  },
177
+ generateAlias: {
178
+ type: 'boolean',
179
+ alias: 'a',
180
+ description: 'Generate an alias tsconfig file to support GJS ESM module imports',
181
+ default: Config.defaults.generateAlias,
182
+ normalize: true,
183
+ },
188
184
  }
189
185
 
190
186
  /**
@@ -198,18 +194,17 @@ export class Config {
198
194
  ignore: this.options.ignore,
199
195
  buildType: this.options.buildType,
200
196
  moduleType: this.options.moduleType,
201
- pretty: this.options.pretty,
202
197
  verbose: this.options.verbose,
203
198
  ignoreVersionConflicts: this.options.ignoreVersionConflicts,
204
199
  print: this.options.print,
205
200
  configName: this.options.configName,
206
- useNamespace: this.options.useNamespace,
201
+ noNamespace: this.options.noNamespace,
207
202
  noComments: this.options.noComments,
208
203
  noDebugComments: this.options.noDebugComments,
209
- noCheck: this.options.noCheck,
210
204
  noDOMLib: this.options.noDOMLib,
211
205
  fixConflicts: this.options.fixConflicts,
212
206
  gnomeShellTypes: this.options.gnomeShellTypes,
207
+ generateAlias: this.options.generateAlias,
213
208
  }
214
209
 
215
210
  static listOptions = {
@@ -243,7 +238,7 @@ export class Config {
243
238
  break
244
239
  }
245
240
  if (writeConfigString && path) {
246
- return fs.writeFile(path, writeConfigString)
241
+ return writeFile(path, writeConfigString)
247
242
  }
248
243
  }
249
244
 
@@ -288,17 +283,16 @@ export class Config {
288
283
  environment: environment,
289
284
  girDirectories: config.girDirectories,
290
285
  outdir: config.outdir,
291
- pretty: config.pretty,
292
286
  verbose: config.verbose,
293
287
  buildType: config.buildType,
294
288
  moduleType: config.moduleType,
295
- useNamespace: config.useNamespace,
289
+ noNamespace: config.noNamespace,
296
290
  noComments: config.noComments,
297
291
  noDebugComments: config.noDebugComments,
298
- noCheck: config.noCheck,
299
292
  fixConflicts: config.fixConflicts,
300
293
  noDOMLib: config.noDOMLib,
301
294
  gnomeShellTypes: config.gnomeShellTypes,
295
+ generateAlias: config.generateAlias,
302
296
  }
303
297
  return generateConfig
304
298
  }
@@ -332,16 +326,34 @@ export class Config {
332
326
 
333
327
  public static async validate(config: UserConfig): Promise<UserConfig> {
334
328
  if (config.buildType === 'types') {
335
- if (config.useNamespace !== true) {
336
- Logger.warn(WARN_USE_NAMESPACE_ON_TYPES)
337
- config.useNamespace = true
329
+ if (config.noNamespace !== false) {
330
+ Logger.warn(WARN_NO_NAMESPACE_ON_TYPES)
331
+ config.noNamespace = false
332
+ }
333
+ }
334
+
335
+ if (config.moduleType === 'esm') {
336
+ if (config.noNamespace !== false) {
337
+ Logger.warn(WARN_NO_NAMESPACE_ON_ESM)
338
+ config.noNamespace = false
339
+ }
340
+ }
341
+
342
+ if (config.generateAlias) {
343
+ if (!config.environments.includes('gjs')) {
344
+ Logger.warn(WARN_USE_GJS_FOR_ALIAS)
345
+ config.environments.push('gjs')
346
+ }
347
+ if (config.moduleType !== 'esm') {
348
+ Logger.warn(WARN_USE_ESM_FOR_ALIAS)
349
+ config.moduleType = 'esm'
338
350
  }
339
351
  }
340
352
 
341
353
  if (config.moduleType === 'esm') {
342
- if (config.useNamespace !== true) {
343
- Logger.warn(WARN_USE_NAMESPACE_ON_ESM)
344
- config.useNamespace = true
354
+ if (config.noNamespace !== false) {
355
+ Logger.warn(WARN_NO_NAMESPACE_ON_ESM)
356
+ config.noNamespace = false
345
357
  }
346
358
  }
347
359
 
@@ -364,19 +376,18 @@ export class Config {
364
376
  moduleType: options.moduleType,
365
377
  verbose: options.verbose,
366
378
  ignoreVersionConflicts: options.ignoreVersionConflicts,
367
- pretty: options.pretty,
368
379
  print: options.print,
369
380
  outdir: options.outdir,
370
381
  girDirectories: options.girDirectories,
371
382
  ignore: options.ignore,
372
383
  modules: options.modules,
373
- useNamespace: options.useNamespace,
384
+ noNamespace: options.noNamespace,
374
385
  noComments: options.noComments,
375
386
  noDebugComments: options.noDebugComments,
376
- noCheck: options.noCheck,
377
387
  fixConflicts: options.fixConflicts,
378
388
  noDOMLib: options.noDOMLib,
379
389
  gnomeShellTypes: options.gnomeShellTypes,
390
+ generateAlias: options.generateAlias,
380
391
  }
381
392
 
382
393
  if (configFile) {
@@ -403,10 +414,6 @@ export class Config {
403
414
  ) {
404
415
  config.ignoreVersionConflicts = configFile.ignoreVersionConflicts
405
416
  }
406
- // pretty
407
- if (config.pretty === Config.options.pretty.default && typeof configFile.pretty === 'boolean') {
408
- config.pretty = configFile.pretty
409
- }
410
417
  // print
411
418
  if (config.print === Config.options.print.default && typeof configFile.print === 'boolean') {
412
419
  config.print = configFile.print
@@ -433,12 +440,12 @@ export class Config {
433
440
  ) {
434
441
  config.modules = configFile.modules
435
442
  }
436
- // useNamespace
443
+ // noNamespace
437
444
  if (
438
- config.useNamespace === Config.options.useNamespace.default &&
439
- typeof configFile.useNamespace === 'boolean'
445
+ config.noNamespace === Config.options.noNamespace.default &&
446
+ typeof configFile.noNamespace === 'boolean'
440
447
  ) {
441
- config.useNamespace = configFile.useNamespace
448
+ config.noNamespace = configFile.noNamespace
442
449
  }
443
450
  // noComments
444
451
  if (config.noComments === Config.options.noComments.default && typeof configFile.noComments === 'boolean') {
@@ -451,10 +458,6 @@ export class Config {
451
458
  ) {
452
459
  config.noDebugComments = configFile.noDebugComments
453
460
  }
454
- // noCheck
455
- if (config.noCheck === Config.options.noCheck.default && typeof configFile.noCheck === 'boolean') {
456
- config.noCheck = configFile.noCheck
457
- }
458
461
  // fixConflicts
459
462
  if (
460
463
  config.fixConflicts === Config.options.fixConflicts.default &&
@@ -473,6 +476,13 @@ export class Config {
473
476
  ) {
474
477
  config.gnomeShellTypes = configFile.gnomeShellTypes
475
478
  }
479
+ // generateAlias
480
+ if (
481
+ config.generateAlias === Config.options.generateAlias.default &&
482
+ typeof configFile.generateAlias === 'boolean'
483
+ ) {
484
+ config.generateAlias = configFile.generateAlias
485
+ }
476
486
  }
477
487
 
478
488
  return await this.validate(config)
package/src/constants.ts CHANGED
@@ -14,7 +14,7 @@ export const MAX_CLASS_PARENT_DEPTH = 100
14
14
 
15
15
  export const APP_NAME = 'ts-for-gir'
16
16
  export const APP_USAGE = 'Typescript .d.ts generator from GIR for gjs or node-gtk'
17
- export const APP_SOURCE = 'https://github.com/sammydre/ts-for-gjs'
17
+ export const APP_SOURCE = 'https://github.com/gjsify/ts-for-gjs'
18
18
 
19
19
  export const GENERIC_NAMES = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K']
20
20
 
@@ -0,0 +1,91 @@
1
+ import { findFileInDirs } from './utils.js'
2
+ import { Logger } from './logger.js'
3
+
4
+ import type { Dependency, GenerateConfig, GirInclude } from './types/index.js'
5
+
6
+ export class DependencyManager {
7
+ protected log: Logger
8
+
9
+ cache: { [key: string]: Dependency } = {}
10
+
11
+ static instance: DependencyManager
12
+
13
+ protected constructor(protected readonly config: GenerateConfig) {
14
+ this.log = new Logger(config.environment, config.verbose, 'DependencyManager')
15
+ }
16
+
17
+ /**
18
+ * Get the DependencyManager singleton instance
19
+ */
20
+ static getInstance(config: GenerateConfig): DependencyManager {
21
+ if (this.instance) {
22
+ return this.instance
23
+ }
24
+ this.instance = new DependencyManager(config)
25
+ return this.instance
26
+ }
27
+
28
+ /**
29
+ * Get the dependency object by namespace and version
30
+ * @param namespace The namespace of the dependency
31
+ * @param version The version of the dependency
32
+ * @returns The dependency object
33
+ */
34
+ get(namespace: string, version: string): Dependency {
35
+ const packageName = `${namespace}-${version}`
36
+ if (this.cache[packageName]) {
37
+ return this.cache[packageName]
38
+ }
39
+ const filename = `${packageName}.gir`
40
+ const { exists, path } = findFileInDirs(this.config.girDirectories, filename)
41
+ const dependency: Dependency = {
42
+ namespace,
43
+ exists,
44
+ filename,
45
+ path,
46
+ packageName,
47
+ version,
48
+ }
49
+
50
+ this.cache[packageName] = dependency
51
+
52
+ return dependency
53
+ }
54
+
55
+ /**
56
+ * Transforms a gir include object array to a dependency object array
57
+ * @param girIncludes - Array of gir includes
58
+ * @returns Array of dependencies
59
+ */
60
+ fromGirIncludes(girIncludes: GirInclude[]): Dependency[] {
61
+ const dependencies: Dependency[] = []
62
+ for (const i of girIncludes) {
63
+ dependencies.unshift(this.get(i.$.name, i.$.version || '0.0'))
64
+ }
65
+ return dependencies
66
+ }
67
+
68
+ /**
69
+ * Find a dependency by it's namespace from the cache
70
+ * @param namespace The namespace of the dependency
71
+ * @returns The dependency object or null if not found
72
+ */
73
+ find(namespace: string): Dependency | null {
74
+ const packageNames = Object.keys(this.cache)
75
+ const candidates = packageNames.filter((packageName) => {
76
+ return packageName.startsWith(`${namespace}-`) && this.cache[packageName].namespace === namespace
77
+ })
78
+
79
+ if (candidates.length > 1) {
80
+ this.log.warn(`Found multiple versions of ${namespace}: ${candidates.join(', ')}`)
81
+ }
82
+
83
+ const latestVersion = candidates.sort().pop()
84
+
85
+ if (latestVersion) {
86
+ return this.cache[latestVersion]
87
+ }
88
+
89
+ return null
90
+ }
91
+ }
@@ -1,4 +1,4 @@
1
- import fs from 'fs'
1
+ import { mkdir } from 'fs/promises'
2
2
  import { GirModule } from './gir-module.js'
3
3
  import { Generator } from './generator.js'
4
4
  import TypeDefinitionGenerator from './type-definition-generator.js'
@@ -66,7 +66,7 @@ export class GenerationHandler {
66
66
  for (const girModule of girModules) {
67
67
  if (this.config.outdir) {
68
68
  const outputDir = getEnvironmentDir(this.config.environment, this.config.outdir)
69
- fs.mkdirSync(outputDir, { recursive: true })
69
+ await mkdir(outputDir, { recursive: true })
70
70
  }
71
71
  this.log.log(` - ${girModule.packageName} ...`)
72
72
  girModule.start()
package/src/gir-module.ts CHANGED
@@ -13,6 +13,7 @@ import { Logger } from './logger.js'
13
13
  import { Injector } from './injection/injector.js'
14
14
  import { GirFactory } from './gir-factory.js'
15
15
  import { ConflictResolver } from './conflict-resolver.js'
16
+ import { DependencyManager } from './dependency-manager.js'
16
17
  import {
17
18
  NO_TSDATA,
18
19
  WARN_NOT_FOUND_TYPE,
@@ -24,6 +25,7 @@ import {
24
25
  import { isEqual, find, clone, girBool, removeNamespace, addNamespace, girElementIsIntrospectable } from './utils.js'
25
26
  import { SymTable } from './symtable.js'
26
27
  import type {
28
+ Dependency,
27
29
  GirRepository,
28
30
  GirNamespace,
29
31
  GirAliasElement,
@@ -33,7 +35,6 @@ import type {
33
35
  GirClassElement,
34
36
  GirArrayType,
35
37
  GirType,
36
- GirInclude,
37
38
  GirCallableParams,
38
39
  GirCallableParamElement,
39
40
  GirVirtualMethodElement,
@@ -106,23 +107,23 @@ export class GirModule {
106
107
  */
107
108
  importName: string
108
109
 
109
- dependencies: string[] = []
110
- private _transitiveDependencies: string[] = []
110
+ dependencies: Dependency[] = []
111
+ private _transitiveDependencies: Dependency[] = []
111
112
 
112
- set transitiveDependencies(deps: string[]) {
113
+ set transitiveDependencies(deps: Dependency[]) {
113
114
  this._transitiveDependencies = this.checkTransitiveDependencies(deps)
114
115
  }
115
116
 
116
- get transitiveDependencies(): string[] {
117
+ get transitiveDependencies(): Dependency[] {
117
118
  return this._transitiveDependencies
118
119
  }
119
120
 
120
- get allDependencies(): string[] {
121
+ get allDependencies(): Dependency[] {
121
122
  return [...new Set([...this.dependencies, ...this.transitiveDependencies])]
122
123
  }
123
124
 
124
125
  repo: GirRepository
125
- ns: GirNamespace = { $: { name: '', version: '' } }
126
+ ns: GirNamespace = { $: { name: '', version: '0.0' } }
126
127
  /**
127
128
  * Used to find namespaces that are used in other modules
128
129
  */
@@ -132,6 +133,8 @@ export class GirModule {
132
133
 
133
134
  girFactory = new GirFactory()
134
135
 
136
+ dependencyManager: DependencyManager
137
+
135
138
  conflictResolver: ConflictResolver
136
139
 
137
140
  log: Logger
@@ -153,7 +156,8 @@ export class GirModule {
153
156
  throw new Error(`Namespace not found!`)
154
157
  }
155
158
 
156
- this.dependencies = this.loadDependencies(this.repo.include || [])
159
+ this.dependencyManager = DependencyManager.getInstance(this.config)
160
+ this.dependencies = this.dependencyManager.fromGirIncludes(this.repo.include || [])
157
161
  this.ns = this.repo.namespace[0]
158
162
  this.namespace = this.ns.$.name
159
163
  this.version = this.ns.$.version
@@ -167,37 +171,28 @@ export class GirModule {
167
171
  this.symTable = new SymTable(this.config, this.packageName, this.namespace)
168
172
  }
169
173
 
170
- private loadDependencies(girInclude: GirInclude[]): string[] {
171
- const dependencies: string[] = []
172
- for (const i of girInclude) {
173
- dependencies.unshift(`${i.$.name}-${i.$.version || ''}`)
174
- }
175
-
176
- return dependencies
177
- }
178
-
179
- private checkTransitiveDependencies(transitiveDependencies: string[]) {
174
+ private checkTransitiveDependencies(transitiveDependencies: Dependency[]) {
180
175
  // Always pull in GObject-2.0, as we may need it for e.g. GObject-2.0.type
181
176
  if (this.packageName !== 'GObject-2.0') {
182
- if (!find(transitiveDependencies, (x) => x === 'GObject-2.0')) {
183
- transitiveDependencies.push('GObject-2.0')
177
+ if (!find(transitiveDependencies, (x) => x.packageName === 'GObject-2.0')) {
178
+ transitiveDependencies.push(this.dependencyManager.get('GObject', '2.0'))
184
179
  }
185
180
  }
186
181
 
187
182
  // Add missing dependencies
188
183
  if (this.packageName === 'UnityExtras-7.0') {
189
- if (!find(transitiveDependencies, (x) => x === 'Unity-7.0')) {
190
- transitiveDependencies.push('Unity-7.0')
184
+ if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-7.0')) {
185
+ transitiveDependencies.push(this.dependencyManager.get('Unity', '7.0'))
191
186
  }
192
187
  }
193
188
  if (this.packageName === 'UnityExtras-6.0') {
194
- if (!find(transitiveDependencies, (x) => x === 'Unity-6.0')) {
195
- transitiveDependencies.push('Unity-6.0')
189
+ if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-6.0')) {
190
+ transitiveDependencies.push(this.dependencyManager.get('Unity', '6.0'))
196
191
  }
197
192
  }
198
193
  if (this.packageName === 'GTop-2.0') {
199
- if (!find(transitiveDependencies, (x) => x === 'GLib-2.0')) {
200
- transitiveDependencies.push('GLib-2.0')
194
+ if (!find(transitiveDependencies, (x) => x.packageName === 'GLib-2.0')) {
195
+ transitiveDependencies.push(this.dependencyManager.get('GLib', '2.0'))
201
196
  }
202
197
  }
203
198
 
@@ -2048,7 +2043,7 @@ export class GirModule {
2048
2043
  let qualifiedParentName: string
2049
2044
  let parentModName: string
2050
2045
 
2051
- // Workaround: Fix wrong parent names
2046
+ // WORKAROUND: Fix wrong parent names
2052
2047
  if (
2053
2048
  (this.packageName === 'GstAudio-0.10' || this.packageName === 'ClutterGst-1.0') &&
2054
2049
  (parentName === 'GstBase.BaseTransform' ||
@@ -2078,6 +2073,8 @@ export class GirModule {
2078
2073
  }
2079
2074
  const localParentName = parentModName == namespace ? parentName : qualifiedParentName
2080
2075
 
2076
+ const dependencyExists = !!this.symTable.get(this.allDependencies, qualifiedParentName)
2077
+
2081
2078
  const cls = this.getClassParent({
2082
2079
  qualifiedParentName,
2083
2080
  parentName,
@@ -2089,6 +2086,7 @@ export class GirModule {
2089
2086
  type,
2090
2087
  parentName,
2091
2088
  cls,
2089
+ dependencyExists,
2092
2090
  // TODO: are there other types that can be inherited or implemented?
2093
2091
  girTypeName: type === 'parent' ? 'class' : 'interface',
2094
2092
  }
@@ -2112,7 +2110,10 @@ export class GirModule {
2112
2110
  for (const implement of implmts) {
2113
2111
  const parentName = implement.$?.name
2114
2112
  if (!parentName) continue
2115
- parents.push(this.getClassParentObject(parentName, girClass._module.namespace, 'implements'))
2113
+ const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'implements')
2114
+ if (parent.dependencyExists) {
2115
+ parents.push(parent)
2116
+ }
2116
2117
  }
2117
2118
  }
2118
2119
 
@@ -2120,14 +2121,20 @@ export class GirModule {
2120
2121
  for (const prerequisite of prerequisites) {
2121
2122
  const parentName = prerequisite.$?.name
2122
2123
  if (!parentName) continue
2123
- parents.push(this.getClassParentObject(parentName, girClass._module.namespace, 'prerequisite'))
2124
+ const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'prerequisite')
2125
+ if (parent.dependencyExists) {
2126
+ parents.push(parent)
2127
+ }
2124
2128
  }
2125
2129
  }
2126
2130
 
2127
2131
  if ((girClass as GirClassElement).$.parent) {
2128
2132
  const parentName = (girClass as GirClassElement).$.parent
2129
2133
  if (parentName) {
2130
- parents.push(this.getClassParentObject(parentName, girClass._module.namespace, 'parent'))
2134
+ const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'parent')
2135
+ if (parent.dependencyExists) {
2136
+ parents.push(parent)
2137
+ }
2131
2138
  }
2132
2139
  }
2133
2140
 
@@ -2138,14 +2145,18 @@ export class GirModule {
2138
2145
  // TODO make sure this class exists in symTable
2139
2146
  const gObjectObjectCls =
2140
2147
  this.symTable.getByHand<GirClassElement>('GObject-2.0.GObject.Object') || undefined
2141
- parents.push({
2148
+ const parent: ClassParent = {
2142
2149
  qualifiedParentName: 'GObject.Object',
2143
2150
  localParentName: girClass._module.namespace === 'GObject' ? 'Object' : 'GObject.Object',
2144
2151
  type: 'parent',
2145
2152
  parentName: 'Object',
2146
2153
  cls: gObjectObjectCls,
2154
+ dependencyExists: !!gObjectObjectCls,
2147
2155
  girTypeName: 'class',
2148
- })
2156
+ }
2157
+ if (parent.dependencyExists) {
2158
+ parents.push(parent)
2159
+ }
2149
2160
  }
2150
2161
  }
2151
2162