claw-dashboard 2.1.1 → 2.2.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/docs/API.md +1 -2
  3. package/index.js +31 -41
  4. package/package.json +22 -12
  5. package/src/auto-save.js +11 -5
  6. package/src/cli/export-snapshot.js +3 -1
  7. package/src/cli/import-snapshot.js +3 -1
  8. package/src/config.js +9 -15
  9. package/src/errors.js +0 -9
  10. package/src/security.js +6 -2
  11. package/src/snapshot.js +73 -26
  12. package/src/web-server.js +7 -10
  13. package/.c8rc.json +0 -38
  14. package/.dockerignore +0 -68
  15. package/.github/dependabot.yml +0 -45
  16. package/.github/pull_request_template.md +0 -39
  17. package/.github/workflows/ci.yml +0 -147
  18. package/.github/workflows/release.yml +0 -40
  19. package/.github/workflows/security.yml +0 -84
  20. package/.husky/pre-commit +0 -1
  21. package/.planning/codebase/ARCHITECTURE.md +0 -206
  22. package/.planning/codebase/INTEGRATIONS.md +0 -150
  23. package/.planning/codebase/STACK.md +0 -122
  24. package/.planning/codebase/STRUCTURE.md +0 -201
  25. package/CONTRIBUTING.md +0 -378
  26. package/Dockerfile +0 -54
  27. package/FEATURES.md +0 -307
  28. package/TODO.md +0 -28
  29. package/ai.openclaw.dashboard.plist +0 -35
  30. package/build-cjs.js +0 -127
  31. package/cjs-shim.js +0 -13
  32. package/dist/clawdash +0 -1729
  33. package/dist/clawdash.meta.json +0 -2236
  34. package/dist/widgets.cjs +0 -6511
  35. package/docker-compose.yml +0 -67
  36. package/esbuild.config.js +0 -158
  37. package/eslint.config.js +0 -56
  38. package/examples/plugins/README.md +0 -122
  39. package/examples/plugins/api-status/index.js +0 -294
  40. package/examples/plugins/api-status/plugin.json +0 -19
  41. package/examples/plugins/hello-world/index.js +0 -104
  42. package/examples/plugins/hello-world/plugin.json +0 -15
  43. package/examples/plugins/system-metrics-chart/index.js +0 -339
  44. package/examples/plugins/system-metrics-chart/plugin.json +0 -18
  45. package/examples/plugins/weather-widget/index.js +0 -136
  46. package/examples/plugins/weather-widget/plugin.json +0 -19
  47. package/index.cjs +0 -23005
  48. package/jest.config.js +0 -11
  49. package/scripts/release.js +0 -595
  50. package/src/database.js +0 -734
  51. package/tests/alerts.test.js +0 -437
  52. package/tests/auto-save.test.js +0 -529
  53. package/tests/cache.test.js +0 -317
  54. package/tests/cli.test.js +0 -351
  55. package/tests/command-palette.test.js +0 -320
  56. package/tests/config-processor.test.js +0 -452
  57. package/tests/config-validator.test.js +0 -710
  58. package/tests/config-watcher.test.js +0 -594
  59. package/tests/config.test.js +0 -755
  60. package/tests/database.test.js +0 -438
  61. package/tests/errors.test.js +0 -189
  62. package/tests/example-plugins.test.js +0 -624
  63. package/tests/integration.test.js +0 -1321
  64. package/tests/loading-states.test.js +0 -300
  65. package/tests/manifest-validation-on-load.test.js +0 -671
  66. package/tests/performance-monitor.test.js +0 -190
  67. package/tests/plugin-api-rate-limit.test.js +0 -302
  68. package/tests/plugin-errors.test.js +0 -311
  69. package/tests/plugin-lifecycle-e2e.test.js +0 -1036
  70. package/tests/plugin-reload.test.js +0 -764
  71. package/tests/rate-limiter.test.js +0 -539
  72. package/tests/removed-dependencies.test.js +0 -74
  73. package/tests/retry.test.js +0 -308
  74. package/tests/security.test.js +0 -411
  75. package/tests/settings-modal.test.js +0 -226
  76. package/tests/theme-selector.test.js +0 -57
  77. package/tests/utils.js +0 -242
  78. package/tests/utils.test.js +0 -317
  79. package/tests/validate-plugin-cli.test.js +0 -359
  80. package/tests/validation.test.js +0 -837
  81. package/tests/web-server.test.js +0 -646
  82. package/tests/widget-arrange-mode.test.js +0 -183
  83. package/tests/widget-config-hot-reload.test.js +0 -465
  84. package/tests/widget-dependency.test.js +0 -591
  85. package/tests/widget-error-boundary.test.js +0 -749
  86. package/tests/widget-error-isolation.test.js +0 -469
  87. package/tests/widget-integration.test.js +0 -1147
  88. package/tests/widget-refresh-intervals.test.js +0 -284
  89. package/tests/worker-pool.test.js +0 -522
package/FEATURES.md DELETED
@@ -1,307 +0,0 @@
1
- # Claw Dashboard Feature History
2
-
3
- ## Features Tried
4
-
5
- ### Top Processes Widget
6
- - **Date tried**: 2026-02-11, 2026-02-12
7
- - **Status**: REMOVED - PERMANENTLY DECLINED
8
- - **Reason**: Layout issues (squeezed display, overflow problems)
9
- - **User feedback (2026-02-11)**: Declined for lack of interest
10
- - **User feedback (2026-02-12)**:
11
- 1. Redundant to previous rejection
12
- 2. **Colors render as markup** - blessed color tags showing literally instead of rendering
13
- 3. **Layout problems**: Split screen makes logs unreadable, limits visible content
14
- - **Re-added by**: Cron job 2026-02-12 (mistake - should not have been re-added)
15
- - **Action**: NEVER implement this feature again
16
-
17
- ### Disk Usage Sparkline
18
- - **Date tried**: 2026-02-15
19
- - **Status**: DECLINED
20
- - **Description**: Added sparkline visualization to disk widget showing disk usage history over time
21
- - **Reason declined**: Disk usage changes too slowly - sparkline provides no useful insight at 2s refresh intervals
22
- - **User feedback**: "Disk usage changes slowly. Spark line kind of useless."
23
- - **Version**: Not shipped
24
-
25
- ### Load Average Display
26
- - **Date tried**: 2026-02-15, 2026-02-18
27
- - **Status**: REJECTED
28
- - **Description**: Added 1/5/15 minute load average display to CPU widget detail line
29
- - **Implementation**:
30
- - Attempt 1 (2026-02-15): Added as new row in System widget (increased all widget heights)
31
- - Attempt 2 (2026-02-18): Moved to CPU box detail line, replacing "X cores" text
32
- - **Reason rejected**: Feature not needed
33
- - **User feedback**: "It would be better added to the cpu box to replace the middle line instead of changing the row size" (2026-02-15), then ultimately rejected 2026-02-18
34
- - **Version**: Not shipped
35
-
36
- ## Current Features (Retained)
37
-
38
- ### Core Features
39
- - System stats (CPU, memory, GPU, disk, network)
40
- - OpenClaw sessions list
41
- - OpenClaw agents list
42
- - Uptime tracking
43
- - OpenClaw logs
44
- - Settings panel
45
- - Web interface / Remote access (HTTP API)
46
-
47
- ### v2.0.0 Features
48
- - **Command Palette** (`Ctrl+K`) - Quick access to all commands
49
- - **Widget Arrangement Mode** (`w`) - Drag-and-drop widget reordering
50
- - **Widget Pinning** (`Alt+1-9`) - Pin favorites to top row
51
- - **Widget Size Presets** - Small/medium/large/wide per widget
52
- - **Dashboard Snapshots** (`Ctrl+S`/`Ctrl+O`) - Export/import state
53
- - **Auto-save** - State persistence with backup rotation
54
- - **Export Scheduling** - Automated cron-like metric exports
55
- - **Plugin System** - Scaffolding CLI, hot-reload, config UI
56
- - **Theme Selector** (`T`) - Interactive theme picker
57
- - **Performance Metrics Overlay** (`p`) - Memory, CPU, refresh stats
58
- - **Worker Thread Pool** - Background system info gathering
59
- - **Memory Pressure Detection** - Long-running session health
60
- - **Multi-gateway Support** - Multiple OpenClaw endpoints
61
- - **Gateway Auto-retry** - Exponential backoff for reconnections
62
- - **Widget Error Boundaries** - Isolate failures, retry UI (`X`)
63
- - **Auto Theme Detection** - Sync with system theme
64
-
65
- ## User Preferences
66
- - Prefer clean, uncluttered layout
67
- - Session list format should match `clawps` style
68
- - Memory calculation should exclude cache (Activity Monitor style)
69
- - No interest in top processes widget
70
-
71
- ## Pending Ideas
72
- - None currently
73
-
74
- ## Technical Notes
75
-
76
- ### Color Markup Fix (blessed)
77
- When colors show as literal text like `{green-fg}text{/green-fg}` instead of rendering:
78
- - **Cause**: Mixing blessed tags with plain strings, or improper tag formatting
79
- - **Fix**: Use blessed's `{color-fg}text{/color-fg}` format consistently
80
- - **Check**: Ensure `tags: true` is set on blessed text elements
81
- - **Avoid**: Concatenating tagged strings with plain strings incorrectly
82
-
83
- ### Layout Guidelines
84
- - Split-screen layouts reduce readability
85
- - Logs need full width to be useful
86
- - Avoid squeezing content into narrow columns
87
-
88
- ## Feature History
89
-
90
- ### Network Traffic Sparkline
91
- - **Date tried**: 2026-02-13
92
- - **Status**: SHIPPED
93
- - **Description**: Added sparkline visualization to network widget showing upload/download traffic history
94
- - **Implementation**: Combined RX+TX data displayed as activity sparkline, consistent with CPU/memory widgets
95
- - **Version**: v1.7.0
96
-
97
- ### Real-time Clock Widget
98
- - **Date tried**: 2026-02-13
99
- - **Status**: SHIPPED
100
- - **Description**: Added a real-time clock showing current time and date in the top-right corner of the dashboard
101
- - **Implementation**: Displays HH:MM:SS AM/PM format with date (e.g., "Feb 13"), updates every refresh cycle
102
- - **Timezone**: America/Chicago (CST) to match user's timezone
103
- - **Version**: v1.7.1
104
-
105
- ### Pause/Resume Refresh Feature
106
- - **Date tried**: 2026-02-14
107
- - **Status**: SHIPPED
108
- - **Description**: Added ability to pause and resume auto-refresh with 'p' or Space key
109
- - **Implementation**:
110
- - Press 'p' or Space to toggle pause state
111
- - When paused: clock shows [PAUSED] in yellow, footer shows "▶ running"
112
- - When running: footer shows "p pause"
113
- - Help panel updated with new key binding
114
- - **Version**: v1.7.2
115
-
116
- ### Network Traffic Sparkline Visualization
117
- - **Date tried**: 2026-02-15
118
- - **Status**: SHIPPED
119
- - **Description**: Added sparkline visualization to network widget showing combined RX+TX traffic history
120
- - **Implementation**:
121
- - Extended network widget height from 4 to 5 rows to accommodate sparkline
122
- - Added combined network activity sparkline (RX + TX data) displayed below interface name
123
- - Uses existing network history data (30 data points, ~60 seconds of history)
124
- - Adjusted log box position to prevent overlap (top: 23, height: 100%-24)
125
- - **Version**: v1.7.3
126
-
127
- ### Session Sorting Feature
128
- - **Date tried**: 2026-02-19
129
- - **Status**: SHIPPED
130
- - **Description**: Added ability to sort sessions by different criteria using the 'o' key
131
- - **Sort modes**:
132
- - `time`: Most recently updated first (default)
133
- - `tokens`: Highest token usage first
134
- - `idle`: Longest idle time first
135
- - `name`: Alphabetical by agent name
136
- - **Implementation**:
137
- - Press 'o' to cycle through sort modes
138
- - Current sort mode shown in footer and session box label
139
- - Setting persists across restarts
140
- - Updated help panel with new key binding
141
- - **Version**: v1.8.3
142
-
143
- ### Performance Monitoring Feature
144
- - **Date tried**: 2026-02-27
145
- - **Status**: SHIPPED
146
- - **Description**: Added performance metrics tracking and display for dashboard monitoring
147
- - **Metrics tracked**:
148
- - Memory usage (heap used/total, percentage)
149
- - CPU usage (process-specific)
150
- - Refresh rate
151
- - Event loop lag
152
- - Process uptime
153
- - **Implementation**:
154
- - Toggle via Settings panel ("Perf Metrics")
155
- - When enabled, shows live metrics in footer: MEM, CPU, refresh rate
156
- - Color-coded indicators (green/yellow/red) for memory and CPU levels
157
- - History tracking for sparkline visualization
158
- - **Version**: v1.9.0
159
-
160
- ### Web Interface / Remote Access Feature
161
- - **Date tried**: 2026-02-27
162
- - **Status**: SHIPPED
163
- - **Description**: Added web server mode for remote dashboard access via HTTP API
164
- - **Implementation**:
165
- - New `--web` CLI flag to run in web server mode (no TUI)
166
- - New `--web-port` flag to configure the port (default: 18790)
167
- - New `--web-host` flag to configure the bind host (default: 0.0.0.0)
168
- - REST API endpoints: `/health`, `/metrics`, `/sessions`, `/agents`, `/logs`, `/status`
169
- - CORS-enabled for cross-origin requests
170
- - JSON responses for all endpoints
171
- - Graceful shutdown handling
172
- - **Endpoints**:
173
- - `GET /health` - Health check with version and uptime
174
- - `GET /metrics` - System metrics (CPU, memory, GPU, disk, network)
175
- - `GET /sessions` - Active OpenClaw sessions
176
- - `GET /agents` - Available OpenClaw agents
177
- - `GET /logs` - Recent OpenClaw logs
178
- - `GET /status` - Full dashboard status (all data combined)
179
- - **Security**: API key authentication and rate limiting added in v2.0.0
180
- - **Version**: v1.10.0
181
-
182
- ### Command Palette Feature
183
- - **Date tried**: 2026-02-28
184
- - **Status**: SHIPPED (v2.0.0)
185
- - **Description**: Quick access to all dashboard commands via fuzzy search overlay
186
- - **Implementation**:
187
- - Press `Ctrl+K` to open command palette
188
- - Type to filter commands by name or description
189
- - Navigate with arrow keys, select with Enter
190
- - Categories: Navigation, Display, System, Widgets
191
- - Shows keyboard shortcuts for each command
192
- - **Version**: v2.0.0
193
-
194
- ### Widget Arrangement Mode
195
- - **Date tried**: 2026-02-28
196
- - **Status**: SHIPPED (v2.0.0)
197
- - **Description**: Drag-and-drop style widget reordering
198
- - **Implementation**:
199
- - Press `w` to enter arrangement mode
200
- - Use arrow keys to move focused widget
201
- - Press Escape or `w` again to exit
202
- - Layout persists across restarts
203
- - **Version**: v2.0.0
204
-
205
- ### Widget Pinning Feature
206
- - **Date tried**: 2026-02-28
207
- - **Status**: SHIPPED (v2.0.0)
208
- - **Description**: Pin up to 4 favorite widgets to a dedicated top row
209
- - **Implementation**:
210
- - Press `Alt+1` through `Alt+9` to pin/unpin widgets
211
- - Pinned widgets appear in a fixed top row
212
- - Independent from visibility toggles
213
- - Useful for keeping important widgets always visible
214
- - **Version**: v2.0.0
215
-
216
- ### Dashboard Snapshots
217
- - **Date tried**: 2026-02-28
218
- - **Status**: SHIPPED (v2.0.0)
219
- - **Description**: Export and import dashboard state as shareable JSON files
220
- - **Implementation**:
221
- - Press `Ctrl+S` to export current state (settings, widget visibility, sizes, positions)
222
- - Press `Ctrl+O` to import a previously saved snapshot
223
- - Useful for sharing configurations across machines or backing up preferences
224
- - **Version**: v2.0.0
225
-
226
- ### Auto-save System
227
- - **Date tried**: 2026-02-28
228
- - **Status**: SHIPPED (v2.0.0)
229
- - **Description**: Automatic state persistence with crash recovery
230
- - **Implementation**:
231
- - Saves state every 30 seconds (configurable)
232
- - Maintains last 5 backups with rotation
233
- - Restores on startup: session selection, search query, favorites filter, widget focus
234
- - Configurable via settings (interval, saveOnExit)
235
- - **Version**: v2.0.0
236
-
237
- ### Plugin System
238
- - **Date tried**: 2026-02-28
239
- - **Status**: SHIPPED (v2.0.0)
240
- - **Description**: Extensible widget plugin architecture with scaffolding
241
- - **Implementation**:
242
- - Interactive scaffolding CLI: `clawdash plugin:create`
243
- - Plugin hot-reload with `--watch` flag for development
244
- - Plugin configuration UI in settings panel
245
- - Manifest validation on load
246
- - Pre-commit hooks with lint-staged
247
- - **Version**: v2.0.0
248
-
249
- ### Theme Selector UI
250
- - **Date tried**: 2026-02-28
251
- - **Status**: SHIPPED (v2.0.0)
252
- - **Description**: Interactive theme picker with live preview
253
- - **Implementation**:
254
- - Press `T` to open theme selector
255
- - Navigate with arrow keys, preview live
256
- - Themes: default, dark, high-contrast, ocean, auto (system sync)
257
- - Auto theme detection syncs with system theme changes
258
- - **Version**: v2.0.0
259
-
260
- ### Worker Thread Pool
261
- - **Date tried**: 2026-02-28
262
- - **Status**: SHIPPED (v2.0.0)
263
- - **Description**: Offload heavy system info gathering to background threads
264
- - **Implementation**:
265
- - Configurable worker pool for systeminformation calls
266
- - Graceful degradation when workers unavailable
267
- - Prevents UI blocking during expensive operations
268
- - Status shown in performance overlay
269
- - **Version**: v2.0.0
270
-
271
- ### Multi-gateway Support
272
- - **Date tried**: 2026-02-28
273
- - **Status**: SHIPPED (v2.0.0)
274
- - **Description**: Connect to multiple OpenClaw endpoints
275
- - **Implementation**:
276
- - Configure multiple gateways in settings
277
- - Visual indicator in footer shows gateway status
278
- - Per-gateway health monitoring
279
- - Auto-retry with exponential backoff for failed connections
280
- - **Version**: v2.0.0
281
-
282
- ### Widget Error Boundaries
283
- - **Date tried**: 2026-02-28
284
- - **Status**: SHIPPED (v2.0.0)
285
- - **Description**: Isolate widget failures from crashing entire dashboard
286
- - **Implementation**:
287
- - Failed widgets show error state with retry button
288
- - Press `X` to retry all failed widgets
289
- - Other widgets continue operating normally
290
- - Error details logged for debugging
291
- - **Version**: v2.0.0
292
-
293
- ## Version History
294
- - v1.5.1: Baseline
295
- - v1.6.0: Session list improvements, memory calculation fix
296
- - v1.7.0: **REVERT** - top processes added then removed
297
- - v1.7.0 (new): Network traffic sparkline visualization
298
- - v1.7.1: Real-time clock widget
299
- - v1.7.2: Pause/resume refresh feature
300
- - v1.7.3: Network sparkline widget enhancement
301
- - v1.7.4: Disk usage sparkline visualization (DECLINED - not useful)
302
- - v1.7.5: Load average display (REJECTED)
303
- - v1.8.1: Session list improvements
304
- - v1.8.2: Session sorting feature
305
- - v1.8.3: Session sorting enhancements
306
- - v1.9.0: Performance monitoring, web interface
307
- - v2.0.0: **MAJOR** - Command palette, widget system overhaul, snapshots, auto-save, plugin system, theme selector, multi-gateway, worker threads, error boundaries
package/TODO.md DELETED
@@ -1,28 +0,0 @@
1
- ## TODO
2
-
3
- ## Backlog
4
-
5
- - Document command palette feature in README.md
6
- - Integration test for command palette execution flow
7
- - E2E test for Ctrl+K keybinding
8
- - Plugin marketplace/discovery - Community registry index
9
- - Session quick-switcher - Ctrl+K fuzzy finder for profiles
10
- - WebSocket support - Push-based real-time updates
11
- - Multiple dashboard profiles - Tabbed navigation
12
- - Widget grouping/collapsing - Organize dense dashboards
13
- - Conditional widget visibility - Show/hide based on data thresholds
14
- - Dashboard layout templates - Preset layouts for different roles
15
- - Historical data persistence - SQLite/LevelDB backend
16
- - Trend indicators - Compare vs historical averages
17
- - Anomaly detection alerts - Automatic spike detection
18
- - Webhook notifications - Threshold breach alerts (Slack/Discord)
19
- - OpenClaw event stream - Consume events from gateway
20
- - Plugin sandbox - Node.js VM isolation
21
- - Widget playground - Live preview during development
22
- - Plugin publishing CLI - npm-style workflow
23
-
24
- ## Technical Debt
25
-
26
- - Test coverage - Improve from ~43% to 70%+
27
- - TypeScript migration - Start with validation.js/security.js
28
- - JSDoc completion - Complete PluginAPI public methods
@@ -1,35 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>Label</key>
6
- <string>ai.openclaw.dashboard</string>
7
- <key>ProgramArguments</key>
8
- <array>
9
- <string>/bin/bash</string>
10
- <string>-l</string>
11
- <string>-c</string>
12
- <string>clawdash</string>
13
- </array>
14
- <key>RunAtLoad</key>
15
- <true/>
16
- <key>KeepAlive</key>
17
- <dict>
18
- <key>SuccessfulExit</key>
19
- <false/>
20
- </dict>
21
- <key>StandardOutPath</key>
22
- <string>/tmp/openclaw/dashboard.out</string>
23
- <key>StandardErrorPath</key>
24
- <string>/tmp/openclaw/dashboard.err</string>
25
- <key>EnvironmentVariables</key>
26
- <dict>
27
- <key>PATH</key>
28
- <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/bin</string>
29
- <key>TERM</key>
30
- <string>xterm-256color</string>
31
- </dict>
32
- <key>ProcessType</key>
33
- <string>Interactive</string>
34
- </dict>
35
- </plist>
package/build-cjs.js DELETED
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Build CJS wrappers for dual-package exports
5
- * Creates CJS versions of ESM modules for backward compatibility
6
- */
7
-
8
- import * as esbuild from 'esbuild';
9
- import { writeFileSync, mkdirSync, existsSync, readFileSync } from 'fs';
10
- import { dirname, join } from 'path';
11
- import { fileURLToPath } from 'url';
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
15
-
16
- // Custom plugin to replace import.meta.url with a CJS-compatible version
17
- const cjsImportMetaPlugin = {
18
- name: 'cjs-import-meta',
19
- setup(build) {
20
- // Filter only JS files
21
- const filter = /\.js$/;
22
-
23
- build.onLoad({ filter }, async (args) => {
24
- const contents = await readFileSync(args.path, 'utf8');
25
-
26
- // Replace import.meta.url with a CJS-compatible expression
27
- // We use process.cwd() as fallback since we can't know the actual file location
28
- const newContents = contents.replace(
29
- /import\.meta\.url/g,
30
- "'file://' + (typeof __dirname !== 'undefined' ? require('path').join(__dirname, 'index.js').replace(/\\\\/g, '/') : process.cwd() + '/index.js')"
31
- );
32
-
33
- return { contents: newContents, loader: 'js' };
34
- });
35
- },
36
- };
37
-
38
- // Build config for widgets CJS bundle
39
- const widgetsCjsConfig = {
40
- entryPoints: ['src/widgets/index.js'],
41
- bundle: true,
42
- platform: 'node',
43
- target: 'node18',
44
- outfile: 'dist/widgets.cjs',
45
- format: 'cjs',
46
- external: ['blessed', 'blessed-contrib', 'systeminformation'],
47
- minify: false,
48
- sourcemap: false,
49
- plugins: [cjsImportMetaPlugin],
50
- };
51
-
52
- // Build config for main CJS bundle
53
- const mainCjsConfig = {
54
- entryPoints: ['index.js'],
55
- bundle: true,
56
- platform: 'node',
57
- target: 'node18',
58
- outfile: 'index.cjs',
59
- format: 'cjs',
60
- external: ['blessed', 'blessed-contrib', 'systeminformation'],
61
- minify: false,
62
- sourcemap: false,
63
- plugins: [cjsImportMetaPlugin],
64
- };
65
-
66
- async function buildCjs(config, name) {
67
- console.log(`Building CJS ${name}...`);
68
- try {
69
- const result = await esbuild.build({
70
- ...config,
71
- write: false,
72
- });
73
-
74
- let output = result.outputFiles[0].text;
75
-
76
- // Extract shebang if present (must be at the very start)
77
- let shebang = '';
78
- const shebangMatch = output.match(/^#![^\n]*\n/);
79
- if (shebangMatch) {
80
- shebang = shebangMatch[0];
81
- output = output.slice(shebang.length);
82
- }
83
-
84
- // Also remove any shebang that might appear later in the file
85
- output = output.replace(/#![^\n]*\n/g, '');
86
-
87
- // Post-process: add __dirname polyfill at the start of the bundle
88
- const polyfill = `// Polyfill for __dirname in CJS bundle
89
- var path = require('path');
90
- var __filename = process.argv[1] || process.cwd() + '/index.js';
91
- var __dirname = path.dirname(__filename);
92
- `;
93
-
94
- // Add shebang first, then polyfill after 'use strict' if present
95
- if (output.startsWith('"use strict";')) {
96
- output = shebang + '"use strict";\n' + polyfill + output.slice('"use strict";'.length);
97
- } else {
98
- output = shebang + polyfill + output;
99
- }
100
-
101
- writeFileSync(config.outfile, output, { mode: 0o755 });
102
- console.log(`✓ CJS ${name} built: ${config.outfile}`);
103
- return true;
104
- } catch (error) {
105
- console.error(`✗ CJS ${name} build failed:`, error.message);
106
- return false;
107
- }
108
- }
109
-
110
- async function main() {
111
- // Ensure dist directory exists
112
- if (!existsSync('dist')) {
113
- mkdirSync('dist', { recursive: true });
114
- }
115
-
116
- const widgetsResult = await buildCjs(widgetsCjsConfig, 'widgets');
117
- const mainResult = await buildCjs(mainCjsConfig, 'main');
118
-
119
- if (widgetsResult && mainResult) {
120
- console.log('✓ All CJS builds completed');
121
- process.exit(0);
122
- } else {
123
- process.exit(1);
124
- }
125
- }
126
-
127
- main();
package/cjs-shim.js DELETED
@@ -1,13 +0,0 @@
1
- // CJS shim for import.meta.url polyfill
2
- // This file is injected into CJS builds to provide __dirname
3
-
4
- const path = require('path');
5
- const { fileURLToPath } = require('url');
6
-
7
- // Check if we're in a bundled environment or regular CJS
8
- if (typeof __filename === 'undefined') {
9
- // In bundled CJS, process.cwd() is used
10
- global.__dirname = path.dirname(process.execPath);
11
- } else {
12
- global.__dirname = path.dirname(__filename);
13
- }