@kidd-cli/config 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Joggr, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ import { i as KiddConfig, n as CompileOptions, r as CompileTarget, t as BuildOptions } from "./types-DZWypERH.js";
2
+ import { Tagged } from "@kidd-cli/utils/tag";
3
+
4
+ //#region src/define-config.d.ts
5
+ /**
6
+ * Type-safe helper for kidd.config.ts.
7
+ *
8
+ * Tags the config with `'KiddConfig'` so consumers can verify
9
+ * it was created through `defineConfig` at runtime via `hasTag`.
10
+ *
11
+ * @param config - The build configuration object.
12
+ * @returns A tagged copy of the config.
13
+ */
14
+ declare function defineConfig(config: KiddConfig): Tagged<KiddConfig, "KiddConfig">;
15
+ //#endregion
16
+ export { type BuildOptions, type CompileOptions, type CompileTarget, type KiddConfig, defineConfig };
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/define-config.ts"],"mappings":";;;;;;AAcA;;;;;;;iBAAgB,YAAA,CAAa,MAAA,EAAQ,UAAA,GAAa,MAAA,CAAO,UAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import { withTag } from "@kidd-cli/utils/tag";
2
+
3
+ //#region src/define-config.ts
4
+ /**
5
+ * Type-safe helper for kidd.config.ts.
6
+ *
7
+ * Tags the config with `'KiddConfig'` so consumers can verify
8
+ * it was created through `defineConfig` at runtime via `hasTag`.
9
+ *
10
+ * @param config - The build configuration object.
11
+ * @returns A tagged copy of the config.
12
+ */
13
+ function defineConfig(config) {
14
+ return withTag(config, "KiddConfig");
15
+ }
16
+
17
+ //#endregion
18
+ export { defineConfig };
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/define-config.ts"],"sourcesContent":["import type { Tagged } from '@kidd-cli/utils/tag'\nimport { withTag } from '@kidd-cli/utils/tag'\n\nimport type { KiddConfig } from './types.js'\n\n/**\n * Type-safe helper for kidd.config.ts.\n *\n * Tags the config with `'KiddConfig'` so consumers can verify\n * it was created through `defineConfig` at runtime via `hasTag`.\n *\n * @param config - The build configuration object.\n * @returns A tagged copy of the config.\n */\nexport function defineConfig(config: KiddConfig): Tagged<KiddConfig, 'KiddConfig'> {\n return withTag(config, 'KiddConfig')\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,aAAa,QAAsD;AACjF,QAAO,QAAQ,QAAQ,aAAa"}
@@ -0,0 +1,63 @@
1
+ import { i as KiddConfig } from "./types-DZWypERH.js";
2
+ import { Tagged } from "@kidd-cli/utils/tag";
3
+ import { AsyncResult, Result } from "@kidd-cli/utils";
4
+ import { z } from "zod";
5
+
6
+ //#region src/schema.d.ts
7
+ /**
8
+ * Zod schema validating the {@link KiddConfig} shape.
9
+ */
10
+ declare const KiddConfigSchema: z.ZodType<KiddConfig>;
11
+ /**
12
+ * Validate arbitrary data against the {@link KiddConfigSchema}.
13
+ *
14
+ * @param data - The unknown value to validate.
15
+ * @returns A Result tuple - `[null, KiddConfig]` on success or `[Error, null]` on failure.
16
+ */
17
+ declare function validateConfig(data: unknown): Result<KiddConfig, Error>;
18
+ //#endregion
19
+ //#region src/loader.d.ts
20
+ /**
21
+ * Options for loading a kidd build config.
22
+ */
23
+ interface LoadConfigOptions {
24
+ /**
25
+ * Working directory to search from.
26
+ */
27
+ readonly cwd?: string;
28
+ /**
29
+ * Default values merged under the loaded config.
30
+ */
31
+ readonly defaults?: Partial<KiddConfig>;
32
+ /**
33
+ * Override values merged over the loaded config.
34
+ */
35
+ readonly overrides?: Partial<KiddConfig>;
36
+ }
37
+ /**
38
+ * Successful result of loading a kidd build config.
39
+ */
40
+ interface LoadConfigResult {
41
+ /**
42
+ * The validated and tagged build config.
43
+ */
44
+ readonly config: Tagged<KiddConfig, "KiddConfig">;
45
+ /**
46
+ * Path to the resolved config file, or `undefined` when none was found.
47
+ */
48
+ readonly configFile: string | undefined;
49
+ }
50
+ /**
51
+ * Load and validate a `kidd.config.ts` file using c12.
52
+ *
53
+ * Searches for a config file named `kidd` (e.g. `kidd.config.ts`, `kidd.config.mts`)
54
+ * in the given working directory, validates it against the build config schema,
55
+ * and returns a tagged config object.
56
+ *
57
+ * @param options - Optional loader configuration.
58
+ * @returns A Result tuple - `[null, LoadConfigResult]` on success or `[Error, null]` on failure.
59
+ */
60
+ declare function loadConfig(options?: LoadConfigOptions): AsyncResult<LoadConfigResult, Error>;
61
+ //#endregion
62
+ export { KiddConfigSchema, LoadConfigOptions, LoadConfigResult, loadConfig, validateConfig };
63
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","names":[],"sources":["../src/schema.ts","../src/loader.ts"],"mappings":";;;;;;;;;cA+Ca,gBAAA,EAAkB,CAAA,CAAE,OAAA,CAAQ,UAAA;;;;;;;iBAgBzB,cAAA,CAAe,IAAA,YAAgB,MAAA,CAAO,UAAA,EAAY,KAAA;;;;;AAhBlE;UC/BiB,iBAAA;;;;WAIN,GAAA;;;;WAIA,QAAA,GAAW,OAAA,CAAQ,UAAA;EDuCd;;;EAAA,SCnCL,SAAA,GAAY,OAAA,CAAQ,UAAA;AAAA;;;;UAMd,gBAAA;;;;WAIN,MAAA,EAAQ,MAAA,CAAO,UAAA;;;;WAIf,UAAA;AAAA;;;;;;;;;;;iBAaW,UAAA,CACpB,OAAA,GAAU,iBAAA,GACT,WAAA,CAAY,gBAAA,EAAkB,KAAA"}
package/dist/loader.js ADDED
@@ -0,0 +1,96 @@
1
+ import { withTag } from "@kidd-cli/utils/tag";
2
+ import { toErrorMessage } from "@kidd-cli/utils";
3
+ import { err } from "@kidd-cli/utils/fp";
4
+ import { loadConfig as loadConfig$1 } from "c12";
5
+ import { attemptAsync } from "es-toolkit";
6
+ import { formatZodIssues } from "@kidd-cli/utils/validate";
7
+ import { z } from "zod";
8
+
9
+ //#region src/schema.ts
10
+ /**
11
+ * @private
12
+ */
13
+ const CompileTargetSchema = z.enum([
14
+ "darwin-arm64",
15
+ "darwin-x64",
16
+ "linux-arm64",
17
+ "linux-x64",
18
+ "linux-x64-musl",
19
+ "windows-arm64",
20
+ "windows-x64"
21
+ ]);
22
+ /**
23
+ * @private
24
+ */
25
+ const BuildOptionsSchema = z.object({
26
+ external: z.array(z.string()).optional(),
27
+ minify: z.boolean().optional(),
28
+ out: z.string().optional(),
29
+ sourcemap: z.boolean().optional(),
30
+ target: z.string().optional()
31
+ }).strict();
32
+ /**
33
+ * @private
34
+ */
35
+ const CompileOptionsSchema = z.object({
36
+ name: z.string().optional(),
37
+ out: z.string().optional(),
38
+ targets: z.array(CompileTargetSchema).optional()
39
+ }).strict();
40
+ /**
41
+ * Zod schema validating the {@link KiddConfig} shape.
42
+ */
43
+ const KiddConfigSchema = z.object({
44
+ build: BuildOptionsSchema.optional(),
45
+ commands: z.string().optional(),
46
+ compile: z.union([z.boolean(), CompileOptionsSchema]).optional(),
47
+ entry: z.string().optional(),
48
+ include: z.array(z.string()).optional()
49
+ }).strict();
50
+ /**
51
+ * Validate arbitrary data against the {@link KiddConfigSchema}.
52
+ *
53
+ * @param data - The unknown value to validate.
54
+ * @returns A Result tuple - `[null, KiddConfig]` on success or `[Error, null]` on failure.
55
+ */
56
+ function validateConfig(data) {
57
+ const result = KiddConfigSchema.safeParse(data);
58
+ if (!result.success) {
59
+ const { message } = formatZodIssues(result.error.issues);
60
+ return err(`Invalid kidd config:\n ${message}`);
61
+ }
62
+ return [null, result.data];
63
+ }
64
+
65
+ //#endregion
66
+ //#region src/loader.ts
67
+ /**
68
+ * Load and validate a `kidd.config.ts` file using c12.
69
+ *
70
+ * Searches for a config file named `kidd` (e.g. `kidd.config.ts`, `kidd.config.mts`)
71
+ * in the given working directory, validates it against the build config schema,
72
+ * and returns a tagged config object.
73
+ *
74
+ * @param options - Optional loader configuration.
75
+ * @returns A Result tuple - `[null, LoadConfigResult]` on success or `[Error, null]` on failure.
76
+ */
77
+ async function loadConfig(options) {
78
+ const { cwd, defaults, overrides } = options ?? {};
79
+ const [loadError, loaded] = await attemptAsync(() => loadConfig$1({
80
+ cwd,
81
+ defaults,
82
+ name: "kidd",
83
+ overrides
84
+ }));
85
+ if (loadError || !loaded) return err(`Failed to load kidd config: ${toErrorMessage(loadError)}`);
86
+ const [validateError, config] = validateConfig(loaded.config);
87
+ if (validateError) return [validateError, null];
88
+ return [null, {
89
+ config: withTag(config, "KiddConfig"),
90
+ configFile: loaded.configFile
91
+ }];
92
+ }
93
+
94
+ //#endregion
95
+ export { KiddConfigSchema, loadConfig, validateConfig };
96
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","names":["c12LoadConfig"],"sources":["../src/schema.ts","../src/loader.ts"],"sourcesContent":["import type { Result } from '@kidd-cli/utils'\nimport { err } from '@kidd-cli/utils/fp'\nimport { formatZodIssues } from '@kidd-cli/utils/validate'\nimport { z } from 'zod'\n\nimport type { KiddConfig } from './types.js'\n\n/**\n * @private\n */\nconst CompileTargetSchema = z.enum([\n 'darwin-arm64',\n 'darwin-x64',\n 'linux-arm64',\n 'linux-x64',\n 'linux-x64-musl',\n 'windows-arm64',\n 'windows-x64',\n])\n\n/**\n * @private\n */\nconst BuildOptionsSchema = z\n .object({\n external: z.array(z.string()).optional(),\n minify: z.boolean().optional(),\n out: z.string().optional(),\n sourcemap: z.boolean().optional(),\n target: z.string().optional(),\n })\n .strict()\n\n/**\n * @private\n */\nconst CompileOptionsSchema = z\n .object({\n name: z.string().optional(),\n out: z.string().optional(),\n targets: z.array(CompileTargetSchema).optional(),\n })\n .strict()\n\n/**\n * Zod schema validating the {@link KiddConfig} shape.\n */\nexport const KiddConfigSchema: z.ZodType<KiddConfig> = z\n .object({\n build: BuildOptionsSchema.optional(),\n commands: z.string().optional(),\n compile: z.union([z.boolean(), CompileOptionsSchema]).optional(),\n entry: z.string().optional(),\n include: z.array(z.string()).optional(),\n })\n .strict()\n\n/**\n * Validate arbitrary data against the {@link KiddConfigSchema}.\n *\n * @param data - The unknown value to validate.\n * @returns A Result tuple - `[null, KiddConfig]` on success or `[Error, null]` on failure.\n */\nexport function validateConfig(data: unknown): Result<KiddConfig, Error> {\n const result = KiddConfigSchema.safeParse(data)\n if (!result.success) {\n const { message } = formatZodIssues(result.error.issues)\n return err(`Invalid kidd config:\\n ${message}`)\n }\n return [null, result.data]\n}\n","import { toErrorMessage } from '@kidd-cli/utils'\nimport type { AsyncResult } from '@kidd-cli/utils'\nimport { err } from '@kidd-cli/utils/fp'\nimport type { Tagged } from '@kidd-cli/utils/tag'\nimport { withTag } from '@kidd-cli/utils/tag'\nimport { loadConfig as c12LoadConfig } from 'c12'\nimport { attemptAsync } from 'es-toolkit'\n\nimport { validateConfig } from './schema.js'\nimport type { KiddConfig } from './types.js'\n\nexport { KiddConfigSchema, validateConfig } from './schema.js'\n\n/**\n * Options for loading a kidd build config.\n */\nexport interface LoadConfigOptions {\n /**\n * Working directory to search from.\n */\n readonly cwd?: string\n /**\n * Default values merged under the loaded config.\n */\n readonly defaults?: Partial<KiddConfig>\n /**\n * Override values merged over the loaded config.\n */\n readonly overrides?: Partial<KiddConfig>\n}\n\n/**\n * Successful result of loading a kidd build config.\n */\nexport interface LoadConfigResult {\n /**\n * The validated and tagged build config.\n */\n readonly config: Tagged<KiddConfig, 'KiddConfig'>\n /**\n * Path to the resolved config file, or `undefined` when none was found.\n */\n readonly configFile: string | undefined\n}\n\n/**\n * Load and validate a `kidd.config.ts` file using c12.\n *\n * Searches for a config file named `kidd` (e.g. `kidd.config.ts`, `kidd.config.mts`)\n * in the given working directory, validates it against the build config schema,\n * and returns a tagged config object.\n *\n * @param options - Optional loader configuration.\n * @returns A Result tuple - `[null, LoadConfigResult]` on success or `[Error, null]` on failure.\n */\nexport async function loadConfig(\n options?: LoadConfigOptions\n): AsyncResult<LoadConfigResult, Error> {\n const { cwd, defaults, overrides } = options ?? {}\n\n const [loadError, loaded] = await attemptAsync(() =>\n c12LoadConfig({\n cwd,\n defaults,\n name: 'kidd',\n overrides,\n })\n )\n\n if (loadError || !loaded) {\n return err(`Failed to load kidd config: ${toErrorMessage(loadError)}`)\n }\n\n const [validateError, config] = validateConfig(loaded.config)\n if (validateError) {\n return [validateError, null]\n }\n\n return [\n null,\n {\n config: withTag(config, 'KiddConfig'),\n configFile: loaded.configFile,\n },\n ]\n}\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,sBAAsB,EAAE,KAAK;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAM,qBAAqB,EACxB,OAAO;CACN,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACxC,QAAQ,EAAE,SAAS,CAAC,UAAU;CAC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EACrC,YAAY,OAAO;EACpB,CACF"}
@@ -0,0 +1,79 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Build options passed to tsdown during `kidd build`.
4
+ */
5
+ interface BuildOptions {
6
+ /**
7
+ * Build output directory. Default: './dist'.
8
+ */
9
+ out?: string;
10
+ /**
11
+ * Node target version. Default: 'node18'.
12
+ */
13
+ target?: string;
14
+ /**
15
+ * Minify the output. Default: false.
16
+ */
17
+ minify?: boolean;
18
+ /**
19
+ * Generate source maps. Default: true.
20
+ */
21
+ sourcemap?: boolean;
22
+ /**
23
+ * Additional external packages (beyond kidd's defaults).
24
+ */
25
+ external?: string[];
26
+ }
27
+ /**
28
+ * Binary compilation options for `kidd compile`.
29
+ */
30
+ interface CompileOptions {
31
+ /**
32
+ * Compile output directory. Default: './dist'.
33
+ */
34
+ out?: string;
35
+ /**
36
+ * Cross-compilation targets. Default: current platform only.
37
+ */
38
+ targets?: CompileTarget[];
39
+ /**
40
+ * Binary name. Defaults to cli name.
41
+ */
42
+ name?: string;
43
+ }
44
+ /**
45
+ * Supported cross-compilation targets for `kidd compile`.
46
+ */
47
+ type CompileTarget = "darwin-arm64" | "darwin-x64" | "linux-x64" | "linux-arm64" | "linux-x64-musl" | "windows-x64" | "windows-arm64";
48
+ /**
49
+ * Configuration for kidd.config.ts.
50
+ */
51
+ interface KiddConfig {
52
+ /**
53
+ * Entry point for the CLI. Default: './index.ts'.
54
+ */
55
+ entry?: string;
56
+ /**
57
+ * Where commands live. Default: './commands'.
58
+ */
59
+ commands?: string;
60
+ /**
61
+ * Build options for kidd build.
62
+ */
63
+ build?: BuildOptions;
64
+ /**
65
+ * Binary compilation options for kidd build --compile.
66
+ *
67
+ * - `true` enables compilation with default options.
68
+ * - An object provides explicit compile options (targets, output dir, name).
69
+ * - `false` or omitted disables compilation.
70
+ */
71
+ compile?: boolean | CompileOptions;
72
+ /**
73
+ * Extra file globs to include in the bundle.
74
+ */
75
+ include?: string[];
76
+ }
77
+ //#endregion
78
+ export { KiddConfig as i, CompileOptions as n, CompileTarget as r, BuildOptions as t };
79
+ //# sourceMappingURL=types-DZWypERH.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DZWypERH.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;AAGA;;UAAiB,YAAA;EAAA;;;EAIf,GAAA;;;;EAIA,MAAA;EAkBF;;;EAdE,MAAA;;;;EAIA,SAAA;;;AA4BF;EAxBE,QAAA;AAAA;;;AAoCF;UA9BiB,cAAA;;;;EAIf,GAAA;;;;EAIA,OAAA,GAAU,aAAA;;;;EAIV,IAAA;AAAA;;;;KAMU,aAAA;;;;UAYK,UAAA;;;;EAIf,KAAA;;;;EAIA,QAAA;;;;EAIA,KAAA,GAAQ,YAAA;;;;;;;;EAQR,OAAA,aAAoB,cAAA;;;;EAIpB,OAAA;AAAA"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@kidd-cli/config",
3
+ "version": "0.1.0",
4
+ "description": "Build-time configuration for kidd CLIs",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./loader": {
16
+ "types": "./dist/loader.d.ts",
17
+ "default": "./dist/loader.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "c12": "4.0.0-beta.3",
22
+ "es-toolkit": "^1.45.0",
23
+ "zod": "^4.3.6",
24
+ "@kidd-cli/utils": "0.1.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^25.3.3",
28
+ "tsdown": "0.21.0-beta.2",
29
+ "typescript": "^5.9.3",
30
+ "vitest": "^4.0.18"
31
+ },
32
+ "scripts": {
33
+ "build": "tsdown",
34
+ "typecheck": "tsgo --noEmit",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest"
37
+ }
38
+ }