@sprucelabs/spruce-skill-utils 33.1.0 → 33.3.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.
@@ -7,11 +7,17 @@ export declare class Logger implements Log {
7
7
  private readonly colors;
8
8
  private readonly pre;
9
9
  private readonly shouldUseColors;
10
+ private static history;
11
+ private static historyLimit;
10
12
  constructor(prefix?: string | undefined, options?: LogOptions);
13
+ static startTrackingHistory(limit: number): void;
11
14
  info(...args: LoggableType[]): string;
12
15
  warn(...args: LoggableType[]): string;
13
16
  error(...args: LoggableType[]): string;
14
17
  buildLog(prefix?: string | undefined, options?: LogOptions): Log;
18
+ private get history();
19
+ private get historyLimit();
20
+ static getHistory(): string[];
15
21
  private write;
16
22
  private shouldLog;
17
23
  private resolveChalk;
@@ -17,6 +17,9 @@ export class Logger {
17
17
  const isInteractive = (_c = (_b = (_a = getProcess()) === null || _a === void 0 ? void 0 : _a.stdout) === null || _b === void 0 ? void 0 : _b.isTTY) !== null && _c !== void 0 ? _c : false;
18
18
  this.shouldUseColors = useColors !== false && isInteractive;
19
19
  }
20
+ static startTrackingHistory(limit) {
21
+ this.historyLimit = limit;
22
+ }
20
23
  info(...args) {
21
24
  return this.write(this.resolveChalk('green', this.colors.info), args, 'INFO');
22
25
  }
@@ -30,6 +33,15 @@ export class Logger {
30
33
  const childPrefix = this.combinePrefixes(prefix);
31
34
  return new Logger(childPrefix, Object.assign({ log: this.baseLog, useColors: this.useColorsOption, transportsByLevel: this.transports }, options));
32
35
  }
36
+ get history() {
37
+ return Logger.history;
38
+ }
39
+ get historyLimit() {
40
+ return Logger.historyLimit;
41
+ }
42
+ static getHistory() {
43
+ return this.history;
44
+ }
33
45
  write(chalkMethod, rawArgs, level) {
34
46
  if (!this.shouldWrite(level)) {
35
47
  return '';
@@ -37,10 +49,17 @@ export class Logger {
37
49
  const shouldLog = this.shouldLog();
38
50
  const formattedArgs = this.formatArgs(rawArgs);
39
51
  const { prefix, logArgs: logArgs } = this.buildPrefixes(formattedArgs);
52
+ const joined = rawArgs.join(' ');
53
+ const flattened = prefix ? prefix + ' ' + joined : joined;
54
+ if (this.historyLimit > 0) {
55
+ this.history.push(flattened);
56
+ if (this.history.length > this.historyLimit) {
57
+ this.history.shift();
58
+ }
59
+ }
40
60
  if (!shouldLog ||
41
61
  this.dispatchToTransports(level, prefix, formattedArgs)) {
42
- const joined = rawArgs.join(' ');
43
- return prefix ? prefix + ' ' + joined : joined;
62
+ return flattened;
44
63
  }
45
64
  const transport = this.resolveTransport(level, this.resolveConsoleMethod(level));
46
65
  const message = this.buildMessage(chalkMethod, logArgs, level, prefix);
@@ -220,6 +239,8 @@ export class Logger {
220
239
  return true;
221
240
  }
222
241
  }
242
+ Logger.history = [];
243
+ Logger.historyLimit = 0;
223
244
  export default function buildLog(prefix = undefined, options) {
224
245
  return new Logger(prefix, options);
225
246
  }
@@ -7,11 +7,17 @@ export declare class Logger implements Log {
7
7
  private readonly colors;
8
8
  private readonly pre;
9
9
  private readonly shouldUseColors;
10
+ private static history;
11
+ private static historyLimit;
10
12
  constructor(prefix?: string | undefined, options?: LogOptions);
13
+ static startTrackingHistory(limit: number): void;
11
14
  info(...args: LoggableType[]): string;
12
15
  warn(...args: LoggableType[]): string;
13
16
  error(...args: LoggableType[]): string;
14
17
  buildLog(prefix?: string | undefined, options?: LogOptions): Log;
18
+ private get history();
19
+ private get historyLimit();
20
+ static getHistory(): string[];
15
21
  private write;
16
22
  private shouldLog;
17
23
  private resolveChalk;
@@ -23,6 +23,9 @@ class Logger {
23
23
  const isInteractive = getProcess()?.stdout?.isTTY ?? false;
24
24
  this.shouldUseColors = useColors !== false && isInteractive;
25
25
  }
26
+ static startTrackingHistory(limit) {
27
+ this.historyLimit = limit;
28
+ }
26
29
  info(...args) {
27
30
  return this.write(this.resolveChalk('green', this.colors.info), args, 'INFO');
28
31
  }
@@ -41,6 +44,15 @@ class Logger {
41
44
  ...options,
42
45
  });
43
46
  }
47
+ get history() {
48
+ return Logger.history;
49
+ }
50
+ get historyLimit() {
51
+ return Logger.historyLimit;
52
+ }
53
+ static getHistory() {
54
+ return this.history;
55
+ }
44
56
  write(chalkMethod, rawArgs, level) {
45
57
  if (!this.shouldWrite(level)) {
46
58
  return '';
@@ -48,10 +60,17 @@ class Logger {
48
60
  const shouldLog = this.shouldLog();
49
61
  const formattedArgs = this.formatArgs(rawArgs);
50
62
  const { prefix, logArgs: logArgs } = this.buildPrefixes(formattedArgs);
63
+ const joined = rawArgs.join(' ');
64
+ const flattened = prefix ? prefix + ' ' + joined : joined;
65
+ if (this.historyLimit > 0) {
66
+ this.history.push(flattened);
67
+ if (this.history.length > this.historyLimit) {
68
+ this.history.shift();
69
+ }
70
+ }
51
71
  if (!shouldLog ||
52
72
  this.dispatchToTransports(level, prefix, formattedArgs)) {
53
- const joined = rawArgs.join(' ');
54
- return prefix ? prefix + ' ' + joined : joined;
73
+ return flattened;
55
74
  }
56
75
  const transport = this.resolveTransport(level, this.resolveConsoleMethod(level));
57
76
  const message = this.buildMessage(chalkMethod, logArgs, level, prefix);
@@ -228,6 +247,8 @@ class Logger {
228
247
  }
229
248
  }
230
249
  exports.Logger = Logger;
250
+ Logger.history = [];
251
+ Logger.historyLimit = 0;
231
252
  function buildLog(prefix = undefined, options) {
232
253
  return new Logger(prefix, options);
233
254
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "33.1.0",
6
+ "version": "33.3.0",
7
7
  "skill": {
8
8
  "namespace": "skill-utils",
9
9
  "upgradeIgnoreList": [
@@ -19,6 +19,18 @@
19
19
  "types": "./build/index.d.ts",
20
20
  "module": "./build/esm/index.js",
21
21
  "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "import": {
25
+ "types": "./build/esm/index.d.ts",
26
+ "default": "./build/esm/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./build/index.d.ts",
30
+ "default": "./build/index.js"
31
+ }
32
+ }
33
+ },
22
34
  "license": "MIT",
23
35
  "description": "Loosely coupled classes and functions to make skill development faster! 🏎",
24
36
  "keywords": [