@node-cli/logger 1.3.2 → 1.3.3

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/dist/Logger.js CHANGED
@@ -76,6 +76,7 @@ export class Logger {
76
76
  }
77
77
  // Still output to console if not in memory-only mode.
78
78
  if (!this.#inMemory) {
79
+ // biome-ignore lint/suspicious/noConsole: logger utility
79
80
  console[type.method](this.#printOptions.colors ? `${type.color(message)}` : message);
80
81
  }
81
82
  }
@@ -158,7 +159,7 @@ export class Logger {
158
159
  this.#globalPrefix = oldPrefix;
159
160
  }
160
161
  }
161
- /* v8 ignore next 48 */ export class Spinner {
162
+ /* v8 ignore start */ export class Spinner {
162
163
  spinner;
163
164
  constructor(options){
164
165
  this.spinner = ora({
@@ -202,6 +203,6 @@ export class Logger {
202
203
  static ERROR = "fail";
203
204
  static WARNING = "warn";
204
205
  static INFO = "info";
205
- }
206
+ } /* v8 ignore stop */
206
207
 
207
208
  //# sourceMappingURL=Logger.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Logger.ts"],"sourcesContent":["import util from \"node:util\";\nimport boxen, { Options as BoxenOptions } from \"boxen\";\nimport kleur from \"kleur\";\nimport ora, { Ora, Options as OraOptions } from \"ora\";\n\nexport type PrintBoxOptions = {\n\tnewLineAfter?: boolean;\n\tnewLineBefore?: boolean;\n} & BoxenOptions;\n\nexport type LoggerOptions = {\n\tboring?: boolean;\n\tsilent?: boolean;\n\tprefix?: string;\n\ttimestamp?: boolean;\n\tinMemory?: boolean;\n};\n\nexport class Logger {\n\t#shouldLog: boolean;\n\t#globalPrefix: string;\n\t#showTimestamp: boolean;\n\t#printOptions: { colors: boolean; compact: boolean; depth: number };\n\t#inMemory: boolean;\n\t#memoryLogs: string[];\n\n\tconstructor({\n\t\tboring = false,\n\t\tsilent = false,\n\t\tprefix = \"\",\n\t\ttimestamp = false,\n\t\tinMemory = false,\n\t} = {}) {\n\t\tthis.#shouldLog = !silent;\n\t\tthis.#globalPrefix = prefix;\n\t\tthis.#showTimestamp = timestamp;\n\t\tthis.#inMemory = inMemory;\n\t\tthis.#memoryLogs = [];\n\n\t\t// When in memory mode, we disable colors.\n\t\tthis.#printOptions = {\n\t\t\tcolors: !boring && !inMemory,\n\t\t\tcompact: false,\n\t\t\tdepth: 5,\n\t\t};\n\t}\n\n\tset silent(flag: boolean) {\n\t\tthis.#shouldLog = !flag;\n\t}\n\n\tset boring(flag: boolean) {\n\t\t// Only set colors if not in memory mode.\n\t\tif (!this.#inMemory) {\n\t\t\tthis.#printOptions.colors = !flag;\n\t\t}\n\t}\n\n\tset prefix(prefix: string) {\n\t\tthis.#globalPrefix = prefix;\n\t}\n\n\tset timestamp(flag: boolean) {\n\t\tthis.#showTimestamp = flag;\n\t}\n\n\tset inMemory(flag: boolean) {\n\t\tthis.#inMemory = flag;\n\t\t// When enabling in-memory mode, disable colors.\n\t\tif (flag) {\n\t\t\tthis.#printOptions.colors = false;\n\t\t}\n\t}\n\n\t/**\n\t * Get the accumulated logs as a string.\n\t * @returns {string} All logs joined by the separator\n\t */\n\tgetMemoryLogs(): string {\n\t\treturn this.#memoryLogs.join(\"\\n\");\n\t}\n\n\t/**\n\t * Clear all accumulated logs from memory.\n\t */\n\tclearMemoryLogs(): void {\n\t\tthis.#memoryLogs = [];\n\t}\n\n\t#_log(\n\t\ttype: { method: string | number; color: (argument0: any) => any },\n\t\t...arguments_: string[]\n\t) {\n\t\tif (this.#shouldLog) {\n\t\t\tlet message: string;\n\t\t\tif (!this.#showTimestamp && !this.#globalPrefix) {\n\t\t\t\tmessage = util.formatWithOptions(this.#printOptions, ...arguments_);\n\t\t\t} else {\n\t\t\t\tconst prefix = this.#globalPrefix ? [this.#globalPrefix] : [];\n\t\t\t\tif (this.#showTimestamp) {\n\t\t\t\t\tconst now = new Date();\n\t\t\t\t\tprefix.push(\n\t\t\t\t\t\tthis.#printOptions.colors\n\t\t\t\t\t\t\t? `${kleur.grey(\n\t\t\t\t\t\t\t\t\t`[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`,\n\t\t\t\t\t\t\t\t)}`\n\t\t\t\t\t\t\t: `[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tmessage = util.formatWithOptions(\n\t\t\t\t\tthis.#printOptions,\n\t\t\t\t\tprefix.join(\" \"),\n\t\t\t\t\t...arguments_,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Store in memory if enabled.\n\t\t\tif (this.#inMemory) {\n\t\t\t\tthis.#memoryLogs.push(message);\n\t\t\t}\n\n\t\t\t// Still output to console if not in memory-only mode.\n\t\t\tif (!this.#inMemory) {\n\t\t\t\tconsole[type.method](\n\t\t\t\t\tthis.#printOptions.colors ? `${type.color(message)}` : message,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tinfo(...arguments_: any) {\n\t\tthis.#_log({ method: \"info\", color: kleur.blue }, ...arguments_);\n\t}\n\n\tlog(...arguments_: any) {\n\t\tthis.#_log({ method: \"log\", color: kleur.white }, ...arguments_);\n\t}\n\n\tdebug(...arguments_: any) {\n\t\tthis.#_log({ method: \"debug\", color: kleur.grey }, ...arguments_);\n\t}\n\n\twarn(...arguments_: any) {\n\t\tthis.#_log({ method: \"warn\", color: kleur.yellow }, ...arguments_);\n\t}\n\n\terror(...arguments_: any) {\n\t\tthis.#_log({ method: \"error\", color: kleur.red }, ...arguments_);\n\t}\n\n\t/**\n\t * Log multiple error messages at the prompt using `console.error` behind the\n\t * scenes.\n\t * @param {string[]} errorMessages array of error message to display line by line\n\t * @param {number} [exitStatus] the process will exit with this value if provided\n\t */\n\tprintErrorsAndExit(errorMessages: string[], exitStatus?: number) {\n\t\tif (errorMessages && errorMessages.length > 0) {\n\t\t\tthis.log();\n\t\t\tfor (const message of errorMessages) {\n\t\t\t\tthis.error(message);\n\t\t\t}\n\t\t\tthis.log();\n\n\t\t\tif (typeof exitStatus === \"number\") {\n\t\t\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\t\t\tprocess.exit(exitStatus);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Print sets of logs in a box (wrapper to Boxen).\n\t * @param messages Messages to print\n\t * @param options\n\t */\n\tprintBox(messages: string | string[], options: PrintBoxOptions = {}) {\n\t\tconst { newLineAfter, newLineBefore } = {\n\t\t\tnewLineAfter: true,\n\t\t\tnewLineBefore: true,\n\t\t\t...options,\n\t\t};\n\n\t\t/**\n\t\t * Setting some sensible Boxen options if not provided by the user.\n\t\t */\n\t\tconst borderColor = options.borderColor || \"yellow\";\n\t\tconst boxenOptions: BoxenOptions = {\n\t\t\t...options,\n\t\t\tborderColor: this.#printOptions.colors ? borderColor : \"white\",\n\t\t\tpadding: typeof options.padding === \"number\" ? options.padding : 1,\n\t\t\ttextAlignment: options.textAlignment || \"center\",\n\t\t};\n\n\t\tconst oldPrefix = this.#globalPrefix;\n\t\tconst oldTimestamp = this.#showTimestamp;\n\n\t\tthis.#globalPrefix = \"\";\n\t\tthis.#showTimestamp = false;\n\n\t\tnewLineBefore && this.log();\n\t\tthis.log(\n\t\t\tboxen(\n\t\t\t\ttypeof messages === \"string\" ? messages : messages.join(\"\\n\"),\n\t\t\t\tboxenOptions,\n\t\t\t),\n\t\t);\n\t\tnewLineAfter && this.log();\n\n\t\tthis.#showTimestamp = oldTimestamp;\n\t\tthis.#globalPrefix = oldPrefix;\n\t}\n}\n\n/* v8 ignore next 48 */\nexport class Spinner {\n\tspinner: Ora;\n\n\tconstructor(options?: OraOptions) {\n\t\tthis.spinner = ora({\n\t\t\t...options,\n\t\t\tisSilent: process.env.NODE_ENV === \"test\",\n\t\t});\n\t}\n\n\tset text(message: string) {\n\t\tthis.spinner.text = message;\n\t}\n\n\tstart(message?: string) {\n\t\tthis.spinner.start(message);\n\t}\n\n\tstop(message?: string, type?: string) {\n\t\tswitch (type) {\n\t\t\tcase Spinner.ERROR: {\n\t\t\t\tthis.spinner.fail(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Spinner.WARNING: {\n\t\t\t\tthis.spinner.warn(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Spinner.INFO: {\n\t\t\t\tthis.spinner.info(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis.spinner.succeed(message);\n\t\t\t\t}, 1000);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic SUCCESS = \"success\";\n\tstatic ERROR = \"fail\";\n\tstatic WARNING = \"warn\";\n\tstatic INFO = \"info\";\n}\n"],"names":["util","boxen","kleur","ora","Logger","boring","silent","prefix","timestamp","inMemory","colors","compact","depth","flag","getMemoryLogs","join","clearMemoryLogs","type","arguments_","message","formatWithOptions","now","Date","push","grey","toDateString","toLocaleTimeString","console","method","color","info","blue","log","white","debug","warn","yellow","error","red","printErrorsAndExit","errorMessages","exitStatus","length","process","exit","printBox","messages","options","newLineAfter","newLineBefore","borderColor","boxenOptions","padding","textAlignment","oldPrefix","oldTimestamp","Spinner","spinner","isSilent","env","NODE_ENV","text","start","stop","ERROR","fail","WARNING","INFO","setTimeout","succeed","SUCCESS"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAC7B,OAAOC,WAAwC,QAAQ;AACvD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,SAAyC,MAAM;AAetD,OAAO,MAAMC;IACZ,CAAA,SAAU,CAAU;IACpB,CAAA,YAAa,CAAS;IACtB,CAAA,aAAc,CAAU;IACxB,CAAA,YAAa,CAAuD;IACpE,CAAA,QAAS,CAAU;IACnB,CAAA,UAAW,CAAW;IAEtB,YAAY,EACXC,SAAS,KAAK,EACdC,SAAS,KAAK,EACdC,SAAS,EAAE,EACXC,YAAY,KAAK,EACjBC,WAAW,KAAK,EAChB,GAAG,CAAC,CAAC,CAAE;QACP,IAAI,CAAC,CAAA,SAAU,GAAG,CAACH;QACnB,IAAI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util from \"node:util\";\nimport boxen, { Options as BoxenOptions } from \"boxen\";\nimport kleur from \"kleur\";\nimport ora, { Ora, Options as OraOptions } from \"ora\";\n\nexport type PrintBoxOptions = {\n\tnewLineAfter?: boolean;\n\tnewLineBefore?: boolean;\n} & BoxenOptions;\n\nexport type LoggerOptions = {\n\tboring?: boolean;\n\tsilent?: boolean;\n\tprefix?: string;\n\ttimestamp?: boolean;\n\tinMemory?: boolean;\n};\n\nexport class Logger {\n\t#shouldLog: boolean;\n\t#globalPrefix: string;\n\t#showTimestamp: boolean;\n\t#printOptions: { colors: boolean; compact: boolean; depth: number };\n\t#inMemory: boolean;\n\t#memoryLogs: string[];\n\n\tconstructor({\n\t\tboring = false,\n\t\tsilent = false,\n\t\tprefix = \"\",\n\t\ttimestamp = false,\n\t\tinMemory = false,\n\t} = {}) {\n\t\tthis.#shouldLog = !silent;\n\t\tthis.#globalPrefix = prefix;\n\t\tthis.#showTimestamp = timestamp;\n\t\tthis.#inMemory = inMemory;\n\t\tthis.#memoryLogs = [];\n\n\t\t// When in memory mode, we disable colors.\n\t\tthis.#printOptions = {\n\t\t\tcolors: !boring && !inMemory,\n\t\t\tcompact: false,\n\t\t\tdepth: 5,\n\t\t};\n\t}\n\n\tset silent(flag: boolean) {\n\t\tthis.#shouldLog = !flag;\n\t}\n\n\tset boring(flag: boolean) {\n\t\t// Only set colors if not in memory mode.\n\t\tif (!this.#inMemory) {\n\t\t\tthis.#printOptions.colors = !flag;\n\t\t}\n\t}\n\n\tset prefix(prefix: string) {\n\t\tthis.#globalPrefix = prefix;\n\t}\n\n\tset timestamp(flag: boolean) {\n\t\tthis.#showTimestamp = flag;\n\t}\n\n\tset inMemory(flag: boolean) {\n\t\tthis.#inMemory = flag;\n\t\t// When enabling in-memory mode, disable colors.\n\t\tif (flag) {\n\t\t\tthis.#printOptions.colors = false;\n\t\t}\n\t}\n\n\t/**\n\t * Get the accumulated logs as a string.\n\t * @returns {string} All logs joined by the separator\n\t */\n\tgetMemoryLogs(): string {\n\t\treturn this.#memoryLogs.join(\"\\n\");\n\t}\n\n\t/**\n\t * Clear all accumulated logs from memory.\n\t */\n\tclearMemoryLogs(): void {\n\t\tthis.#memoryLogs = [];\n\t}\n\n\t#_log(\n\t\ttype: { method: string | number; color: (argument0: any) => any },\n\t\t...arguments_: string[]\n\t) {\n\t\tif (this.#shouldLog) {\n\t\t\tlet message: string;\n\t\t\tif (!this.#showTimestamp && !this.#globalPrefix) {\n\t\t\t\tmessage = util.formatWithOptions(this.#printOptions, ...arguments_);\n\t\t\t} else {\n\t\t\t\tconst prefix = this.#globalPrefix ? [this.#globalPrefix] : [];\n\t\t\t\tif (this.#showTimestamp) {\n\t\t\t\t\tconst now = new Date();\n\t\t\t\t\tprefix.push(\n\t\t\t\t\t\tthis.#printOptions.colors\n\t\t\t\t\t\t\t? `${kleur.grey(\n\t\t\t\t\t\t\t\t\t`[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`,\n\t\t\t\t\t\t\t\t)}`\n\t\t\t\t\t\t\t: `[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tmessage = util.formatWithOptions(\n\t\t\t\t\tthis.#printOptions,\n\t\t\t\t\tprefix.join(\" \"),\n\t\t\t\t\t...arguments_,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Store in memory if enabled.\n\t\t\tif (this.#inMemory) {\n\t\t\t\tthis.#memoryLogs.push(message);\n\t\t\t}\n\n\t\t\t// Still output to console if not in memory-only mode.\n\t\t\tif (!this.#inMemory) {\n\t\t\t\t// biome-ignore lint/suspicious/noConsole: logger utility\n\t\t\t\tconsole[type.method](\n\t\t\t\t\tthis.#printOptions.colors ? `${type.color(message)}` : message,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tinfo(...arguments_: any) {\n\t\tthis.#_log({ method: \"info\", color: kleur.blue }, ...arguments_);\n\t}\n\n\tlog(...arguments_: any) {\n\t\tthis.#_log({ method: \"log\", color: kleur.white }, ...arguments_);\n\t}\n\n\tdebug(...arguments_: any) {\n\t\tthis.#_log({ method: \"debug\", color: kleur.grey }, ...arguments_);\n\t}\n\n\twarn(...arguments_: any) {\n\t\tthis.#_log({ method: \"warn\", color: kleur.yellow }, ...arguments_);\n\t}\n\n\terror(...arguments_: any) {\n\t\tthis.#_log({ method: \"error\", color: kleur.red }, ...arguments_);\n\t}\n\n\t/**\n\t * Log multiple error messages at the prompt using `console.error` behind the\n\t * scenes.\n\t * @param {string[]} errorMessages array of error message to display line by line\n\t * @param {number} [exitStatus] the process will exit with this value if provided\n\t */\n\tprintErrorsAndExit(errorMessages: string[], exitStatus?: number) {\n\t\tif (errorMessages && errorMessages.length > 0) {\n\t\t\tthis.log();\n\t\t\tfor (const message of errorMessages) {\n\t\t\t\tthis.error(message);\n\t\t\t}\n\t\t\tthis.log();\n\n\t\t\tif (typeof exitStatus === \"number\") {\n\t\t\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\t\t\tprocess.exit(exitStatus);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Print sets of logs in a box (wrapper to Boxen).\n\t * @param messages Messages to print\n\t * @param options\n\t */\n\tprintBox(messages: string | string[], options: PrintBoxOptions = {}) {\n\t\tconst { newLineAfter, newLineBefore } = {\n\t\t\tnewLineAfter: true,\n\t\t\tnewLineBefore: true,\n\t\t\t...options,\n\t\t};\n\n\t\t/**\n\t\t * Setting some sensible Boxen options if not provided by the user.\n\t\t */\n\t\tconst borderColor = options.borderColor || \"yellow\";\n\t\tconst boxenOptions: BoxenOptions = {\n\t\t\t...options,\n\t\t\tborderColor: this.#printOptions.colors ? borderColor : \"white\",\n\t\t\tpadding: typeof options.padding === \"number\" ? options.padding : 1,\n\t\t\ttextAlignment: options.textAlignment || \"center\",\n\t\t};\n\n\t\tconst oldPrefix = this.#globalPrefix;\n\t\tconst oldTimestamp = this.#showTimestamp;\n\n\t\tthis.#globalPrefix = \"\";\n\t\tthis.#showTimestamp = false;\n\n\t\tnewLineBefore && this.log();\n\t\tthis.log(\n\t\t\tboxen(\n\t\t\t\ttypeof messages === \"string\" ? messages : messages.join(\"\\n\"),\n\t\t\t\tboxenOptions,\n\t\t\t),\n\t\t);\n\t\tnewLineAfter && this.log();\n\n\t\tthis.#showTimestamp = oldTimestamp;\n\t\tthis.#globalPrefix = oldPrefix;\n\t}\n}\n\n/* v8 ignore start */\nexport class Spinner {\n\tspinner: Ora;\n\n\tconstructor(options?: OraOptions) {\n\t\tthis.spinner = ora({\n\t\t\t...options,\n\t\t\tisSilent: process.env.NODE_ENV === \"test\",\n\t\t});\n\t}\n\n\tset text(message: string) {\n\t\tthis.spinner.text = message;\n\t}\n\n\tstart(message?: string) {\n\t\tthis.spinner.start(message);\n\t}\n\n\tstop(message?: string, type?: string) {\n\t\tswitch (type) {\n\t\t\tcase Spinner.ERROR: {\n\t\t\t\tthis.spinner.fail(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Spinner.WARNING: {\n\t\t\t\tthis.spinner.warn(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Spinner.INFO: {\n\t\t\t\tthis.spinner.info(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis.spinner.succeed(message);\n\t\t\t\t}, 1000);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic SUCCESS = \"success\";\n\tstatic ERROR = \"fail\";\n\tstatic WARNING = \"warn\";\n\tstatic INFO = \"info\";\n}\n/* v8 ignore stop */\n"],"names":["util","boxen","kleur","ora","Logger","boring","silent","prefix","timestamp","inMemory","colors","compact","depth","flag","getMemoryLogs","join","clearMemoryLogs","type","arguments_","message","formatWithOptions","now","Date","push","grey","toDateString","toLocaleTimeString","console","method","color","info","blue","log","white","debug","warn","yellow","error","red","printErrorsAndExit","errorMessages","exitStatus","length","process","exit","printBox","messages","options","newLineAfter","newLineBefore","borderColor","boxenOptions","padding","textAlignment","oldPrefix","oldTimestamp","Spinner","spinner","isSilent","env","NODE_ENV","text","start","stop","ERROR","fail","WARNING","INFO","setTimeout","succeed","SUCCESS"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAC7B,OAAOC,WAAwC,QAAQ;AACvD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,SAAyC,MAAM;AAetD,OAAO,MAAMC;IACZ,CAAA,SAAU,CAAU;IACpB,CAAA,YAAa,CAAS;IACtB,CAAA,aAAc,CAAU;IACxB,CAAA,YAAa,CAAuD;IACpE,CAAA,QAAS,CAAU;IACnB,CAAA,UAAW,CAAW;IAEtB,YAAY,EACXC,SAAS,KAAK,EACdC,SAAS,KAAK,EACdC,SAAS,EAAE,EACXC,YAAY,KAAK,EACjBC,WAAW,KAAK,EAChB,GAAG,CAAC,CAAC,CAAE;QACP,IAAI,CAAC,CAAA,SAAU,GAAG,CAACH;QACnB,IAAI,CAAC,CAAA,YAAa,GAAGC;QACrB,IAAI,CAAC,CAAA,aAAc,GAAGC;QACtB,IAAI,CAAC,CAAA,QAAS,GAAGC;QACjB,IAAI,CAAC,CAAA,UAAW,GAAG,EAAE;QAErB,0CAA0C;QAC1C,IAAI,CAAC,CAAA,YAAa,GAAG;YACpBC,QAAQ,CAACL,UAAU,CAACI;YACpBE,SAAS;YACTC,OAAO;QACR;IACD;IAEA,IAAIN,OAAOO,IAAa,EAAE;QACzB,IAAI,CAAC,CAAA,SAAU,GAAG,CAACA;IACpB;IAEA,IAAIR,OAAOQ,IAAa,EAAE;QACzB,yCAAyC;QACzC,IAAI,CAAC,IAAI,CAAC,CAAA,QAAS,EAAE;YACpB,IAAI,CAAC,CAAA,YAAa,CAACH,MAAM,GAAG,CAACG;QAC9B;IACD;IAEA,IAAIN,OAAOA,MAAc,EAAE;QAC1B,IAAI,CAAC,CAAA,YAAa,GAAGA;IACtB;IAEA,IAAIC,UAAUK,IAAa,EAAE;QAC5B,IAAI,CAAC,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K,CAAC3C;IACpB;IAEA4C,KAAK5C,OAAgB,EAAEF,IAAa,EAAE;QACrC,OAAQA;YACP,KAAKuC,QAAQQ,KAAK;gBAAE;oBACnB,IAAI,CAACP,OAAO,CAACQ,IAAI,CAAC9C;oBAClB;gBACD;YACA,KAAKqC,QAAQU,OAAO;gBAAE;oBACrB,IAAI,CAACT,OAAO,CAACtB,IAAI,CAAChB;oBAClB;gBACD;YACA,KAAKqC,QAAQW,IAAI;gBAAE;oBAClB,IAAI,CAACV,OAAO,CAAC3B,IAAI,CAACX;oBAClB;gBACD;YACA;gBAAS;oBACRiD,WAAW;wBACV,IAAI,CAACX,OAAO,CAACY,OAAO,CAAClD;oBACtB,GAAG;oBACH;gBACD;QACD;IACD;IAEA,OAAOmD,UAAU,UAAU;IAC3B,OAAON,QAAQ,OAAO;IACtB,OAAOE,UAAU,OAAO;IACxB,OAAOC,OAAO,OAAO;AACtB,EACA,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/logger",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "A tiny console logger for nodejs CLI apps",
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "boxen": "8.0.1",
16
16
  "kleur": "4.1.5",
17
- "ora": "8.2.0"
17
+ "ora": "9.0.0"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "npm-run-all --serial clean build:types build:js build:barrel",
@@ -34,9 +34,9 @@
34
34
  "access": "public"
35
35
  },
36
36
  "devDependencies": {
37
- "@node-cli/comments": "0.2.0",
38
- "@vitest/coverage-v8": "3.2.4",
39
- "vitest": "3.2.4"
37
+ "@node-cli/comments": "0.2.7",
38
+ "@vitest/coverage-v8": "4.0.16",
39
+ "vitest": "4.0.16"
40
40
  },
41
- "gitHead": "d90392dcb766dd605bc3eeabc7c7a7ab0c8e6da6"
41
+ "gitHead": "096003826471508d839f2ec3346bb12b1a73b7fe"
42
42
  }