hacksh 0.20.0 → 0.21.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/README.md +4 -2
- package/dist/{command-EDfoT1KJ.d.ts → command-BIeWBYyQ.d.ts} +6 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -57
- package/dist/index.js.map +1 -1
- package/dist/{pretty-BykhfUqM.js → pretty-MURri0un.js} +111 -2
- package/dist/pretty-MURri0un.js.map +1 -0
- package/dist/printer-api.d.ts +2 -2
- package/dist/printer-api.js +2 -2
- package/package.json +1 -1
- package/dist/pretty-BykhfUqM.js.map +0 -1
package/README.md
CHANGED
|
@@ -499,8 +499,10 @@ writer given to `runMain` or `runCommand`.
|
|
|
499
499
|
Every `run` context has a `logger`. Its `trace`, `debug`, `info`, `warn`, `error`, and `fatal`
|
|
500
500
|
methods emit structured records through the invocation's printer. `step` and `success` are
|
|
501
501
|
info-level records with a distinct semantic kind for presentation. Placeholders in braces use the
|
|
502
|
-
record's properties.
|
|
503
|
-
|
|
502
|
+
record's properties. By default every level is emitted (`"trace"`); pass `logLevel` on `runMain`
|
|
503
|
+
or `runCommand`, or set `HACKSH_LOG_LEVEL` (which takes precedence), to filter the primary output's
|
|
504
|
+
minimum log level. Thrown command errors are not log records and are always reported regardless of
|
|
505
|
+
`logLevel`.
|
|
504
506
|
|
|
505
507
|
```ts
|
|
506
508
|
const deploy = defineCommand({
|
|
@@ -135,7 +135,10 @@ interface HackshErrorSummary {
|
|
|
135
135
|
}
|
|
136
136
|
//#endregion
|
|
137
137
|
//#region src/logger.d.ts
|
|
138
|
-
|
|
138
|
+
declare const LOG_LEVELS: readonly ["trace", "debug", "info", "warning", "error", "fatal"];
|
|
139
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
140
|
+
/** Wrap a printer so only log events at or above `minLevel` are forwarded; non-log events always pass through. */
|
|
141
|
+
declare function filterLogPrinter(printer: Printer, minLevel: LogLevel): Printer;
|
|
139
142
|
type LogKind = "message" | "step" | "success";
|
|
140
143
|
type LogProperties = Record<string, unknown>;
|
|
141
144
|
/** A structured message emitted by a command's logger. */
|
|
@@ -440,5 +443,5 @@ interface CommandDef<S extends ArgsSchema = EmptyArgs, Children extends Record<s
|
|
|
440
443
|
type AnyCommandDef = CommandDef<ArgsSchema>;
|
|
441
444
|
declare function defineCommand<S extends ArgsSchema = EmptyArgs, Children extends Record<string, AnyCommandDef> = {}>(def: CommandDef<S, Children>): NoInfer<CommandDef<S, Children>>;
|
|
442
445
|
//#endregion
|
|
443
|
-
export { LogProperties as $, PromptState as A, WaitPromptState as B, OutputPrintEvent as C,
|
|
444
|
-
//# sourceMappingURL=command-
|
|
446
|
+
export { LogProperties as $, PromptState as A, WaitPromptState as B, OutputPrintEvent as C, ExecSkipped as Ct, Printer as D, PrintStream as E, TerminalInput as F, UsageCommandSummary as G, resolveOutputMode as H, TerminalOutput as I, renderUsage as J, UsageOptionSummary as K, TextPromptState as L, ResolveOutputModeOptions as M, SelectPromptState as N, PromptChoiceState as O, StreamColors as P, LogLevel as Q, UsagePrintEvent as R, OutputPreference as S, ExecReturn as St, PrintEvent as T, ShowUsageOptions as U, createJsonPrinter as V, UsageArgumentSummary as W, summarizeUsage as X, showUsage as Y, LogKind as Z, ExecPrintEvent as _, ExecCommand as _t, ArgsSchema as a, HackshErrorSummary as at, OutputFormat as b, ExecOptions as bt, Prompter as c, HackshIssue as ct, TextOptions as d, HackshUsageError as dt, LogRecord as et, WaitOptions as f, HackshValidationError as ft, ErrorPrintEvent as g, Exec as gt, ConfirmPromptState as h, ValidationIssueSummary as ht, defineCommand as i, HackshErrorKind as it, PromptStatus as j, PromptPrintEvent as k, SelectOption as l, HackshPromptError as lt, AutocompletePromptState as m, PromptKind as mt, CommandContext as n, filterLogPrinter as nt, AutocompleteOptions as o, HackshExecError as ot, Output as p, PromptErrorDetails as pt, UsageSummary as q, CommandDef as r, HackshError as rt, ConfirmOptions as s, HackshExitError as st, AnyCommandDef as t, Logger as tt, SelectOptions as u, HackshPromptErrorReason as ut, JsonPrinterOptions as v, ExecFailure as vt, OutputWriter as w, ExecSuccess as wt, OutputMode as x, ExecResult as xt, LogPrintEvent as y, ExecFailureReason as yt, VersionPrintEvent as z };
|
|
447
|
+
//# sourceMappingURL=command-BIeWBYyQ.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ct as
|
|
1
|
+
import { Ct as ExecSkipped, D as Printer, F as TerminalInput, I as TerminalOutput, J as renderUsage, Q as LogLevel, S as OutputPreference, St as ExecReturn, U as ShowUsageOptions, X as summarizeUsage, Y as showUsage, _t as ExecCommand, a as ArgsSchema, bt as ExecOptions, c as Prompter, ct as HackshIssue, d as TextOptions, dt as HackshUsageError, f as WaitOptions, ft as HackshValidationError, gt as Exec, i as defineCommand, l as SelectOption, lt as HackshPromptError, mt as PromptKind, n as CommandContext, o as AutocompleteOptions, ot as HackshExecError, p as Output, pt as PromptErrorDetails, r as CommandDef, rt as HackshError, s as ConfirmOptions, st as HackshExitError, t as AnyCommandDef, tt as Logger, u as SelectOptions, ut as HackshPromptErrorReason, vt as ExecFailure, wt as ExecSuccess, xt as ExecResult, yt as ExecFailureReason } from "./command-BIeWBYyQ.js";
|
|
2
2
|
import { output } from "zod/v4/core";
|
|
3
3
|
//#region src/parser.d.ts
|
|
4
4
|
/**
|
|
@@ -14,6 +14,8 @@ interface OutputOptions {
|
|
|
14
14
|
output?: OutputPreference;
|
|
15
15
|
/** Use Unicode presentation symbols in pretty output. Defaults to true. */
|
|
16
16
|
unicode?: boolean;
|
|
17
|
+
/** Minimum log level emitted to the primary output printer. Defaults to "trace". */
|
|
18
|
+
logLevel?: LogLevel;
|
|
17
19
|
env?: Readonly<Record<string, string | undefined>>;
|
|
18
20
|
stdin?: TerminalInput;
|
|
19
21
|
stdout?: TerminalOutput;
|
|
@@ -33,5 +35,5 @@ interface RunMainOptions extends OutputOptions {
|
|
|
33
35
|
}
|
|
34
36
|
declare function runMain<S extends ArgsSchema>(command: CommandDef<S>, options?: RunMainOptions): Promise<void>;
|
|
35
37
|
//#endregion
|
|
36
|
-
export { type AutocompleteOptions, type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshError, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type Logger, type Output, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, type WaitOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
|
|
38
|
+
export { type AutocompleteOptions, type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshError, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type LogLevel, type Logger, type Output, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, type WaitOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
|
|
37
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as createLogger, c as createExec, d as HackshExitError, f as HackshPromptError, g as summarizeErrors, h as summarizeError, i as resolveOutputMode, l as HackshError, m as HackshValidationError, n as createJsonPrinter, o as filterLogPrinter, p as HackshUsageError, r as createPrintQueue, s as resolveLogLevel, t as createPrettyPrinter, u as HackshExecError } from "./pretty-MURri0un.js";
|
|
2
2
|
import { globalRegistry, safeParseAsync } from "zod/v4/core";
|
|
3
3
|
import { parseArgs as parseArgs$1 } from "node:util";
|
|
4
4
|
import { readFile, realpath } from "node:fs/promises";
|
|
@@ -512,61 +512,6 @@ var TerminalLock = class {
|
|
|
512
512
|
}
|
|
513
513
|
};
|
|
514
514
|
//#endregion
|
|
515
|
-
//#region src/logger.ts
|
|
516
|
-
function interpolate(message, properties) {
|
|
517
|
-
return message.replace(/\{([^{}]+)\}/g, (placeholder, key) => {
|
|
518
|
-
if (!Object.hasOwn(properties, key)) return placeholder;
|
|
519
|
-
try {
|
|
520
|
-
return String(properties[key]);
|
|
521
|
-
} catch {
|
|
522
|
-
return placeholder;
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
function createBoundLogger(printer, category, boundProperties) {
|
|
527
|
-
function emit(level, kind, input, properties = {}) {
|
|
528
|
-
const rawMessage = input instanceof Error ? input.message : input;
|
|
529
|
-
const mergedProperties = {
|
|
530
|
-
...boundProperties,
|
|
531
|
-
...properties
|
|
532
|
-
};
|
|
533
|
-
if (input instanceof Error) mergedProperties.error = input;
|
|
534
|
-
const summarizedProperties = summarizeErrors(mergedProperties);
|
|
535
|
-
printer.print({
|
|
536
|
-
type: "log",
|
|
537
|
-
record: {
|
|
538
|
-
level,
|
|
539
|
-
kind,
|
|
540
|
-
category,
|
|
541
|
-
message: interpolate(rawMessage, mergedProperties),
|
|
542
|
-
rawMessage,
|
|
543
|
-
properties: summarizedProperties,
|
|
544
|
-
timestamp: Date.now()
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
return {
|
|
549
|
-
category,
|
|
550
|
-
trace: (message, properties) => emit("trace", "message", message, properties),
|
|
551
|
-
debug: (message, properties) => emit("debug", "message", message, properties),
|
|
552
|
-
info: (message, properties) => emit("info", "message", message, properties),
|
|
553
|
-
warn: (message, properties) => emit("warning", "message", message, properties),
|
|
554
|
-
error: (message, properties) => emit("error", "message", message, properties),
|
|
555
|
-
fatal: (message, properties) => emit("fatal", "message", message, properties),
|
|
556
|
-
step: (message, properties) => emit("info", "step", message, properties),
|
|
557
|
-
success: (message, properties) => emit("info", "success", message, properties),
|
|
558
|
-
with: (properties) => createBoundLogger(printer, category, {
|
|
559
|
-
...boundProperties,
|
|
560
|
-
...properties
|
|
561
|
-
}),
|
|
562
|
-
getChild: (child) => createBoundLogger(printer, [...category, child], boundProperties)
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
/** Create the logger for one command invocation. */
|
|
566
|
-
function createLogger(printer, category) {
|
|
567
|
-
return createBoundLogger(printer, [...category], {});
|
|
568
|
-
}
|
|
569
|
-
//#endregion
|
|
570
515
|
//#region src/package-version.ts
|
|
571
516
|
async function findPackageVersion(entry) {
|
|
572
517
|
if (!entry) return void 0;
|
|
@@ -1310,8 +1255,10 @@ function prepareOutput(options, env) {
|
|
|
1310
1255
|
outputIsTTY: (options.stdout ?? process.stdout).isTTY,
|
|
1311
1256
|
errorOutputIsTTY: (options.stderr ?? process.stderr).isTTY
|
|
1312
1257
|
});
|
|
1258
|
+
const logLevel = resolveLogLevel(options.logLevel, env);
|
|
1259
|
+
const printer = filterLogPrinter(selectOutputPrinter(options, options.printer, mode), logLevel);
|
|
1313
1260
|
return {
|
|
1314
|
-
...createPrintQueue(
|
|
1261
|
+
...createPrintQueue(printer),
|
|
1315
1262
|
format: mode.format,
|
|
1316
1263
|
interactive: mode.interactive,
|
|
1317
1264
|
input,
|