@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/CHANGELOG.md CHANGED
@@ -5,23 +5,58 @@ All notable changes to the JSG Logger project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [1.6.0] - 2025-01-XX 🎯 **Config-Driven Tree-Shaking & Enhanced Logging**
9
9
 
10
10
  ### Added
11
- - **Conditional DevTools Bundling** - DevTools panel now optional via config, with tree-shaking support
12
- - Added `devtools.enabled` config flag (default: `false`)
13
- - Moved Preact & Evergreen UI to optional peerDependencies
14
- - When disabled, devtools code is tree-shaken out (zero bundle impact)
15
- - When enabled, requires peer dependencies: `npm install preact evergreen-ui`
16
- - Function constructor used for dynamic imports to bypass Vite static analysis
11
+ - **Config-Driven Tree-Shaking** - DevTools panel tree-shaking now based on default config at module load time
12
+ - Tree-shaking determined by `defaultConfig.devtools.enabled` (default: `false`)
13
+ - When disabled, devtools code completely tree-shaken (zero bundle impact)
14
+ - When enabled via runtime config, loads dynamically on demand
15
+ - Static import analysis allows bundlers to eliminate unused code paths
16
+ - **Comprehensive DevTools Logging** - Added detailed logging throughout DevTools lifecycle
17
+ - Module load: logs default config tree-shaking status
18
+ - Config loading: logs when devtools enabled/disabled via user config
19
+ - DevTools activation: logs pre-load status, dynamic loading, and initialization steps
20
+ - Config merge: logs devtools status changes between defaults and user config
17
21
 
18
22
  ### Changed
19
- - **DevTools Dependencies** - Preact and Evergreen UI moved to peerDependencies for optional installation
20
- - **DevTools Import** - Uses Function constructor instead of template literals to prevent Vite static analysis failures
23
+ - **DevTools Import Strategy** - Simplified to relative path imports
24
+ - Removed complex Function constructor + package export path logic
25
+ - Uses simple relative path: `./devtools/dist/panel-entry.js`
26
+ - Works in production builds, requires `server.fs.allow: ['..']` for npm link dev
27
+ - **Config Loading Logging** - Enhanced visibility into config loading process
28
+ - Logs config source (file path vs inline object)
29
+ - Logs devtools status before/after config merge
30
+ - Logs initialization start with config source information
21
31
 
22
32
  ### Fixed
23
- - **Vite Build Failures** - Fixed dynamic import issues that caused Vite dev server startup failures
24
- - **DevTools Bundle Size** - Zero impact when disabled (default), only loads when explicitly enabled
33
+ - **Tree-Shaking Detection** - Bundlers can now properly analyze and eliminate devtools code when disabled
34
+ - **DevTools Pre-loading** - Non-blocking pre-load when default config enables devtools
35
+ - **Runtime Config Override** - Dynamic loading works correctly when runtime config enables devtools but default disabled
36
+
37
+ ### Technical Details
38
+ - **File**: `index.js`
39
+ - Added conditional static import based on `defaultConfig.devtools.enabled`
40
+ - Lazy initialization pattern to avoid top-level await
41
+ - Enhanced `enableDevPanel()` with comprehensive logging
42
+ - Pre-loads devtools module when default config enables it
43
+
44
+ - **File**: `config/config-manager.js`
45
+ - Added logging for config loading (file vs inline)
46
+ - Added devtools status logging before/after config merge
47
+ - Enhanced visibility into config changes
48
+
49
+ ### Migration Notes
50
+ No breaking changes. Existing code continues to work.
51
+
52
+ **For consumers:**
53
+ - DevTools code tree-shaken by default (zero bundle impact)
54
+ - Enable via runtime config: `{ devtools: { enabled: true } }`
55
+ - DevTools loads dynamically when `enableDevPanel()` called
56
+ - No special Vite config needed for production builds
57
+ - npm link users: add `server.fs.allow: ['..']` to Vite config for dev
58
+
59
+ ## [Unreleased]
25
60
 
26
61
  ## [1.5.2] - 2025-10-25 🐛 **PATCH: CLI Formatter Custom Component Display**
27
62
 
package/README.md CHANGED
@@ -560,6 +560,14 @@ logger.controls.addFileOverride('src/popup.js', { // Debug popup
560
560
 
561
561
  JSG Logger includes an optional DevTools panel for visual debugging. The panel is **disabled by default** to keep bundle size minimal.
562
562
 
563
+ ### **How Tree-Shaking Works**
564
+
565
+ Tree-shaking is based on the **default config** (`devtools.enabled: false` by default). This means:
566
+
567
+ - **Default behavior**: DevTools code is completely tree-shaken out, resulting in zero bundle impact
568
+ - **Consumer config override**: If you enable devtools in your runtime config (`{ devtools: { enabled: true } }`), it loads dynamically when needed
569
+ - **Best of both worlds**: Zero bundle by default, but runtime flexibility when needed
570
+
563
571
  ### **Enabling DevTools**
564
572
 
565
573
  1. **Enable in config:**
@@ -571,12 +579,14 @@ JSG Logger includes an optional DevTools panel for visual debugging. The panel i
571
579
  }
572
580
  ```
573
581
 
574
- 2. **Install peer dependencies** (only needed when devtools enabled):
575
- ```bash
576
- npm install preact evergreen-ui
582
+ Or enable at runtime:
583
+ ```javascript
584
+ const logger = JSGLogger.getInstance({
585
+ devtools: { enabled: true }
586
+ });
577
587
  ```
578
588
 
579
- 3. **Enable the panel:**
589
+ 2. **Enable the panel:**
580
590
  ```javascript
581
591
  // Enable DevTools panel (only works if devtools.enabled: true in config)
582
592
  await logger.controls.enableDevPanel();
@@ -590,7 +600,19 @@ await logger.controls.enableDevPanel();
590
600
  - ⚙️ Display option toggles
591
601
  - 📈 Component-level monitoring
592
602
 
593
- **Note:** When `devtools.enabled: false` (default), devtools dependencies are completely tree-shaken out, resulting in zero bundle impact. Only enable when you need the visual debugging interface.
603
+ **Bundle Size:**
604
+ - When `devtools.enabled: false` (default): Zero bundle impact (tree-shaken)
605
+ - When enabled: ~81KB gzipped (includes Preact + Evergreen UI, self-contained)
606
+
607
+ **Note for npm link users:** When developing with `npm link`, ensure your Vite config includes:
608
+ ```typescript
609
+ server: {
610
+ fs: {
611
+ allow: ['..']
612
+ }
613
+ }
614
+ ```
615
+ This allows Vite to serve files from the symlinked package directory.
594
616
 
595
617
  ## 🔧 **Browser Developer Tools**
596
618
 
@@ -25,18 +25,35 @@ export class ConfigManager {
25
25
 
26
26
  if (typeof configSource === 'string') {
27
27
  // Load from file path - handle all path formats
28
+ console.log(`[JSG-LOGGER] Loading config from file: ${configSource}`);
28
29
  externalConfig = await this._loadConfigFromPath(configSource);
29
30
  } else if (typeof configSource === 'object') {
30
31
  // Direct config object
32
+ console.log('[JSG-LOGGER] Loading inline config object:', Object.keys(configSource));
31
33
  externalConfig = configSource;
32
34
  }
33
35
 
34
36
  // Normalize external config to match expected structure
35
37
  const normalizedConfig = this._normalizeConfigStructure(externalConfig);
36
38
 
39
+ // Log devtools status before merge
40
+ const devtoolsBefore = this.config.devtools?.enabled ?? false;
41
+ const devtoolsAfter = normalizedConfig.devtools?.enabled ?? devtoolsBefore;
42
+
37
43
  // Merge configurations - project configs override defaults
38
44
  this.config = this.mergeConfigs(this.config, normalizedConfig);
39
45
 
46
+ // Log devtools activation status
47
+ const finalDevtoolsEnabled = this.config.devtools?.enabled ?? false;
48
+ if (finalDevtoolsEnabled !== devtoolsBefore) {
49
+ console.log(`[JSG-LOGGER] DevTools ${finalDevtoolsEnabled ? 'ENABLED' : 'DISABLED'} via user config (was ${devtoolsBefore ? 'enabled' : 'disabled'} in defaults)`);
50
+ if (finalDevtoolsEnabled) {
51
+ console.log('[JSG-LOGGER] DevTools will be available when enableDevPanel() is called');
52
+ }
53
+ } else {
54
+ console.log(`[JSG-LOGGER] DevTools status: ${finalDevtoolsEnabled ? 'ENABLED' : 'DISABLED'} (using default config)`);
55
+ }
56
+
40
57
  return this.config;
41
58
  } catch (error) {
42
59
  console.error('ConfigManager: Error loading configuration:', error);