@techninja/clearstack 0.3.46 → 0.3.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techninja/clearstack",
3
- "version": "0.3.46",
3
+ "version": "0.3.47",
4
4
  "type": "module",
5
5
  "description": "A no-build web component framework specification — scaffold, validate, and evolve spec-compliant projects",
6
6
  "bin": {
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import express from 'express';
7
+ import { watch } from 'node:fs';
7
8
  import { entityRouter } from './api/entities.js';
8
9
  import { eventsRouter } from './api/events.js';
9
10
 
@@ -14,6 +15,20 @@ app.use(express.json());
14
15
  app.use('/api', eventsRouter);
15
16
  app.use('/api', entityRouter);
16
17
 
18
+ /** @type {Set<import('node:http').ServerResponse>} */
19
+ const reloadClients = new Set();
20
+
21
+ app.get('/_reload', (req, res) => {
22
+ res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
23
+ res.write(': connected\n\n');
24
+ reloadClients.add(res);
25
+ req.on('close', () => reloadClients.delete(res));
26
+ });
27
+
28
+ watch('src', { recursive: true }, () => {
29
+ for (const res of reloadClients) res.write('event: reload\ndata: {}\n\n');
30
+ });
31
+
17
32
  app.use(express.static('src'));
18
33
 
19
34
  // SPA fallback
@@ -38,6 +38,12 @@
38
38
  <app-router></app-router>
39
39
  <script type="module" src="/router/index.js"></script>
40
40
  <script>
41
+ // Hot reload
42
+ (function () {
43
+ const es = new EventSource('/_reload');
44
+ es.addEventListener('reload', () => location.reload());
45
+ es.onerror = () => { es.close(); setTimeout(() => location.reload(), 500); };
46
+ })();
41
47
  // Global error boundary — catches unhandled promise rejections and JS errors
42
48
  window.addEventListener('unhandledrejection', (e) => {
43
49
  console.error('[app] Unhandled rejection:', e.reason);
@@ -4,10 +4,25 @@
4
4
  */
5
5
 
6
6
  import express from 'express';
7
+ import { watch } from 'node:fs';
7
8
 
8
9
  /** @type {any} */
9
10
  const app = express();
10
11
 
12
+ /** @type {Set<import('node:http').ServerResponse>} */
13
+ const reloadClients = new Set();
14
+
15
+ app.get('/_reload', (req, res) => {
16
+ res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
17
+ res.write(': connected\n\n');
18
+ reloadClients.add(res);
19
+ req.on('close', () => reloadClients.delete(res));
20
+ });
21
+
22
+ watch('src', { recursive: true }, () => {
23
+ for (const res of reloadClients) res.write('event: reload\ndata: {}\n\n');
24
+ });
25
+
11
26
  app.use(express.static('src'));
12
27
 
13
28
  app.use((req, res, next) => {