@ts-for-gir/lib 4.0.0-beta.40 → 4.0.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/gir.ts CHANGED
@@ -21,7 +21,7 @@ export enum ConflictType {
21
21
  VFUNC_SIGNATURE_CONFLICT,
22
22
  }
23
23
 
24
- import { ConsoleReporter, ReporterService } from "@ts-for-gir/reporter";
24
+ import { type ConsoleReporter, LazyReporter } from "@ts-for-gir/reporter";
25
25
  import type { IntrospectedField, IntrospectedProperty } from "./gir/property.ts";
26
26
  import type { OptionsBase } from "./types/index.ts";
27
27
  import { isInvalid, sanitizeIdentifierName, sanitizeNamespace } from "./utils/naming.ts";
@@ -49,44 +49,14 @@ export class TypeIdentifier extends TypeExpression {
49
49
  readonly name: string;
50
50
  readonly namespace: string;
51
51
 
52
- // Global reporter configuration and instance
53
- private static reporterConfig: { enabled: boolean; output: string } = {
54
- enabled: false,
55
- output: "ts-for-gir-report.json",
56
- };
57
- private static globalReporter: ConsoleReporter | null = null;
52
+ private static readonly reporter = new LazyReporter("TypeIdentifier");
58
53
 
59
- static configureReporter(enabled: boolean, output: string = "ts-for-gir-report.json") {
60
- TypeIdentifier.reporterConfig = { enabled, output };
61
-
62
- // Reset global reporter to force recreation with new config
63
- if (TypeIdentifier.globalReporter) {
64
- TypeIdentifier.globalReporter = null;
65
- }
66
-
67
- // Create and register the global reporter if enabled
68
- if (enabled) {
69
- TypeIdentifier.globalReporter = new ConsoleReporter(true, "TypeIdentifier", enabled, output);
70
- const reporterService = ReporterService.getInstance();
71
- reporterService.registerReporter("TypeIdentifier", TypeIdentifier.globalReporter);
72
- }
73
- }
74
-
75
- private static getReporter(): ConsoleReporter {
76
- if (!TypeIdentifier.globalReporter) {
77
- const config = TypeIdentifier.reporterConfig;
78
- TypeIdentifier.globalReporter = new ConsoleReporter(true, "TypeIdentifier", config.enabled, config.output);
79
-
80
- if (config.enabled) {
81
- const reporterService = ReporterService.getInstance();
82
- reporterService.registerReporter("TypeIdentifier", TypeIdentifier.globalReporter);
83
- }
84
- }
85
- return TypeIdentifier.globalReporter;
54
+ static configureReporter(enabled: boolean, output?: string) {
55
+ TypeIdentifier.reporter.configure(enabled, output);
86
56
  }
87
57
 
88
58
  get log(): ConsoleReporter {
89
- return TypeIdentifier.getReporter();
59
+ return TypeIdentifier.reporter.get();
90
60
  }
91
61
 
92
62
  constructor(name: string, namespace: string) {
@@ -194,7 +164,7 @@ export class TypeIdentifier extends TypeExpression {
194
164
 
195
165
  return new TypeIdentifier(c_resolved_name, ns.namespace);
196
166
  } else if (namespace.namespace === ns.namespace) {
197
- this.log.reportTypeResolutionError(
167
+ this.log.reportTypeResolutionWarning(
198
168
  this.name,
199
169
  ns.namespace,
200
170
  `Unable to resolve type ${this.name} in same namespace ${ns.namespace}!`,
@@ -203,11 +173,12 @@ export class TypeIdentifier extends TypeExpression {
203
173
  return null;
204
174
  }
205
175
 
206
- this.log.reportTypeResolutionError(
176
+ this.log.reportTypeResolutionWarning(
207
177
  this.name,
208
178
  this.namespace,
209
179
  `Type ${this.name} could not be resolved in ${namespace.namespace} ${namespace.version}`,
210
- `Failed to resolve type during namespace processing`,
180
+ `Referenced from ${namespace.namespace} ${namespace.version}`,
181
+ `${namespace.namespace} ${namespace.version}`,
211
182
  );
212
183
  return null;
213
184
  }
@@ -876,7 +847,12 @@ export class ArrayType extends TypeExpression {
876
847
  }
877
848
  }
878
849
 
879
- // Common native types as constants
850
+ /**
851
+ * Common native types as constants.
852
+ * These represent TypeScript types in generated .d.ts output for GJS runtime,
853
+ * not internal tool types. Uses of `any` here are intentional — they produce
854
+ * correct type definitions for GLib/GIO/GObject APIs that accept dynamic values.
855
+ */
880
856
  export const ThisType = new NativeType("this");
881
857
  export const ObjectType = new NativeType("object");
882
858
  export const AnyType = new NativeType("any");
@@ -1,3 +1,8 @@
1
+ /**
2
+ * GIO type injection overrides.
3
+ * Uses of `any`/`AnyType` in this file are intentional — they produce
4
+ * generated .d.ts output matching GIO's dynamic runtime behavior.
5
+ */
1
6
  import { GirDirection } from "@gi.ts/parser";
2
7
  import { IntrospectedAlias } from "../gir/alias.ts";
3
8
  import { IntrospectedConstructor } from "../gir/constructor.ts";
@@ -28,6 +33,7 @@ import {
28
33
  Uint8ArrayType,
29
34
  VoidType,
30
35
  } from "../gir.ts";
36
+ import { girParsingReporter } from "../utils/gir-parsing.ts";
31
37
 
32
38
  export default {
33
39
  namespace: "Gio",
@@ -700,7 +706,14 @@ export default {
700
706
  if (existingMethodIndex !== -1) {
701
707
  ActionMap.members[existingMethodIndex] = newMethod;
702
708
  } else {
703
- console.warn("Could not find existing add_action_entries method to override");
709
+ girParsingReporter
710
+ .get()
711
+ .reportParsingFailure(
712
+ "add_action_entries",
713
+ "method",
714
+ "Gio",
715
+ "Could not find existing add_action_entries method to override in Gio.ActionMap",
716
+ );
704
717
  ActionMap.members.push(newMethod);
705
718
  }
706
719
  },
@@ -1,3 +1,8 @@
1
+ /**
2
+ * GLib type injection overrides.
3
+ * Uses of `any`/`AnyType` in this file are intentional — they produce
4
+ * generated .d.ts output matching GLib's dynamic runtime behavior.
5
+ */
1
6
  import { GirDirection } from "@gi.ts/parser";
2
7
  import { IntrospectedConstructor } from "../gir/constructor.ts";
3
8
  import { IntrospectedDirectAllocationConstructor } from "../gir/direct-allocation-constructor.ts";
@@ -1,3 +1,8 @@
1
+ /**
2
+ * GObject type injection overrides.
3
+ * Uses of `any`/`AnyType` in this file are intentional — they produce
4
+ * generated .d.ts output matching GObject's dynamic runtime behavior.
5
+ */
1
6
  import { GirDirection } from "@gi.ts/parser";
2
7
  import { IntrospectedAlias } from "../gir/alias.ts";
3
8
  import { IntrospectedFunction } from "../gir/function.ts";
@@ -50,4 +50,16 @@ export interface OptionsGeneration extends OptionsBase {
50
50
  * Output file path for the reporter
51
51
  */
52
52
  reporterOutput: string;
53
+ /** Generate a single unified documentation for all modules instead of separate per-module docs */
54
+ combined?: boolean;
55
+ /** URL template for source links in generated documentation. Supports {path}, {line}, {gitRevision} placeholders */
56
+ sourceLinkTemplate?: string;
57
+ /** Theme for HTML documentation generation (default: "gi-docgen") */
58
+ theme?: string;
59
+ /** Path to a README file to use as the documentation index page (default: "none") */
60
+ readme?: string;
61
+ /** Use TypeDoc merge mode to generate HTML from pre-generated JSON files */
62
+ merge?: boolean;
63
+ /** Directory containing pre-generated TypeDoc JSON files for merge mode (from 'ts-for-gir json') */
64
+ jsonDir?: string;
53
65
  }
@@ -55,4 +55,16 @@ export interface UserConfig {
55
55
  * Output file path for the reporter
56
56
  */
57
57
  reporterOutput: string;
58
+ /** Generate a single unified documentation for all modules instead of separate per-module docs */
59
+ combined?: boolean;
60
+ /** URL template for source links in generated documentation. Supports {path}, {line}, {gitRevision} placeholders */
61
+ sourceLinkTemplate?: string;
62
+ /** Theme for HTML documentation generation (default: "gi-docgen") */
63
+ theme?: string;
64
+ /** Path to a README file to use as the documentation index page (default: "none") */
65
+ readme?: string;
66
+ /** Use TypeDoc merge mode to generate HTML from pre-generated JSON files */
67
+ merge?: boolean;
68
+ /** Directory containing pre-generated TypeDoc JSON files for merge mode (from 'ts-for-gir json') */
69
+ jsonDir?: string;
58
70
  }
@@ -1,5 +1,5 @@
1
1
  import { GirDirection } from "@gi.ts/parser";
2
- import { ConsoleReporter, ReporterService } from "@ts-for-gir/reporter";
2
+ import { LazyReporter } from "@ts-for-gir/reporter";
3
3
  import { IntrospectedConstructor } from "../gir/constructor.ts";
4
4
  import { FilterBehavior } from "../gir/data.ts";
5
5
  import type { IntrospectedFunction } from "../gir/function.ts";
@@ -20,48 +20,14 @@ import { AnyType, ArrayType, ConflictType, NeverType, TypeConflict } from "../gi
20
20
  import { findMap } from "../util.ts";
21
21
  import { isSubtypeOf } from "./type-resolution.ts";
22
22
 
23
- // Global reporter configuration for conflicts
24
- let conflictsReporterInstance: ConsoleReporter | null = null;
25
- let conflictsReporterConfig: { enabled: boolean; output: string } = {
26
- enabled: false,
27
- output: "ts-for-gir-report.json",
28
- };
23
+ export const conflictsReporter = new LazyReporter("conflicts");
29
24
 
30
- function configureConflictsReporterInternal(enabled: boolean, output: string = "ts-for-gir-report.json") {
31
- conflictsReporterConfig = { enabled, output };
32
-
33
- // Reset instance to force recreation with new config
34
- if (conflictsReporterInstance) {
35
- conflictsReporterInstance = null;
36
- }
37
-
38
- // Create and register the global reporter if enabled
39
- if (enabled) {
40
- conflictsReporterInstance = new ConsoleReporter(true, "conflicts", enabled, output);
41
- const reporterService = ReporterService.getInstance();
42
- reporterService.registerReporter("conflicts", conflictsReporterInstance);
43
- }
44
- }
45
-
46
- function getConflictsReporterInstance(): ConsoleReporter {
47
- if (!conflictsReporterInstance) {
48
- const config = conflictsReporterConfig;
49
- conflictsReporterInstance = new ConsoleReporter(true, "conflicts", config.enabled, config.output);
50
-
51
- // Register with reporter service if reporting is enabled
52
- if (config.enabled) {
53
- const reporterService = ReporterService.getInstance();
54
- reporterService.registerReporter("conflicts", conflictsReporterInstance);
55
- }
56
- }
57
- return conflictsReporterInstance;
58
- }
59
-
60
- const log = getConflictsReporterInstance();
61
-
62
- // Export function to configure conflicts reporter
63
- export function configureConflictsReporter(enabled: boolean, output: string = "ts-for-gir-report.json") {
64
- configureConflictsReporterInternal(enabled, output);
25
+ // Use a function to always get the current reporter instance.
26
+ // A module-level `const log = conflictsReporter.get()` would capture a stale
27
+ // reference from before configure() is called, causing problems to be logged
28
+ // to console but not stored in the report.
29
+ function getLog() {
30
+ return conflictsReporter.get();
65
31
  }
66
32
 
67
33
  // Constants for GObject methods that always conflict
@@ -119,7 +85,7 @@ export function filterFunctionConflict<
119
85
 
120
86
  if (conflictResult.shouldOmit) {
121
87
  // Always omit methods that conflict with properties/fields
122
- log.reportTypeConflict(
88
+ getLog().reportTypeConflict(
123
89
  "field_property",
124
90
  next.name,
125
91
  next.parent?.namespace.namespace || "unknown",
@@ -127,7 +93,7 @@ export function filterFunctionConflict<
127
93
  );
128
94
  } else if (conflictResult.hasConflict) {
129
95
  if (isInheritedMethods) {
130
- log.reportTypeConflict(
96
+ getLog().reportTypeConflict(
131
97
  "method",
132
98
  next.name,
133
99
  next.parent?.namespace.namespace || "unknown",
@@ -445,7 +411,7 @@ function checkPropertyConflicts<T extends IntrospectedClassMember | Introspected
445
411
  element instanceof IntrospectedProperty &&
446
412
  !isSubtypeOf(ns, thisType, resolved_parent.getType(), element.type, p.type)
447
413
  ) {
448
- log.reportTypeConflict(
414
+ getLog().reportTypeConflict(
449
415
  "general",
450
416
  element.name,
451
417
  element.parent?.namespace.namespace || "unknown",