@kfiross44/valtio-inspector 0.9.0 → 0.9.2

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.
@@ -4,7 +4,7 @@
4
4
  "commit": false,
5
5
  "fixed": [],
6
6
  "linked": [],
7
- "access": "restricted",
7
+ "access": "public",
8
8
  "baseBranch": "main",
9
9
  "updateInternalDependencies": "patch",
10
10
  "ignore": []
@@ -1 +1 @@
1
- {"version":3,"file":"attachInspector.d.ts","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GAAG;IACnB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,GACrB,MAAM,IAAI,CAmFZ"}
1
+ {"version":3,"file":"attachInspector.d.ts","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GAAG;IACnB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI,CAsCjF"}
@@ -16,53 +16,17 @@ function attachInspector(state, options) {
16
16
  return () => { };
17
17
  }
18
18
  const { name, debounce = 100, inspectorUrl = 'http://localhost:7777' } = options;
19
- const wsUrl = inspectorUrl.replace('http', 'ws');
20
19
  let timeout = null;
21
- let ws = null;
22
- let reconnectAttempts = 0;
23
- const queue = [];
24
- function connect() {
25
- ws = new WebSocket(wsUrl);
26
- ws.onopen = () => {
27
- reconnectAttempts = 0;
28
- // flush queue
29
- while (queue.length) {
30
- ws.send(JSON.stringify(queue.shift()));
31
- }
32
- };
33
- ws.onclose = () => {
34
- const delay = Math.min(1000 * 2 ** reconnectAttempts, 10000);
35
- reconnectAttempts++;
36
- setTimeout(connect, delay);
37
- };
38
- ws.onerror = () => {
39
- ws?.close();
40
- };
41
- }
42
20
  function send() {
43
- const payload = {
44
- store: name,
45
- data: (0, valtio_1.snapshot)(state)
46
- };
47
- // try WS first
48
- if (ws && ws.readyState === WebSocket.OPEN) {
49
- ws.send(JSON.stringify(payload));
50
- }
51
- else {
52
- // queue for later
53
- queue.push(payload);
54
- // fallback to HTTP (optional)
55
- fetch(`${inspectorUrl}/state`, {
56
- method: 'POST',
57
- headers: { 'Content-Type': 'application/json' },
58
- body: JSON.stringify(payload)
59
- }).catch(() => {
60
- // Inspector not running — fail silently
61
- });
62
- }
21
+ const data = (0, valtio_1.snapshot)(state);
22
+ fetch(`${inspectorUrl}/state`, {
23
+ method: 'POST',
24
+ headers: { 'Content-Type': 'application/json' },
25
+ body: JSON.stringify({ store: name, data })
26
+ }).catch(() => {
27
+ // Inspector not running — fail silently
28
+ });
63
29
  }
64
- // init connection
65
- connect();
66
30
  // Send initial snapshot immediately
67
31
  send();
68
32
  const unsubscribe = (0, valtio_1.subscribe)(state, () => {
@@ -70,11 +34,11 @@ function attachInspector(state, options) {
70
34
  clearTimeout(timeout);
71
35
  timeout = setTimeout(send, debounce);
72
36
  });
37
+ // Return cleanup function
73
38
  return () => {
74
39
  if (timeout)
75
40
  clearTimeout(timeout);
76
41
  unsubscribe();
77
- ws?.close();
78
42
  };
79
43
  }
80
44
  //# sourceMappingURL=attachInspector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attachInspector.js","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":";;AAmBA,0CAsFC;AAzGD,mCAA4C;AAW5C;;;;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Ae,CAAC,KAAa,EAAE,OAAsB;IACnE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACpE,gCAAgC;QAChC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACjB,CAAC;IAED,MAAM,EACJ,IAAI,EACJ,QAAQ,GAAG,GAAG,EACd,YAAY,GAAG,uBAAuB,EACvC,GAAG,OAAO,CAAA;IAEX,IAAI,OAAO,GAAyC,IAAI,CAAA;IAExD,SAAS,IAAI;QACX,MAAM,IAAI,GAAG,IAAA,iBAAQ,EAAC,KAAK,CAAC,CAAA;QAC5B,KAAK,CAAC,GAAG,YAAY,QAAQ,EAAE;YAC7B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;SAC5C,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACZ,wCAAwC;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE,CAAA;IAEN,MAAM,WAAW,GAAG,IAAA,kBAAS,EAAC,KAAK,EAAE,GAAG,EAAE;QACxC,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAA;QAClC,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,0BAA0B;IAC1B,OAAO,GAAG,EAAE;QACV,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAA;QAClC,WAAW,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
package/dist/cli.js CHANGED
@@ -2,5 +2,19 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const server_1 = require("./server");
5
- (0, server_1.startServer)();
5
+ console.log("🚀 Inspector server is starting...");
6
+ try {
7
+ (0, server_1.startServer)();
8
+ }
9
+ catch (err) {
10
+ console.error("💥 CRITICAL ERROR DURING STARTUP:", err);
11
+ process.exit(1);
12
+ }
13
+ // תפיסת שגיאות אסינכרוניות שלא נתפסו
14
+ process.on('uncaughtException', (err) => {
15
+ console.error('🔥 Uncaught Exception:', err);
16
+ });
17
+ process.on('unhandledRejection', (reason, promise) => {
18
+ console.error('⚠️ Unhandled Rejection at:', promise, 'reason:', reason);
19
+ });
6
20
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,qCAAuC;AAEvC,IAAA,oBAAW,GAAE,CAAC"}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,qCAAuC;AAEvC,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAElD,IAAI,CAAC;IACH,IAAA,oBAAW,GAAE,CAAC;AAChB,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,qCAAqC;AACrC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;IACnD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@kfiross44/valtio-inspector",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "A dev-only Valtio state inspector with WebSocket live updates",
5
5
  "main": "dist/server/index.js",
6
6
  "bin": {
7
7
  "valtio-inspector": "dist/cli.js"
8
8
  },
9
9
  "scripts": {
10
- "dev": "ts-node server/index.ts",
10
+ "dev": "ts-node src/cli.ts",
11
11
  "build": "tsc",
12
- "release": "bun run build && changeset publish",
12
+ "release": "bun run build && changeset publish --access public",
13
13
  "start": "node dist/server/index.js"
14
14
  },
15
15
  "dependencies": {
@@ -17,10 +17,7 @@ type AttachOptions = {
17
17
  *
18
18
  * ⚠️ Wrap in process.env.NODE_ENV !== 'production' to exclude from builds.
19
19
  */
20
- export function attachInspector(
21
- state: object,
22
- options: AttachOptions
23
- ): () => void {
20
+ export function attachInspector(state: object, options: AttachOptions): () => void {
24
21
  if (typeof window === 'undefined' && typeof process !== 'undefined') {
25
22
  // Node.js / SSR — skip silently
26
23
  return () => {}
@@ -32,64 +29,19 @@ export function attachInspector(
32
29
  inspectorUrl = 'http://localhost:7777'
33
30
  } = options
34
31
 
35
- const wsUrl = inspectorUrl.replace('http', 'ws')
36
-
37
32
  let timeout: ReturnType<typeof setTimeout> | null = null
38
- let ws: WebSocket | null = null
39
- let reconnectAttempts = 0
40
- const queue: any[] = []
41
-
42
- function connect() {
43
- ws = new WebSocket(wsUrl)
44
-
45
- ws.onopen = () => {
46
- reconnectAttempts = 0
47
-
48
- // flush queue
49
- while (queue.length) {
50
- ws!.send(JSON.stringify(queue.shift()))
51
- }
52
- }
53
-
54
- ws.onclose = () => {
55
- const delay = Math.min(1000 * 2 ** reconnectAttempts, 10000)
56
- reconnectAttempts++
57
-
58
- setTimeout(connect, delay)
59
- }
60
-
61
- ws.onerror = () => {
62
- ws?.close()
63
- }
64
- }
65
33
 
66
34
  function send() {
67
- const payload = {
68
- store: name,
69
- data: snapshot(state)
70
- }
71
-
72
- // try WS first
73
- if (ws && ws.readyState === WebSocket.OPEN) {
74
- ws.send(JSON.stringify(payload))
75
- } else {
76
- // queue for later
77
- queue.push(payload)
78
-
79
- // fallback to HTTP (optional)
80
- fetch(`${inspectorUrl}/state`, {
81
- method: 'POST',
82
- headers: { 'Content-Type': 'application/json' },
83
- body: JSON.stringify(payload)
84
- }).catch(() => {
85
- // Inspector not running — fail silently
86
- })
87
- }
35
+ const data = snapshot(state)
36
+ fetch(`${inspectorUrl}/state`, {
37
+ method: 'POST',
38
+ headers: { 'Content-Type': 'application/json' },
39
+ body: JSON.stringify({ store: name, data })
40
+ }).catch(() => {
41
+ // Inspector not running fail silently
42
+ })
88
43
  }
89
44
 
90
- // init connection
91
- connect()
92
-
93
45
  // Send initial snapshot immediately
94
46
  send()
95
47
 
@@ -98,9 +50,9 @@ export function attachInspector(
98
50
  timeout = setTimeout(send, debounce)
99
51
  })
100
52
 
53
+ // Return cleanup function
101
54
  return () => {
102
55
  if (timeout) clearTimeout(timeout)
103
56
  unsubscribe()
104
- ws?.close()
105
57
  }
106
- }
58
+ }
package/src/cli.ts CHANGED
@@ -2,4 +2,20 @@
2
2
 
3
3
  import { startServer } from './server';
4
4
 
5
- startServer();
5
+ console.log("🚀 Inspector server is starting...");
6
+
7
+ try {
8
+ startServer();
9
+ } catch (err) {
10
+ console.error("💥 CRITICAL ERROR DURING STARTUP:", err);
11
+ process.exit(1);
12
+ }
13
+
14
+ // תפיסת שגיאות אסינכרוניות שלא נתפסו
15
+ process.on('uncaughtException', (err) => {
16
+ console.error('🔥 Uncaught Exception:', err);
17
+ });
18
+
19
+ process.on('unhandledRejection', (reason, promise) => {
20
+ console.error('⚠️ Unhandled Rejection at:', promise, 'reason:', reason);
21
+ });