@kjanat/dreamcli 2.5.0 → 3.0.0-rc.10
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 +344 -1
- package/README.md +9 -2
- package/dist/core/cli/dispatch.d.mts +6 -5
- package/dist/core/cli/dispatch.mjs +205 -1
- package/dist/core/cli/help-links.d.mts +0 -1
- package/dist/core/cli/help-links.mjs +41 -1
- package/dist/core/cli/index.d.mts +185 -19
- package/dist/core/cli/index.mjs +945 -1
- package/dist/core/cli/planner.d.mts +32 -6
- package/dist/core/cli/planner.mjs +300 -1
- package/dist/core/cli/plugin.d.mts +1 -1
- package/dist/core/cli/plugin.mjs +41 -1
- package/dist/core/cli/propagate.d.mts +1 -1
- package/dist/core/cli/propagate.mjs +57 -1
- package/dist/core/cli/root-help.d.mts +18 -3
- package/dist/core/cli/root-help.mjs +226 -6
- package/dist/core/cli/root-surface.d.mts +30 -4
- package/dist/core/cli/root-surface.mjs +28 -1
- package/dist/core/cli/runtime-preflight.d.mts +30 -3
- package/dist/core/cli/runtime-preflight.mjs +169 -1
- package/dist/core/completion/index.d.mts +32 -2
- package/dist/core/completion/index.mjs +90 -1
- package/dist/core/completion/shells/bash.d.mts +0 -1
- package/dist/core/completion/shells/bash.mjs +308 -3
- package/dist/core/completion/shells/fish.d.mts +0 -1
- package/dist/core/completion/shells/fish.mjs +162 -2
- package/dist/core/completion/shells/powershell.d.mts +0 -1
- package/dist/core/completion/shells/powershell.mjs +358 -2
- package/dist/core/completion/shells/shared.d.mts +23 -2
- package/dist/core/completion/shells/shared.mjs +176 -1
- package/dist/core/completion/shells/zsh.d.mts +0 -1
- package/dist/core/completion/shells/zsh.mjs +251 -2
- package/dist/core/config/index.d.mts +2 -3
- package/dist/core/config/index.mjs +246 -1
- package/dist/core/config/package-json.d.mts +27 -4
- package/dist/core/config/package-json.mjs +386 -3
- package/dist/core/errors/index.d.mts +3 -3
- package/dist/core/errors/index.mjs +87 -1
- package/dist/core/execution/index.d.mts +0 -1
- package/dist/core/execution/index.mjs +201 -1
- package/dist/core/help/ansi.d.mts +11 -5
- package/dist/core/help/ansi.mjs +121 -2
- package/dist/core/help/index.d.mts +65 -2
- package/dist/core/help/index.mjs +341 -7
- package/dist/core/help/theme.d.mts +68 -0
- package/dist/core/help/theme.mjs +46 -0
- package/dist/core/json-schema/index.d.mts +15 -2
- package/dist/core/json-schema/index.mjs +536 -12
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +22 -5
- package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
- package/dist/core/output/activity.d.mts +0 -1
- package/dist/core/output/activity.mjs +452 -1
- package/dist/core/output/bind.mjs +56 -1
- package/dist/core/output/contracts.d.mts +4 -5
- package/dist/core/output/contracts.mjs +57 -1
- package/dist/core/output/display-value.mjs +32 -1
- package/dist/core/output/index.d.mts +21 -1
- package/dist/core/output/index.mjs +442 -2
- package/dist/core/output/renderers.d.mts +0 -1
- package/dist/core/output/renderers.mjs +46 -1
- package/dist/core/output/writer.mjs +12 -1
- package/dist/core/parse/index.d.mts +54 -7
- package/dist/core/parse/index.mjs +727 -1
- package/dist/core/prompt/index.d.mts +12 -4
- package/dist/core/prompt/index.mjs +348 -6
- package/dist/core/resolve/args.d.mts +1 -1
- package/dist/core/resolve/args.mjs +105 -1
- package/dist/core/resolve/coerce.d.mts +1 -1
- package/dist/core/resolve/coerce.mjs +336 -1
- package/dist/core/resolve/config.mjs +19 -1
- package/dist/core/resolve/contracts.d.mts +9 -4
- package/dist/core/resolve/errors.d.mts +0 -1
- package/dist/core/resolve/errors.mjs +140 -2
- package/dist/core/resolve/flags.d.mts +7 -2
- package/dist/core/resolve/flags.mjs +251 -1
- package/dist/core/resolve/index.d.mts +2 -2
- package/dist/core/resolve/index.mjs +85 -1
- package/dist/core/resolve/property.d.mts +6 -2
- package/dist/core/resolve/property.mjs +53 -1
- package/dist/core/schema/activity.d.mts +31 -11
- package/dist/core/schema/arg.d.mts +92 -13
- package/dist/core/schema/arg.mjs +463 -1
- package/dist/core/schema/command.d.mts +29 -7
- package/dist/core/schema/command.mjs +726 -1
- package/dist/core/schema/flag.d.mts +577 -21
- package/dist/core/schema/flag.mjs +705 -1
- package/dist/core/schema/index.d.mts +5 -2
- package/dist/core/schema/middleware.d.mts +4 -3
- package/dist/core/schema/middleware.mjs +41 -1
- package/dist/core/schema/number-constraints.d.mts +96 -0
- package/dist/core/schema/number-constraints.mjs +60 -0
- package/dist/core/schema/prompt.d.mts +21 -3
- package/dist/core/schema/run.d.mts +24 -5
- package/dist/core/schema/string-constraints.d.mts +97 -0
- package/dist/core/schema/string-constraints.mjs +69 -0
- package/dist/core/schema/value-parsers.d.mts +78 -0
- package/dist/core/schema/value-parsers.mjs +142 -0
- package/dist/core/schema-dsl/runtime.mjs +271 -2
- package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
- package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
- package/dist/core/testkit/index.d.mts +9 -36
- package/dist/core/testkit/index.mjs +83 -1
- package/dist/index.d.mts +12 -6
- package/dist/index.mjs +22 -1
- package/dist/runtime/adapter.d.mts +38 -2
- package/dist/runtime/adapter.mjs +87 -1
- package/dist/runtime/auto.d.mts +2 -3
- package/dist/runtime/auto.mjs +45 -1
- package/dist/runtime/deno.d.mts +24 -5
- package/dist/runtime/deno.mjs +262 -2
- package/dist/runtime/detect.mjs +45 -1
- package/dist/runtime/index.d.mts +3 -4
- package/dist/runtime/node.d.mts +8 -2
- package/dist/runtime/node.mjs +220 -2
- package/dist/runtime/paths.mjs +48 -1
- package/dist/runtime.d.mts +4 -4
- package/dist/runtime.mjs +6 -1
- package/dist/strings.mjs +22 -1
- package/dist/testkit.d.mts +1 -0
- package/dist/testkit.mjs +5 -1
- package/dist/version.d.mts +7 -3
- package/dist/version.mjs +7 -1
- package/dreamcli.schema.json +36 -7
- package/examples/basic.ts +5 -1
- package/examples/gh/package.json +2 -7
- package/examples/pwsh-demo/package.json +1 -7
- package/examples/pwsh-demo/src/main.test.ts +1 -4
- package/examples/pwsh-demo/src/main.ts +14 -4
- package/examples/transport-launcher.ts +85 -0
- package/package.json +43 -49
- package/dist/runtime/bun.d.mts +0 -28
- package/dist/runtime/bun.mjs +0 -1
- package/dist/runtime/support.d.mts +0 -42
- package/dist/runtime/support.mjs +0 -1
- package/src/core/cli/dispatch.ts +0 -349
- package/src/core/cli/help-links.ts +0 -82
- package/src/core/cli/index.ts +0 -1413
- package/src/core/cli/planner.ts +0 -487
- package/src/core/cli/plugin.ts +0 -117
- package/src/core/cli/propagate.ts +0 -97
- package/src/core/cli/root-help.ts +0 -252
- package/src/core/cli/root-surface.ts +0 -74
- package/src/core/cli/runtime-preflight.ts +0 -438
- package/src/core/completion/index.ts +0 -88
- package/src/core/completion/shells/bash.ts +0 -459
- package/src/core/completion/shells/fish.ts +0 -259
- package/src/core/completion/shells/powershell.ts +0 -439
- package/src/core/completion/shells/shared.ts +0 -283
- package/src/core/completion/shells/zsh.ts +0 -381
- package/src/core/config/index.ts +0 -417
- package/src/core/config/package-json.ts +0 -560
- package/src/core/errors/index.ts +0 -193
- package/src/core/execution/index.ts +0 -268
- package/src/core/help/ansi.ts +0 -144
- package/src/core/help/index.ts +0 -516
- package/src/core/json-schema/index.ts +0 -891
- package/src/core/json-schema/meta-descriptions.generated.ts +0 -185
- package/src/core/output/activity.ts +0 -575
- package/src/core/output/bind.ts +0 -59
- package/src/core/output/contracts.ts +0 -194
- package/src/core/output/display-value.ts +0 -48
- package/src/core/output/index.ts +0 -704
- package/src/core/output/renderers.ts +0 -125
- package/src/core/output/writer.ts +0 -46
- package/src/core/parse/index.ts +0 -681
- package/src/core/prompt/index.ts +0 -583
- package/src/core/resolve/args.ts +0 -144
- package/src/core/resolve/coerce.ts +0 -432
- package/src/core/resolve/config.ts +0 -26
- package/src/core/resolve/contracts.ts +0 -135
- package/src/core/resolve/errors.ts +0 -227
- package/src/core/resolve/flags.ts +0 -255
- package/src/core/resolve/index.ts +0 -108
- package/src/core/resolve/property.ts +0 -99
- package/src/core/schema/activity.ts +0 -240
- package/src/core/schema/arg.ts +0 -719
- package/src/core/schema/command.ts +0 -1498
- package/src/core/schema/flag.ts +0 -801
- package/src/core/schema/index.ts +0 -91
- package/src/core/schema/middleware.ts +0 -171
- package/src/core/schema/prompt.ts +0 -156
- package/src/core/schema/run.ts +0 -198
- package/src/core/schema-dsl/index.ts +0 -109
- package/src/core/schema-dsl/parse.ts +0 -262
- package/src/core/schema-dsl/runtime.ts +0 -609
- package/src/core/schema-dsl/to-json-schema.ts +0 -102
- package/src/core/testkit/index.ts +0 -123
- package/src/index.ts +0 -179
- package/src/runtime/adapter.ts +0 -303
- package/src/runtime/auto.ts +0 -110
- package/src/runtime/bun.ts +0 -55
- package/src/runtime/deno.ts +0 -369
- package/src/runtime/detect.ts +0 -105
- package/src/runtime/index.ts +0 -21
- package/src/runtime/node-builtins.d.ts +0 -27
- package/src/runtime/node.ts +0 -300
- package/src/runtime/paths.ts +0 -64
- package/src/runtime/support.ts +0 -135
- package/src/runtime.ts +0 -31
- package/src/strings.ts +0 -34
- package/src/testkit.ts +0 -25
- package/src/version.ts +0 -20
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ActivityEvent, Fallback, ProgressHandle, ProgressOptions, SpinnerHandle, SpinnerOptions, TableColumn, TableFormat, TableOptions, TableStream } from "./core/schema/activity.mjs";
|
|
2
|
+
import { NumberConstraintViolation, NumberConstraints } from "./core/schema/number-constraints.mjs";
|
|
2
3
|
import { ArgBuilder, ArgConfig, ArgFactory, ArgKind, ArgParseFn, ArgPresence, ArgSchema, InferArg, InferArgs, ResolvedArgValue, WithArgPresence, WithVariadic, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
3
4
|
import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./core/schema/prompt.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { StringConstraintViolation, StringConstraints } from "./core/schema/string-constraints.mjs";
|
|
6
|
+
import { DateFlagOptions, UrlFlagOptions } from "./core/schema/value-parsers.mjs";
|
|
7
|
+
import { DuplicatePolicy, FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagNegation, FlagParseFn, FlagPresence, FlagSchema, InferFlag, InferFlags, PathChecks, PathFlagOptions, ResolvedValue, WithPresence, createSchema, flag, getFlagNegatedName } from "./core/schema/flag.mjs";
|
|
5
8
|
import { Middleware, MiddlewareHandler, MiddlewareParams, middleware } from "./core/schema/middleware.mjs";
|
|
6
|
-
import { ParseResult, Token, parse, tokenize } from "./core/parse/index.mjs";
|
|
7
9
|
import { WriteFn } from "./core/output/writer.mjs";
|
|
8
10
|
import { Verbosity } from "./core/output/contracts.mjs";
|
|
9
11
|
import { OutputOptions, createOutput } from "./core/output/index.mjs";
|
|
@@ -12,11 +14,14 @@ import { DeprecationWarning, ResolveOptions, ResolveResult } from "./core/resolv
|
|
|
12
14
|
import { resolve } from "./core/resolve/index.mjs";
|
|
13
15
|
import { BeforeParseParams, CLIPlugin, CLIPluginHooks, PluginCommandContext, ResolvedCommandParams, plugin } from "./core/cli/plugin.mjs";
|
|
14
16
|
import { CLIError, CLIErrorJSON, CLIErrorOptions, ErrorCode, ParseError, ParseErrorCode, ParseErrorOptions, ValidationError, ValidationErrorCode, ValidationErrorOptions, isCLIError, isParseError, isValidationError } from "./core/errors/index.mjs";
|
|
17
|
+
import { HelpTheme, HelpThemeFactory } from "./core/help/theme.mjs";
|
|
15
18
|
import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
16
19
|
import { HelpOptions, formatHelp } from "./core/help/index.mjs";
|
|
17
20
|
import { RunResult } from "./core/schema/run.mjs";
|
|
18
21
|
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
|
|
22
|
+
import "./core/schema/index.mjs";
|
|
23
|
+
import { ParseOptions, ParseResult, Token, parse, tokenize } from "./core/parse/index.mjs";
|
|
24
|
+
import { ManifestDiscoveryOptions, PackageJsonAdapter, PackageJsonData, PackageRepository, PackageRepositoryUrlOptions, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
20
25
|
import { HelpLinks } from "./core/cli/help-links.mjs";
|
|
21
26
|
import { CompletionOptions } from "./core/completion/shells/shared.mjs";
|
|
22
27
|
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
@@ -25,6 +30,7 @@ import { generatePowerShellCompletion } from "./core/completion/shells/powershel
|
|
|
25
30
|
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
26
31
|
import { SHELLS, Shell, generateCompletion } from "./core/completion/index.mjs";
|
|
27
32
|
import { ConfigAdapter, ConfigDiscoveryOptions, ConfigDiscoveryResult, ConfigFound, ConfigNotFound, FormatLoader, buildConfigSearchPaths, configFormat, discoverConfig } from "./core/config/index.mjs";
|
|
28
|
-
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
29
|
-
import { JsonSchemaOptions, definitionMetaSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
30
|
-
|
|
33
|
+
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, DefaultCommandOptions, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
34
|
+
import { JsonSchemaOptions, definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
35
|
+
import { Colors } from "ansispeck";
|
|
36
|
+
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 Colors, 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 DateFlagOptions, type DefaultCommandOptions, type DeprecationWarning, type DeriveHandler, type DeriveParams, type DuplicatePolicy, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagNegation, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type HelpTheme, type HelpThemeFactory, 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 NumberConstraintViolation, type NumberConstraints, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, type PackageRepositoryUrlOptions, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseOptions, type ParseResult, type PathChecks, type PathFlagOptions, 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 StringConstraintViolation, type StringConstraints, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, type UrlFlagOptions, 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, generateCommandSchema, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, getFlagNegatedName, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CLIError, ParseError, ValidationError, isCLIError, isParseError, isValidationError } from "./core/errors/index.mjs";
|
|
2
|
+
import { FlagBuilder, createSchema, flag, getFlagNegatedName } from "./core/schema/flag.mjs";
|
|
3
|
+
import { ArgBuilder, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
4
|
+
import { CommandBuilder, command, group } from "./core/schema/command.mjs";
|
|
5
|
+
import { middleware } from "./core/schema/middleware.mjs";
|
|
6
|
+
import { parse, tokenize } from "./core/parse/index.mjs";
|
|
7
|
+
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
8
|
+
import { generateFishCompletion } from "./core/completion/shells/fish.mjs";
|
|
9
|
+
import { generatePowerShellCompletion } from "./core/completion/shells/powershell.mjs";
|
|
10
|
+
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
11
|
+
import { SHELLS, generateCompletion } from "./core/completion/index.mjs";
|
|
12
|
+
import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
13
|
+
import { formatHelp } from "./core/help/index.mjs";
|
|
14
|
+
import { definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
15
|
+
import { createOutput } from "./core/output/index.mjs";
|
|
16
|
+
import { createTerminalPrompter, resolvePromptConfig } from "./core/prompt/index.mjs";
|
|
17
|
+
import { resolve } from "./core/resolve/index.mjs";
|
|
18
|
+
import { discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
19
|
+
import { plugin } from "./core/cli/plugin.mjs";
|
|
20
|
+
import { buildConfigSearchPaths, configFormat, discoverConfig } from "./core/config/index.mjs";
|
|
21
|
+
import { CLIBuilder, cli } from "./core/cli/index.mjs";
|
|
22
|
+
export { ArgBuilder, CLIBuilder, CLIError, CommandBuilder, FlagBuilder, ParseError, SHELLS, ValidationError, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCommandSchema, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, getFlagNegatedName, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WriteFn } from "../core/output/writer.mjs";
|
|
2
|
+
import "../core/output/index.mjs";
|
|
2
3
|
import { ReadFn } from "../core/prompt/index.mjs";
|
|
3
|
-
|
|
4
4
|
//#region src/runtime/adapter.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Runtime adapter interface.
|
|
@@ -62,6 +62,10 @@ interface RuntimeAdapter {
|
|
|
62
62
|
readonly isTTY: boolean;
|
|
63
63
|
/** Whether stdin is connected to a TTY (used for prompt gating). */
|
|
64
64
|
readonly stdinIsTTY: boolean;
|
|
65
|
+
/** Read current terminal dimensions for stdout, if available. */
|
|
66
|
+
readonly getTerminalSize: () => TerminalSize | undefined;
|
|
67
|
+
/** Subscribe to terminal resize events when the runtime supports them. */
|
|
68
|
+
readonly onTerminalResize: (listener: () => void) => (() => void) | undefined;
|
|
65
69
|
/**
|
|
66
70
|
* Exit the process with the given code.
|
|
67
71
|
* Must not return (divergent function).
|
|
@@ -78,6 +82,15 @@ interface RuntimeAdapter {
|
|
|
78
82
|
* Used by config file discovery to probe multiple candidate paths.
|
|
79
83
|
*/
|
|
80
84
|
readonly readFile: (path: string) => Promise<string | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Probe what exists at a filesystem path.
|
|
87
|
+
*
|
|
88
|
+
* Returns `'file'` or `'directory'` for existing paths (other kinds such
|
|
89
|
+
* as sockets report `'file'`), or `null` when nothing exists there.
|
|
90
|
+
*
|
|
91
|
+
* Used by `flag.path()` existence/type checks after resolution.
|
|
92
|
+
*/
|
|
93
|
+
readonly stat: (path: string) => Promise<'file' | 'directory' | null>;
|
|
81
94
|
/**
|
|
82
95
|
* User home directory (absolute path).
|
|
83
96
|
*
|
|
@@ -95,6 +108,13 @@ interface RuntimeAdapter {
|
|
|
95
108
|
*/
|
|
96
109
|
readonly configDir: string;
|
|
97
110
|
}
|
|
111
|
+
/** Current terminal dimensions in columns and rows. */
|
|
112
|
+
interface TerminalSize {
|
|
113
|
+
/** Terminal width in columns. */
|
|
114
|
+
readonly columns: number;
|
|
115
|
+
/** Terminal height in rows. */
|
|
116
|
+
readonly rows: number;
|
|
117
|
+
}
|
|
98
118
|
/**
|
|
99
119
|
* Options for creating a test adapter.
|
|
100
120
|
*
|
|
@@ -138,6 +158,10 @@ interface TestAdapterOptions {
|
|
|
138
158
|
readonly isTTY?: boolean;
|
|
139
159
|
/** TTY flag for stdin (defaults to `false`). */
|
|
140
160
|
readonly stdinIsTTY?: boolean;
|
|
161
|
+
/** Terminal dimensions returned by `getTerminalSize()`. */
|
|
162
|
+
readonly terminalSize?: TerminalSize;
|
|
163
|
+
/** Resize subscription hook returned by `onTerminalResize()`. */
|
|
164
|
+
readonly onTerminalResize?: (listener: () => void) => (() => void) | undefined;
|
|
141
165
|
/**
|
|
142
166
|
* Exit function (defaults to throwing {@linkcode ExitError}).
|
|
143
167
|
* The default throw-based exit allows tests to catch the exit code.
|
|
@@ -158,6 +182,18 @@ interface TestAdapterOptions {
|
|
|
158
182
|
* ```
|
|
159
183
|
*/
|
|
160
184
|
readonly readFile?: (path: string) => Promise<string | null>;
|
|
185
|
+
/**
|
|
186
|
+
* Filesystem probe stub for `flag.path()` checks (defaults to returning
|
|
187
|
+
* `null` — nothing exists).
|
|
188
|
+
*
|
|
189
|
+
* Supply a custom function to simulate a virtual filesystem in tests:
|
|
190
|
+
* ```ts
|
|
191
|
+
* createTestAdapter({
|
|
192
|
+
* stat: (path) => Promise.resolve(path === '/data' ? 'directory' : null),
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
readonly stat?: (path: string) => Promise<'file' | 'directory' | null>;
|
|
161
197
|
/** Home directory (defaults to `'/home/test'`). */
|
|
162
198
|
readonly homedir?: string;
|
|
163
199
|
/** Config directory (defaults to `'/home/test/.config'`). */
|
|
@@ -209,4 +245,4 @@ declare class ExitError extends Error {
|
|
|
209
245
|
*/
|
|
210
246
|
declare function createTestAdapter(options?: TestAdapterOptions): RuntimeAdapter;
|
|
211
247
|
//#endregion
|
|
212
|
-
export { ExitError, type RuntimeAdapter, type TestAdapterOptions, createTestAdapter };
|
|
248
|
+
export { ExitError, type RuntimeAdapter, type TerminalSize, type TestAdapterOptions, createTestAdapter };
|
package/dist/runtime/adapter.mjs
CHANGED
|
@@ -1 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/runtime/adapter.ts
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown by adapter implementations that model process exit as an
|
|
4
|
+
* exception instead of terminating immediately.
|
|
5
|
+
*
|
|
6
|
+
* Runtime and CLI dispatch layers can catch this to perform real process
|
|
7
|
+
* termination, while tests can assert on exit codes without killing the
|
|
8
|
+
* runner:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* try {
|
|
12
|
+
* await cli.run({ adapter: createTestAdapter() });
|
|
13
|
+
* } catch (e) {
|
|
14
|
+
* if (e instanceof ExitError) expect(e.code).toBe(0);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var ExitError = class extends Error {
|
|
19
|
+
/** Error name — always `'ExitError'` for `instanceof` checks. */
|
|
20
|
+
name = "ExitError";
|
|
21
|
+
/** The exit code passed to `exit()`. */
|
|
22
|
+
code;
|
|
23
|
+
/** Create an ExitError for the given process exit code. */
|
|
24
|
+
constructor(code) {
|
|
25
|
+
super(`Process exited with code ${code}`);
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** Noop writer — silently discards output. */
|
|
30
|
+
const noopWrite = () => {};
|
|
31
|
+
/** Noop reader — returns `null` (EOF) immediately. */
|
|
32
|
+
const eofRead = () => Promise.resolve(null);
|
|
33
|
+
/** Noop file reader — returns `null` (not found) for all paths. */
|
|
34
|
+
const noopReadFile = () => Promise.resolve(null);
|
|
35
|
+
/** Noop stat — reports `null` (nothing exists) for all paths. */
|
|
36
|
+
const noopStat = () => Promise.resolve(null);
|
|
37
|
+
/**
|
|
38
|
+
* Create a test runtime adapter with injectable process state.
|
|
39
|
+
*
|
|
40
|
+
* Use this in `@kjanat/dreamcli/testkit` tests when you need to simulate argv,
|
|
41
|
+
* environment variables, TTY state, stdin, or config-file reads without
|
|
42
|
+
* touching the host process.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Optional overrides for any adapter field.
|
|
45
|
+
* @returns A {@linkcode RuntimeAdapter} suitable for test scenarios.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const adapter = createTestAdapter({
|
|
50
|
+
* argv: ['node', 'cli.js', 'deploy', '--force'],
|
|
51
|
+
* env: { DEPLOY_REGION: 'us' },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const result = await cli('mycli').run({ adapter });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function createTestAdapter(options) {
|
|
58
|
+
const stdinIsTTY = options?.stdinIsTTY ?? false;
|
|
59
|
+
let stdinData = !stdinIsTTY ? options?.stdinData : void 0;
|
|
60
|
+
return {
|
|
61
|
+
argv: options?.argv ?? ["node", "test"],
|
|
62
|
+
env: options?.env ?? {},
|
|
63
|
+
cwd: options?.cwd ?? "/test",
|
|
64
|
+
stdout: options?.stdout ?? noopWrite,
|
|
65
|
+
stderr: options?.stderr ?? noopWrite,
|
|
66
|
+
stdin: options?.stdin ?? eofRead,
|
|
67
|
+
readStdin: () => {
|
|
68
|
+
if (stdinData === void 0) return Promise.resolve(null);
|
|
69
|
+
const result = stdinData;
|
|
70
|
+
stdinData = void 0;
|
|
71
|
+
return Promise.resolve(result);
|
|
72
|
+
},
|
|
73
|
+
isTTY: options?.isTTY ?? false,
|
|
74
|
+
stdinIsTTY,
|
|
75
|
+
getTerminalSize: () => options?.terminalSize,
|
|
76
|
+
onTerminalResize: (listener) => options?.onTerminalResize?.(listener),
|
|
77
|
+
exit: options?.exit ?? ((code) => {
|
|
78
|
+
throw new ExitError(code);
|
|
79
|
+
}),
|
|
80
|
+
readFile: options?.readFile ?? noopReadFile,
|
|
81
|
+
stat: options?.stat ?? noopStat,
|
|
82
|
+
homedir: options?.homedir ?? "/home/test",
|
|
83
|
+
configDir: options?.configDir ?? "/home/test/.config"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { ExitError, createTestAdapter };
|
package/dist/runtime/auto.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
2
|
import { GlobalForDetect } from "./detect.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/runtime/auto.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Create a runtime adapter for the current environment.
|
|
7
6
|
*
|
|
8
7
|
* Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
|
|
9
|
-
*
|
|
10
|
-
* expose a Node-compatible `process` global.
|
|
8
|
+
* Only Deno needs a distinct adapter; Bun, Node, and unknown runtimes all use
|
|
9
|
+
* the Node adapter because they expose a Node-compatible `process` global.
|
|
11
10
|
*
|
|
12
11
|
* @param globals - Override `globalThis` for testing. Production callers
|
|
13
12
|
* should omit this parameter.
|
package/dist/runtime/auto.mjs
CHANGED
|
@@ -1 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createDenoAdapter } from "./deno.mjs";
|
|
2
|
+
import { detectRuntime } from "./detect.mjs";
|
|
3
|
+
import { createNodeAdapter } from "./node.mjs";
|
|
4
|
+
//#region src/runtime/auto.ts
|
|
5
|
+
function isDenoNamespace(value) {
|
|
6
|
+
if (typeof value !== "object" || value === null) return false;
|
|
7
|
+
const candidate = value;
|
|
8
|
+
return Array.isArray(candidate.args) && typeof candidate.cwd === "function" && typeof candidate.exit === "function" && typeof candidate.readTextFile === "function" && typeof candidate.env?.get === "function" && typeof candidate.env.toObject === "function" && typeof candidate.stdout?.writeSync === "function" && typeof candidate.stdout.isTerminal === "function" && typeof candidate.stderr?.writeSync === "function" && typeof candidate.stdin?.isTerminal === "function" && typeof candidate.stdin?.readable?.getReader === "function";
|
|
9
|
+
}
|
|
10
|
+
function getInjectedDenoNamespace(globals) {
|
|
11
|
+
const candidate = globals.Deno;
|
|
12
|
+
return isDenoNamespace(candidate) ? candidate : void 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a runtime adapter for the current environment.
|
|
16
|
+
*
|
|
17
|
+
* Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
|
|
18
|
+
* Only Deno needs a distinct adapter; Bun, Node, and unknown runtimes all use
|
|
19
|
+
* the Node adapter because they expose a Node-compatible `process` global.
|
|
20
|
+
*
|
|
21
|
+
* @param globals - Override `globalThis` for testing. Production callers
|
|
22
|
+
* should omit this parameter.
|
|
23
|
+
* @returns A {@linkcode RuntimeAdapter} for the detected runtime.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { cli } from '@kjanat/dreamcli';
|
|
28
|
+
*
|
|
29
|
+
* // Auto-detects Node/Bun/Deno and creates the right adapter
|
|
30
|
+
* cli('mycli').run(); // uses createAdapter() internally
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function createAdapter(globals) {
|
|
34
|
+
const runtimeGlobals = globals ?? globalThis;
|
|
35
|
+
const runtime = detectRuntime(runtimeGlobals);
|
|
36
|
+
switch (runtime) {
|
|
37
|
+
case "deno": return createDenoAdapter(getInjectedDenoNamespace(runtimeGlobals));
|
|
38
|
+
case "bun":
|
|
39
|
+
case "node":
|
|
40
|
+
case "unknown": return createNodeAdapter();
|
|
41
|
+
default: return runtime;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createAdapter };
|
package/dist/runtime/deno.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/runtime/deno.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Minimal subset of the Deno namespace needed by the adapter.
|
|
@@ -24,29 +23,49 @@ interface DenoNamespace {
|
|
|
24
23
|
readonly args: readonly string[];
|
|
25
24
|
/** Environment variable access (requires `--allow-env`). */
|
|
26
25
|
readonly env: {
|
|
27
|
-
/** Get a single env var. Returns `undefined` if unset or permission denied. */
|
|
26
|
+
/** Get a single env var. Returns `undefined` if unset or permission denied. */
|
|
27
|
+
get(key: string): string | undefined;
|
|
28
|
+
/** Get all env vars as a plain object. Throws on permission denied. */
|
|
28
29
|
toObject(): Record<string, string>;
|
|
29
30
|
};
|
|
30
31
|
/** Current working directory (may throw if `--allow-read` is denied for cwd). */
|
|
31
32
|
cwd(): string;
|
|
32
33
|
/** Standard output — synchronous byte writer with TTY detection. */
|
|
33
34
|
readonly stdout: {
|
|
34
|
-
/** Write raw bytes to stdout synchronously. */
|
|
35
|
+
/** Write raw bytes to stdout synchronously. */
|
|
36
|
+
writeSync(p: Uint8Array): number;
|
|
37
|
+
/** Whether stdout is connected to a TTY. */
|
|
35
38
|
isTerminal(): boolean;
|
|
36
39
|
};
|
|
40
|
+
/** Current console dimensions. */
|
|
41
|
+
consoleSize?(): {
|
|
42
|
+
readonly columns: number;
|
|
43
|
+
readonly rows: number;
|
|
44
|
+
};
|
|
45
|
+
/** Register a native signal listener. */
|
|
46
|
+
addSignalListener?(signal: 'SIGWINCH', listener: () => void): void;
|
|
47
|
+
/** Remove a native signal listener. */
|
|
48
|
+
removeSignalListener?(signal: 'SIGWINCH', listener: () => void): void;
|
|
37
49
|
/** Standard error — synchronous byte writer. */
|
|
38
50
|
readonly stderr: {
|
|
39
|
-
/** Write raw bytes to stderr synchronously. */
|
|
51
|
+
/** Write raw bytes to stderr synchronously. */
|
|
52
|
+
writeSync(p: Uint8Array): number;
|
|
40
53
|
};
|
|
41
54
|
/** Standard input — TTY detection and readable byte stream. */
|
|
42
55
|
readonly stdin: {
|
|
43
|
-
/** Whether stdin is connected to a TTY. */
|
|
56
|
+
/** Whether stdin is connected to a TTY. */
|
|
57
|
+
isTerminal(): boolean;
|
|
58
|
+
/** Readable stream for stdin bytes. */
|
|
44
59
|
readonly readable: ReadableStream<Uint8Array>;
|
|
45
60
|
};
|
|
46
61
|
/** Exit the process with the given code. */
|
|
47
62
|
exit(code: number): never;
|
|
48
63
|
/** Read a file as UTF-8 text (requires `--allow-read`). */
|
|
49
64
|
readTextFile(path: string): Promise<string>;
|
|
65
|
+
/** Probe a filesystem path (requires `--allow-read`). */
|
|
66
|
+
stat(path: string): Promise<{
|
|
67
|
+
readonly isDirectory: boolean;
|
|
68
|
+
}>;
|
|
50
69
|
}
|
|
51
70
|
/**
|
|
52
71
|
* Create a runtime adapter backed by the Deno namespace.
|
package/dist/runtime/deno.mjs
CHANGED
|
@@ -1,2 +1,262 @@
|
|
|
1
|
-
import{resolveConfigDirectory
|
|
2
|
-
|
|
1
|
+
import { resolveConfigDirectory, resolveHomeDirectory } from "./paths.mjs";
|
|
2
|
+
//#region src/runtime/deno.ts
|
|
3
|
+
/**
|
|
4
|
+
* Detect whether an unknown thrown value is a Deno error by name.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
function isDenoErrorNamed(err, name) {
|
|
9
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return false;
|
|
10
|
+
const candidate = err;
|
|
11
|
+
return typeof candidate.name === "string" && candidate.name === name;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Safely read all environment variables. Returns empty object if
|
|
15
|
+
* `--allow-env` permission is not granted.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
function safeEnvToObject(deno) {
|
|
20
|
+
try {
|
|
21
|
+
return deno.env.toObject();
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (isDenoErrorNamed(err, "PermissionDenied")) return {};
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Safely get the current working directory. Returns `/` if the cwd is
|
|
29
|
+
* inaccessible due to missing permissions.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
function safeCwd(deno) {
|
|
34
|
+
try {
|
|
35
|
+
return deno.cwd();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
if (isDenoErrorNamed(err, "PermissionDenied")) return "/";
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a runtime adapter backed by the Deno namespace.
|
|
43
|
+
*
|
|
44
|
+
* Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based
|
|
45
|
+
* I/O into the {@linkcode WriteFn}/{@linkcode ReadFn} functions expected by the framework.
|
|
46
|
+
*
|
|
47
|
+
* Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`.
|
|
48
|
+
* The adapter prepends synthetic entries (`['deno', 'run']`) so the argv
|
|
49
|
+
* shape matches the {@linkcode RuntimeAdapter} contract (binary + script + user args).
|
|
50
|
+
*
|
|
51
|
+
* @param ns - Override the Deno namespace (useful for testing the adapter itself).
|
|
52
|
+
* @returns A {@linkcode RuntimeAdapter} backed by Deno's namespace APIs.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { cli } from '@kjanat/dreamcli';
|
|
57
|
+
* import { createDenoAdapter } from '@kjanat/dreamcli/runtime';
|
|
58
|
+
*
|
|
59
|
+
* cli('mycli')
|
|
60
|
+
* .command(deploy)
|
|
61
|
+
* .run({ adapter: createDenoAdapter() });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function createDenoAdapter(ns) {
|
|
65
|
+
const d = ns ?? getDenoNamespace();
|
|
66
|
+
const encoder = new TextEncoder();
|
|
67
|
+
const argv = [
|
|
68
|
+
"deno",
|
|
69
|
+
"run",
|
|
70
|
+
...d.args
|
|
71
|
+
];
|
|
72
|
+
const env = safeEnvToObject(d);
|
|
73
|
+
const cwd = safeCwd(d);
|
|
74
|
+
const stdoutWrite = (data) => {
|
|
75
|
+
d.stdout.writeSync(encoder.encode(data));
|
|
76
|
+
};
|
|
77
|
+
const stderrWrite = (data) => {
|
|
78
|
+
d.stderr.writeSync(encoder.encode(data));
|
|
79
|
+
};
|
|
80
|
+
const stdinRead = createDenoReadLine(d);
|
|
81
|
+
const readFile = async (path) => {
|
|
82
|
+
try {
|
|
83
|
+
return await d.readTextFile(path);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
if (isDenoErrorNamed(err, "NotFound")) return null;
|
|
86
|
+
if (isDenoErrorNamed(err, "PermissionDenied")) return null;
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const stat = async (path) => {
|
|
91
|
+
try {
|
|
92
|
+
return (await d.stat(path)).isDirectory ? "directory" : "file";
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (isDenoErrorNamed(err, "NotFound")) return null;
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const homedir = resolveDenoHomedir(env, d.build.os === "windows");
|
|
99
|
+
const configDir = resolveDenoConfigDir(env, homedir, d.build.os === "windows");
|
|
100
|
+
const stdinIsTTY = d.stdin.isTerminal();
|
|
101
|
+
return {
|
|
102
|
+
argv,
|
|
103
|
+
env,
|
|
104
|
+
cwd,
|
|
105
|
+
stdout: stdoutWrite,
|
|
106
|
+
stderr: stderrWrite,
|
|
107
|
+
stdin: stdinRead,
|
|
108
|
+
readStdin: () => readDenoStdinAll(d, stdinIsTTY),
|
|
109
|
+
isTTY: d.stdout.isTerminal(),
|
|
110
|
+
stdinIsTTY,
|
|
111
|
+
getTerminalSize: () => readDenoTerminalSize(d),
|
|
112
|
+
onTerminalResize: (listener) => onDenoTerminalResize(d, listener),
|
|
113
|
+
exit: (code) => d.exit(code),
|
|
114
|
+
readFile,
|
|
115
|
+
stat,
|
|
116
|
+
homedir,
|
|
117
|
+
configDir
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Normalize terminal dimensions and discard unusable values. @internal */
|
|
121
|
+
function normalizeTerminalSize(columns, rows) {
|
|
122
|
+
if (columns === void 0 || rows === void 0) return void 0;
|
|
123
|
+
if (!Number.isFinite(columns) || !Number.isFinite(rows)) return void 0;
|
|
124
|
+
if (columns <= 0 || rows <= 0) return void 0;
|
|
125
|
+
return {
|
|
126
|
+
columns,
|
|
127
|
+
rows
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Read native Deno terminal dimensions. @internal */
|
|
131
|
+
function readDenoTerminalSize(deno) {
|
|
132
|
+
if (!deno.stdout.isTerminal() || deno.consoleSize === void 0) return void 0;
|
|
133
|
+
try {
|
|
134
|
+
const size = deno.consoleSize();
|
|
135
|
+
return normalizeTerminalSize(size.columns, size.rows);
|
|
136
|
+
} catch {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Subscribe to native Deno resize signals where SIGWINCH exists. @internal */
|
|
141
|
+
function onDenoTerminalResize(deno, listener) {
|
|
142
|
+
if (!deno.stdout.isTerminal()) return void 0;
|
|
143
|
+
if (deno.build.os === "windows") return void 0;
|
|
144
|
+
if (deno.addSignalListener === void 0 || deno.removeSignalListener === void 0) return;
|
|
145
|
+
try {
|
|
146
|
+
deno.addSignalListener("SIGWINCH", listener);
|
|
147
|
+
} catch {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
return () => {
|
|
151
|
+
deno.removeSignalListener?.("SIGWINCH", listener);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Access the global `Deno` namespace.
|
|
156
|
+
*
|
|
157
|
+
* Cast through `unknown` to avoid TypeScript errors when Deno types
|
|
158
|
+
* aren't installed. Safe because this adapter is only used on Deno
|
|
159
|
+
* where `globalThis.Deno` is always defined.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
function getDenoNamespace() {
|
|
164
|
+
return globalThis.Deno;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Read all of stdin as a single string (for piped data).
|
|
168
|
+
*
|
|
169
|
+
* Returns `null` immediately if stdin is a TTY — the user is typing
|
|
170
|
+
* interactively, so there's no piped data to consume. When stdin is
|
|
171
|
+
* piped, collects all chunks via the `ReadableStream` until EOF and
|
|
172
|
+
* returns the decoded string, which may be empty for an empty pipe.
|
|
173
|
+
*
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
async function readDenoStdinAll(deno, stdinIsTTY) {
|
|
177
|
+
if (stdinIsTTY) return null;
|
|
178
|
+
const reader = deno.stdin.readable.getReader();
|
|
179
|
+
const decoder = new TextDecoder();
|
|
180
|
+
const chunks = [];
|
|
181
|
+
try {
|
|
182
|
+
for (;;) {
|
|
183
|
+
const { value, done } = await reader.read();
|
|
184
|
+
if (done) {
|
|
185
|
+
chunks.push(decoder.decode());
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
chunks.push(decoder.decode(value, { stream: true }));
|
|
189
|
+
}
|
|
190
|
+
} finally {
|
|
191
|
+
reader.releaseLock();
|
|
192
|
+
}
|
|
193
|
+
return chunks.join("");
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Read a single line from Deno's stdin.
|
|
197
|
+
*
|
|
198
|
+
* Uses the `ReadableStream` API with a manual buffer to read until
|
|
199
|
+
* a newline character is found. Returns `null` on EOF.
|
|
200
|
+
*
|
|
201
|
+
* This is intentionally simple — the terminal prompter handles retries
|
|
202
|
+
* and validation.
|
|
203
|
+
*
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
function createDenoReadLine(deno) {
|
|
207
|
+
const decoder = new TextDecoder();
|
|
208
|
+
let buffer = "";
|
|
209
|
+
let done = false;
|
|
210
|
+
return async () => {
|
|
211
|
+
const reader = deno.stdin.readable.getReader();
|
|
212
|
+
try {
|
|
213
|
+
for (;;) {
|
|
214
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
215
|
+
if (newlineIndex !== -1) {
|
|
216
|
+
const line = buffer.slice(0, newlineIndex).replace(/\r$/, "");
|
|
217
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
218
|
+
return line;
|
|
219
|
+
}
|
|
220
|
+
if (done) {
|
|
221
|
+
if (buffer.length === 0) return null;
|
|
222
|
+
const line = buffer;
|
|
223
|
+
buffer = "";
|
|
224
|
+
return line;
|
|
225
|
+
}
|
|
226
|
+
const { value, done: readDone } = await reader.read();
|
|
227
|
+
if (readDone) {
|
|
228
|
+
buffer += decoder.decode();
|
|
229
|
+
done = true;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
buffer += decoder.decode(value, { stream: true });
|
|
233
|
+
}
|
|
234
|
+
} finally {
|
|
235
|
+
reader.releaseLock();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Resolve the user's home directory from environment variables.
|
|
241
|
+
*
|
|
242
|
+
* Deno doesn't expose `os.homedir()` without `--allow-sys`, so we derive
|
|
243
|
+
* it from env vars — same approach as the Node adapter.
|
|
244
|
+
*
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
function resolveDenoHomedir(env, isWindows) {
|
|
248
|
+
return resolveHomeDirectory(env, isWindows);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Resolve the platform-specific user configuration directory.
|
|
252
|
+
*
|
|
253
|
+
* Uses `Deno.build.os` for platform detection, then applies the same fallback
|
|
254
|
+
* chain as the Node adapter.
|
|
255
|
+
*
|
|
256
|
+
* @internal
|
|
257
|
+
*/
|
|
258
|
+
function resolveDenoConfigDir(env, homedir, isWindows) {
|
|
259
|
+
return resolveConfigDirectory(env, isWindows, homedir);
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
export { createDenoAdapter };
|