@gtkx/config 2.0.0-beta.11 → 2.0.0-beta.13
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 +2 -2
- 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 +54 -22
- 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.map +1 -1
- package/dist/config-reloader.js +2 -8
- package/dist/config-reloader.js.map +1 -1
- package/dist/config-source.d.ts +4 -2
- package/dist/config-source.d.ts.map +1 -1
- package/dist/config-source.js +26 -8
- package/dist/config-source.js.map +1 -1
- package/dist/config.d.ts +159 -45
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +28 -19
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +391 -13
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +16 -13
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +3 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +3 -3
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +22 -4
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +59 -31
- package/dist/loader.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 -2
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +2 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +4 -3
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-root.d.ts.map +1 -1
- package/package.json +14 -29
- package/src/builtin-elements.ts +377 -0
- package/src/config-dependencies.ts +61 -27
- package/src/config-error.ts +5 -3
- package/src/config-reloader.ts +2 -11
- package/src/config-source.ts +35 -8
- package/src/config.ts +189 -39
- package/src/deploy.ts +471 -55
- package/src/index.ts +42 -3
- package/src/internal.ts +3 -2
- package/src/loader.ts +106 -37
- package/src/virtual.ts +6 -4
- package/src/vite-plugin.ts +9 -2
- package/dist/static-dependencies.d.ts +0 -3
- package/dist/static-dependencies.d.ts.map +0 -1
- package/dist/static-dependencies.js +0 -350
- package/dist/static-dependencies.js.map +0 -1
- package/src/static-dependencies.ts +0 -464
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { createJiti, type Jiti
|
|
1
|
+
import { createJiti, type Jiti } from "jiti";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
-
import {
|
|
3
|
+
import { registerHooks } from "node:module";
|
|
4
4
|
import { extname, sep } from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { isRecord } from "./config-error.ts";
|
|
7
|
+
import { configSourceCandidates } from "./config-source.ts";
|
|
6
8
|
|
|
7
|
-
type CaptureState = { cacheKey: string; dependencies: Set<string>;
|
|
9
|
+
type CaptureState = { cacheKey: string; dependencies: Set<string>; resolver: Jiti };
|
|
8
10
|
type CapturedConfig<T> = { dependencies: string[]; value: T };
|
|
9
11
|
|
|
10
12
|
const captureStorage: AsyncLocalStorage<CaptureState> = new AsyncLocalStorage();
|
|
11
13
|
const dependenciesByValue: WeakMap<object, string[]> = new WeakMap();
|
|
12
|
-
const CACHE_BUSTED_EXTENSIONS: ReadonlySet<string> = new Set([".
|
|
14
|
+
const CACHE_BUSTED_EXTENSIONS: ReadonlySet<string> = new Set([".js", ".json", ".mjs", ".mts", ".ts"]);
|
|
13
15
|
|
|
14
16
|
const isTrackedPath = (path: string): boolean => !path.includes(`${sep}node_modules${sep}`);
|
|
15
17
|
|
|
@@ -25,6 +27,18 @@ const addUrl = (url: string): void => {
|
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
29
|
|
|
30
|
+
const addConfigSource = (path: string): void => {
|
|
31
|
+
for (const candidate of configSourceCandidates(path)) {
|
|
32
|
+
addPath(candidate);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const addFailedSource = (error: unknown): void => {
|
|
37
|
+
if (isRecord(error) && typeof error.url === "string" && error.url.startsWith("file:")) {
|
|
38
|
+
addConfigSource(fileURLToPath(error.url));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
28
42
|
const cacheBustedUrl = (url: string): string => {
|
|
29
43
|
const state = captureStorage.getStore();
|
|
30
44
|
|
|
@@ -47,49 +61,61 @@ const cacheBustedUrl = (url: string): string => {
|
|
|
47
61
|
const registerResolutionHook = (): ReturnType<typeof registerHooks> =>
|
|
48
62
|
registerHooks({
|
|
49
63
|
resolve(specifier, context, nextResolve) {
|
|
50
|
-
|
|
64
|
+
let result;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
result = nextResolve(specifier, context);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const state = captureStorage.getStore();
|
|
70
|
+
const fallback = captureStorage.exit(() =>
|
|
71
|
+
state?.resolver.esmResolve(specifier, {
|
|
72
|
+
...(context.parentURL !== undefined && { parentURL: context.parentURL }),
|
|
73
|
+
try: true,
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (fallback === undefined) {
|
|
78
|
+
addFailedSource(error);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
result = nextResolve(fallback, context);
|
|
83
|
+
}
|
|
84
|
+
|
|
51
85
|
addUrl(result.url);
|
|
52
86
|
|
|
53
87
|
return { ...result, url: cacheBustedUrl(result.url) };
|
|
54
88
|
},
|
|
55
89
|
});
|
|
56
90
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
for (const path of dependencies) {
|
|
61
|
-
Reflect.deleteProperty(cache, path);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const transformConfigModule = (options: TransformOptions): TransformResult => {
|
|
66
|
-
const state = captureStorage.getStore();
|
|
67
|
-
|
|
68
|
-
if (state === undefined) {
|
|
69
|
-
throw new Error("Configuration transformation started outside a dependency capture");
|
|
91
|
+
const importConfigModule: Jiti["import"] = async <T>(path: string, options?: { default?: true }): Promise<T> => {
|
|
92
|
+
if ([".cjs", ".cts"].includes(extname(path))) {
|
|
93
|
+
throw new Error(`Configuration modules must use ESM: ${path}`);
|
|
70
94
|
}
|
|
71
95
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
96
|
+
const value = (await import(pathToFileURL(path).href, {
|
|
97
|
+
...(extname(path) === ".json" && { with: { type: "json" } }),
|
|
98
|
+
})) as Record<string, unknown>;
|
|
75
99
|
|
|
76
|
-
return {
|
|
100
|
+
return (options?.default ? (value.default ?? { ...value }) : value) as T;
|
|
77
101
|
};
|
|
78
102
|
|
|
103
|
+
const createConfigImporter = (): Jiti =>
|
|
104
|
+
Object.assign(createJiti(import.meta.url, { fsCache: false, moduleCache: false }), { import: importConfigModule });
|
|
105
|
+
|
|
79
106
|
const setConfigDependencies = (value: object, dependencies: Iterable<string>): void => {
|
|
80
107
|
const paths = [...new Set(dependencies)];
|
|
81
108
|
dependenciesByValue.set(value, paths);
|
|
82
|
-
clearNativeModuleCache(paths);
|
|
83
109
|
};
|
|
84
110
|
|
|
85
111
|
const configDependenciesFor = (value: unknown): string[] =>
|
|
86
|
-
typeof value === "object" && value !== null ? dependenciesByValue.get(value) ?? [] : [];
|
|
112
|
+
typeof value === "object" && value !== null ? (dependenciesByValue.get(value) ?? []) : [];
|
|
87
113
|
|
|
88
114
|
const captureConfigDependencies = async <T>(operation: () => Promise<T>): Promise<CapturedConfig<T>> => {
|
|
89
115
|
const state: CaptureState = {
|
|
90
116
|
cacheKey: process.hrtime.bigint().toString(),
|
|
91
117
|
dependencies: new Set(),
|
|
92
|
-
|
|
118
|
+
resolver: createJiti(import.meta.url, { fsCache: false, moduleCache: false }),
|
|
93
119
|
};
|
|
94
120
|
const hook = registerResolutionHook();
|
|
95
121
|
|
|
@@ -108,9 +134,17 @@ const captureConfigDependencies = async <T>(operation: () => Promise<T>): Promis
|
|
|
108
134
|
}
|
|
109
135
|
};
|
|
110
136
|
|
|
137
|
+
const loadConfigModule = async (path: string): Promise<unknown> => {
|
|
138
|
+
const captured = await captureConfigDependencies(() => importConfigModule(path, { default: true }));
|
|
139
|
+
|
|
140
|
+
return captured.value;
|
|
141
|
+
};
|
|
142
|
+
|
|
111
143
|
export {
|
|
144
|
+
addConfigSource,
|
|
112
145
|
captureConfigDependencies,
|
|
113
146
|
configDependenciesFor,
|
|
147
|
+
createConfigImporter,
|
|
148
|
+
loadConfigModule,
|
|
114
149
|
setConfigDependencies,
|
|
115
|
-
transformConfigModule,
|
|
116
150
|
};
|
package/src/config-error.ts
CHANGED
|
@@ -8,9 +8,11 @@ const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
|
8
8
|
const configPrefix = (configFile: string): string => `${configFile}:`;
|
|
9
9
|
|
|
10
10
|
const missingConfigFileError = (cwd: string, configFile?: string): Error =>
|
|
11
|
-
new Error(
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
new Error(
|
|
12
|
+
configFile === undefined
|
|
13
|
+
? `${configPrefix(DEFAULT_CONFIG_FILE)} no configuration file found in ${cwd}`
|
|
14
|
+
: `${configPrefix(configFile)} no configuration file found in ${cwd}`,
|
|
15
|
+
);
|
|
14
16
|
|
|
15
17
|
const configError = (error: z.ZodError, configFile = DEFAULT_CONFIG_FILE): Error =>
|
|
16
18
|
new Error(`${configPrefix(configFile)}\n${z.prettifyError(error)}`);
|
package/src/config-reloader.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
2
|
import { configDependenciesFor } from "./config-dependencies.ts";
|
|
3
3
|
import { loadConfig, type LoadConfigOptions, type LoadedConfig } from "./loader.ts";
|
|
4
|
-
import { resolveConfigDependencies } from "./static-dependencies.ts";
|
|
5
4
|
|
|
6
5
|
type ConfigReloader = {
|
|
7
6
|
reload: () => Promise<LoadedConfig>;
|
|
@@ -24,16 +23,8 @@ const createConfigReloader = async (
|
|
|
24
23
|
selectedConfigFile = resolve(cwd, options.configFile);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
const selectedConfigName = relative(cwd, selectedConfigFile);
|
|
28
|
-
const resolvePaths = (): string[] => [
|
|
29
|
-
...new Set(
|
|
30
|
-
[selectedConfigFile, ...knownDependencies]
|
|
31
|
-
.flatMap((path) => resolveConfigDependencies(path, selectedConfigName, cwd)),
|
|
32
|
-
),
|
|
33
|
-
];
|
|
34
|
-
|
|
35
26
|
return {
|
|
36
|
-
resolvePaths,
|
|
27
|
+
resolvePaths: () => [...new Set([selectedConfigFile, ...knownDependencies])],
|
|
37
28
|
reload: async () => {
|
|
38
29
|
let loaded: LoadedConfig;
|
|
39
30
|
|
package/src/config-source.ts
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SUPPORTED_EXTENSIONS } from "c12";
|
|
2
|
+
import { basename, extname, isAbsolute, join, resolve } from "node:path";
|
|
2
3
|
|
|
3
4
|
type ConfigResolutionOptions = { configFile?: string | undefined; cwd?: string | undefined };
|
|
4
5
|
|
|
6
|
+
const CONFIG_LOCATIONS = ["gtkx.config", ".config/gtkx", ".config/gtkx.config"];
|
|
7
|
+
const CONFIG_EXTENSIONS = SUPPORTED_EXTENSIONS.filter((extension) => extension !== ".cjs" && extension !== ".cts");
|
|
8
|
+
|
|
9
|
+
const configCandidatePaths = (directory: string): string[] =>
|
|
10
|
+
CONFIG_LOCATIONS.flatMap((location) =>
|
|
11
|
+
CONFIG_EXTENSIONS.map((extension) => join(directory, `${location}${extension}`)),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const configSourceCandidates = (path: string): string[] => {
|
|
15
|
+
const extension = extname(path);
|
|
16
|
+
const fallback = extension === ".js" ? ".ts" : extension === ".mjs" ? ".mts" : undefined;
|
|
17
|
+
|
|
18
|
+
if (extension.length > 0) {
|
|
19
|
+
return fallback === undefined ? [path] : [path, `${path.slice(0, -extension.length)}${fallback}`];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return [
|
|
23
|
+
path,
|
|
24
|
+
...CONFIG_EXTENSIONS.flatMap((candidate) => [`${path}${candidate}`, join(path, `index${candidate}`)]),
|
|
25
|
+
];
|
|
26
|
+
};
|
|
27
|
+
|
|
5
28
|
const isLocalConfigSource = (source: string): boolean => source.startsWith(".") || isAbsolute(source);
|
|
6
29
|
|
|
7
30
|
const isDirectoryConfigSource = (source: string): boolean => {
|
|
@@ -10,16 +33,20 @@ const isDirectoryConfigSource = (source: string): boolean => {
|
|
|
10
33
|
return extension.length === 0 || extension === basename(source);
|
|
11
34
|
};
|
|
12
35
|
|
|
13
|
-
const
|
|
36
|
+
const localConfigSourcePaths = (source: string, options: ConfigResolutionOptions): string[] => {
|
|
14
37
|
if (source === "." || !isLocalConfigSource(source)) {
|
|
15
|
-
return
|
|
38
|
+
return [];
|
|
16
39
|
}
|
|
17
40
|
|
|
18
|
-
const
|
|
41
|
+
const path = resolve(options.cwd ?? process.cwd(), source);
|
|
42
|
+
|
|
43
|
+
if (!isDirectoryConfigSource(source)) {
|
|
44
|
+
return [path];
|
|
45
|
+
}
|
|
19
46
|
|
|
20
|
-
return
|
|
21
|
-
?
|
|
22
|
-
:
|
|
47
|
+
return options.configFile === undefined || options.configFile === CONFIG_LOCATIONS[0]
|
|
48
|
+
? configCandidatePaths(path)
|
|
49
|
+
: [join(path, options.configFile)];
|
|
23
50
|
};
|
|
24
51
|
|
|
25
|
-
export {
|
|
52
|
+
export { configCandidatePaths, configSourceCandidates, localConfigSourcePaths, type ConfigResolutionOptions };
|
package/src/config.ts
CHANGED
|
@@ -3,16 +3,16 @@ 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
|
-
/** Which functions the
|
|
13
|
-
compilationMode?:
|
|
14
|
-
/** Which
|
|
15
|
-
panicThreshold?:
|
|
12
|
+
/** Which functions the React Compiler processes. */
|
|
13
|
+
compilationMode?: "all" | "annotation" | "infer" | "syntax" | undefined;
|
|
14
|
+
/** Which React Compiler diagnostics fail the build. */
|
|
15
|
+
panicThreshold?: "all_errors" | "critical_errors" | "none" | undefined;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -27,10 +27,127 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
|
|
|
27
27
|
/**
|
|
28
28
|
* GTKX project configuration authored in `gtkx.config.ts` and validated when loaded.
|
|
29
29
|
*/
|
|
30
|
-
type Config =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
type Config = {
|
|
31
|
+
/**
|
|
32
|
+
* Additional GIR libraries to bind, such as `WebKit-6.0`.
|
|
33
|
+
* Adwaita and GTK are included implicitly and must not be listed.
|
|
34
|
+
*/
|
|
35
|
+
libraries?: string[] | undefined;
|
|
36
|
+
/** Additional GIR search directories. Relative paths are resolved from the project root. */
|
|
37
|
+
girPath?: string[] | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* GApplication identifier, such as `com.example.Tasks`. Required to run, build or deploy the project as an
|
|
40
|
+
* application; a package that is not an application, such as a component library, leaves it out.
|
|
41
|
+
*/
|
|
42
|
+
applicationId?: string | undefined;
|
|
43
|
+
/** Whether to enable the React Compiler, or options passed to it. Enabled by default. */
|
|
44
|
+
reactCompiler?: boolean | ReactCompilerOptions | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Whether GTKX generates project bindings. Set to `false` to reuse an installed binding store.
|
|
47
|
+
* Defaults to `true`.
|
|
48
|
+
*/
|
|
49
|
+
codegen?: boolean | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Additional signals to suppress during React property updates, keyed by GLib type name.
|
|
52
|
+
* Entries extend the built-in signal lists.
|
|
53
|
+
*/
|
|
54
|
+
userEventSignals?: Record<string, string[]> | undefined;
|
|
55
|
+
/** Custom element behaviors and overrides for generated components, props, and documentation. */
|
|
56
|
+
elements?: ElementsOptions | undefined;
|
|
57
|
+
/** Path to an icon theme directory or a single application icon file, relative to the project root. */
|
|
58
|
+
applicationIcon?: string | undefined;
|
|
59
|
+
/** Application metadata, bundled runtime settings, and packaging options used by `gtkx deploy`. */
|
|
60
|
+
deploy?: DeployOptions | undefined;
|
|
61
|
+
/** Controls the project instructions and reference files generated for coding agents. */
|
|
62
|
+
agents?: AgentsOptions | undefined;
|
|
63
|
+
/** Default tool selection and access mode for the project's MCP server. Command-line flags take precedence. */
|
|
64
|
+
mcp?: McpOptions | undefined;
|
|
65
|
+
/** Controls warnings for deprecated configuration and behavior. */
|
|
66
|
+
deprecations?: DeprecationsOptions | undefined;
|
|
67
|
+
};
|
|
68
|
+
/** A {@link Config} whose `applicationId` is known, as loaded for an application. */
|
|
69
|
+
type ApplicationConfig = Config & { applicationId: string };
|
|
70
|
+
|
|
71
|
+
/** A named export of a module, which `elements.config` entries reference for components and props. */
|
|
72
|
+
type ModuleExport = {
|
|
73
|
+
/** Module specifier containing the named export; relative paths start at the project root. */
|
|
74
|
+
module: string;
|
|
75
|
+
/** Name of the export to import from the module. */
|
|
76
|
+
export: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** The props type an `elements.config` entry adds to a generated element, and how it combines with them. */
|
|
80
|
+
type ElementPropsExport = {
|
|
81
|
+
/** Module specifier containing the named export; relative paths start at the project root. */
|
|
82
|
+
module: string;
|
|
83
|
+
/** Name of the props type to import from the module. */
|
|
84
|
+
export: string;
|
|
85
|
+
/**
|
|
86
|
+
* How the exported props are combined: `intersection` is inherited; `factory` applies only to this type.
|
|
87
|
+
* Defaults to `intersection`.
|
|
88
|
+
*/
|
|
89
|
+
composition?: "factory" | "intersection" | undefined;
|
|
90
|
+
/** Props that can only be set when the element is created; changing them afterward throws. */
|
|
91
|
+
constructOnly?: string[] | undefined;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Overrides for one GLib type in `elements.config`, keyed by its registered type name. */
|
|
95
|
+
type ElementConfigOptions = {
|
|
96
|
+
/** Component export that wraps the generated element. */
|
|
97
|
+
component?: ModuleExport | undefined;
|
|
98
|
+
/** Additional props type to combine with the generated element props. */
|
|
99
|
+
props?: ElementPropsExport | undefined;
|
|
100
|
+
/** Whether the parent container creates this element's GObject instead of the element constructing its own. */
|
|
101
|
+
isLazy?: boolean | undefined;
|
|
102
|
+
/** Accepted child GLib type names to show in the generated element documentation. */
|
|
103
|
+
acceptedChildTypes?: string[] | undefined;
|
|
104
|
+
/** GObject properties to leave out of generated props, such as properties managed by an element behavior. */
|
|
105
|
+
omittedProps?: string[] | undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** The `elements` options: custom element behaviors and per-type overrides for generated elements. */
|
|
109
|
+
type ElementsOptions = {
|
|
110
|
+
/** Path, relative to the project root, of the module exporting the element behavior map. */
|
|
111
|
+
behaviors?: string | undefined;
|
|
112
|
+
/** Element configuration overrides keyed by GLib type name, such as `GtkWidget`. */
|
|
113
|
+
config?: Record<string, ElementConfigOptions> | undefined;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** The `agents` options: which files codegen maintains for coding agents. */
|
|
117
|
+
type AgentsOptions = {
|
|
118
|
+
/**
|
|
119
|
+
* Whether codegen maintains the GTKX rules in `AGENTS.md` and creates a missing `CLAUDE.md` import.
|
|
120
|
+
* `false` removes rules written earlier, deleting `AGENTS.md` and the `CLAUDE.md` import when nothing else
|
|
121
|
+
* remains. Defaults to `true` for an application and `false` for a package without an `applicationId`.
|
|
122
|
+
*/
|
|
123
|
+
rules?: boolean | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Whether codegen writes the generated element reference to `.gtkx/reference` and points the rules at it.
|
|
126
|
+
* `false` removes a reference generated earlier. Defaults to `true` for an application and `false` for a
|
|
127
|
+
* package without an `applicationId`.
|
|
128
|
+
*/
|
|
129
|
+
reference?: boolean | undefined;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** The `mcp` options: the tools `gtkx mcp` offers by default and whether it may interact with the app. */
|
|
133
|
+
type McpOptions = {
|
|
134
|
+
/**
|
|
135
|
+
* Tool name patterns applied in order: `*` matches any text and a leading `!` excludes matches.
|
|
136
|
+
* Omitted, empty, or exclusion-only lists start with all tools; other lists start with none.
|
|
137
|
+
*/
|
|
138
|
+
tools?: string[] | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Whether the MCP server exposes only inspection and reference tools, excluding app interactions.
|
|
141
|
+
* Defaults to `false`.
|
|
142
|
+
*/
|
|
143
|
+
readOnly?: boolean | undefined;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** The `deprecations` options: which deprecation warnings stay silent. */
|
|
147
|
+
type DeprecationsOptions = {
|
|
148
|
+
/** Deprecation identifiers whose warnings are suppressed. There are currently no accepted identifiers. */
|
|
149
|
+
silence?: never[] | undefined;
|
|
150
|
+
};
|
|
34
151
|
|
|
35
152
|
type McpSettings = {
|
|
36
153
|
tools: string[];
|
|
@@ -41,6 +158,8 @@ type McpSettings = {
|
|
|
41
158
|
type ResolvedConfig = {
|
|
42
159
|
/** The GApplication identifier the app registers under. */
|
|
43
160
|
applicationId: string;
|
|
161
|
+
/** The gettext domain, which is the `applicationId` production builds use. */
|
|
162
|
+
translationDomain: string;
|
|
44
163
|
/** React Compiler options for the build, or `null` when the compiler is disabled. */
|
|
45
164
|
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
46
165
|
/**
|
|
@@ -56,6 +175,7 @@ type ResolvedConfig = {
|
|
|
56
175
|
|
|
57
176
|
const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
|
|
58
177
|
const APPLICATION_ID_MAX_LENGTH = 255;
|
|
178
|
+
const LIBRARY_APPLICATION_ID = "org.gtkx.Library";
|
|
59
179
|
const IMPLICIT_LIBRARIES: Set<string> = new Set(["Adw-1", "Gtk-4.0"]);
|
|
60
180
|
/** Compilation modes `babel-plugin-react-compiler` accepts. */
|
|
61
181
|
const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
|
|
@@ -63,26 +183,32 @@ const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
|
|
|
63
183
|
const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"] as const;
|
|
64
184
|
const REACT_COMPILER_TARGET = "19";
|
|
65
185
|
|
|
66
|
-
const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"')
|
|
67
|
-
|
|
186
|
+
const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"').refine(
|
|
187
|
+
(library) => !IMPLICIT_LIBRARIES.has(library),
|
|
188
|
+
{ error: "is bound implicitly; remove it" },
|
|
189
|
+
);
|
|
68
190
|
|
|
69
191
|
const librariesSchema = z
|
|
70
192
|
.array(librarySchema, { error: "must be a non-empty string array or omitted" })
|
|
71
193
|
.min(1, { error: "must be a non-empty string array or omitted" });
|
|
72
194
|
|
|
73
195
|
const applicationIdSchema = z
|
|
74
|
-
.string({
|
|
196
|
+
.string({
|
|
197
|
+
error: (issue) =>
|
|
198
|
+
issue.input === undefined
|
|
199
|
+
? 'is required to run, build or deploy an application, such as "org.example.MyApp"'
|
|
200
|
+
: "must satisfy g_application_id_is_valid",
|
|
201
|
+
})
|
|
75
202
|
.refine((value) => isValidApplicationId(value), {
|
|
76
203
|
error: 'must satisfy g_application_id_is_valid, such as "org.example.MyApp"',
|
|
77
204
|
});
|
|
78
205
|
|
|
79
|
-
const
|
|
80
|
-
z.
|
|
81
|
-
z.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
]);
|
|
206
|
+
const reactCompilerOptionsSchema = z.strictObject({
|
|
207
|
+
compilationMode: z.enum(COMPILATION_MODES).optional(),
|
|
208
|
+
panicThreshold: z.enum(PANIC_THRESHOLDS).optional(),
|
|
209
|
+
}) satisfies z.ZodType<ReactCompilerOptions>;
|
|
210
|
+
|
|
211
|
+
const reactCompilerSchema = z.union([z.boolean(), reactCompilerOptionsSchema]);
|
|
86
212
|
|
|
87
213
|
const userEventSignalsSchema = z.record(
|
|
88
214
|
z.string(),
|
|
@@ -101,12 +227,12 @@ const moduleExportSchema = z.strictObject(
|
|
|
101
227
|
export: z.string({ error: "must be an export name" }).min(1, { error: "must be an export name" }),
|
|
102
228
|
},
|
|
103
229
|
{ error: "must be a { module, export } object" },
|
|
104
|
-
)
|
|
230
|
+
) satisfies z.ZodType<ModuleExport>;
|
|
105
231
|
|
|
106
232
|
const elementPropsSchema = moduleExportSchema.extend({
|
|
107
233
|
composition: z.enum(["factory", "intersection"]).optional(),
|
|
108
234
|
constructOnly: z.array(z.string()).optional(),
|
|
109
|
-
})
|
|
235
|
+
}) satisfies z.ZodType<ElementPropsExport>;
|
|
110
236
|
|
|
111
237
|
const elementConfigSchema = z.strictObject({
|
|
112
238
|
component: moduleExportSchema.optional(),
|
|
@@ -121,7 +247,7 @@ const elementConfigSchema = z.strictObject({
|
|
|
121
247
|
{ error: "must be an array of property names" },
|
|
122
248
|
)
|
|
123
249
|
.optional(),
|
|
124
|
-
})
|
|
250
|
+
}) satisfies z.ZodType<ElementConfigOptions>;
|
|
125
251
|
|
|
126
252
|
const elementsSchema = z.strictObject({
|
|
127
253
|
behaviors: z
|
|
@@ -129,12 +255,12 @@ const elementsSchema = z.strictObject({
|
|
|
129
255
|
.min(1, { error: "must be a path to a module exporting element behaviors" })
|
|
130
256
|
.optional(),
|
|
131
257
|
config: z.record(z.string(), elementConfigSchema).optional(),
|
|
132
|
-
})
|
|
258
|
+
}) satisfies z.ZodType<ElementsOptions>;
|
|
133
259
|
|
|
134
260
|
const agentsSchema = z.strictObject({
|
|
135
261
|
rules: z.boolean({ error: "must be a boolean" }).optional(),
|
|
136
262
|
reference: z.boolean({ error: "must be a boolean" }).optional(),
|
|
137
|
-
})
|
|
263
|
+
}) satisfies z.ZodType<AgentsOptions>;
|
|
138
264
|
|
|
139
265
|
const mcpSchema = z.strictObject({
|
|
140
266
|
tools: z
|
|
@@ -143,7 +269,7 @@ const mcpSchema = z.strictObject({
|
|
|
143
269
|
})
|
|
144
270
|
.optional(),
|
|
145
271
|
readOnly: z.boolean({ error: "must be a boolean" }).optional(),
|
|
146
|
-
})
|
|
272
|
+
}) satisfies z.ZodType<McpOptions>;
|
|
147
273
|
|
|
148
274
|
const graduatedFutureSchema = z
|
|
149
275
|
.object({
|
|
@@ -163,13 +289,13 @@ const deprecationsSchema = z.strictObject({
|
|
|
163
289
|
error: "must be an array of current deprecation ids",
|
|
164
290
|
})
|
|
165
291
|
.optional(),
|
|
166
|
-
})
|
|
292
|
+
}) satisfies z.ZodType<DeprecationsOptions>;
|
|
167
293
|
|
|
168
|
-
/** Schema every `gtkx.config.ts` is validated against
|
|
294
|
+
/** Schema every `gtkx.config.ts` is validated against. */
|
|
169
295
|
const configSchema = z.strictObject({
|
|
170
296
|
libraries: librariesSchema.optional(),
|
|
171
297
|
girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
|
|
172
|
-
applicationId: applicationIdSchema,
|
|
298
|
+
applicationId: applicationIdSchema.optional(),
|
|
173
299
|
reactCompiler: reactCompilerSchema.optional(),
|
|
174
300
|
codegen: z.boolean({ error: "must be a boolean" }).optional(),
|
|
175
301
|
userEventSignals: userEventSignalsSchema.optional(),
|
|
@@ -179,14 +305,17 @@ const configSchema = z.strictObject({
|
|
|
179
305
|
agents: agentsSchema.optional(),
|
|
180
306
|
mcp: mcpSchema.optional(),
|
|
181
307
|
deprecations: deprecationsSchema.optional(),
|
|
182
|
-
})
|
|
308
|
+
}) satisfies z.ZodType<Config>;
|
|
183
309
|
|
|
184
310
|
/**
|
|
185
311
|
* Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets
|
|
186
312
|
* autocompletion and type checking.
|
|
187
313
|
*/
|
|
188
314
|
const defineConfig: DefineConfig<Config> = createDefineConfig<Config>();
|
|
189
|
-
const validationSchema = configSchema.extend({
|
|
315
|
+
const validationSchema = configSchema.extend({
|
|
316
|
+
applicationId: applicationIdSchema,
|
|
317
|
+
future: graduatedFutureSchema.optional(),
|
|
318
|
+
});
|
|
190
319
|
|
|
191
320
|
const isValidApplicationId = (applicationId: string): boolean =>
|
|
192
321
|
applicationId.length <= APPLICATION_ID_MAX_LENGTH && APPLICATION_ID_PATTERN.test(applicationId);
|
|
@@ -205,7 +334,10 @@ const resolveReactCompilerOptions = (setting: Config["reactCompiler"]): Resolved
|
|
|
205
334
|
};
|
|
206
335
|
};
|
|
207
336
|
|
|
208
|
-
const validateConfig
|
|
337
|
+
const validateConfig: (config: unknown, configFile?: string) => asserts config is ApplicationConfig = (
|
|
338
|
+
config,
|
|
339
|
+
configFile,
|
|
340
|
+
) => {
|
|
209
341
|
const result = validationSchema.safeParse(config);
|
|
210
342
|
|
|
211
343
|
if (!result.success) {
|
|
@@ -242,7 +374,7 @@ const resolveLazyElements = (elements: Config["elements"]): string[] =>
|
|
|
242
374
|
|
|
243
375
|
const elementEntryValues = <T>(
|
|
244
376
|
elements: Config["elements"],
|
|
245
|
-
pick: (entry:
|
|
377
|
+
pick: (entry: ElementConfigOptions) => T | undefined,
|
|
246
378
|
): Record<string, T> =>
|
|
247
379
|
Object.fromEntries(
|
|
248
380
|
Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
|
|
@@ -252,11 +384,16 @@ const elementEntryValues = <T>(
|
|
|
252
384
|
}),
|
|
253
385
|
);
|
|
254
386
|
|
|
255
|
-
const
|
|
256
|
-
|
|
387
|
+
const resolveModuleSpecifier = <T extends { module: string }>(reference: T, root: string): T =>
|
|
388
|
+
reference.module.startsWith("./") || reference.module.startsWith("../")
|
|
389
|
+
? { ...reference, module: resolve(root, reference.module) }
|
|
390
|
+
: reference;
|
|
391
|
+
|
|
392
|
+
const resolveElementComponents = (elements: Config["elements"], root: string): Record<string, ModuleExport> =>
|
|
393
|
+
elementEntryValues(elements, (entry) => entry.component && resolveModuleSpecifier(entry.component, root));
|
|
257
394
|
|
|
258
|
-
const resolveElementProps = (elements: Config["elements"]): Record<string, ElementPropsExport> =>
|
|
259
|
-
elementEntryValues(elements, (entry) => entry.props);
|
|
395
|
+
const resolveElementProps = (elements: Config["elements"], root: string): Record<string, ElementPropsExport> =>
|
|
396
|
+
elementEntryValues(elements, (entry) => entry.props && resolveModuleSpecifier(entry.props, root));
|
|
260
397
|
|
|
261
398
|
const resolveAcceptedChildTypes = (elements: Config["elements"]): Record<string, string[]> =>
|
|
262
399
|
elementEntryValues(elements, (entry) => entry.acceptedChildTypes);
|
|
@@ -264,16 +401,18 @@ const resolveAcceptedChildTypes = (elements: Config["elements"]): Record<string,
|
|
|
264
401
|
const resolveOmittedProps = (elements: Config["elements"]): Record<string, string[]> =>
|
|
265
402
|
elementEntryValues(elements, (entry) => entry.omittedProps);
|
|
266
403
|
|
|
267
|
-
const isAgentRulesEnabled = (config: Config): boolean => config.agents?.rules
|
|
268
|
-
const isAgentReferenceEnabled = (config: Config): boolean =>
|
|
404
|
+
const isAgentRulesEnabled = (config: Config, isApplication: boolean): boolean => config.agents?.rules ?? isApplication;
|
|
405
|
+
const isAgentReferenceEnabled = (config: Config, isApplication: boolean): boolean =>
|
|
406
|
+
config.agents?.reference ?? isApplication;
|
|
269
407
|
|
|
270
408
|
const resolveMcpSettings = (config: Config): McpSettings => ({
|
|
271
409
|
tools: config.mcp?.tools ?? [],
|
|
272
410
|
isReadOnly: config.mcp?.readOnly === true,
|
|
273
411
|
});
|
|
274
412
|
|
|
275
|
-
const resolveConfig = (config:
|
|
413
|
+
const resolveConfig = (config: ApplicationConfig, translationDomain: string, root?: string): ResolvedConfig => ({
|
|
276
414
|
applicationId: config.applicationId,
|
|
415
|
+
translationDomain,
|
|
277
416
|
reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
|
|
278
417
|
userEventSignals: resolveUserEventSignals(config.userEventSignals),
|
|
279
418
|
elements: resolveElementsModule(config.elements?.behaviors, root),
|
|
@@ -281,7 +420,9 @@ const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
|
|
|
281
420
|
});
|
|
282
421
|
|
|
283
422
|
export {
|
|
423
|
+
configSchema,
|
|
284
424
|
APPLICATION_ID_MAX_LENGTH,
|
|
425
|
+
LIBRARY_APPLICATION_ID,
|
|
285
426
|
defineConfig,
|
|
286
427
|
isAgentReferenceEnabled,
|
|
287
428
|
isAgentRulesEnabled,
|
|
@@ -296,8 +437,17 @@ export {
|
|
|
296
437
|
resolveMcpSettings,
|
|
297
438
|
resolveOmittedProps,
|
|
298
439
|
resolveConfig,
|
|
440
|
+
type AgentsOptions,
|
|
441
|
+
type DeprecationsOptions,
|
|
442
|
+
type ElementsOptions,
|
|
443
|
+
type McpOptions,
|
|
299
444
|
type McpSettings,
|
|
445
|
+
type ReactCompilerOptions,
|
|
300
446
|
type ResolvedReactCompilerOptions,
|
|
447
|
+
type ApplicationConfig,
|
|
301
448
|
type Config,
|
|
449
|
+
type ElementConfigOptions,
|
|
450
|
+
type ElementPropsExport,
|
|
451
|
+
type ModuleExport,
|
|
302
452
|
type ResolvedConfig,
|
|
303
453
|
};
|