@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 +52 -1
- package/README.md +5 -5
- package/dist/core/cli/index.d.mts +173 -64
- package/dist/core/cli/index.mjs +1 -1
- package/dist/core/cli/runtime-preflight.d.mts +15 -4
- package/dist/core/cli/runtime-preflight.mjs +1 -1
- package/dist/core/config/index.d.mts +2 -2
- package/dist/core/config/package-json.d.mts +93 -20
- package/dist/core/config/package-json.mjs +3 -1
- package/dist/core/output/activity.mjs +1 -1
- package/dist/core/output/bind.d.mts +37 -0
- package/dist/core/output/bind.mjs +1 -0
- package/dist/core/output/index.mjs +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +15 -13
- package/src/core/cli/index.ts +286 -88
- package/src/core/cli/runtime-preflight.ts +24 -7
- package/src/core/config/index.ts +12 -2
- package/src/core/config/package-json.ts +250 -41
- package/src/core/output/activity.ts +7 -0
- package/src/core/output/bind.ts +59 -0
- package/src/core/output/index.ts +6 -0
- package/src/index.ts +6 -0
|
@@ -39,26 +39,88 @@ interface PackageJsonData {
|
|
|
39
39
|
* dependency explicit.
|
|
40
40
|
*/
|
|
41
41
|
type PackageJsonAdapter = Pick<RuntimeAdapter, 'readFile' | 'cwd'>;
|
|
42
|
+
/** Options for {@link discoverManifest}. */
|
|
43
|
+
interface ManifestDiscoveryOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Explicit directory or file path to walk up from. Defaults to
|
|
46
|
+
* `adapter.cwd` when omitted. Pass an absolute path inside your own package
|
|
47
|
+
* (e.g. `fileURLToPath(import.meta.url)`) for installable CLIs whose version
|
|
48
|
+
* should reflect the CLI's own package, not the consumer's working directory.
|
|
49
|
+
*
|
|
50
|
+
* This low-level helper takes a resolved path **string** only. The builder
|
|
51
|
+
* sugar `CLIBuilder.manifest({ from })` exposes the same anchor under the name
|
|
52
|
+
* `from` and additionally accepts a `file:` URL string or `URL` instance,
|
|
53
|
+
* normalizing it to a path first.
|
|
54
|
+
*/
|
|
55
|
+
readonly startDir?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Candidate manifest filenames, in per-directory priority order
|
|
58
|
+
* (e.g. `['deno.json', 'jsr.json']`). At each directory the first existing
|
|
59
|
+
* file that carries CLI metadata wins, so the nearest manifest directory
|
|
60
|
+
* always takes precedence over file order. A file that parses but holds no
|
|
61
|
+
* recognised metadata (e.g. a config-only `deno.json` with just
|
|
62
|
+
* `tasks`/`imports`) is skipped, so a sibling `jsr.json` — or a manifest
|
|
63
|
+
* higher up — can still be found. Defaults to `['package.json']`.
|
|
64
|
+
*
|
|
65
|
+
* An empty list is a deliberate no-op: with no candidates to probe, the
|
|
66
|
+
* walk-up reads nothing and resolves to `null` (consistent with the
|
|
67
|
+
* "returns `null` when no manifest is found" contract).
|
|
68
|
+
*/
|
|
69
|
+
readonly files?: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Discover the nearest manifest (`package.json`, `deno.json`, `jsr.json`, …)
|
|
73
|
+
* by walking up from `startDir` (or `adapter.cwd` when omitted).
|
|
74
|
+
*
|
|
75
|
+
* Convenience helper behind `CLIBuilder.manifest()`. Most apps should let the
|
|
76
|
+
* CLI runtime discover metadata automatically; call this directly when testing
|
|
77
|
+
* metadata inference or embedding the behavior in custom tooling.
|
|
78
|
+
*
|
|
79
|
+
* Candidate files are parsed as JSON with a JSONC fallback — `package.json`,
|
|
80
|
+
* `deno.json`, `jsr.json`, and `deno.jsonc` all qualify, including files that
|
|
81
|
+
* carry `//` / block comments or trailing commas (common in `deno.json`). A
|
|
82
|
+
* file that fails both parses is skipped, so discovery keeps probing.
|
|
83
|
+
*
|
|
84
|
+
* Returns the parsed metadata on success, `null` when no manifest is found
|
|
85
|
+
* (not an error). Malformed JSON, non-object roots, and config-only manifests
|
|
86
|
+
* that carry no recognised metadata (e.g. a `deno.json` with only `tasks` /
|
|
87
|
+
* `imports`) are all skipped, so discovery keeps probing the remaining
|
|
88
|
+
* candidate files and parent directories — the feature is a convenience, not a
|
|
89
|
+
* hard requirement.
|
|
90
|
+
*
|
|
91
|
+
* @param adapter - Adapter providing `readFile` + `cwd`.
|
|
92
|
+
* @param options - Optional anchor (`startDir`) and candidate filenames (`files`).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { discoverManifest } from '@kjanat/dreamcli';
|
|
97
|
+
*
|
|
98
|
+
* const meta = await discoverManifest(adapter, { files: ['deno.json', 'jsr.json'] });
|
|
99
|
+
* if (meta !== null) {
|
|
100
|
+
* console.log(meta.version); // '1.2.3'
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function discoverManifest(adapter: PackageJsonAdapter, options?: ManifestDiscoveryOptions): Promise<PackageJsonData | null>;
|
|
42
105
|
/**
|
|
43
106
|
* Discover the nearest `package.json` by walking up from `startDir` (or
|
|
44
107
|
* `adapter.cwd` when omitted).
|
|
45
108
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* when testing metadata inference or embedding the behavior in custom tooling.
|
|
109
|
+
* @deprecated Use {@link discoverManifest} with `{ files: ['package.json'] }`
|
|
110
|
+
* (the default), which also supports `deno.json` / `jsr.json`.
|
|
49
111
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
112
|
+
* Behavior note (changed by the manifest generalization): a parseable but
|
|
113
|
+
* metadata-less `package.json` — `{}`, or one carrying only non-metadata fields
|
|
114
|
+
* such as `dependencies` / `scripts` / `type` — is no longer treated as a
|
|
115
|
+
* discovery hit. Previously such a file halted the walk-up and resolved to `{}`;
|
|
116
|
+
* now it is skipped and the walk-up CONTINUES to parent directories. In a
|
|
117
|
+
* monorepo this means a metadata-less leaf `package.json` no longer shadows an
|
|
118
|
+
* ancestor manifest, so an ancestor's `version` can surface where the old
|
|
119
|
+
* behavior returned `{}`. Pass pre-loaded `data` (or use {@link discoverManifest}
|
|
120
|
+
* with an explicit `startDir`) when you need to pin discovery to one directory.
|
|
53
121
|
*
|
|
54
122
|
* @param adapter - Adapter providing `readFile` + `cwd`.
|
|
55
123
|
* @param startDir - Optional explicit directory or file path to walk up from.
|
|
56
|
-
* Pass an absolute path inside your own package (e.g.
|
|
57
|
-
* `fileURLToPath(import.meta.url)`) when authoring an installable CLI whose
|
|
58
|
-
* version should reflect the CLI's own package, not the consumer's working
|
|
59
|
-
* directory. Defaults to `adapter.cwd` when `undefined`. A file path is
|
|
60
|
-
* probed as a directory first (yielding nothing) before the walk-up reaches
|
|
61
|
-
* its real parent directory, so passing `import.meta.url` resolves correctly.
|
|
62
124
|
*
|
|
63
125
|
* @example
|
|
64
126
|
* ```ts
|
|
@@ -91,23 +153,34 @@ declare function discoverPackageJson(adapter: PackageJsonAdapter, startDir?: str
|
|
|
91
153
|
*/
|
|
92
154
|
declare function packageRepositoryUrl(pkg: PackageJsonData): string | undefined;
|
|
93
155
|
/**
|
|
94
|
-
* Infer the CLI binary name from
|
|
156
|
+
* Infer the CLI binary name from manifest data.
|
|
95
157
|
*
|
|
96
158
|
* Resolution order:
|
|
97
159
|
* 1. First key of `bin` object (e.g. `{"mycli": "./dist/cli.js"}` → `"mycli"`)
|
|
98
|
-
* 2. Package `name
|
|
160
|
+
* 2. Package `name`, scope stripped by default (e.g. `"@scope/mycli"` → `"mycli"`);
|
|
161
|
+
* pass `{ stripScope: false }` to keep the full scoped name
|
|
99
162
|
* 3. `undefined` if neither exists
|
|
100
163
|
*
|
|
164
|
+
* Note: `bin` keys are never scoped, so `stripScope` only affects the `name`
|
|
165
|
+
* fallback (relevant for `deno.json` / `jsr.json`, which have no `bin` field).
|
|
166
|
+
*
|
|
167
|
+
* @param pkg - Parsed manifest metadata.
|
|
168
|
+
* @param options - `stripScope` (default `true`): strip a leading `@scope/`
|
|
169
|
+
* from the `name` fallback.
|
|
170
|
+
*
|
|
101
171
|
* @example
|
|
102
172
|
* ```ts
|
|
103
173
|
* import { inferCliName } from '@kjanat/dreamcli';
|
|
104
174
|
*
|
|
105
|
-
* inferCliName({ bin: { mycli: './dist/cli.js' } });
|
|
106
|
-
* inferCliName({ name: '@scope/mycli' });
|
|
107
|
-
* inferCliName({ name: 'mycli' });
|
|
108
|
-
* inferCliName({});
|
|
175
|
+
* inferCliName({ bin: { mycli: './dist/cli.js' } }); // 'mycli'
|
|
176
|
+
* inferCliName({ name: '@scope/mycli' }); // 'mycli'
|
|
177
|
+
* inferCliName({ name: '@scope/mycli' }, { stripScope: false }); // '@scope/mycli'
|
|
178
|
+
* inferCliName({ name: 'mycli' }); // 'mycli'
|
|
179
|
+
* inferCliName({}); // undefined
|
|
109
180
|
* ```
|
|
110
181
|
*/
|
|
111
|
-
declare function inferCliName(pkg: PackageJsonData
|
|
182
|
+
declare function inferCliName(pkg: PackageJsonData, options?: {
|
|
183
|
+
readonly stripScope?: boolean;
|
|
184
|
+
}): string | undefined;
|
|
112
185
|
//#endregion
|
|
113
|
-
export { type PackageJsonAdapter, type PackageJsonData, type PackageRepository, discoverPackageJson, inferCliName, packageRepositoryUrl };
|
|
186
|
+
export { type ManifestDiscoveryOptions, type PackageJsonAdapter, type PackageJsonData, type PackageRepository, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl };
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{stripTrailing as e}from"../../strings.mjs";function t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function n(e){let t=e.lastIndexOf(`/`),n=e.lastIndexOf(`\\`),r=Math.max(t,n),i=n>t?`\\`:`/`;if(r<0)return;if(r===0)return e.length>1?i:void 0;let a=e.slice(0,r);if(a.length===2&&a[1]===`:`){let t=`${a}${i}`;return t===e?void 0:t}return a}function r(e,t){let n=e.includes(`\\`)?`\\`:`/`;return e.endsWith(n)?`${e}${t}`:`${e}${n}${t}`}
|
|
1
|
+
import{stripTrailing as e}from"../../strings.mjs";function t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function n(e){let t=e.lastIndexOf(`/`),n=e.lastIndexOf(`\\`),r=Math.max(t,n),i=n>t?`\\`:`/`;if(r<0)return;if(r===0)return e.length>1?i:void 0;let a=e.slice(0,r);if(a.length===2&&a[1]===`:`){let t=`${a}${i}`;return t===e?void 0:t}return a}function r(e,t){let n=e.includes(`\\`)?`\\`:`/`;return e.endsWith(n)?`${e}${t}`:`${e}${n}${t}`}const i=[`package.json`];function a(e){return e.name!==void 0||e.version!==void 0||e.description!==void 0||e.bin!==void 0||e.homepage!==void 0||e.repository!==void 0}async function o(e,t={}){let o=t.files??i,s=t.startDir??e.cwd;for(;s!==void 0;){for(let t of o){let n=null;try{n=await e.readFile(r(s,t))}catch{}if(n!==null){let e=u(n);if(e!==null&&a(e))return e}}s=n(s)}return null}async function s(e,t){return o(e,t===void 0?{}:{startDir:t})}function c(e){return e===` `||e===` `||e===`
|
|
2
|
+
`||e===`\r`}function l(e){let t=``,n=!1,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i]??``;if(n){t+=a,r?r=!1:a===`\\`?r=!0:a===`"`&&(n=!1);continue}if(a===`"`){n=!0,t+=a;continue}if(a===`/`&&e[i+1]===`/`){for(i+=2;i<e.length&&e[i]!==`
|
|
3
|
+
`;)i+=1;--i;continue}if(a===`/`&&e[i+1]===`*`){for(i+=2;i<e.length&&!(e[i]===`*`&&e[i+1]===`/`);)i+=1;i+=1;continue}t+=a}let i=``;n=!1,r=!1;for(let e=0;e<t.length;e+=1){let a=t[e]??``;if(n){i+=a,r?r=!1:a===`\\`?r=!0:a===`"`&&(n=!1);continue}if(a===`"`){n=!0,i+=a;continue}if(a===`,`){let n=e+1;for(;n<t.length&&c(t[n]??``);)n+=1;let r=t[n];if(r===`}`||r===`]`)continue}i+=a}return i}function u(e){let n;try{n=JSON.parse(e)}catch{try{n=JSON.parse(l(e))}catch{return null}}try{if(!t(n))return null;let e=typeof n.name==`string`?n.name:void 0,r=typeof n.version==`string`?n.version:void 0,i=typeof n.description==`string`?n.description:void 0,a=d(n.bin),o=typeof n.homepage==`string`?n.homepage:void 0,s=f(n.repository);return{...e===void 0?{}:{name:e},...r===void 0?{}:{version:r},...i===void 0?{}:{description:i},...a===void 0?{}:{bin:a},...o===void 0?{}:{homepage:o},...s===void 0?{}:{repository:s}}}catch{return null}}function d(e){if(typeof e==`string`)return e;if(!t(e))return;let n={};for(let[t,r]of Object.entries(e)){if(typeof r!=`string`)return;n[t]=r}return n}function f(e){if(typeof e==`string`)return e;if(!t(e))return;let n=typeof e.type==`string`?e.type:void 0,r=typeof e.url==`string`?e.url:void 0,i=typeof e.directory==`string`?e.directory:void 0;if(!(n===void 0&&r===void 0&&i===void 0))return{...n===void 0?{}:{type:n},...r===void 0?{}:{url:r},...i===void 0?{}:{directory:i}}}const p={github:`https://github.com`,gitlab:`https://gitlab.com`,bitbucket:`https://bitbucket.org`};function m(e){return e.endsWith(`.git`)?e.slice(0,-4):e}function h(t){let n=typeof t.repository==`string`?t.repository:t.repository?.url;if(n===void 0)return;let r=n.trim();if(r.length===0)return;let i=/^(github|gitlab|bitbucket):([^/]+\/[^/]+)$/.exec(r);if(i!==null&&i[1]!==void 0&&i[2]!==void 0){let e=p[i[1]];if(e!==void 0)return`${e}/${m(i[2])}`}if(/^[\w.-]+\/[\w.-]+$/.test(r))return`https://github.com/${m(r)}`;r.startsWith(`git+`)&&(r=r.slice(4));let a=/^git@([^:/]+):(.+)$/.exec(r);if(a!==null&&a[1]!==void 0&&a[2]!==void 0)return`https://${a[1]}/${m(e(a[2],[47]))}`;if(/^(?:https?|git|ssh):\/\//.test(r))try{let t=new URL(r),n=m(e(t.pathname,[47]));return`https://${t.hostname}${n}`}catch{return}}function g(e,t={}){if(typeof e.bin==`object`){let t=Object.keys(e.bin);if(t.length>0&&t[0]!==void 0)return t[0]}if(e.name!==void 0){if(t.stripScope===!1)return e.name;let n=e.name.indexOf(`/`);return n>=0?e.name.slice(n+1):e.name}}export{o as discoverManifest,s as discoverPackageJson,g as inferCliName,h as packageRepositoryUrl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{bindMethods as e}from"./bind.mjs";import{writeLine as t}from"./writer.mjs";const n={update(){},succeed(){},fail(){},stop(){},wrap(e){return e}},r={increment(){},update(){},done(){},fail(){}};var i=class{write;stopped=!1;constructor(n,r){this.write=r,t(r,n),e(this)}update(e){}succeed(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}stop(){this.stopped||=!0}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},a=class{write;stopped=!1;constructor(n,r){this.write=r,n!==void 0&&t(r,n),e(this)}increment(e){}update(e){}done(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}};const o=`\x1B[?25l`,s=`\x1B[?25h`,c=`\x1B[2K`,l=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];var u=class{write;stopped=!1;timer;frameIndex=0;text;constructor(t,n){this.write=n,this.text=t,n(o),this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%l.length,this.render()},80),e(this)}render(){let e=l[this.frameIndex]??l[0];this.write(`\r${c}${e} ${this.text}`)}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${c}${s}`)}update(e){this.stopped||(this.text=e,this.render())}succeed(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✗ ${e}`))}stop(){this.stopped||(this.stopped=!0,this.cleanup())}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},d=class{write;stopped=!1;timer;current=0;total;label;pulsePos=0;pulseDir=1;constructor(t,n){this.write=n,this.total=t.total,this.label=t.label??``,n(o),this.render(),this.total===void 0&&(this.timer=setInterval(()=>{this.advancePulse(),this.render()},80)),e(this)}advancePulse(){this.pulsePos+=this.pulseDir,this.pulsePos+3>20?(this.pulseDir=-1,this.pulsePos=17):this.pulsePos<0&&(this.pulseDir=1,this.pulsePos=0)}render(){let e=this.total===void 0?this.renderIndeterminate():this.renderDeterminate(this.total),t=this.label.length>0?` ${this.label}`:``;this.write(`\r${c}${e}${t}`)}renderDeterminate(e){let t=e>0?Math.max(0,Math.min(this.current/e,1)):0,n=Math.round(t*20),r=20-n,i=Math.round(t*100);return`[${`█`.repeat(n)}${`░`.repeat(r)}] ${String(i)}%`}renderIndeterminate(){let e=``;for(let t=0;t<20;t++)e+=t>=this.pulsePos&&t<this.pulsePos+3?`█`:`░`;return`[${e}]`}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${c}${s}`)}increment(e){this.stopped||(this.current+=e??1,this.render())}update(e){this.stopped||(this.current=e,this.render())}done(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✗ ${e}`))}},f=class{events;stopped=!1;constructor(t,n){this.events=n,n.push({type:`spinner:start`,text:t}),e(this)}update(e){this.stopped||this.events.push({type:`spinner:update`,text:e})}succeed(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:succeed`,text:e??``}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:fail`,text:e??``}))}stop(){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:stop`}))}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},p=class{events;stopped=!1;constructor(t,n){this.events=n,n.push({type:`progress:start`,label:t.label??``,total:t.total}),e(this)}increment(e){this.stopped||this.events.push({type:`progress:increment`,delta:e??1})}update(e){this.stopped||this.events.push({type:`progress:update`,value:e})}done(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:done`,text:e}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:fail`,text:e}))}};export{p as CaptureProgressHandle,f as CaptureSpinnerHandle,a as StaticProgressHandle,i as StaticSpinnerHandle,d as TTYProgressHandle,u as TTYSpinnerHandle,r as noopProgressHandle,n as noopSpinnerHandle};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/core/output/bind.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Method-binding helper for value objects handed to consumers.
|
|
4
|
+
*
|
|
5
|
+
* Output value objects — the `Out` channel and the spinner/progress handles
|
|
6
|
+
* — expose methods that read instance state via `this`. Consumers naturally
|
|
7
|
+
* detach those methods, either by destructuring
|
|
8
|
+
* (`const { log } = out` / `const { succeed, fail } = spinner`) or by passing
|
|
9
|
+
* them as callbacks (`promise.finally(spinner.stop)`). Detached, an unbound
|
|
10
|
+
* prototype method loses its `this` and crashes on the first field access.
|
|
11
|
+
*
|
|
12
|
+
* {@linkcode bindMethods} eliminates that footgun by installing instance-bound
|
|
13
|
+
* copies of every method, so the ergonomic usage is also the correct one.
|
|
14
|
+
*
|
|
15
|
+
* @module dreamcli/core/output/bind
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Bind every method on an instance's prototype chain to the instance.
|
|
20
|
+
*
|
|
21
|
+
* Walks the prototype chain up to (but excluding) `Object.prototype`, binding
|
|
22
|
+
* each method name exactly once — the most-derived definition wins, so subclass
|
|
23
|
+
* overrides (e.g. `CaptureOutputChannel.spinner`) are preserved rather than
|
|
24
|
+
* clobbered by a base-class version. Bound methods are installed as
|
|
25
|
+
* non-enumerable own properties, mirroring the enumerability of the prototype
|
|
26
|
+
* methods they shadow. Getters and non-function members are left untouched.
|
|
27
|
+
*
|
|
28
|
+
* Call this once, last, in a class constructor. Because it reads the live
|
|
29
|
+
* prototype rather than a hand-maintained name list, methods added later are
|
|
30
|
+
* bound automatically — the binding can't silently fall out of date.
|
|
31
|
+
*
|
|
32
|
+
* @param instance - The object whose methods should be bound to it.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
declare function bindMethods(instance: object): void;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { bindMethods };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=e,n=new Set,r=Object.getPrototypeOf(e);for(;r!==null&&r!==Object.prototype;){for(let i of Object.getOwnPropertyNames(r)){if(i===`constructor`||n.has(i))continue;n.add(i);let a=Object.getOwnPropertyDescriptor(r,i);a===void 0||typeof a.value!=`function`||Object.defineProperty(t,i,{value:a.value.bind(e),writable:!0,enumerable:!1,configurable:!0})}r=Object.getPrototypeOf(r)}}export{e as bindMethods};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{formatDisplayValue as e}from"./display-value.mjs";import{
|
|
2
|
-
`)}function
|
|
1
|
+
import{formatDisplayValue as e}from"./display-value.mjs";import{bindMethods as t}from"./bind.mjs";import{writeLine as n}from"./writer.mjs";import{CaptureProgressHandle as r,CaptureSpinnerHandle as i}from"./activity.mjs";import{resolveOutputPolicy as a,resolveProgressPolicy as o,resolveSpinnerPolicy as s,resolveTableFormat as c,resolveTableTextStream as l,resolveTextStream as u,shouldEmitInfo as d}from"./contracts.mjs";import{createProgressHandleFromPolicy as f,createSpinnerHandleFromPolicy as p,resolveWriterForStream as m}from"./renderers.mjs";const h=()=>{},g=new WeakMap;function _(e){if(!Number.isInteger(e)||e<0||e>255)throw RangeError(`Exit code must be an integer from 0 to 255`);return e}function v(e,t){g.set(e,_(t))}function y(e){return g.get(e)}function b(e){g.delete(e)}function x(e){return{stdout:e?.stdout??h,stderr:e?.stderr??h,isTTY:e?.isTTY??!1,verbosity:e?.verbosity??`normal`,jsonMode:e?.jsonMode??!1}}var S=class{options;policy;jsonMode;isTTY;constructor(e){this.options=e,this.policy=a(e),this.jsonMode=e.jsonMode,this.isTTY=e.isTTY,t(this)}log(e){n(m(this.options,u(this.policy)),e)}info(e){d(this.policy)&&n(m(this.options,u(this.policy)),e)}warn(e){n(this.options.stderr,e)}error(e){n(this.options.stderr,e)}setExitCode(e){v(this,e)}json(e){n(this.options.stdout,JSON.stringify(e))}table(e,t,r){let{columns:i,options:a}=E(t,r),o=c(this.policy,a),s=i??w(e);if(o===`json`){this.json(D(e,s));return}let l=A(e,s);l.length!==0&&n(O(this.options,this.policy,o,a),l)}activeCleanup;stopActive(){this.activeCleanup!==void 0&&(this.activeCleanup(),this.activeCleanup=void 0)}spinner(e,t){let n=p(s(this.policy,t?.fallback??`silent`),e,this.options.stderr);return n.cleanup===void 0?n.handle:(this.stopActive(),this.activeCleanup=n.cleanup,n.handle)}progress(e){let t=f(o(this.policy,e.fallback??`silent`),e,this.options.stderr);return t.cleanup===void 0?t.handle:(this.stopActive(),this.activeCleanup=t.cleanup,t.handle)}},C=class extends S{activity;constructor(e,t){super(e),this.activity=t}spinner(e,t){return new i(e,this.activity)}progress(e){return new r(e,this.activity)}};function w(e){let t=e[0];return t===void 0?[]:Object.keys(t).map(e=>({key:e}))}function T(e){return Array.isArray(e)}function E(e,t){return t===void 0?T(e)?{columns:e,options:t}:{columns:void 0,options:e}:{columns:T(e)?e:void 0,options:t}}function D(e,t){return e.map(e=>Object.fromEntries(t.map(t=>[t.key,e[t.key]])))}function O(e,t,n,r){return n===`json`?e.stdout:m(e,l(t,r))}function k(t){return e(t)}function A(e,t){if(e.length===0||t.length===0)return``;let n=t.map(e=>e.header??e.key),r=e.map(e=>t.map(t=>k(e[t.key]))),i=n.map((e,t)=>{let n=e.length;for(let e of r){let r=e[t];r!==void 0&&r.length>n&&(n=r.length)}return n});return[n.map((e,t)=>e.padEnd(i[t]??0)).join(` `),i.map(e=>`-`.repeat(e)).join(` `),...r.map(e=>e.map((e,t)=>e.padEnd(i[t]??0)).join(` `))].join(`
|
|
2
|
+
`)}function j(e){return new S(x(e))}function M(e){let t={stdout:[],stderr:[],activity:[]};return[new C(x({...e,stdout:e=>t.stdout.push(e),stderr:e=>t.stderr.push(e)}),t.activity),t]}export{b as clearRequestedExitCode,M as createCaptureOutput,j as createOutput,y as getRequestedExitCode};
|
package/dist/index.d.mts
CHANGED
|
@@ -16,7 +16,7 @@ import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
|
16
16
|
import { HelpOptions, formatHelp } from "./core/help/index.mjs";
|
|
17
17
|
import { RunResult } from "./core/schema/run.mjs";
|
|
18
18
|
import { ActionHandler, ActionParams, AnyCommandBuilder, CommandArgEntry, CommandBuilder, CommandConfig, CommandExample, CommandMeta, CommandSchema, DeriveHandler, DeriveParams, InteractiveParams, InteractiveResolver, InteractiveResult, Out, command, group } from "./core/schema/command.mjs";
|
|
19
|
-
import { PackageJsonAdapter, PackageJsonData, PackageRepository, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
19
|
+
import { ManifestDiscoveryOptions, PackageJsonAdapter, PackageJsonData, PackageRepository, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
20
20
|
import { HelpLinks } from "./core/cli/help-links.mjs";
|
|
21
21
|
import { CompletionOptions } from "./core/completion/shells/shared.mjs";
|
|
22
22
|
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
@@ -25,6 +25,6 @@ import { generatePowerShellCompletion } from "./core/completion/shells/powershel
|
|
|
25
25
|
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
26
26
|
import { SHELLS, Shell, generateCompletion } from "./core/completion/index.mjs";
|
|
27
27
|
import { ConfigAdapter, ConfigDiscoveryOptions, ConfigDiscoveryResult, ConfigFound, ConfigNotFound, FormatLoader, buildConfigSearchPaths, configFormat, discoverConfig } from "./core/config/index.mjs";
|
|
28
|
-
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, PackageJsonSettings, cli } from "./core/cli/index.mjs";
|
|
28
|
+
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
29
29
|
import { JsonSchemaOptions, definitionMetaSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
30
|
-
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
|
30
|
+
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InferNameOption, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type ManifestDiscoveryOptions, type ManifestPresetSettings, type ManifestSettings, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedManifestSettings, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FlagBuilder as e,createSchema as t,flag as n}from"./core/schema/flag.mjs";import{generateBashCompletion as r}from"./core/completion/shells/bash.mjs";import{generateFishCompletion as i}from"./core/completion/shells/fish.mjs";import{generatePowerShellCompletion as a}from"./core/completion/shells/powershell.mjs";import{CLIError as o,ParseError as s,ValidationError as c,isCLIError as l,isParseError as u,isValidationError as d}from"./core/errors/index.mjs";import{generateZshCompletion as f}from"./core/completion/shells/zsh.mjs";import{SHELLS as p,generateCompletion as m}from"./core/completion/index.mjs";import{osc8 as h,visibleWidth as g}from"./core/help/ansi.mjs";import{formatHelp as _}from"./core/help/index.mjs";import{createOutput as v}from"./core/output/index.mjs";import{parse as y,tokenize as b}from"./core/parse/index.mjs";import{createTerminalPrompter as x,resolvePromptConfig as S}from"./core/prompt/index.mjs";import{resolve as C}from"./core/resolve/index.mjs";import{ArgBuilder as w,arg as T,createArgSchema as E}from"./core/schema/arg.mjs";import{CommandBuilder as D,command as O,group as k}from"./core/schema/command.mjs";import{
|
|
1
|
+
import{FlagBuilder as e,createSchema as t,flag as n}from"./core/schema/flag.mjs";import{generateBashCompletion as r}from"./core/completion/shells/bash.mjs";import{generateFishCompletion as i}from"./core/completion/shells/fish.mjs";import{generatePowerShellCompletion as a}from"./core/completion/shells/powershell.mjs";import{CLIError as o,ParseError as s,ValidationError as c,isCLIError as l,isParseError as u,isValidationError as d}from"./core/errors/index.mjs";import{generateZshCompletion as f}from"./core/completion/shells/zsh.mjs";import{SHELLS as p,generateCompletion as m}from"./core/completion/index.mjs";import{osc8 as h,visibleWidth as g}from"./core/help/ansi.mjs";import{formatHelp as _}from"./core/help/index.mjs";import{createOutput as v}from"./core/output/index.mjs";import{parse as y,tokenize as b}from"./core/parse/index.mjs";import{createTerminalPrompter as x,resolvePromptConfig as S}from"./core/prompt/index.mjs";import{resolve as C}from"./core/resolve/index.mjs";import{ArgBuilder as w,arg as T,createArgSchema as E}from"./core/schema/arg.mjs";import{CommandBuilder as D,command as O,group as k}from"./core/schema/command.mjs";import{discoverManifest as A,discoverPackageJson as j,inferCliName as M,packageRepositoryUrl as N}from"./core/config/package-json.mjs";import{plugin as P}from"./core/cli/plugin.mjs";import{buildConfigSearchPaths as F,configFormat as I,discoverConfig as L}from"./core/config/index.mjs";import{CLIBuilder as R,cli as z}from"./core/cli/index.mjs";import{definitionMetaSchema as B,generateInputSchema as V,generateSchema as H}from"./core/json-schema/index.mjs";import{middleware as U}from"./core/schema/middleware.mjs";export{w as ArgBuilder,R as CLIBuilder,o as CLIError,D as CommandBuilder,e as FlagBuilder,s as ParseError,p as SHELLS,c as ValidationError,T as arg,F as buildConfigSearchPaths,z as cli,O as command,I as configFormat,E as createArgSchema,v as createOutput,t as createSchema,x as createTerminalPrompter,B as definitionMetaSchema,L as discoverConfig,A as discoverManifest,j as discoverPackageJson,n as flag,_ as formatHelp,r as generateBashCompletion,m as generateCompletion,i as generateFishCompletion,V as generateInputSchema,a as generatePowerShellCompletion,H as generateSchema,f as generateZshCompletion,k as group,M as inferCliName,l as isCLIError,u as isParseError,d as isValidationError,U as middleware,h as osc8,N as packageRepositoryUrl,y as parse,P as plugin,C as resolve,S as resolvePromptConfig,b as tokenize,g as visibleWidth};
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=`2.
|
|
1
|
+
const e=`2.5.0`,t=`6d9491b`;export{t as DREAMCLI_REVISION,e as DREAMCLI_VERSION};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kjanat/dreamcli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Schema-first, fully typed TypeScript CLI framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dreamcli",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"schema-first",
|
|
11
11
|
"command-line"
|
|
12
12
|
],
|
|
13
|
-
"homepage": "https://dreamcli.kjanat.
|
|
13
|
+
"homepage": "https://dreamcli.kjanat.dev",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/kjanat/dreamcli/issues"
|
|
16
16
|
},
|
|
@@ -73,15 +73,17 @@
|
|
|
73
73
|
"./examples/*"
|
|
74
74
|
],
|
|
75
75
|
"scripts": {
|
|
76
|
-
"bd": "
|
|
77
|
-
"build": "
|
|
78
|
-
"build:watch": "
|
|
76
|
+
"bd": "run build",
|
|
77
|
+
"build": "bun --bun tsdown",
|
|
78
|
+
"build:watch": "run build --watch",
|
|
79
79
|
"ci": "run -pk typecheck lint format:check meta-descriptions:check test docs:build bd",
|
|
80
80
|
"coverage": "vitest run --coverage",
|
|
81
|
-
"dev": "
|
|
82
|
-
"docs:build": "
|
|
83
|
-
"docs:
|
|
84
|
-
"docs:
|
|
81
|
+
"dev": "run -p build:watch docs:dev",
|
|
82
|
+
"docs:build": "bun --bun vitepress build docs",
|
|
83
|
+
"docs:deploy": "wrangler deploy",
|
|
84
|
+
"docs:dev": "bun --bun vitepress dev docs --host --port ${PORT:-5173}",
|
|
85
|
+
"docs:preview": "bun --bun vitepress preview docs",
|
|
86
|
+
"docs:upload": "wrangler versions upload",
|
|
85
87
|
"fmt": "dprint fmt",
|
|
86
88
|
"fmt:autofix": "dprint fmt --allow-no-files --excludes .github",
|
|
87
89
|
"fmt:update": "dprint config update --yes --recursive",
|
|
@@ -99,11 +101,11 @@
|
|
|
99
101
|
"lint:fix": "biome lint --fix",
|
|
100
102
|
"meta-descriptions": "bun --bun scripts/build-meta-descriptions.ts",
|
|
101
103
|
"meta-descriptions:check": "bun --bun scripts/build-meta-descriptions.ts --check",
|
|
102
|
-
"prepack": "
|
|
104
|
+
"prepack": "bun --bun tsdown --logLevel silent",
|
|
103
105
|
"publish:preview": "bunx pkg-pr-new publish --bun --comment=update --packageManager=bun,npm",
|
|
104
106
|
"schema:emit": "bun scripts/emit-definition-schema.ts",
|
|
105
107
|
"test": "vitest run",
|
|
106
|
-
"test:bun": "
|
|
108
|
+
"test:bun": "bun --bun vitest run",
|
|
107
109
|
"test:gh": "run --dir examples/gh test",
|
|
108
110
|
"test:node": "npx -y vitest run",
|
|
109
111
|
"test:watch": "vitest",
|
|
@@ -159,8 +161,8 @@
|
|
|
159
161
|
}
|
|
160
162
|
},
|
|
161
163
|
"volta": {
|
|
162
|
-
"node": "
|
|
163
|
-
"npm": "11.
|
|
164
|
+
"node": "26.3.1",
|
|
165
|
+
"npm": "11.17.0"
|
|
164
166
|
},
|
|
165
167
|
"publishConfig": {
|
|
166
168
|
"access": "public",
|