@gtkx/config 2.0.0-beta.10 → 2.0.0-beta.12

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 (68) hide show
  1. package/README.md +11 -169
  2. package/dist/builtin-elements.d.ts +11 -0
  3. package/dist/builtin-elements.d.ts.map +1 -0
  4. package/dist/builtin-elements.js +329 -0
  5. package/dist/builtin-elements.js.map +1 -0
  6. package/dist/config-dependencies.d.ts +5 -3
  7. package/dist/config-dependencies.d.ts.map +1 -1
  8. package/dist/config-dependencies.js +57 -24
  9. package/dist/config-dependencies.js.map +1 -1
  10. package/dist/config-error.d.ts.map +1 -1
  11. package/dist/config-error.js.map +1 -1
  12. package/dist/config-reloader.d.ts +8 -0
  13. package/dist/config-reloader.d.ts.map +1 -0
  14. package/dist/config-reloader.js +32 -0
  15. package/dist/config-reloader.js.map +1 -0
  16. package/dist/config-source.d.ts +9 -0
  17. package/dist/config-source.d.ts.map +1 -0
  18. package/dist/config-source.js +32 -0
  19. package/dist/config-source.js.map +1 -0
  20. package/dist/config.d.ts +63 -29
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +72 -12
  23. package/dist/config.js.map +1 -1
  24. package/dist/deploy.d.ts +67 -13
  25. package/dist/deploy.d.ts.map +1 -1
  26. package/dist/deploy.js +169 -12
  27. package/dist/deploy.js.map +1 -1
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/internal.d.ts +5 -3
  32. package/dist/internal.d.ts.map +1 -1
  33. package/dist/internal.js +5 -3
  34. package/dist/internal.js.map +1 -1
  35. package/dist/loader.d.ts +3 -1
  36. package/dist/loader.d.ts.map +1 -1
  37. package/dist/loader.js +18 -35
  38. package/dist/loader.js.map +1 -1
  39. package/dist/node-version.d.ts +2 -1
  40. package/dist/node-version.d.ts.map +1 -1
  41. package/dist/node-version.js +2 -1
  42. package/dist/node-version.js.map +1 -1
  43. package/dist/resource-base-path.d.ts.map +1 -1
  44. package/dist/schema-text.d.ts.map +1 -1
  45. package/dist/user-event-signals.d.ts.map +1 -1
  46. package/dist/virtual.d.ts +1 -1
  47. package/dist/virtual.d.ts.map +1 -1
  48. package/dist/virtual.js +3 -4
  49. package/dist/virtual.js.map +1 -1
  50. package/dist/vite-plugin.d.ts +2 -0
  51. package/dist/vite-plugin.d.ts.map +1 -1
  52. package/dist/vite-plugin.js +4 -3
  53. package/dist/vite-plugin.js.map +1 -1
  54. package/dist/vite-root.d.ts.map +1 -1
  55. package/package.json +15 -16
  56. package/src/builtin-elements.ts +338 -0
  57. package/src/config-dependencies.ts +65 -29
  58. package/src/config-error.ts +5 -3
  59. package/src/config-reloader.ts +45 -0
  60. package/src/config-source.ts +48 -0
  61. package/src/config.ts +87 -18
  62. package/src/deploy.ts +207 -29
  63. package/src/index.ts +9 -2
  64. package/src/internal.ts +5 -2
  65. package/src/loader.ts +27 -52
  66. package/src/node-version.ts +2 -1
  67. package/src/virtual.ts +5 -6
  68. package/src/vite-plugin.ts +9 -4
package/src/config.ts CHANGED
@@ -25,14 +25,13 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
25
25
  };
26
26
 
27
27
  /**
28
- * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`: the GIR libraries
29
- * to bind and where to find them, the GApplication id, per-element configuration, the React
30
- * Compiler, codegen, and user event signal settings, and the `agents` and `mcp` blocks controlling
31
- * what coding agents are given.
28
+ * GTKX project configuration authored in `gtkx.config.ts` and validated when loaded.
32
29
  */
33
30
  type Config = z.infer<typeof configSchema>;
34
31
  type ModuleExport = z.infer<typeof moduleExportSchema>;
35
- type ElementConfigEntry = z.infer<typeof elementConfigSchema>;
32
+ type ElementPropsExport = z.infer<typeof elementPropsSchema>;
33
+ /** Overrides for one GLib type in `elements.config`, keyed by its registered type name. */
34
+ type ElementConfigOptions = z.infer<typeof elementConfigSchema>;
36
35
 
37
36
  type McpSettings = {
38
37
  tools: string[];
@@ -65,8 +64,10 @@ const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
65
64
  const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"] as const;
66
65
  const REACT_COMPILER_TARGET = "19";
67
66
 
68
- const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"')
69
- .refine((library) => !IMPLICIT_LIBRARIES.has(library), { error: "is bound implicitly; remove it" });
67
+ const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"').refine(
68
+ (library) => !IMPLICIT_LIBRARIES.has(library),
69
+ { error: "is bound implicitly; remove it" },
70
+ );
70
71
 
71
72
  const librariesSchema = z
72
73
  .array(librarySchema, { error: "must be a non-empty string array or omitted" })
@@ -80,8 +81,10 @@ const applicationIdSchema = z
80
81
 
81
82
  const reactCompilerSchema = z.union([
82
83
  z.boolean(),
83
- z.object({
84
+ z.strictObject({
85
+ /** Which functions the React Compiler processes. */
84
86
  compilationMode: z.enum(COMPILATION_MODES).optional(),
87
+ /** Which React Compiler diagnostics fail the build. */
85
88
  panicThreshold: z.enum(PANIC_THRESHOLDS).optional(),
86
89
  }),
87
90
  ]);
@@ -97,18 +100,37 @@ const userEventSignalsSchema = z.record(
97
100
  { error: "must be a record of GLib type names to signal name arrays" },
98
101
  );
99
102
 
100
- const moduleExportSchema = z.object(
103
+ const moduleExportSchema = z.strictObject(
101
104
  {
105
+ /** Module specifier containing the named export. */
102
106
  module: z.string({ error: "must be a module specifier" }).min(1, { error: "must be a module specifier" }),
107
+ /** Name of the export to import from the module. */
103
108
  export: z.string({ error: "must be an export name" }).min(1, { error: "must be an export name" }),
104
109
  },
105
110
  { error: "must be a { module, export } object" },
106
111
  );
107
112
 
108
- const elementConfigSchema = z.object({
113
+ const elementPropsSchema = moduleExportSchema.extend({
114
+ /**
115
+ * How the exported props are combined: `intersection` is inherited; `factory` applies only to this type.
116
+ * Defaults to `intersection`.
117
+ */
118
+ composition: z.enum(["factory", "intersection"]).optional(),
119
+ /** Props that can only be set when the element is created; changing them afterward throws. */
120
+ constructOnly: z.array(z.string()).optional(),
121
+ });
122
+
123
+ /** Schema for one element override and the source of {@link ElementConfigOptions}. */
124
+ const elementConfigSchema = z.strictObject({
125
+ /** Component export that wraps the generated element. */
109
126
  component: moduleExportSchema.optional(),
110
- props: moduleExportSchema.optional(),
127
+ /** Additional props type to combine with the generated element props. */
128
+ props: elementPropsSchema.optional(),
129
+ /** Whether the parent container creates this element's GObject instead of the element constructing its own. */
111
130
  isLazy: z.boolean({ error: "must be a boolean" }).optional(),
131
+ /** Accepted child GLib type names to show in the generated element documentation. */
132
+ acceptedChildTypes: z.array(z.string()).optional(),
133
+ /** GObject properties to leave out of generated props, such as properties managed by an element behavior. */
112
134
  omittedProps: z
113
135
  .array(
114
136
  z.string({ error: "must be a non-empty property name" }).min(1, {
@@ -119,25 +141,43 @@ const elementConfigSchema = z.object({
119
141
  .optional(),
120
142
  });
121
143
 
122
- const elementsSchema = z.object({
144
+ const elementsSchema = z.strictObject({
145
+ /** Path, relative to the project root, of the module exporting the element behavior map. */
123
146
  behaviors: z
124
147
  .string({ error: "must be a path to a module exporting element behaviors" })
125
148
  .min(1, { error: "must be a path to a module exporting element behaviors" })
126
149
  .optional(),
150
+ /**
151
+ * Element configuration overrides keyed by GLib type name, such as `GtkWidget`.
152
+ * @see {@link ElementConfigOptions} for the fields accepted by each entry.
153
+ */
127
154
  config: z.record(z.string(), elementConfigSchema).optional(),
128
155
  });
129
156
 
130
- const agentsSchema = z.object({
157
+ const agentsSchema = z.strictObject({
158
+ /**
159
+ * Whether codegen maintains the GTKX rules in `AGENTS.md` and creates a missing `CLAUDE.md` import.
160
+ * Defaults to `true`.
161
+ */
131
162
  rules: z.boolean({ error: "must be a boolean" }).optional(),
163
+ /** Whether codegen writes the generated element reference to `.gtkx/reference`. Defaults to `true`. */
132
164
  reference: z.boolean({ error: "must be a boolean" }).optional(),
133
165
  });
134
166
 
135
- const mcpSchema = z.object({
167
+ const mcpSchema = z.strictObject({
168
+ /**
169
+ * Tool name patterns applied in order: `*` matches any text and a leading `!` excludes matches.
170
+ * Omitted, empty, or exclusion-only lists start with all tools; other lists start with none.
171
+ */
136
172
  tools: z
137
173
  .array(z.string({ error: "must be a tool name pattern" }).min(1, { error: "must be a tool name pattern" }), {
138
174
  error: "must be an array of tool name patterns",
139
175
  })
140
176
  .optional(),
177
+ /**
178
+ * Whether the MCP server exposes only inspection and reference tools, excluding app interactions.
179
+ * Defaults to `false`.
180
+ */
141
181
  readOnly: z.boolean({ error: "must be a boolean" }).optional(),
142
182
  });
143
183
 
@@ -153,7 +193,8 @@ const graduatedFutureSchema = z
153
193
  })
154
194
  .strict();
155
195
 
156
- const deprecationsSchema = z.object({
196
+ const deprecationsSchema = z.strictObject({
197
+ /** Deprecation identifiers whose warnings are suppressed. There are currently no accepted identifiers. */
157
198
  silence: z
158
199
  .array(z.never({ error: "does not name a current deprecation" }), {
159
200
  error: "must be an array of current deprecation ids",
@@ -162,18 +203,39 @@ const deprecationsSchema = z.object({
162
203
  });
163
204
 
164
205
  /** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */
165
- const configSchema = z.object({
206
+ const configSchema = z.strictObject({
207
+ /**
208
+ * Additional GIR libraries to bind, such as `WebKit-6.0`.
209
+ * Adwaita and GTK are included implicitly and must not be listed.
210
+ */
166
211
  libraries: librariesSchema.optional(),
212
+ /** Additional GIR search directories. Relative paths are resolved from the project root. */
167
213
  girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
214
+ /** Required GApplication identifier, such as `com.example.Tasks`. */
168
215
  applicationId: applicationIdSchema,
216
+ /** Whether to enable the React Compiler, or options passed to it. Enabled by default. */
169
217
  reactCompiler: reactCompilerSchema.optional(),
218
+ /**
219
+ * Whether GTKX generates project bindings. Set to `false` to reuse an installed binding store.
220
+ * Defaults to `true`.
221
+ */
170
222
  codegen: z.boolean({ error: "must be a boolean" }).optional(),
223
+ /**
224
+ * Additional signals to suppress during React property updates, keyed by GLib type name.
225
+ * Entries extend the built-in signal lists.
226
+ */
171
227
  userEventSignals: userEventSignalsSchema.optional(),
228
+ /** Custom element behaviors and overrides for generated components, props, and documentation. */
172
229
  elements: elementsSchema.optional(),
230
+ /** Path to an icon theme directory or a single application icon file, relative to the project root. */
173
231
  applicationIcon: text("must be a path to an icon theme directory or a single icon file").optional(),
232
+ /** Application metadata, bundled runtime settings, and packaging options used by `gtkx deploy`. */
174
233
  deploy: deploySchema.optional(),
234
+ /** Controls the project instructions and reference files generated for coding agents. */
175
235
  agents: agentsSchema.optional(),
236
+ /** Default tool selection and access mode for the project's MCP server. Command-line flags take precedence. */
176
237
  mcp: mcpSchema.optional(),
238
+ /** Controls warnings for deprecated configuration and behavior. */
177
239
  deprecations: deprecationsSchema.optional(),
178
240
  });
179
241
 
@@ -238,7 +300,7 @@ const resolveLazyElements = (elements: Config["elements"]): string[] =>
238
300
 
239
301
  const elementEntryValues = <T>(
240
302
  elements: Config["elements"],
241
- pick: (entry: ElementConfigEntry) => T | undefined,
303
+ pick: (entry: ElementConfigOptions) => T | undefined,
242
304
  ): Record<string, T> =>
243
305
  Object.fromEntries(
244
306
  Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
@@ -251,9 +313,12 @@ const elementEntryValues = <T>(
251
313
  const resolveElementComponents = (elements: Config["elements"]): Record<string, ModuleExport> =>
252
314
  elementEntryValues(elements, (entry) => entry.component);
253
315
 
254
- const resolveElementProps = (elements: Config["elements"]): Record<string, ModuleExport> =>
316
+ const resolveElementProps = (elements: Config["elements"]): Record<string, ElementPropsExport> =>
255
317
  elementEntryValues(elements, (entry) => entry.props);
256
318
 
319
+ const resolveAcceptedChildTypes = (elements: Config["elements"]): Record<string, string[]> =>
320
+ elementEntryValues(elements, (entry) => entry.acceptedChildTypes);
321
+
257
322
  const resolveOmittedProps = (elements: Config["elements"]): Record<string, string[]> =>
258
323
  elementEntryValues(elements, (entry) => entry.omittedProps);
259
324
 
@@ -285,11 +350,15 @@ export {
285
350
  resolveLazyElements,
286
351
  resolveElementComponents,
287
352
  resolveElementProps,
353
+ resolveAcceptedChildTypes,
288
354
  resolveMcpSettings,
289
355
  resolveOmittedProps,
290
356
  resolveConfig,
291
357
  type McpSettings,
292
358
  type ResolvedReactCompilerOptions,
293
359
  type Config,
360
+ type ElementConfigOptions,
361
+ type ElementPropsExport,
362
+ type ModuleExport,
294
363
  type ResolvedConfig,
295
364
  };