@joystick.js/cli-canary 0.0.0-canary.608 → 0.0.0-canary.609
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 _ from"query-string";import{WebSocketServer as i}from"ws";import N from"../generate_id.js";import g from"./get_translations.js";process.title="joystick_hmr";var u=(()=>{const r=new i({port:parseInt(process.env.PORT,10)+1,path:"/_joystick/hmr"});process.on("message",async c=>{const e=JSON.parse(c);if(console.log("message callback",{connections:process.HMR_CONNECTIONS,connections_type:typeof process.HMR_CONNECTIONS,parsed_message:e}),typeof process.HMR_CONNECTIONS=="object"&&e?.type){const o=Object.values(process.HMR_CONNECTIONS);for(let n=0;n<o?.length;n+=1){const s=o[n];if(s?.connection?.send){if(e?.type==="BUILD_ERROR")return s.connection.send(JSON.stringify({type:"BUILD_ERROR"}));if(e?.type==="FILE_CHANGE")return 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 g("./.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}))}}}}),r.on("connection",function(e,o={}){const n=N(16),[s,a]=o?.url?.split("?"),t=_.parse(a);console.log("ADD CONNECTION",n),process.HMR_CONNECTIONS={...process.HMR_CONNECTIONS||{},[n]:{connection:e,browser_language:t?.browser_language,user_language:t?.user_language,page_component_path:t?.page_component_path}},console.log("connection callback",process.HMR_CONNECTIONS),Object.keys(process.HMR_CONNECTIONS||{})?.length>0&&process.send({type:"HAS_HMR_CONNECTIONS"}),e.on("message",p=>{JSON.parse(p)?.type==="HMR_UPDATE_COMPLETE"&&process.send({type:"HMR_UPDATE_COMPLETE"})}),e.on("close",()=>{process.HMR_CONNECTIONS[n]&&(delete process.HMR_CONNECTIONS[n],console.log("DELETE CONNECTION",n),Object.keys(process.HMR_CONNECTIONS||{})?.length===0&&process.send({type:"HAS_NO_HMR_CONNECTIONS"}))})})})();export{u as default};
|
package/package.json
CHANGED
|
@@ -31,27 +31,6 @@ export default (() => {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if (parsed_message?.type === 'FILE_CHANGE') {
|
|
34
|
-
console.log('SENDING...', JSON.stringify({
|
|
35
|
-
type: "FILE_CHANGE",
|
|
36
|
-
settings: parsed_message?.settings ? {
|
|
37
|
-
global: parsed_message?.settings?.global,
|
|
38
|
-
public: parsed_message?.settings?.public,
|
|
39
|
-
} : null,
|
|
40
|
-
i18n: parsed_message?.i18n_change ? await get_translations('./.joystick/build', connection?.page_component_path, {
|
|
41
|
-
headers: {
|
|
42
|
-
'accept-language': connection?.browser_language,
|
|
43
|
-
},
|
|
44
|
-
context: {
|
|
45
|
-
user: {
|
|
46
|
-
language: connection?.user_language,
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
}) : null,
|
|
50
|
-
index_html_changed: parsed_message?.index_html_change,
|
|
51
|
-
index_css_changed: parsed_message?.index_css_change,
|
|
52
|
-
index_client_changed: parsed_message?.index_client_change,
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
34
|
return connection.connection.send(
|
|
56
35
|
JSON.stringify({
|
|
57
36
|
type: "FILE_CHANGE",
|
|
@@ -85,6 +64,8 @@ export default (() => {
|
|
|
85
64
|
const [_path, params] = connection_request?.url?.split("?");
|
|
86
65
|
const connection_params = queryString.parse(params);
|
|
87
66
|
|
|
67
|
+
console.log('ADD CONNECTION', connection_id);
|
|
68
|
+
|
|
88
69
|
process.HMR_CONNECTIONS = {
|
|
89
70
|
...(process.HMR_CONNECTIONS || {}),
|
|
90
71
|
[connection_id]: {
|
|
@@ -113,6 +94,8 @@ export default (() => {
|
|
|
113
94
|
if (process.HMR_CONNECTIONS[connection_id]) {
|
|
114
95
|
delete process.HMR_CONNECTIONS[connection_id];
|
|
115
96
|
|
|
97
|
+
console.log('DELETE CONNECTION', connection_id);
|
|
98
|
+
|
|
116
99
|
if (Object.keys(process.HMR_CONNECTIONS || {})?.length === 0) {
|
|
117
100
|
process.send({ type: "HAS_NO_HMR_CONNECTIONS" });
|
|
118
101
|
}
|