@kjanat/dreamcli 0.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 +706 -0
- package/LICENSE +22 -0
- package/README.md +502 -0
- 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 -0
- package/dist/index.mjs +1 -0
- package/dist/runtime/adapter.d.mts +212 -0
- package/dist/runtime/adapter.mjs +1 -0
- 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 +7 -0
- package/dist/runtime.mjs +1 -0
- package/dist/testkit.d.mts +6 -0
- package/dist/testkit.mjs +1 -0
- package/dist/version.d.mts +16 -0
- package/dist/version.mjs +1 -0
- package/dreamcli.schema.json +338 -0
- package/examples/basic.ts +33 -0
- package/examples/gh/package.json +44 -0
- package/examples/gh/src/commands/auth.ts +66 -0
- package/examples/gh/src/commands/issue.ts +120 -0
- package/examples/gh/src/commands/pr.ts +125 -0
- package/examples/gh/src/data/issues.yaml +5 -0
- package/examples/gh/src/data/issues.yaml.d.ts +17 -0
- package/examples/gh/src/data/pull-requests.yaml +7 -0
- package/examples/gh/src/data/pull-requests.yaml.d.ts +18 -0
- package/examples/gh/src/docs.ts +11 -0
- package/examples/gh/src/lib/auth.ts +37 -0
- package/examples/gh/src/lib/utils.ts +17 -0
- package/examples/gh/src/main.test.ts +307 -0
- package/examples/gh/src/main.ts +40 -0
- package/examples/interactive.ts +66 -0
- package/examples/json-mode.ts +91 -0
- package/examples/middleware.ts +71 -0
- package/examples/multi-command.ts +66 -0
- package/examples/spinner-progress.ts +49 -0
- package/examples/testing.ts +147 -0
- package/package.json +149 -2
- package/src/core/cli/dispatch.ts +286 -0
- package/src/core/cli/index.ts +978 -0
- package/src/core/cli/planner.ts +413 -0
- package/src/core/cli/plugin.ts +117 -0
- package/src/core/cli/propagate.ts +97 -0
- package/src/core/cli/root-help.ts +269 -0
- package/src/core/cli/root-surface.ts +74 -0
- package/src/core/cli/runtime-preflight.ts +409 -0
- package/src/core/completion/index.ts +88 -0
- package/src/core/completion/shells/bash.ts +459 -0
- package/src/core/completion/shells/fish.ts +259 -0
- package/src/core/completion/shells/powershell.ts +405 -0
- package/src/core/completion/shells/shared.ts +283 -0
- package/src/core/completion/shells/zsh.ts +381 -0
- package/src/core/config/index.ts +407 -0
- package/src/core/config/package-json.ts +220 -0
- package/src/core/errors/index.ts +193 -0
- package/src/core/execution/index.ts +270 -0
- package/src/core/help/index.ts +557 -0
- package/src/core/json-schema/index.ts +891 -0
- package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
- package/src/core/output/activity.ts +568 -0
- package/src/core/output/contracts.ts +194 -0
- package/src/core/output/display-value.ts +48 -0
- package/src/core/output/index.ts +669 -0
- package/src/core/output/renderers.ts +125 -0
- package/src/core/output/writer.ts +46 -0
- package/src/core/parse/index.ts +661 -0
- package/src/core/prompt/index.ts +583 -0
- 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 +108 -0
- package/src/core/resolve/property.ts +99 -0
- package/src/core/schema/activity.ts +240 -0
- package/src/core/schema/arg.ts +719 -0
- package/src/core/schema/command.ts +1490 -0
- package/src/core/schema/flag.ts +756 -0
- package/src/core/schema/index.ts +91 -0
- package/src/core/schema/middleware.ts +171 -0
- package/src/core/schema/prompt.ts +156 -0
- package/src/core/schema/run.ts +195 -0
- 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 +123 -0
- package/src/index.ts +170 -0
- package/src/runtime/adapter.ts +303 -0
- package/src/runtime/auto.ts +110 -0
- package/src/runtime/bun.ts +55 -0
- package/src/runtime/deno.ts +369 -0
- package/src/runtime/detect.ts +105 -0
- package/src/runtime/index.ts +21 -0
- package/src/runtime/node-builtins.d.ts +23 -0
- package/src/runtime/node.ts +300 -0
- package/src/runtime/paths.ts +62 -0
- package/src/runtime/support.ts +135 -0
- package/src/runtime.ts +31 -0
- package/src/testkit.ts +25 -0
- package/src/version.ts +20 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { WriteFn } from "../core/output/writer.mjs";
|
|
2
|
+
import { ReadFn } from "../core/prompt/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/adapter.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime adapter interface.
|
|
7
|
+
*
|
|
8
|
+
* Defines the minimal contract between the platform-agnostic core and
|
|
9
|
+
* the host runtime (Node.js, Bun, Deno). Every platform-dependent
|
|
10
|
+
* operation flows through this interface — the core never calls
|
|
11
|
+
* `process.*`, `Deno.*`, or `Bun.*` directly.
|
|
12
|
+
*
|
|
13
|
+
* Adapters are designed to be:
|
|
14
|
+
* - **Immutable in shape:** all properties are readonly
|
|
15
|
+
* - **Minimal:** only the operations the framework actually needs
|
|
16
|
+
* - **Testable:** easily stubbed in tests via {@linkcode createTestAdapter | createTestAdapter()}
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Production: auto-detected
|
|
21
|
+
* cli('mycli').run(); // uses Node/Bun/Deno adapter
|
|
22
|
+
*
|
|
23
|
+
* // Test: explicit adapter
|
|
24
|
+
* cli('mycli').run({ adapter: createTestAdapter({ argv: ['deploy'] }) });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface RuntimeAdapter {
|
|
28
|
+
/** Raw argv array (including binary + script path, e.g. `['node', 'cli.js', 'deploy']`). */
|
|
29
|
+
readonly argv: readonly string[];
|
|
30
|
+
/**
|
|
31
|
+
* Environment variables.
|
|
32
|
+
* Values are `string | undefined` — mirrors Node's `process.env` semantics.
|
|
33
|
+
*/
|
|
34
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
35
|
+
/** Current working directory (absolute path). */
|
|
36
|
+
readonly cwd: string;
|
|
37
|
+
/** Writer for stdout. Framework routes `out.log`/`out.info` through this. */
|
|
38
|
+
readonly stdout: WriteFn;
|
|
39
|
+
/** Writer for stderr. Framework routes `out.warn`/`out.error` through this. */
|
|
40
|
+
readonly stderr: WriteFn;
|
|
41
|
+
/**
|
|
42
|
+
* Line reader for stdin. Used by the prompt engine for interactive input.
|
|
43
|
+
*
|
|
44
|
+
* Returns `null` on EOF (Ctrl+D on Unix, Ctrl+Z on Windows),
|
|
45
|
+
* indicating the user closed the input stream (treated as cancel).
|
|
46
|
+
*/
|
|
47
|
+
readonly stdin: ReadFn;
|
|
48
|
+
/**
|
|
49
|
+
* Read all of stdin as a single string (for piped data).
|
|
50
|
+
*
|
|
51
|
+
* Returns the full stdin contents when data is piped (`stdinIsTTY` is
|
|
52
|
+
* false), or `null` when stdin is a TTY (no piped data available).
|
|
53
|
+
*
|
|
54
|
+
* Used by the resolve chain for args with `.stdin()` configured.
|
|
55
|
+
* Unlike {@link stdin} (which reads one line for prompts), this
|
|
56
|
+
* consumes the entire stream to EOF.
|
|
57
|
+
*
|
|
58
|
+
* @returns Full stdin contents as a string, or `null` if stdin is a TTY.
|
|
59
|
+
*/
|
|
60
|
+
readonly readStdin: () => Promise<string | null>;
|
|
61
|
+
/** Whether stdout is connected to a TTY. */
|
|
62
|
+
readonly isTTY: boolean;
|
|
63
|
+
/** Whether stdin is connected to a TTY (used for prompt gating). */
|
|
64
|
+
readonly stdinIsTTY: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Exit the process with the given code.
|
|
67
|
+
* Must not return (divergent function).
|
|
68
|
+
*/
|
|
69
|
+
readonly exit: (code: number) => never;
|
|
70
|
+
/**
|
|
71
|
+
* Read a file as UTF-8 text.
|
|
72
|
+
*
|
|
73
|
+
* Returns file contents on success, `null` if the file does not exist
|
|
74
|
+
* (ENOENT/NotFound). Throws on other I/O errors (permission denied,
|
|
75
|
+
* is-directory, etc.) — those indicate unexpected failures, not
|
|
76
|
+
* "try the next path".
|
|
77
|
+
*
|
|
78
|
+
* Used by config file discovery to probe multiple candidate paths.
|
|
79
|
+
*/
|
|
80
|
+
readonly readFile: (path: string) => Promise<string | null>;
|
|
81
|
+
/**
|
|
82
|
+
* User home directory (absolute path).
|
|
83
|
+
*
|
|
84
|
+
* - Node/Bun: derived from `HOME` / `USERPROFILE` env
|
|
85
|
+
* - Deno: `Deno.env.get('HOME')` / `Deno.env.get('USERPROFILE')`
|
|
86
|
+
*/
|
|
87
|
+
readonly homedir: string;
|
|
88
|
+
/**
|
|
89
|
+
* Platform-specific user configuration directory (absolute path).
|
|
90
|
+
*
|
|
91
|
+
* - Unix: `$XDG_CONFIG_HOME` or `~/.config`
|
|
92
|
+
* - Windows: `%APPDATA%` or `~\AppData\Roaming`
|
|
93
|
+
*
|
|
94
|
+
* Config discovery appends the app-specific subdirectory.
|
|
95
|
+
*/
|
|
96
|
+
readonly configDir: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Options for creating a test adapter.
|
|
100
|
+
*
|
|
101
|
+
* All fields are optional — sensible defaults are applied for testing
|
|
102
|
+
* scenarios (empty argv, empty env, noop stdout/stderr, non-TTY, exit
|
|
103
|
+
* throws instead of killing the process).
|
|
104
|
+
*/
|
|
105
|
+
interface TestAdapterOptions {
|
|
106
|
+
/** Raw argv (defaults to `['node', 'test']`). */
|
|
107
|
+
readonly argv?: readonly string[];
|
|
108
|
+
/** Environment variables (defaults to `{}`). */
|
|
109
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
110
|
+
/** Working directory (defaults to `'/test'`). */
|
|
111
|
+
readonly cwd?: string;
|
|
112
|
+
/** Stdout writer (defaults to noop). */
|
|
113
|
+
readonly stdout?: WriteFn;
|
|
114
|
+
/** Stderr writer (defaults to noop). */
|
|
115
|
+
readonly stderr?: WriteFn;
|
|
116
|
+
/**
|
|
117
|
+
* Stdin line reader (defaults to returning `null` — immediate EOF).
|
|
118
|
+
*
|
|
119
|
+
* Use a custom {@linkcode ReadFn} to simulate user input in tests.
|
|
120
|
+
*/
|
|
121
|
+
readonly stdin?: ReadFn;
|
|
122
|
+
/**
|
|
123
|
+
* Piped stdin data for testing args with `.stdin()` configured.
|
|
124
|
+
*
|
|
125
|
+
* When provided and `stdinIsTTY` is `false`, `readStdin()` returns this
|
|
126
|
+
* string once, then `null` on subsequent reads. When absent, or when
|
|
127
|
+
* `stdinIsTTY` is `true`, `readStdin()` returns `null`.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* createTestAdapter({
|
|
132
|
+
* stdinData: '{"key": "value"}',
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
readonly stdinData?: string;
|
|
137
|
+
/** TTY flag for stdout (defaults to `false`). */
|
|
138
|
+
readonly isTTY?: boolean;
|
|
139
|
+
/** TTY flag for stdin (defaults to `false`). */
|
|
140
|
+
readonly stdinIsTTY?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Exit function (defaults to throwing {@linkcode ExitError}).
|
|
143
|
+
* The default throw-based exit allows tests to catch the exit code.
|
|
144
|
+
*/
|
|
145
|
+
readonly exit?: (code: number) => never;
|
|
146
|
+
/**
|
|
147
|
+
* File reader stub (defaults to returning `null` — all files not found).
|
|
148
|
+
*
|
|
149
|
+
* Supply a custom function to simulate a virtual filesystem in tests:
|
|
150
|
+
* ```ts
|
|
151
|
+
* createTestAdapter({
|
|
152
|
+
* readFile: (path) => Promise.resolve(
|
|
153
|
+
* path === '/home/test/.config/myapp/config.json'
|
|
154
|
+
* ? '{"region":"eu"}'
|
|
155
|
+
* : null
|
|
156
|
+
* ),
|
|
157
|
+
* })
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
readonly readFile?: (path: string) => Promise<string | null>;
|
|
161
|
+
/** Home directory (defaults to `'/home/test'`). */
|
|
162
|
+
readonly homedir?: string;
|
|
163
|
+
/** Config directory (defaults to `'/home/test/.config'`). */
|
|
164
|
+
readonly configDir?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Error thrown by adapter implementations that model process exit as an
|
|
168
|
+
* exception instead of terminating immediately.
|
|
169
|
+
*
|
|
170
|
+
* Runtime and CLI dispatch layers can catch this to perform real process
|
|
171
|
+
* termination, while tests can assert on exit codes without killing the
|
|
172
|
+
* runner:
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* try {
|
|
176
|
+
* await cli.run({ adapter: createTestAdapter() });
|
|
177
|
+
* } catch (e) {
|
|
178
|
+
* if (e instanceof ExitError) expect(e.code).toBe(0);
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare class ExitError extends Error {
|
|
183
|
+
/** Error name — always `'ExitError'` for `instanceof` checks. */
|
|
184
|
+
readonly name = "ExitError";
|
|
185
|
+
/** The exit code passed to `exit()`. */
|
|
186
|
+
readonly code: number;
|
|
187
|
+
/** Create an ExitError for the given process exit code. */
|
|
188
|
+
constructor(code: number);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create a test runtime adapter with injectable process state.
|
|
192
|
+
*
|
|
193
|
+
* Use this in `@kjanat/dreamcli/testkit` tests when you need to simulate argv,
|
|
194
|
+
* environment variables, TTY state, stdin, or config-file reads without
|
|
195
|
+
* touching the host process.
|
|
196
|
+
*
|
|
197
|
+
* @param options - Optional overrides for any adapter field.
|
|
198
|
+
* @returns A {@linkcode RuntimeAdapter} suitable for test scenarios.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* const adapter = createTestAdapter({
|
|
203
|
+
* argv: ['node', 'cli.js', 'deploy', '--force'],
|
|
204
|
+
* env: { DEPLOY_REGION: 'us' },
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* const result = await cli('mycli').run({ adapter });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function createTestAdapter(options?: TestAdapterOptions): RuntimeAdapter;
|
|
211
|
+
//#endregion
|
|
212
|
+
export { ExitError, type RuntimeAdapter, type TestAdapterOptions, createTestAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{name=`ExitError`;code;constructor(e){super(`Process exited with code ${e}`),this.code=e}};const t=()=>{},n=()=>Promise.resolve(null),r=()=>Promise.resolve(null);function i(i){let a=i?.stdinIsTTY??!1,o=a?void 0:i?.stdinData;return{argv:i?.argv??[`node`,`test`],env:i?.env??{},cwd:i?.cwd??`/test`,stdout:i?.stdout??t,stderr:i?.stderr??t,stdin:i?.stdin??n,readStdin:()=>{if(o===void 0)return Promise.resolve(null);let e=o;return o=void 0,Promise.resolve(e)},isTTY:i?.isTTY??!1,stdinIsTTY:a,exit:i?.exit??(t=>{throw new e(t)}),readFile:i?.readFile??r,homedir:i?.homedir??`/home/test`,configDir:i?.configDir??`/home/test/.config`}}export{e as ExitError,i as createTestAdapter};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
+
import { GlobalForDetect } from "./detect.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/auto.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a runtime adapter for the current environment.
|
|
7
|
+
*
|
|
8
|
+
* Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
|
|
9
|
+
* Unknown runtimes fall back to the Node adapter because most JS runtimes
|
|
10
|
+
* expose a Node-compatible `process` global.
|
|
11
|
+
*
|
|
12
|
+
* @param globals - Override `globalThis` for testing. Production callers
|
|
13
|
+
* should omit this parameter.
|
|
14
|
+
* @returns A {@linkcode RuntimeAdapter} for the detected runtime.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { cli } from '@kjanat/dreamcli';
|
|
19
|
+
*
|
|
20
|
+
* // Auto-detects Node/Bun/Deno and creates the right adapter
|
|
21
|
+
* cli('mycli').run(); // uses createAdapter() internally
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function createAdapter(globals?: GlobalForDetect): RuntimeAdapter;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{assertRuntimeVersionSupported as e}from"./support.mjs";import{createNodeAdapter as t}from"./node.mjs";import{createBunAdapter as n}from"./bun.mjs";import{createDenoAdapter as r}from"./deno.mjs";import{detectRuntime as i}from"./detect.mjs";function a(e,t){switch(e){case`bun`:return t.Bun?.version;case`deno`:return t.Deno?.version?.deno;case`node`:return t.process?.versions?.node;case`unknown`:return;default:return e}}function o(e){if(typeof e!=`object`||!e)return!1;let t=e;return Array.isArray(t.args)&&typeof t.cwd==`function`&&typeof t.exit==`function`&&typeof t.readTextFile==`function`&&typeof t.env?.get==`function`&&typeof t.env.toObject==`function`&&typeof t.stdout?.writeSync==`function`&&typeof t.stdout.isTerminal==`function`&&typeof t.stderr?.writeSync==`function`&&typeof t.stdin?.isTerminal==`function`&&typeof t.stdin?.readable?.getReader==`function`}function s(e){let t=e.Deno;return o(t)?t:void 0}function c(o){let c=o??globalThis,l=i(c);switch(l!==`unknown`&&e(l,a(l,c)),l){case`bun`:return n();case`deno`:return r(s(c));case`node`:case`unknown`:return t();default:return l}}export{c as createAdapter};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
+
import { NodeProcess } from "./node.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/bun.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a runtime adapter backed by Bun's Node-compatible `process` global.
|
|
7
|
+
*
|
|
8
|
+
* Bun exposes `globalThis.process` with the same shape as Node.js, so this
|
|
9
|
+
* delegates entirely to {@link createNodeAdapter}. If Bun-specific optimizations
|
|
10
|
+
* are needed in the future (e.g. `Bun.write` for I/O), they can be layered
|
|
11
|
+
* here without changing the public API.
|
|
12
|
+
*
|
|
13
|
+
* @param proc - Override the process object (useful for testing the adapter itself).
|
|
14
|
+
* @returns A {@linkcode RuntimeAdapter} backed by Bun's process state.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { cli } from '@kjanat/dreamcli';
|
|
19
|
+
* import { createBunAdapter } from '@kjanat/dreamcli/runtime';
|
|
20
|
+
*
|
|
21
|
+
* cli('mycli')
|
|
22
|
+
* .command(deploy)
|
|
23
|
+
* .run({ adapter: createBunAdapter() });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function createBunAdapter(proc?: NodeProcess): RuntimeAdapter;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createBunAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{assertRuntimeVersionSupported as e}from"./support.mjs";import{createNodeAdapter as t}from"./node.mjs";function n(e){return e?.versions?.bun===void 0?globalThis.Bun?.version:e.versions.bun}function r(r){return e(`bun`,n(r)),t(r)}export{r as createBunAdapter};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/deno.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Minimal subset of the Deno namespace needed by the adapter.
|
|
6
|
+
*
|
|
7
|
+
* We avoid `@types/deno` to keep the core runtime-agnostic at the type level.
|
|
8
|
+
* This interface declares only what `createDenoAdapter` actually reads.
|
|
9
|
+
*
|
|
10
|
+
* The `env` property is optional because it requires `--allow-env` permission.
|
|
11
|
+
* When permission is denied, the adapter catches the error and falls back to
|
|
12
|
+
* an empty env object.
|
|
13
|
+
*/
|
|
14
|
+
interface DenoNamespace {
|
|
15
|
+
/** Build target metadata (OS detection). */
|
|
16
|
+
readonly build: {
|
|
17
|
+
readonly os: 'darwin' | 'linux' | 'android' | 'windows' | 'freebsd' | 'netbsd' | 'aix' | 'solaris' | 'illumos';
|
|
18
|
+
};
|
|
19
|
+
/** Deno version info — used for minimum-version guard. */
|
|
20
|
+
readonly version?: {
|
|
21
|
+
readonly deno?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Raw command-line args (excludes the binary/script — Deno pre-strips them). */
|
|
24
|
+
readonly args: readonly string[];
|
|
25
|
+
/** Environment variable access (requires `--allow-env`). */
|
|
26
|
+
readonly env: {
|
|
27
|
+
/** 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. */
|
|
28
|
+
toObject(): Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
/** Current working directory (may throw if `--allow-read` is denied for cwd). */
|
|
31
|
+
cwd(): string;
|
|
32
|
+
/** Standard output — synchronous byte writer with TTY detection. */
|
|
33
|
+
readonly stdout: {
|
|
34
|
+
/** Write raw bytes to stdout synchronously. */writeSync(p: Uint8Array): number; /** Whether stdout is connected to a TTY. */
|
|
35
|
+
isTerminal(): boolean;
|
|
36
|
+
};
|
|
37
|
+
/** Standard error — synchronous byte writer. */
|
|
38
|
+
readonly stderr: {
|
|
39
|
+
/** Write raw bytes to stderr synchronously. */writeSync(p: Uint8Array): number;
|
|
40
|
+
};
|
|
41
|
+
/** Standard input — TTY detection and readable byte stream. */
|
|
42
|
+
readonly stdin: {
|
|
43
|
+
/** Whether stdin is connected to a TTY. */isTerminal(): boolean; /** Readable stream for stdin bytes. */
|
|
44
|
+
readonly readable: ReadableStream<Uint8Array>;
|
|
45
|
+
};
|
|
46
|
+
/** Exit the process with the given code. */
|
|
47
|
+
exit(code: number): never;
|
|
48
|
+
/** Read a file as UTF-8 text (requires `--allow-read`). */
|
|
49
|
+
readTextFile(path: string): Promise<string>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a runtime adapter backed by the Deno namespace.
|
|
53
|
+
*
|
|
54
|
+
* Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based
|
|
55
|
+
* I/O into the {@linkcode WriteFn}/{@linkcode ReadFn} functions expected by the framework.
|
|
56
|
+
*
|
|
57
|
+
* Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`.
|
|
58
|
+
* The adapter prepends synthetic entries (`['deno', 'run']`) so the argv
|
|
59
|
+
* shape matches the {@linkcode RuntimeAdapter} contract (binary + script + user args).
|
|
60
|
+
*
|
|
61
|
+
* @param ns - Override the Deno namespace (useful for testing the adapter itself).
|
|
62
|
+
* @returns A {@linkcode RuntimeAdapter} backed by Deno's namespace APIs.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { cli } from '@kjanat/dreamcli';
|
|
67
|
+
* import { createDenoAdapter } from '@kjanat/dreamcli/runtime';
|
|
68
|
+
*
|
|
69
|
+
* cli('mycli')
|
|
70
|
+
* .command(deploy)
|
|
71
|
+
* .run({ adapter: createDenoAdapter() });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare function createDenoAdapter(ns?: DenoNamespace): RuntimeAdapter;
|
|
75
|
+
//#endregion
|
|
76
|
+
export { type DenoNamespace, createDenoAdapter };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";import{assertRuntimeVersionSupported as n}from"./support.mjs";function r(e,t){if(typeof e!=`object`||!e||!(`name`in e))return!1;let n=e;return typeof n.name==`string`&&n.name===t}function i(e){try{return e.env.toObject()}catch(e){if(r(e,`PermissionDenied`))return{};throw e}}function a(e){try{return e.cwd()}catch(e){if(r(e,`PermissionDenied`))return`/`;throw e}}function o(e){let t=e??s();n(`deno`,t.version?.deno);let o=new TextEncoder,f=[`deno`,`run`,...t.args],p=i(t),m=a(t),h=e=>{t.stdout.writeSync(o.encode(e))},g=e=>{t.stderr.writeSync(o.encode(e))},_=l(t),v=async e=>{try{return await t.readTextFile(e)}catch(e){if(r(e,`NotFound`)||r(e,`PermissionDenied`))return null;throw e}},y=u(p,t.build.os===`windows`),b=d(p,y,t.build.os===`windows`),x=t.stdin.isTerminal();return{argv:f,env:p,cwd:m,stdout:h,stderr:g,stdin:_,readStdin:()=>c(t,x),isTTY:t.stdout.isTerminal(),stdinIsTTY:x,exit:e=>t.exit(e),readFile:v,homedir:y,configDir:b}}function s(){return globalThis.Deno}async function c(e,t){if(t)return null;let n=e.stdin.readable.getReader(),r=new TextDecoder,i=[];try{for(;;){let{value:e,done:t}=await n.read();if(t){i.push(r.decode());break}i.push(r.decode(e,{stream:!0}))}}finally{n.releaseLock()}return i.join(``)}function l(e){let t=new TextDecoder,n=``,r=!1;return async()=>{let i=e.stdin.readable.getReader();try{for(;;){let e=n.indexOf(`
|
|
2
|
+
`);if(e!==-1){let t=n.slice(0,e).replace(/\r$/,``);return n=n.slice(e+1),t}if(r){if(n.length===0)return null;let e=n;return n=``,e}let{value:a,done:o}=await i.read();if(o){n+=t.decode(),r=!0;continue}n+=t.decode(a,{stream:!0})}}finally{i.releaseLock()}}}function u(e,n){return t(e,n)}function d(t,n,r){return e(t,r,n)}export{o as createDenoAdapter};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region src/runtime/detect.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Auto-detects the current JavaScript runtime environment.
|
|
4
|
+
*
|
|
5
|
+
* Uses `globalThis` feature detection (version globals) to identify
|
|
6
|
+
* the runtime without importing platform-specific modules. This is
|
|
7
|
+
* the recommended approach because each runtime defines a unique
|
|
8
|
+
* global marker:
|
|
9
|
+
*
|
|
10
|
+
* - **Bun:** `globalThis.Bun.version` (string)
|
|
11
|
+
* - **Deno:** `globalThis.Deno.version` (object with `deno` key)
|
|
12
|
+
* - **Node:** `globalThis.process.versions.node` (string)
|
|
13
|
+
*
|
|
14
|
+
* Detection order matters: Bun provides a Node-compatible `process`
|
|
15
|
+
* global, so it must be checked *before* Node to avoid misidentification.
|
|
16
|
+
*
|
|
17
|
+
* @module @kjanat/dreamcli/runtime/detect
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Known JavaScript runtime environments.
|
|
21
|
+
*
|
|
22
|
+
* - `'node'` — Node.js
|
|
23
|
+
* - `'bun'` — Bun
|
|
24
|
+
* - `'deno'` — Deno
|
|
25
|
+
* - `'unknown'` — Unrecognized environment
|
|
26
|
+
*/
|
|
27
|
+
type Runtime = 'node' | 'bun' | 'deno' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* All known runtime values as a readonly tuple.
|
|
30
|
+
*
|
|
31
|
+
* Useful for validation, iteration, and exhaustiveness checks.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* if (RUNTIMES.includes(value)) {
|
|
36
|
+
* // value is a valid Runtime
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const RUNTIMES: readonly ['node', 'bun', 'deno', 'unknown'];
|
|
41
|
+
/**
|
|
42
|
+
* Minimal `globalThis` shape used for runtime detection.
|
|
43
|
+
*
|
|
44
|
+
* Each field is optional — only the present one identifies the runtime.
|
|
45
|
+
* Typed as `unknown` where we only need truthiness; version fields are
|
|
46
|
+
* typed just enough to distinguish runtimes safely.
|
|
47
|
+
*/
|
|
48
|
+
interface GlobalForDetect {
|
|
49
|
+
/** Present when running on Bun. */
|
|
50
|
+
readonly Bun?: {
|
|
51
|
+
readonly version?: string;
|
|
52
|
+
};
|
|
53
|
+
/** Present when running on Deno. */
|
|
54
|
+
readonly Deno?: {
|
|
55
|
+
readonly version?: {
|
|
56
|
+
readonly deno?: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** Present on Node.js (and Bun, which mimics it). */
|
|
60
|
+
readonly process?: {
|
|
61
|
+
readonly versions?: {
|
|
62
|
+
readonly node?: string;
|
|
63
|
+
readonly bun?: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Detect the current JavaScript runtime.
|
|
69
|
+
*
|
|
70
|
+
* Uses `globalThis` feature detection to identify the host runtime.
|
|
71
|
+
* Detection order is significant: Bun is checked before Node because
|
|
72
|
+
* Bun exposes a Node-compatible `process` global.
|
|
73
|
+
*
|
|
74
|
+
* @param globals - Override `globalThis` for testing. Production callers
|
|
75
|
+
* should omit this parameter.
|
|
76
|
+
* @returns The detected {@link Runtime} identifier.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const rt = detectRuntime();
|
|
81
|
+
* // rt === 'node' | 'bun' | 'deno' | 'unknown'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function detectRuntime(globals?: GlobalForDetect): Runtime;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { type GlobalForDetect, RUNTIMES, type Runtime, detectRuntime };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=[`node`,`bun`,`deno`,`unknown`];function t(e){let t=e??globalThis;return typeof t.Bun?.version==`string`?`bun`:typeof t.Deno?.version?.deno==`string`?`deno`:typeof t.process?.versions?.node==`string`?`node`:`unknown`}export{e as RUNTIMES,t as detectRuntime};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExitError, RuntimeAdapter, TestAdapterOptions, createTestAdapter } from "./adapter.mjs";
|
|
2
|
+
import { GlobalForDetect, RUNTIMES, Runtime, detectRuntime } from "./detect.mjs";
|
|
3
|
+
import { createAdapter } from "./auto.mjs";
|
|
4
|
+
import { NodeProcess, createNodeAdapter } from "./node.mjs";
|
|
5
|
+
import { createBunAdapter } from "./bun.mjs";
|
|
6
|
+
import { DenoNamespace, createDenoAdapter } from "./deno.mjs";
|
|
7
|
+
export { type DenoNamespace, ExitError, type GlobalForDetect, type NodeProcess, RUNTIMES, type Runtime, type RuntimeAdapter, type TestAdapterOptions, createAdapter, createBunAdapter, createDenoAdapter, createNodeAdapter, createTestAdapter, detectRuntime };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/node.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Minimal subset of the Node.js `process` object needed by the adapter.
|
|
6
|
+
*
|
|
7
|
+
* We avoid importing `@types/node` to keep the core runtime-agnostic
|
|
8
|
+
* at the type level. This interface declares only what `createNodeAdapter`
|
|
9
|
+
* actually reads from the global.
|
|
10
|
+
*/
|
|
11
|
+
interface NodeProcess {
|
|
12
|
+
/** Raw process arguments (`[binary, script, ...userArgs]`). */
|
|
13
|
+
readonly argv: readonly string[];
|
|
14
|
+
/** Environment variables (values are `undefined` for unset keys). */
|
|
15
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
16
|
+
/** Runtime version strings — used for version-guard checks. */
|
|
17
|
+
readonly versions?: {
|
|
18
|
+
readonly node?: string;
|
|
19
|
+
readonly bun?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Return the current working directory. */
|
|
22
|
+
cwd(): string;
|
|
23
|
+
/** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */
|
|
24
|
+
readonly platform: string;
|
|
25
|
+
/** Standard input stream with TTY detection and async iteration. */
|
|
26
|
+
readonly stdin: {
|
|
27
|
+
readonly isTTY?: boolean; /** Async iterable for reading all of stdin (used by readStdin). */
|
|
28
|
+
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
29
|
+
};
|
|
30
|
+
/** Standard output stream with TTY detection and write. */
|
|
31
|
+
readonly stdout: {
|
|
32
|
+
readonly isTTY?: boolean;
|
|
33
|
+
write(data: string): unknown;
|
|
34
|
+
};
|
|
35
|
+
/** Standard error stream with write. */
|
|
36
|
+
readonly stderr: {
|
|
37
|
+
write(data: string): unknown;
|
|
38
|
+
};
|
|
39
|
+
/** Terminate the process with the given exit code. */
|
|
40
|
+
exit(code: number): never;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a runtime adapter backed by Node.js `process` globals.
|
|
44
|
+
*
|
|
45
|
+
* Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
|
|
46
|
+
* `process.stdout.write`/`process.stderr.write` as {@linkcode WriteFn} functions.
|
|
47
|
+
*
|
|
48
|
+
* Also works on Bun, which provides a Node-compatible `process` global.
|
|
49
|
+
*
|
|
50
|
+
* @param proc - Override the process object (useful for testing the adapter itself).
|
|
51
|
+
* @returns A {@linkcode RuntimeAdapter} backed by Node.js process state.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { cli } from '@kjanat/dreamcli';
|
|
56
|
+
* import { createNodeAdapter } from '@kjanat/dreamcli/runtime/node';
|
|
57
|
+
*
|
|
58
|
+
* cli('mycli')
|
|
59
|
+
* .command(deploy)
|
|
60
|
+
* .run({ adapter: createNodeAdapter() });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { type NodeProcess, createNodeAdapter };
|
|
@@ -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};
|
|
@@ -0,0 +1,7 @@
|
|
|
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";
|
|
7
|
+
export { ExitError, RUNTIMES, type Runtime, type RuntimeAdapter, createAdapter, createBunAdapter, createDenoAdapter, createNodeAdapter, detectRuntime };
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1,6 @@
|
|
|
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";
|
|
6
|
+
export { type CapturedOutput, PROMPT_CANCEL, type RunOptions, type RunResult, type TestAdapterOptions, type TestAnswer, type TestPrompterOptions, createCaptureOutput, createTestAdapter, createTestPrompter, runCommand };
|
package/dist/testkit.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|