@leftium/gg 0.0.49 → 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.
Files changed (2) hide show
  1. package/dist/gg.js +20 -24
  2. package/package.json +1 -1
package/dist/gg.js CHANGED
@@ -35,10 +35,6 @@ 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
40
  let httpModule = null;
@@ -105,17 +101,14 @@ void getServerPort().then((p) => {
105
101
  * Determines if gg should be enabled based on environment and runtime triggers.
106
102
  *
107
103
  * Priority order:
108
- * 1. CloudFlare Workers always disabled (no stack traces, no filesystem)
109
- * 2. ENV hard-disableabsolute override, no runtime enable possible
110
- * 3. DEV mode → always enabled
111
- * 4. PROD mode → requires runtime trigger (?gg URL param or localStorage)
104
+ * 1. ENV override takes absolute precedence
105
+ * 2. DEV modealways enabled
106
+ * 3. PROD mode → requires runtime trigger (?gg URL param, localStorage, or GG_ENABLED=true)
112
107
  */
113
108
  function isGgEnabled() {
114
- // CloudFlare Workers - hard disable (no Error stacks, no filesystem)
115
- if (isCloudflareWorker())
116
- return false;
117
- // ENV hard-disable takes absolute precedence
118
- // 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)
119
112
  if (BROWSER) {
120
113
  if (typeof import.meta.env?.VITE_GG_ENABLED === 'string' &&
121
114
  import.meta.env.VITE_GG_ENABLED === 'false') {
@@ -126,6 +119,9 @@ function isGgEnabled() {
126
119
  if (process?.env?.GG_ENABLED === 'false') {
127
120
  return false;
128
121
  }
122
+ if (process?.env?.GG_ENABLED === 'true') {
123
+ return true;
124
+ }
129
125
  }
130
126
  // Development - always enabled (unless ENV explicitly disabled above)
131
127
  if (DEV)
@@ -213,7 +209,7 @@ function openInEditorUrl(fileName, line, col) {
213
209
  return url;
214
210
  }
215
211
  export function gg(...args) {
216
- if (!ggConfig.enabled || isCloudflareWorker()) {
212
+ if (!ggConfig.enabled) {
217
213
  // Return a no-op chain that skips logging
218
214
  return new GgChain(args[0], args, { ns: '' }, true);
219
215
  }
@@ -235,7 +231,7 @@ export function gg(...args) {
235
231
  * <OpenInEditorLink gg={gg.here()} />
236
232
  */
237
233
  gg.here = function () {
238
- if (!ggConfig.enabled || isCloudflareWorker()) {
234
+ if (!ggConfig.enabled) {
239
235
  return { fileName: '', functionName: '', url: '' };
240
236
  }
241
237
  const callpoint = resolveCallpoint(3);
@@ -386,7 +382,7 @@ export class GgChain {
386
382
  */
387
383
  function ggLog(options, ...args) {
388
384
  const { ns: nsLabel, file, line, col, src, level, stack, tableData } = options;
389
- if (!ggConfig.enabled || isCloudflareWorker()) {
385
+ if (!ggConfig.enabled) {
390
386
  return args.length ? args[0] : { fileName: '', functionName: '', url: '' };
391
387
  }
392
388
  const namespace = `gg:${nsLabel}`;
@@ -457,7 +453,7 @@ function ggLog(options, ...args) {
457
453
  * Returns a GgChain for chaining modifiers (.ns(), .warn(), etc.)
458
454
  */
459
455
  gg._ns = function (options, ...args) {
460
- const disabled = !ggConfig.enabled || isCloudflareWorker();
456
+ const disabled = !ggConfig.enabled;
461
457
  return new GgChain(args[0], args, options, disabled);
462
458
  };
463
459
  /**
@@ -466,7 +462,7 @@ gg._ns = function (options, ...args) {
466
462
  * Called by the ggCallSitesPlugin when it rewrites gg.here() calls.
467
463
  */
468
464
  gg._here = function (options) {
469
- if (!ggConfig.enabled || isCloudflareWorker()) {
465
+ if (!ggConfig.enabled) {
470
466
  return { fileName: '', functionName: '', url: '' };
471
467
  }
472
468
  const { ns: nsLabel, file, line, col } = options;
@@ -575,14 +571,14 @@ export class GgTimerChain {
575
571
  */
576
572
  gg.time = function (label = 'default') {
577
573
  const options = { ns: resolveCallpoint(3) };
578
- if (ggConfig.enabled && !isCloudflareWorker()) {
574
+ if (ggConfig.enabled) {
579
575
  timers.set(label, { start: performance.now(), options });
580
576
  }
581
577
  return new GgTimerChain(label, options);
582
578
  };
583
579
  /** gg._time() - Internal: time with call-site metadata from Vite plugin. */
584
580
  gg._time = function (options, label = 'default') {
585
- if (ggConfig.enabled && !isCloudflareWorker()) {
581
+ if (ggConfig.enabled) {
586
582
  timers.set(label, { start: performance.now(), options });
587
583
  }
588
584
  return new GgTimerChain(label, options);
@@ -600,7 +596,7 @@ gg._time = function (options, label = 'default') {
600
596
  * gg.timeEnd('process');
601
597
  */
602
598
  gg.timeLog = function (label = 'default', ...args) {
603
- if (!ggConfig.enabled || isCloudflareWorker())
599
+ if (!ggConfig.enabled)
604
600
  return;
605
601
  const timer = timers.get(label);
606
602
  if (timer === undefined) {
@@ -614,7 +610,7 @@ gg.timeLog = function (label = 'default', ...args) {
614
610
  };
615
611
  /** gg._timeLog() - Internal: timeLog with call-site metadata from Vite plugin. */
616
612
  gg._timeLog = function (options, label = 'default', ...args) {
617
- if (!ggConfig.enabled || isCloudflareWorker())
613
+ if (!ggConfig.enabled)
618
614
  return;
619
615
  const timer = timers.get(label);
620
616
  if (timer === undefined) {
@@ -636,7 +632,7 @@ gg._timeLog = function (options, label = 'default', ...args) {
636
632
  * gg.timeEnd('fetch'); // logs under 'api-pipeline' namespace
637
633
  */
638
634
  gg.timeEnd = function (label = 'default') {
639
- if (!ggConfig.enabled || isCloudflareWorker())
635
+ if (!ggConfig.enabled)
640
636
  return;
641
637
  const timer = timers.get(label);
642
638
  if (timer === undefined) {
@@ -651,7 +647,7 @@ gg.timeEnd = function (label = 'default') {
651
647
  };
652
648
  /** gg._timeEnd() - Internal: timeEnd with call-site metadata from Vite plugin. */
653
649
  gg._timeEnd = function (options, label = 'default') {
654
- if (!ggConfig.enabled || isCloudflareWorker())
650
+ if (!ggConfig.enabled)
655
651
  return;
656
652
  const timer = timers.get(label);
657
653
  if (timer === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leftium/gg",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Leftium/gg.git"