@clerc/logger 2.0.0-beta.1 → 2.0.0-beta.2
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 +1 -1
- package/dist/index.d.mts +14 -15
- package/dist/index.mjs +7 -7
- package/dist/prompts.d.mts +1 -0
- package/dist/prompts.mjs +1 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @clerc/logger
|
|
2
2
|
|
|
3
|
-
Minimal CLI logger with
|
|
3
|
+
Minimal CLI logger with right-aligned word labels, `node:util` `inspect`, Clack-powered `box` / `spinner` / `task`, and structured JSON output.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import * as prompts from "@clack/prompts";
|
|
2
|
-
import { SpinnerOptions as SpinnerOptions$1 } from "@clack/prompts";
|
|
3
1
|
import { Theme } from "@clerc/theme";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { SpinnerOptions as SpinnerOptions$1 } from "@clack/prompts";
|
|
3
|
+
type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
4
|
+
type LogFormat = "pretty" | "json";
|
|
5
|
+
interface LogEntry {
|
|
7
6
|
readonly line: (...values: unknown[]) => LogEntry;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
type LogMethod<TReturn = void> = (message: unknown, ...details: unknown[]) => TReturn;
|
|
9
|
+
interface LogMethods<TReturn = LogEntry> {
|
|
11
10
|
step: LogMethod<TReturn>;
|
|
12
11
|
info: LogMethod<TReturn>;
|
|
13
12
|
success: LogMethod<TReturn>;
|
|
@@ -15,7 +14,7 @@ export interface LogMethods<TReturn = LogEntry> {
|
|
|
15
14
|
error: LogMethod<TReturn>;
|
|
16
15
|
debug: LogMethod<TReturn>;
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
interface SpinnerOptions {
|
|
19
18
|
readonly indicator?: SpinnerOptions$1["indicator"];
|
|
20
19
|
readonly cancelMessage?: string;
|
|
21
20
|
readonly errorMessage?: string;
|
|
@@ -23,7 +22,7 @@ export interface SpinnerOptions {
|
|
|
23
22
|
readonly delay?: number;
|
|
24
23
|
readonly signal?: AbortSignal;
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
interface SpinnerHandle {
|
|
27
26
|
start: (message?: string) => void;
|
|
28
27
|
message: (message: string) => void;
|
|
29
28
|
stop: (message?: string) => void;
|
|
@@ -32,8 +31,8 @@ export interface SpinnerHandle {
|
|
|
32
31
|
clear: () => void;
|
|
33
32
|
readonly isCancelled: boolean;
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
type TaskSpinner = Omit<SpinnerHandle, "start">;
|
|
35
|
+
interface LoggerTerminal {
|
|
37
36
|
readonly stdout: (text: string) => void;
|
|
38
37
|
readonly stderr: (text: string) => void;
|
|
39
38
|
readonly isTTY?: boolean;
|
|
@@ -41,18 +40,18 @@ export interface LoggerTerminal {
|
|
|
41
40
|
readonly unicode?: boolean;
|
|
42
41
|
readonly columns?: number;
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
interface LoggerOptions {
|
|
45
44
|
level?: LogLevel;
|
|
46
45
|
format?: LogFormat;
|
|
47
46
|
scope?: string;
|
|
48
47
|
}
|
|
49
|
-
|
|
48
|
+
interface CreateLoggerOptions extends LoggerOptions {
|
|
50
49
|
readonly terminal?: LoggerTerminal;
|
|
51
50
|
readonly theme?: Theme;
|
|
52
51
|
readonly color?: boolean;
|
|
53
52
|
readonly unicode?: boolean;
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
interface Logger extends LogMethods {
|
|
56
55
|
level: LogLevel;
|
|
57
56
|
format: LogFormat;
|
|
58
57
|
readonly scope?: string;
|
|
@@ -67,4 +66,4 @@ export declare const LOG_LABEL_WIDTH = 5;
|
|
|
67
66
|
export declare const LOG_GUTTER: string;
|
|
68
67
|
export declare const formatLogLabel: (label: string, style?: (text: string) => string) => string;
|
|
69
68
|
export declare function createLogger(options?: CreateLoggerOptions): Logger;
|
|
70
|
-
export {
|
|
69
|
+
export type { CreateLoggerOptions, LogEntry, LogFormat, LogLevel, LogMethod, LogMethods, Logger, LoggerOptions, LoggerTerminal, SpinnerHandle, SpinnerOptions, TaskSpinner };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`).map(e=>e.trim()).filter(e=>e.startsWith(`at `)),r=n.filter(e=>!e.includes(`node:internal/`));return r.length>0?r:n}function
|
|
3
|
-
`).map(e=>
|
|
4
|
-
`).map(e=>
|
|
5
|
-
`);return{headline:
|
|
6
|
-
`):(
|
|
7
|
-
`)
|
|
1
|
+
import{createTheme as e,detectColor as t,detectUnicode as n}from"@clerc/theme";import{inspect as r}from"node:util";import{createRequire as i}from"node:module";const a=5,o=` `.repeat(6),s={step:{level:`info`,stderr:!1,token:`brand`,label:`step`},info:{level:`info`,stderr:!1,token:`info`,label:`info`},success:{level:`info`,stderr:!1,token:`success`,label:`done`},warn:{level:`warn`,stderr:!0,token:`warn`,label:`warn`},error:{level:`error`,stderr:!0,token:`error`,label:`error`},debug:{level:`debug`,stderr:!1,token:`muted`,label:`debug`}},c=e=>e,l=(e,t=c)=>`${` `.repeat(Math.max(0,5-e.length))}${t(e)}`,u=(e,t,n,r)=>l(e,e=>r?t.bold(t[n](e)):t[n](e)),d=e=>JSON.stringify(e,(e,t)=>Error.isError(t)?{name:t.name,message:t.message,stack:t.stack,...t.cause===void 0?{}:{cause:t.cause}}:t),f=e=>e.message.length>0?`${e.name}: ${e.message}`:e.name;function p(e){if(!e.stack)return[];let t=f(e),n=(e.stack.startsWith(t)?e.stack.slice(t.length):e.stack).split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(e=>e.startsWith(`at `)),r=n.filter(e=>!e.includes(`node:internal/`));return r.length>0?r:n}function m(e,t,n,i,a=/* @__PURE__ */ new Set){a.add(e);let o=[];i&&o.push(t(f(e)));for(let t of p(e))o.push(n(` ${t}`));return e.cause!==void 0&&!a.has(e.cause)&&(Error.isError(e.cause)?(o.push(t(`Caused by: ${f(e.cause)}`)),o.push(...m(e.cause,t,n,!1,a))):o.push(t(`Caused by: ${r(e.cause,{colors:!1,depth:2})}`))),o}function h(e,t,n,i,a){let o=t?a:n.muted;return typeof e==`string`?e.split(`
|
|
3
|
+
`).map(e=>o(e)):Error.isError(e)?m(e,o,a,!0):r(e,{colors:!t&&i,depth:4}).split(`
|
|
4
|
+
`).map(e=>o(e))}function g(e,t,n,i,a,o){let s=n.flatMap(t=>h(t,e,i,a,o));if(typeof t==`string`)return{headline:t,extraLines:s,jsonMessage:t};if(Error.isError(t)&&n.length===0)return{headline:t.message.length>0?t.message:t.name,extraLines:m(t,e?o:i.muted,o,t.name!==`Error`),jsonMessage:t};let c=r(t,{colors:!e&&a,depth:4}).split(`
|
|
5
|
+
`);return{headline:c[0]??``,extraLines:[...c.slice(1).map(t=>e?o(t):i.muted(t)),...s],jsonMessage:t}}let _;const v=()=>_??=i(import.meta.url)(`@clack/prompts`);function y(e){let{body:t,title:n,columns:r,unicode:i,faint:a}=e,s=[],c={columns:Math.max(40,r-o.length),write(e){let t=e.replace(/\n$/,``);return t.length>0&&s.push(...t.split(`
|
|
6
|
+
`)),!0}};return v().box(t,n,{output:c,withGuide:!1,rounded:i,width:`auto`,titlePadding:1,contentPadding:2,contentAlign:`left`,titleAlign:`left`,formatBorder:e=>a(i?e:e===`─`?`-`:e===`│`?`|`:`+`)}),s}function b(e){let{options:t,theme:n,unicode:r,noopEntry:i,shouldLogInfo:a,canAnimate:o,formatScope:s,emit:c}=e,l=!1,u=!1,d=i,f;function p(){f&&l&&f.clear(),l=!1,d=i}return{start(e=``){if(p(),u=!1,!a())l=!1,d=i;else if(l=!0,o()){let i=s();f??=v().spinner({...t,output:process.stdout,withGuide:!1,frames:t?.frames??(r?[`◒`,`◐`,`◓`,`◑`]:[`-`,`\\`,`|`,`/`]),styleFrame:e=>`${` `.repeat(Math.max(0,4-e.length))}${n.bold(n.brand(e))}`}),f.start(e.length>0?`${i}${e}`:i.trimEnd())}else f=void 0,d=e.length>0?c(`step`,e):i},message(e){l&&(f?f.message(`${s()}${e}`):e.length>0&&d.line(e))},stop(e){p(),e&&c(`success`,e)},error(e){p(),c(`error`,e??t?.errorMessage??`Failed`)},cancel(e){p(),u=!0,c(`warn`,e??t?.cancelMessage??`Cancelled`)},clear:p,get isCancelled(){return u||!!f?.isCancelled},get active(){return l}}}const x={silent:0,error:1,warn:2,info:3,debug:4},S=Object.freeze({line:()=>S}),C={stdout:e=>process.stdout.write(`${e}\n`),stderr:e=>process.stderr.write(`${e}\n`)},w=e=>({step:(t,...n)=>e(`step`,t,...n),info:(t,...n)=>e(`info`,t,...n),success:(t,...n)=>e(`success`,t,...n),warn:(t,...n)=>e(`warn`,t,...n),error:(t,...n)=>e(`error`,t,...n),debug:(t,...n)=>e(`debug`,t,...n)});function T(e,t){let{terminal:n,color:r,theme:i,unicode:a,state:c}=e,l=a?`│`:`|`,f=a?`›`:`>`,p=e=>i.dim(i.muted(e)),m=e=>x[c.level]>=x[e],_=`${o}${p(l)} `;function v(e){return t?e?`${p(`${t} ${f}`)} `:`${i.muted(t)} ${p(f)} `:``}function E(e,n,a,o){let s={line(...l){if(!m(e)||l.length===0)return s;if(c.format===`json`){for(let e of l)n(d({...o,...t?{scope:t}:{},line:e}));return s}for(let e of l)for(let t of h(e,a,i,r,p))n(`${_}${t}`);return s}};return s}function D(e,n,r,i){let a={level:n,message:r};t&&(a.scope=t),i.length===1?a.detail=i[0]:i.length>1&&(a.details=i),e(d(a))}function O(e,t,...a){let o=s[e];if(!m(o.level))return S;let l=e===`debug`,{headline:d,extraLines:f,jsonMessage:h}=g(l,t,a,i,r,p),y=o.stderr?n.stderr:n.stdout,b=E(o.level,y,l,{level:e,message:h});if(c.format===`json`)return D(y,e,h,a),b;y(`${u(o.label,i,o.token,!l)} ${v(l)}${l?p(d):e===`step`||e===`error`?i.bold(d):d}`);for(let e of f)y(`${_}${e}`);return b}function k(e,l,...d){let h=s[e];if(!m(h.level))return;let _=e===`debug`,{headline:v,extraLines:b,jsonMessage:x}=g(_,l,d,i,r,p),S=h.stderr?n.stderr:n.stdout;if(c.format===`json`){D(S,e,x,d);return}let C=b.length>0,w=C?b.join(`
|
|
7
|
+
`):(_?p:i.muted)(v),T=[];t&&T.push(_?p(`${t} ${f}`):`${i.muted(t)} ${p(f)}`),C&&v.length>0&&T.push(_?p(v):i.bold(v));let E=y({body:w,title:T.length>0?` ${T.join(` `)} `:void 0,columns:n.columns??(h.stderr?process.stderr.columns:process.stdout.columns)??80,unicode:a,faint:p}),O=u(h.label,i,h.token,!_);for(let[e,t]of E.entries())S(`${e===0?`${O} `:o}${t}`)}let A=e=>b({options:e,theme:i,unicode:a,noopEntry:S,shouldLogInfo:()=>m(`info`),canAnimate:()=>m(`info`)&&n===C&&!!process.stdout.isTTY&&c.format===`pretty`,formatScope:()=>v(!1),emit:O});return{get level(){return c.level},set level(e){c.level=e},get format(){return c.format},set format(e){c.format=e},scope:t,theme:i,...w(O),box:w(k),raw:(e=``)=>{c.level!==`silent`&&n.stdout(e)},spinner:e=>A(e),async task(e,t,n){let r=A(n);r.start(e);try{let n=await t(r);if(r.active){let t=typeof n==`string`&&n.length>0?n:e.replace(/\.+$/,``);r.stop(t)}return n}catch(e){throw r.active&&(n?.errorMessage===void 0?r.clear():r.error(n.errorMessage)),e}},child:n=>T(e,t?`${t}:${n}`:n)}}function E(r={}){let i=r.terminal??C,a=r.color??i.color??t();return T({terminal:i,color:a,theme:r.theme??e(a),unicode:r.unicode??i.unicode??n(),state:{level:r.level??`info`,format:r.format??`pretty`}},r.scope)}export{o as LOG_GUTTER,a as LOG_LABEL_WIDTH,E as createLogger,l as formatLogLabel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@clack/prompts";
|
package/dist/prompts.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"@clack/prompts";export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/logger",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Minimal CLI logger with aligned word labels.",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./dist/index.mjs",
|
|
27
|
+
"./prompts": "./dist/prompts.mjs",
|
|
27
28
|
"./package.json": "./package.json"
|
|
28
29
|
},
|
|
29
30
|
"types": "./dist/index.d.mts",
|
|
@@ -31,13 +32,13 @@
|
|
|
31
32
|
"dist"
|
|
32
33
|
],
|
|
33
34
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
35
|
+
"node": ">=24"
|
|
35
36
|
},
|
|
36
37
|
"publishConfig": {
|
|
37
38
|
"access": "public"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@clack/prompts": "^1.9.0",
|
|
41
|
-
"@clerc/theme": "2.0.0-beta.
|
|
42
|
+
"@clerc/theme": "2.0.0-beta.2"
|
|
42
43
|
}
|
|
43
44
|
}
|