@kjanat/dreamcli 1.0.0 → 2.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/CHANGELOG.md +45 -6
- package/LICENSE +1 -1
- package/README.md +296 -164
- package/dist/core/cli/dispatch.d.mts +85 -0
- package/dist/core/cli/dispatch.mjs +1 -0
- package/dist/core/cli/index.d.mts +418 -0
- package/dist/core/cli/index.mjs +1 -0
- package/dist/core/cli/planner.d.mts +143 -0
- package/dist/core/cli/planner.mjs +1 -0
- package/dist/core/cli/plugin.d.mts +94 -0
- package/dist/core/cli/plugin.mjs +1 -0
- package/dist/core/cli/propagate.d.mts +39 -0
- package/dist/core/cli/propagate.mjs +1 -0
- package/dist/core/cli/root-help.d.mts +28 -0
- package/dist/core/cli/root-help.mjs +7 -0
- package/dist/core/cli/root-surface.d.mts +42 -0
- package/dist/core/cli/root-surface.mjs +1 -0
- package/dist/core/cli/runtime-preflight.d.mts +149 -0
- package/dist/core/cli/runtime-preflight.mjs +1 -0
- package/dist/core/completion/index.d.mts +46 -0
- package/dist/core/completion/index.mjs +1 -0
- package/dist/core/completion/shells/bash.d.mts +24 -0
- package/dist/core/completion/shells/bash.mjs +3 -0
- package/dist/core/completion/shells/fish.d.mts +20 -0
- package/dist/core/completion/shells/fish.mjs +2 -0
- package/dist/core/completion/shells/powershell.d.mts +14 -0
- package/dist/core/completion/shells/powershell.mjs +2 -0
- package/dist/core/completion/shells/shared.d.mts +139 -0
- package/dist/core/completion/shells/shared.mjs +1 -0
- package/dist/core/completion/shells/zsh.d.mts +24 -0
- package/dist/core/completion/shells/zsh.mjs +2 -0
- package/dist/core/config/index.d.mts +161 -0
- package/dist/core/config/index.mjs +1 -0
- package/dist/core/config/package-json.d.mts +68 -0
- package/dist/core/config/package-json.mjs +1 -0
- package/dist/core/errors/index.d.mts +126 -0
- package/dist/core/errors/index.mjs +1 -0
- package/dist/core/execution/index.d.mts +49 -0
- package/dist/core/execution/index.mjs +1 -0
- package/dist/core/help/index.d.mts +49 -0
- package/dist/core/help/index.mjs +8 -0
- package/dist/core/json-schema/index.d.mts +109 -0
- package/dist/core/json-schema/index.mjs +55 -0
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +185 -0
- package/dist/core/json-schema/meta-descriptions.generated.mjs +28 -0
- package/dist/core/output/activity.d.mts +194 -0
- package/dist/core/output/activity.mjs +1 -0
- package/dist/core/output/contracts.d.mts +88 -0
- package/dist/core/output/contracts.mjs +1 -0
- package/dist/core/output/display-value.d.mts +19 -0
- package/dist/core/output/display-value.mjs +1 -0
- package/dist/core/output/index.d.mts +280 -0
- package/dist/core/output/index.mjs +2 -0
- package/dist/core/output/renderers.d.mts +46 -0
- package/dist/core/output/renderers.mjs +1 -0
- package/dist/core/output/writer.d.mts +40 -0
- package/dist/core/output/writer.mjs +1 -0
- package/dist/core/parse/index.d.mts +79 -0
- package/dist/core/parse/index.mjs +1 -0
- package/dist/core/prompt/index.d.mts +205 -0
- package/dist/core/prompt/index.mjs +6 -0
- package/dist/core/resolve/args.d.mts +8 -0
- package/dist/core/resolve/args.mjs +1 -0
- package/dist/core/resolve/coerce.d.mts +22 -0
- package/dist/core/resolve/coerce.mjs +1 -0
- package/dist/core/resolve/config.d.mts +10 -0
- package/dist/core/resolve/config.mjs +1 -0
- package/dist/core/resolve/contracts.d.mts +112 -0
- package/dist/core/resolve/errors.d.mts +11 -0
- package/dist/core/resolve/errors.mjs +2 -0
- package/dist/core/resolve/flags.d.mts +10 -0
- package/dist/core/resolve/flags.mjs +1 -0
- package/dist/core/resolve/index.d.mts +42 -0
- package/dist/core/resolve/index.mjs +1 -0
- package/dist/core/resolve/property.d.mts +47 -0
- package/dist/core/resolve/property.mjs +1 -0
- package/dist/core/schema/activity.d.mts +169 -0
- package/dist/core/schema/arg.d.mts +559 -0
- package/dist/core/schema/arg.mjs +1 -0
- package/dist/core/schema/command.d.mts +960 -0
- package/dist/core/schema/command.mjs +1 -0
- package/dist/core/schema/flag.d.mts +491 -0
- package/dist/core/schema/flag.mjs +1 -0
- package/dist/core/schema/index.d.mts +8 -0
- package/dist/core/schema/middleware.d.mts +122 -0
- package/dist/core/schema/middleware.mjs +1 -0
- package/dist/core/schema/prompt.d.mts +117 -0
- package/dist/core/schema/run.d.mts +171 -0
- package/dist/core/schema-dsl/runtime.d.mts +144 -0
- package/dist/core/schema-dsl/runtime.mjs +2 -0
- package/dist/core/schema-dsl/to-json-schema.d.mts +30 -0
- package/dist/core/schema-dsl/to-json-schema.mjs +1 -0
- package/dist/core/testkit/index.d.mts +54 -0
- package/dist/core/testkit/index.mjs +1 -0
- package/dist/index.d.mts +28 -920
- package/dist/index.mjs +1 -10
- package/dist/runtime/adapter.d.mts +212 -0
- package/dist/{adapter-B37d9oia.mjs → runtime/adapter.mjs} +1 -1
- package/dist/runtime/auto.d.mts +26 -0
- package/dist/runtime/auto.mjs +1 -0
- package/dist/runtime/bun.d.mts +28 -0
- package/dist/runtime/bun.mjs +1 -0
- package/dist/runtime/deno.d.mts +76 -0
- package/dist/runtime/deno.mjs +2 -0
- package/dist/runtime/detect.d.mts +86 -0
- package/dist/runtime/detect.mjs +1 -0
- package/dist/runtime/index.d.mts +7 -0
- package/dist/runtime/node.d.mts +65 -0
- package/dist/runtime/node.mjs +2 -0
- package/dist/runtime/paths.d.mts +31 -0
- package/dist/runtime/paths.mjs +1 -0
- package/dist/runtime/support.d.mts +42 -0
- package/dist/runtime/support.mjs +1 -0
- package/dist/runtime.d.mts +6 -252
- package/dist/runtime.mjs +1 -1
- package/dist/testkit.d.mts +5 -24
- package/dist/testkit.mjs +1 -1
- package/dist/version.d.mts +16 -0
- package/dist/version.mjs +1 -0
- package/dreamcli.schema.json +338 -0
- package/examples/basic.ts +2 -2
- package/examples/gh/package.json +7 -11
- package/examples/gh/src/commands/auth.ts +2 -2
- package/examples/gh/src/commands/issue.ts +4 -4
- package/examples/gh/src/commands/pr.ts +4 -4
- package/examples/gh/src/docs.ts +11 -0
- package/examples/gh/src/lib/auth.ts +1 -1
- package/examples/gh/src/main.test.ts +6 -5
- package/examples/gh/src/main.ts +8 -6
- package/examples/interactive.ts +3 -3
- package/examples/json-mode.ts +4 -6
- package/examples/middleware.ts +3 -3
- package/examples/multi-command.ts +3 -3
- package/examples/spinner-progress.ts +5 -5
- package/examples/testing.ts +8 -6
- package/package.json +70 -44
- package/src/core/cli/dispatch.ts +4 -0
- package/src/core/cli/index.ts +185 -632
- package/src/core/cli/planner.ts +413 -0
- package/src/core/cli/plugin.ts +7 -1
- package/src/core/cli/propagate.ts +1 -1
- package/src/core/cli/runtime-preflight.ts +409 -0
- package/src/core/completion/index.ts +15 -9
- package/src/core/completion/shells/bash.ts +6 -3
- package/src/core/completion/shells/fish.ts +245 -10
- package/src/core/completion/shells/powershell.ts +390 -9
- package/src/core/completion/shells/shared.ts +4 -4
- package/src/core/completion/shells/zsh.ts +12 -7
- package/src/core/config/index.ts +7 -4
- package/src/core/config/package-json.ts +6 -2
- package/src/core/errors/index.ts +23 -8
- package/src/core/execution/index.ts +270 -0
- package/src/core/help/index.ts +13 -15
- package/src/core/json-schema/index.ts +193 -7
- package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
- package/src/core/output/contracts.ts +194 -0
- package/src/core/output/index.ts +47 -82
- package/src/core/output/renderers.ts +125 -0
- package/src/core/parse/index.ts +39 -21
- package/src/core/prompt/index.ts +44 -27
- package/src/core/resolve/args.ts +144 -0
- package/src/core/resolve/coerce.ts +432 -0
- package/src/core/resolve/config.ts +26 -0
- package/src/core/resolve/contracts.ts +135 -0
- package/src/core/resolve/errors.ts +227 -0
- package/src/core/resolve/flags.ts +205 -0
- package/src/core/resolve/index.ts +41 -1264
- package/src/core/resolve/property.ts +99 -0
- package/src/core/schema/activity.ts +3 -0
- package/src/core/schema/arg.ts +26 -14
- package/src/core/schema/command.ts +265 -38
- package/src/core/schema/flag.ts +120 -15
- package/src/core/schema/index.ts +11 -2
- package/src/core/schema/middleware.ts +6 -6
- package/src/core/schema/prompt.ts +9 -1
- package/src/core/schema/run.ts +25 -17
- package/src/core/schema-dsl/index.ts +109 -0
- package/src/core/schema-dsl/parse.ts +262 -0
- package/src/core/schema-dsl/runtime.ts +609 -0
- package/src/core/schema-dsl/to-json-schema.ts +102 -0
- package/src/core/testkit/index.ts +55 -297
- package/src/index.ts +10 -4
- package/src/runtime/adapter.ts +13 -10
- package/src/runtime/auto.ts +3 -3
- package/src/runtime/bun.ts +4 -4
- package/src/runtime/deno.ts +43 -29
- package/src/runtime/detect.ts +4 -1
- package/src/runtime/index.ts +1 -1
- package/src/runtime/node.ts +43 -21
- package/src/runtime/paths.ts +9 -3
- package/src/runtime/support.ts +20 -4
- package/src/runtime.ts +1 -1
- package/src/testkit.ts +10 -8
- package/dist/adapter-CCSh5juX.cjs +0 -1
- package/dist/adapter-DIwO-q7K.d.mts +0 -3447
- package/dist/adapter-DQnxxLiE.d.cts +0 -3447
- package/dist/auto-5cjZaF9V.mjs +0 -3
- package/dist/auto-B0eSgoDw.cjs +0 -3
- package/dist/index.cjs +0 -10
- package/dist/index.d.cts +0 -920
- package/dist/runtime.cjs +0 -1
- package/dist/runtime.d.cts +0 -253
- package/dist/testkit-CEDYPvhF.mjs +0 -14
- package/dist/testkit-ClIKijxC.cjs +0 -14
- package/dist/testkit.cjs +0 -1
- package/dist/testkit.d.cts +0 -25
- package/examples/gh/tsconfig.json +0 -37
- package/examples/tsconfig.json +0 -17
- package/src/core/cli/AGENTS.md +0 -72
- package/src/core/completion/AGENTS.md +0 -72
- package/src/core/completion/completion-test-helpers.ts +0 -48
- package/src/core/output/AGENTS.md +0 -69
- package/src/core/resolve/AGENTS.md +0 -69
- package/src/core/schema/AGENTS.md +0 -61
- package/src/core/testkit/AGENTS.md +0 -55
- package/src/runtime/AGENTS.md +0 -74
- package/src/runtime/test-helpers.ts +0 -40
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";import{assertRuntimeVersionSupported as n}from"./support.mjs";function r(){return globalThis.process}function i(e){return typeof e!=`object`||!e||!(`code`in e)?!1:typeof e.code==`string`}function a(e,n){return t(e,n===`win32`)}function o(t,n,r){return e(t,n===`win32`,r)}function s(e){if(e.versions?.bun!==void 0){n(`bun`,e.versions.bun);return}n(`node`,e.versions?.node)}function c(e){let t=e??r();s(t);let n=e=>{t.stdout.write(e)},c=e=>{t.stderr.write(e)},d=u(t),f=async e=>{let t=await import(`node:fs/promises`);try{return await t.readFile(e,`utf8`)}catch(e){if(i(e)&&e.code===`ENOENT`)return null;throw e}},p=a(t.env,t.platform),m=o(t.env,t.platform,p),h=t.stdin.isTTY===!0;return{argv:t.argv,env:t.env,cwd:t.cwd(),stdout:n,stderr:c,stdin:d,readStdin:()=>l(t,h),isTTY:t.stdout.isTTY===!0,stdinIsTTY:h,exit:e=>t.exit(e),readFile:f,homedir:p,configDir:m}}async function l(e,t){if(t)return null;let n=[],r=new TextDecoder;for await(let t of e.stdin)n.push(r.decode(t,{stream:!0}));return n.push(r.decode()),n.join(``)}function u(e){let t=e.stdin[Symbol.asyncIterator](),n=new TextDecoder,r=``,i=!1;return async()=>{for(;;){let e=r.indexOf(`
|
|
2
|
+
`);if(e!==-1){let t=r.slice(0,e).replace(/\r$/,``);return r=r.slice(e+1),t}if(i){if(r.length===0)return null;let e=r;return r=``,e}let a=await t.next();if(a.done){r+=n.decode(),i=!0;continue}r+=n.decode(a.value,{stream:!0})}}}export{c as createNodeAdapter};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/runtime/paths.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared env-based path resolution for runtime adapters.
|
|
4
|
+
*
|
|
5
|
+
* Node, Bun, and Deno all need the same user home/config directory behavior.
|
|
6
|
+
* These helpers keep the fallback chain identical across runtimes while
|
|
7
|
+
* letting each adapter supply its own platform detection.
|
|
8
|
+
*
|
|
9
|
+
* @module @kjanat/dreamcli/runtime/paths
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the user's home directory from environment variables.
|
|
13
|
+
*
|
|
14
|
+
* @param env - Environment variable map.
|
|
15
|
+
* @param isWindows - Whether the platform is Windows.
|
|
16
|
+
* @returns Absolute path to the home directory.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
declare function resolveHomeDirectory(env: Readonly<Record<string, string | undefined>>, isWindows: boolean): string;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the user's config directory (`XDG_CONFIG_HOME` / `APPDATA`).
|
|
22
|
+
*
|
|
23
|
+
* @param env - Environment variable map.
|
|
24
|
+
* @param isWindows - Whether the platform is Windows.
|
|
25
|
+
* @param homedir - Pre-resolved home directory (from {@link resolveHomeDirectory}).
|
|
26
|
+
* @returns Absolute path to the config directory.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
declare function resolveConfigDirectory(env: Readonly<Record<string, string | undefined>>, isWindows: boolean, homedir: string): string;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { resolveConfigDirectory, resolveHomeDirectory };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){return t?e.USERPROFILE?e.USERPROFILE:e.HOMEDRIVE&&e.HOMEPATH?e.HOMEDRIVE+e.HOMEPATH:e.HOME||`C:\\`:e.HOME||`/`}function t(e,t,n){if(t)return e.APPDATA!==void 0&&e.APPDATA!==``?e.APPDATA:`${n.replace(/[\\/]+$/,``)||n}\\AppData\\Roaming`;let r=n.replace(/\/+$/,``);return e.XDG_CONFIG_HOME!==void 0&&e.XDG_CONFIG_HOME!==``?e.XDG_CONFIG_HOME:r.length===0?`/.config`:`${r}/.config`}export{t as resolveConfigDirectory,e as resolveHomeDirectory};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/runtime/support.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime compatibility matrix and version guard helpers.
|
|
4
|
+
*
|
|
5
|
+
* Keeps the supported runtime story in one place so adapter guards,
|
|
6
|
+
* package engines, and docs can stay aligned.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
* @module @kjanat/dreamcli/runtime/support
|
|
10
|
+
*/
|
|
11
|
+
type SupportedRuntime = 'node' | 'bun' | 'deno';
|
|
12
|
+
/**
|
|
13
|
+
* Support entry for a single runtime: version bounds, display names, and adapter mapping.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
interface RuntimeSupportEntry {
|
|
18
|
+
/** Runtime identifier key. */
|
|
19
|
+
readonly runtime: SupportedRuntime;
|
|
20
|
+
/** Human-readable name (e.g. `'Node.js'`, `'Bun'`). */
|
|
21
|
+
readonly displayName: string;
|
|
22
|
+
/** Minimum supported version (semver, e.g. `'22.22.2'`). */
|
|
23
|
+
readonly minimum: string;
|
|
24
|
+
/** `engines` range string for package.json (e.g. `'>=22.22.2'`). */
|
|
25
|
+
readonly engineRange: string;
|
|
26
|
+
/** npm/JSR package name that ships this adapter. */
|
|
27
|
+
readonly packageName: string;
|
|
28
|
+
/** Adapter factory function name (e.g. `'NodeAdapter'`). */
|
|
29
|
+
readonly adapterName: string;
|
|
30
|
+
}
|
|
31
|
+
/** All supported runtimes with their version bounds and adapter metadata. @internal */
|
|
32
|
+
declare const SUPPORTED_RUNTIMES: readonly RuntimeSupportEntry[];
|
|
33
|
+
/** Look up the support entry for a given runtime. Throws on unknown runtime. @internal */
|
|
34
|
+
declare function getRuntimeSupport(runtime: SupportedRuntime): RuntimeSupportEntry;
|
|
35
|
+
/** Format a human-readable version requirement string (e.g. `'Node.js >= 22.22.2'`). @internal */
|
|
36
|
+
declare function formatRuntimeRequirement(runtime: SupportedRuntime): string;
|
|
37
|
+
/** Check whether a version string meets the minimum for the given runtime. @internal */
|
|
38
|
+
declare function isRuntimeVersionSupported(runtime: SupportedRuntime, version: string): boolean;
|
|
39
|
+
/** Throw if the detected version is below the minimum. No-op when version is undefined. @internal */
|
|
40
|
+
declare function assertRuntimeVersionSupported(runtime: SupportedRuntime, version: string | undefined): void;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { type RuntimeSupportEntry, SUPPORTED_RUNTIMES, type SupportedRuntime, assertRuntimeVersionSupported, formatRuntimeRequirement, getRuntimeSupport, isRuntimeVersionSupported };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=[{runtime:`node`,displayName:`Node.js`,minimum:`22.22.2`,engineRange:`>=22.22.2`,packageName:`@kjanat/dreamcli`,adapterName:`NodeAdapter`},{runtime:`bun`,displayName:`Bun`,minimum:`1.3.11`,engineRange:`>=1.3.11`,packageName:`@kjanat/dreamcli`,adapterName:`BunAdapter`},{runtime:`deno`,displayName:`Deno`,minimum:`2.6.0`,engineRange:`>=2.6.0`,packageName:`@kjanat/dreamcli`,adapterName:`DenoAdapter`}],t=/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/;function n(t){for(let n of e)if(n.runtime===t)return n;throw Error(`Unknown supported runtime '${t}'`)}function r(e){let n=t.exec(e);if(n===null)return;let r=Number.parseInt(n[1]??``,10),i=n[2],a=i===void 0?0:Number.parseInt(i,10),o=n[3],s=o===void 0?0:Number.parseInt(o,10);if(!(Number.isNaN(r)||Number.isNaN(a)||Number.isNaN(s)))return{major:r,minor:a,patch:s}}function i(e,t){return e.major===t.major?e.minor===t.minor?e.patch-t.patch:e.minor-t.minor:e.major-t.major}function a(e){let t=n(e);return`${t.displayName} >= ${t.minimum}`}function o(e,t){let a=r(t),o=r(n(e).minimum);return a===void 0||o===void 0?!1:i(a,o)>=0}function s(e,t){if(t!==void 0&&!o(e,t))throw Error(`@kjanat/dreamcli requires ${a(e)}. Detected ${n(e).displayName} ${t}.`)}export{s as assertRuntimeVersionSupported};
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,253 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Uses `globalThis` feature detection (version globals) to identify
|
|
8
|
-
* the runtime without importing platform-specific modules. This is
|
|
9
|
-
* the recommended approach because each runtime defines a unique
|
|
10
|
-
* global marker:
|
|
11
|
-
*
|
|
12
|
-
* - **Bun:** `globalThis.Bun.version` (string)
|
|
13
|
-
* - **Deno:** `globalThis.Deno.version` (object with `deno` key)
|
|
14
|
-
* - **Node:** `globalThis.process.versions.node` (string)
|
|
15
|
-
*
|
|
16
|
-
* Detection order matters: Bun provides a Node-compatible `process`
|
|
17
|
-
* global, so it must be checked *before* Node to avoid misidentification.
|
|
18
|
-
*
|
|
19
|
-
* @module dreamcli/runtime/detect
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Known JavaScript runtime environments.
|
|
23
|
-
*
|
|
24
|
-
* - `'node'` — Node.js
|
|
25
|
-
* - `'bun'` — Bun
|
|
26
|
-
* - `'deno'` — Deno
|
|
27
|
-
* - `'unknown'` — Unrecognized environment
|
|
28
|
-
*/
|
|
29
|
-
type Runtime = 'node' | 'bun' | 'deno' | 'unknown';
|
|
30
|
-
/**
|
|
31
|
-
* All known runtime values as a readonly tuple.
|
|
32
|
-
*
|
|
33
|
-
* Useful for validation, iteration, and exhaustiveness checks.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* if (RUNTIMES.includes(value)) {
|
|
38
|
-
* // value is a valid Runtime
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare const RUNTIMES: readonly ['node', 'bun', 'deno', 'unknown'];
|
|
43
|
-
/**
|
|
44
|
-
* Minimal `globalThis` shape used for runtime detection.
|
|
45
|
-
*
|
|
46
|
-
* Each field is optional — only the present one identifies the runtime.
|
|
47
|
-
* Typed as `unknown` where we only need truthiness; version fields are
|
|
48
|
-
* typed just enough to distinguish runtimes safely.
|
|
49
|
-
*/
|
|
50
|
-
interface GlobalForDetect {
|
|
51
|
-
readonly Bun?: {
|
|
52
|
-
readonly version?: string;
|
|
53
|
-
};
|
|
54
|
-
readonly Deno?: {
|
|
55
|
-
readonly version?: {
|
|
56
|
-
readonly deno?: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
readonly process?: {
|
|
60
|
-
readonly versions?: {
|
|
61
|
-
readonly node?: string;
|
|
62
|
-
readonly bun?: string;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Detect the current JavaScript runtime.
|
|
68
|
-
*
|
|
69
|
-
* Uses `globalThis` feature detection to identify the host runtime.
|
|
70
|
-
* Detection order is significant: Bun is checked before Node because
|
|
71
|
-
* Bun exposes a Node-compatible `process` global.
|
|
72
|
-
*
|
|
73
|
-
* @param globals - Override `globalThis` for testing. Production callers
|
|
74
|
-
* should omit this parameter.
|
|
75
|
-
* @returns The detected {@link Runtime} identifier.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* const rt = detectRuntime();
|
|
80
|
-
* // rt === 'node' | 'bun' | 'deno' | 'unknown'
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
declare function detectRuntime(globals?: GlobalForDetect): Runtime;
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/runtime/auto.d.ts
|
|
86
|
-
/**
|
|
87
|
-
* Create a runtime adapter for the current environment.
|
|
88
|
-
*
|
|
89
|
-
* Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
|
|
90
|
-
* Unknown runtimes fall back to the Node adapter because most JS runtimes
|
|
91
|
-
* expose a Node-compatible `process` global.
|
|
92
|
-
*
|
|
93
|
-
* @param globals - Override `globalThis` for testing. Production callers
|
|
94
|
-
* should omit this parameter.
|
|
95
|
-
* @returns A `RuntimeAdapter` for the detected runtime.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* import { cli } from 'dreamcli';
|
|
100
|
-
*
|
|
101
|
-
* // Auto-detects Node/Bun/Deno and creates the right adapter
|
|
102
|
-
* cli('mycli').run(); // uses createAdapter() internally
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
declare function createAdapter(globals?: GlobalForDetect): RuntimeAdapter;
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/runtime/node.d.ts
|
|
108
|
-
/**
|
|
109
|
-
* Minimal subset of the Node.js `process` object needed by the adapter.
|
|
110
|
-
*
|
|
111
|
-
* We avoid importing `@types/node` to keep the core runtime-agnostic
|
|
112
|
-
* at the type level. This interface declares only what `createNodeAdapter`
|
|
113
|
-
* actually reads from the global.
|
|
114
|
-
*/
|
|
115
|
-
interface NodeProcess {
|
|
116
|
-
readonly argv: readonly string[];
|
|
117
|
-
readonly env: Readonly<Record<string, string | undefined>>;
|
|
118
|
-
readonly versions?: {
|
|
119
|
-
readonly node?: string;
|
|
120
|
-
readonly bun?: string;
|
|
121
|
-
};
|
|
122
|
-
cwd(): string;
|
|
123
|
-
/** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */
|
|
124
|
-
readonly platform: string;
|
|
125
|
-
readonly stdin: {
|
|
126
|
-
readonly isTTY?: boolean; /** Async iterable for reading all of stdin (used by readStdin). */
|
|
127
|
-
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
128
|
-
};
|
|
129
|
-
readonly stdout: {
|
|
130
|
-
readonly isTTY?: boolean;
|
|
131
|
-
write(data: string): unknown;
|
|
132
|
-
};
|
|
133
|
-
readonly stderr: {
|
|
134
|
-
write(data: string): unknown;
|
|
135
|
-
};
|
|
136
|
-
exit(code: number): never;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Create a runtime adapter backed by Node.js `process` globals.
|
|
140
|
-
*
|
|
141
|
-
* Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
|
|
142
|
-
* `process.stdout.write`/`process.stderr.write` as `WriteFn` functions.
|
|
143
|
-
*
|
|
144
|
-
* Also works on Bun, which provides a Node-compatible `process` global.
|
|
145
|
-
*
|
|
146
|
-
* @param proc - Override the process object (useful for testing the adapter itself).
|
|
147
|
-
* @returns A `RuntimeAdapter` backed by Node.js process state.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* import { cli } from 'dreamcli';
|
|
152
|
-
* import { createNodeAdapter } from 'dreamcli/runtime/node';
|
|
153
|
-
*
|
|
154
|
-
* cli('mycli')
|
|
155
|
-
* .command(deploy)
|
|
156
|
-
* .run({ adapter: createNodeAdapter() });
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
declare function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter;
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/runtime/bun.d.ts
|
|
162
|
-
/**
|
|
163
|
-
* Create a runtime adapter backed by Bun's Node-compatible `process` global.
|
|
164
|
-
*
|
|
165
|
-
* Bun exposes `globalThis.process` with the same shape as Node.js, so this
|
|
166
|
-
* delegates entirely to {@link createNodeAdapter}. If Bun-specific optimizations
|
|
167
|
-
* are needed in the future (e.g. `Bun.write` for I/O), they can be layered
|
|
168
|
-
* here without changing the public API.
|
|
169
|
-
*
|
|
170
|
-
* @param proc - Override the process object (useful for testing the adapter itself).
|
|
171
|
-
* @returns A `RuntimeAdapter` backed by Bun's process state.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```ts
|
|
175
|
-
* import { cli } from 'dreamcli';
|
|
176
|
-
* import { createBunAdapter } from 'dreamcli/runtime/bun';
|
|
177
|
-
*
|
|
178
|
-
* cli('mycli')
|
|
179
|
-
* .command(deploy)
|
|
180
|
-
* .run({ adapter: createBunAdapter() });
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
declare function createBunAdapter(proc?: NodeProcess): RuntimeAdapter;
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/runtime/deno.d.ts
|
|
186
|
-
/**
|
|
187
|
-
* Minimal subset of the Deno namespace needed by the adapter.
|
|
188
|
-
*
|
|
189
|
-
* We avoid `@types/deno` to keep the core runtime-agnostic at the type level.
|
|
190
|
-
* This interface declares only what `createDenoAdapter` actually reads.
|
|
191
|
-
*
|
|
192
|
-
* The `env` property is optional because it requires `--allow-env` permission.
|
|
193
|
-
* When permission is denied, the adapter catches the error and falls back to
|
|
194
|
-
* an empty env object.
|
|
195
|
-
*/
|
|
196
|
-
interface DenoNamespace {
|
|
197
|
-
readonly build: {
|
|
198
|
-
readonly os: 'darwin' | 'linux' | 'android' | 'windows' | 'freebsd' | 'netbsd' | 'aix' | 'solaris' | 'illumos';
|
|
199
|
-
};
|
|
200
|
-
readonly version?: {
|
|
201
|
-
readonly deno?: string;
|
|
202
|
-
};
|
|
203
|
-
/** Raw command-line args (excludes the binary/script — Deno pre-strips them). */
|
|
204
|
-
readonly args: readonly string[];
|
|
205
|
-
/** Environment variable access (requires `--allow-env`). */
|
|
206
|
-
readonly env: {
|
|
207
|
-
/** Get a single env var. Returns `undefined` if unset or permission denied. */get(key: string): string | undefined; /** Get all env vars as a plain object. Throws on permission denied. */
|
|
208
|
-
toObject(): Record<string, string>;
|
|
209
|
-
};
|
|
210
|
-
/** Current working directory (may throw if `--allow-read` is denied for cwd). */
|
|
211
|
-
cwd(): string;
|
|
212
|
-
readonly stdout: {
|
|
213
|
-
/** Write raw bytes to stdout synchronously. */writeSync(p: Uint8Array): number; /** Whether stdout is connected to a TTY. */
|
|
214
|
-
isTerminal(): boolean;
|
|
215
|
-
};
|
|
216
|
-
readonly stderr: {
|
|
217
|
-
/** Write raw bytes to stderr synchronously. */writeSync(p: Uint8Array): number;
|
|
218
|
-
};
|
|
219
|
-
readonly stdin: {
|
|
220
|
-
/** Whether stdin is connected to a TTY. */isTerminal(): boolean; /** Readable stream for stdin bytes. */
|
|
221
|
-
readonly readable: ReadableStream<Uint8Array>;
|
|
222
|
-
};
|
|
223
|
-
/** Exit the process with the given code. */
|
|
224
|
-
exit(code: number): never;
|
|
225
|
-
/** Read a file as UTF-8 text (requires `--allow-read`). */
|
|
226
|
-
readTextFile(path: string): Promise<string>;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Create a runtime adapter backed by the Deno namespace.
|
|
230
|
-
*
|
|
231
|
-
* Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based
|
|
232
|
-
* I/O into the `WriteFn`/`ReadFn` functions expected by the framework.
|
|
233
|
-
*
|
|
234
|
-
* Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`.
|
|
235
|
-
* The adapter prepends synthetic entries (`['deno', 'run']`) so the argv
|
|
236
|
-
* shape matches the `RuntimeAdapter` contract (binary + script + user args).
|
|
237
|
-
*
|
|
238
|
-
* @param ns - Override the Deno namespace (useful for testing the adapter itself).
|
|
239
|
-
* @returns A `RuntimeAdapter` backed by Deno's namespace APIs.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* import { cli } from 'dreamcli';
|
|
244
|
-
* import { createDenoAdapter } from 'dreamcli/runtime';
|
|
245
|
-
*
|
|
246
|
-
* cli('mycli')
|
|
247
|
-
* .command(deploy)
|
|
248
|
-
* .run({ adapter: createDenoAdapter() });
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
declare function createDenoAdapter(ns?: DenoNamespace): RuntimeAdapter;
|
|
252
|
-
//#endregion
|
|
1
|
+
import { ExitError, RuntimeAdapter } from "./runtime/adapter.mjs";
|
|
2
|
+
import { RUNTIMES, Runtime, detectRuntime } from "./runtime/detect.mjs";
|
|
3
|
+
import { createAdapter } from "./runtime/auto.mjs";
|
|
4
|
+
import { createNodeAdapter } from "./runtime/node.mjs";
|
|
5
|
+
import { createBunAdapter } from "./runtime/bun.mjs";
|
|
6
|
+
import { createDenoAdapter } from "./runtime/deno.mjs";
|
|
253
7
|
export { ExitError, RUNTIMES, type Runtime, type RuntimeAdapter, createAdapter, createBunAdapter, createDenoAdapter, createNodeAdapter, detectRuntime };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createNodeAdapter as e}from"./runtime/node.mjs";import{createBunAdapter as t}from"./runtime/bun.mjs";import{createDenoAdapter as n}from"./runtime/deno.mjs";import{RUNTIMES as r,detectRuntime as i}from"./runtime/detect.mjs";import{createAdapter as a}from"./runtime/auto.mjs";import{ExitError as o}from"./runtime/adapter.mjs";export{o as ExitError,r as RUNTIMES,a as createAdapter,t as createBunAdapter,n as createDenoAdapter,e as createNodeAdapter,i as detectRuntime};
|
package/dist/testkit.d.mts
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* This is the core execution pipeline:
|
|
8
|
-
* 1. Detect `--help` / `-h` → print help text, exit 0
|
|
9
|
-
* 2. Parse argv against the command schema
|
|
10
|
-
* 3. Resolve values (CLI → env → config → default)
|
|
11
|
-
* 4. Create a capture output channel
|
|
12
|
-
* 5. Run derive/middleware/action execution steps
|
|
13
|
-
* 6. Return structured result
|
|
14
|
-
*
|
|
15
|
-
* All errors are caught and converted to structured `RunResult`s with
|
|
16
|
-
* appropriate exit codes. The function never throws.
|
|
17
|
-
*
|
|
18
|
-
* @param cmd - The command builder (must have an action handler)
|
|
19
|
-
* @param argv - Raw argv strings (NOT including the command name itself)
|
|
20
|
-
* @param options - Injectable runtime state
|
|
21
|
-
* @returns Structured run result with exit code and captured output
|
|
22
|
-
*/
|
|
23
|
-
declare function runCommand<F extends Record<string, FlagBuilder<FlagConfig>>, A extends Record<string, ArgBuilder<ArgConfig>>, C extends Record<string, unknown> = Record<string, never>>(cmd: CommandBuilder<F, A, C>, argv: readonly string[], options?: RunOptions): Promise<RunResult>;
|
|
24
|
-
//#endregion
|
|
1
|
+
import { CapturedOutput, createCaptureOutput } from "./core/output/index.mjs";
|
|
2
|
+
import { PROMPT_CANCEL, TestAnswer, TestPrompterOptions, createTestPrompter } from "./core/prompt/index.mjs";
|
|
3
|
+
import { RunOptions, RunResult } from "./core/schema/run.mjs";
|
|
4
|
+
import { TestAdapterOptions, createTestAdapter } from "./runtime/adapter.mjs";
|
|
5
|
+
import { runCommand } from "./core/testkit/index.mjs";
|
|
25
6
|
export { type CapturedOutput, PROMPT_CANCEL, type RunOptions, type RunResult, type TestAdapterOptions, type TestAnswer, type TestPrompterOptions, createCaptureOutput, createTestAdapter, createTestPrompter, runCommand };
|
package/dist/testkit.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{PROMPT_CANCEL as e,createTestPrompter as t}from"./core/prompt/index.mjs";import{createCaptureOutput as n}from"./core/output/index.mjs";import{runCommand as r}from"./core/testkit/index.mjs";import{createTestAdapter as i}from"./runtime/adapter.mjs";export{e as PROMPT_CANCEL,n as createCaptureOutput,i as createTestAdapter,t as createTestPrompter,r as runCommand};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/version.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Build-time version constants.
|
|
4
|
+
*
|
|
5
|
+
* Replaced by tsdown `define` during bundling. In development (unbundled),
|
|
6
|
+
* the declared globals resolve to the `'dev'` fallback.
|
|
7
|
+
*
|
|
8
|
+
* @module dreamcli/version
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
/** Package version (e.g. `"0.9.1"`). `"dev"` when running unbundled. */
|
|
12
|
+
declare const DREAMCLI_VERSION: string;
|
|
13
|
+
/** Git short SHA (e.g. `"f9b5f1a"`). `"dev"` when running unbundled. */
|
|
14
|
+
declare const DREAMCLI_REVISION: string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { DREAMCLI_REVISION, DREAMCLI_VERSION };
|
package/dist/version.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=`2.0.0`,t=`b890662`;export{t as DREAMCLI_REVISION,e as DREAMCLI_VERSION};
|