@bamboocss/logger 1.11.1 → 1.11.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/dist/index.cjs ADDED
@@ -0,0 +1,238 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let kleur = require("kleur");
25
+ kleur = __toESM(kleur);
26
+ //#region ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
27
+ function escapeStringRegexp(string) {
28
+ if (typeof string !== "string") throw new TypeError("Expected a string");
29
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
30
+ }
31
+ //#endregion
32
+ //#region ../../node_modules/.pnpm/matcher@6.0.0/node_modules/matcher/index.js
33
+ const regexpCache = /* @__PURE__ */ new Map();
34
+ const sanitizeArray = (input, inputName) => {
35
+ if (!Array.isArray(input)) switch (typeof input) {
36
+ case "string":
37
+ input = [input];
38
+ break;
39
+ case "undefined":
40
+ input = [];
41
+ break;
42
+ default: throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
43
+ }
44
+ return input.filter((string) => {
45
+ if (typeof string !== "string") {
46
+ if (string === void 0) return false;
47
+ throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
48
+ }
49
+ return true;
50
+ });
51
+ };
52
+ const makeRegexp = (pattern, options) => {
53
+ options = {
54
+ caseSensitive: false,
55
+ ...options
56
+ };
57
+ const flags = "s" + (options.caseSensitive ? "" : "i");
58
+ const cacheKey = pattern + "|" + flags;
59
+ if (regexpCache.has(cacheKey)) return regexpCache.get(cacheKey);
60
+ const negated = pattern[0] === "!";
61
+ if (negated) pattern = pattern.slice(1);
62
+ pattern = pattern.replaceAll(String.raw`\*`, "__ESCAPED_STAR__").replaceAll("\\\\", "__ESCAPED_BACKSLASH__").replaceAll(/\\(.)/g, "$1");
63
+ pattern = escapeStringRegexp(pattern).replaceAll(String.raw`\*`, ".*");
64
+ pattern = pattern.replaceAll("__ESCAPED_STAR__", String.raw`\*`).replaceAll("__ESCAPED_BACKSLASH__", "\\\\");
65
+ const regexp = new RegExp(`^${pattern}$`, flags);
66
+ regexp.negated = negated;
67
+ regexpCache.set(cacheKey, regexp);
68
+ return regexp;
69
+ };
70
+ const baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
71
+ inputs = sanitizeArray(inputs, "inputs");
72
+ patterns = sanitizeArray(patterns, "patterns");
73
+ if (patterns.length === 0) return [];
74
+ patterns = patterns.map((pattern) => makeRegexp(pattern, options));
75
+ const negatedPatterns = patterns.filter((pattern) => pattern.negated);
76
+ const positivePatterns = patterns.filter((pattern) => !pattern.negated);
77
+ const { allPatterns } = options || {};
78
+ const result = [];
79
+ if (allPatterns && firstMatchOnly && negatedPatterns.length > 1 && positivePatterns.length === 0) {
80
+ for (const input of inputs) for (const pattern of negatedPatterns) if (pattern.test(input)) return [];
81
+ return inputs.slice(0, 1);
82
+ }
83
+ for (const input of inputs) {
84
+ let excludedByNegation = false;
85
+ for (const pattern of negatedPatterns) if (pattern.test(input)) {
86
+ excludedByNegation = true;
87
+ break;
88
+ }
89
+ if (excludedByNegation) continue;
90
+ if (positivePatterns.length === 0) result.push(input);
91
+ else if (allPatterns) {
92
+ const matchedPositive = Array.from({ length: positivePatterns.length }, () => false);
93
+ for (const [index, pattern] of positivePatterns.entries()) if (pattern.test(input)) matchedPositive[index] = true;
94
+ if (matchedPositive.every(Boolean)) result.push(input);
95
+ } else {
96
+ let matchedAny = false;
97
+ for (const pattern of positivePatterns) if (pattern.test(input)) {
98
+ matchedAny = true;
99
+ break;
100
+ }
101
+ if (matchedAny) result.push(input);
102
+ }
103
+ if (firstMatchOnly && result.length > 0) break;
104
+ }
105
+ return result;
106
+ };
107
+ function isMatch(inputs, patterns, options) {
108
+ return baseMatcher(inputs, patterns, options, true).length > 0;
109
+ }
110
+ //#endregion
111
+ //#region src/create-logger.ts
112
+ const createLogger = (conf = {}) => {
113
+ let onLog = conf.onLog;
114
+ let level = conf.isDebug ? "debug" : conf.level ?? "info";
115
+ const filter = conf.filter !== "*" ? conf.filter?.split(/[\s,]+/) ?? [] : [];
116
+ const getLevel = () => filter.length ? "debug" : level;
117
+ const isValid = (level, type) => {
118
+ const badLevel = logLevels[getLevel()].weight > logLevels[level].weight;
119
+ return !(filter.length > 0 && !matches(filter, type) || badLevel);
120
+ };
121
+ const stdout = (level) => (type, data) => {
122
+ const entry = createEntry(level, type, data);
123
+ if (level != null && isValid(level, type)) {
124
+ const logEntry = formatEntry(entry) ?? {};
125
+ console.log(logEntry.label, logEntry.msg);
126
+ } else if (getLevel() !== "silent" && level == null) console.log(...[type, data].filter(Boolean));
127
+ onLog?.(entry);
128
+ };
129
+ const logFns = {
130
+ debug: stdout("debug"),
131
+ info: stdout("info"),
132
+ warn: stdout("warn"),
133
+ error: stdout("error")
134
+ };
135
+ const timing = (level) => (msg) => {
136
+ const start = performance.now();
137
+ return (_msg = msg) => {
138
+ const ms = performance.now() - start;
139
+ logFns[level]("hrtime", `${_msg} ${kleur.default.gray(`(${ms.toFixed(2)}ms)`)}`);
140
+ };
141
+ };
142
+ const caughtError = (type, context, error) => {
143
+ const message = error instanceof Error ? error.message : String(error);
144
+ logFns.error(type, `${context}: ${message}`);
145
+ if (error instanceof Error && error.stack) logFns.debug(type, error.stack);
146
+ };
147
+ return {
148
+ get level() {
149
+ return level;
150
+ },
151
+ set level(newLevel) {
152
+ level = newLevel;
153
+ },
154
+ set onLog(fn) {
155
+ onLog = fn;
156
+ },
157
+ ...logFns,
158
+ caughtError,
159
+ print(data) {
160
+ console.dir(data, {
161
+ depth: null,
162
+ colors: true
163
+ });
164
+ },
165
+ log: (data) => stdout(null)("", data),
166
+ time: {
167
+ info: timing("info"),
168
+ debug: timing("debug")
169
+ },
170
+ isDebug: Boolean(conf.isDebug)
171
+ };
172
+ };
173
+ const matches = (filters, value) => filters.some((search) => isMatch(value, search));
174
+ const createEntry = (level, type, data) => {
175
+ const msg = data instanceof Error ? kleur.default.red(data.stack ?? data.message) : data;
176
+ return {
177
+ t: (/* @__PURE__ */ new Date()).toISOString(),
178
+ type,
179
+ level,
180
+ msg
181
+ };
182
+ };
183
+ const formatEntry = (entry) => {
184
+ const uword = entry.type ? kleur.default.gray(`[${entry.type}]`) : "";
185
+ let label = "";
186
+ let msg = "";
187
+ if (entry.level != null) {
188
+ const { msg: message, level } = entry;
189
+ const color = logLevels[level].color;
190
+ label = [
191
+ `🐼`,
192
+ kleur.default.bold(color(`${level}`)),
193
+ uword
194
+ ].filter(Boolean).join(" ");
195
+ msg = message;
196
+ } else {
197
+ label = uword ?? "";
198
+ msg = entry.msg;
199
+ }
200
+ return {
201
+ label,
202
+ msg
203
+ };
204
+ };
205
+ const logLevels = {
206
+ debug: {
207
+ weight: 0,
208
+ color: kleur.default.magenta
209
+ },
210
+ info: {
211
+ weight: 1,
212
+ color: kleur.default.blue
213
+ },
214
+ warn: {
215
+ weight: 2,
216
+ color: kleur.default.yellow
217
+ },
218
+ error: {
219
+ weight: 3,
220
+ color: kleur.default.red
221
+ },
222
+ silent: {
223
+ weight: 4,
224
+ color: kleur.default.white
225
+ }
226
+ };
227
+ //#endregion
228
+ //#region src/index.ts
229
+ const quote = (...str) => kleur.default.cyan(`\`${str.join("")}\``);
230
+ const debug = typeof process !== "undefined" ? process.env.BAMBOO_DEBUG : void 0;
231
+ const logger = createLogger({
232
+ filter: typeof process !== "undefined" ? debug : void 0,
233
+ isDebug: Boolean(debug)
234
+ });
235
+ //#endregion
236
+ exports.colors = kleur.default;
237
+ exports.logger = logger;
238
+ exports.quote = quote;
@@ -0,0 +1,16 @@
1
+ import colors from "kleur";
2
+ import { LogEntry, LogLevel } from "@bamboocss/types";
3
+
4
+ //#region src/create-logger.d.ts
5
+ interface LoggerConfig {
6
+ level?: LogLevel;
7
+ filter?: string;
8
+ isDebug?: boolean;
9
+ onLog?: (entry: LogEntry) => void;
10
+ }
11
+ //#endregion
12
+ //#region src/index.d.ts
13
+ declare const quote: (...str: string[]) => string;
14
+ declare const logger: import("@bamboocss/types").LoggerInterface;
15
+ //#endregion
16
+ export { type LoggerConfig, colors, logger, quote };
@@ -0,0 +1,16 @@
1
+ import colors from "kleur";
2
+ import { LogEntry, LogLevel } from "@bamboocss/types";
3
+
4
+ //#region src/create-logger.d.ts
5
+ interface LoggerConfig {
6
+ level?: LogLevel;
7
+ filter?: string;
8
+ isDebug?: boolean;
9
+ onLog?: (entry: LogEntry) => void;
10
+ }
11
+ //#endregion
12
+ //#region src/index.d.ts
13
+ declare const quote: (...str: string[]) => string;
14
+ declare const logger: import("@bamboocss/types").LoggerInterface;
15
+ //#endregion
16
+ export { type LoggerConfig, colors, logger, quote };
package/dist/index.mjs CHANGED
@@ -1,237 +1,212 @@
1
- // src/index.ts
2
- import colors2 from "kleur";
3
-
4
- // src/create-logger.ts
5
- import colors from "kleur";
6
-
7
- // ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
1
+ import colors, { default as colors$1 } from "kleur";
2
+ //#region ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
8
3
  function escapeStringRegexp(string) {
9
- if (typeof string !== "string") {
10
- throw new TypeError("Expected a string");
11
- }
12
- return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
4
+ if (typeof string !== "string") throw new TypeError("Expected a string");
5
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
13
6
  }
14
-
15
- // ../../node_modules/.pnpm/matcher@6.0.0/node_modules/matcher/index.js
16
- var regexpCache = /* @__PURE__ */ new Map();
17
- var sanitizeArray = (input, inputName) => {
18
- if (!Array.isArray(input)) {
19
- switch (typeof input) {
20
- case "string": {
21
- input = [input];
22
- break;
23
- }
24
- case "undefined": {
25
- input = [];
26
- break;
27
- }
28
- default: {
29
- throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
30
- }
31
- }
32
- }
33
- return input.filter((string) => {
34
- if (typeof string !== "string") {
35
- if (string === void 0) {
36
- return false;
37
- }
38
- throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
39
- }
40
- return true;
41
- });
7
+ //#endregion
8
+ //#region ../../node_modules/.pnpm/matcher@6.0.0/node_modules/matcher/index.js
9
+ const regexpCache = /* @__PURE__ */ new Map();
10
+ const sanitizeArray = (input, inputName) => {
11
+ if (!Array.isArray(input)) switch (typeof input) {
12
+ case "string":
13
+ input = [input];
14
+ break;
15
+ case "undefined":
16
+ input = [];
17
+ break;
18
+ default: throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
19
+ }
20
+ return input.filter((string) => {
21
+ if (typeof string !== "string") {
22
+ if (string === void 0) return false;
23
+ throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
24
+ }
25
+ return true;
26
+ });
42
27
  };
43
- var makeRegexp = (pattern, options) => {
44
- options = {
45
- caseSensitive: false,
46
- ...options
47
- };
48
- const flags = "s" + (options.caseSensitive ? "" : "i");
49
- const cacheKey = pattern + "|" + flags;
50
- if (regexpCache.has(cacheKey)) {
51
- return regexpCache.get(cacheKey);
52
- }
53
- const negated = pattern[0] === "!";
54
- if (negated) {
55
- pattern = pattern.slice(1);
56
- }
57
- pattern = pattern.replaceAll(String.raw`\*`, "__ESCAPED_STAR__").replaceAll("\\\\", "__ESCAPED_BACKSLASH__").replaceAll(/\\(.)/g, "$1");
58
- pattern = escapeStringRegexp(pattern).replaceAll(String.raw`\*`, ".*");
59
- pattern = pattern.replaceAll("__ESCAPED_STAR__", String.raw`\*`).replaceAll("__ESCAPED_BACKSLASH__", "\\\\");
60
- const regexp = new RegExp(`^${pattern}$`, flags);
61
- regexp.negated = negated;
62
- regexpCache.set(cacheKey, regexp);
63
- return regexp;
28
+ const makeRegexp = (pattern, options) => {
29
+ options = {
30
+ caseSensitive: false,
31
+ ...options
32
+ };
33
+ const flags = "s" + (options.caseSensitive ? "" : "i");
34
+ const cacheKey = pattern + "|" + flags;
35
+ if (regexpCache.has(cacheKey)) return regexpCache.get(cacheKey);
36
+ const negated = pattern[0] === "!";
37
+ if (negated) pattern = pattern.slice(1);
38
+ pattern = pattern.replaceAll(String.raw`\*`, "__ESCAPED_STAR__").replaceAll("\\\\", "__ESCAPED_BACKSLASH__").replaceAll(/\\(.)/g, "$1");
39
+ pattern = escapeStringRegexp(pattern).replaceAll(String.raw`\*`, ".*");
40
+ pattern = pattern.replaceAll("__ESCAPED_STAR__", String.raw`\*`).replaceAll("__ESCAPED_BACKSLASH__", "\\\\");
41
+ const regexp = new RegExp(`^${pattern}$`, flags);
42
+ regexp.negated = negated;
43
+ regexpCache.set(cacheKey, regexp);
44
+ return regexp;
64
45
  };
65
- var baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
66
- inputs = sanitizeArray(inputs, "inputs");
67
- patterns = sanitizeArray(patterns, "patterns");
68
- if (patterns.length === 0) {
69
- return [];
70
- }
71
- patterns = patterns.map((pattern) => makeRegexp(pattern, options));
72
- const negatedPatterns = patterns.filter((pattern) => pattern.negated);
73
- const positivePatterns = patterns.filter((pattern) => !pattern.negated);
74
- const { allPatterns } = options || {};
75
- const result = [];
76
- if (allPatterns && firstMatchOnly && negatedPatterns.length > 1 && positivePatterns.length === 0) {
77
- for (const input of inputs) {
78
- for (const pattern of negatedPatterns) {
79
- if (pattern.test(input)) {
80
- return [];
81
- }
82
- }
83
- }
84
- return inputs.slice(0, 1);
85
- }
86
- for (const input of inputs) {
87
- let excludedByNegation = false;
88
- for (const pattern of negatedPatterns) {
89
- if (pattern.test(input)) {
90
- excludedByNegation = true;
91
- break;
92
- }
93
- }
94
- if (excludedByNegation) {
95
- continue;
96
- }
97
- if (positivePatterns.length === 0) {
98
- result.push(input);
99
- } else if (allPatterns) {
100
- const matchedPositive = Array.from({ length: positivePatterns.length }, () => false);
101
- for (const [index, pattern] of positivePatterns.entries()) {
102
- if (pattern.test(input)) {
103
- matchedPositive[index] = true;
104
- }
105
- }
106
- if (matchedPositive.every(Boolean)) {
107
- result.push(input);
108
- }
109
- } else {
110
- let matchedAny = false;
111
- for (const pattern of positivePatterns) {
112
- if (pattern.test(input)) {
113
- matchedAny = true;
114
- break;
115
- }
116
- }
117
- if (matchedAny) {
118
- result.push(input);
119
- }
120
- }
121
- if (firstMatchOnly && result.length > 0) {
122
- break;
123
- }
124
- }
125
- return result;
46
+ const baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
47
+ inputs = sanitizeArray(inputs, "inputs");
48
+ patterns = sanitizeArray(patterns, "patterns");
49
+ if (patterns.length === 0) return [];
50
+ patterns = patterns.map((pattern) => makeRegexp(pattern, options));
51
+ const negatedPatterns = patterns.filter((pattern) => pattern.negated);
52
+ const positivePatterns = patterns.filter((pattern) => !pattern.negated);
53
+ const { allPatterns } = options || {};
54
+ const result = [];
55
+ if (allPatterns && firstMatchOnly && negatedPatterns.length > 1 && positivePatterns.length === 0) {
56
+ for (const input of inputs) for (const pattern of negatedPatterns) if (pattern.test(input)) return [];
57
+ return inputs.slice(0, 1);
58
+ }
59
+ for (const input of inputs) {
60
+ let excludedByNegation = false;
61
+ for (const pattern of negatedPatterns) if (pattern.test(input)) {
62
+ excludedByNegation = true;
63
+ break;
64
+ }
65
+ if (excludedByNegation) continue;
66
+ if (positivePatterns.length === 0) result.push(input);
67
+ else if (allPatterns) {
68
+ const matchedPositive = Array.from({ length: positivePatterns.length }, () => false);
69
+ for (const [index, pattern] of positivePatterns.entries()) if (pattern.test(input)) matchedPositive[index] = true;
70
+ if (matchedPositive.every(Boolean)) result.push(input);
71
+ } else {
72
+ let matchedAny = false;
73
+ for (const pattern of positivePatterns) if (pattern.test(input)) {
74
+ matchedAny = true;
75
+ break;
76
+ }
77
+ if (matchedAny) result.push(input);
78
+ }
79
+ if (firstMatchOnly && result.length > 0) break;
80
+ }
81
+ return result;
126
82
  };
127
83
  function isMatch(inputs, patterns, options) {
128
- return baseMatcher(inputs, patterns, options, true).length > 0;
84
+ return baseMatcher(inputs, patterns, options, true).length > 0;
129
85
  }
130
-
131
- // src/create-logger.ts
132
- var createLogger = (conf = {}) => {
133
- let onLog = conf.onLog;
134
- let level = conf.isDebug ? "debug" : conf.level ?? "info";
135
- const filter = conf.filter !== "*" ? conf.filter?.split(/[\s,]+/) ?? [] : [];
136
- const getLevel = () => filter.length ? "debug" : level;
137
- const isValid = (level2, type) => {
138
- const badLevel = logLevels[getLevel()].weight > logLevels[level2].weight;
139
- const badType = filter.length > 0 && !matches(filter, type);
140
- return !(badType || badLevel);
141
- };
142
- const stdout = (level2) => (type, data) => {
143
- const entry = createEntry(level2, type, data);
144
- if (level2 != null && isValid(level2, type)) {
145
- const logEntry = formatEntry(entry) ?? {};
146
- console.log(logEntry.label, logEntry.msg);
147
- } else if (getLevel() !== "silent" && level2 == null) {
148
- console.log(...[type, data].filter(Boolean));
149
- }
150
- onLog?.(entry);
151
- };
152
- const logFns = {
153
- debug: stdout("debug"),
154
- info: stdout("info"),
155
- warn: stdout("warn"),
156
- error: stdout("error")
157
- };
158
- const timing = (level2) => (msg) => {
159
- const start = performance.now();
160
- return (_msg = msg) => {
161
- const end = performance.now();
162
- const ms = end - start;
163
- logFns[level2]("hrtime", `${_msg} ${colors.gray(`(${ms.toFixed(2)}ms)`)}`);
164
- };
165
- };
166
- const caughtError = (type, context, error) => {
167
- const message = error instanceof Error ? error.message : String(error);
168
- logFns.error(type, `${context}: ${message}`);
169
- if (error instanceof Error && error.stack) {
170
- logFns.debug(type, error.stack);
171
- }
172
- };
173
- return {
174
- get level() {
175
- return level;
176
- },
177
- set level(newLevel) {
178
- level = newLevel;
179
- },
180
- set onLog(fn) {
181
- onLog = fn;
182
- },
183
- ...logFns,
184
- caughtError,
185
- print(data) {
186
- console.dir(data, { depth: null, colors: true });
187
- },
188
- log: (data) => stdout(null)("", data),
189
- time: {
190
- info: timing("info"),
191
- debug: timing("debug")
192
- },
193
- isDebug: Boolean(conf.isDebug)
194
- };
86
+ //#endregion
87
+ //#region src/create-logger.ts
88
+ const createLogger = (conf = {}) => {
89
+ let onLog = conf.onLog;
90
+ let level = conf.isDebug ? "debug" : conf.level ?? "info";
91
+ const filter = conf.filter !== "*" ? conf.filter?.split(/[\s,]+/) ?? [] : [];
92
+ const getLevel = () => filter.length ? "debug" : level;
93
+ const isValid = (level, type) => {
94
+ const badLevel = logLevels[getLevel()].weight > logLevels[level].weight;
95
+ return !(filter.length > 0 && !matches(filter, type) || badLevel);
96
+ };
97
+ const stdout = (level) => (type, data) => {
98
+ const entry = createEntry(level, type, data);
99
+ if (level != null && isValid(level, type)) {
100
+ const logEntry = formatEntry(entry) ?? {};
101
+ console.log(logEntry.label, logEntry.msg);
102
+ } else if (getLevel() !== "silent" && level == null) console.log(...[type, data].filter(Boolean));
103
+ onLog?.(entry);
104
+ };
105
+ const logFns = {
106
+ debug: stdout("debug"),
107
+ info: stdout("info"),
108
+ warn: stdout("warn"),
109
+ error: stdout("error")
110
+ };
111
+ const timing = (level) => (msg) => {
112
+ const start = performance.now();
113
+ return (_msg = msg) => {
114
+ const ms = performance.now() - start;
115
+ logFns[level]("hrtime", `${_msg} ${colors$1.gray(`(${ms.toFixed(2)}ms)`)}`);
116
+ };
117
+ };
118
+ const caughtError = (type, context, error) => {
119
+ const message = error instanceof Error ? error.message : String(error);
120
+ logFns.error(type, `${context}: ${message}`);
121
+ if (error instanceof Error && error.stack) logFns.debug(type, error.stack);
122
+ };
123
+ return {
124
+ get level() {
125
+ return level;
126
+ },
127
+ set level(newLevel) {
128
+ level = newLevel;
129
+ },
130
+ set onLog(fn) {
131
+ onLog = fn;
132
+ },
133
+ ...logFns,
134
+ caughtError,
135
+ print(data) {
136
+ console.dir(data, {
137
+ depth: null,
138
+ colors: true
139
+ });
140
+ },
141
+ log: (data) => stdout(null)("", data),
142
+ time: {
143
+ info: timing("info"),
144
+ debug: timing("debug")
145
+ },
146
+ isDebug: Boolean(conf.isDebug)
147
+ };
195
148
  };
196
- var matches = (filters, value) => filters.some((search) => isMatch(value, search));
197
- var createEntry = (level, type, data) => {
198
- const msg = data instanceof Error ? colors.red(data.stack ?? data.message) : data;
199
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
200
- return { t: timestamp, type, level, msg };
149
+ const matches = (filters, value) => filters.some((search) => isMatch(value, search));
150
+ const createEntry = (level, type, data) => {
151
+ const msg = data instanceof Error ? colors$1.red(data.stack ?? data.message) : data;
152
+ return {
153
+ t: (/* @__PURE__ */ new Date()).toISOString(),
154
+ type,
155
+ level,
156
+ msg
157
+ };
201
158
  };
202
- var formatEntry = (entry) => {
203
- const uword = entry.type ? colors.gray(`[${entry.type}]`) : "";
204
- let label = "";
205
- let msg = "";
206
- if (entry.level != null) {
207
- const { msg: message, level } = entry;
208
- const color = logLevels[level].color;
209
- const levelLabel = colors.bold(color(`${level}`));
210
- label = [`\u{1F43C}`, levelLabel, uword].filter(Boolean).join(" ");
211
- msg = message;
212
- } else {
213
- label = uword ?? "";
214
- msg = entry.msg;
215
- }
216
- return { label, msg };
159
+ const formatEntry = (entry) => {
160
+ const uword = entry.type ? colors$1.gray(`[${entry.type}]`) : "";
161
+ let label = "";
162
+ let msg = "";
163
+ if (entry.level != null) {
164
+ const { msg: message, level } = entry;
165
+ const color = logLevels[level].color;
166
+ label = [
167
+ `🐼`,
168
+ colors$1.bold(color(`${level}`)),
169
+ uword
170
+ ].filter(Boolean).join(" ");
171
+ msg = message;
172
+ } else {
173
+ label = uword ?? "";
174
+ msg = entry.msg;
175
+ }
176
+ return {
177
+ label,
178
+ msg
179
+ };
217
180
  };
218
- var logLevels = {
219
- debug: { weight: 0, color: colors.magenta },
220
- info: { weight: 1, color: colors.blue },
221
- warn: { weight: 2, color: colors.yellow },
222
- error: { weight: 3, color: colors.red },
223
- silent: { weight: 4, color: colors.white }
181
+ const logLevels = {
182
+ debug: {
183
+ weight: 0,
184
+ color: colors$1.magenta
185
+ },
186
+ info: {
187
+ weight: 1,
188
+ color: colors$1.blue
189
+ },
190
+ warn: {
191
+ weight: 2,
192
+ color: colors$1.yellow
193
+ },
194
+ error: {
195
+ weight: 3,
196
+ color: colors$1.red
197
+ },
198
+ silent: {
199
+ weight: 4,
200
+ color: colors$1.white
201
+ }
224
202
  };
225
-
226
- // src/index.ts
227
- var quote = (...str) => colors2.cyan(`\`${str.join("")}\``);
228
- var debug = typeof process !== "undefined" ? process.env.BAMBOO_DEBUG : void 0;
229
- var logger = createLogger({
230
- filter: typeof process !== "undefined" ? debug : void 0,
231
- isDebug: Boolean(debug)
203
+ //#endregion
204
+ //#region src/index.ts
205
+ const quote = (...str) => colors.cyan(`\`${str.join("")}\``);
206
+ const debug = typeof process !== "undefined" ? process.env.BAMBOO_DEBUG : void 0;
207
+ const logger = createLogger({
208
+ filter: typeof process !== "undefined" ? debug : void 0,
209
+ isDebug: Boolean(debug)
232
210
  });
233
- export {
234
- colors2 as colors,
235
- logger,
236
- quote
237
- };
211
+ //#endregion
212
+ export { colors, logger, quote };
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@bamboocss/logger",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboo-css.com",
6
6
  "license": "MIT",
7
7
  "author": "Segun Adebayo <joseshegs@gmail.com>",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/chakra-ui/bamboo.git",
10
+ "url": "git+https://github.com/bamboocss/bamboo.git",
11
11
  "directory": "packages/logger"
12
12
  },
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
16
  "sideEffects": false,
17
- "main": "dist/index.js",
17
+ "main": "dist/index.cjs",
18
18
  "module": "dist/index.mjs",
19
- "types": "dist/index.d.ts",
19
+ "types": "dist/index.d.cts",
20
20
  "exports": {
21
21
  ".": {
22
22
  "source": "./src/index.ts",
23
- "types": "./dist/index.d.ts",
24
- "require": "./dist/index.js",
23
+ "types": "./dist/index.d.cts",
24
+ "require": "./dist/index.cjs",
25
25
  "import": {
26
26
  "types": "./dist/index.d.mts",
27
27
  "default": "./dist/index.mjs"
@@ -34,14 +34,14 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "kleur": "4.1.5",
37
- "@bamboocss/types": "1.11.1"
37
+ "@bamboocss/types": "1.11.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "matcher": "6.0.0"
41
41
  },
42
42
  "scripts": {
43
- "build": "tsup src/index.ts --format=esm,cjs --dts",
44
- "build-fast": "tsup src/index.ts --format=esm,cjs --no-dts",
43
+ "build": "tsdown src/index.ts --format=esm,cjs --dts",
44
+ "build-fast": "tsdown --dts=false src/index.ts --format=esm,cjs",
45
45
  "dev": "pnpm build-fast --watch"
46
46
  }
47
47
  }
package/dist/index.js DELETED
@@ -1,274 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- colors: () => import_kleur2.default,
34
- logger: () => logger,
35
- quote: () => quote
36
- });
37
- module.exports = __toCommonJS(index_exports);
38
- var import_kleur2 = __toESM(require("kleur"));
39
-
40
- // src/create-logger.ts
41
- var import_kleur = __toESM(require("kleur"));
42
-
43
- // ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
44
- function escapeStringRegexp(string) {
45
- if (typeof string !== "string") {
46
- throw new TypeError("Expected a string");
47
- }
48
- return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
49
- }
50
-
51
- // ../../node_modules/.pnpm/matcher@6.0.0/node_modules/matcher/index.js
52
- var regexpCache = /* @__PURE__ */ new Map();
53
- var sanitizeArray = (input, inputName) => {
54
- if (!Array.isArray(input)) {
55
- switch (typeof input) {
56
- case "string": {
57
- input = [input];
58
- break;
59
- }
60
- case "undefined": {
61
- input = [];
62
- break;
63
- }
64
- default: {
65
- throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
66
- }
67
- }
68
- }
69
- return input.filter((string) => {
70
- if (typeof string !== "string") {
71
- if (string === void 0) {
72
- return false;
73
- }
74
- throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
75
- }
76
- return true;
77
- });
78
- };
79
- var makeRegexp = (pattern, options) => {
80
- options = {
81
- caseSensitive: false,
82
- ...options
83
- };
84
- const flags = "s" + (options.caseSensitive ? "" : "i");
85
- const cacheKey = pattern + "|" + flags;
86
- if (regexpCache.has(cacheKey)) {
87
- return regexpCache.get(cacheKey);
88
- }
89
- const negated = pattern[0] === "!";
90
- if (negated) {
91
- pattern = pattern.slice(1);
92
- }
93
- pattern = pattern.replaceAll(String.raw`\*`, "__ESCAPED_STAR__").replaceAll("\\\\", "__ESCAPED_BACKSLASH__").replaceAll(/\\(.)/g, "$1");
94
- pattern = escapeStringRegexp(pattern).replaceAll(String.raw`\*`, ".*");
95
- pattern = pattern.replaceAll("__ESCAPED_STAR__", String.raw`\*`).replaceAll("__ESCAPED_BACKSLASH__", "\\\\");
96
- const regexp = new RegExp(`^${pattern}$`, flags);
97
- regexp.negated = negated;
98
- regexpCache.set(cacheKey, regexp);
99
- return regexp;
100
- };
101
- var baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
102
- inputs = sanitizeArray(inputs, "inputs");
103
- patterns = sanitizeArray(patterns, "patterns");
104
- if (patterns.length === 0) {
105
- return [];
106
- }
107
- patterns = patterns.map((pattern) => makeRegexp(pattern, options));
108
- const negatedPatterns = patterns.filter((pattern) => pattern.negated);
109
- const positivePatterns = patterns.filter((pattern) => !pattern.negated);
110
- const { allPatterns } = options || {};
111
- const result = [];
112
- if (allPatterns && firstMatchOnly && negatedPatterns.length > 1 && positivePatterns.length === 0) {
113
- for (const input of inputs) {
114
- for (const pattern of negatedPatterns) {
115
- if (pattern.test(input)) {
116
- return [];
117
- }
118
- }
119
- }
120
- return inputs.slice(0, 1);
121
- }
122
- for (const input of inputs) {
123
- let excludedByNegation = false;
124
- for (const pattern of negatedPatterns) {
125
- if (pattern.test(input)) {
126
- excludedByNegation = true;
127
- break;
128
- }
129
- }
130
- if (excludedByNegation) {
131
- continue;
132
- }
133
- if (positivePatterns.length === 0) {
134
- result.push(input);
135
- } else if (allPatterns) {
136
- const matchedPositive = Array.from({ length: positivePatterns.length }, () => false);
137
- for (const [index, pattern] of positivePatterns.entries()) {
138
- if (pattern.test(input)) {
139
- matchedPositive[index] = true;
140
- }
141
- }
142
- if (matchedPositive.every(Boolean)) {
143
- result.push(input);
144
- }
145
- } else {
146
- let matchedAny = false;
147
- for (const pattern of positivePatterns) {
148
- if (pattern.test(input)) {
149
- matchedAny = true;
150
- break;
151
- }
152
- }
153
- if (matchedAny) {
154
- result.push(input);
155
- }
156
- }
157
- if (firstMatchOnly && result.length > 0) {
158
- break;
159
- }
160
- }
161
- return result;
162
- };
163
- function isMatch(inputs, patterns, options) {
164
- return baseMatcher(inputs, patterns, options, true).length > 0;
165
- }
166
-
167
- // src/create-logger.ts
168
- var createLogger = (conf = {}) => {
169
- let onLog = conf.onLog;
170
- let level = conf.isDebug ? "debug" : conf.level ?? "info";
171
- const filter = conf.filter !== "*" ? conf.filter?.split(/[\s,]+/) ?? [] : [];
172
- const getLevel = () => filter.length ? "debug" : level;
173
- const isValid = (level2, type) => {
174
- const badLevel = logLevels[getLevel()].weight > logLevels[level2].weight;
175
- const badType = filter.length > 0 && !matches(filter, type);
176
- return !(badType || badLevel);
177
- };
178
- const stdout = (level2) => (type, data) => {
179
- const entry = createEntry(level2, type, data);
180
- if (level2 != null && isValid(level2, type)) {
181
- const logEntry = formatEntry(entry) ?? {};
182
- console.log(logEntry.label, logEntry.msg);
183
- } else if (getLevel() !== "silent" && level2 == null) {
184
- console.log(...[type, data].filter(Boolean));
185
- }
186
- onLog?.(entry);
187
- };
188
- const logFns = {
189
- debug: stdout("debug"),
190
- info: stdout("info"),
191
- warn: stdout("warn"),
192
- error: stdout("error")
193
- };
194
- const timing = (level2) => (msg) => {
195
- const start = performance.now();
196
- return (_msg = msg) => {
197
- const end = performance.now();
198
- const ms = end - start;
199
- logFns[level2]("hrtime", `${_msg} ${import_kleur.default.gray(`(${ms.toFixed(2)}ms)`)}`);
200
- };
201
- };
202
- const caughtError = (type, context, error) => {
203
- const message = error instanceof Error ? error.message : String(error);
204
- logFns.error(type, `${context}: ${message}`);
205
- if (error instanceof Error && error.stack) {
206
- logFns.debug(type, error.stack);
207
- }
208
- };
209
- return {
210
- get level() {
211
- return level;
212
- },
213
- set level(newLevel) {
214
- level = newLevel;
215
- },
216
- set onLog(fn) {
217
- onLog = fn;
218
- },
219
- ...logFns,
220
- caughtError,
221
- print(data) {
222
- console.dir(data, { depth: null, colors: true });
223
- },
224
- log: (data) => stdout(null)("", data),
225
- time: {
226
- info: timing("info"),
227
- debug: timing("debug")
228
- },
229
- isDebug: Boolean(conf.isDebug)
230
- };
231
- };
232
- var matches = (filters, value) => filters.some((search) => isMatch(value, search));
233
- var createEntry = (level, type, data) => {
234
- const msg = data instanceof Error ? import_kleur.default.red(data.stack ?? data.message) : data;
235
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
236
- return { t: timestamp, type, level, msg };
237
- };
238
- var formatEntry = (entry) => {
239
- const uword = entry.type ? import_kleur.default.gray(`[${entry.type}]`) : "";
240
- let label = "";
241
- let msg = "";
242
- if (entry.level != null) {
243
- const { msg: message, level } = entry;
244
- const color = logLevels[level].color;
245
- const levelLabel = import_kleur.default.bold(color(`${level}`));
246
- label = [`\u{1F43C}`, levelLabel, uword].filter(Boolean).join(" ");
247
- msg = message;
248
- } else {
249
- label = uword ?? "";
250
- msg = entry.msg;
251
- }
252
- return { label, msg };
253
- };
254
- var logLevels = {
255
- debug: { weight: 0, color: import_kleur.default.magenta },
256
- info: { weight: 1, color: import_kleur.default.blue },
257
- warn: { weight: 2, color: import_kleur.default.yellow },
258
- error: { weight: 3, color: import_kleur.default.red },
259
- silent: { weight: 4, color: import_kleur.default.white }
260
- };
261
-
262
- // src/index.ts
263
- var quote = (...str) => import_kleur2.default.cyan(`\`${str.join("")}\``);
264
- var debug = typeof process !== "undefined" ? process.env.BAMBOO_DEBUG : void 0;
265
- var logger = createLogger({
266
- filter: typeof process !== "undefined" ? debug : void 0,
267
- isDebug: Boolean(debug)
268
- });
269
- // Annotate the CommonJS export names for ESM import in node:
270
- 0 && (module.exports = {
271
- colors,
272
- logger,
273
- quote
274
- });