@crimsonsunset/jsg-logger 1.5.5 → 1.7.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.
package/index.js CHANGED
@@ -13,6 +13,31 @@ import {createCLIFormatter} from './formatters/cli-formatter.js';
13
13
  import {createServerFormatter, getServerConfig} from './formatters/server-formatter.js';
14
14
  import {LogStore} from './stores/log-store.js';
15
15
 
16
+ // Check default config for devtools at module load time
17
+ // This allows bundlers to tree-shake if disabled
18
+ const defaultDevtoolsEnabled = defaultConfig.devtools?.enabled ?? false;
19
+
20
+ // Conditional static import - bundlers can eliminate if condition is false
21
+ // If defaultDevtoolsEnabled is false, bundler removes this entire block
22
+ // Use lazy initialization to avoid top-level await (which would make module async)
23
+ let devtoolsModule = null;
24
+ let devtoolsModulePromise = null;
25
+ if (defaultDevtoolsEnabled) {
26
+ console.log('[JSG-LOGGER] DevTools module pre-loading started (default config enabled)');
27
+ // Start loading immediately but don't await (non-blocking)
28
+ // Bundlers can still analyze this static import for tree-shaking
29
+ devtoolsModulePromise = import('./devtools/dist/panel-entry.js').then(module => {
30
+ devtoolsModule = module;
31
+ console.log('[JSG-LOGGER] DevTools module pre-loaded successfully');
32
+ return module;
33
+ }).catch(error => {
34
+ console.error('[JSG-LOGGER] DevTools module pre-load failed:', error);
35
+ return null;
36
+ });
37
+ } else {
38
+ console.log('[JSG-LOGGER] DevTools module NOT pre-loaded (default config disabled - will tree-shake)');
39
+ }
40
+
16
41
  /**
17
42
  * Main Logger Class
18
43
  * Manages logger instances and provides the public API
@@ -88,6 +113,8 @@ class JSGLogger {
88
113
  */
89
114
  async init(options = {}) {
90
115
  try {
116
+ console.log('[JSG-LOGGER] Initializing logger...', options.configPath ? `configPath: ${options.configPath}` : options.config ? 'inline config provided' : 'using defaults');
117
+
91
118
  // Load configuration FIRST (before environment detection)
92
119
  if (options.configPath || options.config) {
93
120
  await configManager.loadConfig(options.configPath || options.config);
@@ -458,8 +485,12 @@ class JSGLogger {
458
485
 
459
486
  // DevTools panel controls
460
487
  enableDevPanel: async () => {
461
- // Early config check - creates tree-shakeable dead code path
462
- if (!configManager.config.devtools?.enabled) {
488
+ // Early config check - uses consumer's runtime config
489
+ const runtimeDevtoolsEnabled = configManager.config.devtools?.enabled ?? false;
490
+
491
+ console.log(`[JSG-LOGGER] enableDevPanel() called - runtime config: ${runtimeDevtoolsEnabled ? 'ENABLED' : 'DISABLED'}`);
492
+
493
+ if (!runtimeDevtoolsEnabled) {
463
494
  console.warn('[JSG-LOGGER] DevTools disabled via config. Set devtools.enabled: true to enable.');
464
495
  return null;
465
496
  }
@@ -470,34 +501,34 @@ class JSGLogger {
470
501
  }
471
502
 
472
503
  try {
473
- // In development: import source files directly for hot reload
474
- // In production: import built bundle
475
- const isDev = import.meta.env?.DEV || window.location.hostname === 'localhost';
476
-
477
- let module;
478
- if (isDev) {
479
- console.log('🔥 DEV MODE: Attempting to load DevTools from SOURCE for hot reload');
480
- try {
481
- // Fix the import path for Vite dev server
482
- const importPath = '/src/panel-entry.jsx';
483
- console.log('🔍 Importing:', importPath);
484
- module = await import(/* @vite-ignore */ importPath);
485
- console.log('✅ Source import successful:', module);
486
- } catch (sourceError) {
487
- console.error('❌ Source import failed, falling back to bundle:', sourceError);
488
- const devtoolsPath = './devtools/dist/panel-entry.js';
489
- const dynamicImport = new Function('path', 'return import(path)');
490
- module = await dynamicImport(devtoolsPath);
504
+ // Use pre-loaded module (from default config) or load dynamically (consumer's runtime config override)
505
+ if (!devtoolsModule) {
506
+ // Check if we have a promise for pre-loading
507
+ if (devtoolsModulePromise) {
508
+ console.log('[JSG-LOGGER] Waiting for pre-loaded DevTools module...');
509
+ // Wait for pre-load to complete
510
+ devtoolsModule = await devtoolsModulePromise;
511
+ } else {
512
+ // Runtime config override: consumer enabled devtools but default was disabled
513
+ // Load on demand via dynamic import
514
+ console.log('[JSG-LOGGER] Loading DevTools module dynamically (runtime config override)...');
515
+ devtoolsModule = await import('./devtools/dist/panel-entry.js');
491
516
  }
492
517
  } else {
493
- console.log('📦 PROD MODE: Loading DevTools from built bundle');
494
- const devtoolsPath = './devtools/dist/panel-entry.js';
495
- const dynamicImport = new Function('path', 'return import(path)');
496
- module = await dynamicImport(devtoolsPath);
518
+ console.log('[JSG-LOGGER] Using pre-loaded DevTools module');
519
+ }
520
+
521
+ if (!devtoolsModule || !devtoolsModule.initializePanel) {
522
+ throw new Error('DevTools panel module missing initializePanel export');
497
523
  }
498
- return module.initializePanel();
524
+
525
+ console.log('[JSG-LOGGER] Initializing DevTools panel...');
526
+ const panel = devtoolsModule.initializePanel();
527
+ console.log('[JSG-LOGGER] DevTools panel initialized successfully');
528
+ return panel;
499
529
  } catch (error) {
500
530
  console.error('[JSG-LOGGER] Failed to load DevTools panel:', error);
531
+ console.error('[JSG-LOGGER] If using npm link, ensure Vite config has: server.fs.allow: [\'..\']');
501
532
  return null;
502
533
  }
503
534
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crimsonsunset/jsg-logger",
3
- "version": "1.5.5",
3
+ "version": "1.7.0",
4
4
  "type": "module",
5
5
  "description": "Multi-environment logger with smart detection, file-level overrides, and beautiful console formatting. Test it live: https://logger.joesangiorgio.com/",
6
6
  "main": "index.js",