@kjanat/dreamcli 2.4.0 → 2.5.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/CHANGELOG.md CHANGED
@@ -7,6 +7,55 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.5.0] - 2026-06-28
11
+
12
+ ### Added
13
+
14
+ - **`.manifest()` — runtime-agnostic manifest discovery** — discover CLI metadata
15
+ from any manifest file, not just `package.json`. Pass `files` to choose candidate
16
+ filenames in priority order (e.g. `['deno.json', 'jsr.json']`); discovery walks up
17
+ from `cwd` (or `from`) and the nearest manifest directory wins. Files are parsed as
18
+ JSON with a JSONC fallback, so `package.json`, `deno.json`, `jsr.json`, and
19
+ `deno.jsonc` all work — including manifests with `//` / block comments or trailing
20
+ commas (a dependency-free, string-aware strip that leaves `//` inside string values
21
+ such as URLs untouched).
22
+ - **`discoverManifest()`** — the generalized discovery helper behind `.manifest()`,
23
+ accepting `{ startDir, files }`.
24
+ - **Optional scope retention in name inference** — `inferName` now accepts
25
+ `{ scope: 'keep' | 'strip' }` (and `inferCliName(pkg, { stripScope })`) so a scoped
26
+ `name` like `@scope/mycli` can be kept verbatim instead of always stripping to
27
+ `mycli`. Relevant for `deno.json` / `jsr.json`, which have no `bin` field.
28
+ - **`.denoJson()`** — deprecated convenience preset for
29
+ `.manifest({ files: ['deno.json', 'deno.jsonc', 'jsr.json'] })` (see Deprecated below).
30
+
31
+ ### Changed
32
+
33
+ - **Manifest discovery now requires recognized metadata to count as a hit** — a
34
+ parseable but metadata-less manifest (`{}`, or one carrying only non-metadata
35
+ fields such as `dependencies` / `scripts` / `type`, or a config-only `deno.json`
36
+ with just `tasks` / `imports`) is no longer treated as a match. Discovery now
37
+ walks up to parent directories and tries the remaining candidate files instead
38
+ of halting. This also changes the deprecated `discoverPackageJson()` /
39
+ `.packageJson()`: where a metadata-less `package.json` previously halted the
40
+ walk-up and resolved to `{}`, the walk-up now continues, so an ancestor's
41
+ version can surface (relevant in monorepos). Pass pre-loaded `data` or an
42
+ explicit `from` / `startDir` to pin discovery to one directory.
43
+
44
+ ### Deprecated
45
+
46
+ - **`.packageJson()`, `.denoJson()`, and `discoverPackageJson()`** — superseded by
47
+ `.manifest()` / `discoverManifest()`, whose defaults (`['package.json']`) match the
48
+ old behavior. All still work, delegating to the generalized path.
49
+
50
+ ## [2.4.1] - 2026-06-27
51
+
52
+ ### Fixed
53
+
54
+ - **Destructuring `out` and activity handles** — `Out` methods and the spinner/progress activity
55
+ handle methods are now bound to their instance, so pulling them off via destructuring (e.g.
56
+ `const { done } = handle`) no longer breaks `this`-dependent behaviour and cleanup
57
+ (https://github.com/kjanat/dreamcli/pull/40).
58
+
10
59
  ## [2.4.0] - 2026-06-23
11
60
 
12
61
  ### Added
@@ -829,7 +878,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
829
878
  - MIT License.
830
879
  - Markdownlint configuration.
831
880
 
832
- [Unreleased]: https://github.com/kjanat/dreamcli/compare/v2.4.0...HEAD
881
+ [Unreleased]: https://github.com/kjanat/dreamcli/compare/v2.5.0...HEAD
882
+ [2.5.0]: https://github.com/kjanat/dreamcli/compare/v2.4.1...v2.5.0
883
+ [2.4.1]: https://github.com/kjanat/dreamcli/compare/v2.4.0...v2.4.1
833
884
  [2.4.0]: https://github.com/kjanat/dreamcli/compare/v2.3.0...v2.4.0
834
885
  [2.3.0]: https://github.com/kjanat/dreamcli/compare/v2.2.1...v2.3.0
835
886
  [2.2.1]: https://github.com/kjanat/dreamcli/compare/v2.2.0...v2.2.1
package/README.md CHANGED
@@ -543,11 +543,11 @@ ESM-only. Source included in package (`src/`).
543
543
 
544
544
  ## Runtime support
545
545
 
546
- | Runtime | Status |
547
- | ------------------ | ----------------------------------- |
548
- | Node.js >= 22.22.2 | Supported |
549
- | Bun >= 1.3 | Supported |
550
- | Deno >= 2.6.0 | Supported (JSR: `@kjanat/dreamcli`) |
546
+ | Runtime | Status |
547
+ | ------------------ | ---------------------------------- |
548
+ | Node.js >= 22.22.2 | Supported |
549
+ | Bun >= 1.3 | Supported |
550
+ | Deno >= 2.6.0 | Supported (`jsr:@kjanat/dreamcli`) |
551
551
 
552
552
  Runtime detection is automatic.
553
553
  The core framework never imports platform-specific APIs directly — a thin `RuntimeAdapter` interface
@@ -51,18 +51,22 @@ interface CLISchema {
51
51
  */
52
52
  readonly configSettings: ConfigSettings | undefined;
53
53
  /**
54
- * Package.json auto-discovery settings. When defined, `.run()` discovers
55
- * the nearest `package.json` and merges metadata before dispatch.
54
+ * Manifest auto-discovery settings. When defined, `.run()` discovers the
55
+ * nearest manifest (`package.json`, `deno.json`, `jsr.json`, …) and merges
56
+ * metadata before dispatch.
56
57
  *
57
- * Set via the {@linkcode CLIBuilder.packageJson | .packageJson()} builder method.
58
+ * Set via the {@linkcode CLIBuilder.manifest | .manifest()} builder method
59
+ * (or the {@linkcode CLIBuilder.packageJson | .packageJson()} /
60
+ * {@linkcode CLIBuilder.denoJson | .denoJson()} presets).
58
61
  */
59
- readonly packageJsonSettings: PackageJsonSettings | undefined;
62
+ readonly packageJsonSettings: ResolvedManifestSettings | undefined;
60
63
  /**
61
64
  * OSC 8 hyperlink targets for the root-help header (name/version).
62
65
  *
63
66
  * Set via the {@linkcode CLIBuilder.links | .links()} builder method.
64
- * Fields left `undefined` are derived from package.json metadata
65
- * (`repository` / `homepage`) when `.packageJson()` is active.
67
+ * Fields left `undefined` are derived from manifest metadata
68
+ * (`repository` / `homepage`) when manifest discovery ({@linkcode
69
+ * CLIBuilder.manifest | .manifest()}) is active.
66
70
  */
67
71
  readonly helpLinks: HelpLinks | undefined;
68
72
  /** Whether built-in `.completions()` command registration is active. */
@@ -90,14 +94,22 @@ interface ConfigSettings {
90
94
  readonly loaders: readonly FormatLoader[] | undefined;
91
95
  }
92
96
  /**
93
- * Package.json auto-discovery settings.
97
+ * Manifest auto-discovery settings — the resolved/normalized shape stored in
98
+ * the schema.
94
99
  *
95
100
  * Stored in {@link CLISchema} and consumed by `CLIBuilder.run()` to
96
- * call {@link discoverPackageJson} before dispatching to a command.
101
+ * call {@link discoverManifest} before dispatching to a command.
102
+ *
103
+ * Note: the schema FIELD name (`packageJsonSettings`) keeps its `packageJson`
104
+ * prefix for backward compatibility — renaming it would break consumers reading
105
+ * `app.schema.packageJsonSettings`. The type itself is now generically named
106
+ * (it holds discovery config for any manifest — `package.json`, `deno.json`,
107
+ * `jsr.json`); the legacy {@link PackageJsonSettings} alias remains exported for
108
+ * backward compatibility.
97
109
  */
98
- interface PackageJsonSettings {
110
+ interface ResolvedManifestSettings {
99
111
  /**
100
- * Infer CLI name from package.json `bin` keys or `name` field.
112
+ * Infer CLI name from manifest `bin` keys or `name` field.
101
113
  *
102
114
  * When `true`, the discovered name replaces the `cli(name)` value.
103
115
  * Explicit `.version()`/`.description()` calls still take precedence
@@ -106,15 +118,30 @@ interface PackageJsonSettings {
106
118
  * @defaultValue `false`
107
119
  */
108
120
  readonly inferName: boolean;
121
+ /**
122
+ * Strip a leading `@scope/` from the inferred `name` fallback.
123
+ *
124
+ * Only consulted when {@link ResolvedManifestSettings.inferName | `inferName`}
125
+ * is `true` and the name comes from the manifest `name` field (not a `bin`
126
+ * key, which is never scoped).
127
+ *
128
+ * @defaultValue `true`
129
+ */
130
+ readonly stripScope: boolean;
109
131
  /**
110
132
  * Explicit filesystem anchor for discovery; overrides `adapter.cwd`.
111
133
  *
112
- * Resolved to a string path before storage. When set, `discoverPackageJson`
134
+ * Resolved to a string path before storage. When set, `discoverManifest`
113
135
  * walks up from here instead of the runtime cwd. Required for installable
114
136
  * CLIs whose version should reflect THEIR OWN package, not the consumer's
115
137
  * working directory.
116
138
  */
117
139
  readonly from: string | undefined;
140
+ /**
141
+ * Candidate manifest filenames, in per-directory priority order
142
+ * (e.g. `['deno.json', 'deno.jsonc', 'jsr.json']` for `.denoJson()`).
143
+ */
144
+ readonly files: readonly string[];
118
145
  /**
119
146
  * Pre-loaded data; skips filesystem discovery, uses values verbatim.
120
147
  *
@@ -122,11 +149,20 @@ interface PackageJsonSettings {
122
149
  * ```ts
123
150
  * import pkg from './package.json' with { type: 'json' };
124
151
  *
125
- * cli('mycli').packageJson(pkg);
152
+ * cli('mycli').manifest(pkg);
126
153
  * ```
127
154
  */
128
155
  readonly data: PackageJsonData | undefined;
129
156
  }
157
+ /**
158
+ * Resolved manifest discovery settings stored in {@link CLISchema}.
159
+ *
160
+ * @deprecated Renamed to {@link ResolvedManifestSettings}. The stored shape
161
+ * holds generic manifest discovery config (`package.json`, `deno.json`,
162
+ * `jsr.json`), not just `package.json`; the misleading name is kept only for
163
+ * backward compatibility.
164
+ */
165
+ type PackageJsonSettings = ResolvedManifestSettings;
130
166
  /**
131
167
  * Options for {@linkcode CLIBuilder.execute | .execute()} and {@linkcode CLIBuilder.run | .run()}.
132
168
  *
@@ -198,21 +234,21 @@ declare class CLIBuilder {
198
234
  * `options.help.hyperlinks`), and only in the header — usage lines, the
199
235
  * `--help` hint, the commands table, and completion scripts stay plain.
200
236
  *
201
- * URLs not provided here are derived from package.json metadata when
202
- * `.packageJson()` is active (works with both filesystem discovery and
237
+ * URLs not provided here are derived from manifest metadata when
238
+ * `.manifest()` is active (works with both filesystem discovery and
203
239
  * pre-loaded data):
204
240
  * - **name** → normalized `repository` URL, falling back to `homepage`
205
241
  * - **version** → forge release tag (`{repo}/releases/tag/v{version}` on
206
242
  * GitHub, `{repo}/-/releases/v{version}` on GitLab)
207
243
  *
208
- * @param links - Explicit URLs; omit to derive everything from package.json.
244
+ * @param links - Explicit URLs; omit to derive everything from the manifest.
209
245
  * @returns The builder (for chaining).
210
246
  *
211
247
  * @example
212
248
  * ```ts
213
- * // Derive both links from package.json repository/homepage:
249
+ * // Derive both links from the manifest repository/homepage:
214
250
  * cli('mycli')
215
- * .packageJson()
251
+ * .manifest()
216
252
  * .links()
217
253
  * .run();
218
254
  *
@@ -292,83 +328,120 @@ declare class CLIBuilder {
292
328
  */
293
329
  configLoader(loader: FormatLoader): CLIBuilder;
294
330
  /**
295
- * Enable package.json metadata from pre-loaded data.
296
- *
297
- * Pass an already-imported `package.json` to skip filesystem discovery
298
- * entirely — useful for bundled or installable CLIs where the version
299
- * should be locked at build time. The data's `version`/`description` are
300
- * merged into the CLI schema immediately, so this form works in **both**
301
- * `.run()` and `.execute()` (the filesystem-free path). Explicit
302
- * `.version()`/`.description()` calls still take precedence, and the data
303
- * form does not infer the CLI name.
331
+ * Enable manifest metadata from pre-loaded data.
332
+ *
333
+ * Pass an already-imported manifest (`package.json`, `deno.json`, `jsr.json`)
334
+ * to skip filesystem discovery entirely — useful for bundled or installable
335
+ * CLIs where the version should be locked at build time. The data's
336
+ * `version`/`description` are merged into the CLI schema immediately, so this
337
+ * form works in **both** `.run()` and `.execute()` (the filesystem-free path).
338
+ * Explicit `.version()`/`.description()` calls still take precedence, and the
339
+ * data form does not infer the CLI name — `inferName` / `{ scope }` are
340
+ * available only on the discovery (settings) form. For a pre-loaded manifest
341
+ * whose scoped `name` should drive the CLI name, set the name explicitly via
342
+ * `cli(name)` (or call {@link inferCliName} on the data yourself).
304
343
  *
305
344
  * Detected by field shape: an object carrying at least one of
306
- * `name`/`version`/`description`/`bin`. An empty `{}` or a settings-shaped
307
- * object falls through to the settings overload.
345
+ * `name`/`version`/`description`/`bin`/`homepage`/`repository`. An empty `{}`
346
+ * or a settings-shaped object falls through to the settings overload.
308
347
  *
309
- * @param data - Pre-loaded `package.json` metadata.
348
+ * @param data - Pre-loaded manifest metadata.
310
349
  *
311
350
  * @example
312
351
  * ```ts
313
- * import pkg from './package.json' with { type: 'json' };
352
+ * import denoCfg from './deno.json' with { type: 'json' };
314
353
  *
315
354
  * // No filesystem; works in .run() AND .execute():
316
355
  * cli('mycli')
317
- * .packageJson(pkg)
356
+ * .manifest(denoCfg)
318
357
  * .command(deploy)
319
358
  * .run();
320
359
  * ```
321
360
  */
322
- packageJson(data: PackageJsonData): CLIBuilder;
361
+ manifest(data: PackageJsonData): CLIBuilder;
323
362
  /**
324
- * Enable automatic package.json metadata discovery.
363
+ * Enable automatic manifest metadata discovery.
325
364
  *
326
- * When enabled, `.run()` walks up from `cwd` to find the nearest
327
- * `package.json` and merges its `version` and `description` fields
328
- * into the CLI schema. Explicit `.version()` and `.description()`
329
- * calls always take precedence over discovered values.
365
+ * When enabled, `.run()` walks up from `cwd` (or {@link ManifestSettings.from})
366
+ * to find the nearest manifest among {@link ManifestSettings.files} and merges
367
+ * its `version`/`description` into the CLI schema. Explicit `.version()` /
368
+ * `.description()` calls always take precedence.
330
369
  *
331
- * Has no effect in `.execute()` (which is filesystem-free by design) —
332
- * use the {@link CLIBuilder.packageJson | data overload} for that.
370
+ * Files are parsed as JSON with a JSONC fallback — `package.json`, `deno.json`,
371
+ * `jsr.json`, and `deno.jsonc` all qualify, including files with `//` / block
372
+ * comments or trailing commas. A file that fails both parses is skipped
373
+ * (discovery keeps walking).
374
+ *
375
+ * Has no effect in `.execute()` (filesystem-free) — use the data overload.
333
376
  *
334
377
  * @param settings - Optional settings:
335
- * - `inferName`: also infer the CLI name from `bin` keys or `name` field.
336
- * - `from`: anchor discovery to a specific file/URL/path instead of `cwd`.
337
- * Pass `import.meta.url` for installable CLIs that need to report
338
- * THEIR OWN version (not the consumer's project version). Accepts
339
- * string paths, `file:` URL strings, or `URL` instances.
378
+ * - `files`: candidate manifest filenames in priority order
379
+ * (default `['package.json']`).
380
+ * - `inferName`: infer the CLI name from `bin` keys or `name`. Pass
381
+ * `{ scope: 'keep' }` to keep a leading `@scope/` (stripped by default).
382
+ * - `from`: anchor discovery to a file/URL/path instead of `cwd`. Pass
383
+ * `import.meta.url` for installable CLIs that must report THEIR OWN
384
+ * version. Accepts string paths, `file:` URL strings, or `URL` instances.
340
385
  *
341
386
  * @example
342
387
  * ```ts
343
- * // Auto-fill version + description from nearest package.json:
388
+ * // Deno CLI: discover OUR deno.json (then jsr.json), keep the scope in name:
344
389
  * cli('mycli')
345
- * .packageJson()
390
+ * .manifest({
391
+ * files: ['deno.json', 'jsr.json'],
392
+ * from: import.meta.url,
393
+ * inferName: { scope: 'keep' },
394
+ * })
346
395
  * .command(deploy)
347
396
  * .run();
397
+ * ```
398
+ */
399
+ manifest(settings?: ManifestSettings): CLIBuilder;
400
+ /**
401
+ * Discover metadata from `package.json` (preset for {@link CLIBuilder.manifest}).
348
402
  *
349
- * // Also infer CLI name from bin key / package name:
350
- * cli('mycli')
351
- * .packageJson({ inferName: true })
352
- * .command(deploy)
353
- * .run();
403
+ * @deprecated Use {@link CLIBuilder.manifest} — `.manifest()` defaults to
404
+ * `package.json` and also supports `deno.json` / `jsr.json` via `files`.
354
405
  *
355
- * // Installable CLI; discover OUR package.json, not the consumer's:
356
- * cli('mycli')
357
- * .packageJson({ from: import.meta.url })
358
- * .command(deploy)
359
- * .run();
406
+ * @param data - Pre-loaded `package.json` metadata.
407
+ */
408
+ packageJson(data: PackageJsonData): CLIBuilder;
409
+ /**
410
+ * Discover metadata from `package.json` (preset for {@link CLIBuilder.manifest}).
411
+ *
412
+ * @deprecated Use {@link CLIBuilder.manifest}.
413
+ *
414
+ * @param settings - `inferName` / `from` (see {@link CLIBuilder.manifest}).
415
+ */
416
+ packageJson(settings?: ManifestPresetSettings): CLIBuilder;
417
+ /**
418
+ * Discover metadata from `deno.json`, `deno.jsonc`, then `jsr.json` (preset for
419
+ * {@link CLIBuilder.manifest}).
420
+ *
421
+ * @deprecated Use `.manifest({ files: ['deno.json', 'deno.jsonc', 'jsr.json'] })`.
360
422
  *
361
- * // Explicit values always win:
423
+ * @param data - Pre-loaded `deno.json` / `jsr.json` metadata.
424
+ */
425
+ denoJson(data: PackageJsonData): CLIBuilder;
426
+ /**
427
+ * Discover metadata from `deno.json`, `deno.jsonc`, then `jsr.json` (preset for
428
+ * {@link CLIBuilder.manifest}).
429
+ *
430
+ * @deprecated Use `.manifest({ files: ['deno.json', 'deno.jsonc', 'jsr.json'] })`.
431
+ *
432
+ * @param settings - `inferName` / `from` (see {@link CLIBuilder.manifest}).
433
+ * `deno.json` / `jsr.json` have no `bin` field, so `inferName` resolves
434
+ * from `name`; pass `{ scope: 'keep' }` to retain a leading `@scope/`.
435
+ *
436
+ * @example
437
+ * ```ts
362
438
  * cli('mycli')
363
- * .packageJson()
364
- * .version('2.0.0-beta') // wins over package.json
439
+ * .denoJson({ from: import.meta.url })
440
+ * .command(deploy)
365
441
  * .run();
366
442
  * ```
367
443
  */
368
- packageJson(settings?: {
369
- readonly inferName?: boolean;
370
- readonly from?: string | URL;
371
- }): CLIBuilder;
444
+ denoJson(settings?: ManifestPresetSettings): CLIBuilder;
372
445
  /**
373
446
  * Register a command with the CLI program.
374
447
  *
@@ -478,6 +551,42 @@ declare class CLIBuilder {
478
551
  */
479
552
  run(options?: CLIRunOptions): Promise<never>;
480
553
  }
554
+ /**
555
+ * CLI-name inference control for {@link ManifestSettings.inferName}.
556
+ *
557
+ * - `false` (or omitted): do not infer the name.
558
+ * - `true`: infer, stripping a leading `@scope/` from the `name` fallback.
559
+ * - `{ scope: 'keep' }`: infer, keeping the full scoped name.
560
+ * - `{ scope: 'strip' }`: infer, stripping the scope (explicit form of `true`).
561
+ *
562
+ * `scope` is required in the object form: an empty `{}` is rejected so that an
563
+ * options object can never silently enable inference (use `true` for that).
564
+ */
565
+ type InferNameOption = boolean | {
566
+ readonly scope: 'keep' | 'strip';
567
+ };
568
+ /** Discovery settings accepted by {@link CLIBuilder.manifest}. */
569
+ interface ManifestSettings {
570
+ /** Infer the CLI name from `bin` keys or `name`. @defaultValue `false` */
571
+ readonly inferName?: InferNameOption;
572
+ /** Anchor discovery to a file/URL/path instead of `cwd`. */
573
+ readonly from?: string | URL;
574
+ /**
575
+ * Candidate manifest filenames in priority order — NOT npm's `files` publish
576
+ * globs. Discovery probes each name per directory and takes the first that
577
+ * parses.
578
+ *
579
+ * @defaultValue `['package.json']`
580
+ */
581
+ readonly files?: readonly string[];
582
+ }
583
+ /**
584
+ * Discovery settings for the `.packageJson()` / `.denoJson()` presets (no `files`).
585
+ *
586
+ * @deprecated Both presets are deprecated; use {@link ManifestSettings} with
587
+ * {@link CLIBuilder.manifest}.
588
+ */
589
+ type ManifestPresetSettings = Omit<ManifestSettings, 'files'>;
481
590
  /**
482
591
  * Options for the `cli({...})` factory form.
483
592
  *
@@ -528,4 +637,4 @@ declare function cli(name: string): CLIBuilder;
528
637
  /** Create a new CLI program builder from an options object. */
529
638
  declare function cli(options: CLIOptions): CLIBuilder;
530
639
  //#endregion
531
- export { type BeforeParseParams, CLIBuilder, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type ConfigSettings, type HelpLinks, type PackageJsonSettings, type PluginCommandContext, type ResolvedCommandParams, cli, formatRootHelp, plugin };
640
+ export { type BeforeParseParams, CLIBuilder, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type ConfigSettings, type HelpLinks, type InferNameOption, type ManifestPresetSettings, type ManifestSettings, type PackageJsonSettings, type PluginCommandContext, type ResolvedCommandParams, type ResolvedManifestSettings, cli, formatRootHelp, plugin };
@@ -1 +1 @@
1
- import{CLIError as e}from"../errors/index.mjs";import{SHELLS as t,generateCompletion as n}from"../completion/index.mjs";import{formatHelp as r}from"../help/index.mjs";import{clearRequestedExitCode as i,createCaptureOutput as a,createOutput as o}from"../output/index.mjs";import{includesBeforeSeparator as s}from"../parse/index.mjs";import{buildRunResult as c,executeCommand as l}from"../execution/index.mjs";import{arg as u}from"../schema/arg.mjs";import{command as d}from"../schema/command.mjs";import{runCommand as f}from"../testkit/index.mjs";import{stripTrailing as p}from"../../strings.mjs";import{createAdapter as m}from"../../runtime/auto.mjs";import{deriveHelpLinks as h}from"./help-links.mjs";import{planInvocation as g}from"./planner.mjs";import"./plugin.mjs";import{formatRootHelp as _}from"./root-help.mjs";import{prepareRuntimePreflight as v}from"./runtime-preflight.mjs";function y(e){return[e.name,...e.aliases]}function b(t,n,r,i){let a=n.get(r);if(a!==void 0)throw new e(`Duplicate command route '${r}' under '${t}' (${a} and ${i})`,{code:`DUPLICATE_COMMAND`,suggest:`Ensure sibling command names and aliases are unique`});n.set(r,i)}function x(t,n){let r=new Map;for(let e of t)for(let t of y(e.schema))b(`root`,r,t,e.schema.name);for(let t of y(n)){let i=r.get(t);if(i!==void 0)throw new e(`Command route '${t}' is already registered by '${i}'`,{code:`DUPLICATE_COMMAND`,suggest:i===n.name?`Ensure command '${n.name}' does not reuse route '${t}'`:`Rename '${n.name}' or remove route '${t}' from '${i}'`});r.set(t,n.name)}}function S(e){let t=new Map,n=new Map;for(let r of e._subcommands){let i=y(r.schema);for(let t of i)b(e.schema.name,n,t,r.schema.name);let a=S(r);for(let e of i)t.set(e,a)}return{schema:e.schema,subcommands:t,_command:e,_execute(t,n){return f(e,t,n)}}}function C(e,t,n){return{help:t,...n===void 0?{}:{meta:n},...e?.plugins===void 0?{}:{plugins:e.plugins},...e?.env===void 0?{}:{env:e.env},...e?.config===void 0?{}:{config:e.config},...e?.stdinData===void 0?{}:{stdinData:e.stdinData},...e?.prompter===void 0?{}:{prompter:e.prompter},...e?.answers===void 0?{}:{answers:e.answers},...e?.verbosity===void 0?{}:{verbosity:e.verbosity},...e?.jsonMode===void 0?{}:{jsonMode:e.jsonMode},...e?.isTTY===void 0?{}:{isTTY:e.isTTY},...e?.out===void 0?{}:{out:e.out},...e?.captured===void 0?{}:{captured:e.captured}}}var w=class f{schema;constructor(e){this.schema=e}version(e){return new f({...this.schema,version:e})}description(e){return new f({...this.schema,description:e})}links(e){return new f({...this.schema,helpLinks:{name:k(e?.name),version:k(e?.version)}})}config(e,t){return new f({...this.schema,configSettings:{appName:e,loaders:t}})}configLoader(t){if(this.schema.configSettings===void 0)throw new e(`.configLoader() requires .config() to be called first`,{code:`INVALID_BUILDER_STATE`,suggest:`Call .config(appName) before .configLoader()`});let n=this.schema.configSettings.loaders??[];return new f({...this.schema,configSettings:{...this.schema.configSettings,loaders:[...n,t]}})}packageJson(e){return M(e)?new f({...this.schema,...this.schema.version===void 0&&e.version!==void 0?{version:e.version}:{},...this.schema.description===void 0&&e.description!==void 0?{description:e.description}:{},packageJsonSettings:{inferName:!1,from:void 0,data:e}}):new f({...this.schema,packageJsonSettings:{inferName:e?.inferName??!1,from:j(e?.from),data:void 0}})}command(e){return x(this.schema.commands,e.schema),new f({...this.schema,commands:[...this.schema.commands,S(e)]})}default(t){if(this.schema.defaultCommand!==void 0)throw new e(`Only one default command is allowed`,{code:`DUPLICATE_DEFAULT`,suggest:`Call .default() only once when building the CLI`});x(this.schema.commands,t.schema);let n=S(t);return new f({...this.schema,commands:[...this.schema.commands,n],defaultCommand:n})}plugin(e){return new f({...this.schema,plugins:[...this.schema.plugins,e]})}completions(r){if(this.schema.hasBuiltInCompletions)throw new e(`.completions() has already been called`,{code:`DUPLICATE_COMMAND`,suggest:`Call .completions() only once when building the CLI`});let i=this.schema,a=r,o=new Map;for(let e of t)o.set(e,e);o.set(`pwsh`,`powershell`);let s=d(`completions`).alias(`completion`).description(`Generate shell completion script`).arg(`shell`,u.custom(e=>{let n=e.split(/[\\/]/),r=(n[n.length-1]??e).replace(/\.(?:exe|cmd|bat)$/i,``),i=o.get(r);if(i===void 0)throw Error(`Unknown shell '${r}'. Valid shells: ${t.join(`, `)}`);return i}).env(`SHELL`).describe(`Target shell (${t.join(`, `)})`)).action(({args:e,meta:t,out:r})=>{let o=n(t.bin===i.name?i:{...i,name:t.bin},e.shell,a);r.jsonMode?r.json({shell:e.shell,script:o}):r.log(o)});return new f({...this.command(s).schema,hasBuiltInCompletions:!0})}async execute(e,t){let n=s(e,`--json`)||t?.jsonMode===!0,o={...t?.verbosity===void 0?{}:{verbosity:t.verbosity},...n?{jsonMode:n}:{},...t?.isTTY===void 0?{}:{isTTY:t.isTTY}},u,d;t?.out===void 0?[u,d]=a(Object.keys(o).length>0?o:void 0):(u=t.out,d=t.captured??{stdout:[],stderr:[],activity:[]}),i(u);let f={...t?.help,binName:t?.help?.binName??this.schema.name,hyperlinks:t?.help?.hyperlinks??u.isTTY},p={...t,plugins:this.schema.plugins,...n?{jsonMode:n}:{}},m={jsonMode:n,isTTY:u.isTTY,verbosity:t?.verbosity??`normal`},h=g({schema:this.schema,argv:e,help:f,output:m});switch(h.kind){case`root-version`:return u.log(h.version),c({exitCode:0,error:void 0},d);case`root-help`:{let e=_(A(this.schema),h.help);return u.log(e),c({exitCode:0,error:void 0},d)}case`dispatch-error`:return n?u.json({error:h.error.toJSON()}):(u.error(h.error.message),h.error.suggest!==void 0&&h.error.code!==`NO_ACTION`&&u.error(`Suggestion: ${h.error.suggest}`)),c({exitCode:h.error.exitCode,error:h.error},d);case`needs-subcommand`:{let e=r(h.command.schema,h.help);return u.log(e),c({exitCode:0,error:void 0},d)}case`match`:{let e=C(p,h.plan.help??f,h.plan.meta);return h.plan.command._command===void 0?h.plan.command._execute(h.plan.argv,{...e,mergedSchema:h.plan.mergedSchema}):c(await l({command:h.plan.command._command,argv:h.plan.argv,out:u,schema:h.plan.mergedSchema,meta:h.plan.meta,options:e}),d)}}}async run(e){let t=e?.adapter??m(),n=this.schema.inheritName?O(t.argv):void 0,r=await v({schema:this.schema,adapter:t,options:e,inheritedName:n});if(r.kind===`config-error`)return r.jsonMode?t.stdout(`${JSON.stringify({error:r.error.toJSON()})}\n`):(t.stderr(`Error: ${r.error.message}\n`),r.error.suggest!==void 0&&t.stderr(`Suggestion: ${r.error.suggest}\n`)),t.exit(r.error.exitCode);let i=r.schema===this.schema?this:new f(r.schema),a={...e,...r.inputs,out:o({stdout:t.stdout,stderr:t.stderr,jsonMode:r.inputs.jsonMode,isTTY:r.inputs.isTTY,...r.inputs.verbosity===`normal`?{}:{verbosity:r.inputs.verbosity}})},s=await i.execute(r.filteredArgv,a);for(let e of s.stdout)t.stdout(e);for(let e of s.stderr)t.stderr(e);return t.exit(s.exitCode)}};const T=new Set([`bun`,`deno`,`node`,`tsx`]);function E(e){let t=p(e,[47,92]);if(t.length===0)return;let n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`)),r=n>=0?t.slice(n+1):t;return r.length>0?r:void 0}function D(e){let t=e.toLowerCase().replace(/\.exe$/i,``);return T.has(t)}function O(e){let t=e[0],n=e[1],r=t===void 0?void 0:E(t);if(r!==void 0&&D(r)){if(r===`bun`&&n===`run`){let t=e[2];return t===void 0||t.startsWith(`-`)?void 0:E(t)}return r===`deno`&&n===`run`||n===void 0||n.startsWith(`-`)?void 0:E(n)}return t===void 0?void 0:E(t)}function k(e){if(e!==void 0)return e instanceof URL?e.href:e}function A(e){return e.helpLinks===void 0?e:{...e,helpLinks:h(e.helpLinks,e.packageJsonSettings?.data,e.version)}}function j(e){if(e===void 0)return;if(e instanceof URL){if(e.protocol!==`file:`)return e.href}else if(!e.startsWith(`file:`))return e;let t=decodeURIComponent(new URL(e).pathname);return/^\/[A-Za-z]:/.test(t)?t.slice(1).replace(/\//g,`\\`):t}function M(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:`name`in e||`version`in e||`description`in e||`bin`in e||`homepage`in e||`repository`in e}function N(e){return new w({name:typeof e==`string`?e:e.name??`cli`,inheritName:typeof e==`string`?!1:e.inherit??!1,version:void 0,description:void 0,commands:[],defaultCommand:void 0,configSettings:void 0,packageJsonSettings:void 0,helpLinks:void 0,hasBuiltInCompletions:!1,plugins:[]})}export{w as CLIBuilder,N as cli};
1
+ import{CLIError as e}from"../errors/index.mjs";import{SHELLS as t,generateCompletion as n}from"../completion/index.mjs";import{formatHelp as r}from"../help/index.mjs";import{clearRequestedExitCode as i,createCaptureOutput as a,createOutput as o}from"../output/index.mjs";import{includesBeforeSeparator as s}from"../parse/index.mjs";import{buildRunResult as c,executeCommand as l}from"../execution/index.mjs";import{arg as u}from"../schema/arg.mjs";import{command as d}from"../schema/command.mjs";import{runCommand as f}from"../testkit/index.mjs";import{stripTrailing as p}from"../../strings.mjs";import{createAdapter as m}from"../../runtime/auto.mjs";import{deriveHelpLinks as h}from"./help-links.mjs";import{planInvocation as g}from"./planner.mjs";import"./plugin.mjs";import{formatRootHelp as _}from"./root-help.mjs";import{prepareRuntimePreflight as v}from"./runtime-preflight.mjs";function y(e){return[e.name,...e.aliases]}function b(t,n,r,i){let a=n.get(r);if(a!==void 0)throw new e(`Duplicate command route '${r}' under '${t}' (${a} and ${i})`,{code:`DUPLICATE_COMMAND`,suggest:`Ensure sibling command names and aliases are unique`});n.set(r,i)}function x(t,n){let r=new Map;for(let e of t)for(let t of y(e.schema))b(`root`,r,t,e.schema.name);for(let t of y(n)){let i=r.get(t);if(i!==void 0)throw new e(`Command route '${t}' is already registered by '${i}'`,{code:`DUPLICATE_COMMAND`,suggest:i===n.name?`Ensure command '${n.name}' does not reuse route '${t}'`:`Rename '${n.name}' or remove route '${t}' from '${i}'`});r.set(t,n.name)}}function S(e){let t=new Map,n=new Map;for(let r of e._subcommands){let i=y(r.schema);for(let t of i)b(e.schema.name,n,t,r.schema.name);let a=S(r);for(let e of i)t.set(e,a)}return{schema:e.schema,subcommands:t,_command:e,_execute(t,n){return f(e,t,n)}}}function C(e,t,n){return{help:t,...n===void 0?{}:{meta:n},...e?.plugins===void 0?{}:{plugins:e.plugins},...e?.env===void 0?{}:{env:e.env},...e?.config===void 0?{}:{config:e.config},...e?.stdinData===void 0?{}:{stdinData:e.stdinData},...e?.prompter===void 0?{}:{prompter:e.prompter},...e?.answers===void 0?{}:{answers:e.answers},...e?.verbosity===void 0?{}:{verbosity:e.verbosity},...e?.jsonMode===void 0?{}:{jsonMode:e.jsonMode},...e?.isTTY===void 0?{}:{isTTY:e.isTTY},...e?.out===void 0?{}:{out:e.out},...e?.captured===void 0?{}:{captured:e.captured}}}var w=class f{schema;constructor(e){this.schema=e}version(e){return new f({...this.schema,version:e})}description(e){return new f({...this.schema,description:e})}links(e){return new f({...this.schema,helpLinks:{name:k(e?.name),version:k(e?.version)}})}config(e,t){return new f({...this.schema,configSettings:{appName:e,loaders:t}})}configLoader(t){if(this.schema.configSettings===void 0)throw new e(`.configLoader() requires .config() to be called first`,{code:`INVALID_BUILDER_STATE`,suggest:`Call .config(appName) before .configLoader()`});let n=this.schema.configSettings.loaders??[];return new f({...this.schema,configSettings:{...this.schema.configSettings,loaders:[...n,t]}})}manifest(e){return new f(P(this.schema,e,j,!1))}packageJson(e){return new f(P(this.schema,e,j,!0))}denoJson(e){return new f(P(this.schema,e,M,!0))}command(e){return x(this.schema.commands,e.schema),new f({...this.schema,commands:[...this.schema.commands,S(e)]})}default(t){if(this.schema.defaultCommand!==void 0)throw new e(`Only one default command is allowed`,{code:`DUPLICATE_DEFAULT`,suggest:`Call .default() only once when building the CLI`});x(this.schema.commands,t.schema);let n=S(t);return new f({...this.schema,commands:[...this.schema.commands,n],defaultCommand:n})}plugin(e){return new f({...this.schema,plugins:[...this.schema.plugins,e]})}completions(r){if(this.schema.hasBuiltInCompletions)throw new e(`.completions() has already been called`,{code:`DUPLICATE_COMMAND`,suggest:`Call .completions() only once when building the CLI`});let i=this.schema,a=r,o=new Map;for(let e of t)o.set(e,e);o.set(`pwsh`,`powershell`);let s=d(`completions`).alias(`completion`).description(`Generate shell completion script`).arg(`shell`,u.custom(e=>{let n=e.split(/[\\/]/),r=(n[n.length-1]??e).replace(/\.(?:exe|cmd|bat)$/i,``),i=o.get(r);if(i===void 0)throw Error(`Unknown shell '${r}'. Valid shells: ${t.join(`, `)}`);return i}).env(`SHELL`).describe(`Target shell (${t.join(`, `)})`)).action(({args:e,meta:t,out:r})=>{let o=n(t.bin===i.name?i:{...i,name:t.bin},e.shell,a);r.jsonMode?r.json({shell:e.shell,script:o}):r.log(o)});return new f({...this.command(s).schema,hasBuiltInCompletions:!0})}async execute(e,t){let n=s(e,`--json`)||t?.jsonMode===!0,o={...t?.verbosity===void 0?{}:{verbosity:t.verbosity},...n?{jsonMode:n}:{},...t?.isTTY===void 0?{}:{isTTY:t.isTTY}},u,d;t?.out===void 0?[u,d]=a(Object.keys(o).length>0?o:void 0):(u=t.out,d=t.captured??{stdout:[],stderr:[],activity:[]}),i(u);let f={...t?.help,binName:t?.help?.binName??this.schema.name,hyperlinks:t?.help?.hyperlinks??u.isTTY},p={...t,plugins:this.schema.plugins,...n?{jsonMode:n}:{}},m={jsonMode:n,isTTY:u.isTTY,verbosity:t?.verbosity??`normal`},h=g({schema:this.schema,argv:e,help:f,output:m});switch(h.kind){case`root-version`:return u.log(h.version),c({exitCode:0,error:void 0},d);case`root-help`:{let e=_(A(this.schema),h.help);return u.log(e),c({exitCode:0,error:void 0},d)}case`dispatch-error`:return n?u.json({error:h.error.toJSON()}):(u.error(h.error.message),h.error.suggest!==void 0&&h.error.code!==`NO_ACTION`&&u.error(`Suggestion: ${h.error.suggest}`)),c({exitCode:h.error.exitCode,error:h.error},d);case`needs-subcommand`:{let e=r(h.command.schema,h.help);return u.log(e),c({exitCode:0,error:void 0},d)}case`match`:{let e=C(p,h.plan.help??f,h.plan.meta);return h.plan.command._command===void 0?h.plan.command._execute(h.plan.argv,{...e,mergedSchema:h.plan.mergedSchema}):c(await l({command:h.plan.command._command,argv:h.plan.argv,out:u,schema:h.plan.mergedSchema,meta:h.plan.meta,options:e}),d)}}}async run(e){let t=e?.adapter??m(),n=this.schema.inheritName?O(t.argv):void 0,r=await v({schema:this.schema,adapter:t,options:e,inheritedName:n});if(r.kind===`config-error`)return r.jsonMode?t.stdout(`${JSON.stringify({error:r.error.toJSON()})}\n`):(t.stderr(`Error: ${r.error.message}\n`),r.error.suggest!==void 0&&t.stderr(`Suggestion: ${r.error.suggest}\n`)),t.exit(r.error.exitCode);let i=r.schema===this.schema?this:new f(r.schema),a={...e,...r.inputs,out:o({stdout:t.stdout,stderr:t.stderr,jsonMode:r.inputs.jsonMode,isTTY:r.inputs.isTTY,...r.inputs.verbosity===`normal`?{}:{verbosity:r.inputs.verbosity}})},s=await i.execute(r.filteredArgv,a);for(let e of s.stdout)t.stdout(e);for(let e of s.stderr)t.stderr(e);return t.exit(s.exitCode)}};const T=new Set([`bun`,`deno`,`node`,`tsx`]);function E(e){let t=p(e,[47,92]);if(t.length===0)return;let n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`)),r=n>=0?t.slice(n+1):t;return r.length>0?r:void 0}function D(e){let t=e.toLowerCase().replace(/\.exe$/i,``);return T.has(t)}function O(e){let t=e[0],n=e[1],r=t===void 0?void 0:E(t);if(r!==void 0&&D(r)){if(r===`bun`&&n===`run`){let t=e[2];return t===void 0||t.startsWith(`-`)?void 0:E(t)}return r===`deno`&&n===`run`||n===void 0||n.startsWith(`-`)?void 0:E(n)}return t===void 0?void 0:E(t)}function k(e){if(e!==void 0)return e instanceof URL?e.href:e}function A(e){return e.helpLinks===void 0?e:{...e,helpLinks:h(e.helpLinks,e.packageJsonSettings?.data,e.version)}}const j=[`package.json`],M=[`deno.json`,`deno.jsonc`,`jsr.json`];function N(e){return e===void 0||e===!1?{inferName:!1,stripScope:!0}:e===!0?{inferName:!0,stripScope:!0}:{inferName:!0,stripScope:e.scope!==`keep`}}function P(e,t,n,r){if(I(t))return{...e,...e.version===void 0&&t.version!==void 0?{version:t.version}:{},...e.description===void 0&&t.description!==void 0?{description:t.description}:{},packageJsonSettings:{inferName:!1,stripScope:!0,from:void 0,files:n,data:t}};let{inferName:i,stripScope:a}=N(t?.inferName),o=r?n:t?.files??n;return{...e,packageJsonSettings:{inferName:i,stripScope:a,from:F(t?.from),files:o,data:void 0}}}function F(e){if(e===void 0)return;if(e instanceof URL){if(e.protocol!==`file:`)return e.href}else if(!e.startsWith(`file:`))return e;let t=decodeURIComponent(new URL(e).pathname);return/^\/[A-Za-z]:/.test(t)?t.slice(1).replace(/\//g,`\\`):t}function I(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:`name`in e||`version`in e||`description`in e||`bin`in e||`homepage`in e||`repository`in e}function L(e){return new w({name:typeof e==`string`?e:e.name??`cli`,inheritName:typeof e==`string`?!1:e.inherit??!1,version:void 0,description:void 0,commands:[],defaultCommand:void 0,configSettings:void 0,packageJsonSettings:void 0,helpLinks:void 0,hasBuiltInCompletions:!1,plugins:[]})}export{w as CLIBuilder,L as cli};
@@ -16,12 +16,23 @@ interface RuntimeConfigSettings {
16
16
  /** Optional format loaders (JSON/YAML/TOML); `undefined` uses built-in JSON. */
17
17
  readonly loaders: readonly FormatLoader[] | undefined;
18
18
  }
19
- /** Package.json discovery settings extracted from CLISchema. @internal */
20
- interface RuntimePackageJsonSettings {
21
- /** Whether to infer the CLI binary name from `package.json` `bin` field. */
19
+ /**
20
+ * Manifest discovery settings extracted from CLISchema for preflight use.
21
+ *
22
+ * Mirrors the public `ResolvedManifestSettings` shape (consumed structurally),
23
+ * named with the `Runtime` prefix to match its {@link RuntimeConfigSettings}
24
+ * sibling and avoid colliding with the exported public type.
25
+ * @internal
26
+ */
27
+ interface RuntimeManifestSettings {
28
+ /** Whether to infer the CLI binary name from `bin` keys or `name`. */
22
29
  readonly inferName: boolean;
30
+ /** Strip a leading `@scope/` from the inferred `name` fallback. */
31
+ readonly stripScope: boolean;
23
32
  /** Explicit anchor (resolved path) for discovery; `undefined` falls back to `adapter.cwd`. */
24
33
  readonly from: string | undefined;
34
+ /** Candidate manifest filenames in priority order. */
35
+ readonly files: readonly string[];
25
36
  /** Pre-loaded data; when set, discovery is skipped entirely. */
26
37
  readonly data: PackageJsonData | undefined;
27
38
  }
@@ -48,7 +59,7 @@ interface RuntimePreflightSchemaLike {
48
59
  /** Config file discovery settings; `undefined` disables config loading. */
49
60
  readonly configSettings: RuntimeConfigSettings | undefined;
50
61
  /** Package.json discovery settings; `undefined` disables package.json inference. */
51
- readonly packageJsonSettings: RuntimePackageJsonSettings | undefined;
62
+ readonly packageJsonSettings: RuntimeManifestSettings | undefined;
52
63
  /** Root-help header link targets; `undefined` fields may be derived from package.json. */
53
64
  readonly helpLinks: HelpLinks | undefined;
54
65
  /** Whether `.completions()` registered the built-in completions command. */
@@ -1 +1 @@
1
- import{CLIError as e,ParseError as t}from"../errors/index.mjs";import{parse as n}from"../parse/index.mjs";import{createTerminalPrompter as r}from"../prompt/index.mjs";import{discoverPackageJson as i,inferCliName as a}from"../config/package-json.mjs";import{deriveHelpLinks as o}from"./help-links.mjs";import{planInvocation as s}from"./planner.mjs";import{discoverConfig as c}from"../config/index.mjs";const l={jsonMode:!1,isTTY:!1,verbosity:`normal`};function u(e){let t=[],n;for(let r=0;r<e.length;r+=1){let i=e[r];if(i!==void 0){if(i===`--`){t.push(...e.slice(r));break}if(n===void 0&&i.startsWith(`--config=`)){let e=i.slice(9);if(e.length>0){n=e;continue}t.push(i);continue}if(n===void 0&&i===`--config`){let a=e[r+1];if(a!==void 0&&!a.startsWith(`-`)&&a!==`--`){n=a,r+=1;continue}t.push(i);continue}t.push(i)}}return{configPath:n,filteredArgv:t}}function d(e,r){if(r.includes(`--help`)||r.includes(`-h`))return!1;try{let t=n(e,r);return e.args.some(({name:e,schema:n})=>{let r=t.args[e];return n.stdinMode&&(r===void 0||r===`-`)})}catch(e){if(e instanceof t)return!1;throw e}}function f(e,t){let n=s({schema:e,argv:t,help:{binName:e.name},output:l});switch(n.kind){case`match`:return d(n.plan.mergedSchema,n.plan.argv);case`dispatch-error`:case`needs-subcommand`:case`root-help`:case`root-version`:return!1}}function p(e,t){if(!e.hasBuiltInCompletions)return!1;let n=s({schema:e,argv:t,help:{binName:e.name},output:l});return n.kind===`match`&&n.plan.command.schema.name===`completions`}async function m(e,t,n,r){let s=e.packageJsonSettings,c=s!==void 0&&!r?await(async()=>{let n=s.data??await i(t,s.from);if(n===null)return e;let r=s.inferName?a(n):void 0;return{...e,...e.version===void 0&&n.version!==void 0?{version:n.version}:{},...e.description===void 0&&n.description!==void 0?{description:n.description}:{},...r===void 0?{}:{name:r},helpLinks:o(e.helpLinks,n,e.version??n.version)}})():e;return n===void 0?c:{...c,name:n}}async function h(t,n,r,i,a){if(t.configSettings===void 0||i||a!==void 0)return a;try{let e=await c(t.configSettings.appName,n,{...r===void 0?{}:{configPath:r},...t.configSettings.loaders===void 0?{}:{loaders:t.configSettings.loaders}});return e.found?e.data:void 0}catch(t){if(t instanceof e)return t;throw t}}async function g(t){let n=t.adapter.argv.slice(2),{configPath:i,filteredArgv:a}=t.schema.configSettings===void 0?{configPath:void 0,filteredArgv:n}:u(n),o=a.includes(`--json`)||t.options?.jsonMode===!0,s=p(t.schema,a),c=await m(t.schema,t.adapter,t.inheritedName,s),l=await h(c,t.adapter,i,s,t.options?.config);if(l instanceof e)return{kind:`config-error`,error:l,jsonMode:o};let d=t.options?.prompter===void 0&&t.adapter.stdinIsTTY?r(t.adapter.stdin,t.adapter.stderr):void 0,g=t.options?.stdinData===void 0&&f(c,a)?await t.adapter.readStdin():t.options?.stdinData;return{kind:`ready`,schema:c,filteredArgv:a,inputs:{env:t.options?.env??t.adapter.env,isTTY:t.options?.isTTY??t.adapter.isTTY,jsonMode:o,verbosity:t.options?.verbosity??`normal`,...g===void 0?{}:{stdinData:g},...t.options?.prompter===void 0?d===void 0?{}:{prompter:d}:{prompter:t.options.prompter},...l===void 0?{}:{config:l}}}}export{g as prepareRuntimePreflight};
1
+ import{CLIError as e,ParseError as t}from"../errors/index.mjs";import{parse as n}from"../parse/index.mjs";import{createTerminalPrompter as r}from"../prompt/index.mjs";import{discoverManifest as i,inferCliName as a}from"../config/package-json.mjs";import{deriveHelpLinks as o}from"./help-links.mjs";import{planInvocation as s}from"./planner.mjs";import{discoverConfig as c}from"../config/index.mjs";const l={jsonMode:!1,isTTY:!1,verbosity:`normal`};function u(e){let t=[],n;for(let r=0;r<e.length;r+=1){let i=e[r];if(i!==void 0){if(i===`--`){t.push(...e.slice(r));break}if(n===void 0&&i.startsWith(`--config=`)){let e=i.slice(9);if(e.length>0){n=e;continue}t.push(i);continue}if(n===void 0&&i===`--config`){let a=e[r+1];if(a!==void 0&&!a.startsWith(`-`)&&a!==`--`){n=a,r+=1;continue}t.push(i);continue}t.push(i)}}return{configPath:n,filteredArgv:t}}function d(e,r){if(r.includes(`--help`)||r.includes(`-h`))return!1;try{let t=n(e,r);return e.args.some(({name:e,schema:n})=>{let r=t.args[e];return n.stdinMode&&(r===void 0||r===`-`)})}catch(e){if(e instanceof t)return!1;throw e}}function f(e,t){let n=s({schema:e,argv:t,help:{binName:e.name},output:l});switch(n.kind){case`match`:return d(n.plan.mergedSchema,n.plan.argv);case`dispatch-error`:case`needs-subcommand`:case`root-help`:case`root-version`:return!1}}function p(e,t){if(!e.hasBuiltInCompletions)return!1;let n=s({schema:e,argv:t,help:{binName:e.name},output:l});return n.kind===`match`&&n.plan.command.schema.name===`completions`}async function m(e,t,n,r){let s=e.packageJsonSettings,c=s!==void 0&&!r?await(async()=>{let n=s.data??await i(t,{...s.from===void 0?{}:{startDir:s.from},files:s.files});if(n===null)return e;let r=s.inferName?a(n,{stripScope:s.stripScope}):void 0;return{...e,...e.version===void 0&&n.version!==void 0?{version:n.version}:{},...e.description===void 0&&n.description!==void 0?{description:n.description}:{},...r===void 0?{}:{name:r},helpLinks:o(e.helpLinks,n,e.version??n.version)}})():e;return n===void 0?c:{...c,name:n}}async function h(t,n,r,i,a){if(t.configSettings===void 0||i||a!==void 0)return a;try{let e=await c(t.configSettings.appName,n,{...r===void 0?{}:{configPath:r},...t.configSettings.loaders===void 0?{}:{loaders:t.configSettings.loaders}});return e.found?e.data:void 0}catch(t){if(t instanceof e)return t;throw t}}async function g(t){let n=t.adapter.argv.slice(2),{configPath:i,filteredArgv:a}=t.schema.configSettings===void 0?{configPath:void 0,filteredArgv:n}:u(n),o=a.includes(`--json`)||t.options?.jsonMode===!0,s=p(t.schema,a),c=await m(t.schema,t.adapter,t.inheritedName,s),l=await h(c,t.adapter,i,s,t.options?.config);if(l instanceof e)return{kind:`config-error`,error:l,jsonMode:o};let d=t.options?.prompter===void 0&&t.adapter.stdinIsTTY?r(t.adapter.stdin,t.adapter.stderr):void 0,g=t.options?.stdinData===void 0&&f(c,a)?await t.adapter.readStdin():t.options?.stdinData;return{kind:`ready`,schema:c,filteredArgv:a,inputs:{env:t.options?.env??t.adapter.env,isTTY:t.options?.isTTY??t.adapter.isTTY,jsonMode:o,verbosity:t.options?.verbosity??`normal`,...g===void 0?{}:{stdinData:g},...t.options?.prompter===void 0?d===void 0?{}:{prompter:d}:{prompter:t.options.prompter},...l===void 0?{}:{config:l}}}}export{g as prepareRuntimePreflight};
@@ -1,5 +1,5 @@
1
1
  import { RuntimeAdapter } from "../../runtime/adapter.mjs";
2
- import { PackageJsonAdapter, PackageJsonData, PackageRepository, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./package-json.mjs";
2
+ import { ManifestDiscoveryOptions, PackageJsonAdapter, PackageJsonData, PackageRepository, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./package-json.mjs";
3
3
 
4
4
  //#region src/core/config/index.d.ts
5
5
  /**
@@ -158,4 +158,4 @@ declare function discoverConfig(appName: string, adapter: ConfigAdapter, options
158
158
  */
159
159
  declare function configFormat(extensions: readonly string[], parse: (content: string) => unknown): FormatLoader;
160
160
  //#endregion
161
- export { type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type FormatLoader, type PackageJsonAdapter, type PackageJsonData, type PackageRepository, buildConfigSearchPaths, configFormat, discoverConfig, discoverPackageJson, inferCliName, packageRepositoryUrl };
161
+ export { type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type FormatLoader, type ManifestDiscoveryOptions, type PackageJsonAdapter, type PackageJsonData, type PackageRepository, buildConfigSearchPaths, configFormat, discoverConfig, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl };