@leftium/gg 0.0.48 → 0.0.50
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 +22 -36
- package/package.json +1 -2
package/dist/gg.js
CHANGED
|
@@ -35,24 +35,13 @@ const isCloudflareWorker = () => {
|
|
|
35
35
|
'caches' in globalThis &&
|
|
36
36
|
typeof globalWithWorkerAPIs.WebSocketPair !== 'undefined');
|
|
37
37
|
};
|
|
38
|
-
// Check if we're in CloudFlare Workers and warn early
|
|
39
|
-
if (isCloudflareWorker()) {
|
|
40
|
-
console.warn('gg: CloudFlare not supported.');
|
|
41
|
-
}
|
|
42
38
|
// Lazy-load Node.js modules to avoid top-level await (Safari compatibility).
|
|
43
39
|
// The imports start immediately but don't block module evaluation.
|
|
44
|
-
let dotenvModule = null;
|
|
45
40
|
let httpModule = null;
|
|
46
41
|
function loadServerModules() {
|
|
47
42
|
if (isCloudflareWorker() || BROWSER)
|
|
48
43
|
return Promise.resolve();
|
|
49
44
|
return (async () => {
|
|
50
|
-
try {
|
|
51
|
-
dotenvModule = await import('dotenv');
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// dotenv not available — optional dependency
|
|
55
|
-
}
|
|
56
45
|
try {
|
|
57
46
|
httpModule = await import('http');
|
|
58
47
|
}
|
|
@@ -112,17 +101,14 @@ void getServerPort().then((p) => {
|
|
|
112
101
|
* Determines if gg should be enabled based on environment and runtime triggers.
|
|
113
102
|
*
|
|
114
103
|
* Priority order:
|
|
115
|
-
* 1.
|
|
116
|
-
* 2.
|
|
117
|
-
* 3.
|
|
118
|
-
* 4. PROD mode → requires runtime trigger (?gg URL param or localStorage)
|
|
104
|
+
* 1. ENV override takes absolute precedence
|
|
105
|
+
* 2. DEV mode → always enabled
|
|
106
|
+
* 3. PROD mode → requires runtime trigger (?gg URL param, localStorage, or GG_ENABLED=true)
|
|
119
107
|
*/
|
|
120
108
|
function isGgEnabled() {
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// ENV hard-disable takes absolute precedence
|
|
125
|
-
// Allows completely removing gg from production builds
|
|
109
|
+
// ENV override takes absolute precedence
|
|
110
|
+
// GG_ENABLED=false: completely removes gg (even in DEV)
|
|
111
|
+
// GG_ENABLED=true: force-enables gg (even in PROD, e.g. Vercel deployments)
|
|
126
112
|
if (BROWSER) {
|
|
127
113
|
if (typeof import.meta.env?.VITE_GG_ENABLED === 'string' &&
|
|
128
114
|
import.meta.env.VITE_GG_ENABLED === 'false') {
|
|
@@ -133,6 +119,9 @@ function isGgEnabled() {
|
|
|
133
119
|
if (process?.env?.GG_ENABLED === 'false') {
|
|
134
120
|
return false;
|
|
135
121
|
}
|
|
122
|
+
if (process?.env?.GG_ENABLED === 'true') {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
136
125
|
}
|
|
137
126
|
// Development - always enabled (unless ENV explicitly disabled above)
|
|
138
127
|
if (DEV)
|
|
@@ -220,7 +209,7 @@ function openInEditorUrl(fileName, line, col) {
|
|
|
220
209
|
return url;
|
|
221
210
|
}
|
|
222
211
|
export function gg(...args) {
|
|
223
|
-
if (!ggConfig.enabled
|
|
212
|
+
if (!ggConfig.enabled) {
|
|
224
213
|
// Return a no-op chain that skips logging
|
|
225
214
|
return new GgChain(args[0], args, { ns: '' }, true);
|
|
226
215
|
}
|
|
@@ -242,7 +231,7 @@ export function gg(...args) {
|
|
|
242
231
|
* <OpenInEditorLink gg={gg.here()} />
|
|
243
232
|
*/
|
|
244
233
|
gg.here = function () {
|
|
245
|
-
if (!ggConfig.enabled
|
|
234
|
+
if (!ggConfig.enabled) {
|
|
246
235
|
return { fileName: '', functionName: '', url: '' };
|
|
247
236
|
}
|
|
248
237
|
const callpoint = resolveCallpoint(3);
|
|
@@ -393,7 +382,7 @@ export class GgChain {
|
|
|
393
382
|
*/
|
|
394
383
|
function ggLog(options, ...args) {
|
|
395
384
|
const { ns: nsLabel, file, line, col, src, level, stack, tableData } = options;
|
|
396
|
-
if (!ggConfig.enabled
|
|
385
|
+
if (!ggConfig.enabled) {
|
|
397
386
|
return args.length ? args[0] : { fileName: '', functionName: '', url: '' };
|
|
398
387
|
}
|
|
399
388
|
const namespace = `gg:${nsLabel}`;
|
|
@@ -464,7 +453,7 @@ function ggLog(options, ...args) {
|
|
|
464
453
|
* Returns a GgChain for chaining modifiers (.ns(), .warn(), etc.)
|
|
465
454
|
*/
|
|
466
455
|
gg._ns = function (options, ...args) {
|
|
467
|
-
const disabled = !ggConfig.enabled
|
|
456
|
+
const disabled = !ggConfig.enabled;
|
|
468
457
|
return new GgChain(args[0], args, options, disabled);
|
|
469
458
|
};
|
|
470
459
|
/**
|
|
@@ -473,7 +462,7 @@ gg._ns = function (options, ...args) {
|
|
|
473
462
|
* Called by the ggCallSitesPlugin when it rewrites gg.here() calls.
|
|
474
463
|
*/
|
|
475
464
|
gg._here = function (options) {
|
|
476
|
-
if (!ggConfig.enabled
|
|
465
|
+
if (!ggConfig.enabled) {
|
|
477
466
|
return { fileName: '', functionName: '', url: '' };
|
|
478
467
|
}
|
|
479
468
|
const { ns: nsLabel, file, line, col } = options;
|
|
@@ -582,14 +571,14 @@ export class GgTimerChain {
|
|
|
582
571
|
*/
|
|
583
572
|
gg.time = function (label = 'default') {
|
|
584
573
|
const options = { ns: resolveCallpoint(3) };
|
|
585
|
-
if (ggConfig.enabled
|
|
574
|
+
if (ggConfig.enabled) {
|
|
586
575
|
timers.set(label, { start: performance.now(), options });
|
|
587
576
|
}
|
|
588
577
|
return new GgTimerChain(label, options);
|
|
589
578
|
};
|
|
590
579
|
/** gg._time() - Internal: time with call-site metadata from Vite plugin. */
|
|
591
580
|
gg._time = function (options, label = 'default') {
|
|
592
|
-
if (ggConfig.enabled
|
|
581
|
+
if (ggConfig.enabled) {
|
|
593
582
|
timers.set(label, { start: performance.now(), options });
|
|
594
583
|
}
|
|
595
584
|
return new GgTimerChain(label, options);
|
|
@@ -607,7 +596,7 @@ gg._time = function (options, label = 'default') {
|
|
|
607
596
|
* gg.timeEnd('process');
|
|
608
597
|
*/
|
|
609
598
|
gg.timeLog = function (label = 'default', ...args) {
|
|
610
|
-
if (!ggConfig.enabled
|
|
599
|
+
if (!ggConfig.enabled)
|
|
611
600
|
return;
|
|
612
601
|
const timer = timers.get(label);
|
|
613
602
|
if (timer === undefined) {
|
|
@@ -621,7 +610,7 @@ gg.timeLog = function (label = 'default', ...args) {
|
|
|
621
610
|
};
|
|
622
611
|
/** gg._timeLog() - Internal: timeLog with call-site metadata from Vite plugin. */
|
|
623
612
|
gg._timeLog = function (options, label = 'default', ...args) {
|
|
624
|
-
if (!ggConfig.enabled
|
|
613
|
+
if (!ggConfig.enabled)
|
|
625
614
|
return;
|
|
626
615
|
const timer = timers.get(label);
|
|
627
616
|
if (timer === undefined) {
|
|
@@ -643,7 +632,7 @@ gg._timeLog = function (options, label = 'default', ...args) {
|
|
|
643
632
|
* gg.timeEnd('fetch'); // logs under 'api-pipeline' namespace
|
|
644
633
|
*/
|
|
645
634
|
gg.timeEnd = function (label = 'default') {
|
|
646
|
-
if (!ggConfig.enabled
|
|
635
|
+
if (!ggConfig.enabled)
|
|
647
636
|
return;
|
|
648
637
|
const timer = timers.get(label);
|
|
649
638
|
if (timer === undefined) {
|
|
@@ -658,7 +647,7 @@ gg.timeEnd = function (label = 'default') {
|
|
|
658
647
|
};
|
|
659
648
|
/** gg._timeEnd() - Internal: timeEnd with call-site metadata from Vite plugin. */
|
|
660
649
|
gg._timeEnd = function (options, label = 'default') {
|
|
661
|
-
if (!ggConfig.enabled
|
|
650
|
+
if (!ggConfig.enabled)
|
|
662
651
|
return;
|
|
663
652
|
const timer = timers.get(label);
|
|
664
653
|
if (timer === undefined) {
|
|
@@ -963,7 +952,7 @@ export async function runGgDiagnostics() {
|
|
|
963
952
|
if (!ggConfig.showHints || isCloudflareWorker() || diagnosticsRan)
|
|
964
953
|
return;
|
|
965
954
|
diagnosticsRan = true;
|
|
966
|
-
// Ensure server modules
|
|
955
|
+
// Ensure server modules and debug factory are loaded before diagnostics
|
|
967
956
|
await serverModulesReady;
|
|
968
957
|
await debugReady;
|
|
969
958
|
// Create test debugger for server-side enabled check
|
|
@@ -995,10 +984,7 @@ export async function runGgDiagnostics() {
|
|
|
995
984
|
message(`${checkbox(ggConfig.enabled)} gg enabled: ${ggConfig.enabled}${enableHint}`);
|
|
996
985
|
if (!BROWSER) {
|
|
997
986
|
// Server-side: check DEBUG env var (the only output path on the server)
|
|
998
|
-
const hint = makeHint(!ggLogTest.enabled, ' (Try `DEBUG=gg:* npm run dev`)');
|
|
999
|
-
if (dotenvModule) {
|
|
1000
|
-
dotenvModule.config();
|
|
1001
|
-
}
|
|
987
|
+
const hint = makeHint(!ggLogTest.enabled, ' (Try `DEBUG=gg:* npm run dev` or use --env-file=.env)');
|
|
1002
988
|
message(`${checkbox(ggLogTest.enabled)} DEBUG env variable: ${process?.env?.DEBUG}${hint}`);
|
|
1003
989
|
}
|
|
1004
990
|
// Optional plugin diagnostics
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leftium/gg",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/Leftium/gg.git"
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
"@tanstack/virtual-core": "^3.13.18",
|
|
74
74
|
"@types/estree": "^1.0.8",
|
|
75
75
|
"acorn": "^8.15.0",
|
|
76
|
-
"dotenv": "^17.2.4",
|
|
77
76
|
"eruda": "^3.4.3",
|
|
78
77
|
"esm-env": "^1.2.2",
|
|
79
78
|
"launch-editor": "^2.12.0"
|