@gtkx/config 1.0.0-rc.2 → 1.0.0-rc.3

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.d.ts CHANGED
@@ -17,11 +17,13 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
17
17
  * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
18
18
  * the GIR libraries to bind, extra `.gir` search paths, the GApplication id,
19
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.
20
+ * per-element component wrappers and omitted props keyed by GLib type name, the
21
+ * React Compiler and codegen settings, additional user event signals to suppress
22
+ * during React commits, and extra GIR records to treat as class structs.
23
23
  */
24
24
  type Config = z.infer<typeof configSchema>;
25
+ /** A `{ module, export }` reference to a named export, as element config entries carry it. */
26
+ type ModuleExport = z.infer<typeof moduleExportSchema>;
25
27
  /**
26
28
  * Configuration reduced to the values needed at runtime: the GApplication
27
29
  * identifier, the resolved React Compiler options (`null` when disabled), the
@@ -35,10 +37,12 @@ type ResolvedConfig = {
35
37
  elements: string | null;
36
38
  lazyElements: string[];
37
39
  };
38
- declare const LIBRARIES_WILDCARD = "*";
39
- declare const GIR_LIBRARY_PATTERN: RegExp;
40
40
  declare const COMPILATION_MODES: readonly ["infer", "syntax", "annotation", "all"];
41
41
  declare const PANIC_THRESHOLDS: readonly ["none", "critical_errors", "all_errors"];
42
+ declare const moduleExportSchema: z.ZodObject<{
43
+ module: z.ZodString;
44
+ export: z.ZodString;
45
+ }, z.core.$strip>;
42
46
  declare const configSchema: z.ZodObject<{
43
47
  libraries: z.ZodOptional<z.ZodCustom<string[] | "*", string[] | "*">>;
44
48
  girPath: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -58,6 +62,7 @@ declare const configSchema: z.ZodObject<{
58
62
  export: z.ZodString;
59
63
  }, z.core.$strip>>;
60
64
  lazy: z.ZodOptional<z.ZodBoolean>;
65
+ omitProps: z.ZodOptional<z.ZodArray<z.ZodString>>;
61
66
  }, z.core.$strip>>>;
62
67
  }, z.core.$strip>>;
63
68
  }, z.core.$strip>;
@@ -76,6 +81,9 @@ declare const validateConfig: (config: Config) => void;
76
81
  */
77
82
  declare const mergeConfig: (base: Config, override: Config) => Config;
78
83
  declare const resolveLazyElements: (elements: Config["elements"]) => string[];
84
+ declare const resolveElementComponents: (elements: Config["elements"]) => Record<string, ModuleExport>;
85
+ declare const resolveElementProps: (elements: Config["elements"]) => Record<string, ModuleExport>;
86
+ declare const resolveOmitProps: (elements: Config["elements"]) => Record<string, string[]>;
79
87
  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, };
88
+ export { defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveElementComponents, resolveElementProps, resolveOmitProps, resolveConfig, type ResolvedReactCompilerOptions, type Config, type ModuleExport, type ResolvedConfig, };
81
89
  //# sourceMappingURL=config.d.ts.map
@@ -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;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,2BAA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nB,gBAAgB,EAChB,aAAa,EACb,KAAK,4BAA4B,EACjC,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,cAAc,GACtB,CAAC"}
package/dist/config.js CHANGED
@@ -64,6 +64,11 @@ const elementConfigSchema = z.object({
64
64
  component: moduleExportSchema.optional(),
65
65
  props: moduleExportSchema.optional(),
66
66
  lazy: z.boolean({ error: "must be a boolean" }).optional(),
67
+ omitProps: z
68
+ .array(z.string({ error: "must be a non-empty property name" }).min(1, {
69
+ error: "must be a non-empty property name",
70
+ }), { error: "must be an array of property names" })
71
+ .optional(),
67
72
  });
68
73
  const elementsSchema = z.object({
69
74
  behaviors: z
@@ -134,6 +139,13 @@ const resolveElementsModule = (behaviors, root) => {
134
139
  const resolveLazyElements = (elements) => Object.entries(elements?.config ?? {})
135
140
  .filter(([, entry]) => entry.lazy === true)
136
141
  .map(([type]) => type);
142
+ const elementEntryValues = (elements, pick) => Object.fromEntries(Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
143
+ const value = pick(entry);
144
+ return value === undefined ? [] : [[type, value]];
145
+ }));
146
+ const resolveElementComponents = (elements) => elementEntryValues(elements, (entry) => entry.component);
147
+ const resolveElementProps = (elements) => elementEntryValues(elements, (entry) => entry.props);
148
+ const resolveOmitProps = (elements) => elementEntryValues(elements, (entry) => entry.omitProps);
137
149
  const resolveConfig = (config, root) => ({
138
150
  applicationId: config.applicationId,
139
151
  reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
@@ -141,5 +153,5 @@ const resolveConfig = (config, root) => ({
141
153
  elements: resolveElementsModule(config.elements?.behaviors, root),
142
154
  lazyElements: resolveLazyElements(config.elements),
143
155
  });
144
- export { LIBRARIES_WILDCARD, GIR_LIBRARY_PATTERN, defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveConfig, };
156
+ export { defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveElementComponents, resolveElementProps, resolveOmitProps, resolveConfig, };
145
157
  //# sourceMappingURL=config.js.map
@@ -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,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AA0ClE,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,mBAAmB,GAAG,sCAAsC,CAAC;AACnE,MAAM,sBAAsB,GAAG,uDAAuD,CAAC;AACvF,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAU,CAAC;AAC5E,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,iBAAiB,EAAE,YAAY,CAAU,CAAC;AAC5E,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,oBAAoB,GAAgB,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;AACrE,MAAM,mBAAmB,GAAgB,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAEnE,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,EAAwC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnF,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IAExB,IAAI,KAAK,KAAK,kBAAkB,EAAE,CAAC;QAC/B,OAAO;IACX,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,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EAAE,CAAC,IAAI,CAAC,CAAC;AAE/B,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,IAAa,EAAkB,EAAE,CAAC,CAAC;IACtE,aAAa,EAAE,MAAM,CAAC,aAAa;IACnC,aAAa,EAAE,2BAA2B,CAAC,MAAM,CAAC,aAAa,CAAC;IAChE,gBAAgB,EAAE,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC;IAClE,QAAQ,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,EAAE,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"]}
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,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AA6ClE,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,mBAAmB,GAAG,sCAAsC,CAAC;AACnE,MAAM,sBAAsB,GAAG,uDAAuD,CAAC;AACvF,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAU,CAAC;AAC5E,MAAM,gBAAgB,GAAG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,EAAgC,EAAE,CAC5F,kBAAkB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAE7D,MAAM,mBAAmB,GAAG,CAAC,QAA4B,EAAgC,EAAE,CACvF,kBAAkB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAEzD,MAAM,gBAAgB,GAAG,CAAC,QAA4B,EAA4B,EAAE,CAChF,kBAAkB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAE7D,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,IAAa,EAAkB,EAAE,CAAC,CAAC;IACtE,aAAa,EAAE,MAAM,CAAC,aAAa;IACnC,aAAa,EAAE,2BAA2B,CAAC,MAAM,CAAC,aAAa,CAAC;IAChE,gBAAgB,EAAE,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC;IAClE,QAAQ,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC;IACjE,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC;CACrD,CAAC,CAAC;AAEH,OAAO,EACH,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GAKhB,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 and omitted props keyed by GLib type name, the\n * React Compiler and codegen settings, additional user event signals to suppress\n * during React commits, and extra GIR records to treat as class structs.\n */\ntype Config = z.infer<typeof configSchema>;\n/** A `{ module, export }` reference to a named export, as element config entries carry it. */\ntype ModuleExport = z.infer<typeof moduleExportSchema>;\ntype ElementConfigEntry = z.infer<typeof elementConfigSchema>;\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 omitProps: z\n .array(\n z.string({ error: \"must be a non-empty property name\" }).min(1, {\n error: \"must be a non-empty property name\",\n }),\n { error: \"must be an array of property names\" },\n )\n .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 elementEntryValues = <T>(\n elements: Config[\"elements\"],\n pick: (entry: ElementConfigEntry) => T | undefined,\n): Record<string, T> =>\n Object.fromEntries(\n Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {\n const value = pick(entry);\n\n return value === undefined ? [] : [[type, value] as const];\n }),\n );\n\nconst resolveElementComponents = (elements: Config[\"elements\"]): Record<string, ModuleExport> =>\n elementEntryValues(elements, (entry) => entry.component);\n\nconst resolveElementProps = (elements: Config[\"elements\"]): Record<string, ModuleExport> =>\n elementEntryValues(elements, (entry) => entry.props);\n\nconst resolveOmitProps = (elements: Config[\"elements\"]): Record<string, string[]> =>\n elementEntryValues(elements, (entry) => entry.omitProps);\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 defineConfig,\n isValidApplicationId,\n resolveReactCompilerOptions,\n validateConfig,\n mergeConfig,\n resolveLazyElements,\n resolveElementComponents,\n resolveElementProps,\n resolveOmitProps,\n resolveConfig,\n type ResolvedReactCompilerOptions,\n type Config,\n type ModuleExport,\n type ResolvedConfig,\n};\n"]}
@@ -1,3 +1,3 @@
1
- export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD, resolveLazyElements } from "./config.js";
1
+ export { isValidApplicationId, resolveElementComponents, resolveElementProps, resolveLazyElements, resolveOmitProps, } from "./config.js";
2
2
  export { type ConfigLoader, createConfigLoader } from "./loader.js";
3
3
  //# sourceMappingURL=internal.d.ts.map
@@ -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,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjH,OAAO,EAAE,KAAK,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GACnB,MAAM,aAAa,CAAC;AACrB,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, resolveLazyElements } from "./config.js";
1
+ export { isValidApplicationId, resolveElementComponents, resolveElementProps, resolveLazyElements, resolveOmitProps, } from "./config.js";
2
2
  export { createConfigLoader } from "./loader.js";
3
3
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
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"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n isValidApplicationId,\n resolveElementComponents,\n resolveElementProps,\n resolveLazyElements,\n resolveOmitProps,\n} from \"./config.js\";\nexport { type ConfigLoader, createConfigLoader } from \"./loader.js\";\n"]}
package/dist/loader.d.ts CHANGED
@@ -1,18 +1,24 @@
1
1
  import { type Config, type ResolvedConfig } from "./config.js";
2
2
  /**
3
3
  * Result of loading a `gtkx.config.ts` file: the parsed configuration, the
4
- * resolved config file path (`undefined` when none was found), and the project
5
- * root it was loaded from.
4
+ * resolved config file path, and the project root it was loaded from.
6
5
  */
7
6
  type LoadedConfig = {
8
7
  config: Config;
9
- configFile: string | undefined;
8
+ configFile: string;
10
9
  root: string;
11
10
  };
12
11
  type LoadConfigOptions = {
13
12
  mode?: string | undefined;
14
13
  };
15
- type ConfigLoader = (cwd: string) => Promise<ResolvedConfig>;
14
+ /**
15
+ * Caching accessor for a project's configuration: `load` yields the validated authored config together with
16
+ * its file path, and `resolve` yields the projection an app needs at runtime.
17
+ */
18
+ type ConfigLoader = {
19
+ load: (cwd: string) => Promise<LoadedConfig>;
20
+ resolve: (cwd: string) => Promise<ResolvedConfig>;
21
+ };
16
22
  /**
17
23
  * Loads and validates the `gtkx.config.ts` file for a project, returning the
18
24
  * parsed configuration together with the config file path and project root.
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAiB,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAE9F;;;GAGG;AACH,KAAK,YAAY,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,KAAK,YAAY,GAAG;IAChB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7C,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,UAAU,GAAU,KAAK,MAAM,EAAE,UAAS,iBAAsB,KAAG,OAAO,CAAC,YAAY,CAwB5F,CAAC;AAEF,QAAA,MAAM,kBAAkB,GAAI,UAAS,iBAAsB,KAAG,YAiB7D,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,CAAC"}
package/dist/loader.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getOrInsert } from "@gtkx/utils";
1
2
  import { loadConfig as loadConfigFile } from "c12";
2
3
  import { existsSync } from "node:fs";
3
4
  import { resolve } from "node:path";
@@ -19,31 +20,28 @@ const loadConfig = async (cwd, options = {}) => {
19
20
  ...((options.mode !== undefined) && { envName: options.mode }),
20
21
  });
21
22
  const config = result.config;
22
- const isFound = result.configFile !== undefined && existsSync(resolve(cwd, result.configFile));
23
- if (isFound) {
24
- validateConfig(config);
23
+ const configFile = result.configFile;
24
+ validateConfig(config);
25
+ if (configFile === undefined || !existsSync(resolve(cwd, configFile))) {
26
+ throw new Error(`gtkx.config.ts: no configuration file was found from ${cwd}`);
25
27
  }
26
28
  return {
27
29
  config,
28
- configFile: isFound ? result.configFile : undefined,
30
+ configFile,
29
31
  root: result.cwd ?? cwd,
30
32
  };
31
33
  };
32
34
  const createConfigLoader = (options = {}) => {
33
- const cache = new Map();
34
- const loadResolved = async (root) => {
35
- const { config } = await loadConfig(root, options);
36
- validateConfig(config);
37
- return resolveConfig(config, root);
35
+ const loaded = new Map();
36
+ const resolved = new Map();
37
+ const load = (cwd) => getOrInsert(loaded, resolve(cwd), (root) => loadConfig(root, options));
38
+ const resolveAt = async (root) => {
39
+ const { config, root: configRoot } = await load(root);
40
+ return resolveConfig(config, configRoot);
38
41
  };
39
- return (cwd) => {
40
- const root = resolve(cwd);
41
- let pending = cache.get(root);
42
- if (!pending) {
43
- pending = loadResolved(root);
44
- cache.set(root, pending);
45
- }
46
- return pending;
42
+ return {
43
+ load,
44
+ resolve: (cwd) => getOrInsert(resolved, resolve(cwd), resolveAt),
47
45
  };
48
46
  };
49
47
  export { loadConfig, createConfigLoader };
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAe,aAAa,EAAuB,cAAc,EAAE,MAAM,aAAa,CAAC;AAmB9F;;;;;GAKG;AACH,MAAM,UAAU,GAAG,KAAK,EAAE,GAAW,EAAE,UAA6B,EAAE,EAAyB,EAAE;IAC7F,MAAM,MAAM,GAAG,MAAM,cAAc,CAAS;QACxC,IAAI,EAAE,MAAM;QACZ,GAAG;QACH,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;QAC/B,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;KACj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EAAgE,CAAC","sourcesContent":["import { loadConfig as loadConfigFile } from \"c12\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { type Config, resolveConfig, type ResolvedConfig, validateConfig } from \"./config.js\";\n\n/**\n * Result of loading a `gtkx.config.ts` file: the parsed configuration, the\n * resolved config file path (`undefined` when none was found), and the project\n * root it was loaded from.\n */\ntype LoadedConfig = {\n config: Config;\n configFile: string | undefined;\n root: string;\n};\n\ntype LoadConfigOptions = {\n mode?: string | undefined;\n};\n\ntype ConfigLoader = (cwd: string) => Promise<ResolvedConfig>;\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project, returning the\n * parsed configuration together with the config file path and project root.\n * @param cwd Directory from which to search for the configuration file.\n * @param options Loading options, such as the environment mode.\n */\nconst loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n const result = await loadConfigFile<Config>({\n name: \"gtkx\",\n cwd,\n rcFile: false,\n globalRc: false,\n packageJson: false,\n context: { mode: options.mode },\n ...((options.mode !== undefined) && { envName: options.mode }),\n });\n\n const config = result.config;\n const isFound = result.configFile !== undefined && existsSync(resolve(cwd, result.configFile));\n\n if (isFound) {\n validateConfig(config);\n }\n\n return {\n config,\n configFile: isFound ? result.configFile : undefined,\n root: result.cwd ?? cwd,\n };\n};\n\nconst createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {\n const cache: Map<string, Promise<ResolvedConfig>> = new Map();\n\n const loadResolved = async (root: string): Promise<ResolvedConfig> => {\n const { config } = await loadConfig(root, options);\n validateConfig(config);\n\n return resolveConfig(config, root);\n };\n\n return (cwd: string): Promise<ResolvedConfig> => {\n const root = resolve(cwd);\n let pending = cache.get(root);\n\n if (!pending) {\n pending = loadResolved(root);\n cache.set(root, pending);\n }\n\n return pending;\n };\n};\n\nexport { loadConfig, createConfigLoader, type LoadedConfig, type LoadConfigOptions, type ConfigLoader };\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader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,IAAI,GAAG,EAAE,CAAC;IAC7D,MAAM,QAAQ,GAAyC,IAAI,GAAG,EAAE,CAAC;IAEjE,MAAM,IAAI,GAAG,CAAC,GAAW,EAAyB,EAAE,CAChD,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAE3E,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAA2B,EAAE;QAC9D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtD,OAAO,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,OAAO;QACH,IAAI;QACJ,OAAO,EAAE,CAAC,GAAW,EAA2B,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC;KACpG,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAgE,CAAC","sourcesContent":["import { getOrInsert } from \"@gtkx/utils\";\nimport { loadConfig as loadConfigFile } from \"c12\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { type Config, resolveConfig, type ResolvedConfig, validateConfig } from \"./config.js\";\n\n/**\n * Result of loading a `gtkx.config.ts` file: the parsed configuration, the\n * resolved config file path, and the project root it was loaded from.\n */\ntype LoadedConfig = {\n config: Config;\n configFile: string;\n root: string;\n};\n\ntype LoadConfigOptions = {\n mode?: string | undefined;\n};\n\n/**\n * Caching accessor for a project's configuration: `load` yields the validated authored config together with\n * its file path, and `resolve` yields the projection an app needs at runtime.\n */\ntype ConfigLoader = {\n load: (cwd: string) => Promise<LoadedConfig>;\n resolve: (cwd: string) => Promise<ResolvedConfig>;\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project, returning the\n * parsed configuration together with the config file path and project root.\n * @param cwd Directory from which to search for the configuration file.\n * @param options Loading options, such as the environment mode.\n */\nconst loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n const result = await loadConfigFile<Config>({\n name: \"gtkx\",\n cwd,\n rcFile: false,\n globalRc: false,\n packageJson: false,\n context: { mode: options.mode },\n ...((options.mode !== undefined) && { envName: options.mode }),\n });\n\n const config = result.config;\n const configFile = result.configFile;\n validateConfig(config);\n\n if (configFile === undefined || !existsSync(resolve(cwd, configFile))) {\n throw new Error(`gtkx.config.ts: no configuration file was found from ${cwd}`);\n }\n\n return {\n config,\n configFile,\n root: result.cwd ?? cwd,\n };\n};\n\nconst createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {\n const loaded: Map<string, Promise<LoadedConfig>> = new Map();\n const resolved: Map<string, Promise<ResolvedConfig>> = new Map();\n\n const load = (cwd: string): Promise<LoadedConfig> =>\n getOrInsert(loaded, resolve(cwd), (root) => loadConfig(root, options));\n\n const resolveAt = async (root: string): Promise<ResolvedConfig> => {\n const { config, root: configRoot } = await load(root);\n\n return resolveConfig(config, configRoot);\n };\n\n return {\n load,\n resolve: (cwd: string): Promise<ResolvedConfig> => getOrInsert(resolved, resolve(cwd), resolveAt),\n };\n};\n\nexport { loadConfig, createConfigLoader, type LoadedConfig, type LoadConfigOptions, type ConfigLoader };\n"]}
@@ -5,7 +5,7 @@ const loadVirtualModule = async (id, loadConfig, state) => {
5
5
  if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {
6
6
  return undefined;
7
7
  }
8
- return renderConfigModule(await loadConfig(state.root ?? process.cwd()));
8
+ return renderConfigModule(await loadConfig.resolve(state.root ?? process.cwd()));
9
9
  };
10
10
  /**
11
11
  * Creates the Vite plugin that resolves and serves the `virtual:gtkx-config`
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AACA,OAA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{ type ConfigLoader, createConfigLoader } from \"./loader.js\";\nimport { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from \"./virtual.js\";\n\ntype PluginState = {\n root: string | undefined;\n};\n\nconst resolveVirtualId = (id: string): string | null =>\n id === GTKX_CONFIG_VIRTUAL_ID ? RESOLVED_GTKX_CONFIG_VIRTUAL_ID : null;\n\nconst loadVirtualModule = async (\n id: string,\n loadConfig: ConfigLoader,\n state: PluginState,\n): Promise<string | undefined> => {\n if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {\n return undefined;\n }\n\n return renderConfigModule(await loadConfig(state.root ?? process.cwd()));\n};\n\n/**\n * Creates the Vite plugin that resolves and serves the `virtual:gtkx-config`\n * module, exposing the JSX metadata and the resolved application ID from the\n * project's configuration.\n * @param options Plugin name, an optional custom {@link ConfigLoader}, and an\n * optional hook returning extra Vite user config.\n */\nconst createConfigPlugin = (options: {\n name: string;\n loadConfig?: ConfigLoader;\n config?: () => Omit<UserConfig, \"plugins\">;\n}): Plugin => {\n const loadConfig = options.loadConfig ?? createConfigLoader();\n const state: PluginState = { root: undefined };\n\n return {\n name: options.name,\n config(config: UserConfig) {\n state.root = config.root ?? state.root;\n\n return options.config?.();\n },\n resolveId: (id: string) => resolveVirtualId(id),\n load: (id: string) => loadVirtualModule(id, loadConfig, state),\n };\n};\n\nexport default createConfigPlugin;\n"]}
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAM3G,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAiB,EAAE,CACnD,EAAE,KAAK,sBAAsB,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,IAAI,CAAC;AAE3E,MAAM,iBAAiB,GAAG,KAAK,EAC3B,EAAU,EACV,UAAwB,EACxB,KAAkB,EACS,EAAE;IAC7B,IAAI,EAAE,KAAK,+BAA+B,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACrF,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAI3B,EAAU,EAAE;IACT,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,kBAAkB,EAAE,CAAC;IAC9D,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAE/C,OAAO;QACH,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,CAAC,MAAkB;YACrB,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;YAEvC,OAAO,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9B,CAAC;QACD,SAAS,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC/C,IAAI,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC;KACjE,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import type { Plugin, UserConfig } from \"vite\";\nimport { type ConfigLoader, createConfigLoader } from \"./loader.js\";\nimport { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from \"./virtual.js\";\n\ntype PluginState = {\n root: string | undefined;\n};\n\nconst resolveVirtualId = (id: string): string | null =>\n id === GTKX_CONFIG_VIRTUAL_ID ? RESOLVED_GTKX_CONFIG_VIRTUAL_ID : null;\n\nconst loadVirtualModule = async (\n id: string,\n loadConfig: ConfigLoader,\n state: PluginState,\n): Promise<string | undefined> => {\n if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {\n return undefined;\n }\n\n return renderConfigModule(await loadConfig.resolve(state.root ?? process.cwd()));\n};\n\n/**\n * Creates the Vite plugin that resolves and serves the `virtual:gtkx-config`\n * module, exposing the JSX metadata and the resolved application ID from the\n * project's configuration.\n * @param options Plugin name, an optional custom {@link ConfigLoader}, and an\n * optional hook returning extra Vite user config.\n */\nconst createConfigPlugin = (options: {\n name: string;\n loadConfig?: ConfigLoader;\n config?: () => Omit<UserConfig, \"plugins\">;\n}): Plugin => {\n const loadConfig = options.loadConfig ?? createConfigLoader();\n const state: PluginState = { root: undefined };\n\n return {\n name: options.name,\n config(config: UserConfig) {\n state.root = config.root ?? state.root;\n\n return options.config?.();\n },\n resolveId: (id: string) => resolveVirtualId(id),\n load: (id: string) => loadVirtualModule(id, loadConfig, state),\n };\n};\n\nexport default createConfigPlugin;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/config",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.3",
4
4
  "description": "gtkx.config.ts schema, loader, and the element-prop mapping language shared across the GTKX toolchain",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -51,7 +51,8 @@
51
51
  "c12": "^3.3.4",
52
52
  "defu": "^6.1.7",
53
53
  "vite": "^8.1.5",
54
- "zod": "^4.4.3"
54
+ "zod": "^4.4.3",
55
+ "@gtkx/utils": "1.0.0-rc.3"
55
56
  },
56
57
  "scripts": {
57
58
  "release": "tsx ../../scripts/release-package.ts"
package/src/config.ts CHANGED
@@ -25,11 +25,14 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
25
25
  * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
26
26
  * the GIR libraries to bind, extra `.gir` search paths, the GApplication id,
27
27
  * a module of per-element configuration (lazy flags and custom behaviors),
28
- * per-element component wrappers keyed by GLib type name, the React Compiler and
29
- * codegen settings, and additional user event signals to suppress during React
30
- * commits.
28
+ * per-element component wrappers and omitted props keyed by GLib type name, the
29
+ * React Compiler and codegen settings, additional user event signals to suppress
30
+ * during React commits, and extra GIR records to treat as class structs.
31
31
  */
32
32
  type Config = z.infer<typeof configSchema>;
33
+ /** A `{ module, export }` reference to a named export, as element config entries carry it. */
34
+ type ModuleExport = z.infer<typeof moduleExportSchema>;
35
+ type ElementConfigEntry = z.infer<typeof elementConfigSchema>;
33
36
 
34
37
  /**
35
38
  * Configuration reduced to the values needed at runtime: the GApplication
@@ -154,6 +157,14 @@ const elementConfigSchema = z.object({
154
157
  component: moduleExportSchema.optional(),
155
158
  props: moduleExportSchema.optional(),
156
159
  lazy: z.boolean({ error: "must be a boolean" }).optional(),
160
+ omitProps: z
161
+ .array(
162
+ z.string({ error: "must be a non-empty property name" }).min(1, {
163
+ error: "must be a non-empty property name",
164
+ }),
165
+ { error: "must be an array of property names" },
166
+ )
167
+ .optional(),
157
168
  });
158
169
 
159
170
  const elementsSchema = z.object({
@@ -249,6 +260,27 @@ const resolveLazyElements = (elements: Config["elements"]): string[] =>
249
260
  .filter(([, entry]) => entry.lazy === true)
250
261
  .map(([type]) => type);
251
262
 
263
+ const elementEntryValues = <T>(
264
+ elements: Config["elements"],
265
+ pick: (entry: ElementConfigEntry) => T | undefined,
266
+ ): Record<string, T> =>
267
+ Object.fromEntries(
268
+ Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
269
+ const value = pick(entry);
270
+
271
+ return value === undefined ? [] : [[type, value] as const];
272
+ }),
273
+ );
274
+
275
+ const resolveElementComponents = (elements: Config["elements"]): Record<string, ModuleExport> =>
276
+ elementEntryValues(elements, (entry) => entry.component);
277
+
278
+ const resolveElementProps = (elements: Config["elements"]): Record<string, ModuleExport> =>
279
+ elementEntryValues(elements, (entry) => entry.props);
280
+
281
+ const resolveOmitProps = (elements: Config["elements"]): Record<string, string[]> =>
282
+ elementEntryValues(elements, (entry) => entry.omitProps);
283
+
252
284
  const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
253
285
  applicationId: config.applicationId,
254
286
  reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
@@ -258,16 +290,18 @@ const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
258
290
  });
259
291
 
260
292
  export {
261
- LIBRARIES_WILDCARD,
262
- GIR_LIBRARY_PATTERN,
263
293
  defineConfig,
264
294
  isValidApplicationId,
265
295
  resolveReactCompilerOptions,
266
296
  validateConfig,
267
297
  mergeConfig,
268
298
  resolveLazyElements,
299
+ resolveElementComponents,
300
+ resolveElementProps,
301
+ resolveOmitProps,
269
302
  resolveConfig,
270
303
  type ResolvedReactCompilerOptions,
271
304
  type Config,
305
+ type ModuleExport,
272
306
  type ResolvedConfig,
273
307
  };
package/src/internal.ts CHANGED
@@ -1,2 +1,8 @@
1
- export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD, resolveLazyElements } from "./config.js";
1
+ export {
2
+ isValidApplicationId,
3
+ resolveElementComponents,
4
+ resolveElementProps,
5
+ resolveLazyElements,
6
+ resolveOmitProps,
7
+ } from "./config.js";
2
8
  export { type ConfigLoader, createConfigLoader } from "./loader.js";
package/src/loader.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { getOrInsert } from "@gtkx/utils";
1
2
  import { loadConfig as loadConfigFile } from "c12";
2
3
  import { existsSync } from "node:fs";
3
4
  import { resolve } from "node:path";
@@ -5,12 +6,11 @@ import { type Config, resolveConfig, type ResolvedConfig, validateConfig } from
5
6
 
6
7
  /**
7
8
  * Result of loading a `gtkx.config.ts` file: the parsed configuration, the
8
- * resolved config file path (`undefined` when none was found), and the project
9
- * root it was loaded from.
9
+ * resolved config file path, and the project root it was loaded from.
10
10
  */
11
11
  type LoadedConfig = {
12
12
  config: Config;
13
- configFile: string | undefined;
13
+ configFile: string;
14
14
  root: string;
15
15
  };
16
16
 
@@ -18,7 +18,14 @@ type LoadConfigOptions = {
18
18
  mode?: string | undefined;
19
19
  };
20
20
 
21
- type ConfigLoader = (cwd: string) => Promise<ResolvedConfig>;
21
+ /**
22
+ * Caching accessor for a project's configuration: `load` yields the validated authored config together with
23
+ * its file path, and `resolve` yields the projection an app needs at runtime.
24
+ */
25
+ type ConfigLoader = {
26
+ load: (cwd: string) => Promise<LoadedConfig>;
27
+ resolve: (cwd: string) => Promise<ResolvedConfig>;
28
+ };
22
29
 
23
30
  /**
24
31
  * Loads and validates the `gtkx.config.ts` file for a project, returning the
@@ -38,39 +45,36 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
38
45
  });
39
46
 
40
47
  const config = result.config;
41
- const isFound = result.configFile !== undefined && existsSync(resolve(cwd, result.configFile));
48
+ const configFile = result.configFile;
49
+ validateConfig(config);
42
50
 
43
- if (isFound) {
44
- validateConfig(config);
51
+ if (configFile === undefined || !existsSync(resolve(cwd, configFile))) {
52
+ throw new Error(`gtkx.config.ts: no configuration file was found from ${cwd}`);
45
53
  }
46
54
 
47
55
  return {
48
56
  config,
49
- configFile: isFound ? result.configFile : undefined,
57
+ configFile,
50
58
  root: result.cwd ?? cwd,
51
59
  };
52
60
  };
53
61
 
54
62
  const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {
55
- const cache: Map<string, Promise<ResolvedConfig>> = new Map();
63
+ const loaded: Map<string, Promise<LoadedConfig>> = new Map();
64
+ const resolved: Map<string, Promise<ResolvedConfig>> = new Map();
56
65
 
57
- const loadResolved = async (root: string): Promise<ResolvedConfig> => {
58
- const { config } = await loadConfig(root, options);
59
- validateConfig(config);
66
+ const load = (cwd: string): Promise<LoadedConfig> =>
67
+ getOrInsert(loaded, resolve(cwd), (root) => loadConfig(root, options));
60
68
 
61
- return resolveConfig(config, root);
62
- };
69
+ const resolveAt = async (root: string): Promise<ResolvedConfig> => {
70
+ const { config, root: configRoot } = await load(root);
63
71
 
64
- return (cwd: string): Promise<ResolvedConfig> => {
65
- const root = resolve(cwd);
66
- let pending = cache.get(root);
67
-
68
- if (!pending) {
69
- pending = loadResolved(root);
70
- cache.set(root, pending);
71
- }
72
+ return resolveConfig(config, configRoot);
73
+ };
72
74
 
73
- return pending;
75
+ return {
76
+ load,
77
+ resolve: (cwd: string): Promise<ResolvedConfig> => getOrInsert(resolved, resolve(cwd), resolveAt),
74
78
  };
75
79
  };
76
80
 
@@ -18,7 +18,7 @@ const loadVirtualModule = async (
18
18
  return undefined;
19
19
  }
20
20
 
21
- return renderConfigModule(await loadConfig(state.root ?? process.cwd()));
21
+ return renderConfigModule(await loadConfig.resolve(state.root ?? process.cwd()));
22
22
  };
23
23
 
24
24
  /**