@kjanat/dreamcli 4.1.0 → 5.0.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/README.md +3 -1
- package/dist/{adapter-YM5QGi3M.d.mts → adapter-DBeedKmD.d.mts} +5 -3
- package/dist/{completion-CUMeOnAz.mjs → completion-Bh-qywmB.mjs} +4 -4
- package/dist/completion.d.mts +1 -11
- package/dist/completion.mjs +1 -1
- package/dist/config-DruA8aFV.mjs +1 -0
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/core-B9YNSJeA.mjs +19 -0
- package/dist/{index-Cap0MA2V.d.mts → index-AIC5Gler.d.mts} +18 -12
- package/dist/{index-BziI2aKc.d.mts → index-BIMjOsR6.d.mts} +316 -53
- package/dist/{index-3l8uj16E.d.mts → index-BidVVmln.d.mts} +51 -11
- package/dist/index-D683D09G.d.mts +129 -0
- package/dist/{index-DWsnGZlx.d.mts → index-DpslpOVV.d.mts} +160 -154
- package/dist/{index-BAj2y70U.d.mts → index-hzYPRc_O.d.mts} +65 -14
- package/dist/{index-Cp9kt2t-.d.mts → index-jq_FJRKt.d.mts} +1 -7
- package/dist/index.d.mts +18 -11
- package/dist/index.mjs +1 -1
- package/dist/json-schema-DF5fXdKQ.mjs +59 -0
- package/dist/json-schema.d.mts +2 -2
- package/dist/json-schema.mjs +1 -1
- package/dist/package-json-fYhxDdWD.mjs +3 -0
- package/dist/prompt.d.mts +32 -5
- package/dist/prompt.mjs +1 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +1 -1
- package/dist/session-Crtzt7LY.mjs +1 -0
- package/dist/terminal-DRsRn4sc.mjs +7 -0
- package/dist/test-prompter-BLNGCOA_.mjs +1 -0
- package/dist/testkit.d.mts +5 -7
- package/dist/testkit.mjs +1 -1
- package/dist/version.d.mts +1 -3
- package/dist/version.mjs +1 -1
- package/dreamcli.schema.json +155 -3
- package/package.json +24 -24
- package/skills/cli-creation/SKILL.md +1 -1
- package/skills/cli-creation/scripts/scaffold_cli.py +12 -4
- package/dist/config-CrlScpYX.mjs +0 -1
- package/dist/core-DvXUolc_.mjs +0 -17
- package/dist/json-schema-DRlrz_IV.mjs +0 -52
- package/dist/package-json-BgE9YjjQ.mjs +0 -3
- package/dist/terminal-C8KTXjv5.mjs +0 -6
- package/dist/test-prompter-v__jT2yG.mjs +0 -1
package/dreamcli.schema.json
CHANGED
|
@@ -62,6 +62,14 @@
|
|
|
62
62
|
"type": "string"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
+
"envAbsolute": {
|
|
66
|
+
"description": "Whether the env source is read exactly as written, outside the CLI-wide\nnamespace set by `CLIBuilder.envPrefix()` (set by `.env(…, { absolute:\ntrue })`). Applies to ArgSchema.envVar and\nArgSchema.envIndexed alike.\n\nDefault: `false`",
|
|
67
|
+
"const": true
|
|
68
|
+
},
|
|
69
|
+
"envIndexed": {
|
|
70
|
+
"$ref": "#/$defs/envIndexed",
|
|
71
|
+
"description": "Indexed environment family read as the env source, set by `.env()` with an\nIndexedEnvBinding (`undefined` otherwise). An arg declares at most\none env source, so this and ArgSchema.envVar are never both set."
|
|
72
|
+
},
|
|
65
73
|
"envVar": {
|
|
66
74
|
"description": "Environment variable name for env resolution.\n\nWhen set and the CLI value is absent, the resolver reads this env var\nand coerces the string to the arg's declared kind.",
|
|
67
75
|
"type": "string"
|
|
@@ -129,6 +137,11 @@
|
|
|
129
137
|
}
|
|
130
138
|
},
|
|
131
139
|
"additionalProperties": false,
|
|
140
|
+
"dependentSchemas": {
|
|
141
|
+
"envAbsolute": {
|
|
142
|
+
"$ref": "#/$defs/envBound"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
132
145
|
"anyOf": [
|
|
133
146
|
{
|
|
134
147
|
"not": {
|
|
@@ -147,7 +160,13 @@
|
|
|
147
160
|
}
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
|
-
]
|
|
163
|
+
],
|
|
164
|
+
"not": {
|
|
165
|
+
"required": [
|
|
166
|
+
"envIndexed",
|
|
167
|
+
"envVar"
|
|
168
|
+
]
|
|
169
|
+
}
|
|
151
170
|
},
|
|
152
171
|
"argElement": {
|
|
153
172
|
"description": "Element schema when `kind === 'keyValue'`.\n\nDescribes the value of each entry, so `arg.keyValue(arg.number())` decodes\n`A=1` to the number `1`. `undefined` leaves entry values as strings.",
|
|
@@ -311,6 +330,14 @@
|
|
|
311
330
|
"description": "Human-readable description for help text.",
|
|
312
331
|
"type": "string"
|
|
313
332
|
},
|
|
333
|
+
"envPrefix": {
|
|
334
|
+
"description": "CLI-wide environment namespace prepended to every relative env binding\n(`undefined` when none is set). `.env('TOKEN')` reads `<envPrefix>TOKEN`;\na binding declared with `{ absolute: true }` is read as written.\n\nSet via the .envPrefix() builder method\nor the `envPrefix` field of CLIDefinition. Fixed when declared, so\nneither manifest name inference nor an inherited invocation name changes it.",
|
|
335
|
+
"type": "string",
|
|
336
|
+
"minLength": 1,
|
|
337
|
+
"not": {
|
|
338
|
+
"pattern": "[={}]"
|
|
339
|
+
}
|
|
340
|
+
},
|
|
314
341
|
"examples": {
|
|
315
342
|
"description": "Usage examples attached to the command.",
|
|
316
343
|
"type": "array",
|
|
@@ -340,6 +367,82 @@
|
|
|
340
367
|
},
|
|
341
368
|
"additionalProperties": false
|
|
342
369
|
},
|
|
370
|
+
"envBound": {
|
|
371
|
+
"anyOf": [
|
|
372
|
+
{
|
|
373
|
+
"required": [
|
|
374
|
+
"envVar"
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
"required": [
|
|
379
|
+
"envIndexed"
|
|
380
|
+
]
|
|
381
|
+
}
|
|
382
|
+
]
|
|
383
|
+
},
|
|
384
|
+
"envIndexed": {
|
|
385
|
+
"description": "A numbered family of environment variables read as one input's env source.\n\nPass it to `.env()` in place of a variable name. The count variable decides\nwhether the env stage supplied a value at all, and how many entries it owns;\na declared entry with a missing member is an error, never a fallback to a\nlater source.",
|
|
386
|
+
"type": "object",
|
|
387
|
+
"required": [
|
|
388
|
+
"count"
|
|
389
|
+
],
|
|
390
|
+
"properties": {
|
|
391
|
+
"count": {
|
|
392
|
+
"description": "Variable holding how many entries the family declares, as a canonical\nnon-negative integer. When it is unset the env source supplies nothing;\n`0` supplies an explicit empty list.",
|
|
393
|
+
"type": "string",
|
|
394
|
+
"minLength": 1,
|
|
395
|
+
"not": {
|
|
396
|
+
"pattern": "[{}=]"
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
"fields": {
|
|
400
|
+
"description": "One variable template per record field, each with `{index}` standing for\nthe zero-based index. Every field is required for every declared entry.",
|
|
401
|
+
"type": "object",
|
|
402
|
+
"minProperties": 1,
|
|
403
|
+
"additionalProperties": {
|
|
404
|
+
"$ref": "#/$defs/envIndexedTemplate"
|
|
405
|
+
},
|
|
406
|
+
"propertyNames": {
|
|
407
|
+
"minLength": 1
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
"value": {
|
|
411
|
+
"$ref": "#/$defs/envIndexedTemplate",
|
|
412
|
+
"description": "Variable template for one entry, with `{index}` standing for the zero-based index."
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
"additionalProperties": false,
|
|
416
|
+
"oneOf": [
|
|
417
|
+
{
|
|
418
|
+
"required": [
|
|
419
|
+
"value"
|
|
420
|
+
],
|
|
421
|
+
"not": {
|
|
422
|
+
"required": [
|
|
423
|
+
"fields"
|
|
424
|
+
]
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
"required": [
|
|
429
|
+
"fields"
|
|
430
|
+
],
|
|
431
|
+
"not": {
|
|
432
|
+
"required": [
|
|
433
|
+
"value"
|
|
434
|
+
]
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
]
|
|
438
|
+
},
|
|
439
|
+
"envIndexedTemplate": {
|
|
440
|
+
"type": "string",
|
|
441
|
+
"pattern": "\\{index\\}",
|
|
442
|
+
"not": {
|
|
443
|
+
"pattern": "="
|
|
444
|
+
}
|
|
445
|
+
},
|
|
343
446
|
"example": {
|
|
344
447
|
"description": "A single usage example shown in help text.",
|
|
345
448
|
"type": "object",
|
|
@@ -432,6 +535,14 @@
|
|
|
432
535
|
"type": "string"
|
|
433
536
|
}
|
|
434
537
|
},
|
|
538
|
+
"envAbsolute": {
|
|
539
|
+
"description": "Whether the env source is read exactly as written, outside the CLI-wide\nnamespace set by `CLIBuilder.envPrefix()` (set by `.env(…, { absolute:\ntrue })`). Applies to FlagSchema.envVar and\nFlagSchema.envIndexed alike.\n\nDefault: `false`",
|
|
540
|
+
"const": true
|
|
541
|
+
},
|
|
542
|
+
"envIndexed": {
|
|
543
|
+
"$ref": "#/$defs/envIndexed",
|
|
544
|
+
"description": "Indexed environment family read as the env source, set by `.env()` with an\nIndexedEnvBinding (`undefined` otherwise). A flag declares at most\none env source, so this and FlagSchema.envVar are never both set."
|
|
545
|
+
},
|
|
435
546
|
"envVar": {
|
|
436
547
|
"description": "Environment variable name for v0.2+ resolution.",
|
|
437
548
|
"type": "string"
|
|
@@ -500,7 +611,18 @@
|
|
|
500
611
|
"type": "string"
|
|
501
612
|
}
|
|
502
613
|
},
|
|
503
|
-
"additionalProperties": false
|
|
614
|
+
"additionalProperties": false,
|
|
615
|
+
"dependentSchemas": {
|
|
616
|
+
"envAbsolute": {
|
|
617
|
+
"$ref": "#/$defs/envBound"
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
"not": {
|
|
621
|
+
"required": [
|
|
622
|
+
"envIndexed",
|
|
623
|
+
"envVar"
|
|
624
|
+
]
|
|
625
|
+
}
|
|
504
626
|
},
|
|
505
627
|
"flagElement": {
|
|
506
628
|
"description": "Element schema when `kind === 'array'` or `kind === 'keyValue'`.",
|
|
@@ -565,6 +687,14 @@
|
|
|
565
687
|
"type": "string"
|
|
566
688
|
}
|
|
567
689
|
},
|
|
690
|
+
"envAbsolute": {
|
|
691
|
+
"description": "Whether the env source is read exactly as written, outside the CLI-wide\nnamespace set by `CLIBuilder.envPrefix()` (set by `.env(…, { absolute:\ntrue })`). Applies to FlagSchema.envVar and\nFlagSchema.envIndexed alike.\n\nDefault: `false`",
|
|
692
|
+
"const": true
|
|
693
|
+
},
|
|
694
|
+
"envIndexed": {
|
|
695
|
+
"$ref": "#/$defs/envIndexed",
|
|
696
|
+
"description": "Indexed environment family read as the env source, set by `.env()` with an\nIndexedEnvBinding (`undefined` otherwise). A flag declares at most\none env source, so this and FlagSchema.envVar are never both set."
|
|
697
|
+
},
|
|
568
698
|
"envVar": {
|
|
569
699
|
"description": "Environment variable name for v0.2+ resolution.",
|
|
570
700
|
"type": "string"
|
|
@@ -700,11 +830,19 @@
|
|
|
700
830
|
"$ref": "#/$defs/choice"
|
|
701
831
|
}
|
|
702
832
|
},
|
|
833
|
+
"empty": {
|
|
834
|
+
"enum": [
|
|
835
|
+
"skip",
|
|
836
|
+
"accept",
|
|
837
|
+
"retry"
|
|
838
|
+
]
|
|
839
|
+
},
|
|
703
840
|
"kind": {
|
|
704
|
-
"description": "The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list",
|
|
841
|
+
"description": "The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'password'` — hidden text input, preserving whitespace\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list",
|
|
705
842
|
"enum": [
|
|
706
843
|
"confirm",
|
|
707
844
|
"input",
|
|
845
|
+
"password",
|
|
708
846
|
"select",
|
|
709
847
|
"multiselect"
|
|
710
848
|
]
|
|
@@ -724,6 +862,12 @@
|
|
|
724
862
|
"placeholder": {
|
|
725
863
|
"description": "Placeholder text shown before user types (informational only).",
|
|
726
864
|
"type": "string"
|
|
865
|
+
},
|
|
866
|
+
"sensitive": {
|
|
867
|
+
"const": true
|
|
868
|
+
},
|
|
869
|
+
"trim": {
|
|
870
|
+
"type": "boolean"
|
|
727
871
|
}
|
|
728
872
|
},
|
|
729
873
|
"additionalProperties": false
|
|
@@ -882,6 +1026,14 @@
|
|
|
882
1026
|
"description": "Program description (shown in root help).",
|
|
883
1027
|
"type": "string"
|
|
884
1028
|
},
|
|
1029
|
+
"envPrefix": {
|
|
1030
|
+
"description": "CLI-wide environment namespace prepended to every relative env binding\n(`undefined` when none is set). `.env('TOKEN')` reads `<envPrefix>TOKEN`;\na binding declared with `{ absolute: true }` is read as written.\n\nSet via the .envPrefix() builder method\nor the `envPrefix` field of CLIDefinition. Fixed when declared, so\nneither manifest name inference nor an inherited invocation name changes it.",
|
|
1031
|
+
"type": "string",
|
|
1032
|
+
"minLength": 1,
|
|
1033
|
+
"not": {
|
|
1034
|
+
"pattern": "[={}]"
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
885
1037
|
"name": {
|
|
886
1038
|
"description": "Program name (used in help text, usage lines, and completion scripts).",
|
|
887
1039
|
"type": "string"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kjanat/dreamcli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Schema-first, fully typed TypeScript CLI framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dreamcli",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"!**/*.pyc",
|
|
87
87
|
"!**/AGENTS.md"
|
|
88
88
|
],
|
|
89
|
-
"workspaces": ["
|
|
89
|
+
"workspaces": ["examples/*", "docs"],
|
|
90
90
|
"scripts": {
|
|
91
91
|
"bd": "run -s build typecheck:dist package:check lazy:check",
|
|
92
92
|
"build": "bun --bun tsdown",
|
|
@@ -135,28 +135,28 @@
|
|
|
135
135
|
"version:check": "bun scripts/check-version-sync.ts"
|
|
136
136
|
},
|
|
137
137
|
"dependencies": {
|
|
138
|
-
"ansispeck": "^0.4.
|
|
138
|
+
"ansispeck": "^0.4.3"
|
|
139
139
|
},
|
|
140
140
|
"devDependencies": {
|
|
141
141
|
"@arethetypeswrong/core": "^0.18.5",
|
|
142
142
|
"@iarna/toml": "^2.2.5",
|
|
143
|
-
"@types/bun": "^1.3
|
|
143
|
+
"@types/bun": "^1.4.3",
|
|
144
144
|
"@types/deno": "^2.7.0",
|
|
145
|
-
"@types/node": ">=26.
|
|
146
|
-
"@typescript/native": "npm:typescript@^7",
|
|
147
|
-
"@vitest/coverage-v8": "5.0.
|
|
148
|
-
"biome": "npm:@biomejs/biome@^2.5.
|
|
149
|
-
"dprint": "0.
|
|
145
|
+
"@types/node": ">=26.6.5",
|
|
146
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
147
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
148
|
+
"biome": "npm:@biomejs/biome@^2.5.15",
|
|
149
|
+
"dprint": "0.64.3",
|
|
150
150
|
"importmapify": "1.7.0",
|
|
151
|
-
"knip": "^6.
|
|
152
|
-
"publint": "^0.3.
|
|
153
|
-
"runner-run": "0.
|
|
154
|
-
"tsdown": "0.23.
|
|
155
|
-
"typescript": ">=6,<7",
|
|
156
|
-
"vitest": "^5.0.
|
|
157
|
-
"yaml": "^2.9.
|
|
151
|
+
"knip": "^6.43.0",
|
|
152
|
+
"publint": "^0.3.25",
|
|
153
|
+
"runner-run": "0.28.0",
|
|
154
|
+
"tsdown": "0.23.2",
|
|
155
|
+
"typescript": ">=6.0.3,<7",
|
|
156
|
+
"vitest": "^5.0.5",
|
|
157
|
+
"yaml": "^2.9.1"
|
|
158
158
|
},
|
|
159
|
-
"packageManager": "bun@1.4.
|
|
159
|
+
"packageManager": "bun@1.4.4",
|
|
160
160
|
"engines": {
|
|
161
161
|
"bun": ">=1.3",
|
|
162
162
|
"deno": ">=2.6.0",
|
|
@@ -173,17 +173,17 @@
|
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
"volta": {
|
|
176
|
-
"node": "26.
|
|
177
|
-
"npm": "11.
|
|
176
|
+
"node": "26.12.1",
|
|
177
|
+
"npm": "11.21.1"
|
|
178
178
|
},
|
|
179
179
|
"publishConfig": {
|
|
180
180
|
"access": "public"
|
|
181
181
|
},
|
|
182
182
|
"catalog": {
|
|
183
|
-
"@types/bun": "^1.3
|
|
184
|
-
"@types/node": ">=26.
|
|
185
|
-
"@typescript/native": "npm:typescript@^7",
|
|
186
|
-
"typescript": ">=6,<7",
|
|
187
|
-
"vitest": "^5.0.
|
|
183
|
+
"@types/bun": "^1.4.3",
|
|
184
|
+
"@types/node": ">=26.6.5",
|
|
185
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
186
|
+
"typescript": ">=6.0.3,<7",
|
|
187
|
+
"vitest": "^5.0.5"
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -52,7 +52,7 @@ deno doc --filter=CLIBuilder jsr:@kjanat/dreamcli 2>/dev/null # one symbol
|
|
|
52
52
|
`2>/dev/null` matters: deno writes download and type-check progress to stderr,
|
|
53
53
|
which otherwise swamps the documentation output.
|
|
54
54
|
|
|
55
|
-
Pin a version with `jsr:@kjanat/dreamcli@4.
|
|
55
|
+
Pin a version with `jsr:@kjanat/dreamcli@4.2.0` when the project is not on
|
|
56
56
|
latest. `--filter` takes a declaration name; it prints nothing for a name that
|
|
57
57
|
does not exist, which is itself a useful signal.
|
|
58
58
|
|
|
@@ -58,7 +58,9 @@ def render_template(template: str, replacements: dict[str, str]) -> str:
|
|
|
58
58
|
|
|
59
59
|
def write_file(path: Path, content: str, force: bool) -> None:
|
|
60
60
|
if path.exists() and not force:
|
|
61
|
-
raise FileExistsError(
|
|
61
|
+
raise FileExistsError(
|
|
62
|
+
f"Refusing to overwrite existing file: {path}. Use --force to overwrite."
|
|
63
|
+
)
|
|
62
64
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
63
65
|
path.write_text(content)
|
|
64
66
|
|
|
@@ -246,7 +248,9 @@ def detect_vitest_usage_in_project(project_root: Path, manager_root: Path | None
|
|
|
246
248
|
return False
|
|
247
249
|
|
|
248
250
|
|
|
249
|
-
def choose_test_template(
|
|
251
|
+
def choose_test_template(
|
|
252
|
+
mode: str, package_manager: str | None, uses_vitest: bool
|
|
253
|
+
) -> tuple[str, str]:
|
|
250
254
|
if package_manager == "bun" and not uses_vitest:
|
|
251
255
|
return (f"{mode}-command.bun-test.ts.tpl", "bun:test")
|
|
252
256
|
return (f"{mode}-command.test.ts.tpl", "vitest")
|
|
@@ -275,7 +279,9 @@ def format_run_path(path: Path, cwd: Path) -> str:
|
|
|
275
279
|
|
|
276
280
|
|
|
277
281
|
def main() -> int:
|
|
278
|
-
parser = argparse.ArgumentParser(
|
|
282
|
+
parser = argparse.ArgumentParser(
|
|
283
|
+
description="Scaffold Bun-first DreamCLI starter files from templates."
|
|
284
|
+
)
|
|
279
285
|
parser.add_argument("--name", required=True, help="CLI name (e.g. mycli)")
|
|
280
286
|
parser.add_argument(
|
|
281
287
|
"--mode",
|
|
@@ -331,7 +337,9 @@ def main() -> int:
|
|
|
331
337
|
print(f"[OK] Wrote {entry_path}")
|
|
332
338
|
|
|
333
339
|
if include_test:
|
|
334
|
-
test_template_name, test_framework = choose_test_template(
|
|
340
|
+
test_template_name, test_framework = choose_test_template(
|
|
341
|
+
args.mode, package_manager, uses_vitest
|
|
342
|
+
)
|
|
335
343
|
test_template_path = templates_dir / test_template_name
|
|
336
344
|
test_template = read_template(test_template_path)
|
|
337
345
|
test_content = render_template(test_template, replacements)
|
package/dist/config-CrlScpYX.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{Q as CLIError}from"./core-DvXUolc_.mjs";var config_exports=__exportAll({buildConfigSearchPaths:()=>buildConfigSearchPaths,configFormat:()=>configFormat,discoverConfig:()=>discoverConfig});function isPlainObject(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const jsonLoader={extensions:[`json`],parse:e=>{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`Config must be a JSON object`);return t}};function joinPath(e,...t){let n=e.includes(`\\`)?`\\`:`/`;return[e.endsWith(n)?e.slice(0,-1):e,...t].join(n)}function ancestorDirs(e){let t=e.includes(`\\`)?`\\`:`/`,n=e;for(;n.length>1&&n.endsWith(t)&&!n.endsWith(`:${t}`);)n=n.slice(0,-1);let r=[n];for(;;){let e=n.lastIndexOf(t);if(e<0)break;let i=n.slice(0,e);if(i===``?i=t:/^[A-Za-z]:$/.test(i)&&(i=`${i}${t}`),i===n)break;r.push(i),n=i}return r}function getExtension(e){let t=e.lastIndexOf(`.`);return t<=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))?``:e.slice(t+1).toLowerCase()}function buildConfigSearchPaths(e,t){let n=buildExtensionList(t.loaders),r=[];for(let i of ancestorDirs(t.baseDir)){for(let t of n)r.push(joinPath(i,`.${e}.${t}`));for(let t of n)r.push(joinPath(i,`${e}.config.${t}`));for(let t of n)r.push(joinPath(i,`.config`,`${e}.${t}`))}for(let i of t.userConfigDirs)for(let t of n)r.push(joinPath(i,e,`config.${t}`));for(let i of t.systemConfigDirs??[])for(let t of n)r.push(joinPath(i,e,`config.${t}`));return r}function buildExtensionList(e){let t=new Set,n=[];for(let e of jsonLoader.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}if(e!==void 0)for(let r of e)for(let e of r.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}return n}function buildLoaderMap(e){let t=new Map;for(let e of jsonLoader.extensions)t.set(e.toLowerCase(),jsonLoader);if(e!==void 0)for(let n of e)for(let e of n.extensions)t.set(e.toLowerCase(),n);return t}async function discoverConfig(e,t,n){let r=buildLoaderMap(n?.loaders),i=n?.configPath===void 0?n?.searchPaths??buildConfigSearchPaths(e,{baseDir:n?.baseDir??t.cwd,userConfigDirs:t.userConfigDirs??[t.configDir],systemConfigDirs:t.systemConfigDirs??[],...n?.loaders===void 0?{}:{loaders:n.loaders}}):[n.configPath];for(let e of i){let i=await t.readFile(e);if(i===null){if(n?.configPath!==void 0)throw new CLIError(`Config file not found: ${e}`,{code:`CONFIG_NOT_FOUND`,details:{path:e},suggest:`Create the config file or remove the --config flag`});continue}let a=getExtension(e),o=r.get(a);if(o===void 0)throw new CLIError(`No loader registered for config format: .${a}`,{code:`CONFIG_UNKNOWN_FORMAT`,details:{path:e,extension:a},suggest:`Supported formats: ${[...r.keys()].join(`, `)}`});try{let t=o.parse(i);if(!isPlainObject(t))throw Error(`Config loader must return a plain object`);return{found:!0,path:e,data:t,format:a}}catch(t){throw new CLIError(`Failed to parse config file: ${e}`,{code:`CONFIG_PARSE_ERROR`,cause:t,details:{path:e,format:a,message:t instanceof Error?t.message:String(t)},suggest:`Check the config file for syntax errors`})}}return{found:!1}}function configFormat(e,t){return{extensions:e,parse:t}}export{discoverConfig as i,configFormat as n,config_exports as r,buildConfigSearchPaths as t};
|