@leftium/gg 0.0.25 → 0.0.26
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/gg.js +32 -2
- package/package.json +1 -1
package/dist/gg.js
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import debugFactory from './debug.js';
|
|
2
2
|
import ErrorStackParser from 'error-stack-parser';
|
|
3
3
|
import { BROWSER, DEV } from 'esm-env';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a debug instance with custom formatArgs to add namespace padding
|
|
6
|
+
* Padding is done at format time, not in the namespace itself, to keep colors stable
|
|
7
|
+
*/
|
|
8
|
+
function createGgDebugger(namespace) {
|
|
9
|
+
const dbg = debugFactory(namespace);
|
|
10
|
+
// Store the original formatArgs (if it exists)
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
const originalFormatArgs = dbg.formatArgs;
|
|
13
|
+
// Override formatArgs to add padding to the namespace display
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
dbg.formatArgs = function (args) {
|
|
16
|
+
// Call original formatArgs first
|
|
17
|
+
if (originalFormatArgs) {
|
|
18
|
+
originalFormatArgs.call(this, args);
|
|
19
|
+
}
|
|
20
|
+
// Extract the callpoint from namespace (strip 'gg:' prefix and any URL suffix)
|
|
21
|
+
const nsMatch = this.namespace.match(/^gg:([^h]+?)(?:http|$)/);
|
|
22
|
+
const callpoint = nsMatch ? nsMatch[1] : this.namespace.replace(/^gg:/, '');
|
|
23
|
+
const paddedCallpoint = callpoint.padEnd(maxCallpointLength, ' ');
|
|
24
|
+
// Replace the namespace in the formatted string with padded version
|
|
25
|
+
if (typeof args[0] === 'string') {
|
|
26
|
+
args[0] = args[0].replace(this.namespace, `gg:${paddedCallpoint}`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return dbg;
|
|
30
|
+
}
|
|
4
31
|
// Helper to detect if we're running in CloudFlare Workers
|
|
5
32
|
const isCloudflareWorker = () => {
|
|
6
33
|
// Check for CloudFlare Workers-specific global
|
|
@@ -176,10 +203,12 @@ export function gg(...args) {
|
|
|
176
203
|
if (callpoint.length < 80 && callpoint.length > maxCallpointLength) {
|
|
177
204
|
maxCallpointLength = callpoint.length;
|
|
178
205
|
}
|
|
179
|
-
|
|
206
|
+
// Namespace without padding - keeps colors stable
|
|
207
|
+
// Editor link appended if enabled
|
|
208
|
+
namespace = `gg:${callpoint}${ggConfig.editorLink ? url : ''}`;
|
|
180
209
|
}
|
|
181
210
|
const ggLogFunction = namespaceToLogFunction.get(namespace) ||
|
|
182
|
-
namespaceToLogFunction.set(namespace,
|
|
211
|
+
namespaceToLogFunction.set(namespace, createGgDebugger(namespace)).get(namespace);
|
|
183
212
|
if (!args.length) {
|
|
184
213
|
ggLogFunction(` 📝📝 ${url} 👀👀`);
|
|
185
214
|
return {
|
|
@@ -200,6 +229,7 @@ export function gg(...args) {
|
|
|
200
229
|
if (gg._onLog) {
|
|
201
230
|
// Don't stringify args - keep them as-is for expandable objects
|
|
202
231
|
const message = args.length === 1 ? String(args[0]) : args.map(String).join(' ');
|
|
232
|
+
// Use debug's native color (now deterministic since namespace has no padding)
|
|
203
233
|
gg._onLog({
|
|
204
234
|
namespace,
|
|
205
235
|
color: ggLogFunction.color,
|