@joystick.js/cli-canary 0.0.0-canary.610 → 0.0.0-canary.612
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p from"query-string";import{WebSocketServer as i}from"ws";import g from"../generate_id.js";import N from"./get_translations.js";process.title="joystick_hmr";var u=(()=>{const a=new i({port:parseInt(process.env.PORT,10)+1,path:"/_joystick/hmr"});process.on("message",async c=>{const e=JSON.parse(c);if(typeof process.HMR_CONNECTIONS=="object"&&e?.type){const t=Object.values(process.HMR_CONNECTIONS);for(let n=0;n<t?.length;n+=1){const s=t[n];s?.connection?.send&&(e?.type==="BUILD_ERROR"&&s.connection.send(JSON.stringify({type:"BUILD_ERROR"})),e?.type==="FILE_CHANGE"&&s.connection.send(JSON.stringify({type:"FILE_CHANGE",settings:e?.settings?{global:e?.settings?.global,public:e?.settings?.public}:null,i18n:e?.i18n_change?await N("./.joystick/build",s?.page_component_path,{headers:{"accept-language":s?.browser_language},context:{user:{language:s?.user_language}}}):null,index_html_changed:e?.index_html_change,index_css_changed:e?.index_css_change,index_client_changed:e?.index_client_change})))}}}),a.on("connection",function(e,t={}){const n=g(16),[s,r]=t?.url?.split("?"),o=p.parse(r);process.HMR_CONNECTIONS={...process.HMR_CONNECTIONS||{},[n]:{connection:e,browser_language:o?.browser_language,user_language:o?.user_language,page_component_path:o?.page_component_path}},Object.keys(process.HMR_CONNECTIONS||{})?.length>0&&process.send({type:"HAS_HMR_CONNECTIONS"}),e.on("message",_=>{JSON.parse(_)?.type==="HMR_UPDATE_COMPLETE"&&process.send({type:"HMR_UPDATE_COMPLETE"})}),e.on("close",()=>{process.HMR_CONNECTIONS[n]&&(delete process.HMR_CONNECTIONS[n],Object.keys(process.HMR_CONNECTIONS||{})?.length===0&&process.send({type:"HAS_NO_HMR_CONNECTIONS"}))})})})();export{u as default};
|
package/package.json
CHANGED
|
@@ -14,26 +14,19 @@ export default (() => {
|
|
|
14
14
|
process.on("message", async (message) => {
|
|
15
15
|
const parsed_message = JSON.parse(message);
|
|
16
16
|
|
|
17
|
-
console.log('message callback', {
|
|
18
|
-
connections: process.HMR_CONNECTIONS,
|
|
19
|
-
connections_type: typeof process.HMR_CONNECTIONS,
|
|
20
|
-
parsed_message,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
17
|
if (typeof process.HMR_CONNECTIONS === "object" && !!parsed_message?.type) {
|
|
24
18
|
const connections = Object.values(process.HMR_CONNECTIONS);
|
|
19
|
+
|
|
25
20
|
for (let i = 0; i < connections?.length; i += 1) {
|
|
26
21
|
const connection = connections[i];
|
|
27
22
|
|
|
28
|
-
console.log('SEND TO', connection);
|
|
29
|
-
|
|
30
23
|
if (connection?.connection?.send) {
|
|
31
24
|
if (parsed_message?.type === 'BUILD_ERROR') {
|
|
32
|
-
|
|
25
|
+
connection.connection.send(JSON.stringify({ type: 'BUILD_ERROR' }));
|
|
33
26
|
}
|
|
34
27
|
|
|
35
28
|
if (parsed_message?.type === 'FILE_CHANGE') {
|
|
36
|
-
|
|
29
|
+
connection.connection.send(
|
|
37
30
|
JSON.stringify({
|
|
38
31
|
type: "FILE_CHANGE",
|
|
39
32
|
settings: parsed_message?.settings ? {
|
|
@@ -66,8 +59,6 @@ export default (() => {
|
|
|
66
59
|
const [_path, params] = connection_request?.url?.split("?");
|
|
67
60
|
const connection_params = queryString.parse(params);
|
|
68
61
|
|
|
69
|
-
console.log('ADD CONNECTION', connection_id);
|
|
70
|
-
|
|
71
62
|
process.HMR_CONNECTIONS = {
|
|
72
63
|
...(process.HMR_CONNECTIONS || {}),
|
|
73
64
|
[connection_id]: {
|
|
@@ -78,8 +69,6 @@ export default (() => {
|
|
|
78
69
|
},
|
|
79
70
|
};
|
|
80
71
|
|
|
81
|
-
console.log('connection callback', process.HMR_CONNECTIONS);
|
|
82
|
-
|
|
83
72
|
if (Object.keys(process.HMR_CONNECTIONS || {})?.length > 0) {
|
|
84
73
|
process.send({ type: "HAS_HMR_CONNECTIONS" });
|
|
85
74
|
}
|
|
@@ -96,8 +85,6 @@ export default (() => {
|
|
|
96
85
|
if (process.HMR_CONNECTIONS[connection_id]) {
|
|
97
86
|
delete process.HMR_CONNECTIONS[connection_id];
|
|
98
87
|
|
|
99
|
-
console.log('DELETE CONNECTION', connection_id);
|
|
100
|
-
|
|
101
88
|
if (Object.keys(process.HMR_CONNECTIONS || {})?.length === 0) {
|
|
102
89
|
process.send({ type: "HAS_NO_HMR_CONNECTIONS" });
|
|
103
90
|
}
|