@gtkx/config 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,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;AA6B9F;;;;;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;KACjE,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,cAAc,CAAC,MAAM,CAAC,CAAC;IAEvB,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,wDAAwD,GAAG,EAAE,CAAC,CAAC;IACnF,CAAC;IAED,OAAO;QACH,MAAM;QACN,UAAU;QACV,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG;KAC1B,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,UAA6B,EAAE,EAAgB,EAAE;IACzE,MAAM,MAAM,GAAuC,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,EAAwC,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.ts\";\n\n/** Result of loading a project's `gtkx.config.ts` file. */\ntype LoadedConfig = {\n /** The parsed and validated configuration. */\n config: Config;\n /** Absolute path of the configuration file that was loaded. */\n configFile: string;\n /** Absolute path of the project root the configuration was resolved against. */\n root: string;\n};\n\n/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */\ntype LoadConfigOptions = {\n /**\n * Environment name such as `development`: the config's matching `$<mode>` block is layered over the\n * top-level values, and the name is passed to a config authored as a function.\n */\n mode?: string | undefined;\n};\n\n/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */\ntype ConfigLoader = {\n /** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */\n load: (cwd: string) => Promise<LoadedConfig>;\n /** Loads the configuration for the given directory and reduces it to what the build and the app need. */\n resolve: (cwd: string) => Promise<ResolvedConfig>;\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project.\n * @param cwd Directory the configuration file is looked up in.\n * @param options Loading options, such as the environment mode whose overrides are applied.\n * @throws When the configuration fails validation, or when no configuration file is found.\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 ConfigLoader };\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,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,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAe,aAAa,EAAuB,cAAc,EAAE,MAAM,aAAa,CAAC;AA6B9F;;;;;GAKG;AACH,MAAM,UAAU,GAAG,KAAK,EAAE,GAAW,EAAE,UAA6B,EAAE,EAAyB,EAAE;IAC7F,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE9B,MAAM,MAAM,GAAG,MAAM,cAAc,CAAS;QACxC,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,QAAQ;QACb,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;KACjE,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAErC,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;QACzE,MAAM,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,cAAc,CAAC,MAAM,CAAC,CAAC;IAEvB,OAAO;QACH,MAAM;QACN,UAAU;QACV,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,QAAQ;KAC/B,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,UAA6B,EAAE,EAAgB,EAAE;IACzE,MAAM,MAAM,GAAuC,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,EAAwC,CAAC","sourcesContent":["import { getOrInsert } from \"@gtkx/utils\";\nimport { loadConfig as loadConfigFile } from \"c12\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { missingConfigFileError } from \"./config-error.ts\";\nimport { type Config, resolveConfig, type ResolvedConfig, validateConfig } from \"./config.ts\";\n\n/** Result of loading a project's `gtkx.config.ts` file. */\ntype LoadedConfig = {\n /** The parsed and validated configuration. */\n config: Config;\n /** Absolute path of the configuration file that was loaded. */\n configFile: string;\n /** Absolute path of the project root the configuration was resolved against. */\n root: string;\n};\n\n/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */\ntype LoadConfigOptions = {\n /**\n * Environment name such as `development`: the config's matching `$<mode>` block is layered over the\n * top-level values, and the name is passed to a config authored as a function.\n */\n mode?: string | undefined;\n};\n\n/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */\ntype ConfigLoader = {\n /** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */\n load: (cwd: string) => Promise<LoadedConfig>;\n /** Loads the configuration for the given directory and reduces it to what the build and the app need. */\n resolve: (cwd: string) => Promise<ResolvedConfig>;\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project.\n * @param cwd Directory the configuration file is looked up in; parent directories are not searched.\n * @param options Loading options, such as the environment mode whose overrides are applied.\n * @throws When that directory holds no configuration file, or when the configuration fails validation.\n */\nconst loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n const searched = resolve(cwd);\n\n const result = await loadConfigFile<Config>({\n name: \"gtkx\",\n cwd: searched,\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 configFile = result.configFile;\n\n if (configFile === undefined || !existsSync(resolve(searched, configFile))) {\n throw missingConfigFileError(searched);\n }\n\n const config = result.config;\n validateConfig(config);\n\n return {\n config,\n configFile,\n root: result.cwd ?? searched,\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 ConfigLoader };\n"]}
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ declare const text: (message: string) => z.ZodString;
3
+ declare const textList: (itemNoun: string, listMessage: string) => z.ZodArray<z.ZodString>;
4
+ declare const url: (message: string) => z.ZodURL;
5
+ declare const flag: (message: string) => z.ZodBoolean;
6
+ declare const textRecord: (valueMessage: string, recordMessage: string) => z.ZodRecord<z.ZodString, z.ZodString>;
7
+ declare const fileExtension: (message: string) => z.ZodString;
8
+ declare const relativePathRecord: (keyMessage: string, valueMessage: string, recordMessage: string) => z.ZodRecord<z.ZodString, z.ZodString>;
9
+ export { fileExtension, flag, relativePathRecord, text, textList, textRecord, url };
10
+ //# sourceMappingURL=schema-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-text.d.ts","sourceRoot":"","sources":["../src/schema-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,QAAA,MAAM,IAAI,GAAI,SAAS,MAAM,KAAG,CAAC,CAAC,SAAoE,CAAC;AAEvG,QAAA,MAAM,QAAQ,GAAI,UAAU,MAAM,EAAE,aAAa,MAAM,KAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CACJ,CAAC;AAE7E,QAAA,MAAM,GAAG,GAAI,SAAS,MAAM,KAAG,CAAC,CAAC,MAAmC,CAAC;AACrE,QAAA,MAAM,IAAI,GAAI,SAAS,MAAM,KAAG,CAAC,CAAC,UAA2C,CAAC;AAE9E,QAAA,MAAM,UAAU,GAAI,cAAc,MAAM,EAAE,eAAe,MAAM,KAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAChC,CAAC;AAEvE,QAAA,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,CAAC,CAAC,SACuD,CAAC;AAKnG,QAAA,MAAM,kBAAkB,GACpB,YAAY,MAAM,EAClB,cAAc,MAAM,EACpB,eAAe,MAAM,KACtB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAC6C,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ const FILE_EXTENSION = /^[^\s./\\*?[\]]+(?:\.[^\s./\\*?[\]]+)*$/;
3
+ const SEGMENT_SEPARATOR = /[/\\]/;
4
+ const isRelativePath = (value) => {
5
+ if (value.length === 0 || value.startsWith("/") || value.includes("\\")) {
6
+ return false;
7
+ }
8
+ return value.split(SEGMENT_SEPARATOR).every((part) => part !== "" && part !== "..");
9
+ };
10
+ const text = (message) => z.string({ error: message }).min(1, { error: message });
11
+ const textList = (itemNoun, listMessage) => z.array(text(`must be a non-empty ${itemNoun}`), { error: listMessage });
12
+ const url = (message) => z.url({ error: message });
13
+ const flag = (message) => z.boolean({ error: message });
14
+ const textRecord = (valueMessage, recordMessage) => z.record(z.string(), text(valueMessage), { error: recordMessage });
15
+ const fileExtension = (message) => z.string({ error: message }).refine((value) => FILE_EXTENSION.test(value), { error: message });
16
+ const relativePath = (message) => z.string({ error: message }).refine((value) => isRelativePath(value), { error: message });
17
+ const relativePathRecord = (keyMessage, valueMessage, recordMessage) => z.record(relativePath(keyMessage), text(valueMessage), { error: recordMessage });
18
+ export { fileExtension, flag, relativePathRecord, text, textList, textRecord, url };
19
+ //# sourceMappingURL=schema-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-text.js","sourceRoot":"","sources":["../src/schema-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,yCAAyC,CAAC;AACjE,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAW,EAAE;IAC9C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC;AACxF,CAAC,CAAC;AAEF,MAAM,IAAI,GAAG,CAAC,OAAe,EAAe,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAEvG,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAE,WAAmB,EAA2B,EAAE,CAChF,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,uBAAuB,QAAQ,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;AAE7E,MAAM,GAAG,GAAG,CAAC,OAAe,EAAY,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AACrE,MAAM,IAAI,GAAG,CAAC,OAAe,EAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAE9E,MAAM,UAAU,GAAG,CAAC,YAAoB,EAAE,aAAqB,EAAyC,EAAE,CACtG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;AAEvE,MAAM,aAAa,GAAG,CAAC,OAAe,EAAe,EAAE,CACnD,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAEnG,MAAM,YAAY,GAAG,CAAC,OAAe,EAAe,EAAE,CAClD,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAE9F,MAAM,kBAAkB,GAAG,CACvB,UAAkB,EAClB,YAAoB,EACpB,aAAqB,EACgB,EAAE,CACvC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC","sourcesContent":["import { z } from \"zod\";\n\nconst FILE_EXTENSION = /^[^\\s./\\\\*?[\\]]+(?:\\.[^\\s./\\\\*?[\\]]+)*$/;\nconst SEGMENT_SEPARATOR = /[/\\\\]/;\n\nconst isRelativePath = (value: string): boolean => {\n if (value.length === 0 || value.startsWith(\"/\") || value.includes(\"\\\\\")) {\n return false;\n }\n\n return value.split(SEGMENT_SEPARATOR).every((part) => part !== \"\" && part !== \"..\");\n};\n\nconst text = (message: string): z.ZodString => z.string({ error: message }).min(1, { error: message });\n\nconst textList = (itemNoun: string, listMessage: string): z.ZodArray<z.ZodString> =>\n z.array(text(`must be a non-empty ${itemNoun}`), { error: listMessage });\n\nconst url = (message: string): z.ZodURL => z.url({ error: message });\nconst flag = (message: string): z.ZodBoolean => z.boolean({ error: message });\n\nconst textRecord = (valueMessage: string, recordMessage: string): z.ZodRecord<z.ZodString, z.ZodString> =>\n z.record(z.string(), text(valueMessage), { error: recordMessage });\n\nconst fileExtension = (message: string): z.ZodString =>\n z.string({ error: message }).refine((value) => FILE_EXTENSION.test(value), { error: message });\n\nconst relativePath = (message: string): z.ZodString =>\n z.string({ error: message }).refine((value) => isRelativePath(value), { error: message });\n\nconst relativePathRecord = (\n keyMessage: string,\n valueMessage: string,\n recordMessage: string,\n): z.ZodRecord<z.ZodString, z.ZodString> =>\n z.record(relativePath(keyMessage), text(valueMessage), { error: recordMessage });\n\nexport { fileExtension, flag, relativePathRecord, text, textList, textRecord, url };\n"]}
@@ -1,4 +1,3 @@
1
- declare const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]>;
2
1
  declare const resolveUserEventSignals: (overrides: Record<string, string[]> | undefined) => Record<string, string[]>;
3
- export { DEFAULT_USER_EVENT_SIGNALS, resolveUserEventSignals };
2
+ export { resolveUserEventSignals };
4
3
  //# sourceMappingURL=user-event-signals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-event-signals.d.ts","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAqCxD,CAAC;AAEF,QAAA,MAAM,uBAAuB,GAAI,WAAW,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CASzG,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"user-event-signals.d.ts","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAuCA,QAAA,MAAM,uBAAuB,GAAI,WAAW,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CASzG,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -44,5 +44,5 @@ const resolveUserEventSignals = (overrides) => {
44
44
  }
45
45
  return resolved;
46
46
  };
47
- export { DEFAULT_USER_EVENT_SIGNALS, resolveUserEventSignals };
47
+ export { resolveUserEventSignals };
48
48
  //# sourceMappingURL=user-event-signals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-event-signals.js","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,MAAM,0BAA0B,GAA6B;IACzD,cAAc,EAAE,CAAC,UAAU,CAAC;IAC5B,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,iBAAiB,EAAE,CAAC,QAAQ,CAAC;IAC7B,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAC9E,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,aAAa,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC;IAC3C,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,cAAc,EAAE,CAAC,SAAS,CAAC;IAC3B,WAAW,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,aAAa,CAAC;IACtD,cAAc,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;IACjD,UAAU,EAAE,CAAC,2BAA2B,CAAC;IACzC,UAAU,EAAE,CAAC,cAAc,EAAE,uBAAuB,CAAC;IACrD,WAAW,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,CAAC;IAC5E,UAAU,EAAE,CAAC,QAAQ,CAAC;IACtB,QAAQ,EAAE,CAAC,eAAe,CAAC;IAC3B,cAAc,EAAE,CAAC,eAAe,CAAC;IACjC,iBAAiB,EAAE,CAAC,cAAc,CAAC;IACnC,cAAc,EAAE,CAAC,gBAAgB,CAAC;IAClC,iBAAiB,EAAE,CAAC,mBAAmB,CAAC;IACxC,aAAa,EAAE,CAAC,eAAe,CAAC;IAChC,SAAS,EAAE,CAAC,WAAW,CAAC;IACxB,aAAa,EAAE;QACX,WAAW;QACX,SAAS;QACT,cAAc;QACd,qBAAqB;QACrB,kBAAkB;QAClB,aAAa;QACb,cAAc;QACd,UAAU;QACV,kBAAkB;QAClB,YAAY;KACf;IACD,eAAe,EAAE,CAAC,SAAS,CAAC;IAC5B,SAAS,EAAE,CAAC,qBAAqB,CAAC;CACrC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,SAA+C,EAA4B,EAAE;IAC1G,MAAM,QAAQ,GAA6B,EAAE,GAAG,0BAA0B,EAAE,CAAC;IAC7E,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAExD,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,eAAe,EAAE,CAAC;QAChD,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,CAAC","sourcesContent":["const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]> = {\n AdwAlertDialog: [\"response\"],\n AdwCarousel: [\"page-changed\"],\n AdwDialog: [\"closed\"],\n AdwNavigationView: [\"pushed\"],\n AdwTabView: [\"close-page\", \"page-attached\", \"page-detached\", \"page-reordered\"],\n GObject: [\"notify\"],\n GtkAdjustment: [\"changed\", \"value-changed\"],\n GtkCalendar: [\"day-selected\"],\n GtkCheckButton: [\"toggled\"],\n GtkEditable: [\"changed\", \"delete-text\", \"insert-text\"],\n GtkEntryBuffer: [\"deleted-text\", \"inserted-text\"],\n GtkFlowBox: [\"selected-children-changed\"],\n GtkListBox: [\"row-selected\", \"selected-rows-changed\"],\n GtkNotebook: [\"page-added\", \"page-removed\", \"page-reordered\", \"switch-page\"],\n GtkPopover: [\"closed\"],\n GtkRange: [\"value-changed\"],\n GtkScaleButton: [\"value-changed\"],\n GtkScrolledWindow: [\"edge-reached\"],\n GtkSearchEntry: [\"search-changed\"],\n GtkSelectionModel: [\"selection-changed\"],\n GtkSpinButton: [\"value-changed\"],\n GtkSwitch: [\"state-set\"],\n GtkTextBuffer: [\n \"apply-tag\",\n \"changed\",\n \"delete-range\",\n \"insert-child-anchor\",\n \"insert-paintable\",\n \"insert-text\",\n \"mark-deleted\",\n \"mark-set\",\n \"modified-changed\",\n \"remove-tag\",\n ],\n GtkToggleButton: [\"toggled\"],\n GtkWidget: [\"state-flags-changed\"],\n};\n\nconst resolveUserEventSignals = (overrides: Record<string, string[]> | undefined): Record<string, string[]> => {\n const resolved: Record<string, string[]> = { ...DEFAULT_USER_EVENT_SIGNALS };\n const overrideEntries = Object.entries(overrides ?? {});\n\n for (const [typeName, signals] of overrideEntries) {\n resolved[typeName] = [...new Set([...(resolved[typeName] ?? []), ...signals])];\n }\n\n return resolved;\n};\n\nexport { DEFAULT_USER_EVENT_SIGNALS, resolveUserEventSignals };\n"]}
1
+ {"version":3,"file":"user-event-signals.js","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,MAAM,0BAA0B,GAA6B;IACzD,cAAc,EAAE,CAAC,UAAU,CAAC;IAC5B,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,iBAAiB,EAAE,CAAC,QAAQ,CAAC;IAC7B,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAC9E,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,aAAa,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC;IAC3C,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,cAAc,EAAE,CAAC,SAAS,CAAC;IAC3B,WAAW,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,aAAa,CAAC;IACtD,cAAc,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;IACjD,UAAU,EAAE,CAAC,2BAA2B,CAAC;IACzC,UAAU,EAAE,CAAC,cAAc,EAAE,uBAAuB,CAAC;IACrD,WAAW,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,CAAC;IAC5E,UAAU,EAAE,CAAC,QAAQ,CAAC;IACtB,QAAQ,EAAE,CAAC,eAAe,CAAC;IAC3B,cAAc,EAAE,CAAC,eAAe,CAAC;IACjC,iBAAiB,EAAE,CAAC,cAAc,CAAC;IACnC,cAAc,EAAE,CAAC,gBAAgB,CAAC;IAClC,iBAAiB,EAAE,CAAC,mBAAmB,CAAC;IACxC,aAAa,EAAE,CAAC,eAAe,CAAC;IAChC,SAAS,EAAE,CAAC,WAAW,CAAC;IACxB,aAAa,EAAE;QACX,WAAW;QACX,SAAS;QACT,cAAc;QACd,qBAAqB;QACrB,kBAAkB;QAClB,aAAa;QACb,cAAc;QACd,UAAU;QACV,kBAAkB;QAClB,YAAY;KACf;IACD,eAAe,EAAE,CAAC,SAAS,CAAC;IAC5B,SAAS,EAAE,CAAC,qBAAqB,CAAC;CACrC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,SAA+C,EAA4B,EAAE;IAC1G,MAAM,QAAQ,GAA6B,EAAE,GAAG,0BAA0B,EAAE,CAAC;IAC7E,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAExD,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,eAAe,EAAE,CAAC;QAChD,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC","sourcesContent":["const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]> = {\n AdwAlertDialog: [\"response\"],\n AdwCarousel: [\"page-changed\"],\n AdwDialog: [\"closed\"],\n AdwNavigationView: [\"pushed\"],\n AdwTabView: [\"close-page\", \"page-attached\", \"page-detached\", \"page-reordered\"],\n GObject: [\"notify\"],\n GtkAdjustment: [\"changed\", \"value-changed\"],\n GtkCalendar: [\"day-selected\"],\n GtkCheckButton: [\"toggled\"],\n GtkEditable: [\"changed\", \"delete-text\", \"insert-text\"],\n GtkEntryBuffer: [\"deleted-text\", \"inserted-text\"],\n GtkFlowBox: [\"selected-children-changed\"],\n GtkListBox: [\"row-selected\", \"selected-rows-changed\"],\n GtkNotebook: [\"page-added\", \"page-removed\", \"page-reordered\", \"switch-page\"],\n GtkPopover: [\"closed\"],\n GtkRange: [\"value-changed\"],\n GtkScaleButton: [\"value-changed\"],\n GtkScrolledWindow: [\"edge-reached\"],\n GtkSearchEntry: [\"search-changed\"],\n GtkSelectionModel: [\"selection-changed\"],\n GtkSpinButton: [\"value-changed\"],\n GtkSwitch: [\"state-set\"],\n GtkTextBuffer: [\n \"apply-tag\",\n \"changed\",\n \"delete-range\",\n \"insert-child-anchor\",\n \"insert-paintable\",\n \"insert-text\",\n \"mark-deleted\",\n \"mark-set\",\n \"modified-changed\",\n \"remove-tag\",\n ],\n GtkToggleButton: [\"toggled\"],\n GtkWidget: [\"state-flags-changed\"],\n};\n\nconst resolveUserEventSignals = (overrides: Record<string, string[]> | undefined): Record<string, string[]> => {\n const resolved: Record<string, string[]> = { ...DEFAULT_USER_EVENT_SIGNALS };\n const overrideEntries = Object.entries(overrides ?? {});\n\n for (const [typeName, signals] of overrideEntries) {\n resolved[typeName] = [...new Set([...(resolved[typeName] ?? []), ...signals])];\n }\n\n return resolved;\n};\n\nexport { resolveUserEventSignals };\n"]}
@@ -9,8 +9,8 @@ declare const createConfigPlugin: (options: {
9
9
  name: string;
10
10
  /** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
11
11
  loadConfig?: ConfigLoader;
12
- /** Extra Vite configuration contributed from the plugin's `config` hook. */
13
- config?: () => Omit<UserConfig, "plugins">;
12
+ /** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */
13
+ config?: (config: UserConfig) => Omit<UserConfig, "plugins">;
14
14
  }) => Plugin;
15
15
  export default createConfigPlugin;
16
16
  //# sourceMappingURL=vite-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,aAAa,CAAC;AAwBpE;;;GAGG;AACH,QAAA,MAAM,kBAAkB,GAAI,SAAS;IACjC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;CAC9C,KAAG,MAcH,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,aAAa,CAAC;AAwBpE;;;GAGG;AACH,QAAA,MAAM,kBAAkB,GAAI,SAAS;IACjC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,gHAAgH;IAChH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;CAChE,KAAG,MAcH,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -18,7 +18,7 @@ const createConfigPlugin = (options) => {
18
18
  name: options.name,
19
19
  config(config) {
20
20
  state.root = config.root ?? state.root;
21
- return options.config?.();
21
+ return options.config?.(config);
22
22
  },
23
23
  resolveId: (id) => resolveVirtualId(id),
24
24
  load: (id) => loadVirtualModule(id, loadConfig, state),
@@ -1 +1 @@
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;AAQ3G,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;;;GAGG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAO3B,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.ts\";\nimport { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from \"./virtual.ts\";\n\n/** State the plugin carries from Vite's `config` hook to the virtual module it serves. */\ntype PluginState = {\n /** Project root taken from Vite's `config` hook, undefined when the user config leaves it unset. */\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 a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved\n * `gtkx.config.ts`.\n */\nconst createConfigPlugin = (options: {\n /** Name the plugin is registered under in Vite. */\n name: string;\n /** Loader the configuration is resolved through, defaulting to a fresh caching loader. */\n loadConfig?: ConfigLoader;\n /** Extra Vite configuration contributed from the plugin's `config` hook. */\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;AAQ3G,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;;;GAGG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAO3B,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,CAAC,MAAM,CAAC,CAAC;QACpC,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.ts\";\nimport { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from \"./virtual.ts\";\n\n/** State the plugin carries from Vite's `config` hook to the virtual module it serves. */\ntype PluginState = {\n /** Project root taken from Vite's `config` hook, undefined when the user config leaves it unset. */\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 a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved\n * `gtkx.config.ts`.\n */\nconst createConfigPlugin = (options: {\n /** Name the plugin is registered under in Vite. */\n name: string;\n /** Loader the configuration is resolved through, defaulting to a fresh caching loader. */\n loadConfig?: ConfigLoader;\n /** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */\n config?: (config: UserConfig) => 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?.(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",
3
+ "version": "1.2.0",
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",
@@ -44,6 +44,16 @@
44
44
  "dist",
45
45
  "src"
46
46
  ],
47
+ "nx": {
48
+ "targets": {
49
+ "lint": {
50
+ "options": {
51
+ "cwd": ".",
52
+ "command": "eslint {projectRoot}"
53
+ }
54
+ }
55
+ }
56
+ },
47
57
  "engines": {
48
58
  "node": ">=24"
49
59
  },
@@ -52,7 +62,7 @@
52
62
  "defu": "^6.1.7",
53
63
  "vite": "^8.2.1",
54
64
  "zod": "^4.4.3",
55
- "@gtkx/utils": "1.0.0"
65
+ "@gtkx/utils": "1.2.0"
56
66
  },
57
67
  "scripts": {
58
68
  "release": "tsx ../../scripts/release-package.ts"
@@ -3,6 +3,7 @@ import type { z } from "zod";
3
3
  type IssuePath = (string | number)[];
4
4
 
5
5
  const CONFIG_PREFIX = "gtkx.config.ts:";
6
+ const UNRECOGNIZED_KEY_REASON = "is not a recognized key";
6
7
 
7
8
  const isRecord = (value: unknown): value is Record<string, unknown> =>
8
9
  typeof value === "object" && value !== null && !Array.isArray(value);
@@ -37,12 +38,27 @@ const dottedPath = (segments: PropertyKey[]): string => {
37
38
  const isStandaloneIssue = (issue: z.core.$ZodIssue): boolean =>
38
39
  "params" in issue && isRecord(issue.params) && issue.params.standalone === true;
39
40
 
40
- const formatIssue = (issue: z.core.$ZodIssue, fullPath: PropertyKey[]): string => {
41
+ const unrecognizedKeyPath = (issue: z.core.$ZodIssue, fullPath: PropertyKey[]): string | undefined => {
41
42
  if (issue.code === "unrecognized_keys") {
42
43
  const [key] = issue.keys;
43
- const path = dottedPath(key === undefined ? fullPath : [...fullPath, key]);
44
44
 
45
- return `${CONFIG_PREFIX} \`${path}\` is not a recognized key`;
45
+ return dottedPath(key === undefined ? fullPath : [...fullPath, key]);
46
+ }
47
+
48
+ return issue.code === "invalid_key" ? dottedPath(fullPath) : undefined;
49
+ };
50
+
51
+ const keyRejectionReason = (issue: z.core.$ZodIssue): string => {
52
+ const nested = issue.code === "invalid_key" ? issue.issues[0] : undefined;
53
+
54
+ return nested?.code === "custom" ? nested.message : UNRECOGNIZED_KEY_REASON;
55
+ };
56
+
57
+ const formatIssue = (issue: z.core.$ZodIssue, fullPath: PropertyKey[]): string => {
58
+ const unrecognized = unrecognizedKeyPath(issue, fullPath);
59
+
60
+ if (unrecognized !== undefined) {
61
+ return `${CONFIG_PREFIX} \`${unrecognized}\` ${keyRejectionReason(issue)}`;
46
62
  }
47
63
 
48
64
  if (isStandaloneIssue(issue)) {
@@ -54,6 +70,9 @@ const formatIssue = (issue: z.core.$ZodIssue, fullPath: PropertyKey[]): string =
54
70
  return path === "" ? `${CONFIG_PREFIX} ${issue.message}` : `${CONFIG_PREFIX} \`${path}\` ${issue.message}`;
55
71
  };
56
72
 
73
+ const missingConfigFileError = (cwd: string): Error =>
74
+ new Error(`${CONFIG_PREFIX} no configuration file found in ${cwd}`);
75
+
57
76
  const configError = (error: z.ZodError): Error => {
58
77
  const issue = error.issues[0];
59
78
 
@@ -64,4 +83,4 @@ const configError = (error: z.ZodError): Error => {
64
83
  return new Error(formatIssue(issue, issue.path));
65
84
  };
66
85
 
67
- export { isRecord, rawIssue, configError };
86
+ export { isRecord, rawIssue, missingConfigFileError, configError };
package/src/config.ts CHANGED
@@ -3,6 +3,7 @@ import { defu } from "defu";
3
3
  import { resolve } from "node:path";
4
4
  import { z } from "zod";
5
5
  import { configError, isRecord, rawIssue } from "./config-error.ts";
6
+ import { deploySchema } from "./deploy.ts";
6
7
  import { resolveUserEventSignals } from "./user-event-signals.ts";
7
8
 
8
9
  /** Accepted `reactCompiler.compilationMode` values, choosing which functions the compiler processes. */
@@ -29,8 +30,9 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
29
30
 
30
31
  /**
31
32
  * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`: the GIR libraries
32
- * to bind and where to find them, the GApplication id, per-element configuration, and the React
33
- * Compiler, codegen, and user event signal settings.
33
+ * to bind and where to find them, the GApplication id, per-element configuration, the React
34
+ * Compiler, codegen, and user event signal settings, and the `future` block opting into behavior
35
+ * that becomes the default in the next major version.
34
36
  */
35
37
  type Config = z.infer<typeof configSchema>;
36
38
  type ModuleExport = z.infer<typeof moduleExportSchema>;
@@ -179,8 +181,13 @@ const elementsSchema = z.object({
179
181
  config: z.record(z.string(), elementConfigSchema).optional(),
180
182
  });
181
183
 
184
+ const futureSchema = z.object({
185
+ v2ByteArrays: z.boolean({ error: "must be a boolean" }).optional(),
186
+ });
187
+
182
188
  /** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */
183
189
  const configSchema = z.object({
190
+ future: futureSchema.optional(),
184
191
  libraries: librariesSchema.optional(),
185
192
  girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
186
193
  applicationId: applicationIdSchema,
@@ -188,6 +195,7 @@ const configSchema = z.object({
188
195
  codegen: z.boolean({ error: "must be a boolean" }).optional(),
189
196
  userEventSignals: userEventSignalsSchema.optional(),
190
197
  elements: elementsSchema.optional(),
198
+ deploy: deploySchema.optional(),
191
199
  });
192
200
 
193
201
  /**
@@ -294,9 +302,9 @@ const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
294
302
  });
295
303
 
296
304
  export {
305
+ APPLICATION_ID_MAX_LENGTH,
297
306
  defineConfig,
298
307
  isValidApplicationId,
299
- resolveReactCompilerOptions,
300
308
  validateConfig,
301
309
  mergeConfig,
302
310
  resolveLazyElements,
package/src/deploy.ts ADDED
@@ -0,0 +1,260 @@
1
+ import { z } from "zod";
2
+ import { fileExtension, flag, relativePathRecord, text, textList, textRecord, url } from "./schema-text.ts";
3
+
4
+ const APPIMAGE_COMPRESSIONS = ["gzip", "xz", "zstd"] as const;
5
+ const DEB_COMPRESSIONS = ["gzip", "none", "xz", "zstd"] as const;
6
+ const DEB_SIGN_METHODS = ["debsign", "dpkg-sig"] as const;
7
+ const DEB_SIGN_TYPES = ["archive", "maint", "origin"] as const;
8
+ const DEPLOY_TARGET_NAMES = ["appimage", "deb", "flatpak", "rpm"] as const;
9
+ const FLATPAK_MODES = ["prebuilt", "source"] as const;
10
+ const NODE_SOURCES = ["download", "host", "path"] as const;
11
+ const OARS_INTENSITIES = ["intense", "mild", "moderate", "none"] as const;
12
+ const PACKAGE_MANAGERS = ["npm", "pnpm", "yarn"] as const;
13
+ const RELEASE_TYPES = ["development", "snapshot", "stable"] as const;
14
+ const RELEASE_URGENCIES = ["critical", "high", "low", "medium"] as const;
15
+ const RPM_COMPRESSIONS = ["gzip", "lzma", "xz", "zstd"] as const;
16
+
17
+ const URL_KINDS = [
18
+ "bugtracker",
19
+ "contact",
20
+ "contribute",
21
+ "donation",
22
+ "faq",
23
+ "help",
24
+ "translate",
25
+ "vcs-browser",
26
+ ] as const;
27
+
28
+ const BOOLEAN_ERROR = "must be a boolean";
29
+ const EPOCH_ERROR = "must be a non-negative integer";
30
+ const HEX_COLOR_ERROR = "must be a #rrggbb color";
31
+ const HEX_COLOR_PATTERN = /^#[\dA-Fa-f]{6}$/;
32
+ const KEY_FILE_ERROR = "must be a path to a PGP key file";
33
+ const KEY_ID_ERROR = "must be a PGP key id";
34
+ const SCRIPT_ERROR = "must be a path to a shell script";
35
+ const SPDX_ERROR = "must be an SPDX license expression";
36
+ const URL_ERROR = "must be an absolute URL";
37
+ const VERSION_ERROR = "must be a version string";
38
+ const hexColorSchema = z.string({ error: HEX_COLOR_ERROR }).regex(HEX_COLOR_PATTERN, { error: HEX_COLOR_ERROR });
39
+
40
+ const relationsSchema = z.strictObject({
41
+ deb: textList("Debian package relation", "must be an array of Debian package relations").optional(),
42
+ rpm: textList("RPM package relation", "must be an array of RPM package relations").optional(),
43
+ });
44
+
45
+ const developerSchema = z.strictObject({
46
+ id: text("must be a reverse-DNS developer id").optional(),
47
+ name: text("must be a developer or organization name").optional(),
48
+ email: text("must be an email address").optional(),
49
+ });
50
+
51
+ const screenshotSchema = z
52
+ .strictObject({
53
+ url: url("must be an absolute URL to a PNG or JPEG").optional(),
54
+ file: text("must be an image path relative to the project root").optional(),
55
+ caption: text("must be a screenshot caption").optional(),
56
+ isDefault: flag(BOOLEAN_ERROR).optional(),
57
+ })
58
+ .refine((entry) => entry.url !== undefined || entry.file !== undefined, {
59
+ error: "must have either a `url` or a `file`",
60
+ });
61
+
62
+ const releaseSchema = z.strictObject({
63
+ version: text(VERSION_ERROR),
64
+ date: z.iso.date({ error: "must be an ISO date (YYYY-MM-DD)" }),
65
+ type: z.enum(RELEASE_TYPES, { error: "must be one of development, snapshot, stable" }).optional(),
66
+ urgency: z.enum(RELEASE_URGENCIES, { error: "must be one of critical, high, low, medium" }).optional(),
67
+ notes: textList("release note paragraph", "must be an array of release note paragraphs").optional(),
68
+ url: url(URL_ERROR).optional(),
69
+ });
70
+
71
+ const fileAssociationSchema = z.strictObject({
72
+ extension: fileExtension("must be a file extension without a leading dot"),
73
+ mimeType: text("must be a MIME type such as text/plain"),
74
+ description: text("must be a description of the file type").optional(),
75
+ });
76
+
77
+ const desktopActionSchema = z.strictObject({
78
+ name: text("must be an action name"),
79
+ args: textList("argument", "must be an array of arguments appended to Exec").optional(),
80
+ icon: text("must be an icon name").optional(),
81
+ });
82
+
83
+ const brandingSchema = z.strictObject({
84
+ light: hexColorSchema,
85
+ dark: hexColorSchema,
86
+ });
87
+
88
+ const nodeRuntimeSchema = z.strictObject({
89
+ source: z.enum(NODE_SOURCES, { error: "must be one of download, host, path" }).optional(),
90
+ version: text("must be a Node.js version such as 24.19.0").optional(),
91
+ path: text("must be a path to a node binary").optional(),
92
+ shouldStrip: flag(BOOLEAN_ERROR).optional(),
93
+ shouldUseCompileCache: flag(BOOLEAN_ERROR).optional(),
94
+ });
95
+
96
+ const scriptsSchema = z.strictObject({
97
+ preInstall: text(SCRIPT_ERROR).optional(),
98
+ postInstall: text(SCRIPT_ERROR).optional(),
99
+ preRemove: text(SCRIPT_ERROR).optional(),
100
+ postRemove: text(SCRIPT_ERROR).optional(),
101
+ });
102
+
103
+ const debSchema = z.strictObject({
104
+ packageName: text("must be a Debian package name").optional(),
105
+ section: text("must be a Debian archive section").optional(),
106
+ priority: text("must be a Debian priority").optional(),
107
+ compression: z.enum(DEB_COMPRESSIONS, { error: "must be one of gzip, none, xz, zstd" }).optional(),
108
+ fields: textRecord("must be a control field value", "must be a record of control field names to values")
109
+ .optional(),
110
+ });
111
+
112
+ const rpmSchema = z.strictObject({
113
+ packageName: text("must be an RPM package name").optional(),
114
+ group: text("must be an RPM group").optional(),
115
+ compression: z.enum(RPM_COMPRESSIONS, { error: "must be one of gzip, lzma, xz, zstd" }).optional(),
116
+ prefixes: textList("prefix", "must be an array of relocation prefixes").optional(),
117
+ });
118
+
119
+ const appimageSchema = z.strictObject({
120
+ fileName: text("must be an output file name").optional(),
121
+ compression: z.enum(APPIMAGE_COMPRESSIONS, { error: "must be one of gzip, xz, zstd" }).optional(),
122
+ updateInformation: text("must be an AppImage update information string").optional(),
123
+ runtimeFile: text("must be a path to an AppImage runtime file").optional(),
124
+ });
125
+
126
+ const flatpakSourceSchema = z.strictObject({
127
+ url: url("must be an absolute git URL").optional(),
128
+ tag: text("must be a git tag").optional(),
129
+ commit: text("must be a git commit sha").optional(),
130
+ });
131
+
132
+ const flatpakSchema = z.strictObject({
133
+ mode: z.enum(FLATPAK_MODES, { error: 'must be "prebuilt" or "source"' }).optional(),
134
+ runtime: text("must be a runtime id").optional(),
135
+ runtimeVersion: text('must be a runtime branch such as "50"').optional(),
136
+ sdk: text("must be an SDK id").optional(),
137
+ nodeExtension: text("must be a Node SDK extension id").optional(),
138
+ sdkExtensions: textList("SDK extension id", "must be an array of SDK extension ids").optional(),
139
+ base: text("must be a base app id").optional(),
140
+ baseVersion: text("must be a base app version").optional(),
141
+ branch: text("must be a branch name").optional(),
142
+ finishArgs: textList("finish argument", "must be an array of flatpak finish arguments").optional(),
143
+ cleanup: textList("cleanup pattern", "must be an array of cleanup patterns").optional(),
144
+ buildCommands: textList("shell command", "must be an array of shell commands").optional(),
145
+ modules: z.array(z.unknown(), { error: "must be an array of flatpak module objects" }).optional(),
146
+ source: flatpakSourceSchema.optional(),
147
+ packageManager: z.enum(PACKAGE_MANAGERS, { error: "must be one of npm, pnpm, yarn" }).optional(),
148
+ lockfile: text("must be a path to a lockfile").optional(),
149
+ runtimeRepo: url("must be an absolute .flatpakrepo URL").optional(),
150
+ shouldEmitBundle: flag(BOOLEAN_ERROR).optional(),
151
+ shouldInstall: flag(BOOLEAN_ERROR).optional(),
152
+ shouldUseRofilesFuse: flag(BOOLEAN_ERROR).optional(),
153
+ });
154
+
155
+ const debSigningSchema = z.strictObject({
156
+ keyFile: text(KEY_FILE_ERROR),
157
+ keyId: text(KEY_ID_ERROR).optional(),
158
+ method: z.enum(DEB_SIGN_METHODS, { error: 'must be "debsign" or "dpkg-sig"' }).optional(),
159
+ type: z.enum(DEB_SIGN_TYPES, { error: "must be one of archive, maint, origin" }).optional(),
160
+ signer: text("must be a signer name and email").optional(),
161
+ });
162
+
163
+ const rpmSigningSchema = z.strictObject({
164
+ keyFile: text(KEY_FILE_ERROR),
165
+ keyId: text(KEY_ID_ERROR).optional(),
166
+ });
167
+
168
+ const flatpakSigningSchema = z.strictObject({
169
+ gpgKeyId: text("must be a GPG key id"),
170
+ gpgHomeDir: text("must be a path to a GPG home directory").optional(),
171
+ });
172
+
173
+ const appimageSigningSchema = z.strictObject({
174
+ gpgKeyId: text("must be a GPG key id"),
175
+ });
176
+
177
+ const signingSchema = z.strictObject({
178
+ appimage: appimageSigningSchema.optional(),
179
+ deb: debSigningSchema.optional(),
180
+ flatpak: flatpakSigningSchema.optional(),
181
+ rpm: rpmSigningSchema.optional(),
182
+ });
183
+
184
+ const extraRelationsSchema = z.strictObject({
185
+ recommends: relationsSchema.optional(),
186
+ suggests: relationsSchema.optional(),
187
+ provides: relationsSchema.optional(),
188
+ conflicts: relationsSchema.optional(),
189
+ replaces: relationsSchema.optional(),
190
+ breaks: relationsSchema.optional(),
191
+ preDepends: relationsSchema.optional(),
192
+ });
193
+
194
+ const deploySchema = z.strictObject({
195
+ targets: z
196
+ .array(z.enum(DEPLOY_TARGET_NAMES, { error: "must be one of appimage, deb, flatpak, rpm" }), {
197
+ error: "must be an array of deploy targets",
198
+ })
199
+ .optional(),
200
+ outDir: text("must be a directory path relative to the project root").optional(),
201
+ name: text("must be the display name shown in the launcher").optional(),
202
+ genericName: text("must be a generic application name").optional(),
203
+ binaryName: text("must be a kebab-case command name").optional(),
204
+ version: text(VERSION_ERROR).optional(),
205
+ release: text("must be a packaging revision").optional(),
206
+ epoch: z.int({ error: EPOCH_ERROR }).min(0, { error: EPOCH_ERROR }).optional(),
207
+ summary: text("must be a single-line summary without a trailing period").optional(),
208
+ description: textList("description paragraph", "must be an array of description paragraphs").optional(),
209
+ keywords: textList("search keyword", "must be an array of search keywords").optional(),
210
+ categories: textList("freedesktop category", "must be an array of freedesktop categories").optional(),
211
+ mimeTypes: textList("MIME type", "must be an array of MIME types").optional(),
212
+ developer: developerSchema.optional(),
213
+ license: text(SPDX_ERROR).optional(),
214
+ licenseFile: text("must be a path to a license file").optional(),
215
+ metadataLicense: text(SPDX_ERROR).optional(),
216
+ copyright: text("must be a copyright line").optional(),
217
+ homepage: url(URL_ERROR).optional(),
218
+ urls: z
219
+ .partialRecord(z.enum(URL_KINDS), url(URL_ERROR), {
220
+ error: "must be a record of AppStream url kinds to URLs",
221
+ })
222
+ .optional(),
223
+ icons: text("must be a path to an icon theme directory or a single icon file").optional(),
224
+ screenshots: z.array(screenshotSchema, { error: "must be an array of screenshots" }).optional(),
225
+ screenshotBaseUrl: url("must be an absolute base URL").optional(),
226
+ branding: brandingSchema.optional(),
227
+ contentRating: z
228
+ .record(z.string(), z.enum(OARS_INTENSITIES, { error: "must be one of intense, mild, moderate, none" }), {
229
+ error: "must be a record of OARS 1.1 attribute ids to intensities",
230
+ })
231
+ .optional(),
232
+ releases: z.array(releaseSchema, { error: "must be an array of releases" }).optional(),
233
+ execArgs: textList("argument", "must be an array of arguments appended to Exec").optional(),
234
+ fileAssociations: z
235
+ .array(fileAssociationSchema, { error: "must be an array of file associations" })
236
+ .optional(),
237
+ protocols: textList("URL scheme", "must be an array of URL schemes").optional(),
238
+ desktopActions: z
239
+ .record(z.string(), desktopActionSchema, { error: "must be a record of action ids to actions" })
240
+ .optional(),
241
+ desktopEntry: textRecord("must be a desktop entry value", "must be a record of desktop entry keys to values")
242
+ .optional(),
243
+ isDbusActivatable: flag(BOOLEAN_ERROR).optional(),
244
+ extraFiles: relativePathRecord(
245
+ "must be a destination path inside the install prefix, without a leading slash or a .. segment",
246
+ "must be a source path",
247
+ "must be a record of prefix-relative destinations to source paths",
248
+ ).optional(),
249
+ depends: relationsSchema.optional(),
250
+ relations: extraRelationsSchema.optional(),
251
+ scripts: scriptsSchema.optional(),
252
+ node: nodeRuntimeSchema.optional(),
253
+ signing: signingSchema.optional(),
254
+ appimage: appimageSchema.optional(),
255
+ deb: debSchema.optional(),
256
+ flatpak: flatpakSchema.optional(),
257
+ rpm: rpmSchema.optional(),
258
+ });
259
+
260
+ export { deploySchema };
package/src/internal.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type { ResolvedReactCompilerOptions } from "./config.ts";
2
2
  export {
3
+ APPLICATION_ID_MAX_LENGTH,
3
4
  isValidApplicationId,
4
5
  resolveElementComponents,
5
6
  resolveElementProps,
package/src/loader.ts CHANGED
@@ -2,6 +2,7 @@ import { getOrInsert } from "@gtkx/utils";
2
2
  import { loadConfig as loadConfigFile } from "c12";
3
3
  import { existsSync } from "node:fs";
4
4
  import { resolve } from "node:path";
5
+ import { missingConfigFileError } from "./config-error.ts";
5
6
  import { type Config, resolveConfig, type ResolvedConfig, validateConfig } from "./config.ts";
6
7
 
7
8
  /** Result of loading a project's `gtkx.config.ts` file. */
@@ -33,14 +34,16 @@ type ConfigLoader = {
33
34
 
34
35
  /**
35
36
  * Loads and validates the `gtkx.config.ts` file for a project.
36
- * @param cwd Directory the configuration file is looked up in.
37
+ * @param cwd Directory the configuration file is looked up in; parent directories are not searched.
37
38
  * @param options Loading options, such as the environment mode whose overrides are applied.
38
- * @throws When the configuration fails validation, or when no configuration file is found.
39
+ * @throws When that directory holds no configuration file, or when the configuration fails validation.
39
40
  */
40
41
  const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {
42
+ const searched = resolve(cwd);
43
+
41
44
  const result = await loadConfigFile<Config>({
42
45
  name: "gtkx",
43
- cwd,
46
+ cwd: searched,
44
47
  rcFile: false,
45
48
  globalRc: false,
46
49
  packageJson: false,
@@ -48,18 +51,19 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
48
51
  ...((options.mode !== undefined) && { envName: options.mode }),
49
52
  });
50
53
 
51
- const config = result.config;
52
54
  const configFile = result.configFile;
53
- validateConfig(config);
54
55
 
55
- if (configFile === undefined || !existsSync(resolve(cwd, configFile))) {
56
- throw new Error(`gtkx.config.ts: no configuration file was found from ${cwd}`);
56
+ if (configFile === undefined || !existsSync(resolve(searched, configFile))) {
57
+ throw missingConfigFileError(searched);
57
58
  }
58
59
 
60
+ const config = result.config;
61
+ validateConfig(config);
62
+
59
63
  return {
60
64
  config,
61
65
  configFile,
62
- root: result.cwd ?? cwd,
66
+ root: result.cwd ?? searched,
63
67
  };
64
68
  };
65
69