@gtkx/config 1.0.0-rc.1 → 1.0.0-rc.2
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/dist/config-error.d.ts +16 -0
- package/dist/config-error.d.ts.map +1 -0
- package/dist/config-error.js +45 -0
- package/dist/config-error.js.map +1 -0
- package/dist/config.d.ts +51 -56
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +90 -42
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +6 -5
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +10 -8
- package/dist/loader.js.map +1 -1
- package/dist/user-event-signals.d.ts +4 -0
- package/dist/user-event-signals.d.ts.map +1 -0
- package/dist/user-event-signals.js +54 -0
- package/dist/user-event-signals.js.map +1 -0
- package/dist/virtual.d.ts +8 -3
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +26 -6
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +12 -13
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +3 -9
- package/src/config-error.ts +67 -0
- package/src/config.ts +176 -84
- package/src/index.ts +0 -12
- package/src/internal.ts +1 -1
- package/src/loader.ts +22 -13
- package/src/user-event-signals.ts +57 -0
- package/src/virtual.ts +28 -5
- package/src/vite-plugin.ts +25 -11
- package/dist/element-props.d.ts +0 -180
- package/dist/element-props.d.ts.map +0 -1
- package/dist/element-props.js +0 -154
- package/dist/element-props.js.map +0 -1
- package/env.d.ts +0 -8
- package/src/element-props.ts +0 -248
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
type IssuePath = (string | number)[];
|
|
3
|
+
declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
4
|
+
declare const rawIssue: (input: unknown, path: IssuePath, message: string, isStandalone?: boolean) => {
|
|
5
|
+
params?: {
|
|
6
|
+
standalone: boolean;
|
|
7
|
+
};
|
|
8
|
+
code: "custom";
|
|
9
|
+
input: unknown;
|
|
10
|
+
path: IssuePath;
|
|
11
|
+
message: string;
|
|
12
|
+
continue: true;
|
|
13
|
+
};
|
|
14
|
+
declare const configError: (error: z.ZodError) => Error;
|
|
15
|
+
export { isRecord, rawIssue, configError };
|
|
16
|
+
//# sourceMappingURL=config-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-error.d.ts","sourceRoot":"","sources":["../src/config-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,KAAK,SAAS,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AAIrC,QAAA,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACM,CAAC;AAEzE,QAAA,MAAM,QAAQ,GAAI,OAAO,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,MAAM,EAAE,sBAAoB;;;;;;;;;CAOtF,CAAC;AAwCH,QAAA,MAAM,WAAW,GAAI,OAAO,CAAC,CAAC,QAAQ,KAAG,KAQxC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const CONFIG_PREFIX = "gtkx.config.ts:";
|
|
2
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
const rawIssue = (input, path, message, isStandalone = false) => ({
|
|
4
|
+
code: "custom",
|
|
5
|
+
input,
|
|
6
|
+
path,
|
|
7
|
+
message,
|
|
8
|
+
continue: true,
|
|
9
|
+
...(isStandalone && { params: { standalone: true } }),
|
|
10
|
+
});
|
|
11
|
+
const appendSegment = (path, segment) => {
|
|
12
|
+
if (typeof segment === "number") {
|
|
13
|
+
return `${path}[${String(segment)}]`;
|
|
14
|
+
}
|
|
15
|
+
return path === "" ? String(segment) : `${path}.${String(segment)}`;
|
|
16
|
+
};
|
|
17
|
+
const dottedPath = (segments) => {
|
|
18
|
+
let path = "";
|
|
19
|
+
for (const segment of segments) {
|
|
20
|
+
path = appendSegment(path, segment);
|
|
21
|
+
}
|
|
22
|
+
return path;
|
|
23
|
+
};
|
|
24
|
+
const isStandaloneIssue = (issue) => "params" in issue && isRecord(issue.params) && issue.params.standalone === true;
|
|
25
|
+
const formatIssue = (issue, fullPath) => {
|
|
26
|
+
if (issue.code === "unrecognized_keys") {
|
|
27
|
+
const [key] = issue.keys;
|
|
28
|
+
const path = dottedPath(key === undefined ? fullPath : [...fullPath, key]);
|
|
29
|
+
return `${CONFIG_PREFIX} \`${path}\` is not a recognized key`;
|
|
30
|
+
}
|
|
31
|
+
if (isStandaloneIssue(issue)) {
|
|
32
|
+
return `${CONFIG_PREFIX} ${issue.message}`;
|
|
33
|
+
}
|
|
34
|
+
const path = dottedPath(fullPath);
|
|
35
|
+
return path === "" ? `${CONFIG_PREFIX} ${issue.message}` : `${CONFIG_PREFIX} \`${path}\` ${issue.message}`;
|
|
36
|
+
};
|
|
37
|
+
const configError = (error) => {
|
|
38
|
+
const issue = error.issues[0];
|
|
39
|
+
if (issue === undefined) {
|
|
40
|
+
return new Error(`${CONFIG_PREFIX} invalid configuration`);
|
|
41
|
+
}
|
|
42
|
+
return new Error(formatIssue(issue, issue.path));
|
|
43
|
+
};
|
|
44
|
+
export { isRecord, rawIssue, configError };
|
|
45
|
+
//# sourceMappingURL=config-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-error.js","sourceRoot":"","sources":["../src/config-error.ts"],"names":[],"mappings":"AAIA,MAAM,aAAa,GAAG,iBAAiB,CAA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IG_PREFIX = \"gtkx.config.ts:\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst rawIssue = (input: unknown, path: IssuePath, message: string, isStandalone = false) => ({\n code: \"custom\" as const,\n input,\n path,\n message,\n continue: true as const,\n ...(isStandalone && { params: { standalone: true } }),\n});\n\nconst appendSegment = (path: string, segment: PropertyKey): string => {\n if (typeof segment === \"number\") {\n return `${path}[${String(segment)}]`;\n }\n\n return path === \"\" ? String(segment) : `${path}.${String(segment)}`;\n};\n\nconst dottedPath = (segments: PropertyKey[]): string => {\n let path = \"\";\n\n for (const segment of segments) {\n path = appendSegment(path, segment);\n }\n\n return path;\n};\n\nconst isStandaloneIssue = (issue: z.core.$ZodIssue): boolean =>\n \"params\" in issue && isRecord(issue.params) && issue.params.standalone === true;\n\nconst formatIssue = (issue: z.core.$ZodIssue, fullPath: PropertyKey[]): string => {\n if (issue.code === \"unrecognized_keys\") {\n const [key] = issue.keys;\n const path = dottedPath(key === undefined ? fullPath : [...fullPath, key]);\n\n return `${CONFIG_PREFIX} \\`${path}\\` is not a recognized key`;\n }\n\n if (isStandaloneIssue(issue)) {\n return `${CONFIG_PREFIX} ${issue.message}`;\n }\n\n const path = dottedPath(fullPath);\n\n return path === \"\" ? `${CONFIG_PREFIX} ${issue.message}` : `${CONFIG_PREFIX} \\`${path}\\` ${issue.message}`;\n};\n\nconst configError = (error: z.ZodError): Error => {\n const issue = error.issues[0];\n\n if (issue === undefined) {\n return new Error(`${CONFIG_PREFIX} invalid configuration`);\n }\n\n return new Error(formatIssue(issue, issue.path));\n};\n\nexport { isRecord, rawIssue, configError };\n"]}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { type DefineConfig } from "c12";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
export declare const LIBRARIES_WILDCARD = "*";
|
|
4
|
-
export declare const GIR_LIBRARY_PATTERN: RegExp;
|
|
5
|
-
export declare const isValidApplicationId: (applicationId: string) => boolean;
|
|
6
|
-
declare const COMPILATION_MODES: readonly ["infer", "syntax", "annotation", "all"];
|
|
7
|
-
declare const PANIC_THRESHOLDS: readonly ["none", "critical_errors", "all_errors"];
|
|
8
3
|
type ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];
|
|
9
4
|
type ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];
|
|
10
5
|
type ReactCompilerOptions = {
|
|
@@ -15,72 +10,72 @@ type ReactCompilerOptions = {
|
|
|
15
10
|
* React Compiler options resolved for the build, with the compilation target
|
|
16
11
|
* fixed to React 19.
|
|
17
12
|
*/
|
|
18
|
-
|
|
13
|
+
type ResolvedReactCompilerOptions = ReactCompilerOptions & {
|
|
19
14
|
target: "19";
|
|
20
15
|
};
|
|
21
|
-
|
|
16
|
+
/**
|
|
17
|
+
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
|
|
18
|
+
* the GIR libraries to bind, extra `.gir` search paths, the GApplication id,
|
|
19
|
+
* a module of per-element configuration (lazy flags and custom behaviors),
|
|
20
|
+
* per-element component wrappers keyed by GLib type name, the React Compiler and
|
|
21
|
+
* codegen settings, and additional user event signals to suppress during React
|
|
22
|
+
* commits.
|
|
23
|
+
*/
|
|
24
|
+
type Config = z.infer<typeof configSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* Configuration reduced to the values needed at runtime: the GApplication
|
|
27
|
+
* identifier, the resolved React Compiler options (`null` when disabled), the
|
|
28
|
+
* user event signals suppressed while a React commit is in progress, and the
|
|
29
|
+
* module path holding per-element configuration (`null` when unset).
|
|
30
|
+
*/
|
|
31
|
+
type ResolvedConfig = {
|
|
32
|
+
applicationId: string;
|
|
33
|
+
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
34
|
+
userEventSignals: Record<string, string[]>;
|
|
35
|
+
elements: string | null;
|
|
36
|
+
lazyElements: string[];
|
|
37
|
+
};
|
|
38
|
+
declare const LIBRARIES_WILDCARD = "*";
|
|
39
|
+
declare const GIR_LIBRARY_PATTERN: RegExp;
|
|
40
|
+
declare const COMPILATION_MODES: readonly ["infer", "syntax", "annotation", "all"];
|
|
41
|
+
declare const PANIC_THRESHOLDS: readonly ["none", "critical_errors", "all_errors"];
|
|
22
42
|
declare const configSchema: z.ZodObject<{
|
|
23
|
-
libraries: z.ZodOptional<z.ZodCustom<"*"
|
|
43
|
+
libraries: z.ZodOptional<z.ZodCustom<string[] | "*", string[] | "*">>;
|
|
24
44
|
girPath: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
45
|
applicationId: z.ZodCustom<string, string>;
|
|
26
|
-
elementProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
|
-
kind: z.ZodLiteral<"container">;
|
|
28
|
-
prop: z.ZodString;
|
|
29
|
-
child: z.ZodString;
|
|
30
|
-
append: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
31
|
-
remove: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
32
|
-
insert: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
33
|
-
reorder: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
34
|
-
autowrap: z.ZodOptional<z.ZodString>;
|
|
35
|
-
adopt: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodString]>>;
|
|
36
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
37
|
-
kind: z.ZodLiteral<"value">;
|
|
38
|
-
prop: z.ZodString;
|
|
39
|
-
call: z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>;
|
|
40
|
-
after: z.ZodOptional<z.ZodString>;
|
|
41
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
42
|
-
kind: z.ZodLiteral<"controlled-text">;
|
|
43
|
-
prop: z.ZodString;
|
|
44
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
-
kind: z.ZodLiteral<"lazy">;
|
|
46
|
-
prop: z.ZodString;
|
|
47
|
-
lookup: z.ZodOptional<z.ZodString>;
|
|
48
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
49
|
-
kind: z.ZodLiteral<"list">;
|
|
50
|
-
prop: z.ZodString;
|
|
51
|
-
add: z.ZodUnion<readonly [z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>, z.ZodArray<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>]>;
|
|
52
|
-
remove: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
53
|
-
clear: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
54
|
-
}, z.core.$strict>], "kind">>>>;
|
|
55
46
|
reactCompiler: z.ZodOptional<z.ZodCustom<boolean | ReactCompilerOptions, boolean | ReactCompilerOptions>>;
|
|
56
47
|
codegen: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
userEventSignals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
49
|
+
elements: z.ZodOptional<z.ZodObject<{
|
|
50
|
+
behaviors: z.ZodOptional<z.ZodString>;
|
|
51
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
52
|
+
component: z.ZodOptional<z.ZodObject<{
|
|
53
|
+
module: z.ZodString;
|
|
54
|
+
export: z.ZodString;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
props: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
module: z.ZodString;
|
|
58
|
+
export: z.ZodString;
|
|
59
|
+
}, z.core.$strip>>;
|
|
60
|
+
lazy: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
}, z.core.$strip>>>;
|
|
62
|
+
}, z.core.$strip>>;
|
|
57
63
|
}, z.core.$strip>;
|
|
58
|
-
/**
|
|
59
|
-
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
|
|
60
|
-
* the GIR libraries to bind, extra `.gir` search paths, the GApplication id,
|
|
61
|
-
* custom element prop mappings, and the React Compiler and codegen settings.
|
|
62
|
-
*/
|
|
63
|
-
export type Config = z.infer<typeof configSchema>;
|
|
64
|
-
export declare const validateConfig: (config: Config) => void;
|
|
65
64
|
/**
|
|
66
65
|
* Identity helper that returns the given configuration typed as {@link Config},
|
|
67
66
|
* enabling editor autocompletion and type checking in `gtkx.config.ts`.
|
|
68
67
|
*/
|
|
69
|
-
|
|
68
|
+
declare const defineConfig: DefineConfig<Config>;
|
|
69
|
+
declare const isValidApplicationId: (applicationId: string) => boolean;
|
|
70
|
+
declare const resolveReactCompilerOptions: (setting: Config["reactCompiler"]) => ResolvedReactCompilerOptions | null;
|
|
71
|
+
declare const validateConfig: (config: Config) => void;
|
|
70
72
|
/**
|
|
71
73
|
* Deep-merges two configurations, with `override` taking precedence over `base`.
|
|
72
74
|
* @param base The lower-priority configuration.
|
|
73
75
|
* @param override The higher-priority configuration whose values win on conflict.
|
|
74
76
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*/
|
|
80
|
-
export type ResolvedConfig = {
|
|
81
|
-
applicationId: string;
|
|
82
|
-
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
83
|
-
};
|
|
84
|
-
export declare const resolveConfig: (config: Config) => ResolvedConfig;
|
|
85
|
-
export {};
|
|
77
|
+
declare const mergeConfig: (base: Config, override: Config) => Config;
|
|
78
|
+
declare const resolveLazyElements: (elements: Config["elements"]) => string[];
|
|
79
|
+
declare const resolveConfig: (config: Config, root?: string) => ResolvedConfig;
|
|
80
|
+
export { LIBRARIES_WILDCARD, GIR_LIBRARY_PATTERN, defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveConfig, type ResolvedReactCompilerOptions, type Config, type ResolvedConfig, };
|
|
86
81
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAG5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,KAAK,4BAA4B,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AACvE,KAAK,2BAA2B,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,KAAK,oBAAoB,GAAG;IACxB,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAC/C,cAAc,CAAC,EAAE,2BAA2B,CAAC;CAChD,CAAC;AAEF;;;GAGG;AACH,KAAK,4BAA4B,GAAG,oBAAoB,GAAG;IACvD,MAAM,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF;;;;;;;GAOG;AACH,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAE3C;;;;;GAKG;AACH,KAAK,cAAc,GAAG;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACnD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,QAAA,MAAM,kBAAkB,MAAM,CAAC;AAC/B,QAAA,MAAM,mBAAmB,QAAyC,CAAC;AAGnE,QAAA,MAAM,iBAAiB,mDAAoD,CAAC;AAC5E,QAAA,MAAM,gBAAgB,oDAAqD,CAAC;AAkH5E,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;iBAQhB,CAAC;AAEH;;;GAGG;AACH,QAAA,MAAM,YAAY,EAAE,YAAY,CAAC,MAAM,CAAgC,CAAC;AAsBxE,QAAA,MAAM,oBAAoB,GAAI,eAAe,MAAM,KAAG,OAMrD,CAAC;AAEF,QAAA,MAAM,2BAA2B,GAAI,SAAS,MAAM,CAAC,eAAe,CAAC,KAAG,4BAA4B,GAAG,IAQtG,CAAC;AAKF,QAAA,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,IAMxC,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,KAAG,MAA8B,CAAC;AAUrF,QAAA,MAAM,mBAAmB,GAAI,UAAU,MAAM,CAAC,UAAU,CAAC,KAAG,MAAM,EAGpC,CAAC;AAE/B,QAAA,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,cAMrD,CAAC;AAEH,OAAO,EACH,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,KAAK,4BAA4B,EACjC,KAAK,MAAM,EACX,KAAK,cAAc,GACtB,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,97 +1,145 @@
|
|
|
1
1
|
import { createDefineConfig } from "c12";
|
|
2
2
|
import { defu } from "defu";
|
|
3
|
+
import { resolve } from "node:path";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
import { configError,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { configError, isRecord, rawIssue } from "./config-error.js";
|
|
6
|
+
import { resolveUserEventSignals } from "./user-event-signals.js";
|
|
7
|
+
const LIBRARIES_WILDCARD = "*";
|
|
8
|
+
const GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\d+(?:\.\d+)*$/;
|
|
7
9
|
const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
|
|
8
10
|
const APPLICATION_ID_MAX_LENGTH = 255;
|
|
9
|
-
export const isValidApplicationId = (applicationId) => {
|
|
10
|
-
if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return APPLICATION_ID_PATTERN.test(applicationId);
|
|
14
|
-
};
|
|
15
11
|
const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"];
|
|
16
12
|
const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"];
|
|
17
13
|
const REACT_COMPILER_TARGET = "19";
|
|
18
|
-
export const resolveReactCompilerOptions = (setting) => {
|
|
19
|
-
if (setting === false)
|
|
20
|
-
return null;
|
|
21
|
-
const overrides = setting === undefined || setting === true ? {} : setting;
|
|
22
|
-
return { ...overrides, target: REACT_COMPILER_TARGET };
|
|
23
|
-
};
|
|
24
14
|
const COMPILATION_MODE_SET = new Set(COMPILATION_MODES);
|
|
25
15
|
const PANIC_THRESHOLD_SET = new Set(PANIC_THRESHOLDS);
|
|
26
16
|
const librariesSchema = z.custom().check((ctx) => {
|
|
27
17
|
const value = ctx.value;
|
|
28
|
-
if (value === LIBRARIES_WILDCARD)
|
|
18
|
+
if (value === LIBRARIES_WILDCARD) {
|
|
29
19
|
return;
|
|
20
|
+
}
|
|
30
21
|
if (!Array.isArray(value) || value.length === 0) {
|
|
31
22
|
ctx.issues.push(rawIssue(value, [], `must be "${LIBRARIES_WILDCARD}", a non-empty string array, or omitted`));
|
|
32
23
|
return;
|
|
33
24
|
}
|
|
34
|
-
value.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (entry === LIBRARIES_WILDCARD) {
|
|
38
|
-
ctx.issues.push(rawIssue(value, [index], `to generate every library, set \`libraries: "${LIBRARIES_WILDCARD}"\` as a bare string, not an array entry`, true));
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
ctx.issues.push(rawIssue(value, [index], `invalid library identifier "${String(entry)}", must be of the form "Name-Version" (e.g. "Gtk-4.0")`, true));
|
|
42
|
-
});
|
|
25
|
+
for (const [index, entry] of value.entries()) {
|
|
26
|
+
ctx.issues.push(...libraryEntryIssues(value, index, entry));
|
|
27
|
+
}
|
|
43
28
|
});
|
|
44
29
|
const applicationIdSchema = z.custom().check((ctx) => {
|
|
45
30
|
const value = ctx.value;
|
|
46
31
|
if (typeof value !== "string" || !isValidApplicationId(value)) {
|
|
47
|
-
ctx.issues.push(rawIssue(value, [], `invalid \`applicationId\` "${
|
|
32
|
+
ctx.issues.push(rawIssue(value, [], `invalid \`applicationId\` "${value}", must satisfy g_application_id_is_valid ` +
|
|
33
|
+
'(e.g. "org.example.MyApp")', true));
|
|
48
34
|
}
|
|
49
35
|
});
|
|
50
36
|
const reactCompilerSchema = z.custom().check((ctx) => {
|
|
51
37
|
const value = ctx.value;
|
|
52
|
-
if (typeof value === "boolean")
|
|
38
|
+
if (typeof value === "boolean") {
|
|
53
39
|
return;
|
|
40
|
+
}
|
|
54
41
|
if (!isRecord(value)) {
|
|
55
42
|
ctx.issues.push(rawIssue(value, [], "must be a boolean or an options object"));
|
|
56
43
|
return;
|
|
57
44
|
}
|
|
58
45
|
const compilationMode = value.compilationMode;
|
|
59
|
-
if (compilationMode
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
if (!isValidReactCompilerOption(compilationMode, COMPILATION_MODE_SET)) {
|
|
47
|
+
ctx.issues.push(rawIssue(value, [], `invalid \`reactCompiler.compilationMode\` "${String(compilationMode)}", ` +
|
|
48
|
+
`must be one of ${COMPILATION_MODES.join(", ")}`, true));
|
|
62
49
|
}
|
|
63
50
|
const panicThreshold = value.panicThreshold;
|
|
64
|
-
if (panicThreshold
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
if (!isValidReactCompilerOption(panicThreshold, PANIC_THRESHOLD_SET)) {
|
|
52
|
+
ctx.issues.push(rawIssue(value, [], `invalid \`reactCompiler.panicThreshold\` "${String(panicThreshold)}", ` +
|
|
53
|
+
`must be one of ${PANIC_THRESHOLDS.join(", ")}`, true));
|
|
67
54
|
}
|
|
68
55
|
});
|
|
56
|
+
const userEventSignalsSchema = z.record(z.string(), z.array(z.string({ error: "must be a non-empty signal name" }).min(1, { error: "must be a non-empty signal name" }), {
|
|
57
|
+
error: "must be an array of signal names",
|
|
58
|
+
}), { error: "must be a record of GLib type names to signal name arrays" });
|
|
59
|
+
const moduleExportSchema = z.object({
|
|
60
|
+
module: z.string({ error: "must be a module specifier" }).min(1, { error: "must be a module specifier" }),
|
|
61
|
+
export: z.string({ error: "must be an export name" }).min(1, { error: "must be an export name" }),
|
|
62
|
+
}, { error: "must be a { module, export } object" });
|
|
63
|
+
const elementConfigSchema = z.object({
|
|
64
|
+
component: moduleExportSchema.optional(),
|
|
65
|
+
props: moduleExportSchema.optional(),
|
|
66
|
+
lazy: z.boolean({ error: "must be a boolean" }).optional(),
|
|
67
|
+
});
|
|
68
|
+
const elementsSchema = z.object({
|
|
69
|
+
behaviors: z
|
|
70
|
+
.string({ error: "must be a path to a module exporting element behaviors" })
|
|
71
|
+
.min(1, { error: "must be a path to a module exporting element behaviors" })
|
|
72
|
+
.optional(),
|
|
73
|
+
config: z.record(z.string(), elementConfigSchema).optional(),
|
|
74
|
+
});
|
|
69
75
|
const configSchema = z.object({
|
|
70
76
|
libraries: librariesSchema.optional(),
|
|
71
77
|
girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
|
|
72
78
|
applicationId: applicationIdSchema,
|
|
73
|
-
elementProps: elementPropsSchema.optional(),
|
|
74
79
|
reactCompiler: reactCompilerSchema.optional(),
|
|
75
80
|
codegen: z.boolean({ error: "must be a boolean" }).optional(),
|
|
81
|
+
userEventSignals: userEventSignalsSchema.optional(),
|
|
82
|
+
elements: elementsSchema.optional(),
|
|
76
83
|
});
|
|
77
|
-
export const validateConfig = (config) => {
|
|
78
|
-
const result = configSchema.safeParse(config);
|
|
79
|
-
if (!result.success)
|
|
80
|
-
throw configError(result.error);
|
|
81
|
-
};
|
|
82
84
|
/**
|
|
83
85
|
* Identity helper that returns the given configuration typed as {@link Config},
|
|
84
86
|
* enabling editor autocompletion and type checking in `gtkx.config.ts`.
|
|
85
87
|
*/
|
|
86
|
-
|
|
88
|
+
const defineConfig = createDefineConfig();
|
|
89
|
+
const libraryEntryIssues = (value, index, entry) => {
|
|
90
|
+
if (typeof entry === "string" && GIR_LIBRARY_PATTERN.test(entry)) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
if (entry === LIBRARIES_WILDCARD) {
|
|
94
|
+
const message = `to generate every library, set \`libraries: "${LIBRARIES_WILDCARD}"\` as a bare string, ` +
|
|
95
|
+
"not an array entry";
|
|
96
|
+
return [rawIssue(value, [index], message, true)];
|
|
97
|
+
}
|
|
98
|
+
const message = `invalid library identifier "${String(entry)}", must be of the form "Name-Version" ` +
|
|
99
|
+
'(e.g. "Gtk-4.0")';
|
|
100
|
+
return [rawIssue(value, [index], message, true)];
|
|
101
|
+
};
|
|
102
|
+
const isValidApplicationId = (applicationId) => {
|
|
103
|
+
if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return APPLICATION_ID_PATTERN.test(applicationId);
|
|
107
|
+
};
|
|
108
|
+
const resolveReactCompilerOptions = (setting) => {
|
|
109
|
+
if (setting === false) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const overrides = setting === undefined || setting === true ? {} : setting;
|
|
113
|
+
return { ...overrides, target: REACT_COMPILER_TARGET };
|
|
114
|
+
};
|
|
115
|
+
const isValidReactCompilerOption = (value, allowed) => value === undefined || (typeof value === "string" && allowed.has(value));
|
|
116
|
+
const validateConfig = (config) => {
|
|
117
|
+
const result = configSchema.safeParse(config);
|
|
118
|
+
if (!result.success) {
|
|
119
|
+
throw configError(result.error);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
87
122
|
/**
|
|
88
123
|
* Deep-merges two configurations, with `override` taking precedence over `base`.
|
|
89
124
|
* @param base The lower-priority configuration.
|
|
90
125
|
* @param override The higher-priority configuration whose values win on conflict.
|
|
91
126
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
const mergeConfig = (base, override) => defu(override, base);
|
|
128
|
+
const resolveElementsModule = (behaviors, root) => {
|
|
129
|
+
if (behaviors === undefined) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return root === undefined ? behaviors : resolve(root, behaviors);
|
|
133
|
+
};
|
|
134
|
+
const resolveLazyElements = (elements) => Object.entries(elements?.config ?? {})
|
|
135
|
+
.filter(([, entry]) => entry.lazy === true)
|
|
136
|
+
.map(([type]) => type);
|
|
137
|
+
const resolveConfig = (config, root) => ({
|
|
94
138
|
applicationId: config.applicationId,
|
|
95
139
|
reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
|
|
140
|
+
userEventSignals: resolveUserEventSignals(config.userEventSignals),
|
|
141
|
+
elements: resolveElementsModule(config.elements?.behaviors, root),
|
|
142
|
+
lazyElements: resolveLazyElements(config.elements),
|
|
96
143
|
});
|
|
144
|
+
export { LIBRARIES_WILDCARD, GIR_LIBRARY_PATTERN, defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveConfig, };
|
|
97
145
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,CAAC,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Config, type DefineConfig } from \"c12\";\nimport { defu } from \"defu\";\nimport { z } from \"zod\";\nimport { configError, elementPropsSchema, isRecord, rawIssue } from \"./element-props.js\";\n\nexport const LIBRARIES_WILDCARD = \"*\";\n\nexport const GIR_LIBRARY_PATTERN: RegExp = /^[A-Za-z][A-Za-z0-9]*-\\d+(?:\\.\\d+)*$/;\n\nconst APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*)+$/;\nconst APPLICATION_ID_MAX_LENGTH = 255;\n\nexport const isValidApplicationId = (applicationId: string): boolean => {\n if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {\n return false;\n }\n return APPLICATION_ID_PATTERN.test(applicationId);\n};\n\nconst COMPILATION_MODES = [\"infer\", \"syntax\", \"annotation\", \"all\"] as const;\n\nconst PANIC_THRESHOLDS = [\"none\", \"critical_errors\", \"all_errors\"] as const;\n\ntype ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];\n\ntype ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];\n\ntype ReactCompilerOptions = {\n compilationMode?: ReactCompilerCompilationMode;\n panicThreshold?: ReactCompilerPanicThreshold;\n};\n\n/**\n * React Compiler options resolved for the build, with the compilation target\n * fixed to React 19.\n */\nexport type ResolvedReactCompilerOptions = ReactCompilerOptions & {\n target: \"19\";\n};\n\nconst REACT_COMPILER_TARGET = \"19\";\n\nexport const resolveReactCompilerOptions = (setting: Config[\"reactCompiler\"]): ResolvedReactCompilerOptions | null => {\n if (setting === false) return null;\n const overrides = setting === undefined || setting === true ? {} : setting;\n return { ...overrides, target: REACT_COMPILER_TARGET };\n};\n\nconst COMPILATION_MODE_SET: Set<string> = new Set(COMPILATION_MODES);\n\nconst PANIC_THRESHOLD_SET: Set<string> = new Set(PANIC_THRESHOLDS);\n\nconst librariesSchema = z.custom<typeof LIBRARIES_WILDCARD | string[]>().check((ctx) => {\n const value = ctx.value;\n if (value === LIBRARIES_WILDCARD) return;\n if (!Array.isArray(value) || value.length === 0) {\n ctx.issues.push(rawIssue(value, [], `must be \"${LIBRARIES_WILDCARD}\", a non-empty string array, or omitted`));\n return;\n }\n value.forEach((entry, index) => {\n if (typeof entry === \"string\" && GIR_LIBRARY_PATTERN.test(entry)) return;\n if (entry === LIBRARIES_WILDCARD) {\n ctx.issues.push(\n rawIssue(\n value,\n [index],\n `to generate every library, set \\`libraries: \"${LIBRARIES_WILDCARD}\"\\` as a bare string, not an array entry`,\n true,\n ),\n );\n return;\n }\n ctx.issues.push(\n rawIssue(\n value,\n [index],\n `invalid library identifier \"${String(entry)}\", must be of the form \"Name-Version\" (e.g. \"Gtk-4.0\")`,\n true,\n ),\n );\n });\n});\n\nconst applicationIdSchema = z.custom<string>().check((ctx) => {\n const value = ctx.value;\n if (typeof value !== \"string\" || !isValidApplicationId(value)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`applicationId\\` \"${String(value)}\", must satisfy g_application_id_is_valid (e.g. \"org.example.MyApp\")`,\n true,\n ),\n );\n }\n});\n\nconst reactCompilerSchema = z.custom<boolean | ReactCompilerOptions>().check((ctx) => {\n const value = ctx.value;\n if (typeof value === \"boolean\") return;\n if (!isRecord(value)) {\n ctx.issues.push(rawIssue(value, [], \"must be a boolean or an options object\"));\n return;\n }\n const compilationMode = value.compilationMode;\n if (\n compilationMode !== undefined &&\n !(typeof compilationMode === \"string\" && COMPILATION_MODE_SET.has(compilationMode))\n ) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.compilationMode\\` \"${String(compilationMode)}\", must be one of ${COMPILATION_MODES.join(\", \")}`,\n true,\n ),\n );\n }\n const panicThreshold = value.panicThreshold;\n if (\n panicThreshold !== undefined &&\n !(typeof panicThreshold === \"string\" && PANIC_THRESHOLD_SET.has(panicThreshold))\n ) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.panicThreshold\\` \"${String(panicThreshold)}\", must be one of ${PANIC_THRESHOLDS.join(\", \")}`,\n true,\n ),\n );\n }\n});\n\nconst configSchema = z.object({\n libraries: librariesSchema.optional(),\n girPath: z.array(z.string(), { error: \"must be an array of strings if provided\" }).optional(),\n applicationId: applicationIdSchema,\n elementProps: elementPropsSchema.optional(),\n reactCompiler: reactCompilerSchema.optional(),\n codegen: z.boolean({ error: \"must be a boolean\" }).optional(),\n});\n\n/**\n * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:\n * the GIR libraries to bind, extra `.gir` search paths, the GApplication id,\n * custom element prop mappings, and the React Compiler and codegen settings.\n */\nexport type Config = z.infer<typeof configSchema>;\n\nexport const validateConfig = (config: Config): void => {\n const result = configSchema.safeParse(config);\n if (!result.success) throw configError(result.error);\n};\n\n/**\n * Identity helper that returns the given configuration typed as {@link Config},\n * enabling editor autocompletion and type checking in `gtkx.config.ts`.\n */\nexport const defineConfig: DefineConfig<Config> = createDefineConfig<Config>();\n\n/**\n * Deep-merges two configurations, with `override` taking precedence over `base`.\n * @param base The lower-priority configuration.\n * @param override The higher-priority configuration whose values win on conflict.\n */\nexport const mergeConfig = (base: Config, override: Config): Config => defu(override, base);\n\n/**\n * Configuration reduced to the values needed at runtime: the GApplication\n * identifier and the resolved React Compiler options (`null` when disabled).\n */\nexport type ResolvedConfig = {\n applicationId: string;\n reactCompiler: ResolvedReactCompilerOptions | null;\n};\n\nexport const resolveConfig = (config: Config): ResolvedConfig => ({\n applicationId: config.applicationId,\n reactCompiler: resolveReactCompilerOptions(config.reactCompiler),\n});\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KA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SAAS,EAAE,IAAI,CAAC;IACjE,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC;CACrD,CAAC,CAAC;AAEH,OAAO,EACH,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,aAAa,GAIhB,CAAC","sourcesContent":["import { createDefineConfig, type DefineConfig } from \"c12\";\nimport { defu } from \"defu\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport { configError, isRecord, rawIssue } from \"./config-error.js\";\nimport { resolveUserEventSignals } from \"./user-event-signals.js\";\n\ntype ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];\ntype ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];\n\ntype ReactCompilerOptions = {\n compilationMode?: ReactCompilerCompilationMode;\n panicThreshold?: ReactCompilerPanicThreshold;\n};\n\n/**\n * React Compiler options resolved for the build, with the compilation target\n * fixed to React 19.\n */\ntype ResolvedReactCompilerOptions = ReactCompilerOptions & {\n target: \"19\";\n};\n\n/**\n * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:\n * the GIR libraries to bind, extra `.gir` search paths, the GApplication id,\n * a module of per-element configuration (lazy flags and custom behaviors),\n * per-element component wrappers keyed by GLib type name, the React Compiler and\n * codegen settings, and additional user event signals to suppress during React\n * commits.\n */\ntype Config = z.infer<typeof configSchema>;\n\n/**\n * Configuration reduced to the values needed at runtime: the GApplication\n * identifier, the resolved React Compiler options (`null` when disabled), the\n * user event signals suppressed while a React commit is in progress, and the\n * module path holding per-element configuration (`null` when unset).\n */\ntype ResolvedConfig = {\n applicationId: string;\n reactCompiler: ResolvedReactCompilerOptions | null;\n userEventSignals: Record<string, string[]>;\n elements: string | null;\n lazyElements: string[];\n};\n\nconst LIBRARIES_WILDCARD = \"*\";\nconst GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\\d+(?:\\.\\d+)*$/;\nconst APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*)+$/;\nconst APPLICATION_ID_MAX_LENGTH = 255;\nconst COMPILATION_MODES = [\"infer\", \"syntax\", \"annotation\", \"all\"] as const;\nconst PANIC_THRESHOLDS = [\"none\", \"critical_errors\", \"all_errors\"] as const;\nconst REACT_COMPILER_TARGET = \"19\";\nconst COMPILATION_MODE_SET: Set<string> = new Set(COMPILATION_MODES);\nconst PANIC_THRESHOLD_SET: Set<string> = new Set(PANIC_THRESHOLDS);\n\nconst librariesSchema = z.custom<typeof LIBRARIES_WILDCARD | string[]>().check((ctx) => {\n const value = ctx.value;\n\n if (value === LIBRARIES_WILDCARD) {\n return;\n }\n\n if (!Array.isArray(value) || value.length === 0) {\n ctx.issues.push(rawIssue(value, [], `must be \"${LIBRARIES_WILDCARD}\", a non-empty string array, or omitted`));\n\n return;\n }\n\n for (const [index, entry] of value.entries()) {\n ctx.issues.push(...libraryEntryIssues(value, index, entry));\n }\n});\n\nconst applicationIdSchema = z.custom<string>().check((ctx) => {\n const value = ctx.value;\n\n if (typeof value !== \"string\" || !isValidApplicationId(value)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`applicationId\\` \"${value}\", must satisfy g_application_id_is_valid ` +\n '(e.g. \"org.example.MyApp\")',\n true,\n ),\n );\n }\n});\n\nconst reactCompilerSchema = z.custom<boolean | ReactCompilerOptions>().check((ctx) => {\n const value = ctx.value;\n\n if (typeof value === \"boolean\") {\n return;\n }\n\n if (!isRecord(value)) {\n ctx.issues.push(rawIssue(value, [], \"must be a boolean or an options object\"));\n\n return;\n }\n\n const compilationMode = value.compilationMode;\n\n if (!isValidReactCompilerOption(compilationMode, COMPILATION_MODE_SET)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.compilationMode\\` \"${String(compilationMode)}\", ` +\n `must be one of ${COMPILATION_MODES.join(\", \")}`,\n true,\n ),\n );\n }\n\n const panicThreshold = value.panicThreshold;\n\n if (!isValidReactCompilerOption(panicThreshold, PANIC_THRESHOLD_SET)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.panicThreshold\\` \"${String(panicThreshold)}\", ` +\n `must be one of ${PANIC_THRESHOLDS.join(\", \")}`,\n true,\n ),\n );\n }\n});\n\nconst userEventSignalsSchema = z.record(\n z.string(),\n z.array(\n z.string({ error: \"must be a non-empty signal name\" }).min(1, { error: \"must be a non-empty signal name\" }),\n {\n error: \"must be an array of signal names\",\n },\n ),\n { error: \"must be a record of GLib type names to signal name arrays\" },\n);\n\nconst moduleExportSchema = z.object(\n {\n module: z.string({ error: \"must be a module specifier\" }).min(1, { error: \"must be a module specifier\" }),\n export: z.string({ error: \"must be an export name\" }).min(1, { error: \"must be an export name\" }),\n },\n { error: \"must be a { module, export } object\" },\n);\n\nconst elementConfigSchema = z.object({\n component: moduleExportSchema.optional(),\n props: moduleExportSchema.optional(),\n lazy: z.boolean({ error: \"must be a boolean\" }).optional(),\n});\n\nconst elementsSchema = z.object({\n behaviors: z\n .string({ error: \"must be a path to a module exporting element behaviors\" })\n .min(1, { error: \"must be a path to a module exporting element behaviors\" })\n .optional(),\n config: z.record(z.string(), elementConfigSchema).optional(),\n});\n\nconst configSchema = z.object({\n libraries: librariesSchema.optional(),\n girPath: z.array(z.string(), { error: \"must be an array of strings if provided\" }).optional(),\n applicationId: applicationIdSchema,\n reactCompiler: reactCompilerSchema.optional(),\n codegen: z.boolean({ error: \"must be a boolean\" }).optional(),\n userEventSignals: userEventSignalsSchema.optional(),\n elements: elementsSchema.optional(),\n});\n\n/**\n * Identity helper that returns the given configuration typed as {@link Config},\n * enabling editor autocompletion and type checking in `gtkx.config.ts`.\n */\nconst defineConfig: DefineConfig<Config> = createDefineConfig<Config>();\n\nconst libraryEntryIssues = (value: unknown[], index: number, entry: unknown): ReturnType<typeof rawIssue>[] => {\n if (typeof entry === \"string\" && GIR_LIBRARY_PATTERN.test(entry)) {\n return [];\n }\n\n if (entry === LIBRARIES_WILDCARD) {\n const message =\n `to generate every library, set \\`libraries: \"${LIBRARIES_WILDCARD}\"\\` as a bare string, ` +\n \"not an array entry\";\n\n return [rawIssue(value, [index], message, true)];\n }\n\n const message =\n `invalid library identifier \"${String(entry)}\", must be of the form \"Name-Version\" ` +\n '(e.g. \"Gtk-4.0\")';\n\n return [rawIssue(value, [index], message, true)];\n};\n\nconst isValidApplicationId = (applicationId: string): boolean => {\n if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {\n return false;\n }\n\n return APPLICATION_ID_PATTERN.test(applicationId);\n};\n\nconst resolveReactCompilerOptions = (setting: Config[\"reactCompiler\"]): ResolvedReactCompilerOptions | null => {\n if (setting === false) {\n return null;\n }\n\n const overrides = setting === undefined || setting === true ? {} : setting;\n\n return { ...overrides, target: REACT_COMPILER_TARGET };\n};\n\nconst isValidReactCompilerOption = (value: unknown, allowed: Set<string>): boolean =>\n value === undefined || (typeof value === \"string\" && allowed.has(value));\n\nconst validateConfig = (config: Config): void => {\n const result = configSchema.safeParse(config);\n\n if (!result.success) {\n throw configError(result.error);\n }\n};\n\n/**\n * Deep-merges two configurations, with `override` taking precedence over `base`.\n * @param base The lower-priority configuration.\n * @param override The higher-priority configuration whose values win on conflict.\n */\nconst mergeConfig = (base: Config, override: Config): Config => defu(override, base);\n\nconst resolveElementsModule = (behaviors: string | undefined, root: string | undefined): string | null => {\n if (behaviors === undefined) {\n return null;\n }\n\n return root === undefined ? behaviors : resolve(root, behaviors);\n};\n\nconst resolveLazyElements = (elements: Config[\"elements\"]): string[] =>\n Object.entries(elements?.config ?? {})\n .filter(([, entry]) => entry.lazy === true)\n .map(([type]) => type);\n\nconst resolveConfig = (config: Config, root?: string): ResolvedConfig => ({\n applicationId: config.applicationId,\n reactCompiler: resolveReactCompilerOptions(config.reactCompiler),\n userEventSignals: resolveUserEventSignals(config.userEventSignals),\n elements: resolveElementsModule(config.elements?.behaviors, root),\n lazyElements: resolveLazyElements(config.elements),\n});\n\nexport {\n LIBRARIES_WILDCARD,\n GIR_LIBRARY_PATTERN,\n defineConfig,\n isValidApplicationId,\n resolveReactCompilerOptions,\n validateConfig,\n mergeConfig,\n resolveLazyElements,\n resolveConfig,\n type ResolvedReactCompilerOptions,\n type Config,\n type ResolvedConfig,\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { type Config, defineConfig, mergeConfig, type ResolvedConfig, type ResolvedReactCompilerOptions, } from "./config.js";
|
|
2
|
-
export type { AppliedProp, Arg, ArgRef, Call, ContainerProp, ControlledTextProp, ElementProp, LazyProp, ListProp, ValueProp, } from "./element-props.js";
|
|
3
2
|
export { type LoadedConfig, loadConfig } from "./loader.js";
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,MAAM,EACX,YAAY,EACZ,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,4BAA4B,GACpC,MAAM,aAAa,CAAC;AACrB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,MAAM,EACX,YAAY,EACZ,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,4BAA4B,GACpC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EACZ,WAAW,GAGd,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EACZ,WAAW,GAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAqB,UAAU,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n type Config,\n defineConfig,\n mergeConfig,\n type ResolvedConfig,\n type ResolvedReactCompilerOptions,\n} from \"./config.js\";\nexport { type LoadedConfig, loadConfig } from \"./loader.js\";\n"]}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD } from "./config.js";
|
|
1
|
+
export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD, resolveLazyElements } from "./config.js";
|
|
2
2
|
export { type ConfigLoader, createConfigLoader } from "./loader.js";
|
|
3
3
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjH,OAAO,EAAE,KAAK,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD } from "./config.js";
|
|
1
|
+
export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD, resolveLazyElements } from "./config.js";
|
|
2
2
|
export { createConfigLoader } from "./loader.js";
|
|
3
3
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjH,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD, resolveLazyElements } from \"./config.js\";\nexport { type ConfigLoader, createConfigLoader } from \"./loader.js\";\n"]}
|
package/dist/loader.d.ts
CHANGED
|
@@ -4,21 +4,22 @@ import { type Config, type ResolvedConfig } from "./config.js";
|
|
|
4
4
|
* resolved config file path (`undefined` when none was found), and the project
|
|
5
5
|
* root it was loaded from.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type LoadedConfig = {
|
|
8
8
|
config: Config;
|
|
9
9
|
configFile: string | undefined;
|
|
10
10
|
root: string;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type LoadConfigOptions = {
|
|
13
13
|
mode?: string | undefined;
|
|
14
14
|
};
|
|
15
|
+
type ConfigLoader = (cwd: string) => Promise<ResolvedConfig>;
|
|
15
16
|
/**
|
|
16
17
|
* Loads and validates the `gtkx.config.ts` file for a project, returning the
|
|
17
18
|
* parsed configuration together with the config file path and project root.
|
|
18
19
|
* @param cwd Directory from which to search for the configuration file.
|
|
19
20
|
* @param options Loading options, such as the environment mode.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export
|
|
22
|
+
declare const loadConfig: (cwd: string, options?: LoadConfigOptions) => Promise<LoadedConfig>;
|
|
23
|
+
declare const createConfigLoader: (options?: LoadConfigOptions) => ConfigLoader;
|
|
24
|
+
export { loadConfig, createConfigLoader, type LoadedConfig, type LoadConfigOptions, type ConfigLoader };
|
|
24
25
|
//# sourceMappingURL=loader.d.ts.map
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,EAAiB,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAE9F;;;;GAIG;AACH,KAAK,YAAY,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7D;;;;;GAKG;AACH,QAAA,MAAM,UAAU,GAAU,KAAK,MAAM,EAAE,UAAS,iBAAsB,KAAG,OAAO,CAAC,YAAY,CAuB5F,CAAC;AAEF,QAAA,MAAM,kBAAkB,GAAI,UAAS,iBAAsB,KAAG,YAqB7D,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,CAAC"}
|
package/dist/loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { loadConfig as loadConfigFile } from "c12";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import { resolve } from "node:path";
|
|
3
|
-
import { loadConfig as loadConfigFile } from "c12";
|
|
4
4
|
import { resolveConfig, validateConfig } from "./config.js";
|
|
5
5
|
/**
|
|
6
6
|
* Loads and validates the `gtkx.config.ts` file for a project, returning the
|
|
@@ -8,7 +8,7 @@ import { resolveConfig, validateConfig } from "./config.js";
|
|
|
8
8
|
* @param cwd Directory from which to search for the configuration file.
|
|
9
9
|
* @param options Loading options, such as the environment mode.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
const loadConfig = async (cwd, options = {}) => {
|
|
12
12
|
const result = await loadConfigFile({
|
|
13
13
|
name: "gtkx",
|
|
14
14
|
cwd,
|
|
@@ -16,24 +16,25 @@ export const loadConfig = async (cwd, options = {}) => {
|
|
|
16
16
|
globalRc: false,
|
|
17
17
|
packageJson: false,
|
|
18
18
|
context: { mode: options.mode },
|
|
19
|
-
...(options.mode !== undefined
|
|
19
|
+
...((options.mode !== undefined) && { envName: options.mode }),
|
|
20
20
|
});
|
|
21
21
|
const config = result.config;
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
22
|
+
const isFound = result.configFile !== undefined && existsSync(resolve(cwd, result.configFile));
|
|
23
|
+
if (isFound) {
|
|
24
24
|
validateConfig(config);
|
|
25
|
+
}
|
|
25
26
|
return {
|
|
26
27
|
config,
|
|
27
|
-
configFile:
|
|
28
|
+
configFile: isFound ? result.configFile : undefined,
|
|
28
29
|
root: result.cwd ?? cwd,
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
+
const createConfigLoader = (options = {}) => {
|
|
32
33
|
const cache = new Map();
|
|
33
34
|
const loadResolved = async (root) => {
|
|
34
35
|
const { config } = await loadConfig(root, options);
|
|
35
36
|
validateConfig(config);
|
|
36
|
-
return resolveConfig(config);
|
|
37
|
+
return resolveConfig(config, root);
|
|
37
38
|
};
|
|
38
39
|
return (cwd) => {
|
|
39
40
|
const root = resolve(cwd);
|
|
@@ -45,4 +46,5 @@ export const createConfigLoader = (options = {}) => {
|
|
|
45
46
|
return pending;
|
|
46
47
|
};
|
|
47
48
|
};
|
|
49
|
+
export { loadConfig, createConfigLoader };
|
|
48
50
|
//# sourceMappingURL=loader.js.map
|