@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.
- package/.changeset/config.json +1 -1
- package/dist/attachInspector.d.ts.map +1 -1
- package/dist/attachInspector.js +9 -45
- package/dist/attachInspector.js.map +1 -1
- package/dist/cli.js +15 -1
- package/dist/cli.js.map +1 -1
- package/kfiross44-valtio-inspector-0.9.0.tgz +0 -0
- package/package.json +3 -3
- package/src/attachInspector.ts +11 -59
- package/src/cli.ts +17 -1
- package/kfiross44-valtio-inspector-1.0.0.tgz +0 -0
package/.changeset/config.json
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/attachInspector.js
CHANGED
|
@@ -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
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"attachInspector.js","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":";;AAmBA,0CAsCC;AAzDD,mCAA4C;AAW5C;;;;;;;GAOG;AACH,SAAgB,eAAe,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
|
-
(
|
|
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"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kfiross44/valtio-inspector",
|
|
3
|
-
"version": "0.9.
|
|
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
|
|
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": {
|
package/src/attachInspector.ts
CHANGED
|
@@ -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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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
|
+
});
|
|
Binary file
|