@sprucelabs/spruce-skill-utils 31.0.655 → 31.1.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.
@@ -10,7 +10,7 @@ export interface LogOptions {
10
10
  }
11
11
  export type Level = 'ERROR' | 'INFO' | 'WARN';
12
12
  export type LogTransport = (...messageParts: string[]) => void;
13
- type TransportMap = Record<Level, LogTransport | null | undefined>;
13
+ type TransportMap = Record<Level, LogTransport | LogTransport[] | null | undefined>;
14
14
  type Anything = string | number | boolean | null | undefined | Error;
15
15
  export type LoggableType = Anything | Anything[] | Record<string, Anything>;
16
16
  export interface Log {
@@ -44,8 +44,15 @@ export default function buildLog(prefix = undefined, options) {
44
44
  },
45
45
  };
46
46
  return logUtil;
47
- function getTransport(level) {
48
- return transports[level];
47
+ function getTransports(level) {
48
+ const t = transports[level];
49
+ if (!t) {
50
+ return [];
51
+ }
52
+ if (!Array.isArray(t)) {
53
+ return [t];
54
+ }
55
+ return t;
49
56
  }
50
57
  function write(chalkMethod, rawArgs, level) {
51
58
  var _a, _b, _c, _d, _e;
@@ -63,9 +70,11 @@ export default function buildLog(prefix = undefined, options) {
63
70
  chalkArgs = [builtPrefix, ...chalkArgs];
64
71
  }
65
72
  const prefix = `${builtPrefix ? ` ${builtPrefix}` : ''}`;
66
- let transport = getTransport(level);
67
- if (transport) {
68
- transport(...[prefix.trim(), ...args].filter((t) => t && t.length > 0));
73
+ let transports = getTransports(level);
74
+ if (transports.length > 0) {
75
+ for (const transport of transports) {
76
+ transport(...[prefix.trim(), ...args].filter((t) => t && t.length > 0));
77
+ }
69
78
  return prefix;
70
79
  }
71
80
  const env = (_b = (_a = getProcess()) === null || _a === void 0 ? void 0 : _a.env) !== null && _b !== void 0 ? _b : {};
@@ -81,13 +90,12 @@ export default function buildLog(prefix = undefined, options) {
81
90
  logMethod = 'log';
82
91
  break;
83
92
  }
84
- transport =
85
- log !== null && log !== void 0 ? log : (level === 'ERROR' && ((_d = (_c = getProcess()) === null || _c === void 0 ? void 0 : _c.stderr) === null || _d === void 0 ? void 0 : _d.write)
86
- ? (...args) => {
87
- var _a;
88
- (_a = getProcess()) === null || _a === void 0 ? void 0 : _a.stderr.write(args.join(' ') + '\n');
89
- }
90
- : ((_e = console[logMethod]) !== null && _e !== void 0 ? _e : console.log).bind(console));
93
+ const transport = log !== null && log !== void 0 ? log : (level === 'ERROR' && ((_d = (_c = getProcess()) === null || _c === void 0 ? void 0 : _c.stderr) === null || _d === void 0 ? void 0 : _d.write)
94
+ ? (...args) => {
95
+ var _a;
96
+ (_a = getProcess()) === null || _a === void 0 ? void 0 : _a.stderr.write(args.join(' ') + '\n');
97
+ }
98
+ : ((_e = console[logMethod]) !== null && _e !== void 0 ? _e : console.log).bind(console));
91
99
  let message = shouldUseColors === false
92
100
  ? `(${level})${prefix}`
93
101
  : chalkMethod(...chalkArgs);
@@ -10,7 +10,7 @@ export interface LogOptions {
10
10
  }
11
11
  export type Level = 'ERROR' | 'INFO' | 'WARN';
12
12
  export type LogTransport = (...messageParts: string[]) => void;
13
- type TransportMap = Record<Level, LogTransport | null | undefined>;
13
+ type TransportMap = Record<Level, LogTransport | LogTransport[] | null | undefined>;
14
14
  type Anything = string | number | boolean | null | undefined | Error;
15
15
  export type LoggableType = Anything | Anything[] | Record<string, Anything>;
16
16
  export interface Log {
@@ -53,8 +53,15 @@ function buildLog(prefix = undefined, options) {
53
53
  },
54
54
  };
55
55
  return logUtil;
56
- function getTransport(level) {
57
- return transports[level];
56
+ function getTransports(level) {
57
+ const t = transports[level];
58
+ if (!t) {
59
+ return [];
60
+ }
61
+ if (!Array.isArray(t)) {
62
+ return [t];
63
+ }
64
+ return t;
58
65
  }
59
66
  function write(chalkMethod, rawArgs, level) {
60
67
  const args = rawArgs.map((a) => a?.toString?.() ?? 'undefined');
@@ -71,9 +78,11 @@ function buildLog(prefix = undefined, options) {
71
78
  chalkArgs = [builtPrefix, ...chalkArgs];
72
79
  }
73
80
  const prefix = `${builtPrefix ? ` ${builtPrefix}` : ''}`;
74
- let transport = getTransport(level);
75
- if (transport) {
76
- transport(...[prefix.trim(), ...args].filter((t) => t && t.length > 0));
81
+ let transports = getTransports(level);
82
+ if (transports.length > 0) {
83
+ for (const transport of transports) {
84
+ transport(...[prefix.trim(), ...args].filter((t) => t && t.length > 0));
85
+ }
77
86
  return prefix;
78
87
  }
79
88
  const env = getProcess()?.env ?? {};
@@ -89,13 +98,12 @@ function buildLog(prefix = undefined, options) {
89
98
  logMethod = 'log';
90
99
  break;
91
100
  }
92
- transport =
93
- log ??
94
- (level === 'ERROR' && getProcess()?.stderr?.write
95
- ? (...args) => {
96
- getProcess()?.stderr.write(args.join(' ') + '\n');
97
- }
98
- : (console[logMethod] ?? console.log).bind(console));
101
+ const transport = log ??
102
+ (level === 'ERROR' && getProcess()?.stderr?.write
103
+ ? (...args) => {
104
+ getProcess()?.stderr.write(args.join(' ') + '\n');
105
+ }
106
+ : (console[logMethod] ?? console.log).bind(console));
99
107
  let message = shouldUseColors === false
100
108
  ? `(${level})${prefix}`
101
109
  : chalkMethod(...chalkArgs);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "31.0.655",
6
+ "version": "31.1.0",
7
7
  "skill": {
8
8
  "namespace": "skill-utils",
9
9
  "upgradeIgnoreList": [
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@sprucelabs/globby": "^2.0.501",
62
- "@sprucelabs/schema": "^30.0.589",
62
+ "@sprucelabs/schema": "^30.0.590",
63
63
  "chalk": "^4.1.2",
64
64
  "dotenv": "^16.4.7",
65
65
  "fs-extra": "^11.2.0",