@gtkx/config 2.0.0-beta.8 → 2.0.0
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/README.md +11 -169
- package/dist/builtin-elements.d.ts +23 -0
- package/dist/builtin-elements.d.ts.map +1 -0
- package/dist/builtin-elements.js +366 -0
- package/dist/builtin-elements.js.map +1 -0
- package/dist/config-dependencies.d.ts +5 -3
- package/dist/config-dependencies.d.ts.map +1 -1
- package/dist/config-dependencies.js +57 -24
- package/dist/config-dependencies.js.map +1 -1
- package/dist/config-error.d.ts.map +1 -1
- package/dist/config-error.js.map +1 -1
- package/dist/config-reloader.d.ts +8 -0
- package/dist/config-reloader.d.ts.map +1 -0
- package/dist/config-reloader.js +32 -0
- package/dist/config-reloader.js.map +1 -0
- package/dist/config-source.d.ts +9 -0
- package/dist/config-source.d.ts.map +1 -0
- package/dist/config-source.js +35 -0
- package/dist/config-source.js.map +1 -0
- package/dist/config.d.ts +286 -53
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +42 -27
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +949 -20
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +17 -15
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +5 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -3
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +23 -5
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +58 -42
- package/dist/loader.js.map +1 -1
- package/dist/node-version.d.ts +2 -1
- package/dist/node-version.d.ts.map +1 -1
- package/dist/node-version.js +2 -1
- package/dist/node-version.js.map +1 -1
- package/dist/resource-base-path.d.ts.map +1 -1
- package/dist/schema-text.d.ts.map +1 -1
- package/dist/user-event-signals.d.ts.map +1 -1
- package/dist/virtual.d.ts +1 -1
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +4 -4
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +7 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +13 -4
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-root.d.ts.map +1 -1
- package/package.json +15 -16
- package/src/builtin-elements.ts +377 -0
- package/src/config-dependencies.ts +65 -29
- package/src/config-error.ts +5 -3
- package/src/config-reloader.ts +45 -0
- package/src/config-source.ts +52 -0
- package/src/config.ts +316 -49
- package/src/deploy.ts +1029 -59
- package/src/index.ts +47 -3
- package/src/internal.ts +6 -2
- package/src/loader.ts +103 -54
- package/src/node-version.ts +2 -1
- package/src/virtual.ts +6 -6
- package/src/vite-plugin.ts +24 -5
package/src/config.ts
CHANGED
|
@@ -3,16 +3,24 @@ import { defu } from "defu";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { configError, isRecord } from "./config-error.ts";
|
|
6
|
-
import { deploySchema } from "./deploy.ts";
|
|
6
|
+
import { type DeployOptions, deploySchema } from "./deploy.ts";
|
|
7
7
|
import { girLibrary, text } from "./schema-text.ts";
|
|
8
8
|
import { resolveUserEventSignals } from "./user-event-signals.ts";
|
|
9
9
|
|
|
10
10
|
/** Object form of the `reactCompiler` config key, forwarded to `babel-plugin-react-compiler`. */
|
|
11
11
|
type ReactCompilerOptions = {
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Which functions the React Compiler processes.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue `"infer"`, the React Compiler's own default
|
|
16
|
+
*/
|
|
17
|
+
compilationMode?: "all" | "annotation" | "infer" | "syntax" | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Which React Compiler diagnostics fail the build.
|
|
20
|
+
*
|
|
21
|
+
* @defaultValue `"none"`, the React Compiler's own default
|
|
22
|
+
*/
|
|
23
|
+
panicThreshold?: "all_errors" | "critical_errors" | "none" | undefined;
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
/**
|
|
@@ -25,14 +33,230 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
|
|
|
25
33
|
};
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* what
|
|
36
|
+
* GTKX project configuration authored in `gtkx.config.ts` and validated when loaded.
|
|
37
|
+
*
|
|
38
|
+
* [Configuration and Codegen](https://gtkx.dev/v2/guide/configuration-and-codegen) shows how to set up the file
|
|
39
|
+
* and what codegen generates from it.
|
|
32
40
|
*/
|
|
33
|
-
type Config =
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
type Config = {
|
|
42
|
+
/**
|
|
43
|
+
* Additional GIR libraries to bind, such as `WebKit-6.0`.
|
|
44
|
+
* Adwaita and GTK are included implicitly and must not be listed.
|
|
45
|
+
*
|
|
46
|
+
* @defaultValue None: GTKX binds `Adw-1`, `Gtk-4.0` and the libraries they depend on
|
|
47
|
+
*/
|
|
48
|
+
libraries?: string[] | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Additional GIR search directories, searched before the system ones. Relative paths are resolved from the
|
|
51
|
+
* project root.
|
|
52
|
+
*
|
|
53
|
+
* @defaultValue None: GTKX searches `/usr/share/gir-1.0` and the GIR directories pkg-config reports for
|
|
54
|
+
* `gobject-introspection-1.0`
|
|
55
|
+
*/
|
|
56
|
+
girPath?: string[] | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* GApplication identifier, such as `com.example.Tasks`. Required to run, build or deploy the project as an
|
|
59
|
+
* application; a package that is not an application, such as a component library, leaves it out.
|
|
60
|
+
*
|
|
61
|
+
* @defaultValue None: the project loads as a package, with `isApplication` set to `false`
|
|
62
|
+
*/
|
|
63
|
+
applicationId?: string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to enable the React Compiler, or options passed to it. `false` disables it.
|
|
66
|
+
*
|
|
67
|
+
* @defaultValue `true`
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* reactCompiler: { compilationMode: "annotation" },
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
reactCompiler?: boolean | ReactCompilerOptions | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Whether GTKX generates project bindings. Set to `false` to reuse an installed binding store.
|
|
76
|
+
*
|
|
77
|
+
* @defaultValue `true`
|
|
78
|
+
*/
|
|
79
|
+
codegen?: boolean | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Additional signals to suppress during React property updates, keyed by GLib type name.
|
|
82
|
+
* Entries extend the built-in signal lists.
|
|
83
|
+
*
|
|
84
|
+
* @defaultValue `{}`: only the built-in lists
|
|
85
|
+
*/
|
|
86
|
+
userEventSignals?: Record<string, string[]> | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Custom element behaviors and overrides for generated components, props, and documentation.
|
|
89
|
+
*
|
|
90
|
+
* @defaultValue `{}`: no custom behaviors or overrides
|
|
91
|
+
*/
|
|
92
|
+
elements?: ElementsOptions | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Path to an icon theme directory or a single SVG, PNG or XPM application icon file, relative to the project
|
|
95
|
+
* root. Deployment requires an icon.
|
|
96
|
+
*
|
|
97
|
+
* @defaultValue The one `<applicationId>.svg`, `.png` or `.xpm` file in the project root, if exactly one
|
|
98
|
+
* exists
|
|
99
|
+
*/
|
|
100
|
+
applicationIcon?: string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Application metadata, bundled runtime settings, and packaging options used by `gtkx deploy`.
|
|
103
|
+
*
|
|
104
|
+
* @defaultValue `{}`: metadata comes from `package.json` and packaging builds a Flatpak
|
|
105
|
+
*/
|
|
106
|
+
deploy?: DeployOptions | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Controls the project instructions and reference files generated for coding agents.
|
|
109
|
+
*
|
|
110
|
+
* @defaultValue `{}`: an application gets both, a package neither
|
|
111
|
+
*/
|
|
112
|
+
agents?: AgentsOptions | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Default tool selection and access mode for the project's MCP server. The `gtkx mcp` flags `--tools` and
|
|
115
|
+
* `--read-only` take precedence.
|
|
116
|
+
*
|
|
117
|
+
* @defaultValue `{}`: every tool, app interactions included
|
|
118
|
+
*/
|
|
119
|
+
mcp?: McpOptions | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Controls warnings for deprecated configuration and behavior.
|
|
122
|
+
*
|
|
123
|
+
* @defaultValue `{}`: every deprecation warning is shown
|
|
124
|
+
*/
|
|
125
|
+
deprecations?: DeprecationsOptions | undefined;
|
|
126
|
+
};
|
|
127
|
+
/** A {@link Config} whose `applicationId` is known, as loaded for an application. */
|
|
128
|
+
type ApplicationConfig = Config & { applicationId: string };
|
|
129
|
+
|
|
130
|
+
/** A named export of a module, which `elements.config` entries reference for components and props. */
|
|
131
|
+
type ModuleExport = {
|
|
132
|
+
/** Module specifier containing the named export; relative paths start at the project root. */
|
|
133
|
+
module: string;
|
|
134
|
+
/** Name of the export to import from the module. */
|
|
135
|
+
export: string;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** The props type an `elements.config` entry adds to a generated element, and how it combines with them. */
|
|
139
|
+
type ElementPropsExport = {
|
|
140
|
+
/** Module specifier containing the named export; relative paths start at the project root. */
|
|
141
|
+
module: string;
|
|
142
|
+
/** Name of the props type to import from the module. */
|
|
143
|
+
export: string;
|
|
144
|
+
/**
|
|
145
|
+
* How the exported props are combined: `intersection` is inherited; `factory` applies only to this type.
|
|
146
|
+
*
|
|
147
|
+
* @defaultValue `"intersection"`
|
|
148
|
+
*/
|
|
149
|
+
composition?: "factory" | "intersection" | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Props that can only be set when the element is created; changing them afterward throws.
|
|
152
|
+
*
|
|
153
|
+
* @defaultValue `[]`
|
|
154
|
+
*/
|
|
155
|
+
constructOnly?: string[] | undefined;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/** Overrides for one GLib type in `elements.config`, keyed by its registered type name. */
|
|
159
|
+
type ElementConfigOptions = {
|
|
160
|
+
/**
|
|
161
|
+
* Component export that wraps the generated element.
|
|
162
|
+
*
|
|
163
|
+
* @defaultValue None: no wrapper `component`
|
|
164
|
+
*/
|
|
165
|
+
component?: ModuleExport | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Additional props type to combine with the generated element props.
|
|
168
|
+
*
|
|
169
|
+
* @defaultValue None: no extra `props` type
|
|
170
|
+
*/
|
|
171
|
+
props?: ElementPropsExport | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Whether the parent container creates this element's GObject instead of the element constructing its own.
|
|
174
|
+
* Subtypes inherit the setting.
|
|
175
|
+
*
|
|
176
|
+
* @defaultValue `false`
|
|
177
|
+
*/
|
|
178
|
+
isLazy?: boolean | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Accepted child GLib type names to show in the generated element documentation.
|
|
181
|
+
*
|
|
182
|
+
* @defaultValue `[]`
|
|
183
|
+
*/
|
|
184
|
+
acceptedChildTypes?: string[] | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* GObject properties to leave out of generated props, such as properties managed by an element behavior.
|
|
187
|
+
*
|
|
188
|
+
* @defaultValue `[]`: every GObject property becomes a prop
|
|
189
|
+
*/
|
|
190
|
+
omittedProps?: string[] | undefined;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** The `elements` options: custom element behaviors and per-type overrides for generated elements. */
|
|
194
|
+
type ElementsOptions = {
|
|
195
|
+
/**
|
|
196
|
+
* Path, relative to the project root, of the module exporting the element behavior map.
|
|
197
|
+
*
|
|
198
|
+
* @defaultValue None: only the behaviors built into `@gtkx/react` apply
|
|
199
|
+
*/
|
|
200
|
+
behaviors?: string | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Element configuration overrides keyed by GLib type name, such as `GtkWidget`.
|
|
203
|
+
*
|
|
204
|
+
* @defaultValue `{}`
|
|
205
|
+
*/
|
|
206
|
+
config?: Record<string, ElementConfigOptions> | undefined;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** The `agents` options: which files codegen maintains for coding agents. */
|
|
210
|
+
type AgentsOptions = {
|
|
211
|
+
/**
|
|
212
|
+
* Whether codegen maintains the GTKX rules in `AGENTS.md` and creates a missing `CLAUDE.md` import.
|
|
213
|
+
* `false` removes rules written earlier, deleting `AGENTS.md` and the `CLAUDE.md` import when nothing else
|
|
214
|
+
* remains.
|
|
215
|
+
*
|
|
216
|
+
* @defaultValue `true` for an application, `false` for a package without an `applicationId`
|
|
217
|
+
*/
|
|
218
|
+
rules?: boolean | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* Whether codegen writes the generated element reference to `.gtkx/reference` and points the rules at it.
|
|
221
|
+
* `false` removes a reference generated earlier.
|
|
222
|
+
*
|
|
223
|
+
* @defaultValue `true` for an application, `false` for a package without an `applicationId`
|
|
224
|
+
*/
|
|
225
|
+
reference?: boolean | undefined;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/** The `mcp` options: the tools `gtkx mcp` offers by default and whether it may interact with the app. */
|
|
229
|
+
type McpOptions = {
|
|
230
|
+
/**
|
|
231
|
+
* Tool name patterns applied in order: `*` matches any text and a leading `!` excludes matches.
|
|
232
|
+
* Omitted, empty, or exclusion-only lists start with all tools; other lists start with none.
|
|
233
|
+
* `gtkx mcp --tools` overrides it.
|
|
234
|
+
*
|
|
235
|
+
* @defaultValue `[]`: every tool
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* tools: ["gtkx_*", "!gtkx_take_screenshot"],
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
tools?: string[] | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Whether the MCP server exposes only inspection and reference tools, excluding app interactions.
|
|
244
|
+
* `gtkx mcp --read-only` overrides it.
|
|
245
|
+
*
|
|
246
|
+
* @defaultValue `false`
|
|
247
|
+
*/
|
|
248
|
+
readOnly?: boolean | undefined;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/** The `deprecations` options: which deprecation warnings stay silent. */
|
|
252
|
+
type DeprecationsOptions = {
|
|
253
|
+
/**
|
|
254
|
+
* Deprecation identifiers whose warnings are suppressed. There are currently no accepted identifiers.
|
|
255
|
+
*
|
|
256
|
+
* @defaultValue `[]`
|
|
257
|
+
*/
|
|
258
|
+
silence?: never[] | undefined;
|
|
259
|
+
};
|
|
36
260
|
|
|
37
261
|
type McpSettings = {
|
|
38
262
|
tools: string[];
|
|
@@ -43,6 +267,8 @@ type McpSettings = {
|
|
|
43
267
|
type ResolvedConfig = {
|
|
44
268
|
/** The GApplication identifier the app registers under. */
|
|
45
269
|
applicationId: string;
|
|
270
|
+
/** The gettext domain, which is the `applicationId` production builds use. */
|
|
271
|
+
translationDomain: string;
|
|
46
272
|
/** React Compiler options for the build, or `null` when the compiler is disabled. */
|
|
47
273
|
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
48
274
|
/**
|
|
@@ -58,6 +284,7 @@ type ResolvedConfig = {
|
|
|
58
284
|
|
|
59
285
|
const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
|
|
60
286
|
const APPLICATION_ID_MAX_LENGTH = 255;
|
|
287
|
+
const LIBRARY_APPLICATION_ID = "org.gtkx.Library";
|
|
61
288
|
const IMPLICIT_LIBRARIES: Set<string> = new Set(["Adw-1", "Gtk-4.0"]);
|
|
62
289
|
/** Compilation modes `babel-plugin-react-compiler` accepts. */
|
|
63
290
|
const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
|
|
@@ -65,26 +292,32 @@ const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
|
|
|
65
292
|
const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"] as const;
|
|
66
293
|
const REACT_COMPILER_TARGET = "19";
|
|
67
294
|
|
|
68
|
-
const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"')
|
|
69
|
-
|
|
295
|
+
const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"').refine(
|
|
296
|
+
(library) => !IMPLICIT_LIBRARIES.has(library),
|
|
297
|
+
{ error: "is bound implicitly; remove it" },
|
|
298
|
+
);
|
|
70
299
|
|
|
71
300
|
const librariesSchema = z
|
|
72
301
|
.array(librarySchema, { error: "must be a non-empty string array or omitted" })
|
|
73
302
|
.min(1, { error: "must be a non-empty string array or omitted" });
|
|
74
303
|
|
|
75
304
|
const applicationIdSchema = z
|
|
76
|
-
.string({
|
|
305
|
+
.string({
|
|
306
|
+
error: (issue) =>
|
|
307
|
+
issue.input === undefined
|
|
308
|
+
? 'is required to run, build or deploy an application, such as "org.example.MyApp"'
|
|
309
|
+
: "must satisfy g_application_id_is_valid",
|
|
310
|
+
})
|
|
77
311
|
.refine((value) => isValidApplicationId(value), {
|
|
78
312
|
error: 'must satisfy g_application_id_is_valid, such as "org.example.MyApp"',
|
|
79
313
|
});
|
|
80
314
|
|
|
81
|
-
const
|
|
82
|
-
z.
|
|
83
|
-
z.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
]);
|
|
315
|
+
const reactCompilerOptionsSchema = z.strictObject({
|
|
316
|
+
compilationMode: z.enum(COMPILATION_MODES).optional(),
|
|
317
|
+
panicThreshold: z.enum(PANIC_THRESHOLDS).optional(),
|
|
318
|
+
}) satisfies z.ZodType<ReactCompilerOptions>;
|
|
319
|
+
|
|
320
|
+
const reactCompilerSchema = z.union([z.boolean(), reactCompilerOptionsSchema]);
|
|
88
321
|
|
|
89
322
|
const userEventSignalsSchema = z.record(
|
|
90
323
|
z.string(),
|
|
@@ -97,18 +330,24 @@ const userEventSignalsSchema = z.record(
|
|
|
97
330
|
{ error: "must be a record of GLib type names to signal name arrays" },
|
|
98
331
|
);
|
|
99
332
|
|
|
100
|
-
const moduleExportSchema = z.
|
|
333
|
+
const moduleExportSchema = z.strictObject(
|
|
101
334
|
{
|
|
102
335
|
module: z.string({ error: "must be a module specifier" }).min(1, { error: "must be a module specifier" }),
|
|
103
336
|
export: z.string({ error: "must be an export name" }).min(1, { error: "must be an export name" }),
|
|
104
337
|
},
|
|
105
338
|
{ error: "must be a { module, export } object" },
|
|
106
|
-
)
|
|
339
|
+
) satisfies z.ZodType<ModuleExport>;
|
|
107
340
|
|
|
108
|
-
const
|
|
341
|
+
const elementPropsSchema = moduleExportSchema.extend({
|
|
342
|
+
composition: z.enum(["factory", "intersection"]).optional(),
|
|
343
|
+
constructOnly: z.array(z.string()).optional(),
|
|
344
|
+
}) satisfies z.ZodType<ElementPropsExport>;
|
|
345
|
+
|
|
346
|
+
const elementConfigSchema = z.strictObject({
|
|
109
347
|
component: moduleExportSchema.optional(),
|
|
110
|
-
props:
|
|
348
|
+
props: elementPropsSchema.optional(),
|
|
111
349
|
isLazy: z.boolean({ error: "must be a boolean" }).optional(),
|
|
350
|
+
acceptedChildTypes: z.array(z.string()).optional(),
|
|
112
351
|
omittedProps: z
|
|
113
352
|
.array(
|
|
114
353
|
z.string({ error: "must be a non-empty property name" }).min(1, {
|
|
@@ -117,29 +356,29 @@ const elementConfigSchema = z.object({
|
|
|
117
356
|
{ error: "must be an array of property names" },
|
|
118
357
|
)
|
|
119
358
|
.optional(),
|
|
120
|
-
})
|
|
359
|
+
}) satisfies z.ZodType<ElementConfigOptions>;
|
|
121
360
|
|
|
122
|
-
const elementsSchema = z.
|
|
361
|
+
const elementsSchema = z.strictObject({
|
|
123
362
|
behaviors: z
|
|
124
363
|
.string({ error: "must be a path to a module exporting element behaviors" })
|
|
125
364
|
.min(1, { error: "must be a path to a module exporting element behaviors" })
|
|
126
365
|
.optional(),
|
|
127
366
|
config: z.record(z.string(), elementConfigSchema).optional(),
|
|
128
|
-
})
|
|
367
|
+
}) satisfies z.ZodType<ElementsOptions>;
|
|
129
368
|
|
|
130
|
-
const agentsSchema = z.
|
|
369
|
+
const agentsSchema = z.strictObject({
|
|
131
370
|
rules: z.boolean({ error: "must be a boolean" }).optional(),
|
|
132
371
|
reference: z.boolean({ error: "must be a boolean" }).optional(),
|
|
133
|
-
})
|
|
372
|
+
}) satisfies z.ZodType<AgentsOptions>;
|
|
134
373
|
|
|
135
|
-
const mcpSchema = z.
|
|
374
|
+
const mcpSchema = z.strictObject({
|
|
136
375
|
tools: z
|
|
137
376
|
.array(z.string({ error: "must be a tool name pattern" }).min(1, { error: "must be a tool name pattern" }), {
|
|
138
377
|
error: "must be an array of tool name patterns",
|
|
139
378
|
})
|
|
140
379
|
.optional(),
|
|
141
380
|
readOnly: z.boolean({ error: "must be a boolean" }).optional(),
|
|
142
|
-
})
|
|
381
|
+
}) satisfies z.ZodType<McpOptions>;
|
|
143
382
|
|
|
144
383
|
const graduatedFutureSchema = z
|
|
145
384
|
.object({
|
|
@@ -153,19 +392,19 @@ const graduatedFutureSchema = z
|
|
|
153
392
|
})
|
|
154
393
|
.strict();
|
|
155
394
|
|
|
156
|
-
const deprecationsSchema = z.
|
|
395
|
+
const deprecationsSchema = z.strictObject({
|
|
157
396
|
silence: z
|
|
158
397
|
.array(z.never({ error: "does not name a current deprecation" }), {
|
|
159
398
|
error: "must be an array of current deprecation ids",
|
|
160
399
|
})
|
|
161
400
|
.optional(),
|
|
162
|
-
})
|
|
401
|
+
}) satisfies z.ZodType<DeprecationsOptions>;
|
|
163
402
|
|
|
164
|
-
/** Schema every `gtkx.config.ts` is validated against
|
|
165
|
-
const configSchema = z.
|
|
403
|
+
/** Schema every `gtkx.config.ts` is validated against. */
|
|
404
|
+
const configSchema = z.strictObject({
|
|
166
405
|
libraries: librariesSchema.optional(),
|
|
167
406
|
girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
|
|
168
|
-
applicationId: applicationIdSchema,
|
|
407
|
+
applicationId: applicationIdSchema.optional(),
|
|
169
408
|
reactCompiler: reactCompilerSchema.optional(),
|
|
170
409
|
codegen: z.boolean({ error: "must be a boolean" }).optional(),
|
|
171
410
|
userEventSignals: userEventSignalsSchema.optional(),
|
|
@@ -175,14 +414,17 @@ const configSchema = z.object({
|
|
|
175
414
|
agents: agentsSchema.optional(),
|
|
176
415
|
mcp: mcpSchema.optional(),
|
|
177
416
|
deprecations: deprecationsSchema.optional(),
|
|
178
|
-
})
|
|
417
|
+
}) satisfies z.ZodType<Config>;
|
|
179
418
|
|
|
180
419
|
/**
|
|
181
420
|
* Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets
|
|
182
421
|
* autocompletion and type checking.
|
|
183
422
|
*/
|
|
184
423
|
const defineConfig: DefineConfig<Config> = createDefineConfig<Config>();
|
|
185
|
-
const validationSchema = configSchema.extend({
|
|
424
|
+
const validationSchema = configSchema.extend({
|
|
425
|
+
applicationId: applicationIdSchema,
|
|
426
|
+
future: graduatedFutureSchema.optional(),
|
|
427
|
+
});
|
|
186
428
|
|
|
187
429
|
const isValidApplicationId = (applicationId: string): boolean =>
|
|
188
430
|
applicationId.length <= APPLICATION_ID_MAX_LENGTH && APPLICATION_ID_PATTERN.test(applicationId);
|
|
@@ -201,7 +443,10 @@ const resolveReactCompilerOptions = (setting: Config["reactCompiler"]): Resolved
|
|
|
201
443
|
};
|
|
202
444
|
};
|
|
203
445
|
|
|
204
|
-
const validateConfig
|
|
446
|
+
const validateConfig: (config: unknown, configFile?: string) => asserts config is ApplicationConfig = (
|
|
447
|
+
config,
|
|
448
|
+
configFile,
|
|
449
|
+
) => {
|
|
205
450
|
const result = validationSchema.safeParse(config);
|
|
206
451
|
|
|
207
452
|
if (!result.success) {
|
|
@@ -238,7 +483,7 @@ const resolveLazyElements = (elements: Config["elements"]): string[] =>
|
|
|
238
483
|
|
|
239
484
|
const elementEntryValues = <T>(
|
|
240
485
|
elements: Config["elements"],
|
|
241
|
-
pick: (entry:
|
|
486
|
+
pick: (entry: ElementConfigOptions) => T | undefined,
|
|
242
487
|
): Record<string, T> =>
|
|
243
488
|
Object.fromEntries(
|
|
244
489
|
Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
|
|
@@ -248,25 +493,35 @@ const elementEntryValues = <T>(
|
|
|
248
493
|
}),
|
|
249
494
|
);
|
|
250
495
|
|
|
251
|
-
const
|
|
252
|
-
|
|
496
|
+
const resolveModuleSpecifier = <T extends { module: string }>(reference: T, root: string): T =>
|
|
497
|
+
reference.module.startsWith("./") || reference.module.startsWith("../")
|
|
498
|
+
? { ...reference, module: resolve(root, reference.module) }
|
|
499
|
+
: reference;
|
|
500
|
+
|
|
501
|
+
const resolveElementComponents = (elements: Config["elements"], root: string): Record<string, ModuleExport> =>
|
|
502
|
+
elementEntryValues(elements, (entry) => entry.component && resolveModuleSpecifier(entry.component, root));
|
|
503
|
+
|
|
504
|
+
const resolveElementProps = (elements: Config["elements"], root: string): Record<string, ElementPropsExport> =>
|
|
505
|
+
elementEntryValues(elements, (entry) => entry.props && resolveModuleSpecifier(entry.props, root));
|
|
253
506
|
|
|
254
|
-
const
|
|
255
|
-
elementEntryValues(elements, (entry) => entry.
|
|
507
|
+
const resolveAcceptedChildTypes = (elements: Config["elements"]): Record<string, string[]> =>
|
|
508
|
+
elementEntryValues(elements, (entry) => entry.acceptedChildTypes);
|
|
256
509
|
|
|
257
510
|
const resolveOmittedProps = (elements: Config["elements"]): Record<string, string[]> =>
|
|
258
511
|
elementEntryValues(elements, (entry) => entry.omittedProps);
|
|
259
512
|
|
|
260
|
-
const isAgentRulesEnabled = (config: Config): boolean => config.agents?.rules
|
|
261
|
-
const isAgentReferenceEnabled = (config: Config): boolean =>
|
|
513
|
+
const isAgentRulesEnabled = (config: Config, isApplication: boolean): boolean => config.agents?.rules ?? isApplication;
|
|
514
|
+
const isAgentReferenceEnabled = (config: Config, isApplication: boolean): boolean =>
|
|
515
|
+
config.agents?.reference ?? isApplication;
|
|
262
516
|
|
|
263
517
|
const resolveMcpSettings = (config: Config): McpSettings => ({
|
|
264
518
|
tools: config.mcp?.tools ?? [],
|
|
265
519
|
isReadOnly: config.mcp?.readOnly === true,
|
|
266
520
|
});
|
|
267
521
|
|
|
268
|
-
const resolveConfig = (config:
|
|
522
|
+
const resolveConfig = (config: ApplicationConfig, translationDomain: string, root?: string): ResolvedConfig => ({
|
|
269
523
|
applicationId: config.applicationId,
|
|
524
|
+
translationDomain,
|
|
270
525
|
reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
|
|
271
526
|
userEventSignals: resolveUserEventSignals(config.userEventSignals),
|
|
272
527
|
elements: resolveElementsModule(config.elements?.behaviors, root),
|
|
@@ -274,7 +529,9 @@ const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
|
|
|
274
529
|
});
|
|
275
530
|
|
|
276
531
|
export {
|
|
532
|
+
configSchema,
|
|
277
533
|
APPLICATION_ID_MAX_LENGTH,
|
|
534
|
+
LIBRARY_APPLICATION_ID,
|
|
278
535
|
defineConfig,
|
|
279
536
|
isAgentReferenceEnabled,
|
|
280
537
|
isAgentRulesEnabled,
|
|
@@ -285,11 +542,21 @@ export {
|
|
|
285
542
|
resolveLazyElements,
|
|
286
543
|
resolveElementComponents,
|
|
287
544
|
resolveElementProps,
|
|
545
|
+
resolveAcceptedChildTypes,
|
|
288
546
|
resolveMcpSettings,
|
|
289
547
|
resolveOmittedProps,
|
|
290
548
|
resolveConfig,
|
|
549
|
+
type AgentsOptions,
|
|
550
|
+
type DeprecationsOptions,
|
|
551
|
+
type ElementsOptions,
|
|
552
|
+
type McpOptions,
|
|
291
553
|
type McpSettings,
|
|
554
|
+
type ReactCompilerOptions,
|
|
292
555
|
type ResolvedReactCompilerOptions,
|
|
556
|
+
type ApplicationConfig,
|
|
293
557
|
type Config,
|
|
558
|
+
type ElementConfigOptions,
|
|
559
|
+
type ElementPropsExport,
|
|
560
|
+
type ModuleExport,
|
|
294
561
|
type ResolvedConfig,
|
|
295
562
|
};
|